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

Side by Side Diff: media/filters/pipeline_controller.h

Issue 2689863002: Change ownership of PipelineImpl (Closed)
Patch Set: Proper rebase Created 3 years, 9 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
« no previous file with comments | « media/blink/webmediaplayer_impl.cc ('k') | media/filters/pipeline_controller.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 replaces the Renderer (via Suspend/Resume).
27 // - Expose an operation that replaces the Demuxer (via Start/Stop). This will
28 // also implicitly replace the Renderer.
28 // - Block invalid calls after an error occurs. 29 // - Block invalid calls after an error occurs.
29 class MEDIA_EXPORT PipelineController { 30 class MEDIA_EXPORT PipelineController {
30 public: 31 public:
31 enum class State { 32 enum class State {
32 CREATED, 33 CREATED,
33 STARTING, 34 STARTING,
34 PLAYING, 35 PLAYING,
35 SEEKING, 36 SEEKING,
36 SUSPENDING, 37 SUSPENDING,
37 SUSPENDED, 38 SUSPENDED,
38 RESUMING, 39 RESUMING,
39 }; 40 };
40 41
41 using RendererFactoryCB = base::Callback<std::unique_ptr<Renderer>(void)>; 42 using RendererFactoryCB = base::Callback<std::unique_ptr<Renderer>(void)>;
42 using SeekedCB = base::Callback<void(bool time_updated)>; 43 using SeekedCB = base::Callback<void(bool time_updated)>;
43 using SuspendedCB = base::Callback<void()>; 44 using SuspendedCB = base::Callback<void()>;
44 using BeforeResumeCB = base::Callback<void()>; 45 using BeforeResumeCB = base::Callback<void()>;
45 using ResumedCB = base::Callback<void()>; 46 using ResumedCB = base::Callback<void()>;
46 47
47 // Construct a PipelineController wrapping |pipeline_|. |pipeline_| must 48 // Construct a PipelineController wrapping |pipeline_|.
48 // outlive the resulting PipelineController. The callbacks are: 49 // The callbacks are:
49 // - |renderer_factory_cb| is called by PipelineController to create new 50 // - |renderer_factory_cb| is called by PipelineController to create new
50 // renderers when starting and resuming. 51 // renderers when starting and resuming.
51 // - |seeked_cb| is called upon reaching a stable state if a seek occured. 52 // - |seeked_cb| is called upon reaching a stable state if a seek occured.
52 // - |suspended_cb| is called immediately after suspending. 53 // - |suspended_cb| is called immediately after suspending.
53 // - |before_resume_cb| is called immediately before resuming. 54 // - |before_resume_cb| is called immediately before resuming.
54 // - |resumed_cb| is called immediately after resuming. 55 // - |resumed_cb| is called immediately after resuming.
55 // - |error_cb| is called if any operation on |pipeline_| does not result 56 // - |error_cb| is called if any operation on |pipeline_| does not result
56 // in PIPELINE_OK or its error callback is called. 57 // in PIPELINE_OK or its error callback is called.
57 PipelineController(Pipeline* pipeline, 58 PipelineController(std::unique_ptr<Pipeline> pipeline,
58 const RendererFactoryCB& renderer_factory_cb, 59 const RendererFactoryCB& renderer_factory_cb,
59 const SeekedCB& seeked_cb, 60 const SeekedCB& seeked_cb,
60 const SuspendedCB& suspended_cb, 61 const SuspendedCB& suspended_cb,
61 const BeforeResumeCB& before_resume_cb, 62 const BeforeResumeCB& before_resume_cb,
62 const ResumedCB& resumed_cb, 63 const ResumedCB& resumed_cb,
63 const PipelineStatusCB& error_cb); 64 const PipelineStatusCB& error_cb);
64 ~PipelineController(); 65 ~PipelineController();
65 66
66 // Start |pipeline_|. |demuxer| will be retained and StartWaitingForSeek()/ 67 // Start |pipeline_|. |demuxer| will be retained and StartWaitingForSeek()/
67 // CancelPendingSeek() will be issued to it as necessary. 68 // CancelPendingSeek() will be issued to it as necessary.
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 // - Start() is processed immediately while in the CREATED state. 102 // - Start() is processed immediately while in the CREATED state.
102 // - Resume() is processed immediately while in the SUSPENDED state. 103 // - Resume() is processed immediately while in the SUSPENDED state.
103 bool IsStable(); 104 bool IsStable();
104 105
105 // Returns true if the current target state is suspended. 106 // Returns true if the current target state is suspended.
106 bool IsSuspended(); 107 bool IsSuspended();
107 108
108 // Returns true if |pipeline_| is suspended. 109 // Returns true if |pipeline_| is suspended.
109 bool IsPipelineSuspended(); 110 bool IsPipelineSuspended();
110 111
112 // Subset of the Pipeline interface directly exposing |pipeline_|.
113 void Stop();
114 bool IsPipelineRunning() const;
115 double GetPlaybackRate() const;
116 void SetPlaybackRate(double playback_rate);
117 float GetVolume() const;
118 void SetVolume(float volume);
119 base::TimeDelta GetMediaTime() const;
120 Ranges<base::TimeDelta> GetBufferedTimeRanges() const;
121 base::TimeDelta GetMediaDuration() const;
122 bool DidLoadingProgress();
123 PipelineStatistics GetStatistics() const;
124 void SetCdm(CdmContext* cdm_context, const CdmAttachedCB& cdm_attached_cb);
125 void OnEnabledAudioTracksChanged(
126 const std::vector<MediaTrack::Id>& enabledTrackIds);
127 void OnSelectedVideoTrackChanged(
128 base::Optional<MediaTrack::Id> selected_track_id);
129
111 private: 130 private:
112 // Attempts to make progress from the current state to the target state. 131 // Attempts to make progress from the current state to the target state.
113 void Dispatch(); 132 void Dispatch();
114 133
115 // PipelineStaus callback that also carries the target state. 134 // PipelineStaus callback that also carries the target state.
116 void OnPipelineStatus(State state, PipelineStatus pipeline_status); 135 void OnPipelineStatus(State state, PipelineStatus pipeline_status);
117 136
118 // The Pipeline we are managing state for. 137 // The Pipeline we are managing state for.
119 Pipeline* pipeline_ = nullptr; 138 std::unique_ptr<Pipeline> pipeline_;
120 139
121 // Factory for Renderers, used for Start() and Resume(). 140 // Factory for Renderers, used for Start() and Resume().
122 RendererFactoryCB renderer_factory_cb_; 141 RendererFactoryCB renderer_factory_cb_;
123 142
124 // Called after seeks (which includes Start()) upon reaching a stable state. 143 // Called after seeks (which includes Start()) upon reaching a stable state.
125 // Multiple seeks result in only one callback if no stable state occurs 144 // Multiple seeks result in only one callback if no stable state occurs
126 // between them. 145 // between them.
127 SeekedCB seeked_cb_; 146 SeekedCB seeked_cb_;
128 147
129 // Called immediately when |pipeline_| completes a suspend operation. 148 // Called immediately when |pipeline_| completes a suspend operation.
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 191
173 base::ThreadChecker thread_checker_; 192 base::ThreadChecker thread_checker_;
174 base::WeakPtrFactory<PipelineController> weak_factory_; 193 base::WeakPtrFactory<PipelineController> weak_factory_;
175 194
176 DISALLOW_COPY_AND_ASSIGN(PipelineController); 195 DISALLOW_COPY_AND_ASSIGN(PipelineController);
177 }; 196 };
178 197
179 } // namespace media 198 } // namespace media
180 199
181 #endif // MEDIA_FILTERS_PIPELINE_CONTROLLER_H_ 200 #endif // MEDIA_FILTERS_PIPELINE_CONTROLLER_H_
OLDNEW
« no previous file with comments | « media/blink/webmediaplayer_impl.cc ('k') | media/filters/pipeline_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698