1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

fix(macos): update deprecated AVFoundation API

This commit is contained in:
Anthony Bilinski 2021-06-27 11:20:17 -07:00
parent e0ba376723
commit 65ff532a54
No known key found for this signature in database
GPG Key ID: 2AA8E0DA1B31FB3C
2 changed files with 19 additions and 0 deletions

View File

@ -537,6 +537,17 @@ endif()
add_definitions(-DQT_MESSAGELOGCONTEXT=1) add_definitions(-DQT_MESSAGELOGCONTEXT=1)
if(AVFOUNDATION_FOUND) 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} set(${PROJECT_NAME}_SOURCES ${${PROJECT_NAME}_SOURCES}
src/platform/camera/avfoundation.mm src/platform/camera/avfoundation.mm
src/platform/camera/avfoundation.h) src/platform/camera/avfoundation.h)

View File

@ -27,7 +27,15 @@ QVector<QPair<QString, QString> > avfoundation::getDeviceList()
{ {
QVector<QPair<QString, QString> > result; 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]; NSArray* devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];
#endif
for (AVCaptureDevice* device in devices) { for (AVCaptureDevice* device in devices) {
result.append({ QString::fromNSString([device uniqueID]), QString::fromNSString([device localizedName]) }); result.append({ QString::fromNSString([device uniqueID]), QString::fromNSString([device localizedName]) });
} }