From 484ea7ce9be971266a890c9bb76b4e23d0c8a622 Mon Sep 17 00:00:00 2001 From: Anthony Bilinski Date: Sun, 27 Jun 2021 11:20:17 -0700 Subject: [PATCH] fix(macos): update deprecated AVFoundation API Backported from 65ff532a54122a09357a0240b287219c0306c0be --- CMakeLists.txt | 11 +++++++++++ src/platform/camera/avfoundation.mm | 8 ++++++++ 2 files changed, 19 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index c5191d58a..29858c416 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -614,6 +614,17 @@ if (NOT DEFINED ENABLE_STATUSNOTIFIER AND UNIX AND NOT APPLE) endif() if(AVFOUNDATION_FOUND) + # used for AVFoundation compile time deprecation check + execute_process( + COMMAND sw_vers -productVersion + OUTPUT_VARIABLE MACOS_VER + ) + string(REPLACE "." ";" VERSION_LIST ${MACOS_VER}) + list(GET VERSION_LIST 0 MACOS_VERSION_MAJOR) + list(GET VERSION_LIST 1 MACOS_VERSION_MINOR) + add_definitions(-DMACOS_VERSION_MAJOR=${MACOS_VERSION_MAJOR}) + add_definitions(-DMACOS_VERSION_MINOR=${MACOS_VERSION_MINOR}) + set(${PROJECT_NAME}_SOURCES ${${PROJECT_NAME}_SOURCES} src/platform/camera/avfoundation.mm src/platform/camera/avfoundation.h) diff --git a/src/platform/camera/avfoundation.mm b/src/platform/camera/avfoundation.mm index e856197e9..2f4b90b62 100644 --- a/src/platform/camera/avfoundation.mm +++ b/src/platform/camera/avfoundation.mm @@ -27,7 +27,15 @@ QVector > avfoundation::getDeviceList() { QVector > result; +#if MACOS_VERSION_MAJOR > 10 || (MACOS_VERSION_MAJOR == 10 && MACOS_VERSION_MINOR > 14) + AVCaptureDevice* device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo]; + id objects[] = {device}; + NSUInteger count = sizeof(objects) / sizeof(id); + NSArray* devices = [NSArray arrayWithObjects:objects count:count]; +#else NSArray* devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo]; +#endif + for (AVCaptureDevice* device in devices) { result.append({ QString::fromNSString([device uniqueID]), QString::fromNSString([device localizedName]) }); }