blob: 86ddb105f924e998f19dee296b0e19c0c5a184e1 [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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#include "modules/rtp_rtcp/source/dtmf_queue.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000012
solenbergffbbcac2016-11-17 05:25:37 -080013namespace {
14constexpr size_t kDtmfOutbandMax = 20;
15}
niklase@google.com470e71d2011-07-07 08:21:25 +000016
17namespace webrtc {
solenbergffbbcac2016-11-17 05:25:37 -080018DtmfQueue::DtmfQueue() {}
niklase@google.com470e71d2011-07-07 08:21:25 +000019
solenbergffbbcac2016-11-17 05:25:37 -080020DtmfQueue::~DtmfQueue() {}
phoglund@webrtc.org315d3982013-05-08 10:04:06 +000021
solenbergffbbcac2016-11-17 05:25:37 -080022bool DtmfQueue::AddDtmf(const Event& event) {
danilchap7c9426c2016-04-14 03:05:31 -070023 rtc::CritScope lock(&dtmf_critsect_);
solenbergffbbcac2016-11-17 05:25:37 -080024 if (queue_.size() >= kDtmfOutbandMax) {
25 return false;
phoglund@webrtc.org315d3982013-05-08 10:04:06 +000026 }
solenbergffbbcac2016-11-17 05:25:37 -080027 queue_.push_back(event);
28 return true;
niklase@google.com470e71d2011-07-07 08:21:25 +000029}
30
solenbergffbbcac2016-11-17 05:25:37 -080031bool DtmfQueue::NextDtmf(Event* event) {
32 RTC_DCHECK(event);
danilchap7c9426c2016-04-14 03:05:31 -070033 rtc::CritScope lock(&dtmf_critsect_);
solenbergffbbcac2016-11-17 05:25:37 -080034 if (queue_.empty()) {
35 return false;
36 }
pbos@webrtc.org7c4d20f2015-02-12 12:20:08 +000037
solenbergffbbcac2016-11-17 05:25:37 -080038 *event = queue_.front();
39 queue_.pop_front();
40 return true;
niklase@google.com470e71d2011-07-07 08:21:25 +000041}
42
solenbergffbbcac2016-11-17 05:25:37 -080043bool DtmfQueue::PendingDtmf() const {
danilchap7c9426c2016-04-14 03:05:31 -070044 rtc::CritScope lock(&dtmf_critsect_);
solenbergffbbcac2016-11-17 05:25:37 -080045 return !queue_.empty();
pbos@webrtc.org7c4d20f2015-02-12 12:20:08 +000046}
phoglund@webrtc.org315d3982013-05-08 10:04:06 +000047} // namespace webrtc