niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
| 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 Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #ifndef MODULES_AUDIO_CODING_TEST_UTILITY_H_ |
| 12 | #define MODULES_AUDIO_CODING_TEST_UTILITY_H_ |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 13 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 14 | #include "modules/audio_coding/include/audio_coding_module.h" |
| 15 | #include "test/gtest.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 16 | |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 17 | namespace webrtc { |
| 18 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 19 | //----------------------------- |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame^] | 20 | #define CHECK_ERROR(f) \ |
| 21 | do { \ |
| 22 | EXPECT_GE(f, 0) << "Error Calling API"; \ |
| 23 | } while (0) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 24 | |
| 25 | //----------------------------- |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame^] | 26 | #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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 34 | |
| 35 | //---------------------------- |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame^] | 36 | #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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 43 | |
| 44 | //---------------------------- |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame^] | 45 | #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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 54 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame^] | 55 | #define DELETE_POINTER(p) \ |
| 56 | do { \ |
| 57 | if (p != NULL) { \ |
| 58 | delete p; \ |
| 59 | p = NULL; \ |
| 60 | } \ |
| 61 | } while (0) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 62 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 63 | class ACMTestTimer { |
| 64 | public: |
| 65 | ACMTestTimer(); |
| 66 | ~ACMTestTimer(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 67 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 68 | void Reset(); |
| 69 | void Tick10ms(); |
| 70 | void Tick1ms(); |
| 71 | void Tick100ms(); |
| 72 | void Tick1sec(); |
| 73 | void CurrentTimeHMS(char* currTime); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame^] | 74 | void CurrentTime(unsigned long& h, |
| 75 | unsigned char& m, |
| 76 | unsigned char& s, |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 77 | unsigned short& ms); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 78 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 79 | private: |
| 80 | void Adjust(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 81 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 82 | unsigned short _msec; |
| 83 | unsigned char _sec; |
| 84 | unsigned char _min; |
| 85 | unsigned long _hour; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 86 | }; |
| 87 | |
brandtr | 6607d84 | 2017-02-11 00:24:10 -0800 | [diff] [blame] | 88 | // To avoid clashes with CircularBuffer in APM. |
| 89 | namespace test { |
| 90 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 91 | class CircularBuffer { |
| 92 | public: |
| 93 | CircularBuffer(uint32_t len); |
| 94 | ~CircularBuffer(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 95 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 96 | void SetArithMean(bool enable); |
| 97 | void SetVariance(bool enable); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 98 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 99 | void Update(const double newVal); |
| 100 | void IsBufferFull(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 101 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 102 | int16_t Variance(double& var); |
| 103 | int16_t ArithMean(double& mean); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 104 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 105 | protected: |
| 106 | double* _buff; |
| 107 | uint32_t _idx; |
| 108 | uint32_t _buffLen; |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 109 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 110 | bool _buffIsFull; |
| 111 | bool _calcAvg; |
| 112 | bool _calcVar; |
| 113 | double _sum; |
| 114 | double _sumSqr; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 115 | }; |
| 116 | |
brandtr | 6607d84 | 2017-02-11 00:24:10 -0800 | [diff] [blame] | 117 | } // namespace test |
| 118 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 119 | int16_t ChooseCodec(CodecInst& codecInst); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 120 | |
| 121 | void PrintCodecs(); |
| 122 | |
| 123 | bool FixedPayloadTypeCodec(const char* payloadName); |
| 124 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 125 | class VADCallback : public ACMVADCallback { |
| 126 | public: |
| 127 | VADCallback(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 128 | |
kwiberg | 65fc8b9 | 2016-08-29 10:05:24 -0700 | [diff] [blame] | 129 | int32_t InFrameType(FrameType frame_type) override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 130 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 131 | void PrintFrameTypes(); |
| 132 | void Reset(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 133 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 134 | private: |
henrik.lundin@webrtc.org | e9217b4 | 2015-03-06 07:50:34 +0000 | [diff] [blame] | 135 | uint32_t _numFrameTypes[5]; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 136 | }; |
| 137 | |
tina.legrand@webrtc.org | 73222cf | 2013-03-15 13:29:17 +0000 | [diff] [blame] | 138 | } // namespace webrtc |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 139 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 140 | #endif // MODULES_AUDIO_CODING_TEST_UTILITY_H_ |