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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 // |ended_cb| will be executed whenever the media reaches the end. | 109 // |ended_cb| will be executed whenever the media reaches the end. |
110 // |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 |
111 // been reported already through another callback. | 111 // been reported already through another callback. |
112 // | 112 // |
113 // 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. |
114 void Start(scoped_ptr<FilterCollection> filter_collection, | 114 void Start(scoped_ptr<FilterCollection> filter_collection, |
115 const PipelineStatusCB& ended_cb, | 115 const PipelineStatusCB& ended_cb, |
116 const PipelineStatusCB& error_cb, | 116 const PipelineStatusCB& error_cb, |
117 const PipelineStatusCB& start_cb); | 117 const PipelineStatusCB& start_cb); |
118 | 118 |
119 // Asynchronously stops the pipeline and resets it to an uninitialized state. | 119 // Asynchronously stops the pipeline, executing |stop_cb| when the pipeline |
| 120 // teardown has completed. |
120 // | 121 // |
121 // If provided, |stop_cb| will be executed when the pipeline has been | 122 // Stop() must complete before destroying the pipeline. It it permissible to |
122 // completely torn down and reset to an uninitialized state. It is acceptable | 123 // call Stop() at any point during the lifetime of the pipeline. |
123 // to call Start() again once the callback has finished executing. | |
124 // | |
125 // Stop() must be called before destroying the pipeline. Clients can | |
126 // determine whether Stop() must be called by checking IsRunning(). | |
127 // | |
128 // It is an error to call this method if the pipeline has not started. | |
129 // | |
130 // TODO(scherkus): ideally clients would destroy the pipeline after calling | |
131 // Stop() and create a new pipeline as needed. | |
132 void Stop(const base::Closure& stop_cb); | 124 void Stop(const base::Closure& stop_cb); |
133 | 125 |
134 // 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 |
135 // 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. |
136 // | 128 // |
137 // Clients are expected to call GetMediaTime() to check whether the seek | 129 // Clients are expected to call GetMediaTime() to check whether the seek |
138 // succeeded. | 130 // succeeded. |
139 // | 131 // |
140 // 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. |
141 void Seek(base::TimeDelta time, const PipelineStatusCB& seek_cb); | 133 void Seek(base::TimeDelta time, const PipelineStatusCB& seek_cb); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 // be 0. | 186 // be 0. |
195 void GetNaturalVideoSize(gfx::Size* out_size) const; | 187 void GetNaturalVideoSize(gfx::Size* out_size) const; |
196 | 188 |
197 // Return true if loading progress has been made since the last time this | 189 // Return true if loading progress has been made since the last time this |
198 // method was called. | 190 // method was called. |
199 bool DidLoadingProgress() const; | 191 bool DidLoadingProgress() const; |
200 | 192 |
201 // Gets the current pipeline statistics. | 193 // Gets the current pipeline statistics. |
202 PipelineStatistics GetStatistics() const; | 194 PipelineStatistics GetStatistics() const; |
203 | 195 |
204 // TODO(scherkus): Remove IsInitializedForTesting() after stop/error teardown | |
205 // paths are sane, see http://crbug.com/110228 | |
206 bool IsInitializedForTesting(); | |
207 void SetClockForTesting(Clock* clock); | 196 void SetClockForTesting(Clock* clock); |
208 void SetErrorForTesting(PipelineStatus status); | 197 void SetErrorForTesting(PipelineStatus status); |
209 | 198 |
210 private: | 199 private: |
211 FRIEND_TEST_ALL_PREFIXES(PipelineTest, GetBufferedTimeRanges); | 200 FRIEND_TEST_ALL_PREFIXES(PipelineTest, GetBufferedTimeRanges); |
212 FRIEND_TEST_ALL_PREFIXES(PipelineTest, DisableAudioRenderer); | 201 FRIEND_TEST_ALL_PREFIXES(PipelineTest, DisableAudioRenderer); |
213 FRIEND_TEST_ALL_PREFIXES(PipelineTest, DisableAudioRendererDuringInit); | 202 FRIEND_TEST_ALL_PREFIXES(PipelineTest, DisableAudioRendererDuringInit); |
214 FRIEND_TEST_ALL_PREFIXES(PipelineTest, EndedCallback); | 203 FRIEND_TEST_ALL_PREFIXES(PipelineTest, EndedCallback); |
215 FRIEND_TEST_ALL_PREFIXES(PipelineTest, AudioStreamShorterThanVideo); | 204 FRIEND_TEST_ALL_PREFIXES(PipelineTest, AudioStreamShorterThanVideo); |
216 friend class MediaLog; | 205 friend class MediaLog; |
(...skipping 10 matching lines...) Expand all Loading... |
227 kInitAudioRenderer, | 216 kInitAudioRenderer, |
228 kInitVideoDecoder, | 217 kInitVideoDecoder, |
229 kInitVideoRenderer, | 218 kInitVideoRenderer, |
230 kPausing, | 219 kPausing, |
231 kSeeking, | 220 kSeeking, |
232 kFlushing, | 221 kFlushing, |
233 kStarting, | 222 kStarting, |
234 kStarted, | 223 kStarted, |
235 kStopping, | 224 kStopping, |
236 kStopped, | 225 kStopped, |
237 kError, | |
238 }; | 226 }; |
239 | 227 |
240 // Updates |state_|. All state transitions should use this call. | 228 // Updates |state_|. All state transitions should use this call. |
241 void SetState(State next_state); | 229 void SetState(State next_state); |
242 | 230 |
243 // Simple method used to make sure the pipeline is running normally. | 231 // Simple method used to make sure the pipeline is running normally. |
244 bool IsPipelineOk(); | 232 bool IsPipelineOk(); |
245 | 233 |
246 // Helper method to tell whether we are stopped or in error. | |
247 bool IsPipelineStopped(); | |
248 | |
249 // Helper method to tell whether we are in transition to stop state. | |
250 bool IsPipelineTearingDown(); | |
251 | |
252 // Helper method to tell whether we are in transition to seek state. | 234 // Helper method to tell whether we are in transition to seek state. |
253 bool IsPipelineSeeking(); | 235 bool IsPipelineSeeking(); |
254 | 236 |
255 // Helper method to execute callback from Start() and reset | 237 // Helper method to execute callback from Start() and reset |
256 // |filter_collection_|. Called when initialization completes | 238 // |filter_collection_|. Called when initialization completes |
257 // normally or when pipeline is stopped or error occurs during | 239 // normally or when pipeline is stopped or error occurs during |
258 // initialization. | 240 // initialization. |
259 void FinishInitialization(); | 241 void FinishInitialization(); |
260 | 242 |
261 // Returns true if the given state is one that transitions to a new state | 243 // Returns true if the given state is one that transitions to a new state |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 // as a result of calling Start() or InitializationComplete() that advances | 303 // as a result of calling Start() or InitializationComplete() that advances |
322 // initialization to the next state. It works as a hub of state transition for | 304 // initialization to the next state. It works as a hub of state transition for |
323 // initialization. One stage communicates its status to the next through | 305 // initialization. One stage communicates its status to the next through |
324 // |last_stage_status|. | 306 // |last_stage_status|. |
325 void InitializeTask(PipelineStatus last_stage_status); | 307 void InitializeTask(PipelineStatus last_stage_status); |
326 | 308 |
327 // Stops and destroys all filters, placing the pipeline in the kStopped state. | 309 // Stops and destroys all filters, placing the pipeline in the kStopped state. |
328 void StopTask(const base::Closure& stop_cb); | 310 void StopTask(const base::Closure& stop_cb); |
329 | 311 |
330 // Carries out stopping and destroying all filters, placing the pipeline in | 312 // Carries out stopping and destroying all filters, placing the pipeline in |
331 // the kError state. | 313 // the kStopped state. |
332 void ErrorChangedTask(PipelineStatus error); | 314 void ErrorChangedTask(PipelineStatus error); |
333 | 315 |
334 // Carries out notifying filters that the playback rate has changed. | 316 // Carries out notifying filters that the playback rate has changed. |
335 void PlaybackRateChangedTask(float playback_rate); | 317 void PlaybackRateChangedTask(float playback_rate); |
336 | 318 |
337 // Carries out notifying filters that the volume has changed. | 319 // Carries out notifying filters that the volume has changed. |
338 void VolumeChangedTask(float volume); | 320 void VolumeChangedTask(float volume); |
339 | 321 |
340 // Carries out notifying filters that we are seeking to a new timestamp. | 322 // Carries out notifying filters that we are seeking to a new timestamp. |
341 void SeekTask(base::TimeDelta time, const PipelineStatusCB& seek_cb); | 323 void SeekTask(base::TimeDelta time, const PipelineStatusCB& seek_cb); |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
428 | 410 |
429 // Whether or not the pipeline is running. | 411 // Whether or not the pipeline is running. |
430 bool running_; | 412 bool running_; |
431 | 413 |
432 // Whether or not the pipeline is in transition for a seek operation. | 414 // Whether or not the pipeline is in transition for a seek operation. |
433 bool seek_pending_; | 415 bool seek_pending_; |
434 | 416 |
435 // Whether or not the pipeline is perform a stop operation. | 417 // Whether or not the pipeline is perform a stop operation. |
436 bool tearing_down_; | 418 bool tearing_down_; |
437 | 419 |
438 // Whether or not an error triggered the teardown. | |
439 bool error_caused_teardown_; | |
440 | |
441 // Whether or not a playback rate change should be done once seeking is done. | 420 // Whether or not a playback rate change should be done once seeking is done. |
442 bool playback_rate_change_pending_; | 421 bool playback_rate_change_pending_; |
443 | 422 |
444 // Amount of available buffered data. Set by filters. | 423 // Amount of available buffered data. Set by filters. |
445 Ranges<int64> buffered_byte_ranges_; | 424 Ranges<int64> buffered_byte_ranges_; |
446 Ranges<base::TimeDelta> buffered_time_ranges_; | 425 Ranges<base::TimeDelta> buffered_time_ranges_; |
447 | 426 |
448 // True when AddBufferedByteRange() has been called more recently than | 427 // True when AddBufferedByteRange() has been called more recently than |
449 // DidLoadingProgress(). | 428 // DidLoadingProgress(). |
450 mutable bool did_loading_progress_; | 429 mutable bool did_loading_progress_; |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
545 base::Time creation_time_; | 524 base::Time creation_time_; |
546 | 525 |
547 scoped_ptr<SerialRunner> pending_callbacks_; | 526 scoped_ptr<SerialRunner> pending_callbacks_; |
548 | 527 |
549 DISALLOW_COPY_AND_ASSIGN(Pipeline); | 528 DISALLOW_COPY_AND_ASSIGN(Pipeline); |
550 }; | 529 }; |
551 | 530 |
552 } // namespace media | 531 } // namespace media |
553 | 532 |
554 #endif // MEDIA_BASE_PIPELINE_H_ | 533 #endif // MEDIA_BASE_PIPELINE_H_ |
OLD | NEW |