1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2025-08-10 06:10:52 +02:00

avcodec/videotoolbox: deprecate creating AVVideotoolboxContext by user

Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
This commit is contained in:
Zhao Zhili
2023-01-09 20:50:06 +08:00
parent ade89bc6de
commit d6bd980da6
3 changed files with 33 additions and 15 deletions

View File

@@ -52,6 +52,7 @@
#define FF_API_SVTAV1_OPTS (LIBAVCODEC_VERSION_MAJOR < 60) #define FF_API_SVTAV1_OPTS (LIBAVCODEC_VERSION_MAJOR < 60)
#define FF_API_AYUV_CODECID (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_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) #define FF_API_AVCODEC_CHROMA_POS (LIBAVCODEC_VERSION_MAJOR < 60)
#endif /* AVCODEC_VERSION_MAJOR_H */ #endif /* AVCODEC_VERSION_MAJOR_H */

View File

@@ -1173,6 +1173,22 @@ static enum AVPixelFormat videotoolbox_best_pixel_format(AVCodecContext *avctx)
return AV_PIX_FMT_NV12; 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) int ff_videotoolbox_common_init(AVCodecContext *avctx)
{ {
VTContext *vtctx = avctx->internal->hwaccel_priv_data; VTContext *vtctx = avctx->internal->hwaccel_priv_data;
@@ -1191,7 +1207,7 @@ int ff_videotoolbox_common_init(AVCodecContext *avctx)
return AVERROR(EINVAL); 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) { if (!vtctx->vt_ctx) {
err = AVERROR(ENOMEM); err = AVERROR(ENOMEM);
goto fail; goto fail;
@@ -1371,22 +1387,9 @@ const AVHWAccel ff_prores_videotoolbox_hwaccel = {
.priv_data_size = sizeof(VTContext), .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) AVVideotoolboxContext *av_videotoolbox_alloc_context(void)
{ {
return av_videotoolbox_alloc_context_with_pix_fmt(AV_PIX_FMT_NONE, false); 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); videotoolbox_stop(avctx);
av_freep(&avctx->hwaccel_context); av_freep(&avctx->hwaccel_context);
} }
#endif /* FF_API_VT_HWACCEL_CONTEXT */
#endif /* CONFIG_VIDEOTOOLBOX */ #endif /* CONFIG_VIDEOTOOLBOX */

View File

@@ -90,6 +90,8 @@ typedef struct AVVideotoolboxContext {
int cm_codec_type; int cm_codec_type;
} AVVideotoolboxContext; } AVVideotoolboxContext;
#if FF_API_VT_HWACCEL_CONTEXT
/** /**
* Allocate and initialize a Videotoolbox context. * Allocate and initialize a Videotoolbox context.
* *
@@ -102,7 +104,9 @@ typedef struct AVVideotoolboxContext {
* object and free the Videotoolbox context using av_free(). * object and free the Videotoolbox context using av_free().
* *
* @return the newly allocated context or NULL on failure * @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); AVVideotoolboxContext *av_videotoolbox_alloc_context(void);
/** /**
@@ -112,7 +116,9 @@ AVVideotoolboxContext *av_videotoolbox_alloc_context(void);
* @param avctx the corresponding codec context * @param avctx the corresponding codec context
* *
* @return >= 0 on success, a negative AVERROR code on failure * @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); 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 * @param vtctx the Videotoolbox context to use
* *
* @return >= 0 on success, a negative AVERROR code on failure * @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); 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(). * av_videotoolbox_default_init().
* *
* @param avctx the corresponding codec context * @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); void av_videotoolbox_default_free(AVCodecContext *avctx);
#endif /* FF_API_VT_HWACCEL_CONTEXT */
/** /**
* @} * @}
*/ */