add CF_MEDIA_PAUSE channel flag to allow waiting for IO before media codec is ready

This could be used at endpoints where signalling and media negotiated separately like in H323
This commit is contained in:
Seven Du 2013-11-22 14:23:18 +08:00
parent b8dc07132a
commit 9c72dc950e
2 changed files with 24 additions and 0 deletions

View File

@ -1362,6 +1362,7 @@ typedef enum {
CF_VIDEO_ECHO,
CF_SLA_INTERCEPT,
CF_VIDEO_BREAK,
CF_MEDIA_PAUSE,
/* WARNING: DO NOT ADD ANY FLAGS BELOW THIS LINE */
/* IF YOU ADD NEW ONES CHECK IF THEY SHOULD PERSIST OR ZERO THEM IN switch_core_session.c switch_core_session_request_xml() */
CF_FLAG_MAX

View File

@ -26,6 +26,7 @@
* Anthony Minessale II <anthm@freeswitch.org>
* Michael Jerris <mike@jerris.com>
* Paul D. Tinsley <pdt at jackhammer.org>
* Seven Du <dujinfang@gmail.com>
*
*
* switch_core_io.c -- Main Core Library (Media I/O)
@ -45,6 +46,10 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_write_video_frame(switch_cor
return SWITCH_STATUS_FALSE;
}
if (switch_channel_test_flag(session->channel, CF_MEDIA_PAUSE)) {
return SWITCH_STATUS_SUCCESS;
}
if (session->endpoint_interface->io_routines->write_video_frame) {
if ((status = session->endpoint_interface->io_routines->write_video_frame(session, frame, flags, stream_id)) == SWITCH_STATUS_SUCCESS) {
for (ptr = session->event_hooks.video_write_frame; ptr; ptr = ptr->next) {
@ -69,6 +74,12 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_video_frame(switch_core
return SWITCH_STATUS_FALSE;
}
if (switch_channel_test_flag(session->channel, CF_MEDIA_PAUSE)) {
*frame = &runtime.dummy_cng_frame;
switch_yield(20000);
return SWITCH_STATUS_SUCCESS;
}
if (session->endpoint_interface->io_routines->read_video_frame) {
if ((status = session->endpoint_interface->io_routines->read_video_frame(session, frame, flags, stream_id)) == SWITCH_STATUS_SUCCESS) {
for (ptr = session->event_hooks.video_read_frame; ptr; ptr = ptr->next) {
@ -165,6 +176,14 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_frame(switch_core_sessi
*frame = &runtime.dummy_cng_frame;
return SWITCH_STATUS_SUCCESS;
}
if (switch_channel_test_flag(session->channel, CF_MEDIA_PAUSE)) {
switch_yield(20000);
*frame = &runtime.dummy_cng_frame;
// switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Media Paused!!!!\n");
return SWITCH_STATUS_SUCCESS;
}
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "%s has no read codec.\n", switch_channel_get_name(session->channel));
switch_channel_hangup(session->channel, SWITCH_CAUSE_INCOMPATIBLE_DESTINATION);
return SWITCH_STATUS_FALSE;
@ -1033,6 +1052,10 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_write_frame(switch_core_sess
}
}
if (switch_channel_test_flag(session->channel, CF_MEDIA_PAUSE)) {
return SWITCH_STATUS_SUCCESS;
}
if (!(session->write_codec && switch_core_codec_ready(session->write_codec)) && !pass_cng) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "%s has no write codec.\n", switch_channel_get_name(session->channel));
switch_channel_hangup(session->channel, SWITCH_CAUSE_INCOMPATIBLE_DESTINATION);