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
Created attachment 454492 [details] Patch
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.
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.
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.
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].
<rdar://problem/90243150>