From 517e0bc342382a393d159c620a7bb0d57692ecd9 Mon Sep 17 00:00:00 2001 From: Vitor K Date: Sat, 17 Dec 2022 12:05:04 -0300 Subject: [PATCH] Camera fixes (#6181) --- src/citra_qt/camera/qt_multimedia_camera.cpp | 5 ++++- src/citra_qt/camera/qt_multimedia_camera.h | 1 + src/citra_qt/macos_authorization.mm | 20 ++++++++++++++++---- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/citra_qt/camera/qt_multimedia_camera.cpp b/src/citra_qt/camera/qt_multimedia_camera.cpp index 5b7d497a2..0681814b7 100644 --- a/src/citra_qt/camera/qt_multimedia_camera.cpp +++ b/src/citra_qt/camera/qt_multimedia_camera.cpp @@ -199,6 +199,7 @@ void QtMultimediaCameraHandler::StartCamera() { camera->setViewfinderSettings(settings); camera->start(); started = true; + paused = false; } bool QtMultimediaCameraHandler::CameraAvailable() const { @@ -210,13 +211,14 @@ void QtMultimediaCameraHandler::StopCameras() { for (auto& handler : handlers) { if (handler && handler->started) { handler->StopCamera(); + handler->paused = true; } } } void QtMultimediaCameraHandler::ResumeCameras() { for (auto& handler : handlers) { - if (handler && handler->started) { + if (handler && handler->paused) { handler->StartCamera(); } } @@ -228,6 +230,7 @@ void QtMultimediaCameraHandler::ReleaseHandlers() { for (std::size_t i = 0; i < handlers.size(); i++) { status[i] = false; handlers[i]->started = false; + handlers[i]->paused = false; } } diff --git a/src/citra_qt/camera/qt_multimedia_camera.h b/src/citra_qt/camera/qt_multimedia_camera.h index 14242c554..099000927 100644 --- a/src/citra_qt/camera/qt_multimedia_camera.h +++ b/src/citra_qt/camera/qt_multimedia_camera.h @@ -90,6 +90,7 @@ private: QtCameraSurface camera_surface{}; QCameraViewfinderSettings settings; bool started = false; + bool paused = false; // was previously started but was paused, to be resumed static std::array, 3> handlers; static std::array status; diff --git a/src/citra_qt/macos_authorization.mm b/src/citra_qt/macos_authorization.mm index 165c35107..465b13085 100644 --- a/src/citra_qt/macos_authorization.mm +++ b/src/citra_qt/macos_authorization.mm @@ -9,13 +9,19 @@ namespace AppleAuthorization { +static bool authorized_camera = false; +static bool authorized_microphone = false; + static bool authorized = false; enum class AuthMediaType { Camera, Microphone }; // Based on // https://developer.apple.com/documentation/avfoundation/cameras_and_media_capture/requesting_authorization_for_media_capture_on_macos +// TODO: This could be rewritten to return the authorization state, having pure c++ code deal with +// it, log information and possibly wait for the camera access request. void CheckAuthorization(AuthMediaType type) { + authorized = false; if (@available(macOS 10.14, *)) { NSString* media_type; if (type == AuthMediaType::Camera) { @@ -69,13 +75,19 @@ void CheckAuthorization(AuthMediaType type) { } bool CheckAuthorizationForCamera() { - CheckAuthorization(AuthMediaType::Camera); - return authorized; + if (!authorized_camera) { + CheckAuthorization(AuthMediaType::Camera); + authorized_camera = authorized; + } + return authorized_camera; } bool CheckAuthorizationForMicrophone() { - CheckAuthorization(AuthMediaType::Microphone); - return authorized; + if (!authorized_microphone) { + CheckAuthorization(AuthMediaType::Microphone); + authorized_microphone = authorized; + } + return authorized_microphone; } } // AppleAuthorization