Skip to content

Commit

Permalink
fix(macos): update deprecated AVFoundation API
Browse files Browse the repository at this point in the history
Backported from 65ff532
  • Loading branch information
anthonybilinski committed Mar 6, 2022
1 parent c282c6e commit 484ea7c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
11 changes: 11 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions src/platform/camera/avfoundation.mm
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,15 @@
{
QVector<QPair<QString, QString> > 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]) });
}
Expand Down

0 comments on commit 484ea7c

Please sign in to comment.