diff options
| author | sumuel <samuel@yakubos.org> | 2026-08-17 20:44:55 +0000 |
|---|---|---|
| committer | sumuel <samuel@yakubos.org> | 2026-08-17 20:44:55 +0000 |
| commit | 76424950e373d3b04ac3dd13019151bfba3e8423 (patch) | |
| tree | 4c3cfdbda039e592b9186be3e28f8d7cfd439e8a /src/detection/camera/camera_apple.m | |
Add the files
Diffstat (limited to 'src/detection/camera/camera_apple.m')
| -rw-r--r-- | src/detection/camera/camera_apple.m | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/src/detection/camera/camera_apple.m b/src/detection/camera/camera_apple.m new file mode 100644 index 0000000..aa5c1cf --- /dev/null +++ b/src/detection/camera/camera_apple.m @@ -0,0 +1,61 @@ +#include "camera.h" +#include "common/io.h" + +#import <AVFoundation/AVCaptureDevice.h> + +// warning: 'AVCaptureDeviceTypeExternalUnknown' is deprecated +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" + +#ifdef MAC_OS_VERSION_14_0 +// To make fastfetch compiled on newer macOS versions runs on older ones +AVF_EXPORT FF_A_WEAK_IMPORT AVCaptureDeviceType const AVCaptureDeviceTypeExternal; +#endif + +const char* ffDetectCamera(FFlist* result) +{ + #ifdef MAC_OS_X_VERSION_10_15 + FF_SUPPRESS_IO(); // #822 + + AVCaptureDeviceType deviceType = NULL; + + #ifdef MAC_OS_VERSION_14_0 + // Strangely `@available(macOS 14.0, *)` doesn't work here (#1594) + if (@available(macOS 14.0, *)) + { + if (&AVCaptureDeviceTypeExternal) + deviceType = AVCaptureDeviceTypeExternal; + } + #endif + if (deviceType == NULL) + deviceType = AVCaptureDeviceTypeExternalUnknown; + + AVCaptureDeviceDiscoverySession* session = [AVCaptureDeviceDiscoverySession discoverySessionWithDeviceTypes:@[AVCaptureDeviceTypeBuiltInWideAngleCamera, deviceType] + mediaType:AVMediaTypeVideo + position:AVCaptureDevicePositionUnspecified]; + if (!session) + return "Failed to create AVCaptureDeviceDiscoverySession"; + + for (AVCaptureDevice* device in session.devices) + { + FFCameraResult* camera = FF_LIST_ADD(FFCameraResult, *result); + ffStrbufInitS(&camera->name, device.localizedName.UTF8String); + ffStrbufInitS(&camera->vendor, device.manufacturer.UTF8String); + ffStrbufInitS(&camera->id, device.uniqueID.UTF8String); + switch (device.activeColorSpace) + { + case AVCaptureColorSpace_sRGB: ffStrbufInitStatic(&camera->colorspace, "sRGB"); break; + case AVCaptureColorSpace_P3_D65: ffStrbufInitStatic(&camera->colorspace, "P3-D65"); break; + case 2 /*AVCaptureColorSpace_HLG_BT2020*/: ffStrbufInitStatic(&camera->colorspace, "BT2020-HLG"); break; + case 3 /*AVCaptureColorSpace_AppleLog*/: ffStrbufInitStatic(&camera->colorspace, "AppleLog"); break; + case 4 /*AVCaptureColorSpace_AppleLog2*/: ffStrbufInitStatic(&camera->colorspace, "AppleLog2"); break; + } + + CMVideoDimensions size = CMVideoFormatDescriptionGetDimensions(device.activeFormat.formatDescription); + camera->width = size.width < 0 ? 0 : (uint32_t) size.width; + camera->height = size.height < 0 ? 0 : (uint32_t) size.height; + } + return NULL; + #else + return "No support for old MacOS version"; + #endif +} |