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

Side by Side Diff: media/base/pipeline.h

Issue 206103004: Remove HasAudio(), HasVideo(), GetInitialNaturalSize() from media::Pipeline. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Split BufferingStateCB. Created 6 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
OLDNEW
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 16 matching lines...) Expand all
27 27
28 namespace media { 28 namespace media {
29 29
30 class Clock; 30 class Clock;
31 class FilterCollection; 31 class FilterCollection;
32 class MediaLog; 32 class MediaLog;
33 class TextRenderer; 33 class TextRenderer;
34 class TextTrackConfig; 34 class TextTrackConfig;
35 class VideoRenderer; 35 class VideoRenderer;
36 36
37 // Metadata describing a pipeline once it has been initialized. Sent by the
38 // buffering_state callback.
scherkus (not reviewing) 2014/03/21 22:26:10 second sentence is incorrect -- heck I'd just remo
sandersd (OOO until July 31) 2014/03/21 23:30:35 Done.
39 struct PipelineMetadata {
40 PipelineMetadata() : has_audio_(), has_video_(), natural_size_() {}
scherkus (not reviewing) 2014/03/21 22:26:10 nit: instead of using the zero-initializer for POD
sandersd (OOO until July 31) 2014/03/21 23:30:35 Done.
41
42 bool has_audio_;
scherkus (not reviewing) 2014/03/21 22:26:10 structs don't use trailing _ for variables: http:/
sandersd (OOO until July 31) 2014/03/21 23:30:35 Done.
43 bool has_video_;
44 gfx::Size natural_size_;
45 };
46
47 typedef base::Callback<void(PipelineMetadata)> HaveMetadataCB;
scherkus (not reviewing) 2014/03/21 22:26:10 I'd model the naming after PipelineStatusCB: - c
sandersd (OOO until July 31) 2014/03/21 23:30:35 Done.
48
37 // Pipeline runs the media pipeline. Filters are created and called on the 49 // Pipeline runs the media pipeline. Filters are created and called on the
38 // task runner injected into this object. Pipeline works like a state 50 // task runner injected into this object. Pipeline works like a state
39 // machine to perform asynchronous initialization, pausing, seeking and playing. 51 // machine to perform asynchronous initialization, pausing, seeking and playing.
40 // 52 //
41 // Here's a state diagram that describes the lifetime of this object. 53 // Here's a state diagram that describes the lifetime of this object.
42 // 54 //
43 // [ *Created ] [ Any State ] 55 // [ *Created ] [ Any State ]
44 // | Start() | Stop() / SetError() 56 // | Start() | Stop() / SetError()
45 // V V 57 // V V
46 // [ InitXXX (for each filter) ] [ Stopping ] 58 // [ InitXXX (for each filter) ] [ Stopping ]
(...skipping 13 matching lines...) Expand all
60 // completed, we are implicitly in a "Paused" state. At that point we simulate 72 // 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. 73 // 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 74 // From then on the normal Seek() transitions are carried out and we start
63 // playing the media. 75 // playing the media.
64 // 76 //
65 // If any error ever happens, this object will transition to the "Error" state 77 // 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 78 // from any state. If Stop() is ever called, this object will transition to
67 // "Stopped" state. 79 // "Stopped" state.
68 class MEDIA_EXPORT Pipeline : public DemuxerHost { 80 class MEDIA_EXPORT Pipeline : public DemuxerHost {
69 public: 81 public:
70 // Buffering states the pipeline transitions between during playback.
71 // kHaveMetadata:
72 // Indicates that the following things are known:
73 // content duration, container video size, start time, and whether the
74 // content has audio and/or video in supported formats.
75 // kPrerollCompleted:
76 // All renderers have buffered enough data to satisfy preroll and are ready
77 // to start playback.
78 enum BufferingState {
79 kHaveMetadata,
80 kPrerollCompleted,
81 };
82
83 typedef base::Callback<void(BufferingState)> BufferingStateCB;
84
85 // Constructs a media pipeline that will execute on |task_runner|. 82 // Constructs a media pipeline that will execute on |task_runner|.
86 Pipeline(const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, 83 Pipeline(const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
87 MediaLog* media_log); 84 MediaLog* media_log);
88 virtual ~Pipeline(); 85 virtual ~Pipeline();
89 86
90 // Build a pipeline to using the given filter collection to construct a filter 87 // Build a pipeline to using the given filter collection to construct a filter
91 // chain, executing |seek_cb| when the initial seek/preroll has completed. 88 // chain, executing |seek_cb| when the initial seek/preroll has completed.
92 // 89 //
93 // |filter_collection| must be a complete collection containing a demuxer, 90 // |filter_collection| must be a complete collection containing a demuxer,
94 // audio/video decoders, and audio/video renderers. Failing to do so will 91 // audio/video decoders, and audio/video renderers. Failing to do so will
95 // result in a crash. 92 // result in a crash.
96 // 93 //
97 // The following permanent callbacks will be executed as follows up until 94 // The following permanent callbacks will be executed as follows up until
98 // Stop() has completed: 95 // Stop() has completed:
99 // |ended_cb| will be executed whenever the media reaches the end. 96 // |ended_cb| will be executed whenever the media reaches the end.
100 // |error_cb| will be executed whenever an error occurs but hasn't 97 // |error_cb| optional callback that will be executed whenever an error
scherkus (not reviewing) 2014/03/21 22:26:10 careful tweaking comments: error_cb is definitely
sandersd (OOO until July 31) 2014/03/21 23:30:35 Done.
101 // been reported already through another callback. 98 // occurs but hasn't been reported already through another
102 // |buffering_state_cb| Optional callback that will be executed whenever the 99 // callback.
103 // pipeline's buffering state changes. 100 // |have_metadata_cb| optional callback that will be executed when the
scherkus (not reviewing) 2014/03/21 22:26:10 I usually advocate for as little optional-ness as
sandersd (OOO until July 31) 2014/03/21 23:30:35 Done.
104 // |duration_change_cb| Optional callback that will be executed whenever the 101 // content duration, container video size, start time,
102 // and whether the content has audio and/or video in
103 // supported formats are known.
104 // |preroll_completed_cb| optional callback that will be executed when all
105 // renderers have buffered enough data to satisfy
106 // preroll and are ready to start playback.
107 // |duration_change_cb| optional callback that will be executed whenever the
105 // presentation duration changes. 108 // presentation duration changes.
106 // It is an error to call this method after the pipeline has already started. 109 // It is an error to call this method after the pipeline has already started.
107 void Start(scoped_ptr<FilterCollection> filter_collection, 110 void Start(scoped_ptr<FilterCollection> filter_collection,
108 const base::Closure& ended_cb, 111 const base::Closure& ended_cb,
109 const PipelineStatusCB& error_cb, 112 const PipelineStatusCB& error_cb,
110 const PipelineStatusCB& seek_cb, 113 const PipelineStatusCB& seek_cb,
111 const BufferingStateCB& buffering_state_cb, 114 const HaveMetadataCB& have_metadata_cb,
115 const base::Closure& preroll_completed_cb,
112 const base::Closure& duration_change_cb); 116 const base::Closure& duration_change_cb);
113 117
114 // Asynchronously stops the pipeline, executing |stop_cb| when the pipeline 118 // Asynchronously stops the pipeline, executing |stop_cb| when the pipeline
115 // teardown has completed. 119 // teardown has completed.
116 // 120 //
117 // Stop() must complete before destroying the pipeline. It it permissible to 121 // Stop() must complete before destroying the pipeline. It it permissible to
118 // call Stop() at any point during the lifetime of the pipeline. 122 // call Stop() at any point during the lifetime of the pipeline.
119 // 123 //
120 // It is safe to delete the pipeline during the execution of |stop_cb|. 124 // It is safe to delete the pipeline during the execution of |stop_cb|.
121 void Stop(const base::Closure& stop_cb); 125 void Stop(const base::Closure& stop_cb);
122 126
123 // Attempt to seek to the position specified by time. |seek_cb| will be 127 // 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. 128 // executed when the all filters in the pipeline have processed the seek.
125 // 129 //
126 // Clients are expected to call GetMediaTime() to check whether the seek 130 // Clients are expected to call GetMediaTime() to check whether the seek
127 // succeeded. 131 // succeeded.
128 // 132 //
129 // It is an error to call this method if the pipeline has not started. 133 // It is an error to call this method if the pipeline has not started.
130 void Seek(base::TimeDelta time, const PipelineStatusCB& seek_cb); 134 void Seek(base::TimeDelta time, const PipelineStatusCB& seek_cb);
131 135
132 // Returns true if the pipeline has been started via Start(). If IsRunning() 136 // 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 137 // returns true, it is expected that Stop() will be called before destroying
134 // the pipeline. 138 // the pipeline.
135 bool IsRunning() const; 139 bool IsRunning() const;
136 140
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 141 // 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 142 // 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 143 // that the pipeline is rendering the media at the standard rate. Valid
146 // values for playback rate are >= 0.0f. 144 // values for playback rate are >= 0.0f.
147 float GetPlaybackRate() const; 145 float GetPlaybackRate() const;
148 146
149 // Attempt to adjust the playback rate. Setting a playback rate of 0.0f pauses 147 // 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 148 // 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. 149 // rate. Values for the playback rate must be greater than or equal to 0.0f.
152 // 150 //
(...skipping 18 matching lines...) Expand all
171 Ranges<base::TimeDelta> GetBufferedTimeRanges(); 169 Ranges<base::TimeDelta> GetBufferedTimeRanges();
172 170
173 // Get the duration of the media in microseconds. If the duration has not 171 // Get the duration of the media in microseconds. If the duration has not
174 // been determined yet, then returns 0. 172 // been determined yet, then returns 0.
175 base::TimeDelta GetMediaDuration() const; 173 base::TimeDelta GetMediaDuration() const;
176 174
177 // Get the total size of the media file. If the size has not yet been 175 // Get the total size of the media file. If the size has not yet been
178 // determined or can not be determined, this value is 0. 176 // determined or can not be determined, this value is 0.
179 int64 GetTotalBytes() const; 177 int64 GetTotalBytes() const;
180 178
181 // Get the video's initial natural size as reported by the container. Note
182 // that the natural size can change during playback.
183 gfx::Size GetInitialNaturalSize() const;
184
185 // Return true if loading progress has been made since the last time this 179 // Return true if loading progress has been made since the last time this
186 // method was called. 180 // method was called.
187 bool DidLoadingProgress() const; 181 bool DidLoadingProgress() const;
188 182
189 // Gets the current pipeline statistics. 183 // Gets the current pipeline statistics.
190 PipelineStatistics GetStatistics() const; 184 PipelineStatistics GetStatistics() const;
191 185
192 void SetClockForTesting(Clock* clock); 186 void SetClockForTesting(Clock* clock);
193 void SetErrorForTesting(PipelineStatus status); 187 void SetErrorForTesting(PipelineStatus status);
194 188
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 249
256 // Callback executed by audio renderer to update clock time. 250 // Callback executed by audio renderer to update clock time.
257 void OnAudioTimeUpdate(base::TimeDelta time, base::TimeDelta max_time); 251 void OnAudioTimeUpdate(base::TimeDelta time, base::TimeDelta max_time);
258 252
259 // Callback executed by video renderer to update clock time. 253 // Callback executed by video renderer to update clock time.
260 void OnVideoTimeUpdate(base::TimeDelta max_time); 254 void OnVideoTimeUpdate(base::TimeDelta max_time);
261 255
262 // The following "task" methods correspond to the public methods, but these 256 // 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 257 // methods are run as the result of posting a task to the Pipeline's
264 // task runner. 258 // task runner.
265 void StartTask(scoped_ptr<FilterCollection> filter_collection, 259 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 260
272 // Stops and destroys all filters, placing the pipeline in the kStopped state. 261 // Stops and destroys all filters, placing the pipeline in the kStopped state.
273 void StopTask(const base::Closure& stop_cb); 262 void StopTask(const base::Closure& stop_cb);
274 263
275 // Carries out stopping and destroying all filters, placing the pipeline in 264 // Carries out stopping and destroying all filters, placing the pipeline in
276 // the kStopped state. 265 // the kStopped state.
277 void ErrorChangedTask(PipelineStatus error); 266 void ErrorChangedTask(PipelineStatus error);
278 267
279 // Carries out notifying filters that the playback rate has changed. 268 // Carries out notifying filters that the playback rate has changed.
280 void PlaybackRateChangedTask(float playback_rate); 269 void PlaybackRateChangedTask(float playback_rate);
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 Ranges<int64> buffered_byte_ranges_; 352 Ranges<int64> buffered_byte_ranges_;
364 Ranges<base::TimeDelta> buffered_time_ranges_; 353 Ranges<base::TimeDelta> buffered_time_ranges_;
365 354
366 // True when AddBufferedByteRange() has been called more recently than 355 // True when AddBufferedByteRange() has been called more recently than
367 // DidLoadingProgress(). 356 // DidLoadingProgress().
368 mutable bool did_loading_progress_; 357 mutable bool did_loading_progress_;
369 358
370 // Total size of the media. Set by filters. 359 // Total size of the media. Set by filters.
371 int64 total_bytes_; 360 int64 total_bytes_;
372 361
373 // The initial natural size of the video as reported by the container.
374 gfx::Size initial_natural_size_;
375
376 // Current volume level (from 0.0f to 1.0f). This value is set immediately 362 // Current volume level (from 0.0f to 1.0f). This value is set immediately
377 // via SetVolume() and a task is dispatched on the task runner to notify the 363 // via SetVolume() and a task is dispatched on the task runner to notify the
378 // filters. 364 // filters.
379 float volume_; 365 float volume_;
380 366
381 // Current playback rate (>= 0.0f). This value is set immediately via 367 // Current playback rate (>= 0.0f). This value is set immediately via
382 // SetPlaybackRate() and a task is dispatched on the task runner to notify 368 // SetPlaybackRate() and a task is dispatched on the task runner to notify
383 // the filters. 369 // the filters.
384 float playback_rate_; 370 float playback_rate_;
385 371
386 // base::TickClock used by |clock_|. 372 // base::TickClock used by |clock_|.
387 base::DefaultTickClock default_tick_clock_; 373 base::DefaultTickClock default_tick_clock_;
388 374
389 // Reference clock. Keeps track of current playback time. Uses system 375 // Reference clock. Keeps track of current playback time. Uses system
390 // clock and linear interpolation, but can have its time manually set 376 // clock and linear interpolation, but can have its time manually set
391 // by filters. 377 // by filters.
392 scoped_ptr<Clock> clock_; 378 scoped_ptr<Clock> clock_;
393 379
394 // If this value is set to true, then |clock_| is paused and we are waiting 380 // If this value is set to true, then |clock_| is paused and we are waiting
395 // for an update of the clock greater than or equal to the elapsed time to 381 // for an update of the clock greater than or equal to the elapsed time to
396 // start the clock. 382 // start the clock.
397 bool waiting_for_clock_update_; 383 bool waiting_for_clock_update_;
398 384
399 // Status of the pipeline. Initialized to PIPELINE_OK which indicates that 385 // Status of the pipeline. Initialized to PIPELINE_OK which indicates that
400 // the pipeline is operating correctly. Any other value indicates that the 386 // 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 387 // pipeline is stopped or is stopping. Clients can call the Stop() method to
402 // reset the pipeline state, and restore this to PIPELINE_OK. 388 // reset the pipeline state, and restore this to PIPELINE_OK.
403 PipelineStatus status_; 389 PipelineStatus status_;
404 390
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 391 // The following data members are only accessed by tasks posted to
413 // |task_runner_|. 392 // |task_runner_|.
414 393
415 // Member that tracks the current state. 394 // Member that tracks the current state.
416 State state_; 395 State state_;
417 396
397 // The initial natural size of the video as reported by the container.
398 gfx::Size initial_natural_size_;
399
418 // Whether we've received the audio/video/text ended events. 400 // Whether we've received the audio/video/text ended events.
419 bool audio_ended_; 401 bool audio_ended_;
420 bool video_ended_; 402 bool video_ended_;
421 bool text_ended_; 403 bool text_ended_;
422 404
423 // Set to true in DisableAudioRendererTask(). 405 // Set to true in DisableAudioRendererTask().
424 bool audio_disabled_; 406 bool audio_disabled_;
425 407
426 // Temporary callback used for Start() and Seek(). 408 // Temporary callback used for Start() and Seek().
427 PipelineStatusCB seek_cb_; 409 PipelineStatusCB seek_cb_;
428 410
429 // Temporary callback used for Stop(). 411 // Temporary callback used for Stop().
430 base::Closure stop_cb_; 412 base::Closure stop_cb_;
431 413
432 // Permanent callbacks passed in via Start(). 414 // Permanent callbacks passed in via Start().
433 base::Closure ended_cb_; 415 base::Closure ended_cb_;
434 PipelineStatusCB error_cb_; 416 PipelineStatusCB error_cb_;
435 BufferingStateCB buffering_state_cb_; 417 HaveMetadataCB have_metadata_cb_;
418 base::Closure preroll_completed_cb_;
436 base::Closure duration_change_cb_; 419 base::Closure duration_change_cb_;
437 420
438 // Contains the demuxer and renderers to use when initializing. 421 // Contains the demuxer and renderers to use when initializing.
439 scoped_ptr<FilterCollection> filter_collection_; 422 scoped_ptr<FilterCollection> filter_collection_;
440 423
441 // Holds the initialized demuxer. Used for seeking. Owned by client. 424 // Holds the initialized demuxer. Used for seeking. Owned by client.
442 Demuxer* demuxer_; 425 Demuxer* demuxer_;
443 426
444 // Holds the initialized renderers. Used for setting the volume, 427 // Holds the initialized renderers. Used for setting the volume,
445 // playback rate, and determining when playback has finished. 428 // playback rate, and determining when playback has finished.
(...skipping 10 matching lines...) Expand all
456 scoped_ptr<SerialRunner> pending_callbacks_; 439 scoped_ptr<SerialRunner> pending_callbacks_;
457 440
458 base::ThreadChecker thread_checker_; 441 base::ThreadChecker thread_checker_;
459 442
460 DISALLOW_COPY_AND_ASSIGN(Pipeline); 443 DISALLOW_COPY_AND_ASSIGN(Pipeline);
461 }; 444 };
462 445
463 } // namespace media 446 } // namespace media
464 447
465 #endif // MEDIA_BASE_PIPELINE_H_ 448 #endif // MEDIA_BASE_PIPELINE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698