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 <string> | 8 #include <string> |
9 | 9 |
10 #include "base/gtest_prod_util.h" | 10 #include "base/gtest_prod_util.h" |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 // completed, we are implicitly in a "Paused" state. At that point we simulate | 60 // completed, we are implicitly in a "Paused" state. At that point we simulate |
61 // a Seek() to the beginning of the media to give filters a chance to preroll. | 61 // a Seek() to the beginning of the media to give filters a chance to preroll. |
62 // From then on the normal Seek() transitions are carried out and we start | 62 // From then on the normal Seek() transitions are carried out and we start |
63 // playing the media. | 63 // playing the media. |
64 // | 64 // |
65 // If any error ever happens, this object will transition to the "Error" state | 65 // If any error ever happens, this object will transition to the "Error" state |
66 // from any state. If Stop() is ever called, this object will transition to | 66 // from any state. If Stop() is ever called, this object will transition to |
67 // "Stopped" state. | 67 // "Stopped" state. |
68 class MEDIA_EXPORT Pipeline : public DemuxerHost { | 68 class MEDIA_EXPORT Pipeline : public DemuxerHost { |
69 public: | 69 public: |
| 70 // Types of tracks the pipeline may initialize. |
| 71 enum TrackType { AUDIO, VIDEO }; |
| 72 |
| 73 typedef base::Callback<void(TrackType)> HasTrackCB; |
| 74 |
70 // Buffering states the pipeline transitions between during playback. | 75 // Buffering states the pipeline transitions between during playback. |
71 // kHaveMetadata: | 76 // kHaveMetadata: |
72 // Indicates that the following things are known: | 77 // Indicates that the following things are known: |
73 // content duration, container video size, start time, and whether the | 78 // content duration, container video size, start time, and whether the |
74 // content has audio and/or video in supported formats. | 79 // content has audio and/or video in supported formats. |
75 // kPrerollCompleted: | 80 // kPrerollCompleted: |
76 // All renderers have buffered enough data to satisfy preroll and are ready | 81 // All renderers have buffered enough data to satisfy preroll and are ready |
77 // to start playback. | 82 // to start playback. |
78 enum BufferingState { | 83 enum BufferingState { |
79 kHaveMetadata, | 84 kHaveMetadata, |
(...skipping 12 matching lines...) Expand all Loading... |
92 // | 97 // |
93 // |filter_collection| must be a complete collection containing a demuxer, | 98 // |filter_collection| must be a complete collection containing a demuxer, |
94 // audio/video decoders, and audio/video renderers. Failing to do so will | 99 // audio/video decoders, and audio/video renderers. Failing to do so will |
95 // result in a crash. | 100 // result in a crash. |
96 // | 101 // |
97 // The following permanent callbacks will be executed as follows up until | 102 // The following permanent callbacks will be executed as follows up until |
98 // Stop() has completed: | 103 // Stop() has completed: |
99 // |ended_cb| will be executed whenever the media reaches the end. | 104 // |ended_cb| will be executed whenever the media reaches the end. |
100 // |error_cb| will be executed whenever an error occurs but hasn't | 105 // |error_cb| will be executed whenever an error occurs but hasn't |
101 // been reported already through another callback. | 106 // been reported already through another callback. |
102 // |buffering_state_cb| Optional callback that will be executed whenever the | 107 // |has_track_cb| optional callback that wii be executed whenever the |
103 // pipeline's buffering state changes. | 108 // pipeline initializes a track. |
104 // |duration_change_cb| Optional callback that will be executed whenever the | 109 // |buffering_state_cb| will be executed whenever the pipeline's buffering |
| 110 // state changes. |
| 111 // |duration_change_cb| optional callback that will be executed whenever the |
105 // presentation duration changes. | 112 // presentation duration changes. |
106 // It is an error to call this method after the pipeline has already started. | 113 // It is an error to call this method after the pipeline has already started. |
107 void Start(scoped_ptr<FilterCollection> filter_collection, | 114 void Start(scoped_ptr<FilterCollection> filter_collection, |
108 const base::Closure& ended_cb, | 115 const base::Closure& ended_cb, |
109 const PipelineStatusCB& error_cb, | 116 const PipelineStatusCB& error_cb, |
110 const PipelineStatusCB& seek_cb, | 117 const PipelineStatusCB& seek_cb, |
| 118 const HasTrackCB& has_track_cb, |
111 const BufferingStateCB& buffering_state_cb, | 119 const BufferingStateCB& buffering_state_cb, |
112 const base::Closure& duration_change_cb); | 120 const base::Closure& duration_change_cb); |
113 | 121 |
114 // Asynchronously stops the pipeline, executing |stop_cb| when the pipeline | 122 // Asynchronously stops the pipeline, executing |stop_cb| when the pipeline |
115 // teardown has completed. | 123 // teardown has completed. |
116 // | 124 // |
117 // Stop() must complete before destroying the pipeline. It it permissible to | 125 // Stop() must complete before destroying the pipeline. It it permissible to |
118 // call Stop() at any point during the lifetime of the pipeline. | 126 // call Stop() at any point during the lifetime of the pipeline. |
119 // | 127 // |
120 // It is safe to delete the pipeline during the execution of |stop_cb|. | 128 // It is safe to delete the pipeline during the execution of |stop_cb|. |
121 void Stop(const base::Closure& stop_cb); | 129 void Stop(const base::Closure& stop_cb); |
122 | 130 |
123 // Attempt to seek to the position specified by time. |seek_cb| will be | 131 // Attempt to seek to the position specified by time. |seek_cb| will be |
124 // executed when the all filters in the pipeline have processed the seek. | 132 // executed when the all filters in the pipeline have processed the seek. |
125 // | 133 // |
126 // Clients are expected to call GetMediaTime() to check whether the seek | 134 // Clients are expected to call GetMediaTime() to check whether the seek |
127 // succeeded. | 135 // succeeded. |
128 // | 136 // |
129 // It is an error to call this method if the pipeline has not started. | 137 // It is an error to call this method if the pipeline has not started. |
130 void Seek(base::TimeDelta time, const PipelineStatusCB& seek_cb); | 138 void Seek(base::TimeDelta time, const PipelineStatusCB& seek_cb); |
131 | 139 |
132 // Returns true if the pipeline has been started via Start(). If IsRunning() | 140 // Returns true if the pipeline has been started via Start(). If IsRunning() |
133 // returns true, it is expected that Stop() will be called before destroying | 141 // returns true, it is expected that Stop() will be called before destroying |
134 // the pipeline. | 142 // the pipeline. |
135 bool IsRunning() const; | 143 bool IsRunning() const; |
136 | 144 |
137 // Returns true if the media has audio. | |
138 bool HasAudio() const; | |
139 | |
140 // Returns true if the media has video. | |
141 bool HasVideo() const; | |
142 | |
143 // Gets the current playback rate of the pipeline. When the pipeline is | 145 // Gets the current playback rate of the pipeline. When the pipeline is |
144 // started, the playback rate will be 0.0f. A rate of 1.0f indicates | 146 // started, the playback rate will be 0.0f. A rate of 1.0f indicates |
145 // that the pipeline is rendering the media at the standard rate. Valid | 147 // that the pipeline is rendering the media at the standard rate. Valid |
146 // values for playback rate are >= 0.0f. | 148 // values for playback rate are >= 0.0f. |
147 float GetPlaybackRate() const; | 149 float GetPlaybackRate() const; |
148 | 150 |
149 // Attempt to adjust the playback rate. Setting a playback rate of 0.0f pauses | 151 // Attempt to adjust the playback rate. Setting a playback rate of 0.0f pauses |
150 // all rendering of the media. A rate of 1.0f indicates a normal playback | 152 // all rendering of the media. A rate of 1.0f indicates a normal playback |
151 // rate. Values for the playback rate must be greater than or equal to 0.0f. | 153 // rate. Values for the playback rate must be greater than or equal to 0.0f. |
152 // | 154 // |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 | 257 |
256 // Callback executed by audio renderer to update clock time. | 258 // Callback executed by audio renderer to update clock time. |
257 void OnAudioTimeUpdate(base::TimeDelta time, base::TimeDelta max_time); | 259 void OnAudioTimeUpdate(base::TimeDelta time, base::TimeDelta max_time); |
258 | 260 |
259 // Callback executed by video renderer to update clock time. | 261 // Callback executed by video renderer to update clock time. |
260 void OnVideoTimeUpdate(base::TimeDelta max_time); | 262 void OnVideoTimeUpdate(base::TimeDelta max_time); |
261 | 263 |
262 // The following "task" methods correspond to the public methods, but these | 264 // The following "task" methods correspond to the public methods, but these |
263 // methods are run as the result of posting a task to the Pipeline's | 265 // methods are run as the result of posting a task to the Pipeline's |
264 // task runner. | 266 // task runner. |
265 void StartTask(scoped_ptr<FilterCollection> filter_collection, | 267 void StartTask(); |
266 const base::Closure& ended_cb, | |
267 const PipelineStatusCB& error_cb, | |
268 const PipelineStatusCB& seek_cb, | |
269 const BufferingStateCB& buffering_state_cb, | |
270 const base::Closure& duration_change_cb); | |
271 | 268 |
272 // Stops and destroys all filters, placing the pipeline in the kStopped state. | 269 // Stops and destroys all filters, placing the pipeline in the kStopped state. |
273 void StopTask(const base::Closure& stop_cb); | 270 void StopTask(const base::Closure& stop_cb); |
274 | 271 |
275 // Carries out stopping and destroying all filters, placing the pipeline in | 272 // Carries out stopping and destroying all filters, placing the pipeline in |
276 // the kStopped state. | 273 // the kStopped state. |
277 void ErrorChangedTask(PipelineStatus error); | 274 void ErrorChangedTask(PipelineStatus error); |
278 | 275 |
279 // Carries out notifying filters that the playback rate has changed. | 276 // Carries out notifying filters that the playback rate has changed. |
280 void PlaybackRateChangedTask(float playback_rate); | 277 void PlaybackRateChangedTask(float playback_rate); |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
395 // for an update of the clock greater than or equal to the elapsed time to | 392 // for an update of the clock greater than or equal to the elapsed time to |
396 // start the clock. | 393 // start the clock. |
397 bool waiting_for_clock_update_; | 394 bool waiting_for_clock_update_; |
398 | 395 |
399 // Status of the pipeline. Initialized to PIPELINE_OK which indicates that | 396 // Status of the pipeline. Initialized to PIPELINE_OK which indicates that |
400 // the pipeline is operating correctly. Any other value indicates that the | 397 // the pipeline is operating correctly. Any other value indicates that the |
401 // pipeline is stopped or is stopping. Clients can call the Stop() method to | 398 // pipeline is stopped or is stopping. Clients can call the Stop() method to |
402 // reset the pipeline state, and restore this to PIPELINE_OK. | 399 // reset the pipeline state, and restore this to PIPELINE_OK. |
403 PipelineStatus status_; | 400 PipelineStatus status_; |
404 | 401 |
405 // Whether the media contains rendered audio or video streams. | |
406 // TODO(fischman,scherkus): replace these with checks for | |
407 // {audio,video}_decoder_ once extraction of {Audio,Video}Decoder from the | |
408 // Filter heirarchy is done. | |
409 bool has_audio_; | |
410 bool has_video_; | |
411 | |
412 // The following data members are only accessed by tasks posted to | 402 // The following data members are only accessed by tasks posted to |
413 // |task_runner_|. | 403 // |task_runner_|. |
414 | 404 |
415 // Member that tracks the current state. | 405 // Member that tracks the current state. |
416 State state_; | 406 State state_; |
417 | 407 |
418 // Whether we've received the audio/video/text ended events. | 408 // Whether we've received the audio/video/text ended events. |
419 bool audio_ended_; | 409 bool audio_ended_; |
420 bool video_ended_; | 410 bool video_ended_; |
421 bool text_ended_; | 411 bool text_ended_; |
422 | 412 |
423 // Set to true in DisableAudioRendererTask(). | 413 // Set to true in DisableAudioRendererTask(). |
424 bool audio_disabled_; | 414 bool audio_disabled_; |
425 | 415 |
426 // Temporary callback used for Start() and Seek(). | 416 // Temporary callback used for Start() and Seek(). |
427 PipelineStatusCB seek_cb_; | 417 PipelineStatusCB seek_cb_; |
428 | 418 |
429 // Temporary callback used for Stop(). | 419 // Temporary callback used for Stop(). |
430 base::Closure stop_cb_; | 420 base::Closure stop_cb_; |
431 | 421 |
432 // Permanent callbacks passed in via Start(). | 422 // Permanent callbacks passed in via Start(). |
433 base::Closure ended_cb_; | 423 base::Closure ended_cb_; |
434 PipelineStatusCB error_cb_; | 424 PipelineStatusCB error_cb_; |
| 425 HasTrackCB has_track_cb_; |
435 BufferingStateCB buffering_state_cb_; | 426 BufferingStateCB buffering_state_cb_; |
436 base::Closure duration_change_cb_; | 427 base::Closure duration_change_cb_; |
437 | 428 |
438 // Contains the demuxer and renderers to use when initializing. | 429 // Contains the demuxer and renderers to use when initializing. |
439 scoped_ptr<FilterCollection> filter_collection_; | 430 scoped_ptr<FilterCollection> filter_collection_; |
440 | 431 |
441 // Holds the initialized demuxer. Used for seeking. Owned by client. | 432 // Holds the initialized demuxer. Used for seeking. Owned by client. |
442 Demuxer* demuxer_; | 433 Demuxer* demuxer_; |
443 | 434 |
444 // Holds the initialized renderers. Used for setting the volume, | 435 // Holds the initialized renderers. Used for setting the volume, |
(...skipping 11 matching lines...) Expand all Loading... |
456 scoped_ptr<SerialRunner> pending_callbacks_; | 447 scoped_ptr<SerialRunner> pending_callbacks_; |
457 | 448 |
458 base::ThreadChecker thread_checker_; | 449 base::ThreadChecker thread_checker_; |
459 | 450 |
460 DISALLOW_COPY_AND_ASSIGN(Pipeline); | 451 DISALLOW_COPY_AND_ASSIGN(Pipeline); |
461 }; | 452 }; |
462 | 453 |
463 } // namespace media | 454 } // namespace media |
464 | 455 |
465 #endif // MEDIA_BASE_PIPELINE_H_ | 456 #endif // MEDIA_BASE_PIPELINE_H_ |
OLD | NEW |