| 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" |
| 11 #include "base/synchronization/condition_variable.h" | 11 #include "base/synchronization/condition_variable.h" |
| 12 #include "base/synchronization/lock.h" | 12 #include "base/synchronization/lock.h" |
| 13 #include "base/threading/thread_checker.h" | 13 #include "base/threading/thread_checker.h" |
| 14 #include "base/time/default_tick_clock.h" | 14 #include "base/time/default_tick_clock.h" |
| 15 #include "media/base/audio_renderer.h" | 15 #include "media/base/audio_renderer.h" |
| 16 #include "media/base/buffering_state.h" |
| 16 #include "media/base/demuxer.h" | 17 #include "media/base/demuxer.h" |
| 17 #include "media/base/media_export.h" | 18 #include "media/base/media_export.h" |
| 18 #include "media/base/pipeline_status.h" | 19 #include "media/base/pipeline_status.h" |
| 19 #include "media/base/ranges.h" | 20 #include "media/base/ranges.h" |
| 20 #include "media/base/serial_runner.h" | 21 #include "media/base/serial_runner.h" |
| 21 #include "ui/gfx/size.h" | 22 #include "ui/gfx/size.h" |
| 22 | 23 |
| 23 namespace base { | 24 namespace base { |
| 24 class SingleThreadTaskRunner; | 25 class SingleThreadTaskRunner; |
| 25 class TimeDelta; | 26 class TimeDelta; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 51 // machine to perform asynchronous initialization, pausing, seeking and playing. | 52 // machine to perform asynchronous initialization, pausing, seeking and playing. |
| 52 // | 53 // |
| 53 // Here's a state diagram that describes the lifetime of this object. | 54 // Here's a state diagram that describes the lifetime of this object. |
| 54 // | 55 // |
| 55 // [ *Created ] [ Any State ] | 56 // [ *Created ] [ Any State ] |
| 56 // | Start() | Stop() / SetError() | 57 // | Start() | Stop() / SetError() |
| 57 // V V | 58 // V V |
| 58 // [ InitXXX (for each filter) ] [ Stopping ] | 59 // [ InitXXX (for each filter) ] [ Stopping ] |
| 59 // | | | 60 // | | |
| 60 // V V | 61 // V V |
| 61 // [ InitPreroll ] [ Stopped ] | 62 // [ InitPrerolling ] [ Stopped ] |
| 62 // | | 63 // | |
| 63 // V | 64 // V |
| 64 // [ Starting ] <-- [ Seeking ] | 65 // [ Playing ] <-- [ Seeking ] |
| 65 // | ^ | 66 // | ^ |
| 66 // V | | 67 // `---------------' |
| 67 // [ Started ] ----------' | 68 // Seek() |
| 68 // Seek() | |
| 69 // | 69 // |
| 70 // Initialization is a series of state transitions from "Created" through each | 70 // Initialization is a series of state transitions from "Created" through each |
| 71 // filter initialization state. When all filter initialization states have | 71 // filter initialization state. When all filter initialization states have |
| 72 // completed, we are implicitly in a "Paused" state. At that point we simulate | 72 // completed, we are implicitly in a "Paused" state. At that point we simulate |
| 73 // a Seek() to the beginning of the media to give filters a chance to preroll. | 73 // a Seek() to the beginning of the media to give filters a chance to preroll. |
| 74 // From then on the normal Seek() transitions are carried out and we start | 74 // From then on the normal Seek() transitions are carried out and we start |
| 75 // playing the media. | 75 // playing the media. |
| 76 // | 76 // |
| 77 // If any error ever happens, this object will transition to the "Error" state | 77 // If any error ever happens, this object will transition to the "Error" state |
| 78 // from any state. If Stop() is ever called, this object will transition to | 78 // from any state. If Stop() is ever called, this object will transition to |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 friend class MediaLog; | 187 friend class MediaLog; |
| 188 | 188 |
| 189 // Pipeline states, as described above. | 189 // Pipeline states, as described above. |
| 190 enum State { | 190 enum State { |
| 191 kCreated, | 191 kCreated, |
| 192 kInitDemuxer, | 192 kInitDemuxer, |
| 193 kInitAudioRenderer, | 193 kInitAudioRenderer, |
| 194 kInitVideoRenderer, | 194 kInitVideoRenderer, |
| 195 kInitPrerolling, | 195 kInitPrerolling, |
| 196 kSeeking, | 196 kSeeking, |
| 197 kStarting, | 197 kPlaying, |
| 198 kStarted, | |
| 199 kStopping, | 198 kStopping, |
| 200 kStopped, | 199 kStopped, |
| 201 }; | 200 }; |
| 202 | 201 |
| 203 // Updates |state_|. All state transitions should use this call. | 202 // Updates |state_|. All state transitions should use this call. |
| 204 void SetState(State next_state); | 203 void SetState(State next_state); |
| 205 | 204 |
| 206 static const char* GetStateString(State state); | 205 static const char* GetStateString(State state); |
| 207 State GetNextState() const; | 206 State GetNextState() const; |
| 208 | 207 |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 void DoInitialPreroll(const PipelineStatusCB& done_cb); | 297 void DoInitialPreroll(const PipelineStatusCB& done_cb); |
| 299 | 298 |
| 300 // Initiates an asynchronous pause-flush-seek-preroll call sequence | 299 // Initiates an asynchronous pause-flush-seek-preroll call sequence |
| 301 // executing |done_cb| with the final status when completed. | 300 // executing |done_cb| with the final status when completed. |
| 302 // | 301 // |
| 303 // TODO(scherkus): Prerolling should be separate from seeking so we can report | 302 // TODO(scherkus): Prerolling should be separate from seeking so we can report |
| 304 // finer grained ready states (HAVE_CURRENT_DATA vs. HAVE_FUTURE_DATA) | 303 // finer grained ready states (HAVE_CURRENT_DATA vs. HAVE_FUTURE_DATA) |
| 305 // indepentent from seeking. | 304 // indepentent from seeking. |
| 306 void DoSeek(base::TimeDelta seek_timestamp, const PipelineStatusCB& done_cb); | 305 void DoSeek(base::TimeDelta seek_timestamp, const PipelineStatusCB& done_cb); |
| 307 | 306 |
| 308 // Updates playback rate and volume and initiates an asynchronous play call | |
| 309 // sequence executing |done_cb| with the final status when completed. | |
| 310 void DoPlay(const PipelineStatusCB& done_cb); | |
| 311 | |
| 312 // Initiates an asynchronous pause-flush-stop call sequence executing | 307 // Initiates an asynchronous pause-flush-stop call sequence executing |
| 313 // |done_cb| when completed. | 308 // |done_cb| when completed. |
| 314 void DoStop(const PipelineStatusCB& done_cb); | 309 void DoStop(const PipelineStatusCB& done_cb); |
| 315 void OnStopCompleted(PipelineStatus status); | 310 void OnStopCompleted(PipelineStatus status); |
| 316 | 311 |
| 317 void OnAudioUnderflow(); | 312 void OnAudioUnderflow(); |
| 318 | 313 |
| 314 // Collection of callback methods and helpers for tracking changes in |
| 315 // buffering state and transition from paused/underflow states and playing |
| 316 // states. |
| 317 // |
| 318 // While in the kPlaying state: |
| 319 // - A waiting to non-waiting transition indicates preroll has completed |
| 320 // and StartPlayback() should be called |
| 321 // - A non-waiting to waiting transition indicates underflow has occurred |
| 322 // and StartWaitingForEnoughData() should be called |
| 323 void BufferingStateChanged(BufferingState* buffering_state, |
| 324 BufferingState new_buffering_state); |
| 325 bool WaitingForEnoughData() const; |
| 326 void StartWaitingForEnoughData(); |
| 327 void StartPlayback(); |
| 328 |
| 319 void StartClockIfWaitingForTimeUpdate_Locked(); | 329 void StartClockIfWaitingForTimeUpdate_Locked(); |
| 320 | 330 |
| 321 // Task runner used to execute pipeline tasks. | 331 // Task runner used to execute pipeline tasks. |
| 322 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 332 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 323 | 333 |
| 324 // MediaLog to which to log events. | 334 // MediaLog to which to log events. |
| 325 scoped_refptr<MediaLog> media_log_; | 335 scoped_refptr<MediaLog> media_log_; |
| 326 | 336 |
| 327 // Lock used to serialize access for the following data members. | 337 // Lock used to serialize access for the following data members. |
| 328 mutable base::Lock lock_; | 338 mutable base::Lock lock_; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 // |task_runner_|. | 380 // |task_runner_|. |
| 371 | 381 |
| 372 // Member that tracks the current state. | 382 // Member that tracks the current state. |
| 373 State state_; | 383 State state_; |
| 374 | 384 |
| 375 // Whether we've received the audio/video/text ended events. | 385 // Whether we've received the audio/video/text ended events. |
| 376 bool audio_ended_; | 386 bool audio_ended_; |
| 377 bool video_ended_; | 387 bool video_ended_; |
| 378 bool text_ended_; | 388 bool text_ended_; |
| 379 | 389 |
| 390 BufferingState audio_buffering_state_; |
| 391 BufferingState video_buffering_state_; |
| 392 |
| 380 // Temporary callback used for Start() and Seek(). | 393 // Temporary callback used for Start() and Seek(). |
| 381 PipelineStatusCB seek_cb_; | 394 PipelineStatusCB seek_cb_; |
| 382 | 395 |
| 383 // Temporary callback used for Stop(). | 396 // Temporary callback used for Stop(). |
| 384 base::Closure stop_cb_; | 397 base::Closure stop_cb_; |
| 385 | 398 |
| 386 // Permanent callbacks passed in via Start(). | 399 // Permanent callbacks passed in via Start(). |
| 387 base::Closure ended_cb_; | 400 base::Closure ended_cb_; |
| 388 PipelineStatusCB error_cb_; | 401 PipelineStatusCB error_cb_; |
| 389 PipelineMetadataCB metadata_cb_; | 402 PipelineMetadataCB metadata_cb_; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 411 scoped_ptr<SerialRunner> pending_callbacks_; | 424 scoped_ptr<SerialRunner> pending_callbacks_; |
| 412 | 425 |
| 413 base::ThreadChecker thread_checker_; | 426 base::ThreadChecker thread_checker_; |
| 414 | 427 |
| 415 DISALLOW_COPY_AND_ASSIGN(Pipeline); | 428 DISALLOW_COPY_AND_ASSIGN(Pipeline); |
| 416 }; | 429 }; |
| 417 | 430 |
| 418 } // namespace media | 431 } // namespace media |
| 419 | 432 |
| 420 #endif // MEDIA_BASE_PIPELINE_H_ | 433 #endif // MEDIA_BASE_PIPELINE_H_ |
| OLD | NEW |