Bug 252938

Summary: ManagedMediaSource content should be evicted whenever it is under memory pressure
Product: WebKit Reporter: Jean-Yves Avenard [:jya] <jean-yves.avenard>
Component: MediaAssignee: Jean-Yves Avenard [:jya] <jean-yves.avenard>
Status: RESOLVED FIXED    
Severity: Normal CC: commit-queue, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
See Also: https://bugs.webkit.org/show_bug.cgi?id=252957
Bug Depends on: 253004    
Bug Blocks:    

Description Jean-Yves Avenard [:jya] 2023-02-24 17:26:19 PST
Right now, the decision to act on a media element following a memory pressure event is left to the WebProcess' MemoryPressureHandler which is set in `WebProcess::initializeWebProcess`
which ends up calling `releaseCriticalMemory` [1]
through the loop:
```
#if ENABLE(VIDEO)
    for (auto* mediaElement : HTMLMediaElement::allMediaElements()) {
        if (mediaElement->paused())
            mediaElement->purgeBufferedDataIfPossible();
    }
#endif
```

The eviction of data in a ManagedMediaSource is designed to allow the media element to continue being playable, we do not have to wait for it to be paused.

And it should be up to the MediaElement itself to determine of data should be purged or not anyway.

[1] https://searchfox.org/wubkat/source/Source/WebCore/page/MemoryRelease.cpp#118-123
Comment 1 Radar WebKit Bug Importer 2023-02-24 17:26:41 PST
<rdar://problem/105908445>
Comment 2 Jean-Yves Avenard [:jya] 2023-02-26 17:14:04 PST
Pull request: https://github.com/WebKit/WebKit/pull/10708
Comment 3 EWS 2023-02-27 02:59:11 PST
Committed 260871@main (fee371950f62): <https://commits.webkit.org/260871@main>

Reviewed commits have been landed. Closing PR #10708 and removing active labels.
Comment 4 Ryan Haddad 2023-02-27 10:18:14 PST
This change caused TestWebKitAPI.WebKit.MediaBufferingPolicy to consistently fail on macOS bots:

    TestWebKitAPI.WebKit.MediaBufferingPolicy
        
        /Volumes/Data/worker/Apple-Ventura-Release-Build/build/Tools/TestWebKitAPI/Tests/WebKitCocoa/MediaBufferingPolicy.mm:47
        Expected equality of these values:
          expected
            Which is: "PurgeResources"
          observed
            Which is: "LimitReadAhead"


https://build.webkit.org/#/builders/702/builds/1684/steps/19/logs/stdio

https://results.webkit.org/?suite=api-tests&test=TestWebKitAPI.WebKit.MediaBufferingPolicy
Comment 5 WebKit Commit Bot 2023-02-27 10:20:03 PST
Re-opened since this is blocked by bug 253004
Comment 6 Jean-Yves Avenard [:jya] 2023-02-27 18:54:21 PST
Pull request: https://github.com/WebKit/WebKit/pull/10774
Comment 7 EWS 2023-02-27 20:13:52 PST
Committed 260920@main (98b2a211bb53): <https://commits.webkit.org/260920@main>

Reviewed commits have been landed. Closing PR #10774 and removing active labels.