blob: 8af36751673426403738323920519a93a4129cd4 [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
kjellander3e6db232015-11-26 04:44:54 -080011#ifndef WEBRTC_MODULES_AUDIO_CODING_TEST_UTILITY_H_
12#define WEBRTC_MODULES_AUDIO_CODING_TEST_UTILITY_H_
niklase@google.com470e71d2011-07-07 08:21:25 +000013
kjellander3e6db232015-11-26 04:44:54 -080014#include "webrtc/modules/audio_coding/include/audio_coding_module.h"
kwibergac9f8762016-09-30 22:29:43 -070015#include "webrtc/test/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//-----------------------------
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 DELETE_POINTER(p) \
56 do { \
57 if (p != NULL) { \
58 delete p; \
59 p = NULL; \
60 } \
61 } while(0)
niklase@google.com470e71d2011-07-07 08:21:25 +000062
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000063class ACMTestTimer {
64 public:
65 ACMTestTimer();
66 ~ACMTestTimer();
niklase@google.com470e71d2011-07-07 08:21:25 +000067
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000068 void Reset();
69 void Tick10ms();
70 void Tick1ms();
71 void Tick100ms();
72 void Tick1sec();
73 void CurrentTimeHMS(char* currTime);
74 void CurrentTime(unsigned long& h, unsigned char& m, unsigned char& s,
75 unsigned short& ms);
niklase@google.com470e71d2011-07-07 08:21:25 +000076
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000077 private:
78 void Adjust();
niklase@google.com470e71d2011-07-07 08:21:25 +000079
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000080 unsigned short _msec;
81 unsigned char _sec;
82 unsigned char _min;
83 unsigned long _hour;
niklase@google.com470e71d2011-07-07 08:21:25 +000084};
85
brandtr6607d842017-02-11 00:24:10 -080086// To avoid clashes with CircularBuffer in APM.
87namespace test {
88
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000089class CircularBuffer {
90 public:
91 CircularBuffer(uint32_t len);
92 ~CircularBuffer();
niklase@google.com470e71d2011-07-07 08:21:25 +000093
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000094 void SetArithMean(bool enable);
95 void SetVariance(bool enable);
niklase@google.com470e71d2011-07-07 08:21:25 +000096
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000097 void Update(const double newVal);
98 void IsBufferFull();
niklase@google.com470e71d2011-07-07 08:21:25 +000099
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000100 int16_t Variance(double& var);
101 int16_t ArithMean(double& mean);
niklase@google.com470e71d2011-07-07 08:21:25 +0000102
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000103 protected:
104 double* _buff;
105 uint32_t _idx;
106 uint32_t _buffLen;
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000107
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000108 bool _buffIsFull;
109 bool _calcAvg;
110 bool _calcVar;
111 double _sum;
112 double _sumSqr;
niklase@google.com470e71d2011-07-07 08:21:25 +0000113};
114
brandtr6607d842017-02-11 00:24:10 -0800115} // namespace test
116
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000117int16_t ChooseCodec(CodecInst& codecInst);
niklase@google.com470e71d2011-07-07 08:21:25 +0000118
119void PrintCodecs();
120
121bool FixedPayloadTypeCodec(const char* payloadName);
122
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000123class VADCallback : public ACMVADCallback {
124 public:
125 VADCallback();
niklase@google.com470e71d2011-07-07 08:21:25 +0000126
kwiberg65fc8b92016-08-29 10:05:24 -0700127 int32_t InFrameType(FrameType frame_type) override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000128
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000129 void PrintFrameTypes();
130 void Reset();
niklase@google.com470e71d2011-07-07 08:21:25 +0000131
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000132 private:
henrik.lundin@webrtc.orge9217b42015-03-06 07:50:34 +0000133 uint32_t _numFrameTypes[5];
niklase@google.com470e71d2011-07-07 08:21:25 +0000134};
135
tina.legrand@webrtc.org73222cf2013-03-15 13:29:17 +0000136} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000137
kjellander3e6db232015-11-26 04:44:54 -0800138#endif // WEBRTC_MODULES_AUDIO_CODING_TEST_UTILITY_H_