Chromium Code Reviews| 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 "media/audio/audio_util.h" | |
| 6 #include "media/audio/null_audio_sink.h" | |
| 7 #include "media/base/audio_renderer_mixer.h" | 5 #include "media/base/audio_renderer_mixer.h" |
| 8 #include "media/base/audio_renderer_mixer_input.h" | 6 #include "media/base/audio_renderer_mixer_input.h" |
| 9 #include "media/base/fake_audio_render_callback.h" | 7 #include "media/base/fake_audio_render_callback.h" |
| 8 #include "media/base/mock_audio_renderer_sink.h" | |
| 10 #include "testing/gmock/include/gmock/gmock.h" | 9 #include "testing/gmock/include/gmock/gmock.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 12 | 11 |
| 13 namespace media { | 12 namespace media { |
| 14 | 13 |
| 15 static const int kBitsPerChannel = 16; | 14 static const int kBitsPerChannel = 16; |
| 16 static const int kSampleRate = 48000; | 15 static const int kSampleRate = 48000; |
| 16 static const int kBufferSize = 8192; | |
| 17 static const ChannelLayout kChannelLayout = CHANNEL_LAYOUT_STEREO; | 17 static const ChannelLayout kChannelLayout = CHANNEL_LAYOUT_STEREO; |
| 18 | 18 |
| 19 class AudioRendererMixerInputTest : public ::testing::Test { | 19 class AudioRendererMixerInputTest : public testing::Test { |
| 20 public: | 20 public: |
| 21 AudioRendererMixerInputTest() { | 21 AudioRendererMixerInputTest() { |
| 22 audio_parameters_ = AudioParameters( | 22 audio_parameters_ = AudioParameters( |
| 23 AudioParameters::AUDIO_PCM_LINEAR, kChannelLayout, kSampleRate, | 23 AudioParameters::AUDIO_PCM_LINEAR, kChannelLayout, kSampleRate, |
| 24 kBitsPerChannel, GetHighLatencyOutputBufferSize(kSampleRate)); | 24 kBitsPerChannel, kBufferSize); |
| 25 | 25 |
| 26 mixer_ = new AudioRendererMixer(audio_parameters_, new NullAudioSink()); | 26 scoped_refptr<MockAudioRendererSink> sink = new MockAudioRendererSink(); |
| 27 EXPECT_CALL(*sink, Start()); | |
| 28 EXPECT_CALL(*sink, Stop()); | |
|
scherkus (not reviewing)
2012/07/12 23:02:52
ideally you should try to move this closer to wher
DaleCurtis
2012/07/12 23:16:29
Would need to make sink a class variable then, it
scherkus (not reviewing)
2012/07/14 01:45:02
ah didn't notice sink wasn't saved anywhere -- wha
| |
| 29 mixer_ = new AudioRendererMixer(audio_parameters_, audio_parameters_, sink); | |
| 27 mixer_input_ = new AudioRendererMixerInput(mixer_); | 30 mixer_input_ = new AudioRendererMixerInput(mixer_); |
| 28 fake_callback_.reset(new FakeAudioRenderCallback(audio_parameters_)); | 31 fake_callback_.reset(new FakeAudioRenderCallback(0)); |
| 29 mixer_input_->Initialize(audio_parameters_, fake_callback_.get()); | 32 mixer_input_->Initialize(audio_parameters_, fake_callback_.get()); |
| 30 } | 33 EXPECT_TRUE(sink->callback()); |
| 31 | |
| 32 // Render audio_parameters_.frames_per_buffer() frames into |audio_data_| and | |
| 33 // verify the result against |check_value|. | |
| 34 void RenderAndValidateAudioData(float check_value) { | |
| 35 const std::vector<float*>& audio_data = mixer_input_->audio_data(); | |
| 36 | |
| 37 ASSERT_EQ(fake_callback_->Render( | |
| 38 audio_data, audio_parameters_.frames_per_buffer(), 0), | |
| 39 audio_parameters_.frames_per_buffer()); | |
| 40 | |
| 41 for (size_t i = 0; i < audio_data.size(); ++i) | |
| 42 for (int j = 0; j < audio_parameters_.frames_per_buffer(); j++) | |
| 43 ASSERT_FLOAT_EQ(check_value, audio_data[i][j]); | |
| 44 } | 34 } |
| 45 | 35 |
| 46 protected: | 36 protected: |
| 47 virtual ~AudioRendererMixerInputTest() {} | 37 virtual ~AudioRendererMixerInputTest() {} |
| 48 | 38 |
| 49 AudioParameters audio_parameters_; | 39 AudioParameters audio_parameters_; |
| 50 scoped_refptr<AudioRendererMixer> mixer_; | 40 scoped_refptr<AudioRendererMixer> mixer_; |
| 51 scoped_refptr<AudioRendererMixerInput> mixer_input_; | 41 scoped_refptr<AudioRendererMixerInput> mixer_input_; |
| 52 scoped_ptr<FakeAudioRenderCallback> fake_callback_; | 42 scoped_ptr<FakeAudioRenderCallback> fake_callback_; |
| 53 | 43 |
| 54 DISALLOW_COPY_AND_ASSIGN(AudioRendererMixerInputTest); | 44 DISALLOW_COPY_AND_ASSIGN(AudioRendererMixerInputTest); |
| 55 }; | 45 }; |
| 56 | 46 |
| 47 // Test callback() works as expected. | |
| 48 TEST_F(AudioRendererMixerInputTest, GetCallback) { | |
| 49 EXPECT_EQ(mixer_input_->callback(), fake_callback_.get()); | |
| 50 } | |
| 51 | |
| 57 // Test that getting and setting the volume work as expected. | 52 // Test that getting and setting the volume work as expected. |
| 58 TEST_F(AudioRendererMixerInputTest, GetSetVolume) { | 53 TEST_F(AudioRendererMixerInputTest, GetSetVolume) { |
| 59 // Starting volume should be 0. | 54 // Starting volume should be 0. |
| 60 double volume = 1.0f; | 55 double volume = 1.0f; |
| 61 mixer_input_->GetVolume(&volume); | 56 mixer_input_->GetVolume(&volume); |
| 62 EXPECT_EQ(volume, 1.0f); | 57 EXPECT_EQ(volume, 1.0f); |
| 63 | 58 |
| 64 const double kVolume = 0.5f; | 59 const double kVolume = 0.5f; |
| 65 EXPECT_TRUE(mixer_input_->SetVolume(kVolume)); | 60 EXPECT_TRUE(mixer_input_->SetVolume(kVolume)); |
| 66 mixer_input_->GetVolume(&volume); | 61 mixer_input_->GetVolume(&volume); |
| 67 EXPECT_EQ(volume, kVolume); | 62 EXPECT_EQ(volume, kVolume); |
| 68 } | 63 } |
| 69 | 64 |
| 70 // Test audio_data() is allocated correctly. | |
| 71 TEST_F(AudioRendererMixerInputTest, GetAudioData) { | |
| 72 RenderAndValidateAudioData(fake_callback_->fill_value()); | |
| 73 | |
| 74 // TODO(dalecurtis): Perform alignment and size checks when we switch over to | |
| 75 // FFmpeg optimized vector_fmac. | |
| 76 } | |
| 77 | |
| 78 // Test callback() works as expected. | |
| 79 TEST_F(AudioRendererMixerInputTest, GetCallback) { | |
| 80 EXPECT_EQ(mixer_input_->callback(), fake_callback_.get()); | |
| 81 RenderAndValidateAudioData(fake_callback_->fill_value()); | |
| 82 } | |
| 83 | |
| 84 // Test Start()/Play()/Pause()/Stop()/playing() all work as expected. Also | 65 // Test Start()/Play()/Pause()/Stop()/playing() all work as expected. Also |
| 85 // implicitly tests that AddMixerInput() and RemoveMixerInput() work without | 66 // implicitly tests that AddMixerInput() and RemoveMixerInput() work without |
| 86 // crashing; functional tests for these methods are in AudioRendererMixerTest. | 67 // crashing; functional tests for these methods are in AudioRendererMixerTest. |
| 87 TEST_F(AudioRendererMixerInputTest, StartPlayPauseStopPlaying) { | 68 TEST_F(AudioRendererMixerInputTest, StartPlayPauseStopPlaying) { |
| 88 mixer_input_->Start(); | 69 mixer_input_->Start(); |
| 89 EXPECT_FALSE(mixer_input_->playing()); | 70 EXPECT_FALSE(mixer_input_->playing()); |
| 90 mixer_input_->Play(); | 71 mixer_input_->Play(); |
| 91 EXPECT_TRUE(mixer_input_->playing()); | 72 EXPECT_TRUE(mixer_input_->playing()); |
| 92 mixer_input_->Pause(false); | 73 mixer_input_->Pause(false); |
| 93 EXPECT_FALSE(mixer_input_->playing()); | 74 EXPECT_FALSE(mixer_input_->playing()); |
| 94 mixer_input_->Play(); | 75 mixer_input_->Play(); |
| 95 EXPECT_TRUE(mixer_input_->playing()); | 76 EXPECT_TRUE(mixer_input_->playing()); |
| 96 mixer_input_->Stop(); | 77 mixer_input_->Stop(); |
| 97 EXPECT_FALSE(mixer_input_->playing()); | 78 EXPECT_FALSE(mixer_input_->playing()); |
| 98 } | 79 } |
| 99 | 80 |
| 100 } // namespace media | 81 } // namespace media |
| OLD | NEW |