Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Niklas Haas <ffmpeg@haasn.xyz>
To: ffmpeg-devel@ffmpeg.org
Cc: Niklas Haas <git@haasn.dev>
Subject: [FFmpeg-devel] [PATCH 5/5] avfilter/vsrc_ddagrab: move hwctx init to init()
Date: Fri,  9 Feb 2024 15:53:49 +0100
Message-ID: <20240209145349.104511-5-ffmpeg@haasn.xyz> (raw)
In-Reply-To: <20240209145349.104511-1-ffmpeg@haasn.xyz>

From: Niklas Haas <git@haasn.dev>

Not as strongly motivated as the previous commits, but there's still no
reason to do this from config_props if we can avoid it.
---
 libavfilter/vsrc_ddagrab.c | 99 ++++++++++++++++++--------------------
 1 file changed, 48 insertions(+), 51 deletions(-)

diff --git a/libavfilter/vsrc_ddagrab.c b/libavfilter/vsrc_ddagrab.c
index 51e928d785..c89eff6e5a 100644
--- a/libavfilter/vsrc_ddagrab.c
+++ b/libavfilter/vsrc_ddagrab.c
@@ -445,7 +445,54 @@ static av_cold int ddagrab_init(AVFilterContext *avctx)
     dda->mouse_x = -1;
     dda->mouse_y = -1;
 
-    return 0;
+    /* Init hardware context */
+    if (avctx->hw_device_ctx) {
+        dda->device_ctx = (AVHWDeviceContext*)avctx->hw_device_ctx->data;
+
+        if (dda->device_ctx->type != AV_HWDEVICE_TYPE_D3D11VA) {
+            av_log(avctx, AV_LOG_ERROR, "Non-D3D11VA input hw_device_ctx\n");
+            return AVERROR(EINVAL);
+        }
+
+        dda->device_ref = av_buffer_ref(avctx->hw_device_ctx);
+        if (!dda->device_ref)
+            return AVERROR(ENOMEM);
+
+        av_log(avctx, AV_LOG_VERBOSE, "Using provided hw_device_ctx\n");
+    } else {
+        ret = av_hwdevice_ctx_create(&dda->device_ref, AV_HWDEVICE_TYPE_D3D11VA, NULL, NULL, 0);
+        if (ret < 0) {
+            av_log(avctx, AV_LOG_ERROR, "Failed to create D3D11VA device.\n");
+            return ret;
+        }
+
+        dda->device_ctx = (AVHWDeviceContext*)dda->device_ref->data;
+
+        av_log(avctx, AV_LOG_VERBOSE, "Created internal hw_device_ctx\n");
+    }
+
+    dda->device_hwctx = (AVD3D11VADeviceContext*)dda->device_ctx->hwctx;
+
+    ret = init_dxgi_dda(avctx);
+    if (ret < 0)
+        return ret;
+
+    ret = probe_output_format(avctx);
+    if (ret < 0)
+        return ret;
+
+    if (dda->out_fmt && dda->raw_format != dda->out_fmt && (!dda->allow_fallback || dda->force_fmt)) {
+        av_log(avctx, AV_LOG_ERROR, "Requested output format unavailable.\n");
+        return AVERROR(ENOTSUP);
+    }
+
+    if (dda->draw_mouse) {
+        ret = init_render_resources(avctx);
+        if (ret < 0)
+            return ret;
+    }
+
+    return init_hwframes_ctx(avctx);
 }
 
 static int create_d3d11_pointer_tex(AVFilterContext *avctx,
@@ -814,46 +861,6 @@ static int ddagrab_config_props(AVFilterLink *outlink)
     DdagrabContext *dda = avctx->priv;
     int ret;
 
-    if (avctx->hw_device_ctx) {
-        dda->device_ctx = (AVHWDeviceContext*)avctx->hw_device_ctx->data;
-
-        if (dda->device_ctx->type != AV_HWDEVICE_TYPE_D3D11VA) {
-            av_log(avctx, AV_LOG_ERROR, "Non-D3D11VA input hw_device_ctx\n");
-            return AVERROR(EINVAL);
-        }
-
-        dda->device_ref = av_buffer_ref(avctx->hw_device_ctx);
-        if (!dda->device_ref)
-            return AVERROR(ENOMEM);
-
-        av_log(avctx, AV_LOG_VERBOSE, "Using provided hw_device_ctx\n");
-    } else {
-        ret = av_hwdevice_ctx_create(&dda->device_ref, AV_HWDEVICE_TYPE_D3D11VA, NULL, NULL, 0);
-        if (ret < 0) {
-            av_log(avctx, AV_LOG_ERROR, "Failed to create D3D11VA device.\n");
-            return ret;
-        }
-
-        dda->device_ctx = (AVHWDeviceContext*)dda->device_ref->data;
-
-        av_log(avctx, AV_LOG_VERBOSE, "Created internal hw_device_ctx\n");
-    }
-
-    dda->device_hwctx = (AVD3D11VADeviceContext*)dda->device_ctx->hwctx;
-
-    ret = init_dxgi_dda(avctx);
-    if (ret < 0)
-        return ret;
-
-    ret = probe_output_format(avctx);
-    if (ret < 0)
-        return ret;
-
-    if (dda->out_fmt && dda->raw_format != dda->out_fmt && (!dda->allow_fallback || dda->force_fmt)) {
-        av_log(avctx, AV_LOG_ERROR, "Requested output format unavailable.\n");
-        return AVERROR(ENOTSUP);
-    }
-
     dda->width -= FFMAX(dda->width - dda->raw_width + dda->offset_x, 0);
     dda->height -= FFMAX(dda->height - dda->raw_height + dda->offset_y, 0);
 
@@ -861,16 +868,6 @@ static int ddagrab_config_props(AVFilterLink *outlink)
     dda->time_frame = av_gettime_relative() / av_q2d(dda->time_base);
     dda->time_timeout = av_rescale_q(1, dda->time_base, (AVRational) { 1, 1000 }) / 2;
 
-    if (dda->draw_mouse) {
-        ret = init_render_resources(avctx);
-        if (ret < 0)
-            return ret;
-    }
-
-    ret = init_hwframes_ctx(avctx);
-    if (ret < 0)
-        return ret;
-
     outlink->hw_frames_ctx = av_buffer_ref(dda->frames_ref);
     if (!outlink->hw_frames_ctx)
         return AVERROR(ENOMEM);
-- 
2.43.0

_______________________________________________
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".

  parent reply	other threads:[~2024-02-09 14:54 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-09 14:53 [FFmpeg-devel] [PATCH 1/5] avfilter: tighten semantics on hw_device_ctx Niklas Haas
2024-02-09 14:53 ` [FFmpeg-devel] [PATCH 2/5] fftools/ffmpeg_filter: provide hwctx when probing graph Niklas Haas
2024-02-09 17:12   ` Anton Khirnov
2024-02-09 14:53 ` [FFmpeg-devel] [PATCH 3/5] avfilter/hwupload: move hwctx init to init() Niklas Haas
2024-02-09 17:17   ` Anton Khirnov
2024-02-09 14:53 ` [FFmpeg-devel] [PATCH 4/5] avfilter/libplacebo: " Niklas Haas
2024-02-09 14:53 ` Niklas Haas [this message]
2024-02-09 16:53 ` [FFmpeg-devel] [PATCH 1/5] avfilter: tighten semantics on hw_device_ctx Anton Khirnov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240209145349.104511-5-ffmpeg@haasn.xyz \
    --to=ffmpeg@haasn.xyz \
    --cc=ffmpeg-devel@ffmpeg.org \
    --cc=git@haasn.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git