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 | |
solenberg | ffbbcac | 2016-11-17 05:25:37 -0800 | [diff] [blame] | 13 | namespace { |
| 14 | constexpr size_t kDtmfOutbandMax = 20; |
| 15 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 16 | |
| 17 | namespace webrtc { |
solenberg | ffbbcac | 2016-11-17 05:25:37 -0800 | [diff] [blame] | 18 | DtmfQueue::DtmfQueue() {} |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 19 | |
solenberg | ffbbcac | 2016-11-17 05:25:37 -0800 | [diff] [blame] | 20 | DtmfQueue::~DtmfQueue() {} |
phoglund@webrtc.org | 315d398 | 2013-05-08 10:04:06 +0000 | [diff] [blame] | 21 | |
solenberg | ffbbcac | 2016-11-17 05:25:37 -0800 | [diff] [blame] | 22 | bool DtmfQueue::AddDtmf(const Event& event) { |
danilchap | 7c9426c | 2016-04-14 03:05:31 -0700 | [diff] [blame] | 23 | rtc::CritScope lock(&dtmf_critsect_); |
solenberg | ffbbcac | 2016-11-17 05:25:37 -0800 | [diff] [blame] | 24 | if (queue_.size() >= kDtmfOutbandMax) { |
| 25 | return false; |
phoglund@webrtc.org | 315d398 | 2013-05-08 10:04:06 +0000 | [diff] [blame] | 26 | } |
solenberg | ffbbcac | 2016-11-17 05:25:37 -0800 | [diff] [blame] | 27 | queue_.push_back(event); |
| 28 | return true; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 29 | } |
| 30 | |
solenberg | ffbbcac | 2016-11-17 05:25:37 -0800 | [diff] [blame] | 31 | bool DtmfQueue::NextDtmf(Event* event) { |
| 32 | RTC_DCHECK(event); |
danilchap | 7c9426c | 2016-04-14 03:05:31 -0700 | [diff] [blame] | 33 | rtc::CritScope lock(&dtmf_critsect_); |
solenberg | ffbbcac | 2016-11-17 05:25:37 -0800 | [diff] [blame] | 34 | if (queue_.empty()) { |
| 35 | return false; |
| 36 | } |
pbos@webrtc.org | 7c4d20f | 2015-02-12 12:20:08 +0000 | [diff] [blame] | 37 | |
solenberg | ffbbcac | 2016-11-17 05:25:37 -0800 | [diff] [blame] | 38 | *event = queue_.front(); |
| 39 | queue_.pop_front(); |
| 40 | return true; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 41 | } |
| 42 | |
solenberg | ffbbcac | 2016-11-17 05:25:37 -0800 | [diff] [blame] | 43 | bool DtmfQueue::PendingDtmf() const { |
danilchap | 7c9426c | 2016-04-14 03:05:31 -0700 | [diff] [blame] | 44 | rtc::CritScope lock(&dtmf_critsect_); |
solenberg | ffbbcac | 2016-11-17 05:25:37 -0800 | [diff] [blame] | 45 | return !queue_.empty(); |
pbos@webrtc.org | 7c4d20f | 2015-02-12 12:20:08 +0000 | [diff] [blame] | 46 | } |
phoglund@webrtc.org | 315d398 | 2013-05-08 10:04:06 +0000 | [diff] [blame] | 47 | } // namespace webrtc |