summaryrefslogtreecommitdiffstats
path: root/media
diff options
context:
space:
mode:
authorscherkus@chromium.org <scherkus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-27 18:51:53 +0000
committerscherkus@chromium.org <scherkus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-27 18:51:53 +0000
commitf89011f3c76c6e896f846969840a8180169b21e2 (patch)
tree96a009e7ca33748ba0e10232288a228e6984a153 /media
parentbf4c6715370046b35261bd77235fc11b98f74c97 (diff)
downloadchromium_src-f89011f3c76c6e896f846969840a8180169b21e2.zip
chromium_src-f89011f3c76c6e896f846969840a8180169b21e2.tar.gz
chromium_src-f89011f3c76c6e896f846969840a8180169b21e2.tar.bz2
Delay calling NotifyEnded() until the audio hardware has played the last of the audio.
Previously we were calling NotifyEnded() when we had sent the last of the audio to the hardware. This is a small change to call NotifyEnded() when the audio hardware replies asking for additional data. Not perfect, but better than what we were doing before. TEST=play a short seamless audio clip on loop, it should be closer to seamless looping BUG=20349 Review URL: http://codereview.chromium.org/173520 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@24637 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media')
-rw-r--r--media/filters/audio_renderer_base.cc10
-rw-r--r--media/filters/audio_renderer_base_unittest.cc15
2 files changed, 18 insertions, 7 deletions
diff --git a/media/filters/audio_renderer_base.cc b/media/filters/audio_renderer_base.cc
index e29d07bc..65829f6 100644
--- a/media/filters/audio_renderer_base.cc
+++ b/media/filters/audio_renderer_base.cc
@@ -184,15 +184,15 @@ size_t AudioRendererBase::FillBuffer(uint8* dest,
last_fill_buffer_time = last_fill_buffer_time_;
last_fill_buffer_time_ = base::TimeDelta();
- // Do the fill.
- dest_written = algorithm_->FillBuffer(dest, dest_len);
-
// Check if we finally reached end of stream by emptying |algorithm_|.
- if (recieved_end_of_stream_ && algorithm_->IsQueueEmpty()) {
- if (!rendered_end_of_stream_) {
+ if (algorithm_->IsQueueEmpty()) {
+ if (recieved_end_of_stream_ && !rendered_end_of_stream_) {
rendered_end_of_stream_ = true;
host()->NotifyEnded();
}
+ } else {
+ // Otherwise fill the buffer.
+ dest_written = algorithm_->FillBuffer(dest, dest_len);
}
// Get the current time.
diff --git a/media/filters/audio_renderer_base_unittest.cc b/media/filters/audio_renderer_base_unittest.cc
index c5e55c1..1827424 100644
--- a/media/filters/audio_renderer_base_unittest.cc
+++ b/media/filters/audio_renderer_base_unittest.cc
@@ -218,15 +218,26 @@ TEST_F(AudioRendererBaseTest, OneCompleteReadCycle) {
// We should have one less read request in the queue.
EXPECT_EQ(kMaxQueueSize - 1, read_queue_.size());
- // Flush the entire internal buffer, which should notify the host we've ended.
+ // Flush the entire internal buffer and verify NotifyEnded() isn't called
+ // right away.
+ EXPECT_CALL(*renderer_, CheckPoint(1));
EXPECT_EQ(0u, bytes_buffered % kDataSize);
- EXPECT_CALL(host_, NotifyEnded());
while (bytes_buffered > 0) {
EXPECT_EQ(kDataSize,
renderer_->FillBuffer(buffer, kDataSize, base::TimeDelta()));
bytes_buffered -= kDataSize;
}
+ // Although we've emptied the buffer, we don't consider ourselves ended until
+ // we request another buffer. This way we know the last of the audio has
+ // played.
+ EXPECT_FALSE(renderer_->HasEnded());
+ renderer_->CheckPoint(1);
+
+ // Do an additional read to trigger NotifyEnded().
+ EXPECT_CALL(host_, NotifyEnded());
+ EXPECT_EQ(0u, renderer_->FillBuffer(buffer, kDataSize, base::TimeDelta()));
+
// We should now report ended.
EXPECT_TRUE(renderer_->HasEnded());