OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/file_util.h" | 6 #include "base/file_util.h" |
7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
11 #include "content/public/common/content_switches.h" | 11 #include "content/public/common/content_switches.h" |
12 #include "content/public/common/media_stream_request.h" | 12 #include "content/public/common/media_stream_request.h" |
13 #include "content/renderer/media/media_stream_audio_processor.h" | 13 #include "content/renderer/media/media_stream_audio_processor.h" |
14 #include "content/renderer/media/media_stream_audio_processor_options.h" | |
14 #include "content/renderer/media/mock_media_constraint_factory.h" | 15 #include "content/renderer/media/mock_media_constraint_factory.h" |
15 #include "media/audio/audio_parameters.h" | 16 #include "media/audio/audio_parameters.h" |
16 #include "media/base/audio_bus.h" | 17 #include "media/base/audio_bus.h" |
17 #include "testing/gmock/include/gmock/gmock.h" | 18 #include "testing/gmock/include/gmock/gmock.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
19 #include "third_party/WebKit/public/platform/WebMediaConstraints.h" | 20 #include "third_party/WebKit/public/platform/WebMediaConstraints.h" |
20 #include "third_party/libjingle/source/talk/app/webrtc/mediastreaminterface.h" | 21 #include "third_party/libjingle/source/talk/app/webrtc/mediastreaminterface.h" |
21 | 22 |
22 using ::testing::_; | 23 using ::testing::_; |
23 using ::testing::AnyNumber; | 24 using ::testing::AnyNumber; |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
146 EXPECT_TRUE(audio_processing->voice_detection()->likelihood() == | 147 EXPECT_TRUE(audio_processing->voice_detection()->likelihood() == |
147 webrtc::VoiceDetection::kVeryLowLikelihood); | 148 webrtc::VoiceDetection::kVeryLowLikelihood); |
148 #endif | 149 #endif |
149 } | 150 } |
150 | 151 |
151 media::AudioParameters params_; | 152 media::AudioParameters params_; |
152 }; | 153 }; |
153 | 154 |
154 TEST_F(MediaStreamAudioProcessorTest, WithoutAudioProcessing) { | 155 TEST_F(MediaStreamAudioProcessorTest, WithoutAudioProcessing) { |
155 // Setup the audio processor without enabling the flag. | 156 // Setup the audio processor without enabling the flag. |
156 blink::WebMediaConstraints constraints; | 157 MockMediaConstraintFactory constraint_factory; |
157 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device( | 158 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device( |
158 new WebRtcAudioDeviceImpl()); | 159 new WebRtcAudioDeviceImpl()); |
159 scoped_refptr<MediaStreamAudioProcessor> audio_processor( | 160 scoped_refptr<MediaStreamAudioProcessor> audio_processor( |
160 new talk_base::RefCountedObject<MediaStreamAudioProcessor>( | 161 new talk_base::RefCountedObject<MediaStreamAudioProcessor>( |
161 constraints, 0, MEDIA_DEVICE_AUDIO_CAPTURE, | 162 constraint_factory.CreateWebMediaConstraints(), 0, |
162 webrtc_audio_device.get())); | 163 webrtc_audio_device.get())); |
163 EXPECT_FALSE(audio_processor->has_audio_processing()); | 164 EXPECT_FALSE(audio_processor->has_audio_processing()); |
164 audio_processor->OnCaptureFormatChanged(params_); | 165 audio_processor->OnCaptureFormatChanged(params_); |
165 | 166 |
166 ProcessDataAndVerifyFormat(audio_processor, | 167 ProcessDataAndVerifyFormat(audio_processor, |
167 params_.sample_rate(), | 168 params_.sample_rate(), |
168 params_.channels(), | 169 params_.channels(), |
169 params_.sample_rate() / 100); | 170 params_.sample_rate() / 100); |
170 // Set |audio_processor| to NULL to make sure |webrtc_audio_device| outlives | 171 // Set |audio_processor| to NULL to make sure |webrtc_audio_device| outlives |
171 // |audio_processor|. | 172 // |audio_processor|. |
172 audio_processor = NULL; | 173 audio_processor = NULL; |
173 } | 174 } |
174 | 175 |
175 TEST_F(MediaStreamAudioProcessorTest, WithAudioProcessing) { | 176 TEST_F(MediaStreamAudioProcessorTest, WithAudioProcessing) { |
176 // Setup the audio processor with the flag enabled. | 177 // Setup the audio processor with the flag enabled. |
177 CommandLine::ForCurrentProcess()->AppendSwitch( | 178 CommandLine::ForCurrentProcess()->AppendSwitch( |
178 switches::kEnableAudioTrackProcessing); | 179 switches::kEnableAudioTrackProcessing); |
179 blink::WebMediaConstraints constraints; | 180 MockMediaConstraintFactory constraint_factory; |
180 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device( | 181 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device( |
181 new WebRtcAudioDeviceImpl()); | 182 new WebRtcAudioDeviceImpl()); |
182 scoped_refptr<MediaStreamAudioProcessor> audio_processor( | 183 scoped_refptr<MediaStreamAudioProcessor> audio_processor( |
183 new talk_base::RefCountedObject<MediaStreamAudioProcessor>( | 184 new talk_base::RefCountedObject<MediaStreamAudioProcessor>( |
184 constraints, 0, MEDIA_DEVICE_AUDIO_CAPTURE, | 185 constraint_factory.CreateWebMediaConstraints(), 0, |
185 webrtc_audio_device.get())); | 186 webrtc_audio_device.get())); |
186 EXPECT_TRUE(audio_processor->has_audio_processing()); | 187 EXPECT_TRUE(audio_processor->has_audio_processing()); |
187 audio_processor->OnCaptureFormatChanged(params_); | 188 audio_processor->OnCaptureFormatChanged(params_); |
188 VerifyDefaultComponents(audio_processor); | 189 VerifyDefaultComponents(audio_processor); |
189 | 190 |
190 ProcessDataAndVerifyFormat(audio_processor, | 191 ProcessDataAndVerifyFormat(audio_processor, |
191 kAudioProcessingSampleRate, | 192 kAudioProcessingSampleRate, |
192 kAudioProcessingNumberOfChannel, | 193 kAudioProcessingNumberOfChannel, |
193 kAudioProcessingSampleRate / 100); | 194 kAudioProcessingSampleRate / 100); |
194 // Set |audio_processor| to NULL to make sure |webrtc_audio_device| outlives | 195 // Set |audio_processor| to NULL to make sure |webrtc_audio_device| outlives |
195 // |audio_processor|. | 196 // |audio_processor|. |
196 audio_processor = NULL; | 197 audio_processor = NULL; |
197 } | 198 } |
198 | 199 |
199 TEST_F(MediaStreamAudioProcessorTest, VerifyTabCaptureWithoutAudioProcessing) { | 200 TEST_F(MediaStreamAudioProcessorTest, VerifyTabCaptureWithoutAudioProcessing) { |
200 // Setup the audio processor with enabling the flag. | 201 // Setup the audio processor with enabling the flag. |
201 CommandLine::ForCurrentProcess()->AppendSwitch( | 202 CommandLine::ForCurrentProcess()->AppendSwitch( |
202 switches::kEnableAudioTrackProcessing); | 203 switches::kEnableAudioTrackProcessing); |
203 blink::WebMediaConstraints constraints; | |
204 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device( | 204 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device( |
205 new WebRtcAudioDeviceImpl()); | 205 new WebRtcAudioDeviceImpl()); |
206 // Create MediaStreamAudioProcessor instance for MEDIA_TAB_AUDIO_CAPTURE type. | 206 // Create MediaStreamAudioProcessor instance for kMediaStreamSourceTab source. |
207 MockMediaConstraintFactory tab_constraint_factory; | |
208 tab_constraint_factory.AddMandatory(kMediaStreamSource, | |
209 kMediaStreamSourceTab); | |
207 scoped_refptr<MediaStreamAudioProcessor> audio_processor( | 210 scoped_refptr<MediaStreamAudioProcessor> audio_processor( |
208 new talk_base::RefCountedObject<MediaStreamAudioProcessor>( | 211 new talk_base::RefCountedObject<MediaStreamAudioProcessor>( |
209 constraints, 0, MEDIA_TAB_AUDIO_CAPTURE, | 212 tab_constraint_factory.CreateWebMediaConstraints(), 0, |
210 webrtc_audio_device.get())); | 213 webrtc_audio_device.get())); |
211 EXPECT_FALSE(audio_processor->has_audio_processing()); | 214 EXPECT_FALSE(audio_processor->has_audio_processing()); |
212 audio_processor->OnCaptureFormatChanged(params_); | 215 audio_processor->OnCaptureFormatChanged(params_); |
213 | 216 |
214 ProcessDataAndVerifyFormat(audio_processor, | 217 ProcessDataAndVerifyFormat(audio_processor, |
215 params_.sample_rate(), | 218 params_.sample_rate(), |
216 params_.channels(), | 219 params_.channels(), |
217 params_.sample_rate() / 100); | 220 params_.sample_rate() / 100); |
218 | 221 |
219 // Create MediaStreamAudioProcessor instance for MEDIA_LOOPBACK_AUDIO_CAPTURE. | 222 // Create MediaStreamAudioProcessor instance for kMediaStreamSourceSystem |
220 audio_processor = | 223 // source. |
221 new talk_base::RefCountedObject<MediaStreamAudioProcessor>( | 224 MockMediaConstraintFactory system_constraint_factory; |
222 constraints, 0, MEDIA_LOOPBACK_AUDIO_CAPTURE, | 225 system_constraint_factory.AddMandatory(kMediaStreamSource, |
223 webrtc_audio_device.get()); | 226 kMediaStreamSourceSystem); |
227 audio_processor = new talk_base::RefCountedObject<MediaStreamAudioProcessor>( | |
228 system_constraint_factory.CreateWebMediaConstraints(), 0, | |
229 webrtc_audio_device.get()); | |
224 EXPECT_FALSE(audio_processor->has_audio_processing()); | 230 EXPECT_FALSE(audio_processor->has_audio_processing()); |
225 | 231 |
226 // Set |audio_processor| to NULL to make sure |webrtc_audio_device| outlives | 232 // Set |audio_processor| to NULL to make sure |webrtc_audio_device| outlives |
227 // |audio_processor|. | 233 // |audio_processor|. |
228 audio_processor = NULL; | 234 audio_processor = NULL; |
229 } | 235 } |
230 | 236 |
231 TEST_F(MediaStreamAudioProcessorTest, TurnOffDefaultConstraints) { | 237 TEST_F(MediaStreamAudioProcessorTest, TurnOffDefaultConstraints) { |
232 // Setup the audio processor with enabling the flag. | 238 // Setup the audio processor with enabling the flag. |
233 CommandLine::ForCurrentProcess()->AppendSwitch( | 239 CommandLine::ForCurrentProcess()->AppendSwitch( |
234 switches::kEnableAudioTrackProcessing); | 240 switches::kEnableAudioTrackProcessing); |
235 | 241 |
236 // Turn off the default constraints and pass it to MediaStreamAudioProcessor. | 242 // Turn off the default constraints and pass it to MediaStreamAudioProcessor. |
237 MockMediaConstraintFactory constraint_factory; | 243 MockMediaConstraintFactory constraint_factory; |
238 constraint_factory.DisableDefaultAudioConstraints(); | 244 constraint_factory.DisableDefaultAudioConstraints(); |
239 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device( | 245 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device( |
240 new WebRtcAudioDeviceImpl()); | 246 new WebRtcAudioDeviceImpl()); |
241 scoped_refptr<MediaStreamAudioProcessor> audio_processor( | 247 scoped_refptr<MediaStreamAudioProcessor> audio_processor( |
242 new talk_base::RefCountedObject<MediaStreamAudioProcessor>( | 248 new talk_base::RefCountedObject<MediaStreamAudioProcessor>( |
243 constraint_factory.CreateWebMediaConstraints(), 0, | 249 constraint_factory.CreateWebMediaConstraints(), 0, |
244 MEDIA_DEVICE_AUDIO_CAPTURE, webrtc_audio_device.get())); | 250 webrtc_audio_device.get())); |
245 EXPECT_FALSE(audio_processor->has_audio_processing()); | 251 EXPECT_FALSE(audio_processor->has_audio_processing()); |
246 audio_processor->OnCaptureFormatChanged(params_); | 252 audio_processor->OnCaptureFormatChanged(params_); |
247 | 253 |
248 ProcessDataAndVerifyFormat(audio_processor, | 254 ProcessDataAndVerifyFormat(audio_processor, |
249 params_.sample_rate(), | 255 params_.sample_rate(), |
250 params_.channels(), | 256 params_.channels(), |
251 params_.sample_rate() / 100); | 257 params_.sample_rate() / 100); |
252 // Set |audio_processor| to NULL to make sure |webrtc_audio_device| outlives | 258 // Set |audio_processor| to NULL to make sure |webrtc_audio_device| outlives |
253 // |audio_processor|. | 259 // |audio_processor|. |
254 audio_processor = NULL; | 260 audio_processor = NULL; |
255 } | 261 } |
256 | 262 |
263 TEST_F(MediaStreamAudioProcessorTest, VerifyConstraints) { | |
264 // Setup the audio processor with enabling the flag. | |
265 CommandLine::ForCurrentProcess()->AppendSwitch( | |
266 switches::kEnableAudioTrackProcessing); | |
267 | |
268 static const char* kDefaultAudioConstraints[] = { | |
269 MediaAudioConstraints::kEchoCancellation, | |
270 MediaAudioConstraints::kGoogEchoCancellation, | |
271 MediaAudioConstraints::kGoogExperimentalEchoCancellation, | |
272 MediaAudioConstraints::kGoogAutoGainControl, | |
273 MediaAudioConstraints::kGoogExperimentalAutoGainControl, | |
274 MediaAudioConstraints::kGoogNoiseSuppression, | |
275 MediaAudioConstraints::kGoogExperimentalNoiseSuppression, | |
276 MediaAudioConstraints::kGoogHighpassFilter, | |
277 MediaAudioConstraints::kGoogTypingNoiseDetection, | |
278 MediaAudioConstraints::kGoogAudioMirroring | |
279 }; | |
280 | |
281 // Verify mandatory constraints. | |
282 for (size_t i = 0; i < arraysize(kDefaultAudioConstraints); ++i) { | |
283 MockMediaConstraintFactory constraint_factory; | |
284 constraint_factory.AddMandatory(kDefaultAudioConstraints[i], false); | |
285 blink::WebMediaConstraints constraints = | |
286 constraint_factory.CreateWebMediaConstraints(); | |
287 MediaAudioConstraints audio_constraints(constraints, 0); | |
288 EXPECT_FALSE(audio_constraints.GetProperty(kDefaultAudioConstraints[i])); | |
289 } | |
290 | |
291 // Verify optional constraints. | |
292 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kDefaultAudioConstraints); ++i) { | |
293 MockMediaConstraintFactory constraint_factory; | |
294 constraint_factory.AddOptional(kDefaultAudioConstraints[i], false); | |
295 blink::WebMediaConstraints constraints = | |
296 constraint_factory.CreateWebMediaConstraints(); | |
297 MediaAudioConstraints audio_constraints(constraints, 0); | |
298 EXPECT_FALSE(audio_constraints.GetProperty(kDefaultAudioConstraints[i])); | |
299 } | |
300 | |
301 // Verify echo cancellation is off when platform aec effect is on. | |
302 MockMediaConstraintFactory constraint_factory; | |
303 MediaAudioConstraints audio_constraints( | |
304 constraint_factory.CreateWebMediaConstraints(), | |
305 media::AudioParameters::ECHO_CANCELLER); | |
306 EXPECT_FALSE(audio_constraints.GetProperty( | |
307 MediaAudioConstraints::kGoogEchoCancellation)); | |
308 } | |
309 | |
310 TEST_F(MediaStreamAudioProcessorTest, VerifyAllMandatoryConstraints) { | |
311 // Verify gUM will fail if getting an invalid mandatory audio constraint. | |
312 MockMediaConstraintFactory constraint_factory; | |
313 const std::string dummy_constraint = "dummy"; | |
314 constraint_factory.AddMandatory(dummy_constraint, true); | |
315 MediaAudioConstraints audio_constraints( | |
316 constraint_factory.CreateWebMediaConstraints(), 0); | |
317 EXPECT_FALSE(audio_constraints.IsValid()); | |
perkj_chrome
2014/04/14 12:15:19
Add test to make sure guM fail? ie, media_stream_i
no longer working on chromium
2014/04/14 14:40:50
I don't see any existing framework in media_stream
| |
318 } | |
319 | |
257 } // namespace content | 320 } // namespace content |
OLD | NEW |