niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
| 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 | |
phoglund@webrtc.org | 315d398 | 2013-05-08 10:04:06 +0000 | [diff] [blame] | 11 | #include "webrtc/modules/rtp_rtcp/source/dtmf_queue.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 12 | |
phoglund@webrtc.org | 315d398 | 2013-05-08 10:04:06 +0000 | [diff] [blame] | 13 | #include <string.h> //memset |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 14 | |
| 15 | namespace webrtc { |
phoglund@webrtc.org | 315d398 | 2013-05-08 10:04:06 +0000 | [diff] [blame] | 16 | DTMFqueue::DTMFqueue() |
| 17 | : dtmf_critsect_(CriticalSectionWrapper::CreateCriticalSection()), |
| 18 | next_empty_index_(0) { |
| 19 | memset(dtmf_key_, 0, sizeof(dtmf_key_)); |
| 20 | memset(dtmf_length, 0, sizeof(dtmf_length)); |
| 21 | memset(dtmf_level_, 0, sizeof(dtmf_level_)); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 22 | } |
| 23 | |
phoglund@webrtc.org | 315d398 | 2013-05-08 10:04:06 +0000 | [diff] [blame] | 24 | DTMFqueue::~DTMFqueue() { delete dtmf_critsect_; } |
| 25 | |
| 26 | int32_t DTMFqueue::AddDTMF(uint8_t key, uint16_t len, uint8_t level) { |
| 27 | CriticalSectionScoped lock(dtmf_critsect_); |
| 28 | |
| 29 | if (next_empty_index_ >= DTMF_OUTBAND_MAX) { |
| 30 | return -1; |
| 31 | } |
| 32 | int32_t index = next_empty_index_; |
| 33 | dtmf_key_[index] = key; |
| 34 | dtmf_length[index] = len; |
| 35 | dtmf_level_[index] = level; |
| 36 | next_empty_index_++; |
| 37 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 38 | } |
| 39 | |
phoglund@webrtc.org | 315d398 | 2013-05-08 10:04:06 +0000 | [diff] [blame] | 40 | int8_t DTMFqueue::NextDTMF(uint8_t* dtmf_key, uint16_t* len, uint8_t* level) { |
| 41 | CriticalSectionScoped lock(dtmf_critsect_); |
pbos@webrtc.org | 7c4d20f | 2015-02-12 12:20:08 +0000 | [diff] [blame] | 42 | if (next_empty_index_ == 0) |
phoglund@webrtc.org | 315d398 | 2013-05-08 10:04:06 +0000 | [diff] [blame] | 43 | return -1; |
pbos@webrtc.org | 7c4d20f | 2015-02-12 12:20:08 +0000 | [diff] [blame] | 44 | |
phoglund@webrtc.org | 315d398 | 2013-05-08 10:04:06 +0000 | [diff] [blame] | 45 | *dtmf_key = dtmf_key_[0]; |
| 46 | *len = dtmf_length[0]; |
| 47 | *level = dtmf_level_[0]; |
| 48 | |
| 49 | memmove(&(dtmf_key_[0]), &(dtmf_key_[1]), |
| 50 | next_empty_index_ * sizeof(uint8_t)); |
| 51 | memmove(&(dtmf_length[0]), &(dtmf_length[1]), |
| 52 | next_empty_index_ * sizeof(uint16_t)); |
| 53 | memmove(&(dtmf_level_[0]), &(dtmf_level_[1]), |
| 54 | next_empty_index_ * sizeof(uint8_t)); |
| 55 | |
| 56 | next_empty_index_--; |
| 57 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 58 | } |
| 59 | |
pbos@webrtc.org | 7c4d20f | 2015-02-12 12:20:08 +0000 | [diff] [blame] | 60 | bool DTMFqueue::PendingDTMF() { |
| 61 | CriticalSectionScoped lock(dtmf_critsect_); |
| 62 | return next_empty_index_ > 0; |
| 63 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 64 | |
pbos@webrtc.org | 7c4d20f | 2015-02-12 12:20:08 +0000 | [diff] [blame] | 65 | void DTMFqueue::ResetDTMF() { |
| 66 | CriticalSectionScoped lock(dtmf_critsect_); |
| 67 | next_empty_index_ = 0; |
| 68 | } |
phoglund@webrtc.org | 315d398 | 2013-05-08 10:04:06 +0000 | [diff] [blame] | 69 | } // namespace webrtc |