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

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: Address CR comments and fix tests. 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') | webkit/media/webmediaplayer_impl.h » ('J')
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 // Current buffering state in terms of HTMLMediaElement.readyState values.
scherkus (not reviewing) 2012/08/15 23:46:55 layering violation in comment form! instead of a
acolwell GONE FROM CHROMIUM 2012/08/16 00:54:18 Done.
101 enum ReadyState {
102 kHaveMetadata,
103 kHaveEnoughData,
104 };
105
106 typedef base::Callback<void(ReadyState)> ReadyStateCB;
107
100 // Constructs a media pipeline that will execute on |message_loop|. 108 // Constructs a media pipeline that will execute on |message_loop|.
101 Pipeline(const scoped_refptr<base::MessageLoopProxy>& message_loop, 109 Pipeline(const scoped_refptr<base::MessageLoopProxy>& message_loop,
102 MediaLog* media_log); 110 MediaLog* media_log);
103 111
104 // Build a pipeline to using the given filter collection to construct a filter 112 // Build a pipeline to using the given filter collection to construct a filter
105 // chain, executing |start_cb| when initialization has completed. 113 // chain, executing |seek_cb| when the initial seek/preroll has completed.
106 // 114 //
107 // The following permanent callbacks will be executed as follows up until 115 // The following permanent callbacks will be executed as follows up until
108 // Stop() has completed: 116 // Stop() has completed:
109 // |ended_cb| will be executed whenever the media reaches the end. 117 // |ended_cb| will be executed whenever the media reaches the end.
110 // |error_cb| will be executed whenever an error occurs but hasn't 118 // |error_cb| will be executed whenever an error occurs but hasn't
111 // been reported already through another callback. 119 // been reported already through another callback.
112 // 120 // |ready_state_cb| will be executed whenever the pipeline does something
121 // that should trigger a HTMLMediaElement.readyState
scherkus (not reviewing) 2012/08/15 23:46:55 ditto -- this comment shouldn't reference what the
acolwell GONE FROM CHROMIUM 2012/08/16 00:54:18 Done.
122 // transition.
113 // It is an error to call this method after the pipeline has already started. 123 // It is an error to call this method after the pipeline has already started.
114 void Start(scoped_ptr<FilterCollection> filter_collection, 124 void Start(scoped_ptr<FilterCollection> filter_collection,
115 const PipelineStatusCB& ended_cb, 125 const PipelineStatusCB& ended_cb,
116 const PipelineStatusCB& error_cb, 126 const PipelineStatusCB& error_cb,
117 const PipelineStatusCB& start_cb); 127 const PipelineStatusCB& seek_cb,
128 const ReadyStateCB& ready_state_cb);
118 129
119 // Asynchronously stops the pipeline, executing |stop_cb| when the pipeline 130 // Asynchronously stops the pipeline, executing |stop_cb| when the pipeline
120 // teardown has completed. 131 // teardown has completed.
121 // 132 //
122 // Stop() must complete before destroying the pipeline. It it permissible to 133 // Stop() must complete before destroying the pipeline. It it permissible to
123 // call Stop() at any point during the lifetime of the pipeline. 134 // call Stop() at any point during the lifetime of the pipeline.
124 void Stop(const base::Closure& stop_cb); 135 void Stop(const base::Closure& stop_cb);
125 136
126 // Attempt to seek to the position specified by time. |seek_cb| will be 137 // 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. 138 // 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 237
227 // Updates |state_|. All state transitions should use this call. 238 // Updates |state_|. All state transitions should use this call.
228 void SetState(State next_state); 239 void SetState(State next_state);
229 240
230 // Simple method used to make sure the pipeline is running normally. 241 // Simple method used to make sure the pipeline is running normally.
231 bool IsPipelineOk(); 242 bool IsPipelineOk();
232 243
233 // Helper method to tell whether we are in transition to seek state. 244 // Helper method to tell whether we are in transition to seek state.
234 bool IsPipelineSeeking(); 245 bool IsPipelineSeeking();
235 246
236 // Helper method to execute callback from Start() and reset 247 // Helper method that runs & resets |seek_cb_| and resets |seek_timestamp_|
237 // |filter_collection_|. Called when initialization completes 248 // and |seek_pending_|.
238 // normally or when pipeline is stopped or error occurs during 249 void FinishSeek();
239 // initialization.
240 void FinishInitialization();
241 250
242 // Returns true if the given state is one that transitions to a new state 251 // Returns true if the given state is one that transitions to a new state
243 // after iterating through each filter. 252 // after iterating through each filter.
244 static bool TransientState(State state); 253 static bool TransientState(State state);
245 254
246 // Given the current state, returns the next state. 255 // Given the current state, returns the next state.
247 State FindNextState(State current); 256 State FindNextState(State current);
248 257
249 // DataSourceHost (by way of DemuxerHost) implementation. 258 // DataSourceHost (by way of DemuxerHost) implementation.
250 virtual void SetTotalBytes(int64 total_bytes) OVERRIDE; 259 virtual void SetTotalBytes(int64 total_bytes) OVERRIDE;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 298
290 // Callback executed by video renderer to update clock time. 299 // Callback executed by video renderer to update clock time.
291 void OnVideoTimeUpdate(base::TimeDelta max_time); 300 void OnVideoTimeUpdate(base::TimeDelta max_time);
292 301
293 // The following "task" methods correspond to the public methods, but these 302 // 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 303 // methods are run as the result of posting a task to the PipelineInternal's
295 // message loop. 304 // message loop.
296 void StartTask(scoped_ptr<FilterCollection> filter_collection, 305 void StartTask(scoped_ptr<FilterCollection> filter_collection,
297 const PipelineStatusCB& ended_cb, 306 const PipelineStatusCB& ended_cb,
298 const PipelineStatusCB& error_cb, 307 const PipelineStatusCB& error_cb,
299 const PipelineStatusCB& start_cb); 308 const PipelineStatusCB& seek_cb,
309 const ReadyStateCB& ready_state_cb);
300 310
301 // InitializeTask() performs initialization in multiple passes. It is executed 311 // InitializeTask() performs initialization in multiple passes. It is executed
302 // as a result of calling Start() or InitializationComplete() that advances 312 // 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 313 // 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 314 // initialization. One stage communicates its status to the next through
305 // |last_stage_status|. 315 // |last_stage_status|.
306 void InitializeTask(PipelineStatus last_stage_status); 316 void InitializeTask(PipelineStatus last_stage_status);
307 317
308 // Stops and destroys all filters, placing the pipeline in the kStopped state. 318 // Stops and destroys all filters, placing the pipeline in the kStopped state.
309 void StopTask(const base::Closure& stop_cb); 319 void StopTask(const base::Closure& stop_cb);
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
487 bool audio_disabled_; 497 bool audio_disabled_;
488 498
489 // Filter collection as passed in by Start(). 499 // Filter collection as passed in by Start().
490 scoped_ptr<FilterCollection> filter_collection_; 500 scoped_ptr<FilterCollection> filter_collection_;
491 501
492 // Callbacks for various pipeline operations. 502 // Callbacks for various pipeline operations.
493 PipelineStatusCB seek_cb_; 503 PipelineStatusCB seek_cb_;
494 base::Closure stop_cb_; 504 base::Closure stop_cb_;
495 PipelineStatusCB ended_cb_; 505 PipelineStatusCB ended_cb_;
496 PipelineStatusCB error_cb_; 506 PipelineStatusCB error_cb_;
507 ReadyStateCB ready_state_cb_;
497 508
498 // Audio renderer reference used for setting the volume and determining 509 // Audio renderer reference used for setting the volume and determining
499 // when playback has finished. 510 // when playback has finished.
500 scoped_refptr<AudioRenderer> audio_renderer_; 511 scoped_refptr<AudioRenderer> audio_renderer_;
501 512
502 // Video Renderer reference used for determining when playback has finished 513 // Video Renderer reference used for determining when playback has finished
503 // and for signalling imminent shutdown. 514 // and for signalling imminent shutdown.
504 // The signalling imminent shutdown is a HACK necessary because 515 // The signalling imminent shutdown is a HACK necessary because
505 // WebMediaPlayerImpl::Destroy() holds the render thread loop hostage 516 // WebMediaPlayerImpl::Destroy() holds the render thread loop hostage
506 // until PipelineImpl::Stop() calls its callback. 517 // until PipelineImpl::Stop() calls its callback.
(...skipping 15 matching lines...) Expand all
522 base::Time creation_time_; 533 base::Time creation_time_;
523 534
524 scoped_ptr<SerialRunner> pending_callbacks_; 535 scoped_ptr<SerialRunner> pending_callbacks_;
525 536
526 DISALLOW_COPY_AND_ASSIGN(Pipeline); 537 DISALLOW_COPY_AND_ASSIGN(Pipeline);
527 }; 538 };
528 539
529 } // namespace media 540 } // namespace media
530 541
531 #endif // MEDIA_BASE_PIPELINE_H_ 542 #endif // MEDIA_BASE_PIPELINE_H_
OLDNEW
« no previous file with comments | « no previous file | media/base/pipeline.cc » ('j') | webkit/media/webmediaplayer_impl.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698