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

Side by Side Diff: media/audio/audio_output_proxy_unittest.cc

Issue 12082111: Delete AudioOutputMixer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix .gyp Created 7 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « media/audio/audio_output_mixer.cc ('k') | media/audio/audio_util.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <string> 5 #include <string>
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/message_loop_proxy.h" 9 #include "base/message_loop_proxy.h"
10 #include "media/audio/audio_output_dispatcher_impl.h" 10 #include "media/audio/audio_output_dispatcher_impl.h"
11 #include "media/audio/audio_output_proxy.h" 11 #include "media/audio/audio_output_proxy.h"
12 #include "media/audio/audio_output_resampler.h" 12 #include "media/audio/audio_output_resampler.h"
13 #include "media/audio/audio_manager.h" 13 #include "media/audio/audio_manager.h"
14 #include "media/audio/audio_manager_base.h" 14 #include "media/audio/audio_manager_base.h"
15 #include "media/audio/fake_audio_output_stream.h" 15 #include "media/audio/fake_audio_output_stream.h"
16 #include "media/base/media_switches.h" 16 #include "media/base/media_switches.h"
17 #include "testing/gmock/include/gmock/gmock.h" 17 #include "testing/gmock/include/gmock/gmock.h"
18 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
19 19
20 // TODO(dalecurtis): Temporarily disabled while switching pipeline to use float,
21 // http://crbug.com/114700
22 #if defined(ENABLE_AUDIO_MIXER)
23 #include "media/audio/audio_output_mixer.h"
24 #endif
25
26 using ::testing::_; 20 using ::testing::_;
27 using ::testing::AllOf; 21 using ::testing::AllOf;
28 using ::testing::DoAll; 22 using ::testing::DoAll;
29 using ::testing::Field; 23 using ::testing::Field;
30 using ::testing::Mock; 24 using ::testing::Mock;
31 using ::testing::NotNull; 25 using ::testing::NotNull;
32 using ::testing::Return; 26 using ::testing::Return;
33 using ::testing::SetArrayArgument; 27 using ::testing::SetArrayArgument;
34 using media::AudioBus; 28 using media::AudioBus;
35 using media::AudioBuffersState; 29 using media::AudioBuffersState;
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 156
163 virtual void InitDispatcher(base::TimeDelta close_delay) { 157 virtual void InitDispatcher(base::TimeDelta close_delay) {
164 // Use a low sample rate and large buffer size when testing otherwise the 158 // Use a low sample rate and large buffer size when testing otherwise the
165 // FakeAudioOutputStream will keep the message loop busy indefinitely; i.e., 159 // FakeAudioOutputStream will keep the message loop busy indefinitely; i.e.,
166 // RunUntilIdle() will never terminate. 160 // RunUntilIdle() will never terminate.
167 params_ = AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, 161 params_ = AudioParameters(AudioParameters::AUDIO_PCM_LINEAR,
168 CHANNEL_LAYOUT_STEREO, 8000, 16, 2048); 162 CHANNEL_LAYOUT_STEREO, 8000, 16, 2048);
169 dispatcher_impl_ = new AudioOutputDispatcherImpl(&manager(), 163 dispatcher_impl_ = new AudioOutputDispatcherImpl(&manager(),
170 params_, 164 params_,
171 close_delay); 165 close_delay);
172 #if defined(ENABLE_AUDIO_MIXER)
173 mixer_ = new AudioOutputMixer(&manager(), params_, close_delay);
174 #endif
175 166
176 // Necessary to know how long the dispatcher will wait before posting 167 // Necessary to know how long the dispatcher will wait before posting
177 // StopStreamTask. 168 // StopStreamTask.
178 pause_delay_ = dispatcher_impl_->pause_delay_; 169 pause_delay_ = dispatcher_impl_->pause_delay_;
179 } 170 }
180 171
181 virtual void OnStart() {} 172 virtual void OnStart() {}
182 173
183 MockAudioManager& manager() { 174 MockAudioManager& manager() {
184 return manager_; 175 return manager_;
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 434
444 proxy->Start(&callback_); 435 proxy->Start(&callback_);
445 436
446 Mock::VerifyAndClear(&callback_); 437 Mock::VerifyAndClear(&callback_);
447 438
448 proxy->Close(); 439 proxy->Close();
449 } 440 }
450 441
451 MessageLoop message_loop_; 442 MessageLoop message_loop_;
452 scoped_refptr<AudioOutputDispatcherImpl> dispatcher_impl_; 443 scoped_refptr<AudioOutputDispatcherImpl> dispatcher_impl_;
453 #if defined(ENABLE_AUDIO_MIXER)
454 scoped_refptr<AudioOutputMixer> mixer_;
455 #endif
456 base::TimeDelta pause_delay_; 444 base::TimeDelta pause_delay_;
457 MockAudioManager manager_; 445 MockAudioManager manager_;
458 MockAudioSourceCallback callback_; 446 MockAudioSourceCallback callback_;
459 AudioParameters params_; 447 AudioParameters params_;
460 }; 448 };
461 449
462 class AudioOutputResamplerTest : public AudioOutputProxyTest { 450 class AudioOutputResamplerTest : public AudioOutputProxyTest {
463 public: 451 public:
464 virtual void TearDown() { 452 virtual void TearDown() {
465 AudioOutputProxyTest::TearDown(); 453 AudioOutputProxyTest::TearDown();
(...skipping 21 matching lines...) Expand all
487 protected: 475 protected:
488 AudioParameters resampler_params_; 476 AudioParameters resampler_params_;
489 scoped_refptr<AudioOutputResampler> resampler_; 477 scoped_refptr<AudioOutputResampler> resampler_;
490 }; 478 };
491 479
492 TEST_F(AudioOutputProxyTest, CreateAndClose) { 480 TEST_F(AudioOutputProxyTest, CreateAndClose) {
493 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher_impl_); 481 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher_impl_);
494 proxy->Close(); 482 proxy->Close();
495 } 483 }
496 484
497 #if defined(ENABLE_AUDIO_MIXER)
498 TEST_F(AudioOutputProxyTest, CreateAndClose_Mixer) {
499 AudioOutputProxy* proxy = new AudioOutputProxy(mixer_);
500 proxy->Close();
501 }
502 #endif
503
504 TEST_F(AudioOutputResamplerTest, CreateAndClose) { 485 TEST_F(AudioOutputResamplerTest, CreateAndClose) {
505 AudioOutputProxy* proxy = new AudioOutputProxy(resampler_); 486 AudioOutputProxy* proxy = new AudioOutputProxy(resampler_);
506 proxy->Close(); 487 proxy->Close();
507 } 488 }
508 489
509 TEST_F(AudioOutputProxyTest, OpenAndClose) { 490 TEST_F(AudioOutputProxyTest, OpenAndClose) {
510 OpenAndClose(dispatcher_impl_); 491 OpenAndClose(dispatcher_impl_);
511 } 492 }
512 493
513 #if defined(ENABLE_AUDIO_MIXER)
514 TEST_F(AudioOutputProxyTest, OpenAndClose_Mixer) {
515 OpenAndClose(mixer_);
516 }
517 #endif
518
519 TEST_F(AudioOutputResamplerTest, OpenAndClose) { 494 TEST_F(AudioOutputResamplerTest, OpenAndClose) {
520 OpenAndClose(resampler_); 495 OpenAndClose(resampler_);
521 } 496 }
522 497
523 // Create a stream, and verify that it is closed after kTestCloseDelayMs. 498 // Create a stream, and verify that it is closed after kTestCloseDelayMs.
524 // if it doesn't start playing. 499 // if it doesn't start playing.
525 TEST_F(AudioOutputProxyTest, CreateAndWait) { 500 TEST_F(AudioOutputProxyTest, CreateAndWait) {
526 CreateAndWait(dispatcher_impl_); 501 CreateAndWait(dispatcher_impl_);
527 } 502 }
528 503
529 // Create a stream, and verify that it is closed after kTestCloseDelayMs. 504 // Create a stream, and verify that it is closed after kTestCloseDelayMs.
530 // if it doesn't start playing. 505 // if it doesn't start playing.
531 TEST_F(AudioOutputResamplerTest, CreateAndWait) { 506 TEST_F(AudioOutputResamplerTest, CreateAndWait) {
532 CreateAndWait(resampler_); 507 CreateAndWait(resampler_);
533 } 508 }
534 509
535 TEST_F(AudioOutputProxyTest, StartAndStop) { 510 TEST_F(AudioOutputProxyTest, StartAndStop) {
536 StartAndStop(dispatcher_impl_); 511 StartAndStop(dispatcher_impl_);
537 } 512 }
538 513
539 #if defined(ENABLE_AUDIO_MIXER)
540 TEST_F(AudioOutputProxyTest, StartAndStop_Mixer) {
541 StartAndStop(mixer_);
542 }
543 #endif
544
545 TEST_F(AudioOutputResamplerTest, StartAndStop) { 514 TEST_F(AudioOutputResamplerTest, StartAndStop) {
546 StartAndStop(resampler_); 515 StartAndStop(resampler_);
547 } 516 }
548 517
549 TEST_F(AudioOutputProxyTest, CloseAfterStop) { 518 TEST_F(AudioOutputProxyTest, CloseAfterStop) {
550 CloseAfterStop(dispatcher_impl_); 519 CloseAfterStop(dispatcher_impl_);
551 } 520 }
552 521
553 #if defined(ENABLE_AUDIO_MIXER)
554 TEST_F(AudioOutputProxyTest, CloseAfterStop_Mixer) {
555 CloseAfterStop(mixer_);
556 }
557 #endif
558
559 TEST_F(AudioOutputResamplerTest, CloseAfterStop) { 522 TEST_F(AudioOutputResamplerTest, CloseAfterStop) {
560 CloseAfterStop(resampler_); 523 CloseAfterStop(resampler_);
561 } 524 }
562 525
563 TEST_F(AudioOutputProxyTest, TwoStreams) { 526 TEST_F(AudioOutputProxyTest, TwoStreams) {
564 TwoStreams(dispatcher_impl_); 527 TwoStreams(dispatcher_impl_);
565 } 528 }
566 529
567 #if defined(ENABLE_AUDIO_MIXER)
568 TEST_F(AudioOutputProxyTest, TwoStreams_Mixer) {
569 TwoStreams(mixer_);
570 }
571 #endif
572
573 TEST_F(AudioOutputResamplerTest, TwoStreams) { 530 TEST_F(AudioOutputResamplerTest, TwoStreams) {
574 TwoStreams(resampler_); 531 TwoStreams(resampler_);
575 } 532 }
576 533
577 // Two streams: verify that second stream is allocated when the first 534 // Two streams: verify that second stream is allocated when the first
578 // starts playing. 535 // starts playing.
579 TEST_F(AudioOutputProxyTest, TwoStreams_OnePlaying) { 536 TEST_F(AudioOutputProxyTest, TwoStreams_OnePlaying) {
580 InitDispatcher(base::TimeDelta::FromSeconds(kTestBigCloseDelaySeconds)); 537 InitDispatcher(base::TimeDelta::FromSeconds(kTestBigCloseDelaySeconds));
581 TwoStreams_OnePlaying(dispatcher_impl_); 538 TwoStreams_OnePlaying(dispatcher_impl_);
582 } 539 }
583 540
584 #if defined(ENABLE_AUDIO_MIXER)
585 // Two streams: verify that only one device will be created.
586 TEST_F(AudioOutputProxyTest, TwoStreams_OnePlaying_Mixer) {
587 MockAudioOutputStream stream(&manager_, params_);
588
589 InitDispatcher(base::TimeDelta::FromMilliseconds(kTestCloseDelayMs));
590
591 EXPECT_CALL(manager(), MakeAudioOutputStream(_))
592 .WillOnce(Return(&stream));
593
594 EXPECT_CALL(stream, Open())
595 .WillOnce(Return(true));
596 EXPECT_CALL(stream, Start(_))
597 .Times(1);
598 EXPECT_CALL(stream, SetVolume(_))
599 .Times(1);
600 EXPECT_CALL(stream, Stop())
601 .Times(1);
602 EXPECT_CALL(stream, Close())
603 .Times(1);
604
605 AudioOutputProxy* proxy1 = new AudioOutputProxy(mixer_);
606 AudioOutputProxy* proxy2 = new AudioOutputProxy(mixer_);
607 EXPECT_TRUE(proxy1->Open());
608 EXPECT_TRUE(proxy2->Open());
609
610 proxy1->Start(&callback_);
611 proxy1->Stop();
612
613 proxy1->Close();
614 proxy2->Close();
615 WaitForCloseTimer(kTestCloseDelayMs);
616 }
617 #endif
618
619 TEST_F(AudioOutputResamplerTest, TwoStreams_OnePlaying) { 541 TEST_F(AudioOutputResamplerTest, TwoStreams_OnePlaying) {
620 InitDispatcher(base::TimeDelta::FromSeconds(kTestBigCloseDelaySeconds)); 542 InitDispatcher(base::TimeDelta::FromSeconds(kTestBigCloseDelaySeconds));
621 TwoStreams_OnePlaying(resampler_); 543 TwoStreams_OnePlaying(resampler_);
622 } 544 }
623 545
624 // Two streams, both are playing. Dispatcher should not open a third stream. 546 // Two streams, both are playing. Dispatcher should not open a third stream.
625 TEST_F(AudioOutputProxyTest, TwoStreams_BothPlaying) { 547 TEST_F(AudioOutputProxyTest, TwoStreams_BothPlaying) {
626 InitDispatcher(base::TimeDelta::FromSeconds(kTestBigCloseDelaySeconds)); 548 InitDispatcher(base::TimeDelta::FromSeconds(kTestBigCloseDelaySeconds));
627 TwoStreams_BothPlaying(dispatcher_impl_); 549 TwoStreams_BothPlaying(dispatcher_impl_);
628 } 550 }
629 551
630 #if defined(ENABLE_AUDIO_MIXER)
631 // Two streams, both are playing. Still have to use single device.
632 // Also verifies that every proxy stream gets its own pending_bytes.
633 TEST_F(AudioOutputProxyTest, TwoStreams_BothPlaying_Mixer) {
634 MockAudioOutputStream stream(&manager_, params_);
635
636 InitDispatcher(base::TimeDelta::FromMilliseconds(kTestCloseDelayMs));
637
638 EXPECT_CALL(manager(), MakeAudioOutputStream(_))
639 .WillOnce(Return(&stream));
640
641 EXPECT_CALL(stream, Open())
642 .WillOnce(Return(true));
643 EXPECT_CALL(stream, Start(_))
644 .Times(1);
645 EXPECT_CALL(stream, SetVolume(_))
646 .Times(1);
647 EXPECT_CALL(stream, Stop())
648 .Times(1);
649 EXPECT_CALL(stream, Close())
650 .Times(1);
651
652 AudioOutputProxy* proxy1 = new AudioOutputProxy(mixer_);
653 AudioOutputProxy* proxy2 = new AudioOutputProxy(mixer_);
654 EXPECT_TRUE(proxy1->Open());
655 EXPECT_TRUE(proxy2->Open());
656
657 proxy1->Start(&callback_);
658
659 // Mute the proxy. Resulting stream should still have correct length.
660 proxy1->SetVolume(0.0);
661
662 uint8 zeroes[4] = {0, 0, 0, 0};
663 uint8 buf1[4] = {0};
664 EXPECT_CALL(callback_,
665 OnMoreData(NotNull(), 4,
666 AllOf(Field(&AudioBuffersState::pending_bytes, 0),
667 Field(&AudioBuffersState::hardware_delay_bytes, 0))))
668 .WillOnce(DoAll(SetArrayArgument<0>(zeroes, zeroes + sizeof(zeroes)),
669 Return(4)));
670 mixer_->OnMoreData(buf1, sizeof(buf1), AudioBuffersState(0, 0));
671 proxy2->Start(&callback_);
672 uint8 buf2[4] = {0};
673 EXPECT_CALL(callback_,
674 OnMoreData(NotNull(), 4,
675 AllOf(Field(&AudioBuffersState::pending_bytes, 4),
676 Field(&AudioBuffersState::hardware_delay_bytes, 0))))
677 .WillOnce(DoAll(SetArrayArgument<0>(zeroes, zeroes + sizeof(zeroes)),
678 Return(4)));
679 EXPECT_CALL(callback_,
680 OnMoreData(NotNull(), 4,
681 AllOf(Field(&AudioBuffersState::pending_bytes, 0),
682 Field(&AudioBuffersState::hardware_delay_bytes, 0))))
683 .WillOnce(DoAll(SetArrayArgument<0>(zeroes, zeroes + sizeof(zeroes)),
684 Return(4)));
685 mixer_->OnMoreData(buf2, sizeof(buf2), AudioBuffersState(4, 0));
686 proxy1->Stop();
687 proxy2->Stop();
688
689 proxy1->Close();
690 proxy2->Close();
691 WaitForCloseTimer(kTestCloseDelayMs);
692 }
693 #endif
694
695 TEST_F(AudioOutputResamplerTest, TwoStreams_BothPlaying) { 552 TEST_F(AudioOutputResamplerTest, TwoStreams_BothPlaying) {
696 InitDispatcher(base::TimeDelta::FromSeconds(kTestBigCloseDelaySeconds)); 553 InitDispatcher(base::TimeDelta::FromSeconds(kTestBigCloseDelaySeconds));
697 TwoStreams_BothPlaying(resampler_); 554 TwoStreams_BothPlaying(resampler_);
698 } 555 }
699 556
700 TEST_F(AudioOutputProxyTest, OpenFailed) { 557 TEST_F(AudioOutputProxyTest, OpenFailed) {
701 OpenFailed(dispatcher_impl_); 558 OpenFailed(dispatcher_impl_);
702 } 559 }
703 560
704 #if defined(ENABLE_AUDIO_MIXER)
705 TEST_F(AudioOutputProxyTest, OpenFailed_Mixer) {
706 OpenFailed(mixer_);
707 }
708 #endif
709
710 TEST_F(AudioOutputResamplerTest, OpenFailed) { 561 TEST_F(AudioOutputResamplerTest, OpenFailed) {
711 CommandLine::ForCurrentProcess()->AppendSwitch( 562 CommandLine::ForCurrentProcess()->AppendSwitch(
712 switches::kDisableAudioFallback); 563 switches::kDisableAudioFallback);
713 OpenFailed(resampler_); 564 OpenFailed(resampler_);
714 } 565 }
715 566
716 // Start() method failed. 567 // Start() method failed.
717 TEST_F(AudioOutputProxyTest, StartFailed) { 568 TEST_F(AudioOutputProxyTest, StartFailed) {
718 StartFailed(dispatcher_impl_); 569 StartFailed(dispatcher_impl_);
719 } 570 }
720 571
721 #if defined(ENABLE_AUDIO_MIXER)
722 // Start() method failed.
723 TEST_F(AudioOutputProxyTest, StartFailed_Mixer) {
724 MockAudioOutputStream stream(&manager_, params_);
725
726 EXPECT_CALL(manager(), MakeAudioOutputStream(_))
727 .WillOnce(Return(&stream));
728 EXPECT_CALL(stream, Open())
729 .WillOnce(Return(true));
730 EXPECT_CALL(stream, Close())
731 .Times(1);
732 EXPECT_CALL(stream, Start(_))
733 .Times(1);
734 EXPECT_CALL(stream, SetVolume(_))
735 .Times(1);
736 EXPECT_CALL(stream, Stop())
737 .Times(1);
738
739 AudioOutputProxy* proxy1 = new AudioOutputProxy(mixer_);
740 AudioOutputProxy* proxy2 = new AudioOutputProxy(mixer_);
741 EXPECT_TRUE(proxy1->Open());
742 EXPECT_TRUE(proxy2->Open());
743 proxy1->Start(&callback_);
744 proxy1->Stop();
745 proxy1->Close();
746 WaitForCloseTimer(kTestCloseDelayMs);
747
748 // Verify expectation before continueing.
749 Mock::VerifyAndClear(&stream);
750
751 // |stream| is closed at this point. Start() should reopen it again.
752 EXPECT_CALL(manager(), MakeAudioOutputStream(_))
753 .WillOnce(Return(reinterpret_cast<AudioOutputStream*>(NULL)));
754
755 EXPECT_CALL(callback_, OnError(_, _))
756 .Times(1);
757
758 proxy2->Start(&callback_);
759
760 Mock::VerifyAndClear(&callback_);
761
762 proxy2->Close();
763 WaitForCloseTimer(kTestCloseDelayMs);
764 }
765 #endif
766
767 TEST_F(AudioOutputResamplerTest, StartFailed) { 572 TEST_F(AudioOutputResamplerTest, StartFailed) {
768 StartFailed(resampler_); 573 StartFailed(resampler_);
769 } 574 }
770 575
771 // Simulate AudioOutputStream::Create() failure with a low latency stream and 576 // Simulate AudioOutputStream::Create() failure with a low latency stream and
772 // ensure AudioOutputResampler falls back to the high latency path. 577 // ensure AudioOutputResampler falls back to the high latency path.
773 TEST_F(AudioOutputResamplerTest, LowLatencyCreateFailedFallback) { 578 TEST_F(AudioOutputResamplerTest, LowLatencyCreateFailedFallback) {
774 MockAudioOutputStream stream(&manager_, params_); 579 MockAudioOutputStream stream(&manager_, params_);
775 EXPECT_CALL(manager(), MakeAudioOutputStream(_)) 580 EXPECT_CALL(manager(), MakeAudioOutputStream(_))
776 .Times(2) 581 .Times(2)
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
891 WaitForCloseTimer(kTestCloseDelayMs); 696 WaitForCloseTimer(kTestCloseDelayMs);
892 EXPECT_TRUE(stream1.stop_called()); 697 EXPECT_TRUE(stream1.stop_called());
893 EXPECT_TRUE(stream1.start_called()); 698 EXPECT_TRUE(stream1.start_called());
894 EXPECT_TRUE(stream2.stop_called()); 699 EXPECT_TRUE(stream2.stop_called());
895 EXPECT_TRUE(stream2.start_called()); 700 EXPECT_TRUE(stream2.start_called());
896 EXPECT_FALSE(stream3.stop_called()); 701 EXPECT_FALSE(stream3.stop_called());
897 EXPECT_FALSE(stream3.start_called()); 702 EXPECT_FALSE(stream3.start_called());
898 } 703 }
899 704
900 } // namespace media 705 } // namespace media
OLDNEW
« no previous file with comments | « media/audio/audio_output_mixer.cc ('k') | media/audio/audio_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698