FS-7513: add some mutexes on video_read_callback code

This commit is contained in:
Anthony Minessale 2015-04-15 14:49:01 -05:00 committed by Michael Jerris
parent 1fb0dcd61d
commit d8e5334a05
3 changed files with 44 additions and 30 deletions

View File

@ -4661,10 +4661,8 @@ static switch_status_t video_thread_callback(switch_core_session_t *session, swi
switch_assert(member); switch_assert(member);
lock_member(member);
if (switch_thread_rwlock_tryrdlock(member->conference->rwlock) != SWITCH_STATUS_SUCCESS) { if (switch_thread_rwlock_tryrdlock(member->conference->rwlock) != SWITCH_STATUS_SUCCESS) {
unlock_member(member);
return SWITCH_STATUS_FALSE; 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_queue_push(member->video_queue, img_copy);
} }
switch_thread_rwlock_unlock(member->conference->rwlock); switch_thread_rwlock_unlock(member->conference->rwlock);
unlock_member(member);
return SWITCH_STATUS_SUCCESS; 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); switch_thread_rwlock_unlock(member->conference->rwlock);
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;

View File

@ -10563,6 +10563,50 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_video_frame(switch_core
return status; 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: /* For Emacs:

View File

@ -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_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: /* For Emacs:
* Local Variables: * Local Variables:
* mode:c * mode:c