blob: 6f17df5bdf66e26eb9d951ea93343d35a1f54ede [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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef MODULES_AUDIO_CODING_TEST_UTILITY_H_
12#define MODULES_AUDIO_CODING_TEST_UTILITY_H_
niklase@google.com470e71d2011-07-07 08:21:25 +000013
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020014#include "modules/audio_coding/include/audio_coding_module.h"
15#include "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//-----------------------------
Yves Gerey665174f2018-06-19 15:03:05 +020020#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//-----------------------------
Yves Gerey665174f2018-06-19 15:03:05 +020026#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//----------------------------
Yves Gerey665174f2018-06-19 15:03:05 +020036#define CHECK_ERROR_MT(f) \
37 do { \
38 if (f < 0) { \
39 fprintf(stderr, "Error Calling API in file %s at line %d \n", __FILE__, \
40 __LINE__); \
41 } \
42 } while (0)
niklase@google.com470e71d2011-07-07 08:21:25 +000043
44//----------------------------
Yves Gerey665174f2018-06-19 15:03:05 +020045#define CHECK_PROTECTED_MT(f) \
46 do { \
47 if (f >= 0) { \
48 fprintf(stderr, "Error Calling API in file %s at line %d \n", __FILE__, \
49 __LINE__); \
50 } else { \
51 printf("An expected error is caught.\n"); \
52 } \
53 } while (0)
niklase@google.com470e71d2011-07-07 08:21:25 +000054
Yves Gerey665174f2018-06-19 15:03:05 +020055#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);
Yves Gerey665174f2018-06-19 15:03:05 +020074 void CurrentTime(unsigned long& h,
75 unsigned char& m,
76 unsigned char& s,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000077 unsigned short& ms);
niklase@google.com470e71d2011-07-07 08:21:25 +000078
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000079 private:
80 void Adjust();
niklase@google.com470e71d2011-07-07 08:21:25 +000081
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000082 unsigned short _msec;
83 unsigned char _sec;
84 unsigned char _min;
85 unsigned long _hour;
niklase@google.com470e71d2011-07-07 08:21:25 +000086};
87
brandtr6607d842017-02-11 00:24:10 -080088// To avoid clashes with CircularBuffer in APM.
89namespace test {
90
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000091class CircularBuffer {
92 public:
93 CircularBuffer(uint32_t len);
94 ~CircularBuffer();
niklase@google.com470e71d2011-07-07 08:21:25 +000095
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000096 void SetArithMean(bool enable);
97 void SetVariance(bool enable);
niklase@google.com470e71d2011-07-07 08:21:25 +000098
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000099 void Update(const double newVal);
100 void IsBufferFull();
niklase@google.com470e71d2011-07-07 08:21:25 +0000101
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000102 int16_t Variance(double& var);
103 int16_t ArithMean(double& mean);
niklase@google.com470e71d2011-07-07 08:21:25 +0000104
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000105 protected:
106 double* _buff;
107 uint32_t _idx;
108 uint32_t _buffLen;
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000109
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000110 bool _buffIsFull;
111 bool _calcAvg;
112 bool _calcVar;
113 double _sum;
114 double _sumSqr;
niklase@google.com470e71d2011-07-07 08:21:25 +0000115};
116
brandtr6607d842017-02-11 00:24:10 -0800117} // namespace test
118
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000119int16_t ChooseCodec(CodecInst& codecInst);
niklase@google.com470e71d2011-07-07 08:21:25 +0000120
121void PrintCodecs();
122
123bool FixedPayloadTypeCodec(const char* payloadName);
124
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000125class VADCallback : public ACMVADCallback {
126 public:
127 VADCallback();
niklase@google.com470e71d2011-07-07 08:21:25 +0000128
kwiberg65fc8b92016-08-29 10:05:24 -0700129 int32_t InFrameType(FrameType frame_type) override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000130
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000131 void PrintFrameTypes();
132 void Reset();
niklase@google.com470e71d2011-07-07 08:21:25 +0000133
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000134 private:
henrik.lundin@webrtc.orge9217b42015-03-06 07:50:34 +0000135 uint32_t _numFrameTypes[5];
niklase@google.com470e71d2011-07-07 08:21:25 +0000136};
137
tina.legrand@webrtc.org73222cf2013-03-15 13:29:17 +0000138} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000139
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200140#endif // MODULES_AUDIO_CODING_TEST_UTILITY_H_