OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2011 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/modules/rtp_rtcp/source/dtmf_queue.h" | 11 #include "webrtc/modules/rtp_rtcp/source/dtmf_queue.h" |
12 | 12 |
13 #include <string.h> | 13 namespace { |
14 constexpr size_t DTMF_OUTBAND_MAX = 20; | |
hlundin-webrtc
2016/11/08 09:01:59
Now, you'll only have to rename it kDtmfOutbandMax
the sun
2016/11/11 12:07:24
Done.
| |
15 } | |
14 | 16 |
15 namespace webrtc { | 17 namespace webrtc { |
16 DTMFqueue::DTMFqueue() : next_empty_index_(0) { | 18 DtmfQueue::DtmfQueue() {} |
17 memset(dtmf_key_, 0, sizeof(dtmf_key_)); | 19 |
18 memset(dtmf_length, 0, sizeof(dtmf_length)); | 20 DtmfQueue::~DtmfQueue() {} |
19 memset(dtmf_level_, 0, sizeof(dtmf_level_)); | 21 |
22 bool DtmfQueue::AddDtmf(const Event& event) { | |
23 rtc::CritScope lock(&dtmf_critsect_); | |
24 if (queue_.size() >= DTMF_OUTBAND_MAX) { | |
25 return false; | |
26 } | |
27 queue_.push_back(event); | |
28 return true; | |
20 } | 29 } |
21 | 30 |
22 DTMFqueue::~DTMFqueue() {} | 31 bool DtmfQueue::NextDtmf(Event* event) { |
32 RTC_DCHECK(event); | |
33 rtc::CritScope lock(&dtmf_critsect_); | |
34 if (queue_.empty()) { | |
35 return false; | |
36 } | |
23 | 37 |
24 int32_t DTMFqueue::AddDTMF(uint8_t key, uint16_t len, uint8_t level) { | 38 *event = queue_.front(); |
25 rtc::CritScope lock(&dtmf_critsect_); | 39 queue_.pop_front(); |
26 | 40 return true; |
27 if (next_empty_index_ >= DTMF_OUTBAND_MAX) { | |
28 return -1; | |
29 } | |
30 int32_t index = next_empty_index_; | |
31 dtmf_key_[index] = key; | |
32 dtmf_length[index] = len; | |
33 dtmf_level_[index] = level; | |
34 next_empty_index_++; | |
35 return 0; | |
36 } | 41 } |
37 | 42 |
38 int8_t DTMFqueue::NextDTMF(uint8_t* dtmf_key, uint16_t* len, uint8_t* level) { | 43 bool DtmfQueue::PendingDtmf() const { |
39 rtc::CritScope lock(&dtmf_critsect_); | 44 rtc::CritScope lock(&dtmf_critsect_); |
40 if (next_empty_index_ == 0) | 45 return !queue_.empty(); |
41 return -1; | |
42 | |
43 *dtmf_key = dtmf_key_[0]; | |
44 *len = dtmf_length[0]; | |
45 *level = dtmf_level_[0]; | |
46 | |
47 memmove(&(dtmf_key_[0]), &(dtmf_key_[1]), | |
48 next_empty_index_ * sizeof(uint8_t)); | |
49 memmove(&(dtmf_length[0]), &(dtmf_length[1]), | |
50 next_empty_index_ * sizeof(uint16_t)); | |
51 memmove(&(dtmf_level_[0]), &(dtmf_level_[1]), | |
52 next_empty_index_ * sizeof(uint8_t)); | |
53 | |
54 next_empty_index_--; | |
55 return 0; | |
56 } | |
57 | |
58 bool DTMFqueue::PendingDTMF() { | |
59 rtc::CritScope lock(&dtmf_critsect_); | |
60 return next_empty_index_ > 0; | |
61 } | 46 } |
62 } // namespace webrtc | 47 } // namespace webrtc |
OLD | NEW |