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

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: Add a message loop to the test. Created 4 years, 9 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.
193 // TODO(hubbe): Make private.
DaleCurtis 2016/02/26 02:54:24 Please explicitly use the words WMPI_CAST so that
sandersd (OOO until July 31) 2016/02/26 22:10:48 Done.
194 void OnPipelineSeeked(bool time_updated);
195
201 private: 196 private:
202 // Ask for the pipeline to be suspended, will call Suspend() when ready. 197 void OnPipelineSuspended();
203 // (Possibly immediately.) 198 void OnPipelineEnded();
204 void ScheduleSuspend(); 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);
205 205
206 // Initiate suspending the pipeline. 206 // Actually seek. Avoids causing |should_notify_time_changed_| to be set when
207 void Suspend(); 207 // |time_updated| is false.
208 208 void DoSeek(base::TimeDelta time, bool time_updated);
209 // Ask for the pipeline to be resumed, will call Resume() when ready.
210 // (Possibly immediately.)
211 void ScheduleResume();
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_;
301
302 // |pipeline_controller_| references |pipeline_| and therefore must be
303 // constructed after and destructed before |pipeline_|.
311 PipelineImpl pipeline_; 304 PipelineImpl pipeline_;
305 PipelineController pipeline_controller_;
312 306
313 // The LoadType passed in the |load_type| parameter of the load() call. 307 // The LoadType passed in the |load_type| parameter of the load() call.
314 LoadType load_type_; 308 LoadType load_type_;
315 309
316 // Cache of metadata for answering hasAudio(), hasVideo(), and naturalSize(). 310 // Cache of metadata for answering hasAudio(), hasVideo(), and naturalSize().
317 PipelineMetadata pipeline_metadata_; 311 PipelineMetadata pipeline_metadata_;
318 312
319 // Whether the video is known to be opaque or not. 313 // Whether the video is known to be opaque or not.
320 bool opaque_; 314 bool opaque_;
321 315
322 // Playback state. 316 // Playback state.
323 // 317 //
324 // TODO(scherkus): we have these because Pipeline favours the simplicity of a 318 // TODO(scherkus): we have these because Pipeline favours the simplicity of a
325 // single "playback rate" over worrying about paused/stopped etc... It forces 319 // single "playback rate" over worrying about paused/stopped etc... It forces
326 // all clients to manage the pause+playback rate externally, but is that 320 // all clients to manage the pause+playback rate externally, but is that
327 // really a bad thing? 321 // really a bad thing?
328 // 322 //
329 // TODO(scherkus): since SetPlaybackRate(0) is asynchronous and we don't want 323 // 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 324 // 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 325 // time we pause and then return that value in currentTime(). Otherwise our
332 // clock can creep forward a little bit while the asynchronous 326 // clock can creep forward a little bit while the asynchronous
333 // SetPlaybackRate(0) is being executed. 327 // SetPlaybackRate(0) is being executed.
334 double playback_rate_; 328 double playback_rate_;
329
330 // Set while paused. |paused_time_| is only valid when |paused_| is true.
335 bool paused_; 331 bool paused_;
336 base::TimeDelta paused_time_; 332 base::TimeDelta paused_time_;
333
334 // Set when starting, seeking, and resuming (all of which require a Pipeline
335 // seek). |seek_time_| is only valid when |seeking_| is true.
337 bool seeking_; 336 bool seeking_;
338
339 // Set when seeking (|seeking_| is true) or resuming.
340 base::TimeDelta seek_time_; 337 base::TimeDelta seek_time_;
341 338
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 339 // 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 340 // in order to destruct and reinitialize the decoders. This is separate from
363 // |pending_resume_| and |pending_suspend_| because they can be elided in 341 // |pending_resume_| and |pending_suspend_| because they can be elided in
364 // certain cases, whereas for a restart they must happen. 342 // certain cases, whereas for a restart they must happen.
365 // TODO(sandersd,watk): Create a simpler interface for a pipeline restart. 343 // TODO(sandersd,watk): Create a simpler interface for a pipeline restart.
366 bool pending_suspend_resume_cycle_; 344 bool pending_suspend_resume_cycle_;
367 345
368 // TODO(scherkus): Replace with an explicit ended signal to HTMLMediaElement, 346 // TODO(scherkus): Replace with an explicit ended signal to HTMLMediaElement,
369 // see http://crbug.com/409280 347 // see http://crbug.com/409280
370 bool ended_; 348 bool ended_;
371 349
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 350 // Tracks whether to issue time changed notifications during buffering state
381 // changes. 351 // changes.
382 bool should_notify_time_changed_; 352 bool should_notify_time_changed_;
383 353
384 bool fullscreen_; 354 bool fullscreen_;
385 355
386 // Whether the current decoder requires a restart on fullscreen transitions. 356 // Whether the current decoder requires a restart on fullscreen transitions.
387 bool decoder_requires_restart_for_fullscreen_; 357 bool decoder_requires_restart_for_fullscreen_;
388 358
389 blink::WebMediaPlayerClient* client_; 359 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. 423 // For requesting surfaces on behalf of the Android H/W decoder in fullscreen.
454 // This will be null everywhere but Android. 424 // This will be null everywhere but Android.
455 SurfaceManager* surface_manager_; 425 SurfaceManager* surface_manager_;
456 426
457 DISALLOW_COPY_AND_ASSIGN(WebMediaPlayerImpl); 427 DISALLOW_COPY_AND_ASSIGN(WebMediaPlayerImpl);
458 }; 428 };
459 429
460 } // namespace media 430 } // namespace media
461 431
462 #endif // MEDIA_BLINK_WEBMEDIAPLAYER_IMPL_H_ 432 #endif // MEDIA_BLINK_WEBMEDIAPLAYER_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698