Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(71)

Side by Side Diff: media/base/pipeline_impl.h

Issue 1658303002: Create abstract interface for media::Pipeline. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix FakeMediaSource includes. Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « media/base/pipeline.cc ('k') | media/base/pipeline_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2016 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_IMPL_H_
6 #define MEDIA_BASE_PIPELINE_H_ 6 #define MEDIA_BASE_PIPELINE_IMPL_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"
11 #include "base/memory/weak_ptr.h" 11 #include "base/memory/weak_ptr.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/time.h"
15 #include "media/base/buffering_state.h" 15 #include "media/base/buffering_state.h"
16 #include "media/base/cdm_context.h" 16 #include "media/base/cdm_context.h"
17 #include "media/base/demuxer.h" 17 #include "media/base/demuxer.h"
18 #include "media/base/media_export.h" 18 #include "media/base/media_export.h"
19 #include "media/base/pipeline.h"
19 #include "media/base/pipeline_status.h" 20 #include "media/base/pipeline_status.h"
20 #include "media/base/ranges.h" 21 #include "media/base/ranges.h"
21 #include "media/base/serial_runner.h" 22 #include "media/base/serial_runner.h"
22 #include "media/base/text_track.h" 23 #include "media/base/text_track.h"
23 #include "media/base/video_rotation.h"
24 #include "ui/gfx/geometry/size.h"
25 24
26 namespace base { 25 namespace base {
27 class SingleThreadTaskRunner; 26 class SingleThreadTaskRunner;
28 class TimeDelta;
29 } 27 }
30 28
31 namespace media { 29 namespace media {
32 30
33 class MediaLog; 31 class MediaLog;
34 class Renderer; 32 class Renderer;
35 class TextRenderer; 33 class TextRenderer;
36 class TextTrackConfig;
37 class TimeDeltaInterpolator;
38 class VideoFrame;
39
40 // Metadata describing a pipeline once it has been initialized.
41 struct PipelineMetadata {
42 PipelineMetadata()
43 : has_audio(false), has_video(false), video_rotation(VIDEO_ROTATION_0) {}
44
45 bool has_audio;
46 bool has_video;
47 gfx::Size natural_size;
48 VideoRotation video_rotation;
49 base::Time timeline_offset;
50 };
51
52 typedef base::Callback<void(PipelineMetadata)> PipelineMetadataCB;
53 34
54 // Pipeline runs the media pipeline. Filters are created and called on the 35 // Pipeline runs the media pipeline. Filters are created and called on the
55 // task runner injected into this object. Pipeline works like a state 36 // task runner injected into this object. Pipeline works like a state
56 // machine to perform asynchronous initialization, pausing, seeking and playing. 37 // machine to perform asynchronous initialization, pausing, seeking and playing.
57 // 38 //
58 // Here's a state diagram that describes the lifetime of this object. 39 // Here's a state diagram that describes the lifetime of this object.
59 // 40 //
60 // [ *Created ] [ Any State ] 41 // [ *Created ] [ Any State ]
61 // | Start() | Stop() / SetError() 42 // | Start() | Stop() / SetError()
62 // V V 43 // V V
(...skipping 21 matching lines...) Expand all
84 // a chance to preroll. From then on the normal Seek() transitions are carried 65 // a chance to preroll. From then on the normal Seek() transitions are carried
85 // out and we start playing the media. 66 // out and we start playing the media.
86 // 67 //
87 // If any error ever happens, this object will transition to the "Error" state 68 // 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 69 // from any state. If Stop() is ever called, this object will transition to
89 // "Stopped" state. 70 // "Stopped" state.
90 // 71 //
91 // TODO(sandersd): It should be possible to pass through Suspended when going 72 // TODO(sandersd): It should be possible to pass through Suspended when going
92 // from InitDemuxer to InitRenderer, thereby eliminating the Resuming state. 73 // from InitDemuxer to InitRenderer, thereby eliminating the Resuming state.
93 // Some annoying differences between the two paths need to be removed first. 74 // Some annoying differences between the two paths need to be removed first.
94 class MEDIA_EXPORT Pipeline : public DemuxerHost { 75 class MEDIA_EXPORT PipelineImpl : public Pipeline, public DemuxerHost {
95 public: 76 public:
96 // Used to paint VideoFrame. 77 // Constructs a media pipeline that will execute on |task_runner|.
97 typedef base::Callback<void(const scoped_refptr<VideoFrame>&)> PaintCB; 78 PipelineImpl(const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
79 MediaLog* media_log);
80 ~PipelineImpl() override;
98 81
99 // Constructs a media pipeline that will execute on |task_runner|. 82 void SetErrorForTesting(PipelineStatus status);
100 Pipeline(const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, 83 bool HasWeakPtrsForTesting() const;
101 MediaLog* media_log);
102 ~Pipeline() override;
103 84
104 // Build a pipeline to using the given |demuxer| and |renderer| to construct 85 // Pipeline implementation.
105 // a filter chain, executing |seek_cb| when the initial seek has completed.
106 //
107 // The following permanent callbacks will be executed as follows up until
108 // Stop() has completed:
109 // |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
111 // reported already through another callback.
112 // |metadata_cb| will be executed when the content duration, container video
113 // size, start time, and whether the content has audio and/or
114 // video in supported formats are known.
115 // |buffering_state_cb| will be executed whenever there are changes in the
116 // overall buffering state of the pipeline.
117 // |duration_change_cb| optional callback that will be executed whenever the
118 // presentation duration changes.
119 // |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
121 // to decrypt the stream is not available.
122 // It is an error to call this method after the pipeline has already started.
123 void Start(Demuxer* demuxer, 86 void Start(Demuxer* demuxer,
124 scoped_ptr<Renderer> renderer, 87 scoped_ptr<Renderer> renderer,
125 const base::Closure& ended_cb, 88 const base::Closure& ended_cb,
126 const PipelineStatusCB& error_cb, 89 const PipelineStatusCB& error_cb,
127 const PipelineStatusCB& seek_cb, 90 const PipelineStatusCB& seek_cb,
128 const PipelineMetadataCB& metadata_cb, 91 const PipelineMetadataCB& metadata_cb,
129 const BufferingStateCB& buffering_state_cb, 92 const BufferingStateCB& buffering_state_cb,
130 const base::Closure& duration_change_cb, 93 const base::Closure& duration_change_cb,
131 const AddTextTrackCB& add_text_track_cb, 94 const AddTextTrackCB& add_text_track_cb,
132 const base::Closure& waiting_for_decryption_key_cb); 95 const base::Closure& waiting_for_decryption_key_cb) override;
133 96 void Stop(const base::Closure& stop_cb) override;
134 // Asynchronously stops the pipeline, executing |stop_cb| when the pipeline 97 void Seek(base::TimeDelta time, const PipelineStatusCB& seek_cb) override;
135 // teardown has completed. 98 bool IsRunning() const override;
136 // 99 double GetPlaybackRate() const override;
137 // Stop() must complete before destroying the pipeline. It it permissible to 100 void SetPlaybackRate(double playback_rate) override;
138 // call Stop() at any point during the lifetime of the pipeline. 101 void Suspend(const PipelineStatusCB& suspend_cb) override;
139 //
140 // It is safe to delete the pipeline during the execution of |stop_cb|.
141 void Stop(const base::Closure& stop_cb);
142
143 // 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.
145 //
146 // Clients are expected to call GetMediaTime() to check whether the seek
147 // succeeded.
148 //
149 // It is an error to call this method if the pipeline has not started or
150 // is suspended.
151 void Seek(base::TimeDelta time, const PipelineStatusCB& seek_cb);
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
171 // Suspend the pipeline, discarding the current renderer.
172 //
173 // While suspended, GetMediaTime() returns the presentation timestamp of the
174 // last rendered frame.
175 //
176 // It is an error to call this method if the pipeline has not started or is
177 // seeking.
178 void Suspend(const PipelineStatusCB& suspend_cb);
179
180 // Resume the pipeline with a new renderer, and initialize it with a seek.
181 void Resume(scoped_ptr<Renderer> renderer, 102 void Resume(scoped_ptr<Renderer> renderer,
182 base::TimeDelta timestamp, 103 base::TimeDelta timestamp,
183 const PipelineStatusCB& seek_cb); 104 const PipelineStatusCB& seek_cb) override;
184 105 float GetVolume() const override;
185 // Gets the current volume setting being used by the audio renderer. When 106 void SetVolume(float volume) override;
186 // the pipeline is started, this value will be 1.0f. Valid values range 107 base::TimeDelta GetMediaTime() const override;
187 // from 0.0f to 1.0f. 108 Ranges<base::TimeDelta> GetBufferedTimeRanges() const override;
188 float GetVolume() const; 109 base::TimeDelta GetMediaDuration() const override;
189 110 bool DidLoadingProgress() override;
190 // Attempt to set the volume of the audio renderer. Valid values for volume 111 PipelineStatistics GetStatistics() const override;
191 // range from 0.0f (muted) to 1.0f (full volume). This value affects all 112 void SetCdm(CdmContext* cdm_context,
192 // channels proportionately for multi-channel audio streams. 113 const CdmAttachedCB& cdm_attached_cb) override;
193 void SetVolume(float volume);
194
195 // Returns the current media playback time, which progresses from 0 until
196 // GetMediaDuration().
197 base::TimeDelta GetMediaTime() const;
198
199 // Get approximate time ranges of buffered media.
200 Ranges<base::TimeDelta> GetBufferedTimeRanges() const;
201
202 // Get the duration of the media in microseconds. If the duration has not
203 // been determined yet, then returns 0.
204 base::TimeDelta GetMediaDuration() const;
205
206 // Return true if loading progress has been made since the last time this
207 // method was called.
208 bool DidLoadingProgress();
209
210 // Gets the current pipeline statistics.
211 PipelineStatistics GetStatistics() const;
212
213 void SetCdm(CdmContext* cdm_context, const CdmAttachedCB& cdm_attached_cb);
214
215 void SetErrorForTesting(PipelineStatus status);
216 bool HasWeakPtrsForTesting() const;
217 114
218 private: 115 private:
219 FRIEND_TEST_ALL_PREFIXES(PipelineTest, GetBufferedTimeRanges); 116 FRIEND_TEST_ALL_PREFIXES(PipelineImplTest, GetBufferedTimeRanges);
220 FRIEND_TEST_ALL_PREFIXES(PipelineTest, EndedCallback); 117 FRIEND_TEST_ALL_PREFIXES(PipelineImplTest, EndedCallback);
221 FRIEND_TEST_ALL_PREFIXES(PipelineTest, AudioStreamShorterThanVideo); 118 FRIEND_TEST_ALL_PREFIXES(PipelineImplTest, AudioStreamShorterThanVideo);
222 friend class MediaLog; 119 friend class MediaLog;
223 120
224 // Pipeline states, as described above. 121 // Pipeline states, as described above.
225 enum State { 122 enum State {
226 kCreated, 123 kCreated,
227 kInitDemuxer, 124 kInitDemuxer,
228 kInitRenderer, 125 kInitRenderer,
229 kSeeking, 126 kSeeking,
230 kPlaying, 127 kPlaying,
231 kStopping, 128 kStopping,
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 scoped_ptr<SerialRunner> pending_callbacks_; 319 scoped_ptr<SerialRunner> pending_callbacks_;
423 320
424 // CdmContext to be used to decrypt (and decode) encrypted stream in this 321 // 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 322 // 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_|. 323 // been started. Then during Start(), this value will be set on |renderer_|.
427 CdmContext* pending_cdm_context_; 324 CdmContext* pending_cdm_context_;
428 325
429 base::ThreadChecker thread_checker_; 326 base::ThreadChecker thread_checker_;
430 327
431 // NOTE: Weak pointers must be invalidated before all other member variables. 328 // NOTE: Weak pointers must be invalidated before all other member variables.
432 base::WeakPtrFactory<Pipeline> weak_factory_; 329 base::WeakPtrFactory<PipelineImpl> weak_factory_;
433 330
434 DISALLOW_COPY_AND_ASSIGN(Pipeline); 331 DISALLOW_COPY_AND_ASSIGN(PipelineImpl);
435 }; 332 };
436 333
437 } // namespace media 334 } // namespace media
438 335
439 #endif // MEDIA_BASE_PIPELINE_H_ 336 #endif // MEDIA_BASE_PIPELINE_IMPL_H_
OLDNEW
« no previous file with comments | « media/base/pipeline.cc ('k') | media/base/pipeline_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698