From ae5132c388f0072b42bdf545aaf4b876bd31e8ff Mon Sep 17 00:00:00 2001 From: Carter Li Date: Sun, 31 May 2026 12:37:20 +0800 Subject: [PATCH] Decoder (macOS): adds support --- CMakeLists.txt | 2 ++ src/detection/decoder/decoder.h | 6 +++- src/detection/decoder/decoder_apple.m | 51 +++++++++++++++++++++++++++ src/modules/decoder/decoder.c | 8 +++++ 4 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 src/detection/decoder/decoder_apple.m diff --git a/CMakeLists.txt b/CMakeLists.txt index 34d6f8f9d..7ed6a9160 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -980,6 +980,7 @@ elseif(APPLE) src/detection/cpucache/cpucache_apple.c src/detection/cpuusage/cpuusage_apple.c src/detection/cursor/cursor_apple.m + src/detection/decoder/decoder_apple.m src/detection/disk/disk_bsd.c src/detection/dns/dns_apple.c src/detection/physicaldisk/physicaldisk_apple.c @@ -1834,6 +1835,7 @@ elseif(APPLE) PRIVATE "-framework OpenGL" PRIVATE "-framework OpenCL" PRIVATE "-framework SystemConfiguration" + PRIVATE "-framework VideoToolbox" PRIVATE "-weak_framework CoreDisplay" PRIVATE "-F /System/Library/PrivateFrameworks" diff --git a/src/detection/decoder/decoder.h b/src/detection/decoder/decoder.h index 656ccd286..76b946c53 100644 --- a/src/detection/decoder/decoder.h +++ b/src/detection/decoder/decoder.h @@ -21,7 +21,11 @@ typedef enum FF_A_PACKED FFDecoderType { FF_DECODER_TYPE_VP9 = UINT32_C(1) << 13, FF_DECODER_TYPE_AV1 = UINT32_C(1) << 14, FF_DECODER_TYPE_VVC = UINT32_C(1) << 15, - FF_DECODER_TYPE_MAX = FF_DECODER_TYPE_VVC, + FF_DECODER_TYPE_DOLBY_VISION_HEVC = UINT32_C(1) << 16, + FF_DECODER_TYPE_PRORES = UINT32_C(1) << 17, + FF_DECODER_TYPE_PRORES_RAW = UINT32_C(1) << 18, + FF_DECODER_TYPE_JPEG_XL = UINT32_C(1) << 19, + FF_DECODER_TYPE_MAX = FF_DECODER_TYPE_JPEG_XL, FF_DECODER_TYPE_FORCE_UNSIGNED = UINT32_MAX, } FFDecoderType; diff --git a/src/detection/decoder/decoder_apple.m b/src/detection/decoder/decoder_apple.m new file mode 100644 index 000000000..e8dab2895 --- /dev/null +++ b/src/detection/decoder/decoder_apple.m @@ -0,0 +1,51 @@ +#include "decoder.h" + +#import +#import + +const char* ffDetectDecoder(FF_A_UNUSED FFDecoderOptions* options, FFlist* result /* list of FFDecoderResult */) { + static const struct { + CMVideoCodecType codec; + FFDecoderType type; + } codecs[] = { + { kCMVideoCodecType_H263, FF_DECODER_TYPE_H263 }, + { kCMVideoCodecType_JPEG, FF_DECODER_TYPE_MJPEG }, + { kCMVideoCodecType_JPEG_XL, FF_DECODER_TYPE_JPEG_XL }, + { kCMVideoCodecType_MPEG1Video, FF_DECODER_TYPE_MPEG1 }, + { kCMVideoCodecType_MPEG2Video, FF_DECODER_TYPE_MPEG2 }, + { kCMVideoCodecType_MPEG4Video, FF_DECODER_TYPE_DIVX_XVID }, + { kCMVideoCodecType_H264, FF_DECODER_TYPE_H264 }, + { kCMVideoCodecType_HEVC, FF_DECODER_TYPE_HEVC }, + { kCMVideoCodecType_HEVCWithAlpha, FF_DECODER_TYPE_HEVC }, + { kCMVideoCodecType_DolbyVisionHEVC, FF_DECODER_TYPE_DOLBY_VISION_HEVC }, + { kCMVideoCodecType_DisparityHEVC, FF_DECODER_TYPE_HEVC }, + { kCMVideoCodecType_DepthHEVC, FF_DECODER_TYPE_HEVC }, + { kCMVideoCodecType_VP9, FF_DECODER_TYPE_VP9 }, + { kCMVideoCodecType_AV1, FF_DECODER_TYPE_AV1 }, + { kCMVideoCodecType_AppleProRes4444XQ, FF_DECODER_TYPE_PRORES }, + { kCMVideoCodecType_AppleProRes4444, FF_DECODER_TYPE_PRORES }, + { kCMVideoCodecType_AppleProRes422HQ, FF_DECODER_TYPE_PRORES }, + { kCMVideoCodecType_AppleProRes422, FF_DECODER_TYPE_PRORES }, + { kCMVideoCodecType_AppleProRes422LT, FF_DECODER_TYPE_PRORES }, + { kCMVideoCodecType_AppleProRes422Proxy, FF_DECODER_TYPE_PRORES }, + { kCMVideoCodecType_AppleProResRAW, FF_DECODER_TYPE_PRORES_RAW }, + { kCMVideoCodecType_AppleProResRAWHQ, FF_DECODER_TYPE_PRORES_RAW }, + }; + + FFDecoderType types = FF_DECODER_TYPE_NONE; + + for (uint32_t i = 0; i < ARRAY_SIZE(codecs); ++i) { + if (types & codecs[i].type || !VTIsHardwareDecodeSupported(codecs[i].codec)) { + continue; + } + types |= codecs[i].type; + } + + if (types != FF_DECODER_TYPE_NONE) { + FFDecoderResult* item = FF_LIST_ADD(FFDecoderResult, *result); + ffStrbufInitS(&item->gpu, MTLCreateSystemDefaultDevice().name.UTF8String ?: "VideoToolbox"); + item->types = types; + } + + return NULL; +} diff --git a/src/modules/decoder/decoder.c b/src/modules/decoder/decoder.c index 74c4cc47b..d8f0c5038 100644 --- a/src/modules/decoder/decoder.c +++ b/src/modules/decoder/decoder.c @@ -35,6 +35,14 @@ static const char* ffDecoderTypeToString(FFDecoderType type) { return "AV1"; case FF_DECODER_TYPE_VVC: return "VVC / H.266"; + case FF_DECODER_TYPE_DOLBY_VISION_HEVC: + return "Dolby Vision (HEVC)"; + case FF_DECODER_TYPE_PRORES: + return "Apple ProRes"; + case FF_DECODER_TYPE_PRORES_RAW: + return "Apple ProRes RAW"; + case FF_DECODER_TYPE_JPEG_XL: + return "JPEG XL"; case FF_DECODER_TYPE_UNKNOWN: default: return "Unknown";