diff --git a/src/include/switch_ivr.h b/src/include/switch_ivr.h index 318ce26214..1e76848dc9 100644 --- a/src/include/switch_ivr.h +++ b/src/include/switch_ivr.h @@ -1031,6 +1031,7 @@ SWITCH_DECLARE(char *) switch_ivr_check_presence_mapping(const char *exten_name, SWITCH_DECLARE(switch_status_t) switch_ivr_kill_uuid(const char *uuid, switch_call_cause_t cause); SWITCH_DECLARE(switch_status_t) switch_ivr_blind_transfer_ack(switch_core_session_t *session, switch_bool_t success); SWITCH_DECLARE(switch_status_t) switch_ivr_record_session_mask(switch_core_session_t *session, const char *file, switch_bool_t on); +SWITCH_DECLARE(switch_status_t) switch_ivr_record_session_pause(switch_core_session_t *session, const char *file, switch_bool_t on); SWITCH_DECLARE(switch_status_t) switch_ivr_stop_video_write_overlay_session(switch_core_session_t *session); diff --git a/src/include/switch_types.h b/src/include/switch_types.h index 47a50869d8..b9ae217472 100644 --- a/src/include/switch_types.h +++ b/src/include/switch_types.h @@ -1910,7 +1910,8 @@ typedef enum { SMBF_SPY_VIDEO_STREAM_BLEG = (1 << 23), SMBF_READ_VIDEO_PATCH = (1 << 24), SMBF_READ_TEXT_STREAM = (1 << 25), - SMBF_FIRST = (1 << 26) + SMBF_FIRST = (1 << 26), + SMBF_PAUSE = (1 << 27) } switch_media_bug_flag_enum_t; typedef uint32_t switch_media_bug_flag_t; diff --git a/src/mod/applications/mod_commands/mod_commands.c b/src/mod/applications/mod_commands/mod_commands.c index 960268cd4f..8c185bcb12 100644 --- a/src/mod/applications/mod_commands/mod_commands.c +++ b/src/mod/applications/mod_commands/mod_commands.c @@ -4781,6 +4781,18 @@ SWITCH_STANDARD_API(session_record_function) } else { stream->write_function(stream, "+OK Success\n"); } + } else if (!strcasecmp(action, "pause")) { + if (switch_ivr_record_session_pause(rsession, path, SWITCH_TRUE) != SWITCH_STATUS_SUCCESS) { + stream->write_function(stream, "-ERR Cannot pause recording session!\n"); + } else { + stream->write_function(stream, "+OK Success\n"); + } + } else if (!strcasecmp(action, "resume")) { + if (switch_ivr_record_session_pause(rsession, path, SWITCH_FALSE) != SWITCH_STATUS_SUCCESS) { + stream->write_function(stream, "-ERR Cannot resume recording session!\n"); + } else { + stream->write_function(stream, "+OK Success\n"); + } } else if (!strcasecmp(action, "mask")) { if (switch_ivr_record_session_mask(rsession, path, SWITCH_TRUE) != SWITCH_STATUS_SUCCESS) { stream->write_function(stream, "-ERR Cannot mask recording session!\n"); diff --git a/src/mod/applications/mod_dptools/mod_dptools.c b/src/mod/applications/mod_dptools/mod_dptools.c index 079487f9e7..d755640c35 100644 --- a/src/mod/applications/mod_dptools/mod_dptools.c +++ b/src/mod/applications/mod_dptools/mod_dptools.c @@ -1,6 +1,6 @@ /* * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application - * Copyright (C) 2005-2015, Anthony Minessale II + * Copyright (C) 2005-2020, Anthony Minessale II * * Version: MPL 1.1 * @@ -3317,6 +3317,16 @@ SWITCH_STANDARD_APP(record_session_unmask_function) switch_ivr_record_session_mask(session, (char *) data, SWITCH_FALSE); } +SWITCH_STANDARD_APP(record_session_pause_function) +{ + switch_ivr_record_session_pause(session, (char *) data, SWITCH_TRUE); +} + +SWITCH_STANDARD_APP(record_session_resume_function) +{ + switch_ivr_record_session_pause(session, (char *) data, SWITCH_FALSE); +} + SWITCH_STANDARD_APP(record_session_function) { char *array[5] = {0}; @@ -6679,7 +6689,9 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_dptools_load) SWITCH_ADD_APP(app_interface, "stop_record_session", "Stop Record Session", STOP_SESS_REC_DESC, stop_record_session_function, "", SAF_NONE); SWITCH_ADD_APP(app_interface, "record_session", "Record Session", SESS_REC_DESC, record_session_function, " [+]", SAF_MEDIA_TAP); SWITCH_ADD_APP(app_interface, "record_session_mask", "Mask audio in recording", SESS_REC_MASK_DESC, record_session_mask_function, "", SAF_MEDIA_TAP); - SWITCH_ADD_APP(app_interface, "record_session_unmask", "Resume recording", SESS_REC_UNMASK_DESC, record_session_unmask_function, "", SAF_MEDIA_TAP); + SWITCH_ADD_APP(app_interface, "record_session_unmask", "Stop masking audio in recording", SESS_REC_UNMASK_DESC, record_session_unmask_function, "", SAF_MEDIA_TAP); + SWITCH_ADD_APP(app_interface, "record_session_pause", "Pause recording", "Temporarily pause writing call recording audio to file", record_session_pause_function, "", SAF_MEDIA_TAP); + SWITCH_ADD_APP(app_interface, "record_session_resume", "Resume paused recording", "Resume writing call recording audio to file", record_session_resume_function, "", SAF_MEDIA_TAP); SWITCH_ADD_APP(app_interface, "record", "Record File", "Record a file from the channels input", record_function, " [] [] []", SAF_NONE); SWITCH_ADD_APP(app_interface, "preprocess", "pre-process", "pre-process", preprocess_session_function, "", SAF_NONE); diff --git a/src/switch_core_io.c b/src/switch_core_io.c index 1d5ff7510b..13054b5b08 100644 --- a/src/switch_core_io.c +++ b/src/switch_core_io.c @@ -242,7 +242,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_frame(switch_core_sessi for (bp = session->bugs; bp; bp = bp->next) { ok = SWITCH_TRUE; - if (switch_channel_test_flag(session->channel, CF_PAUSE_BUGS) && !switch_core_media_bug_test_flag(bp, SMBF_NO_PAUSE)) { + if (switch_core_media_bug_test_flag(bp, SMBF_PAUSE) || (switch_channel_test_flag(session->channel, CF_PAUSE_BUGS) && !switch_core_media_bug_test_flag(bp, SMBF_NO_PAUSE))) { continue; } @@ -303,7 +303,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_frame(switch_core_sessi for (bp = session->bugs; bp; bp = bp->next) { ok = SWITCH_TRUE; - if (switch_channel_test_flag(session->channel, CF_PAUSE_BUGS) && !switch_core_media_bug_test_flag(bp, SMBF_NO_PAUSE)) { + if (switch_core_media_bug_test_flag(bp, SMBF_PAUSE) || (switch_channel_test_flag(session->channel, CF_PAUSE_BUGS) && !switch_core_media_bug_test_flag(bp, SMBF_NO_PAUSE))) { continue; } @@ -652,7 +652,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_frame(switch_core_sessi for (bp = session->bugs; bp; bp = bp->next) { ok = SWITCH_TRUE; - if (switch_channel_test_flag(session->channel, CF_PAUSE_BUGS) && !switch_core_media_bug_test_flag(bp, SMBF_NO_PAUSE)) { + if (switch_core_media_bug_test_flag(bp, SMBF_PAUSE) || (switch_channel_test_flag(session->channel, CF_PAUSE_BUGS) && !switch_core_media_bug_test_flag(bp, SMBF_NO_PAUSE))) { continue; } @@ -703,7 +703,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_frame(switch_core_sessi for (bp = session->bugs; bp; bp = bp->next) { ok = SWITCH_TRUE; - if (switch_channel_test_flag(session->channel, CF_PAUSE_BUGS) && !switch_core_media_bug_test_flag(bp, SMBF_NO_PAUSE)) { + if (switch_core_media_bug_test_flag(bp, SMBF_PAUSE) || (switch_channel_test_flag(session->channel, CF_PAUSE_BUGS) && !switch_core_media_bug_test_flag(bp, SMBF_NO_PAUSE))) { continue; } @@ -883,7 +883,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_frame(switch_core_sessi for (bp = session->bugs; bp; bp = bp->next) { ok = SWITCH_TRUE; - if (switch_channel_test_flag(session->channel, CF_PAUSE_BUGS) && !switch_core_media_bug_test_flag(bp, SMBF_NO_PAUSE)) { + if (switch_core_media_bug_test_flag(bp, SMBF_PAUSE) || (switch_channel_test_flag(session->channel, CF_PAUSE_BUGS) && !switch_core_media_bug_test_flag(bp, SMBF_NO_PAUSE))) { continue; } diff --git a/src/switch_core_media.c b/src/switch_core_media.c index 5c4e19ad49..0db5a7c95d 100644 --- a/src/switch_core_media.c +++ b/src/switch_core_media.c @@ -7224,7 +7224,7 @@ static switch_status_t perform_write(switch_core_session_t *session, switch_fram for (bp = session->bugs; bp; bp = bp->next) { ok = SWITCH_TRUE; - if (switch_channel_test_flag(session->channel, CF_PAUSE_BUGS) && !switch_core_media_bug_test_flag(bp, SMBF_NO_PAUSE)) { + if (switch_core_media_bug_test_flag(bp, SMBF_PAUSE) || (switch_channel_test_flag(session->channel, CF_PAUSE_BUGS) && !switch_core_media_bug_test_flag(bp, SMBF_NO_PAUSE))) { continue; } @@ -14871,7 +14871,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_write_video_frame(switch_cor for (bp = session->bugs; bp; bp = bp->next) { switch_bool_t ok = SWITCH_TRUE; - if (switch_channel_test_flag(session->channel, CF_PAUSE_BUGS) && !switch_core_media_bug_test_flag(bp, SMBF_NO_PAUSE)) { + if (switch_core_media_bug_test_flag(bp, SMBF_PAUSE) || (switch_channel_test_flag(session->channel, CF_PAUSE_BUGS) && !switch_core_media_bug_test_flag(bp, SMBF_NO_PAUSE))) { continue; } @@ -15252,7 +15252,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_video_frame(switch_core for (bp = session->bugs; bp; bp = bp->next) { switch_bool_t ok = SWITCH_TRUE; - if (switch_channel_test_flag(session->channel, CF_PAUSE_BUGS) && !switch_core_media_bug_test_flag(bp, SMBF_NO_PAUSE)) { + if (switch_core_media_bug_test_flag(bp, SMBF_PAUSE) || (switch_channel_test_flag(session->channel, CF_PAUSE_BUGS) && !switch_core_media_bug_test_flag(bp, SMBF_NO_PAUSE))) { continue; } @@ -15516,7 +15516,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_text_frame(switch_core_ for (bp = session->bugs; bp; bp = bp->next) { switch_bool_t ok = SWITCH_TRUE; - if (switch_channel_test_flag(session->channel, CF_PAUSE_BUGS) && !switch_core_media_bug_test_flag(bp, SMBF_NO_PAUSE)) { + if (switch_core_media_bug_test_flag(bp, SMBF_PAUSE) || (switch_channel_test_flag(session->channel, CF_PAUSE_BUGS) && !switch_core_media_bug_test_flag(bp, SMBF_NO_PAUSE))) { continue; } @@ -16199,7 +16199,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_write_frame(switch_core_sess continue; } - if (switch_channel_test_flag(session->channel, CF_PAUSE_BUGS) && !switch_core_media_bug_test_flag(bp, SMBF_NO_PAUSE)) { + if (switch_core_media_bug_test_flag(bp, SMBF_PAUSE) || (switch_channel_test_flag(session->channel, CF_PAUSE_BUGS) && !switch_core_media_bug_test_flag(bp, SMBF_NO_PAUSE))) { continue; } diff --git a/src/switch_ivr_async.c b/src/switch_ivr_async.c index 953d49ed7d..bcf5f17499 100644 --- a/src/switch_ivr_async.c +++ b/src/switch_ivr_async.c @@ -1869,6 +1869,22 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_record_session_mask(switch_core_sessi return SWITCH_STATUS_FALSE; } +SWITCH_DECLARE(switch_status_t) switch_ivr_record_session_pause(switch_core_session_t *session, const char *file, switch_bool_t on) +{ + switch_media_bug_t *bug; + switch_channel_t *channel = switch_core_session_get_channel(session); + + if ((bug = switch_channel_get_private(channel, file))) { + if (on) { + switch_core_media_bug_set_flag(bug, SMBF_PAUSE); + } else { + switch_core_media_bug_clear_flag(bug, SMBF_PAUSE); + } + return SWITCH_STATUS_SUCCESS; + } + return SWITCH_STATUS_FALSE; +} + SWITCH_DECLARE(switch_status_t) switch_ivr_stop_record_session(switch_core_session_t *session, const char *file) { switch_media_bug_t *bug; diff --git a/tests/unit/.gitignore b/tests/unit/.gitignore index b3689b97ab..a9c5b8eb8f 100644 --- a/tests/unit/.gitignore +++ b/tests/unit/.gitignore @@ -17,9 +17,12 @@ switch_core switch_core_codec switch_core_db switch_core_file +switch_core_session switch_core_video +switch_eavesdrop switch_event switch_hash +switch_ivr_async switch_ivr_originate switch_ivr_play_say switch_packetizer @@ -37,7 +40,9 @@ switch_vpx switch_xml switch_estimators switch_jitter_buffer +test_sofia .deps/ Makefile conf/*/ conf_playsay/*/ +conf_async/*/ diff --git a/tests/unit/Makefile.am b/tests/unit/Makefile.am index 10660c7dbd..9d57dbe589 100644 --- a/tests/unit/Makefile.am +++ b/tests/unit/Makefile.am @@ -2,7 +2,7 @@ include $(top_srcdir)/build/modmake.rulesam noinst_PROGRAMS = switch_event switch_hash switch_ivr_originate switch_utils switch_core switch_console switch_vpx switch_core_file \ switch_ivr_play_say switch_core_codec switch_rtp switch_xml -noinst_PROGRAMS += switch_core_video switch_core_db switch_vad switch_packetizer test_sofia switch_core_asr switch_core_session +noinst_PROGRAMS += switch_core_video switch_core_db switch_vad switch_packetizer test_sofia switch_ivr_async switch_core_asr switch_core_session AM_LDFLAGS += -avoid-version -no-undefined $(SWITCH_AM_LDFLAGS) $(openssl_LIBS) AM_LDFLAGS += $(FREESWITCH_LIBS) $(switch_builddir)/libfreeswitch.la $(CORE_LIBS) $(APR_LIBS) diff --git a/tests/unit/conf_async/freeswitch.xml b/tests/unit/conf_async/freeswitch.xml new file mode 100644 index 0000000000..3e870470ea --- /dev/null +++ b/tests/unit/conf_async/freeswitch.xml @@ -0,0 +1,47 @@ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + +
+
diff --git a/tests/unit/switch_ivr_async.c b/tests/unit/switch_ivr_async.c new file mode 100644 index 0000000000..3cf8a8a52e --- /dev/null +++ b/tests/unit/switch_ivr_async.c @@ -0,0 +1,124 @@ +/* + * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application + * Copyright (C) 2005-2020, Anthony Minessale II + * + * Version: MPL 1.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application + * + * The Initial Developer of the Original Code is + * Anthony Minessale II + * Portions created by the Initial Developer are Copyright (C) + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Chris Rienzo + * + * + * switch_ivr_async.c -- Async IVR tests + * + */ +#include +#include + +#include + +static switch_status_t partial_play_and_collect_input_callback(switch_core_session_t *session, void *input, switch_input_type_t input_type, void *data, __attribute__((unused))unsigned int len) +{ + switch_status_t status = SWITCH_STATUS_SUCCESS; + int *count = (int *)data; + + if (input_type == SWITCH_INPUT_TYPE_EVENT) { + switch_event_t *event = (switch_event_t *)input; + + if (event->event_id == SWITCH_EVENT_DETECTED_SPEECH) { + const char *speech_type = switch_event_get_header(event, "Speech-Type"); + + if (zstr(speech_type) || strcmp(speech_type, "detected-partial-speech")) { + return status; + } + + (*count)++; + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "partial events count: %d\n", *count); + + char *body = switch_event_get_body(event); + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_NOTICE, "body=[%s]\n", body); + } + } else if (input_type == SWITCH_INPUT_TYPE_DTMF) { + // never mind + } + + return status; +} + +FST_CORE_BEGIN("./conf_async") +{ + FST_SUITE_BEGIN(switch_ivr_play_async) + { + FST_SETUP_BEGIN() + { + fst_requires_module("mod_tone_stream"); + fst_requires_module("mod_sndfile"); + fst_requires_module("mod_dptools"); + fst_requires_module("mod_test"); + } + FST_SETUP_END() + + FST_TEARDOWN_BEGIN() + { + } + FST_TEARDOWN_END() + + FST_SESSION_BEGIN(session_record_pause) + { + const char *record_filename = switch_core_session_sprintf(fst_session, "%s%s%s.wav", SWITCH_GLOBAL_dirs.temp_dir, SWITCH_PATH_SEPARATOR, switch_core_session_get_uuid(fst_session)); + + switch_status_t status; + status = switch_ivr_record_session_event(fst_session, record_filename, 0, NULL, NULL); + fst_xcheck(status == SWITCH_STATUS_SUCCESS, "Expect switch_ivr_record_session() to return SWITCH_STATUS_SUCCESS"); + + status = switch_ivr_play_file(fst_session, NULL, "tone_stream://%(400,200,400,450);%(400,2000,400,450)", NULL); + fst_xcheck(status == SWITCH_STATUS_SUCCESS, "Expect switch_ivr_play_file() to return SWITCH_STATUS_SUCCESS"); + + status = switch_ivr_record_session_pause(fst_session, record_filename, SWITCH_TRUE); + fst_xcheck(status == SWITCH_STATUS_SUCCESS, "Expect switch_ivr_record_session_pause(SWITCH_TRUE) to return SWITCH_STATUS_SUCCESS"); + + switch_ivr_play_file(fst_session, NULL, "silence_stream://1000,0", NULL); + + status = switch_ivr_record_session_pause(fst_session, record_filename, SWITCH_FALSE); + fst_xcheck(status == SWITCH_STATUS_SUCCESS, "Expect switch_ivr_record_session_pause(SWITCH_FALSE) to return SWITCH_STATUS_SUCCESS"); + + status = switch_ivr_play_file(fst_session, NULL, "tone_stream://%(400,200,400,450)", NULL); + fst_xcheck(status == SWITCH_STATUS_SUCCESS, "Expect switch_ivr_play_file() to return SWITCH_STATUS_SUCCESS"); + + status = switch_ivr_stop_record_session(fst_session, record_filename); + fst_xcheck(status == SWITCH_STATUS_SUCCESS, "Expect switch_ivr_stop_record_session() to return SWITCH_STATUS_SUCCESS"); + + switch_ivr_play_file(fst_session, NULL, "silence_stream://100,0", NULL); + + fst_xcheck(switch_file_exists(record_filename, fst_pool) == SWITCH_STATUS_SUCCESS, "Expect recording file to exist"); + + unlink(record_filename); + + const char *duration_ms_str = switch_channel_get_variable(fst_channel, "record_ms"); + fst_requires(duration_ms_str != NULL); + int duration_ms = atoi(duration_ms_str); + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(fst_session), SWITCH_LOG_NOTICE, "Recording duration is %s ms\n", duration_ms_str); + fst_xcheck(duration_ms > 3500 && duration_ms < 3700, "Expect recording to be between 3500 and 3700 ms"); + } + FST_SESSION_END() + } + FST_SUITE_END() +} +FST_CORE_END() +