From 0e8d3e06b6a817e8077641b75d143a7223bf1d67 Mon Sep 17 00:00:00 2001 From: Julien Wadel Date: Tue, 7 Apr 2020 15:37:07 +0200 Subject: [PATCH] Use AVFoundation to request media permissions on start if there are not accepted. --- linphone-app/CMakeLists.txt | 3 ++- linphone-app/src/app/App.cpp | 1 + .../other/desktop-tools/DesktopToolsLinux.hpp | 1 + .../other/desktop-tools/DesktopToolsMacOs.hpp | 2 ++ .../other/desktop-tools/DesktopToolsMacOs.mm | 10 ++++++++++ .../other/desktop-tools/DesktopToolsWindows.hpp | 1 + 6 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 linphone-app/src/components/other/desktop-tools/DesktopToolsMacOs.mm diff --git a/linphone-app/CMakeLists.txt b/linphone-app/CMakeLists.txt index a0cc17087..e54e11c6f 100644 --- a/linphone-app/CMakeLists.txt +++ b/linphone-app/CMakeLists.txt @@ -218,6 +218,7 @@ if (APPLE) src/app/single-application/SingleApplication.cpp src/components/core/event-count-notifier/EventCountNotifierMacOs.m src/components/other/desktop-tools/DesktopToolsMacOs.cpp + src/components/other/desktop-tools/DesktopToolsMacOs.mm src/components/other/desktop-tools/screen-saver/ScreenSaverMacOs.m src/components/other/desktop-tools/state-process/StateProcessMacOs.mm ) @@ -435,7 +436,7 @@ foreach (package ${QT5_PACKAGES_OPTIONAL}) endforeach () if (APPLE) - list(APPEND LIBRARIES "-framework Cocoa -framework IOKit") + list(APPEND LIBRARIES "-framework Cocoa -framework IOKit -framework AVFoundation") # -framework linphone") #This doesn't work yet endif () diff --git a/linphone-app/src/app/App.cpp b/linphone-app/src/app/App.cpp index 09d0457dc..59cbe5662 100644 --- a/linphone-app/src/app/App.cpp +++ b/linphone-app/src/app/App.cpp @@ -209,6 +209,7 @@ App::App (int &argc, char *argv[]) : SingleApplication(argc, argv, true, Mode::U qInfo() << QStringLiteral("Starting " APPLICATION_NAME " (bin: " EXECUTABLE_NAME ")"); qInfo() << QStringLiteral("Use locale: %1").arg(mLocale); + DesktopTools::initialize(); } App::~App () { diff --git a/linphone-app/src/components/other/desktop-tools/DesktopToolsLinux.hpp b/linphone-app/src/components/other/desktop-tools/DesktopToolsLinux.hpp index fce67e103..26446ee8b 100644 --- a/linphone-app/src/components/other/desktop-tools/DesktopToolsLinux.hpp +++ b/linphone-app/src/components/other/desktop-tools/DesktopToolsLinux.hpp @@ -38,6 +38,7 @@ public: bool getScreenSaverStatus () const; void setScreenSaverStatus (bool status); + static void initialization(){} static void applicationStateChanged(Qt::ApplicationState){}; signals: diff --git a/linphone-app/src/components/other/desktop-tools/DesktopToolsMacOs.hpp b/linphone-app/src/components/other/desktop-tools/DesktopToolsMacOs.hpp index a426d882a..f1f1fa6ce 100644 --- a/linphone-app/src/components/other/desktop-tools/DesktopToolsMacOs.hpp +++ b/linphone-app/src/components/other/desktop-tools/DesktopToolsMacOs.hpp @@ -36,8 +36,10 @@ public: bool getScreenSaverStatus () const; void setScreenSaverStatus (bool status); + static void initialize(); // Do first initialization static void applicationStateChanged(Qt::ApplicationState currentState); + signals: void screenSaverStatusChanged (bool status); diff --git a/linphone-app/src/components/other/desktop-tools/DesktopToolsMacOs.mm b/linphone-app/src/components/other/desktop-tools/DesktopToolsMacOs.mm new file mode 100644 index 000000000..ec6747f15 --- /dev/null +++ b/linphone-app/src/components/other/desktop-tools/DesktopToolsMacOs.mm @@ -0,0 +1,10 @@ +#include "DesktopToolsMacOs.hpp" +#import + +void DesktopTools::initialize(){ +// Request permissions + if([AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo] != AVAuthorizationStatusAuthorized) + [AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL) {}]; + if([AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeAudio] != AVAuthorizationStatusAuthorized) + [AVCaptureDevice requestAccessForMediaType:AVMediaTypeAudio completionHandler:^(BOOL) {}]; +} diff --git a/linphone-app/src/components/other/desktop-tools/DesktopToolsWindows.hpp b/linphone-app/src/components/other/desktop-tools/DesktopToolsWindows.hpp index a60b21c5b..2db14634f 100644 --- a/linphone-app/src/components/other/desktop-tools/DesktopToolsWindows.hpp +++ b/linphone-app/src/components/other/desktop-tools/DesktopToolsWindows.hpp @@ -37,6 +37,7 @@ public: bool getScreenSaverStatus () const; void setScreenSaverStatus (bool status); + static void initialization(){} static void applicationStateChanged(Qt::ApplicationState){}; signals: