citra-emu
/
citra-canary
Archived
1
0
Fork 0

Camera fixes (#6181)

This commit is contained in:
Vitor K 2022-12-17 12:05:04 -03:00 committed by GitHub
parent 812c4fa059
commit 517e0bc342
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 5 deletions

View File

@ -199,6 +199,7 @@ void QtMultimediaCameraHandler::StartCamera() {
camera->setViewfinderSettings(settings); camera->setViewfinderSettings(settings);
camera->start(); camera->start();
started = true; started = true;
paused = false;
} }
bool QtMultimediaCameraHandler::CameraAvailable() const { bool QtMultimediaCameraHandler::CameraAvailable() const {
@ -210,13 +211,14 @@ void QtMultimediaCameraHandler::StopCameras() {
for (auto& handler : handlers) { for (auto& handler : handlers) {
if (handler && handler->started) { if (handler && handler->started) {
handler->StopCamera(); handler->StopCamera();
handler->paused = true;
} }
} }
} }
void QtMultimediaCameraHandler::ResumeCameras() { void QtMultimediaCameraHandler::ResumeCameras() {
for (auto& handler : handlers) { for (auto& handler : handlers) {
if (handler && handler->started) { if (handler && handler->paused) {
handler->StartCamera(); handler->StartCamera();
} }
} }
@ -228,6 +230,7 @@ void QtMultimediaCameraHandler::ReleaseHandlers() {
for (std::size_t i = 0; i < handlers.size(); i++) { for (std::size_t i = 0; i < handlers.size(); i++) {
status[i] = false; status[i] = false;
handlers[i]->started = false; handlers[i]->started = false;
handlers[i]->paused = false;
} }
} }

View File

@ -90,6 +90,7 @@ private:
QtCameraSurface camera_surface{}; QtCameraSurface camera_surface{};
QCameraViewfinderSettings settings; QCameraViewfinderSettings settings;
bool started = false; bool started = false;
bool paused = false; // was previously started but was paused, to be resumed
static std::array<std::shared_ptr<QtMultimediaCameraHandler>, 3> handlers; static std::array<std::shared_ptr<QtMultimediaCameraHandler>, 3> handlers;
static std::array<bool, 3> status; static std::array<bool, 3> status;

View File

@ -9,13 +9,19 @@
namespace AppleAuthorization { namespace AppleAuthorization {
static bool authorized_camera = false;
static bool authorized_microphone = false;
static bool authorized = false; static bool authorized = false;
enum class AuthMediaType { Camera, Microphone }; enum class AuthMediaType { Camera, Microphone };
// Based on // Based on
// https://developer.apple.com/documentation/avfoundation/cameras_and_media_capture/requesting_authorization_for_media_capture_on_macos // 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) { void CheckAuthorization(AuthMediaType type) {
authorized = false;
if (@available(macOS 10.14, *)) { if (@available(macOS 10.14, *)) {
NSString* media_type; NSString* media_type;
if (type == AuthMediaType::Camera) { if (type == AuthMediaType::Camera) {
@ -69,13 +75,19 @@ void CheckAuthorization(AuthMediaType type) {
} }
bool CheckAuthorizationForCamera() { bool CheckAuthorizationForCamera() {
CheckAuthorization(AuthMediaType::Camera); if (!authorized_camera) {
return authorized; CheckAuthorization(AuthMediaType::Camera);
authorized_camera = authorized;
}
return authorized_camera;
} }
bool CheckAuthorizationForMicrophone() { bool CheckAuthorizationForMicrophone() {
CheckAuthorization(AuthMediaType::Microphone); if (!authorized_microphone) {
return authorized; CheckAuthorization(AuthMediaType::Microphone);
authorized_microphone = authorized;
}
return authorized_microphone;
} }
} // AppleAuthorization } // AppleAuthorization