From 1b430c76d5be1b28ae6a048d46280fc76ffe10c7 Mon Sep 17 00:00:00 2001 From: Sergey Khripchenko Date: Fri, 22 Mar 2019 09:43:59 -0700 Subject: [PATCH] FS-11726 New dialplan application to wait for video stream being ready (ICE and DTLS setup) --- .../applications/mod_dptools/mod_dptools.c | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/mod/applications/mod_dptools/mod_dptools.c b/src/mod/applications/mod_dptools/mod_dptools.c index 60105de3c9..f0e18b3336 100644 --- a/src/mod/applications/mod_dptools/mod_dptools.c +++ b/src/mod/applications/mod_dptools/mod_dptools.c @@ -1386,6 +1386,34 @@ SWITCH_STANDARD_APP(wait_for_answer_function) } } +#define WAIT_FOR_VIDEO_READY_SYNTAX "[]" +SWITCH_STANDARD_APP(wait_for_video_ready_function) +{ + uint32_t delay = 0, delay_def = 10000; + switch_status_t res; + + switch_channel_t *channel = switch_core_session_get_channel(session); + + if (zstr(data) || ((delay = atoi(data)) < 1) || (delay > 10000)) { + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "wait_for_video_ready: Invalid Timeout. Use default %d ms.\n", delay_def); + delay = delay_def; + } + + if (switch_channel_test_flag(channel, CF_VIDEO)) { + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Starting to wait %d ms until video stream is ready\n", delay); + res = switch_channel_wait_for_flag(channel, CF_VIDEO_READY, SWITCH_TRUE, delay, NULL); + if (res == SWITCH_STATUS_SUCCESS) { + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "Video stream is ready\n"); + } else if (res == SWITCH_STATUS_TIMEOUT) { + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "Video stream is not ready after %d ms. Abort waiting.\n", delay); + } else { + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "Error (%d) waiting for video stream to be ready\n", res); + } + } else { + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_NOTICE, "Cannot wait for video stream on a non video call\n"); + } +} + SWITCH_STANDARD_APP(presence_function) { char *argv[6] = { 0 }; @@ -6449,6 +6477,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_dptools_load) SWITCH_ADD_APP(app_interface, "pre_answer", "Pre-Answer the call", "Pre-Answer the call for a channel.", pre_answer_function, "", SAF_SUPPORT_NOMEDIA); SWITCH_ADD_APP(app_interface, "answer", "Answer the call", "Answer the call for a channel.", answer_function, "", SAF_SUPPORT_NOMEDIA); SWITCH_ADD_APP(app_interface, "wait_for_answer", "Wait for call to be answered", "Wait for call to be answered.", wait_for_answer_function, "", SAF_SUPPORT_NOMEDIA); + SWITCH_ADD_APP(app_interface, "wait_for_video_ready", "Wait for video stream to be ready", "Wait for video stream to be ready.", wait_for_video_ready_function, WAIT_FOR_VIDEO_READY_SYNTAX, SAF_NONE); SWITCH_ADD_APP(app_interface, "hangup", "Hangup the call", "Hangup the call for a channel.", hangup_function, "[]", SAF_SUPPORT_NOMEDIA); SWITCH_ADD_APP(app_interface, "set_name", "Name the channel", "Name the channel", set_name_function, "", SAF_SUPPORT_NOMEDIA); SWITCH_ADD_APP(app_interface, "presence", "Send Presence", "Send Presence.", presence_function, " []",