From 9c72dc950e3b08c4b987e62a1a02358a319d599b Mon Sep 17 00:00:00 2001 From: Seven Du Date: Fri, 22 Nov 2013 14:23:18 +0800 Subject: [PATCH] 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 --- src/include/switch_types.h | 1 + src/switch_core_io.c | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/include/switch_types.h b/src/include/switch_types.h index 0567fd2455..cf6f4c247d 100644 --- a/src/include/switch_types.h +++ b/src/include/switch_types.h @@ -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 diff --git a/src/switch_core_io.c b/src/switch_core_io.c index 13c15874f4..d571da41b0 100644 --- a/src/switch_core_io.c +++ b/src/switch_core_io.c @@ -26,6 +26,7 @@ * Anthony Minessale II * Michael Jerris * Paul D. Tinsley + * Seven Du * * * 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);