diff --git a/src/include/switch_types.h b/src/include/switch_types.h index 193908ef14..7aba5f10af 100644 --- a/src/include/switch_types.h +++ b/src/include/switch_types.h @@ -1120,7 +1120,7 @@ typedef enum { SMBF_READ_REPLACE = (1 << 3), SMBF_READ_PING = (1 << 4), SMBF_STEREO = (1 << 5), - SMBF_RECORD_ANSWER_REQ = (1 << 6), + SMBF_ANSWER_REQ = (1 << 6), SMBF_THREAD_LOCK = (1 << 7) } switch_media_bug_flag_enum_t; typedef uint32_t switch_media_bug_flag_t; diff --git a/src/switch_core_io.c b/src/switch_core_io.c index e2d002b0ec..bbf661152e 100644 --- a/src/switch_core_io.c +++ b/src/switch_core_io.c @@ -334,6 +334,10 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_frame(switch_core_sessi switch_bool_t ok = SWITCH_TRUE; switch_thread_rwlock_rdlock(session->bug_rwlock); for (bp = session->bugs; bp; bp = bp->next) { + if (!switch_channel_test_flag(session->channel, CF_ANSWERED) && switch_core_media_bug_test_flag(bp, SMBF_ANSWER_REQ)) { + continue; + } + if (bp->ready && switch_test_flag(bp, SMBF_READ_STREAM)) { switch_mutex_lock(bp->read_mutex); switch_buffer_write(bp->raw_read_buffer, read_frame->data, read_frame->datalen); @@ -496,6 +500,10 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_frame(switch_core_sessi switch_bool_t ok = SWITCH_TRUE; switch_thread_rwlock_rdlock(session->bug_rwlock); for (bp = session->bugs; bp; bp = bp->next) { + if (!switch_channel_test_flag(session->channel, CF_ANSWERED) && switch_core_media_bug_test_flag(bp, SMBF_ANSWER_REQ)) { + continue; + } + if (bp->ready && switch_test_flag(bp, SMBF_READ_PING)) { switch_mutex_lock(bp->read_mutex); if (bp->callback) { @@ -760,6 +768,11 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_write_frame(switch_core_sess if (!bp->ready) { continue; } + + if (!switch_channel_test_flag(session->channel, CF_ANSWERED) && switch_core_media_bug_test_flag(bp, SMBF_ANSWER_REQ)) { + continue; + } + if (switch_test_flag(bp, SMBF_WRITE_STREAM)) { switch_mutex_lock(bp->write_mutex); diff --git a/src/switch_core_media_bug.c b/src/switch_core_media_bug.c index dbed565ba1..014abb2c0f 100644 --- a/src/switch_core_media_bug.c +++ b/src/switch_core_media_bug.c @@ -235,7 +235,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_bug_add(switch_core_session_t switch_size_t bytes; switch_codec_implementation_t read_impl = {0}; switch_codec_implementation_t write_impl = {0}; - + const char *p; if (!switch_channel_media_ready(session->channel)) { if (switch_channel_pre_answer(session->channel) != SWITCH_STATUS_SUCCESS) { @@ -248,6 +248,11 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_bug_add(switch_core_session_t *new_bug = NULL; + + if ((p = switch_channel_get_variable(session->channel, "media_bug_answer_req")) && switch_true(p)) { + flags |= SMBF_ANSWER_REQ; + } + #if 0 if (flags & SMBF_WRITE_REPLACE) { switch_thread_rwlock_wrlock(session->bug_rwlock); diff --git a/src/switch_ivr_async.c b/src/switch_ivr_async.c index 43b74b59ec..945ec06a5f 100644 --- a/src/switch_ivr_async.c +++ b/src/switch_ivr_async.c @@ -459,20 +459,18 @@ static switch_bool_t record_callback(switch_media_bug_t *bug, void *user_data, s } if (rh->fh) { - if (switch_channel_test_flag(channel, CF_ANSWERED) || !switch_core_media_bug_test_flag(bug, SMBF_RECORD_ANSWER_REQ)) { - switch_size_t len; - uint8_t data[SWITCH_RECOMMENDED_BUFFER_SIZE]; - switch_frame_t frame = { 0 }; + switch_size_t len; + uint8_t data[SWITCH_RECOMMENDED_BUFFER_SIZE]; + switch_frame_t frame = { 0 }; + frame.data = data; + frame.buflen = SWITCH_RECOMMENDED_BUFFER_SIZE; - frame.data = data; - frame.buflen = SWITCH_RECOMMENDED_BUFFER_SIZE; - - while (switch_core_media_bug_read(bug, &frame, SWITCH_TRUE) == SWITCH_STATUS_SUCCESS && !switch_test_flag((&frame), SFF_CNG)) { - len = (switch_size_t) frame.datalen / 2; - if (len) switch_core_file_write(rh->fh, data, &len); - } + while (switch_core_media_bug_read(bug, &frame, SWITCH_TRUE) == SWITCH_STATUS_SUCCESS && !switch_test_flag((&frame), SFF_CNG)) { + len = (switch_size_t) frame.datalen / 2; + if (len) switch_core_file_write(rh->fh, data, &len); } + switch_core_file_close(rh->fh); if (rh->fh->samples_out < read_impl.samples_per_second * 3) { @@ -493,12 +491,11 @@ static switch_bool_t record_callback(switch_media_bug_t *bug, void *user_data, s frame.data = data; frame.buflen = SWITCH_RECOMMENDED_BUFFER_SIZE; - if (switch_channel_test_flag(channel, CF_ANSWERED) || !switch_core_media_bug_test_flag(bug, SMBF_RECORD_ANSWER_REQ)) { - while (switch_core_media_bug_read(bug, &frame, SWITCH_TRUE) == SWITCH_STATUS_SUCCESS && !switch_test_flag((&frame), SFF_CNG)) { - len = (switch_size_t) frame.datalen / 2; - if (len) switch_core_file_write(rh->fh, data, &len); - } + while (switch_core_media_bug_read(bug, &frame, SWITCH_TRUE) == SWITCH_STATUS_SUCCESS && !switch_test_flag((&frame), SFF_CNG)) { + len = (switch_size_t) frame.datalen / 2; + if (len) switch_core_file_write(rh->fh, data, &len); } + } break; case SWITCH_ABC_TYPE_WRITE: @@ -911,7 +908,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_record_session(switch_core_session_t } if ((p = switch_channel_get_variable(channel, "RECORD_ANSWER_REQ")) && switch_true(p)) { - flags |= SMBF_RECORD_ANSWER_REQ; + flags |= SMBF_ANSWER_REQ; }