Home | History | Annotate | Download | only in test
      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 
     11 #ifndef WEBRTC_MODULES_AUDIO_CODING_MAIN_TEST_UTILITY_H_
     12 #define WEBRTC_MODULES_AUDIO_CODING_MAIN_TEST_UTILITY_H_
     13 
     14 #include "testing/gtest/include/gtest/gtest.h"
     15 #include "webrtc/modules/audio_coding/main/interface/audio_coding_module.h"
     16 
     17 namespace webrtc {
     18 
     19 //-----------------------------
     20 #define CHECK_ERROR(f)                                                         \
     21   do {                                                                         \
     22     EXPECT_GE(f, 0) << "Error Calling API";                                    \
     23   } while(0)
     24 
     25 //-----------------------------
     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)
     34 
     35 //----------------------------
     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)
     43 
     44 //----------------------------
     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)
     54 
     55 #define DELETE_POINTER(p)                                                      \
     56   do {                                                                         \
     57     if (p != NULL) {                                                           \
     58       delete p;                                                                \
     59       p = NULL;                                                                \
     60     }                                                                          \
     61   } while(0)
     62 
     63 class ACMTestTimer {
     64  public:
     65   ACMTestTimer();
     66   ~ACMTestTimer();
     67 
     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);
     76 
     77  private:
     78   void Adjust();
     79 
     80   unsigned short _msec;
     81   unsigned char _sec;
     82   unsigned char _min;
     83   unsigned long _hour;
     84 };
     85 
     86 class CircularBuffer {
     87  public:
     88   CircularBuffer(uint32_t len);
     89   ~CircularBuffer();
     90 
     91   void SetArithMean(bool enable);
     92   void SetVariance(bool enable);
     93 
     94   void Update(const double newVal);
     95   void IsBufferFull();
     96 
     97   int16_t Variance(double& var);
     98   int16_t ArithMean(double& mean);
     99 
    100  protected:
    101   double* _buff;
    102   uint32_t _idx;
    103   uint32_t _buffLen;
    104 
    105   bool _buffIsFull;
    106   bool _calcAvg;
    107   bool _calcVar;
    108   double _sum;
    109   double _sumSqr;
    110 };
    111 
    112 int16_t ChooseCodec(CodecInst& codecInst);
    113 
    114 void PrintCodecs();
    115 
    116 bool FixedPayloadTypeCodec(const char* payloadName);
    117 
    118 class DTMFDetector : public AudioCodingFeedback {
    119  public:
    120   DTMFDetector();
    121   ~DTMFDetector();
    122   // used for inband DTMF detection
    123   int32_t IncomingDtmf(const uint8_t digitDtmf, const bool toneEnded);
    124   void PrintDetectedDigits();
    125 
    126  private:
    127   uint32_t _toneCntr[1000];
    128 
    129 };
    130 
    131 class VADCallback : public ACMVADCallback {
    132  public:
    133   VADCallback();
    134   ~VADCallback() {
    135   }
    136 
    137   int32_t InFrameType(int16_t frameType);
    138 
    139   void PrintFrameTypes();
    140   void Reset();
    141 
    142  private:
    143   uint32_t _numFrameTypes[6];
    144 };
    145 
    146 void UseLegacyAcm(webrtc::Config* config);
    147 
    148 void UseNewAcm(webrtc::Config* config);
    149 
    150 }  // namespace webrtc
    151 
    152 #endif  // WEBRTC_MODULES_AUDIO_CODING_MAIN_TEST_UTILITY_H_
    153