diff options
author | fischman@chromium.org <fischman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-16 16:57:02 +0000 |
---|---|---|
committer | fischman@chromium.org <fischman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-16 16:57:02 +0000 |
commit | a9590c25660d4be4caad2add5e16e08003e5ed39 (patch) | |
tree | 10b2dd0b18e9122aa0eb86d80e14c8e3efafd73e /media/tools | |
parent | bac2d4979f97026ed1344cd2dc9b208f58886537 (diff) | |
download | chromium_src-a9590c25660d4be4caad2add5e16e08003e5ed39.zip chromium_src-a9590c25660d4be4caad2add5e16e08003e5ed39.tar.gz chromium_src-a9590c25660d4be4caad2add5e16e08003e5ed39.tar.bz2 |
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
Diffstat (limited to 'media/tools')
-rw-r--r-- | media/tools/player_wtl/movie.cc | 15 | ||||
-rw-r--r-- | media/tools/player_x11/player_x11.cc | 45 |
2 files changed, 32 insertions, 28 deletions
diff --git a/media/tools/player_wtl/movie.cc b/media/tools/player_wtl/movie.cc index 042d1f4..2c705ef 100644 --- a/media/tools/player_wtl/movie.cc +++ b/media/tools/player_wtl/movie.cc @@ -84,14 +84,13 @@ bool Movie::Open(const wchar_t* url, WtlVideoRenderer* video_renderer) { collection->AddVideoRenderer(video_renderer); // Create and start our pipeline. - pipeline_->Start(collection.release(), WideToUTF8(std::wstring(url)), NULL); - while (true) { - base::PlatformThread::Sleep(100); - if (pipeline_->IsInitialized()) - break; - if (pipeline_->GetError() != media::PIPELINE_OK) - return false; - } + media::PipelineStatusNotification note; + pipeline_->Start(collection.release(), WideToUTF8(std::wstring(url)), + note.Callback()); + // Wait until the pipeline is fully initialized. + note.Wait(); + if (note.status() != PIPELINE_OK) + return false; pipeline_->SetPlaybackRate(play_rate_); return true; } 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 |