-
Notifications
You must be signed in to change notification settings - Fork 22.8k
Editorial review: Add docs for MediaTrackSettings.screenPixelRatio #39980
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
Editorial review: Add docs for MediaTrackSettings.screenPixelRatio #39980
Conversation
Preview URLs
Flaws (2)Note! 2 documents with no flaws that don't need to be listed. 🎉 URL:
(comment last updated: 2025-07-04 08:58:42) |
lgtm % link to the spec |
I added spec/browser compat data for this feature in mdn/browser-compat-data#27092, so that data should appear as soon as we resolve what to do with the issue highlighted in the description. I think in the meantime this PR can be put forward to the editorial review stage. Thanks for the tech review, @guidou! |
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 found this page quite hard to understand.
There's a very technical description of the property, repeated word for word, twice:
a double-precision floating point value indicating the ratio of the size of a CSS pixel on the capturing screen by the vertical size of a pixel on the captured display surface
The "value" has an additional sentence which is a direct quote from the spec.
The description seems to be taken from the chromestatus entry, and I kind of understand it, on its own, but there's nothing there that connects the general explanation with how exactly I could use this property to meet the use case described.
It also has hedging terms like "The logical resolution is normally lower than the physical resolution". What is "normally" doing here? When is it, when isn't it? And how is this reflected by the screenPixelRatio property? That is, how can examining the value of screenPixelRatio tell me whether it is or not? The definition of this property doesn't mention physical resolution at all.
My understanding of this property is something like:
If a user has the display zoomed in, then the physical resolution is greater than the logical resolution. In a case like this, it's a more efficient use of bandwidth for the sender to capture the video at the logical resolution and send the video at that resolution, and for the recipient to then reapply the zoom when they receive the video stream.
The
screenPixelRatio
property describes the ratio of the physical size of a pixel to its logical size, and therefore enables the application to work out how much of a zoom has been applied, and then constrain the video to the logical size.
Is that about right? If so I think it's important to say this. It's important to connect the technical definition of the property with the use case given in the description.
@wbamberg thanks for your thoughtful comment here. I agree that the wording is a bit complicated. I've pushed another commit that simplifies and de-duplicates, and also takes your wording into account. |
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
…sdavidmills/content into mediatracksettings-screenpixelratio
|
||
{{APIRef("Media Capture and Streams")}} | ||
|
||
The {{domxref("MediaTrackSettings")}} dictionary's **`screenPixelRatio`** property is a number representing the ratio of the size of a CSS pixel on the capturing screen by the vertical size of a pixel on the captured display surface. It cannot be used as a constraint or capability. |
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.
This first sentence is quite complex, but AIUI "by" is the word used to connect the two values being compared in the ratio, right? Why "by"? Usually I'd expect the connector in a ratio to be "to". And AIUI the value is positive if the physical size is greater than the logical size, so wouldn't that make it "the ratio of [physical size] to [logical size]", i.e. the physical would come first?
See e.g. https://en.wikipedia.org/wiki/Ratio:
if there are eight oranges and six lemons in a bowl of fruit, then the ratio of oranges to lemons is eight to six (that is, 8:6, which is equivalent to the ratio 4:3). Similarly, the ratio of lemons to oranges is 6:8 (or 3:4) and the ratio of oranges to the total amount of fruit is 8:14 (or 4:7).
I also think it would be helpful to clarify the connection between "CSS pixel" and "logical size", and "vertical size of a pixel" and "physical size". This intro and the value talks only about the first set of terms, and the description talks only about the second set. I assume they are the same(?) but as a reader I should not have to make that assumption.
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.
Is the underlying issue here only about zoom levels? If so, it would be nice if this concept were introduced here, and the connection made between zoom levels and different values for this property.
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.
Right, OK, you've made some good points here. I've adjusted the wording as suggested, and made the terminology more consistent.
I've also tested it slightly more thoroughly, adjusted the description of why the difference in ratio occurs, and added some example value explanations.
|
||
A video-conferencing app can save bandwidth and CPU when the captured screen is zoomed in on the sender side by: |
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.
A video-conferencing app can save bandwidth and CPU when the captured screen is zoomed in on the sender side by: | |
If the screen in the sender is zoomed in, then the physical resolution is greater than the logical resolution, and a video-conferencing app can therefore save bandwidth and CPU by: |
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.
used, but tweaked a little bit.
|
||
1. Removing the zoom applied to the captured display surface by the OS. | ||
2. Sending the video of the screen capture at the logical resolution. | ||
3. Reapplying the zoom after receiving it on the remote client to size it back up to its physical resolution. |
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.
Sorry if this is a stupid q, but how does the receiver side know whether/how much to reapply the zoom?
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.
You'd send the screenPixelRatio
value over with the captured stream, and then zoom the video by that amount on the receiving end.
|
||
### Basic `screenPixelRatio` usage | ||
|
||
The following snippet shows how an application may use `screenPixelRatio` to constrain a {{domxref("MediaStreamTrack")}}'s' [`width`](/en-US/docs/Web/API/MediaTrackConstraints/width) and [`height`](/en-US/docs/Web/API/MediaTrackConstraints/height) to the logical resolution when scaling exceeds an acceptable threshold (specified by an application-defined constant). |
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.
This could also use some more explanation IMO.
We could say something like:
In this example, the application defines a constant
RESOLUTION_LIMIT
, which represents the scaling factor beyond which which the sending application should send video at the logical resolution rather than the physical resolution.When
screenPixelRatio
exceeds this limit, the application uses thescreenPixelRatio
value to calculate the logical resolution from the physical resolution, and then constrains video capture to the logical resolution.
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.
Sure, added, but tweaked.
const settings = track.getSettings(); | ||
const capabilities = track.getCapabilities(); | ||
|
||
if (track.screenPixelRatio > RESOLUTION_LIMIT) { |
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.
if (track.screenPixelRatio > RESOLUTION_LIMIT) { | |
if (settings.screenPixelRatio > RESOLUTION_LIMIT) { |
I think?
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.
Yup, good spot. Updated.
let physicalWidth = capabilities.width.max; | ||
let physicalHeight = capabilities.height.max; | ||
let logicalWidth = physicalWidth / settings.screenPixelRatio; | ||
let logicalHeight = physicalHeight / settings.screenPixelRatio; |
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 all be const
.
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.
Good call; updated
files/en-us/web/api/mediatracksettings/screenpixelratio/index.md
Outdated
Show resolved
Hide resolved
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.
Thanks for your work on this Chris, I'm approving.
But, what do you want to do about BCD? At the moment the spec and BCD sections look pretty sad.
I read mdn/browser-compat-data#27092 and mdn/browser-compat-data#27119.
It is tricky because yes, BCD doesn't represent dictionaries, and this makes sense really because there's no compat story about "just data" - data doesn't do anything, and when nothing is done, there's no compat story.
What I would do here is:
- not include BCD for this page
- add a subfeature to
getSettings
that captures the fact that the returned object includesscreenPixelRatio
, and tie the BCD to that. I don't know if there's a convention for adding subfeatures like "the returned object has propertyfoo
set".
Thanks a lot @wbamberg, these are good suggestions
I've removed the BCD section for now, and added a direct
I'll investigate doing this as my next port of call, and see what the BCD folk say about it. |
Description
Chrome 136+ supports the
MediaTrackSettings.screenPixelRatio
property, on desktop only. See https://chromestatus.com/feature/6738236535472128 for details.This PR adds a ref page for the new property.
Motivation
Additional details
Related issues and pull requests