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 7E4F04B9B0 for ; Thu, 1 Aug 2024 22:25:47 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9152168D909; Fri, 2 Aug 2024 01:25:44 +0300 (EEST) Received: from mr85p00im-hyfv06021301.me.com (mr85p00im-hyfv06021301.me.com [17.58.23.188]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 60FC068C4F1 for ; Fri, 2 Aug 2024 01:25:37 +0300 (EEST) Received: from Yakumo-Yukari.lan (mr38p00im-dlb-asmtp-mailmevip.me.com [17.57.152.18]) by mr85p00im-hyfv06021301.me.com (Postfix) with ESMTPSA id 360242150D52; Thu, 1 Aug 2024 22:25:32 +0000 (UTC) To: ffmpeg-devel@ffmpeg.org Date: Fri, 2 Aug 2024 06:25:26 +0800 Message-Id: <20240801222526.69641-1-gnattuoc@me.com> X-Mailer: git-send-email 2.39.3 (Apple Git-146) MIME-Version: 1.0 X-Proofpoint-GUID: xbDOPj9LQ70Sb6pDoM0diTVDjuRXvzM7 X-Proofpoint-ORIG-GUID: xbDOPj9LQ70Sb6pDoM0diTVDjuRXvzM7 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-08-01_20,2024-08-01_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 mlxscore=0 malwarescore=0 suspectscore=0 spamscore=0 mlxlogscore=841 adultscore=0 bulkscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2408010150 X-Apple-Remote-Links: v=1;h=KCk=;charset=UTF-8 Subject: [FFmpeg-devel] [PATCH] avutil/hwcontext_videotoolbox: Allocate attachments dictionary 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: , From: gnattu via ffmpeg-devel Reply-To: FFmpeg development discussions and patches Cc: gnattu 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: From: Gnattu OC Allocate a dedicated attachments dictionary instead of trying to get one from the pixel buffer. The attachments got from the pixel buffer confuses the CVImageBufferCreateColorSpaceFromAttachments method and will make it to output a wrong colorspace that causes problem like #10884. Signed-off-by: gnattu --- libavutil/hwcontext_videotoolbox.c | 35 ++++++++++++++++++------------ 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/libavutil/hwcontext_videotoolbox.c b/libavutil/hwcontext_videotoolbox.c index 1794459943..dda6ada1af 100644 --- a/libavutil/hwcontext_videotoolbox.c +++ b/libavutil/hwcontext_videotoolbox.c @@ -569,11 +569,19 @@ static int vt_pixbuf_set_colorspace(void *log_ctx, CGColorSpaceRef colorspace = NULL; CFStringRef colormatrix = NULL, colorpri = NULL, colortrc = NULL; Float32 gamma = 0; + CFMutableDictionaryRef attachments = NULL; + attachments = CFDictionaryCreateMutable(NULL, 0, + &kCFTypeDictionaryKeyCallBacks, + &kCFTypeDictionaryValueCallBacks); + if (!attachments) + return AVERROR(ENOMEM); colormatrix = av_map_videotoolbox_color_matrix_from_av(src->colorspace); - if (colormatrix) + if (colormatrix) { + CFDictionarySetValue(attachments, kCVImageBufferYCbCrMatrixKey, colormatrix); CVBufferSetAttachment(pixbuf, kCVImageBufferYCbCrMatrixKey, - colormatrix, kCVAttachmentMode_ShouldPropagate); + colormatrix, kCVAttachmentMode_ShouldPropagate); + } else { CVBufferRemoveAttachment(pixbuf, kCVImageBufferYCbCrMatrixKey); if (src->colorspace != AVCOL_SPC_UNSPECIFIED) @@ -583,9 +591,11 @@ static int vt_pixbuf_set_colorspace(void *log_ctx, } colorpri = av_map_videotoolbox_color_primaries_from_av(src->color_primaries); - if (colorpri) + if (colorpri) { + CFDictionarySetValue(attachments, kCVImageBufferColorPrimariesKey, colorpri); CVBufferSetAttachment(pixbuf, kCVImageBufferColorPrimariesKey, - colorpri, kCVAttachmentMode_ShouldPropagate); + colorpri, kCVAttachmentMode_ShouldPropagate); + } else { CVBufferRemoveAttachment(pixbuf, kCVImageBufferColorPrimariesKey); if (src->color_primaries != AVCOL_SPC_UNSPECIFIED) @@ -595,9 +605,11 @@ static int vt_pixbuf_set_colorspace(void *log_ctx, } colortrc = av_map_videotoolbox_color_trc_from_av(src->color_trc); - if (colortrc) + if (colortrc) { + CFDictionarySetValue(attachments, kCVImageBufferTransferFunctionKey, colortrc); CVBufferSetAttachment(pixbuf, kCVImageBufferTransferFunctionKey, - colorpri, kCVAttachmentMode_ShouldPropagate); + colorpri, kCVAttachmentMode_ShouldPropagate); + } else { CVBufferRemoveAttachment(pixbuf, kCVImageBufferTransferFunctionKey); if (src->color_trc != AVCOL_TRC_UNSPECIFIED) @@ -622,17 +634,12 @@ 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 = - vt_cv_buffer_copy_attachments(pixbuf, kCVAttachmentMode_ShouldPropagate); - - if (attachments) { - colorspace = - CVImageBufferCreateColorSpaceFromAttachments(attachments); - CFRelease(attachments); - } + colorspace = CVImageBufferCreateColorSpaceFromAttachments(attachments); } #endif + CFRelease(attachments); + // 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. -- 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".