Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MSE in Workers #547

Open
wolenetz opened this issue Jun 30, 2021 · 11 comments
Open

MSE in Workers #547

wolenetz opened this issue Jun 30, 2021 · 11 comments
Labels
venue: W3C Specifications in W3C Working Groups

Comments

@wolenetz
Copy link

Request for Mozilla Position on an Emerging Web Specification: MSE-in-Workers feature addition to MSE in the MSEv2 specification.

Other information

This feature has previously been discussed at HTML Media WG F2F and FOMS conferences as early as Fall 2018 and March 2019, with Mozilla representatives present. It expands the availability of the MSE API to be useable from a DedicatedWorker context, and retains the existing MediaSource objectURL idiom/mechanism for attaching/extending an HTMLMediaElement for use with the MediaSource API. Chromium has an experimental implementation and there is a demo [1] of the feature and how it can effectively improve media buffering and playback performance especially when the main Window context is under contention.

[1] https://wolenetz.github.io/mse-in-workers-demo/mse-in-workers-demo.html

@wolenetz
Copy link
Author

The associated MSE feature-tracking issue in the MSE specification's repository is w3c/media-source#175

@annevk
Copy link
Contributor

annevk commented Jul 21, 2021

It seems rather unfortunate that this further cements URL.createObjectURL() rather than building on media.srcObject in some way. It's rather easy to create memory leaks with the former.

cc @padenot @jan-ivar

@annevk annevk added the venue: W3C Specifications in W3C Working Groups label Jul 21, 2021
@jan-ivar
Copy link
Member

@annevk I agree. Oddly, the spec mentions the url hack, but doesn't mention that MediaSource can already be directly assigned to srcObject, which is the superior way that should be encouraged (an oversight?). It looks like only Safari implements srcObject correctly here so far, maybe that's a factor?

Why isn't MediaSource Serializable? (copy semantics seem preferable here over transferable).

I'd consider this a minor issue however, as urls would probably need to work too, and I wouldn't block on removing urls. Overall I'm supportive of MSE in workers and welcome it. Cc @youennf

@annevk
Copy link
Contributor

annevk commented Jul 23, 2021

Unless I'm missing something, the current design for MediaSource in workers depends on URL.createObjectURL(), so unless that is addressed we'll further spread it. And since MediaSource isn't exposed in workers, we could make URL.createObjectURL() in workers throw for it once we expose MediaSource there. It's somewhat minor relative to the entire feature, but I would like to see it addressed.

@johnBartos
Copy link

I'd like to put in a big +1 on behalf of Twitch. I believe we'll see a very significant drop in rebuffering, especially during periods of main thread contention like the initial page load. We have already implemented this thanks to @wolenetz 's efforts in Chrome, and I'd love to see this in FF as well (and Safari, but one can dream).

@wolenetz
Copy link
Author

wolenetz commented Jul 28, 2021 via email

@karlt
Copy link

karlt commented Aug 10, 2021

Use of object URLs across threads/realms would introduce new problems that are not present with use in a single realm.
Some of these issues were raised previously.

There is also a potential race at creation of the URL. I guess the implementation is expected to somehow pass meaning for the URL to Window scope prior to receiving any postMessage() message from the worker? Content can also pass URLs via shared memory.

Is the set of Window scopes that must associate a URL with a Worker MediaSource after or during createObjectURL() defined?

IIUC the original MediaSourceHandle approach involved creating the MediaSource in Window scope and transferring a handle to Worker scope, which handle had the complexity of a number of methods and/or attributes to be replicated to behave as a MediaSource.

Has consideration been given to a transferable object that would solely pass a MediaSource identifier from Worker to Window?
Wouldn't an explicit transfer of a MediaSource reference be simpler than having to specify and implement a new mechanism for when an object URL might have meaning in different realms, including when such meaning would expire?

@wolenetz
Copy link
Author

Note that using srcObject for MSE-in-Workers attachments is a change to the feature that the media wg arrived at last September [1], and I'm working on getting that into both the feature spec and Chromium's experimental implementation currently.

[1] https://www.w3.org/2021/09/14-mediawg-minutes.html

@wolenetz
Copy link
Author

wolenetz commented Feb 16, 2022

@#547 (comment) -

Has consideration been given to a transferable object that would solely pass a MediaSource identifier from Worker to Window?

This is the approach I'm currently considering: since the MediaSource itself isn't transferrable as it's an EventTarget, and since the experiment with worker-originated objectURLs has already shown significant improvements, having the attach object be constructable in a dedicated worker for worker-originated-then-transferred-to-main for use in srcObject attachment is the precise mechanism I'm considering now (to more readily replace the existing objectURL worker attachment mechanism).

Other ways of using srcObject (e.g. main-thread-only MSE attachments, or even main-thread origination of the transfer) are out of scope of this work but are not precluded.

-edited for format

@wolenetz
Copy link
Author

Transferable MediaSourceHandle settable on main thread media element srcObject, and obtained via [SameObject] readonly MediaSource.handle has landed in the MSE specification following discussions here and especially in MSE spec PRs w3c/media-source#305 and w3c/media-source#306. I believe I've addressed all concerns.

@wolenetz
Copy link
Author

With the specification, explainer and demo all updated now, please revisit this official request for position. Thank you.

@zcorpan zcorpan changed the title Request for position on MSE-in-Workers MSE in Workers Apr 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
venue: W3C Specifications in W3C Working Groups
Projects
Status: Unscreened
Development

No branches or pull requests

5 participants