w3c / media-source

Media Source Extensions
https://w3c.github.io/media-source/
Other
267 stars 59 forks source link

MSE-in-Workers: Consider (eventually) transitioning attached element to error upon termination of MediaSource's worker/what should media element do? #277

Open wolenetz opened 3 years ago

wolenetz commented 3 years ago

MSE-in-Workers feature issue is #175

This issue tracks discussing whether or not the HTMLMediaElement should do any error transition upon the termination of the DedicatedWorkerGlobalScope that owns the attached MediaSource.

The Chromium experimental implementation just leaves the element's readyState, networkState and error attributes as they were prior to the termination, and simply forces the element's seekable and buffered attributes to each return an empty TimeRange. This is sufficient to prevent unexpected playback of a resource that is no longer available. Note that the termination of the worker is typically caused either by worker.terminate() or DedicatedWorkerGlobalScope.close() from the application side, or as part of teardown of the dedicated workers owned by a Window that is terminating.

There may be important edge cases where the app may not know the MediaSource's worker scope is terminated, when it needs to. Hence this issue to discuss and see if an explicit error transition on the element would be useful in this case.

Note that such error transition might not occur until sometime after the termination of the worker has completed, since the termination steps are run in parallel with whatever is running on the element's context, so there will still be a window of time where the app might get empty buffered or seekable TimeRanges and not immediately know why, even if there were some eventual error transition of the element later due to the worker's termination.

wolenetz commented 3 years ago

Note, this corresponds to the discussion on the feature issue (#175) beginning at https://github.com/w3c/media-source/issues/175#issuecomment-721395481 -- specifically, this issue tracks the first question:

If the DedicatedWorker MediaSource's context is terminated (e.g. worker.terminate()), then the main thread element still remains connected, but seekable and buffered range information reset. There is no other immediate error exposed to the main-thread media element. Would you prefer other behavior in this scenario?

wolenetz commented 2 years ago

Due to mitigating security issues related to over-optimized cross-context communication in the Chromium experimental implementation, it will soon instead cache a recent value of each of seekable and buffered.

Edited: This doesn't fully enable the media element to continue to operate on previously buffered state after the attached MediaSource's execution context has been terminated: the experimental Chromium implementation of this removes the underlying track buffers associated with each SourceBuffer of a MSE-in-Worker whose worker context has destructed while still attached to a not-yet-destructed media element and media element's context is still alive. As such, even though the mitigation caches seekable and buffered, it will still respond with empty ranges if the worker's context has been destroyed.

The question remains:

wolenetz commented 2 years ago

Requesting this be discussed at Sept 14 Media WG meeting.

chrisn commented 1 year ago

Minutes from 14 Sep 2021 meeting: https://www.w3.org/2021/09/14-mediawg-minutes.html#t05