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