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

Side by Side 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, 10 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 unified diff | Download patch
OLDNEW
(Empty)
1 // 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.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef MEDIA_BLINK_PIPELINE_STATE_H_
6 #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
7
8 #include "base/callback.h"
9 #include "base/macros.h"
10 #include "base/time/time.h"
11 #include "media/base/pipeline.h"
12 #include "media/base/renderer.h"
13
14 namespace media {
15
16 class ChunkDemuxer;
17 class Demuxer;
18
19 // PipelineState wraps a Pipeline to expose the one-at-a-time operations
20 // (Seek(), Suspend(), and Resume()) with a simpler API. Internally it tracks
21 // pending operations and dispatches them when possible. Duplicate requests
22 // (such as seeking twice to the same time) may be elided.
23 //
24 // "Stable state", used in comments below, means that |state_| is PLAYING and
25 // there are no pending operations. When the state is not stable, it means that
26 // |pipeline_| is processing an operation and that incoming requests will be
27 // queued. (Exception: even though SUSPENDED is not a stable state, a Resume()
28 // request while suspended is processed immediately.)
29 //
30 // TODO(sandersd):
31 // - Expose an operation that restarts via suspend+resume.
32 // - Block invalid calls after an error occurs.
33 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
34 public:
35 enum class State {
36 PLAYING,
37 SEEKING,
38 SUSPENDING,
39 SUSPENDED,
40 RESUMING,
41 };
42
43 typedef base::Callback<scoped_ptr<Renderer>(void)> RendererFactoryCB;
44 typedef base::Callback<void(bool time_updated)> SeekedCB;
45 typedef base::Callback<void()> SuspendedCB;
46
47 PipelineState(Pipeline* pipeline,
48 const RendererFactoryCB& renderer_factory_cb,
49 const SeekedCB& seeked_cb,
50 const SuspendedCB& suspended_cb,
51 const PipelineStatusCB& error_cb);
52 ~PipelineState();
53
54 // Start |pipeline_|. If provided, |chunk_demuxer| will be stored and
55 // StartWaitingForSeek()/CancelPendingSeek() will be issued to it as
56 // necessary. Other parameters are just passed directly to |pipeline_|.
57 void Start(ChunkDemuxer* chunk_demuxer,
58 Demuxer* demuxer,
59 const base::Closure& ended_cb,
60 const PipelineMetadataCB& metadata_cb,
61 const BufferingStateCB& buffering_state_cb,
62 const base::Closure& duration_change_cb,
63 const AddTextTrackCB& add_text_track_cb,
64 const base::Closure& waiting_for_decryption_key_cb);
65
66 void Seek(base::TimeDelta time, bool time_updated);
67 void Suspend();
68 void Resume();
69
70 // Returns true if the current state is stable.
71 bool IsPlaying();
72
73 // Returns true if |pipeline_| is suspended. Specifically, it is false while
74 // suspending and true while resuming. (The compositor is expected to not
75 // render any new frames while IsSuspended() returns true.)
76 bool IsSuspended();
77
78 private:
79 // Attempts to make progress from the current state to the target state.
80 void Dispatch();
81
82 // PipelineStaus callback that also carries the target state.
83 void OnPipelineStatus(State state, PipelineStatus pipeline_status);
84
85 // The Pipeline we are managing state for.
86 Pipeline* pipeline_ = nullptr;
87
88 // Factory for Renderers, used for Start() and Resume().
89 RendererFactoryCB renderer_factory_cb_;
90
91 // Called after seeks (which includes Start()) upon reaching a stable state.
92 // Multiple seeks result in only one callback if no stable state occurs
93 // between them.
94 SeekedCB seeked_cb_;
95
96 // Called immediately when |pipeline_| completes a suspend operation.
97 SuspendedCB suspended_cb_;
98
99 // Called immediately when any operation on |pipeline_| results in an error.
100 PipelineStatusCB error_cb_;
101
102 // State for handling StartWaitingForSeek()/CancelPendingSeek().
103 ChunkDemuxer* chunk_demuxer_ = nullptr;
104 bool waiting_for_seek_ = false;
105
106 // Tracks the current state of |pipeline_|.
107 State state_ = State::PLAYING;
108
109 // Indicates that a seek has occurred. When set, a seeked callback will be
110 // issued at the next stable state.
111 bool pending_seeked_ = true;
112
113 // Indicates that time has been changed by a seek, which will be reported at
114 // the next seeked callback.
115 bool pending_time_update_ = false;
116
117 // The target time of the active seek; valid while SEEKING or RESUMING.
118 base::TimeDelta seek_time_;
119
120 // Target state which we will work to achieve. |pending_seek_time_| is only
121 // valid when |pending_seek_| is true.
122 bool pending_seek_ = false;
123 base::TimeDelta pending_seek_time_;
124 bool pending_suspend_ = false;
125 bool pending_resume_ = false;
126
127 DISALLOW_COPY_AND_ASSIGN(PipelineState);
128 };
129
130 } // namespace media
131
132 #endif // MEDIA_BLINK_PIPELINE_STATE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698