Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(204)

Side by Side Diff: media/base/audio_renderer_mixer_unittest.cc

Issue 1809093003: Moving SwitchOutputDevice out of OutputDevice interface, eliminating OutputDevice (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « media/base/audio_renderer_mixer_input_unittest.cc ('k') | media/base/audio_renderer_sink.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
101 void InitializeInputs(int inputs_per_sample_rate) { 98 void InitializeInputs(int inputs_per_sample_rate) {
102 mixer_inputs_.reserve(inputs_per_sample_rate * input_parameters_.size()); 99 mixer_inputs_.reserve(inputs_per_sample_rate * input_parameters_.size());
103 fake_callbacks_.reserve(inputs_per_sample_rate * input_parameters_.size()); 100 fake_callbacks_.reserve(inputs_per_sample_rate * input_parameters_.size());
104 101
105 for (size_t i = 0, input = 0; i < input_parameters_.size(); ++i) { 102 for (size_t i = 0, input = 0; i < input_parameters_.size(); ++i) {
106 // Setup FakeAudioRenderCallback step to compensate for resampling. 103 // Setup FakeAudioRenderCallback step to compensate for resampling.
107 double scale_factor = 104 double scale_factor =
108 input_parameters_[i].sample_rate() / 105 input_parameters_[i].sample_rate() /
109 static_cast<double>(output_parameters_.sample_rate()); 106 static_cast<double>(output_parameters_.sample_rate());
110 double step = 107 double step =
111 kSineCycles / 108 kSineCycles /
112 (scale_factor * 109 (scale_factor *
113 static_cast<double>(output_parameters_.frames_per_buffer())); 110 static_cast<double>(output_parameters_.frames_per_buffer()));
114 111
115 for (int j = 0; j < inputs_per_sample_rate; ++j, ++input) { 112 for (int j = 0; j < inputs_per_sample_rate; ++j, ++input) {
116 fake_callbacks_.push_back(new FakeAudioRenderCallback(step)); 113 fake_callbacks_.push_back(new FakeAudioRenderCallback(step));
117 mixer_inputs_.push_back(new AudioRendererMixerInput( 114 mixer_inputs_.push_back(new AudioRendererMixerInput(
118 base::Bind(&AudioRendererMixerTest::GetMixer, 115 base::Bind(&AudioRendererMixerTest::GetMixer,
119 base::Unretained(this)), 116 base::Unretained(this)),
120 base::Bind(&AudioRendererMixerTest::RemoveMixer, 117 base::Bind(&AudioRendererMixerTest::RemoveMixer,
121 base::Unretained(this)), 118 base::Unretained(this)),
122 base::Bind(&AudioRendererMixerTest::GetOutputHWParams,
123 base::Unretained(this)),
124 // Default device ID and security origin. 119 // Default device ID and security origin.
125 std::string(), url::Origin())); 120 std::string(), url::Origin()));
126 mixer_inputs_[input]->Initialize(input_parameters_[i], 121 mixer_inputs_[input]->Initialize(input_parameters_[i],
127 fake_callbacks_[input]); 122 fake_callbacks_[input]);
128 mixer_inputs_[input]->SetVolume(1.0f); 123 mixer_inputs_[input]->SetVolume(1.0f);
129 } 124 }
130 } 125 }
131 EXPECT_CALL(*this, RemoveMixer(testing::_, testing::_, testing::_)) 126 EXPECT_CALL(*this, RemoveMixer(testing::_, testing::_, testing::_))
132 .Times(mixer_inputs_.size()); 127 .Times(mixer_inputs_.size());
133 } 128 }
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 mixer_callback_->OnRenderError(); 457 mixer_callback_->OnRenderError();
463 458
464 for (size_t i = 0; i < mixer_inputs_.size(); ++i) 459 for (size_t i = 0; i < mixer_inputs_.size(); ++i)
465 mixer_inputs_[i]->Stop(); 460 mixer_inputs_[i]->Stop();
466 } 461 }
467 462
468 // Ensure constructing an AudioRendererMixerInput, but not initializing it does 463 // Ensure constructing an AudioRendererMixerInput, but not initializing it does
469 // not call RemoveMixer(). 464 // not call RemoveMixer().
470 TEST_P(AudioRendererMixerBehavioralTest, NoInitialize) { 465 TEST_P(AudioRendererMixerBehavioralTest, NoInitialize) {
471 EXPECT_CALL(*this, RemoveMixer(testing::_, testing::_, testing::_)).Times(0); 466 EXPECT_CALL(*this, RemoveMixer(testing::_, testing::_, testing::_)).Times(0);
472 scoped_refptr<AudioRendererMixerInput> audio_renderer_mixer = 467 scoped_refptr<AudioRendererMixerInput> audio_renderer_mixer_input =
473 new AudioRendererMixerInput( 468 new AudioRendererMixerInput(
474 base::Bind(&AudioRendererMixerTest::GetMixer, base::Unretained(this)), 469 base::Bind(&AudioRendererMixerTest::GetMixer, base::Unretained(this)),
475 base::Bind(&AudioRendererMixerTest::RemoveMixer, 470 base::Bind(&AudioRendererMixerTest::RemoveMixer,
476 base::Unretained(this)), 471 base::Unretained(this)),
477 base::Bind(&AudioRendererMixerTest::GetOutputHWParams,
478 base::Unretained(this)),
479 // Default device ID and security origin. 472 // Default device ID and security origin.
480 std::string(), url::Origin()); 473 std::string(), url::Origin());
481 } 474 }
482 475
483 // Ensure the physical stream is paused after a certain amount of time with no 476 // 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. 477 // inputs playing. The test will hang if the behavior is incorrect.
485 TEST_P(AudioRendererMixerBehavioralTest, MixerPausesStream) { 478 TEST_P(AudioRendererMixerBehavioralTest, MixerPausesStream) {
486 const base::TimeDelta kPauseTime = base::TimeDelta::FromMilliseconds(500); 479 const base::TimeDelta kPauseTime = base::TimeDelta::FromMilliseconds(500);
487 // This value can't be too low or valgrind, tsan will timeout on the bots. 480 // This value can't be too low or valgrind, tsan will timeout on the bots.
488 const base::TimeDelta kTestTimeout = 10 * kPauseTime; 481 const base::TimeDelta kTestTimeout = 10 * kPauseTime;
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
557 INSTANTIATE_TEST_CASE_P( 550 INSTANTIATE_TEST_CASE_P(
558 AudioRendererMixerBehavioralTest, 551 AudioRendererMixerBehavioralTest,
559 AudioRendererMixerBehavioralTest, 552 AudioRendererMixerBehavioralTest,
560 testing::ValuesIn(std::vector<AudioRendererMixerTestData>( 553 testing::ValuesIn(std::vector<AudioRendererMixerTestData>(
561 1, 554 1,
562 std::tr1::make_tuple(&kTestInputLower, 555 std::tr1::make_tuple(&kTestInputLower,
563 1, 556 1,
564 kTestInputLower, 557 kTestInputLower,
565 0.00000048)))); 558 0.00000048))));
566 } // namespace media 559 } // namespace media
OLDNEW
« no previous file with comments | « media/base/audio_renderer_mixer_input_unittest.cc ('k') | media/base/audio_renderer_sink.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698