Fix crash in DTMF detection.
authorTilghman Lesher <tilghman@meg.abyt.es>
Sat, 5 Jun 2010 17:55:28 +0000 (17:55 +0000)
committerTilghman Lesher <tilghman@meg.abyt.es>
Sat, 5 Jun 2010 17:55:28 +0000 (17:55 +0000)
What I did not originally see in my previous commit was that even though the
next digit could be detected before the previous was considered ended, the
detection of the next digit effectively ends the detection of the previous.
Therefore, the length moves in lockstep with the digit, and no separate counter
is needed for the length alone.

(closes issue #17371)
 Reported by: alecdavis

(closes issue #17474)
 Reported by: kenner

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@268456 65c4cc65-6c06-0410-ace0-fbb531ad65f3

main/dsp.c

index c9fd643..649ae9f 100644 (file)
@@ -273,11 +273,8 @@ typedef struct
 typedef struct
 {
        char digits[MAX_DTMF_DIGITS + 1];
-       int current_digits;
-       /* Store lengths separately, because next digit may begin before last has
-        * ended (because hits_to_begin may be less than misses_to_end). */
        int digitlen[MAX_DTMF_DIGITS + 1];
-       int current_len;
+       int current_digits;
        int detected_digits;
        int lost_digits;
 
@@ -507,7 +504,6 @@ static void ast_mf_detect_init (mf_detect_state_t *s)
 static void ast_digit_detect_init(digit_detect_state_t *s, int mf)
 {
        s->current_digits = 0;
-       s->current_len = 0;
        s->detected_digits = 0;
        s->lost_digits = 0;
        s->digits[0] = '\0';
@@ -731,8 +727,8 @@ static int dtmf_detect(struct ast_dsp *dsp, digit_detect_state_t *s, int16_t amp
                                }
                        } else {
                                s->td.dtmf.misses = 0;
-                               /* Current hit was same as last, so increment digit duration */
-                               s->digitlen[s->current_len] += DTMF_GSIZE;
+                               /* Current hit was same as last, so increment digit duration (of last digit) */
+                               s->digitlen[s->current_digits - 1] += DTMF_GSIZE;
                        }
                }
 
@@ -1414,9 +1410,8 @@ struct ast_frame *ast_dsp_process(struct ast_channel *chan, struct ast_dsp *dsp,
                                        event_len = dsp->digit_state.digitlen[0] * 1000 / SAMPLE_RATE;
                                }
                                memmove(&dsp->digit_state.digits[0], &dsp->digit_state.digits[1], dsp->digit_state.current_digits);
+                               memmove(&dsp->digit_state.digitlen[0], &dsp->digit_state.digitlen[1], dsp->digit_state.current_digits * sizeof(dsp->digit_state.digitlen[0]));
                                dsp->digit_state.current_digits--;
-                               memmove(&dsp->digit_state.digitlen[0], &dsp->digit_state.digitlen[1], dsp->digit_state.current_len * sizeof(dsp->digit_state.digitlen[0]));
-                               dsp->digit_state.current_len--;
                                dsp->dtmf_began = 0;
 
                                if (dsp->features & DSP_FEATURE_BUSY_DETECT) {