versatica / libmediasoupclient

mediasoup client side C++ library

Home Page:https://mediasoup.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Transport produce method must be called in thread

richmonkey opened this issue · comments

commented

Because Transportlistener->onProducer must access network, so Transport.produce must be called in thread.
It's not a issuse, but as a library, it's not very good.
Can split transport.produce into two step.

  1. sendResult = transport.prepareProduce(params...);
  2. request server, transport produce(sendResult...);
  3. if request success, got producerId from server, call native transport.produce(producerId, sendResult)
    else request failure, call native transport.cancelProduce(sendResult)

If api like this, it's my free to call mediaclient api in main thread or other thread.

commented

Need more work to do,
Handler.SetupTransport is another async method,
Only if precreate local dtlsParameters is possible, the target is possible.

if device.createSendTransport() can get local dtlsParameters
after createSendTransport, request server connectTransport with local dtlsParameters .
last transport.produce

commented

How to get local dtlsParameters in the step device.createSendTransport()?
in handler create peerconnect, add transceiver, createoffer, get dtlsparamters from localsdp, close peerconnection. save the local dtlsParamters
in last produce step, when after createoffer, modify the sdp's dtlsparamters field with saved local dtlsParamters, setlocaldescription with the changed sdp.
Is it possible?

commented

My opinion:library's listener is async, it's complex for caller, also not good smell.

commented

Transport.produce must be called in thread.

Actually, calls to Transport.produce should be queued somehow, otherwise the handler may try to connect the transport more than once, not to mention that internal manipulations with sdp are not thread-safe.

commented

“calls to Transport.produce should be queued somehow”, I know this.
meidasoupclient is not threadsafe.
I want to express:
So for simple, call meidasoupclient always in one thread,
mediasoupcliennt can't be called in ui thread, because Transport.produce is sync method and long time(access network).

This is not a bug. This is by design. Nobody said that libmediasoupclient can be used in UI thread. Please let's use the mediasoup forum for further discussions.