blob: 749309b6b1aae5b091bab90037e3ee15e3ecc17b [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11#include "dtmf_queue.h"
12
13#include <string.h> //memset
14
15namespace webrtc {
16DTMFqueue::DTMFqueue():
henrike@webrtc.org65573f22011-12-13 19:17:27 +000017 _DTMFCritsect(CriticalSectionWrapper::CreateCriticalSection()),
niklase@google.com470e71d2011-07-07 08:21:25 +000018 _nextEmptyIndex(0)
19{
20 memset(_DTMFKey,0, sizeof(_DTMFKey));
21 memset(_DTMFLen,0, sizeof(_DTMFLen));
22 memset(_DTMFLevel,0, sizeof(_DTMFLevel));
23}
24
25DTMFqueue::~DTMFqueue()
26{
henrike@webrtc.org65573f22011-12-13 19:17:27 +000027 delete _DTMFCritsect;
niklase@google.com470e71d2011-07-07 08:21:25 +000028}
29
30WebRtc_Word32
31DTMFqueue::AddDTMF(WebRtc_UWord8 key, WebRtc_UWord16 len, WebRtc_UWord8 level)
32{
33 CriticalSectionScoped lock(_DTMFCritsect);
34
35 if(_nextEmptyIndex >= DTMF_OUTBAND_MAX)
36 {
37 return -1;
38 }
39 WebRtc_Word32 index = _nextEmptyIndex;
40 _DTMFKey[index] = key;
41 _DTMFLen[index] = len;
42 _DTMFLevel[index] = level;
43 _nextEmptyIndex++;
44 return 0;
45}
46
47WebRtc_Word8
48DTMFqueue::NextDTMF(WebRtc_UWord8* DTMFKey, WebRtc_UWord16* len, WebRtc_UWord8* level)
49{
50 CriticalSectionScoped lock(_DTMFCritsect);
51
52 if(!PendingDTMF())
53 {
54 return -1;
55 }
56 *DTMFKey=_DTMFKey[0];
57 *len=_DTMFLen[0];
58 *level=_DTMFLevel[0];
59
60 memmove(&(_DTMFKey[0]), &(_DTMFKey[1]), _nextEmptyIndex*sizeof(WebRtc_UWord8));
61 memmove(&(_DTMFLen[0]), &(_DTMFLen[1]), _nextEmptyIndex*sizeof(WebRtc_UWord16));
62 memmove(&(_DTMFLevel[0]), &(_DTMFLevel[1]), _nextEmptyIndex*sizeof(WebRtc_UWord8));
63
64 _nextEmptyIndex--;
65 return 0;
66}
67
68bool
69DTMFqueue::PendingDTMF()
70{
71 return(_nextEmptyIndex>0);
72}
73
74void
75DTMFqueue::ResetDTMF()
76{
77 _nextEmptyIndex = 0;
78}
79} // namespace webrtc