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

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

Issue 2611333003: [Video] Disable bg optimization if avg keyframe distance is >10s (Closed)
Patch Set: Rebase the test Created 3 years, 11 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/blink/webmediaplayer_impl_unittest.cc » ('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 869 matching lines...) Expand 10 before | Expand all | Expand 10 after
880 return false; 880 return false;
881 } 881 }
882 882
883 double WebMediaPlayerImpl::mediaTimeForTimeValue(double timeValue) const { 883 double WebMediaPlayerImpl::mediaTimeForTimeValue(double timeValue) const {
884 return base::TimeDelta::FromSecondsD(timeValue).InSecondsF(); 884 return base::TimeDelta::FromSecondsD(timeValue).InSecondsF();
885 } 885 }
886 886
887 unsigned WebMediaPlayerImpl::decodedFrameCount() const { 887 unsigned WebMediaPlayerImpl::decodedFrameCount() const {
888 DCHECK(main_task_runner_->BelongsToCurrentThread()); 888 DCHECK(main_task_runner_->BelongsToCurrentThread());
889 889
890 PipelineStatistics stats = pipeline_.GetStatistics(); 890 PipelineStatistics stats = GetPipelineStatistics();
891 return stats.video_frames_decoded; 891 return stats.video_frames_decoded;
892 } 892 }
893 893
894 unsigned WebMediaPlayerImpl::droppedFrameCount() const { 894 unsigned WebMediaPlayerImpl::droppedFrameCount() const {
895 DCHECK(main_task_runner_->BelongsToCurrentThread()); 895 DCHECK(main_task_runner_->BelongsToCurrentThread());
896 896
897 PipelineStatistics stats = pipeline_.GetStatistics(); 897 PipelineStatistics stats = GetPipelineStatistics();
898 return stats.video_frames_dropped; 898 return stats.video_frames_dropped;
899 } 899 }
900 900
901 size_t WebMediaPlayerImpl::audioDecodedByteCount() const { 901 size_t WebMediaPlayerImpl::audioDecodedByteCount() const {
902 DCHECK(main_task_runner_->BelongsToCurrentThread()); 902 DCHECK(main_task_runner_->BelongsToCurrentThread());
903 903
904 PipelineStatistics stats = pipeline_.GetStatistics(); 904 PipelineStatistics stats = GetPipelineStatistics();
905 return stats.audio_bytes_decoded; 905 return stats.audio_bytes_decoded;
906 } 906 }
907 907
908 size_t WebMediaPlayerImpl::videoDecodedByteCount() const { 908 size_t WebMediaPlayerImpl::videoDecodedByteCount() const {
909 DCHECK(main_task_runner_->BelongsToCurrentThread()); 909 DCHECK(main_task_runner_->BelongsToCurrentThread());
910 910
911 PipelineStatistics stats = pipeline_.GetStatistics(); 911 PipelineStatistics stats = GetPipelineStatistics();
912 return stats.video_bytes_decoded; 912 return stats.video_bytes_decoded;
913 } 913 }
914 914
915 bool WebMediaPlayerImpl::copyVideoTextureToPlatformTexture( 915 bool WebMediaPlayerImpl::copyVideoTextureToPlatformTexture(
916 gpu::gles2::GLES2Interface* gl, 916 gpu::gles2::GLES2Interface* gl,
917 unsigned int texture, 917 unsigned int texture,
918 bool premultiply_alpha, 918 bool premultiply_alpha,
919 bool flip_y) { 919 bool flip_y) {
920 DCHECK(main_task_runner_->BelongsToCurrentThread()); 920 DCHECK(main_task_runner_->BelongsToCurrentThread());
921 TRACE_EVENT0("media", "WebMediaPlayerImpl:copyVideoTextureToPlatformTexture"); 921 TRACE_EVENT0("media", "WebMediaPlayerImpl:copyVideoTextureToPlatformTexture");
(...skipping 1076 matching lines...) Expand 10 before | Expand all | Expand 10 after
1998 base::Bind(&Demuxer::GetMemoryUsage, base::Unretained(demuxer_.get())), 1998 base::Bind(&Demuxer::GetMemoryUsage, base::Unretained(demuxer_.get())),
1999 base::Bind(&WebMediaPlayerImpl::FinishMemoryUsageReport, AsWeakPtr())); 1999 base::Bind(&WebMediaPlayerImpl::FinishMemoryUsageReport, AsWeakPtr()));
2000 } else { 2000 } else {
2001 FinishMemoryUsageReport(0); 2001 FinishMemoryUsageReport(0);
2002 } 2002 }
2003 } 2003 }
2004 2004
2005 void WebMediaPlayerImpl::FinishMemoryUsageReport(int64_t demuxer_memory_usage) { 2005 void WebMediaPlayerImpl::FinishMemoryUsageReport(int64_t demuxer_memory_usage) {
2006 DCHECK(main_task_runner_->BelongsToCurrentThread()); 2006 DCHECK(main_task_runner_->BelongsToCurrentThread());
2007 2007
2008 const PipelineStatistics stats = pipeline_.GetStatistics(); 2008 const PipelineStatistics stats = GetPipelineStatistics();
2009 const int64_t data_source_memory_usage = 2009 const int64_t data_source_memory_usage =
2010 data_source_ ? data_source_->GetMemoryUsage() : 0; 2010 data_source_ ? data_source_->GetMemoryUsage() : 0;
2011 const int64_t current_memory_usage = 2011 const int64_t current_memory_usage =
2012 stats.audio_memory_usage + stats.video_memory_usage + 2012 stats.audio_memory_usage + stats.video_memory_usage +
2013 data_source_memory_usage + demuxer_memory_usage; 2013 data_source_memory_usage + demuxer_memory_usage;
2014 2014
2015 // Note, this isn't entirely accurate, there may be VideoFrames held by the 2015 // Note, this isn't entirely accurate, there may be VideoFrames held by the
2016 // compositor or other resources that we're unaware of. 2016 // compositor or other resources that we're unaware of.
2017 2017
2018 DVLOG(2) << "Memory Usage -- Audio: " << stats.audio_memory_usage 2018 DVLOG(2) << "Memory Usage -- Audio: " << stats.audio_memory_usage
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
2100 return false; 2100 return false;
2101 #else // defined(OS_ANDROID) 2101 #else // defined(OS_ANDROID)
2102 if (!IsBackgroundVideoTrackOptimizationEnabled()) 2102 if (!IsBackgroundVideoTrackOptimizationEnabled())
2103 return false; 2103 return false;
2104 #endif // defined(OS_ANDROID) 2104 #endif // defined(OS_ANDROID)
2105 2105
2106 return hasVideo() && !hasAudio(); 2106 return hasVideo() && !hasAudio();
2107 } 2107 }
2108 2108
2109 bool WebMediaPlayerImpl::ShouldDisableVideoWhenHidden() const { 2109 bool WebMediaPlayerImpl::ShouldDisableVideoWhenHidden() const {
2110 DCHECK(main_task_runner_->BelongsToCurrentThread());
2110 DCHECK(IsHidden()); 2111 DCHECK(IsHidden());
2111 return IsBackgroundVideoTrackOptimizationEnabled() && hasVideo() && 2112
2112 hasAudio() && !IsStreaming(); 2113 if (!IsBackgroundVideoTrackOptimizationEnabled() || !hasVideo() ||
2114 !hasAudio() || IsStreaming()) {
2115 return false;
2116 }
2117
2118 PipelineStatistics stats = GetPipelineStatistics();
2119 return stats.video_keyframe_distance_average <
2120 max_keyframe_distance_to_disable_background_video_;
2113 } 2121 }
2114 2122
2115 void WebMediaPlayerImpl::EnableVideoTrackIfNeeded() { 2123 void WebMediaPlayerImpl::EnableVideoTrackIfNeeded() {
2116 DCHECK(!IsHidden()); 2124 DCHECK(!IsHidden());
2117 2125
2118 // Don't change video track while the pipeline is resuming or seeking. 2126 // Don't change video track while the pipeline is resuming or seeking.
2119 if (is_pipeline_resuming_ || seeking_) 2127 if (is_pipeline_resuming_ || seeking_)
2120 return; 2128 return;
2121 2129
2122 if (video_track_disabled_) { 2130 if (video_track_disabled_) {
(...skipping 11 matching lines...) Expand all
2134 // Don't change video track while the pipeline is resuming or seeking. 2142 // Don't change video track while the pipeline is resuming or seeking.
2135 if (is_pipeline_resuming_ || seeking_) 2143 if (is_pipeline_resuming_ || seeking_)
2136 return; 2144 return;
2137 2145
2138 if (!video_track_disabled_ && ShouldDisableVideoWhenHidden()) { 2146 if (!video_track_disabled_ && ShouldDisableVideoWhenHidden()) {
2139 video_track_disabled_ = true; 2147 video_track_disabled_ = true;
2140 selectedVideoTrackChanged(nullptr); 2148 selectedVideoTrackChanged(nullptr);
2141 } 2149 }
2142 } 2150 }
2143 2151
2152 void WebMediaPlayerImpl::SetPipelineStatisticsForTest(
2153 const PipelineStatistics& stats) {
2154 pipeline_statistics_for_test_ = base::make_optional(stats);
2155 }
2156
2157 PipelineStatistics WebMediaPlayerImpl::GetPipelineStatistics() const {
2158 DCHECK(main_task_runner_->BelongsToCurrentThread());
2159
2160 return pipeline_statistics_for_test_.value_or(pipeline_.GetStatistics());
2161 }
2162
2144 } // namespace media 2163 } // namespace media
OLDNEW
« no previous file with comments | « media/blink/webmediaplayer_impl.h ('k') | media/blink/webmediaplayer_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698