[FFmpeg-devel] [PATCH 3/5] avcodec/videotoolbox: deprecate creating AVVideotoolboxContext by user
Zhao Zhili
quinkblack at foxmail.com
Mon Jan 9 14:50:06 EET 2023
From: Zhao Zhili <zhilizhao at tencent.com>
---
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 */
+
/**
* @}
*/
--
2.35.3
More information about the ffmpeg-devel
mailing list