| 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/demuxer.h" | 13 #include "media/base/demuxer.h" |
| 14 #include "media/base/download_rate_monitor.h" | 14 #include "media/base/download_rate_monitor.h" |
| 15 #include "media/base/filter_host.h" | 15 #include "media/base/filter_host.h" |
| 16 #include "media/base/media_export.h" | 16 #include "media/base/media_export.h" |
| 17 #include "media/base/pipeline_status.h" | 17 #include "media/base/pipeline_status.h" |
| 18 #include "media/base/preload.h" | |
| 19 #include "ui/gfx/size.h" | 18 #include "ui/gfx/size.h" |
| 20 | 19 |
| 21 class MessageLoop; | 20 class MessageLoop; |
| 22 | 21 |
| 23 namespace base { | 22 namespace base { |
| 24 class TimeDelta; | 23 class TimeDelta; |
| 25 } | 24 } |
| 26 | 25 |
| 27 namespace media { | 26 namespace media { |
| 28 | 27 |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 // from any state. If Stop() is ever called, this object will transition to | 109 // from any state. If Stop() is ever called, this object will transition to |
| 111 // "Stopped" state. | 110 // "Stopped" state. |
| 112 class MEDIA_EXPORT Pipeline | 111 class MEDIA_EXPORT Pipeline |
| 113 : public base::RefCountedThreadSafe<Pipeline>, | 112 : public base::RefCountedThreadSafe<Pipeline>, |
| 114 public FilterHost, | 113 public FilterHost, |
| 115 public DemuxerHost { | 114 public DemuxerHost { |
| 116 public: | 115 public: |
| 117 // Constructs a media pipeline that will execute on |message_loop|. | 116 // Constructs a media pipeline that will execute on |message_loop|. |
| 118 Pipeline(MessageLoop* message_loop, MediaLog* media_log); | 117 Pipeline(MessageLoop* message_loop, MediaLog* media_log); |
| 119 | 118 |
| 120 // Build a pipeline to render the given URL using the given filter collection | 119 // Build a pipeline to using the given filter collection to construct a filter |
| 121 // to construct a filter chain. | 120 // chain. |
| 122 // | 121 // |
| 123 // Pipeline initialization is an inherently asynchronous process. Clients can | 122 // Pipeline initialization is an inherently asynchronous process. Clients can |
| 124 // either poll the IsInitialized() method (discouraged) or optionally pass in | 123 // either poll the IsInitialized() method (discouraged) or optionally pass in |
| 125 // |start_cb|, which will be executed when initialization completes. | 124 // |start_cb|, which will be executed when initialization completes. |
| 126 // | 125 // |
| 127 // The following permanent callbacks will be executed as follows: | 126 // The following permanent callbacks will be executed as follows: |
| 128 // |start_cb_| will be executed when Start is done (successfully or not). | 127 // |start_cb_| will be executed when Start is done (successfully or not). |
| 129 // |network_cb_| will be executed whenever there's a network activity. | 128 // |network_cb_| will be executed whenever there's a network activity. |
| 130 // |ended_cb| will be executed whenever the media reaches the end. | 129 // |ended_cb| will be executed whenever the media reaches the end. |
| 131 // |error_cb_| will be executed whenever an error occurs but hasn't | 130 // |error_cb_| will be executed whenever an error occurs but hasn't |
| 132 // been reported already through another callback. | 131 // been reported already through another callback. |
| 133 // | 132 // |
| 134 // These callbacks are only executed after Start() has been called and until | 133 // These callbacks are only executed after Start() has been called and until |
| 135 // Stop() has completed. | 134 // Stop() has completed. |
| 136 // | 135 // |
| 137 // It is an error to call this method after the pipeline has already started. | 136 // It is an error to call this method after the pipeline has already started. |
| 138 // | 137 // |
| 139 // TODO(scherkus): remove IsInitialized() and force clients to use callbacks. | 138 // TODO(scherkus): remove IsInitialized() and force clients to use callbacks. |
| 140 void Start(scoped_ptr<FilterCollection> filter_collection, | 139 void Start(scoped_ptr<FilterCollection> filter_collection, |
| 141 const std::string& url, | |
| 142 const PipelineStatusCB& ended_cb, | 140 const PipelineStatusCB& ended_cb, |
| 143 const PipelineStatusCB& error_cb, | 141 const PipelineStatusCB& error_cb, |
| 144 const NetworkEventCB& network_cb, | 142 const NetworkEventCB& network_cb, |
| 145 const PipelineStatusCB& start_cb); | 143 const PipelineStatusCB& start_cb); |
| 146 | 144 |
| 147 // Asynchronously stops the pipeline and resets it to an uninitialized state. | 145 // Asynchronously stops the pipeline and resets it to an uninitialized state. |
| 148 // | 146 // |
| 149 // If provided, |stop_cb| will be executed when the pipeline has been | 147 // If provided, |stop_cb| will be executed when the pipeline has been |
| 150 // completely torn down and reset to an uninitialized state. It is acceptable | 148 // completely torn down and reset to an uninitialized state. It is acceptable |
| 151 // to call Start() again once the callback has finished executing. | 149 // to call Start() again once the callback has finished executing. |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 // Gets the current volume setting being used by the audio renderer. When | 198 // Gets the current volume setting being used by the audio renderer. When |
| 201 // the pipeline is started, this value will be 1.0f. Valid values range | 199 // the pipeline is started, this value will be 1.0f. Valid values range |
| 202 // from 0.0f to 1.0f. | 200 // from 0.0f to 1.0f. |
| 203 float GetVolume() const; | 201 float GetVolume() const; |
| 204 | 202 |
| 205 // Attempt to set the volume of the audio renderer. Valid values for volume | 203 // Attempt to set the volume of the audio renderer. Valid values for volume |
| 206 // range from 0.0f (muted) to 1.0f (full volume). This value affects all | 204 // range from 0.0f (muted) to 1.0f (full volume). This value affects all |
| 207 // channels proportionately for multi-channel audio streams. | 205 // channels proportionately for multi-channel audio streams. |
| 208 void SetVolume(float volume); | 206 void SetVolume(float volume); |
| 209 | 207 |
| 210 // Set the preload value for the pipeline. | |
| 211 void SetPreload(Preload preload); | |
| 212 | |
| 213 // Gets the current pipeline time. For a pipeline "time" progresses from 0 to | 208 // Gets the current pipeline time. For a pipeline "time" progresses from 0 to |
| 214 // the end of the media. | 209 // the end of the media. |
| 215 base::TimeDelta GetCurrentTime() const; | 210 base::TimeDelta GetCurrentTime() const; |
| 216 | 211 |
| 217 // Get the approximate amount of playable data buffered so far in micro- | 212 // Get the approximate amount of playable data buffered so far in micro- |
| 218 // seconds. | 213 // seconds. |
| 219 base::TimeDelta GetBufferedTime(); | 214 base::TimeDelta GetBufferedTime(); |
| 220 | 215 |
| 221 // Get the duration of the media in microseconds. If the duration has not | 216 // Get the duration of the media in microseconds. If the duration has not |
| 222 // been determined yet, then returns 0. | 217 // been determined yet, then returns 0. |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 // Callback executed by audio renderer to update clock time. | 342 // Callback executed by audio renderer to update clock time. |
| 348 void OnAudioTimeUpdate(base::TimeDelta time, base::TimeDelta max_time); | 343 void OnAudioTimeUpdate(base::TimeDelta time, base::TimeDelta max_time); |
| 349 | 344 |
| 350 // Callback executed by video renderer to update clock time. | 345 // Callback executed by video renderer to update clock time. |
| 351 void OnVideoTimeUpdate(base::TimeDelta max_time); | 346 void OnVideoTimeUpdate(base::TimeDelta max_time); |
| 352 | 347 |
| 353 // The following "task" methods correspond to the public methods, but these | 348 // The following "task" methods correspond to the public methods, but these |
| 354 // methods are run as the result of posting a task to the PipelineInternal's | 349 // methods are run as the result of posting a task to the PipelineInternal's |
| 355 // message loop. | 350 // message loop. |
| 356 void StartTask(scoped_ptr<FilterCollection> filter_collection, | 351 void StartTask(scoped_ptr<FilterCollection> filter_collection, |
| 357 const std::string& url, | |
| 358 const PipelineStatusCB& ended_cb, | 352 const PipelineStatusCB& ended_cb, |
| 359 const PipelineStatusCB& error_cb, | 353 const PipelineStatusCB& error_cb, |
| 360 const NetworkEventCB& network_cb, | 354 const NetworkEventCB& network_cb, |
| 361 const PipelineStatusCB& start_cb); | 355 const PipelineStatusCB& start_cb); |
| 362 | 356 |
| 363 // InitializeTask() performs initialization in multiple passes. It is executed | 357 // InitializeTask() performs initialization in multiple passes. It is executed |
| 364 // as a result of calling Start() or InitializationComplete() that advances | 358 // as a result of calling Start() or InitializationComplete() that advances |
| 365 // initialization to the next state. It works as a hub of state transition for | 359 // initialization to the next state. It works as a hub of state transition for |
| 366 // initialization. One stage communicates its status to the next through | 360 // initialization. One stage communicates its status to the next through |
| 367 // |last_stage_status|. | 361 // |last_stage_status|. |
| 368 void InitializeTask(PipelineStatus last_stage_status); | 362 void InitializeTask(PipelineStatus last_stage_status); |
| 369 | 363 |
| 370 // Stops and destroys all filters, placing the pipeline in the kStopped state. | 364 // Stops and destroys all filters, placing the pipeline in the kStopped state. |
| 371 void StopTask(const base::Closure& stop_cb); | 365 void StopTask(const base::Closure& stop_cb); |
| 372 | 366 |
| 373 // Carries out stopping and destroying all filters, placing the pipeline in | 367 // Carries out stopping and destroying all filters, placing the pipeline in |
| 374 // the kError state. | 368 // the kError state. |
| 375 void ErrorChangedTask(PipelineStatus error); | 369 void ErrorChangedTask(PipelineStatus error); |
| 376 | 370 |
| 377 // Carries out notifying filters that the playback rate has changed. | 371 // Carries out notifying filters that the playback rate has changed. |
| 378 void PlaybackRateChangedTask(float playback_rate); | 372 void PlaybackRateChangedTask(float playback_rate); |
| 379 | 373 |
| 380 // Carries out notifying filters that the volume has changed. | 374 // Carries out notifying filters that the volume has changed. |
| 381 void VolumeChangedTask(float volume); | 375 void VolumeChangedTask(float volume); |
| 382 | 376 |
| 383 // Returns media preload value. | |
| 384 virtual Preload GetPreload() const; | |
| 385 | |
| 386 // Carries out notifying filters that the preload value has changed. | |
| 387 void PreloadChangedTask(Preload preload); | |
| 388 | |
| 389 // Carries out notifying filters that we are seeking to a new timestamp. | 377 // Carries out notifying filters that we are seeking to a new timestamp. |
| 390 void SeekTask(base::TimeDelta time, const PipelineStatusCB& seek_cb); | 378 void SeekTask(base::TimeDelta time, const PipelineStatusCB& seek_cb); |
| 391 | 379 |
| 392 // Carries out handling a notification from a filter that it has ended. | 380 // Carries out handling a notification from a filter that it has ended. |
| 393 void NotifyEndedTask(); | 381 void NotifyEndedTask(); |
| 394 | 382 |
| 395 // Carries out handling a notification of network event. | 383 // Carries out handling a notification of network event. |
| 396 void NotifyNetworkEventTask(NetworkEvent type); | 384 void NotifyNetworkEventTask(NetworkEvent type); |
| 397 | 385 |
| 398 // Carries out disabling the audio renderer. | 386 // Carries out disabling the audio renderer. |
| 399 void DisableAudioRendererTask(); | 387 void DisableAudioRendererTask(); |
| 400 | 388 |
| 401 // Carries out advancing to the next filter during Play()/Pause()/Seek(). | 389 // Carries out advancing to the next filter during Play()/Pause()/Seek(). |
| 402 void FilterStateTransitionTask(); | 390 void FilterStateTransitionTask(); |
| 403 | 391 |
| 404 // Carries out advancing to the next teardown operation. | 392 // Carries out advancing to the next teardown operation. |
| 405 void TeardownStateTransitionTask(); | 393 void TeardownStateTransitionTask(); |
| 406 | 394 |
| 407 // Carries out stopping filter threads, deleting filters, running | 395 // Carries out stopping filter threads, deleting filters, running |
| 408 // appropriate callbacks, and setting the appropriate pipeline state | 396 // appropriate callbacks, and setting the appropriate pipeline state |
| 409 // depending on whether we performing Stop() or SetError(). | 397 // depending on whether we performing Stop() or SetError(). |
| 410 // Called after all filters have been stopped. | 398 // Called after all filters have been stopped. |
| 411 void FinishDestroyingFiltersTask(); | 399 void FinishDestroyingFiltersTask(); |
| 412 | 400 |
| 413 // Internal methods used in the implementation of the pipeline thread. All | 401 // Internal methods used in the implementation of the pipeline thread. All |
| 414 // of these methods are only called on the pipeline thread. | 402 // of these methods are only called on the pipeline thread. |
| 415 | 403 |
| 416 // The following initialize methods are used to select a specific type of | 404 // The following initialize methods are used to select a specific type of |
| 417 // Filter object from FilterCollection and initialize it asynchronously. | 405 // object from FilterCollection and initialize it asynchronously. |
| 418 void InitializeDemuxer(); | 406 void InitializeDemuxer(); |
| 419 void OnDemuxerBuilt(PipelineStatus status, Demuxer* demuxer); | 407 void OnDemuxerInitialized(PipelineStatus status); |
| 420 | 408 |
| 421 // Returns true if the asynchronous action of creating decoder has started. | 409 // Returns true if the asynchronous action of creating decoder has started. |
| 422 // Returns false if this method did nothing because the corresponding | 410 // Returns false if this method did nothing because the corresponding |
| 423 // audio/video stream does not exist. | 411 // audio/video stream does not exist. |
| 424 bool InitializeAudioDecoder(const scoped_refptr<Demuxer>& demuxer); | 412 bool InitializeAudioDecoder(const scoped_refptr<Demuxer>& demuxer); |
| 425 bool InitializeVideoDecoder(const scoped_refptr<Demuxer>& demuxer); | 413 bool InitializeVideoDecoder(const scoped_refptr<Demuxer>& demuxer); |
| 426 | 414 |
| 427 // Initializes a renderer and connects it with decoder. Returns true if the | 415 // Initializes a renderer and connects it with decoder. Returns true if the |
| 428 // asynchronous action of creating renderer has started. Returns | 416 // asynchronous action of creating renderer has started. Returns |
| 429 // false if this method did nothing because the corresponding audio/video | 417 // false if this method did nothing because the corresponding audio/video |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 520 | 508 |
| 521 // Indicates whether the data source is local, such as a local media file | 509 // Indicates whether the data source is local, such as a local media file |
| 522 // from disk or a local webcam stream. | 510 // from disk or a local webcam stream. |
| 523 bool local_source_; | 511 bool local_source_; |
| 524 | 512 |
| 525 // Current volume level (from 0.0f to 1.0f). This value is set immediately | 513 // Current volume level (from 0.0f to 1.0f). This value is set immediately |
| 526 // via SetVolume() and a task is dispatched on the message loop to notify the | 514 // via SetVolume() and a task is dispatched on the message loop to notify the |
| 527 // filters. | 515 // filters. |
| 528 float volume_; | 516 float volume_; |
| 529 | 517 |
| 530 // Current value of preload attribute. This value is set immediately via | |
| 531 // SetPreload() and a task is dispatched on the message loop to notify the | |
| 532 // filters. | |
| 533 Preload preload_; | |
| 534 | |
| 535 // Current playback rate (>= 0.0f). This value is set immediately via | 518 // Current playback rate (>= 0.0f). This value is set immediately via |
| 536 // SetPlaybackRate() and a task is dispatched on the message loop to notify | 519 // SetPlaybackRate() and a task is dispatched on the message loop to notify |
| 537 // the filters. | 520 // the filters. |
| 538 float playback_rate_; | 521 float playback_rate_; |
| 539 | 522 |
| 540 // Playback rate to set when the current seek has finished. | 523 // Playback rate to set when the current seek has finished. |
| 541 float pending_playback_rate_; | 524 float pending_playback_rate_; |
| 542 | 525 |
| 543 // Reference clock. Keeps track of current playback time. Uses system | 526 // Reference clock. Keeps track of current playback time. Uses system |
| 544 // clock and linear interpolation, but can have its time manually set | 527 // clock and linear interpolation, but can have its time manually set |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 581 bool audio_disabled_; | 564 bool audio_disabled_; |
| 582 | 565 |
| 583 // Keep track of the maximum buffered position so the buffering appears | 566 // Keep track of the maximum buffered position so the buffering appears |
| 584 // smooth. | 567 // smooth. |
| 585 // TODO(vrk): This is a hack. | 568 // TODO(vrk): This is a hack. |
| 586 base::TimeDelta max_buffered_time_; | 569 base::TimeDelta max_buffered_time_; |
| 587 | 570 |
| 588 // Filter collection as passed in by Start(). | 571 // Filter collection as passed in by Start(). |
| 589 scoped_ptr<FilterCollection> filter_collection_; | 572 scoped_ptr<FilterCollection> filter_collection_; |
| 590 | 573 |
| 591 // URL for the data source as passed in by Start(). | |
| 592 std::string url_; | |
| 593 | |
| 594 // Callbacks for various pipeline operations. | 574 // Callbacks for various pipeline operations. |
| 595 PipelineStatusCB seek_cb_; | 575 PipelineStatusCB seek_cb_; |
| 596 base::Closure stop_cb_; | 576 base::Closure stop_cb_; |
| 597 PipelineStatusCB ended_cb_; | 577 PipelineStatusCB ended_cb_; |
| 598 PipelineStatusCB error_cb_; | 578 PipelineStatusCB error_cb_; |
| 599 NetworkEventCB network_cb_; | 579 NetworkEventCB network_cb_; |
| 600 | 580 |
| 601 // Reference to the filter(s) that constitute the pipeline. | 581 // Reference to the filter(s) that constitute the pipeline. |
| 602 scoped_refptr<Filter> pipeline_filter_; | 582 scoped_refptr<Filter> pipeline_filter_; |
| 603 | 583 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 633 | 613 |
| 634 // True if the pipeline is actively downloading bytes, false otherwise. | 614 // True if the pipeline is actively downloading bytes, false otherwise. |
| 635 bool is_downloading_data_; | 615 bool is_downloading_data_; |
| 636 | 616 |
| 637 DISALLOW_COPY_AND_ASSIGN(Pipeline); | 617 DISALLOW_COPY_AND_ASSIGN(Pipeline); |
| 638 }; | 618 }; |
| 639 | 619 |
| 640 } // namespace media | 620 } // namespace media |
| 641 | 621 |
| 642 #endif // MEDIA_BASE_PIPELINE_H_ | 622 #endif // MEDIA_BASE_PIPELINE_H_ |
| OLD | NEW |