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

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: CHECK waiter PostTask 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"
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 // 69 //
70 // If any error ever happens, this object will transition to the "Error" state 70 // 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 71 // from any state. If Stop() is ever called, this object will transition to
72 // "Stopped" state. 72 // "Stopped" state.
73 // 73 //
74 // TODO(sandersd): It should be possible to pass through Suspended when going 74 // TODO(sandersd): It should be possible to pass through Suspended when going
75 // from InitDemuxer to InitRenderer, thereby eliminating the Resuming state. 75 // from InitDemuxer to InitRenderer, thereby eliminating the Resuming state.
76 // Some annoying differences between the two paths need to be removed first. 76 // Some annoying differences between the two paths need to be removed first.
77 class MEDIA_EXPORT PipelineImpl : public Pipeline, public DemuxerHost { 77 class MEDIA_EXPORT PipelineImpl : public Pipeline, public DemuxerHost {
78 public: 78 public:
79 // Constructs a media pipeline that will execute on |task_runner|. 79 // Constructs a media pipeline that will execute media tasks on
80 PipelineImpl(const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, 80 // |media_task_runner|.
81 MediaLog* media_log); 81 PipelineImpl(
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,
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
229 // Initiates an asynchronous pause-flush-stop call sequence executing 228 // Stops media rendering and executes |stop_cb_| when done.
230 // |done_cb| when completed. 229 void DoStop();
231 void DoStop(const PipelineStatusCB& done_cb);
232 void OnStopCompleted(PipelineStatus status);
233 230
234 void ReportMetadata(); 231 void ReportMetadata();
235 232
236 void BufferingStateChanged(BufferingState new_buffering_state); 233 void BufferingStateChanged(BufferingState new_buffering_state);
237 234
235 // Task runner of the thread on which this class is constructed.
236 // Also used to post notifications on Pipeline::Client object.
237 const scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_;
238
238 // Task runner used to execute pipeline tasks. 239 // Task runner used to execute pipeline tasks.
239 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; 240 const scoped_refptr<base::SingleThreadTaskRunner> media_task_runner_;
240 241
241 // MediaLog to which to log events. 242 // MediaLog to which to log events.
242 scoped_refptr<MediaLog> media_log_; 243 scoped_refptr<MediaLog> media_log_;
243 244
244 // Lock used to serialize access for the following data members. 245 // Lock used to serialize access for the following data members.
245 mutable base::Lock lock_; 246 mutable base::Lock lock_;
246 247
247 // Whether or not the pipeline is running. 248 // Whether or not the pipeline is running.
248 bool running_; 249 bool running_;
249 250
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 // set to kNoTimestamp(). 288 // set to kNoTimestamp().
288 base::TimeDelta suspend_timestamp_; 289 base::TimeDelta suspend_timestamp_;
289 290
290 // Whether we've received the audio/video/text ended events. 291 // Whether we've received the audio/video/text ended events.
291 bool renderer_ended_; 292 bool renderer_ended_;
292 bool text_renderer_ended_; 293 bool text_renderer_ended_;
293 294
294 // Temporary callback used for Start(), Seek(), and Resume(). 295 // Temporary callback used for Start(), Seek(), and Resume().
295 PipelineStatusCB seek_cb_; 296 PipelineStatusCB seek_cb_;
296 297
297 // Temporary callback used for Stop(). 298 // Temporary callback used for Stop().
xhwang 2016/05/04 06:32:22 This is really for StopTask() now. Actually it s
alokp 2016/05/04 17:40:01 In StopTask, we skip calling DoStop if the pipelin
298 base::Closure stop_cb_; 299 base::Closure stop_cb_;
299 300
300 // Temporary callback used for Suspend(). 301 // Temporary callback used for Suspend().
301 PipelineStatusCB suspend_cb_; 302 PipelineStatusCB suspend_cb_;
302 303
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. 304 // Holds the initialized demuxer. Used for seeking. Owned by client.
313 Demuxer* demuxer_; 305 Demuxer* demuxer_;
314 306
315 // Holds the initialized renderers. Used for setting the volume, 307 // Holds the initialized renderers. Used for setting the volume,
316 // playback rate, and determining when playback has finished. 308 // playback rate, and determining when playback has finished.
317 std::unique_ptr<Renderer> renderer_; 309 std::unique_ptr<Renderer> renderer_;
318 std::unique_ptr<TextRenderer> text_renderer_; 310 std::unique_ptr<TextRenderer> text_renderer_;
319 311
312 // Holds the client passed on Start().
313 std::unique_ptr<base::WeakPtrFactory<Client>> client_weak_factory_;
xhwang 2016/05/04 06:32:22 Can you add comments about the threading expectati
alokp 2016/05/04 17:40:01 Added comments and also created weak_client_ as su
314
320 PipelineStatistics statistics_; 315 PipelineStatistics statistics_;
321 316
322 std::unique_ptr<SerialRunner> pending_callbacks_; 317 std::unique_ptr<SerialRunner> pending_callbacks_;
323 318
324 // The CdmContext to be used to decrypt (and decode) encrypted stream in this 319 // 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 320 // 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 321 // 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, 322 // this pipeline. The saved value will be used to configure new renderers,
328 // when starting or resuming. 323 // when starting or resuming.
329 CdmContext* cdm_context_; 324 CdmContext* cdm_context_;
330 325
331 base::ThreadChecker thread_checker_; 326 base::ThreadChecker thread_checker_;
332 327
333 // A weak pointer that can be safely copied on the media thread. 328 // A weak pointer that can be safely copied on the media thread.
334 base::WeakPtr<PipelineImpl> weak_this_; 329 base::WeakPtr<PipelineImpl> weak_this_;
335 330
336 // Weak pointers must be created on the main thread, and must be dereferenced 331 // Weak pointers must be created on the main thread, and must be dereferenced
337 // on the media thread. 332 // on the media thread.
338 // 333 //
339 // Declared last so that weak pointers will be invalidated before all other 334 // Declared last so that weak pointers will be invalidated before all other
340 // member variables. 335 // member variables.
341 base::WeakPtrFactory<PipelineImpl> weak_factory_; 336 base::WeakPtrFactory<PipelineImpl> weak_factory_;
342 337
343 DISALLOW_COPY_AND_ASSIGN(PipelineImpl); 338 DISALLOW_COPY_AND_ASSIGN(PipelineImpl);
344 }; 339 };
345 340
346 } // namespace media 341 } // namespace media
347 342
348 #endif // MEDIA_BASE_PIPELINE_IMPL_H_ 343 #endif // MEDIA_BASE_PIPELINE_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698