Commit 503f6d32 authored by Matt Wolenetz's avatar Matt Wolenetz Committed by Commit Bot

MSE-in-Workers: Narrow the SourceBuffer GC exclusion

Before this change, the MSE SourceBuffer's coded frame eviction
algorithm (run during the synchronous portion of appendBuffer() as part
of the Prepare Append Algorithm) returned early without evicting
anything if the media element had not yet reached HAVE_METADATA. In MSE,
the only way for the media element to have reached HAVE_METADATA (at
least in Chromium) is for all of the SourceBuffers currently in the
MediaSource to have all had enough data appended to each of them such
that at least one initialization segment each has been successfully
processed.

This has two problems:
1) It relies upon external state unnecessarily: the SourceBuffer knows
   if it has potentially buffered media frames already beyond the first
   init segment if its |first_initialization_segment_received_| flag is
   true. A (good) side effect of switching to using this flag instead of
   consulting the media element is a simplification of the dependency
   upon media element state in the current MSE-in-Workers feature work
   that is clarifying such dependencies into the MediaSourceAttachment
   interface.

2) Making eviction a noop when there is at least one other SourceBuffer
   that has not yet received an initialization segment lets an app
   append potentially too much without having to handle the pushback of
   a quota-exceeded-error earlier, limiting the effectiveness of MSE's
   automatic garbage collection of coded frames, especially when device
   memory is constrained.

This change switches from using MediaElement.readyState < HAVE_METADATA
to instead using !first_initialization_segment_received_ as the
condition which would allow skipping coded frame eviction during an
appendBuffer().

Note: This condition was always intended as a runtime performance
optimization, and is part of the implementation area that is allowed
flexibility by the MSE specification.

BUG=878133

Change-Id: I1173fbdf8aec5e4521b0f73049aeeb7c56ab7ab7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2393356Reviewed-by: default avatarWill Cassella <cassew@google.com>
Commit-Queue: Matthew Wolenetz <wolenetz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#804509}
parent 7a21ab44
......@@ -1253,11 +1253,9 @@ bool SourceBuffer::EvictCodedFrames(double media_time, size_t new_data_size) {
DCHECK(source_);
DCHECK(source_->MediaElement());
// Nothing to do if the mediaElement does not yet have frames to evict.
if (source_->MediaElement()->getReadyState() <
HTMLMediaElement::kHaveMetadata) {
// Nothing to do if this SourceBuffer does not yet have frames to evict.
if (!first_initialization_segment_received_)
return true;
}
bool result = web_source_buffer_->EvictCodedFrames(media_time, new_data_size);
if (!result) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment