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

Side by Side Diff: media/blink/webmediaplayer_impl.h

Issue 1641423002: Re-land extract state management from WebMediaPlayerImpl. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: More unit tests. 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_BLINK_WEBMEDIAPLAYER_IMPL_H_ 5 #ifndef MEDIA_BLINK_WEBMEDIAPLAYER_IMPL_H_
6 #define MEDIA_BLINK_WEBMEDIAPLAYER_IMPL_H_ 6 #define MEDIA_BLINK_WEBMEDIAPLAYER_IMPL_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <string> 10 #include <string>
(...skipping 12 matching lines...) Expand all
23 #include "media/base/surface_manager.h" 23 #include "media/base/surface_manager.h"
24 #include "media/base/text_track.h" 24 #include "media/base/text_track.h"
25 #include "media/blink/buffered_data_source.h" 25 #include "media/blink/buffered_data_source.h"
26 #include "media/blink/buffered_data_source_host_impl.h" 26 #include "media/blink/buffered_data_source_host_impl.h"
27 #include "media/blink/media_blink_export.h" 27 #include "media/blink/media_blink_export.h"
28 #include "media/blink/multibuffer_data_source.h" 28 #include "media/blink/multibuffer_data_source.h"
29 #include "media/blink/video_frame_compositor.h" 29 #include "media/blink/video_frame_compositor.h"
30 #include "media/blink/webmediaplayer_delegate.h" 30 #include "media/blink/webmediaplayer_delegate.h"
31 #include "media/blink/webmediaplayer_params.h" 31 #include "media/blink/webmediaplayer_params.h"
32 #include "media/blink/webmediaplayer_util.h" 32 #include "media/blink/webmediaplayer_util.h"
33 #include "media/filters/pipeline_controller.h"
33 #include "media/renderers/skcanvas_video_renderer.h" 34 #include "media/renderers/skcanvas_video_renderer.h"
34 #include "third_party/WebKit/public/platform/WebAudioSourceProvider.h" 35 #include "third_party/WebKit/public/platform/WebAudioSourceProvider.h"
35 #include "third_party/WebKit/public/platform/WebContentDecryptionModuleResult.h" 36 #include "third_party/WebKit/public/platform/WebContentDecryptionModuleResult.h"
36 #include "third_party/WebKit/public/platform/WebMediaPlayer.h" 37 #include "third_party/WebKit/public/platform/WebMediaPlayer.h"
37 #include "url/gurl.h" 38 #include "url/gurl.h"
38 39
39 #if defined(OS_ANDROID) // WMPI_CAST 40 #if defined(OS_ANDROID) // WMPI_CAST
40 // Delete this file when WMPI_CAST is no longer needed. 41 // Delete this file when WMPI_CAST is no longer needed.
41 #include "media/blink/webmediaplayer_cast_android.h" 42 #include "media/blink/webmediaplayer_cast_android.h"
42 #endif 43 #endif
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 159
159 blink::WebAudioSourceProvider* audioSourceProvider() override; 160 blink::WebAudioSourceProvider* audioSourceProvider() override;
160 161
161 void setContentDecryptionModule( 162 void setContentDecryptionModule(
162 blink::WebContentDecryptionModule* cdm, 163 blink::WebContentDecryptionModule* cdm,
163 blink::WebContentDecryptionModuleResult result) override; 164 blink::WebContentDecryptionModuleResult result) override;
164 165
165 void enteredFullscreen() override; 166 void enteredFullscreen() override;
166 void exitedFullscreen() override; 167 void exitedFullscreen() override;
167 168
168 void OnPipelineSeeked(bool time_changed, PipelineStatus status);
169 void OnPipelineSuspended(PipelineStatus status);
170 void OnPipelineEnded();
171 void OnPipelineError(PipelineStatus error);
172 void OnPipelineMetadata(PipelineMetadata metadata);
173 void OnPipelineBufferingStateChanged(BufferingState buffering_state);
174 void OnDemuxerOpened();
175 void OnAddTextTrack(const TextTrackConfig& config,
176 const AddTextTrackDoneCB& done_cb);
177
178 // WebMediaPlayerDelegate::Observer implementation. 169 // WebMediaPlayerDelegate::Observer implementation.
179 void OnHidden(bool must_suspend) override; 170 void OnHidden(bool must_suspend) override;
180 void OnShown() override; 171 void OnShown() override;
181 void OnPlay() override; 172 void OnPlay() override;
182 void OnPause() override; 173 void OnPause() override;
183 void OnVolumeMultiplierUpdate(double multiplier) override; 174 void OnVolumeMultiplierUpdate(double multiplier) override;
184 175
185 #if defined(OS_ANDROID) // WMPI_CAST 176 #if defined(OS_ANDROID) // WMPI_CAST
186 bool isRemote() const override; 177 bool isRemote() const override;
187 void requestRemotePlayback() override; 178 void requestRemotePlayback() override;
188 void requestRemotePlaybackControl() override; 179 void requestRemotePlaybackControl() override;
189 180
190 void SetMediaPlayerManager( 181 void SetMediaPlayerManager(
191 RendererMediaPlayerManagerInterface* media_player_manager); 182 RendererMediaPlayerManagerInterface* media_player_manager);
192 void OnRemotePlaybackEnded(); 183 void OnRemotePlaybackEnded();
193 void OnDisconnectedFromRemoteDevice(double t); 184 void OnDisconnectedFromRemoteDevice(double t);
194 void SuspendForRemote(); 185 void SuspendForRemote();
195 void DisplayCastFrameAfterSuspend(const scoped_refptr<VideoFrame>& new_frame, 186 void DisplayCastFrameAfterSuspend(const scoped_refptr<VideoFrame>& new_frame,
196 PipelineStatus status); 187 PipelineStatus status);
197 gfx::Size GetCanvasSize() const; 188 gfx::Size GetCanvasSize() const;
198 void SetDeviceScaleFactor(float scale_factor); 189 void SetDeviceScaleFactor(float scale_factor);
199 #endif 190 #endif
200 191
192 // Called from WebMediaPlayerCast.
DaleCurtis 2016/02/25 01:58:29 Mark with TODO WMPI_CAST make private?
sandersd (OOO until July 31) 2016/02/25 20:33:46 Done.
193 void OnPipelineSeeked(bool time_updated);
194
201 private: 195 private:
202 // Ask for the pipeline to be suspended, will call Suspend() when ready. 196 void OnPipelineSuspended();
203 // (Possibly immediately.)
204 void ScheduleSuspend();
205 197
DaleCurtis 2016/02/25 01:58:30 Extra space?
sandersd (OOO until July 31) 2016/02/25 20:33:46 The methods were distinguished by whether they wer
206 // Initiate suspending the pipeline. 198 void OnPipelineEnded();
207 void Suspend(); 199 void OnPipelineError(PipelineStatus error);
200 void OnPipelineMetadata(PipelineMetadata metadata);
201 void OnPipelineBufferingStateChanged(BufferingState buffering_state);
202 void OnDemuxerOpened();
203 void OnAddTextTrack(const TextTrackConfig& config,
204 const AddTextTrackDoneCB& done_cb);
208 205
209 // Ask for the pipeline to be resumed, will call Resume() when ready. 206 // Actually seek. Avoids causing |should_notify_time_changed_| to be set when
210 // (Possibly immediately.) 207 // |renderer_initiated| is true.
211 void ScheduleResume(); 208 void DoSeek(base::TimeDelta time, bool renderer_initiated);
212
213 // Initiate resuming the pipeline.
214 void Resume();
215 209
216 // Ask for the renderer to be restarted (destructed and recreated). 210 // Ask for the renderer to be restarted (destructed and recreated).
217 void ScheduleRestart(); 211 void ScheduleRestart();
218 212
219 // Called after |defer_load_cb_| has decided to allow the load. If 213 // Called after |defer_load_cb_| has decided to allow the load. If
220 // |defer_load_cb_| is null this is called immediately. 214 // |defer_load_cb_| is null this is called immediately.
221 void DoLoad(LoadType load_type, 215 void DoLoad(LoadType load_type,
222 const blink::WebURL& url, 216 const blink::WebURL& url,
223 CORSMode cors_mode); 217 CORSMode cors_mode);
224 218
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 // is not available. 259 // is not available.
266 void OnWaitingForDecryptionKey(); 260 void OnWaitingForDecryptionKey();
267 261
268 // Sets |cdm_context| on the pipeline and fires |cdm_attached_cb| when done. 262 // Sets |cdm_context| on the pipeline and fires |cdm_attached_cb| when done.
269 // Parameter order is reversed for easy binding. 263 // Parameter order is reversed for easy binding.
270 void SetCdm(const CdmAttachedCB& cdm_attached_cb, CdmContext* cdm_context); 264 void SetCdm(const CdmAttachedCB& cdm_attached_cb, CdmContext* cdm_context);
271 265
272 // Called when a CDM has been attached to the |pipeline_|. 266 // Called when a CDM has been attached to the |pipeline_|.
273 void OnCdmAttached(bool success); 267 void OnCdmAttached(bool success);
274 268
275 // Updates |paused_time_| to the current media time with consideration for the
276 // |ended_| state by clamping current time to duration upon |ended_|.
277 void UpdatePausedTime();
278
279 // Notifies |delegate_| that playback has started or was paused; also starts 269 // Notifies |delegate_| that playback has started or was paused; also starts
280 // or stops the memory usage reporting timer respectively. 270 // or stops the memory usage reporting timer respectively.
281 void NotifyPlaybackStarted(); 271 void NotifyPlaybackStarted();
282 void NotifyPlaybackPaused(); 272 void NotifyPlaybackPaused();
283 273
284 // Called at low frequency to tell external observers how much memory we're 274 // Called at low frequency to tell external observers how much memory we're
285 // using for video playback. Called by |memory_usage_reporting_timer_|. 275 // using for video playback. Called by |memory_usage_reporting_timer_|.
286 // Memory usage reporting is done in two steps, because |demuxer_| must be 276 // Memory usage reporting is done in two steps, because |demuxer_| must be
287 // accessed on the media thread. 277 // accessed on the media thread.
288 void ReportMemoryUsage(); 278 void ReportMemoryUsage();
(...skipping 12 matching lines...) Expand all
301 // setBufferingStrategy(). 291 // setBufferingStrategy().
302 BufferedDataSource::BufferingStrategy buffering_strategy_; 292 BufferedDataSource::BufferingStrategy buffering_strategy_;
303 293
304 // Task runner for posting tasks on Chrome's main thread. Also used 294 // Task runner for posting tasks on Chrome's main thread. Also used
305 // for DCHECKs so methods calls won't execute in the wrong thread. 295 // for DCHECKs so methods calls won't execute in the wrong thread.
306 const scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; 296 const scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_;
307 297
308 scoped_refptr<base::SingleThreadTaskRunner> media_task_runner_; 298 scoped_refptr<base::SingleThreadTaskRunner> media_task_runner_;
309 scoped_refptr<base::TaskRunner> worker_task_runner_; 299 scoped_refptr<base::TaskRunner> worker_task_runner_;
310 scoped_refptr<MediaLog> media_log_; 300 scoped_refptr<MediaLog> media_log_;
311 PipelineImpl pipeline_; 301 PipelineImpl pipeline_;
DaleCurtis 2016/02/25 01:58:30 Might add a comment here that pipeline_controller_
sandersd (OOO until July 31) 2016/02/25 20:33:46 Done.
302 PipelineController pipeline_controller_;
312 303
313 // The LoadType passed in the |load_type| parameter of the load() call. 304 // The LoadType passed in the |load_type| parameter of the load() call.
314 LoadType load_type_; 305 LoadType load_type_;
315 306
316 // Cache of metadata for answering hasAudio(), hasVideo(), and naturalSize(). 307 // Cache of metadata for answering hasAudio(), hasVideo(), and naturalSize().
317 PipelineMetadata pipeline_metadata_; 308 PipelineMetadata pipeline_metadata_;
318 309
319 // Whether the video is known to be opaque or not. 310 // Whether the video is known to be opaque or not.
320 bool opaque_; 311 bool opaque_;
321 312
322 // Playback state. 313 // Playback state.
323 // 314 //
324 // TODO(scherkus): we have these because Pipeline favours the simplicity of a 315 // TODO(scherkus): we have these because Pipeline favours the simplicity of a
325 // single "playback rate" over worrying about paused/stopped etc... It forces 316 // single "playback rate" over worrying about paused/stopped etc... It forces
326 // all clients to manage the pause+playback rate externally, but is that 317 // all clients to manage the pause+playback rate externally, but is that
327 // really a bad thing? 318 // really a bad thing?
328 // 319 //
329 // TODO(scherkus): since SetPlaybackRate(0) is asynchronous and we don't want 320 // TODO(scherkus): since SetPlaybackRate(0) is asynchronous and we don't want
330 // to hang the render thread during pause(), we record the time at the same 321 // to hang the render thread during pause(), we record the time at the same
331 // time we pause and then return that value in currentTime(). Otherwise our 322 // time we pause and then return that value in currentTime(). Otherwise our
332 // clock can creep forward a little bit while the asynchronous 323 // clock can creep forward a little bit while the asynchronous
333 // SetPlaybackRate(0) is being executed. 324 // SetPlaybackRate(0) is being executed.
334 double playback_rate_; 325 double playback_rate_;
326
327 // Set while paused. |paused_time_| is only valid when |paused_| is true.
335 bool paused_; 328 bool paused_;
336 base::TimeDelta paused_time_; 329 base::TimeDelta paused_time_;
330
331 // Set when starting, seeking, and resuming (all of which require a Pipeline
332 // seek). |seek_time_| is only valid when |seeking_| is true.
337 bool seeking_; 333 bool seeking_;
338
339 // Set when seeking (|seeking_| is true) or resuming.
340 base::TimeDelta seek_time_; 334 base::TimeDelta seek_time_;
341 335
342 // Set when a suspend is required but another suspend or seek is in progress.
343 bool pending_suspend_;
344
345 // Set when suspending immediately after a seek. The time change will happen
346 // after Resume().
347 bool pending_time_change_;
348
349 // Set when a resume is required but suspending is in progress.
350 bool pending_resume_;
351
352 // Set for the entire period between suspend starting and resume completing.
353 bool suspending_;
354
355 // Set while suspending to detect double-suspend.
356 bool suspended_;
357
358 // Set while resuming to detect double-resume.
359 bool resuming_;
360
361 // Set when doing a restart (a suspend and resume in sequence) of the pipeline 336 // Set when doing a restart (a suspend and resume in sequence) of the pipeline
362 // in order to destruct and reinitialize the decoders. This is separate from 337 // in order to destruct and reinitialize the decoders. This is separate from
363 // |pending_resume_| and |pending_suspend_| because they can be elided in 338 // |pending_resume_| and |pending_suspend_| because they can be elided in
364 // certain cases, whereas for a restart they must happen. 339 // certain cases, whereas for a restart they must happen.
365 // TODO(sandersd,watk): Create a simpler interface for a pipeline restart. 340 // TODO(sandersd,watk): Create a simpler interface for a pipeline restart.
366 bool pending_suspend_resume_cycle_; 341 bool pending_suspend_resume_cycle_;
367 342
368 // TODO(scherkus): Replace with an explicit ended signal to HTMLMediaElement, 343 // TODO(scherkus): Replace with an explicit ended signal to HTMLMediaElement,
369 // see http://crbug.com/409280 344 // see http://crbug.com/409280
370 bool ended_; 345 bool ended_;
371 346
372 // Indicates that a seek is queued after the current seek completes or, if the
373 // pipeline is suspended, after it resumes. Only the last queued seek will
374 // have any effect.
375 bool pending_seek_;
376
377 // |pending_seek_time_| is meaningless when |pending_seek_| is false.
378 base::TimeDelta pending_seek_time_;
379
380 // Tracks whether to issue time changed notifications during buffering state 347 // Tracks whether to issue time changed notifications during buffering state
381 // changes. 348 // changes.
382 bool should_notify_time_changed_; 349 bool should_notify_time_changed_;
383 350
384 bool fullscreen_; 351 bool fullscreen_;
385 352
386 // Whether the current decoder requires a restart on fullscreen transitions. 353 // Whether the current decoder requires a restart on fullscreen transitions.
387 bool decoder_requires_restart_for_fullscreen_; 354 bool decoder_requires_restart_for_fullscreen_;
388 355
389 blink::WebMediaPlayerClient* client_; 356 blink::WebMediaPlayerClient* client_;
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 // For requesting surfaces on behalf of the Android H/W decoder in fullscreen. 420 // For requesting surfaces on behalf of the Android H/W decoder in fullscreen.
454 // This will be null everywhere but Android. 421 // This will be null everywhere but Android.
455 SurfaceManager* surface_manager_; 422 SurfaceManager* surface_manager_;
456 423
457 DISALLOW_COPY_AND_ASSIGN(WebMediaPlayerImpl); 424 DISALLOW_COPY_AND_ASSIGN(WebMediaPlayerImpl);
458 }; 425 };
459 426
460 } // namespace media 427 } // namespace media
461 428
462 #endif // MEDIA_BLINK_WEBMEDIAPLAYER_IMPL_H_ 429 #endif // MEDIA_BLINK_WEBMEDIAPLAYER_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698