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 | |
kjellander | 3e6db23 | 2015-11-26 04:44:54 -0800 | [diff] [blame] | 11 | #ifndef WEBRTC_MODULES_AUDIO_CODING_TEST_UTILITY_H_ |
| 12 | #define WEBRTC_MODULES_AUDIO_CODING_TEST_UTILITY_H_ |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 13 | |
kjellander | 3e6db23 | 2015-11-26 04:44:54 -0800 | [diff] [blame] | 14 | #include "webrtc/modules/audio_coding/include/audio_coding_module.h" |
kwiberg | ac9f876 | 2016-09-30 22:29:43 -0700 | [diff] [blame] | 15 | #include "webrtc/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 | //----------------------------- |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [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 | //----------------------------- |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [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 | //---------------------------- |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [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", \ |
| 40 | __FILE__, __LINE__); \ |
| 41 | } \ |
| 42 | } while(0) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 43 | |
| 44 | //---------------------------- |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [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", \ |
| 49 | __FILE__, __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 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [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); |
| 74 | void CurrentTime(unsigned long& h, unsigned char& m, unsigned char& s, |
| 75 | unsigned short& ms); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 76 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 77 | private: |
| 78 | void Adjust(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 79 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 80 | unsigned short _msec; |
| 81 | unsigned char _sec; |
| 82 | unsigned char _min; |
| 83 | unsigned long _hour; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 84 | }; |
| 85 | |
brandtr | 6607d84 | 2017-02-11 00:24:10 -0800 | [diff] [blame^] | 86 | // To avoid clashes with CircularBuffer in APM. |
| 87 | namespace test { |
| 88 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 89 | class CircularBuffer { |
| 90 | public: |
| 91 | CircularBuffer(uint32_t len); |
| 92 | ~CircularBuffer(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 93 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 94 | void SetArithMean(bool enable); |
| 95 | void SetVariance(bool enable); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 96 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 97 | void Update(const double newVal); |
| 98 | void IsBufferFull(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 99 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 100 | int16_t Variance(double& var); |
| 101 | int16_t ArithMean(double& mean); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 102 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 103 | protected: |
| 104 | double* _buff; |
| 105 | uint32_t _idx; |
| 106 | uint32_t _buffLen; |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 107 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 108 | bool _buffIsFull; |
| 109 | bool _calcAvg; |
| 110 | bool _calcVar; |
| 111 | double _sum; |
| 112 | double _sumSqr; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 113 | }; |
| 114 | |
brandtr | 6607d84 | 2017-02-11 00:24:10 -0800 | [diff] [blame^] | 115 | } // namespace test |
| 116 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 117 | int16_t ChooseCodec(CodecInst& codecInst); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 118 | |
| 119 | void PrintCodecs(); |
| 120 | |
| 121 | bool FixedPayloadTypeCodec(const char* payloadName); |
| 122 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 123 | class VADCallback : public ACMVADCallback { |
| 124 | public: |
| 125 | VADCallback(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 126 | |
kwiberg | 65fc8b9 | 2016-08-29 10:05:24 -0700 | [diff] [blame] | 127 | int32_t InFrameType(FrameType frame_type) override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 128 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 129 | void PrintFrameTypes(); |
| 130 | void Reset(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 131 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 132 | private: |
henrik.lundin@webrtc.org | e9217b4 | 2015-03-06 07:50:34 +0000 | [diff] [blame] | 133 | uint32_t _numFrameTypes[5]; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 134 | }; |
| 135 | |
tina.legrand@webrtc.org | 73222cf | 2013-03-15 13:29:17 +0000 | [diff] [blame] | 136 | } // namespace webrtc |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 137 | |
kjellander | 3e6db23 | 2015-11-26 04:44:54 -0800 | [diff] [blame] | 138 | #endif // WEBRTC_MODULES_AUDIO_CODING_TEST_UTILITY_H_ |