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

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

Issue 2366373003: Not for submission. fastSeek prototype. (Closed)
Patch Set: Created 4 years, 2 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/blink/webmediaplayer_impl.h ('k') | media/filters/pipeline_controller.h » ('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 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 #include "media/blink/webmediaplayer_impl.h" 5 #include "media/blink/webmediaplayer_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 #include <limits> 9 #include <limits>
10 #include <string> 10 #include <string>
(...skipping 16 matching lines...) Expand all
27 #include "build/build_config.h" 27 #include "build/build_config.h"
28 #include "cc/blink/web_layer_impl.h" 28 #include "cc/blink/web_layer_impl.h"
29 #include "cc/layers/video_layer.h" 29 #include "cc/layers/video_layer.h"
30 #include "media/audio/null_audio_sink.h" 30 #include "media/audio/null_audio_sink.h"
31 #include "media/base/bind_to_current_loop.h" 31 #include "media/base/bind_to_current_loop.h"
32 #include "media/base/cdm_context.h" 32 #include "media/base/cdm_context.h"
33 #include "media/base/limits.h" 33 #include "media/base/limits.h"
34 #include "media/base/media_content_type.h" 34 #include "media/base/media_content_type.h"
35 #include "media/base/media_log.h" 35 #include "media/base/media_log.h"
36 #include "media/base/media_switches.h" 36 #include "media/base/media_switches.h"
37 #include "media/base/stream_position.h"
37 #include "media/base/text_renderer.h" 38 #include "media/base/text_renderer.h"
38 #include "media/base/timestamp_constants.h" 39 #include "media/base/timestamp_constants.h"
39 #include "media/base/video_frame.h" 40 #include "media/base/video_frame.h"
40 #include "media/blink/texttrack_impl.h" 41 #include "media/blink/texttrack_impl.h"
41 #include "media/blink/watch_time_reporter.h" 42 #include "media/blink/watch_time_reporter.h"
42 #include "media/blink/webaudiosourceprovider_impl.h" 43 #include "media/blink/webaudiosourceprovider_impl.h"
43 #include "media/blink/webcontentdecryptionmodule_impl.h" 44 #include "media/blink/webcontentdecryptionmodule_impl.h"
44 #include "media/blink/webinbandtexttrack_impl.h" 45 #include "media/blink/webinbandtexttrack_impl.h"
45 #include "media/blink/webmediaplayer_delegate.h" 46 #include "media/blink/webmediaplayer_delegate.h"
46 #include "media/blink/webmediaplayer_util.h" 47 #include "media/blink/webmediaplayer_util.h"
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 } 439 }
439 440
440 bool WebMediaPlayerImpl::supportsSave() const { 441 bool WebMediaPlayerImpl::supportsSave() const {
441 DCHECK(main_task_runner_->BelongsToCurrentThread()); 442 DCHECK(main_task_runner_->BelongsToCurrentThread());
442 return supports_save_; 443 return supports_save_;
443 } 444 }
444 445
445 void WebMediaPlayerImpl::seek(double seconds) { 446 void WebMediaPlayerImpl::seek(double seconds) {
446 DVLOG(1) << __func__ << "(" << seconds << "s)"; 447 DVLOG(1) << __func__ << "(" << seconds << "s)";
447 DCHECK(main_task_runner_->BelongsToCurrentThread()); 448 DCHECK(main_task_runner_->BelongsToCurrentThread());
448 DoSeek(base::TimeDelta::FromSecondsD(seconds), true); 449 DoSeek(StreamPosition::KeyFramePrecedingTime(
450 base::TimeDelta::FromSecondsD(seconds)),
451 true);
449 } 452 }
450 453
451 void WebMediaPlayerImpl::DoSeek(base::TimeDelta time, bool time_updated) { 454 void WebMediaPlayerImpl::fastSeek(double seconds) {
455 DVLOG(1) << __func__ << "(" << seconds << "s)";
456 DCHECK(main_task_runner_->BelongsToCurrentThread());
457 DoSeek(StreamPosition::Precise(base::TimeDelta::FromSecondsD(seconds)), true);
458 }
459
460 void WebMediaPlayerImpl::DoSeek(StreamPosition position, bool time_updated) {
452 DCHECK(main_task_runner_->BelongsToCurrentThread()); 461 DCHECK(main_task_runner_->BelongsToCurrentThread());
453 462
454 #if defined(OS_ANDROID) // WMPI_CAST 463 #if defined(OS_ANDROID) // WMPI_CAST
455 if (isRemote()) { 464 if (isRemote()) {
456 cast_impl_.seek(time); 465 // XXX: Revisit.
466 cast_impl_.seek(position.time);
457 return; 467 return;
458 } 468 }
459 #endif 469 #endif
460 470
461 ReadyState old_state = ready_state_; 471 ReadyState old_state = ready_state_;
462 if (ready_state_ > WebMediaPlayer::ReadyStateHaveMetadata) 472 if (ready_state_ > WebMediaPlayer::ReadyStateHaveMetadata)
463 SetReadyState(WebMediaPlayer::ReadyStateHaveMetadata); 473 SetReadyState(WebMediaPlayer::ReadyStateHaveMetadata);
464 474
465 // When paused, we know exactly what the current time is and can elide seeks 475 // When paused, we know exactly what the current time is and can elide seeks
466 // to it. However, there are two cases that are not elided: 476 // to it. However, there are two cases that are not elided:
467 // 1) When the pipeline state is not stable. 477 // 1) When the pipeline state is not stable.
468 // In this case we just let |pipeline_controller_| decide what to do, as 478 // In this case we just let |pipeline_controller_| decide what to do, as
469 // it has complete information. 479 // it has complete information.
470 // 2) For MSE. 480 // 2) For MSE.
471 // Because the buffers may have changed between seeks, MSE seeks are 481 // Because the buffers may have changed between seeks, MSE seeks are
472 // never elided. 482 // never elided.
473 if (paused_ && pipeline_controller_.IsStable() && paused_time_ == time && 483 if (paused_ && pipeline_controller_.IsStable() &&
474 !chunk_demuxer_) { 484 paused_time_ == position.time && !chunk_demuxer_) {
475 // If the ready state was high enough before, we can indicate that the seek 485 // If the ready state was high enough before, we can indicate that the seek
476 // completed just by restoring it. Otherwise we will just wait for the real 486 // completed just by restoring it. Otherwise we will just wait for the real
477 // ready state change to eventually happen. 487 // ready state change to eventually happen.
478 if (old_state == ReadyStateHaveEnoughData) { 488 if (old_state == ReadyStateHaveEnoughData) {
479 main_task_runner_->PostTask( 489 main_task_runner_->PostTask(
480 FROM_HERE, base::Bind(&WebMediaPlayerImpl::OnBufferingStateChange, 490 FROM_HERE, base::Bind(&WebMediaPlayerImpl::OnBufferingStateChange,
481 AsWeakPtr(), BUFFERING_HAVE_ENOUGH)); 491 AsWeakPtr(), BUFFERING_HAVE_ENOUGH));
482 } 492 }
483 return; 493 return;
484 } 494 }
485 495
486 // Call this before setting |seeking_| so that the current media time can be 496 // Call this before setting |seeking_| so that the current media time can be
487 // recorded by the reporter. 497 // recorded by the reporter.
488 if (watch_time_reporter_) 498 if (watch_time_reporter_)
489 watch_time_reporter_->OnSeeking(); 499 watch_time_reporter_->OnSeeking();
490 500
491 // TODO(sandersd): Ideally we would not clear the idle state if 501 // TODO(sandersd): Ideally we would not clear the idle state if
492 // |pipeline_controller_| can elide the seek. 502 // |pipeline_controller_| can elide the seek.
493 is_idle_ = false; 503 is_idle_ = false;
494 ended_ = false; 504 ended_ = false;
495 505
496 seeking_ = true; 506 seeking_ = true;
497 seek_time_ = time; 507 // XXX: Revisit. The page can observe time going backwards, but Android has
508 // always had this problem.
509 seek_time_ = position.time;
498 if (paused_) 510 if (paused_)
499 paused_time_ = time; 511 paused_time_ = position.time;
500 pipeline_controller_.Seek(time, time_updated); 512 pipeline_controller_.Seek(position, time_updated);
501 513
502 // This needs to be called after Seek() so that if a resume is triggered, it 514 // This needs to be called after Seek() so that if a resume is triggered, it
503 // is to the correct time. 515 // is to the correct time.
504 UpdatePlayState(); 516 UpdatePlayState();
505 } 517 }
506 518
507 void WebMediaPlayerImpl::setRate(double rate) { 519 void WebMediaPlayerImpl::setRate(double rate) {
508 DVLOG(1) << __func__ << "(" << rate << ")"; 520 DVLOG(1) << __func__ << "(" << rate << ")";
509 DCHECK(main_task_runner_->BelongsToCurrentThread()); 521 DCHECK(main_task_runner_->BelongsToCurrentThread());
510 522
(...skipping 801 matching lines...) Expand 10 before | Expand all | Expand 10 after
1312 1324
1313 void WebMediaPlayerImpl::OnRemotePlaybackEnded() { 1325 void WebMediaPlayerImpl::OnRemotePlaybackEnded() {
1314 DVLOG(1) << __func__; 1326 DVLOG(1) << __func__;
1315 DCHECK(main_task_runner_->BelongsToCurrentThread()); 1327 DCHECK(main_task_runner_->BelongsToCurrentThread());
1316 1328
1317 ended_ = true; 1329 ended_ = true;
1318 client_->timeChanged(); 1330 client_->timeChanged();
1319 } 1331 }
1320 1332
1321 void WebMediaPlayerImpl::OnDisconnectedFromRemoteDevice(double t) { 1333 void WebMediaPlayerImpl::OnDisconnectedFromRemoteDevice(double t) {
1322 DoSeek(base::TimeDelta::FromSecondsD(t), false); 1334 DoSeek(StreamPosition::Precise(base::TimeDelta::FromSecondsD(t)), false);
1323 1335
1324 // We already told the delegate we're paused when remoting started. 1336 // We already told the delegate we're paused when remoting started.
1325 client_->playbackStateChanged(); 1337 client_->playbackStateChanged();
1326 client_->disconnectedFromRemoteDevice(); 1338 client_->disconnectedFromRemoteDevice();
1327 1339
1328 UpdatePlayState(); 1340 UpdatePlayState();
1329 } 1341 }
1330 1342
1331 void WebMediaPlayerImpl::SuspendForRemote() { 1343 void WebMediaPlayerImpl::SuspendForRemote() {
1332 if (pipeline_controller_.IsPipelineSuspended()) { 1344 if (pipeline_controller_.IsPipelineSuspended()) {
(...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after
1815 pipeline_metadata_.natural_size, 1827 pipeline_metadata_.natural_size,
1816 base::Bind(&GetCurrentTimeInternal, this))); 1828 base::Bind(&GetCurrentTimeInternal, this)));
1817 watch_time_reporter_->OnVolumeChange(volume_); 1829 watch_time_reporter_->OnVolumeChange(volume_);
1818 if (delegate_ && delegate_->IsHidden()) 1830 if (delegate_ && delegate_->IsHidden())
1819 watch_time_reporter_->OnHidden(); 1831 watch_time_reporter_->OnHidden();
1820 else 1832 else
1821 watch_time_reporter_->OnShown(); 1833 watch_time_reporter_->OnShown();
1822 } 1834 }
1823 1835
1824 } // namespace media 1836 } // namespace media
OLDNEW
« no previous file with comments | « media/blink/webmediaplayer_impl.h ('k') | media/filters/pipeline_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698