-
Notifications
You must be signed in to change notification settings - Fork 19
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
Add support for transferable MediaStreamTracks #21
Conversation
@dontcallmedom, do you know why there is an issue with IPR? |
it's a bug in the IPR manager AFAICT, which I have reported and hope to see resolved soon |
Thanks! |
the IPR manager bug has been fixed, although for some reason I can't seem to reset the IPR flag - anyway, hopefully this is already clear it should not block merging this PR |
Adding a small commit fixes the issue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall I'm positive about doing this, though I have some questions about design.
Unlike the streams spec, the desirable semantics here seem closer to track.clone() than to a data tunnel, except when it comes to lifetime which seems tied to permission granted the original document.
index.html
Outdated
<p>To preserve the existing privacy and security infrastructure, in particular for capture tracks, | ||
a transferred track remains tightly bound to the original track. | ||
In particular, if the original track gets muted, unmuted or ended, the transferred track will automatically be muted, unmuted or ended. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find this sentence confusing, as no "original track" survives a transfer in any functional sense to have experiences like "gets muted" (only a "detached" interface remains).
I also think the (un)muted and enabled properties are implicit in being a MediaStreamTrack
(we say less in clone).
But I think we need to expressly limit the track being live to when the realm it was originally granted to exists. And this mustn't be transitive (if the transferred track is transferred yet again). How about:
<p>To preserve the existing privacy and security infrastructure, in particular for capture tracks, | |
a transferred track remains tightly bound to the original track. | |
In particular, if the original track gets muted, unmuted or ended, the transferred track will automatically be muted, unmuted or ended. | |
<p>To preserve existing privacy, security, and permission infrastructure, in particular for tracks from | |
capture sources, transferred tracks MUST [= track/ended | end =], if they haven't already, when they | |
would have ended had they never been transferred. |
This also exposes that mediacapture-main doesn't expressly say anywhere that tracks must end on navigation. We should probably specify that with some unloading document cleanup steps. — Luckily browsers already do this.
// Remove partial once we figure out how to do it without creating respec warnings. | ||
// No change to MediaStreamTrack exposed API. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How can we remove partial
? This isn't the full interface.
This might be one of those cases where we need to say "wait for the document to be merged with mediacapture-main"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, that is the best tradeoff I found to still add useful IDL information in that PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see why partial should be removed, given that this is only part of the interface, and that the WebIDL convention is that all IDL that a browser implements should be considered merged in the implementation.
Having an extended visibility list in a partial is unusual for sure, but if the IDL parser doesn't complain, I'm not going to.
index.html
Outdated
<li><p>Let <var>port1</var> be a new {{MessagePort}} in <a href="https://tc39.es/ecma262/#current-realm">the current Realm</a>.</p></li> | ||
<li><p>Let <var>port2</var> be a new {{MessagePort}} in <a href="https://tc39.es/ecma262/#current-realm">the current Realm</a>.</p></li> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not convinced we need these ports. They seem to be used solely to convey signals from the user agent — track.stop()
on the detached track won't work — which I think may be better described as requirements on the user agent, if they aren't already, without going through the original track. This also avoids complexity if a transferred track is transferred around further.
E.g. I'd expect user agents to mute/unmute or end the source, not individual tracks. To the extent this is not the case, I wouldn't begin to assume how this might work in a particular user agent, nor would I try to prescribe it.
We should probably audit our permission indicator logic after this though.
Note I was mostly thinking about camera, microphone, and screen-capture in this review. I suspect those are the short-term targets here, correct? If so, should we perhaps scope this down? E.g. for things like canvas/element capture (less sure about RTCPeerConnection?), tunnel semantics may make more sense. |
Thanks for the review!
I agree but the media capture spec is not talking about that, it is merely talking about muting/unmuting a track. Maybe we should improve media capture main spec, mute/unmute/stop sources, more clearly define sources and how they relate to sinks...
Maybe. I would first try to have something working generally and scope it down if we cannot agree on the general procedure. With the current PR, if transferring from R1 to R2 then to R3, the final MediaStreamTrack living in R3 will not get ended when R2 goes away. It will only happen when R1 goes away. |
Fixes #16 |
I passed on a suggestion in #16 (comment) that might simplify this PR a bit. Suggest evaluating that before progressing with this CL. |
@alvestrand, can you clarify the potential simplifications you have in mind? |
A version of this PR that uses serializable is uploaded as #24 - the main simplification is to drop the whole internal port stuff by referring to the track source as the object that has the power to end the track. |
The port stuff is somehow orthogonal to serialisable vs. transferable. To do so, we would need to more precisely describe the notion of a source, its lifetime, its muting in mediacapture-main. Let's take the following example:
The port stuff tries to handle these cases as an algorithm based on what is observable and interoperable in UAs, i.e. tracks. |
To Youenn's example: If TA1 and TB1 have the same origin, the argument for considering them to be separate sources is strictly utilitarian; it binds them to their original context, so we can close TA2 when iframe A closes; if they instead are considered the same source, TB1 and TB2 have no real reason to stop (but then the argument for stopping them at all as long as the worker lives becoms weaker). Suggest that the principle of least surprise says that we define a (device) source to be specific to the document/context it is created in. |
As per WG discussion, I split the lifetime management from this PR and only kept the transferable pieces. |
It might be a good approach to define a source and a sink model (for this PR but also for raw access) but this is a hard task and we might encounter issues with how implementations actually work. That is why the lifetime management I removed from this PR was based on tracks which is more solid from an interop point of view. Implementations might not need to actually use tracks to implement the same behavior.
Right, this seems to go well with the lifetime management pieces I removed from this PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we make it more clear where data holder is defined (e.g. HTML spec)?
…is not GCed until port1 is
Co-authored-by: Jan-Ivar Bruaroey <jan-ivar@users.noreply.github.com>
Co-authored-by: Jan-Ivar Bruaroey <jan-ivar@users.noreply.github.com>
Co-authored-by: Jan-Ivar Bruaroey <jan-ivar@users.noreply.github.com>
The transfer steps refer to the HTML spec (https://html.spec.whatwg.org/multipage/structured-data.html#transfer-steps), shortly before dataHolder is defined. Not sure how much I can improve things. |
579e9c4
to
0846b9c
Compare
Rebasing on top of main to have correct sections |
Preview | Diff