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

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

Issue 1815893002: Merge M50: "Disable "pause-and-buffer" on Android, cancel suspended players." (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2661
Patch Set: 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 542 matching lines...) Expand 10 before | Expand all | Expand 10 after
553 STATIC_ASSERT_ENUM(WebMediaPlayer::BufferingStrategy::Normal, 553 STATIC_ASSERT_ENUM(WebMediaPlayer::BufferingStrategy::Normal,
554 BufferedDataSource::BUFFERING_STRATEGY_NORMAL); 554 BufferedDataSource::BUFFERING_STRATEGY_NORMAL);
555 STATIC_ASSERT_ENUM(WebMediaPlayer::BufferingStrategy::Aggressive, 555 STATIC_ASSERT_ENUM(WebMediaPlayer::BufferingStrategy::Aggressive,
556 BufferedDataSource::BUFFERING_STRATEGY_AGGRESSIVE); 556 BufferedDataSource::BUFFERING_STRATEGY_AGGRESSIVE);
557 557
558 void WebMediaPlayerImpl::setBufferingStrategy( 558 void WebMediaPlayerImpl::setBufferingStrategy(
559 WebMediaPlayer::BufferingStrategy buffering_strategy) { 559 WebMediaPlayer::BufferingStrategy buffering_strategy) {
560 DVLOG(1) << __FUNCTION__; 560 DVLOG(1) << __FUNCTION__;
561 DCHECK(main_task_runner_->BelongsToCurrentThread()); 561 DCHECK(main_task_runner_->BelongsToCurrentThread());
562 562
563 #if defined(OS_ANDROID)
564 // We disallow aggressive buffering on Android since it matches the behavior
565 // of the platform media player and may have data usage penalties.
566 // TODO(dalecurtis, hubbe): We should probably stop using "pause-and-buffer"
567 // everywhere. See http://crbug.com/594669 for more details.
568 buffering_strategy_ = BufferedDataSource::BUFFERING_STRATEGY_NORMAL;
569 #else
563 buffering_strategy_ = 570 buffering_strategy_ =
564 static_cast<BufferedDataSource::BufferingStrategy>(buffering_strategy); 571 static_cast<BufferedDataSource::BufferingStrategy>(buffering_strategy);
572 #endif
573
565 if (data_source_) 574 if (data_source_)
566 data_source_->SetBufferingStrategy(buffering_strategy_); 575 data_source_->SetBufferingStrategy(buffering_strategy_);
567 } 576 }
568 577
569 bool WebMediaPlayerImpl::hasVideo() const { 578 bool WebMediaPlayerImpl::hasVideo() const {
570 DCHECK(main_task_runner_->BelongsToCurrentThread()); 579 DCHECK(main_task_runner_->BelongsToCurrentThread());
571 580
572 return pipeline_metadata_.has_video; 581 return pipeline_metadata_.has_video;
573 } 582 }
574 583
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after
953 scoped_refptr<VideoFrame> frame = cast_impl_.GetCastingBanner(); 962 scoped_refptr<VideoFrame> frame = cast_impl_.GetCastingBanner();
954 if (frame) { 963 if (frame) {
955 compositor_->PaintFrameUsingOldRenderingPath(frame); 964 compositor_->PaintFrameUsingOldRenderingPath(frame);
956 } 965 }
957 } 966 }
958 #endif 967 #endif
959 968
960 memory_usage_reporting_timer_.Stop(); 969 memory_usage_reporting_timer_.Stop();
961 ReportMemoryUsage(); 970 ReportMemoryUsage();
962 971
972 // If we're not in an aggressive buffering state, tell the data source we have
973 // enough data so that it may release the connection.
974 if (buffering_strategy_ !=
975 BufferedDataSource::BUFFERING_STRATEGY_AGGRESSIVE) {
976 if (data_source_)
977 data_source_->OnBufferingHaveEnough(true);
978 }
979
963 if (pending_resume_ || pending_suspend_resume_cycle_) { 980 if (pending_resume_ || pending_suspend_resume_cycle_) {
964 pending_resume_ = false; 981 pending_resume_ = false;
965 pending_suspend_resume_cycle_ = false; 982 pending_suspend_resume_cycle_ = false;
966 Resume(); 983 Resume();
967 return; 984 return;
968 } 985 }
969 } 986 }
970 987
971 void WebMediaPlayerImpl::OnPipelineEnded() { 988 void WebMediaPlayerImpl::OnPipelineEnded() {
972 DVLOG(1) << __FUNCTION__; 989 DVLOG(1) << __FUNCTION__;
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
1043 return; 1060 return;
1044 1061
1045 // TODO(scherkus): Handle other buffering states when Pipeline starts using 1062 // TODO(scherkus): Handle other buffering states when Pipeline starts using
1046 // them and translate them ready state changes http://crbug.com/144683 1063 // them and translate them ready state changes http://crbug.com/144683
1047 DCHECK_EQ(buffering_state, BUFFERING_HAVE_ENOUGH); 1064 DCHECK_EQ(buffering_state, BUFFERING_HAVE_ENOUGH);
1048 SetReadyState(WebMediaPlayer::ReadyStateHaveEnoughData); 1065 SetReadyState(WebMediaPlayer::ReadyStateHaveEnoughData);
1049 1066
1050 // Let the DataSource know we have enough data. It may use this information to 1067 // Let the DataSource know we have enough data. It may use this information to
1051 // release unused network connections. 1068 // release unused network connections.
1052 if (data_source_) 1069 if (data_source_)
1053 data_source_->OnBufferingHaveEnough(); 1070 data_source_->OnBufferingHaveEnough(false);
1054 1071
1055 // Blink expects a timeChanged() in response to a seek(). 1072 // Blink expects a timeChanged() in response to a seek().
1056 if (should_notify_time_changed_) 1073 if (should_notify_time_changed_)
1057 client_->timeChanged(); 1074 client_->timeChanged();
1058 1075
1059 // Once we have enough, start reporting the total memory usage. We'll also 1076 // Once we have enough, start reporting the total memory usage. We'll also
1060 // report once playback starts. 1077 // report once playback starts.
1061 ReportMemoryUsage(); 1078 ReportMemoryUsage();
1062 } 1079 }
1063 1080
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1113 #endif 1130 #endif
1114 1131
1115 if (must_suspend || (paused_ && ended_) || hasVideo()) 1132 if (must_suspend || (paused_ && ended_) || hasVideo())
1116 ScheduleSuspend(); 1133 ScheduleSuspend();
1117 } 1134 }
1118 1135
1119 void WebMediaPlayerImpl::ScheduleSuspend() { 1136 void WebMediaPlayerImpl::ScheduleSuspend() {
1120 if (!pipeline_.IsRunning()) 1137 if (!pipeline_.IsRunning())
1121 return; 1138 return;
1122 1139
1140 // Always reset the buffering strategy to normal when suspending for hidden to
1141 // prevent an idle network connection from lingering.
1142 setBufferingStrategy(WebMediaPlayer::BufferingStrategy::Normal);
1123 if (resuming_ || seeking_) { 1143 if (resuming_ || seeking_) {
1124 pending_suspend_ = true; 1144 pending_suspend_ = true;
1125 return; 1145 return;
1126 } 1146 }
1127 1147
1128 if (pending_resume_) { 1148 if (pending_resume_) {
1129 pending_resume_ = false; 1149 pending_resume_ = false;
1130 return; 1150 return;
1131 } 1151 }
1132 1152
(...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after
1612 << ", Video: " << stats.video_memory_usage << ", DataSource: " 1632 << ", Video: " << stats.video_memory_usage << ", DataSource: "
1613 << (data_source_ ? data_source_->GetMemoryUsage() : 0) 1633 << (data_source_ ? data_source_->GetMemoryUsage() : 0)
1614 << ", Demuxer: " << demuxer_memory_usage; 1634 << ", Demuxer: " << demuxer_memory_usage;
1615 1635
1616 const int64_t delta = current_memory_usage - last_reported_memory_usage_; 1636 const int64_t delta = current_memory_usage - last_reported_memory_usage_;
1617 last_reported_memory_usage_ = current_memory_usage; 1637 last_reported_memory_usage_ = current_memory_usage;
1618 adjust_allocated_memory_cb_.Run(delta); 1638 adjust_allocated_memory_cb_.Run(delta);
1619 } 1639 }
1620 1640
1621 } // namespace media 1641 } // 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