blob: 6fa6d65f99a42cb9ea05ccafd70a529b0c054a2c [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
11#include "dtmf_queue.h"
12
13#include <string.h> //memset
14
15namespace webrtc {
16DTMFqueue::DTMFqueue():
henrike@webrtc.org65573f22011-12-13 19:17:27 +000017 _DTMFCritsect(CriticalSectionWrapper::CreateCriticalSection()),
niklase@google.com470e71d2011-07-07 08:21:25 +000018 _nextEmptyIndex(0)
19{
20 memset(_DTMFKey,0, sizeof(_DTMFKey));
21 memset(_DTMFLen,0, sizeof(_DTMFLen));
22 memset(_DTMFLevel,0, sizeof(_DTMFLevel));
23}
24
25DTMFqueue::~DTMFqueue()
26{
henrike@webrtc.org65573f22011-12-13 19:17:27 +000027 delete _DTMFCritsect;
niklase@google.com470e71d2011-07-07 08:21:25 +000028}
29
pbos@webrtc.org2f446732013-04-08 11:08:41 +000030int32_t
31DTMFqueue::AddDTMF(uint8_t key, uint16_t len, uint8_t level)
niklase@google.com470e71d2011-07-07 08:21:25 +000032{
33 CriticalSectionScoped lock(_DTMFCritsect);
34
35 if(_nextEmptyIndex >= DTMF_OUTBAND_MAX)
36 {
37 return -1;
38 }
pbos@webrtc.org2f446732013-04-08 11:08:41 +000039 int32_t index = _nextEmptyIndex;
niklase@google.com470e71d2011-07-07 08:21:25 +000040 _DTMFKey[index] = key;
41 _DTMFLen[index] = len;
42 _DTMFLevel[index] = level;
43 _nextEmptyIndex++;
44 return 0;
45}
46
pbos@webrtc.org2f446732013-04-08 11:08:41 +000047int8_t
48DTMFqueue::NextDTMF(uint8_t* DTMFKey, uint16_t* len, uint8_t* level)
niklase@google.com470e71d2011-07-07 08:21:25 +000049{
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.org2f446732013-04-08 11:08:41 +000060 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.com470e71d2011-07-07 08:21:25 +000063
64 _nextEmptyIndex--;
65 return 0;
66}
67
68bool
69DTMFqueue::PendingDTMF()
70{
71 return(_nextEmptyIndex>0);
72}
73
74void
75DTMFqueue::ResetDTMF()
76{
77 _nextEmptyIndex = 0;
78}
79} // namespace webrtc