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

Side by Side Diff: media/filters/source_buffer_state.cc

Issue 2605993002: Experiment with more aggressive MSE GC on memory pressure (Closed)
Patch Set: Allow MSE GC to happen in EOS state now 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/filters/source_buffer_state.h" 5 #include "media/filters/source_buffer_state.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "base/callback_helpers.h" 9 #include "base/callback_helpers.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 for (const auto& it : video_streams_) { 250 for (const auto& it : video_streams_) {
251 it.second->Remove(start, end, duration); 251 it.second->Remove(start, end, duration);
252 } 252 }
253 253
254 for (const auto& it : text_streams_) { 254 for (const auto& it : text_streams_) {
255 it.second->Remove(start, end, duration); 255 it.second->Remove(start, end, duration);
256 } 256 }
257 } 257 }
258 258
259 bool SourceBufferState::EvictCodedFrames(DecodeTimestamp media_time, 259 bool SourceBufferState::EvictCodedFrames(DecodeTimestamp media_time,
260 size_t newDataSize) { 260 size_t eviction_size) {
261 size_t total_buffered_size = 0; 261 size_t total_buffered_size = 0;
262 for (const auto& it : audio_streams_) 262 for (const auto& it : audio_streams_)
263 total_buffered_size += it.second->GetBufferedSize(); 263 total_buffered_size += it.second->GetBufferedSize();
264 for (const auto& it : video_streams_) 264 for (const auto& it : video_streams_)
265 total_buffered_size += it.second->GetBufferedSize(); 265 total_buffered_size += it.second->GetBufferedSize();
266 for (const auto& it : text_streams_) 266 for (const auto& it : text_streams_)
267 total_buffered_size += it.second->GetBufferedSize(); 267 total_buffered_size += it.second->GetBufferedSize();
268 268
269 DVLOG(3) << __func__ << " media_time=" << media_time.InSecondsF() 269 DVLOG(3) << __func__ << " media_time=" << media_time.InSecondsF()
270 << " newDataSize=" << newDataSize 270 << " eviction_size=" << eviction_size
271 << " total_buffered_size=" << total_buffered_size; 271 << " total_buffered_size=" << total_buffered_size;
272 272
273 if (total_buffered_size == 0) 273 if (total_buffered_size == 0)
274 return true; 274 return true;
275 275
276 bool success = true; 276 bool success = true;
277 for (const auto& it : audio_streams_) { 277 for (const auto& it : audio_streams_) {
278 uint64_t curr_size = it.second->GetBufferedSize(); 278 uint64_t curr_size = it.second->GetBufferedSize();
279 if (curr_size == 0) 279 if (curr_size == 0)
280 continue; 280 continue;
281 uint64_t estimated_new_size = newDataSize * curr_size / total_buffered_size; 281 uint64_t evict_size = eviction_size * curr_size / total_buffered_size;
282 DCHECK_LE(estimated_new_size, SIZE_MAX); 282 DCHECK_LE(evict_size, SIZE_MAX);
283 success &= it.second->EvictCodedFrames( 283 success &= it.second->EvictCodedFrames(media_time,
284 media_time, static_cast<size_t>(estimated_new_size)); 284 static_cast<size_t>(evict_size));
285 } 285 }
286 for (const auto& it : video_streams_) { 286 for (const auto& it : video_streams_) {
287 uint64_t curr_size = it.second->GetBufferedSize(); 287 uint64_t curr_size = it.second->GetBufferedSize();
288 if (curr_size == 0) 288 if (curr_size == 0)
289 continue; 289 continue;
290 uint64_t estimated_new_size = newDataSize * curr_size / total_buffered_size; 290 uint64_t evict_size = eviction_size * curr_size / total_buffered_size;
291 DCHECK_LE(estimated_new_size, SIZE_MAX); 291 DCHECK_LE(evict_size, SIZE_MAX);
292 success &= it.second->EvictCodedFrames( 292 success &= it.second->EvictCodedFrames(media_time,
293 media_time, static_cast<size_t>(estimated_new_size)); 293 static_cast<size_t>(evict_size));
294 } 294 }
295 for (const auto& it : text_streams_) { 295 for (const auto& it : text_streams_) {
296 uint64_t curr_size = it.second->GetBufferedSize(); 296 uint64_t curr_size = it.second->GetBufferedSize();
297 if (curr_size == 0) 297 if (curr_size == 0)
298 continue; 298 continue;
299 uint64_t estimated_new_size = newDataSize * curr_size / total_buffered_size; 299 uint64_t evict_size = eviction_size * curr_size / total_buffered_size;
300 DCHECK_LE(estimated_new_size, SIZE_MAX); 300 DCHECK_LE(evict_size, SIZE_MAX);
301 success &= it.second->EvictCodedFrames( 301 success &= it.second->EvictCodedFrames(media_time,
302 media_time, static_cast<size_t>(estimated_new_size)); 302 static_cast<size_t>(evict_size));
303 } 303 }
304 304
305 DVLOG(3) << __func__ << " success=" << success; 305 DVLOG(3) << __func__ << " success=" << success;
306 return success; 306 return success;
307 } 307 }
308 308
309 void SourceBufferState::OnMemoryPressure(
310 DecodeTimestamp media_time,
311 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level) {
312 size_t total_released = 0;
313
314 // Under moderate memory pressure we'll try to release about half of each
315 // stream's memory limit. But for critical memory pressure we'll want to
316 // release as much as possible.
317 size_t mem_pressure_factor = 2;
318 if (memory_pressure_level ==
319 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL)
320 mem_pressure_factor = 1;
321
322 // Try to perform garbage collection in video streams first, since that's
323 // where we'll probably get most memory savings.
324 for (const auto& it : video_streams_) {
325 size_t released = 0;
326 it.second->EvictCodedFrames(
327 media_time, it.second->stream_memory_limit() / mem_pressure_factor,
328 &released);
329 total_released += released;
330 }
331 for (const auto& it : audio_streams_) {
332 size_t released = 0;
333 it.second->EvictCodedFrames(
334 media_time, it.second->stream_memory_limit() / mem_pressure_factor,
335 &released);
336 total_released += released;
337 }
338 for (const auto& it : text_streams_) {
339 size_t released = 0;
340 it.second->EvictCodedFrames(
341 media_time, it.second->stream_memory_limit() / mem_pressure_factor,
342 &released);
343 total_released += released;
344 }
345 DVLOG(3) << __func__ << " total_released=" << total_released;
346 }
347
309 Ranges<TimeDelta> SourceBufferState::GetBufferedRanges(TimeDelta duration, 348 Ranges<TimeDelta> SourceBufferState::GetBufferedRanges(TimeDelta duration,
310 bool ended) const { 349 bool ended) const {
311 RangesList ranges_list; 350 RangesList ranges_list;
312 for (const auto& it : audio_streams_) 351 for (const auto& it : audio_streams_)
313 ranges_list.push_back(it.second->GetBufferedRanges(duration)); 352 ranges_list.push_back(it.second->GetBufferedRanges(duration));
314 353
315 for (const auto& it : video_streams_) 354 for (const auto& it : video_streams_)
316 ranges_list.push_back(it.second->GetBufferedRanges(duration)); 355 ranges_list.push_back(it.second->GetBufferedRanges(duration));
317 356
318 for (const auto& it : text_streams_) 357 for (const auto& it : text_streams_)
(...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after
888 } 927 }
889 void SourceBufferState::OnSourceInitDone( 928 void SourceBufferState::OnSourceInitDone(
890 const StreamParser::InitParameters& params) { 929 const StreamParser::InitParameters& params) {
891 DCHECK_EQ(state_, PENDING_PARSER_INIT); 930 DCHECK_EQ(state_, PENDING_PARSER_INIT);
892 state_ = PARSER_INITIALIZED; 931 state_ = PARSER_INITIALIZED;
893 auto_update_timestamp_offset_ = params.auto_update_timestamp_offset; 932 auto_update_timestamp_offset_ = params.auto_update_timestamp_offset;
894 base::ResetAndReturn(&init_cb_).Run(params); 933 base::ResetAndReturn(&init_cb_).Run(params);
895 } 934 }
896 935
897 } // namespace media 936 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698