Chromium Code Reviews| 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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 76 // [ Seeking (for each filter) ] <--------[ Flushing (for each filter) ] | 76 // [ Seeking (for each filter) ] <--------[ Flushing (for each filter) ] |
| 77 // | if Seek ^ | 77 // | if Seek ^ |
| 78 // V | | 78 // V | |
| 79 // [ Starting (for each filter) ] | | 79 // [ Starting (for each filter) ] | |
| 80 // | | | 80 // | | |
| 81 // V Seek()/Stop() | | 81 // V Seek()/Stop() | |
| 82 // [ Started ] -------------------------> [ Pausing (for each filter) ] | 82 // [ Started ] -------------------------> [ Pausing (for each filter) ] |
| 83 // ^ SetError() | 83 // ^ SetError() |
| 84 // | | 84 // | |
| 85 // [ Any State Other Than InitXXX ] | 85 // [ Any State Other Than InitXXX ] |
| 86 | |
| 87 // | 86 // |
| 88 // Initialization is a series of state transitions from "Created" through each | 87 // Initialization is a series of state transitions from "Created" through each |
| 89 // filter initialization state. When all filter initialization states have | 88 // filter initialization state. When all filter initialization states have |
| 90 // completed, we are implicitly in a "Paused" state. At that point we simulate | 89 // 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. | 90 // 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 | 91 // From then on the normal Seek() transitions are carried out and we start |
| 93 // playing the media. | 92 // playing the media. |
| 94 // | 93 // |
| 95 // If any error ever happens, this object will transition to the "Error" state | 94 // If any error ever happens, this object will transition to the "Error" state |
| 96 // from any state. If Stop() is ever called, this object will transition to | 95 // from any state. If Stop() is ever called, this object will transition to |
| 97 // "Stopped" state. | 96 // "Stopped" state. |
| 98 class MEDIA_EXPORT Pipeline | 97 class MEDIA_EXPORT Pipeline |
| 99 : public base::RefCountedThreadSafe<Pipeline>, | 98 : public base::RefCountedThreadSafe<Pipeline>, |
| 100 public DemuxerHost { | 99 public DemuxerHost { |
| 101 public: | 100 public: |
| 102 // Constructs a media pipeline that will execute on |message_loop|. | 101 // Constructs a media pipeline that will execute on |message_loop|. |
| 103 Pipeline(MessageLoop* message_loop, MediaLog* media_log); | 102 Pipeline(MessageLoop* message_loop, MediaLog* media_log); |
| 104 | 103 |
| 105 // Build a pipeline to using the given filter collection to construct a filter | 104 // Build a pipeline to using the given filter collection to construct a filter |
| 106 // chain. | 105 // chain, executing |start_cb| when initialization has completed. |
| 107 // | 106 // |
| 108 // Pipeline initialization is an inherently asynchronous process. Clients can | 107 // The following permanent callbacks will be executed as follows up until |
| 109 // either poll the IsInitialized() method (discouraged) or optionally pass in | 108 // Stop() has completed: |
|
Ami GONE FROM CHROMIUM
2012/08/09 20:46:23
I thought error during Stop() doesn't fire error_c
scherkus (not reviewing)
2012/08/09 21:02:59
You are correct but as discussed offline this is a
| |
| 110 // |start_cb|, which will be executed when initialization completes. | |
| 111 // | |
| 112 // The following permanent callbacks will be executed as follows: | |
| 113 // |start_cb_| will be executed when Start is done (successfully or not). | |
| 114 // |ended_cb| will be executed whenever the media reaches the end. | 109 // |ended_cb| will be executed whenever the media reaches the end. |
| 115 // |error_cb_| will be executed whenever an error occurs but hasn't | 110 // |error_cb| will be executed whenever an error occurs but hasn't |
| 116 // been reported already through another callback. | 111 // been reported already through another callback. |
| 117 // | 112 // |
| 118 // These callbacks are only executed after Start() has been called and until | |
| 119 // Stop() has completed. | |
| 120 // | |
| 121 // 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. |
| 122 // | |
| 123 // TODO(scherkus): remove IsInitialized() and force clients to use callbacks. | |
| 124 void Start(scoped_ptr<FilterCollection> filter_collection, | 114 void Start(scoped_ptr<FilterCollection> filter_collection, |
| 125 const PipelineStatusCB& ended_cb, | 115 const PipelineStatusCB& ended_cb, |
| 126 const PipelineStatusCB& error_cb, | 116 const PipelineStatusCB& error_cb, |
| 127 const PipelineStatusCB& start_cb); | 117 const PipelineStatusCB& start_cb); |
| 128 | 118 |
| 129 // Asynchronously stops the pipeline and resets it to an uninitialized state. | 119 // Asynchronously stops the pipeline and resets it to an uninitialized state. |
| 130 // | 120 // |
| 131 // If provided, |stop_cb| will be executed when the pipeline has been | 121 // If provided, |stop_cb| will be executed when the pipeline has been |
| 132 // completely torn down and reset to an uninitialized state. It is acceptable | 122 // completely torn down and reset to an uninitialized state. It is acceptable |
| 133 // to call Start() again once the callback has finished executing. | 123 // to call Start() again once the callback has finished executing. |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 148 // succeeded. | 138 // succeeded. |
| 149 // | 139 // |
| 150 // It is an error to call this method if the pipeline has not started. | 140 // It is an error to call this method if the pipeline has not started. |
| 151 void Seek(base::TimeDelta time, const PipelineStatusCB& seek_cb); | 141 void Seek(base::TimeDelta time, const PipelineStatusCB& seek_cb); |
| 152 | 142 |
| 153 // Returns true if the pipeline has been started via Start(). If IsRunning() | 143 // 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 | 144 // returns true, it is expected that Stop() will be called before destroying |
| 155 // the pipeline. | 145 // the pipeline. |
| 156 bool IsRunning() const; | 146 bool IsRunning() const; |
| 157 | 147 |
| 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. | 148 // Returns true if the media has audio. |
| 164 bool HasAudio() const; | 149 bool HasAudio() const; |
| 165 | 150 |
| 166 // Returns true if the media has video. | 151 // Returns true if the media has video. |
| 167 bool HasVideo() const; | 152 bool HasVideo() const; |
| 168 | 153 |
| 169 // Gets the current playback rate of the pipeline. When the pipeline is | 154 // 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 | 155 // 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 | 156 // that the pipeline is rendering the media at the standard rate. Valid |
| 172 // values for playback rate are >= 0.0f. | 157 // values for playback rate are >= 0.0f. |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 209 // be 0. | 194 // be 0. |
| 210 void GetNaturalVideoSize(gfx::Size* out_size) const; | 195 void GetNaturalVideoSize(gfx::Size* out_size) const; |
| 211 | 196 |
| 212 // Return true if loading progress has been made since the last time this | 197 // Return true if loading progress has been made since the last time this |
| 213 // method was called. | 198 // method was called. |
| 214 bool DidLoadingProgress() const; | 199 bool DidLoadingProgress() const; |
| 215 | 200 |
| 216 // Gets the current pipeline statistics. | 201 // Gets the current pipeline statistics. |
| 217 PipelineStatistics GetStatistics() const; | 202 PipelineStatistics GetStatistics() const; |
| 218 | 203 |
| 204 // TODO(scherkus): Remove IsInitializedForTesting() after stop/error teardown | |
| 205 // paths are sane, see http://crbug.com/110228 | |
| 206 bool IsInitializedForTesting(); | |
|
scherkus (not reviewing)
2012/08/09 19:27:10
FYI this gets removed in follow-up CL http://coder
| |
| 219 void SetClockForTesting(Clock* clock); | 207 void SetClockForTesting(Clock* clock); |
| 220 void SetErrorForTesting(PipelineStatus status); | 208 void SetErrorForTesting(PipelineStatus status); |
| 221 | 209 |
| 222 private: | 210 private: |
| 223 FRIEND_TEST_ALL_PREFIXES(PipelineTest, GetBufferedTimeRanges); | 211 FRIEND_TEST_ALL_PREFIXES(PipelineTest, GetBufferedTimeRanges); |
| 224 FRIEND_TEST_ALL_PREFIXES(PipelineTest, DisableAudioRenderer); | 212 FRIEND_TEST_ALL_PREFIXES(PipelineTest, DisableAudioRenderer); |
| 225 FRIEND_TEST_ALL_PREFIXES(PipelineTest, DisableAudioRendererDuringInit); | 213 FRIEND_TEST_ALL_PREFIXES(PipelineTest, DisableAudioRendererDuringInit); |
| 226 FRIEND_TEST_ALL_PREFIXES(PipelineTest, EndedCallback); | 214 FRIEND_TEST_ALL_PREFIXES(PipelineTest, EndedCallback); |
| 227 FRIEND_TEST_ALL_PREFIXES(PipelineTest, AudioStreamShorterThanVideo); | 215 FRIEND_TEST_ALL_PREFIXES(PipelineTest, AudioStreamShorterThanVideo); |
| 228 friend class MediaLog; | 216 friend class MediaLog; |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 254 | 242 |
| 255 // Simple method used to make sure the pipeline is running normally. | 243 // Simple method used to make sure the pipeline is running normally. |
| 256 bool IsPipelineOk(); | 244 bool IsPipelineOk(); |
| 257 | 245 |
| 258 // Helper method to tell whether we are stopped or in error. | 246 // Helper method to tell whether we are stopped or in error. |
| 259 bool IsPipelineStopped(); | 247 bool IsPipelineStopped(); |
| 260 | 248 |
| 261 // Helper method to tell whether we are in transition to stop state. | 249 // Helper method to tell whether we are in transition to stop state. |
| 262 bool IsPipelineTearingDown(); | 250 bool IsPipelineTearingDown(); |
| 263 | 251 |
| 264 // We could also be delayed by a transition during seek is performed. | |
| 265 bool IsPipelineStopPending(); | |
| 266 | |
| 267 // Helper method to tell whether we are in transition to seek state. | 252 // Helper method to tell whether we are in transition to seek state. |
| 268 bool IsPipelineSeeking(); | 253 bool IsPipelineSeeking(); |
| 269 | 254 |
| 270 // Helper method to execute callback from Start() and reset | 255 // Helper method to execute callback from Start() and reset |
| 271 // |filter_collection_|. Called when initialization completes | 256 // |filter_collection_|. Called when initialization completes |
| 272 // normally or when pipeline is stopped or error occurs during | 257 // normally or when pipeline is stopped or error occurs during |
| 273 // initialization. | 258 // initialization. |
| 274 void FinishInitialization(); | 259 void FinishInitialization(); |
| 275 | 260 |
| 276 // Returns true if the given state is one that transitions to a new state | 261 // Returns true if the given state is one that transitions to a new state |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 440 | 425 |
| 441 // Lock used to serialize access for the following data members. | 426 // Lock used to serialize access for the following data members. |
| 442 mutable base::Lock lock_; | 427 mutable base::Lock lock_; |
| 443 | 428 |
| 444 // Whether or not the pipeline is running. | 429 // Whether or not the pipeline is running. |
| 445 bool running_; | 430 bool running_; |
| 446 | 431 |
| 447 // Whether or not the pipeline is in transition for a seek operation. | 432 // Whether or not the pipeline is in transition for a seek operation. |
| 448 bool seek_pending_; | 433 bool seek_pending_; |
| 449 | 434 |
| 450 // Whether or not the pipeline is pending a stop operation. | |
| 451 bool stop_pending_; | |
| 452 | |
| 453 // Whether or not the pipeline is perform a stop operation. | 435 // Whether or not the pipeline is perform a stop operation. |
| 454 bool tearing_down_; | 436 bool tearing_down_; |
| 455 | 437 |
| 456 // Whether or not an error triggered the teardown. | 438 // Whether or not an error triggered the teardown. |
| 457 bool error_caused_teardown_; | 439 bool error_caused_teardown_; |
| 458 | 440 |
| 459 // Whether or not a playback rate change should be done once seeking is done. | 441 // Whether or not a playback rate change should be done once seeking is done. |
| 460 bool playback_rate_change_pending_; | 442 bool playback_rate_change_pending_; |
| 461 | 443 |
| 462 // Amount of available buffered data. Set by filters. | 444 // Amount of available buffered data. Set by filters. |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 563 base::Time creation_time_; | 545 base::Time creation_time_; |
| 564 | 546 |
| 565 scoped_ptr<SerialRunner> pending_callbacks_; | 547 scoped_ptr<SerialRunner> pending_callbacks_; |
| 566 | 548 |
| 567 DISALLOW_COPY_AND_ASSIGN(Pipeline); | 549 DISALLOW_COPY_AND_ASSIGN(Pipeline); |
| 568 }; | 550 }; |
| 569 | 551 |
| 570 } // namespace media | 552 } // namespace media |
| 571 | 553 |
| 572 #endif // MEDIA_BASE_PIPELINE_H_ | 554 #endif // MEDIA_BASE_PIPELINE_H_ |
| OLD | NEW |