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 OnData(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 AudioTransportImpl(AudioDeviceModule* audioDevice);
140 ~AudioTransportImpl();
143 int32_t SetFilePlayout(bool enable, const char* fileName = NULL);
144 void SetFullDuplex(bool enable);
145 void SetSpeakerVolume(bool enable)
147 _speakerVolume = enable;
150 void SetSpeakerMute(bool enable)
152 _speakerMute = enable;
155 void SetMicrophoneMute(bool enable)
157 _microphoneMute = enable;
160 void SetMicrophoneVolume(bool enable)
162 _microphoneVolume = enable;
165 void SetMicrophoneBoost(bool enable)
167 _microphoneBoost = enable;
170 void SetLoopbackMeasurements(bool enable)
172 _loopBackMeasurements = enable;
175 void SetMicrophoneAGC(bool enable)
177 _microphoneAGC = enable;
182 typedef std::list<AudioPacket*> AudioPacketList;
183 AudioDeviceModule* _audioDevice;
189 bool _microphoneVolume;
190 bool _microphoneMute;
191 bool _microphoneBoost;
193 bool _loopBackMeasurements;
195 FileWrapper& _playFile;
199 AudioPacketList _audioList;
201 Resampler _resampler;
204 // ----------------------------------------------------------------------------
206 // ----------------------------------------------------------------------------
208 class FuncTestManager
215 int32_t DoTest(const TestType testType);
217 int32_t TestAudioLayerSelection();
218 int32_t TestDeviceEnumeration();
219 int32_t TestDeviceSelection();
220 int32_t TestAudioTransport();
221 int32_t TestSpeakerVolume();
222 int32_t TestMicrophoneVolume();
223 int32_t TestSpeakerMute();
224 int32_t TestMicrophoneMute();
225 int32_t TestMicrophoneBoost();
226 int32_t TestLoopback();
227 int32_t TestDeviceRemoval();
229 int32_t TestMicrophoneAGC();
230 int32_t SelectPlayoutDevice();
231 int32_t SelectRecordingDevice();
232 int32_t TestAdvancedMBAPI();
234 // Paths to where the resource files to be used for this test are located.
235 std::string _playoutFile48;
236 std::string _playoutFile44;
237 std::string _playoutFile16;
238 std::string _playoutFile8;
240 ProcessThread* _processThread;
241 AudioDeviceModule* _audioDevice;
242 AudioEventObserver* _audioEventObserver;
243 AudioTransportImpl* _audioTransport;
246 } // namespace webrtc
248 #endif // #ifndef WEBRTC_AUDIO_DEVICE_FUNC_TEST_MANAGER_H