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 "base/gtest_prod_util.h" | 8 #include "base/gtest_prod_util.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 44 | 44 |
| 45 bool has_audio; | 45 bool has_audio; |
| 46 bool has_video; | 46 bool has_video; |
| 47 gfx::Size natural_size; | 47 gfx::Size natural_size; |
| 48 VideoRotation video_rotation; | 48 VideoRotation video_rotation; |
| 49 base::Time timeline_offset; | 49 base::Time timeline_offset; |
| 50 }; | 50 }; |
| 51 | 51 |
| 52 typedef base::Callback<void(PipelineMetadata)> PipelineMetadataCB; | 52 typedef base::Callback<void(PipelineMetadata)> PipelineMetadataCB; |
| 53 | 53 |
| 54 // Pipeline runs the media pipeline. Filters are created and called on the | 54 class MEDIA_EXPORT Pipeline { |
| 55 // task runner injected into this object. Pipeline works like a state | |
| 56 // machine to perform asynchronous initialization, pausing, seeking and playing. | |
| 57 // | |
| 58 // Here's a state diagram that describes the lifetime of this object. | |
| 59 // | |
| 60 // [ *Created ] [ Any State ] | |
| 61 // | Start() | Stop() / SetError() | |
| 62 // V V | |
| 63 // [ InitXXX (for each filter) ] [ Stopping ] | |
| 64 // | | | |
| 65 // V V | |
| 66 // [ Playing ] <---------. [ Stopped ] | |
| 67 // | | Seek() | | |
| 68 // | V | | |
| 69 // | [ Seeking ] ----' | |
| 70 // | ^ | |
| 71 // | Suspend() | | |
| 72 // V | | |
| 73 // [ Suspending ] | | |
| 74 // | | | |
| 75 // V | | |
| 76 // [ Suspended ] | | |
| 77 // | Resume() | | |
| 78 // V | | |
| 79 // [ Resuming ] ---------' | |
| 80 // | |
| 81 // Initialization is a series of state transitions from "Created" through each | |
| 82 // filter initialization state. When all filter initialization states have | |
| 83 // completed, we simulate a Seek() to the beginning of the media to give filters | |
| 84 // a chance to preroll. From then on the normal Seek() transitions are carried | |
| 85 // out and we start playing the media. | |
| 86 // | |
| 87 // If any error ever happens, this object will transition to the "Error" state | |
| 88 // from any state. If Stop() is ever called, this object will transition to | |
| 89 // "Stopped" state. | |
| 90 // | |
| 91 // TODO(sandersd): It should be possible to pass through Suspended when going | |
| 92 // from InitDemuxer to InitRenderer, thereby eliminating the Resuming state. | |
| 93 // Some annoying differences between the two paths need to be removed first. | |
| 94 class MEDIA_EXPORT Pipeline : public DemuxerHost { | |
| 95 public: | 55 public: |
| 96 // Used to paint VideoFrame. | 56 // Used to paint VideoFrame. |
| 97 typedef base::Callback<void(const scoped_refptr<VideoFrame>&)> PaintCB; | 57 typedef base::Callback<void(const scoped_refptr<VideoFrame>&)> PaintCB; |
| 98 | 58 |
| 99 // Constructs a media pipeline that will execute on |task_runner|. | |
| 100 Pipeline(const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, | |
| 101 MediaLog* media_log); | |
| 102 ~Pipeline() override; | |
| 103 | |
| 104 // Build a pipeline to using the given |demuxer| and |renderer| to construct | 59 // Build a pipeline to using the given |demuxer| and |renderer| to construct |
| 105 // a filter chain, executing |seek_cb| when the initial seek has completed. | 60 // a filter chain, executing |seek_cb| when the initial seek has completed. |
| 106 // | 61 // |
| 107 // The following permanent callbacks will be executed as follows up until | 62 // The following permanent callbacks will be executed as follows up until |
| 108 // Stop() has completed: | 63 // Stop() has completed: |
| 109 // |ended_cb| will be executed whenever the media reaches the end. | 64 // |ended_cb| will be executed whenever the media reaches the end. |
| 110 // |error_cb| will be executed whenever an error occurs but hasn't been | 65 // |error_cb| will be executed whenever an error occurs but hasn't been |
| 111 // reported already through another callback. | 66 // reported already through another callback. |
| 112 // |metadata_cb| will be executed when the content duration, container video | 67 // |metadata_cb| will be executed when the content duration, container video |
| 113 // size, start time, and whether the content has audio and/or | 68 // size, start time, and whether the content has audio and/or |
| 114 // video in supported formats are known. | 69 // video in supported formats are known. |
| 115 // |buffering_state_cb| will be executed whenever there are changes in the | 70 // |buffering_state_cb| will be executed whenever there are changes in the |
| 116 // overall buffering state of the pipeline. | 71 // overall buffering state of the pipeline. |
| 117 // |duration_change_cb| optional callback that will be executed whenever the | 72 // |duration_change_cb| optional callback that will be executed whenever the |
| 118 // presentation duration changes. | 73 // presentation duration changes. |
| 119 // |add_text_track_cb| will be executed whenever a text track is added. | 74 // |add_text_track_cb| will be executed whenever a text track is added. |
| 120 // |waiting_for_decryption_key_cb| will be executed whenever the key needed | 75 // |waiting_for_decryption_key_cb| will be executed whenever the key needed |
| 121 // to decrypt the stream is not available. | 76 // to decrypt the stream is not available. |
| 122 // It is an error to call this method after the pipeline has already started. | 77 // It is an error to call this method after the pipeline has already started. |
| 123 void Start(Demuxer* demuxer, | 78 virtual void Start(Demuxer* demuxer, |
| 124 scoped_ptr<Renderer> renderer, | 79 scoped_ptr<Renderer>* renderer, |
|
DaleCurtis
2016/02/17 00:19:11
Remind me, what was the reason for this change? I
sandersd (OOO until July 31)
2016/02/18 19:14:46
The ownership of |renderer| is already pretty mess
| |
| 125 const base::Closure& ended_cb, | 80 const base::Closure& ended_cb, |
| 126 const PipelineStatusCB& error_cb, | 81 const PipelineStatusCB& error_cb, |
| 127 const PipelineStatusCB& seek_cb, | 82 const PipelineStatusCB& seek_cb, |
| 128 const PipelineMetadataCB& metadata_cb, | 83 const PipelineMetadataCB& metadata_cb, |
| 129 const BufferingStateCB& buffering_state_cb, | 84 const BufferingStateCB& buffering_state_cb, |
| 130 const base::Closure& duration_change_cb, | 85 const base::Closure& duration_change_cb, |
| 131 const AddTextTrackCB& add_text_track_cb, | 86 const AddTextTrackCB& add_text_track_cb, |
| 132 const base::Closure& waiting_for_decryption_key_cb); | 87 const base::Closure& waiting_for_decryption_key_cb) = 0; |
| 133 | 88 |
| 134 // Asynchronously stops the pipeline, executing |stop_cb| when the pipeline | 89 // Asynchronously stops the pipeline, executing |stop_cb| when the pipeline |
| 135 // teardown has completed. | 90 // teardown has completed. |
| 136 // | 91 // |
| 137 // Stop() must complete before destroying the pipeline. It it permissible to | 92 // Stop() must complete before destroying the pipeline. It it permissible to |
| 138 // call Stop() at any point during the lifetime of the pipeline. | 93 // call Stop() at any point during the lifetime of the pipeline. |
| 139 // | 94 // |
| 140 // It is safe to delete the pipeline during the execution of |stop_cb|. | 95 // It is safe to delete the pipeline during the execution of |stop_cb|. |
| 141 void Stop(const base::Closure& stop_cb); | 96 virtual void Stop(const base::Closure& stop_cb) = 0; |
| 142 | 97 |
| 143 // Attempt to seek to the position specified by time. |seek_cb| will be | 98 // Attempt to seek to the position specified by time. |seek_cb| will be |
| 144 // executed when the all filters in the pipeline have processed the seek. | 99 // executed when the all filters in the pipeline have processed the seek. |
| 145 // | 100 // |
| 146 // Clients are expected to call GetMediaTime() to check whether the seek | 101 // Clients are expected to call GetMediaTime() to check whether the seek |
| 147 // succeeded. | 102 // succeeded. |
| 148 // | 103 // |
| 149 // It is an error to call this method if the pipeline has not started or | 104 // It is an error to call this method if the pipeline has not started or |
| 150 // is suspended. | 105 // is suspended. |
| 151 void Seek(base::TimeDelta time, const PipelineStatusCB& seek_cb); | 106 virtual void Seek(base::TimeDelta time, const PipelineStatusCB& seek_cb) = 0; |
| 152 | |
| 153 // Returns true if the pipeline has been started via Start(). If IsRunning() | |
| 154 // returns true, it is expected that Stop() will be called before destroying | |
| 155 // the pipeline. | |
| 156 bool IsRunning() const; | |
| 157 | |
| 158 // Gets the current playback rate of the pipeline. When the pipeline is | |
| 159 // started, the playback rate will be 0.0. A rate of 1.0 indicates | |
| 160 // that the pipeline is rendering the media at the standard rate. Valid | |
| 161 // values for playback rate are >= 0.0. | |
| 162 double GetPlaybackRate() const; | |
| 163 | |
| 164 // Attempt to adjust the playback rate. Setting a playback rate of 0.0 pauses | |
| 165 // all rendering of the media. A rate of 1.0 indicates a normal playback | |
| 166 // rate. Values for the playback rate must be greater than or equal to 0.0. | |
| 167 // | |
| 168 // TODO(scherkus): What about maximum rate? Does HTML5 specify a max? | |
| 169 void SetPlaybackRate(double playback_rate); | |
| 170 | 107 |
| 171 // Suspend the pipeline, discarding the current renderer. | 108 // Suspend the pipeline, discarding the current renderer. |
| 172 // | 109 // |
| 173 // While suspended, GetMediaTime() returns the presentation timestamp of the | 110 // While suspended, GetMediaTime() returns the presentation timestamp of the |
| 174 // last rendered frame. | 111 // last rendered frame. |
| 175 // | 112 // |
| 176 // It is an error to call this method if the pipeline has not started or is | 113 // It is an error to call this method if the pipeline has not started or is |
| 177 // seeking. | 114 // seeking. |
| 178 void Suspend(const PipelineStatusCB& suspend_cb); | 115 virtual void Suspend(const PipelineStatusCB& suspend_cb) = 0; |
| 179 | 116 |
| 180 // Resume the pipeline with a new renderer, and initialize it with a seek. | 117 // Resume the pipeline with a new renderer, and initialize it with a seek. |
| 181 void Resume(scoped_ptr<Renderer> renderer, | 118 virtual void Resume(scoped_ptr<Renderer>* renderer, |
| 182 base::TimeDelta timestamp, | 119 base::TimeDelta timestamp, |
| 183 const PipelineStatusCB& seek_cb); | 120 const PipelineStatusCB& seek_cb) = 0; |
| 121 | |
| 122 // Returns true if the pipeline has been started via Start(). If IsRunning() | |
| 123 // returns true, it is expected that Stop() will be called before destroying | |
| 124 // the pipeline. | |
| 125 virtual bool IsRunning() const = 0; | |
| 126 | |
| 127 // Gets the current playback rate of the pipeline. When the pipeline is | |
| 128 // started, the playback rate will be 0.0. A rate of 1.0 indicates | |
| 129 // that the pipeline is rendering the media at the standard rate. Valid | |
| 130 // values for playback rate are >= 0.0. | |
| 131 virtual double GetPlaybackRate() const = 0; | |
| 132 | |
| 133 // Attempt to adjust the playback rate. Setting a playback rate of 0.0 pauses | |
| 134 // all rendering of the media. A rate of 1.0 indicates a normal playback | |
| 135 // rate. Values for the playback rate must be greater than or equal to 0.0. | |
| 136 // | |
| 137 // TODO(scherkus): What about maximum rate? Does HTML5 specify a max? | |
| 138 virtual void SetPlaybackRate(double playback_rate) = 0; | |
| 184 | 139 |
| 185 // Gets the current volume setting being used by the audio renderer. When | 140 // Gets the current volume setting being used by the audio renderer. When |
| 186 // the pipeline is started, this value will be 1.0f. Valid values range | 141 // the pipeline is started, this value will be 1.0f. Valid values range |
| 187 // from 0.0f to 1.0f. | 142 // from 0.0f to 1.0f. |
| 188 float GetVolume() const; | 143 virtual float GetVolume() const = 0; |
| 189 | 144 |
| 190 // Attempt to set the volume of the audio renderer. Valid values for volume | 145 // Attempt to set the volume of the audio renderer. Valid values for volume |
| 191 // range from 0.0f (muted) to 1.0f (full volume). This value affects all | 146 // range from 0.0f (muted) to 1.0f (full volume). This value affects all |
| 192 // channels proportionately for multi-channel audio streams. | 147 // channels proportionately for multi-channel audio streams. |
| 193 void SetVolume(float volume); | 148 virtual void SetVolume(float volume) = 0; |
| 194 | 149 |
| 195 // Returns the current media playback time, which progresses from 0 until | 150 // Returns the current media playback time, which progresses from 0 until |
| 196 // GetMediaDuration(). | 151 // GetMediaDuration(). |
| 197 base::TimeDelta GetMediaTime() const; | 152 virtual base::TimeDelta GetMediaTime() const = 0; |
| 198 | 153 |
| 199 // Get approximate time ranges of buffered media. | 154 // Get approximate time ranges of buffered media. |
| 200 Ranges<base::TimeDelta> GetBufferedTimeRanges() const; | 155 virtual Ranges<base::TimeDelta> GetBufferedTimeRanges() const = 0; |
| 201 | 156 |
| 202 // Get the duration of the media in microseconds. If the duration has not | 157 // Get the duration of the media in microseconds. If the duration has not |
| 203 // been determined yet, then returns 0. | 158 // been determined yet, then returns 0. |
| 204 base::TimeDelta GetMediaDuration() const; | 159 virtual base::TimeDelta GetMediaDuration() const = 0; |
| 205 | 160 |
| 206 // Return true if loading progress has been made since the last time this | 161 // Return true if loading progress has been made since the last time this |
| 207 // method was called. | 162 // method was called. |
| 208 bool DidLoadingProgress(); | 163 virtual bool DidLoadingProgress() = 0; |
| 209 | 164 |
| 210 // Gets the current pipeline statistics. | 165 // Gets the current pipeline statistics. |
| 211 PipelineStatistics GetStatistics() const; | 166 virtual PipelineStatistics GetStatistics() const = 0; |
| 212 | 167 |
| 213 void SetCdm(CdmContext* cdm_context, const CdmAttachedCB& cdm_attached_cb); | 168 virtual void SetCdm(CdmContext* cdm_context, |
| 169 const CdmAttachedCB& cdm_attached_cb) = 0; | |
| 170 }; | |
| 171 | |
| 172 // Pipeline runs the media pipeline. Filters are created and called on the | |
| 173 // task runner injected into this object. Pipeline works like a state | |
| 174 // machine to perform asynchronous initialization, pausing, seeking and playing. | |
| 175 // | |
| 176 // Here's a state diagram that describes the lifetime of this object. | |
| 177 // | |
| 178 // [ *Created ] [ Any State ] | |
| 179 // | Start() | Stop() / SetError() | |
| 180 // V V | |
| 181 // [ InitXXX (for each filter) ] [ Stopping ] | |
| 182 // | | | |
| 183 // V V | |
| 184 // [ Playing ] <---------. [ Stopped ] | |
| 185 // | | Seek() | | |
| 186 // | V | | |
| 187 // | [ Seeking ] ----' | |
| 188 // | ^ | |
| 189 // | Suspend() | | |
| 190 // V | | |
| 191 // [ Suspending ] | | |
| 192 // | | | |
| 193 // V | | |
| 194 // [ Suspended ] | | |
| 195 // | Resume() | | |
| 196 // V | | |
| 197 // [ Resuming ] ---------' | |
| 198 // | |
| 199 // Initialization is a series of state transitions from "Created" through each | |
| 200 // filter initialization state. When all filter initialization states have | |
| 201 // completed, we simulate a Seek() to the beginning of the media to give filters | |
| 202 // a chance to preroll. From then on the normal Seek() transitions are carried | |
| 203 // out and we start playing the media. | |
| 204 // | |
| 205 // If any error ever happens, this object will transition to the "Error" state | |
| 206 // from any state. If Stop() is ever called, this object will transition to | |
| 207 // "Stopped" state. | |
| 208 // | |
| 209 // TODO(sandersd): It should be possible to pass through Suspended when going | |
| 210 // from InitDemuxer to InitRenderer, thereby eliminating the Resuming state. | |
| 211 // Some annoying differences between the two paths need to be removed first. | |
| 212 class MEDIA_EXPORT PipelineImpl : public Pipeline, public DemuxerHost { | |
| 213 public: | |
| 214 // Constructs a media pipeline that will execute on |task_runner|. | |
| 215 PipelineImpl(const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, | |
| 216 MediaLog* media_log); | |
| 217 ~PipelineImpl() override; | |
| 214 | 218 |
| 215 void SetErrorForTesting(PipelineStatus status); | 219 void SetErrorForTesting(PipelineStatus status); |
| 216 bool HasWeakPtrsForTesting() const; | 220 bool HasWeakPtrsForTesting() const; |
| 217 | 221 |
| 222 // PipelineInterface implementation. | |
| 223 void Start(Demuxer* demuxer, | |
| 224 scoped_ptr<Renderer>* renderer, | |
| 225 const base::Closure& ended_cb, | |
| 226 const PipelineStatusCB& error_cb, | |
| 227 const PipelineStatusCB& seek_cb, | |
| 228 const PipelineMetadataCB& metadata_cb, | |
| 229 const BufferingStateCB& buffering_state_cb, | |
| 230 const base::Closure& duration_change_cb, | |
| 231 const AddTextTrackCB& add_text_track_cb, | |
| 232 const base::Closure& waiting_for_decryption_key_cb) override; | |
| 233 void Stop(const base::Closure& stop_cb) override; | |
| 234 void Seek(base::TimeDelta time, const PipelineStatusCB& seek_cb) override; | |
| 235 bool IsRunning() const override; | |
| 236 double GetPlaybackRate() const override; | |
| 237 void SetPlaybackRate(double playback_rate) override; | |
| 238 void Suspend(const PipelineStatusCB& suspend_cb) override; | |
| 239 void Resume(scoped_ptr<Renderer>* renderer, | |
| 240 base::TimeDelta timestamp, | |
| 241 const PipelineStatusCB& seek_cb) override; | |
| 242 float GetVolume() const override; | |
| 243 void SetVolume(float volume) override; | |
| 244 base::TimeDelta GetMediaTime() const override; | |
| 245 Ranges<base::TimeDelta> GetBufferedTimeRanges() const override; | |
| 246 base::TimeDelta GetMediaDuration() const override; | |
| 247 bool DidLoadingProgress() override; | |
| 248 PipelineStatistics GetStatistics() const override; | |
| 249 void SetCdm(CdmContext* cdm_context, | |
| 250 const CdmAttachedCB& cdm_attached_cb) override; | |
| 251 | |
| 218 private: | 252 private: |
| 219 FRIEND_TEST_ALL_PREFIXES(PipelineTest, GetBufferedTimeRanges); | 253 FRIEND_TEST_ALL_PREFIXES(PipelineTest, GetBufferedTimeRanges); |
| 220 FRIEND_TEST_ALL_PREFIXES(PipelineTest, EndedCallback); | 254 FRIEND_TEST_ALL_PREFIXES(PipelineTest, EndedCallback); |
| 221 FRIEND_TEST_ALL_PREFIXES(PipelineTest, AudioStreamShorterThanVideo); | 255 FRIEND_TEST_ALL_PREFIXES(PipelineTest, AudioStreamShorterThanVideo); |
| 222 friend class MediaLog; | 256 friend class MediaLog; |
| 223 | 257 |
| 224 // Pipeline states, as described above. | 258 // Pipeline states, as described above. |
| 225 enum State { | 259 enum State { |
| 226 kCreated, | 260 kCreated, |
| 227 kInitDemuxer, | 261 kInitDemuxer, |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 422 scoped_ptr<SerialRunner> pending_callbacks_; | 456 scoped_ptr<SerialRunner> pending_callbacks_; |
| 423 | 457 |
| 424 // CdmContext to be used to decrypt (and decode) encrypted stream in this | 458 // CdmContext to be used to decrypt (and decode) encrypted stream in this |
| 425 // pipeline. Non-null only when SetCdm() is called and the pipeline has not | 459 // pipeline. Non-null only when SetCdm() is called and the pipeline has not |
| 426 // been started. Then during Start(), this value will be set on |renderer_|. | 460 // been started. Then during Start(), this value will be set on |renderer_|. |
| 427 CdmContext* pending_cdm_context_; | 461 CdmContext* pending_cdm_context_; |
| 428 | 462 |
| 429 base::ThreadChecker thread_checker_; | 463 base::ThreadChecker thread_checker_; |
| 430 | 464 |
| 431 // NOTE: Weak pointers must be invalidated before all other member variables. | 465 // NOTE: Weak pointers must be invalidated before all other member variables. |
| 432 base::WeakPtrFactory<Pipeline> weak_factory_; | 466 base::WeakPtrFactory<PipelineImpl> weak_factory_; |
| 433 | 467 |
| 434 DISALLOW_COPY_AND_ASSIGN(Pipeline); | 468 DISALLOW_COPY_AND_ASSIGN(PipelineImpl); |
| 435 }; | 469 }; |
| 436 | 470 |
| 437 } // namespace media | 471 } // namespace media |
| 438 | 472 |
| 439 #endif // MEDIA_BASE_PIPELINE_H_ | 473 #endif // MEDIA_BASE_PIPELINE_H_ |
| OLD | NEW |