Index: media/filters/audio_renderer_impl.cc |
diff --git a/media/filters/audio_renderer_impl.cc b/media/filters/audio_renderer_impl.cc |
index ae4096a9de0377ef34bd44acfad78026d2c152fe..e1e46df5cb6a9e7d6b7fcf987ff6817d0d177e01 100644 |
--- a/media/filters/audio_renderer_impl.cc |
+++ b/media/filters/audio_renderer_impl.cc |
@@ -72,7 +72,7 @@ AudioRendererImpl::~AudioRendererImpl() { |
DCHECK(!algorithm_.get()); |
} |
-void AudioRendererImpl::StartRendering() { |
+void AudioRendererImpl::StartTicking() { |
DVLOG(1) << __FUNCTION__; |
DCHECK(task_runner_->BelongsToCurrentThread()); |
DCHECK(!rendering_); |
@@ -102,7 +102,7 @@ void AudioRendererImpl::StartRendering_Locked() { |
sink_->Play(); |
} |
-void AudioRendererImpl::StopRendering() { |
+void AudioRendererImpl::StopTicking() { |
DVLOG(1) << __FUNCTION__; |
DCHECK(task_runner_->BelongsToCurrentThread()); |
DCHECK(rendering_); |
@@ -206,7 +206,6 @@ void AudioRendererImpl::Stop(const base::Closure& callback) { |
ChangeState_Locked(kStopped); |
algorithm_.reset(); |
- time_cb_.Reset(); |
flush_cb_.Reset(); |
} |
@@ -218,8 +217,8 @@ void AudioRendererImpl::Stop(const base::Closure& callback) { |
audio_buffer_stream_.Stop(callback); |
} |
-void AudioRendererImpl::StartPlayingFrom(base::TimeDelta timestamp) { |
- DVLOG(1) << __FUNCTION__ << "(" << timestamp.InMicroseconds() << ")"; |
+void AudioRendererImpl::StartPlaying() { |
+ DVLOG(1) << __FUNCTION__; |
DCHECK(task_runner_->BelongsToCurrentThread()); |
base::AutoLock auto_lock(lock_); |
@@ -229,15 +228,30 @@ void AudioRendererImpl::StartPlayingFrom(base::TimeDelta timestamp) { |
DCHECK(!pending_read_) << "Pending read must complete before seeking"; |
ChangeState_Locked(kPlaying); |
+ AttemptRead_Locked(); |
+} |
+ |
+void AudioRendererImpl::SetMediaTimestamp(base::TimeDelta timestamp) { |
+ DVLOG(1) << __FUNCTION__ << "(" << timestamp.InMicroseconds() << ")"; |
+ DCHECK(!rendering_); |
start_timestamp_ = timestamp; |
+} |
- AttemptRead_Locked(); |
+base::TimeDelta AudioRendererImpl::CurrentMediaTimestamp() { |
+ DVLOG(1) << __FUNCTION__; |
+ DCHECK(task_runner_->BelongsToCurrentThread()); |
+ |
+ // TODO(scherkus): Take time since last updating |audio_clock_| into account. |
xhwang
2014/07/12 06:36:44
Yeah, this will improve time accuracy, also solve
|
+ base::AutoLock auto_lock(lock_); |
+ base::TimeDelta timestamp = audio_clock_->CurrentMediaTimestamp(); |
+ if (timestamp == kNoTimestamp()) |
+ return start_timestamp_; |
+ return timestamp; |
} |
void AudioRendererImpl::Initialize(DemuxerStream* stream, |
const PipelineStatusCB& init_cb, |
const StatisticsCB& statistics_cb, |
- const TimeCB& time_cb, |
const BufferingStateCB& buffering_state_cb, |
const base::Closure& ended_cb, |
const PipelineStatusCB& error_cb) { |
@@ -246,7 +260,6 @@ void AudioRendererImpl::Initialize(DemuxerStream* stream, |
DCHECK_EQ(stream->type(), DemuxerStream::AUDIO); |
DCHECK(!init_cb.is_null()); |
DCHECK(!statistics_cb.is_null()); |
- DCHECK(!time_cb.is_null()); |
DCHECK(!buffering_state_cb.is_null()); |
DCHECK(!ended_cb.is_null()); |
DCHECK(!error_cb.is_null()); |
@@ -256,7 +269,6 @@ void AudioRendererImpl::Initialize(DemuxerStream* stream, |
state_ = kInitializing; |
init_cb_ = init_cb; |
- time_cb_ = time_cb; |
buffering_state_cb_ = buffering_state_cb; |
ended_cb_ = ended_cb; |
error_cb_ = error_cb; |
@@ -552,7 +564,6 @@ int AudioRendererImpl::Render(AudioBus* audio_bus, |
const int delay_frames = static_cast<int>(playback_delay.InSecondsF() * |
audio_parameters_.sample_rate()); |
int frames_written = 0; |
- base::Closure time_cb; |
{ |
base::AutoLock auto_lock(lock_); |
@@ -586,8 +597,6 @@ int AudioRendererImpl::Render(AudioBus* audio_bus, |
// 3) We are in the kPlaying state |
// |
// Otherwise the buffer has data we can send to the device. |
- const base::TimeDelta media_timestamp_before_filling = |
- audio_clock_->CurrentMediaTimestamp(); |
if (algorithm_->frames_buffered() > 0) { |
frames_written = algorithm_->FillBuffer(audio_bus, requested_frames); |
audio_clock_->WroteAudio( |
@@ -614,21 +623,8 @@ int AudioRendererImpl::Render(AudioBus* audio_bus, |
base::Bind(&AudioRendererImpl::AttemptRead, |
weak_factory_.GetWeakPtr())); |
} |
- |
- // We only want to execute |time_cb_| if time has progressed and we haven't |
- // signaled end of stream yet. |
- if (media_timestamp_before_filling != |
- audio_clock_->CurrentMediaTimestamp() && |
- !rendered_end_of_stream_) { |
- time_cb = base::Bind(time_cb_, |
- audio_clock_->CurrentMediaTimestamp(), |
- audio_clock_->last_endpoint_timestamp()); |
- } |
} |
- if (!time_cb.is_null()) |
- task_runner_->PostTask(FROM_HERE, time_cb); |
- |
DCHECK_LE(frames_written, requested_frames); |
return frames_written; |
} |