-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Allowing UA to do <source> selection for media element #10077
Comments
@whatwg/media thoughts? |
I think this would require a fundamental change to how the algorithm works. Currently, the algorithm can pick a For the script-created elements case, we can probably do what If the algorithm fails to select something because all This change would probably make the spec simpler. While arbitrary order makes sense for Example: <video>
<source src="a" type="video/mp4" media="(min-width: 600px)">
<source src="b" type="video/mp4">
<source src="c" type="video/webm" media="(min-width: 600px)">
<source src="d" type="video/webm">
</video> Maybe selection could be in two passes: first, select a list of candidates that has the first (in tree order) |
Yeah, I was also thinking this would need to be done in two passes after parsing. And yeah, I was also thinking it would simplify the spec quite a lot, but I was unsure also how much breakage there would be given how much stuff seems to happen right now in the algorithm. |
It seems like the intent of this feature is to allow the browser to make the best choice for users. In a case like <video>
<source ...>
<source ...>
[... the server hangs for 5 seconds ...]
<source ...>
</video> it seems like the best choice is for the browser to give up sometime early during that 5 second window, and choose from the first 2 sources. It would be bad to mandate in the spec that the browser has to wait until it sees the end tag. Does that fit with what you all are thinking? How does it play into the discussions above about multiple passes after parsing? |
I don't believe the proposal prevents this behaviour. If two sources are available and the second is preferable over the first, then the UA play the 2nd. I would limit to the two passes parsing to only the sources that are immediately available. The 2nd parse cycle being only required if during the first parse; one of the source was playable, but the system would have liked to see if a preferred one was there (like if the available source only allowed for software decoding). |
As long as this proposal doesn't involve waiting for the end |
Waiting for the end tag is what I had in mind, to make processing predictable and not depend on network latency. I'm not convinced it's best to allow processing of partial data here. I think speculatively fetching a video is OK, but AFAIK browsers don't do that today. If the server stalls while parsing the But maybe there's some heuristic we can apply to load (and play) sooner without introducing network latency impact on resource selection. For example, when seeing fallback content (non-whitespace text or elements other than |
How are you proposing to decide a better source? Do you just want to always select the mp4? I'm not sure how you'd make a better decision beyond some simple cases (that seem uncommon nowadays) w/o parsing and loading each source -- which could slow down loading significantly. It's not common to list |
Not at all; we would want to select the "best" source, which could (and has) meant the one with a HW decoder available. For context, we have previously de-prioritized HEVC on platforms containing only a SW HEVC codec, and way, way, way back in the day, de-prioritized Ogg on systems that had Perian installed as a QuickTime extension. And of course, this behavior will work better when there is more information provided in |
Can you clarify "works" in the case of |
Adding a |
There might be some privacy issues here. The site could learn more about what sort of hardware the user has. |
MediaCapabilities already expose in much more details the information. Whichever remedial work done for MC is applicable here too (as is, disabling under some circumstances the selection algorithm) |
Interesting, since the privacy and security issues are similar (not the same though) as with delayed clipboard rendering. And that one is being objected strongly because of the privacy issues |
One exposes specific user behaviour , the other could expose hardware capabilities (information already available). And for the latter we have existing policy to limit exposure covering it |
A possible web compat issue is with https://html.spec.whatwg.org/multipage/embedded-content.html#the-source-element:event-error If a browser then picks that A possible mitigation could be to defer firing |
Per https://webkit.org/blog/15063/webkit-features-in-safari-17-4/#source-prioritization it seems this change was shipped in Safari 17.4. Correct? If so, can you clarify what was implemented? |
A (too late?) note that from an author education/understanding standpoint, the model for years has been:
I agree that for the type-switching use case, UAs will generally make better decisions than authors. The question is less "what does this particular content and page context need" (author best-suited), and more "what does this particular user and UA context need" (UA best-suited). Rather than changing |
This is the webkit change that implemented the policy on iOS devices only It does as described as an earlier proposal; if at the time of the check we have an alternative source following the one currently being checked, and if the currently checked source is using VP8 (SW only) or doesn't have hardware decoded VP9; then this source will be skipped. If there's no source to try after, then it will be used. full WebM support was only added in Safari on iOS 17.4, one of the reason for this decision was to reduce the potential for unexpected regressions. |
(I did some digging and I think that WebKit has had the "wait for end tag" behavior for about 12 years, although seemingly it's only used for |
Waiting for the end tag for |
The code in WebKit to try
If WebKit doesn't wait for the |
Note that a server hang already prevents:
The effect of not waiting for the end tag is that users will sometimes get a suboptimal format selected, for the same HTML. As I said above, I think processing should be predictable and not depend on network latency. |
Yeah, that seems correct. If network conditions are bad the end user won't see media so in practice it prolly doesn't matter, but it seems reasonable to make this more solid, especially as we already have this logic for |
What is the issue with the HTML Standard?
The “resource selection algorithm” for a media element (as part of the “Otherwise (mode is children)” case) states that when a developer has listed various different formats, the browser is supposed to use the first media type that's recognized (after matching on
media=
).Tree-order based selection is problematic because developers lack sufficient information about the end user’s device/environment to make an adequate determination as to which
<source>
is most optimal, potentially leading to the wrong<source>
order appearing in a document (or the user agent being put into a situation where it has to choose a sub-optimal<source>
).Unlike developers, user agent have a greater understanding of the user’s device and environment, so are in a privileged position to choose the most optimal
<source>
that will give the best user's experience. There could be a lot of conditions where its better for the user agent to intelligently choose between formats, for example picking hardware decoding support over those that are software-only, picking one that preserves battery, or one that's higher quality / a better codec, etc.Ultimately developers shouldn’t concern themselves as to which format will be best for a given set of environmental conditions (as currently implied by the order, which could lead to a sub-optimal choice!). Instead, they can put the responsibility on the use agent to make the best choice for users.
Admittedly, we could use a little help updating that part of the spec. The current algorithm seems a little finicky with all the pointers and async waits/loops, so we could really use some help or guidance with updating it to say that after matching on
media=
and checking all thetype=
’s it supports, the user agent may choose the most suitable<source>
element based on the user’s environment, device capabilities, or optimal hardware support.NB: we are aware that the above could also apply equally to
<picture>
, but we should probably do that independently once we sort out media elements.Cc @jyavenard
The text was updated successfully, but these errors were encountered: