Bug 254324 - [GPUP][MSE] networkState doesn't move to NETWORK_IDLE once MediaSource.endOfStream() is called
Summary: [GPUP][MSE] networkState doesn't move to NETWORK_IDLE once MediaSource.endOfS...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Media (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Jean-Yves Avenard [:jya]
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2023-03-23 04:37 PDT by Jean-Yves Avenard [:jya]
Modified: 2023-03-23 08:23 PDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jean-Yves Avenard [:jya] 2023-03-23 04:37:50 PDT
While the MSE specs provides no extension to HTMLMediaElement's networkState, the spec for the HTML media element provides clear details on how it should behave.

In particular in the Resource Fetch Algorithm [1]
```
Once the entire media resource has been fetched (but potentially before any of it has been decoded)

    Fire an event named progress at the media element.

    Set the networkState to NETWORK_IDLE and fire an event named suspend at the media element.

    If the user agent ever discards any media data and then needs to resume the network activity to obtain it again, then it must queue a media element task given the media element to set the networkState to NETWORK_LOADING.

```

With MSE, the player can indicate via `endOfStream()` [2] and the End Of Stream algorithm [3]
"This algorithm gets called when the application signals the end of stream via an endOfStream()" the MediaSource readyState moves to `ended` and "Notify the media element that it now has all of the media data."

The implication is that we should move the networkState to NETWORK_IDLE and fire the `suspend` event on the video element.

The notification from the MediaSource to the MediaPlayer that it is now ended, to the MediaPlayer is done by calling `MediaSourcePrivate->markEndOfStream()` [4]

However: for the MediaSourcePrivateRemote we have for the related methods:

```
void MediaSourcePrivateRemote::markEndOfStream(EndOfStreamStatus)
{
    notImplemented();
}

void MediaSourcePrivateRemote::unmarkEndOfStream()
{
    notImplemented();
}

bool MediaSourcePrivateRemote::isEnded() const
{
    notImplemented();
    return false;
}
```

As such, the HTMLMediElement is never notified of the change of networkState and we don't fire the `suspend` event.

This code is exercised in the test `media/media-source/media-source-end-of-stream.html` when running the MockMediaSource in the GPU Process [see bug 225367)

[1] https://html.spec.whatwg.org/multipage/media.html#concept-media-load-resource
[2] https://w3c.github.io/media-source/#dom-mediasource-endofstream
[3] https://w3c.github.io/media-source/#end-of-stream-algorithm
[4] https://searchfox.org/wubkat/rev/4433b2e3d9c8bf7c4707b1afa1c8bd3a2d13f94d/Source/WebCore/Modules/mediasource/MediaSource.cpp#601
Comment 1 Radar WebKit Bug Importer 2023-03-23 04:38:26 PDT
<rdar://problem/107129124>
Comment 2 Jean-Yves Avenard [:jya] 2023-03-23 05:41:31 PDT
Pull request: https://github.com/WebKit/WebKit/pull/11860
Comment 3 EWS 2023-03-23 08:23:52 PDT
Committed 262016@main (39a3835b1f41): <https://commits.webkit.org/262016@main>

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