Re: [mediacapture-main] Move "global" internal slots to MediaDevices, and fix "relevant object" links (#939)

> I do not see why it would not work, getUserMedia creates a source that gets associated to ONE global object.

My understanding is a [source](https://w3c.github.io/mediacapture-main/#dfn-source) _"can be a physical webcam"_, making it a singleton in the entire user agent.

[gUM](https://w3c.github.io/mediacapture-main/#dfn-same-permission) doesn't "create" it, as much as it: _"Let[s] grantedDevice be finalCandidate's source device. ... Let track be the result of [creating a MediaStreamTrack](https://w3c.github.io/mediacapture-main/#dfn-create-a-mediastreamtrack) with grantedDevice"_, which initializes track.[[[Source]]](https://w3c.github.io/mediacapture-main/#dfn-source-0).

E.g. in [this iframe example](https://jan-ivar.github.io/dummy/iframe_iframe_gum_cross.html) (Once I hit Allow and the `Camera` button in the iframe) two video element self-views will play, but there is ONE source (the singular physical camera) associated with TWO global objects (two `navigator.mediaDevices` objects with distinct [relevant global object](https://html.spec.whatwg.org/multipage/webappapis.html#concept-relevant-global)s).

> For transferred tracks, stopping the source will trigger the ended event

But [stop all sources](https://w3c.github.io/mediacapture-main/getusermedia.html#dfn-stop-all-sources) isn't handling that correctly, as written. It says: _"For each [MediaStreamTrack](https://w3c.github.io/mediacapture-main/getusermedia.html#dom-mediastreamtrack) object track whose [relevant global object](https://html.spec.whatwg.org/multipage/#concept-relevant-global) is globalObject, set track's [[[ReadyState]]](https://w3c.github.io/mediacapture-main/getusermedia.html#dfn-readystate) to "[ended](https://w3c.github.io/mediacapture-main/getusermedia.html#idl-def-MediaStreamTrackState.ended)"."_

This fails to:
1. queue a task
2. consider the same source may be tied to multiple global objects
3. include tracks that have been transferred away to other global objects that now should end (since [track source lifetime management remains tied to the context that created it](https://w3c.github.io/mediacapture-extensions/#transferable-mediastreamtrack))
4. consider tracks that have been transferred _here_ from _other_ global objects (which get included here), but if this was the last reference, it needs to [end](https://www.w3.org/TR/mediacapture-streams/#ends-nostop) that reference and stop the source in those other global objects)

In the PR this is fixed [like this](https://pr-preview.s3.amazonaws.com/jan-ivar/mediacapture-main/pull/939.html#dfn-end-all-mediastreamtracks).

-- 
GitHub Notification of comment by jan-ivar
Please view or discuss this issue at https://github.com/w3c/mediacapture-main/pull/939#issuecomment-1458870504 using your GitHub account


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Tuesday, 7 March 2023 21:02:46 UTC