Benny Prijono wrote: > Klaus Darilion wrote: >> The workaround is to use Qt's "signals and slots" mechanism with >> Qt::QueuedConnection between the callback function and your application >> logic which access Qt objects. > > I'm not sure how Qt's signals and slots is implemented, but if it's > implemented with some kind of queuing where one thread posts an > event to other thread's event queue, we'll have a problem. Qt - we have a problem ;-) > The problem is some object state is only valid for the duration of > the callback. For example, if on_call_state() callback is called > with state==DISCONNECTED, pjsua-lib only retains the call until this > callback is called, so that the application can retrieve the call > state inside the callback. Once the callback returns, the call will > be destroyed. So if you queue this callback to be processed by > another thread, the handler may not be able to access the call since > it may have been destroyed. For things which require no user interaction it is no problem - the logic is handled in the callback and the result will be presented by the user by the other thread (e.g. display "connected" to the user). But as you said it may be problematic for callbacks which require user interaction, e.g. "do you want to accept the incoming call?". And if the user answers "yes" it may happen that the call is not more valid anymore. > I think there are two solutions for this: > > One is to make the original callback waits synchronously until the > queue is processed by the other thread. Maybe this can be done in Qt by sending a signal to the GUI thread and then wait for a signal which is returned from the GUI to the callback. > The second solution is a lot simpler. You just need to disable the > worker thread in pjsua-lib by setting pjsua_config.thread_cnt to > zero, and create your own Qt thread to poll pjsip, something like: > > void qt_poller_thread() > { > while (!qt_quit) { > pjsua_handle_events(10); > } > } > > With this approach, all callbacks will be called in the context of > your Qt thread. There is still another problem, that is for > callbacks that are called from the media thread context (for > example, on_dtmf_digit(), or the WAV EOF callbacks if you have one). > Since these callbacks are not called by pjsip's worker thread, > you'll probably need to use the queue approach to process them. Is it possible to make pjsua single-threaded - so that even RTP is processed by a single thread? regards klaus > > regards, > -benny > > >> cheers >> Klaus > > > _______________________________________________ > Visit our blog: http://blog.pjsip.org > > pjsip mailing list > pjsip at lists.pjsip.org > http://lists.pjsip.org/mailman/listinfo/pjsip_lists.pjsip.org