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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: media/filters/source_buffer_state.cc
diff --git a/media/filters/source_buffer_state.cc b/media/filters/source_buffer_state.cc
index 5d692c44dde081715cc57842c09a438bb2b590dc..46fa7ce6f2c2f30a7410aaf1f17dc0665b9627cf 100644
--- a/media/filters/source_buffer_state.cc
+++ b/media/filters/source_buffer_state.cc
@@ -257,7 +257,7 @@ void SourceBufferState::Remove(TimeDelta start,
}
bool SourceBufferState::EvictCodedFrames(DecodeTimestamp media_time,
- size_t newDataSize) {
+ size_t eviction_size) {
size_t total_buffered_size = 0;
for (const auto& it : audio_streams_)
total_buffered_size += it.second->GetBufferedSize();
@@ -267,7 +267,7 @@ bool SourceBufferState::EvictCodedFrames(DecodeTimestamp media_time,
total_buffered_size += it.second->GetBufferedSize();
DVLOG(3) << __func__ << " media_time=" << media_time.InSecondsF()
- << " newDataSize=" << newDataSize
+ << " eviction_size=" << eviction_size
<< " total_buffered_size=" << total_buffered_size;
if (total_buffered_size == 0)
@@ -278,34 +278,73 @@ bool SourceBufferState::EvictCodedFrames(DecodeTimestamp media_time,
uint64_t curr_size = it.second->GetBufferedSize();
if (curr_size == 0)
continue;
- uint64_t estimated_new_size = newDataSize * curr_size / total_buffered_size;
- DCHECK_LE(estimated_new_size, SIZE_MAX);
- success &= it.second->EvictCodedFrames(
- media_time, static_cast<size_t>(estimated_new_size));
+ uint64_t evict_size = eviction_size * curr_size / total_buffered_size;
+ DCHECK_LE(evict_size, SIZE_MAX);
+ success &= it.second->EvictCodedFrames(media_time,
+ static_cast<size_t>(evict_size));
}
for (const auto& it : video_streams_) {
uint64_t curr_size = it.second->GetBufferedSize();
if (curr_size == 0)
continue;
- uint64_t estimated_new_size = newDataSize * curr_size / total_buffered_size;
- DCHECK_LE(estimated_new_size, SIZE_MAX);
- success &= it.second->EvictCodedFrames(
- media_time, static_cast<size_t>(estimated_new_size));
+ uint64_t evict_size = eviction_size * curr_size / total_buffered_size;
+ DCHECK_LE(evict_size, SIZE_MAX);
+ success &= it.second->EvictCodedFrames(media_time,
+ static_cast<size_t>(evict_size));
}
for (const auto& it : text_streams_) {
uint64_t curr_size = it.second->GetBufferedSize();
if (curr_size == 0)
continue;
- uint64_t estimated_new_size = newDataSize * curr_size / total_buffered_size;
- DCHECK_LE(estimated_new_size, SIZE_MAX);
- success &= it.second->EvictCodedFrames(
- media_time, static_cast<size_t>(estimated_new_size));
+ uint64_t evict_size = eviction_size * curr_size / total_buffered_size;
+ DCHECK_LE(evict_size, SIZE_MAX);
+ success &= it.second->EvictCodedFrames(media_time,
+ static_cast<size_t>(evict_size));
}
DVLOG(3) << __func__ << " success=" << success;
return success;
}
+void SourceBufferState::OnMemoryPressure(
+ DecodeTimestamp media_time,
+ base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level) {
+ size_t total_released = 0;
+
+ // Under moderate memory pressure we'll try to release about half of each
+ // stream's memory limit. But for critical memory pressure we'll want to
+ // release as much as possible.
+ size_t mem_pressure_factor = 2;
+ if (memory_pressure_level ==
+ base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL)
+ mem_pressure_factor = 1;
+
+ // Try to perform garbage collection in video streams first, since that's
+ // where we'll probably get most memory savings.
+ for (const auto& it : video_streams_) {
+ size_t released = 0;
+ it.second->EvictCodedFrames(
+ media_time, it.second->stream_memory_limit() / mem_pressure_factor,
+ &released);
+ total_released += released;
+ }
+ for (const auto& it : audio_streams_) {
+ size_t released = 0;
+ it.second->EvictCodedFrames(
+ media_time, it.second->stream_memory_limit() / mem_pressure_factor,
+ &released);
+ total_released += released;
+ }
+ for (const auto& it : text_streams_) {
+ size_t released = 0;
+ it.second->EvictCodedFrames(
+ media_time, it.second->stream_memory_limit() / mem_pressure_factor,
+ &released);
+ total_released += released;
+ }
+ DVLOG(3) << __func__ << " total_released=" << total_released;
+}
+
Ranges<TimeDelta> SourceBufferState::GetBufferedRanges(TimeDelta duration,
bool ended) const {
RangesList ranges_list;

Powered by Google App Engine
This is Rietveld 408576698