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

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

Issue 10826196: Clean up Pipeline terminal state logic by merging kError into kStopped state. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src
Patch Set: 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
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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 // [ Any State Other Than InitXXX ] 85 // [ Any State Other Than InitXXX ]
86 86
87 // 87 //
88 // Initialization is a series of state transitions from "Created" through each 88 // Initialization is a series of state transitions from "Created" through each
89 // filter initialization state. When all filter initialization states have 89 // filter initialization state. When all filter initialization states have
90 // completed, we are implicitly in a "Paused" state. At that point we simulate 90 // completed, we are implicitly in a "Paused" state. At that point we simulate
91 // a Seek() to the beginning of the media to give filters a chance to preroll. 91 // a Seek() to the beginning of the media to give filters a chance to preroll.
92 // From then on the normal Seek() transitions are carried out and we start 92 // From then on the normal Seek() transitions are carried out and we start
93 // playing the media. 93 // playing the media.
94 // 94 //
95 // If any error ever happens, this object will transition to the "Error" state 95 // Any runtime error will cause the pipeline to end up in the stopped state.
96 // from any state. If Stop() is ever called, this object will transition to
97 // "Stopped" state.
98 class MEDIA_EXPORT Pipeline 96 class MEDIA_EXPORT Pipeline
99 : public base::RefCountedThreadSafe<Pipeline>, 97 : public base::RefCountedThreadSafe<Pipeline>,
100 public DemuxerHost { 98 public DemuxerHost {
101 public: 99 public:
102 // Constructs a media pipeline that will execute on |message_loop|. 100 // Constructs a media pipeline that will execute on |message_loop|.
103 Pipeline(MessageLoop* message_loop, MediaLog* media_log); 101 Pipeline(MessageLoop* message_loop, MediaLog* media_log);
104 102
105 // Build a pipeline to using the given filter collection to construct a filter 103 // Build a pipeline to using the given filter collection to construct a filter
106 // chain. 104 // chain.
107 // 105 //
108 // Pipeline initialization is an inherently asynchronous process. Clients can
109 // either poll the IsInitialized() method (discouraged) or optionally pass in
110 // |start_cb|, which will be executed when initialization completes.
111 //
112 // The following permanent callbacks will be executed as follows: 106 // The following permanent callbacks will be executed as follows:
113 // |start_cb_| will be executed when Start is done (successfully or not). 107 // |start_cb_| will be executed when Start is done (successfully or not).
114 // |ended_cb| will be executed whenever the media reaches the end. 108 // |ended_cb| will be executed whenever the media reaches the end.
115 // |error_cb_| will be executed whenever an error occurs but hasn't 109 // |error_cb_| will be executed whenever an error occurs but hasn't
116 // been reported already through another callback. 110 // been reported already through another callback.
117 // 111 //
118 // These callbacks are only executed after Start() has been called and until 112 // These callbacks are only executed after Start() has been called and until
119 // Stop() has completed. 113 // Stop() has completed.
120 // 114 //
121 // It is an error to call this method after the pipeline has already started. 115 // It is an error to call this method after the pipeline has already started.
122 //
123 // TODO(scherkus): remove IsInitialized() and force clients to use callbacks.
124 void Start(scoped_ptr<FilterCollection> filter_collection, 116 void Start(scoped_ptr<FilterCollection> filter_collection,
125 const PipelineStatusCB& ended_cb, 117 const PipelineStatusCB& ended_cb,
126 const PipelineStatusCB& error_cb, 118 const PipelineStatusCB& error_cb,
127 const PipelineStatusCB& start_cb); 119 const PipelineStatusCB& start_cb);
128 120
129 // Asynchronously stops the pipeline and resets it to an uninitialized state. 121 // Asynchronously stops the pipeline, executing |stop_cb| when completed.
130 // 122 //
131 // If provided, |stop_cb| will be executed when the pipeline has been 123 // Clients can delete the pipeline after |stop_cb| runs.
132 // completely torn down and reset to an uninitialized state. It is acceptable
133 // to call Start() again once the callback has finished executing.
134 //
135 // Stop() must be called before destroying the pipeline. Clients can
136 // determine whether Stop() must be called by checking IsRunning().
137 //
138 // It is an error to call this method if the pipeline has not started.
139 //
140 // TODO(scherkus): ideally clients would destroy the pipeline after calling
141 // Stop() and create a new pipeline as needed.
142 void Stop(const base::Closure& stop_cb); 124 void Stop(const base::Closure& stop_cb);
143 125
144 // Attempt to seek to the position specified by time. |seek_cb| will be 126 // Attempt to seek to the position specified by time. |seek_cb| will be
145 // executed when the all filters in the pipeline have processed the seek. 127 // executed when the all filters in the pipeline have processed the seek.
146 // 128 //
147 // Clients are expected to call GetMediaTime() to check whether the seek 129 // Clients are expected to call GetMediaTime() to check whether the seek
148 // succeeded. 130 // succeeded.
149 // 131 //
150 // It is an error to call this method if the pipeline has not started. 132 // It is an error to call this method if the pipeline has not started.
151 void Seek(base::TimeDelta time, const PipelineStatusCB& seek_cb); 133 void Seek(base::TimeDelta time, const PipelineStatusCB& seek_cb);
152 134
153 // Returns true if the pipeline has been started via Start(). If IsRunning() 135 // Returns true if the pipeline has been started via Start(). If IsRunning()
154 // returns true, it is expected that Stop() will be called before destroying 136 // returns true, it is expected that Stop() will be called before destroying
155 // the pipeline. 137 // the pipeline.
156 bool IsRunning() const; 138 bool IsRunning() const;
157 139
158 // Returns true if the pipeline has been started and fully initialized to a
159 // point where playback controls will be respected. Note that it is possible
160 // for a pipeline to be started but not initialized (i.e., an error occurred).
161 bool IsInitialized() const;
162
163 // Returns true if the media has audio. 140 // Returns true if the media has audio.
164 bool HasAudio() const; 141 bool HasAudio() const;
165 142
166 // Returns true if the media has video. 143 // Returns true if the media has video.
167 bool HasVideo() const; 144 bool HasVideo() const;
168 145
169 // Gets the current playback rate of the pipeline. When the pipeline is 146 // Gets the current playback rate of the pipeline. When the pipeline is
170 // started, the playback rate will be 0.0f. A rate of 1.0f indicates 147 // started, the playback rate will be 0.0f. A rate of 1.0f indicates
171 // that the pipeline is rendering the media at the standard rate. Valid 148 // that the pipeline is rendering the media at the standard rate. Valid
172 // values for playback rate are >= 0.0f. 149 // values for playback rate are >= 0.0f.
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 kInitAudioRenderer, 215 kInitAudioRenderer,
239 kInitVideoDecoder, 216 kInitVideoDecoder,
240 kInitVideoRenderer, 217 kInitVideoRenderer,
241 kPausing, 218 kPausing,
242 kSeeking, 219 kSeeking,
243 kFlushing, 220 kFlushing,
244 kStarting, 221 kStarting,
245 kStarted, 222 kStarted,
246 kStopping, 223 kStopping,
247 kStopped, 224 kStopped,
248 kError,
249 }; 225 };
250 226
251 // Updates |state_|. All state transitions should use this call. 227 // Updates |state_|. All state transitions should use this call.
252 void SetState(State next_state); 228 void SetState(State next_state);
253 229
254 // Simple method used to make sure the pipeline is running normally. 230 // Simple method used to make sure the pipeline is running normally.
255 bool IsPipelineOk(); 231 bool IsPipelineOk();
256 232
257 // Helper method to tell whether we are stopped or in error. 233 // Helper method to tell whether we are stopped or in error.
258 bool IsPipelineStopped(); 234 bool IsPipelineStopped();
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 // as a result of calling Start() or InitializationComplete() that advances 310 // as a result of calling Start() or InitializationComplete() that advances
335 // initialization to the next state. It works as a hub of state transition for 311 // initialization to the next state. It works as a hub of state transition for
336 // initialization. One stage communicates its status to the next through 312 // initialization. One stage communicates its status to the next through
337 // |last_stage_status|. 313 // |last_stage_status|.
338 void InitializeTask(PipelineStatus last_stage_status); 314 void InitializeTask(PipelineStatus last_stage_status);
339 315
340 // Stops and destroys all filters, placing the pipeline in the kStopped state. 316 // Stops and destroys all filters, placing the pipeline in the kStopped state.
341 void StopTask(const base::Closure& stop_cb); 317 void StopTask(const base::Closure& stop_cb);
342 318
343 // Carries out stopping and destroying all filters, placing the pipeline in 319 // Carries out stopping and destroying all filters, placing the pipeline in
344 // the kError state. 320 // the kStopped state.
345 void ErrorChangedTask(PipelineStatus error); 321 void ErrorChangedTask(PipelineStatus error);
346 322
347 // Carries out notifying filters that the playback rate has changed. 323 // Carries out notifying filters that the playback rate has changed.
348 void PlaybackRateChangedTask(float playback_rate); 324 void PlaybackRateChangedTask(float playback_rate);
349 325
350 // Carries out notifying filters that the volume has changed. 326 // Carries out notifying filters that the volume has changed.
351 void VolumeChangedTask(float volume); 327 void VolumeChangedTask(float volume);
352 328
353 // Carries out notifying filters that we are seeking to a new timestamp. 329 // Carries out notifying filters that we are seeking to a new timestamp.
354 void SeekTask(base::TimeDelta time, const PipelineStatusCB& seek_cb); 330 void SeekTask(base::TimeDelta time, const PipelineStatusCB& seek_cb);
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 412
437 // Lock used to serialize access for the following data members. 413 // Lock used to serialize access for the following data members.
438 mutable base::Lock lock_; 414 mutable base::Lock lock_;
439 415
440 // Whether or not the pipeline is running. 416 // Whether or not the pipeline is running.
441 bool running_; 417 bool running_;
442 418
443 // Whether or not the pipeline is in transition for a seek operation. 419 // Whether or not the pipeline is in transition for a seek operation.
444 bool seek_pending_; 420 bool seek_pending_;
445 421
446 // Whether or not the pipeline is pending a stop operation.
447 bool stop_pending_;
scherkus (not reviewing) 2012/08/08 02:20:56 this is equivalent to inspecting stop_cb_
448
449 // Whether or not the pipeline is perform a stop operation. 422 // Whether or not the pipeline is perform a stop operation.
450 bool tearing_down_; 423 bool tearing_down_;
451 424
452 // Whether or not an error triggered the teardown.
453 bool error_caused_teardown_;
scherkus (not reviewing) 2012/08/08 02:20:56 this is equivalent to (status_ != PIPELINE_OK)
454
455 // Whether or not a playback rate change should be done once seeking is done. 425 // Whether or not a playback rate change should be done once seeking is done.
456 bool playback_rate_change_pending_; 426 bool playback_rate_change_pending_;
457 427
458 // Amount of available buffered data. Set by filters. 428 // Amount of available buffered data. Set by filters.
459 Ranges<int64> buffered_byte_ranges_; 429 Ranges<int64> buffered_byte_ranges_;
460 Ranges<base::TimeDelta> buffered_time_ranges_; 430 Ranges<base::TimeDelta> buffered_time_ranges_;
461 431
462 // True when AddBufferedByteRange() has been called more recently than 432 // True when AddBufferedByteRange() has been called more recently than
463 // DidLoadingProgress(). 433 // DidLoadingProgress().
464 mutable bool did_loading_progress_; 434 mutable bool did_loading_progress_;
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
555 base::Time creation_time_; 525 base::Time creation_time_;
556 526
557 scoped_ptr<SerialRunner> pending_callbacks_; 527 scoped_ptr<SerialRunner> pending_callbacks_;
558 528
559 DISALLOW_COPY_AND_ASSIGN(Pipeline); 529 DISALLOW_COPY_AND_ASSIGN(Pipeline);
560 }; 530 };
561 531
562 } // namespace media 532 } // namespace media
563 533
564 #endif // MEDIA_BASE_PIPELINE_H_ 534 #endif // MEDIA_BASE_PIPELINE_H_
OLDNEW
« no previous file with comments | « media/base/media_log.cc ('k') | media/base/pipeline.cc » ('j') | media/base/pipeline_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698