From 2fc37c42391a38bfe0aea248f2fe75c9033f98e5 Mon Sep 17 00:00:00 2001 From: Marvin Scholz Date: Tue, 9 Jul 2024 16:46:47 +0200 Subject: [PATCH] avutil/hwcontext_videotoolbox: Fix build with older SDKs I've accidentally used API not available on the checked version. Additionally check for the SDK to be new enough to even have the CVImageBufferCreateColorSpaceFromAttachments API to not fail the build. Signed-off-by: Zhao Zhili --- libavutil/hwcontext_videotoolbox.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/libavutil/hwcontext_videotoolbox.c b/libavutil/hwcontext_videotoolbox.c index dd89edfa08..ab7556936d 100644 --- a/libavutil/hwcontext_videotoolbox.c +++ b/libavutil/hwcontext_videotoolbox.c @@ -588,13 +588,26 @@ static int vt_pixbuf_set_colorspace(void *log_ctx, } else CVBufferRemoveAttachment(pixbuf, kCVImageBufferGammaLevelKey); - if (__builtin_available(macOS 12.0, iOS 15.0, *)) { - CFDictionaryRef attachments = CVBufferCopyAttachments(pixbuf, kCVAttachmentMode_ShouldPropagate); +#if (TARGET_OS_OSX && __MAC_OS_X_VERSION_MAX_ALLOWED >= 100800) || \ + (TARGET_OS_IOS && __IPHONE_OS_VERSION_MAX_ALLOWED >= 100000) + if (__builtin_available(macOS 10.8, iOS 10, *)) { + CFDictionaryRef attachments = NULL; + if (__builtin_available(macOS 12.0, iOS 15.0, *)) + attachments = CVBufferCopyAttachments(pixbuf, kCVAttachmentMode_ShouldPropagate); +#if (TARGET_OS_OSX && __MAC_OS_X_VERSION_MIN_REQUIRED <= 120000) || \ + (TARGET_OS_IOS && __IPHONE_OS_VERSION_MIN_REQUIRED <= 150000) + else { + CFDictionaryRef tmp = CVBufferGetAttachments(pixbuf, kCVAttachmentMode_ShouldPropagate); + if (tmp) + attachments = CFDictionaryCreateCopy(NULL, tmp); + } +#endif if (attachments) { colorspace = CVImageBufferCreateColorSpaceFromAttachments(attachments); CFRelease(attachments); } } +#endif if (colorspace) { CVBufferSetAttachment(pixbuf, kCVImageBufferCGColorSpaceKey,