OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef MEDIA_FILTERS_PIPELINE_CONTROLLER_H_ | 5 #ifndef MEDIA_FILTERS_PIPELINE_CONTROLLER_H_ |
6 #define MEDIA_FILTERS_PIPELINE_CONTROLLER_H_ | 6 #define MEDIA_FILTERS_PIPELINE_CONTROLLER_H_ |
7 | 7 |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
11 #include "base/threading/thread_checker.h" | 11 #include "base/threading/thread_checker.h" |
12 #include "base/time/time.h" | 12 #include "base/time/time.h" |
13 #include "media/base/media_export.h" | 13 #include "media/base/media_export.h" |
14 #include "media/base/pipeline.h" | 14 #include "media/base/pipeline.h" |
15 #include "media/base/renderer.h" | 15 #include "media/base/renderer.h" |
16 | 16 |
17 namespace media { | 17 namespace media { |
18 | |
19 class Demuxer; | 18 class Demuxer; |
20 | 19 |
21 // PipelineController wraps a Pipeline to expose the one-at-a-time operations | 20 // PipelineController wraps a Pipeline to expose the one-at-a-time operations |
22 // (Seek(), Suspend(), and Resume()) with a simpler API. Internally it tracks | 21 // (Seek(), Suspend(), and Resume()) with a simpler API. Internally it tracks |
23 // pending operations and dispatches them when possible. Duplicate requests | 22 // pending operations and dispatches them when possible. Duplicate requests |
24 // (such as seeking twice to the same time) may be elided. | 23 // (such as seeking twice to the same time) may be elided. |
25 // | 24 // |
26 // TODO(sandersd): | 25 // TODO(sandersd/tguilbert): |
27 // - Expose an operation that restarts via suspend+resume. | 26 // - Expose an operation that cycles via suspend+resume. |
sandersd (OOO until July 31)
2017/02/23 23:11:46
Nit: Reword these as:
- Expose an operation that
tguilbert
2017/02/24 02:13:59
Done.
| |
28 // - Block invalid calls after an error occurs. | 27 // - Block invalid calls after an error occurs. |
28 // - Support restarting with a new demuxer. | |
29 class MEDIA_EXPORT PipelineController { | 29 class MEDIA_EXPORT PipelineController { |
30 public: | 30 public: |
31 enum class State { | 31 enum class State { |
32 CREATED, | 32 CREATED, |
33 STARTING, | 33 STARTING, |
34 PLAYING, | 34 PLAYING, |
35 SEEKING, | 35 SEEKING, |
36 SUSPENDING, | 36 SUSPENDING, |
37 SUSPENDED, | 37 SUSPENDED, |
38 RESUMING, | 38 RESUMING, |
39 }; | 39 }; |
40 | 40 |
41 using RendererFactoryCB = base::Callback<std::unique_ptr<Renderer>(void)>; | 41 using RendererFactoryCB = base::Callback<std::unique_ptr<Renderer>(void)>; |
42 using SeekedCB = base::Callback<void(bool time_updated)>; | 42 using SeekedCB = base::Callback<void(bool time_updated)>; |
43 using SuspendedCB = base::Callback<void()>; | 43 using SuspendedCB = base::Callback<void()>; |
44 using BeforeResumeCB = base::Callback<void()>; | 44 using BeforeResumeCB = base::Callback<void()>; |
45 using ResumedCB = base::Callback<void()>; | 45 using ResumedCB = base::Callback<void()>; |
46 | 46 |
47 // Construct a PipelineController wrapping |pipeline_|. |pipeline_| must | 47 // Construct a PipelineController wrapping |pipeline_|. |
48 // outlive the resulting PipelineController. The callbacks are: | 48 // The callbacks are: |
49 // - |renderer_factory_cb| is called by PipelineController to create new | 49 // - |renderer_factory_cb| is called by PipelineController to create new |
50 // renderers when starting and resuming. | 50 // renderers when starting and resuming. |
51 // - |seeked_cb| is called upon reaching a stable state if a seek occured. | 51 // - |seeked_cb| is called upon reaching a stable state if a seek occured. |
52 // - |suspended_cb| is called immediately after suspending. | 52 // - |suspended_cb| is called immediately after suspending. |
53 // - |before_resume_cb| is called immediately before resuming. | 53 // - |before_resume_cb| is called immediately before resuming. |
54 // - |resumed_cb| is called immediately after resuming. | 54 // - |resumed_cb| is called immediately after resuming. |
55 // - |error_cb| is called if any operation on |pipeline_| does not result | 55 // - |error_cb| is called if any operation on |pipeline_| does not result |
56 // in PIPELINE_OK or its error callback is called. | 56 // in PIPELINE_OK or its error callback is called. |
57 PipelineController(Pipeline* pipeline, | 57 PipelineController(std::unique_ptr<Pipeline> pipeline, |
58 const RendererFactoryCB& renderer_factory_cb, | 58 const RendererFactoryCB& renderer_factory_cb, |
59 const SeekedCB& seeked_cb, | 59 const SeekedCB& seeked_cb, |
60 const SuspendedCB& suspended_cb, | 60 const SuspendedCB& suspended_cb, |
61 const BeforeResumeCB& before_resume_cb, | 61 const BeforeResumeCB& before_resume_cb, |
62 const ResumedCB& resumed_cb, | 62 const ResumedCB& resumed_cb, |
63 const PipelineStatusCB& error_cb); | 63 const PipelineStatusCB& error_cb); |
64 ~PipelineController(); | 64 ~PipelineController(); |
65 | 65 |
66 // Start |pipeline_|. |demuxer| will be retained and StartWaitingForSeek()/ | 66 // Start |pipeline_|. |demuxer| will be retained and StartWaitingForSeek()/ |
67 // CancelPendingSeek() will be issued to it as necessary. | 67 // CancelPendingSeek() will be issued to it as necessary. |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
101 // - Start() is processed immediately while in the CREATED state. | 101 // - Start() is processed immediately while in the CREATED state. |
102 // - Resume() is processed immediately while in the SUSPENDED state. | 102 // - Resume() is processed immediately while in the SUSPENDED state. |
103 bool IsStable(); | 103 bool IsStable(); |
104 | 104 |
105 // Returns true if the current target state is suspended. | 105 // Returns true if the current target state is suspended. |
106 bool IsSuspended(); | 106 bool IsSuspended(); |
107 | 107 |
108 // Returns true if |pipeline_| is suspended. | 108 // Returns true if |pipeline_| is suspended. |
109 bool IsPipelineSuspended(); | 109 bool IsPipelineSuspended(); |
110 | 110 |
111 // Subset of the Pipeline interface directly exposing |pipeline_|. | |
112 void Stop(); | |
113 bool IsPipelineRunning() const; | |
114 double GetPlaybackRate() const; | |
115 void SetPlaybackRate(double playback_rate); | |
116 float GetVolume() const; | |
117 void SetVolume(float volume); | |
118 base::TimeDelta GetMediaTime() const; | |
119 Ranges<base::TimeDelta> GetBufferedTimeRanges() const; | |
120 base::TimeDelta GetMediaDuration() const; | |
121 bool DidLoadingProgress(); | |
122 PipelineStatistics GetStatistics() const; | |
123 void SetCdm(CdmContext* cdm_context, const CdmAttachedCB& cdm_attached_cb); | |
124 void OnEnabledAudioTracksChanged( | |
125 const std::vector<MediaTrack::Id>& enabledTrackIds); | |
126 void OnSelectedVideoTrackChanged( | |
127 const std::vector<MediaTrack::Id>& selectedTrackId); | |
128 | |
111 private: | 129 private: |
112 // Attempts to make progress from the current state to the target state. | 130 // Attempts to make progress from the current state to the target state. |
113 void Dispatch(); | 131 void Dispatch(); |
114 | 132 |
115 // PipelineStaus callback that also carries the target state. | 133 // PipelineStaus callback that also carries the target state. |
116 void OnPipelineStatus(State state, PipelineStatus pipeline_status); | 134 void OnPipelineStatus(State state, PipelineStatus pipeline_status); |
117 | 135 |
118 // The Pipeline we are managing state for. | 136 // The Pipeline we are managing state for. |
119 Pipeline* pipeline_ = nullptr; | 137 std::unique_ptr<Pipeline> pipeline_; |
120 | 138 |
121 // Factory for Renderers, used for Start() and Resume(). | 139 // Factory for Renderers, used for Start() and Resume(). |
122 RendererFactoryCB renderer_factory_cb_; | 140 RendererFactoryCB renderer_factory_cb_; |
123 | 141 |
124 // Called after seeks (which includes Start()) upon reaching a stable state. | 142 // Called after seeks (which includes Start()) upon reaching a stable state. |
125 // Multiple seeks result in only one callback if no stable state occurs | 143 // Multiple seeks result in only one callback if no stable state occurs |
126 // between them. | 144 // between them. |
127 SeekedCB seeked_cb_; | 145 SeekedCB seeked_cb_; |
128 | 146 |
129 // Called immediately when |pipeline_| completes a suspend operation. | 147 // Called immediately when |pipeline_| completes a suspend operation. |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
172 | 190 |
173 base::ThreadChecker thread_checker_; | 191 base::ThreadChecker thread_checker_; |
174 base::WeakPtrFactory<PipelineController> weak_factory_; | 192 base::WeakPtrFactory<PipelineController> weak_factory_; |
175 | 193 |
176 DISALLOW_COPY_AND_ASSIGN(PipelineController); | 194 DISALLOW_COPY_AND_ASSIGN(PipelineController); |
177 }; | 195 }; |
178 | 196 |
179 } // namespace media | 197 } // namespace media |
180 | 198 |
181 #endif // MEDIA_FILTERS_PIPELINE_CONTROLLER_H_ | 199 #endif // MEDIA_FILTERS_PIPELINE_CONTROLLER_H_ |
OLD | NEW |