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 | //----------------------------- |
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 DESTROY_ACM(acm) \ |
| 56 | do { \ |
| 57 | if (acm != NULL) { \ |
| 58 | AudioCodingModule::Destroy(acm); \ |
| 59 | acm = 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 | #define DELETE_POINTER(p) \ |
| 64 | do { \ |
| 65 | if (p != NULL) { \ |
| 66 | delete p; \ |
| 67 | p = NULL; \ |
| 68 | } \ |
| 69 | } while(0) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 70 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame^] | 71 | class ACMTestTimer { |
| 72 | public: |
| 73 | ACMTestTimer(); |
| 74 | ~ACMTestTimer(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 75 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame^] | 76 | void Reset(); |
| 77 | void Tick10ms(); |
| 78 | void Tick1ms(); |
| 79 | void Tick100ms(); |
| 80 | void Tick1sec(); |
| 81 | void CurrentTimeHMS(char* currTime); |
| 82 | void CurrentTime(unsigned long& h, unsigned char& m, unsigned char& s, |
| 83 | unsigned short& ms); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 84 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame^] | 85 | private: |
| 86 | void Adjust(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 87 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame^] | 88 | unsigned short _msec; |
| 89 | unsigned char _sec; |
| 90 | unsigned char _min; |
| 91 | unsigned long _hour; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 92 | }; |
| 93 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame^] | 94 | class CircularBuffer { |
| 95 | public: |
| 96 | CircularBuffer(uint32_t len); |
| 97 | ~CircularBuffer(); |
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 SetArithMean(bool enable); |
| 100 | void SetVariance(bool enable); |
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 | void Update(const double newVal); |
| 103 | void IsBufferFull(); |
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 | int16_t Variance(double& var); |
| 106 | int16_t ArithMean(double& mean); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 107 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame^] | 108 | protected: |
| 109 | double* _buff; |
| 110 | uint32_t _idx; |
| 111 | uint32_t _buffLen; |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 112 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame^] | 113 | bool _buffIsFull; |
| 114 | bool _calcAvg; |
| 115 | bool _calcVar; |
| 116 | double _sum; |
| 117 | double _sumSqr; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 118 | }; |
| 119 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame^] | 120 | int16_t ChooseCodec(CodecInst& codecInst); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 121 | |
| 122 | void PrintCodecs(); |
| 123 | |
| 124 | bool FixedPayloadTypeCodec(const char* payloadName); |
| 125 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame^] | 126 | class DTMFDetector : public AudioCodingFeedback { |
| 127 | public: |
| 128 | DTMFDetector(); |
| 129 | ~DTMFDetector(); |
| 130 | // used for inband DTMF detection |
| 131 | int32_t IncomingDtmf(const uint8_t digitDtmf, const bool toneEnded); |
| 132 | void PrintDetectedDigits(); |
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: |
| 135 | uint32_t _toneCntr[1000]; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 136 | |
| 137 | }; |
| 138 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame^] | 139 | class VADCallback : public ACMVADCallback { |
| 140 | public: |
| 141 | VADCallback(); |
| 142 | ~VADCallback() { |
| 143 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 144 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame^] | 145 | int32_t InFrameType(int16_t frameType); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 146 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame^] | 147 | void PrintFrameTypes(); |
| 148 | void Reset(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 149 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame^] | 150 | private: |
| 151 | uint32_t _numFrameTypes[6]; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 152 | }; |
| 153 | |
tina.legrand@webrtc.org | 73222cf | 2013-03-15 13:29:17 +0000 | [diff] [blame] | 154 | } // namespace webrtc |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 155 | |
tina.legrand@webrtc.org | 73222cf | 2013-03-15 13:29:17 +0000 | [diff] [blame] | 156 | #endif // WEBRTC_MODULES_AUDIO_CODING_MAIN_TEST_UTILITY_H_ |