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 | |
| 11 | #include "dtmf_queue.h" |
| 12 | |
| 13 | #include <string.h> //memset |
| 14 | |
| 15 | namespace webrtc { |
| 16 | DTMFqueue::DTMFqueue(): |
henrike@webrtc.org | 65573f2 | 2011-12-13 19:17:27 +0000 | [diff] [blame] | 17 | _DTMFCritsect(CriticalSectionWrapper::CreateCriticalSection()), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 18 | _nextEmptyIndex(0) |
| 19 | { |
| 20 | memset(_DTMFKey,0, sizeof(_DTMFKey)); |
| 21 | memset(_DTMFLen,0, sizeof(_DTMFLen)); |
| 22 | memset(_DTMFLevel,0, sizeof(_DTMFLevel)); |
| 23 | } |
| 24 | |
| 25 | DTMFqueue::~DTMFqueue() |
| 26 | { |
henrike@webrtc.org | 65573f2 | 2011-12-13 19:17:27 +0000 | [diff] [blame] | 27 | delete _DTMFCritsect; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 28 | } |
| 29 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 30 | int32_t |
| 31 | DTMFqueue::AddDTMF(uint8_t key, uint16_t len, uint8_t level) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 32 | { |
| 33 | CriticalSectionScoped lock(_DTMFCritsect); |
| 34 | |
| 35 | if(_nextEmptyIndex >= DTMF_OUTBAND_MAX) |
| 36 | { |
| 37 | return -1; |
| 38 | } |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 39 | int32_t index = _nextEmptyIndex; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 40 | _DTMFKey[index] = key; |
| 41 | _DTMFLen[index] = len; |
| 42 | _DTMFLevel[index] = level; |
| 43 | _nextEmptyIndex++; |
| 44 | return 0; |
| 45 | } |
| 46 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 47 | int8_t |
| 48 | DTMFqueue::NextDTMF(uint8_t* DTMFKey, uint16_t* len, uint8_t* level) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 49 | { |
| 50 | CriticalSectionScoped lock(_DTMFCritsect); |
| 51 | |
| 52 | if(!PendingDTMF()) |
| 53 | { |
| 54 | return -1; |
| 55 | } |
| 56 | *DTMFKey=_DTMFKey[0]; |
| 57 | *len=_DTMFLen[0]; |
| 58 | *level=_DTMFLevel[0]; |
| 59 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 60 | memmove(&(_DTMFKey[0]), &(_DTMFKey[1]), _nextEmptyIndex*sizeof(uint8_t)); |
| 61 | memmove(&(_DTMFLen[0]), &(_DTMFLen[1]), _nextEmptyIndex*sizeof(uint16_t)); |
| 62 | memmove(&(_DTMFLevel[0]), &(_DTMFLevel[1]), _nextEmptyIndex*sizeof(uint8_t)); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 63 | |
| 64 | _nextEmptyIndex--; |
| 65 | return 0; |
| 66 | } |
| 67 | |
| 68 | bool |
| 69 | DTMFqueue::PendingDTMF() |
| 70 | { |
| 71 | return(_nextEmptyIndex>0); |
| 72 | } |
| 73 | |
| 74 | void |
| 75 | DTMFqueue::ResetDTMF() |
| 76 | { |
| 77 | _nextEmptyIndex = 0; |
| 78 | } |
| 79 | } // namespace webrtc |