Crash in pjsua_aud with multiple worker threads

JD
Johnny Depp
Tue, Sep 10, 2019 3:28 PM

Hi Y'alls,

I have a problem in a multi-threaded environment that I am trying to alleviate.

This is what I have done:
I have an end of file callback for any prompt file played in the system. I have followed the examples and set and EOF callback using pjmedia_wav_player_set_eof_cb and in that callback making calls to  pjsua_conf_disconnect, pjsua_player_get_conf_port,
pjsua_call_get_conf_port, and pjsua_player_destroy. But this would always lead to a deadlock as any of these function calls will interfere with get_frame that runs on the timer thread.

Therefore, I scheduled all these calls on the timer thread as mentioned on this 12 year old thread:
https://pjsip.pjsip.narkive.com/y7A4ge2Z/deadlock-with-pjsua-api-and-eof-callback

Now the system works but only if I have 0 pjsip worker threads. Which will not scale well in the future.
It seems that when calculating the size of the array
PJ_ASSERT_RETURN(id>=0&&id<(int)PJ_ARRAY_SIZE(pjsua_var.player),PJ_EINVAL);
in any of the above pjsua function calls in the pjsua_aud.c I get a segmentation crash when using more than 0 worker threads.

Is there any way to alleviate this? I can provide source code if needed.

Thank you,

Joey.

Hi Y'alls, I have a problem in a multi-threaded environment that I am trying to alleviate. This is what I have done: I have an end of file callback for any prompt file played in the system. I have followed the examples and set and EOF callback using pjmedia_wav_player_set_eof_cb and in that callback making calls to pjsua_conf_disconnect, pjsua_player_get_conf_port, pjsua_call_get_conf_port, and pjsua_player_destroy. But this would always lead to a deadlock as any of these function calls will interfere with get_frame that runs on the timer thread. Therefore, I scheduled all these calls on the timer thread as mentioned on this 12 year old thread: https://pjsip.pjsip.narkive.com/y7A4ge2Z/deadlock-with-pjsua-api-and-eof-callback Now the system works but only if I have 0 pjsip worker threads. Which will not scale well in the future. It seems that when calculating the size of the array PJ_ASSERT_RETURN(id>=0&&id<(int)PJ_ARRAY_SIZE(pjsua_var.player),PJ_EINVAL); in any of the above pjsua function calls in the pjsua_aud.c I get a segmentation crash when using more than 0 worker threads. Is there any way to alleviate this? I can provide source code if needed. Thank you, Joey.