Skip to content
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

[PTZ] Should pan, tilt, and zoom double constraints apply to getUserMedia? #224

Closed
beaufortfrancois opened this issue Apr 27, 2020 · 8 comments
Labels
PTZ Pan-Tilt-Zoom

Comments

@beaufortfrancois
Copy link
Contributor

beaufortfrancois commented Apr 27, 2020

When would web developers set pan, tilt, and zoom double values as part of a getUserMedia call?

await navigator.mediaDevices.getUserMedia({
  video: {
    pan: 1,
    tilt: 2,
    zoom: 3,
  }
});

As we're not sure which camera would be plugged in and cameras have different ranges for pan, tilt, and zoom, I'm not sure those values should be "set" or "applied" to the video stream, as they're not meaningful.
In other words, what does even mean providing pan:1 without knowing the min and max values?

In this case, shall we simply set them as boolean constraint for getUserMedia (or have as suggested initially one single panTiltZoom boolean constraint) and keep double constraint for applyConstraints?

One more thing. Could this code be a thing eventually?
Would it be a way to detect a certain type of camera?

await navigator.mediaDevices.getUserMedia({
  video: {
    pan: { min: 0, max: 1 },
    tilt: { min: 0, max: 1 },
    zoom: { min: 0, max: 1 },
  }
});
@beaufortfrancois
Copy link
Contributor Author

@beaufortfrancois beaufortfrancois changed the title [PTZ] Should pan,tilt,zoom double constraints apply to getUserMedia? [PTZ] Should pan, tilt, and zoom double constraints apply to getUserMedia? Apr 27, 2020
@riju riju added the PTZ Pan-Tilt-Zoom label Apr 27, 2020
@eehakkin
Copy link
Contributor

When would web developers set pan, tilt, and zoom double values as part of a getUserMedia call?
[...]
As we're not sure which camera would be plugged in and cameras have different ranges for pan, tilt, and zoom, I'm not sure those values should be "set" or "applied" to the video stream.

Web developers could have a priori knowledge of ranges (for instance if a user wants to resume a previously stopped video stream) in which case the site could issue

await navigator.mediaDevices.getUserMedia({
  video: {
    deviceId: "...",
    pan: 1,
    tilt: 2,
    zoom: 3,
  }
});

Even without a priori knowledge, it might make sense to use {video: {pan: 0, tilt: 0, zoom: 1}}, for instance. If the user does not have a PTZ camera, pan/tilt/zoom constraints make no harm and if the user does have a PTZ camera, the constraints most probably reset the PTZ camera to a sensible state. For pan and tilt, the ranges is probably symmetric so 0 is in the middle. For zoom, the value 1 probably means no digital zoom or is less than or equal to the minimum of an optical zoom range resulting in widest possible optical zoom to be selected by media stream selection algorithms.

Resetting a PTZ camera to a sensible state might be quite important because the image quality of a PTZ camera may degrade drastically if a digital zoom level is high.

@beaufortfrancois
Copy link
Contributor Author

beaufortfrancois commented Apr 27, 2020

Web developers could have a priori knowledge of ranges (for instance if a user wants to resume a previously stopped video stream) in which case the site could issue

await navigator.mediaDevices.getUserMedia({
  video: {
    deviceId: "...",
    pan: 1,
    tilt: 2,
    zoom: 3,
  }
});

The PTZ camera device could have been placed somewhere else or pointed in another direction, so those values are not guaranteed to still be good.
I thought adding the boolean was to not alter PTZ values. If a video stream is stopped, we can safely assume that when a user wants to resume a previously stopped video stream, it will used its previous position, so no need to manually restore those values.

Even without a priori knowledge, it might make sense to use {video: {pan: 0, tilt: 0, zoom: 1}}, for instance. If the user does not have a PTZ camera, pan/tilt/zoom constraints make no harm and if the user does have a PTZ camera, the constraints most probably reset the PTZ camera to a sensible state. For pan and tilt, the ranges is probably symmetric so 0 is in the middle. For zoom, the value 1 probably means no digital zoom or is less than or equal to the minimum of an optical zoom range resulting in widest possible optical zoom to be selected by media stream selection algorithms.

Resetting a PTZ camera to a sensible state might be quite important because the image quality of a PTZ camera may degrade drastically if a digital zoom level is high.

It seems to me that this is simply a shortcut of this code below.

const stream = await navigator.mediaDevices.getUserMedia({
  video: { pan: true, tilt: true, zoom: true, deviceId: '...' }
});
const videoTrack = videoStream.getVideoTracks()[0];
await videoTrack.applyConstraints({
  advanced: [{ pan: 0, tilt: 0, zoom: 1 }],
});

I think providing a "reset" button to users would be a nice way for websites to reset the camera to a sensible state if that's their wish instead of assuming that this is the case.

Note that on Android, the zoom property resets to "1" each time the camera is "opened"

One thing I've learnt while reading about PTZ is that we can't make guesses about the values of pan and tilt and their meanings. They are even sometimes off.

@reillyeon
Copy link
Member

Calling getUserMedia({ pan: true, tilt: true, zoom: true }) and then adjusting based on the reported capabilities seems like the most sensible site behavior but I don't see an issue with sites using double constraints immediately. Is this consistent with other parameters to getUserMedia()?

@beaufortfrancois
Copy link
Contributor Author

beaufortfrancois commented Apr 27, 2020

I believe it is how it works with other parameters of getUserMedia but like I said, it seems odd to allow this kind of initial behaviour for pan, tilt, and zoom.

@reillyeon
Copy link
Member

I don't see any security or privacy concerns with allowing it even though it doesn't seem that useful.

@beaufortfrancois
Copy link
Contributor Author

I guess it will be a matter of documenting best practices then. I'll close this non-issue now.
Thanks everyone for your feedback.

@fippo
Copy link

fippo commented Apr 29, 2020

If a video stream is stopped, we can safely assume that when a user wants to resume a previously stopped video stream, it will used its previous position, so no need to manually restore those values.

Unless and until Chrome turns off the camera light when track.enabled is set to false, GUM will be frequently called in the same session to emulate Firefox' behaviour (see w3c/mediacapture-main#642)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PTZ Pan-Tilt-Zoom
Projects
None yet
Development

No branches or pull requests

5 participants