* [FFmpeg-devel] [PATCH 2/5] avcodec/videotoolbox: prefer hw_frames_ctx/hw_device_ctx over hwaccel_context
[not found] <20230109125008.13336-1-quinkblack@foxmail.com>
@ 2023-01-09 12:50 ` Zhao Zhili
2023-01-09 12:50 ` [FFmpeg-devel] [PATCH 3/5] avcodec/videotoolbox: deprecate create AVVideotoolboxContext by user Zhao Zhili
` (3 subsequent siblings)
4 siblings, 0 replies; 5+ messages in thread
From: Zhao Zhili @ 2023-01-09 12:50 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Zhao Zhili
From: Zhao Zhili <zhilizhao@tencent.com>
---
libavcodec/videotoolbox.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/libavcodec/videotoolbox.c b/libavcodec/videotoolbox.c
index a18b49007d..acf0c79822 100644
--- a/libavcodec/videotoolbox.c
+++ b/libavcodec/videotoolbox.c
@@ -1181,7 +1181,8 @@ int ff_videotoolbox_common_init(AVCodecContext *avctx)
vtctx->logctx = avctx;
- if (avctx->hwaccel_context)
+ if (!avctx->hw_frames_ctx && !avctx->hw_device_ctx &&
+ avctx->hwaccel_context)
return videotoolbox_start(avctx);
if (!avctx->hw_frames_ctx && !avctx->hw_device_ctx) {
--
2.35.3
_______________________________________________
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".
^ permalink raw reply [flat|nested] 5+ messages in thread
* [FFmpeg-devel] [PATCH 3/5] avcodec/videotoolbox: deprecate create AVVideotoolboxContext by user
[not found] <20230109125008.13336-1-quinkblack@foxmail.com>
2023-01-09 12:50 ` [FFmpeg-devel] [PATCH 2/5] avcodec/videotoolbox: prefer hw_frames_ctx/hw_device_ctx over hwaccel_context Zhao Zhili
@ 2023-01-09 12:50 ` Zhao Zhili
2023-01-09 12:50 ` [FFmpeg-devel] [PATCH 3/5] avcodec/videotoolbox: deprecate creating " Zhao Zhili
` (2 subsequent siblings)
4 siblings, 0 replies; 5+ messages in thread
From: Zhao Zhili @ 2023-01-09 12:50 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Zhao Zhili
From: Zhao Zhili <zhilizhao@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
_______________________________________________
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".
^ permalink raw reply [flat|nested] 5+ messages in thread
* [FFmpeg-devel] [PATCH 3/5] avcodec/videotoolbox: deprecate creating AVVideotoolboxContext by user
[not found] <20230109125008.13336-1-quinkblack@foxmail.com>
2023-01-09 12:50 ` [FFmpeg-devel] [PATCH 2/5] avcodec/videotoolbox: prefer hw_frames_ctx/hw_device_ctx over hwaccel_context Zhao Zhili
2023-01-09 12:50 ` [FFmpeg-devel] [PATCH 3/5] avcodec/videotoolbox: deprecate create AVVideotoolboxContext by user Zhao Zhili
@ 2023-01-09 12:50 ` Zhao Zhili
2023-01-09 12:50 ` [FFmpeg-devel] [PATCH 4/5] avcodec/videotoolbox: fix documents of AVVideotoolboxContext Zhao Zhili
2023-01-09 12:50 ` [FFmpeg-devel] [PATCH 5/5] avcodec/videotoolbox: don't use av_ prefix for local function Zhao Zhili
4 siblings, 0 replies; 5+ messages in thread
From: Zhao Zhili @ 2023-01-09 12:50 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Zhao Zhili
From: Zhao Zhili <zhilizhao@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
_______________________________________________
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".
^ permalink raw reply [flat|nested] 5+ messages in thread
* [FFmpeg-devel] [PATCH 4/5] avcodec/videotoolbox: fix documents of AVVideotoolboxContext
[not found] <20230109125008.13336-1-quinkblack@foxmail.com>
` (2 preceding siblings ...)
2023-01-09 12:50 ` [FFmpeg-devel] [PATCH 3/5] avcodec/videotoolbox: deprecate creating " Zhao Zhili
@ 2023-01-09 12:50 ` Zhao Zhili
2023-01-09 12:50 ` [FFmpeg-devel] [PATCH 5/5] avcodec/videotoolbox: don't use av_ prefix for local function Zhao Zhili
4 siblings, 0 replies; 5+ messages in thread
From: Zhao Zhili @ 2023-01-09 12:50 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Zhao Zhili
From: Zhao Zhili <zhilizhao@tencent.com>
Since those fields will be overridden by videotoolbox_start(), they
should never be set by user, it can trigger memory leaks otherwise.
---
libavcodec/videotoolbox.h | 3 ---
1 file changed, 3 deletions(-)
diff --git a/libavcodec/videotoolbox.h b/libavcodec/videotoolbox.h
index 3cd1d254ff..ba5eddbf46 100644
--- a/libavcodec/videotoolbox.h
+++ b/libavcodec/videotoolbox.h
@@ -57,7 +57,6 @@
typedef struct AVVideotoolboxContext {
/**
* Videotoolbox decompression session object.
- * Created and freed the caller.
*/
VTDecompressionSessionRef session;
@@ -79,13 +78,11 @@ typedef struct AVVideotoolboxContext {
/**
* CoreMedia Format Description that Videotoolbox will use to create the decompression session.
- * Set by the caller.
*/
CMVideoFormatDescriptionRef cm_fmt_desc;
/**
* CoreMedia codec type that Videotoolbox will use to create the decompression session.
- * Set by the caller.
*/
int cm_codec_type;
} AVVideotoolboxContext;
--
2.35.3
_______________________________________________
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".
^ permalink raw reply [flat|nested] 5+ messages in thread
* [FFmpeg-devel] [PATCH 5/5] avcodec/videotoolbox: don't use av_ prefix for local function
[not found] <20230109125008.13336-1-quinkblack@foxmail.com>
` (3 preceding siblings ...)
2023-01-09 12:50 ` [FFmpeg-devel] [PATCH 4/5] avcodec/videotoolbox: fix documents of AVVideotoolboxContext Zhao Zhili
@ 2023-01-09 12:50 ` Zhao Zhili
4 siblings, 0 replies; 5+ messages in thread
From: Zhao Zhili @ 2023-01-09 12:50 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Zhao Zhili
From: Zhao Zhili <zhilizhao@tencent.com>
---
libavcodec/videotoolbox.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/libavcodec/videotoolbox.c b/libavcodec/videotoolbox.c
index a3d19c4c63..e42fea6f32 100644
--- a/libavcodec/videotoolbox.c
+++ b/libavcodec/videotoolbox.c
@@ -1173,8 +1173,8 @@ 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)
+static AVVideotoolboxContext *videotoolbox_alloc_context_with_pix_fmt(enum AVPixelFormat pix_fmt,
+ bool full_range)
{
AVVideotoolboxContext *ret = av_mallocz(sizeof(*ret));
@@ -1207,7 +1207,7 @@ int ff_videotoolbox_common_init(AVCodecContext *avctx)
return AVERROR(EINVAL);
}
- vtctx->vt_ctx = av_videotoolbox_alloc_context_with_pix_fmt(AV_PIX_FMT_NONE, false);
+ vtctx->vt_ctx = videotoolbox_alloc_context_with_pix_fmt(AV_PIX_FMT_NONE, false);
if (!vtctx->vt_ctx) {
err = AVERROR(ENOMEM);
goto fail;
@@ -1392,7 +1392,7 @@ const AVHWAccel ff_prores_videotoolbox_hwaccel = {
#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);
+ return videotoolbox_alloc_context_with_pix_fmt(AV_PIX_FMT_NONE, false);
}
int av_videotoolbox_default_init(AVCodecContext *avctx)
@@ -1404,7 +1404,7 @@ int av_videotoolbox_default_init2(AVCodecContext *avctx, AVVideotoolboxContext *
{
enum AVPixelFormat pix_fmt = videotoolbox_best_pixel_format(avctx);
bool full_range = avctx->color_range == AVCOL_RANGE_JPEG;
- avctx->hwaccel_context = vtctx ?: av_videotoolbox_alloc_context_with_pix_fmt(pix_fmt, full_range);
+ avctx->hwaccel_context = vtctx ?: videotoolbox_alloc_context_with_pix_fmt(pix_fmt, full_range);
if (!avctx->hwaccel_context)
return AVERROR(ENOMEM);
return 0;
--
2.35.3
_______________________________________________
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".
^ permalink raw reply [flat|nested] 5+ messages in thread