| 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 17 matching lines...) Expand all Loading... |
| 28 | 28 |
| 29 class AudioDecoder; | 29 class AudioDecoder; |
| 30 class AudioRenderer; | 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 enum NetworkEvent { | |
| 39 DOWNLOAD_CONTINUED, | |
| 40 DOWNLOAD_PAUSED, | |
| 41 CAN_PLAY_THROUGH | |
| 42 }; | |
| 43 | |
| 44 // Callback that executes when a network event occurs. | |
| 45 // The parameter specifies the type of event that is being signalled. | |
| 46 typedef base::Callback<void(NetworkEvent)> NetworkEventCB; | |
| 47 | |
| 48 // 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 |
| 49 // 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 |
| 50 // |Callback()| to the Pipeline method requiring a callback. Then Wait() for | 40 // |Callback()| to the Pipeline method requiring a callback. Then Wait() for |
| 51 // the callback to get fired and call status() to see what the callback's | 41 // the callback to get fired and call status() to see what the callback's |
| 52 // argument was. This object is for one-time use; call |Callback()| exactly | 42 // argument was. This object is for one-time use; call |Callback()| exactly |
| 53 // once. | 43 // once. |
| 54 class MEDIA_EXPORT PipelineStatusNotification { | 44 class MEDIA_EXPORT PipelineStatusNotification { |
| 55 public: | 45 public: |
| 56 PipelineStatusNotification(); | 46 PipelineStatusNotification(); |
| 57 ~PipelineStatusNotification(); | 47 ~PipelineStatusNotification(); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 | 109 |
| 120 // Build a pipeline to using the given filter collection to construct a filter | 110 // Build a pipeline to using the given filter collection to construct a filter |
| 121 // chain. | 111 // chain. |
| 122 // | 112 // |
| 123 // Pipeline initialization is an inherently asynchronous process. Clients can | 113 // Pipeline initialization is an inherently asynchronous process. Clients can |
| 124 // either poll the IsInitialized() method (discouraged) or optionally pass in | 114 // either poll the IsInitialized() method (discouraged) or optionally pass in |
| 125 // |start_cb|, which will be executed when initialization completes. | 115 // |start_cb|, which will be executed when initialization completes. |
| 126 // | 116 // |
| 127 // The following permanent callbacks will be executed as follows: | 117 // The following permanent callbacks will be executed as follows: |
| 128 // |start_cb_| will be executed when Start is done (successfully or not). | 118 // |start_cb_| will be executed when Start is done (successfully or not). |
| 129 // |network_cb_| will be executed whenever there's a network activity. | |
| 130 // |ended_cb| will be executed whenever the media reaches the end. | 119 // |ended_cb| will be executed whenever the media reaches the end. |
| 131 // |error_cb_| will be executed whenever an error occurs but hasn't | 120 // |error_cb_| will be executed whenever an error occurs but hasn't |
| 132 // been reported already through another callback. | 121 // been reported already through another callback. |
| 133 // | 122 // |
| 134 // These callbacks are only executed after Start() has been called and until | 123 // These callbacks are only executed after Start() has been called and until |
| 135 // Stop() has completed. | 124 // Stop() has completed. |
| 136 // | 125 // |
| 137 // It is an error to call this method after the pipeline has already started. | 126 // It is an error to call this method after the pipeline has already started. |
| 138 // | 127 // |
| 139 // TODO(scherkus): remove IsInitialized() and force clients to use callbacks. | 128 // TODO(scherkus): remove IsInitialized() and force clients to use callbacks. |
| 140 void Start(scoped_ptr<FilterCollection> filter_collection, | 129 void Start(scoped_ptr<FilterCollection> filter_collection, |
| 141 const PipelineStatusCB& ended_cb, | 130 const PipelineStatusCB& ended_cb, |
| 142 const PipelineStatusCB& error_cb, | 131 const PipelineStatusCB& error_cb, |
| 143 const NetworkEventCB& network_cb, | |
| 144 const PipelineStatusCB& start_cb); | 132 const PipelineStatusCB& start_cb); |
| 145 | 133 |
| 146 // Asynchronously stops the pipeline and resets it to an uninitialized state. | 134 // Asynchronously stops the pipeline and resets it to an uninitialized state. |
| 147 // | 135 // |
| 148 // If provided, |stop_cb| will be executed when the pipeline has been | 136 // If provided, |stop_cb| will be executed when the pipeline has been |
| 149 // completely torn down and reset to an uninitialized state. It is acceptable | 137 // completely torn down and reset to an uninitialized state. It is acceptable |
| 150 // to call Start() again once the callback has finished executing. | 138 // to call Start() again once the callback has finished executing. |
| 151 // | 139 // |
| 152 // Stop() must be called before destroying the pipeline. Clients can | 140 // Stop() must be called before destroying the pipeline. Clients can |
| 153 // determine whether Stop() must be called by checking IsRunning(). | 141 // determine whether Stop() must be called by checking IsRunning(). |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 // Returns true if the given state is one that transitions to a new state | 281 // Returns true if the given state is one that transitions to a new state |
| 294 // after iterating through each filter. | 282 // after iterating through each filter. |
| 295 static bool TransientState(State state); | 283 static bool TransientState(State state); |
| 296 | 284 |
| 297 // Given the current state, returns the next state. | 285 // Given the current state, returns the next state. |
| 298 State FindNextState(State current); | 286 State FindNextState(State current); |
| 299 | 287 |
| 300 // DataSourceHost (by way of DemuxerHost) implementation. | 288 // DataSourceHost (by way of DemuxerHost) implementation. |
| 301 virtual void SetTotalBytes(int64 total_bytes) OVERRIDE; | 289 virtual void SetTotalBytes(int64 total_bytes) OVERRIDE; |
| 302 virtual void AddBufferedByteRange(int64 start, int64 end) OVERRIDE; | 290 virtual void AddBufferedByteRange(int64 start, int64 end) OVERRIDE; |
| 303 virtual void SetNetworkActivity(bool is_downloading_data) OVERRIDE; | |
| 304 | 291 |
| 305 // DemuxerHost implementaion. | 292 // DemuxerHost implementaion. |
| 306 virtual void SetDuration(base::TimeDelta duration) OVERRIDE; | 293 virtual void SetDuration(base::TimeDelta duration) OVERRIDE; |
| 307 virtual void OnDemuxerError(PipelineStatus error) OVERRIDE; | 294 virtual void OnDemuxerError(PipelineStatus error) OVERRIDE; |
| 308 | 295 |
| 309 // FilterHost implementation. | 296 // FilterHost implementation. |
| 310 virtual void SetError(PipelineStatus error) OVERRIDE; | 297 virtual void SetError(PipelineStatus error) OVERRIDE; |
| 311 virtual base::TimeDelta GetTime() const OVERRIDE; | 298 virtual base::TimeDelta GetTime() const OVERRIDE; |
| 312 virtual base::TimeDelta GetDuration() const OVERRIDE; | 299 virtual base::TimeDelta GetDuration() const OVERRIDE; |
| 313 virtual void SetNaturalVideoSize(const gfx::Size& size) OVERRIDE; | 300 virtual void SetNaturalVideoSize(const gfx::Size& size) OVERRIDE; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 334 | 321 |
| 335 // Callback executed by video renderer to update clock time. | 322 // Callback executed by video renderer to update clock time. |
| 336 void OnVideoTimeUpdate(base::TimeDelta max_time); | 323 void OnVideoTimeUpdate(base::TimeDelta max_time); |
| 337 | 324 |
| 338 // The following "task" methods correspond to the public methods, but these | 325 // The following "task" methods correspond to the public methods, but these |
| 339 // methods are run as the result of posting a task to the PipelineInternal's | 326 // methods are run as the result of posting a task to the PipelineInternal's |
| 340 // message loop. | 327 // message loop. |
| 341 void StartTask(scoped_ptr<FilterCollection> filter_collection, | 328 void StartTask(scoped_ptr<FilterCollection> filter_collection, |
| 342 const PipelineStatusCB& ended_cb, | 329 const PipelineStatusCB& ended_cb, |
| 343 const PipelineStatusCB& error_cb, | 330 const PipelineStatusCB& error_cb, |
| 344 const NetworkEventCB& network_cb, | |
| 345 const PipelineStatusCB& start_cb); | 331 const PipelineStatusCB& start_cb); |
| 346 | 332 |
| 347 // InitializeTask() performs initialization in multiple passes. It is executed | 333 // InitializeTask() performs initialization in multiple passes. It is executed |
| 348 // as a result of calling Start() or InitializationComplete() that advances | 334 // as a result of calling Start() or InitializationComplete() that advances |
| 349 // initialization to the next state. It works as a hub of state transition for | 335 // initialization to the next state. It works as a hub of state transition for |
| 350 // initialization. One stage communicates its status to the next through | 336 // initialization. One stage communicates its status to the next through |
| 351 // |last_stage_status|. | 337 // |last_stage_status|. |
| 352 void InitializeTask(PipelineStatus last_stage_status); | 338 void InitializeTask(PipelineStatus last_stage_status); |
| 353 | 339 |
| 354 // Stops and destroys all filters, placing the pipeline in the kStopped state. | 340 // Stops and destroys all filters, placing the pipeline in the kStopped state. |
| 355 void StopTask(const base::Closure& stop_cb); | 341 void StopTask(const base::Closure& stop_cb); |
| 356 | 342 |
| 357 // Carries out stopping and destroying all filters, placing the pipeline in | 343 // Carries out stopping and destroying all filters, placing the pipeline in |
| 358 // the kError state. | 344 // the kError state. |
| 359 void ErrorChangedTask(PipelineStatus error); | 345 void ErrorChangedTask(PipelineStatus error); |
| 360 | 346 |
| 361 // Carries out notifying filters that the playback rate has changed. | 347 // Carries out notifying filters that the playback rate has changed. |
| 362 void PlaybackRateChangedTask(float playback_rate); | 348 void PlaybackRateChangedTask(float playback_rate); |
| 363 | 349 |
| 364 // Carries out notifying filters that the volume has changed. | 350 // Carries out notifying filters that the volume has changed. |
| 365 void VolumeChangedTask(float volume); | 351 void VolumeChangedTask(float volume); |
| 366 | 352 |
| 367 // Carries out notifying filters that we are seeking to a new timestamp. | 353 // Carries out notifying filters that we are seeking to a new timestamp. |
| 368 void SeekTask(base::TimeDelta time, const PipelineStatusCB& seek_cb); | 354 void SeekTask(base::TimeDelta time, const PipelineStatusCB& seek_cb); |
| 369 | 355 |
| 370 // Carries out handling a notification from a filter that it has ended. | 356 // Carries out handling a notification from a filter that it has ended. |
| 371 void NotifyEndedTask(); | 357 void NotifyEndedTask(); |
| 372 | 358 |
| 373 // Carries out handling a notification of network event. | |
| 374 void NotifyNetworkEventTask(NetworkEvent type); | |
| 375 | |
| 376 // Carries out disabling the audio renderer. | 359 // Carries out disabling the audio renderer. |
| 377 void DisableAudioRendererTask(); | 360 void DisableAudioRendererTask(); |
| 378 | 361 |
| 379 // Carries out advancing to the next filter during Play()/Pause()/Seek(). | 362 // Carries out advancing to the next filter during Play()/Pause()/Seek(). |
| 380 void FilterStateTransitionTask(); | 363 void FilterStateTransitionTask(); |
| 381 | 364 |
| 382 // Carries out advancing to the next teardown operation. | 365 // Carries out advancing to the next teardown operation. |
| 383 void TeardownStateTransitionTask(); | 366 void TeardownStateTransitionTask(); |
| 384 | 367 |
| 385 // Carries out stopping filter threads, deleting filters, running | 368 // Carries out stopping filter threads, deleting filters, running |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 538 bool audio_disabled_; | 521 bool audio_disabled_; |
| 539 | 522 |
| 540 // Filter collection as passed in by Start(). | 523 // Filter collection as passed in by Start(). |
| 541 scoped_ptr<FilterCollection> filter_collection_; | 524 scoped_ptr<FilterCollection> filter_collection_; |
| 542 | 525 |
| 543 // Callbacks for various pipeline operations. | 526 // Callbacks for various pipeline operations. |
| 544 PipelineStatusCB seek_cb_; | 527 PipelineStatusCB seek_cb_; |
| 545 base::Closure stop_cb_; | 528 base::Closure stop_cb_; |
| 546 PipelineStatusCB ended_cb_; | 529 PipelineStatusCB ended_cb_; |
| 547 PipelineStatusCB error_cb_; | 530 PipelineStatusCB error_cb_; |
| 548 NetworkEventCB network_cb_; | |
| 549 | 531 |
| 550 // Reference to the filter(s) that constitute the pipeline. | 532 // Reference to the filter(s) that constitute the pipeline. |
| 551 scoped_refptr<Filter> pipeline_filter_; | 533 scoped_refptr<Filter> pipeline_filter_; |
| 552 | 534 |
| 553 // Decoder reference used for signalling imminent shutdown. | 535 // Decoder reference used for signalling imminent shutdown. |
| 554 // This is a HACK necessary because WebMediaPlayerImpl::Destroy() holds the | 536 // This is a HACK necessary because WebMediaPlayerImpl::Destroy() holds the |
| 555 // renderer thread loop hostage for until PipelineImpl::Stop() calls its | 537 // renderer thread loop hostage for until PipelineImpl::Stop() calls its |
| 556 // callback. | 538 // callback. |
| 557 // This reference should only be used for this hack and no other purposes. | 539 // This reference should only be used for this hack and no other purposes. |
| 558 // http://crbug.com/110228 tracks removing this hack. | 540 // http://crbug.com/110228 tracks removing this hack. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 576 // Time of pipeline creation; is non-zero only until the pipeline first | 558 // Time of pipeline creation; is non-zero only until the pipeline first |
| 577 // reaches "kStarted", at which point it is used & zeroed out. | 559 // reaches "kStarted", at which point it is used & zeroed out. |
| 578 base::Time creation_time_; | 560 base::Time creation_time_; |
| 579 | 561 |
| 580 DISALLOW_COPY_AND_ASSIGN(Pipeline); | 562 DISALLOW_COPY_AND_ASSIGN(Pipeline); |
| 581 }; | 563 }; |
| 582 | 564 |
| 583 } // namespace media | 565 } // namespace media |
| 584 | 566 |
| 585 #endif // MEDIA_BASE_PIPELINE_H_ | 567 #endif // MEDIA_BASE_PIPELINE_H_ |
| OLD | NEW |