summaryrefslogtreecommitdiffstats
path: root/media
diff options
context:
space:
mode:
authorscherkus@chromium.org <scherkus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-05-21 22:55:28 +0000
committerscherkus@chromium.org <scherkus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-05-21 22:55:28 +0000
commit64ee3521f462aa121b51356b9cdf43f79e60e327 (patch)
tree121ca27497c6d914df04d36c5175adae67bc712e /media
parent3dc8f1b1cfb7c919d78a2325d72571176c2096b9 (diff)
downloadchromium_src-64ee3521f462aa121b51356b9cdf43f79e60e327.zip
chromium_src-64ee3521f462aa121b51356b9cdf43f79e60e327.tar.gz
chromium_src-64ee3521f462aa121b51356b9cdf43f79e60e327.tar.bz2
Remove media::AudioRendererImpl::SignalEndOfStream() and some other minor cleanup.
BUG=none TEST=none Review URL: https://chromiumcodereview.appspot.com/10389138 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@138161 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media')
-rw-r--r--media/filters/audio_renderer_algorithm.cc8
-rw-r--r--media/filters/audio_renderer_algorithm.h8
-rw-r--r--media/filters/audio_renderer_impl.cc61
-rw-r--r--media/filters/audio_renderer_impl.h6
4 files changed, 34 insertions, 49 deletions
diff --git a/media/filters/audio_renderer_algorithm.cc b/media/filters/audio_renderer_algorithm.cc
index 8004339..030c1ac 100644
--- a/media/filters/audio_renderer_algorithm.cc
+++ b/media/filters/audio_renderer_algorithm.cc
@@ -420,12 +420,8 @@ void AudioRendererAlgorithm::EnqueueBuffer(Buffer* buffer_in) {
request_read_cb_.Run();
}
-bool AudioRendererAlgorithm::NeedsMoreData() {
- return needs_more_data_ || IsQueueEmpty();
-}
-
-bool AudioRendererAlgorithm::IsQueueEmpty() {
- return audio_buffer_.forward_bytes() == 0;
+bool AudioRendererAlgorithm::CanFillBuffer() {
+ return audio_buffer_.forward_bytes() > 0 && !needs_more_data_;
}
bool AudioRendererAlgorithm::IsQueueFull() {
diff --git a/media/filters/audio_renderer_algorithm.h b/media/filters/audio_renderer_algorithm.h
index 9c0543be..933be82c 100644
--- a/media/filters/audio_renderer_algorithm.h
+++ b/media/filters/audio_renderer_algorithm.h
@@ -75,8 +75,9 @@ class MEDIA_EXPORT AudioRendererAlgorithm {
float playback_rate() const { return playback_rate_; }
void SetPlaybackRate(float new_rate);
- // Returns whether the algorithm needs more data to continue filling buffers.
- bool NeedsMoreData();
+ // Returns whether the algorithm has enough data at the current playback rate
+ // such that it can write data on the next call to FillBuffer().
+ bool CanFillBuffer();
// Returns true if |audio_buffer_| is at or exceeds capacity.
bool IsQueueFull();
@@ -99,9 +100,6 @@ class MEDIA_EXPORT AudioRendererAlgorithm {
bool is_muted() { return muted_; }
private:
- // Returns true if |audio_buffer_| is empty.
- bool IsQueueEmpty();
-
// Fills |dest| with one frame of audio data at normal speed. Returns true if
// a frame was rendered, false otherwise.
bool OutputNormalPlayback(uint8* dest);
diff --git a/media/filters/audio_renderer_impl.cc b/media/filters/audio_renderer_impl.cc
index bed9a68..4f59593 100644
--- a/media/filters/audio_renderer_impl.cc
+++ b/media/filters/audio_renderer_impl.cc
@@ -199,7 +199,7 @@ void AudioRendererImpl::Initialize(const scoped_refptr<AudioDecoder>& decoder,
bool AudioRendererImpl::HasEnded() {
base::AutoLock auto_lock(lock_);
- DCHECK(!rendered_end_of_stream_ || algorithm_->NeedsMoreData());
+ DCHECK(!rendered_end_of_stream_ || !algorithm_->CanFillBuffer());
return received_end_of_stream_ && rendered_end_of_stream_;
}
@@ -277,14 +277,6 @@ void AudioRendererImpl::DecodedAudioReady(scoped_refptr<Buffer> buffer) {
}
}
-void AudioRendererImpl::SignalEndOfStream() {
- DCHECK(received_end_of_stream_);
- if (!rendered_end_of_stream_) {
- rendered_end_of_stream_ = true;
- host()->NotifyEnded();
- }
-}
-
void AudioRendererImpl::ScheduleRead_Locked() {
lock_.AssertAcquired();
if (pending_read_ || state_ == kPaused)
@@ -406,31 +398,36 @@ uint32 AudioRendererImpl::FillBuffer(uint8* dest,
return zeros_to_write / bytes_per_frame_;
}
- // Use three conditions to determine the end of playback:
- // 1. Algorithm needs more audio data.
- // 2. We've received an end of stream buffer.
- // (received_end_of_stream_ == true)
- // 3. Browser process has no audio data being played.
- // There is no way to check that condition that would work for all
- // derived classes, so call virtual method that would either render
- // end of stream or schedule such rendering.
+ // We use the following conditions to determine end of playback:
+ // 1) Algorithm can not fill the audio callback buffer
+ // 2) We received an end of stream buffer
+ // 3) We haven't already signalled that we've ended
+ // 4) Our estimated earliest end time has expired
//
- // Three conditions determine when an underflow occurs:
- // 1. Algorithm has no audio data.
- // 2. Currently in the kPlaying state.
- // 3. Have not received an end of stream buffer.
- if (algorithm_->NeedsMoreData()) {
- if (received_end_of_stream_) {
- // TODO(enal): schedule callback instead of polling.
- if (base::Time::Now() >= earliest_end_time_)
- SignalEndOfStream();
- } else if (state_ == kPlaying) {
- state_ = kUnderflow;
- underflow_cb = underflow_cb_;
- }
- } else {
- // Otherwise fill the buffer.
+ // TODO(enal): we should replace (4) with a check that the browser has no
+ // more audio data or at least use a delayed callback.
+ //
+ // We use the following conditions to determine underflow:
+ // 1) Algorithm can not fill the audio callback buffer
+ // 2) We have NOT received an end of stream buffer
+ // 3) We are in the kPlaying state
+ //
+ // Otherwise fill the buffer with whatever data we can send to the device.
+ if (!algorithm_->CanFillBuffer() && received_end_of_stream_ &&
+ !rendered_end_of_stream_ && base::Time::Now() >= earliest_end_time_) {
+ rendered_end_of_stream_ = true;
+ host()->NotifyEnded();
+ } else if (!algorithm_->CanFillBuffer() && !received_end_of_stream_ &&
+ state_ == kPlaying) {
+ state_ = kUnderflow;
+ underflow_cb = underflow_cb_;
+ } else if (algorithm_->CanFillBuffer()) {
frames_written = algorithm_->FillBuffer(dest, requested_frames);
+ DCHECK_GT(frames_written, 0u);
+ } else {
+ // We can't write any data this cycle. For example, we may have
+ // sent all available data to the audio device while not reaching
+ // |earliest_end_time_|.
}
// The |audio_time_buffered_| is the ending timestamp of the last frame
diff --git a/media/filters/audio_renderer_impl.h b/media/filters/audio_renderer_impl.h
index 0a6d660..b3c014f 100644
--- a/media/filters/audio_renderer_impl.h
+++ b/media/filters/audio_renderer_impl.h
@@ -85,17 +85,11 @@ class MEDIA_EXPORT AudioRendererImpl
// should the filled buffer be played. If FillBuffer() is called as the audio
// hardware plays the buffer, then |playback_delay| should be zero.
//
- // FillBuffer() calls SignalEndOfStream() when it reaches end of stream.
- //
// Safe to call on any thread.
uint32 FillBuffer(uint8* dest,
uint32 requested_frames,
const base::TimeDelta& playback_delay);
- // Called at the end of stream when all the hardware buffers become empty
- // (i.e. when all the data written to the device has been played).
- void SignalEndOfStream();
-
// Get the playback rate of |algorithm_|.
float GetPlaybackRate();