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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #include "modules/rtp_rtcp/source/dtmf_queue.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 12 | |
Yves Gerey | 988cc08 | 2018-10-23 12:03:01 +0200 | [diff] [blame] | 13 | #include <stddef.h> |
| 14 | |
| 15 | #include "rtc_base/checks.h" |
| 16 | |
solenberg | ffbbcac | 2016-11-17 05:25:37 -0800 | [diff] [blame] | 17 | namespace { |
| 18 | constexpr size_t kDtmfOutbandMax = 20; |
| 19 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 20 | |
| 21 | namespace webrtc { |
solenberg | ffbbcac | 2016-11-17 05:25:37 -0800 | [diff] [blame] | 22 | DtmfQueue::DtmfQueue() {} |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 23 | |
solenberg | ffbbcac | 2016-11-17 05:25:37 -0800 | [diff] [blame] | 24 | DtmfQueue::~DtmfQueue() {} |
phoglund@webrtc.org | 315d398 | 2013-05-08 10:04:06 +0000 | [diff] [blame] | 25 | |
solenberg | ffbbcac | 2016-11-17 05:25:37 -0800 | [diff] [blame] | 26 | bool DtmfQueue::AddDtmf(const Event& event) { |
Markus Handell | e7c015e | 2020-07-07 11:44:28 +0200 | [diff] [blame] | 27 | MutexLock lock(&dtmf_mutex_); |
solenberg | ffbbcac | 2016-11-17 05:25:37 -0800 | [diff] [blame] | 28 | if (queue_.size() >= kDtmfOutbandMax) { |
| 29 | return false; |
phoglund@webrtc.org | 315d398 | 2013-05-08 10:04:06 +0000 | [diff] [blame] | 30 | } |
solenberg | ffbbcac | 2016-11-17 05:25:37 -0800 | [diff] [blame] | 31 | queue_.push_back(event); |
| 32 | return true; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 33 | } |
| 34 | |
solenberg | ffbbcac | 2016-11-17 05:25:37 -0800 | [diff] [blame] | 35 | bool DtmfQueue::NextDtmf(Event* event) { |
| 36 | RTC_DCHECK(event); |
Markus Handell | e7c015e | 2020-07-07 11:44:28 +0200 | [diff] [blame] | 37 | MutexLock lock(&dtmf_mutex_); |
solenberg | ffbbcac | 2016-11-17 05:25:37 -0800 | [diff] [blame] | 38 | if (queue_.empty()) { |
| 39 | return false; |
| 40 | } |
pbos@webrtc.org | 7c4d20f | 2015-02-12 12:20:08 +0000 | [diff] [blame] | 41 | |
solenberg | ffbbcac | 2016-11-17 05:25:37 -0800 | [diff] [blame] | 42 | *event = queue_.front(); |
| 43 | queue_.pop_front(); |
| 44 | return true; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 45 | } |
| 46 | |
solenberg | ffbbcac | 2016-11-17 05:25:37 -0800 | [diff] [blame] | 47 | bool DtmfQueue::PendingDtmf() const { |
Markus Handell | e7c015e | 2020-07-07 11:44:28 +0200 | [diff] [blame] | 48 | MutexLock lock(&dtmf_mutex_); |
solenberg | ffbbcac | 2016-11-17 05:25:37 -0800 | [diff] [blame] | 49 | return !queue_.empty(); |
pbos@webrtc.org | 7c4d20f | 2015-02-12 12:20:08 +0000 | [diff] [blame] | 50 | } |
phoglund@webrtc.org | 315d398 | 2013-05-08 10:04:06 +0000 | [diff] [blame] | 51 | } // namespace webrtc |