blob: 4e3d525f48d1aa4b023c0b545c8d9ef179b986f7 [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//-----------------------------
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000020#define CHECK_ERROR(f) \
21 do { \
22 EXPECT_GE(f, 0) << "Error Calling API"; \
23 } while(0)
niklase@google.com470e71d2011-07-07 08:21:25 +000024
25//-----------------------------
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000026#define CHECK_PROTECTED(f) \
27 do { \
28 if (f >= 0) { \
29 ADD_FAILURE() << "Error Calling API"; \
30 } else { \
31 printf("An expected error is caught.\n"); \
32 } \
33 } while(0)
niklase@google.com470e71d2011-07-07 08:21:25 +000034
35//----------------------------
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000036#define CHECK_ERROR_MT(f) \
37 do { \
38 if (f < 0) { \
39 fprintf(stderr, "Error Calling API in file %s at line %d \n", \
40 __FILE__, __LINE__); \
41 } \
42 } while(0)
niklase@google.com470e71d2011-07-07 08:21:25 +000043
44//----------------------------
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000045#define CHECK_PROTECTED_MT(f) \
46 do { \
47 if (f >= 0) { \
48 fprintf(stderr, "Error Calling API in file %s at line %d \n", \
49 __FILE__, __LINE__); \
50 } else { \
51 printf("An expected error is caught.\n"); \
52 } \
53 } while(0)
niklase@google.com470e71d2011-07-07 08:21:25 +000054
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000055#define DESTROY_ACM(acm) \
56 do { \
57 if (acm != NULL) { \
58 AudioCodingModule::Destroy(acm); \
59 acm = NULL; \
60 } \
61 } while(0)
niklase@google.com470e71d2011-07-07 08:21:25 +000062
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000063#define DELETE_POINTER(p) \
64 do { \
65 if (p != NULL) { \
66 delete p; \
67 p = NULL; \
68 } \
69 } while(0)
niklase@google.com470e71d2011-07-07 08:21:25 +000070
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000071class ACMTestTimer {
72 public:
73 ACMTestTimer();
74 ~ACMTestTimer();
niklase@google.com470e71d2011-07-07 08:21:25 +000075
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000076 void Reset();
77 void Tick10ms();
78 void Tick1ms();
79 void Tick100ms();
80 void Tick1sec();
81 void CurrentTimeHMS(char* currTime);
82 void CurrentTime(unsigned long& h, unsigned char& m, unsigned char& s,
83 unsigned short& ms);
niklase@google.com470e71d2011-07-07 08:21:25 +000084
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000085 private:
86 void Adjust();
niklase@google.com470e71d2011-07-07 08:21:25 +000087
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000088 unsigned short _msec;
89 unsigned char _sec;
90 unsigned char _min;
91 unsigned long _hour;
niklase@google.com470e71d2011-07-07 08:21:25 +000092};
93
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000094class CircularBuffer {
95 public:
96 CircularBuffer(uint32_t len);
97 ~CircularBuffer();
niklase@google.com470e71d2011-07-07 08:21:25 +000098
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000099 void SetArithMean(bool enable);
100 void SetVariance(bool enable);
niklase@google.com470e71d2011-07-07 08:21:25 +0000101
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000102 void Update(const double newVal);
103 void IsBufferFull();
niklase@google.com470e71d2011-07-07 08:21:25 +0000104
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000105 int16_t Variance(double& var);
106 int16_t ArithMean(double& mean);
niklase@google.com470e71d2011-07-07 08:21:25 +0000107
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000108 protected:
109 double* _buff;
110 uint32_t _idx;
111 uint32_t _buffLen;
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000112
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000113 bool _buffIsFull;
114 bool _calcAvg;
115 bool _calcVar;
116 double _sum;
117 double _sumSqr;
niklase@google.com470e71d2011-07-07 08:21:25 +0000118};
119
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000120int16_t ChooseCodec(CodecInst& codecInst);
niklase@google.com470e71d2011-07-07 08:21:25 +0000121
122void PrintCodecs();
123
124bool FixedPayloadTypeCodec(const char* payloadName);
125
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000126class DTMFDetector : public AudioCodingFeedback {
127 public:
128 DTMFDetector();
129 ~DTMFDetector();
130 // used for inband DTMF detection
131 int32_t IncomingDtmf(const uint8_t digitDtmf, const bool toneEnded);
132 void PrintDetectedDigits();
niklase@google.com470e71d2011-07-07 08:21:25 +0000133
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000134 private:
135 uint32_t _toneCntr[1000];
niklase@google.com470e71d2011-07-07 08:21:25 +0000136
137};
138
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000139class VADCallback : public ACMVADCallback {
140 public:
141 VADCallback();
142 ~VADCallback() {
143 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000144
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000145 int32_t InFrameType(int16_t frameType);
niklase@google.com470e71d2011-07-07 08:21:25 +0000146
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000147 void PrintFrameTypes();
148 void Reset();
niklase@google.com470e71d2011-07-07 08:21:25 +0000149
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000150 private:
151 uint32_t _numFrameTypes[6];
niklase@google.com470e71d2011-07-07 08:21:25 +0000152};
153
tina.legrand@webrtc.org73222cf2013-03-15 13:29:17 +0000154} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000155
tina.legrand@webrtc.org73222cf2013-03-15 13:29:17 +0000156#endif // WEBRTC_MODULES_AUDIO_CODING_MAIN_TEST_UTILITY_H_