• 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 <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/include/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 
27 enum 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 
47 struct AudioPacket
48 {
49     uint8_t dataBuffer[4 * 960];
50     size_t nSamples;
51     size_t nBytesPerSample;
52     size_t nChannels;
53     uint32_t samplesPerSec;
54 };
55 
56 class ProcessThread;
57 
58 namespace webrtc
59 {
60 
61 class AudioDeviceModule;
62 class AudioEventObserver;
63 class AudioTransport;
64 
65 // ----------------------------------------------------------------------------
66 //  AudioEventObserver
67 // ----------------------------------------------------------------------------
68 
69 class AudioEventObserver: public AudioDeviceObserver
70 {
71 public:
72     virtual void OnErrorIsReported(const ErrorCode error);
73     virtual void OnWarningIsReported(const WarningCode warning);
74     AudioEventObserver(AudioDeviceModule* audioDevice);
75     ~AudioEventObserver();
76 public:
77     ErrorCode _error;
78     WarningCode _warning;
79 };
80 
81 // ----------------------------------------------------------------------------
82 //  AudioTransport
83 // ----------------------------------------------------------------------------
84 
85 class AudioTransportImpl: public AudioTransport
86 {
87 public:
88     int32_t RecordedDataIsAvailable(const void* audioSamples,
89                                     const size_t nSamples,
90                                     const size_t nBytesPerSample,
91                                     const size_t nChannels,
92                                     const uint32_t samplesPerSec,
93                                     const uint32_t totalDelayMS,
94                                     const int32_t clockDrift,
95                                     const uint32_t currentMicLevel,
96                                     const bool keyPressed,
97                                     uint32_t& newMicLevel) override;
98 
99     int32_t NeedMorePlayData(const size_t nSamples,
100                              const size_t nBytesPerSample,
101                              const size_t nChannels,
102                              const uint32_t samplesPerSec,
103                              void* audioSamples,
104                              size_t& nSamplesOut,
105                              int64_t* elapsed_time_ms,
106                              int64_t* ntp_time_ms) override;
107 
108     AudioTransportImpl(AudioDeviceModule* audioDevice);
109     ~AudioTransportImpl();
110 
111 public:
112     int32_t SetFilePlayout(bool enable, const char* fileName = NULL);
113     void SetFullDuplex(bool enable);
SetSpeakerVolume(bool enable)114     void SetSpeakerVolume(bool enable)
115     {
116         _speakerVolume = enable;
117     }
118     ;
SetSpeakerMute(bool enable)119     void SetSpeakerMute(bool enable)
120     {
121         _speakerMute = enable;
122     }
123     ;
SetMicrophoneMute(bool enable)124     void SetMicrophoneMute(bool enable)
125     {
126         _microphoneMute = enable;
127     }
128     ;
SetMicrophoneVolume(bool enable)129     void SetMicrophoneVolume(bool enable)
130     {
131         _microphoneVolume = enable;
132     }
133     ;
SetMicrophoneBoost(bool enable)134     void SetMicrophoneBoost(bool enable)
135     {
136         _microphoneBoost = enable;
137     }
138     ;
SetLoopbackMeasurements(bool enable)139     void SetLoopbackMeasurements(bool enable)
140     {
141         _loopBackMeasurements = enable;
142     }
143     ;
SetMicrophoneAGC(bool enable)144     void SetMicrophoneAGC(bool enable)
145     {
146         _microphoneAGC = enable;
147     }
148     ;
149 
150 private:
151     typedef std::list<AudioPacket*> AudioPacketList;
152     AudioDeviceModule* _audioDevice;
153 
154     bool _playFromFile;
155     bool _fullDuplex;
156     bool _speakerVolume;
157     bool _speakerMute;
158     bool _microphoneVolume;
159     bool _microphoneMute;
160     bool _microphoneBoost;
161     bool _microphoneAGC;
162     bool _loopBackMeasurements;
163 
164     FileWrapper& _playFile;
165 
166     uint32_t _recCount;
167     uint32_t _playCount;
168     AudioPacketList _audioList;
169 
170     Resampler _resampler;
171 };
172 
173 // ----------------------------------------------------------------------------
174 //  FuncTestManager
175 // ----------------------------------------------------------------------------
176 
177 class FuncTestManager
178 {
179 public:
180     FuncTestManager();
181     ~FuncTestManager();
182     int32_t Init();
183     int32_t Close();
184     int32_t DoTest(const TestType testType);
185 private:
186     int32_t TestAudioLayerSelection();
187     int32_t TestDeviceEnumeration();
188     int32_t TestDeviceSelection();
189     int32_t TestAudioTransport();
190     int32_t TestSpeakerVolume();
191     int32_t TestMicrophoneVolume();
192     int32_t TestSpeakerMute();
193     int32_t TestMicrophoneMute();
194     int32_t TestMicrophoneBoost();
195     int32_t TestLoopback();
196     int32_t TestDeviceRemoval();
197     int32_t TestExtra();
198     int32_t TestMicrophoneAGC();
199     int32_t SelectPlayoutDevice();
200     int32_t SelectRecordingDevice();
201     int32_t TestAdvancedMBAPI();
202 private:
203     // Paths to where the resource files to be used for this test are located.
204     std::string _playoutFile48;
205     std::string _playoutFile44;
206     std::string _playoutFile16;
207     std::string _playoutFile8;
208 
209     rtc::scoped_ptr<ProcessThread> _processThread;
210     AudioDeviceModule* _audioDevice;
211     AudioEventObserver* _audioEventObserver;
212     AudioTransportImpl* _audioTransport;
213 };
214 
215 }  // namespace webrtc
216 
217 #endif  // #ifndef WEBRTC_AUDIO_DEVICE_FUNC_TEST_MANAGER_H
218