]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
update
authorAnthony Minessale <anthony.minessale@gmail.com>
Wed, 13 Jun 2007 03:09:53 +0000 (03:09 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Wed, 13 Jun 2007 03:09:53 +0000 (03:09 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@5318 d0543943-73ff-0310-b7d9-9358b9ac24b2

build/modules.conf.in
src/include/private/switch_core_pvt.h
src/include/switch_core.h
src/include/switch_types.h
src/mod/applications/mod_soundtouch/mod_soundtouch.cpp
src/switch_core_io.c
src/switch_core_media_bug.c

index 73adea54c30adbfe8b26508ec66a38155ed9f71e..5062529a60d7d0725d665fed0682ad6cb60a7a9a 100644 (file)
@@ -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
index c10f7d253c74c157ef6532e678a87b12f25219ac..9211a4d3d09a7e65662a0f96fb4069a30f69e806 100644 (file)
@@ -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;
index 79d9e3c0672b82a747198a60859d3002b582e577..fa08685b89e03d0320467913f04a37207ff224b4 100644 (file)
@@ -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
index bcd26773bf6f9983e6895de4783070506ca5e933..33013e31b87d4f9c7b50c3d7381ddc11a89bff43 100644 (file)
@@ -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 {
 <pre>
 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
 </pre>
 */
 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;
 
 /*!
index d0248f50706ad30e71bf616e9b54c8ca50159852..162d165a0a147e7e246f88e163eb6048a89e1219 100644 (file)
@@ -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);
             
             
         }
index 2462087bbcac25d7d1e915dfbe2ae395ffcfba15..0eb56fa349e0a09e3a0119ce0d0d0a68d008311c 100644 (file)
@@ -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;
                                                }
                                        }
                                }
index b61557328000097b3031d13e934fb0f4adc1e3e4..72b468db19549d96304834b3e33e88bc6a0ff19f 100644 (file)
@@ -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;
        }