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" |
| 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 "media/base/audio_renderer.h" | |
| 13 #include "media/base/demuxer.h" | 14 #include "media/base/demuxer.h" |
| 14 #include "media/base/filter_host.h" | 15 #include "media/base/filter_host.h" |
| 15 #include "media/base/media_export.h" | 16 #include "media/base/media_export.h" |
| 16 #include "media/base/pipeline_status.h" | 17 #include "media/base/pipeline_status.h" |
| 17 #include "media/base/ranges.h" | 18 #include "media/base/ranges.h" |
| 18 #include "ui/gfx/size.h" | 19 #include "ui/gfx/size.h" |
| 19 | 20 |
| 20 class MessageLoop; | 21 class MessageLoop; |
| 21 | 22 |
| 22 namespace base { | 23 namespace base { |
| 23 class MessageLoopProxy; | 24 class MessageLoopProxy; |
| 24 class TimeDelta; | 25 class TimeDelta; |
| 25 } | 26 } |
| 26 | 27 |
| 27 namespace media { | 28 namespace media { |
| 28 | 29 |
| 29 class AudioDecoder; | 30 class AudioDecoder; |
| 30 class AudioRenderer; | |
| 31 class Clock; | 31 class Clock; |
| 32 class Filter; | 32 class Filter; |
| 33 class FilterCollection; | 33 class FilterCollection; |
| 34 class MediaLog; | 34 class MediaLog; |
| 35 class VideoDecoder; | 35 class VideoDecoder; |
| 36 class VideoRenderer; | 36 class VideoRenderer; |
| 37 | 37 |
| 38 // Adapter for using asynchronous Pipeline methods in code that wants to run | 38 // Adapter for using asynchronous Pipeline methods in code that wants to run |
| 39 // synchronously. To use, construct an instance of this class and pass the | 39 // synchronously. To use, construct an instance of this class and pass the |
| 40 // |Callback()| to the Pipeline method requiring a callback. Then Wait() for | 40 // |Callback()| to the Pipeline method requiring a callback. Then Wait() for |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 95 // a Seek() to the beginning of the media to give filters a chance to preroll. | 95 // a Seek() to the beginning of the media to give filters a chance to preroll. |
| 96 // From then on the normal Seek() transitions are carried out and we start | 96 // From then on the normal Seek() transitions are carried out and we start |
| 97 // playing the media. | 97 // playing the media. |
| 98 // | 98 // |
| 99 // If any error ever happens, this object will transition to the "Error" state | 99 // If any error ever happens, this object will transition to the "Error" state |
| 100 // from any state. If Stop() is ever called, this object will transition to | 100 // from any state. If Stop() is ever called, this object will transition to |
| 101 // "Stopped" state. | 101 // "Stopped" state. |
| 102 class MEDIA_EXPORT Pipeline | 102 class MEDIA_EXPORT Pipeline |
| 103 : public base::RefCountedThreadSafe<Pipeline>, | 103 : public base::RefCountedThreadSafe<Pipeline>, |
| 104 public FilterHost, | 104 public FilterHost, |
| 105 public DemuxerHost { | 105 public DemuxerHost, |
| 106 public AudioRendererHost { | |
| 106 public: | 107 public: |
| 107 // Constructs a media pipeline that will execute on |message_loop|. | 108 // Constructs a media pipeline that will execute on |message_loop|. |
| 108 Pipeline(MessageLoop* message_loop, MediaLog* media_log); | 109 Pipeline(MessageLoop* message_loop, MediaLog* media_log); |
| 109 | 110 |
| 110 // Build a pipeline to using the given filter collection to construct a filter | 111 // Build a pipeline to using the given filter collection to construct a filter |
| 111 // chain. | 112 // chain. |
| 112 // | 113 // |
| 113 // Pipeline initialization is an inherently asynchronous process. Clients can | 114 // Pipeline initialization is an inherently asynchronous process. Clients can |
| 114 // either poll the IsInitialized() method (discouraged) or optionally pass in | 115 // either poll the IsInitialized() method (discouraged) or optionally pass in |
| 115 // |start_cb|, which will be executed when initialization completes. | 116 // |start_cb|, which will be executed when initialization completes. |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 294 // DemuxerHost implementaion. | 295 // DemuxerHost implementaion. |
| 295 virtual void SetDuration(base::TimeDelta duration) OVERRIDE; | 296 virtual void SetDuration(base::TimeDelta duration) OVERRIDE; |
| 296 virtual void OnDemuxerError(PipelineStatus error) OVERRIDE; | 297 virtual void OnDemuxerError(PipelineStatus error) OVERRIDE; |
| 297 | 298 |
| 298 // FilterHost implementation. | 299 // FilterHost implementation. |
| 299 virtual void SetError(PipelineStatus error) OVERRIDE; | 300 virtual void SetError(PipelineStatus error) OVERRIDE; |
| 300 virtual base::TimeDelta GetTime() const OVERRIDE; | 301 virtual base::TimeDelta GetTime() const OVERRIDE; |
| 301 virtual base::TimeDelta GetDuration() const OVERRIDE; | 302 virtual base::TimeDelta GetDuration() const OVERRIDE; |
| 302 virtual void SetNaturalVideoSize(const gfx::Size& size) OVERRIDE; | 303 virtual void SetNaturalVideoSize(const gfx::Size& size) OVERRIDE; |
| 303 virtual void NotifyEnded() OVERRIDE; | 304 virtual void NotifyEnded() OVERRIDE; |
| 304 virtual void DisableAudioRenderer() OVERRIDE; | 305 |
| 306 // AudioRendererHost implementation. | |
| 307 virtual void AudioRendererEnded() OVERRIDE; | |
| 308 virtual void AudioRendererDisabled() OVERRIDE; | |
| 305 | 309 |
| 306 // Callbacks executed by filters upon completing initialization. | 310 // Callbacks executed by filters upon completing initialization. |
| 307 void OnFilterInitialize(PipelineStatus status); | 311 void OnFilterInitialize(PipelineStatus status); |
| 308 | 312 |
| 309 // Callback executed by filters upon completing Play(), Pause(), or Stop(). | 313 // Callback executed by filters upon completing Play(), Pause(), or Stop(). |
| 310 void OnFilterStateTransition(); | 314 void OnFilterStateTransition(); |
| 311 | 315 |
| 312 // Callback executed by filters upon completing Seek(). | 316 // Callback executed by filters upon completing Seek(). |
| 313 void OnFilterStateTransitionWithStatus(PipelineStatus status); | 317 void OnFilterStateTransitionWithStatus(PipelineStatus status); |
| 314 | 318 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 352 // Carries out notifying filters that the volume has changed. | 356 // Carries out notifying filters that the volume has changed. |
| 353 void VolumeChangedTask(float volume); | 357 void VolumeChangedTask(float volume); |
| 354 | 358 |
| 355 // Carries out notifying filters that we are seeking to a new timestamp. | 359 // Carries out notifying filters that we are seeking to a new timestamp. |
| 356 void SeekTask(base::TimeDelta time, const PipelineStatusCB& seek_cb); | 360 void SeekTask(base::TimeDelta time, const PipelineStatusCB& seek_cb); |
| 357 | 361 |
| 358 // Carries out handling a notification from a filter that it has ended. | 362 // Carries out handling a notification from a filter that it has ended. |
| 359 void NotifyEndedTask(); | 363 void NotifyEndedTask(); |
| 360 | 364 |
| 361 // Carries out disabling the audio renderer. | 365 // Carries out disabling the audio renderer. |
| 362 void DisableAudioRendererTask(); | 366 void AudioRendererDisabledTask(); |
| 363 | 367 |
| 364 // Carries out advancing to the next filter during Play()/Pause()/Seek(). | 368 // Carries out advancing to the next filter during Play()/Pause()/Seek(). |
| 365 void FilterStateTransitionTask(); | 369 void FilterStateTransitionTask(); |
| 366 | 370 |
| 367 // Carries out advancing to the next teardown operation. | 371 // Carries out advancing to the next teardown operation. |
| 368 void TeardownStateTransitionTask(); | 372 void TeardownStateTransitionTask(); |
| 369 | 373 |
| 370 // Carries out stopping filter threads, deleting filters, running | 374 // Carries out stopping filter threads, deleting filters, running |
| 371 // appropriate callbacks, and setting the appropriate pipeline state | 375 // appropriate callbacks, and setting the appropriate pipeline state |
| 372 // depending on whether we performing Stop() or SetError(). | 376 // depending on whether we performing Stop() or SetError(). |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 403 // This will remove the race condition during stop between filters. | 407 // This will remove the race condition during stop between filters. |
| 404 void TearDownPipeline(); | 408 void TearDownPipeline(); |
| 405 | 409 |
| 406 // Compute the current time. Assumes that the lock has been acquired by the | 410 // Compute the current time. Assumes that the lock has been acquired by the |
| 407 // caller. | 411 // caller. |
| 408 base::TimeDelta GetCurrentTime_Locked() const; | 412 base::TimeDelta GetCurrentTime_Locked() const; |
| 409 | 413 |
| 410 // Compute the time corresponding to a byte offset. | 414 // Compute the time corresponding to a byte offset. |
| 411 base::TimeDelta TimeForByteOffset_Locked(int64 byte_offset) const; | 415 base::TimeDelta TimeForByteOffset_Locked(int64 byte_offset) const; |
| 412 | 416 |
| 413 // Initiates a Stop() on |demuxer_| & |pipeline_filter_|. |callback| | 417 // Initiates an asynchronous Pause/Flush/Play/Stop() call sequence executing |
| 414 // is called once both objects have been stopped. | 418 // |done_cb| when completed. |
| 415 void DoStop(const base::Closure& callback); | 419 void DoPause(const base::Closure& done_cb); |
| 420 void DoFlush(const base::Closure& done_cb); | |
| 421 void DoPlay(const base::Closure& done_cb); | |
| 422 void DoStop(const base::Closure& done_cb); | |
| 416 | 423 |
| 417 // Called when |demuxer_| has stopped. This method calls Stop() | 424 // Initiates an asynchronous Seek() call sequence executing |done_cb| when |
|
acolwell GONE FROM CHROMIUM
2012/07/10 16:34:37
s/done_cb/seek_cb_ since there are no done_cb para
scherkus (not reviewing)
2012/07/17 03:43:00
Done.
| |
| 418 // on |pipeline_filter_|. | 425 // completed. Seek() is separated from the other operations as we will |
| 419 void OnDemuxerStopDone(const base::Closure& callback); | 426 // prematurely terminate the call sequence if an error occurs. |
| 420 | |
| 421 // Initiates a Seek() on the |demuxer_| & |pipeline_filter_|. | |
| 422 void DoSeek(base::TimeDelta seek_timestamp); | 427 void DoSeek(base::TimeDelta seek_timestamp); |
| 423 | |
| 424 // Called when |demuxer_| finishes seeking. If seeking was successful, | |
| 425 // then Seek() is called on |pipeline_filter_|. | |
| 426 void OnDemuxerSeekDone(base::TimeDelta seek_timestamp, | 428 void OnDemuxerSeekDone(base::TimeDelta seek_timestamp, |
| 427 PipelineStatus status); | 429 PipelineStatus status); |
| 430 void OnAudioRendererSeekDone(base::TimeDelta seek_timestamp, | |
| 431 PipelineStatus status); | |
| 428 | 432 |
| 429 void OnAudioUnderflow(); | 433 void OnAudioUnderflow(); |
| 430 | 434 |
| 431 void StartClockIfWaitingForTimeUpdate_Locked(); | 435 void StartClockIfWaitingForTimeUpdate_Locked(); |
| 432 | 436 |
| 433 // Report pipeline |status| through |cb| avoiding duplicate error reporting. | 437 // Report pipeline |status| through |cb| avoiding duplicate error reporting. |
| 434 void ReportStatus(const PipelineStatusCB& cb, PipelineStatus status); | 438 void ReportStatus(const PipelineStatusCB& cb, PipelineStatus status); |
| 435 | 439 |
| 440 void RunOnPipelineThread(const base::Closure& closure); | |
| 441 | |
| 436 // Message loop used to execute pipeline tasks. | 442 // Message loop used to execute pipeline tasks. |
| 437 scoped_refptr<base::MessageLoopProxy> message_loop_; | 443 scoped_refptr<base::MessageLoopProxy> message_loop_; |
| 438 | 444 |
| 439 // MediaLog to which to log events. | 445 // MediaLog to which to log events. |
| 440 scoped_refptr<MediaLog> media_log_; | 446 scoped_refptr<MediaLog> media_log_; |
| 441 | 447 |
| 442 // Lock used to serialize access for the following data members. | 448 // Lock used to serialize access for the following data members. |
| 443 mutable base::Lock lock_; | 449 mutable base::Lock lock_; |
| 444 | 450 |
| 445 // Whether or not the pipeline is running. | 451 // Whether or not the pipeline is running. |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 561 // Time of pipeline creation; is non-zero only until the pipeline first | 567 // Time of pipeline creation; is non-zero only until the pipeline first |
| 562 // reaches "kStarted", at which point it is used & zeroed out. | 568 // reaches "kStarted", at which point it is used & zeroed out. |
| 563 base::Time creation_time_; | 569 base::Time creation_time_; |
| 564 | 570 |
| 565 DISALLOW_COPY_AND_ASSIGN(Pipeline); | 571 DISALLOW_COPY_AND_ASSIGN(Pipeline); |
| 566 }; | 572 }; |
| 567 | 573 |
| 568 } // namespace media | 574 } // namespace media |
| 569 | 575 |
| 570 #endif // MEDIA_BASE_PIPELINE_H_ | 576 #endif // MEDIA_BASE_PIPELINE_H_ |
| OLD | NEW |