1 /*
2  *  Copyright (c) 2012 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 MODULES_AUDIO_CODING_TEST_APITEST_H_
12 #define MODULES_AUDIO_CODING_TEST_APITEST_H_
13 
14 #include <memory>
15 
16 #include "modules/audio_coding/include/audio_coding_module.h"
17 #include "modules/audio_coding/test/ACMTest.h"
18 #include "modules/audio_coding/test/Channel.h"
19 #include "modules/audio_coding/test/PCMFile.h"
20 #include "modules/audio_coding/test/utility.h"
21 #include "system_wrappers/include/event_wrapper.h"
22 #include "system_wrappers/include/rw_lock_wrapper.h"
23 
24 namespace webrtc {
25 
26 enum APITESTAction {
27   TEST_CHANGE_CODEC_ONLY = 0,
28   DTX_TEST = 1
29 };
30 
31 class APITest : public ACMTest {
32  public:
33   APITest();
34   ~APITest();
35 
36   void Perform();
37  private:
38   int16_t SetUp();
39 
40   static bool PushAudioThreadA(void* obj);
41   static bool PullAudioThreadA(void* obj);
42   static bool ProcessThreadA(void* obj);
43   static bool APIThreadA(void* obj);
44 
45   static bool PushAudioThreadB(void* obj);
46   static bool PullAudioThreadB(void* obj);
47   static bool ProcessThreadB(void* obj);
48   static bool APIThreadB(void* obj);
49 
50   void CheckVADStatus(char side);
51 
52   // Set Min delay, get delay, playout timestamp
53   void TestDelay(char side);
54 
55   // Unregister a codec & register again.
56   void TestRegisteration(char side);
57 
58   // Playout Mode, background noise mode.
59   // Receiver Frequency, playout frequency.
60   void TestPlayout(char receiveSide);
61 
62   //
63   void TestSendVAD(char side);
64 
65   void CurrentCodec(char side);
66 
67   void ChangeCodec(char side);
68 
69   void Wait(uint32_t waitLengthMs);
70 
71   void RunTest(char thread);
72 
73   bool PushAudioRunA();
74   bool PullAudioRunA();
75   bool ProcessRunA();
76   bool APIRunA();
77 
78   bool PullAudioRunB();
79   bool PushAudioRunB();
80   bool ProcessRunB();
81   bool APIRunB();
82 
83   //--- ACMs
84   std::unique_ptr<AudioCodingModule> _acmA;
85   std::unique_ptr<AudioCodingModule> _acmB;
86 
87   //--- Channels
88   Channel* _channel_A2B;
89   Channel* _channel_B2A;
90 
91   //--- I/O files
92   // A
93   PCMFile _inFileA;
94   PCMFile _outFileA;
95   // B
96   PCMFile _outFileB;
97   PCMFile _inFileB;
98 
99   //--- I/O params
100   // A
101   int32_t _outFreqHzA;
102   // B
103   int32_t _outFreqHzB;
104 
105   // Should we write to file.
106   // we might skip writing to file if we
107   // run the test for a long time.
108   bool _writeToFile;
109   //--- Events
110   // A
111   EventTimerWrapper* _pullEventA;      // pulling data from ACM
112   EventTimerWrapper* _pushEventA;      // pushing data to ACM
113   EventTimerWrapper* _processEventA;   // process
114   EventWrapper* _apiEventA;       // API calls
115   // B
116   EventTimerWrapper* _pullEventB;      // pulling data from ACM
117   EventTimerWrapper* _pushEventB;      // pushing data to ACM
118   EventTimerWrapper* _processEventB;   // process
119   EventWrapper* _apiEventB;       // API calls
120 
121   // keep track of the codec in either side.
122   uint8_t _codecCntrA;
123   uint8_t _codecCntrB;
124 
125   // Is set to true if there is no encoder in either side
126   bool _thereIsEncoderA;
127   bool _thereIsEncoderB;
128   bool _thereIsDecoderA;
129   bool _thereIsDecoderB;
130 
131   bool _sendVADA;
132   bool _sendDTXA;
133   ACMVADMode _sendVADModeA;
134 
135   bool _sendVADB;
136   bool _sendDTXB;
137   ACMVADMode _sendVADModeB;
138 
139   int32_t _minDelayA;
140   int32_t _minDelayB;
141   bool _payloadUsed[32];
142 
143   bool _verbose;
144 
145   int _dotPositionA;
146   int _dotMoveDirectionA;
147   int _dotPositionB;
148   int _dotMoveDirectionB;
149 
150   char _movingDot[41];
151 
152   VADCallback* _vadCallbackA;
153   VADCallback* _vadCallbackB;
154   RWLockWrapper& _apiTestRWLock;
155   bool _randomTest;
156   int _testNumA;
157   int _testNumB;
158 };
159 
160 }  // namespace webrtc
161 
162 #endif  // MODULES_AUDIO_CODING_TEST_APITEST_H_
163