Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: softworkz <ffmpegagent@gmail.com>
To: ffmpeg-devel@ffmpeg.org
Cc: softworkz <softworkz@hotmail.com>,
	"Xiang, Haihao" <haihao.xiang-at-intel.com@ffmpeg.org>,
	Gyan Doshi <ffmpeg@gyani.pro>
Subject: [FFmpeg-devel] [PATCH v2 04/11] avfilter/overlay_vaapi: handle secondary null input
Date: Mon, 31 Oct 2022 06:20:00 +0000
Message-ID: <fb365de03606f26889a6ed0a7961dc60e80232cd.1667197207.git.ffmpegagent@gmail.com> (raw)
In-Reply-To: <pull.42.v2.ffstaging.FFmpeg.1667197207.ffmpegagent@gmail.com>

From: softworkz <softworkz@hotmail.com>

Currently segfaults in this case.

Signed-off-by: softworkz <softworkz@hotmail.com>
---
 libavfilter/vf_overlay_vaapi.c | 94 ++++++++++++++++++----------------
 1 file changed, 49 insertions(+), 45 deletions(-)

diff --git a/libavfilter/vf_overlay_vaapi.c b/libavfilter/vf_overlay_vaapi.c
index 66e736cce4..1281038c36 100644
--- a/libavfilter/vf_overlay_vaapi.c
+++ b/libavfilter/vf_overlay_vaapi.c
@@ -106,18 +106,6 @@ static int overlay_vaapi_render_picture(AVFilterContext *avctx,
            params_id);
 
 
-    vas = vaCreateBuffer(ctx->hwctx->display, ctx->va_context,
-                         VAProcPipelineParameterBufferType,
-                         sizeof(*subpic_params), 1, subpic_params, &subpic_params_id);
-    if (vas != VA_STATUS_SUCCESS) {
-        av_log(avctx, AV_LOG_ERROR, "Failed to create parameter buffer: "
-               "%d (%s).\n", vas, vaErrorStr(vas));
-        err = AVERROR(EIO);
-        goto fail_after_begin;
-    }
-    av_log(avctx, AV_LOG_DEBUG, "Pipeline subpic parameter buffer is %#x.\n",
-           subpic_params_id);
-
     vas = vaRenderPicture(ctx->hwctx->display, ctx->va_context,
                           &params_id, 1);
     if (vas != VA_STATUS_SUCCESS) {
@@ -127,13 +115,27 @@ static int overlay_vaapi_render_picture(AVFilterContext *avctx,
         goto fail_after_begin;
     }
 
-    vas = vaRenderPicture(ctx->hwctx->display, ctx->va_context,
-                          &subpic_params_id, 1);
-    if (vas != VA_STATUS_SUCCESS) {
-        av_log(avctx, AV_LOG_ERROR, "Failed to render subpic parameter buffer: "
-               "%d (%s).\n", vas, vaErrorStr(vas));
-        err = AVERROR(EIO);
-        goto fail_after_begin;
+    if (subpic_params) {
+        vas = vaCreateBuffer(ctx->hwctx->display, ctx->va_context,
+                             VAProcPipelineParameterBufferType,
+                             sizeof(*subpic_params), 1, subpic_params, &subpic_params_id);
+        if (vas != VA_STATUS_SUCCESS) {
+            av_log(avctx, AV_LOG_ERROR, "Failed to create parameter buffer: "
+                   "%d (%s).\n", vas, vaErrorStr(vas));
+            err = AVERROR(EIO);
+            goto fail_after_begin;
+        }
+        av_log(avctx, AV_LOG_DEBUG, "Pipeline subpic parameter buffer is %#x.\n",
+               subpic_params_id);
+
+        vas = vaRenderPicture(ctx->hwctx->display, ctx->va_context,
+                              &subpic_params_id, 1);
+        if (vas != VA_STATUS_SUCCESS) {
+            av_log(avctx, AV_LOG_ERROR, "Failed to render subpic parameter buffer: "
+                   "%d (%s).\n", vas, vaErrorStr(vas));
+            err = AVERROR(EIO);
+            goto fail_after_begin;
+        }
     }
 
     vas = vaEndPicture(ctx->hwctx->display, ctx->va_context);
@@ -177,7 +179,7 @@ static int overlay_vaapi_blend(FFFrameSync *fs)
     AVFrame *input_main, *input_overlay;
     AVFrame *output;
     VAProcPipelineParameterBuffer params, subpic_params;
-    VABlendState blend_state; /**< Blend State */
+    VABlendState blend_state = { 0 }; /**< Blend State */
     VARectangle overlay_region, output_region;
     int err;
 
@@ -192,10 +194,6 @@ static int overlay_vaapi_blend(FFFrameSync *fs)
            av_get_pix_fmt_name(input_main->format),
            input_main->width, input_main->height, input_main->pts);
 
-    av_log(avctx, AV_LOG_DEBUG, "Filter overlay: %s, %ux%u (%"PRId64").\n",
-           av_get_pix_fmt_name(input_overlay->format),
-           input_overlay->width, input_overlay->height, input_overlay->pts);
-
     if (vpp_ctx->va_context == VA_INVALID_ID)
         return AVERROR(EINVAL);
 
@@ -214,13 +212,6 @@ static int overlay_vaapi_blend(FFFrameSync *fs)
     if (err < 0)
         goto fail;
 
-    overlay_region = (VARectangle) {
-        .x      = ctx->overlay_ox,
-        .y      = ctx->overlay_oy,
-        .width  = ctx->overlay_ow ? ctx->overlay_ow : input_overlay->width,
-        .height = ctx->overlay_oh ? ctx->overlay_oh : input_overlay->height,
-    };
-
     output_region = (VARectangle) {
         .x      = 0,
         .y      = 0,
@@ -228,29 +219,42 @@ static int overlay_vaapi_blend(FFFrameSync *fs)
         .height = output->height,
     };
 
-    if (overlay_region.x + overlay_region.width > input_main->width ||
-        overlay_region.y + overlay_region.height > input_main->height) {
-        av_log(ctx, AV_LOG_WARNING,
-               "The overlay image exceeds the scope of the main image, "
-               "will crop the overlay image according based on the main image.\n");
-    }
-
     params.filters     = &vpp_ctx->filter_buffers[0];
     params.num_filters = vpp_ctx->nb_filter_buffers;
 
     params.output_region = &output_region;
     params.output_background_color = VAAPI_VPP_BACKGROUND_BLACK;
 
-    memcpy(&subpic_params, &params, sizeof(subpic_params));
+    if (input_overlay) {
+        av_log(avctx, AV_LOG_DEBUG, "Filter overlay: %s, %ux%u (%"PRId64").\n",
+               av_get_pix_fmt_name(input_overlay->format),
+               input_overlay->width, input_overlay->height, input_overlay->pts);
+
+        overlay_region = (VARectangle) {
+            .x      = ctx->overlay_ox,
+            .y      = ctx->overlay_oy,
+            .width  = ctx->overlay_ow ? ctx->overlay_ow : input_overlay->width,
+            .height = ctx->overlay_oh ? ctx->overlay_oh : input_overlay->height,
+        };
+
+        if (overlay_region.x + overlay_region.width > input_main->width ||
+            overlay_region.y + overlay_region.height > input_main->height) {
+            av_log(ctx, AV_LOG_WARNING,
+                   "The overlay image exceeds the scope of the main image, "
+                   "will crop the overlay image according based on the main image.\n");
+        }
+
+        memcpy(&subpic_params, &params, sizeof(subpic_params));
 
-    blend_state.flags = VA_BLEND_GLOBAL_ALPHA;
-    blend_state.global_alpha = ctx->alpha;
-    subpic_params.blend_state = &blend_state;
+        blend_state.flags         = VA_BLEND_GLOBAL_ALPHA;
+        blend_state.global_alpha  = ctx->alpha;
+        subpic_params.blend_state = &blend_state;
 
-    subpic_params.surface = (VASurfaceID)(uintptr_t)input_overlay->data[3];
-    subpic_params.output_region = &overlay_region;
+        subpic_params.surface       = (VASurfaceID)(uintptr_t)input_overlay->data[3];
+        subpic_params.output_region = &overlay_region;
+    }
 
-    err = overlay_vaapi_render_picture(avctx, &params, &subpic_params, output);
+    err = overlay_vaapi_render_picture(avctx, &params, input_overlay ? &subpic_params : NULL, output);
     if (err < 0)
         goto fail;
 
-- 
ffmpeg-codebot

_______________________________________________
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:[~2022-10-31  6:21 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-10 10:54 [FFmpeg-devel] [PATCH 00/11] Fixes and Enhancements for VAAPI Overlay ffmpegagent
2022-10-10 10:54 ` [FFmpeg-devel] [PATCH 01/11] avfilter/overlay_vaapi: use FILTER_SINGLE_PIXFMT softworkz
2022-10-31  5:55   ` Xiang, Haihao
2022-10-10 10:54 ` [FFmpeg-devel] [PATCH 02/11] avfilter/overlay_vaapi: build filter params just once softworkz
2022-10-10 10:54 ` [FFmpeg-devel] [PATCH 03/11] avfilter/overlay_vaapi: remove double framesync init softworkz
2022-10-10 10:54 ` [FFmpeg-devel] [PATCH 04/11] avfilter/overlay_vaapi: handle secondary null input softworkz
2022-10-10 10:54 ` [FFmpeg-devel] [PATCH 05/11] avfilter/overlay_vaapi: reformat options softworkz
2022-10-10 10:54 ` [FFmpeg-devel] [PATCH 06/11] avfilter/overlay_vaapi: remove redundant .get_buffer assignments softworkz
2022-10-10 10:54 ` [FFmpeg-devel] [PATCH 07/11] avfilter/overlay_vaapi: add framesync options softworkz
2022-10-10 10:54 ` [FFmpeg-devel] [PATCH 08/11] avfilter/overlay_vaapi: precalculate blend_state, enable pixel alpha softworkz
2022-10-10 10:54 ` [FFmpeg-devel] [PATCH 09/11] avfilter/overlay_vaapi: enable expressions for overlay parameters softworkz
2022-10-31  5:43   ` Xiang, Haihao
2022-10-31  5:56     ` Soft Works
2022-10-10 10:54 ` [FFmpeg-devel] [PATCH 10/11] doc/filters.texi: remove incorrect statement softworkz
2022-10-10 10:54 ` [FFmpeg-devel] [PATCH 11/11] doc/filters.texi: update overlay_vaapi documentation softworkz
2022-10-10 11:08   ` Gyan Doshi
2022-10-10 11:25     ` Soft Works
2022-10-31  6:19 ` [FFmpeg-devel] [PATCH v2 00/11] Fixes and Enhancements for VAAPI Overlay ffmpegagent
2022-10-31  6:19   ` [FFmpeg-devel] [PATCH v2 01/11] avfilter/overlay_vaapi: use FILTER_SINGLE_PIXFMT softworkz
2022-11-04  2:07     ` Xiang, Haihao
2022-11-07  3:10       ` Xiang, Haihao
2022-10-31  6:19   ` [FFmpeg-devel] [PATCH v2 02/11] avfilter/overlay_vaapi: build filter params just once softworkz
2022-10-31  6:19   ` [FFmpeg-devel] [PATCH v2 03/11] avfilter/overlay_vaapi: remove double framesync init softworkz
2022-10-31  6:20   ` softworkz [this message]
2022-10-31  6:20   ` [FFmpeg-devel] [PATCH v2 05/11] avfilter/overlay_vaapi: reformat options softworkz
2022-10-31  6:20   ` [FFmpeg-devel] [PATCH v2 06/11] avfilter/overlay_vaapi: remove redundant .get_buffer assignments softworkz
2022-10-31  6:20   ` [FFmpeg-devel] [PATCH v2 07/11] avfilter/overlay_vaapi: add framesync options softworkz
2022-10-31  6:20   ` [FFmpeg-devel] [PATCH v2 08/11] avfilter/overlay_vaapi: precalculate blend_state, enable pixel alpha softworkz
2022-10-31  6:20   ` [FFmpeg-devel] [PATCH v2 09/11] avfilter/overlay_vaapi: enable expressions for overlay parameters softworkz
2022-10-31  6:20   ` [FFmpeg-devel] [PATCH v2 10/11] doc/filters.texi: remove incorrect statement softworkz
2022-10-31  6:20   ` [FFmpeg-devel] [PATCH v2 11/11] doc/filters.texi: update overlay_vaapi documentation softworkz

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=fb365de03606f26889a6ed0a7961dc60e80232cd.1667197207.git.ffmpegagent@gmail.com \
    --to=ffmpegagent@gmail.com \
    --cc=ffmpeg-devel@ffmpeg.org \
    --cc=ffmpeg@gyani.pro \
    --cc=haihao.xiang-at-intel.com@ffmpeg.org \
    --cc=softworkz@hotmail.com \
    /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