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

Add permission-related methods to CameraServer #10829

Open
j20001970 opened this issue Sep 26, 2024 · 1 comment · May be fixed by godotengine/godot#97508
Open

Add permission-related methods to CameraServer #10829

j20001970 opened this issue Sep 26, 2024 · 1 comment · May be fixed by godotengine/godot#97508

Comments

@j20001970
Copy link

Describe the project you are working on

GDExtension library that involves accessing camera devices for frames capture.

Describe the problem or limitation you are having in your project

Many platforms (AFAIK: Android, iOS, macOS, Linux with XDG Portal and PipeWire when running in sandbox, Web) require explicit user interaction for camera permission before accessing camera devices for frames capture. While CameraServer is not supported on all platforms, there has been progress on implementing support for Linux.

But with currently available methods provided by CameraServer, there is no way no know if camera permission is granted in advance, and requesting permission is handled in activate_feed, if user refused camera access, there is no way to react to it.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

The following enhancement should be able to solve the limitation stated above:

  • Add a method to CameraServer for querying if camera access is granted, with bool return value indicating it is granted or not, it will always return true if no permission is required.
  • Add a method to CameraServer for requesting camera permission, no-op if no permission is required or it is already granted.
  • Add a signal for indicating request camera permission result or permission change.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

...

func _ready():
    CameraServer.permission_changed.connect(self.on_camera_permission_changed)
    start_camera()

func on_camera_permission_changed(granted: bool):
    if not granted and camera_started:
        # Do something about it
    elif granted and camera_started:
        # Access camera feeds

func start_camera():
    camera_started = true
    if CameraServer.permission_granted():
        # Access camera feeds
    else:
        CameraServer.request_permission()

If this enhancement will not be used often, can it be worked around with a few lines of script?

Permission-related operation usually requires access to platform-specific API.

While OS.request_permission exists, it is currently specific to Android, and IMO leaving camera permission handling to CameraServer feels more consistent.

Is there a reason why this should be core and not an add-on in the asset library?

It is absolutely possible to handle camera permission with GDExtension/GDNative library, but it would feel redundant, and since CameraServer is already there, it wouldn't hurt to add permission-related methods to CameraServer for supported platforms.

@Calinou
Copy link
Member

Calinou commented Sep 26, 2024

On Windows, you can also prevent apps from accessing the camera (or microphone) in the system settings, although no explicit permission is required when access is allowed. We could make the permission grant status return false in this case.

@Calinou Calinou removed the topic:xr label Sep 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants