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, |
| 99 AudioParameters(const std::string&, const url::Origin&)); |
| 100 |
98 void InitializeInputs(int inputs_per_sample_rate) { | 101 void InitializeInputs(int inputs_per_sample_rate) { |
99 mixer_inputs_.reserve(inputs_per_sample_rate * input_parameters_.size()); | 102 mixer_inputs_.reserve(inputs_per_sample_rate * input_parameters_.size()); |
100 fake_callbacks_.reserve(inputs_per_sample_rate * input_parameters_.size()); | 103 fake_callbacks_.reserve(inputs_per_sample_rate * input_parameters_.size()); |
101 | 104 |
102 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) { |
103 // Setup FakeAudioRenderCallback step to compensate for resampling. | 106 // Setup FakeAudioRenderCallback step to compensate for resampling. |
104 double scale_factor = | 107 double scale_factor = |
105 input_parameters_[i].sample_rate() / | 108 input_parameters_[i].sample_rate() / |
106 static_cast<double>(output_parameters_.sample_rate()); | 109 static_cast<double>(output_parameters_.sample_rate()); |
107 double step = | 110 double step = |
108 kSineCycles / | 111 kSineCycles / |
109 (scale_factor * | 112 (scale_factor * |
110 static_cast<double>(output_parameters_.frames_per_buffer())); | 113 static_cast<double>(output_parameters_.frames_per_buffer())); |
111 | 114 |
112 for (int j = 0; j < inputs_per_sample_rate; ++j, ++input) { | 115 for (int j = 0; j < inputs_per_sample_rate; ++j, ++input) { |
113 fake_callbacks_.push_back(new FakeAudioRenderCallback(step)); | 116 fake_callbacks_.push_back(new FakeAudioRenderCallback(step)); |
114 mixer_inputs_.push_back(new AudioRendererMixerInput( | 117 mixer_inputs_.push_back(new AudioRendererMixerInput( |
115 base::Bind(&AudioRendererMixerTest::GetMixer, | 118 base::Bind(&AudioRendererMixerTest::GetMixer, |
116 base::Unretained(this)), | 119 base::Unretained(this)), |
117 base::Bind(&AudioRendererMixerTest::RemoveMixer, | 120 base::Bind(&AudioRendererMixerTest::RemoveMixer, |
118 base::Unretained(this)), | 121 base::Unretained(this)), |
| 122 base::Bind(&AudioRendererMixerTest::GetOutputHWParams, |
| 123 base::Unretained(this)), |
119 // Default device ID and security origin. | 124 // Default device ID and security origin. |
120 std::string(), url::Origin())); | 125 std::string(), url::Origin())); |
121 mixer_inputs_[input]->Initialize(input_parameters_[i], | 126 mixer_inputs_[input]->Initialize(input_parameters_[i], |
122 fake_callbacks_[input]); | 127 fake_callbacks_[input]); |
123 mixer_inputs_[input]->SetVolume(1.0f); | 128 mixer_inputs_[input]->SetVolume(1.0f); |
124 } | 129 } |
125 } | 130 } |
126 EXPECT_CALL(*this, RemoveMixer(testing::_, testing::_, testing::_)) | 131 EXPECT_CALL(*this, RemoveMixer(testing::_, testing::_, testing::_)) |
127 .Times(mixer_inputs_.size()); | 132 .Times(mixer_inputs_.size()); |
128 } | 133 } |
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
462 | 467 |
463 // Ensure constructing an AudioRendererMixerInput, but not initializing it does | 468 // Ensure constructing an AudioRendererMixerInput, but not initializing it does |
464 // not call RemoveMixer(). | 469 // not call RemoveMixer(). |
465 TEST_P(AudioRendererMixerBehavioralTest, NoInitialize) { | 470 TEST_P(AudioRendererMixerBehavioralTest, NoInitialize) { |
466 EXPECT_CALL(*this, RemoveMixer(testing::_, testing::_, testing::_)).Times(0); | 471 EXPECT_CALL(*this, RemoveMixer(testing::_, testing::_, testing::_)).Times(0); |
467 scoped_refptr<AudioRendererMixerInput> audio_renderer_mixer = | 472 scoped_refptr<AudioRendererMixerInput> audio_renderer_mixer = |
468 new AudioRendererMixerInput( | 473 new AudioRendererMixerInput( |
469 base::Bind(&AudioRendererMixerTest::GetMixer, base::Unretained(this)), | 474 base::Bind(&AudioRendererMixerTest::GetMixer, base::Unretained(this)), |
470 base::Bind(&AudioRendererMixerTest::RemoveMixer, | 475 base::Bind(&AudioRendererMixerTest::RemoveMixer, |
471 base::Unretained(this)), | 476 base::Unretained(this)), |
| 477 base::Bind(&AudioRendererMixerTest::GetOutputHWParams, |
| 478 base::Unretained(this)), |
472 // Default device ID and security origin. | 479 // Default device ID and security origin. |
473 std::string(), url::Origin()); | 480 std::string(), url::Origin()); |
474 } | 481 } |
475 | 482 |
476 // 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 |
477 // inputs playing. The test will hang if the behavior is incorrect. | 484 // inputs playing. The test will hang if the behavior is incorrect. |
478 TEST_P(AudioRendererMixerBehavioralTest, MixerPausesStream) { | 485 TEST_P(AudioRendererMixerBehavioralTest, MixerPausesStream) { |
479 const base::TimeDelta kPauseTime = base::TimeDelta::FromMilliseconds(500); | 486 const base::TimeDelta kPauseTime = base::TimeDelta::FromMilliseconds(500); |
480 // 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. |
481 const base::TimeDelta kTestTimeout = 10 * kPauseTime; | 488 const base::TimeDelta kTestTimeout = 10 * kPauseTime; |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
550 INSTANTIATE_TEST_CASE_P( | 557 INSTANTIATE_TEST_CASE_P( |
551 AudioRendererMixerBehavioralTest, | 558 AudioRendererMixerBehavioralTest, |
552 AudioRendererMixerBehavioralTest, | 559 AudioRendererMixerBehavioralTest, |
553 testing::ValuesIn(std::vector<AudioRendererMixerTestData>( | 560 testing::ValuesIn(std::vector<AudioRendererMixerTestData>( |
554 1, | 561 1, |
555 std::tr1::make_tuple(&kTestInputLower, | 562 std::tr1::make_tuple(&kTestInputLower, |
556 1, | 563 1, |
557 kTestInputLower, | 564 kTestInputLower, |
558 0.00000048)))); | 565 0.00000048)))); |
559 } // namespace media | 566 } // namespace media |
OLD | NEW |