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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 half_fill_(false) { | 45 half_fill_(false) { |
46 // Create input and output parameters based on test parameters. | 46 // Create input and output parameters based on test parameters. |
47 input_parameters_ = AudioParameters( | 47 input_parameters_ = AudioParameters( |
48 AudioParameters::AUDIO_PCM_LINEAR, kChannelLayout, | 48 AudioParameters::AUDIO_PCM_LINEAR, kChannelLayout, |
49 std::tr1::get<0>(GetParam()), kBitsPerChannel, kHighLatencyBufferSize); | 49 std::tr1::get<0>(GetParam()), kBitsPerChannel, kHighLatencyBufferSize); |
50 output_parameters_ = AudioParameters( | 50 output_parameters_ = AudioParameters( |
51 AudioParameters::AUDIO_PCM_LOW_LATENCY, kChannelLayout, | 51 AudioParameters::AUDIO_PCM_LOW_LATENCY, kChannelLayout, |
52 std::tr1::get<1>(GetParam()), 16, kLowLatencyBufferSize); | 52 std::tr1::get<1>(GetParam()), 16, kLowLatencyBufferSize); |
53 | 53 |
54 sink_ = new MockAudioRendererSink(); | 54 sink_ = new MockAudioRendererSink(); |
55 EXPECT_CALL(*sink_, Start()); | 55 EXPECT_CALL(*sink_.get(), Start()); |
56 EXPECT_CALL(*sink_, Stop()); | 56 EXPECT_CALL(*sink_.get(), Stop()); |
57 | 57 |
58 mixer_.reset(new AudioRendererMixer( | 58 mixer_.reset(new AudioRendererMixer( |
59 input_parameters_, output_parameters_, sink_)); | 59 input_parameters_, output_parameters_, sink_)); |
60 mixer_callback_ = sink_->callback(); | 60 mixer_callback_ = sink_->callback(); |
61 | 61 |
62 audio_bus_ = AudioBus::Create(output_parameters_); | 62 audio_bus_ = AudioBus::Create(output_parameters_); |
63 expected_audio_bus_ = AudioBus::Create(output_parameters_); | 63 expected_audio_bus_ = AudioBus::Create(output_parameters_); |
64 | 64 |
65 // Allocate one callback for generating expected results. | 65 // Allocate one callback for generating expected results. |
66 double step = kSineCycles / static_cast<double>( | 66 double step = kSineCycles / static_cast<double>( |
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
408 | 408 |
409 // Ensure the physical stream is paused after a certain amount of time with no | 409 // Ensure the physical stream is paused after a certain amount of time with no |
410 // inputs playing. The test will hang if the behavior is incorrect. | 410 // inputs playing. The test will hang if the behavior is incorrect. |
411 TEST_P(AudioRendererMixerBehavioralTest, MixerPausesStream) { | 411 TEST_P(AudioRendererMixerBehavioralTest, MixerPausesStream) { |
412 const base::TimeDelta kPauseTime = base::TimeDelta::FromMilliseconds(500); | 412 const base::TimeDelta kPauseTime = base::TimeDelta::FromMilliseconds(500); |
413 // This value can't be too low or valgrind, tsan will timeout on the bots. | 413 // This value can't be too low or valgrind, tsan will timeout on the bots. |
414 const base::TimeDelta kTestTimeout = 10 * kPauseTime; | 414 const base::TimeDelta kTestTimeout = 10 * kPauseTime; |
415 mixer_->set_pause_delay_for_testing(kPauseTime); | 415 mixer_->set_pause_delay_for_testing(kPauseTime); |
416 | 416 |
417 base::WaitableEvent pause_event(true, false); | 417 base::WaitableEvent pause_event(true, false); |
418 EXPECT_CALL(*sink_, Pause()) | 418 EXPECT_CALL(*sink_.get(), Pause()).Times(2) |
419 .Times(2).WillRepeatedly(SignalEvent(&pause_event)); | 419 .WillRepeatedly(SignalEvent(&pause_event)); |
420 InitializeInputs(1); | 420 InitializeInputs(1); |
421 | 421 |
422 // Ensure never playing the input results in a sink pause. | 422 // Ensure never playing the input results in a sink pause. |
423 const base::TimeDelta kSleepTime = base::TimeDelta::FromMilliseconds(100); | 423 const base::TimeDelta kSleepTime = base::TimeDelta::FromMilliseconds(100); |
424 base::Time start_time = base::Time::Now(); | 424 base::Time start_time = base::Time::Now(); |
425 while (!pause_event.IsSignaled()) { | 425 while (!pause_event.IsSignaled()) { |
426 mixer_callback_->Render(audio_bus_.get(), 0); | 426 mixer_callback_->Render(audio_bus_.get(), 0); |
427 base::PlatformThread::Sleep(kSleepTime); | 427 base::PlatformThread::Sleep(kSleepTime); |
428 ASSERT_TRUE(base::Time::Now() - start_time < kTestTimeout); | 428 ASSERT_TRUE(base::Time::Now() - start_time < kTestTimeout); |
429 } | 429 } |
430 pause_event.Reset(); | 430 pause_event.Reset(); |
431 | 431 |
432 // Playing the input for the first time should cause a sink play. | 432 // Playing the input for the first time should cause a sink play. |
433 mixer_inputs_[0]->Start(); | 433 mixer_inputs_[0]->Start(); |
434 EXPECT_CALL(*sink_, Play()); | 434 EXPECT_CALL(*sink_.get(), Play()); |
435 mixer_inputs_[0]->Play(); | 435 mixer_inputs_[0]->Play(); |
436 mixer_inputs_[0]->Pause(); | 436 mixer_inputs_[0]->Pause(); |
437 | 437 |
438 // Ensure once the input is paused the sink eventually pauses. | 438 // Ensure once the input is paused the sink eventually pauses. |
439 start_time = base::Time::Now(); | 439 start_time = base::Time::Now(); |
440 while (!pause_event.IsSignaled()) { | 440 while (!pause_event.IsSignaled()) { |
441 mixer_callback_->Render(audio_bus_.get(), 0); | 441 mixer_callback_->Render(audio_bus_.get(), 0); |
442 base::PlatformThread::Sleep(kSleepTime); | 442 base::PlatformThread::Sleep(kSleepTime); |
443 ASSERT_TRUE(base::Time::Now() - start_time < kTestTimeout); | 443 ASSERT_TRUE(base::Time::Now() - start_time < kTestTimeout); |
444 } | 444 } |
(...skipping 14 matching lines...) Expand all Loading... |
459 | 459 |
460 // Test cases for behavior which is independent of parameters. Values() doesn't | 460 // Test cases for behavior which is independent of parameters. Values() doesn't |
461 // support single item lists and we don't want these test cases to run for every | 461 // support single item lists and we don't want these test cases to run for every |
462 // parameter set. | 462 // parameter set. |
463 INSTANTIATE_TEST_CASE_P( | 463 INSTANTIATE_TEST_CASE_P( |
464 AudioRendererMixerBehavioralTest, AudioRendererMixerBehavioralTest, | 464 AudioRendererMixerBehavioralTest, AudioRendererMixerBehavioralTest, |
465 testing::ValuesIn(std::vector<AudioRendererMixerTestData>( | 465 testing::ValuesIn(std::vector<AudioRendererMixerTestData>( |
466 1, std::tr1::make_tuple(44100, 44100, 0)))); | 466 1, std::tr1::make_tuple(44100, 44100, 0)))); |
467 | 467 |
468 } // namespace media | 468 } // namespace media |
OLD | NEW |