From f1bede824c723d586969fe65ab426df607fa6bab Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 13 Jun 2007 03:09:53 +0000 Subject: [PATCH] update git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@5318 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- build/modules.conf.in | 1 + src/include/private/switch_core_pvt.h | 6 ++- src/include/switch_core.h | 17 ++++++- src/include/switch_types.h | 7 ++- .../mod_soundtouch/mod_soundtouch.cpp | 4 +- src/switch_core_io.c | 48 ++++++++++++------- src/switch_core_media_bug.c | 30 ++++++++++-- 7 files changed, 83 insertions(+), 30 deletions(-) diff --git a/build/modules.conf.in b/build/modules.conf.in index 73adea54c3..5062529a60 100644 --- a/build/modules.conf.in +++ b/build/modules.conf.in @@ -8,6 +8,7 @@ applications/mod_echo applications/mod_enum #applications/mod_ivrtest #applications/mod_park +#applications/mod_soundtouch applications/mod_playback #applications/mod_rss #applications/mod_skel diff --git a/src/include/private/switch_core_pvt.h b/src/include/private/switch_core_pvt.h index c10f7d253c..9211a4d3d0 100644 --- a/src/include/private/switch_core_pvt.h +++ b/src/include/private/switch_core_pvt.h @@ -127,8 +127,10 @@ struct switch_core_session { struct switch_media_bug { switch_buffer_t *raw_write_buffer; switch_buffer_t *raw_read_buffer; - switch_frame_t *replace_frame_in; - switch_frame_t *replace_frame_out; + switch_frame_t *read_replace_frame_in; + switch_frame_t *read_replace_frame_out; + switch_frame_t *write_replace_frame_in; + switch_frame_t *write_replace_frame_out; switch_media_bug_callback_t callback; switch_mutex_t *read_mutex; switch_mutex_t *write_mutex; diff --git a/src/include/switch_core.h b/src/include/switch_core.h index 79d9e3c067..fa08685b89 100644 --- a/src/include/switch_core.h +++ b/src/include/switch_core.h @@ -142,14 +142,27 @@ SWITCH_DECLARE(void *) switch_core_media_bug_get_user_data(switch_media_bug_t *b \brief Obtain a replace frame from a media bug \param bug the bug to get the data from */ -SWITCH_DECLARE(switch_frame_t *) switch_core_media_bug_get_replace_frame(switch_media_bug_t *bug); +SWITCH_DECLARE(switch_frame_t *) switch_core_media_bug_get_write_replace_frame(switch_media_bug_t *bug); /*! \brief Set a return replace frame \param bug the bug to set the frame on \param frame the frame to set */ -SWITCH_DECLARE(void) switch_core_media_bug_set_replace_frame(switch_media_bug_t *bug, switch_frame_t *frame); +SWITCH_DECLARE(void) switch_core_media_bug_set_write_replace_frame(switch_media_bug_t *bug, switch_frame_t *frame); + +/*! + \brief Obtain a replace frame from a media bug + \param bug the bug to get the data from +*/ +SWITCH_DECLARE(switch_frame_t *) switch_core_media_bug_get_read_replace_frame(switch_media_bug_t *bug); + +/*! + \brief Set a return replace frame + \param bug the bug to set the frame on + \param frame the frame to set +*/ +SWITCH_DECLARE(void) switch_core_media_bug_set_read_replace_frame(switch_media_bug_t *bug, switch_frame_t *frame); /*! \brief Remove a media bug from the session diff --git a/src/include/switch_types.h b/src/include/switch_types.h index bcd26773bf..33013e31b8 100644 --- a/src/include/switch_types.h +++ b/src/include/switch_types.h @@ -196,6 +196,7 @@ typedef enum { SWITCH_ABC_TYPE_READ, SWITCH_ABC_TYPE_WRITE, SWITCH_ABC_TYPE_WRITE_REPLACE, + SWITCH_ABC_TYPE_READ_REPLACE, SWITCH_ABC_TYPE_CLOSE } switch_abc_type_t; @@ -742,14 +743,16 @@ typedef enum {
 SMBF_READ_STREAM - Include the Read Stream
 SMBF_WRITE_STREAM - Include the Write Stream
-SMBF_WRITE_STREAM - Replace the Write Stream
+SMBF_WRITE_REPLACE - Replace the Write Stream
+SMBF_READ_REPLACE - Replace the Read Stream
 
*/ typedef enum { SMBF_BOTH = 0, SMBF_READ_STREAM = (1 << 0), SMBF_WRITE_STREAM = (1 << 1), - SMBF_WRITE_REPLACE = (1 << 2) + SMBF_WRITE_REPLACE = (1 << 2), + SMBF_READ_REPLACE = (1 << 3) } switch_media_bug_flag_t; /*! diff --git a/src/mod/applications/mod_soundtouch/mod_soundtouch.cpp b/src/mod/applications/mod_soundtouch/mod_soundtouch.cpp index d0248f5070..162d165a0a 100644 --- a/src/mod/applications/mod_soundtouch/mod_soundtouch.cpp +++ b/src/mod/applications/mod_soundtouch/mod_soundtouch.cpp @@ -215,7 +215,7 @@ static switch_bool_t soundtouch_callback(switch_media_bug_t *bug, void *user_dat assert(sth != NULL); assert(sth->st != NULL); - frame = switch_core_media_bug_get_replace_frame(bug); + frame = switch_core_media_bug_get_write_replace_frame(bug); sth->st->putSamples((SAMPLETYPE *)frame->data, frame->samples); if (sth->st->numSamples() >= frame->samples * 2) { @@ -225,7 +225,7 @@ static switch_bool_t soundtouch_callback(switch_media_bug_t *bug, void *user_dat memset(frame->data, 0, frame->datalen); } - switch_core_media_bug_set_replace_frame(bug, frame); + switch_core_media_bug_set_write_replace_frame(bug, frame); } diff --git a/src/switch_core_io.c b/src/switch_core_io.c index 2462087bbc..0eb56fa349 100644 --- a/src/switch_core_io.c +++ b/src/switch_core_io.c @@ -225,7 +225,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_frame(switch_core_sessi if (session->bugs) { switch_media_bug_t *bp, *dp, *last = NULL; - + switch_bool_t ok = SWITCH_TRUE; switch_thread_rwlock_rdlock(session->bug_rwlock); for (bp = session->bugs; bp; bp = bp->next) { if (bp->ready && switch_test_flag(bp, SMBF_READ_STREAM)) { @@ -233,23 +233,35 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_frame(switch_core_sessi switch_buffer_write(bp->raw_read_buffer, read_frame->data, read_frame->datalen); if (bp->callback) { if (bp->callback(bp, bp->user_data, SWITCH_ABC_TYPE_READ) == SWITCH_FALSE || (bp->stop_time && bp->stop_time >= time(NULL))) { - bp->ready = 0; - if (last) { - last->next = bp->next; - } else { - session->bugs = bp->next; - } - switch_mutex_unlock(bp->read_mutex); - dp = bp; - bp = last; - switch_core_media_bug_close(&dp); - if (!bp) { - break; - } - continue; + ok = SWITCH_FALSE; } } switch_mutex_unlock(bp->read_mutex); + } else if (switch_test_flag(bp, SMBF_READ_REPLACE)) { + do_bugs = 0; + if (bp->callback) { + bp->read_replace_frame_in = read_frame; + bp->read_replace_frame_out = NULL; + if ((ok = bp->callback(bp, bp->user_data, SWITCH_ABC_TYPE_READ_REPLACE)) == SWITCH_TRUE) { + read_frame = bp->read_replace_frame_out; + } + } + } + + if (ok == SWITCH_FALSE) { + bp->ready = 0; + if (last) { + last->next = bp->next; + } else { + session->bugs = bp->next; + } + dp = bp; + bp = last; + switch_core_media_bug_close(&dp); + if (!bp) { + break; + } + continue; } last = bp; } @@ -497,10 +509,10 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_write_frame(switch_core_sess } else if (switch_test_flag(bp, SMBF_WRITE_REPLACE)) { do_bugs = 0; if (bp->callback) { - bp->replace_frame_in = write_frame; - bp->replace_frame_out = NULL; + bp->write_replace_frame_in = write_frame; + bp->write_replace_frame_out = NULL; if ((ok = bp->callback(bp, bp->user_data, SWITCH_ABC_TYPE_WRITE_REPLACE)) == SWITCH_TRUE) { - write_frame = bp->replace_frame_out; + write_frame = bp->write_replace_frame_out; } } } diff --git a/src/switch_core_media_bug.c b/src/switch_core_media_bug.c index b615573280..72b468db19 100644 --- a/src/switch_core_media_bug.c +++ b/src/switch_core_media_bug.c @@ -41,14 +41,24 @@ static void switch_core_media_bug_destroy(switch_media_bug_t *bug) } -SWITCH_DECLARE(switch_frame_t *) switch_core_media_bug_get_replace_frame(switch_media_bug_t *bug) +SWITCH_DECLARE(switch_frame_t *) switch_core_media_bug_get_write_replace_frame(switch_media_bug_t *bug) { - return bug->replace_frame_in; + return bug->write_replace_frame_in; } -SWITCH_DECLARE(void) switch_core_media_bug_set_replace_frame(switch_media_bug_t *bug, switch_frame_t *frame) +SWITCH_DECLARE(void) switch_core_media_bug_set_write_replace_frame(switch_media_bug_t *bug, switch_frame_t *frame) { - bug->replace_frame_out = frame; + bug->write_replace_frame_out = frame; +} + +SWITCH_DECLARE(switch_frame_t *) switch_core_media_bug_get_read_replace_frame(switch_media_bug_t *bug) +{ + return bug->read_replace_frame_in; +} + +SWITCH_DECLARE(void) switch_core_media_bug_set_read_replace_frame(switch_media_bug_t *bug, switch_frame_t *frame) +{ + bug->read_replace_frame_out = frame; } SWITCH_DECLARE(void *) switch_core_media_bug_get_user_data(switch_media_bug_t *bug) @@ -161,6 +171,18 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_bug_add(switch_core_session_t switch_thread_rwlock_unlock(session->bug_rwlock); } + if (flags & SMBF_READ_REPLACE) { + switch_thread_rwlock_wrlock(session->bug_rwlock); + for (bp = session->bugs; bp; bp = bp->next) { + if (switch_test_flag(bp, SMBF_READ_REPLACE)) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Only one bug of this type allowed!\n"); + switch_thread_rwlock_unlock(session->bug_rwlock); + return SWITCH_STATUS_GENERR; + } + } + switch_thread_rwlock_unlock(session->bug_rwlock); + } + if (!(bug = switch_core_session_alloc(session, sizeof(*bug)))) { return SWITCH_STATUS_MEMERR; }