blob: 81e8b5926e2f6af288fa8bc6df548fd915424544 [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
phoglund@webrtc.org315d3982013-05-08 10:04:06 +000011#include "webrtc/modules/rtp_rtcp/source/dtmf_queue.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000012
danilchap162abd32015-12-10 02:39:40 -080013#include <string.h>
niklase@google.com470e71d2011-07-07 08:21:25 +000014
15namespace webrtc {
danilchap7c9426c2016-04-14 03:05:31 -070016DTMFqueue::DTMFqueue() : next_empty_index_(0) {
phoglund@webrtc.org315d3982013-05-08 10:04:06 +000017 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.com470e71d2011-07-07 08:21:25 +000020}
21
danilchap7c9426c2016-04-14 03:05:31 -070022DTMFqueue::~DTMFqueue() {}
phoglund@webrtc.org315d3982013-05-08 10:04:06 +000023
24int32_t DTMFqueue::AddDTMF(uint8_t key, uint16_t len, uint8_t level) {
danilchap7c9426c2016-04-14 03:05:31 -070025 rtc::CritScope lock(&dtmf_critsect_);
phoglund@webrtc.org315d3982013-05-08 10:04:06 +000026
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.com470e71d2011-07-07 08:21:25 +000036}
37
phoglund@webrtc.org315d3982013-05-08 10:04:06 +000038int8_t DTMFqueue::NextDTMF(uint8_t* dtmf_key, uint16_t* len, uint8_t* level) {
danilchap7c9426c2016-04-14 03:05:31 -070039 rtc::CritScope lock(&dtmf_critsect_);
pbos@webrtc.org7c4d20f2015-02-12 12:20:08 +000040 if (next_empty_index_ == 0)
phoglund@webrtc.org315d3982013-05-08 10:04:06 +000041 return -1;
pbos@webrtc.org7c4d20f2015-02-12 12:20:08 +000042
phoglund@webrtc.org315d3982013-05-08 10:04:06 +000043 *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.com470e71d2011-07-07 08:21:25 +000056}
57
pbos@webrtc.org7c4d20f2015-02-12 12:20:08 +000058bool DTMFqueue::PendingDTMF() {
danilchap7c9426c2016-04-14 03:05:31 -070059 rtc::CritScope lock(&dtmf_critsect_);
pbos@webrtc.org7c4d20f2015-02-12 12:20:08 +000060 return next_empty_index_ > 0;
61}
niklase@google.com470e71d2011-07-07 08:21:25 +000062
pbos@webrtc.org7c4d20f2015-02-12 12:20:08 +000063void DTMFqueue::ResetDTMF() {
danilchap7c9426c2016-04-14 03:05:31 -070064 rtc::CritScope lock(&dtmf_critsect_);
pbos@webrtc.org7c4d20f2015-02-12 12:20:08 +000065 next_empty_index_ = 0;
66}
phoglund@webrtc.org315d3982013-05-08 10:04:06 +000067} // namespace webrtc