| 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 // MSVC++ requires this to be set before any other includes to get M_PI. | 5 // MSVC++ requires this to be set before any other includes to get M_PI. |
| 6 #define _USE_MATH_DEFINES | 6 #define _USE_MATH_DEFINES |
| 7 | 7 |
| 8 #include "media/base/audio_renderer_mixer.h" | 8 #include "media/base/audio_renderer_mixer.h" |
| 9 | 9 |
| 10 #include <stddef.h> | 10 #include <stddef.h> |
| 11 | 11 |
| 12 #include <cmath> | 12 #include <cmath> |
| 13 #include <memory> | 13 #include <memory> |
| 14 | 14 |
| 15 #include "base/bind.h" | 15 #include "base/bind.h" |
| 16 #include "base/bind_helpers.h" | 16 #include "base/bind_helpers.h" |
| 17 #include "base/macros.h" | 17 #include "base/macros.h" |
| 18 #include "base/memory/scoped_vector.h" | 18 #include "base/memory/scoped_vector.h" |
| 19 #include "base/synchronization/waitable_event.h" | 19 #include "base/synchronization/waitable_event.h" |
| 20 #include "base/threading/platform_thread.h" | 20 #include "base/threading/platform_thread.h" |
| 21 #include "media/base/audio_renderer_mixer_input.h" | 21 #include "media/base/audio_renderer_mixer_input.h" |
| 22 #include "media/base/audio_renderer_mixer_pool.h" | 22 #include "media/base/audio_renderer_mixer_pool.h" |
| 23 #include "media/base/fake_audio_render_callback.h" | 23 #include "media/base/fake_audio_render_callback.h" |
| 24 #include "media/base/mock_audio_renderer_sink.h" | 24 #include "media/base/mock_audio_renderer_sink.h" |
| 25 #include "testing/gmock/include/gmock/gmock.h" | 25 #include "testing/gmock/include/gmock/gmock.h" |
| 26 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
| 27 | 27 |
| 28 namespace { |
| 29 void LogUma(int value) {} |
| 30 } |
| 31 |
| 28 namespace media { | 32 namespace media { |
| 29 | 33 |
| 30 // Parameters which control the many input case tests. | 34 // Parameters which control the many input case tests. |
| 31 const int kMixerInputs = 8; | 35 const int kMixerInputs = 8; |
| 32 const int kOddMixerInputs = 7; | 36 const int kOddMixerInputs = 7; |
| 33 const int kMixerCycles = 3; | 37 const int kMixerCycles = 3; |
| 34 | 38 |
| 35 // Parameters used for testing. | 39 // Parameters used for testing. |
| 36 const int kBitsPerChannel = 32; | 40 const int kBitsPerChannel = 32; |
| 37 const ChannelLayout kChannelLayout = CHANNEL_LAYOUT_STEREO; | 41 const ChannelLayout kChannelLayout = CHANNEL_LAYOUT_STEREO; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 67 | 71 |
| 68 // Create output parameters based on test parameters. | 72 // Create output parameters based on test parameters. |
| 69 output_parameters_ = AudioParameters( | 73 output_parameters_ = AudioParameters( |
| 70 AudioParameters::AUDIO_PCM_LOW_LATENCY, kChannelLayout, | 74 AudioParameters::AUDIO_PCM_LOW_LATENCY, kChannelLayout, |
| 71 std::tr1::get<2>(GetParam()), 16, kLowLatencyBufferSize); | 75 std::tr1::get<2>(GetParam()), 16, kLowLatencyBufferSize); |
| 72 | 76 |
| 73 sink_ = new MockAudioRendererSink(); | 77 sink_ = new MockAudioRendererSink(); |
| 74 EXPECT_CALL(*sink_.get(), Start()); | 78 EXPECT_CALL(*sink_.get(), Start()); |
| 75 EXPECT_CALL(*sink_.get(), Stop()); | 79 EXPECT_CALL(*sink_.get(), Stop()); |
| 76 | 80 |
| 77 mixer_.reset(new AudioRendererMixer(output_parameters_, sink_)); | 81 mixer_.reset( |
| 82 new AudioRendererMixer(output_parameters_, sink_, base::Bind(&LogUma))); |
| 78 mixer_callback_ = sink_->callback(); | 83 mixer_callback_ = sink_->callback(); |
| 79 | 84 |
| 80 audio_bus_ = AudioBus::Create(output_parameters_); | 85 audio_bus_ = AudioBus::Create(output_parameters_); |
| 81 expected_audio_bus_ = AudioBus::Create(output_parameters_); | 86 expected_audio_bus_ = AudioBus::Create(output_parameters_); |
| 82 | 87 |
| 83 // Allocate one callback for generating expected results. | 88 // Allocate one callback for generating expected results. |
| 84 double step = kSineCycles / static_cast<double>( | 89 double step = kSineCycles / static_cast<double>( |
| 85 output_parameters_.frames_per_buffer()); | 90 output_parameters_.frames_per_buffer()); |
| 86 expected_callback_.reset(new FakeAudioRenderCallback(step)); | 91 expected_callback_.reset(new FakeAudioRenderCallback(step)); |
| 87 } | 92 } |
| 88 | 93 |
| 89 AudioRendererMixer* GetMixer(int owner_id, | 94 AudioRendererMixer* GetMixer(int owner_id, |
| 90 const AudioParameters& params, | 95 const AudioParameters& params, |
| 96 AudioLatency::LatencyType latency, |
| 91 const std::string& device_id, | 97 const std::string& device_id, |
| 92 const url::Origin& security_origin, | 98 const url::Origin& security_origin, |
| 93 OutputDeviceStatus* device_status) final { | 99 OutputDeviceStatus* device_status) final { |
| 94 return mixer_.get(); | 100 return mixer_.get(); |
| 95 }; | 101 }; |
| 96 | 102 |
| 97 MOCK_METHOD4(ReturnMixer, | 103 MOCK_METHOD1(ReturnMixer, void(AudioRendererMixer*)); |
| 98 void(int, | |
| 99 const AudioParameters&, | |
| 100 const std::string&, | |
| 101 const url::Origin&)); | |
| 102 | 104 |
| 103 MOCK_METHOD4( | 105 MOCK_METHOD4( |
| 104 GetOutputDeviceInfo, | 106 GetOutputDeviceInfo, |
| 105 OutputDeviceInfo(int, int, const std::string&, const url::Origin&)); | 107 OutputDeviceInfo(int, int, const std::string&, const url::Origin&)); |
| 106 | 108 |
| 107 void InitializeInputs(int inputs_per_sample_rate) { | 109 void InitializeInputs(int inputs_per_sample_rate) { |
| 108 mixer_inputs_.reserve(inputs_per_sample_rate * input_parameters_.size()); | 110 mixer_inputs_.reserve(inputs_per_sample_rate * input_parameters_.size()); |
| 109 fake_callbacks_.reserve(inputs_per_sample_rate * input_parameters_.size()); | 111 fake_callbacks_.reserve(inputs_per_sample_rate * input_parameters_.size()); |
| 110 | 112 |
| 111 for (size_t i = 0, input = 0; i < input_parameters_.size(); ++i) { | 113 for (size_t i = 0, input = 0; i < input_parameters_.size(); ++i) { |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 326 std::max(1.f, static_cast<float>(floor(mixer_inputs_.size() / 2.f))))); | 328 std::max(1.f, static_cast<float>(floor(mixer_inputs_.size() / 2.f))))); |
| 327 | 329 |
| 328 for (size_t i = 1; i < mixer_inputs_.size(); i += 2) | 330 for (size_t i = 1; i < mixer_inputs_.size(); i += 2) |
| 329 mixer_inputs_[i]->Stop(); | 331 mixer_inputs_[i]->Stop(); |
| 330 } | 332 } |
| 331 | 333 |
| 332 scoped_refptr<AudioRendererMixerInput> CreateMixerInput() { | 334 scoped_refptr<AudioRendererMixerInput> CreateMixerInput() { |
| 333 return new AudioRendererMixerInput( | 335 return new AudioRendererMixerInput( |
| 334 this, | 336 this, |
| 335 // Zero frame id, default device ID and security origin. | 337 // Zero frame id, default device ID and security origin. |
| 336 0, std::string(), url::Origin()); | 338 0, std::string(), url::Origin(), AudioLatency::LATENCY_PLAYBACK); |
| 337 } | 339 } |
| 338 | 340 |
| 339 protected: | 341 protected: |
| 340 virtual ~AudioRendererMixerTest() {} | 342 virtual ~AudioRendererMixerTest() {} |
| 341 | 343 |
| 342 scoped_refptr<MockAudioRendererSink> sink_; | 344 scoped_refptr<MockAudioRendererSink> sink_; |
| 343 std::unique_ptr<AudioRendererMixer> mixer_; | 345 std::unique_ptr<AudioRendererMixer> mixer_; |
| 344 AudioRendererSink::RenderCallback* mixer_callback_; | 346 AudioRendererSink::RenderCallback* mixer_callback_; |
| 345 std::vector<AudioParameters> input_parameters_; | 347 std::vector<AudioParameters> input_parameters_; |
| 346 AudioParameters output_parameters_; | 348 AudioParameters output_parameters_; |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 547 INSTANTIATE_TEST_CASE_P( | 549 INSTANTIATE_TEST_CASE_P( |
| 548 AudioRendererMixerBehavioralTest, | 550 AudioRendererMixerBehavioralTest, |
| 549 AudioRendererMixerBehavioralTest, | 551 AudioRendererMixerBehavioralTest, |
| 550 testing::ValuesIn(std::vector<AudioRendererMixerTestData>( | 552 testing::ValuesIn(std::vector<AudioRendererMixerTestData>( |
| 551 1, | 553 1, |
| 552 std::tr1::make_tuple(&kTestInputLower, | 554 std::tr1::make_tuple(&kTestInputLower, |
| 553 1, | 555 1, |
| 554 kTestInputLower, | 556 kTestInputLower, |
| 555 0.00000048)))); | 557 0.00000048)))); |
| 556 } // namespace media | 558 } // namespace media |
| OLD | NEW |