diff mbox series

[FFmpeg-devel,3/5] avfilter/hwupload: move hwctx init to init()

Message ID 20240209145349.104511-3-ffmpeg@haasn.xyz
State New
Headers show
Series [FFmpeg-devel,1/5] avfilter: tighten semantics on hw_device_ctx | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Niklas Haas Feb. 9, 2024, 2:53 p.m. UTC
From: Niklas Haas <git@haasn.dev>

---
 libavfilter/vf_hwupload.c | 49 ++++++++++++++++++++++-----------------
 1 file changed, 28 insertions(+), 21 deletions(-)

Comments

Anton Khirnov Feb. 9, 2024, 5:17 p.m. UTC | #1
Quoting Niklas Haas (2024-02-09 15:53:47)
> From: Niklas Haas <git@haasn.dev>
> 
> ---
>  libavfilter/vf_hwupload.c | 49 ++++++++++++++++++++++-----------------
>  1 file changed, 28 insertions(+), 21 deletions(-)

LGTM
diff mbox series

Patch

diff --git a/libavfilter/vf_hwupload.c b/libavfilter/vf_hwupload.c
index ef61bb4137..bc1e32af1a 100644
--- a/libavfilter/vf_hwupload.c
+++ b/libavfilter/vf_hwupload.c
@@ -39,35 +39,41 @@  typedef struct HWUploadContext {
     char *device_type;
 } HWUploadContext;
 
-static int hwupload_query_formats(AVFilterContext *avctx)
+static av_cold int hwupload_init(AVFilterContext *avctx)
 {
     HWUploadContext *ctx = avctx->priv;
-    AVHWFramesConstraints *constraints = NULL;
-    const enum AVPixelFormat *input_pix_fmts, *output_pix_fmts;
-    AVFilterFormats *input_formats = NULL;
-    int err, i;
+    int err;
 
-    if (ctx->hwdevice_ref) {
-        /* We already have a specified device. */
-    } else if (avctx->hw_device_ctx) {
-        if (ctx->device_type) {
-            err = av_hwdevice_ctx_create_derived(
-                &ctx->hwdevice_ref,
-                av_hwdevice_find_type_by_name(ctx->device_type),
-                avctx->hw_device_ctx, 0);
-            if (err < 0)
-                return err;
-        } else {
-            ctx->hwdevice_ref = av_buffer_ref(avctx->hw_device_ctx);
-            if (!ctx->hwdevice_ref)
-                return AVERROR(ENOMEM);
-        }
-    } else {
+    if (!avctx->hw_device_ctx) {
         av_log(ctx, AV_LOG_ERROR, "A hardware device reference is required "
                "to upload frames to.\n");
         return AVERROR(EINVAL);
     }
 
+    if (ctx->device_type) {
+        err = av_hwdevice_ctx_create_derived(
+            &ctx->hwdevice_ref,
+            av_hwdevice_find_type_by_name(ctx->device_type),
+            avctx->hw_device_ctx, 0);
+        if (err < 0)
+            return err;
+    } else {
+        ctx->hwdevice_ref = av_buffer_ref(avctx->hw_device_ctx);
+        if (!ctx->hwdevice_ref)
+            return AVERROR(ENOMEM);
+    }
+
+    return 0;
+}
+
+static int hwupload_query_formats(AVFilterContext *avctx)
+{
+    HWUploadContext *ctx = avctx->priv;
+    AVHWFramesConstraints *constraints = NULL;
+    const enum AVPixelFormat *input_pix_fmts, *output_pix_fmts;
+    AVFilterFormats *input_formats = NULL;
+    int err, i;
+
     constraints = av_hwdevice_get_hwframe_constraints(ctx->hwdevice_ref, NULL);
     if (!constraints) {
         err = AVERROR(EINVAL);
@@ -251,6 +257,7 @@  static const AVFilterPad hwupload_outputs[] = {
 const AVFilter ff_vf_hwupload = {
     .name          = "hwupload",
     .description   = NULL_IF_CONFIG_SMALL("Upload a normal frame to a hardware frame"),
+    .init          = hwupload_init,
     .uninit        = hwupload_uninit,
     .priv_size     = sizeof(HWUploadContext),
     .priv_class    = &hwupload_class,