OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_H_ | 5 #ifndef MEDIA_BASE_PIPELINE_H_ |
6 #define MEDIA_BASE_PIPELINE_H_ | 6 #define MEDIA_BASE_PIPELINE_H_ |
7 | 7 |
8 #include "base/gtest_prod_util.h" | 8 #include "base/gtest_prod_util.h" |
9 #include "base/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
10 #include "base/synchronization/lock.h" | 10 #include "base/synchronization/lock.h" |
11 #include "base/threading/thread_checker.h" | 11 #include "base/threading/thread_checker.h" |
12 #include "base/time/default_tick_clock.h" | 12 #include "base/time/default_tick_clock.h" |
13 #include "media/base/buffering_state.h" | 13 #include "media/base/buffering_state.h" |
14 #include "media/base/demuxer.h" | 14 #include "media/base/demuxer.h" |
15 #include "media/base/media_export.h" | 15 #include "media/base/media_export.h" |
16 #include "media/base/pipeline_status.h" | 16 #include "media/base/pipeline_status.h" |
17 #include "media/base/ranges.h" | 17 #include "media/base/ranges.h" |
18 #include "media/base/serial_runner.h" | 18 #include "media/base/serial_runner.h" |
| 19 #include "media/base/text_track.h" |
19 #include "media/base/video_rotation.h" | 20 #include "media/base/video_rotation.h" |
20 #include "ui/gfx/size.h" | 21 #include "ui/gfx/size.h" |
21 | 22 |
22 namespace base { | 23 namespace base { |
23 class SingleThreadTaskRunner; | 24 class SingleThreadTaskRunner; |
24 class TimeDelta; | 25 class TimeDelta; |
25 } | 26 } |
26 | 27 |
27 namespace media { | 28 namespace media { |
28 | 29 |
29 class FilterCollection; | |
30 class MediaLog; | 30 class MediaLog; |
31 class Renderer; | 31 class Renderer; |
32 class TextRenderer; | 32 class TextRenderer; |
33 class TextTrackConfig; | 33 class TextTrackConfig; |
34 class TimeDeltaInterpolator; | 34 class TimeDeltaInterpolator; |
35 | 35 |
36 // Metadata describing a pipeline once it has been initialized. | 36 // Metadata describing a pipeline once it has been initialized. |
37 struct PipelineMetadata { | 37 struct PipelineMetadata { |
38 PipelineMetadata() | 38 PipelineMetadata() |
39 : has_audio(false), has_video(false), video_rotation(VIDEO_ROTATION_0) {} | 39 : has_audio(false), has_video(false), video_rotation(VIDEO_ROTATION_0) {} |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 // If any error ever happens, this object will transition to the "Error" state | 74 // If any error ever happens, this object will transition to the "Error" state |
75 // from any state. If Stop() is ever called, this object will transition to | 75 // from any state. If Stop() is ever called, this object will transition to |
76 // "Stopped" state. | 76 // "Stopped" state. |
77 class MEDIA_EXPORT Pipeline : public DemuxerHost { | 77 class MEDIA_EXPORT 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 Pipeline(const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, | 80 Pipeline(const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, |
81 MediaLog* media_log); | 81 MediaLog* media_log); |
82 virtual ~Pipeline(); | 82 virtual ~Pipeline(); |
83 | 83 |
84 // Build a pipeline to using the given filter collection to construct a filter | 84 // Build a pipeline to using the given |demuxer| and |renderer| to construct |
85 // chain, executing |seek_cb| when the initial seek has completed. | 85 // a filter chain, executing |seek_cb| when the initial seek has completed. |
86 // | |
87 // |filter_collection| must be a complete collection containing a demuxer, | |
88 // audio/video decoders, and audio/video renderers. Failing to do so will | |
89 // result in a crash. | |
90 // | 86 // |
91 // The following permanent callbacks will be executed as follows up until | 87 // The following permanent callbacks will be executed as follows up until |
92 // Stop() has completed: | 88 // Stop() has completed: |
93 // |ended_cb| will be executed whenever the media reaches the end. | 89 // |ended_cb| will be executed whenever the media reaches the end. |
94 // |error_cb| will be executed whenever an error occurs but hasn't been | 90 // |error_cb| will be executed whenever an error occurs but hasn't been |
95 // reported already through another callback. | 91 // reported already through another callback. |
96 // |metadata_cb| will be executed when the content duration, container video | 92 // |metadata_cb| will be executed when the content duration, container video |
97 // size, start time, and whether the content has audio and/or | 93 // size, start time, and whether the content has audio and/or |
98 // video in supported formats are known. | 94 // video in supported formats are known. |
99 // |buffering_state_cb| will be executed whenever there are changes in the | 95 // |buffering_state_cb| will be executed whenever there are changes in the |
100 // overall buffering state of the pipeline. | 96 // overall buffering state of the pipeline. |
101 // |duration_change_cb| optional callback that will be executed whenever the | 97 // |duration_change_cb| optional callback that will be executed whenever the |
102 // presentation duration changes. | 98 // presentation duration changes. |
| 99 // |add_text_track_cb| will be executed whenever a text track is added. |
103 // It is an error to call this method after the pipeline has already started. | 100 // It is an error to call this method after the pipeline has already started. |
104 void Start(scoped_ptr<FilterCollection> filter_collection, | 101 void Start(Demuxer* demuxer, |
| 102 scoped_ptr<Renderer> renderer, |
105 const base::Closure& ended_cb, | 103 const base::Closure& ended_cb, |
106 const PipelineStatusCB& error_cb, | 104 const PipelineStatusCB& error_cb, |
107 const PipelineStatusCB& seek_cb, | 105 const PipelineStatusCB& seek_cb, |
108 const PipelineMetadataCB& metadata_cb, | 106 const PipelineMetadataCB& metadata_cb, |
109 const BufferingStateCB& buffering_state_cb, | 107 const BufferingStateCB& buffering_state_cb, |
110 const base::Closure& duration_change_cb); | 108 const base::Closure& duration_change_cb, |
| 109 const AddTextTrackCB& add_text_track_cb); |
111 | 110 |
112 // Asynchronously stops the pipeline, executing |stop_cb| when the pipeline | 111 // Asynchronously stops the pipeline, executing |stop_cb| when the pipeline |
113 // teardown has completed. | 112 // teardown has completed. |
114 // | 113 // |
115 // Stop() must complete before destroying the pipeline. It it permissible to | 114 // Stop() must complete before destroying the pipeline. It it permissible to |
116 // call Stop() at any point during the lifetime of the pipeline. | 115 // call Stop() at any point during the lifetime of the pipeline. |
117 // | 116 // |
118 // It is safe to delete the pipeline during the execution of |stop_cb|. | 117 // It is safe to delete the pipeline during the execution of |stop_cb|. |
119 void Stop(const base::Closure& stop_cb); | 118 void Stop(const base::Closure& stop_cb); |
120 | 119 |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 void VolumeChangedTask(float volume); | 237 void VolumeChangedTask(float volume); |
239 | 238 |
240 // Carries out notifying filters that we are seeking to a new timestamp. | 239 // Carries out notifying filters that we are seeking to a new timestamp. |
241 void SeekTask(base::TimeDelta time, const PipelineStatusCB& seek_cb); | 240 void SeekTask(base::TimeDelta time, const PipelineStatusCB& seek_cb); |
242 | 241 |
243 // Callbacks executed when a renderer has ended. | 242 // Callbacks executed when a renderer has ended. |
244 void OnRendererEnded(); | 243 void OnRendererEnded(); |
245 void OnTextRendererEnded(); | 244 void OnTextRendererEnded(); |
246 void RunEndedCallbackIfNeeded(); | 245 void RunEndedCallbackIfNeeded(); |
247 | 246 |
| 247 scoped_ptr<TextRenderer> CreateTextRenderer(); |
| 248 |
248 // Carries out adding a new text stream to the text renderer. | 249 // Carries out adding a new text stream to the text renderer. |
249 void AddTextStreamTask(DemuxerStream* text_stream, | 250 void AddTextStreamTask(DemuxerStream* text_stream, |
250 const TextTrackConfig& config); | 251 const TextTrackConfig& config); |
251 | 252 |
252 // Carries out removing a text stream from the text renderer. | 253 // Carries out removing a text stream from the text renderer. |
253 void RemoveTextStreamTask(DemuxerStream* text_stream); | 254 void RemoveTextStreamTask(DemuxerStream* text_stream); |
254 | 255 |
| 256 // Callbacks executed when a text track is added. |
| 257 void OnAddTextTrack(const TextTrackConfig& config, |
| 258 const AddTextTrackDoneCB& done_cb); |
| 259 |
255 // Kicks off initialization for each media object, executing |done_cb| with | 260 // Kicks off initialization for each media object, executing |done_cb| with |
256 // the result when completed. | 261 // the result when completed. |
257 void InitializeDemuxer(const PipelineStatusCB& done_cb); | 262 void InitializeDemuxer(const PipelineStatusCB& done_cb); |
258 void InitializeRenderer(const PipelineStatusCB& done_cb); | 263 void InitializeRenderer(const PipelineStatusCB& done_cb); |
259 | 264 |
260 void OnStateTransition(PipelineStatus status); | 265 void OnStateTransition(PipelineStatus status); |
261 void StateTransitionTask(PipelineStatus status); | 266 void StateTransitionTask(PipelineStatus status); |
262 | 267 |
263 // Initiates an asynchronous pause-flush-seek-preroll call sequence | 268 // Initiates an asynchronous pause-flush-seek-preroll call sequence |
264 // executing |done_cb| with the final status when completed. | 269 // executing |done_cb| with the final status when completed. |
265 void DoSeek(base::TimeDelta seek_timestamp, const PipelineStatusCB& done_cb); | 270 void DoSeek(base::TimeDelta seek_timestamp, const PipelineStatusCB& done_cb); |
266 | 271 |
267 // Initiates an asynchronous pause-flush-stop call sequence executing | 272 // Initiates an asynchronous pause-flush-stop call sequence executing |
268 // |done_cb| when completed. | 273 // |done_cb| when completed. |
269 void DoStop(const PipelineStatusCB& done_cb); | 274 void DoStop(const PipelineStatusCB& done_cb); |
270 void OnStopCompleted(PipelineStatus status); | 275 void OnStopCompleted(PipelineStatus status); |
271 | 276 |
| 277 void ReportMetadata(); |
| 278 |
272 void BufferingStateChanged(BufferingState new_buffering_state); | 279 void BufferingStateChanged(BufferingState new_buffering_state); |
273 | 280 |
274 // Task runner used to execute pipeline tasks. | 281 // Task runner used to execute pipeline tasks. |
275 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 282 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
276 | 283 |
277 // MediaLog to which to log events. | 284 // MediaLog to which to log events. |
278 scoped_refptr<MediaLog> media_log_; | 285 scoped_refptr<MediaLog> media_log_; |
279 | 286 |
280 // Lock used to serialize access for the following data members. | 287 // Lock used to serialize access for the following data members. |
281 mutable base::Lock lock_; | 288 mutable base::Lock lock_; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 | 336 |
330 // Temporary callback used for Stop(). | 337 // Temporary callback used for Stop(). |
331 base::Closure stop_cb_; | 338 base::Closure stop_cb_; |
332 | 339 |
333 // Permanent callbacks passed in via Start(). | 340 // Permanent callbacks passed in via Start(). |
334 base::Closure ended_cb_; | 341 base::Closure ended_cb_; |
335 PipelineStatusCB error_cb_; | 342 PipelineStatusCB error_cb_; |
336 PipelineMetadataCB metadata_cb_; | 343 PipelineMetadataCB metadata_cb_; |
337 BufferingStateCB buffering_state_cb_; | 344 BufferingStateCB buffering_state_cb_; |
338 base::Closure duration_change_cb_; | 345 base::Closure duration_change_cb_; |
339 | 346 AddTextTrackCB add_text_track_cb_; |
340 // Contains the demuxer and renderers to use when initializing. | |
341 scoped_ptr<FilterCollection> filter_collection_; | |
342 | 347 |
343 // Holds the initialized demuxer. Used for seeking. Owned by client. | 348 // Holds the initialized demuxer. Used for seeking. Owned by client. |
344 Demuxer* demuxer_; | 349 Demuxer* demuxer_; |
345 | 350 |
346 // Holds the initialized renderers. Used for setting the volume, | 351 // Holds the initialized renderers. Used for setting the volume, |
347 // playback rate, and determining when playback has finished. | 352 // playback rate, and determining when playback has finished. |
348 scoped_ptr<Renderer> renderer_; | 353 scoped_ptr<Renderer> renderer_; |
349 scoped_ptr<TextRenderer> text_renderer_; | 354 scoped_ptr<TextRenderer> text_renderer_; |
350 | 355 |
351 PipelineStatistics statistics_; | 356 PipelineStatistics statistics_; |
352 | 357 |
353 scoped_ptr<SerialRunner> pending_callbacks_; | 358 scoped_ptr<SerialRunner> pending_callbacks_; |
354 | 359 |
355 base::ThreadChecker thread_checker_; | 360 base::ThreadChecker thread_checker_; |
356 | 361 |
357 // NOTE: Weak pointers must be invalidated before all other member variables. | 362 // NOTE: Weak pointers must be invalidated before all other member variables. |
358 base::WeakPtrFactory<Pipeline> weak_factory_; | 363 base::WeakPtrFactory<Pipeline> weak_factory_; |
359 | 364 |
360 DISALLOW_COPY_AND_ASSIGN(Pipeline); | 365 DISALLOW_COPY_AND_ASSIGN(Pipeline); |
361 }; | 366 }; |
362 | 367 |
363 } // namespace media | 368 } // namespace media |
364 | 369 |
365 #endif // MEDIA_BASE_PIPELINE_H_ | 370 #endif // MEDIA_BASE_PIPELINE_H_ |
OLD | NEW |