From d553f93de393e1d1b21a622bab3cfcf1c8cd0dfe Mon Sep 17 00:00:00 2001 From: "acolwell@chromium.org" Date: Fri, 23 Dec 2011 01:11:36 +0000 Subject: Moving underflow callback execution so ResumeAfterUnderflow() can be called inside the callback. BUG=103920 TEST=AudioRendererBaseTest.Underflow_ResumeFromCallback Review URL: http://codereview.chromium.org/9005022 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@115662 0039d316-1c4b-4281-b951-d872f2087c98 --- media/filters/audio_renderer_base.cc | 6 ++++- media/filters/audio_renderer_base_unittest.cc | 33 +++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) (limited to 'media') diff --git a/media/filters/audio_renderer_base.cc b/media/filters/audio_renderer_base.cc index e3f2164..bca260a 100644 --- a/media/filters/audio_renderer_base.cc +++ b/media/filters/audio_renderer_base.cc @@ -195,6 +195,7 @@ uint32 AudioRendererBase::FillBuffer(uint8* dest, // FillBuffer(). base::TimeDelta last_fill_buffer_time; size_t dest_written = 0; + base::Closure underflow_cb; { base::AutoLock auto_lock(lock_); @@ -237,7 +238,7 @@ uint32 AudioRendererBase::FillBuffer(uint8* dest, } } else if (state_ == kPlaying && !recieved_end_of_stream_) { state_ = kUnderflow; - underflow_callback_.Run(); + underflow_cb = underflow_callback_; } } else { // Otherwise fill the buffer. @@ -262,6 +263,9 @@ uint32 AudioRendererBase::FillBuffer(uint8* dest, host()->SetTime(last_fill_buffer_time); } + if (!underflow_cb.is_null()) + underflow_cb.Run(); + return dest_written; } diff --git a/media/filters/audio_renderer_base_unittest.cc b/media/filters/audio_renderer_base_unittest.cc index 964686e..2dd5cc8 100644 --- a/media/filters/audio_renderer_base_unittest.cc +++ b/media/filters/audio_renderer_base_unittest.cc @@ -172,6 +172,10 @@ class AudioRendererBaseTest : public ::testing::Test { return buffer_capacity() - bytes_buffered(); } + void CallResumeAfterUnderflow() { + renderer_->ResumeAfterUnderflow(false); + } + // Fixture members. scoped_refptr renderer_; scoped_refptr decoder_; @@ -321,4 +325,33 @@ TEST_F(AudioRendererBaseTest, Underflow_EndOfStream) { EXPECT_FALSE(muted); } +TEST_F(AudioRendererBaseTest, Underflow_ResumeFromCallback) { + Initialize(); + Preroll(); + Play(); + + // Drain internal buffer, we should have a pending read. + EXPECT_CALL(*decoder_, Read(_)); + EXPECT_TRUE(ConsumeBufferedData(bytes_buffered(), NULL)); + + // Verify the next FillBuffer() call triggers the underflow callback + // since the decoder hasn't delivered any data after it was drained. + const size_t kDataSize = 1024; + EXPECT_CALL(*this, OnUnderflow()) + .WillOnce(Invoke(this, &AudioRendererBaseTest::CallResumeAfterUnderflow)); + EXPECT_FALSE(ConsumeBufferedData(kDataSize, NULL)); + + // Verify after resuming that we're still not getting data. + bool muted = false; + EXPECT_EQ(0u, bytes_buffered()); + EXPECT_TRUE(ConsumeBufferedData(kDataSize, &muted)); + EXPECT_TRUE(muted); + + // Deliver data, we should get non-muted audio. + DeliverRemainingAudio(); + EXPECT_CALL(*decoder_, Read(_)); + EXPECT_TRUE(ConsumeBufferedData(kDataSize, &muted)); + EXPECT_FALSE(muted); +} + } // namespace media -- cgit v1.1