OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include "webrtc/system_wrappers/include/trace.h" | 11 #include "webrtc/system_wrappers/include/trace.h" |
12 #include "webrtc/voice_engine/dtmf_inband_queue.h" | 12 #include "webrtc/voice_engine/dtmf_inband_queue.h" |
13 | 13 |
14 namespace webrtc { | 14 namespace webrtc { |
15 | 15 |
16 DtmfInbandQueue::DtmfInbandQueue(int32_t id): | 16 DtmfInbandQueue::DtmfInbandQueue(int32_t id): |
17 _id(id), | 17 _id(id), |
18 _DtmfCritsect(*CriticalSectionWrapper::CreateCriticalSection()), | |
19 _nextEmptyIndex(0) | 18 _nextEmptyIndex(0) |
20 { | 19 { |
21 memset(_DtmfKey,0, sizeof(_DtmfKey)); | 20 memset(_DtmfKey,0, sizeof(_DtmfKey)); |
22 memset(_DtmfLen,0, sizeof(_DtmfLen)); | 21 memset(_DtmfLen,0, sizeof(_DtmfLen)); |
23 memset(_DtmfLevel,0, sizeof(_DtmfLevel)); | 22 memset(_DtmfLevel,0, sizeof(_DtmfLevel)); |
24 } | 23 } |
25 | 24 |
26 DtmfInbandQueue::~DtmfInbandQueue() | 25 DtmfInbandQueue::~DtmfInbandQueue() |
27 { | 26 { |
28 delete &_DtmfCritsect; | |
29 } | 27 } |
30 | 28 |
31 int | 29 int |
32 DtmfInbandQueue::AddDtmf(uint8_t key, uint16_t len, uint8_t level) | 30 DtmfInbandQueue::AddDtmf(uint8_t key, uint16_t len, uint8_t level) |
33 { | 31 { |
34 CriticalSectionScoped lock(&_DtmfCritsect); | 32 rtc::CritScope lock(&_DtmfCritsect); |
35 | 33 |
36 if (_nextEmptyIndex >= kDtmfInbandMax) | 34 if (_nextEmptyIndex >= kDtmfInbandMax) |
37 { | 35 { |
38 WEBRTC_TRACE(kTraceWarning, kTraceVoice, VoEId(_id,-1), | 36 WEBRTC_TRACE(kTraceWarning, kTraceVoice, VoEId(_id,-1), |
39 "DtmfInbandQueue::AddDtmf() unable to add Dtmf tone"); | 37 "DtmfInbandQueue::AddDtmf() unable to add Dtmf tone"); |
40 return -1; | 38 return -1; |
41 } | 39 } |
42 int32_t index = _nextEmptyIndex; | 40 int32_t index = _nextEmptyIndex; |
43 _DtmfKey[index] = key; | 41 _DtmfKey[index] = key; |
44 _DtmfLen[index] = len; | 42 _DtmfLen[index] = len; |
45 _DtmfLevel[index] = level; | 43 _DtmfLevel[index] = level; |
46 _nextEmptyIndex++; | 44 _nextEmptyIndex++; |
47 return 0; | 45 return 0; |
48 } | 46 } |
49 | 47 |
50 int8_t | 48 int8_t |
51 DtmfInbandQueue::NextDtmf(uint16_t* len, uint8_t* level) | 49 DtmfInbandQueue::NextDtmf(uint16_t* len, uint8_t* level) |
52 { | 50 { |
53 CriticalSectionScoped lock(&_DtmfCritsect); | 51 rtc::CritScope lock(&_DtmfCritsect); |
54 | 52 |
55 if(!PendingDtmf()) | 53 if(!PendingDtmf()) |
56 { | 54 { |
57 return -1; | 55 return -1; |
58 } | 56 } |
59 int8_t nextDtmf = _DtmfKey[0]; | 57 int8_t nextDtmf = _DtmfKey[0]; |
60 *len=_DtmfLen[0]; | 58 *len=_DtmfLen[0]; |
61 *level=_DtmfLevel[0]; | 59 *level=_DtmfLevel[0]; |
62 | 60 |
63 memmove(&(_DtmfKey[0]), &(_DtmfKey[1]), | 61 memmove(&(_DtmfKey[0]), &(_DtmfKey[1]), |
64 _nextEmptyIndex*sizeof(uint8_t)); | 62 _nextEmptyIndex*sizeof(uint8_t)); |
65 memmove(&(_DtmfLen[0]), &(_DtmfLen[1]), | 63 memmove(&(_DtmfLen[0]), &(_DtmfLen[1]), |
66 _nextEmptyIndex*sizeof(uint16_t)); | 64 _nextEmptyIndex*sizeof(uint16_t)); |
67 memmove(&(_DtmfLevel[0]), &(_DtmfLevel[1]), | 65 memmove(&(_DtmfLevel[0]), &(_DtmfLevel[1]), |
68 _nextEmptyIndex*sizeof(uint8_t)); | 66 _nextEmptyIndex*sizeof(uint8_t)); |
69 | 67 |
70 _nextEmptyIndex--; | 68 _nextEmptyIndex--; |
71 return nextDtmf; | 69 return nextDtmf; |
72 } | 70 } |
73 | 71 |
74 bool | 72 bool |
75 DtmfInbandQueue::PendingDtmf() | 73 DtmfInbandQueue::PendingDtmf() |
76 { | 74 { |
77 CriticalSectionScoped lock(&_DtmfCritsect); | 75 rtc::CritScope lock(&_DtmfCritsect); |
78 return _nextEmptyIndex > 0; | 76 return _nextEmptyIndex > 0; |
79 } | 77 } |
80 | 78 |
81 void | 79 void |
82 DtmfInbandQueue::ResetDtmf() | 80 DtmfInbandQueue::ResetDtmf() |
83 { | 81 { |
84 CriticalSectionScoped lock(&_DtmfCritsect); | 82 rtc::CritScope lock(&_DtmfCritsect); |
85 _nextEmptyIndex = 0; | 83 _nextEmptyIndex = 0; |
86 } | 84 } |
87 | 85 |
88 } // namespace webrtc | 86 } // namespace webrtc |
OLD | NEW |