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 #include <cmath> | 7 #include <cmath> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 if (half_fill_) { | 131 if (half_fill_) { |
132 for (size_t i = 0; i < fake_callbacks_.size(); ++i) | 132 for (size_t i = 0; i < fake_callbacks_.size(); ++i) |
133 fake_callbacks_[i]->set_half_fill(true); | 133 fake_callbacks_[i]->set_half_fill(true); |
134 expected_callback_->set_half_fill(true); | 134 expected_callback_->set_half_fill(true); |
135 // Initialize the AudioBus completely or we'll run into Valgrind problems | 135 // Initialize the AudioBus completely or we'll run into Valgrind problems |
136 // during the verification step below. | 136 // during the verification step below. |
137 expected_audio_bus_->Zero(); | 137 expected_audio_bus_->Zero(); |
138 } | 138 } |
139 | 139 |
140 // Render actual audio data. | 140 // Render actual audio data. |
141 int frames = mixer_callback_->Render(audio_bus_.get(), 0); | 141 int frames = mixer_callback_->Render(audio_bus_.get(), 0, 0); |
142 if (frames != audio_bus_->frames()) | 142 if (frames != audio_bus_->frames()) |
143 return false; | 143 return false; |
144 | 144 |
145 // Render expected audio data (without scaling). | 145 // Render expected audio data (without scaling). |
146 expected_callback_->Render(expected_audio_bus_.get(), 0); | 146 expected_callback_->Render(expected_audio_bus_.get(), 0, 0); |
147 | 147 |
148 if (half_fill_) { | 148 if (half_fill_) { |
149 // In this case, just verify that every frame was initialized, this will | 149 // In this case, just verify that every frame was initialized, this will |
150 // only fail under tooling such as valgrind. | 150 // only fail under tooling such as valgrind. |
151 return ValidateAudioData( | 151 return ValidateAudioData( |
152 0, frames, 0, std::numeric_limits<double>::max()); | 152 0, frames, 0, std::numeric_limits<double>::max()); |
153 } else { | 153 } else { |
154 return ValidateAudioData(0, frames, scale); | 154 return ValidateAudioData(0, frames, scale); |
155 } | 155 } |
156 } | 156 } |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
443 | 443 |
444 base::WaitableEvent pause_event(true, false); | 444 base::WaitableEvent pause_event(true, false); |
445 EXPECT_CALL(*sink_.get(), Pause()).Times(2) | 445 EXPECT_CALL(*sink_.get(), Pause()).Times(2) |
446 .WillRepeatedly(SignalEvent(&pause_event)); | 446 .WillRepeatedly(SignalEvent(&pause_event)); |
447 InitializeInputs(1); | 447 InitializeInputs(1); |
448 | 448 |
449 // Ensure never playing the input results in a sink pause. | 449 // Ensure never playing the input results in a sink pause. |
450 const base::TimeDelta kSleepTime = base::TimeDelta::FromMilliseconds(100); | 450 const base::TimeDelta kSleepTime = base::TimeDelta::FromMilliseconds(100); |
451 base::TimeTicks start_time = base::TimeTicks::Now(); | 451 base::TimeTicks start_time = base::TimeTicks::Now(); |
452 while (!pause_event.IsSignaled()) { | 452 while (!pause_event.IsSignaled()) { |
453 mixer_callback_->Render(audio_bus_.get(), 0); | 453 mixer_callback_->Render(audio_bus_.get(), 0, 0); |
454 base::PlatformThread::Sleep(kSleepTime); | 454 base::PlatformThread::Sleep(kSleepTime); |
455 ASSERT_TRUE(base::TimeTicks::Now() - start_time < kTestTimeout); | 455 ASSERT_TRUE(base::TimeTicks::Now() - start_time < kTestTimeout); |
456 } | 456 } |
457 pause_event.Reset(); | 457 pause_event.Reset(); |
458 | 458 |
459 // Playing the input for the first time should cause a sink play. | 459 // Playing the input for the first time should cause a sink play. |
460 mixer_inputs_[0]->Start(); | 460 mixer_inputs_[0]->Start(); |
461 EXPECT_CALL(*sink_.get(), Play()); | 461 EXPECT_CALL(*sink_.get(), Play()); |
462 mixer_inputs_[0]->Play(); | 462 mixer_inputs_[0]->Play(); |
463 mixer_inputs_[0]->Pause(); | 463 mixer_inputs_[0]->Pause(); |
464 | 464 |
465 // Ensure once the input is paused the sink eventually pauses. | 465 // Ensure once the input is paused the sink eventually pauses. |
466 start_time = base::TimeTicks::Now(); | 466 start_time = base::TimeTicks::Now(); |
467 while (!pause_event.IsSignaled()) { | 467 while (!pause_event.IsSignaled()) { |
468 mixer_callback_->Render(audio_bus_.get(), 0); | 468 mixer_callback_->Render(audio_bus_.get(), 0, 0); |
469 base::PlatformThread::Sleep(kSleepTime); | 469 base::PlatformThread::Sleep(kSleepTime); |
470 ASSERT_TRUE(base::TimeTicks::Now() - start_time < kTestTimeout); | 470 ASSERT_TRUE(base::TimeTicks::Now() - start_time < kTestTimeout); |
471 } | 471 } |
472 | 472 |
473 mixer_inputs_[0]->Stop(); | 473 mixer_inputs_[0]->Stop(); |
474 } | 474 } |
475 | 475 |
476 INSTANTIATE_TEST_CASE_P( | 476 INSTANTIATE_TEST_CASE_P( |
477 AudioRendererMixerTest, AudioRendererMixerTest, testing::Values( | 477 AudioRendererMixerTest, AudioRendererMixerTest, testing::Values( |
478 // No resampling. | 478 // No resampling. |
479 std::tr1::make_tuple(44100, 44100, 0.00000048), | 479 std::tr1::make_tuple(44100, 44100, 0.00000048), |
480 | 480 |
481 // Upsampling. | 481 // Upsampling. |
482 std::tr1::make_tuple(44100, 48000, 0.033), | 482 std::tr1::make_tuple(44100, 48000, 0.033), |
483 | 483 |
484 // Downsampling. | 484 // Downsampling. |
485 std::tr1::make_tuple(48000, 41000, 0.042))); | 485 std::tr1::make_tuple(48000, 41000, 0.042))); |
486 | 486 |
487 // Test cases for behavior which is independent of parameters. Values() doesn't | 487 // Test cases for behavior which is independent of parameters. Values() doesn't |
488 // support single item lists and we don't want these test cases to run for every | 488 // support single item lists and we don't want these test cases to run for every |
489 // parameter set. | 489 // parameter set. |
490 INSTANTIATE_TEST_CASE_P( | 490 INSTANTIATE_TEST_CASE_P( |
491 AudioRendererMixerBehavioralTest, AudioRendererMixerBehavioralTest, | 491 AudioRendererMixerBehavioralTest, AudioRendererMixerBehavioralTest, |
492 testing::ValuesIn(std::vector<AudioRendererMixerTestData>( | 492 testing::ValuesIn(std::vector<AudioRendererMixerTestData>( |
493 1, std::tr1::make_tuple(44100, 44100, 0)))); | 493 1, std::tr1::make_tuple(44100, 44100, 0)))); |
494 | 494 |
495 } // namespace media | 495 } // namespace media |
OLD | NEW |