From a9590c25660d4be4caad2add5e16e08003e5ed39 Mon Sep 17 00:00:00 2001 From: "fischman@chromium.org" Date: Wed, 16 Mar 2011 16:57:02 +0000 Subject: PipelineError is dead. Long live PipelineStatus! PipelineError was a poor naming choice because most of the time variables of that type held the value PIPELINE_OK meaning there was in fact no error. Replaced the idiom of [0-ary callback + GetError()] with [1-ary callback taking PipelineStatus argument] which makes the Pipeline API cleaner and less error-prone. Before, consumers of the API had to make sure to call GetError() at the top of each callback, or risk missing state transitions in the pipeline. Now each callback gets an explicit parameter holding the pipeline status at the moment the callback was invoked so failing to handle error conditions should be more apparent in the code. BUG=none TEST=media_unittests + trybots: {mac,linux,win}{_layout,}, linux_rel, linux_clang (all pass or fail with unrelated errors) Review URL: http://codereview.chromium.org/6686061 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@78379 0039d316-1c4b-4281-b951-d872f2087c98 --- media/tools/player_x11/player_x11.cc | 45 ++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 20 deletions(-) (limited to 'media/tools/player_x11') diff --git a/media/tools/player_x11/player_x11.cc b/media/tools/player_x11/player_x11.cc index 84e08e6..ace2ba6 100644 --- a/media/tools/player_x11/player_x11.cc +++ b/media/tools/player_x11/player_x11.cc @@ -52,9 +52,17 @@ Display* g_display = NULL; Window g_window = 0; bool g_running = false; -void Quit(MessageLoop* message_loop) { - message_loop->PostTask(FROM_HERE, new MessageLoop::QuitTask()); -} +class MessageLoopQuitter { + public: + explicit MessageLoopQuitter(MessageLoop* loop) : loop_(loop) {} + void Quit(media::PipelineStatus status) { + loop_->PostTask(FROM_HERE, new MessageLoop::QuitTask()); + delete this; + } + private: + MessageLoop* loop_; + DISALLOW_COPY_AND_ASSIGN(MessageLoopQuitter); +}; // Initialize X11. Returns true if successful. This method creates the X11 // window. Further initialization is done in X11VideoRenderer. @@ -126,23 +134,20 @@ bool InitPipeline(MessageLoop* message_loop, else collection->AddAudioRenderer(new media::NullAudioRenderer()); - // Create and start the pipeline. + // Create the pipeline and start it. *pipeline = new media::PipelineImpl(message_loop); - (*pipeline)->Start(collection.release(), filename, NULL); + media::PipelineStatusNotification note; + (*pipeline)->Start(collection.release(), filename, note.Callback()); // Wait until the pipeline is fully initialized. - while (true) { - base::PlatformThread::Sleep(100); - if ((*pipeline)->IsInitialized()) - break; - if ((*pipeline)->GetError() != media::PIPELINE_OK) { - std::cout << "InitPipeline: " << (*pipeline)->GetError() << std::endl; - (*pipeline)->Stop(NULL); - return false; - } + note.Wait(); + if (note.status() != media::PIPELINE_OK) { + std::cout << "InitPipeline: " << note.status() << std::endl; + (*pipeline)->Stop(NULL); + return false; } - // And starts the playback. + // And start the playback. (*pipeline)->SetPlaybackRate(1.0f); return true; } @@ -156,10 +161,10 @@ void PeriodicalUpdate( MessageLoop* message_loop, bool audio_only) { if (!g_running) { - // interrupt signal is received during lat time period. + // interrupt signal was received during last time period. // Quit message_loop only when pipeline is fully stopped. - pipeline->Stop(media::TaskToCallbackAdapter::NewCallback( - NewRunnableFunction(Quit, message_loop))); + MessageLoopQuitter* quitter = new MessageLoopQuitter(message_loop); + pipeline->Stop(NewCallback(quitter, &MessageLoopQuitter::Quit)); return; } @@ -199,8 +204,8 @@ void PeriodicalUpdate( if (key == XK_Escape) { g_running = false; // Quit message_loop only when pipeline is fully stopped. - pipeline->Stop(media::TaskToCallbackAdapter::NewCallback( - NewRunnableFunction(Quit, message_loop))); + MessageLoopQuitter* quitter = new MessageLoopQuitter(message_loop); + pipeline->Stop(NewCallback(quitter, &MessageLoopQuitter::Quit)); return; } else if (key == XK_space) { if (pipeline->GetPlaybackRate() < 0.01f) // paused -- cgit v1.1