~damg/ubuntu/quantal/asterisk/LP1097687

« back to all changes in this revision

Viewing changes to main/dsp.c

  • Committer: Bazaar Package Importer
  • Author(s): Lorenzo De Liso
  • Date: 2010-10-15 22:24:34 UTC
  • mfrom: (1.2.8 upstream) (8.3.8 sid)
  • Revision ID: james.westby@ubuntu.com-20101015222434-iy328q8in3lajzlv
Tags: 1:1.6.2.9-2ubuntu1
* Merge from debian unstable, remaining changes:
  - debian/control:
    + Build-depend on hardening-wrapper
    + Change Maintainer
    + Removed Uploaders field.
    + Removed Debian Vcs-Svn entry and replaced with ubuntu-voip Vcs-Bzr,
      to reflect divergence in packages.
  - debian/rules: Make use of hardening-wrapper
  - debian/asterisk.init: chown /dev/dahdi
  - debian/backports/hardy: add file
  - debian/backports/asterisk.init.hardy: add file
 

Show diffs side-by-side

added added

removed removed

Lines of Context:
42
42
 
43
43
#include "asterisk.h"
44
44
 
45
 
ASTERISK_FILE_VERSION(__FILE__, "$Revision: 235775 $")
 
45
ASTERISK_FILE_VERSION(__FILE__, "$Revision: 268577 $")
46
46
 
47
47
#include <math.h>
48
48
 
273
273
typedef struct
274
274
{
275
275
        char digits[MAX_DTMF_DIGITS + 1];
 
276
        int digitlen[MAX_DTMF_DIGITS + 1];
276
277
        int current_digits;
277
278
        int detected_digits;
278
279
        int lost_digits;
630
631
{
631
632
        s->detected_digits++;
632
633
        if (s->current_digits < MAX_DTMF_DIGITS) {
 
634
                s->digitlen[s->current_digits] = 0;
633
635
                s->digits[s->current_digits++] = digit;
634
636
                s->digits[s->current_digits] = '\0';
635
637
        } else {
733
735
                                }
734
736
                        } else {
735
737
                                s->td.dtmf.misses = 0;
 
738
                                /* Current hit was same as last, so increment digit duration (of last digit) */
 
739
                                s->digitlen[s->current_digits - 1] += DTMF_GSIZE;
736
740
                        }
737
741
                }
738
742
 
998
1002
                                } else if (hz[HZ_950] > TONE_MIN_THRESH * TONE_THRESH) {
999
1003
                                        newstate = DSP_TONE_STATE_SPECIAL1;
1000
1004
                                } else if (hz[HZ_1400] > TONE_MIN_THRESH * TONE_THRESH) {
1001
 
                                        if (dsp->tstate == DSP_TONE_STATE_SPECIAL1)
 
1005
                                        /* End of SPECIAL1 or middle of SPECIAL2 */
 
1006
                                        if (dsp->tstate == DSP_TONE_STATE_SPECIAL1 || dsp->tstate == DSP_TONE_STATE_SPECIAL2) {
1002
1007
                                                newstate = DSP_TONE_STATE_SPECIAL2;
 
1008
                                        }
1003
1009
                                } else if (hz[HZ_1800] > TONE_MIN_THRESH * TONE_THRESH) {
1004
 
                                        if (dsp->tstate == DSP_TONE_STATE_SPECIAL2) {
 
1010
                                        /* End of SPECIAL2 or middle of SPECIAL3 */
 
1011
                                        if (dsp->tstate == DSP_TONE_STATE_SPECIAL2 || dsp->tstate == DSP_TONE_STATE_SPECIAL3) {
1005
1012
                                                newstate = DSP_TONE_STATE_SPECIAL3;
1006
1013
                                        }
1007
1014
                                } else if (dsp->genergy > TONE_MIN_THRESH * TONE_THRESH) {
1035
1042
                                        dsp->ringtimeout++;
1036
1043
                                }
1037
1044
                                switch (dsp->tstate) {
1038
 
                                        case DSP_TONE_STATE_RINGING:
1039
 
                                                if ((dsp->features & DSP_PROGRESS_RINGING) &&
1040
 
                                                    (dsp->tcount==THRESH_RING)) {
1041
 
                                                        res = AST_CONTROL_RINGING;
1042
 
                                                        dsp->ringtimeout= 1;
1043
 
                                                }
1044
 
                                                break;
1045
 
                                        case DSP_TONE_STATE_BUSY:
1046
 
                                                if ((dsp->features & DSP_PROGRESS_BUSY) &&
1047
 
                                                    (dsp->tcount==THRESH_BUSY)) {
1048
 
                                                        res = AST_CONTROL_BUSY;
1049
 
                                                        dsp->features &= ~DSP_FEATURE_CALL_PROGRESS;
1050
 
                                                }
1051
 
                                                break;
1052
 
                                        case DSP_TONE_STATE_TALKING:
1053
 
                                                if ((dsp->features & DSP_PROGRESS_TALK) &&
1054
 
                                                    (dsp->tcount==THRESH_TALK)) {
1055
 
                                                        res = AST_CONTROL_ANSWER;
1056
 
                                                        dsp->features &= ~DSP_FEATURE_CALL_PROGRESS;
1057
 
                                                }
1058
 
                                                break;
1059
 
                                        case DSP_TONE_STATE_SPECIAL3:
1060
 
                                                if ((dsp->features & DSP_PROGRESS_CONGESTION) &&
1061
 
                                                    (dsp->tcount==THRESH_CONGESTION)) {
1062
 
                                                        res = AST_CONTROL_CONGESTION;
1063
 
                                                        dsp->features &= ~DSP_FEATURE_CALL_PROGRESS;
1064
 
                                                }
1065
 
                                                break;
1066
 
                                        case DSP_TONE_STATE_HUNGUP:
1067
 
                                                if ((dsp->features & DSP_FEATURE_CALL_PROGRESS) &&
1068
 
                                                    (dsp->tcount==THRESH_HANGUP)) {
1069
 
                                                        res = AST_CONTROL_HANGUP;
1070
 
                                                        dsp->features &= ~DSP_FEATURE_CALL_PROGRESS;
1071
 
                                                }
1072
 
                                                break;
 
1045
                                case DSP_TONE_STATE_RINGING:
 
1046
                                        if ((dsp->features & DSP_PROGRESS_RINGING) &&
 
1047
                                            (dsp->tcount == THRESH_RING)) {
 
1048
                                                res = AST_CONTROL_RINGING;
 
1049
                                                dsp->ringtimeout = 1;
 
1050
                                        }
 
1051
                                        break;
 
1052
                                case DSP_TONE_STATE_BUSY:
 
1053
                                        if ((dsp->features & DSP_PROGRESS_BUSY) &&
 
1054
                                            (dsp->tcount == THRESH_BUSY)) {
 
1055
                                                res = AST_CONTROL_BUSY;
 
1056
                                                dsp->features &= ~DSP_FEATURE_CALL_PROGRESS;
 
1057
                                        }
 
1058
                                        break;
 
1059
                                case DSP_TONE_STATE_TALKING:
 
1060
                                        if ((dsp->features & DSP_PROGRESS_TALK) &&
 
1061
                                            (dsp->tcount == THRESH_TALK)) {
 
1062
                                                res = AST_CONTROL_ANSWER;
 
1063
                                                dsp->features &= ~DSP_FEATURE_CALL_PROGRESS;
 
1064
                                        }
 
1065
                                        break;
 
1066
                                case DSP_TONE_STATE_SPECIAL3:
 
1067
                                        if ((dsp->features & DSP_PROGRESS_CONGESTION) &&
 
1068
                                            (dsp->tcount == THRESH_CONGESTION)) {
 
1069
                                                res = AST_CONTROL_CONGESTION;
 
1070
                                                dsp->features &= ~DSP_FEATURE_CALL_PROGRESS;
 
1071
                                        }
 
1072
                                        break;
 
1073
                                case DSP_TONE_STATE_HUNGUP:
 
1074
                                        if ((dsp->features & DSP_FEATURE_CALL_PROGRESS) &&
 
1075
                                            (dsp->tcount == THRESH_HANGUP)) {
 
1076
                                                res = AST_CONTROL_HANGUP;
 
1077
                                                dsp->features &= ~DSP_FEATURE_CALL_PROGRESS;
 
1078
                                        }
 
1079
                                        break;
1073
1080
                                }
1074
 
                                if (dsp->ringtimeout==THRESH_RING2ANSWER) {
 
1081
                                if (dsp->ringtimeout == THRESH_RING2ANSWER) {
1075
1082
                                        ast_debug(1, "Consider call as answered because of timeout after last ring\n");
1076
1083
                                        res = AST_CONTROL_ANSWER;
1077
1084
                                        dsp->features &= ~DSP_FEATURE_CALL_PROGRESS;
1082
1089
                                dsp->tstate = newstate;
1083
1090
                                dsp->tcount = 1;
1084
1091
                        }
1085
 
                        
1086
 
                        /* Reset goertzel */                                            
 
1092
 
 
1093
                        /* Reset goertzel */
1087
1094
                        for (x = 0; x < 7; x++) {
1088
1095
                                dsp->freqs[x].v2 = dsp->freqs[x].v3 = 0.0;
1089
1096
                        }
1392
1399
                        digit = dtmf_detect(dsp, &dsp->digit_state, shortdata, len, (dsp->digitmode & DSP_DIGITMODE_NOQUELCH) == 0, (dsp->digitmode & DSP_DIGITMODE_RELAXDTMF));
1393
1400
 
1394
1401
                if (dsp->digit_state.current_digits) {
1395
 
                        int event = 0;
 
1402
                        int event = 0, event_len = 0;
1396
1403
                        char event_digit = 0;
1397
1404
 
1398
1405
                        if (!dsp->dtmf_began) {
1409
1416
                                if (dsp->features & DSP_FEATURE_DIGIT_DETECT) {
1410
1417
                                        event = AST_FRAME_DTMF_END;
1411
1418
                                        event_digit = dsp->digit_state.digits[0];
 
1419
                                        event_len = dsp->digit_state.digitlen[0] * 1000 / SAMPLE_RATE;
1412
1420
                                }
1413
 
                                memmove(dsp->digit_state.digits, dsp->digit_state.digits + 1, dsp->digit_state.current_digits);
 
1421
                                memmove(&dsp->digit_state.digits[0], &dsp->digit_state.digits[1], dsp->digit_state.current_digits);
 
1422
                                memmove(&dsp->digit_state.digitlen[0], &dsp->digit_state.digitlen[1], dsp->digit_state.current_digits * sizeof(dsp->digit_state.digitlen[0]));
1414
1423
                                dsp->digit_state.current_digits--;
1415
1424
                                dsp->dtmf_began = 0;
1416
1425
 
1426
1435
                                memset(&dsp->f, 0, sizeof(dsp->f));
1427
1436
                                dsp->f.frametype = event;
1428
1437
                                dsp->f.subclass = event_digit;
 
1438
                                dsp->f.len = event_len;
1429
1439
                                outf = &dsp->f;
1430
1440
                                goto done;
1431
1441
                        }