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