Chromium Code Reviews| Index: media/base/pipeline.cc |
| diff --git a/media/base/pipeline.cc b/media/base/pipeline.cc |
| index ca53be0ceb874e7e567c0c6c831d425bd76b1329..7cc024ec44818a6d4aa4cdb5ae20cf811fbd4654 100644 |
| --- a/media/base/pipeline.cc |
| +++ b/media/base/pipeline.cc |
| @@ -23,10 +23,10 @@ |
| #include "media/base/media_log.h" |
| #include "media/base/text_renderer.h" |
| #include "media/base/text_track_config.h" |
| -#include "media/base/time_delta_interpolator.h" |
| #include "media/base/video_decoder.h" |
| #include "media/base/video_decoder_config.h" |
| #include "media/base/video_renderer.h" |
| +#include "media/base/wall_clock_time_source.h" |
| using base::TimeDelta; |
| @@ -41,8 +41,6 @@ Pipeline::Pipeline( |
| did_loading_progress_(false), |
| volume_(1.0f), |
| playback_rate_(0.0f), |
| - interpolator_(new TimeDeltaInterpolator(&default_tick_clock_)), |
| - interpolation_state_(INTERPOLATION_STOPPED), |
| status_(PIPELINE_OK), |
| state_(kCreated), |
| audio_ended_(false), |
| @@ -51,11 +49,11 @@ Pipeline::Pipeline( |
| audio_buffering_state_(BUFFERING_HAVE_NOTHING), |
| video_buffering_state_(BUFFERING_HAVE_NOTHING), |
| demuxer_(NULL), |
| + time_source_(NULL), |
| underflow_disabled_for_testing_(false) { |
| media_log_->AddEvent(media_log_->CreatePipelineStateChangedEvent(kCreated)); |
| media_log_->AddEvent( |
| media_log_->CreateEvent(MediaLogEvent::PIPELINE_CREATED)); |
| - interpolator_->SetBounds(base::TimeDelta(), base::TimeDelta()); |
| } |
| Pipeline::~Pipeline() { |
| @@ -157,7 +155,7 @@ void Pipeline::SetVolume(float volume) { |
| TimeDelta Pipeline::GetMediaTime() const { |
| base::AutoLock auto_lock(lock_); |
| - return std::min(interpolator_->GetInterpolatedTime(), duration_); |
| + return time_source_->CurrentMediaTimestamp(); |
|
xhwang
2014/07/12 06:36:44
Other use of time_source_ in this file is not prot
|
| } |
| Ranges<TimeDelta> Pipeline::GetBufferedTimeRanges() const { |
| @@ -182,11 +180,6 @@ PipelineStatistics Pipeline::GetStatistics() const { |
| return statistics_; |
| } |
| -void Pipeline::SetTimeDeltaInterpolatorForTesting( |
| - TimeDeltaInterpolator* interpolator) { |
| - interpolator_.reset(interpolator); |
| -} |
| - |
| void Pipeline::SetErrorForTesting(PipelineStatus status) { |
| SetError(status); |
| } |
| @@ -283,37 +276,6 @@ void Pipeline::SetError(PipelineStatus error) { |
| media_log_->AddEvent(media_log_->CreatePipelineErrorEvent(error)); |
| } |
| -void Pipeline::OnAudioTimeUpdate(TimeDelta time, TimeDelta max_time) { |
| - DCHECK(task_runner_->BelongsToCurrentThread()); |
| - DCHECK_LE(time.InMicroseconds(), max_time.InMicroseconds()); |
| - base::AutoLock auto_lock(lock_); |
| - |
| - if (interpolation_state_ == INTERPOLATION_WAITING_FOR_AUDIO_TIME_UPDATE && |
| - time < interpolator_->GetInterpolatedTime()) { |
| - return; |
| - } |
| - |
| - if (state_ == kSeeking) |
| - return; |
| - |
| - interpolator_->SetBounds(time, max_time); |
| - StartClockIfWaitingForTimeUpdate_Locked(); |
| -} |
| - |
| -void Pipeline::OnVideoTimeUpdate(TimeDelta max_time) { |
| - DCHECK(task_runner_->BelongsToCurrentThread()); |
| - |
| - if (audio_renderer_) |
| - return; |
| - |
| - if (state_ == kSeeking) |
| - return; |
| - |
| - base::AutoLock auto_lock(lock_); |
| - DCHECK_NE(interpolation_state_, INTERPOLATION_WAITING_FOR_AUDIO_TIME_UPDATE); |
| - interpolator_->SetUpperBound(max_time); |
| -} |
| - |
| void Pipeline::SetDuration(TimeDelta duration) { |
| DCHECK(IsRunning()); |
| media_log_->AddEvent( |
| @@ -392,20 +354,24 @@ void Pipeline::StateTransitionTask(PipelineStatus status) { |
| metadata.video_rotation = stream->video_rotation(); |
| } |
| metadata_cb_.Run(metadata); |
| + |
| + if (audio_renderer_) { |
| + time_source_ = audio_renderer_.get(); |
| + } else { |
| + wall_clock_time_source_.reset(new WallClockTimeSource()); |
| + time_source_ = wall_clock_time_source_.get(); |
| + } |
| } |
| } |
| base::ResetAndReturn(&seek_cb_).Run(PIPELINE_OK); |
| - { |
| - base::AutoLock auto_lock(lock_); |
| - interpolator_->SetBounds(start_timestamp_, start_timestamp_); |
| - } |
| + time_source_->SetMediaTimestamp(start_timestamp_); |
| if (audio_renderer_) |
| - audio_renderer_->StartPlayingFrom(start_timestamp_); |
| + audio_renderer_->StartPlaying(); |
| if (video_renderer_) |
| - video_renderer_->StartPlayingFrom(start_timestamp_); |
| + video_renderer_->StartPlaying(); |
| if (text_renderer_) |
| text_renderer_->StartPlaying(); |
| @@ -445,7 +411,7 @@ void Pipeline::DoSeek( |
| SerialRunner::Queue bound_fns; |
| { |
| base::AutoLock auto_lock(lock_); |
| - PauseClockAndStopRendering_Locked(); |
| + PausePlayback(); |
| } |
| // Pause. |
| @@ -642,13 +608,7 @@ void Pipeline::PlaybackRateChangedTask(float playback_rate) { |
| if (state_ != kPlaying) |
| return; |
| - { |
| - base::AutoLock auto_lock(lock_); |
| - interpolator_->SetPlaybackRate(playback_rate); |
| - } |
| - |
| - if (audio_renderer_) |
| - audio_renderer_->SetPlaybackRate(playback_rate_); |
| + time_source_->SetPlaybackRate(playback_rate_); |
| } |
| void Pipeline::VolumeChangedTask(float volume) { |
| @@ -700,13 +660,6 @@ void Pipeline::DoAudioRendererEnded() { |
| DCHECK(!audio_ended_); |
| audio_ended_ = true; |
| - // Start clock since there is no more audio to trigger clock updates. |
| - { |
| - base::AutoLock auto_lock(lock_); |
| - interpolator_->SetUpperBound(duration_); |
| - StartClockIfWaitingForTimeUpdate_Locked(); |
| - } |
| - |
| RunEndedCallbackIfNeeded(); |
| } |
| @@ -746,11 +699,7 @@ void Pipeline::RunEndedCallbackIfNeeded() { |
| if (text_renderer_ && text_renderer_->HasTracks() && !text_ended_) |
| return; |
| - { |
| - base::AutoLock auto_lock(lock_); |
| - PauseClockAndStopRendering_Locked(); |
| - interpolator_->SetBounds(duration_, duration_); |
| - } |
| + PausePlayback(); |
| DCHECK_EQ(status_, PIPELINE_OK); |
| ended_cb_.Run(); |
| @@ -784,7 +733,6 @@ void Pipeline::InitializeAudioRenderer(const PipelineStatusCB& done_cb) { |
| demuxer_->GetStream(DemuxerStream::AUDIO), |
| done_cb, |
| base::Bind(&Pipeline::OnUpdateStatistics, base::Unretained(this)), |
| - base::Bind(&Pipeline::OnAudioTimeUpdate, base::Unretained(this)), |
| base::Bind(&Pipeline::BufferingStateChanged, base::Unretained(this), |
| &audio_buffering_state_), |
| base::Bind(&Pipeline::OnAudioRendererEnded, base::Unretained(this)), |
| @@ -800,7 +748,6 @@ void Pipeline::InitializeVideoRenderer(const PipelineStatusCB& done_cb) { |
| demuxer_->GetLiveness() == Demuxer::LIVENESS_LIVE, |
| done_cb, |
| base::Bind(&Pipeline::OnUpdateStatistics, base::Unretained(this)), |
| - base::Bind(&Pipeline::OnVideoTimeUpdate, base::Unretained(this)), |
| base::Bind(&Pipeline::BufferingStateChanged, base::Unretained(this), |
| &video_buffering_state_), |
| base::Bind(&Pipeline::OnVideoRendererEnded, base::Unretained(this)), |
| @@ -819,12 +766,14 @@ void Pipeline::BufferingStateChanged(BufferingState* buffering_state, |
| *buffering_state = new_buffering_state; |
| +#if 0 |
| // Disable underflow by ignoring updates that renderers have ran out of data |
| // after we have started the clock. |
| if (state_ == kPlaying && underflow_disabled_for_testing_ && |
| interpolation_state_ != INTERPOLATION_STOPPED) { |
| return; |
| } |
| +#endif |
| // Renderer underflowed. |
| if (!was_waiting_for_enough_data && WaitingForEnoughData()) { |
| @@ -860,58 +809,16 @@ void Pipeline::PausePlayback() { |
| DCHECK(WaitingForEnoughData()); |
| DCHECK(task_runner_->BelongsToCurrentThread()); |
| - base::AutoLock auto_lock(lock_); |
| - PauseClockAndStopRendering_Locked(); |
| + time_source_->StopTicking(); |
| } |
| void Pipeline::StartPlayback() { |
| DVLOG(1) << __FUNCTION__; |
| DCHECK_EQ(state_, kPlaying); |
| - DCHECK_EQ(interpolation_state_, INTERPOLATION_STOPPED); |
| DCHECK(!WaitingForEnoughData()); |
| DCHECK(task_runner_->BelongsToCurrentThread()); |
| - if (audio_renderer_) { |
| - // We use audio stream to update the clock. So if there is such a |
| - // stream, we pause the clock until we receive a valid timestamp. |
| - base::AutoLock auto_lock(lock_); |
| - interpolation_state_ = INTERPOLATION_WAITING_FOR_AUDIO_TIME_UPDATE; |
| - audio_renderer_->StartRendering(); |
| - } else { |
| - base::AutoLock auto_lock(lock_); |
| - interpolation_state_ = INTERPOLATION_STARTED; |
| - interpolator_->SetUpperBound(duration_); |
| - interpolator_->StartInterpolating(); |
| - } |
| -} |
| - |
| -void Pipeline::PauseClockAndStopRendering_Locked() { |
| - lock_.AssertAcquired(); |
| - switch (interpolation_state_) { |
| - case INTERPOLATION_STOPPED: |
| - return; |
| - |
| - case INTERPOLATION_WAITING_FOR_AUDIO_TIME_UPDATE: |
| - audio_renderer_->StopRendering(); |
| - break; |
| - |
| - case INTERPOLATION_STARTED: |
| - if (audio_renderer_) |
| - audio_renderer_->StopRendering(); |
| - interpolator_->StopInterpolating(); |
| - break; |
| - } |
| - |
| - interpolation_state_ = INTERPOLATION_STOPPED; |
| -} |
| - |
| -void Pipeline::StartClockIfWaitingForTimeUpdate_Locked() { |
| - lock_.AssertAcquired(); |
| - if (interpolation_state_ != INTERPOLATION_WAITING_FOR_AUDIO_TIME_UPDATE) |
| - return; |
| - |
| - interpolation_state_ = INTERPOLATION_STARTED; |
| - interpolator_->StartInterpolating(); |
| + time_source_->StartTicking(); |
| } |
| } // namespace media |