Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(82)

Side by Side Diff: media/audio/win/core_audio_util_win_unittest.cc

Issue 367923004: Turn audio ducking on by default on Windows again. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/memory/scoped_ptr.h" 5 #include "base/memory/scoped_ptr.h"
6 #include "base/strings/utf_string_conversions.h" 6 #include "base/strings/utf_string_conversions.h"
7 #include "base/synchronization/waitable_event.h" 7 #include "base/synchronization/waitable_event.h"
8 #include "base/win/scoped_co_mem.h" 8 #include "base/win/scoped_co_mem.h"
9 #include "base/win/scoped_com_initializer.h" 9 #include "base/win/scoped_com_initializer.h"
10 #include "base/win/scoped_handle.h" 10 #include "base/win/scoped_handle.h"
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 client = CoreAudioUtil::CreateDefaultClient(eRender, eConsole); 339 client = CoreAudioUtil::CreateDefaultClient(eRender, eConsole);
340 EXPECT_TRUE(client); 340 EXPECT_TRUE(client);
341 341
342 WAVEFORMATPCMEX format; 342 WAVEFORMATPCMEX format;
343 EXPECT_TRUE(SUCCEEDED(CoreAudioUtil::GetSharedModeMixFormat(client, 343 EXPECT_TRUE(SUCCEEDED(CoreAudioUtil::GetSharedModeMixFormat(client,
344 &format))); 344 &format)));
345 345
346 // Perform a shared-mode initialization without event-driven buffer handling. 346 // Perform a shared-mode initialization without event-driven buffer handling.
347 uint32 endpoint_buffer_size = 0; 347 uint32 endpoint_buffer_size = 0;
348 HRESULT hr = CoreAudioUtil::SharedModeInitialize(client, &format, NULL, 348 HRESULT hr = CoreAudioUtil::SharedModeInitialize(client, &format, NULL,
349 &endpoint_buffer_size); 349 &endpoint_buffer_size, NULL);
350 EXPECT_TRUE(SUCCEEDED(hr)); 350 EXPECT_TRUE(SUCCEEDED(hr));
351 EXPECT_GT(endpoint_buffer_size, 0u); 351 EXPECT_GT(endpoint_buffer_size, 0u);
352 352
353 // It is only possible to create a client once. 353 // It is only possible to create a client once.
354 hr = CoreAudioUtil::SharedModeInitialize(client, &format, NULL, 354 hr = CoreAudioUtil::SharedModeInitialize(client, &format, NULL,
355 &endpoint_buffer_size); 355 &endpoint_buffer_size, NULL);
356 EXPECT_FALSE(SUCCEEDED(hr)); 356 EXPECT_FALSE(SUCCEEDED(hr));
357 EXPECT_EQ(hr, AUDCLNT_E_ALREADY_INITIALIZED); 357 EXPECT_EQ(hr, AUDCLNT_E_ALREADY_INITIALIZED);
358 358
359 // Verify that it is possible to reinitialize the client after releasing it. 359 // Verify that it is possible to reinitialize the client after releasing it.
360 client = CoreAudioUtil::CreateDefaultClient(eRender, eConsole); 360 client = CoreAudioUtil::CreateDefaultClient(eRender, eConsole);
361 EXPECT_TRUE(client); 361 EXPECT_TRUE(client);
362 hr = CoreAudioUtil::SharedModeInitialize(client, &format, NULL, 362 hr = CoreAudioUtil::SharedModeInitialize(client, &format, NULL,
363 &endpoint_buffer_size); 363 &endpoint_buffer_size, NULL);
364 EXPECT_TRUE(SUCCEEDED(hr)); 364 EXPECT_TRUE(SUCCEEDED(hr));
365 EXPECT_GT(endpoint_buffer_size, 0u); 365 EXPECT_GT(endpoint_buffer_size, 0u);
366 366
367 // Use a non-supported format and verify that initialization fails. 367 // Use a non-supported format and verify that initialization fails.
368 // A simple way to emulate an invalid format is to use the shared-mode 368 // A simple way to emulate an invalid format is to use the shared-mode
369 // mixing format and modify the preferred sample. 369 // mixing format and modify the preferred sample.
370 client = CoreAudioUtil::CreateDefaultClient(eRender, eConsole); 370 client = CoreAudioUtil::CreateDefaultClient(eRender, eConsole);
371 EXPECT_TRUE(client); 371 EXPECT_TRUE(client);
372 format.Format.nSamplesPerSec = format.Format.nSamplesPerSec + 1; 372 format.Format.nSamplesPerSec = format.Format.nSamplesPerSec + 1;
373 EXPECT_FALSE(CoreAudioUtil::IsFormatSupported( 373 EXPECT_FALSE(CoreAudioUtil::IsFormatSupported(
374 client, AUDCLNT_SHAREMODE_SHARED, &format)); 374 client, AUDCLNT_SHAREMODE_SHARED, &format));
375 hr = CoreAudioUtil::SharedModeInitialize(client, &format, NULL, 375 hr = CoreAudioUtil::SharedModeInitialize(client, &format, NULL,
376 &endpoint_buffer_size); 376 &endpoint_buffer_size, NULL);
377 EXPECT_TRUE(FAILED(hr)); 377 EXPECT_TRUE(FAILED(hr));
378 EXPECT_EQ(hr, E_INVALIDARG); 378 EXPECT_EQ(hr, E_INVALIDARG);
379 379
380 // Finally, perform a shared-mode initialization using event-driven buffer 380 // Finally, perform a shared-mode initialization using event-driven buffer
381 // handling. The event handle will be signaled when an audio buffer is ready 381 // handling. The event handle will be signaled when an audio buffer is ready
382 // to be processed by the client (not verified here). 382 // to be processed by the client (not verified here).
383 // The event handle should be in the nonsignaled state. 383 // The event handle should be in the nonsignaled state.
384 base::win::ScopedHandle event_handle(::CreateEvent(NULL, TRUE, FALSE, NULL)); 384 base::win::ScopedHandle event_handle(::CreateEvent(NULL, TRUE, FALSE, NULL));
385 client = CoreAudioUtil::CreateDefaultClient(eRender, eConsole); 385 client = CoreAudioUtil::CreateDefaultClient(eRender, eConsole);
386 EXPECT_TRUE(client); 386 EXPECT_TRUE(client);
387 EXPECT_TRUE(SUCCEEDED(CoreAudioUtil::GetSharedModeMixFormat(client, 387 EXPECT_TRUE(SUCCEEDED(CoreAudioUtil::GetSharedModeMixFormat(client,
388 &format))); 388 &format)));
389 EXPECT_TRUE(CoreAudioUtil::IsFormatSupported( 389 EXPECT_TRUE(CoreAudioUtil::IsFormatSupported(
390 client, AUDCLNT_SHAREMODE_SHARED, &format)); 390 client, AUDCLNT_SHAREMODE_SHARED, &format));
391 hr = CoreAudioUtil::SharedModeInitialize(client, &format, event_handle.Get(), 391 hr = CoreAudioUtil::SharedModeInitialize(client, &format, event_handle.Get(),
392 &endpoint_buffer_size); 392 &endpoint_buffer_size, NULL);
393 EXPECT_TRUE(SUCCEEDED(hr)); 393 EXPECT_TRUE(SUCCEEDED(hr));
394 EXPECT_GT(endpoint_buffer_size, 0u); 394 EXPECT_GT(endpoint_buffer_size, 0u);
395 } 395 }
396 396
397 TEST_F(CoreAudioUtilWinTest, CreateRenderAndCaptureClients) { 397 TEST_F(CoreAudioUtilWinTest, CreateRenderAndCaptureClients) {
398 if (!CanRunAudioTest()) 398 if (!CanRunAudioTest())
399 return; 399 return;
400 400
401 EDataFlow data[] = {eRender, eCapture}; 401 EDataFlow data[] = {eRender, eCapture};
402 402
(...skipping 10 matching lines...) Expand all
413 EXPECT_TRUE(SUCCEEDED(CoreAudioUtil::GetSharedModeMixFormat(client, 413 EXPECT_TRUE(SUCCEEDED(CoreAudioUtil::GetSharedModeMixFormat(client,
414 &format))); 414 &format)));
415 if (data[i] == eRender) { 415 if (data[i] == eRender) {
416 // It is not possible to create a render client using an unitialized 416 // It is not possible to create a render client using an unitialized
417 // client interface. 417 // client interface.
418 render_client = CoreAudioUtil::CreateRenderClient(client); 418 render_client = CoreAudioUtil::CreateRenderClient(client);
419 EXPECT_FALSE(render_client); 419 EXPECT_FALSE(render_client);
420 420
421 // Do a proper initialization and verify that it works this time. 421 // Do a proper initialization and verify that it works this time.
422 CoreAudioUtil::SharedModeInitialize(client, &format, NULL, 422 CoreAudioUtil::SharedModeInitialize(client, &format, NULL,
423 &endpoint_buffer_size); 423 &endpoint_buffer_size, NULL);
424 render_client = CoreAudioUtil::CreateRenderClient(client); 424 render_client = CoreAudioUtil::CreateRenderClient(client);
425 EXPECT_TRUE(render_client); 425 EXPECT_TRUE(render_client);
426 EXPECT_GT(endpoint_buffer_size, 0u); 426 EXPECT_GT(endpoint_buffer_size, 0u);
427 } else if (data[i] == eCapture) { 427 } else if (data[i] == eCapture) {
428 // It is not possible to create a capture client using an unitialized 428 // It is not possible to create a capture client using an unitialized
429 // client interface. 429 // client interface.
430 capture_client = CoreAudioUtil::CreateCaptureClient(client); 430 capture_client = CoreAudioUtil::CreateCaptureClient(client);
431 EXPECT_FALSE(capture_client); 431 EXPECT_FALSE(capture_client);
432 432
433 // Do a proper initialization and verify that it works this time. 433 // Do a proper initialization and verify that it works this time.
434 CoreAudioUtil::SharedModeInitialize(client, &format, NULL, 434 CoreAudioUtil::SharedModeInitialize(client, &format, NULL,
435 &endpoint_buffer_size); 435 &endpoint_buffer_size, NULL);
436 capture_client = CoreAudioUtil::CreateCaptureClient(client); 436 capture_client = CoreAudioUtil::CreateCaptureClient(client);
437 EXPECT_TRUE(capture_client); 437 EXPECT_TRUE(capture_client);
438 EXPECT_GT(endpoint_buffer_size, 0u); 438 EXPECT_GT(endpoint_buffer_size, 0u);
439 } 439 }
440 } 440 }
441 } 441 }
442 442
443 TEST_F(CoreAudioUtilWinTest, FillRenderEndpointBufferWithSilence) { 443 TEST_F(CoreAudioUtilWinTest, FillRenderEndpointBufferWithSilence) {
444 if (!CanRunAudioTest()) 444 if (!CanRunAudioTest())
445 return; 445 return;
446 446
447 // Create default clients using the default mixing format for shared mode. 447 // Create default clients using the default mixing format for shared mode.
448 ScopedComPtr<IAudioClient> client( 448 ScopedComPtr<IAudioClient> client(
449 CoreAudioUtil::CreateDefaultClient(eRender, eConsole)); 449 CoreAudioUtil::CreateDefaultClient(eRender, eConsole));
450 EXPECT_TRUE(client); 450 EXPECT_TRUE(client);
451 451
452 WAVEFORMATPCMEX format; 452 WAVEFORMATPCMEX format;
453 uint32 endpoint_buffer_size = 0; 453 uint32 endpoint_buffer_size = 0;
454 EXPECT_TRUE(SUCCEEDED(CoreAudioUtil::GetSharedModeMixFormat(client, 454 EXPECT_TRUE(SUCCEEDED(CoreAudioUtil::GetSharedModeMixFormat(client,
455 &format))); 455 &format)));
456 CoreAudioUtil::SharedModeInitialize(client, &format, NULL, 456 CoreAudioUtil::SharedModeInitialize(client, &format, NULL,
457 &endpoint_buffer_size); 457 &endpoint_buffer_size, NULL);
458 EXPECT_GT(endpoint_buffer_size, 0u); 458 EXPECT_GT(endpoint_buffer_size, 0u);
459 459
460 ScopedComPtr<IAudioRenderClient> render_client( 460 ScopedComPtr<IAudioRenderClient> render_client(
461 CoreAudioUtil::CreateRenderClient(client)); 461 CoreAudioUtil::CreateRenderClient(client));
462 EXPECT_TRUE(render_client); 462 EXPECT_TRUE(render_client);
463 463
464 // The endpoint audio buffer should not be filled up by default after being 464 // The endpoint audio buffer should not be filled up by default after being
465 // created. 465 // created.
466 UINT32 num_queued_frames = 0; 466 UINT32 num_queued_frames = 0;
467 client->GetCurrentPadding(&num_queued_frames); 467 client->GetCurrentPadding(&num_queued_frames);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
513 513
514 TEST_F(CoreAudioUtilWinTest, GetDefaultOutputDeviceID) { 514 TEST_F(CoreAudioUtilWinTest, GetDefaultOutputDeviceID) {
515 if (!CanRunAudioTest()) 515 if (!CanRunAudioTest())
516 return; 516 return;
517 517
518 std::string default_device_id(CoreAudioUtil::GetDefaultOutputDeviceID()); 518 std::string default_device_id(CoreAudioUtil::GetDefaultOutputDeviceID());
519 EXPECT_FALSE(default_device_id.empty()); 519 EXPECT_FALSE(default_device_id.empty());
520 } 520 }
521 521
522 } // namespace media 522 } // namespace media
OLDNEW
« media/audio/win/core_audio_util_win.cc ('K') | « media/audio/win/core_audio_util_win.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698