blob: 887c73535024250c2751550f64e86bac9faf17ae [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#ifndef ACM_TEST_UTILITY_H
12#define ACM_TEST_UTILITY_H
13
14#include "audio_coding_module.h"
kjellander@webrtc.org5490c712011-12-21 13:34:18 +000015#include "gtest/gtest.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000016
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000017namespace webrtc {
18
niklase@google.com470e71d2011-07-07 08:21:25 +000019//-----------------------------
20#define CHECK_ERROR(f) \
21 do { \
kjellander@webrtc.org5490c712011-12-21 13:34:18 +000022 EXPECT_GE(f, 0) << "Error Calling API"; \
niklase@google.com470e71d2011-07-07 08:21:25 +000023 }while(0)
24
25//-----------------------------
26#define CHECK_PROTECTED(f) \
27 do { \
28 if(f >= 0) { \
kjellander@webrtc.org5490c712011-12-21 13:34:18 +000029 ADD_FAILURE() << "Error Calling API"; \
niklase@google.com470e71d2011-07-07 08:21:25 +000030 } \
31 else { \
32 printf("An expected error is caught.\n"); \
33 } \
34 }while(0)
35
36//----------------------------
37#define CHECK_ERROR_MT(f) \
38 do { \
39 if(f < 0) { \
40 fprintf(stderr, "Error Calling API in file %s at line %d \n", \
41 __FILE__, __LINE__); \
42 } \
43 }while(0)
44
45//----------------------------
46#define CHECK_PROTECTED_MT(f) \
47 do { \
48 if(f >= 0) { \
49 fprintf(stderr, "Error Calling API in file %s at line %d \n", \
50 __FILE__, __LINE__); \
51 } \
52 else { \
53 printf("An expected error is caught.\n"); \
54 } \
55 }while(0)
56
57
58
59#ifdef WIN32
60 /* Exclude rarely-used stuff from Windows headers */
61 //#define WIN32_LEAN_AND_MEAN
62 /* OS-dependent case-insensitive string comparison */
63 #define STR_CASE_CMP(x,y) ::_stricmp(x,y)
64#else
65 /* OS-dependent case-insensitive string comparison */
66 #define STR_CASE_CMP(x,y) ::strcasecmp(x,y)
67#endif
68
69#define DESTROY_ACM(acm) \
70 do { \
71 if(acm != NULL) { \
72 AudioCodingModule::Destroy(acm); \
73 acm = NULL; \
74 } \
75 } while(0)
76
77
78#define DELETE_POINTER(p) \
79 do { \
80 if(p != NULL) { \
81 delete p; \
82 p = NULL; \
83 } \
84 } while(0)
85
niklase@google.com470e71d2011-07-07 08:21:25 +000086class ACMTestTimer
87{
88public:
89 ACMTestTimer();
90 ~ACMTestTimer();
91
92 void Reset();
93 void Tick10ms();
94 void Tick1ms();
95 void Tick100ms();
96 void Tick1sec();
97 void CurrentTimeHMS(
98 char* currTime);
99 void CurrentTime(
100 unsigned long& h,
101 unsigned char& m,
102 unsigned char& s,
103 unsigned short& ms);
104
105private:
106 void Adjust();
107
108 unsigned short _msec;
109 unsigned char _sec;
110 unsigned char _min;
111 unsigned long _hour;
112};
113
114
115
116class CircularBuffer
117{
118public:
119 CircularBuffer(WebRtc_UWord32 len);
120 ~CircularBuffer();
121
122 void SetArithMean(
123 bool enable);
124 void SetVariance(
125 bool enable);
126
127 void Update(
128 const double newVal);
129 void IsBufferFull();
130
131 WebRtc_Word16 Variance(double& var);
132 WebRtc_Word16 ArithMean(double& mean);
133
134protected:
135 double* _buff;
136 WebRtc_UWord32 _idx;
137 WebRtc_UWord32 _buffLen;
138
139 bool _buffIsFull;
140 bool _calcAvg;
141 bool _calcVar;
142 double _sum;
143 double _sumSqr;
144};
145
146
147
148
149
150WebRtc_Word16 ChooseCodec(
151 CodecInst& codecInst);
152
153void PrintCodecs();
154
155bool FixedPayloadTypeCodec(const char* payloadName);
156
157
158
159
160class DTMFDetector: public AudioCodingFeedback
161{
162public:
163 DTMFDetector();
164 ~DTMFDetector();
165 // used for inband DTMF detection
166 WebRtc_Word32 IncomingDtmf(const WebRtc_UWord8 digitDtmf, const bool toneEnded);
167 void PrintDetectedDigits();
168
169private:
170 WebRtc_UWord32 _toneCntr[1000];
171
172};
173
174
175
176
177class VADCallback : public ACMVADCallback
178{
179public:
180 VADCallback();
181 ~VADCallback(){}
182
183 WebRtc_Word32 InFrameType(
184 WebRtc_Word16 frameType);
185
186 void PrintFrameTypes();
187 void Reset();
188
189private:
190 WebRtc_UWord32 _numFrameTypes[6];
191};
192
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +0000193} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000194
195#endif // ACM_TEST_UTILITY_H