OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <windows.h> | 5 #include <windows.h> |
6 #include <mmsystem.h> | 6 #include <mmsystem.h> |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/environment.h" | 9 #include "base/environment.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 scoped_array<int> delta_times_; | 135 scoped_array<int> delta_times_; |
136 int file_size_; | 136 int file_size_; |
137 int pos_; | 137 int pos_; |
138 base::Time previous_call_time_; | 138 base::Time previous_call_time_; |
139 FILE* text_file_; | 139 FILE* text_file_; |
140 size_t elements_to_write_; | 140 size_t elements_to_write_; |
141 }; | 141 }; |
142 | 142 |
143 // Convenience method which ensures that we are not running on the build | 143 // Convenience method which ensures that we are not running on the build |
144 // bots and that at least one valid output device can be found. | 144 // bots and that at least one valid output device can be found. |
145 static bool CanRunAudioTests() { | 145 static bool CanRunAudioTests(AudioManager* audio_man) { |
| 146 if (NULL == audio_man) |
| 147 return false; |
| 148 |
146 scoped_ptr<base::Environment> env(base::Environment::Create()); | 149 scoped_ptr<base::Environment> env(base::Environment::Create()); |
147 if (env->HasVar("CHROME_HEADLESS")) | 150 if (env->HasVar("CHROME_HEADLESS")) |
148 return false; | 151 return false; |
149 AudioManager* audio_man = AudioManager::GetAudioManager(); | |
150 if (NULL == audio_man) | |
151 return false; | |
152 // TODO(henrika): note that we use Wave today to query the number of | 152 // TODO(henrika): note that we use Wave today to query the number of |
153 // existing output devices. | 153 // existing output devices. |
154 return audio_man->HasAudioOutputDevices(); | 154 return audio_man->HasAudioOutputDevices(); |
155 } | 155 } |
156 | 156 |
157 // Convenience method which creates a default AudioOutputStream object but | 157 // Convenience method which creates a default AudioOutputStream object but |
158 // also allows the user to modify the default settings. | 158 // also allows the user to modify the default settings. |
159 class AudioOutputStreamWrapper { | 159 class AudioOutputStreamWrapper { |
160 public: | 160 public: |
161 AudioOutputStreamWrapper() | 161 explicit AudioOutputStreamWrapper(AudioManager* audio_manager) |
162 : com_init_(ScopedCOMInitializer::kMTA), | 162 : com_init_(ScopedCOMInitializer::kMTA), |
163 audio_man_(AudioManager::GetAudioManager()), | 163 audio_man_(audio_manager), |
164 format_(AudioParameters::AUDIO_PCM_LOW_LATENCY), | 164 format_(AudioParameters::AUDIO_PCM_LOW_LATENCY), |
165 channel_layout_(CHANNEL_LAYOUT_STEREO), | 165 channel_layout_(CHANNEL_LAYOUT_STEREO), |
166 bits_per_sample_(16) { | 166 bits_per_sample_(16) { |
167 // Use native/mixing sample rate and 10ms frame size as default. | 167 // Use native/mixing sample rate and 10ms frame size as default. |
168 sample_rate_ = static_cast<int>( | 168 sample_rate_ = static_cast<int>( |
169 WASAPIAudioOutputStream::HardwareSampleRate(eConsole)); | 169 WASAPIAudioOutputStream::HardwareSampleRate(eConsole)); |
170 samples_per_packet_ = sample_rate_ / 100; | 170 samples_per_packet_ = sample_rate_ / 100; |
171 DCHECK(sample_rate_); | 171 DCHECK(sample_rate_); |
172 } | 172 } |
173 | 173 |
(...skipping 27 matching lines...) Expand all Loading... |
201 private: | 201 private: |
202 AudioOutputStream* CreateOutputStream() { | 202 AudioOutputStream* CreateOutputStream() { |
203 AudioOutputStream* aos = audio_man_->MakeAudioOutputStream( | 203 AudioOutputStream* aos = audio_man_->MakeAudioOutputStream( |
204 AudioParameters(format_, channel_layout_, sample_rate_, | 204 AudioParameters(format_, channel_layout_, sample_rate_, |
205 bits_per_sample_, samples_per_packet_)); | 205 bits_per_sample_, samples_per_packet_)); |
206 EXPECT_TRUE(aos); | 206 EXPECT_TRUE(aos); |
207 return aos; | 207 return aos; |
208 } | 208 } |
209 | 209 |
210 ScopedCOMInitializer com_init_; | 210 ScopedCOMInitializer com_init_; |
211 AudioManager* audio_man_; | 211 scoped_refptr<AudioManager> audio_man_; |
212 AudioParameters::Format format_; | 212 AudioParameters::Format format_; |
213 ChannelLayout channel_layout_; | 213 ChannelLayout channel_layout_; |
214 int bits_per_sample_; | 214 int bits_per_sample_; |
215 int sample_rate_; | 215 int sample_rate_; |
216 int samples_per_packet_; | 216 int samples_per_packet_; |
217 }; | 217 }; |
218 | 218 |
219 // Convenience method which creates a default AudioOutputStream object. | 219 // Convenience method which creates a default AudioOutputStream object. |
220 static AudioOutputStream* CreateDefaultAudioOutputStream() { | 220 static AudioOutputStream* CreateDefaultAudioOutputStream( |
221 AudioOutputStreamWrapper aosw; | 221 AudioManager* audio_manager) { |
| 222 AudioOutputStreamWrapper aosw(audio_manager); |
222 AudioOutputStream* aos = aosw.Create(); | 223 AudioOutputStream* aos = aosw.Create(); |
223 return aos; | 224 return aos; |
224 } | 225 } |
225 | 226 |
226 static void QuitMessageLoop(base::MessageLoopProxy* proxy) { | 227 static void QuitMessageLoop(base::MessageLoopProxy* proxy) { |
227 proxy->PostTask(FROM_HERE, MessageLoop::QuitClosure()); | 228 proxy->PostTask(FROM_HERE, MessageLoop::QuitClosure()); |
228 } | 229 } |
229 | 230 |
230 // Verify that we can retrieve the current hardware/mixing sample rate | 231 // Verify that we can retrieve the current hardware/mixing sample rate |
231 // for all supported device roles. The ERole enumeration defines constants | 232 // for all supported device roles. The ERole enumeration defines constants |
232 // that indicate the role that the system/user has assigned to an audio | 233 // that indicate the role that the system/user has assigned to an audio |
233 // endpoint device. | 234 // endpoint device. |
234 // TODO(henrika): modify this test when we support full device enumeration. | 235 // TODO(henrika): modify this test when we support full device enumeration. |
235 TEST(WinAudioOutputTest, WASAPIAudioOutputStreamTestHardwareSampleRate) { | 236 TEST(WinAudioOutputTest, WASAPIAudioOutputStreamTestHardwareSampleRate) { |
236 if (!CanRunAudioTests()) | 237 scoped_refptr<AudioManager> audio_manager(AudioManager::Create()); |
| 238 if (!CanRunAudioTests(audio_manager)) |
237 return; | 239 return; |
238 | 240 |
239 ScopedCOMInitializer com_init(ScopedCOMInitializer::kMTA); | 241 ScopedCOMInitializer com_init(ScopedCOMInitializer::kMTA); |
240 | 242 |
241 // Default device intended for games, system notification sounds, | 243 // Default device intended for games, system notification sounds, |
242 // and voice commands. | 244 // and voice commands. |
243 int fs = static_cast<int>( | 245 int fs = static_cast<int>( |
244 WASAPIAudioOutputStream::HardwareSampleRate(eConsole)); | 246 WASAPIAudioOutputStream::HardwareSampleRate(eConsole)); |
245 EXPECT_GE(fs, 0); | 247 EXPECT_GE(fs, 0); |
246 | 248 |
247 // Default communication device intended for e.g. VoIP communication. | 249 // Default communication device intended for e.g. VoIP communication. |
248 fs = static_cast<int>( | 250 fs = static_cast<int>( |
249 WASAPIAudioOutputStream::HardwareSampleRate(eCommunications)); | 251 WASAPIAudioOutputStream::HardwareSampleRate(eCommunications)); |
250 EXPECT_GE(fs, 0); | 252 EXPECT_GE(fs, 0); |
251 | 253 |
252 // Multimedia device for music, movies and live music recording. | 254 // Multimedia device for music, movies and live music recording. |
253 fs = static_cast<int>( | 255 fs = static_cast<int>( |
254 WASAPIAudioOutputStream::HardwareSampleRate(eMultimedia)); | 256 WASAPIAudioOutputStream::HardwareSampleRate(eMultimedia)); |
255 EXPECT_GE(fs, 0); | 257 EXPECT_GE(fs, 0); |
256 } | 258 } |
257 | 259 |
258 // Test Create(), Close() calling sequence. | 260 // Test Create(), Close() calling sequence. |
259 TEST(WinAudioOutputTest, WASAPIAudioOutputStreamTestCreateAndClose) { | 261 TEST(WinAudioOutputTest, WASAPIAudioOutputStreamTestCreateAndClose) { |
260 if (!CanRunAudioTests()) | 262 scoped_refptr<AudioManager> audio_manager(AudioManager::Create()); |
| 263 if (!CanRunAudioTests(audio_manager)) |
261 return; | 264 return; |
262 AudioOutputStream* aos = CreateDefaultAudioOutputStream(); | 265 AudioOutputStream* aos = CreateDefaultAudioOutputStream(audio_manager); |
263 aos->Close(); | 266 aos->Close(); |
264 } | 267 } |
265 | 268 |
266 // Test Open(), Close() calling sequence. | 269 // Test Open(), Close() calling sequence. |
267 TEST(WinAudioOutputTest, WASAPIAudioOutputStreamTestOpenAndClose) { | 270 TEST(WinAudioOutputTest, WASAPIAudioOutputStreamTestOpenAndClose) { |
268 if (!CanRunAudioTests()) | 271 scoped_refptr<AudioManager> audio_manager(AudioManager::Create()); |
| 272 if (!CanRunAudioTests(audio_manager)) |
269 return; | 273 return; |
270 AudioOutputStream* aos = CreateDefaultAudioOutputStream(); | 274 AudioOutputStream* aos = CreateDefaultAudioOutputStream(audio_manager); |
271 EXPECT_TRUE(aos->Open()); | 275 EXPECT_TRUE(aos->Open()); |
272 aos->Close(); | 276 aos->Close(); |
273 } | 277 } |
274 | 278 |
275 // Test Open(), Start(), Close() calling sequence. | 279 // Test Open(), Start(), Close() calling sequence. |
276 TEST(WinAudioOutputTest, WASAPIAudioOutputStreamTestOpenStartAndClose) { | 280 TEST(WinAudioOutputTest, WASAPIAudioOutputStreamTestOpenStartAndClose) { |
277 if (!CanRunAudioTests()) | 281 scoped_refptr<AudioManager> audio_manager(AudioManager::Create()); |
| 282 if (!CanRunAudioTests(audio_manager)) |
278 return; | 283 return; |
279 AudioOutputStream* aos = CreateDefaultAudioOutputStream(); | 284 AudioOutputStream* aos = CreateDefaultAudioOutputStream(audio_manager); |
280 EXPECT_TRUE(aos->Open()); | 285 EXPECT_TRUE(aos->Open()); |
281 MockAudioSourceCallback source; | 286 MockAudioSourceCallback source; |
282 EXPECT_CALL(source, OnError(aos, _)) | 287 EXPECT_CALL(source, OnError(aos, _)) |
283 .Times(0); | 288 .Times(0); |
284 aos->Start(&source); | 289 aos->Start(&source); |
285 aos->Close(); | 290 aos->Close(); |
286 } | 291 } |
287 | 292 |
288 // Test Open(), Start(), Stop(), Close() calling sequence. | 293 // Test Open(), Start(), Stop(), Close() calling sequence. |
289 TEST(WinAudioOutputTest, WASAPIAudioOutputStreamTestOpenStartStopAndClose) { | 294 TEST(WinAudioOutputTest, WASAPIAudioOutputStreamTestOpenStartStopAndClose) { |
290 if (!CanRunAudioTests()) | 295 scoped_refptr<AudioManager> audio_manager(AudioManager::Create()); |
| 296 if (!CanRunAudioTests(audio_manager)) |
291 return; | 297 return; |
292 AudioOutputStream* aos = CreateDefaultAudioOutputStream(); | 298 AudioOutputStream* aos = CreateDefaultAudioOutputStream(audio_manager); |
293 EXPECT_TRUE(aos->Open()); | 299 EXPECT_TRUE(aos->Open()); |
294 MockAudioSourceCallback source; | 300 MockAudioSourceCallback source; |
295 EXPECT_CALL(source, OnError(aos, _)) | 301 EXPECT_CALL(source, OnError(aos, _)) |
296 .Times(0); | 302 .Times(0); |
297 aos->Start(&source); | 303 aos->Start(&source); |
298 aos->Stop(); | 304 aos->Stop(); |
299 aos->Close(); | 305 aos->Close(); |
300 } | 306 } |
301 | 307 |
302 // Test SetVolume(), GetVolume() | 308 // Test SetVolume(), GetVolume() |
303 TEST(WinAudioOutputTest, WASAPIAudioOutputStreamTestVolume) { | 309 TEST(WinAudioOutputTest, WASAPIAudioOutputStreamTestVolume) { |
304 if (!CanRunAudioTests()) | 310 scoped_refptr<AudioManager> audio_manager(AudioManager::Create()); |
| 311 if (!CanRunAudioTests(audio_manager)) |
305 return; | 312 return; |
306 AudioOutputStream* aos = CreateDefaultAudioOutputStream(); | 313 AudioOutputStream* aos = CreateDefaultAudioOutputStream(audio_manager); |
307 | 314 |
308 // Initial volume should be full volume (1.0). | 315 // Initial volume should be full volume (1.0). |
309 double volume = 0.0; | 316 double volume = 0.0; |
310 aos->GetVolume(&volume); | 317 aos->GetVolume(&volume); |
311 EXPECT_EQ(1.0, volume); | 318 EXPECT_EQ(1.0, volume); |
312 | 319 |
313 // Verify some valid volume settings. | 320 // Verify some valid volume settings. |
314 aos->SetVolume(0.0); | 321 aos->SetVolume(0.0); |
315 aos->GetVolume(&volume); | 322 aos->GetVolume(&volume); |
316 EXPECT_EQ(0.0, volume); | 323 EXPECT_EQ(0.0, volume); |
(...skipping 13 matching lines...) Expand all Loading... |
330 | 337 |
331 aos->SetVolume(-0.5); | 338 aos->SetVolume(-0.5); |
332 aos->GetVolume(&volume); | 339 aos->GetVolume(&volume); |
333 EXPECT_EQ(1.0, volume); | 340 EXPECT_EQ(1.0, volume); |
334 | 341 |
335 aos->Close(); | 342 aos->Close(); |
336 } | 343 } |
337 | 344 |
338 // Test some additional calling sequences. | 345 // Test some additional calling sequences. |
339 TEST(WinAudioOutputTest, WASAPIAudioOutputStreamTestMiscCallingSequences) { | 346 TEST(WinAudioOutputTest, WASAPIAudioOutputStreamTestMiscCallingSequences) { |
340 if (!CanRunAudioTests()) | 347 scoped_refptr<AudioManager> audio_manager(AudioManager::Create()); |
| 348 if (!CanRunAudioTests(audio_manager)) |
341 return; | 349 return; |
342 AudioOutputStream* aos = CreateDefaultAudioOutputStream(); | 350 |
| 351 AudioOutputStream* aos = CreateDefaultAudioOutputStream(audio_manager); |
343 WASAPIAudioOutputStream* waos = static_cast<WASAPIAudioOutputStream*>(aos); | 352 WASAPIAudioOutputStream* waos = static_cast<WASAPIAudioOutputStream*>(aos); |
344 | 353 |
345 // Open(), Open() is a valid calling sequence (second call does nothing). | 354 // Open(), Open() is a valid calling sequence (second call does nothing). |
346 EXPECT_TRUE(aos->Open()); | 355 EXPECT_TRUE(aos->Open()); |
347 EXPECT_TRUE(aos->Open()); | 356 EXPECT_TRUE(aos->Open()); |
348 | 357 |
349 MockAudioSourceCallback source; | 358 MockAudioSourceCallback source; |
350 | 359 |
351 // Start(), Start() is a valid calling sequence (second call does nothing). | 360 // Start(), Start() is a valid calling sequence (second call does nothing). |
352 aos->Start(&source); | 361 aos->Start(&source); |
353 EXPECT_TRUE(waos->started()); | 362 EXPECT_TRUE(waos->started()); |
354 aos->Start(&source); | 363 aos->Start(&source); |
355 EXPECT_TRUE(waos->started()); | 364 EXPECT_TRUE(waos->started()); |
356 | 365 |
357 // Stop(), Stop() is a valid calling sequence (second call does nothing). | 366 // Stop(), Stop() is a valid calling sequence (second call does nothing). |
358 aos->Stop(); | 367 aos->Stop(); |
359 EXPECT_FALSE(waos->started()); | 368 EXPECT_FALSE(waos->started()); |
360 aos->Stop(); | 369 aos->Stop(); |
361 EXPECT_FALSE(waos->started()); | 370 EXPECT_FALSE(waos->started()); |
362 | 371 |
363 aos->Close(); | 372 aos->Close(); |
364 } | 373 } |
365 | 374 |
366 // Use default packet size (10ms) and verify that rendering starts. | 375 // Use default packet size (10ms) and verify that rendering starts. |
367 TEST(WinAudioOutputTest, WASAPIAudioOutputStreamTestPacketSizeInMilliseconds) { | 376 TEST(WinAudioOutputTest, WASAPIAudioOutputStreamTestPacketSizeInMilliseconds) { |
368 if (!CanRunAudioTests()) | 377 scoped_refptr<AudioManager> audio_manager(AudioManager::Create()); |
| 378 if (!CanRunAudioTests(audio_manager)) |
369 return; | 379 return; |
370 | 380 |
371 MessageLoopForUI loop; | 381 MessageLoopForUI loop; |
372 scoped_refptr<base::MessageLoopProxy> proxy(loop.message_loop_proxy()); | 382 scoped_refptr<base::MessageLoopProxy> proxy(loop.message_loop_proxy()); |
373 | 383 |
374 MockAudioSourceCallback source; | 384 MockAudioSourceCallback source; |
375 | 385 |
376 // Create default WASAPI output stream which plays out in stereo using | 386 // Create default WASAPI output stream which plays out in stereo using |
377 // the shared mixing rate. The default buffer size is 10ms. | 387 // the shared mixing rate. The default buffer size is 10ms. |
378 AudioOutputStreamWrapper aosw; | 388 AudioOutputStreamWrapper aosw(audio_manager); |
379 AudioOutputStream* aos = aosw.Create(); | 389 AudioOutputStream* aos = aosw.Create(); |
380 EXPECT_TRUE(aos->Open()); | 390 EXPECT_TRUE(aos->Open()); |
381 | 391 |
382 // Derive the expected size in bytes of each packet. | 392 // Derive the expected size in bytes of each packet. |
383 uint32 bytes_per_packet = aosw.channels() * aosw.samples_per_packet() * | 393 uint32 bytes_per_packet = aosw.channels() * aosw.samples_per_packet() * |
384 (aosw.bits_per_sample() / 8); | 394 (aosw.bits_per_sample() / 8); |
385 | 395 |
386 // Set up expected minimum delay estimation. | 396 // Set up expected minimum delay estimation. |
387 AudioBuffersState state(0, bytes_per_packet); | 397 AudioBuffersState state(0, bytes_per_packet); |
388 | 398 |
(...skipping 10 matching lines...) Expand all Loading... |
399 loop.PostDelayedTask(FROM_HERE, MessageLoop::QuitClosure(), | 409 loop.PostDelayedTask(FROM_HERE, MessageLoop::QuitClosure(), |
400 TestTimeouts::action_timeout_ms()); | 410 TestTimeouts::action_timeout_ms()); |
401 loop.Run(); | 411 loop.Run(); |
402 aos->Stop(); | 412 aos->Stop(); |
403 aos->Close(); | 413 aos->Close(); |
404 } | 414 } |
405 | 415 |
406 // Use a fixed packets size (independent of sample rate) and verify | 416 // Use a fixed packets size (independent of sample rate) and verify |
407 // that rendering starts. | 417 // that rendering starts. |
408 TEST(WinAudioOutputTest, WASAPIAudioOutputStreamTestPacketSizeInSamples) { | 418 TEST(WinAudioOutputTest, WASAPIAudioOutputStreamTestPacketSizeInSamples) { |
409 if (!CanRunAudioTests()) | 419 scoped_refptr<AudioManager> audio_manager(AudioManager::Create()); |
| 420 if (!CanRunAudioTests(audio_manager)) |
410 return; | 421 return; |
411 | 422 |
412 MessageLoopForUI loop; | 423 MessageLoopForUI loop; |
413 scoped_refptr<base::MessageLoopProxy> proxy(loop.message_loop_proxy()); | 424 scoped_refptr<base::MessageLoopProxy> proxy(loop.message_loop_proxy()); |
414 | 425 |
415 MockAudioSourceCallback source; | 426 MockAudioSourceCallback source; |
416 | 427 |
417 // Create default WASAPI output stream which plays out in stereo using | 428 // Create default WASAPI output stream which plays out in stereo using |
418 // the shared mixing rate. The buffer size is set to 1024 samples. | 429 // the shared mixing rate. The buffer size is set to 1024 samples. |
419 AudioOutputStreamWrapper aosw; | 430 AudioOutputStreamWrapper aosw(audio_manager); |
420 AudioOutputStream* aos = aosw.Create(1024); | 431 AudioOutputStream* aos = aosw.Create(1024); |
421 EXPECT_TRUE(aos->Open()); | 432 EXPECT_TRUE(aos->Open()); |
422 | 433 |
423 // Derive the expected size in bytes of each packet. | 434 // Derive the expected size in bytes of each packet. |
424 uint32 bytes_per_packet = aosw.channels() * aosw.samples_per_packet() * | 435 uint32 bytes_per_packet = aosw.channels() * aosw.samples_per_packet() * |
425 (aosw.bits_per_sample() / 8); | 436 (aosw.bits_per_sample() / 8); |
426 | 437 |
427 // Set up expected minimum delay estimation. | 438 // Set up expected minimum delay estimation. |
428 AudioBuffersState state(0, bytes_per_packet); | 439 AudioBuffersState state(0, bytes_per_packet); |
429 | 440 |
430 // Wait for the first callback and verify its parameters. | 441 // Wait for the first callback and verify its parameters. |
431 EXPECT_CALL(source, OnMoreData(aos, NotNull(), bytes_per_packet, | 442 EXPECT_CALL(source, OnMoreData(aos, NotNull(), bytes_per_packet, |
432 HasValidDelay(state))) | 443 HasValidDelay(state))) |
433 .WillOnce( | 444 .WillOnce( |
434 DoAll( | 445 DoAll( |
435 InvokeWithoutArgs( | 446 InvokeWithoutArgs( |
436 CreateFunctor(&QuitMessageLoop, proxy.get())), | 447 CreateFunctor(&QuitMessageLoop, proxy.get())), |
437 Return(bytes_per_packet))); | 448 Return(bytes_per_packet))); |
438 | 449 |
439 aos->Start(&source); | 450 aos->Start(&source); |
440 loop.PostDelayedTask(FROM_HERE, MessageLoop::QuitClosure(), | 451 loop.PostDelayedTask(FROM_HERE, MessageLoop::QuitClosure(), |
441 TestTimeouts::action_timeout_ms()); | 452 TestTimeouts::action_timeout_ms()); |
442 loop.Run(); | 453 loop.Run(); |
443 aos->Stop(); | 454 aos->Stop(); |
444 aos->Close(); | 455 aos->Close(); |
445 } | 456 } |
446 | 457 |
447 TEST(WinAudioOutputTest, WASAPIAudioOutputStreamTestMono) { | 458 TEST(WinAudioOutputTest, WASAPIAudioOutputStreamTestMono) { |
448 if (!CanRunAudioTests()) | 459 scoped_refptr<AudioManager> audio_manager(AudioManager::Create()); |
| 460 if (!CanRunAudioTests(audio_manager)) |
449 return; | 461 return; |
450 | 462 |
451 MessageLoopForUI loop; | 463 MessageLoopForUI loop; |
452 scoped_refptr<base::MessageLoopProxy> proxy(loop.message_loop_proxy()); | 464 scoped_refptr<base::MessageLoopProxy> proxy(loop.message_loop_proxy()); |
453 | 465 |
454 MockAudioSourceCallback source; | 466 MockAudioSourceCallback source; |
455 | 467 |
456 // Create default WASAPI output stream which plays out in *mono* using | 468 // Create default WASAPI output stream which plays out in *mono* using |
457 // the shared mixing rate. The default buffer size is 10ms. | 469 // the shared mixing rate. The default buffer size is 10ms. |
458 AudioOutputStreamWrapper aosw; | 470 AudioOutputStreamWrapper aosw(audio_manager); |
459 AudioOutputStream* aos = aosw.Create(CHANNEL_LAYOUT_MONO); | 471 AudioOutputStream* aos = aosw.Create(CHANNEL_LAYOUT_MONO); |
460 EXPECT_TRUE(aos->Open()); | 472 bool opened; |
461 | 473 EXPECT_TRUE(opened = aos->Open()); |
| 474 if (!opened) { |
| 475 delete aos; |
| 476 return; |
| 477 } |
462 // Derive the expected size in bytes of each packet. | 478 // Derive the expected size in bytes of each packet. |
463 uint32 bytes_per_packet = aosw.channels() * aosw.samples_per_packet() * | 479 uint32 bytes_per_packet = aosw.channels() * aosw.samples_per_packet() * |
464 (aosw.bits_per_sample() / 8); | 480 (aosw.bits_per_sample() / 8); |
465 | 481 |
466 // Set up expected minimum delay estimation. | 482 // Set up expected minimum delay estimation. |
467 AudioBuffersState state(0, bytes_per_packet); | 483 AudioBuffersState state(0, bytes_per_packet); |
468 | 484 |
469 EXPECT_CALL(source, OnMoreData(aos, NotNull(), bytes_per_packet, | 485 EXPECT_CALL(source, OnMoreData(aos, NotNull(), bytes_per_packet, |
470 HasValidDelay(state))) | 486 HasValidDelay(state))) |
471 .WillOnce( | 487 .WillOnce( |
(...skipping 11 matching lines...) Expand all Loading... |
483 } | 499 } |
484 | 500 |
485 // This test is intended for manual tests and should only be enabled | 501 // This test is intended for manual tests and should only be enabled |
486 // when it is required to store the captured data on a local file. | 502 // when it is required to store the captured data on a local file. |
487 // By default, GTest will print out YOU HAVE 1 DISABLED TEST. | 503 // By default, GTest will print out YOU HAVE 1 DISABLED TEST. |
488 // To include disabled tests in test execution, just invoke the test program | 504 // To include disabled tests in test execution, just invoke the test program |
489 // with --gtest_also_run_disabled_tests or set the GTEST_ALSO_RUN_DISABLED_TESTS | 505 // with --gtest_also_run_disabled_tests or set the GTEST_ALSO_RUN_DISABLED_TESTS |
490 // environment variable to a value greater than 0. | 506 // environment variable to a value greater than 0. |
491 // The test files are approximately 20 seconds long. | 507 // The test files are approximately 20 seconds long. |
492 TEST(WinAudioOutputTest, DISABLED_WASAPIAudioOutputStreamReadFromFile) { | 508 TEST(WinAudioOutputTest, DISABLED_WASAPIAudioOutputStreamReadFromFile) { |
493 if (!CanRunAudioTests()) | 509 scoped_refptr<AudioManager> audio_manager(AudioManager::Create()); |
| 510 if (!CanRunAudioTests(audio_manager)) |
494 return; | 511 return; |
495 | 512 |
496 AudioOutputStreamWrapper aosw; | 513 AudioOutputStreamWrapper aosw(audio_manager); |
497 AudioOutputStream* aos = aosw.Create(); | 514 AudioOutputStream* aos = aosw.Create(); |
498 EXPECT_TRUE(aos->Open()); | 515 EXPECT_TRUE(aos->Open()); |
499 | 516 |
500 std::string file_name; | 517 std::string file_name; |
501 if (aosw.sample_rate() == 48000) { | 518 if (aosw.sample_rate() == 48000) { |
502 file_name = kSpeechFile_16b_s_48k; | 519 file_name = kSpeechFile_16b_s_48k; |
503 } else if (aosw.sample_rate() == 44100) { | 520 } else if (aosw.sample_rate() == 44100) { |
504 file_name = kSpeechFile_16b_s_44k; | 521 file_name = kSpeechFile_16b_s_44k; |
505 } else if (aosw.sample_rate() == 96000) { | 522 } else if (aosw.sample_rate() == 96000) { |
506 // Use 48kHz file at 96kHz as well. Will sound like Donald Duck. | 523 // Use 48kHz file at 96kHz as well. Will sound like Donald Duck. |
(...skipping 12 matching lines...) Expand all Loading... |
519 | 536 |
520 aos->Start(&file_source); | 537 aos->Start(&file_source); |
521 base::PlatformThread::Sleep(file_duration_ms); | 538 base::PlatformThread::Sleep(file_duration_ms); |
522 aos->Stop(); | 539 aos->Stop(); |
523 | 540 |
524 LOG(INFO) << ">> File playout has stopped."; | 541 LOG(INFO) << ">> File playout has stopped."; |
525 aos->Close(); | 542 aos->Close(); |
526 } | 543 } |
527 | 544 |
528 } // namespace media | 545 } // namespace media |
OLD | NEW |