From 6481a0d11b869398b9fd65f467c5cb7658661bd3 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 23 Nov 2007 18:35:38 +0000 Subject: [PATCH] add RECORD_ANSWER_REQ var git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@6389 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- src/include/switch_core.h | 8 ++++++++ src/include/switch_types.h | 5 ++++- src/switch_core_media_bug.c | 9 +++++++++ src/switch_ivr_async.c | 24 +++++++++++++++++++++--- 4 files changed, 42 insertions(+), 4 deletions(-) diff --git a/src/include/switch_core.h b/src/include/switch_core.h index 34bd23fe65..c3c49eaf11 100644 --- a/src/include/switch_core.h +++ b/src/include/switch_core.h @@ -157,6 +157,14 @@ SWITCH_DECLARE(void) switch_core_media_bug_set_write_replace_frame(switch_media_ */ SWITCH_DECLARE(switch_frame_t *) switch_core_media_bug_get_read_replace_frame(switch_media_bug_t *bug); +/*! + \brief Obtain the session from a media bug + \param bug the bug to get the data from +*/ +SWITCH_DECLARE(switch_core_session_t *) switch_core_media_bug_get_session(switch_media_bug_t *bug); + +SWITCH_DECLARE(uint32_t) switch_core_media_bug_test_flag(switch_media_bug_t *bug, uint32_t flag); + /*! \brief Set a return replace frame \param bug the bug to set the frame on diff --git a/src/include/switch_types.h b/src/include/switch_types.h index 8a7537c467..d9a8a30a5e 100644 --- a/src/include/switch_types.h +++ b/src/include/switch_types.h @@ -783,6 +783,8 @@ SMBF_READ_STREAM - Include the Read Stream SMBF_WRITE_STREAM - Include the Write Stream SMBF_WRITE_REPLACE - Replace the Write Stream SMBF_READ_REPLACE - Replace the Read Stream +SMBF_STEREO - Record in stereo +SMBF_ANSWER_RECORD_REQ - Don't record until the channel is answered */ typedef enum { @@ -791,7 +793,8 @@ typedef enum { SMBF_WRITE_STREAM = (1 << 1), SMBF_WRITE_REPLACE = (1 << 2), SMBF_READ_REPLACE = (1 << 3), - SMBF_STEREO = (1 << 4) + SMBF_STEREO = (1 << 4), + SMBF_RECORD_ANSWER_REQ = (1 << 5) } switch_media_bug_flag_t; /*! diff --git a/src/switch_core_media_bug.c b/src/switch_core_media_bug.c index 5c196925bb..ff443ffce4 100644 --- a/src/switch_core_media_bug.c +++ b/src/switch_core_media_bug.c @@ -40,6 +40,15 @@ static void switch_core_media_bug_destroy(switch_media_bug_t *bug) switch_buffer_destroy(&bug->raw_write_buffer); } +SWITCH_DECLARE(uint32_t) switch_core_media_bug_test_flag(switch_media_bug_t *bug, uint32_t flag) +{ + return switch_test_flag(bug, flag); +} + +SWITCH_DECLARE(switch_core_session_t *) switch_core_media_bug_get_session(switch_media_bug_t *bug) +{ + return bug->session; +} SWITCH_DECLARE(switch_frame_t *) switch_core_media_bug_get_write_replace_frame(switch_media_bug_t *bug) { diff --git a/src/switch_ivr_async.c b/src/switch_ivr_async.c index cd2b2db3fe..f3bf5212fd 100644 --- a/src/switch_ivr_async.c +++ b/src/switch_ivr_async.c @@ -262,10 +262,24 @@ static switch_bool_t record_callback(switch_media_bug_t *bug, void *user_data, s case SWITCH_ABC_TYPE_READ: if (fh) { switch_size_t len; - + switch_core_session_t *session; + switch_channel_t *channel; + + session = switch_core_media_bug_get_session(bug); + assert(session != NULL); + channel = switch_core_session_get_channel(session); + assert(channel != NULL); + if (switch_core_media_bug_read(bug, &frame) == SWITCH_STATUS_SUCCESS) { - len = (switch_size_t) frame.datalen / 2; - switch_core_file_write(fh, frame.data, &len); + int doit = 1; + if (!switch_channel_test_flag(channel, CF_ANSWERED) && switch_core_media_bug_test_flag(bug, SMBF_RECORD_ANSWER_REQ)) { + doit = 0; + } + + if (doit) { + len = (switch_size_t) frame.datalen / 2; + switch_core_file_write(fh, frame.data, &len); + } } } break; @@ -327,6 +341,10 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_record_session(switch_core_session_t flags |= SMBF_STEREO; channels = 2; } + + if ((p = switch_channel_get_variable(channel, "RECORD_ANSWER_REQ")) && switch_true(p)) { + flags |= SMBF_RECORD_ANSWER_REQ; + } fh->channels = channels; fh->samplerate = read_codec->implementation->actual_samples_per_second;