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 E38E748A99 for ; Fri, 29 Dec 2023 13:23:21 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id EE05E68CCFE; Fri, 29 Dec 2023 15:23:18 +0200 (EET) Received: from out203-205-221-155.mail.qq.com (out203-205-221-155.mail.qq.com [203.205.221.155]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A8C0068CC40 for ; Fri, 29 Dec 2023 15:23:10 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foxmail.com; s=s201512; t=1703856181; bh=/be65iR05IPYSNuLf7mQRaICbLWXp4A0IG/svB7wFLM=; h=From:To:Cc:Subject:Date; b=wabQ6Qd6Dc+tnhmaVb3y9/rT2Vx2/ZRgPiHVDM58rATuXd3IQU88ynDALzyMfXT5F 9qPdVyR6zM5O707dbITyCBvVkT61xpRabbVrf3dIHyKu7RjN9JUs+x8jfTiS46JqKI 8SL005Gwf2N6Jvf/obzKNF6rUJx9vmMAn5WtnM8s= Received: from ZHILIZHAO-MB1.tencent.com ([119.147.10.198]) by newxmesmtplogicsvrsza10-0.qq.com (NewEsmtp) with SMTP id 5C0A34B8; Fri, 29 Dec 2023 21:23:00 +0800 X-QQ-mid: xmsmtpt1703856180tp78exfxq Message-ID: X-QQ-XMAILINFO: NhUkPfKlCtQwpi+UTm5bFoHMpSmo4s6Lm3tsSXek4LpAaqlbj9RuQ3r0LX6Xud 9Xkxv9yZKxfbqcWSqNJG6F8/f+HRgaPy23kP+aZTZABZ7vmrJBquRxOMvQnCREHlvL9ej0ikW/F/ 0yeip4M6M97Mddt1ktj7XV6VOYEYblHWl5muCYz+1Je0jpAi6zzoHIh8c06B2sSNnYXG//zJYxC+ lG3M+6qobesYQPvs111X5ulwHPudT8Iy/x+e6lJp1U6BRXBHARWk0xfZTNb32KmuAuFwdEu9pkwL uCDT3XGzXTWibbWNigX1UhAeqBQ7gdhMHV1Yj4D4um2ML/Yw3g+wzs0/0pBki6zGu1sGhjpsn9wO 7aWv+dLl4PicSsoD4VuZ+bq11h1KVFonQOKEjuy+TDKFaXNyPTEUnNNozY5MTG/lO+6Zg50N1zM5 qipzV3FH+IFC4GWffB6pLBW6bX4t7ZjXZnWBiwMlhWtxzBZZ/D9jWsayWYFpQBVMjTaeNxaCfgfR hMWtiIEM4ZL07D2fFzH8PBUE0rtIU0A+MkNsGecgw3aSM1MzUdCzNOod5c3UX11tH3vsWjYDnzhF xpYThOEGX7/Cz4LgI2UyGVxR3gPRASMBv638Mjc4ATwp5X9Z7rzXiOEa6HoI350qfbf/3kyw2dXL F88t183wlslZ2okT8GGBtpsR9eaYOOVYgMIRn7ksppTH8aKkN0yWM3r3ofDyScz6dcp2CoET4Fa0 N6cpnVsXpS6NpqbH3wRp2jahPRgfhAwp9GC6dL4qqMIF0PS9UvsKcfWreD7QnHnB1GL1PlpZen6g yh/RkcD7MOl9ZI0Nc+8YW+FL7MylRP3MN/iuNtFTd/ypPxkrc86C1ESS7/xes4PtiV2Oehy3mGZN Y2n4Nls5wj/CPYfxieXYnJ9pY4c33sEKrk8Z4fpayYBHRbizJepgvqaQDv/TB5MT/S1HLAjvgS6h f1zeZgbDFGfsUvq6mZU1InKQUqnZnfcFH5Qotrfo6AMrdUzzVGlpwhYGh7RAxA X-QQ-XMRINFO: M/715EihBoGSf6IYSX1iLFg= From: Zhao Zhili To: ffmpeg-devel@ffmpeg.org Date: Fri, 29 Dec 2023 21:22:57 +0800 X-OQ-MSGID: <20231229132258.31094-1-quinkblack@foxmail.com> X-Mailer: git-send-email 2.42.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/2] avutil/hwcontext_videotoolbox: add frame hwctx to specify color range 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 Cc: Zhao Zhili 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: Zhao Zhili VideoToolbox use different identifiers for the same pixel format with different color range, like kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange kCVPixelFormatType_420YpCbCr8BiPlanarFullRange. Before the patch, vt_pool_alloc() always use limited range, and it will fail for pixel format AV_PIX_FMT_BGRA since there is no limited range kCVPixelFormatType_32BGRA. --- libavutil/hwcontext_videotoolbox.c | 30 +++++++++++++++++++++++------- libavutil/hwcontext_videotoolbox.h | 7 +++++-- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/libavutil/hwcontext_videotoolbox.c b/libavutil/hwcontext_videotoolbox.c index b8e6bb407f..bb5b7e2764 100644 --- a/libavutil/hwcontext_videotoolbox.c +++ b/libavutil/hwcontext_videotoolbox.c @@ -144,6 +144,25 @@ enum AVPixelFormat av_map_videotoolbox_format_to_pixfmt(uint32_t cv_fmt) return AV_PIX_FMT_NONE; } +static uint32_t vt_format_from_pixfmt(enum AVPixelFormat pix_fmt, + enum AVColorRange range) +{ + for (int i = 0; i < FF_ARRAY_ELEMS(cv_pix_fmts); i++) { + if (cv_pix_fmts[i].pix_fmt == pix_fmt) { + int full_range = (range == AVCOL_RANGE_JPEG); + + // Don't care if unspecified + if (range == AVCOL_RANGE_UNSPECIFIED) + return cv_pix_fmts[i].cv_fmt; + + if (cv_pix_fmts[i].full_range == full_range) + return cv_pix_fmts[i].cv_fmt; + } + } + + return 0; +} + uint32_t av_map_videotoolbox_format_from_pixfmt(enum AVPixelFormat pix_fmt) { return av_map_videotoolbox_format_from_pixfmt2(pix_fmt, false); @@ -151,12 +170,7 @@ uint32_t av_map_videotoolbox_format_from_pixfmt(enum AVPixelFormat pix_fmt) uint32_t av_map_videotoolbox_format_from_pixfmt2(enum AVPixelFormat pix_fmt, bool full_range) { - int i; - for (i = 0; i < FF_ARRAY_ELEMS(cv_pix_fmts); i++) { - if (cv_pix_fmts[i].pix_fmt == pix_fmt && cv_pix_fmts[i].full_range == full_range) - return cv_pix_fmts[i].cv_fmt; - } - return 0; + return vt_format_from_pixfmt(pix_fmt, full_range ? AVCOL_RANGE_JPEG : AVCOL_RANGE_MPEG); } static int vt_pool_alloc(AVHWFramesContext *ctx) @@ -166,6 +180,7 @@ static int vt_pool_alloc(AVHWFramesContext *ctx) CFNumberRef w, h, pixfmt; uint32_t cv_pixfmt; CFMutableDictionaryRef attributes, iosurface_properties; + AVVTFramesContext *hw_ctx = ctx->hwctx; attributes = CFDictionaryCreateMutable( NULL, @@ -173,7 +188,7 @@ static int vt_pool_alloc(AVHWFramesContext *ctx) &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); - cv_pixfmt = av_map_videotoolbox_format_from_pixfmt(ctx->sw_format); + cv_pixfmt = vt_format_from_pixfmt(ctx->sw_format, hw_ctx->color_range); pixfmt = CFNumberCreate(NULL, kCFNumberSInt32Type, &cv_pixfmt); CFDictionarySetValue( attributes, @@ -750,6 +765,7 @@ const HWContextType ff_hwcontext_type_videotoolbox = { .frames_priv_size = sizeof(VTFramesContext), .device_create = vt_device_create, + .frames_hwctx_size = sizeof(AVVTFramesContext), .frames_init = vt_frames_init, .frames_get_buffer = vt_get_buffer, .frames_get_constraints = vt_frames_get_constraints, diff --git a/libavutil/hwcontext_videotoolbox.h b/libavutil/hwcontext_videotoolbox.h index 25dde85df5..600e9f2c8d 100644 --- a/libavutil/hwcontext_videotoolbox.h +++ b/libavutil/hwcontext_videotoolbox.h @@ -39,10 +39,13 @@ * depending on application usage, so it is preferable to let CoreVideo manage * the pool using the default implementation. * - * Currently AVHWDeviceContext.hwctx and AVHWFramesContext.hwctx are always - * NULL. + * Currently AVHWDeviceContext.hwctx are always NULL. */ +typedef struct AVVTFramesContext { + enum AVColorRange color_range; +} AVVTFramesContext; + /** * Convert a VideoToolbox (actually CoreVideo) format to AVPixelFormat. * Returns AV_PIX_FMT_NONE if no known equivalent was found. -- 2.42.0 _______________________________________________ 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".