]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
add CF_MEDIA_PAUSE channel flag to allow waiting for IO before media codec is ready
authorSeven Du <dujinfang@gmail.com>
Fri, 22 Nov 2013 06:23:18 +0000 (14:23 +0800)
committerSeven Du <dujinfang@gmail.com>
Fri, 22 Nov 2013 06:37:37 +0000 (14:37 +0800)
This could be used at endpoints where signalling and media negotiated separately like in H323

src/include/switch_types.h
src/switch_core_io.c

index 0567fd245551abdb8c9606b026c8fc2f37864951..cf6f4c247dfaf356ac32801d5caac160c7f00d29 100644 (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
index 13c15874f4f54748bbebade1c2fea360f364bf59..d571da41b0c19f82cc59c84eec16c8f8ec145337 100644 (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);