dtmf_queue.cc (1215B)
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 11 #include "modules/rtp_rtcp/source/dtmf_queue.h" 12 13 #include <cstddef> 14 15 #include "rtc_base/checks.h" 16 #include "rtc_base/synchronization/mutex.h" 17 18 namespace { 19 constexpr size_t kDtmfOutbandMax = 20; 20 } // namespace 21 22 namespace webrtc { 23 DtmfQueue::DtmfQueue() {} 24 25 DtmfQueue::~DtmfQueue() {} 26 27 bool DtmfQueue::AddDtmf(const Event& event) { 28 MutexLock lock(&dtmf_mutex_); 29 if (queue_.size() >= kDtmfOutbandMax) { 30 return false; 31 } 32 queue_.push_back(event); 33 return true; 34 } 35 36 bool DtmfQueue::NextDtmf(Event* event) { 37 RTC_DCHECK(event); 38 MutexLock lock(&dtmf_mutex_); 39 if (queue_.empty()) { 40 return false; 41 } 42 43 *event = queue_.front(); 44 queue_.pop_front(); 45 return true; 46 } 47 48 bool DtmfQueue::PendingDtmf() const { 49 MutexLock lock(&dtmf_mutex_); 50 return !queue_.empty(); 51 } 52 } // namespace webrtc