Bug 237780

Summary: [MSE][SourceBuffer] Fix removal of paddings from buffered range
Product: WebKit Reporter: Enrique Ocaña <eocanha>
Component: MediaAssignee: Enrique Ocaña <eocanha>
Status: RESOLVED FIXED    
Severity: Normal CC: calvaris, eric.carlson, ews-watchlist, glenn, jer.noble, philipj, sergio, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch none

Description Enrique Ocaña 2022-03-11 06:38:41 PST
This change fixes high memory usage in apps that do TS -> MP4 transmuxing. The high memory usage is observed in some streams that have a slight overlap in media samples (usually happens on video quality change), when application applies its own logic for samples removal (that looks like sourceBuffer.remove(sourceBuffer.buffered.start(0), ...)).

Current implementation reports a buffered range that is inconsistent with the actual samples that are still in the buffer (after range removal). The reported range excludes one sample, allowing that sample to "leak". Such a sample holds a reference to the entire appended chunk (due to in-place demuxing in GStreamer MSE backend), but it accounts only for a small size in the buffer. So eviction algorithm doesn't kick in.

See the full discussion of this problem here:
https://github.com/WebPlatformForEmbedded/WPEWebKit/pull/797#discussion_r818973424
Comment 1 Enrique Ocaña 2022-03-11 09:56:29 PST
Created attachment 454492 [details]
Patch
Comment 2 Jer Noble 2022-03-11 10:05:15 PST
Comment on attachment 454492 [details]
Patch

Thanks for the patch, and thanks for working with me on it in the WPEWebKit repo. r=me once the EWS clears it.
Comment 3 Enrique Ocaña 2022-03-11 10:11:42 PST
All the merit goes to Eugene, not to me. He took the time to debug and solve the issue, as well as creating the test case. I just ported it.
Comment 4 Enrique Ocaña 2022-03-14 05:52:56 PDT
The editing/spelling/spellcheck-api-crash.html failed test in the ios-wk2 EWS is completely unrelated to MSE and to the changes done in this patch. Also "MediaSource is not currently supported on iOS". 

I'm assuming that I can ignore it and safely land the patch.
Comment 5 EWS 2022-03-14 06:22:54 PDT
Committed r291225 (248380@main): <https://commits.webkit.org/248380@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 454492 [details].
Comment 6 Radar WebKit Bug Importer 2022-03-14 06:23:17 PDT
<rdar://problem/90243150>