-
Notifications
You must be signed in to change notification settings - Fork 62
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
Should we revisit and document getUserMedia() track order? #1028
Comments
@jan-ivar Is there ever a time when a MediaStream would be returned from |
|
See webrtcHacks/adapter#969 and the related discussion. I am not sure if lexographically order of tracks sorted by the id is meaningful to anyone, sorting by kind and then by id seems more natural. I'd suggest checking how getTracks + addTrack behaves and look forward to the WPT! edit: done, see this fiddle:
|
Note: chromium returns audiotracks-then-videotracks from getTracks(), see here, changed in 2014 Which makes sense for getUserMedia but not so much when you consider manually added tracks (empty stream + video + audio => [audio, video] or clones. |
[audio,video] + video clone + audio clone: https://jsfiddle.net/fippo/w7z91b8k/1/ show link
I do not think this this is an improvement. We also need to be careful about remote tracks as shown by this which puts video first, then audio in the SDP: I'm happy to send a PR updating https://w3c.github.io/webrtc-pc/#legacy-interface-extensions but the biggest compat-win would be Safari stopping to randomize the order. (and note that adapter does not interfere with |
Working like Firefox is not "breakage". There's no risk here as far as I'm concerned. Only upside.
SDP is garbage in garbage out. E.g. put the It seems clear we would have heard about it by now if this were problematic. Knowing there's no breakage, it's disappointing we cannot align around the spec which has the most natural and logical behavior, which happens to be how Firefox already works in this case. |
As an exercise let me walk you through https://www.chromium.org/blink/launching-features/#behavior-changes:
Since we do not have a use-counter I'll make a guess:
Should we ask some Chromium API owners if they would sign this off as a "web-facing change"? And keep in mind that this affects SDP... you know why Firefox continues to put version 99 into its SDP? Does not seem logical to me... |
I see no evidence that changing Chrome’s track order would cause breakage. Other browsers (Firefox and Safari) have always had different track orders with no ill effect. Any site depending on a particular browser’s order is already non-interoperable, since the spec explicitly allows any order. Unifying behavior reduces confusion and helps developers. If there’s usage data showing a real dependency, that would be valuable, but absent that, fears of “breakage” seem unfounded.
IOW no issue for Chromium whose gUM order would remain unchanged:
There's no evidence websites rely on this order or that anything would break. There's evidence they don't (interoperable websites). If usage data for ordering assumptions exists, it would be good to see it. Absent that, we should not assume a hidden dependency that has somehow gone unreported despite existing browser differences. |
Absence of evidence is very different from evidence of absence.
We don't want to break those sites either.
Let's unify then around Chrome's behavior. If we want to guarantee order for getTracks() we should also do it for getAudioTracks() and getVideoTracks(). We can specify it as internally having two ordered sets, one for getAudioTracks() and one for getVideoTracks(). The order would be the order in which tracks are added to the corresponding set. |
It seems incumbent on those making unsubstantiated claims of "breakage" to provide evidence, and explain how breakage would manifest. I've provided plenty of evidence of absence: years of different browser orders without bug reports.
Which sites are those?
Unifying on Chrome’s historic ordering seems arbitrary. If we truly suspect real-world reliance, a usage counter could confirm that. Otherwise, there is no evidence of harm in converging on a single, simpler order that aligns track set with https://infra.spec.whatwg.org/#sets
Agreed. Those already appear expressed as the |
What's unsubstantiated is claiming that this change is risk-free.
That's only evidence that the status quo does not cause problems to anyone, which is strong evidence in favor of maintaining the status quo. It is not evidence of absence of harm after we deploy the change.
I don't want to find out.
No more arbitrary than any other ordering.
In the past, behavior changes to established APIs like this one have caused breakage for Chrome users.
But we still need to wait for WebKit's assessment.
I support proceeding with this one if no one objects. |
It’s contradictory to cite “no bug reports” as evidence supporting the status quo while also dismissing the same “no bug reports” as no evidence supporting change. If lack of bug reports proves anything, it’s that different orders have coexisted for years without incident—i.e. the absence of bug reports is actually evidence that changes like these pose little risk. |
An outcome completely consistent with the evidence presented so far is that the browser that changes its behavior starts to receive bug reports, and the browsers that keep their behavior continue to receive no bug reports. But I have already presented our concerns and a compromise solution that seems to address all concerns presented so far. I think we should now wait for WebKit's assessment and continue from there. |
There are four separate technical issues here. 1/ getUserMedia track order (what the title says) and how it affects peerconnection
2/ how does getTracks behave if a video track and a audio track are added to a GUM track and then used in a peerconnection
3/ how does getTracks behave if an audio track from getUserMedia is added to a video track from getDisplayMedia and then used in a peerconnection
4/ SDP
Of those four problems I have only seen evidence of breakage for (1, link above) and of course (4) is a headache. Speaking as a web developer please @youennf consider (1) |
I explained on the call the history of why track order is implemented as "group by type": The original specification had only "getAudioTracks" and "getVideoTracks"; "getTracks" was added later. Thus, a natural implementation was to return the concatenation of getAudioTracks and getVideoTracks, and since we had explicit language stating that the order of tracks was not guaranteed, this was a safe implementation choice vs the spec at the time. |
Is there any evidence the Firefox and Safari implementations are unsafe? |
and is not dependent on the order of tracks in the MediaStream See w3c/mediacapture-main#1028 Bug: None Change-Id: I77ac10a078632bc9ae944a3254626ff30965c433 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6286091 Commit-Queue: Philipp Hancke <philipp.hancke@googlemail.com> Reviewed-by: Harald Alvestrand <hta@chromium.org> Reviewed-by: Guido Urdaneta <guidou@chromium.org> Cr-Commit-Position: refs/heads/main@{#1424488}
and is not dependent on the order of tracks in the MediaStream See w3c/mediacapture-main#1028 Bug: None Change-Id: I77ac10a078632bc9ae944a3254626ff30965c433 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6286091 Commit-Queue: Philipp Hancke <philipp.hancke@googlemail.com> Reviewed-by: Harald Alvestrand <hta@chromium.org> Reviewed-by: Guido Urdaneta <guidou@chromium.org> Cr-Commit-Position: refs/heads/main@{#1424488}
and is not dependent on the order of tracks in the MediaStream See w3c/mediacapture-main#1028 Bug: None Change-Id: I77ac10a078632bc9ae944a3254626ff30965c433 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6286091 Commit-Queue: Philipp Hancke <philipp.hancke@googlemail.com> Reviewed-by: Harald Alvestrand <hta@chromium.org> Reviewed-by: Guido Urdaneta <guidou@chromium.org> Cr-Commit-Position: refs/heads/main@{#1424488}
That argument ignores the actual evidence that browsers have already changed this behavior (or never matched Chrome’s) with no bug reports. If track ordering were a real point of failure, we’d see it in Safari or Firefox, which have behaved differently for years. Suggesting a new change might produce bug reports assumes a risk we’ve effectively tested in the real world already—and we’ve seen no problems. The status quo proves we can safely change behavior here to align with Web Platform Infra. Why do so? Because future uses of WebRTC might be more plentiful and involve more tracks than today's use. Just because it's no problem today doesn't mean it won't be tomorrow. |
WRT "effectively tested" we had no tests even for basic assertions in WPT (added above), no tests which would have shown Safaris behavior for single-track-of-kind and no tests for multi-track behavior. Your "works in Firefox therefore no risk" theory was very recently proven when libWebRTC changed how it assigned rtx payload types (not intentionally). It turned out that folks relied on "rtx pt == pt + 1" even though that is non-spec and Firefox does not follow that pattern. That was far from "no cost". |
Lack of tests is a red herring. Thanks for contributing them, but tests have nothing to do with the risk of breakage we're discussing. WPT only tests browser conformance to behaviors we specify. A decision here would inform tests, not the other way around. What I said was that track order dependency has been "effectively tested in the real world" by Safari and Firefox behaving differently for years (in the case of Safari having no reliable order from one track to the next). Therefore, we know interoperable websites—by definition—do not rely on track order. Kudos to Safari for proving this point and taking one for the team here!
In case it's unclear to readers, by "folks" we're down to maintainers of non-interoperable chromium-only websites. I would venture these websites represent a much larger "cost" to us than to you. |
Please look at the very beginning of the issue where your testing claimed
The meeting slide states this which is one of the very few points where we agree:
"Needlessly confusing web developers" is not a good thing. websites may The public numbers we have show that addStream are still hovering at ~5% of Chrome getUserMedia calls and pretty stable for the last years:
Same for https://webrtchacks.github.io/chromestatus/?buckets=1656 which shows
Unshipping this is a great way to test your theory! And we can see if this moves the needle in the public Chrome metrics. This demonstrates that the working group has a problem with the way it ignores WPT:
"Maintainers" seems the right word, from what I saw the affected product had reached "end of sale". |
Just for fun, I found the git commit that added getTracks(). commit 1149581
The very first instantiation of this function had the "order is user agent defined and doesn't have to be stable" language. The Chrome implementation (https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/modules/mediastream/media_stream.cc;drc=5b1ceafef667af5fa64c3002e9427ddf01e105a1;l=291) is literally "first take all the audio tracks, and then all the video tracks" - due to a Blink reformat, I can't see its history beyond 2016, but it's been unchanged since that time. "User needs come before the needs of web page authors, which come before the needs of user agent implementors, which come before the needs of specification writers, which come before theoretical purity." For Chrome-as-a-product, changing this behavior risks hurting users (those using software that was working fine on earlier versions, and may no longer be maintained, but suddenly stops working). In addition, changing the spec harms web page authors that actually believe the spec to reflect realilty until the time such a behavior change can be agreed to and experimented with to the degree that one can have evidence of absence of harm rather than absence of evidence of harm. For Chrome, no benefit has been demonstrated. A "theoretical purity" argument carries very little weight. |
This issue had an associated resolution in WebRTC February 2025 meeting – (Issue #1028 Revisit and document getUserMedia() track order):
|
Let's not broaden discussion to include unrelated issues. Evidence of B is not evidence of A.
That's a false choice. The status quo relies on interop-hygiene among web developers, which can be effective AND not great at the same time. It's our job to ensure long-term interop. So it seems a totally reasonable position for me to suggest there's no breakage today given the evidence, AND saying this may not hold in the future as more advanced multi-track uses appear, or say interest in interop among WebRTC-related web developers dips.
The current spec relies on interop hygiene among web developers. We should thank them for staying interoperable so far, and fix the spec to relieve them of carrying this interop burden, which they should never have had (we didn't know better back then). Hopefully, we can all agree that standardizing one behavior would be beneficial, and that we're down to picking what that behavior should be. Any evidence of track order dependency would be helpful to this WG in making the decision of what behavior to pick.
Track order is directly observable, and hence not "theoretical". I think you mean logically consistent observable behavior. |
A few thoughts:
web-platform-tests/interop#855 is a good example of trying to keep the web a sane place. |
… of track events matches the SDP, a=testonly Automatic update from web-platform-tests webrtc wpt: add test asserting the order of track events matches the SDP and is not dependent on the order of tracks in the MediaStream See w3c/mediacapture-main#1028 Bug: None Change-Id: I77ac10a078632bc9ae944a3254626ff30965c433 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6286091 Commit-Queue: Philipp Hancke <philipp.hancke@googlemail.com> Reviewed-by: Harald Alvestrand <hta@chromium.org> Reviewed-by: Guido Urdaneta <guidou@chromium.org> Cr-Commit-Position: refs/heads/main@{#1424488} -- wpt-commits: 436123f65ed0a64afd3aea668b8928126fb422c1 wpt-pr: 50929
… of track events matches the SDP, a=testonly Automatic update from web-platform-tests webrtc wpt: add test asserting the order of track events matches the SDP and is not dependent on the order of tracks in the MediaStream See w3c/mediacapture-main#1028 Bug: None Change-Id: I77ac10a078632bc9ae944a3254626ff30965c433 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6286091 Commit-Queue: Philipp Hancke <philipp.hancke@googlemail.com> Reviewed-by: Harald Alvestrand <hta@chromium.org> Reviewed-by: Guido Urdaneta <guidou@chromium.org> Cr-Commit-Position: refs/heads/main@{#1424488} -- wpt-commits: 436123f65ed0a64afd3aea668b8928126fb422c1 wpt-pr: 50929
… of track events matches the SDP, a=testonly Automatic update from web-platform-tests webrtc wpt: add test asserting the order of track events matches the SDP and is not dependent on the order of tracks in the MediaStream See w3c/mediacapture-main#1028 Bug: None Change-Id: I77ac10a078632bc9ae944a3254626ff30965c433 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6286091 Commit-Queue: Philipp Hancke <philipp.hanckegooglemail.com> Reviewed-by: Harald Alvestrand <htachromium.org> Reviewed-by: Guido Urdaneta <guidouchromium.org> Cr-Commit-Position: refs/heads/main{#1424488} -- wpt-commits: 436123f65ed0a64afd3aea668b8928126fb422c1 wpt-pr: 50929 UltraBlame original commit: a225ba3e9bd15af60aead9ce00df7d7070c240ad
… of track events matches the SDP, a=testonly Automatic update from web-platform-tests webrtc wpt: add test asserting the order of track events matches the SDP and is not dependent on the order of tracks in the MediaStream See w3c/mediacapture-main#1028 Bug: None Change-Id: I77ac10a078632bc9ae944a3254626ff30965c433 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6286091 Commit-Queue: Philipp Hancke <philipp.hanckegooglemail.com> Reviewed-by: Harald Alvestrand <htachromium.org> Reviewed-by: Guido Urdaneta <guidouchromium.org> Cr-Commit-Position: refs/heads/main{#1424488} -- wpt-commits: 436123f65ed0a64afd3aea668b8928126fb422c1 wpt-pr: 50929 UltraBlame original commit: a225ba3e9bd15af60aead9ce00df7d7070c240ad
… of track events matches the SDP, a=testonly Automatic update from web-platform-tests webrtc wpt: add test asserting the order of track events matches the SDP and is not dependent on the order of tracks in the MediaStream See w3c/mediacapture-main#1028 Bug: None Change-Id: I77ac10a078632bc9ae944a3254626ff30965c433 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6286091 Commit-Queue: Philipp Hancke <philipp.hanckegooglemail.com> Reviewed-by: Harald Alvestrand <htachromium.org> Reviewed-by: Guido Urdaneta <guidouchromium.org> Cr-Commit-Position: refs/heads/main{#1424488} -- wpt-commits: 436123f65ed0a64afd3aea668b8928126fb422c1 wpt-pr: 50929 UltraBlame original commit: a225ba3e9bd15af60aead9ce00df7d7070c240ad
… of track events matches the SDP, a=testonly Automatic update from web-platform-tests webrtc wpt: add test asserting the order of track events matches the SDP and is not dependent on the order of tracks in the MediaStream See w3c/mediacapture-main#1028 Bug: None Change-Id: I77ac10a078632bc9ae944a3254626ff30965c433 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6286091 Commit-Queue: Philipp Hancke <philipp.hancke@googlemail.com> Reviewed-by: Harald Alvestrand <hta@chromium.org> Reviewed-by: Guido Urdaneta <guidou@chromium.org> Cr-Commit-Position: refs/heads/main@{#1424488} -- wpt-commits: 436123f65ed0a64afd3aea668b8928126fb422c1 wpt-pr: 50929
The spec says: "The tracks of a MediaStream are stored in a track set. The track set MUST contain the MediaStreamTrack objects that correspond to the tracks of the stream. The relative order of the tracks in the set is User Agent defined and the API will never put any requirements on the order. The proper way to find a specific MediaStreamTrack object in the set is to look it up by its id."
But #1020 is concerned about deterministic event order between track clones, looking at using track creation order.
If we're chasing determinism at this level, might
getUserMedia
need to be clearer about whether it creates its audio or video track first?I suspect audio comes first, given "2. Let requestedMediaTypes be the set of media types in constraints with either a dictionary value or a value of true... 11.3 For each media type kind in requestedMediaTypes ...", and the fact that dictionary members are sorted lexographically.
While use of the word "set" in the sentences above do not link to set, they might be understood to mean the same thing. It reads:

Thankfully, an implementation check reveals the same order in all browsers:
audio, video
. Is it time to document this?The text was updated successfully, but these errors were encountered: