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 | |
danilchap | 162abd3 | 2015-12-10 02:39:40 -0800 | [diff] [blame] | 13 | #include <string.h> |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 14 | |
| 15 | namespace webrtc { |
danilchap | 7c9426c | 2016-04-14 03:05:31 -0700 | [diff] [blame^] | 16 | DTMFqueue::DTMFqueue() : next_empty_index_(0) { |
phoglund@webrtc.org | 315d398 | 2013-05-08 10:04:06 +0000 | [diff] [blame] | 17 | memset(dtmf_key_, 0, sizeof(dtmf_key_)); |
| 18 | memset(dtmf_length, 0, sizeof(dtmf_length)); |
| 19 | memset(dtmf_level_, 0, sizeof(dtmf_level_)); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 20 | } |
| 21 | |
danilchap | 7c9426c | 2016-04-14 03:05:31 -0700 | [diff] [blame^] | 22 | DTMFqueue::~DTMFqueue() {} |
phoglund@webrtc.org | 315d398 | 2013-05-08 10:04:06 +0000 | [diff] [blame] | 23 | |
| 24 | int32_t DTMFqueue::AddDTMF(uint8_t key, uint16_t len, uint8_t level) { |
danilchap | 7c9426c | 2016-04-14 03:05:31 -0700 | [diff] [blame^] | 25 | rtc::CritScope lock(&dtmf_critsect_); |
phoglund@webrtc.org | 315d398 | 2013-05-08 10:04:06 +0000 | [diff] [blame] | 26 | |
| 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; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 36 | } |
| 37 | |
phoglund@webrtc.org | 315d398 | 2013-05-08 10:04:06 +0000 | [diff] [blame] | 38 | int8_t DTMFqueue::NextDTMF(uint8_t* dtmf_key, uint16_t* len, uint8_t* level) { |
danilchap | 7c9426c | 2016-04-14 03:05:31 -0700 | [diff] [blame^] | 39 | rtc::CritScope lock(&dtmf_critsect_); |
pbos@webrtc.org | 7c4d20f | 2015-02-12 12:20:08 +0000 | [diff] [blame] | 40 | if (next_empty_index_ == 0) |
phoglund@webrtc.org | 315d398 | 2013-05-08 10:04:06 +0000 | [diff] [blame] | 41 | return -1; |
pbos@webrtc.org | 7c4d20f | 2015-02-12 12:20:08 +0000 | [diff] [blame] | 42 | |
phoglund@webrtc.org | 315d398 | 2013-05-08 10:04:06 +0000 | [diff] [blame] | 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; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 56 | } |
| 57 | |
pbos@webrtc.org | 7c4d20f | 2015-02-12 12:20:08 +0000 | [diff] [blame] | 58 | bool DTMFqueue::PendingDTMF() { |
danilchap | 7c9426c | 2016-04-14 03:05:31 -0700 | [diff] [blame^] | 59 | rtc::CritScope lock(&dtmf_critsect_); |
pbos@webrtc.org | 7c4d20f | 2015-02-12 12:20:08 +0000 | [diff] [blame] | 60 | return next_empty_index_ > 0; |
| 61 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 62 | |
pbos@webrtc.org | 7c4d20f | 2015-02-12 12:20:08 +0000 | [diff] [blame] | 63 | void DTMFqueue::ResetDTMF() { |
danilchap | 7c9426c | 2016-04-14 03:05:31 -0700 | [diff] [blame^] | 64 | rtc::CritScope lock(&dtmf_critsect_); |
pbos@webrtc.org | 7c4d20f | 2015-02-12 12:20:08 +0000 | [diff] [blame] | 65 | next_empty_index_ = 0; |
| 66 | } |
phoglund@webrtc.org | 315d398 | 2013-05-08 10:04:06 +0000 | [diff] [blame] | 67 | } // namespace webrtc |