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

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

Issue 1904793002: Move Pipeline permanent callbacks into Pipeline::Client interface. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: restored lock during stop Created 4 years, 7 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
OLDNEW
1 // Copyright (c) 2016 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_IMPL_H_ 5 #ifndef MEDIA_BASE_PIPELINE_IMPL_H_
6 #define MEDIA_BASE_PIPELINE_IMPL_H_ 6 #define MEDIA_BASE_PIPELINE_IMPL_H_
7 7
8 #include <memory> 8 #include <memory>
9 9
10 #include "base/gtest_prod_util.h" 10 #include "base/gtest_prod_util.h"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
13 #include "base/memory/weak_ptr.h" 13 #include "base/memory/weak_ptr.h"
14 #include "base/synchronization/lock.h" 14 #include "base/synchronization/lock.h"
15 #include "base/threading/thread_checker.h" 15 #include "base/threading/thread_checker.h"
16 #include "base/time/time.h" 16 #include "base/time/time.h"
17 #include "media/base/buffering_state.h" 17 #include "media/base/buffering_state.h"
18 #include "media/base/cdm_context.h" 18 #include "media/base/cdm_context.h"
19 #include "media/base/demuxer.h" 19 #include "media/base/demuxer.h"
20 #include "media/base/media_export.h" 20 #include "media/base/media_export.h"
21 #include "media/base/pipeline.h" 21 #include "media/base/pipeline.h"
22 #include "media/base/pipeline_status.h" 22 #include "media/base/pipeline_status.h"
23 #include "media/base/ranges.h" 23 #include "media/base/ranges.h"
24 #include "media/base/serial_runner.h" 24 #include "media/base/serial_runner.h"
25 #include "media/base/text_track.h" 25 #include "media/base/text_track.h"
26 26
27 namespace base { 27 namespace base {
28 class SingleThreadTaskRunner; 28 class SingleThreadTaskRunner;
29 class WaitableEvent;
29 } 30 }
30 31
31 namespace media { 32 namespace media {
32 33
33 class MediaLog; 34 class MediaLog;
34 class Renderer; 35 class Renderer;
35 class TextRenderer; 36 class TextRenderer;
36 37
37 // Pipeline runs the media pipeline. Filters are created and called on the 38 // Pipeline runs the media pipeline. Filters are created and called on the
38 // task runner injected into this object. Pipeline works like a state 39 // task runner injected into this object. Pipeline works like a state
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 // If any error ever happens, this object will transition to the "Error" state 71 // If any error ever happens, this object will transition to the "Error" state
71 // from any state. If Stop() is ever called, this object will transition to 72 // from any state. If Stop() is ever called, this object will transition to
72 // "Stopped" state. 73 // "Stopped" state.
73 // 74 //
74 // TODO(sandersd): It should be possible to pass through Suspended when going 75 // TODO(sandersd): It should be possible to pass through Suspended when going
75 // from InitDemuxer to InitRenderer, thereby eliminating the Resuming state. 76 // from InitDemuxer to InitRenderer, thereby eliminating the Resuming state.
76 // Some annoying differences between the two paths need to be removed first. 77 // Some annoying differences between the two paths need to be removed first.
77 class MEDIA_EXPORT PipelineImpl : public Pipeline, public DemuxerHost { 78 class MEDIA_EXPORT PipelineImpl : public Pipeline, public DemuxerHost {
78 public: 79 public:
79 // Constructs a media pipeline that will execute on |task_runner|. 80 // Constructs a media pipeline that will execute on |task_runner|.
80 PipelineImpl(const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, 81 PipelineImpl(
81 MediaLog* media_log); 82 const scoped_refptr<base::SingleThreadTaskRunner>& media_task_runner,
83 MediaLog* media_log);
82 ~PipelineImpl() override; 84 ~PipelineImpl() override;
83 85
84 void SetErrorForTesting(PipelineStatus status); 86 void SetErrorForTesting(PipelineStatus status);
85 bool HasWeakPtrsForTesting() const; 87 bool HasWeakPtrsForTesting() const;
86 88
87 // Pipeline implementation. 89 // Pipeline implementation.
88 void Start(Demuxer* demuxer, 90 void Start(Demuxer* demuxer,
89 std::unique_ptr<Renderer> renderer, 91 std::unique_ptr<Renderer> renderer,
90 const base::Closure& ended_cb, 92 Client* client,
91 const PipelineStatusCB& error_cb, 93 const PipelineStatusCB& seek_cb) override;
92 const PipelineStatusCB& seek_cb, 94 void Stop() override;
93 const PipelineMetadataCB& metadata_cb,
94 const BufferingStateCB& buffering_state_cb,
95 const base::Closure& duration_change_cb,
96 const AddTextTrackCB& add_text_track_cb,
97 const base::Closure& waiting_for_decryption_key_cb) override;
98 void Stop(const base::Closure& stop_cb) override;
99 void Seek(base::TimeDelta time, const PipelineStatusCB& seek_cb) override; 95 void Seek(base::TimeDelta time, const PipelineStatusCB& seek_cb) override;
100 bool IsRunning() const override; 96 bool IsRunning() const override;
101 double GetPlaybackRate() const override; 97 double GetPlaybackRate() const override;
102 void SetPlaybackRate(double playback_rate) override; 98 void SetPlaybackRate(double playback_rate) override;
103 void Suspend(const PipelineStatusCB& suspend_cb) override; 99 void Suspend(const PipelineStatusCB& suspend_cb) override;
104 void Resume(std::unique_ptr<Renderer> renderer, 100 void Resume(std::unique_ptr<Renderer> renderer,
105 base::TimeDelta timestamp, 101 base::TimeDelta timestamp,
106 const PipelineStatusCB& seek_cb) override; 102 const PipelineStatusCB& seek_cb) override;
107 float GetVolume() const override; 103 float GetVolume() const override;
108 void SetVolume(float volume) override; 104 void SetVolume(float volume) override;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 const TextTrackConfig& config) override; 147 const TextTrackConfig& config) override;
152 void RemoveTextStream(DemuxerStream* text_stream) override; 148 void RemoveTextStream(DemuxerStream* text_stream) override;
153 149
154 // Callback executed when a rendering error happened, initiating the teardown 150 // Callback executed when a rendering error happened, initiating the teardown
155 // sequence. 151 // sequence.
156 void OnError(PipelineStatus error); 152 void OnError(PipelineStatus error);
157 153
158 // Callback executed by filters to update statistics. 154 // Callback executed by filters to update statistics.
159 void OnUpdateStatistics(const PipelineStatistics& stats_delta); 155 void OnUpdateStatistics(const PipelineStatistics& stats_delta);
160 156
157 // Callback executed by renderer when waiting for decryption key.
158 void OnWaitingForDecryptionKey();
159
161 // The following "task" methods correspond to the public methods, but these 160 // The following "task" methods correspond to the public methods, but these
162 // methods are run as the result of posting a task to the Pipeline's 161 // methods are run as the result of posting a task to the Pipeline's
163 // task runner. 162 // task runner.
164 void StartTask(); 163 void StartTask();
165 164
166 // Suspends the pipeline, discarding the current renderer. 165 // Suspends the pipeline, discarding the current renderer.
167 void SuspendTask(const PipelineStatusCB& suspend_cb); 166 void SuspendTask(const PipelineStatusCB& suspend_cb);
168 167
169 // Resumes the pipeline with a new renderer, and initializes it with a seek. 168 // Resumes the pipeline with a new renderer, and initializes it with a seek.
170 void ResumeTask(std::unique_ptr<Renderer> renderer, 169 void ResumeTask(std::unique_ptr<Renderer> renderer,
171 base::TimeDelta timestamp, 170 base::TimeDelta timestamp,
172 const PipelineStatusCB& seek_sb); 171 const PipelineStatusCB& seek_sb);
173 172
174 // Stops and destroys all filters, placing the pipeline in the kStopped state. 173 // Stops and destroys all filters, placing the pipeline in the kStopped state.
175 void StopTask(const base::Closure& stop_cb); 174 void StopTask(base::WaitableEvent* event);
176 175
177 // Carries out stopping and destroying all filters, placing the pipeline in 176 // Carries out stopping and destroying all filters, placing the pipeline in
178 // the kStopped state. 177 // the kStopped state.
179 void ErrorChangedTask(PipelineStatus error); 178 void ErrorChangedTask(PipelineStatus error);
180 179
181 // Carries out notifying filters that the playback rate has changed. 180 // Carries out notifying filters that the playback rate has changed.
182 void PlaybackRateChangedTask(double playback_rate); 181 void PlaybackRateChangedTask(double playback_rate);
183 182
184 // Carries out notifying filters that the volume has changed. 183 // Carries out notifying filters that the volume has changed.
185 void VolumeChangedTask(float volume); 184 void VolumeChangedTask(float volume);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 // Kicks off initialization for each media object, executing |done_cb| with 217 // Kicks off initialization for each media object, executing |done_cb| with
219 // the result when completed. 218 // the result when completed.
220 void InitializeDemuxer(const PipelineStatusCB& done_cb); 219 void InitializeDemuxer(const PipelineStatusCB& done_cb);
221 void InitializeRenderer(const PipelineStatusCB& done_cb); 220 void InitializeRenderer(const PipelineStatusCB& done_cb);
222 221
223 void StateTransitionTask(PipelineStatus status); 222 void StateTransitionTask(PipelineStatus status);
224 223
225 // Initiates an asynchronous pause-flush-seek-preroll call sequence 224 // Initiates an asynchronous pause-flush-seek-preroll call sequence
226 // executing |done_cb| with the final status when completed. 225 // executing |done_cb| with the final status when completed.
227 void DoSeek(base::TimeDelta seek_timestamp, const PipelineStatusCB& done_cb); 226 void DoSeek(base::TimeDelta seek_timestamp, const PipelineStatusCB& done_cb);
228 227 // Stops media rendering and signals the |waiter| when done.
sandersd (OOO until July 31) 2016/05/02 18:37:47 Newline before comment.
alokp 2016/05/02 22:25:17 Done.
229 // Initiates an asynchronous pause-flush-stop call sequence executing 228 void DoStop(base::WaitableEvent* waiter);
230 // |done_cb| when completed.
231 void DoStop(const PipelineStatusCB& done_cb);
232 void OnStopCompleted(PipelineStatus status);
233 229
234 void ReportMetadata(); 230 void ReportMetadata();
235 231
236 void BufferingStateChanged(BufferingState new_buffering_state); 232 void BufferingStateChanged(BufferingState new_buffering_state);
237 233
234 // Task runner of the thread on which this class is constructed.
235 // Also used to post notifications on Pipeline::Client object.
236 const scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_;
238 // Task runner used to execute pipeline tasks. 237 // Task runner used to execute pipeline tasks.
sandersd (OOO until July 31) 2016/05/02 18:37:47 Newline before comment.
alokp 2016/05/02 22:25:17 Done.
239 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; 238 const scoped_refptr<base::SingleThreadTaskRunner> media_task_runner_;
240 239
241 // MediaLog to which to log events. 240 // MediaLog to which to log events.
242 scoped_refptr<MediaLog> media_log_; 241 scoped_refptr<MediaLog> media_log_;
243 242
244 // Lock used to serialize access for the following data members. 243 // Lock used to serialize access for the following data members.
245 mutable base::Lock lock_; 244 mutable base::Lock lock_;
246 245
247 // Whether or not the pipeline is running. 246 // Whether or not the pipeline is running.
248 bool running_; 247 bool running_;
249 248
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 // set to kNoTimestamp(). 286 // set to kNoTimestamp().
288 base::TimeDelta suspend_timestamp_; 287 base::TimeDelta suspend_timestamp_;
289 288
290 // Whether we've received the audio/video/text ended events. 289 // Whether we've received the audio/video/text ended events.
291 bool renderer_ended_; 290 bool renderer_ended_;
292 bool text_renderer_ended_; 291 bool text_renderer_ended_;
293 292
294 // Temporary callback used for Start(), Seek(), and Resume(). 293 // Temporary callback used for Start(), Seek(), and Resume().
295 PipelineStatusCB seek_cb_; 294 PipelineStatusCB seek_cb_;
296 295
297 // Temporary callback used for Stop().
298 base::Closure stop_cb_;
299
300 // Temporary callback used for Suspend(). 296 // Temporary callback used for Suspend().
301 PipelineStatusCB suspend_cb_; 297 PipelineStatusCB suspend_cb_;
302 298
303 // Permanent callbacks passed in via Start().
304 base::Closure ended_cb_;
305 PipelineStatusCB error_cb_;
306 PipelineMetadataCB metadata_cb_;
307 BufferingStateCB buffering_state_cb_;
308 base::Closure duration_change_cb_;
309 AddTextTrackCB add_text_track_cb_;
310 base::Closure waiting_for_decryption_key_cb_;
311
312 // Holds the initialized demuxer. Used for seeking. Owned by client. 299 // Holds the initialized demuxer. Used for seeking. Owned by client.
313 Demuxer* demuxer_; 300 Demuxer* demuxer_;
314 301
315 // Holds the initialized renderers. Used for setting the volume, 302 // Holds the initialized renderers. Used for setting the volume,
316 // playback rate, and determining when playback has finished. 303 // playback rate, and determining when playback has finished.
317 std::unique_ptr<Renderer> renderer_; 304 std::unique_ptr<Renderer> renderer_;
318 std::unique_ptr<TextRenderer> text_renderer_; 305 std::unique_ptr<TextRenderer> text_renderer_;
319 306
307 // Holds the client passed on Start().
308 Client* client_;
309
320 PipelineStatistics statistics_; 310 PipelineStatistics statistics_;
321 311
322 std::unique_ptr<SerialRunner> pending_callbacks_; 312 std::unique_ptr<SerialRunner> pending_callbacks_;
323 313
324 // The CdmContext to be used to decrypt (and decode) encrypted stream in this 314 // The CdmContext to be used to decrypt (and decode) encrypted stream in this
325 // pipeline. It is set when SetCdm() succeeds on the renderer (or when 315 // pipeline. It is set when SetCdm() succeeds on the renderer (or when
326 // SetCdm() is called before Start()), after which it is guaranteed to outlive 316 // SetCdm() is called before Start()), after which it is guaranteed to outlive
327 // this pipeline. The saved value will be used to configure new renderers, 317 // this pipeline. The saved value will be used to configure new renderers,
328 // when starting or resuming. 318 // when starting or resuming.
329 CdmContext* cdm_context_; 319 CdmContext* cdm_context_;
330 320
331 base::ThreadChecker thread_checker_; 321 base::ThreadChecker thread_checker_;
332 322
333 // A weak pointer that can be safely copied on the media thread. 323 // A weak pointer that can be safely copied on the media thread.
334 base::WeakPtr<PipelineImpl> weak_this_; 324 base::WeakPtr<PipelineImpl> weak_this_;
335 325
336 // Weak pointers must be created on the main thread, and must be dereferenced 326 // Weak pointers must be created on the main thread, and must be dereferenced
337 // on the media thread. 327 // on the media thread.
338 // 328 //
339 // Declared last so that weak pointers will be invalidated before all other 329 // Declared last so that weak pointers will be invalidated before all other
340 // member variables. 330 // member variables.
341 base::WeakPtrFactory<PipelineImpl> weak_factory_; 331 base::WeakPtrFactory<PipelineImpl> weak_factory_;
342 332
343 DISALLOW_COPY_AND_ASSIGN(PipelineImpl); 333 DISALLOW_COPY_AND_ASSIGN(PipelineImpl);
344 }; 334 };
345 335
346 } // namespace media 336 } // namespace media
347 337
348 #endif // MEDIA_BASE_PIPELINE_IMPL_H_ 338 #endif // MEDIA_BASE_PIPELINE_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698