Discussion:
Deadlock with PJSUA-API and EOF-callback
Velthoen, Arie
2007-07-23 15:40:27 UTC
Permalink
Hi all,

I am working on an application based on simple_pjsua.c.that plays
announcements.
The application answers a call, plays a wav-file, and at end of the
wav-file it hangs-up the call.
However when handling more than one call simultaneously it runs into a
deadlock.

Can you give me some guidance how to use the wav-player-EOF callback
(set with
pjmedia_wav_player_set_eof_cb) without the risk of running into a
deadlock?

Details are as follows:

With pjmedia_wav_player_set_eof_cb callback AnnouncementStopped has been
registered.
At EOF AnnouncementStopped is called which calls
- pjsua_player_destroy
- pjsua_call_hangup.

Now when I use PJSUA to make SIP-calls to this announcement-application
with 2 (or more) calls simultaneously, a deadlock occurs when
- Call 0: 200-OK response is received on the BYE, handled by thread
pjsua
- Call 1: EOF is reached, handled by thread clock.

Thread pjsua (handling the 200-OK response on BYE for call 0), has mutex
"pjsua",
but remains waiting for mutex "conf" with the following call stack:
- pjmedia_conf_remove_port
- call_destroy_media
- pjsua_call_on_state_changed
- inv_set_state
- inv_handle_bye_response
- inv_on_state_confirmed
- mod_inv_on_tsx_state
- pjsip_dlg_on_tsx_state
- mod_ua_on_tsx_state
- tsx_set_state
- tsx_on_state_proceeding_uac
- tsx_on_state_calling
- pjsip_tsx_recv_msg
- mod_tsx_layer_on_rx_response
- endpt_on_rx_msg
- pjsip_tpmgr_receive_packet
- on_read_complete
- ioqueue_dispatch_read_event
- pj_ioqueue_poll
- pjsip_endpt_handle_events2
- pjsua_handle_events
- worker_thread
- thread_main

Thread clock (handling the EOF for call 1) has mutex "conf", but remains
waiting for mutex "pjsua" with the following call stack:
- acquire_call
- pjsua_call_hangup
- AnnouncementStopped
- fill_buffer
- file_get_frame
- pjmedia_port_get_frame
- read_port
- get_frame
- pjmedia_port_get_frame
- clock_callback
- clock_thread
- thread_main


Best regards,

Arie Velthoen
Benny Prijono
2007-07-24 15:20:28 UTC
Permalink
Hi Arie,
Post by Velthoen, Arie
Hi all,
I am working on an application based on simple_pjsua.c.that plays
announcements.
The application answers a call, plays a wav-file, and at end of the
wav-file it hangs-up the call.
However when handling more than one call simultaneously it runs into a
deadlock.
Can you give me some guidance how to use the wav-player-EOF callback
(set with
pjmedia_wav_player_set_eof_cb) without the risk of running into a deadlock?
Thanks for the detailed info. I guess this is quite a difficult
problem, and I don't know any other solution other than to use timer
to hangup the call. So perhaps you could do something like this:

on EOF callback:
pjsip_endpt_schedule_timer(with_zero_delay);

on timer callback:
pjsua_call_hangup();

on call's disconnected state:
pjsua_player_destroy();

I think the above solution should be safe. It's not too convenient,
but unfortunately that's the only solution that I can think of.

-benny

_______________________________________________
pjsip mailing list: ***@pjsip.org
http://pjsip.org/mailman/listinfo/pjsip

Visit pjsip blog: http://blog.pjsip.org
Velthoen, Arie
2007-07-24 13:13:38 UTC
Permalink
Benny,

Thank you.

Arie Velthoen

_______________________________________________
pjsip mailing list: ***@pjsip.org
http://pjsip.org/mailman/listinfo/pjsip

Visit pjsip blog: http://blog.pjsip.org
tech
2007-07-25 04:59:12 UTC
Permalink
I modified simple-pjsua to either call or answer several calls at the same
time to stream a wave file to caller. However, when streaming a file using
stream_to_call example, I got no sound. The file is PCMA/8KHz mono. I did
not change sampling default.
I call stream_to_call on "CONFIRMED" call status.
I am using the sample with asterisk to call/answer another phone x-lite.

Any clue?

Thanks,
Alsaleem


_______________________________________________
pjsip mailing list: ***@pjsip.org
http://pjsip.org/mailman/listinfo/pjsip

Visit pjsip blog: http://blog.pjsip.org
Benny Prijono
2007-07-27 04:58:55 UTC
Permalink
Post by tech
I modified simple-pjsua to either call or answer several calls at the same
time to stream a wave file to caller. However, when streaming a file using
stream_to_call example, I got no sound. The file is PCMA/8KHz mono. I did
not change sampling default.
I call stream_to_call on "CONFIRMED" call status.
I am using the sample with asterisk to call/answer another phone x-lite.
Please see this page first on anything related to audio problems:
http://www.pjsip.org/trac/wiki/sound-problems

-benny

_______________________________________________
pjsip mailing list: ***@pjsip.org
http://pjsip.org/mailman/listinfo/pjsip

Visit pjsip blog: http://blog.pjsip.org

Loading...