OLD | NEW |
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 858 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
869 return false; | 869 return false; |
870 } | 870 } |
871 | 871 |
872 double WebMediaPlayerImpl::mediaTimeForTimeValue(double timeValue) const { | 872 double WebMediaPlayerImpl::mediaTimeForTimeValue(double timeValue) const { |
873 return base::TimeDelta::FromSecondsD(timeValue).InSecondsF(); | 873 return base::TimeDelta::FromSecondsD(timeValue).InSecondsF(); |
874 } | 874 } |
875 | 875 |
876 unsigned WebMediaPlayerImpl::decodedFrameCount() const { | 876 unsigned WebMediaPlayerImpl::decodedFrameCount() const { |
877 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 877 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
878 | 878 |
879 PipelineStatistics stats = pipeline_.GetStatistics(); | 879 PipelineStatistics stats = GetPipelineStatistics(); |
880 return stats.video_frames_decoded; | 880 return stats.video_frames_decoded; |
881 } | 881 } |
882 | 882 |
883 unsigned WebMediaPlayerImpl::droppedFrameCount() const { | 883 unsigned WebMediaPlayerImpl::droppedFrameCount() const { |
884 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 884 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
885 | 885 |
886 PipelineStatistics stats = pipeline_.GetStatistics(); | 886 PipelineStatistics stats = GetPipelineStatistics(); |
887 return stats.video_frames_dropped; | 887 return stats.video_frames_dropped; |
888 } | 888 } |
889 | 889 |
890 size_t WebMediaPlayerImpl::audioDecodedByteCount() const { | 890 size_t WebMediaPlayerImpl::audioDecodedByteCount() const { |
891 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 891 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
892 | 892 |
893 PipelineStatistics stats = pipeline_.GetStatistics(); | 893 PipelineStatistics stats = GetPipelineStatistics(); |
894 return stats.audio_bytes_decoded; | 894 return stats.audio_bytes_decoded; |
895 } | 895 } |
896 | 896 |
897 size_t WebMediaPlayerImpl::videoDecodedByteCount() const { | 897 size_t WebMediaPlayerImpl::videoDecodedByteCount() const { |
898 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 898 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
899 | 899 |
900 PipelineStatistics stats = pipeline_.GetStatistics(); | 900 PipelineStatistics stats = GetPipelineStatistics(); |
901 return stats.video_bytes_decoded; | 901 return stats.video_bytes_decoded; |
902 } | 902 } |
903 | 903 |
904 bool WebMediaPlayerImpl::copyVideoTextureToPlatformTexture( | 904 bool WebMediaPlayerImpl::copyVideoTextureToPlatformTexture( |
905 gpu::gles2::GLES2Interface* gl, | 905 gpu::gles2::GLES2Interface* gl, |
906 unsigned int texture, | 906 unsigned int texture, |
907 unsigned int internal_format, | 907 unsigned int internal_format, |
908 unsigned int type, | 908 unsigned int type, |
909 bool premultiply_alpha, | 909 bool premultiply_alpha, |
910 bool flip_y) { | 910 bool flip_y) { |
(...skipping 1098 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2009 base::Bind(&Demuxer::GetMemoryUsage, base::Unretained(demuxer_.get())), | 2009 base::Bind(&Demuxer::GetMemoryUsage, base::Unretained(demuxer_.get())), |
2010 base::Bind(&WebMediaPlayerImpl::FinishMemoryUsageReport, AsWeakPtr())); | 2010 base::Bind(&WebMediaPlayerImpl::FinishMemoryUsageReport, AsWeakPtr())); |
2011 } else { | 2011 } else { |
2012 FinishMemoryUsageReport(0); | 2012 FinishMemoryUsageReport(0); |
2013 } | 2013 } |
2014 } | 2014 } |
2015 | 2015 |
2016 void WebMediaPlayerImpl::FinishMemoryUsageReport(int64_t demuxer_memory_usage) { | 2016 void WebMediaPlayerImpl::FinishMemoryUsageReport(int64_t demuxer_memory_usage) { |
2017 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 2017 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
2018 | 2018 |
2019 const PipelineStatistics stats = pipeline_.GetStatistics(); | 2019 const PipelineStatistics stats = GetPipelineStatistics(); |
2020 const int64_t data_source_memory_usage = | 2020 const int64_t data_source_memory_usage = |
2021 data_source_ ? data_source_->GetMemoryUsage() : 0; | 2021 data_source_ ? data_source_->GetMemoryUsage() : 0; |
2022 const int64_t current_memory_usage = | 2022 const int64_t current_memory_usage = |
2023 stats.audio_memory_usage + stats.video_memory_usage + | 2023 stats.audio_memory_usage + stats.video_memory_usage + |
2024 data_source_memory_usage + demuxer_memory_usage; | 2024 data_source_memory_usage + demuxer_memory_usage; |
2025 | 2025 |
2026 // Note, this isn't entirely accurate, there may be VideoFrames held by the | 2026 // Note, this isn't entirely accurate, there may be VideoFrames held by the |
2027 // compositor or other resources that we're unaware of. | 2027 // compositor or other resources that we're unaware of. |
2028 | 2028 |
2029 DVLOG(2) << "Memory Usage -- Audio: " << stats.audio_memory_usage | 2029 DVLOG(2) << "Memory Usage -- Audio: " << stats.audio_memory_usage |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2111 return false; | 2111 return false; |
2112 #else // defined(OS_ANDROID) | 2112 #else // defined(OS_ANDROID) |
2113 if (!IsBackgroundVideoTrackOptimizationEnabled()) | 2113 if (!IsBackgroundVideoTrackOptimizationEnabled()) |
2114 return false; | 2114 return false; |
2115 #endif // defined(OS_ANDROID) | 2115 #endif // defined(OS_ANDROID) |
2116 | 2116 |
2117 return hasVideo() && !hasAudio(); | 2117 return hasVideo() && !hasAudio(); |
2118 } | 2118 } |
2119 | 2119 |
2120 bool WebMediaPlayerImpl::ShouldDisableVideoWhenHidden() const { | 2120 bool WebMediaPlayerImpl::ShouldDisableVideoWhenHidden() const { |
| 2121 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
2121 DCHECK(IsHidden()); | 2122 DCHECK(IsHidden()); |
2122 return IsBackgroundVideoTrackOptimizationEnabled() && hasVideo() && | 2123 |
2123 hasAudio() && !IsStreaming(); | 2124 if (!IsBackgroundVideoTrackOptimizationEnabled() || !hasVideo() || |
| 2125 !hasAudio() || IsStreaming()) { |
| 2126 return false; |
| 2127 } |
| 2128 |
| 2129 PipelineStatistics stats = GetPipelineStatistics(); |
| 2130 return stats.video_keyframe_distance_average < |
| 2131 max_keyframe_distance_to_disable_background_video_; |
2124 } | 2132 } |
2125 | 2133 |
2126 void WebMediaPlayerImpl::EnableVideoTrackIfNeeded() { | 2134 void WebMediaPlayerImpl::EnableVideoTrackIfNeeded() { |
2127 DCHECK(!IsHidden()); | 2135 DCHECK(!IsHidden()); |
2128 | 2136 |
2129 // Don't change video track while the pipeline is resuming or seeking. | 2137 // Don't change video track while the pipeline is resuming or seeking. |
2130 if (is_pipeline_resuming_ || seeking_) | 2138 if (is_pipeline_resuming_ || seeking_) |
2131 return; | 2139 return; |
2132 | 2140 |
2133 if (video_track_disabled_) { | 2141 if (video_track_disabled_) { |
(...skipping 11 matching lines...) Expand all Loading... |
2145 // Don't change video track while the pipeline is resuming or seeking. | 2153 // Don't change video track while the pipeline is resuming or seeking. |
2146 if (is_pipeline_resuming_ || seeking_) | 2154 if (is_pipeline_resuming_ || seeking_) |
2147 return; | 2155 return; |
2148 | 2156 |
2149 if (!video_track_disabled_ && ShouldDisableVideoWhenHidden()) { | 2157 if (!video_track_disabled_ && ShouldDisableVideoWhenHidden()) { |
2150 video_track_disabled_ = true; | 2158 video_track_disabled_ = true; |
2151 selectedVideoTrackChanged(nullptr); | 2159 selectedVideoTrackChanged(nullptr); |
2152 } | 2160 } |
2153 } | 2161 } |
2154 | 2162 |
| 2163 void WebMediaPlayerImpl::SetPipelineStatisticsForTest( |
| 2164 const PipelineStatistics& stats) { |
| 2165 pipeline_statistics_for_test_ = base::make_optional(stats); |
| 2166 } |
| 2167 |
| 2168 PipelineStatistics WebMediaPlayerImpl::GetPipelineStatistics() const { |
| 2169 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 2170 |
| 2171 return pipeline_statistics_for_test_.value_or(pipeline_.GetStatistics()); |
| 2172 } |
| 2173 |
2155 } // namespace media | 2174 } // namespace media |
OLD | NEW |