Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(22)

Unified Diff: media/blink/pipeline_state.h

Issue 1641423002: Re-land extract state management from WebMediaPlayerImpl. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: WMPI fixes. Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: media/blink/pipeline_state.h
diff --git a/media/blink/pipeline_state.h b/media/blink/pipeline_state.h
new file mode 100644
index 0000000000000000000000000000000000000000..5a0b3c5eb0b269148a72e631b0b676ec07a6d2fe
--- /dev/null
+++ b/media/blink/pipeline_state.h
@@ -0,0 +1,132 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
xhwang 2016/02/01 21:16:44 nit: 2016
sandersd (OOO until July 31) 2016/02/01 23:19:26 Done.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef MEDIA_BLINK_PIPELINE_STATE_H_
+#define MEDIA_BLINK_PIPELINE_STATE_H_
xhwang 2016/02/01 21:16:44 Can we put this file in the same folder as the pip
sandersd (OOO until July 31) 2016/02/01 23:19:26 It depends on media/filters; I wasn't sure if that
xhwang 2016/02/01 23:26:00 Then probably we should put this under media/filte
+
+#include "base/callback.h"
+#include "base/macros.h"
+#include "base/time/time.h"
+#include "media/base/pipeline.h"
+#include "media/base/renderer.h"
+
+namespace media {
+
+class ChunkDemuxer;
+class Demuxer;
+
+// PipelineState wraps a Pipeline to expose the one-at-a-time operations
+// (Seek(), Suspend(), and Resume()) with a simpler API. Internally it tracks
+// pending operations and dispatches them when possible. Duplicate requests
+// (such as seeking twice to the same time) may be elided.
+//
+// "Stable state", used in comments below, means that |state_| is PLAYING and
+// there are no pending operations. When the state is not stable, it means that
+// |pipeline_| is processing an operation and that incoming requests will be
+// queued. (Exception: even though SUSPENDED is not a stable state, a Resume()
+// request while suspended is processed immediately.)
+//
+// TODO(sandersd):
+// - Expose an operation that restarts via suspend+resume.
+// - Block invalid calls after an error occurs.
+class PipelineState {
xhwang 2016/02/01 21:16:44 Can we hide this in the Pipeline so that WMPI only
sandersd (OOO until July 31) 2016/02/01 23:19:26 That's exactly the plan (pending some changes to t
+ public:
+ enum class State {
+ PLAYING,
+ SEEKING,
+ SUSPENDING,
+ SUSPENDED,
+ RESUMING,
+ };
+
+ typedef base::Callback<scoped_ptr<Renderer>(void)> RendererFactoryCB;
+ typedef base::Callback<void(bool time_updated)> SeekedCB;
+ typedef base::Callback<void()> SuspendedCB;
+
+ PipelineState(Pipeline* pipeline,
+ const RendererFactoryCB& renderer_factory_cb,
+ const SeekedCB& seeked_cb,
+ const SuspendedCB& suspended_cb,
+ const PipelineStatusCB& error_cb);
+ ~PipelineState();
+
+ // Start |pipeline_|. If provided, |chunk_demuxer| will be stored and
+ // StartWaitingForSeek()/CancelPendingSeek() will be issued to it as
+ // necessary. Other parameters are just passed directly to |pipeline_|.
+ void Start(ChunkDemuxer* chunk_demuxer,
+ Demuxer* demuxer,
+ const base::Closure& ended_cb,
+ const PipelineMetadataCB& metadata_cb,
+ const BufferingStateCB& buffering_state_cb,
+ const base::Closure& duration_change_cb,
+ const AddTextTrackCB& add_text_track_cb,
+ const base::Closure& waiting_for_decryption_key_cb);
+
+ void Seek(base::TimeDelta time, bool time_updated);
+ void Suspend();
+ void Resume();
+
+ // Returns true if the current state is stable.
+ bool IsPlaying();
+
+ // Returns true if |pipeline_| is suspended. Specifically, it is false while
+ // suspending and true while resuming. (The compositor is expected to not
+ // render any new frames while IsSuspended() returns true.)
+ bool IsSuspended();
+
+ private:
+ // Attempts to make progress from the current state to the target state.
+ void Dispatch();
+
+ // PipelineStaus callback that also carries the target state.
+ void OnPipelineStatus(State state, PipelineStatus pipeline_status);
+
+ // The Pipeline we are managing state for.
+ Pipeline* pipeline_ = nullptr;
+
+ // Factory for Renderers, used for Start() and Resume().
+ RendererFactoryCB renderer_factory_cb_;
+
+ // Called after seeks (which includes Start()) upon reaching a stable state.
+ // Multiple seeks result in only one callback if no stable state occurs
+ // between them.
+ SeekedCB seeked_cb_;
+
+ // Called immediately when |pipeline_| completes a suspend operation.
+ SuspendedCB suspended_cb_;
+
+ // Called immediately when any operation on |pipeline_| results in an error.
+ PipelineStatusCB error_cb_;
+
+ // State for handling StartWaitingForSeek()/CancelPendingSeek().
+ ChunkDemuxer* chunk_demuxer_ = nullptr;
+ bool waiting_for_seek_ = false;
+
+ // Tracks the current state of |pipeline_|.
+ State state_ = State::PLAYING;
+
+ // Indicates that a seek has occurred. When set, a seeked callback will be
+ // issued at the next stable state.
+ bool pending_seeked_ = true;
+
+ // Indicates that time has been changed by a seek, which will be reported at
+ // the next seeked callback.
+ bool pending_time_update_ = false;
+
+ // The target time of the active seek; valid while SEEKING or RESUMING.
+ base::TimeDelta seek_time_;
+
+ // Target state which we will work to achieve. |pending_seek_time_| is only
+ // valid when |pending_seek_| is true.
+ bool pending_seek_ = false;
+ base::TimeDelta pending_seek_time_;
+ bool pending_suspend_ = false;
+ bool pending_resume_ = false;
+
+ DISALLOW_COPY_AND_ASSIGN(PipelineState);
+};
+
+} // namespace media
+
+#endif // MEDIA_BLINK_PIPELINE_STATE_H_

Powered by Google App Engine
This is Rietveld 408576698