From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 3C5FB4C1D5 for ; Tue, 23 Jul 2024 09:11:18 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4272268D62B; Tue, 23 Jul 2024 12:11:15 +0300 (EEST) Received: from mail-ed1-f41.google.com (mail-ed1-f41.google.com [209.85.208.41]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 620FD68D463 for ; Tue, 23 Jul 2024 12:11:08 +0300 (EEST) Received: by mail-ed1-f41.google.com with SMTP id 4fb4d7f45d1cf-5a1c496335aso2257664a12.1 for ; Tue, 23 Jul 2024 02:11:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721725868; x=1722330668; darn=ffmpeg.org; h=subject:date:from:to:message-id:from:to:cc:subject:date:message-id :reply-to; bh=sCxpVxaBvHXGJVmDMgAGJ9fUjxuR/loQWprIM6+NXzc=; b=VB/vAk2rNLk2wmt4fJvdlo7z03FhTCJFH0WwlK1CRpOVFQmB8o6ulKUyuAag1EQvmH khrapWlTzre68N1xZXBpZwZOdlCYctRvq2su7nUXqcxvI4AgnWktZw6INfZp3K0Iy3JC kpBnFpN1HLoN1P43w17sX00xeZvIzjrlnFcvERChLZliYYnUq9dRvCG/RrsL0DstycDe ZHhdjBoHsMibJTFZnnORRIeB+vb8KA8aBAXKhRUpbRtWTQ+6IcZr2f8XwjkVtbQrL7Ol Pq7OCvdE7h2s4xkxQvAdAHFAKmMBtGYCOWfo/OBx71+kIRLIUTMafuoUSChXLOhfitNI 1k0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721725868; x=1722330668; h=subject:date:from:to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=sCxpVxaBvHXGJVmDMgAGJ9fUjxuR/loQWprIM6+NXzc=; b=lAtCDCmUsAwcyDWdWQw0Odp7jAWKq33HwpYcTWiyogfB3iPT5IPZYuuBirdAcOUkmt 8v2bEkLT0QqtA3d9yVK/3Aed4pv4wlHKCs6KfvkmFy1PJt1d40//e6QOIsNfJwsTeX28 hbqc2jwJBlvFkIERX3Nu4l3JGXrKdLLGVgmWHXdKXQk8uGOQdg4nrgK164fSvdImIRjI sF5sY/EPngXFfPxUbGi3IozXLVd0tRvt/OILX7/lLM9oDieD8Al2BfGVaTsyLh5fFxrV 09j4w2I+cpcuhrp7idMP2bCkfyw0lhbZ4w5aLc+SYnZSaICH249VvWmQWrF8kw1HQ9cg W/Gw== X-Gm-Message-State: AOJu0YySxnq0rGYkeVm03gmYY7fNYm+XRyYztKAZd28/5tahwWMjLgkP tetNKLHOIRIYiWIYeWblhSqaLXyEgKKYlg5Y40/+fJP79EXqIdX8s8o/QCC+ X-Google-Smtp-Source: AGHT+IF3aIAQ8aYGd8BBjne+7itXGo+oWNOEexHE7zvZCj1G/CnFqFO6RrVIZjX7yvMoyOuCdSDvPA== X-Received: by 2002:a05:6402:1d4c:b0:5a2:4558:d17c with SMTP id 4fb4d7f45d1cf-5a478b65d96mr9135258a12.4.1721725867407; Tue, 23 Jul 2024 02:11:07 -0700 (PDT) Received: from localhost ([213.235.133.41]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5a30a4d6e67sm7234225a12.17.2024.07.23.02.11.05 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 23 Jul 2024 02:11:06 -0700 (PDT) Message-Id: To: From: "Marvin Scholz" Date: Tue, 23 Jul 2024 11:10:44 +0200 Subject: [FFmpeg-devel] [PATCH] avutil/hwcontext_videotoolbox: Fix build with older SDKs X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: The previous fix was not sufficient. To make things easier to reason about, split the function and add the guards there instead of complicating the call site more. --- libavutil/hwcontext_videotoolbox.c | 51 +++++++++++++++++++++++------- 1 file changed, 39 insertions(+), 12 deletions(-) diff --git a/libavutil/hwcontext_videotoolbox.c b/libavutil/hwcontext_videotoolbox.c index ab7556936d..1794459943 100644 --- a/libavutil/hwcontext_videotoolbox.c +++ b/libavutil/hwcontext_videotoolbox.c @@ -532,6 +532,37 @@ CFStringRef av_map_videotoolbox_color_trc_from_av(enum AVColorTransferCharacteri } } +/** + * Copy all attachments for the specified mode from the given buffer. + */ +static CFDictionaryRef vt_cv_buffer_copy_attachments(CVBufferRef buffer, + CVAttachmentMode attachment_mode) +{ + CFDictionaryRef dict; + + // Check that our SDK is at least macOS 12 / iOS 15 / tvOS 15 + #if (TARGET_OS_OSX && defined(__MAC_12_0) && __MAC_OS_X_VERSION_MAX_ALLOWED >= __MAC_12_0) || \ + (TARGET_OS_IOS && defined(__IPHONE_15_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_15_0) || \ + (TARGET_OS_TV && defined(__TVOS_15_0) && __TV_OS_VERSION_MAX_ALLOWED >= __TVOS_15_0) + // On recent enough versions, just use the respective API + if (__builtin_available(macOS 12.0, iOS 15.0, tvOS 15.0, *)) + return CVBufferCopyAttachments(buffer, attachment_mode); + #endif + + // Check that the target is lower than macOS 12 / iOS 15 / tvOS 15 + // else this would generate a deprecation warning and anyway never run because + // the runtime availability check above would be always true. + #if (TARGET_OS_OSX && (!defined(__MAC_12_0) || __MAC_OS_X_VERSION_MIN_REQUIRED < __MAC_12_0)) || \ + (TARGET_OS_IOS && (!defined(__IPHONE_15_0) || __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_15_0)) || \ + (TARGET_OS_TV && (!defined(__TVOS_15_0) || __TV_OS_VERSION_MIN_REQUIRED < __TVOS_15_0)) + // Fallback on SDKs or runtime versions < macOS 12 / iOS 15 / tvOS 15 + dict = CVBufferGetAttachments(buffer, attachment_mode); + return (dict) ? CFDictionaryCreateCopy(NULL, dict) : NULL; + #else + return NULL; // Impossible, just make the compiler happy + #endif +} + static int vt_pixbuf_set_colorspace(void *log_ctx, CVPixelBufferRef pixbuf, const AVFrame *src) { @@ -591,24 +622,20 @@ static int vt_pixbuf_set_colorspace(void *log_ctx, #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 + CFDictionaryRef attachments = + vt_cv_buffer_copy_attachments(pixbuf, kCVAttachmentMode_ShouldPropagate); + if (attachments) { - colorspace = CVImageBufferCreateColorSpaceFromAttachments(attachments); + colorspace = + CVImageBufferCreateColorSpaceFromAttachments(attachments); CFRelease(attachments); } } #endif + // Done outside the above preprocessor code and if's so that + // in any case a wrong kCVImageBufferCGColorSpaceKey is removed + // if the above code is not used or fails. if (colorspace) { CVBufferSetAttachment(pixbuf, kCVImageBufferCGColorSpaceKey, colorspace, kCVAttachmentMode_ShouldPropagate); base-commit: fa5a6055422a9e38905de9274e63f245cef96c57 -- 2.39.3 (Apple Git-146) _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".