From patchwork Tue Jul 23 09:10:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marvin Scholz X-Patchwork-Id: 50704 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:a742:0:b0:482:c625:d099 with SMTP id f2csp2498283vqm; Tue, 23 Jul 2024 02:21:52 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCV16IClsFZ0ij1h/5WhaYvU/uy9ip42q16tFXf9fdrIsb765pPusCvD9cpW8RXXPjWy5ryQMr3W1y7WT6WnRtEVa4gawjt9ME6xMg== X-Google-Smtp-Source: AGHT+IG0J74CDR5YJEZIGRfkTTMqhZDTeUlXeHPtXp21aSyaS1LjLunXjxVYj/oOSyqeFs/NI4Kz X-Received: by 2002:a05:6512:2826:b0:52e:932d:88ab with SMTP id 2adb3069b0e04-52efb63d1f8mr8769956e87.23.1721726511776; Tue, 23 Jul 2024 02:21:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1721726511; cv=none; d=google.com; s=arc-20160816; b=aI6U9Q8+p1h7UsnNwOxsnT1dEmLFKHmx18GCw9C8Pfb9RVaqk+sBkNMKfouRRSCu7B G/e2ZD/jvr7xou0Jpbaj6rvKpj6ODIfUL1NgZSN0d7s4+u44QV5FBe91jH/km7rXUlfr e4jFsrCWS2WaoTtfm4G2tkCJmWB7F9C9FisyGqO+wpovEY3rbwn8VwsQXFMNDeAEhCoJ 65IwOhfLO2GnQU4+Vs+VkhKQQR9+GtyEvcedcEwPwmikOEWr4irUoUegFGIRIWGSmR1n T4+SvMkRGQdsKBAjjxizrJB5SxGiMiGwrJTCQGradZusxD2BaI4KJkT4ktmTbx3zM7qm ZWXw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:date:from:to:message-id:dkim-signature :delivered-to; bh=ZPmOjnmuSlG24GKBSWS+E/6l9cT4B/3/PFO1YR3/2K0=; fh=5IeVwzS1vbVKjIV8MP3mnmnRtZGb8uteQ9r4QD2keV0=; b=n2f4tBw16KUyDK5I4NikXw/sy4WAtfNicTvfsqTWdbfXk2/10QXJ9f9Y3mrv3TsydB SaujICrC8O/gxgwT+l55THoy/u2OQsAeCpHPbgeXQW0+dMLnMA7nsWlA82fIO5kP0cOn 2sWfvdlrG8ARFVsWVJnBwSkDJkDqo06Q0/9iZ2oF+v3zn9YHY8/jYfMD82QiMlltIcZ6 hq1uiNirBFVPZ3b/5FKyPE8VGNBdVuuP7HrgsTLaBocHEySw512iCdPfD+O/qXuJjMEI UrbVwP5+L0Zvic6wU++xrN5tgsJPKwpZpsNhltB0G7S7IZIAW/ipyY61BJCa8skaxjKO OzvQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b="VB/vAk2r"; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com; dara=fail header.i=@gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id 2adb3069b0e04-52fc5ee3f3asi381702e87.317.2024.07.23.02.21.51; Tue, 23 Jul 2024 02:21:51 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b="VB/vAk2r"; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com; dara=fail header.i=@gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 3D2DF68D333; Tue, 23 Jul 2024 12:11:16 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org 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-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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: S/4rBsNo8fni 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(-) base-commit: fa5a6055422a9e38905de9274e63f245cef96c57 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);