From 9ec76089b0f907ad125a1710a5868c4212289d3f Mon Sep 17 00:00:00 2001 From: "scherkus@chromium.org" Date: Thu, 3 Jul 2014 07:21:57 +0000 Subject: Make TextRenderer::Play() a synchronous method. This mirrors the style of API that Audio/VideoRenderer have moved towards as well as clears the way for removing more state from Pipeline. BUG=144683 Review URL: https://codereview.chromium.org/361293003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@281212 0039d316-1c4b-4281-b951-d872f2087c98 --- media/base/pipeline.cc | 27 +++++---------------------- media/base/pipeline.h | 4 ---- media/base/text_renderer.cc | 3 +-- media/base/text_renderer.h | 5 ++--- media/base/text_renderer_unittest.cc | 6 +----- 5 files changed, 9 insertions(+), 36 deletions(-) (limited to 'media') diff --git a/media/base/pipeline.cc b/media/base/pipeline.cc index a81e758..a393cc8 100644 --- a/media/base/pipeline.cc +++ b/media/base/pipeline.cc @@ -353,8 +353,7 @@ void Pipeline::StateTransitionTask(PipelineStatus status) { // Guard against accidentally clearing |pending_callbacks_| for states that // use it as well as states that should not be using it. - DCHECK_EQ(pending_callbacks_.get() != NULL, - (state_ == kInitPrerolling || state_ == kSeeking)); + DCHECK_EQ(pending_callbacks_.get() != NULL, state_ == kSeeking); pending_callbacks_.reset(); @@ -397,7 +396,8 @@ void Pipeline::StateTransitionTask(PipelineStatus status) { metadata_cb_.Run(metadata); } - return DoInitialPreroll(done_cb); + // TODO(scherkus): Fold kInitPrerolling state into kPlaying. + return done_cb.Run(PIPELINE_OK); case kPlaying: base::ResetAndReturn(&seek_cb_).Run(PIPELINE_OK); @@ -406,6 +406,8 @@ void Pipeline::StateTransitionTask(PipelineStatus status) { audio_renderer_->StartPlayingFrom(start_timestamp_); if (video_renderer_) video_renderer_->StartPlayingFrom(start_timestamp_); + if (text_renderer_) + text_renderer_->StartPlaying(); PlaybackRateChangedTask(GetPlaybackRate()); VolumeChangedTask(GetVolume()); @@ -426,19 +428,6 @@ void Pipeline::StateTransitionTask(PipelineStatus status) { // // That being said, deleting the renderers while keeping |pending_callbacks_| // running on the media thread would result in crashes. -void Pipeline::DoInitialPreroll(const PipelineStatusCB& done_cb) { - DCHECK(task_runner_->BelongsToCurrentThread()); - DCHECK(!pending_callbacks_.get()); - SerialRunner::Queue bound_fns; - - // Preroll renderers. - if (text_renderer_) { - bound_fns.Push(base::Bind( - &TextRenderer::Play, base::Unretained(text_renderer_.get()))); - } - - pending_callbacks_ = SerialRunner::Run(bound_fns, done_cb); -} #if DCHECK_IS_ON static void VerifyBufferingStates(BufferingState* audio_buffering_state, @@ -488,12 +477,6 @@ void Pipeline::DoSeek( bound_fns.Push(base::Bind( &Demuxer::Seek, base::Unretained(demuxer_), seek_timestamp)); - // Preroll renderers. - if (text_renderer_) { - bound_fns.Push(base::Bind( - &TextRenderer::Play, base::Unretained(text_renderer_.get()))); - } - pending_callbacks_ = SerialRunner::Run(bound_fns, done_cb); } diff --git a/media/base/pipeline.h b/media/base/pipeline.h index b8307bd..f042548 100644 --- a/media/base/pipeline.h +++ b/media/base/pipeline.h @@ -294,10 +294,6 @@ class MEDIA_EXPORT Pipeline : public DemuxerHost { void OnStateTransition(PipelineStatus status); void StateTransitionTask(PipelineStatus status); - // Initiates an asynchronous preroll call sequence executing |done_cb| - // with the final status when completed. - void DoInitialPreroll(const PipelineStatusCB& done_cb); - // Initiates an asynchronous pause-flush-seek-preroll call sequence // executing |done_cb| with the final status when completed. // diff --git a/media/base/text_renderer.cc b/media/base/text_renderer.cc index 6f88ef7..3a04348 100644 --- a/media/base/text_renderer.cc +++ b/media/base/text_renderer.cc @@ -46,7 +46,7 @@ void TextRenderer::Initialize(const base::Closure& ended_cb) { state_ = kPaused; } -void TextRenderer::Play(const base::Closure& callback) { +void TextRenderer::StartPlaying() { DCHECK(task_runner_->BelongsToCurrentThread()); DCHECK_EQ(state_, kPaused) << "state_ " << state_; @@ -62,7 +62,6 @@ void TextRenderer::Play(const base::Closure& callback) { } state_ = kPlaying; - callback.Run(); } void TextRenderer::Pause(const base::Closure& callback) { diff --git a/media/base/text_renderer.h b/media/base/text_renderer.h index ce10912..7e719db 100644 --- a/media/base/text_renderer.h +++ b/media/base/text_renderer.h @@ -44,9 +44,8 @@ class MEDIA_EXPORT TextRenderer { // end of stream, following a play request. void Initialize(const base::Closure& ended_cb); - // Start text track cue decoding and rendering, executing |callback| when - // playback is underway. - void Play(const base::Closure& callback); + // Start text track cue decoding and rendering. + void StartPlaying(); // Temporarily suspend decoding and rendering, executing |callback| when // playback has been suspended. diff --git a/media/base/text_renderer_unittest.cc b/media/base/text_renderer_unittest.cc index 77e8c47..2c31c92 100644 --- a/media/base/text_renderer_unittest.cc +++ b/media/base/text_renderer_unittest.cc @@ -184,10 +184,7 @@ class TextRendererTest : public testing::Test { } void Play() { - EXPECT_CALL(*this, OnPlay()); - text_renderer_->Play(base::Bind(&TextRendererTest::OnPlay, - base::Unretained(this))); - message_loop_.RunUntilIdle(); + text_renderer_->StartPlaying(); } void Pause() { @@ -215,7 +212,6 @@ class TextRendererTest : public testing::Test { MOCK_METHOD0(OnEnd, void()); MOCK_METHOD0(OnStop, void()); - MOCK_METHOD0(OnPlay, void()); MOCK_METHOD0(OnPause, void()); MOCK_METHOD0(OnFlush, void()); -- cgit v1.1