Merge pull request #5786 from vitor-k/macos-perms
Request Camera Permission on MacOS
This commit is contained in:
commit
e3804a4c06
9 changed files with 220 additions and 5 deletions
|
@ -248,7 +248,8 @@ endif()
|
||||||
if (APPLE)
|
if (APPLE)
|
||||||
# Umbrella framework for everything GUI-related
|
# Umbrella framework for everything GUI-related
|
||||||
find_library(COCOA_LIBRARY Cocoa)
|
find_library(COCOA_LIBRARY Cocoa)
|
||||||
set(PLATFORM_LIBRARIES ${COCOA_LIBRARY} ${IOKIT_LIBRARY} ${COREVIDEO_LIBRARY})
|
find_library(AVFOUNDATION_LIBRARY AVFoundation)
|
||||||
|
set(PLATFORM_LIBRARIES ${COCOA_LIBRARY} ${AVFOUNDATION_LIBRARY} ${IOKIT_LIBRARY} ${COREVIDEO_LIBRARY})
|
||||||
elseif (WIN32)
|
elseif (WIN32)
|
||||||
# WSAPoll and SHGetKnownFolderPath (AppData/Roaming) didn't exist before WinNT 6.x (Vista)
|
# WSAPoll and SHGetKnownFolderPath (AppData/Roaming) didn't exist before WinNT 6.x (Vista)
|
||||||
add_definitions(-D_WIN32_WINNT=0x0600 -DWINVER=0x0600)
|
add_definitions(-D_WIN32_WINNT=0x0600 -DWINVER=0x0600)
|
||||||
|
@ -294,15 +295,15 @@ if (CLANG_FORMAT)
|
||||||
set(CCOMMENT "Running clang format against all the .h and .cpp files in src/")
|
set(CCOMMENT "Running clang format against all the .h and .cpp files in src/")
|
||||||
if (WIN32)
|
if (WIN32)
|
||||||
add_custom_target(clang-format
|
add_custom_target(clang-format
|
||||||
COMMAND powershell.exe -Command "Get-ChildItem '${SRCS}/*' -Include *.cpp,*.h -Recurse | Foreach {&'${CLANG_FORMAT}' -i $_.fullname}"
|
COMMAND powershell.exe -Command "Get-ChildItem '${SRCS}/*' -Include *.cpp,*.h,*.mm -Recurse | Foreach {&'${CLANG_FORMAT}' -i $_.fullname}"
|
||||||
COMMENT ${CCOMMENT})
|
COMMENT ${CCOMMENT})
|
||||||
elseif(MINGW)
|
elseif(MINGW)
|
||||||
add_custom_target(clang-format
|
add_custom_target(clang-format
|
||||||
COMMAND find `cygpath -u ${SRCS}` -iname *.h -o -iname *.cpp | xargs `cygpath -u ${CLANG_FORMAT}` -i
|
COMMAND find `cygpath -u ${SRCS}` -iname *.h -o -iname *.cpp -o -iname *.mm | xargs `cygpath -u ${CLANG_FORMAT}` -i
|
||||||
COMMENT ${CCOMMENT})
|
COMMENT ${CCOMMENT})
|
||||||
else()
|
else()
|
||||||
add_custom_target(clang-format
|
add_custom_target(clang-format
|
||||||
COMMAND find ${SRCS} -iname *.h -o -iname *.cpp | xargs ${CLANG_FORMAT} -i
|
COMMAND find ${SRCS} -iname *.h -o -iname *.cpp -o -iname *.mm | xargs ${CLANG_FORMAT} -i
|
||||||
COMMENT ${CCOMMENT})
|
COMMENT ${CCOMMENT})
|
||||||
endif()
|
endif()
|
||||||
unset(SRCS)
|
unset(SRCS)
|
||||||
|
|
|
@ -169,4 +169,88 @@ SpacesInParentheses: false
|
||||||
SpacesInSquareBrackets: false
|
SpacesInSquareBrackets: false
|
||||||
TabWidth: 4
|
TabWidth: 4
|
||||||
UseTab: Never
|
UseTab: Never
|
||||||
|
---
|
||||||
|
Language: ObjC
|
||||||
|
# BasedOnStyle: LLVM
|
||||||
|
AccessModifierOffset: -4
|
||||||
|
AlignAfterOpenBracket: Align
|
||||||
|
AlignConsecutiveAssignments: false
|
||||||
|
AlignConsecutiveDeclarations: false
|
||||||
|
AlignEscapedNewlinesLeft: false
|
||||||
|
AlignOperands: true
|
||||||
|
AlignTrailingComments: true
|
||||||
|
AllowAllParametersOfDeclarationOnNextLine: true
|
||||||
|
AllowShortBlocksOnASingleLine: false
|
||||||
|
AllowShortCaseLabelsOnASingleLine: false
|
||||||
|
AllowShortFunctionsOnASingleLine: Empty
|
||||||
|
AllowShortIfStatementsOnASingleLine: false
|
||||||
|
AllowShortLoopsOnASingleLine: false
|
||||||
|
AlwaysBreakAfterDefinitionReturnType: None
|
||||||
|
AlwaysBreakAfterReturnType: None
|
||||||
|
AlwaysBreakBeforeMultilineStrings: false
|
||||||
|
AlwaysBreakTemplateDeclarations: true
|
||||||
|
BinPackArguments: true
|
||||||
|
BinPackParameters: true
|
||||||
|
BraceWrapping:
|
||||||
|
AfterClass: false
|
||||||
|
AfterControlStatement: false
|
||||||
|
AfterEnum: false
|
||||||
|
AfterFunction: false
|
||||||
|
AfterNamespace: false
|
||||||
|
AfterObjCDeclaration: false
|
||||||
|
AfterStruct: false
|
||||||
|
AfterUnion: false
|
||||||
|
BeforeCatch: false
|
||||||
|
BeforeElse: false
|
||||||
|
IndentBraces: false
|
||||||
|
BreakBeforeBinaryOperators: None
|
||||||
|
BreakBeforeBraces: Attach
|
||||||
|
BreakBeforeTernaryOperators: true
|
||||||
|
BreakConstructorInitializersBeforeComma: false
|
||||||
|
ColumnLimit: 100
|
||||||
|
ConstructorInitializerAllOnOneLineOrOnePerLine: false
|
||||||
|
ConstructorInitializerIndentWidth: 4
|
||||||
|
ContinuationIndentWidth: 4
|
||||||
|
Cpp11BracedListStyle: true
|
||||||
|
DerivePointerAlignment: false
|
||||||
|
DisableFormat: false
|
||||||
|
IncludeCategories:
|
||||||
|
- Regex: '^\<[^Q][^/.>]*\>'
|
||||||
|
Priority: -2
|
||||||
|
- Regex: '^\<'
|
||||||
|
Priority: -1
|
||||||
|
- Regex: '^\"'
|
||||||
|
Priority: 0
|
||||||
|
IndentCaseLabels: false
|
||||||
|
IndentWidth: 4
|
||||||
|
IndentWrappedFunctionNames: false
|
||||||
|
KeepEmptyLinesAtTheStartOfBlocks: true
|
||||||
|
MacroBlockBegin: ''
|
||||||
|
MacroBlockEnd: ''
|
||||||
|
MaxEmptyLinesToKeep: 1
|
||||||
|
NamespaceIndentation: None
|
||||||
|
ObjCBlockIndentWidth: 2
|
||||||
|
ObjCSpaceAfterProperty: false
|
||||||
|
ObjCSpaceBeforeProtocolList: true
|
||||||
|
PenaltyBreakBeforeFirstCallParameter: 19
|
||||||
|
PenaltyBreakComment: 300
|
||||||
|
PenaltyBreakFirstLessLess: 120
|
||||||
|
PenaltyBreakString: 1000
|
||||||
|
PenaltyExcessCharacter: 1000000
|
||||||
|
PenaltyReturnTypeOnItsOwnLine: 150
|
||||||
|
PointerAlignment: Left
|
||||||
|
ReflowComments: true
|
||||||
|
SortIncludes: true
|
||||||
|
SpaceAfterCStyleCast: false
|
||||||
|
SpaceBeforeAssignmentOperators: true
|
||||||
|
SpaceBeforeParens: ControlStatements
|
||||||
|
SpaceInEmptyParentheses: false
|
||||||
|
SpacesBeforeTrailingComments: 1
|
||||||
|
SpacesInAngles: false
|
||||||
|
SpacesInContainerLiterals: true
|
||||||
|
SpacesInCStyleCastParentheses: false
|
||||||
|
SpacesInParentheses: false
|
||||||
|
SpacesInSquareBrackets: false
|
||||||
|
TabWidth: 4
|
||||||
|
UseTab: Never
|
||||||
...
|
...
|
||||||
|
|
|
@ -236,6 +236,10 @@ if (APPLE)
|
||||||
target_sources(citra-qt PRIVATE ${MACOSX_ICON})
|
target_sources(citra-qt PRIVATE ${MACOSX_ICON})
|
||||||
set_target_properties(citra-qt PROPERTIES MACOSX_BUNDLE TRUE)
|
set_target_properties(citra-qt PROPERTIES MACOSX_BUNDLE TRUE)
|
||||||
set_target_properties(citra-qt PROPERTIES MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_SOURCE_DIR}/Info.plist)
|
set_target_properties(citra-qt PROPERTIES MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_SOURCE_DIR}/Info.plist)
|
||||||
|
target_sources(citra-qt PRIVATE
|
||||||
|
macos_authorization.h
|
||||||
|
macos_authorization.mm
|
||||||
|
)
|
||||||
elseif(WIN32)
|
elseif(WIN32)
|
||||||
# compile as a win32 gui application instead of a console application
|
# compile as a win32 gui application instead of a console application
|
||||||
target_link_libraries(citra-qt PRIVATE Qt5::WinMain)
|
target_link_libraries(citra-qt PRIVATE Qt5::WinMain)
|
||||||
|
|
|
@ -36,5 +36,9 @@
|
||||||
<string>NSApplication</string>
|
<string>NSApplication</string>
|
||||||
<key>NSHighResolutionCapable</key>
|
<key>NSHighResolutionCapable</key>
|
||||||
<string>True</string>
|
<string>True</string>
|
||||||
|
<key>NSCameraUsageDescription</key>
|
||||||
|
<string>This app requires camera access to emulate the 3DS's cameras.</string>
|
||||||
|
<key>NSMicrophoneUsageDescription</key>
|
||||||
|
<string>This app requires microphone access to emulate the 3DS's microphone.</string>
|
||||||
</dict>
|
</dict>
|
||||||
</plist>
|
</plist>
|
||||||
|
|
|
@ -10,6 +10,10 @@
|
||||||
#include "citra_qt/camera/qt_multimedia_camera.h"
|
#include "citra_qt/camera/qt_multimedia_camera.h"
|
||||||
#include "citra_qt/main.h"
|
#include "citra_qt/main.h"
|
||||||
|
|
||||||
|
#if defined(__APPLE__)
|
||||||
|
#include "citra_qt/macos_authorization.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace Camera {
|
namespace Camera {
|
||||||
|
|
||||||
QList<QVideoFrame::PixelFormat> QtCameraSurface::supportedPixelFormats([
|
QList<QVideoFrame::PixelFormat> QtCameraSurface::supportedPixelFormats([
|
||||||
|
@ -187,6 +191,12 @@ void QtMultimediaCameraHandler::StopCamera() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtMultimediaCameraHandler::StartCamera() {
|
void QtMultimediaCameraHandler::StartCamera() {
|
||||||
|
#if defined(__APPLE__)
|
||||||
|
if (!AppleAuthorization::CheckAuthorizationForCamera()) {
|
||||||
|
LOG_ERROR(Service_CAM, "Unable to start camera due to lack of authorization");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
camera->setViewfinderSettings(settings);
|
camera->setViewfinderSettings(settings);
|
||||||
camera->start();
|
camera->start();
|
||||||
started = true;
|
started = true;
|
||||||
|
|
|
@ -15,6 +15,10 @@
|
||||||
#include "core/settings.h"
|
#include "core/settings.h"
|
||||||
#include "ui_configure_audio.h"
|
#include "ui_configure_audio.h"
|
||||||
|
|
||||||
|
#if defined(__APPLE__)
|
||||||
|
#include "citra_qt/macos_authorization.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
constexpr int DEFAULT_INPUT_DEVICE_INDEX = 0;
|
constexpr int DEFAULT_INPUT_DEVICE_INDEX = 0;
|
||||||
|
|
||||||
ConfigureAudio::ConfigureAudio(QWidget* parent)
|
ConfigureAudio::ConfigureAudio(QWidget* parent)
|
||||||
|
@ -148,6 +152,11 @@ void ConfigureAudio::UpdateAudioOutputDevices(int sink_index) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigureAudio::UpdateAudioInputDevices(int index) {
|
void ConfigureAudio::UpdateAudioInputDevices(int index) {
|
||||||
|
#if defined(__APPLE__)
|
||||||
|
if (index == 1) {
|
||||||
|
AppleAuthorization::CheckAuthorizationForMicrophone();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
if (Settings::values.mic_input_device != Frontend::Mic::default_device_name) {
|
if (Settings::values.mic_input_device != Frontend::Mic::default_device_name) {
|
||||||
ui->input_device_combo_box->setCurrentText(
|
ui->input_device_combo_box->setCurrentText(
|
||||||
QString::fromStdString(Settings::values.mic_input_device));
|
QString::fromStdString(Settings::values.mic_input_device));
|
||||||
|
|
|
@ -17,6 +17,10 @@
|
||||||
#include "core/settings.h"
|
#include "core/settings.h"
|
||||||
#include "ui_configure_camera.h"
|
#include "ui_configure_camera.h"
|
||||||
|
|
||||||
|
#if defined(__APPLE__)
|
||||||
|
#include "citra_qt/macos_authorization.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
const std::array<std::string, 3> ConfigureCamera::Implementations = {
|
const std::array<std::string, 3> ConfigureCamera::Implementations = {
|
||||||
"blank", /* Blank */
|
"blank", /* Blank */
|
||||||
"image", /* Image */
|
"image", /* Image */
|
||||||
|
@ -46,9 +50,15 @@ ConfigureCamera::~ConfigureCamera() {
|
||||||
|
|
||||||
void ConfigureCamera::ConnectEvents() {
|
void ConfigureCamera::ConnectEvents() {
|
||||||
connect(ui->image_source,
|
connect(ui->image_source,
|
||||||
static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, [this] {
|
static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
|
||||||
|
[this](int index) {
|
||||||
StopPreviewing();
|
StopPreviewing();
|
||||||
UpdateImageSourceUI();
|
UpdateImageSourceUI();
|
||||||
|
#if defined(__APPLE__)
|
||||||
|
if (index == 2) {
|
||||||
|
AppleAuthorization::CheckAuthorizationForCamera();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
});
|
});
|
||||||
connect(ui->camera_selection,
|
connect(ui->camera_selection,
|
||||||
static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, [this] {
|
static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, [this] {
|
||||||
|
|
12
src/citra_qt/macos_authorization.h
Normal file
12
src/citra_qt/macos_authorization.h
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
// Copyright 2020 Citra Emulator Project
|
||||||
|
// Licensed under GPLv2 or any later version
|
||||||
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace AppleAuthorization {
|
||||||
|
|
||||||
|
bool CheckAuthorizationForCamera();
|
||||||
|
bool CheckAuthorizationForMicrophone();
|
||||||
|
|
||||||
|
} // namespace AppleAuthorization
|
81
src/citra_qt/macos_authorization.mm
Normal file
81
src/citra_qt/macos_authorization.mm
Normal file
|
@ -0,0 +1,81 @@
|
||||||
|
// Copyright 2020 Citra Emulator Project
|
||||||
|
// Licensed under GPLv2 or any later version
|
||||||
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
|
#import <AVFoundation/AVFoundation.h>
|
||||||
|
|
||||||
|
#include "citra_qt/macos_authorization.h"
|
||||||
|
#include "common/logging/log.h"
|
||||||
|
|
||||||
|
namespace AppleAuthorization {
|
||||||
|
|
||||||
|
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
|
||||||
|
void CheckAuthorization(AuthMediaType type) {
|
||||||
|
if (@available(macOS 10.14, *)) {
|
||||||
|
NSString* media_type;
|
||||||
|
if (type == AuthMediaType::Camera) {
|
||||||
|
media_type = AVMediaTypeVideo;
|
||||||
|
} else {
|
||||||
|
media_type = AVMediaTypeAudio;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Request permission to access the camera and microphone.
|
||||||
|
switch ([AVCaptureDevice authorizationStatusForMediaType:media_type]) {
|
||||||
|
case AVAuthorizationStatusAuthorized:
|
||||||
|
// The user has previously granted access to the camera.
|
||||||
|
authorized = true;
|
||||||
|
break;
|
||||||
|
case AVAuthorizationStatusNotDetermined: {
|
||||||
|
// The app hasn't yet asked the user for camera access.
|
||||||
|
[AVCaptureDevice requestAccessForMediaType:media_type
|
||||||
|
completionHandler:^(BOOL granted) {
|
||||||
|
authorized = granted;
|
||||||
|
}];
|
||||||
|
if (type == AuthMediaType::Camera) {
|
||||||
|
LOG_INFO(Frontend, "Camera access requested.");
|
||||||
|
} else { // AuthMediaType::Microphone
|
||||||
|
LOG_INFO(Frontend, "Microphone access requested.");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case AVAuthorizationStatusDenied: {
|
||||||
|
// The user has previously denied access.
|
||||||
|
authorized = false;
|
||||||
|
if (type == AuthMediaType::Camera) {
|
||||||
|
LOG_WARNING(Frontend, "Camera access denied. To change this you may modify the "
|
||||||
|
"macOS system permission settings "
|
||||||
|
"for Citra at 'System Preferences -> Security & Privacy'");
|
||||||
|
} else { // AuthMediaType::Microphone
|
||||||
|
LOG_WARNING(Frontend, "Microphone access denied. To change this you may modify the "
|
||||||
|
"macOS system permission settings "
|
||||||
|
"for Citra at 'System Preferences -> Security & Privacy'");
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
case AVAuthorizationStatusRestricted: {
|
||||||
|
// The user can't grant access due to restrictions.
|
||||||
|
authorized = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
authorized = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CheckAuthorizationForCamera() {
|
||||||
|
CheckAuthorization(AuthMediaType::Camera);
|
||||||
|
return authorized;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CheckAuthorizationForMicrophone() {
|
||||||
|
CheckAuthorization(AuthMediaType::Microphone);
|
||||||
|
return authorized;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // AppleAuthorization
|
Loading…
Reference in a new issue