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

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

Issue 1798213002: Disable "pause-and-buffer" on Android, cancel suspended players. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix test bug. 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
« no previous file with comments | « media/blink/multibuffer_data_source_unittest.cc ('k') | no next file » | 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 519 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 STATIC_ASSERT_ENUM(WebMediaPlayer::BufferingStrategy::Normal, 530 STATIC_ASSERT_ENUM(WebMediaPlayer::BufferingStrategy::Normal,
531 BufferedDataSource::BUFFERING_STRATEGY_NORMAL); 531 BufferedDataSource::BUFFERING_STRATEGY_NORMAL);
532 STATIC_ASSERT_ENUM(WebMediaPlayer::BufferingStrategy::Aggressive, 532 STATIC_ASSERT_ENUM(WebMediaPlayer::BufferingStrategy::Aggressive,
533 BufferedDataSource::BUFFERING_STRATEGY_AGGRESSIVE); 533 BufferedDataSource::BUFFERING_STRATEGY_AGGRESSIVE);
534 534
535 void WebMediaPlayerImpl::setBufferingStrategy( 535 void WebMediaPlayerImpl::setBufferingStrategy(
536 WebMediaPlayer::BufferingStrategy buffering_strategy) { 536 WebMediaPlayer::BufferingStrategy buffering_strategy) {
537 DVLOG(1) << __FUNCTION__; 537 DVLOG(1) << __FUNCTION__;
538 DCHECK(main_task_runner_->BelongsToCurrentThread()); 538 DCHECK(main_task_runner_->BelongsToCurrentThread());
539 539
540 #if defined(OS_ANDROID)
541 // We disallow aggressive buffering on Android since it matches the behavior
542 // of the platform media player and may have data usage penalties.
543 // TODO(dalecurtis, hubbe): We should probably stop using "pause-and-buffer"
544 // everywhere. See http://crbug.com/594669 for more details.
545 buffering_strategy_ = BufferedDataSource::BUFFERING_STRATEGY_NORMAL;
546 #else
540 buffering_strategy_ = 547 buffering_strategy_ =
541 static_cast<BufferedDataSource::BufferingStrategy>(buffering_strategy); 548 static_cast<BufferedDataSource::BufferingStrategy>(buffering_strategy);
549 #endif
550
542 if (data_source_) 551 if (data_source_)
543 data_source_->SetBufferingStrategy(buffering_strategy_); 552 data_source_->SetBufferingStrategy(buffering_strategy_);
544 } 553 }
545 554
546 bool WebMediaPlayerImpl::hasVideo() const { 555 bool WebMediaPlayerImpl::hasVideo() const {
547 DCHECK(main_task_runner_->BelongsToCurrentThread()); 556 DCHECK(main_task_runner_->BelongsToCurrentThread());
548 557
549 return pipeline_metadata_.has_video; 558 return pipeline_metadata_.has_video;
550 } 559 }
551 560
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
866 scoped_refptr<VideoFrame> frame = cast_impl_.GetCastingBanner(); 875 scoped_refptr<VideoFrame> frame = cast_impl_.GetCastingBanner();
867 if (frame) { 876 if (frame) {
868 compositor_->PaintFrameUsingOldRenderingPath(frame); 877 compositor_->PaintFrameUsingOldRenderingPath(frame);
869 } 878 }
870 } 879 }
871 #endif 880 #endif
872 881
873 memory_usage_reporting_timer_.Stop(); 882 memory_usage_reporting_timer_.Stop();
874 ReportMemoryUsage(); 883 ReportMemoryUsage();
875 884
885 // If we're not in an aggressive buffering state, tell the data source we have
886 // enough data so that it may release the connection.
887 if (buffering_strategy_ !=
888 BufferedDataSource::BUFFERING_STRATEGY_AGGRESSIVE) {
889 data_source_->OnBufferingHaveEnough(true);
890 }
891
876 if (pending_suspend_resume_cycle_) { 892 if (pending_suspend_resume_cycle_) {
877 pending_suspend_resume_cycle_ = false; 893 pending_suspend_resume_cycle_ = false;
878 pipeline_controller_.Resume(); 894 pipeline_controller_.Resume();
879 return; 895 return;
880 } 896 }
881 } 897 }
882 898
883 void WebMediaPlayerImpl::OnPipelineResumed() { 899 void WebMediaPlayerImpl::OnPipelineResumed() {
884 if (playback_rate_ > 0 && !paused_) { 900 if (playback_rate_ > 0 && !paused_) {
885 NotifyPlaybackStarted(); 901 NotifyPlaybackStarted();
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
965 return; 981 return;
966 982
967 // TODO(scherkus): Handle other buffering states when Pipeline starts using 983 // TODO(scherkus): Handle other buffering states when Pipeline starts using
968 // them and translate them ready state changes http://crbug.com/144683 984 // them and translate them ready state changes http://crbug.com/144683
969 DCHECK_EQ(buffering_state, BUFFERING_HAVE_ENOUGH); 985 DCHECK_EQ(buffering_state, BUFFERING_HAVE_ENOUGH);
970 SetReadyState(WebMediaPlayer::ReadyStateHaveEnoughData); 986 SetReadyState(WebMediaPlayer::ReadyStateHaveEnoughData);
971 987
972 // Let the DataSource know we have enough data. It may use this information to 988 // Let the DataSource know we have enough data. It may use this information to
973 // release unused network connections. 989 // release unused network connections.
974 if (data_source_) 990 if (data_source_)
975 data_source_->OnBufferingHaveEnough(); 991 data_source_->OnBufferingHaveEnough(false);
976 992
977 // Blink expects a timeChanged() in response to a seek(). 993 // Blink expects a timeChanged() in response to a seek().
978 if (should_notify_time_changed_) 994 if (should_notify_time_changed_)
979 client_->timeChanged(); 995 client_->timeChanged();
980 996
981 // Once we have enough, start reporting the total memory usage. We'll also 997 // Once we have enough, start reporting the total memory usage. We'll also
982 // report once playback starts. 998 // report once playback starts.
983 ReportMemoryUsage(); 999 ReportMemoryUsage();
984 } 1000 }
985 1001
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1023 return; 1039 return;
1024 #endif 1040 #endif
1025 1041
1026 // Don't suspend players which only have audio and have not completed 1042 // Don't suspend players which only have audio and have not completed
1027 // playback. The user can still control these players via the MediaSession UI. 1043 // playback. The user can still control these players via the MediaSession UI.
1028 // If the player has never started playback, OnSuspendRequested() will handle 1044 // If the player has never started playback, OnSuspendRequested() will handle
1029 // release of any idle resources. 1045 // release of any idle resources.
1030 if (!hasVideo() && !paused_ && !ended_) 1046 if (!hasVideo() && !paused_ && !ended_)
1031 return; 1047 return;
1032 1048
1049 // Always reset the buffering strategy to normal when suspending for hidden to
1050 // prevent an idle network connection from lingering.
1051 setBufferingStrategy(WebMediaPlayer::BufferingStrategy::Normal);
1033 pipeline_controller_.Suspend(); 1052 pipeline_controller_.Suspend();
1034 if (delegate_) 1053 if (delegate_)
1035 delegate_->PlayerGone(delegate_id_); 1054 delegate_->PlayerGone(delegate_id_);
1036 } 1055 }
1037 1056
1038 void WebMediaPlayerImpl::OnShown() { 1057 void WebMediaPlayerImpl::OnShown() {
1039 DCHECK(main_task_runner_->BelongsToCurrentThread()); 1058 DCHECK(main_task_runner_->BelongsToCurrentThread());
1040 if (!IsSuspendUponHiddenEnabled()) 1059 if (!IsSuspendUponHiddenEnabled())
1041 return; 1060 return;
1042 1061
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after
1459 bool WebMediaPlayerImpl::IsAutomaticResumeAllowed() { 1478 bool WebMediaPlayerImpl::IsAutomaticResumeAllowed() {
1460 #if defined(OS_ANDROID) 1479 #if defined(OS_ANDROID)
1461 return !hasVideo() || (delegate_ && !delegate_->IsHidden()); 1480 return !hasVideo() || (delegate_ && !delegate_->IsHidden());
1462 #else 1481 #else
1463 // On non-Android platforms Resume() is always allowed. 1482 // On non-Android platforms Resume() is always allowed.
1464 return true; 1483 return true;
1465 #endif 1484 #endif
1466 } 1485 }
1467 1486
1468 } // namespace media 1487 } // namespace media
OLDNEW
« no previous file with comments | « media/blink/multibuffer_data_source_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698