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 <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include <cmath> | 10 #include <cmath> |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 const url::Origin& security_origin, | 88 const url::Origin& security_origin, |
89 OutputDeviceStatus* device_status) { | 89 OutputDeviceStatus* device_status) { |
90 return mixer_.get(); | 90 return mixer_.get(); |
91 } | 91 } |
92 | 92 |
93 MOCK_METHOD3(RemoveMixer, | 93 MOCK_METHOD3(RemoveMixer, |
94 void(const AudioParameters&, | 94 void(const AudioParameters&, |
95 const std::string&, | 95 const std::string&, |
96 const url::Origin&)); | 96 const url::Origin&)); |
97 | 97 |
98 MOCK_METHOD2(GetOutputHWParams, | 98 MOCK_METHOD2(GetOutputDevice, |
99 AudioParameters(const std::string&, const url::Origin&)); | 99 OutputDevice*(const std::string&, const url::Origin&)); |
100 | 100 |
101 void InitializeInputs(int inputs_per_sample_rate) { | 101 void InitializeInputs(int inputs_per_sample_rate) { |
102 mixer_inputs_.reserve(inputs_per_sample_rate * input_parameters_.size()); | 102 mixer_inputs_.reserve(inputs_per_sample_rate * input_parameters_.size()); |
103 fake_callbacks_.reserve(inputs_per_sample_rate * input_parameters_.size()); | 103 fake_callbacks_.reserve(inputs_per_sample_rate * input_parameters_.size()); |
104 | 104 |
105 for (size_t i = 0, input = 0; i < input_parameters_.size(); ++i) { | 105 for (size_t i = 0, input = 0; i < input_parameters_.size(); ++i) { |
106 // Setup FakeAudioRenderCallback step to compensate for resampling. | 106 // Setup FakeAudioRenderCallback step to compensate for resampling. |
107 double scale_factor = | 107 double scale_factor = |
108 input_parameters_[i].sample_rate() / | 108 input_parameters_[i].sample_rate() / |
109 static_cast<double>(output_parameters_.sample_rate()); | 109 static_cast<double>(output_parameters_.sample_rate()); |
110 double step = | 110 double step = |
111 kSineCycles / | 111 kSineCycles / |
112 (scale_factor * | 112 (scale_factor * |
113 static_cast<double>(output_parameters_.frames_per_buffer())); | 113 static_cast<double>(output_parameters_.frames_per_buffer())); |
114 | 114 |
115 for (int j = 0; j < inputs_per_sample_rate; ++j, ++input) { | 115 for (int j = 0; j < inputs_per_sample_rate; ++j, ++input) { |
116 fake_callbacks_.push_back(new FakeAudioRenderCallback(step)); | 116 fake_callbacks_.push_back(new FakeAudioRenderCallback(step)); |
117 mixer_inputs_.push_back(new AudioRendererMixerInput( | 117 mixer_inputs_.push_back(new AudioRendererMixerInput( |
118 base::Bind(&AudioRendererMixerTest::GetMixer, | 118 base::Bind(&AudioRendererMixerTest::GetMixer, |
119 base::Unretained(this)), | 119 base::Unretained(this)), |
120 base::Bind(&AudioRendererMixerTest::RemoveMixer, | 120 base::Bind(&AudioRendererMixerTest::RemoveMixer, |
121 base::Unretained(this)), | 121 base::Unretained(this)), |
122 base::Bind(&AudioRendererMixerTest::GetOutputHWParams, | 122 base::Bind(&AudioRendererMixerTest::GetOutputDevice, |
123 base::Unretained(this)), | 123 base::Unretained(this)), |
124 // Default device ID and security origin. | 124 // Default device ID and security origin. |
125 std::string(), url::Origin())); | 125 std::string(), url::Origin())); |
126 mixer_inputs_[input]->Initialize(input_parameters_[i], | 126 mixer_inputs_[input]->Initialize(input_parameters_[i], |
127 fake_callbacks_[input]); | 127 fake_callbacks_[input]); |
128 mixer_inputs_[input]->SetVolume(1.0f); | 128 mixer_inputs_[input]->SetVolume(1.0f); |
129 } | 129 } |
130 } | 130 } |
131 EXPECT_CALL(*this, RemoveMixer(testing::_, testing::_, testing::_)) | 131 EXPECT_CALL(*this, RemoveMixer(testing::_, testing::_, testing::_)) |
132 .Times(mixer_inputs_.size()); | 132 .Times(mixer_inputs_.size()); |
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
467 | 467 |
468 // Ensure constructing an AudioRendererMixerInput, but not initializing it does | 468 // Ensure constructing an AudioRendererMixerInput, but not initializing it does |
469 // not call RemoveMixer(). | 469 // not call RemoveMixer(). |
470 TEST_P(AudioRendererMixerBehavioralTest, NoInitialize) { | 470 TEST_P(AudioRendererMixerBehavioralTest, NoInitialize) { |
471 EXPECT_CALL(*this, RemoveMixer(testing::_, testing::_, testing::_)).Times(0); | 471 EXPECT_CALL(*this, RemoveMixer(testing::_, testing::_, testing::_)).Times(0); |
472 scoped_refptr<AudioRendererMixerInput> audio_renderer_mixer = | 472 scoped_refptr<AudioRendererMixerInput> audio_renderer_mixer = |
473 new AudioRendererMixerInput( | 473 new AudioRendererMixerInput( |
474 base::Bind(&AudioRendererMixerTest::GetMixer, base::Unretained(this)), | 474 base::Bind(&AudioRendererMixerTest::GetMixer, base::Unretained(this)), |
475 base::Bind(&AudioRendererMixerTest::RemoveMixer, | 475 base::Bind(&AudioRendererMixerTest::RemoveMixer, |
476 base::Unretained(this)), | 476 base::Unretained(this)), |
477 base::Bind(&AudioRendererMixerTest::GetOutputHWParams, | 477 base::Bind(&AudioRendererMixerTest::GetOutputDevice, |
478 base::Unretained(this)), | 478 base::Unretained(this)), |
479 // Default device ID and security origin. | 479 // Default device ID and security origin. |
480 std::string(), url::Origin()); | 480 std::string(), url::Origin()); |
481 } | 481 } |
482 | 482 |
483 // Ensure the physical stream is paused after a certain amount of time with no | 483 // Ensure the physical stream is paused after a certain amount of time with no |
484 // inputs playing. The test will hang if the behavior is incorrect. | 484 // inputs playing. The test will hang if the behavior is incorrect. |
485 TEST_P(AudioRendererMixerBehavioralTest, MixerPausesStream) { | 485 TEST_P(AudioRendererMixerBehavioralTest, MixerPausesStream) { |
486 const base::TimeDelta kPauseTime = base::TimeDelta::FromMilliseconds(500); | 486 const base::TimeDelta kPauseTime = base::TimeDelta::FromMilliseconds(500); |
487 // This value can't be too low or valgrind, tsan will timeout on the bots. | 487 // This value can't be too low or valgrind, tsan will timeout on the bots. |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
557 INSTANTIATE_TEST_CASE_P( | 557 INSTANTIATE_TEST_CASE_P( |
558 AudioRendererMixerBehavioralTest, | 558 AudioRendererMixerBehavioralTest, |
559 AudioRendererMixerBehavioralTest, | 559 AudioRendererMixerBehavioralTest, |
560 testing::ValuesIn(std::vector<AudioRendererMixerTestData>( | 560 testing::ValuesIn(std::vector<AudioRendererMixerTestData>( |
561 1, | 561 1, |
562 std::tr1::make_tuple(&kTestInputLower, | 562 std::tr1::make_tuple(&kTestInputLower, |
563 1, | 563 1, |
564 kTestInputLower, | 564 kTestInputLower, |
565 0.00000048)))); | 565 0.00000048)))); |
566 } // namespace media | 566 } // namespace media |
OLD | NEW |