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

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

Issue 2605993002: Experiment with more aggressive MSE GC on memory pressure (Closed)
Patch Set: CR feedback Created 3 years, 10 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
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>
11 #include <utility> 11 #include <utility>
12 12
13 #include "base/bind.h" 13 #include "base/bind.h"
14 #include "base/bind_helpers.h" 14 #include "base/bind_helpers.h"
15 #include "base/callback.h" 15 #include "base/callback.h"
16 #include "base/callback_helpers.h" 16 #include "base/callback_helpers.h"
17 #include "base/command_line.h" 17 #include "base/command_line.h"
18 #include "base/debug/alias.h" 18 #include "base/debug/alias.h"
19 #include "base/debug/crash_logging.h" 19 #include "base/debug/crash_logging.h"
20 #include "base/location.h" 20 #include "base/location.h"
21 #include "base/memory/ptr_util.h"
21 #include "base/metrics/histogram_macros.h" 22 #include "base/metrics/histogram_macros.h"
22 #include "base/single_thread_task_runner.h" 23 #include "base/single_thread_task_runner.h"
23 #include "base/strings/string_number_conversions.h" 24 #include "base/strings/string_number_conversions.h"
24 #include "base/task_runner_util.h" 25 #include "base/task_runner_util.h"
25 #include "base/threading/thread_task_runner_handle.h" 26 #include "base/threading/thread_task_runner_handle.h"
26 #include "base/trace_event/trace_event.h" 27 #include "base/trace_event/trace_event.h"
27 #include "build/build_config.h" 28 #include "build/build_config.h"
28 #include "cc/blink/web_layer_impl.h" 29 #include "cc/blink/web_layer_impl.h"
29 #include "cc/layers/video_layer.h" 30 #include "cc/layers/video_layer.h"
30 #include "media/audio/null_audio_sink.h" 31 #include "media/audio/null_audio_sink.h"
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 surface_manager_(params.surface_manager()), 239 surface_manager_(params.surface_manager()),
239 overlay_surface_id_(SurfaceManager::kNoSurfaceID), 240 overlay_surface_id_(SurfaceManager::kNoSurfaceID),
240 suppress_destruction_errors_(false), 241 suppress_destruction_errors_(false),
241 can_suspend_state_(CanSuspendState::UNKNOWN), 242 can_suspend_state_(CanSuspendState::UNKNOWN),
242 use_fallback_path_(false), 243 use_fallback_path_(false),
243 is_encrypted_(false), 244 is_encrypted_(false),
244 underflow_count_(0), 245 underflow_count_(0),
245 preroll_attempt_pending_(false), 246 preroll_attempt_pending_(false),
246 observer_(params.media_observer()), 247 observer_(params.media_observer()),
247 max_keyframe_distance_to_disable_background_video_( 248 max_keyframe_distance_to_disable_background_video_(
248 params.max_keyframe_distance_to_disable_background_video()) { 249 params.max_keyframe_distance_to_disable_background_video()),
250 enable_instant_source_buffer_gc_(
251 params.enable_instant_source_buffer_gc()) {
249 DCHECK(!adjust_allocated_memory_cb_.is_null()); 252 DCHECK(!adjust_allocated_memory_cb_.is_null());
250 DCHECK(renderer_factory_); 253 DCHECK(renderer_factory_);
251 DCHECK(client_); 254 DCHECK(client_);
252 DCHECK(delegate_); 255 DCHECK(delegate_);
253 256
254 tick_clock_.reset(new base::DefaultTickClock()); 257 tick_clock_.reset(new base::DefaultTickClock());
255 258
256 force_video_overlays_ = base::CommandLine::ForCurrentProcess()->HasSwitch( 259 force_video_overlays_ = base::CommandLine::ForCurrentProcess()->HasSwitch(
257 switches::kForceVideoOverlays); 260 switches::kForceVideoOverlays);
258 261
(...skipping 902 matching lines...) Expand 10 before | Expand all | Expand 10 after
1161 1164
1162 UpdateBackgroundVideoOptimizationState(); 1165 UpdateBackgroundVideoOptimizationState();
1163 } 1166 }
1164 1167
1165 void WebMediaPlayerImpl::OnDemuxerOpened() { 1168 void WebMediaPlayerImpl::OnDemuxerOpened() {
1166 DCHECK(main_task_runner_->BelongsToCurrentThread()); 1169 DCHECK(main_task_runner_->BelongsToCurrentThread());
1167 client_->mediaSourceOpened( 1170 client_->mediaSourceOpened(
1168 new WebMediaSourceImpl(chunk_demuxer_, media_log_)); 1171 new WebMediaSourceImpl(chunk_demuxer_, media_log_));
1169 } 1172 }
1170 1173
1174 void WebMediaPlayerImpl::OnMemoryPressure(
1175 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level) {
1176 DVLOG(2) << __func__ << " memory_pressure_level=" << memory_pressure_level;
1177 DCHECK(main_task_runner_->BelongsToCurrentThread());
1178 DCHECK(base::FeatureList::IsEnabled(kMemoryPressureBasedSourceBufferGC));
1179 DCHECK(chunk_demuxer_);
1180
1181 // The new value of |memory_pressure_level| will take effect on the next
1182 // garbage collection. Typically this means the next SourceBuffer append()
1183 // operation, since per MSE spec, the garbage collection must only occur
1184 // during SourceBuffer append(). But if memory pressure is critical it might
1185 // be better to perform GC immediately rather than wait for the next append
1186 // and potentially get killed due to out-of-memory.
1187 // So if this experiment is enabled and pressure level is critical, we'll pass
1188 // down force_gc==true, which will force immediate GC on SourceBufferStreams.
1189 bool force_gc =
1190 (enable_instant_source_buffer_gc_ &&
1191 memory_pressure_level ==
1192 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL);
1193
1194 // base::Unretained is safe, since chunk_demuxer_ is actually owned by
1195 // |this| via this->demuxer_.
1196 media_task_runner_->PostTask(
1197 FROM_HERE, base::Bind(&ChunkDemuxer::OnMemoryPressure,
1198 base::Unretained(chunk_demuxer_),
1199 base::TimeDelta::FromSecondsD(currentTime()),
1200 memory_pressure_level, force_gc));
1201 }
1202
1171 void WebMediaPlayerImpl::OnError(PipelineStatus status) { 1203 void WebMediaPlayerImpl::OnError(PipelineStatus status) {
1172 DVLOG(1) << __func__; 1204 DVLOG(1) << __func__;
1173 DCHECK(main_task_runner_->BelongsToCurrentThread()); 1205 DCHECK(main_task_runner_->BelongsToCurrentThread());
1174 DCHECK_NE(status, PIPELINE_OK); 1206 DCHECK_NE(status, PIPELINE_OK);
1175 1207
1176 if (suppress_destruction_errors_) 1208 if (suppress_destruction_errors_)
1177 return; 1209 return;
1178 1210
1179 ReportPipelineError(load_type_, frame_->getSecurityOrigin(), status); 1211 ReportPipelineError(load_type_, frame_->getSecurityOrigin(), status);
1180 media_log_->AddEvent(media_log_->CreatePipelineErrorEvent(status)); 1212 media_log_->AddEvent(media_log_->CreatePipelineErrorEvent(status));
(...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after
1710 return; 1742 return;
1711 #endif 1743 #endif
1712 } else { 1744 } else {
1713 DCHECK(!chunk_demuxer_); 1745 DCHECK(!chunk_demuxer_);
1714 DCHECK(!data_source_); 1746 DCHECK(!data_source_);
1715 1747
1716 chunk_demuxer_ = new ChunkDemuxer( 1748 chunk_demuxer_ = new ChunkDemuxer(
1717 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnDemuxerOpened), 1749 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnDemuxerOpened),
1718 encrypted_media_init_data_cb, media_log_); 1750 encrypted_media_init_data_cb, media_log_);
1719 demuxer_.reset(chunk_demuxer_); 1751 demuxer_.reset(chunk_demuxer_);
1752
1753 if (base::FeatureList::IsEnabled(kMemoryPressureBasedSourceBufferGC)) {
1754 // base::Unretained is safe because |this| owns memory_pressure_listener_.
1755 memory_pressure_listener_ =
1756 base::MakeUnique<base::MemoryPressureListener>(base::Bind(
1757 &WebMediaPlayerImpl::OnMemoryPressure, base::Unretained(this)));
1758 }
1720 } 1759 }
1721 1760
1722 // TODO(sandersd): FileSystem objects may also be non-static, but due to our 1761 // TODO(sandersd): FileSystem objects may also be non-static, but due to our
1723 // caching layer such situations are broken already. http://crbug.com/593159 1762 // caching layer such situations are broken already. http://crbug.com/593159
1724 bool is_static = !chunk_demuxer_; 1763 bool is_static = !chunk_demuxer_;
1725 bool is_streaming = IsStreaming(); 1764 bool is_streaming = IsStreaming();
1726 UMA_HISTOGRAM_BOOLEAN("Media.IsStreaming", is_streaming); 1765 UMA_HISTOGRAM_BOOLEAN("Media.IsStreaming", is_streaming);
1727 1766
1728 // ... and we're ready to go! 1767 // ... and we're ready to go!
1729 // TODO(sandersd): On Android, defer Start() if the tab is not visible. 1768 // TODO(sandersd): On Android, defer Start() if the tab is not visible.
(...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after
2257 UMA_HISTOGRAM_TIMES( 2296 UMA_HISTOGRAM_TIMES(
2258 "Media.Video.TimeFromForegroundToFirstFrame.DisableTrack", 2297 "Media.Video.TimeFromForegroundToFirstFrame.DisableTrack",
2259 time_to_first_frame); 2298 time_to_first_frame);
2260 } else { 2299 } else {
2261 UMA_HISTOGRAM_TIMES("Media.Video.TimeFromForegroundToFirstFrame.Paused", 2300 UMA_HISTOGRAM_TIMES("Media.Video.TimeFromForegroundToFirstFrame.Paused",
2262 time_to_first_frame); 2301 time_to_first_frame);
2263 } 2302 }
2264 } 2303 }
2265 2304
2266 } // namespace media 2305 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698