2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
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.
11 #ifndef WEBRTC_AUDIO_DEVICE_FUNC_TEST_MANAGER_H
12 #define WEBRTC_AUDIO_DEVICE_FUNC_TEST_MANAGER_H
14 #include "webrtc/modules/audio_device/audio_device_utility.h"
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"
25 #if defined(WEBRTC_IOS) || defined(ANDROID)
26 #define USE_SLEEP_AS_PAUSE
28 //#define USE_SLEEP_AS_PAUSE
31 // Sets the default pause time if using sleep as pause
32 #define DEFAULT_PAUSE_TIME 5000
34 #if defined(USE_SLEEP_AS_PAUSE)
35 #define PAUSE(a) SleepMs(a);
37 #define PAUSE(a) AudioDeviceUtility::WaitForKey();
40 #define ADM_AUDIO_LAYER AudioDeviceModule::kPlatformDefaultAudio
41 //#define ADM_AUDIO_LAYER AudioDeviceModule::kLinuxPulseAudio
47 TTAudioLayerSelection = 1,
48 TTDeviceEnumeration = 2,
49 TTDeviceSelection = 3,
52 TTMicrophoneVolume = 6,
55 TTMicrophoneBoost = 9,
65 uint8_t dataBuffer[4 * 960];
67 uint16_t nBytesPerSample;
69 uint32_t samplesPerSec;
77 class AudioDeviceModule;
78 class AudioEventObserver;
81 // ----------------------------------------------------------------------------
83 // ----------------------------------------------------------------------------
85 class AudioEventObserver: public AudioDeviceObserver
88 virtual void OnErrorIsReported(const ErrorCode error);
89 virtual void OnWarningIsReported(const WarningCode warning);
90 AudioEventObserver(AudioDeviceModule* audioDevice);
91 ~AudioEventObserver();
97 // ----------------------------------------------------------------------------
99 // ----------------------------------------------------------------------------
101 class AudioTransportImpl: public AudioTransport
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);
116 virtual int32_t NeedMorePlayData(const uint32_t nSamples,
117 const uint8_t nBytesPerSample,
118 const uint8_t nChannels,
119 const uint32_t samplesPerSec,
121 uint32_t& nSamplesOut);
123 virtual int OnDataAvailable(const int voe_channels[],
124 int number_of_voe_channels,
125 const int16_t* audio_data,
127 int number_of_channels,
128 int number_of_frames,
129 int audio_delay_milliseconds,
132 bool need_audio_processing);
134 virtual void PushCaptureData(int voe_channel, const void* audio_data,
135 int bits_per_sample, int sample_rate,
136 int number_of_channels,
137 int number_of_frames);
139 virtual void PullRenderData(int bits_per_sample, int sample_rate,
140 int number_of_channels, int number_of_frames,
143 AudioTransportImpl(AudioDeviceModule* audioDevice);
144 ~AudioTransportImpl();
147 int32_t SetFilePlayout(bool enable, const char* fileName = NULL);
148 void SetFullDuplex(bool enable);
149 void SetSpeakerVolume(bool enable)
151 _speakerVolume = enable;
154 void SetSpeakerMute(bool enable)
156 _speakerMute = enable;
159 void SetMicrophoneMute(bool enable)
161 _microphoneMute = enable;
164 void SetMicrophoneVolume(bool enable)
166 _microphoneVolume = enable;
169 void SetMicrophoneBoost(bool enable)
171 _microphoneBoost = enable;
174 void SetLoopbackMeasurements(bool enable)
176 _loopBackMeasurements = enable;
179 void SetMicrophoneAGC(bool enable)
181 _microphoneAGC = enable;
186 typedef std::list<AudioPacket*> AudioPacketList;
187 AudioDeviceModule* _audioDevice;
193 bool _microphoneVolume;
194 bool _microphoneMute;
195 bool _microphoneBoost;
197 bool _loopBackMeasurements;
199 FileWrapper& _playFile;
203 AudioPacketList _audioList;
205 Resampler _resampler;
208 // ----------------------------------------------------------------------------
210 // ----------------------------------------------------------------------------
212 class FuncTestManager
219 int32_t DoTest(const TestType testType);
221 int32_t TestAudioLayerSelection();
222 int32_t TestDeviceEnumeration();
223 int32_t TestDeviceSelection();
224 int32_t TestAudioTransport();
225 int32_t TestSpeakerVolume();
226 int32_t TestMicrophoneVolume();
227 int32_t TestSpeakerMute();
228 int32_t TestMicrophoneMute();
229 int32_t TestMicrophoneBoost();
230 int32_t TestLoopback();
231 int32_t TestDeviceRemoval();
233 int32_t TestMicrophoneAGC();
234 int32_t SelectPlayoutDevice();
235 int32_t SelectRecordingDevice();
236 int32_t TestAdvancedMBAPI();
238 // Paths to where the resource files to be used for this test are located.
239 std::string _playoutFile48;
240 std::string _playoutFile44;
241 std::string _playoutFile16;
242 std::string _playoutFile8;
244 ProcessThread* _processThread;
245 AudioDeviceModule* _audioDevice;
246 AudioEventObserver* _audioEventObserver;
247 AudioTransportImpl* _audioTransport;
250 } // namespace webrtc
252 #endif // #ifndef WEBRTC_AUDIO_DEVICE_FUNC_TEST_MANAGER_H