Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / third_party / webrtc / modules / audio_device / test / func_test_manager.h
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 "webrtc/modules/audio_device/audio_device_utility.h"
15
16 #include <list>
17 #include <string>
18
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"
24
25 #if defined(WEBRTC_IOS) || defined(ANDROID)
26 #define USE_SLEEP_AS_PAUSE
27 #else
28 //#define USE_SLEEP_AS_PAUSE
29 #endif
30
31 // Sets the default pause time if using sleep as pause
32 #define DEFAULT_PAUSE_TIME 5000
33
34 #if defined(USE_SLEEP_AS_PAUSE)
35 #define PAUSE(a) SleepMs(a);
36 #else
37 #define PAUSE(a) AudioDeviceUtility::WaitForKey();
38 #endif
39
40 #define ADM_AUDIO_LAYER AudioDeviceModule::kPlatformDefaultAudio
41 //#define ADM_AUDIO_LAYER AudioDeviceModule::kLinuxPulseAudio
42
43 enum TestType
44 {
45     TTInvalid = -1,
46     TTAll = 0,
47     TTAudioLayerSelection = 1,
48     TTDeviceEnumeration = 2,
49     TTDeviceSelection = 3,
50     TTAudioTransport = 4,
51     TTSpeakerVolume = 5,
52     TTMicrophoneVolume = 6,
53     TTSpeakerMute = 7,
54     TTMicrophoneMute = 8,
55     TTMicrophoneBoost = 9,
56     TTMicrophoneAGC = 10,
57     TTLoopback = 11,
58     TTDeviceRemoval = 13,
59     TTMobileAPI = 14,
60     TTTest = 66,
61 };
62
63 struct AudioPacket
64 {
65     uint8_t dataBuffer[4 * 960];
66     uint16_t nSamples;
67     uint16_t nBytesPerSample;
68     uint8_t nChannels;
69     uint32_t samplesPerSec;
70 };
71
72 class ProcessThread;
73
74 namespace webrtc
75 {
76
77 class AudioDeviceModule;
78 class AudioEventObserver;
79 class AudioTransport;
80
81 // ----------------------------------------------------------------------------
82 //  AudioEventObserver
83 // ----------------------------------------------------------------------------
84
85 class AudioEventObserver: public AudioDeviceObserver
86 {
87 public:
88     virtual void OnErrorIsReported(const ErrorCode error);
89     virtual void OnWarningIsReported(const WarningCode warning);
90     AudioEventObserver(AudioDeviceModule* audioDevice);
91     ~AudioEventObserver();
92 public:
93     ErrorCode _error;
94     WarningCode _warning;
95 };
96
97 // ----------------------------------------------------------------------------
98 //  AudioTransport
99 // ----------------------------------------------------------------------------
100
101 class AudioTransportImpl: public AudioTransport
102 {
103 public:
104     virtual int32_t
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);
115
116     virtual int32_t NeedMorePlayData(const uint32_t nSamples,
117                                      const uint8_t nBytesPerSample,
118                                      const uint8_t nChannels,
119                                      const uint32_t samplesPerSec,
120                                      void* audioSamples,
121                                      uint32_t& nSamplesOut);
122
123     virtual int OnDataAvailable(const int voe_channels[],
124                                 int number_of_voe_channels,
125                                 const int16_t* audio_data,
126                                 int sample_rate,
127                                 int number_of_channels,
128                                 int number_of_frames,
129                                 int audio_delay_milliseconds,
130                                 int current_volume,
131                                 bool key_pressed,
132                                 bool need_audio_processing);
133
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);
138
139     virtual void PullRenderData(int bits_per_sample, int sample_rate,
140                                 int number_of_channels, int number_of_frames,
141                                 void* audio_data);
142
143     AudioTransportImpl(AudioDeviceModule* audioDevice);
144     ~AudioTransportImpl();
145
146 public:
147     int32_t SetFilePlayout(bool enable, const char* fileName = NULL);
148     void SetFullDuplex(bool enable);
149     void SetSpeakerVolume(bool enable)
150     {
151         _speakerVolume = enable;
152     }
153     ;
154     void SetSpeakerMute(bool enable)
155     {
156         _speakerMute = enable;
157     }
158     ;
159     void SetMicrophoneMute(bool enable)
160     {
161         _microphoneMute = enable;
162     }
163     ;
164     void SetMicrophoneVolume(bool enable)
165     {
166         _microphoneVolume = enable;
167     }
168     ;
169     void SetMicrophoneBoost(bool enable)
170     {
171         _microphoneBoost = enable;
172     }
173     ;
174     void SetLoopbackMeasurements(bool enable)
175     {
176         _loopBackMeasurements = enable;
177     }
178     ;
179     void SetMicrophoneAGC(bool enable)
180     {
181         _microphoneAGC = enable;
182     }
183     ;
184
185 private:
186     typedef std::list<AudioPacket*> AudioPacketList;
187     AudioDeviceModule* _audioDevice;
188
189     bool _playFromFile;
190     bool _fullDuplex;
191     bool _speakerVolume;
192     bool _speakerMute;
193     bool _microphoneVolume;
194     bool _microphoneMute;
195     bool _microphoneBoost;
196     bool _microphoneAGC;
197     bool _loopBackMeasurements;
198
199     FileWrapper& _playFile;
200
201     uint32_t _recCount;
202     uint32_t _playCount;
203     AudioPacketList _audioList;
204
205     Resampler _resampler;
206 };
207
208 // ----------------------------------------------------------------------------
209 //  FuncTestManager
210 // ----------------------------------------------------------------------------
211
212 class FuncTestManager
213 {
214 public:
215     FuncTestManager();
216     ~FuncTestManager();
217     int32_t Init();
218     int32_t Close();
219     int32_t DoTest(const TestType testType);
220 private:
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();
232     int32_t TestExtra();
233     int32_t TestMicrophoneAGC();
234     int32_t SelectPlayoutDevice();
235     int32_t SelectRecordingDevice();
236     int32_t TestAdvancedMBAPI();
237 private:
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;
243
244     ProcessThread* _processThread;
245     AudioDeviceModule* _audioDevice;
246     AudioEventObserver* _audioEventObserver;
247     AudioTransportImpl* _audioTransport;
248 };
249
250 }  // namespace webrtc
251
252 #endif  // #ifndef WEBRTC_AUDIO_DEVICE_FUNC_TEST_MANAGER_H