Enable Media Source Extensions (MSE) API usage from DedicatedWorker contexts to enable improved performance of buffering media for playback by an HTMLMediaElement on the main Window context. By creating a MediaSource object on a DedicatedWorker context, an application may then create an ObjectURL for it and postMessage that URL to the main thread for use in attaching to an HTMLMediaElement. The context that created the MediaSource object may then use it to buffer media.
Main interoperability risk is that other browsers may not implement it. Compatibility risk is mitigated by unchanged same-thread MSE API support and proactive feature-detectability of MSE-in-Workers with a new canConstructInDedicatedWorker attribute on the MediaSource interface.
DedicatedWorker, WorkerGlobalScope and postMessage/onmessage availability is integral to using this feature.
The primary risk is the potential difficulty in refactoring existing MSE web applications to (conditionally, depending on browser support) perform buffering in a different execution context from the Window context that hosts the DOM and the media element. The benefit of potentially improved buffering performance by offloading the MSE API usage to a worker context provides motivation to overcome this challenge.
Unpredictability of racing context destruction of either the main thread hosting the media element (and owning the underlying MSE media demuxer and player) or the dedicated worker thread hosting the interface to the MSE demuxer when using MSE from a worker context motivated careful design of a refcounted, outside-of-Oilpan, attachment abstraction to ensure safety of operations using locks and having a lifetime that exceeds those execution contexts. Preventing use-after-free and similar was a primary complexity of implementation and a focus area of added tests.
* Obtain developer feedback on API ergonomics and implementation stability. * Increase confidence in benefits of feature (exposing and enabling MSE usage from DedicatedWorker contexts) to support its standardization.
MSE and DedicatedWorker already exist on all six Blink platforms. This feature lets MSE work from DedicatedWorker contexts.
--
You received this message because you are subscribed to the Google Groups "blink-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blink-dev+...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/blink-dev/CAADho6OYdKY_VBN94cDZGKwDrR_D7JSG4EZq%3DvMas%2B5Q%2BXR-xA%40mail.gmail.com.
Thank you for your question. I'm uncertain what is meant by a "cross-thread stream" in the context of MSE-in-Workers, though I believe I understand your overall concern.The specification makes most of the MSE/HTMLMediaEelement Worker/Window state communication operations rely upon a "cross-context communication mechanism" which allows for implementations to be as slow as an app doing postMessages to communicate state changes across contexts. However, the spec also allows for implementations to perform such communication in more optimized fashion. The current experimental Chromium implementation does some, though not all, operations in this more performant fashion. I'll attempt to list the ops which are/are not optimized here:
- Most operations in the MSE impl that touch the media pipeline/demuxer are asynchronous:
- SourceBuffer appendBuffer(..)/appendEncodedChunk(..)/remove(start,end): apart from initial sanity checks internal to the MSE API, these queue tasks to parse and buffer input (or remove a range of buffered media) with the demuxer asynchronously, with completion or error causing a change to the 'updating' attribute in Worker, newly queued events in Worker, and if the media pipeline deems the newly buffered information merits media element notification (readyState transition, playback state progress/stall/etc), that is done too (though concurrently and not synchronous with the dispatch or 'updating' transition in Worker). Also, at most one of these operations on a specific SourceBuffer can be in flight at a time. I don't think it's possible to construct a high-res timer from these operations.
- Duration attribute updates in Worker are trampolined via media thread asynchronously to Window.
- HTMLMediaElement.buffered and seekable queries in Window are dependent upon the result of asynchronous operations in Worker (appends/removes, described above), with the exception of:
- The buffered and seekable synchronous calculations are done under a micro-lock on the shared Worker state, and though the buffered ranges are updated asynchronously (per above) in a SourceBuffer, there are other operations on MSE API that are synchronous and could modify the result of the seekable query:
- [*] set/clearLiveSeekableRange is used by .seekable if duration is +Infinity. If duration is not used and nothing is buffered, then seekable contains the duration value as the single range's end time. This is the only information of which I am aware that the implementation might allow a Worker to set timing information using the seekable range and duration.
Considering a successful MSE-in-Worker attachment/connection is allowed only for same-origin workers, if I understand correctly, then would [*] be a cause for concern?Possible mitigations for [*]:
- Make the seekable and buffered queries done by the media element depend on asynchronously updated live-seekable-range and duration information.
To unsubscribe from this group and stop receiving emails from it, send an email to blink-dev+unsubscribe@chromium.org.
To unsubscribe from this group and stop receiving emails from it, send an email to blink-dev+...@chromium.org.