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->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;
}
}

View File

@ -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<std::shared_ptr<QtMultimediaCameraHandler>, 3> handlers;
static std::array<bool, 3> status;

View File

@ -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() {
if (!authorized_camera) {
CheckAuthorization(AuthMediaType::Camera);
return authorized;
authorized_camera = authorized;
}
return authorized_camera;
}
bool CheckAuthorizationForMicrophone() {
if (!authorized_microphone) {
CheckAuthorization(AuthMediaType::Microphone);
return authorized;
authorized_microphone = authorized;
}
return authorized_microphone;
}
} // AppleAuthorization