• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 WEBRTC_AUDIO_DEVICE_FUNC_TEST_MANAGER_H
12 #define WEBRTC_AUDIO_DEVICE_FUNC_TEST_MANAGER_H
13 
14 #include "webrtc/modules/audio_device/audio_device_utility.h"
15 
16 #include <list>
17 #include <string>
18 
19 #include "webrtc/common_audio/resampler/include/resampler.h"
20 #include "webrtc/modules/audio_device/include/audio_device.h"
21 #include "webrtc/modules/audio_device/test/audio_device_test_defines.h"
22 #include "webrtc/system_wrappers/interface/file_wrapper.h"
23 #include "webrtc/typedefs.h"
24 
25 #if defined(WEBRTC_IOS) || defined(ANDROID)
26 #define USE_SLEEP_AS_PAUSE
27 #else
28 //#define USE_SLEEP_AS_PAUSE
29 #endif
30 
31 // Sets the default pause time if using sleep as pause
32 #define DEFAULT_PAUSE_TIME 5000
33 
34 #if defined(USE_SLEEP_AS_PAUSE)
35 #define PAUSE(a) SleepMs(a);
36 #else
37 #define PAUSE(a) AudioDeviceUtility::WaitForKey();
38 #endif
39 
40 #define ADM_AUDIO_LAYER AudioDeviceModule::kPlatformDefaultAudio
41 //#define ADM_AUDIO_LAYER AudioDeviceModule::kLinuxPulseAudio
42 
43 enum TestType
44 {
45     TTInvalid = -1,
46     TTAll = 0,
47     TTAudioLayerSelection = 1,
48     TTDeviceEnumeration = 2,
49     TTDeviceSelection = 3,
50     TTAudioTransport = 4,
51     TTSpeakerVolume = 5,
52     TTMicrophoneVolume = 6,
53     TTSpeakerMute = 7,
54     TTMicrophoneMute = 8,
55     TTMicrophoneBoost = 9,
56     TTMicrophoneAGC = 10,
57     TTLoopback = 11,
58     TTDeviceRemoval = 13,
59     TTMobileAPI = 14,
60     TTTest = 66,
61 };
62 
63 struct AudioPacket
64 {
65     uint8_t dataBuffer[4 * 960];
66     uint16_t nSamples;
67     uint16_t nBytesPerSample;
68     uint8_t nChannels;
69     uint32_t samplesPerSec;
70 };
71 
72 class ProcessThread;
73 
74 namespace webrtc
75 {
76 
77 class AudioDeviceModule;
78 class AudioEventObserver;
79 class AudioTransport;
80 
81 // ----------------------------------------------------------------------------
82 //  AudioEventObserver
83 // ----------------------------------------------------------------------------
84 
85 class AudioEventObserver: public AudioDeviceObserver
86 {
87 public:
88     virtual void OnErrorIsReported(const ErrorCode error);
89     virtual void OnWarningIsReported(const WarningCode warning);
90     AudioEventObserver(AudioDeviceModule* audioDevice);
91     ~AudioEventObserver();
92 public:
93     ErrorCode _error;
94     WarningCode _warning;
95 };
96 
97 // ----------------------------------------------------------------------------
98 //  AudioTransport
99 // ----------------------------------------------------------------------------
100 
101 class AudioTransportImpl: public AudioTransport
102 {
103 public:
104     virtual int32_t
105         RecordedDataIsAvailable(const void* audioSamples,
106                                 const uint32_t nSamples,
107                                 const uint8_t nBytesPerSample,
108                                 const uint8_t nChannels,
109                                 const uint32_t samplesPerSec,
110                                 const uint32_t totalDelayMS,
111                                 const int32_t clockDrift,
112                                 const uint32_t currentMicLevel,
113                                 const bool keyPressed,
114                                 uint32_t& newMicLevel);
115 
116     virtual int32_t NeedMorePlayData(const uint32_t nSamples,
117                                      const uint8_t nBytesPerSample,
118                                      const uint8_t nChannels,
119                                      const uint32_t samplesPerSec,
120                                      void* audioSamples,
121                                      uint32_t& nSamplesOut,
122                                      int64_t* elapsed_time_ms,
123                                      int64_t* ntp_time_ms);
124 
125     virtual int OnDataAvailable(const int voe_channels[],
126                                 int number_of_voe_channels,
127                                 const int16_t* audio_data,
128                                 int sample_rate,
129                                 int number_of_channels,
130                                 int number_of_frames,
131                                 int audio_delay_milliseconds,
132                                 int current_volume,
133                                 bool key_pressed,
134                                 bool need_audio_processing);
135 
136     virtual void PushCaptureData(int voe_channel, const void* audio_data,
137                                  int bits_per_sample, int sample_rate,
138                                  int number_of_channels,
139                                  int number_of_frames);
140 
141     virtual void PullRenderData(int bits_per_sample, int sample_rate,
142                                 int number_of_channels, int number_of_frames,
143                                 void* audio_data,
144                                 int64_t* elapsed_time_ms,
145                                 int64_t* ntp_time_ms);
146 
147     AudioTransportImpl(AudioDeviceModule* audioDevice);
148     ~AudioTransportImpl();
149 
150 public:
151     int32_t SetFilePlayout(bool enable, const char* fileName = NULL);
152     void SetFullDuplex(bool enable);
SetSpeakerVolume(bool enable)153     void SetSpeakerVolume(bool enable)
154     {
155         _speakerVolume = enable;
156     }
157     ;
SetSpeakerMute(bool enable)158     void SetSpeakerMute(bool enable)
159     {
160         _speakerMute = enable;
161     }
162     ;
SetMicrophoneMute(bool enable)163     void SetMicrophoneMute(bool enable)
164     {
165         _microphoneMute = enable;
166     }
167     ;
SetMicrophoneVolume(bool enable)168     void SetMicrophoneVolume(bool enable)
169     {
170         _microphoneVolume = enable;
171     }
172     ;
SetMicrophoneBoost(bool enable)173     void SetMicrophoneBoost(bool enable)
174     {
175         _microphoneBoost = enable;
176     }
177     ;
SetLoopbackMeasurements(bool enable)178     void SetLoopbackMeasurements(bool enable)
179     {
180         _loopBackMeasurements = enable;
181     }
182     ;
SetMicrophoneAGC(bool enable)183     void SetMicrophoneAGC(bool enable)
184     {
185         _microphoneAGC = enable;
186     }
187     ;
188 
189 private:
190     typedef std::list<AudioPacket*> AudioPacketList;
191     AudioDeviceModule* _audioDevice;
192 
193     bool _playFromFile;
194     bool _fullDuplex;
195     bool _speakerVolume;
196     bool _speakerMute;
197     bool _microphoneVolume;
198     bool _microphoneMute;
199     bool _microphoneBoost;
200     bool _microphoneAGC;
201     bool _loopBackMeasurements;
202 
203     FileWrapper& _playFile;
204 
205     uint32_t _recCount;
206     uint32_t _playCount;
207     AudioPacketList _audioList;
208 
209     Resampler _resampler;
210 };
211 
212 // ----------------------------------------------------------------------------
213 //  FuncTestManager
214 // ----------------------------------------------------------------------------
215 
216 class FuncTestManager
217 {
218 public:
219     FuncTestManager();
220     ~FuncTestManager();
221     int32_t Init();
222     int32_t Close();
223     int32_t DoTest(const TestType testType);
224 private:
225     int32_t TestAudioLayerSelection();
226     int32_t TestDeviceEnumeration();
227     int32_t TestDeviceSelection();
228     int32_t TestAudioTransport();
229     int32_t TestSpeakerVolume();
230     int32_t TestMicrophoneVolume();
231     int32_t TestSpeakerMute();
232     int32_t TestMicrophoneMute();
233     int32_t TestMicrophoneBoost();
234     int32_t TestLoopback();
235     int32_t TestDeviceRemoval();
236     int32_t TestExtra();
237     int32_t TestMicrophoneAGC();
238     int32_t SelectPlayoutDevice();
239     int32_t SelectRecordingDevice();
240     int32_t TestAdvancedMBAPI();
241 private:
242     // Paths to where the resource files to be used for this test are located.
243     std::string _playoutFile48;
244     std::string _playoutFile44;
245     std::string _playoutFile16;
246     std::string _playoutFile8;
247 
248     ProcessThread* _processThread;
249     AudioDeviceModule* _audioDevice;
250     AudioEventObserver* _audioEventObserver;
251     AudioTransportImpl* _audioTransport;
252 };
253 
254 }  // namespace webrtc
255 
256 #endif  // #ifndef WEBRTC_AUDIO_DEVICE_FUNC_TEST_MANAGER_H
257