From patchwork Mon Jan 9 12:50:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhao Zhili X-Patchwork-Id: 39941 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:bc95:b0:ad:ade2:bfd2 with SMTP id fx21csp3065747pzb; Mon, 9 Jan 2023 04:50:36 -0800 (PST) X-Google-Smtp-Source: AMrXdXsqR/LTGqfU2ya7N2ZlRnyhMyZzRF43VSOLfltWpdWAkPWbVwXcIQVv23lh1e8oLy0vhICm X-Received: by 2002:a17:907:9b06:b0:83f:8e58:6427 with SMTP id kn6-20020a1709079b0600b0083f8e586427mr54208611ejc.63.1673268636542; Mon, 09 Jan 2023 04:50:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673268636; cv=none; d=google.com; s=arc-20160816; b=GRTBDzmQ1DyWTIFDraBn+qRCodtp16rrbFEIoyMC+D52mrGiLobYChCpxCgVqwhs+L Y/2UZ4Sudy+oTGKgtwzU3H+DPqaS1tiM06imgXexCaWEqVvYp52SJQDmEhDRH5I/conS KzEgeL1Q6MYIl3G/CnBx8+C/SxoaKBJIZxIebJTV9nheV3dN2FVfp2RZ4KJRJXHRot8U esafK42OIIuMHHFp3Fy2LBishqanq02lvzT6JLKkQRWLOSVsQzPWShgxiQJP5MEUqdRP yRSMjXPW1cQIMTI3/Vm1pP0fPNOik/ayVuCpV7mICFYq4awEu2VNaUutZwWP7NqK4Ryo zMDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to:date :to:from:message-id:dkim-signature:delivered-to; bh=BD3xBA1vQMAvwkNGj+QMX1AxdmgKSuHNUNflxFMJyLo=; b=GoGHXlhct8qbN4SrDe+lgJgsJSCM6MGa9tTgRtaIDSTapUseIEqWgT9hPtBbtgLDJg XE8Hn6g17F6nBnFUsnEvf7ChFZVidasZb7Mzd8SlQ+PBjmOu4JDatq7hU+ZPVovGuyjm GWot+nMZn5EQZYjY0YAao4WvENu3tT7pkW1pjdcLVXOdkvZ9DtkraFzCOik0/Od5CW+b ljyA29ge4z6qWHwqWj1/2L/2N1TEMrBg5m8mFXzsmtJt5CTIpA5RKoFJ4jbIY29YBHZK 8qQwc0KcGFAj7y7pEm1MSV1lYTBph8m8BNJgoQ+Tp/CUDvL9123cQ9hzhF6bzer3tvay DriA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@foxmail.com header.s=s201512 header.b=zJxo9voD; 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=NONE dis=NONE) header.from=foxmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id a21-20020a1709066d5500b007add8160fd9si6933393ejt.765.2023.01.09.04.50.36; Mon, 09 Jan 2023 04:50:36 -0800 (PST) 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=@foxmail.com header.s=s201512 header.b=zJxo9voD; 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=NONE dis=NONE) header.from=foxmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id DAD1C68BD03; Mon, 9 Jan 2023 14:50:23 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from out162-62-57-252.mail.qq.com (out162-62-57-252.mail.qq.com [162.62.57.252]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6784968BCCD for ; Mon, 9 Jan 2023 14:50:16 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foxmail.com; s=s201512; t=1673268612; bh=WmzlHax//eSYjDOOErYRm+t+D+BZdVx9rc7Gwk78zew=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=zJxo9voDv1cjei+z9XKE7Ne9iPoBa/idYZJ2muP7yb0aA8w0EdTMGVhhxIH50nSvN 2hOlqtNLTPaOpHjauwAOeRKt+Rb/Ub6GxFo0cIvNrWEB0rh/lSnhgldIUVysgR2ryP bsIpd689qCMCWmUfdpQDIb8zzhaJcmQc9GY4VJLM= Received: from ZHILIZHAO-MB2.tencent.com ([119.147.10.192]) by newxmesmtplogicsvrszc5-0.qq.com (NewEsmtp) with SMTP id C898A4CD; Mon, 09 Jan 2023 20:50:09 +0800 X-QQ-mid: xmsmtpt1673268612tgn8u8g6l Message-ID: X-QQ-XMAILINFO: NkHKfw09D6j8cg1OayiKssWwlBa1+bV3bi25a1TJ9FI1e5Doz0GWHV9wKfJzuM huGwFVyP4WA76f1dLwy6L5qBnXPGbhoNQUwfKC1yV7NOQnLCP8xk1QFFOGfpIZ1QxE7fv8IEoxJH XKM8Wk/AAGvYNG/F7y7MwG6gdaqesDYMlFxhB5UBRqr4GlTTZF4C5KloDf2cPSGa2trMyhEiOBeb aI6MV/Awm0F2Rpm/Vvz52EM/Y/zClTBWqJe0X1wQojPjfmJ0z9+/SS48GcWljkAeB1UvPBo+jvhl dihPoXJtJZLqPSlnmCMjVaRSH46INvgJiBi5+Ms1yR6i6y5mOdgphQSvLe3wAx0rmqnL1pT1tVXP 6/MxV0M+IAlwNf4/zmbwbHR67P1DHJZDBU+DYHv5dC1d4FuNvLjtty7BBy5rN/7IMHjqFDlU0c/v JyK+xbQDSh3DV5sN1tP8Fk9+kMMl1st6wFG/ThG5e/b2rPZFhcP3QbJv/jxM0kmpS3VF8rboiXwA 3ltYvqxrGMQ4mHG9QR/cdz9L6RXRt/a+jb3W3VjLEs6V8c5YO6zqY7BGaZKdZ3YWrUxTJm4X08x0 +hJG3oO2s9waaOujHH/NKOCp+flfcwibUh2hlC2nTbOJX9qB/CvpH+4MkiWQw7qE1pu9COLNhRdh bazgEOnJPOQU6vH6IwOIFbv6o5ZxTKugmKLDuhmbaduxt/lEBzDPPcbDsjpmsIuftAVF6uTpua0s D6zWb1SjYLbc/qGNUz5IdOJDkJ0y0IceOyiMeKyQJvICvsuVlq4aCx0jvQy7oDgF3XRMS7WAv6xS JVbABQCibRigfBmYdECinaBPDHCzrUuBWHWya+QmfTDAKSE4gN9HCEfEM/AQ7g2MU2mLnBQjC11u 863eQL2uH1JTj+yJIEuHiZB5+IfyFGafdUSoaxUyNYhI/Y6X/XxxcjXg+HTLZOkZFXa+mmZugvgB ElDhqgoO1EDmhQ/4E7diUfo0m1XLfYWvjEzRvS5HwO5R+v9iW5voTzpFtPheBvSDWg3ZJYDcEr0Y YU+WrpuSTmnDHiWhE4 From: Zhao Zhili To: ffmpeg-devel@ffmpeg.org Date: Mon, 9 Jan 2023 20:50:06 +0800 X-OQ-MSGID: <20230109125008.13336-4-quinkblack@foxmail.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230109125008.13336-1-quinkblack@foxmail.com> References: <20230109125008.13336-1-quinkblack@foxmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 3/5] avcodec/videotoolbox: deprecate creating AVVideotoolboxContext by user 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: GYgWRsDf2EPW From: Zhao Zhili --- libavcodec/version_major.h | 1 + libavcodec/videotoolbox.c | 35 ++++++++++++++++++++--------------- libavcodec/videotoolbox.h | 12 ++++++++++++ 3 files changed, 33 insertions(+), 15 deletions(-) diff --git a/libavcodec/version_major.h b/libavcodec/version_major.h index 12f863deb7..2c0443c4c8 100644 --- a/libavcodec/version_major.h +++ b/libavcodec/version_major.h @@ -52,6 +52,7 @@ #define FF_API_SVTAV1_OPTS (LIBAVCODEC_VERSION_MAJOR < 60) #define FF_API_AYUV_CODECID (LIBAVCODEC_VERSION_MAJOR < 60) #define FF_API_VT_OUTPUT_CALLBACK (LIBAVCODEC_VERSION_MAJOR < 60) +#define FF_API_VT_HWACCEL_CONTEXT (LIBAVCODEC_VERSION_MAJOR < 60) #define FF_API_AVCODEC_CHROMA_POS (LIBAVCODEC_VERSION_MAJOR < 60) #endif /* AVCODEC_VERSION_MAJOR_H */ diff --git a/libavcodec/videotoolbox.c b/libavcodec/videotoolbox.c index acf0c79822..a3d19c4c63 100644 --- a/libavcodec/videotoolbox.c +++ b/libavcodec/videotoolbox.c @@ -1173,6 +1173,22 @@ static enum AVPixelFormat videotoolbox_best_pixel_format(AVCodecContext *avctx) return AV_PIX_FMT_NV12; } +static AVVideotoolboxContext *av_videotoolbox_alloc_context_with_pix_fmt(enum AVPixelFormat pix_fmt, + bool full_range) +{ + AVVideotoolboxContext *ret = av_mallocz(sizeof(*ret)); + + if (ret) { + OSType cv_pix_fmt_type = av_map_videotoolbox_format_from_pixfmt2(pix_fmt, full_range); + if (cv_pix_fmt_type == 0) { + cv_pix_fmt_type = kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange; + } + ret->cv_pix_fmt_type = cv_pix_fmt_type; + } + + return ret; +} + int ff_videotoolbox_common_init(AVCodecContext *avctx) { VTContext *vtctx = avctx->internal->hwaccel_priv_data; @@ -1191,7 +1207,7 @@ int ff_videotoolbox_common_init(AVCodecContext *avctx) return AVERROR(EINVAL); } - vtctx->vt_ctx = av_videotoolbox_alloc_context(); + vtctx->vt_ctx = av_videotoolbox_alloc_context_with_pix_fmt(AV_PIX_FMT_NONE, false); if (!vtctx->vt_ctx) { err = AVERROR(ENOMEM); goto fail; @@ -1371,22 +1387,9 @@ const AVHWAccel ff_prores_videotoolbox_hwaccel = { .priv_data_size = sizeof(VTContext), }; -static AVVideotoolboxContext *av_videotoolbox_alloc_context_with_pix_fmt(enum AVPixelFormat pix_fmt, - bool full_range) -{ - AVVideotoolboxContext *ret = av_mallocz(sizeof(*ret)); - if (ret) { - OSType cv_pix_fmt_type = av_map_videotoolbox_format_from_pixfmt2(pix_fmt, full_range); - if (cv_pix_fmt_type == 0) { - cv_pix_fmt_type = kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange; - } - ret->cv_pix_fmt_type = cv_pix_fmt_type; - } - - return ret; -} +#if FF_API_VT_HWACCEL_CONTEXT AVVideotoolboxContext *av_videotoolbox_alloc_context(void) { return av_videotoolbox_alloc_context_with_pix_fmt(AV_PIX_FMT_NONE, false); @@ -1413,4 +1416,6 @@ void av_videotoolbox_default_free(AVCodecContext *avctx) videotoolbox_stop(avctx); av_freep(&avctx->hwaccel_context); } +#endif /* FF_API_VT_HWACCEL_CONTEXT */ + #endif /* CONFIG_VIDEOTOOLBOX */ diff --git a/libavcodec/videotoolbox.h b/libavcodec/videotoolbox.h index 25a747a49f..3cd1d254ff 100644 --- a/libavcodec/videotoolbox.h +++ b/libavcodec/videotoolbox.h @@ -90,6 +90,8 @@ typedef struct AVVideotoolboxContext { int cm_codec_type; } AVVideotoolboxContext; +#if FF_API_VT_HWACCEL_CONTEXT + /** * Allocate and initialize a Videotoolbox context. * @@ -102,7 +104,9 @@ typedef struct AVVideotoolboxContext { * object and free the Videotoolbox context using av_free(). * * @return the newly allocated context or NULL on failure + * @deprecated Use AVCodecContext.hw_frames_ctx or hw_device_ctx instead. */ +attribute_deprecated AVVideotoolboxContext *av_videotoolbox_alloc_context(void); /** @@ -112,7 +116,9 @@ AVVideotoolboxContext *av_videotoolbox_alloc_context(void); * @param avctx the corresponding codec context * * @return >= 0 on success, a negative AVERROR code on failure + * @deprecated Use AVCodecContext.hw_frames_ctx or hw_device_ctx instead. */ +attribute_deprecated int av_videotoolbox_default_init(AVCodecContext *avctx); /** @@ -123,7 +129,9 @@ int av_videotoolbox_default_init(AVCodecContext *avctx); * @param vtctx the Videotoolbox context to use * * @return >= 0 on success, a negative AVERROR code on failure + * @deprecated Use AVCodecContext.hw_frames_ctx or hw_device_ctx instead. */ +attribute_deprecated int av_videotoolbox_default_init2(AVCodecContext *avctx, AVVideotoolboxContext *vtctx); /** @@ -131,9 +139,13 @@ int av_videotoolbox_default_init2(AVCodecContext *avctx, AVVideotoolboxContext * * av_videotoolbox_default_init(). * * @param avctx the corresponding codec context + * @deprecated Use AVCodecContext.hw_frames_ctx or hw_device_ctx instead. */ +attribute_deprecated void av_videotoolbox_default_free(AVCodecContext *avctx); +#endif /* FF_API_VT_HWACCEL_CONTEXT */ + /** * @} */