6e21466e67635dcdbb6c8b3da8c1adb8f8061149
[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 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);
138
139     AudioTransportImpl(AudioDeviceModule* audioDevice);
140     ~AudioTransportImpl();
141
142 public:
143     int32_t SetFilePlayout(bool enable, const char* fileName = NULL);
144     void SetFullDuplex(bool enable);
145     void SetSpeakerVolume(bool enable)
146     {
147         _speakerVolume = enable;
148     }
149     ;
150     void SetSpeakerMute(bool enable)
151     {
152         _speakerMute = enable;
153     }
154     ;
155     void SetMicrophoneMute(bool enable)
156     {
157         _microphoneMute = enable;
158     }
159     ;
160     void SetMicrophoneVolume(bool enable)
161     {
162         _microphoneVolume = enable;
163     }
164     ;
165     void SetMicrophoneBoost(bool enable)
166     {
167         _microphoneBoost = enable;
168     }
169     ;
170     void SetLoopbackMeasurements(bool enable)
171     {
172         _loopBackMeasurements = enable;
173     }
174     ;
175     void SetMicrophoneAGC(bool enable)
176     {
177         _microphoneAGC = enable;
178     }
179     ;
180
181 private:
182     typedef std::list<AudioPacket*> AudioPacketList;
183     AudioDeviceModule* _audioDevice;
184
185     bool _playFromFile;
186     bool _fullDuplex;
187     bool _speakerVolume;
188     bool _speakerMute;
189     bool _microphoneVolume;
190     bool _microphoneMute;
191     bool _microphoneBoost;
192     bool _microphoneAGC;
193     bool _loopBackMeasurements;
194
195     FileWrapper& _playFile;
196
197     uint32_t _recCount;
198     uint32_t _playCount;
199     AudioPacketList _audioList;
200
201     Resampler _resampler;
202 };
203
204 // ----------------------------------------------------------------------------
205 //  FuncTestManager
206 // ----------------------------------------------------------------------------
207
208 class FuncTestManager
209 {
210 public:
211     FuncTestManager();
212     ~FuncTestManager();
213     int32_t Init();
214     int32_t Close();
215     int32_t DoTest(const TestType testType);
216 private:
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();
228     int32_t TestExtra();
229     int32_t TestMicrophoneAGC();
230     int32_t SelectPlayoutDevice();
231     int32_t SelectRecordingDevice();
232     int32_t TestAdvancedMBAPI();
233 private:
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;
239
240     ProcessThread* _processThread;
241     AudioDeviceModule* _audioDevice;
242     AudioEventObserver* _audioEventObserver;
243     AudioTransportImpl* _audioTransport;
244 };
245
246 }  // namespace webrtc
247
248 #endif  // #ifndef WEBRTC_AUDIO_DEVICE_FUNC_TEST_MANAGER_H