OLD | NEW |
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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_BASE_PIPELINE_IMPL_H_ | 5 #ifndef MEDIA_BASE_PIPELINE_IMPL_H_ |
6 #define MEDIA_BASE_PIPELINE_IMPL_H_ | 6 #define MEDIA_BASE_PIPELINE_IMPL_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 | 9 |
10 #include "base/gtest_prod_util.h" | 10 #include "base/gtest_prod_util.h" |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 // If any error ever happens, this object will transition to the "Error" state | 70 // If any error ever happens, this object will transition to the "Error" state |
71 // from any state. If Stop() is ever called, this object will transition to | 71 // from any state. If Stop() is ever called, this object will transition to |
72 // "Stopped" state. | 72 // "Stopped" state. |
73 // | 73 // |
74 // TODO(sandersd): It should be possible to pass through Suspended when going | 74 // TODO(sandersd): It should be possible to pass through Suspended when going |
75 // from InitDemuxer to InitRenderer, thereby eliminating the Resuming state. | 75 // from InitDemuxer to InitRenderer, thereby eliminating the Resuming state. |
76 // Some annoying differences between the two paths need to be removed first. | 76 // Some annoying differences between the two paths need to be removed first. |
77 class MEDIA_EXPORT PipelineImpl : public Pipeline, public DemuxerHost { | 77 class MEDIA_EXPORT PipelineImpl : public Pipeline, public DemuxerHost { |
78 public: | 78 public: |
79 // Constructs a media pipeline that will execute on |task_runner|. | 79 // Constructs a media pipeline that will execute on |task_runner|. |
80 PipelineImpl(const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, | 80 PipelineImpl( |
81 MediaLog* media_log); | 81 const scoped_refptr<base::SingleThreadTaskRunner>& media_task_runner, |
| 82 MediaLog* media_log); |
82 ~PipelineImpl() override; | 83 ~PipelineImpl() override; |
83 | 84 |
84 void SetErrorForTesting(PipelineStatus status); | 85 void SetErrorForTesting(PipelineStatus status); |
85 bool HasWeakPtrsForTesting() const; | 86 bool HasWeakPtrsForTesting() const; |
86 | 87 |
87 // Pipeline implementation. | 88 // Pipeline implementation. |
88 void Start(Demuxer* demuxer, | 89 void Start(Demuxer* demuxer, |
89 std::unique_ptr<Renderer> renderer, | 90 std::unique_ptr<Renderer> renderer, |
90 const base::Closure& ended_cb, | 91 Client* client, |
91 const PipelineStatusCB& error_cb, | 92 const PipelineStatusCB& seek_cb) override; |
92 const PipelineStatusCB& seek_cb, | |
93 const PipelineMetadataCB& metadata_cb, | |
94 const BufferingStateCB& buffering_state_cb, | |
95 const base::Closure& duration_change_cb, | |
96 const AddTextTrackCB& add_text_track_cb, | |
97 const base::Closure& waiting_for_decryption_key_cb) override; | |
98 void Stop(const base::Closure& stop_cb) override; | 93 void Stop(const base::Closure& stop_cb) override; |
99 void Seek(base::TimeDelta time, const PipelineStatusCB& seek_cb) override; | 94 void Seek(base::TimeDelta time, const PipelineStatusCB& seek_cb) override; |
100 bool IsRunning() const override; | 95 bool IsRunning() const override; |
101 double GetPlaybackRate() const override; | 96 double GetPlaybackRate() const override; |
102 void SetPlaybackRate(double playback_rate) override; | 97 void SetPlaybackRate(double playback_rate) override; |
103 void Suspend(const PipelineStatusCB& suspend_cb) override; | 98 void Suspend(const PipelineStatusCB& suspend_cb) override; |
104 void Resume(std::unique_ptr<Renderer> renderer, | 99 void Resume(std::unique_ptr<Renderer> renderer, |
105 base::TimeDelta timestamp, | 100 base::TimeDelta timestamp, |
106 const PipelineStatusCB& seek_cb) override; | 101 const PipelineStatusCB& seek_cb) override; |
107 float GetVolume() const override; | 102 float GetVolume() const override; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 const TextTrackConfig& config) override; | 146 const TextTrackConfig& config) override; |
152 void RemoveTextStream(DemuxerStream* text_stream) override; | 147 void RemoveTextStream(DemuxerStream* text_stream) override; |
153 | 148 |
154 // Callback executed when a rendering error happened, initiating the teardown | 149 // Callback executed when a rendering error happened, initiating the teardown |
155 // sequence. | 150 // sequence. |
156 void OnError(PipelineStatus error); | 151 void OnError(PipelineStatus error); |
157 | 152 |
158 // Callback executed by filters to update statistics. | 153 // Callback executed by filters to update statistics. |
159 void OnUpdateStatistics(const PipelineStatistics& stats_delta); | 154 void OnUpdateStatistics(const PipelineStatistics& stats_delta); |
160 | 155 |
| 156 // Callback executed by renderer when waiting for decryption key. |
| 157 void OnWaitingForDecryptionKey(); |
| 158 |
161 // The following "task" methods correspond to the public methods, but these | 159 // The following "task" methods correspond to the public methods, but these |
162 // methods are run as the result of posting a task to the Pipeline's | 160 // methods are run as the result of posting a task to the Pipeline's |
163 // task runner. | 161 // task runner. |
164 void StartTask(); | 162 void StartTask(); |
165 | 163 |
166 // Suspends the pipeline, discarding the current renderer. | 164 // Suspends the pipeline, discarding the current renderer. |
167 void SuspendTask(const PipelineStatusCB& suspend_cb); | 165 void SuspendTask(const PipelineStatusCB& suspend_cb); |
168 | 166 |
169 // Resumes the pipeline with a new renderer, and initializes it with a seek. | 167 // Resumes the pipeline with a new renderer, and initializes it with a seek. |
170 void ResumeTask(std::unique_ptr<Renderer> renderer, | 168 void ResumeTask(std::unique_ptr<Renderer> renderer, |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 | 226 |
229 // Initiates an asynchronous pause-flush-stop call sequence executing | 227 // Initiates an asynchronous pause-flush-stop call sequence executing |
230 // |done_cb| when completed. | 228 // |done_cb| when completed. |
231 void DoStop(const PipelineStatusCB& done_cb); | 229 void DoStop(const PipelineStatusCB& done_cb); |
232 void OnStopCompleted(PipelineStatus status); | 230 void OnStopCompleted(PipelineStatus status); |
233 | 231 |
234 void ReportMetadata(); | 232 void ReportMetadata(); |
235 | 233 |
236 void BufferingStateChanged(BufferingState new_buffering_state); | 234 void BufferingStateChanged(BufferingState new_buffering_state); |
237 | 235 |
| 236 // Task runner of the thread on which this class is constructed. |
| 237 // Also used to post notifications on Pipeline::Client object. |
| 238 const scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; |
238 // Task runner used to execute pipeline tasks. | 239 // Task runner used to execute pipeline tasks. |
239 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 240 const scoped_refptr<base::SingleThreadTaskRunner> media_task_runner_; |
240 | 241 |
241 // MediaLog to which to log events. | 242 // MediaLog to which to log events. |
242 scoped_refptr<MediaLog> media_log_; | 243 scoped_refptr<MediaLog> media_log_; |
243 | 244 |
244 // Lock used to serialize access for the following data members. | 245 // Lock used to serialize access for the following data members. |
245 mutable base::Lock lock_; | 246 mutable base::Lock lock_; |
246 | 247 |
247 // Whether or not the pipeline is running. | 248 // Whether or not the pipeline is running. |
248 bool running_; | 249 bool running_; |
249 | 250 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 | 294 |
294 // Temporary callback used for Start(), Seek(), and Resume(). | 295 // Temporary callback used for Start(), Seek(), and Resume(). |
295 PipelineStatusCB seek_cb_; | 296 PipelineStatusCB seek_cb_; |
296 | 297 |
297 // Temporary callback used for Stop(). | 298 // Temporary callback used for Stop(). |
298 base::Closure stop_cb_; | 299 base::Closure stop_cb_; |
299 | 300 |
300 // Temporary callback used for Suspend(). | 301 // Temporary callback used for Suspend(). |
301 PipelineStatusCB suspend_cb_; | 302 PipelineStatusCB suspend_cb_; |
302 | 303 |
303 // Permanent callbacks passed in via Start(). | |
304 base::Closure ended_cb_; | |
305 PipelineStatusCB error_cb_; | |
306 PipelineMetadataCB metadata_cb_; | |
307 BufferingStateCB buffering_state_cb_; | |
308 base::Closure duration_change_cb_; | |
309 AddTextTrackCB add_text_track_cb_; | |
310 base::Closure waiting_for_decryption_key_cb_; | |
311 | |
312 // Holds the initialized demuxer. Used for seeking. Owned by client. | 304 // Holds the initialized demuxer. Used for seeking. Owned by client. |
313 Demuxer* demuxer_; | 305 Demuxer* demuxer_; |
314 | 306 |
315 // Holds the initialized renderers. Used for setting the volume, | 307 // Holds the initialized renderers. Used for setting the volume, |
316 // playback rate, and determining when playback has finished. | 308 // playback rate, and determining when playback has finished. |
317 std::unique_ptr<Renderer> renderer_; | 309 std::unique_ptr<Renderer> renderer_; |
318 std::unique_ptr<TextRenderer> text_renderer_; | 310 std::unique_ptr<TextRenderer> text_renderer_; |
319 | 311 |
| 312 // Holds the client passed on Start(). |
| 313 Client* client_; |
| 314 |
320 PipelineStatistics statistics_; | 315 PipelineStatistics statistics_; |
321 | 316 |
322 std::unique_ptr<SerialRunner> pending_callbacks_; | 317 std::unique_ptr<SerialRunner> pending_callbacks_; |
323 | 318 |
324 // The CdmContext to be used to decrypt (and decode) encrypted stream in this | 319 // The CdmContext to be used to decrypt (and decode) encrypted stream in this |
325 // pipeline. It is set when SetCdm() succeeds on the renderer (or when | 320 // pipeline. It is set when SetCdm() succeeds on the renderer (or when |
326 // SetCdm() is called before Start()), after which it is guaranteed to outlive | 321 // SetCdm() is called before Start()), after which it is guaranteed to outlive |
327 // this pipeline. The saved value will be used to configure new renderers, | 322 // this pipeline. The saved value will be used to configure new renderers, |
328 // when starting or resuming. | 323 // when starting or resuming. |
329 CdmContext* cdm_context_; | 324 CdmContext* cdm_context_; |
330 | 325 |
331 base::ThreadChecker thread_checker_; | 326 base::ThreadChecker thread_checker_; |
332 | 327 |
333 // A weak pointer that can be safely copied on the media thread. | 328 // A weak pointer that can be safely copied on the media thread. |
334 base::WeakPtr<PipelineImpl> weak_this_; | 329 base::WeakPtr<PipelineImpl> weak_this_; |
335 | 330 |
336 // Weak pointers must be created on the main thread, and must be dereferenced | 331 // Weak pointers must be created on the main thread, and must be dereferenced |
337 // on the media thread. | 332 // on the media thread. |
338 // | 333 // |
339 // Declared last so that weak pointers will be invalidated before all other | 334 // Declared last so that weak pointers will be invalidated before all other |
340 // member variables. | 335 // member variables. |
341 base::WeakPtrFactory<PipelineImpl> weak_factory_; | 336 base::WeakPtrFactory<PipelineImpl> weak_factory_; |
342 | 337 |
343 DISALLOW_COPY_AND_ASSIGN(PipelineImpl); | 338 DISALLOW_COPY_AND_ASSIGN(PipelineImpl); |
344 }; | 339 }; |
345 | 340 |
346 } // namespace media | 341 } // namespace media |
347 | 342 |
348 #endif // MEDIA_BASE_PIPELINE_IMPL_H_ | 343 #endif // MEDIA_BASE_PIPELINE_IMPL_H_ |
OLD | NEW |