blob: a4a89d1f9ac8c5b19ad486c268fed6dc4dd5da00 [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
tina.legrand@webrtc.org73222cf2013-03-15 13:29:17 +000011#ifndef WEBRTC_MODULES_AUDIO_CODING_MAIN_TEST_UTILITY_H_
12#define WEBRTC_MODULES_AUDIO_CODING_MAIN_TEST_UTILITY_H_
niklase@google.com470e71d2011-07-07 08:21:25 +000013
tina.legrand@webrtc.org73222cf2013-03-15 13:29:17 +000014#include "testing/gtest/include/gtest/gtest.h"
15#include "webrtc/modules/audio_coding/main/interface/audio_coding_module.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
niklase@google.com470e71d2011-07-07 08:21:25 +000058#define DESTROY_ACM(acm) \
59 do { \
60 if(acm != NULL) { \
61 AudioCodingModule::Destroy(acm); \
62 acm = NULL; \
63 } \
64 } while(0)
65
66
67#define DELETE_POINTER(p) \
68 do { \
69 if(p != NULL) { \
70 delete p; \
71 p = NULL; \
72 } \
73 } while(0)
74
niklase@google.com470e71d2011-07-07 08:21:25 +000075class ACMTestTimer
76{
77public:
78 ACMTestTimer();
79 ~ACMTestTimer();
80
81 void Reset();
82 void Tick10ms();
83 void Tick1ms();
84 void Tick100ms();
85 void Tick1sec();
86 void CurrentTimeHMS(
87 char* currTime);
88 void CurrentTime(
89 unsigned long& h,
90 unsigned char& m,
91 unsigned char& s,
92 unsigned short& ms);
93
94private:
95 void Adjust();
96
97 unsigned short _msec;
98 unsigned char _sec;
99 unsigned char _min;
100 unsigned long _hour;
101};
102
103
104
105class CircularBuffer
106{
107public:
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000108 CircularBuffer(uint32_t len);
niklase@google.com470e71d2011-07-07 08:21:25 +0000109 ~CircularBuffer();
110
111 void SetArithMean(
112 bool enable);
113 void SetVariance(
114 bool enable);
115
116 void Update(
117 const double newVal);
118 void IsBufferFull();
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000119
120 int16_t Variance(double& var);
121 int16_t ArithMean(double& mean);
niklase@google.com470e71d2011-07-07 08:21:25 +0000122
123protected:
124 double* _buff;
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000125 uint32_t _idx;
126 uint32_t _buffLen;
niklase@google.com470e71d2011-07-07 08:21:25 +0000127
128 bool _buffIsFull;
129 bool _calcAvg;
130 bool _calcVar;
131 double _sum;
132 double _sumSqr;
133};
134
135
136
137
138
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000139int16_t ChooseCodec(
niklase@google.com470e71d2011-07-07 08:21:25 +0000140 CodecInst& codecInst);
141
142void PrintCodecs();
143
144bool FixedPayloadTypeCodec(const char* payloadName);
145
146
147
148
149class DTMFDetector: public AudioCodingFeedback
150{
151public:
152 DTMFDetector();
153 ~DTMFDetector();
154 // used for inband DTMF detection
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000155 int32_t IncomingDtmf(const uint8_t digitDtmf, const bool toneEnded);
niklase@google.com470e71d2011-07-07 08:21:25 +0000156 void PrintDetectedDigits();
157
158private:
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000159 uint32_t _toneCntr[1000];
niklase@google.com470e71d2011-07-07 08:21:25 +0000160
161};
162
163
164
165
166class VADCallback : public ACMVADCallback
167{
168public:
169 VADCallback();
170 ~VADCallback(){}
171
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000172 int32_t InFrameType(
173 int16_t frameType);
niklase@google.com470e71d2011-07-07 08:21:25 +0000174
175 void PrintFrameTypes();
176 void Reset();
177
178private:
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000179 uint32_t _numFrameTypes[6];
niklase@google.com470e71d2011-07-07 08:21:25 +0000180};
181
tina.legrand@webrtc.org73222cf2013-03-15 13:29:17 +0000182} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000183
tina.legrand@webrtc.org73222cf2013-03-15 13:29:17 +0000184#endif // WEBRTC_MODULES_AUDIO_CODING_MAIN_TEST_UTILITY_H_