| OLD | NEW |
| 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/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/bind_helpers.h" | 6 #include "base/bind_helpers.h" |
| 7 #include "media/base/audio_renderer_mixer.h" | 7 #include "media/base/audio_renderer_mixer.h" |
| 8 #include "media/base/audio_renderer_mixer_input.h" | 8 #include "media/base/audio_renderer_mixer_input.h" |
| 9 #include "media/base/fake_audio_render_callback.h" | 9 #include "media/base/fake_audio_render_callback.h" |
| 10 #include "media/base/mock_audio_renderer_sink.h" | 10 #include "media/base/mock_audio_renderer_sink.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 public: | 22 public: |
| 23 AudioRendererMixerInputTest() { | 23 AudioRendererMixerInputTest() { |
| 24 audio_parameters_ = AudioParameters( | 24 audio_parameters_ = AudioParameters( |
| 25 AudioParameters::AUDIO_PCM_LINEAR, kChannelLayout, kSampleRate, | 25 AudioParameters::AUDIO_PCM_LINEAR, kChannelLayout, kSampleRate, |
| 26 kBitsPerChannel, kBufferSize); | 26 kBitsPerChannel, kBufferSize); |
| 27 | 27 |
| 28 CreateMixerInput(); | 28 CreateMixerInput(); |
| 29 fake_callback_.reset(new FakeAudioRenderCallback(0)); | 29 fake_callback_.reset(new FakeAudioRenderCallback(0)); |
| 30 mixer_input_->Initialize(audio_parameters_, fake_callback_.get()); | 30 mixer_input_->Initialize(audio_parameters_, fake_callback_.get()); |
| 31 EXPECT_CALL(*this, RemoveMixer(testing::_)); | 31 EXPECT_CALL(*this, RemoveMixer(testing::_)); |
| 32 audio_bus_ = AudioBus::Create(audio_parameters_); |
| 32 } | 33 } |
| 33 | 34 |
| 34 void CreateMixerInput() { | 35 void CreateMixerInput() { |
| 35 mixer_input_ = new AudioRendererMixerInput( | 36 mixer_input_ = new AudioRendererMixerInput( |
| 36 base::Bind( | 37 base::Bind( |
| 37 &AudioRendererMixerInputTest::GetMixer, base::Unretained(this)), | 38 &AudioRendererMixerInputTest::GetMixer, base::Unretained(this)), |
| 38 base::Bind( | 39 base::Bind( |
| 39 &AudioRendererMixerInputTest::RemoveMixer, base::Unretained(this))); | 40 &AudioRendererMixerInputTest::RemoveMixer, base::Unretained(this))); |
| 40 } | 41 } |
| 41 | 42 |
| 42 AudioRendererMixer* GetMixer(const AudioParameters& params) { | 43 AudioRendererMixer* GetMixer(const AudioParameters& params) { |
| 43 if (!mixer_.get()) { | 44 if (!mixer_.get()) { |
| 44 scoped_refptr<MockAudioRendererSink> sink = new MockAudioRendererSink(); | 45 scoped_refptr<MockAudioRendererSink> sink = new MockAudioRendererSink(); |
| 45 EXPECT_CALL(*sink, Start()); | 46 EXPECT_CALL(*sink, Start()); |
| 46 EXPECT_CALL(*sink, Stop()); | 47 EXPECT_CALL(*sink, Stop()); |
| 47 | 48 |
| 48 mixer_.reset(new AudioRendererMixer( | 49 mixer_.reset(new AudioRendererMixer( |
| 49 audio_parameters_, audio_parameters_, sink)); | 50 audio_parameters_, audio_parameters_, sink)); |
| 50 } | 51 } |
| 51 return mixer_.get(); | 52 return mixer_.get(); |
| 52 } | 53 } |
| 53 | 54 |
| 55 float ProvideInput() { |
| 56 return mixer_input_->ProvideAudioTransformInput( |
| 57 audio_bus_.get(), base::TimeDelta()); |
| 58 } |
| 59 |
| 60 int GetAudioDelayMilliseconds() { |
| 61 return mixer_input_->current_audio_delay_milliseconds_; |
| 62 } |
| 63 |
| 54 MOCK_METHOD1(RemoveMixer, void(const AudioParameters&)); | 64 MOCK_METHOD1(RemoveMixer, void(const AudioParameters&)); |
| 55 | 65 |
| 56 protected: | 66 protected: |
| 57 virtual ~AudioRendererMixerInputTest() {} | 67 virtual ~AudioRendererMixerInputTest() {} |
| 58 | 68 |
| 59 AudioParameters audio_parameters_; | 69 AudioParameters audio_parameters_; |
| 60 scoped_ptr<AudioRendererMixer> mixer_; | 70 scoped_ptr<AudioRendererMixer> mixer_; |
| 61 scoped_refptr<AudioRendererMixerInput> mixer_input_; | 71 scoped_refptr<AudioRendererMixerInput> mixer_input_; |
| 62 scoped_ptr<FakeAudioRenderCallback> fake_callback_; | 72 scoped_ptr<FakeAudioRenderCallback> fake_callback_; |
| 73 scoped_ptr<AudioBus> audio_bus_; |
| 63 | 74 |
| 64 DISALLOW_COPY_AND_ASSIGN(AudioRendererMixerInputTest); | 75 DISALLOW_COPY_AND_ASSIGN(AudioRendererMixerInputTest); |
| 65 }; | 76 }; |
| 66 | 77 |
| 67 // Test callback() works as expected. | 78 // Test that getting and setting the volume work as expected. The volume is |
| 68 TEST_F(AudioRendererMixerInputTest, GetCallback) { | 79 // returned from ProvideInput() only when playing. |
| 69 EXPECT_EQ(mixer_input_->callback(), fake_callback_.get()); | 80 TEST_F(AudioRendererMixerInputTest, GetSetVolume) { |
| 70 } | 81 mixer_input_->Start(); |
| 82 mixer_input_->Play(); |
| 71 | 83 |
| 72 // Test that getting and setting the volume work as expected. | 84 // Starting volume should be 1.0. |
| 73 TEST_F(AudioRendererMixerInputTest, GetSetVolume) { | 85 EXPECT_FLOAT_EQ(ProvideInput(), 1); |
| 74 // Starting volume should be 0. | |
| 75 double volume = 1.0f; | |
| 76 mixer_input_->GetVolume(&volume); | |
| 77 EXPECT_EQ(volume, 1.0f); | |
| 78 | 86 |
| 79 const double kVolume = 0.5f; | 87 const double kVolume = 0.5; |
| 80 EXPECT_TRUE(mixer_input_->SetVolume(kVolume)); | 88 EXPECT_TRUE(mixer_input_->SetVolume(kVolume)); |
| 81 mixer_input_->GetVolume(&volume); | 89 EXPECT_FLOAT_EQ(ProvideInput(), kVolume); |
| 82 EXPECT_EQ(volume, kVolume); | 90 |
| 91 mixer_input_->Stop(); |
| 83 } | 92 } |
| 84 | 93 |
| 85 // Test Start()/Play()/Pause()/Stop()/playing() all work as expected. Also | 94 // Test Start()/Play()/Pause()/Stop()/playing() all work as expected. Also |
| 86 // implicitly tests that AddMixerInput() and RemoveMixerInput() work without | 95 // implicitly tests that AddMixerInput() and RemoveMixerInput() work without |
| 87 // crashing; functional tests for these methods are in AudioRendererMixerTest. | 96 // crashing; functional tests for these methods are in AudioRendererMixerTest. |
| 88 TEST_F(AudioRendererMixerInputTest, StartPlayPauseStopPlaying) { | 97 TEST_F(AudioRendererMixerInputTest, StartPlayPauseStopPlaying) { |
| 89 mixer_input_->Start(); | 98 mixer_input_->Start(); |
| 90 EXPECT_FALSE(mixer_input_->playing()); | 99 EXPECT_FLOAT_EQ(ProvideInput(), 0); |
| 91 mixer_input_->Play(); | 100 mixer_input_->Play(); |
| 92 EXPECT_TRUE(mixer_input_->playing()); | 101 EXPECT_FLOAT_EQ(ProvideInput(), 1); |
| 93 mixer_input_->Pause(false); | 102 mixer_input_->Pause(false); |
| 94 EXPECT_FALSE(mixer_input_->playing()); | 103 EXPECT_FLOAT_EQ(ProvideInput(), 0); |
| 95 mixer_input_->Play(); | 104 mixer_input_->Play(); |
| 96 EXPECT_TRUE(mixer_input_->playing()); | 105 EXPECT_FLOAT_EQ(ProvideInput(), 1); |
| 97 mixer_input_->Stop(); | 106 mixer_input_->Stop(); |
| 98 EXPECT_FALSE(mixer_input_->playing()); | 107 EXPECT_FLOAT_EQ(ProvideInput(), 0); |
| 99 } | 108 } |
| 100 | 109 |
| 101 // Test that Stop() can be called before Initialize() and Start(). | 110 // Test that Stop() can be called before Initialize() and Start(). |
| 102 TEST_F(AudioRendererMixerInputTest, StopBeforeInitializeOrStart) { | 111 TEST_F(AudioRendererMixerInputTest, StopBeforeInitializeOrStart) { |
| 103 // |mixer_input_| was initialized during construction. | 112 // |mixer_input_| was initialized during construction. |
| 104 mixer_input_->Stop(); | 113 mixer_input_->Stop(); |
| 105 | 114 |
| 106 // Verify Stop() works without Initialize() or Start(). | 115 // Verify Stop() works without Initialize() or Start(). |
| 107 CreateMixerInput(); | 116 CreateMixerInput(); |
| 108 mixer_input_->Stop(); | 117 mixer_input_->Stop(); |
| 109 } | 118 } |
| 110 | 119 |
| 111 } // namespace media | 120 } // namespace media |
| OLD | NEW |