]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
fix queued dtmf on channels with no timer issue
authorAnthony Minessale <anthm@freeswitch.org>
Mon, 14 Nov 2011 18:37:45 +0000 (12:37 -0600)
committerAnthony Minessale <anthm@freeswitch.org>
Mon, 14 Nov 2011 18:37:45 +0000 (12:37 -0600)
src/switch_channel.c
src/switch_core_io.c
src/switch_rtp.c

index 13392da933c6f87a56150af54a201e9fe67900a1..2a77ac99761f155e07ecb9655505e401e6d43411 100644 (file)
@@ -380,18 +380,23 @@ SWITCH_DECLARE(switch_status_t) switch_channel_queue_dtmf(switch_channel_t *chan
                char str[2] = "";
 
                str[0] = new_dtmf.digit;
+
+               if (new_dtmf.digit != 'w' && new_dtmf.digit != 'W') {
+                       if (new_dtmf.duration > switch_core_max_dtmf_duration(0)) {
+                               switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(channel), SWITCH_LOG_DEBUG1, "%s EXCESSIVE DTMF DIGIT [%s] LEN [%d]\n",
+                                                                 switch_channel_get_name(channel), str, new_dtmf.duration);
+                               new_dtmf.duration = switch_core_max_dtmf_duration(0);
+                       } else if (new_dtmf.duration < switch_core_min_dtmf_duration(0)) {
+                               switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(channel), SWITCH_LOG_DEBUG1, "%s SHORT DTMF DIGIT [%s] LEN [%d]\n",
+                                                                 switch_channel_get_name(channel), str, new_dtmf.duration);
+                               new_dtmf.duration = switch_core_min_dtmf_duration(0);
+                       } 
+               }
                
-               if (new_dtmf.duration > switch_core_max_dtmf_duration(0)) {
-                       switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(channel), SWITCH_LOG_DEBUG1, "%s EXCESSIVE DTMF DIGIT [%s] LEN [%d]\n",
-                                                         switch_channel_get_name(channel), str, new_dtmf.duration);
-                       new_dtmf.duration = switch_core_max_dtmf_duration(0);
-               } else if (new_dtmf.duration < switch_core_min_dtmf_duration(0)) {
-                       switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(channel), SWITCH_LOG_DEBUG1, "%s SHORT DTMF DIGIT [%s] LEN [%d]\n",
-                                                         switch_channel_get_name(channel), str, new_dtmf.duration);
-                       new_dtmf.duration = switch_core_min_dtmf_duration(0);
-               } else if (!new_dtmf.duration) {
+               if (!new_dtmf.duration) {
                        new_dtmf.duration = switch_core_default_dtmf_duration(0);
                }
+               
 
                switch_zmalloc(dt, sizeof(*dt));
                *dt = new_dtmf;
index d8a519a294fd0430de2b7f0ccd9b9421db20e6ff..7d19e95f718aba3d5c1dc275c9ed5594ee7caba7 100644 (file)
@@ -1341,19 +1341,22 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_send_dtmf(switch_core_sessio
        switch_assert(dtmf);
 
        new_dtmf = *dtmf;
-
-       if (new_dtmf.duration > switch_core_max_dtmf_duration(0)) {
-               switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "%s EXCESSIVE DTMF DIGIT [%c] LEN [%d]\n",
-                                                 switch_channel_get_name(session->channel), new_dtmf.digit, new_dtmf.duration);
-               new_dtmf.duration = switch_core_max_dtmf_duration(0);
-       } else if (new_dtmf.duration < switch_core_min_dtmf_duration(0)) {
-               switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "%s SHORT DTMF DIGIT [%c] LEN [%d]\n",
+       
+       if (new_dtmf.digit != 'w' && new_dtmf.digit != 'W') {
+               if (new_dtmf.duration > switch_core_max_dtmf_duration(0)) {
+                       switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "%s EXCESSIVE DTMF DIGIT [%c] LEN [%d]\n",
+                                                         switch_channel_get_name(session->channel), new_dtmf.digit, new_dtmf.duration);
+                       new_dtmf.duration = switch_core_max_dtmf_duration(0);
+               } else if (new_dtmf.duration < switch_core_min_dtmf_duration(0)) {
+                       switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "%s SHORT DTMF DIGIT [%c] LEN [%d]\n",
                                                  switch_channel_get_name(session->channel), new_dtmf.digit, new_dtmf.duration);
-               new_dtmf.duration = switch_core_min_dtmf_duration(0);
-       } else if (!new_dtmf.duration) {
-               new_dtmf.duration = switch_core_default_dtmf_duration(0);
+                       new_dtmf.duration = switch_core_min_dtmf_duration(0);
+               } 
        }
 
+       if (!new_dtmf.duration) {
+               new_dtmf.duration = switch_core_default_dtmf_duration(0);
+       }
 
        if (!switch_test_flag(dtmf, DTMF_FLAG_SKIP_PROCESS)) {  
                for (ptr = session->event_hooks.send_dtmf; ptr; ptr = ptr->next) {
@@ -1444,18 +1447,23 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_send_dtmf_string(switch_core
                for (p = argv[i]; p && *p; p++) {
                        if (is_dtmf(*p)) {
                                dtmf.digit = *p;
-                               
-                               if (dtmf.duration > switch_core_max_dtmf_duration(0)) {
-                                       switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "%s EXCESSIVE DTMF DIGIT [%c] LEN [%d]\n",
-                                                                         switch_channel_get_name(session->channel), dtmf.digit, dtmf.duration);
-                                       dtmf.duration = switch_core_max_dtmf_duration(0);
-                               } else if (dtmf.duration < switch_core_min_dtmf_duration(0)) {
-                                       switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "%s SHORT DTMF DIGIT [%c] LEN [%d]\n",
-                                                                         switch_channel_get_name(session->channel), dtmf.digit, dtmf.duration);
-                                       dtmf.duration = switch_core_min_dtmf_duration(0);
-                               } else if (!dtmf.duration) {
+
+                               if (dtmf.digit != 'w' && dtmf.digit != 'W') {
+                                       if (dtmf.duration > switch_core_max_dtmf_duration(0)) {
+                                               switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "%s EXCESSIVE DTMF DIGIT [%c] LEN [%d]\n",
+                                                                                 switch_channel_get_name(session->channel), dtmf.digit, dtmf.duration);
+                                               dtmf.duration = switch_core_max_dtmf_duration(0);
+                                       } else if (dtmf.duration < switch_core_min_dtmf_duration(0)) {
+                                               switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "%s SHORT DTMF DIGIT [%c] LEN [%d]\n",
+                                                                                 switch_channel_get_name(session->channel), dtmf.digit, dtmf.duration);
+                                               dtmf.duration = switch_core_min_dtmf_duration(0);
+                                       } 
+                               }
+
+                               if (!dtmf.duration) {
                                        dtmf.duration = switch_core_default_dtmf_duration(0);
                                }
+                               
 
                                if (switch_core_session_send_dtmf(session, &dtmf) == SWITCH_STATUS_SUCCESS) {
                                        switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s send dtmf\ndigit=%c ms=%u samples=%u\n",
index 0ea3a978b049c84e415b554f3f50b5e30dfb5cc8..38e4019d5666229092a9c83c521433a34293bbd5 100644 (file)
@@ -185,7 +185,7 @@ struct switch_rtp {
        uint32_t last_read_ts;
        uint32_t last_cng_ts;
        uint32_t last_write_samplecount;
-       uint32_t next_write_samplecount;
+       uint32_t delay_samples;
        uint32_t max_next_write_samplecount;
        uint32_t queue_delay;
        switch_time_t last_write_timestamp;
@@ -2318,7 +2318,6 @@ static void do_2833(switch_rtp_t *rtp_session, switch_core_session_t *session)
 
                        rtp_session->dtmf_data.out_digit_dur = 0;
                        set_dtmf_delay(rtp_session, 40, 500);
-                       
                        return;
                }
        }
@@ -2327,16 +2326,23 @@ static void do_2833(switch_rtp_t *rtp_session, switch_core_session_t *session)
                void *pop;
 
                if (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_USE_TIMER)) {
-                       if (rtp_session->last_write_ts < rtp_session->next_write_samplecount && rtp_session->timer.samplecount < rtp_session->max_next_write_samplecount) {
+                       if (rtp_session->timer.samplecount < rtp_session->max_next_write_samplecount) {
                                return;
                        }
+
                        if (rtp_session->timer.samplecount >= rtp_session->max_next_write_samplecount) {
                                rtp_session->queue_delay = 0;
                        }
 
-               } else {
-                       if (rtp_session->last_write_ts < rtp_session->next_write_samplecount) {
-                               return;
+               } else if (rtp_session->queue_delay) {
+                       if (rtp_session->delay_samples >= rtp_session->samples_per_interval) {
+                               rtp_session->delay_samples -= rtp_session->samples_per_interval;
+                       } else {
+                               rtp_session->delay_samples = 0;
+                       }
+
+                       if (!rtp_session->delay_samples) {
+                               rtp_session->queue_delay = 0;
                        }
                }
                
@@ -3926,7 +3932,7 @@ static int rtp_common_write(switch_rtp_t *rtp_session,
                rtp_session->last_write_ts = this_ts;
 
                if (rtp_session->queue_delay) {
-                       rtp_session->next_write_samplecount = rtp_session->last_write_ts + rtp_session->queue_delay;
+                       rtp_session->delay_samples = rtp_session->queue_delay;
                        rtp_session->queue_delay = 0;
                }
 
@@ -4175,9 +4181,11 @@ SWITCH_DECLARE(int) switch_rtp_write_frame(switch_rtp_t *rtp_session, switch_fra
 
        fwd = (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_RAW_WRITE) && switch_test_flag(frame, SFF_RAW_RTP)) ? 1 : 0;
 
-       if (!fwd && switch_test_flag(rtp_session, SWITCH_RTP_FLAG_RAW_WRITE) && (rtp_session->rtp_bugs & RTP_BUG_GEN_ONE_GEN_ALL)) {
+       if (!fwd && !rtp_session->sending_dtmf && !rtp_session->queue_delay && 
+               switch_test_flag(rtp_session, SWITCH_RTP_FLAG_RAW_WRITE) && (rtp_session->rtp_bugs & RTP_BUG_GEN_ONE_GEN_ALL)) {
                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Generating RTP locally but timestamp passthru is configured, disabling....\n");
                switch_clear_flag(rtp_session, SWITCH_RTP_FLAG_RAW_WRITE);
+               rtp_session->last_write_ts = RTP_TS_RESET;
        }
 
        switch_assert(frame != NULL);