summaryrefslogtreecommitdiffstats
path: root/media
diff options
context:
space:
mode:
Diffstat (limited to 'media')
-rw-r--r--media/filters/audio_renderer_base.cc6
-rw-r--r--media/filters/audio_renderer_base_unittest.cc33
2 files changed, 38 insertions, 1 deletions
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<MockAudioRendererBase> renderer_;
scoped_refptr<MockAudioDecoder> 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