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 | |
tina.legrand@webrtc.org | 73222cf | 2013-03-15 13:29:17 +0000 | [diff] [blame] | 11 | #ifndef WEBRTC_MODULES_AUDIO_CODING_MAIN_TEST_UTILITY_H_ |
| 12 | #define WEBRTC_MODULES_AUDIO_CODING_MAIN_TEST_UTILITY_H_ |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 13 | |
tina.legrand@webrtc.org | 73222cf | 2013-03-15 13:29:17 +0000 | [diff] [blame] | 14 | #include "testing/gtest/include/gtest/gtest.h" |
| 15 | #include "webrtc/modules/audio_coding/main/interface/audio_coding_module.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 | //----------------------------- |
| 20 | #define CHECK_ERROR(f) \ |
| 21 | do { \ |
kjellander@webrtc.org | 5490c71 | 2011-12-21 13:34:18 +0000 | [diff] [blame] | 22 | EXPECT_GE(f, 0) << "Error Calling API"; \ |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 23 | }while(0) |
| 24 | |
| 25 | //----------------------------- |
| 26 | #define CHECK_PROTECTED(f) \ |
| 27 | do { \ |
| 28 | if(f >= 0) { \ |
kjellander@webrtc.org | 5490c71 | 2011-12-21 13:34:18 +0000 | [diff] [blame] | 29 | ADD_FAILURE() << "Error Calling API"; \ |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 30 | } \ |
| 31 | else { \ |
| 32 | printf("An expected error is caught.\n"); \ |
| 33 | } \ |
| 34 | }while(0) |
| 35 | |
| 36 | //---------------------------- |
| 37 | #define CHECK_ERROR_MT(f) \ |
| 38 | do { \ |
| 39 | if(f < 0) { \ |
| 40 | fprintf(stderr, "Error Calling API in file %s at line %d \n", \ |
| 41 | __FILE__, __LINE__); \ |
| 42 | } \ |
| 43 | }while(0) |
| 44 | |
| 45 | //---------------------------- |
| 46 | #define CHECK_PROTECTED_MT(f) \ |
| 47 | do { \ |
| 48 | if(f >= 0) { \ |
| 49 | fprintf(stderr, "Error Calling API in file %s at line %d \n", \ |
| 50 | __FILE__, __LINE__); \ |
| 51 | } \ |
| 52 | else { \ |
| 53 | printf("An expected error is caught.\n"); \ |
| 54 | } \ |
| 55 | }while(0) |
| 56 | |
| 57 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 58 | #define DESTROY_ACM(acm) \ |
| 59 | do { \ |
| 60 | if(acm != NULL) { \ |
| 61 | AudioCodingModule::Destroy(acm); \ |
| 62 | acm = NULL; \ |
| 63 | } \ |
| 64 | } while(0) |
| 65 | |
| 66 | |
| 67 | #define DELETE_POINTER(p) \ |
| 68 | do { \ |
| 69 | if(p != NULL) { \ |
| 70 | delete p; \ |
| 71 | p = NULL; \ |
| 72 | } \ |
| 73 | } while(0) |
| 74 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 75 | class ACMTestTimer |
| 76 | { |
| 77 | public: |
| 78 | ACMTestTimer(); |
| 79 | ~ACMTestTimer(); |
| 80 | |
| 81 | void Reset(); |
| 82 | void Tick10ms(); |
| 83 | void Tick1ms(); |
| 84 | void Tick100ms(); |
| 85 | void Tick1sec(); |
| 86 | void CurrentTimeHMS( |
| 87 | char* currTime); |
| 88 | void CurrentTime( |
| 89 | unsigned long& h, |
| 90 | unsigned char& m, |
| 91 | unsigned char& s, |
| 92 | unsigned short& ms); |
| 93 | |
| 94 | private: |
| 95 | void Adjust(); |
| 96 | |
| 97 | unsigned short _msec; |
| 98 | unsigned char _sec; |
| 99 | unsigned char _min; |
| 100 | unsigned long _hour; |
| 101 | }; |
| 102 | |
| 103 | |
| 104 | |
| 105 | class CircularBuffer |
| 106 | { |
| 107 | public: |
| 108 | CircularBuffer(WebRtc_UWord32 len); |
| 109 | ~CircularBuffer(); |
| 110 | |
| 111 | void SetArithMean( |
| 112 | bool enable); |
| 113 | void SetVariance( |
| 114 | bool enable); |
| 115 | |
| 116 | void Update( |
| 117 | const double newVal); |
| 118 | void IsBufferFull(); |
| 119 | |
| 120 | WebRtc_Word16 Variance(double& var); |
| 121 | WebRtc_Word16 ArithMean(double& mean); |
| 122 | |
| 123 | protected: |
| 124 | double* _buff; |
| 125 | WebRtc_UWord32 _idx; |
| 126 | WebRtc_UWord32 _buffLen; |
| 127 | |
| 128 | bool _buffIsFull; |
| 129 | bool _calcAvg; |
| 130 | bool _calcVar; |
| 131 | double _sum; |
| 132 | double _sumSqr; |
| 133 | }; |
| 134 | |
| 135 | |
| 136 | |
| 137 | |
| 138 | |
| 139 | WebRtc_Word16 ChooseCodec( |
| 140 | CodecInst& codecInst); |
| 141 | |
| 142 | void PrintCodecs(); |
| 143 | |
| 144 | bool FixedPayloadTypeCodec(const char* payloadName); |
| 145 | |
| 146 | |
| 147 | |
| 148 | |
| 149 | class DTMFDetector: public AudioCodingFeedback |
| 150 | { |
| 151 | public: |
| 152 | DTMFDetector(); |
| 153 | ~DTMFDetector(); |
| 154 | // used for inband DTMF detection |
| 155 | WebRtc_Word32 IncomingDtmf(const WebRtc_UWord8 digitDtmf, const bool toneEnded); |
| 156 | void PrintDetectedDigits(); |
| 157 | |
| 158 | private: |
| 159 | WebRtc_UWord32 _toneCntr[1000]; |
| 160 | |
| 161 | }; |
| 162 | |
| 163 | |
| 164 | |
| 165 | |
| 166 | class VADCallback : public ACMVADCallback |
| 167 | { |
| 168 | public: |
| 169 | VADCallback(); |
| 170 | ~VADCallback(){} |
| 171 | |
| 172 | WebRtc_Word32 InFrameType( |
| 173 | WebRtc_Word16 frameType); |
| 174 | |
| 175 | void PrintFrameTypes(); |
| 176 | void Reset(); |
| 177 | |
| 178 | private: |
| 179 | WebRtc_UWord32 _numFrameTypes[6]; |
| 180 | }; |
| 181 | |
tina.legrand@webrtc.org | 73222cf | 2013-03-15 13:29:17 +0000 | [diff] [blame] | 182 | } // namespace webrtc |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 183 | |
tina.legrand@webrtc.org | 73222cf | 2013-03-15 13:29:17 +0000 | [diff] [blame] | 184 | #endif // WEBRTC_MODULES_AUDIO_CODING_MAIN_TEST_UTILITY_H_ |