OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
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_FILTERS_PIPELINE_CONTROLLER_H_ | |
6 #define MEDIA_FILTERS_PIPELINE_CONTROLLER_H_ | |
7 | |
8 #include "base/callback.h" | |
9 #include "base/macros.h" | |
10 #include "base/memory/weak_ptr.h" | |
11 #include "base/time/time.h" | |
12 #include "media/base/media_export.h" | |
13 #include "media/base/pipeline.h" | |
14 #include "media/base/renderer.h" | |
15 | |
16 namespace media { | |
17 | |
18 class ChunkDemuxer; | |
19 class Demuxer; | |
20 | |
21 // PipelineController wraps a Pipeline to expose the one-at-a-time operations | |
22 // (Seek(), Suspend(), and Resume()) with a simpler API. Internally it tracks | |
23 // pending operations and dispatches them when possible. Duplicate requests | |
24 // (such as seeking twice to the same time) may be elided. | |
25 // | |
26 // TODO(sandersd): | |
27 // - Expose an operation that restarts via suspend+resume. | |
28 // - Block invalid calls after an error occurs. | |
29 class MEDIA_EXPORT PipelineController | |
30 : public base::SupportsWeakPtr<PipelineController> { | |
DaleCurtis
2016/02/25 01:58:30
Do we need SupportsWeakPtr() here? Can you instead
sandersd (OOO until July 31)
2016/02/25 20:33:46
Done.
| |
31 public: | |
32 enum class State { | |
33 CREATED, | |
34 STARTING, | |
35 PLAYING, | |
36 SEEKING, | |
37 SUSPENDING, | |
38 SUSPENDED, | |
39 RESUMING, | |
40 }; | |
41 | |
42 typedef base::Callback<scoped_ptr<Renderer>(void)> RendererFactoryCB; | |
DaleCurtis
2016/02/25 01:58:30
"using" instead of typedef now
sandersd (OOO until July 31)
2016/02/25 20:33:46
Done.
| |
43 typedef base::Callback<void(bool time_updated)> SeekedCB; | |
44 typedef base::Callback<void()> SuspendedCB; | |
45 | |
46 PipelineController(Pipeline* pipeline, | |
DaleCurtis
2016/02/25 01:58:30
Needs comments about lifetime of pipeline and what
sandersd (OOO until July 31)
2016/02/25 20:33:46
Those comments made somewhat more sense on the mem
| |
47 const RendererFactoryCB& renderer_factory_cb, | |
48 const SeekedCB& seeked_cb, | |
49 const SuspendedCB& suspended_cb, | |
50 const PipelineStatusCB& error_cb); | |
51 ~PipelineController(); | |
52 | |
53 // Start |pipeline_|. If provided, |chunk_demuxer| will be stored and | |
54 // StartWaitingForSeek()/CancelPendingSeek() will be issued to it as | |
55 // necessary. When |is_streaming| is true, Resume() will always start at the | |
56 // beginning of the stream, rather than attempting to seek to the current | |
57 // time. Other parameters are just passed directly to pipeline_.Start(). | |
58 void Start(ChunkDemuxer* chunk_demuxer, | |
59 Demuxer* demuxer, | |
60 bool is_streaming, | |
61 const base::Closure& ended_cb, | |
62 const PipelineMetadataCB& metadata_cb, | |
63 const BufferingStateCB& buffering_state_cb, | |
64 const base::Closure& duration_change_cb, | |
65 const AddTextTrackCB& add_text_track_cb, | |
66 const base::Closure& waiting_for_decryption_key_cb); | |
67 | |
68 void Seek(base::TimeDelta time, bool time_updated); | |
DaleCurtis
2016/02/25 01:58:30
Ditto for comments.
sandersd (OOO until July 31)
2016/02/25 20:33:46
Done.
| |
69 void Suspend(); | |
70 void Resume(); | |
71 | |
72 // Returns true if the current state is stable. This means that |state_| is | |
73 // PLAYING and there are no pending operations. Requests are processed | |
74 // immediately when the state is stable, otherwise they are queued. | |
75 // (Exception: Resume() is processed immediately while suspended.) | |
76 bool IsStable(); | |
77 | |
78 // Returns true if |pipeline_| is suspended. | |
79 bool IsSuspended(); | |
80 | |
81 private: | |
82 // Attempts to make progress from the current state to the target state. | |
83 void Dispatch(); | |
84 | |
85 // PipelineStaus callback that also carries the target state. | |
86 void OnPipelineStatus(State state, PipelineStatus pipeline_status); | |
87 | |
88 // The Pipeline we are managing state for. | |
89 Pipeline* pipeline_ = nullptr; | |
90 | |
91 // Factory for Renderers, used for Start() and Resume(). | |
92 RendererFactoryCB renderer_factory_cb_; | |
93 | |
94 // Called after seeks (which includes Start()) upon reaching a stable state. | |
95 // Multiple seeks result in only one callback if no stable state occurs | |
96 // between them. | |
97 SeekedCB seeked_cb_; | |
98 | |
99 // Called immediately when |pipeline_| completes a suspend operation. | |
100 SuspendedCB suspended_cb_; | |
101 | |
102 // Called immediately when any operation on |pipeline_| results in an error. | |
103 PipelineStatusCB error_cb_; | |
104 | |
105 // State for handling StartWaitingForSeek()/CancelPendingSeek(). | |
106 ChunkDemuxer* chunk_demuxer_ = nullptr; | |
107 bool waiting_for_seek_ = false; | |
108 | |
109 // When true, Resume() will start at time zero instead of seeking to the | |
110 // current time. | |
111 bool is_streaming_ = false; | |
112 | |
113 // Tracks the current state of |pipeline_|. | |
114 State state_ = State::CREATED; | |
115 | |
116 // Indicates that a seek has occurred. When set, a seeked callback will be | |
117 // issued at the next stable state. | |
118 bool pending_seeked_ = false; | |
119 | |
120 // Indicates that time has been changed by a seek, which will be reported at | |
121 // the next seeked callback. | |
122 bool pending_time_update_ = false; | |
123 | |
124 // The target time of the active seek; valid while SEEKING or RESUMING. | |
125 base::TimeDelta seek_time_; | |
126 | |
127 // Target state which we will work to achieve. |pending_seek_time_| is only | |
128 // valid when |pending_seek_| is true. | |
129 bool pending_seek_ = false; | |
130 base::TimeDelta pending_seek_time_; | |
131 bool pending_suspend_ = false; | |
132 bool pending_resume_ = false; | |
133 | |
134 DISALLOW_COPY_AND_ASSIGN(PipelineController); | |
135 }; | |
136 | |
137 } // namespace media | |
138 | |
139 #endif // MEDIA_FILTERS_PIPELINE_CONTROLLER_H_ | |
OLD | NEW |