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

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

Issue 10854151: Allow transitioning to HAVE_METADATA before pipeline initialization completes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase and address final comments Created 8 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | media/base/pipeline.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 (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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 // From then on the normal Seek() transitions are carried out and we start 90 // From then on the normal Seek() transitions are carried out and we start
91 // playing the media. 91 // playing the media.
92 // 92 //
93 // If any error ever happens, this object will transition to the "Error" state 93 // If any error ever happens, this object will transition to the "Error" state
94 // from any state. If Stop() is ever called, this object will transition to 94 // from any state. If Stop() is ever called, this object will transition to
95 // "Stopped" state. 95 // "Stopped" state.
96 class MEDIA_EXPORT Pipeline 96 class MEDIA_EXPORT Pipeline
97 : public base::RefCountedThreadSafe<Pipeline>, 97 : public base::RefCountedThreadSafe<Pipeline>,
98 public DemuxerHost { 98 public DemuxerHost {
99 public: 99 public:
100 // Buffering states the pipeline transitions between during playback.
101 // kHaveMetadata:
102 // Indicates that the following things are known:
103 // content duration, natural size, start time, and whether the content has
104 // audio and/or video in supported formats.
105 // kPrerollCompleted:
106 // All renderers have buffered enough data to satisfy preroll and are ready
107 // to start playback.
108 enum BufferingState {
109 kHaveMetadata,
110 kPrerollCompleted,
111 };
112
113 typedef base::Callback<void(BufferingState)> BufferingStateCB;
114
100 // Constructs a media pipeline that will execute on |message_loop|. 115 // Constructs a media pipeline that will execute on |message_loop|.
101 Pipeline(const scoped_refptr<base::MessageLoopProxy>& message_loop, 116 Pipeline(const scoped_refptr<base::MessageLoopProxy>& message_loop,
102 MediaLog* media_log); 117 MediaLog* media_log);
103 118
104 // Build a pipeline to using the given filter collection to construct a filter 119 // Build a pipeline to using the given filter collection to construct a filter
105 // chain, executing |start_cb| when initialization has completed. 120 // chain, executing |seek_cb| when the initial seek/preroll has completed.
106 // 121 //
107 // The following permanent callbacks will be executed as follows up until 122 // The following permanent callbacks will be executed as follows up until
108 // Stop() has completed: 123 // Stop() has completed:
109 // |ended_cb| will be executed whenever the media reaches the end. 124 // |ended_cb| will be executed whenever the media reaches the end.
110 // |error_cb| will be executed whenever an error occurs but hasn't 125 // |error_cb| will be executed whenever an error occurs but hasn't
111 // been reported already through another callback. 126 // been reported already through another callback.
112 // 127 // |buffering_state_cb| Optional callback that will be executed whenever the
128 // pipeline's buffering state changes.
113 // It is an error to call this method after the pipeline has already started. 129 // It is an error to call this method after the pipeline has already started.
114 void Start(scoped_ptr<FilterCollection> filter_collection, 130 void Start(scoped_ptr<FilterCollection> filter_collection,
115 const PipelineStatusCB& ended_cb, 131 const PipelineStatusCB& ended_cb,
116 const PipelineStatusCB& error_cb, 132 const PipelineStatusCB& error_cb,
117 const PipelineStatusCB& start_cb); 133 const PipelineStatusCB& seek_cb,
134 const BufferingStateCB& buffering_state_cb);
118 135
119 // Asynchronously stops the pipeline, executing |stop_cb| when the pipeline 136 // Asynchronously stops the pipeline, executing |stop_cb| when the pipeline
120 // teardown has completed. 137 // teardown has completed.
121 // 138 //
122 // Stop() must complete before destroying the pipeline. It it permissible to 139 // Stop() must complete before destroying the pipeline. It it permissible to
123 // call Stop() at any point during the lifetime of the pipeline. 140 // call Stop() at any point during the lifetime of the pipeline.
124 void Stop(const base::Closure& stop_cb); 141 void Stop(const base::Closure& stop_cb);
125 142
126 // Attempt to seek to the position specified by time. |seek_cb| will be 143 // Attempt to seek to the position specified by time. |seek_cb| will be
127 // executed when the all filters in the pipeline have processed the seek. 144 // executed when the all filters in the pipeline have processed the seek.
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 243
227 // Updates |state_|. All state transitions should use this call. 244 // Updates |state_|. All state transitions should use this call.
228 void SetState(State next_state); 245 void SetState(State next_state);
229 246
230 // Simple method used to make sure the pipeline is running normally. 247 // Simple method used to make sure the pipeline is running normally.
231 bool IsPipelineOk(); 248 bool IsPipelineOk();
232 249
233 // Helper method to tell whether we are in transition to seek state. 250 // Helper method to tell whether we are in transition to seek state.
234 bool IsPipelineSeeking(); 251 bool IsPipelineSeeking();
235 252
236 // Helper method to execute callback from Start() and reset 253 // Helper method that runs & resets |seek_cb_| and resets |seek_timestamp_|
237 // |filter_collection_|. Called when initialization completes 254 // and |seek_pending_|.
238 // normally or when pipeline is stopped or error occurs during 255 void FinishSeek();
239 // initialization.
240 void FinishInitialization();
241 256
242 // Returns true if the given state is one that transitions to a new state 257 // Returns true if the given state is one that transitions to a new state
243 // after iterating through each filter. 258 // after iterating through each filter.
244 static bool TransientState(State state); 259 static bool TransientState(State state);
245 260
246 // Given the current state, returns the next state. 261 // Given the current state, returns the next state.
247 State FindNextState(State current); 262 State FindNextState(State current);
248 263
249 // DataSourceHost (by way of DemuxerHost) implementation. 264 // DataSourceHost (by way of DemuxerHost) implementation.
250 virtual void SetTotalBytes(int64 total_bytes) OVERRIDE; 265 virtual void SetTotalBytes(int64 total_bytes) OVERRIDE;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 304
290 // Callback executed by video renderer to update clock time. 305 // Callback executed by video renderer to update clock time.
291 void OnVideoTimeUpdate(base::TimeDelta max_time); 306 void OnVideoTimeUpdate(base::TimeDelta max_time);
292 307
293 // The following "task" methods correspond to the public methods, but these 308 // The following "task" methods correspond to the public methods, but these
294 // methods are run as the result of posting a task to the PipelineInternal's 309 // methods are run as the result of posting a task to the PipelineInternal's
295 // message loop. 310 // message loop.
296 void StartTask(scoped_ptr<FilterCollection> filter_collection, 311 void StartTask(scoped_ptr<FilterCollection> filter_collection,
297 const PipelineStatusCB& ended_cb, 312 const PipelineStatusCB& ended_cb,
298 const PipelineStatusCB& error_cb, 313 const PipelineStatusCB& error_cb,
299 const PipelineStatusCB& start_cb); 314 const PipelineStatusCB& seek_cb,
315 const BufferingStateCB& buffering_state_cb);
300 316
301 // InitializeTask() performs initialization in multiple passes. It is executed 317 // InitializeTask() performs initialization in multiple passes. It is executed
302 // as a result of calling Start() or InitializationComplete() that advances 318 // as a result of calling Start() or InitializationComplete() that advances
303 // initialization to the next state. It works as a hub of state transition for 319 // initialization to the next state. It works as a hub of state transition for
304 // initialization. One stage communicates its status to the next through 320 // initialization. One stage communicates its status to the next through
305 // |last_stage_status|. 321 // |last_stage_status|.
306 void InitializeTask(PipelineStatus last_stage_status); 322 void InitializeTask(PipelineStatus last_stage_status);
307 323
308 // Stops and destroys all filters, placing the pipeline in the kStopped state. 324 // Stops and destroys all filters, placing the pipeline in the kStopped state.
309 void StopTask(const base::Closure& stop_cb); 325 void StopTask(const base::Closure& stop_cb);
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
487 bool audio_disabled_; 503 bool audio_disabled_;
488 504
489 // Filter collection as passed in by Start(). 505 // Filter collection as passed in by Start().
490 scoped_ptr<FilterCollection> filter_collection_; 506 scoped_ptr<FilterCollection> filter_collection_;
491 507
492 // Callbacks for various pipeline operations. 508 // Callbacks for various pipeline operations.
493 PipelineStatusCB seek_cb_; 509 PipelineStatusCB seek_cb_;
494 base::Closure stop_cb_; 510 base::Closure stop_cb_;
495 PipelineStatusCB ended_cb_; 511 PipelineStatusCB ended_cb_;
496 PipelineStatusCB error_cb_; 512 PipelineStatusCB error_cb_;
513 BufferingStateCB buffering_state_cb_;
497 514
498 // Audio renderer reference used for setting the volume and determining 515 // Audio renderer reference used for setting the volume and determining
499 // when playback has finished. 516 // when playback has finished.
500 scoped_refptr<AudioRenderer> audio_renderer_; 517 scoped_refptr<AudioRenderer> audio_renderer_;
501 518
502 // Video Renderer reference used for determining when playback has finished 519 // Video Renderer reference used for determining when playback has finished
503 // and for signalling imminent shutdown. 520 // and for signalling imminent shutdown.
504 // The signalling imminent shutdown is a HACK necessary because 521 // The signalling imminent shutdown is a HACK necessary because
505 // WebMediaPlayerImpl::Destroy() holds the render thread loop hostage 522 // WebMediaPlayerImpl::Destroy() holds the render thread loop hostage
506 // until PipelineImpl::Stop() calls its callback. 523 // until PipelineImpl::Stop() calls its callback.
(...skipping 15 matching lines...) Expand all
522 base::Time creation_time_; 539 base::Time creation_time_;
523 540
524 scoped_ptr<SerialRunner> pending_callbacks_; 541 scoped_ptr<SerialRunner> pending_callbacks_;
525 542
526 DISALLOW_COPY_AND_ASSIGN(Pipeline); 543 DISALLOW_COPY_AND_ASSIGN(Pipeline);
527 }; 544 };
528 545
529 } // namespace media 546 } // namespace media
530 547
531 #endif // MEDIA_BASE_PIPELINE_H_ 548 #endif // MEDIA_BASE_PIPELINE_H_
OLDNEW
« no previous file with comments | « no previous file | media/base/pipeline.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698