Skip to content

Commit

Permalink
Best effort avoid crash when media transport adapter not using group …
Browse files Browse the repository at this point in the history
…lock
  • Loading branch information
nanangizz committed Jan 31, 2025
1 parent f986ad8 commit 30e092e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pjmedia/src/pjmedia/stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -3168,6 +3168,12 @@ PJ_DEF(pj_status_t) pjmedia_stream_destroy( pjmedia_stream *stream )

PJ_LOG(4,(stream->port.info.name.ptr, "Stream destroying"));

/* Stop the streaming */
if (stream->enc)
stream->port.put_frame = NULL;
if (stream->dec)
stream->port.get_frame = NULL;

/* Send RTCP BYE (also SDES & XR) */
if (stream->transport && !stream->rtcp_sdes_bye_disabled) {
#if defined(PJMEDIA_HAS_RTCP_XR) && (PJMEDIA_HAS_RTCP_XR != 0)
Expand Down
14 changes: 14 additions & 0 deletions pjsip/src/pjsua-lib/pjsua_media.c
Original file line number Diff line number Diff line change
Expand Up @@ -2269,6 +2269,7 @@ static pj_status_t media_channel_init_cb(pjsua_call_id call_id,

if (call_med->use_custom_med_tp) {
unsigned custom_med_tp_flags = PJSUA_MED_TP_CLOSE_MEMBER;
pj_grp_lock_t *tp_grp_lock = call_med->tp->grp_lock;

/* Use custom media transport returned by the application */
call_med->tp =
Expand All @@ -2279,6 +2280,19 @@ static pj_status_t media_channel_init_cb(pjsua_call_id call_id,
status =
PJSIP_ERRNO_FROM_SIP_STATUS(PJSIP_SC_TEMPORARILY_UNAVAILABLE);
}

/* Check if the media transport adapter has no group lock. */
if (call_med->tp && call_med->tp->grp_lock==NULL) {
PJ_LOG(3, (THIS_FILE, "Call %d media %d: Warning, "
"media transport adapter should manage its "
"lifetime using group lock of the underlying "
"transport", call_id, mi));

/* Assign group lock, this will maintain the lifetime of
* the original transport only, not the transport adapter.
*/
call_med->tp->grp_lock = tp_grp_lock;
}
}

if (call_med->tp) {
Expand Down

0 comments on commit 30e092e

Please sign in to comment.