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 #include "media/renderers/audio_renderer_impl.h" | 5 #include "media/renderers/audio_renderer_impl.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 sink_.get(), std::move(decoders), | 107 sink_.get(), std::move(decoders), |
108 new MediaLog())); | 108 new MediaLog())); |
109 renderer_->tick_clock_.reset(tick_clock_); | 109 renderer_->tick_clock_.reset(tick_clock_); |
110 tick_clock_->Advance(base::TimeDelta::FromSeconds(1)); | 110 tick_clock_->Advance(base::TimeDelta::FromSeconds(1)); |
111 } | 111 } |
112 | 112 |
113 virtual ~AudioRendererImplTest() { | 113 virtual ~AudioRendererImplTest() { |
114 SCOPED_TRACE("~AudioRendererImplTest()"); | 114 SCOPED_TRACE("~AudioRendererImplTest()"); |
115 } | 115 } |
116 | 116 |
| 117 // Reconfigures a renderer without config change support using given params. |
| 118 void ConfigureBasicRenderer(const AudioParameters& params) { |
| 119 hardware_params_ = params; |
| 120 sink_ = new FakeAudioRendererSink(hardware_params_); |
| 121 decoder_ = new MockAudioDecoder(); |
| 122 ScopedVector<AudioDecoder> decoders; |
| 123 decoders.push_back(decoder_); |
| 124 renderer_.reset(new AudioRendererImpl(message_loop_.task_runner(), |
| 125 sink_.get(), std::move(decoders), |
| 126 new MediaLog())); |
| 127 testing::Mock::VerifyAndClearExpectations(&demuxer_stream_); |
| 128 EXPECT_CALL(demuxer_stream_, SupportsConfigChanges()) |
| 129 .WillRepeatedly(Return(false)); |
| 130 } |
| 131 |
117 void ExpectUnsupportedAudioDecoder() { | 132 void ExpectUnsupportedAudioDecoder() { |
118 EXPECT_CALL(*decoder_, Initialize(_, _, _, _)) | 133 EXPECT_CALL(*decoder_, Initialize(_, _, _, _)) |
119 .WillOnce(DoAll(SaveArg<3>(&output_cb_), RunCallback<2>(false))); | 134 .WillOnce(DoAll(SaveArg<3>(&output_cb_), RunCallback<2>(false))); |
120 } | 135 } |
121 | 136 |
122 // RendererClient implementation. | 137 // RendererClient implementation. |
123 MOCK_METHOD1(OnError, void(PipelineStatus)); | 138 MOCK_METHOD1(OnError, void(PipelineStatus)); |
124 void OnEnded() override { | 139 void OnEnded() override { |
125 CHECK(!ended_); | 140 CHECK(!ended_); |
126 ended_ = true; | 141 ended_ = true; |
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
530 EXPECT_FALSE(ConsumeBufferedData(OutputFrames(1))); | 545 EXPECT_FALSE(ConsumeBufferedData(OutputFrames(1))); |
531 | 546 |
532 // Verify that the buffer capacity increased as a result of underflowing. | 547 // Verify that the buffer capacity increased as a result of underflowing. |
533 EXPECT_GT(buffer_capacity().value, initial_capacity.value); | 548 EXPECT_GT(buffer_capacity().value, initial_capacity.value); |
534 | 549 |
535 // Verify that the buffer capacity is restored to the |initial_capacity|. | 550 // Verify that the buffer capacity is restored to the |initial_capacity|. |
536 FlushDuringPendingRead(); | 551 FlushDuringPendingRead(); |
537 EXPECT_EQ(buffer_capacity().value, initial_capacity.value); | 552 EXPECT_EQ(buffer_capacity().value, initial_capacity.value); |
538 } | 553 } |
539 | 554 |
| 555 TEST_F(AudioRendererImplTest, Underflow_CapacityIncreasesBeforeHaveNothing) { |
| 556 Initialize(); |
| 557 Preroll(); |
| 558 StartTicking(); |
| 559 |
| 560 // Verify the next FillBuffer() call triggers the underflow callback |
| 561 // since the decoder hasn't delivered any data after it was drained. |
| 562 OutputFrames initial_capacity = buffer_capacity(); |
| 563 |
| 564 // Drain internal buffer, we should have a pending read. |
| 565 EXPECT_FALSE(ConsumeBufferedData(OutputFrames(frames_buffered().value + 1))); |
| 566 |
| 567 // Verify that the buffer capacity increased despite not sending have nothing. |
| 568 EXPECT_GT(buffer_capacity().value, initial_capacity.value); |
| 569 } |
| 570 |
| 571 TEST_F(AudioRendererImplTest, CapacityAppropriateForHardware) { |
| 572 // Verify that initial capacity is reasonable in normal case. |
| 573 Initialize(); |
| 574 EXPECT_GT(buffer_capacity().value, hardware_params_.frames_per_buffer()); |
| 575 |
| 576 // Verify in the no-config-changes-expected case. |
| 577 ConfigureBasicRenderer(AudioParameters( |
| 578 AudioParameters::AUDIO_PCM_LOW_LATENCY, kChannelLayout, |
| 579 kOutputSamplesPerSecond, SampleFormatToBytesPerChannel(kSampleFormat) * 8, |
| 580 1024 * 15)); |
| 581 |
| 582 Initialize(); |
| 583 EXPECT_GT(buffer_capacity().value, hardware_params_.frames_per_buffer()); |
| 584 } |
| 585 |
540 TEST_F(AudioRendererImplTest, Underflow_Flush) { | 586 TEST_F(AudioRendererImplTest, Underflow_Flush) { |
541 Initialize(); | 587 Initialize(); |
542 Preroll(); | 588 Preroll(); |
543 StartTicking(); | 589 StartTicking(); |
544 | 590 |
545 // Force underflow. | 591 // Force underflow. |
546 EXPECT_TRUE(ConsumeBufferedData(frames_buffered())); | 592 EXPECT_TRUE(ConsumeBufferedData(frames_buffered())); |
547 WaitForPendingRead(); | 593 WaitForPendingRead(); |
548 EXPECT_CALL(*this, OnBufferingStateChange(BUFFERING_HAVE_NOTHING)); | 594 EXPECT_CALL(*this, OnBufferingStateChange(BUFFERING_HAVE_NOTHING)); |
549 EXPECT_FALSE(ConsumeBufferedData(OutputFrames(1))); | 595 EXPECT_FALSE(ConsumeBufferedData(OutputFrames(1))); |
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
981 // Advance far enough that we shouldn't be clamped to current time (tested | 1027 // Advance far enough that we shouldn't be clamped to current time (tested |
982 // already above). | 1028 // already above). |
983 tick_clock_->Advance(kOneSecond); | 1029 tick_clock_->Advance(kOneSecond); |
984 EXPECT_EQ( | 1030 EXPECT_EQ( |
985 current_time + timestamp_helper.GetFrameDuration(frames_to_consume.value), | 1031 current_time + timestamp_helper.GetFrameDuration(frames_to_consume.value), |
986 CurrentMediaWallClockTime(&is_time_moving)); | 1032 CurrentMediaWallClockTime(&is_time_moving)); |
987 EXPECT_TRUE(is_time_moving); | 1033 EXPECT_TRUE(is_time_moving); |
988 } | 1034 } |
989 | 1035 |
990 } // namespace media | 1036 } // namespace media |
OLD | NEW |