blob: df06d2a2f3ac09c272a43dfcb4669e5fdb53c513 [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
Yves Gerey988cc082018-10-23 12:03:01 +020013#include <stddef.h>
14
15#include "rtc_base/checks.h"
16
solenbergffbbcac2016-11-17 05:25:37 -080017namespace {
18constexpr size_t kDtmfOutbandMax = 20;
19}
niklase@google.com470e71d2011-07-07 08:21:25 +000020
21namespace webrtc {
solenbergffbbcac2016-11-17 05:25:37 -080022DtmfQueue::DtmfQueue() {}
niklase@google.com470e71d2011-07-07 08:21:25 +000023
solenbergffbbcac2016-11-17 05:25:37 -080024DtmfQueue::~DtmfQueue() {}
phoglund@webrtc.org315d3982013-05-08 10:04:06 +000025
solenbergffbbcac2016-11-17 05:25:37 -080026bool DtmfQueue::AddDtmf(const Event& event) {
Markus Handelle7c015e2020-07-07 11:44:28 +020027 MutexLock lock(&dtmf_mutex_);
solenbergffbbcac2016-11-17 05:25:37 -080028 if (queue_.size() >= kDtmfOutbandMax) {
29 return false;
phoglund@webrtc.org315d3982013-05-08 10:04:06 +000030 }
solenbergffbbcac2016-11-17 05:25:37 -080031 queue_.push_back(event);
32 return true;
niklase@google.com470e71d2011-07-07 08:21:25 +000033}
34
solenbergffbbcac2016-11-17 05:25:37 -080035bool DtmfQueue::NextDtmf(Event* event) {
36 RTC_DCHECK(event);
Markus Handelle7c015e2020-07-07 11:44:28 +020037 MutexLock lock(&dtmf_mutex_);
solenbergffbbcac2016-11-17 05:25:37 -080038 if (queue_.empty()) {
39 return false;
40 }
pbos@webrtc.org7c4d20f2015-02-12 12:20:08 +000041
solenbergffbbcac2016-11-17 05:25:37 -080042 *event = queue_.front();
43 queue_.pop_front();
44 return true;
niklase@google.com470e71d2011-07-07 08:21:25 +000045}
46
solenbergffbbcac2016-11-17 05:25:37 -080047bool DtmfQueue::PendingDtmf() const {
Markus Handelle7c015e2020-07-07 11:44:28 +020048 MutexLock lock(&dtmf_mutex_);
solenbergffbbcac2016-11-17 05:25:37 -080049 return !queue_.empty();
pbos@webrtc.org7c4d20f2015-02-12 12:20:08 +000050}
phoglund@webrtc.org315d3982013-05-08 10:04:06 +000051} // namespace webrtc