From d8e5334a055bf5042db18c1a8f2f9c8871f36bbf Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 15 Apr 2015 14:49:01 -0500 Subject: [PATCH] FS-7513: add some mutexes on video_read_callback code --- .../mod_conference/mod_conference.c | 4 -- src/switch_core_media.c | 44 +++++++++++++++++++ src/switch_core_session.c | 26 ----------- 3 files changed, 44 insertions(+), 30 deletions(-) diff --git a/src/mod/applications/mod_conference/mod_conference.c b/src/mod/applications/mod_conference/mod_conference.c index 3a6ad5184e..70b34be686 100644 --- a/src/mod/applications/mod_conference/mod_conference.c +++ b/src/mod/applications/mod_conference/mod_conference.c @@ -4661,10 +4661,8 @@ static switch_status_t video_thread_callback(switch_core_session_t *session, swi switch_assert(member); - lock_member(member); if (switch_thread_rwlock_tryrdlock(member->conference->rwlock) != SWITCH_STATUS_SUCCESS) { - unlock_member(member); return SWITCH_STATUS_FALSE; } @@ -4676,7 +4674,6 @@ static switch_status_t video_thread_callback(switch_core_session_t *session, swi switch_queue_push(member->video_queue, img_copy); } switch_thread_rwlock_unlock(member->conference->rwlock); - unlock_member(member); return SWITCH_STATUS_SUCCESS; } @@ -4720,7 +4717,6 @@ static switch_status_t video_thread_callback(switch_core_session_t *session, swi } } - unlock_member(member); switch_thread_rwlock_unlock(member->conference->rwlock); return SWITCH_STATUS_SUCCESS; diff --git a/src/switch_core_media.c b/src/switch_core_media.c index c72c2a5183..8b9ee13d54 100644 --- a/src/switch_core_media.c +++ b/src/switch_core_media.c @@ -10563,6 +10563,50 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_video_frame(switch_core return status; } +SWITCH_DECLARE(switch_status_t) switch_core_session_set_video_read_callback(switch_core_session_t *session, + switch_core_video_thread_callback_func_t func, void *user_data) +{ + switch_status_t status = SWITCH_STATUS_SUCCESS; + switch_media_handle_t *smh; + + if (!(smh = session->media_handle)) { + return SWITCH_STATUS_FALSE; + } + + switch_mutex_lock(smh->control_mutex); + if (!func) { + session->video_read_callback = NULL; + session->video_read_user_data = NULL; + } else if (session->video_read_callback) { + status = SWITCH_STATUS_FALSE; + } else { + session->video_read_callback = func; + session->video_read_user_data = user_data; + } + switch_mutex_unlock(smh->control_mutex); + + return status; +} + +SWITCH_DECLARE(switch_status_t) switch_core_session_video_read_callback(switch_core_session_t *session, switch_frame_t *frame) +{ + switch_media_handle_t *smh; + switch_status_t status = SWITCH_STATUS_CONTINUE; + + if (!(smh = session->media_handle)) { + return SWITCH_STATUS_FALSE; + } + + switch_mutex_lock(smh->control_mutex); + + if (session->video_read_callback) { + status = session->video_read_callback(session, frame, session->video_read_user_data); + } + + switch_mutex_unlock(smh->control_mutex); + + return status; +} /* For Emacs: diff --git a/src/switch_core_session.c b/src/switch_core_session.c index c37af893d4..40c1a0ed35 100644 --- a/src/switch_core_session.c +++ b/src/switch_core_session.c @@ -3073,32 +3073,6 @@ SWITCH_DECLARE(void) switch_core_session_raw_read(switch_core_session_t *session switch_core_session_set_codec_slin(session, session->sdata); } - -SWITCH_DECLARE(switch_status_t) switch_core_session_set_video_read_callback(switch_core_session_t *session, - switch_core_video_thread_callback_func_t func, void *user_data) -{ - if (!func) { - session->video_read_callback = NULL; - session->video_read_user_data = NULL; - return SWITCH_STATUS_SUCCESS; - } else if (session->video_read_callback) { - return SWITCH_STATUS_FALSE; - } else { - session->video_read_callback = func; - session->video_read_user_data = user_data; - return SWITCH_STATUS_SUCCESS; - } -} - -SWITCH_DECLARE(switch_status_t) switch_core_session_video_read_callback(switch_core_session_t *session, switch_frame_t *frame) -{ - if (session->video_read_callback) { - return session->video_read_callback(session, frame, session->video_read_user_data); - } - - return SWITCH_STATUS_CONTINUE; -} - /* For Emacs: * Local Variables: * mode:c