]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
possible fix for FSCORE-221
authorAnthony Minessale <anthony.minessale@gmail.com>
Wed, 12 Nov 2008 11:44:13 +0000 (11:44 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Wed, 12 Nov 2008 11:44:13 +0000 (11:44 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@10346 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/include/switch_core.h
src/switch_core_media_bug.c
src/switch_core_session.c
src/switch_ivr_async.c

index bf5730a90a385714ddfb83fcaa41d27b430c8f7a..d2bd2c819fff4ecaa3944a79793b8c6b5dfbc170 100644 (file)
@@ -212,6 +212,9 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_bug_remove_all(_In_ switch_cor
 */
 SWITCH_DECLARE(switch_status_t) switch_core_media_bug_read(_In_ switch_media_bug_t *bug, _In_ switch_frame_t *frame);
 
+SWITCH_DECLARE(void) switch_core_media_bug_flush(_In_ switch_media_bug_t *bug);
+SWITCH_DECLARE(switch_status_t) switch_core_media_bug_flush_all(_In_ switch_core_session_t *session);
+
 ///\}
 
 ///\defgroup pa1 Port Allocation
index d2121c214594df80d0b178fbd5d6618697f7bff2..c6fc06cd5ca8ab4b1686d550f867113c25b2b160 100644 (file)
@@ -76,6 +76,12 @@ SWITCH_DECLARE(void *) switch_core_media_bug_get_user_data(switch_media_bug_t *b
        return bug->user_data;
 }
 
+SWITCH_DECLARE(void) switch_core_media_bug_flush(switch_media_bug_t *bug)
+{
+       switch_buffer_zero(bug->raw_read_buffer);
+       switch_buffer_zero(bug->raw_write_buffer);
+}
+
 SWITCH_DECLARE(switch_status_t) switch_core_media_bug_read(switch_media_bug_t *bug, switch_frame_t *frame)
 {
        uint32_t bytes = 0;
@@ -265,9 +271,27 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_bug_add(switch_core_session_t
 }
 
 
+SWITCH_DECLARE(switch_status_t) switch_core_media_bug_flush_all(switch_core_session_t *session)
+{
+       switch_media_bug_t *bp;
+
+       if (session->bugs) {
+               switch_thread_rwlock_wrlock(session->bug_rwlock);
+               for (bp = session->bugs; bp; bp = bp->next) {
+                       switch_core_media_bug_flush(bp);
+               }
+               switch_thread_rwlock_unlock(session->bug_rwlock);
+               return SWITCH_STATUS_SUCCESS;
+       }
+
+       return SWITCH_STATUS_FALSE;
+}
+
+
 SWITCH_DECLARE(switch_status_t) switch_core_media_bug_remove_all(switch_core_session_t *session)
 {
        switch_media_bug_t *bp;
+       switch_status_t status = SWITCH_STATUS_FALSE;
 
        if (session->bugs) {
                switch_thread_rwlock_wrlock(session->bug_rwlock);
@@ -285,7 +309,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_bug_remove_all(switch_core_ses
                }
                session->bugs = NULL;
                switch_thread_rwlock_unlock(session->bug_rwlock);
-               return SWITCH_STATUS_SUCCESS;
+               status = SWITCH_STATUS_SUCCESS;
        }
 
        if (session->bug_codec.implementation) {
@@ -293,7 +317,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_bug_remove_all(switch_core_ses
                memset(&session->bug_codec, 0, sizeof(session->bug_codec));
        }
 
-       return SWITCH_STATUS_FALSE;
+       return status;
 }
 
 SWITCH_DECLARE(switch_status_t) switch_core_media_bug_close(switch_media_bug_t **bug)
index a34826aa99eef66a99646171fd2ebd9c9b84441d..6449444f9dc6eada991cdff11622ba47dcd99bc1 100644 (file)
@@ -742,6 +742,7 @@ SWITCH_DECLARE(void) switch_core_session_reset(switch_core_session_t *session, s
        switch_clear_flag(session, SSF_WARN_TRANSCODE);
        switch_ivr_deactivate_unicast(session);
        switch_channel_clear_flag(channel, CF_BREAK);
+       switch_core_media_bug_flush_all(session);
 }
 
 
index 49e238ed57754d1b064ea88eea363c1eff1ba06d..5eb053c43293c1303e6776e3bbf20535401f8bd8 100644 (file)
@@ -913,22 +913,18 @@ typedef struct {
 static switch_bool_t inband_dtmf_callback(switch_media_bug_t *bug, void *user_data, switch_abc_type_t type)
 {
        switch_inband_dtmf_t *pvt = (switch_inband_dtmf_t *) user_data;
-       uint8_t data[SWITCH_RECOMMENDED_BUFFER_SIZE];
-       switch_frame_t frame = { 0 };
+       switch_frame_t *frame = NULL;
        char digit_str[80];
        switch_channel_t *channel = switch_core_session_get_channel(pvt->session);
 
-       frame.data = data;
-       frame.buflen = SWITCH_RECOMMENDED_BUFFER_SIZE;
-
        switch (type) {
        case SWITCH_ABC_TYPE_INIT:
                break;
        case SWITCH_ABC_TYPE_CLOSE:
                break;
-       case SWITCH_ABC_TYPE_READ:
-               if (switch_core_media_bug_read(bug, &frame) == SWITCH_STATUS_SUCCESS) {
-                       teletone_dtmf_detect(&pvt->dtmf_detect, frame.data, frame.samples);
+       case SWITCH_ABC_TYPE_READ_REPLACE:
+               if ((frame = switch_core_media_bug_get_read_replace_frame(bug))) {
+                       teletone_dtmf_detect(&pvt->dtmf_detect, frame->data, frame->samples);
                        teletone_dtmf_get(&pvt->dtmf_detect, digit_str, sizeof(digit_str));
                        if (digit_str[0]) {
                                char *p = digit_str;
@@ -941,6 +937,7 @@ static switch_bool_t inband_dtmf_callback(switch_media_bug_t *bug, void *user_da
                                }
                                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "DTMF DETECTED: [%s]\n", digit_str);
                        }
+                       switch_core_media_bug_set_read_replace_frame(bug, frame);
                }
                break;
        case SWITCH_ABC_TYPE_WRITE:
@@ -984,7 +981,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_inband_dtmf_session(switch_core_sessi
 
        switch_channel_pre_answer(channel);
 
-       if ((status = switch_core_media_bug_add(session, inband_dtmf_callback, pvt, 0, SMBF_READ_STREAM, &bug)) != SWITCH_STATUS_SUCCESS) {
+       if ((status = switch_core_media_bug_add(session, inband_dtmf_callback, pvt, 0, SMBF_READ_REPLACE, &bug)) != SWITCH_STATUS_SUCCESS) {
                return status;
        }