Camera fixes (#6181)
This commit is contained in:
parent
812c4fa059
commit
517e0bc342
3 changed files with 21 additions and 5 deletions
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue