From patchwork Tue Apr 9 22:07:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Thompson X-Patchwork-Id: 12670 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 624E2448A83 for ; Wed, 10 Apr 2019 01:07:50 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4D87568ADF7; Wed, 10 Apr 2019 01:07:50 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6E87868ADEE for ; Wed, 10 Apr 2019 01:07:43 +0300 (EEST) Received: by mail-wm1-f48.google.com with SMTP id y197so396236wmd.0 for ; Tue, 09 Apr 2019 15:07:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jkqxz-net.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=/BlMvvQ3DlEZHE+Wj/jNAiamwbcDTU5VpFFjmPSoBLA=; b=mn4ITXJzfxP8uFo88kVsCcEcZlXI/DrrY9SvQbAGL7FkrKxif2iOlo/UvMZxgPO7lx UaV3kjD6GXg5GFJ7ikyfGByTkwP6RpruPuigWAaRYamGx9byOcHI9683ZfjrZ22iJdmr Mp457gtFNW042wyG50JF+uync3EQr+R251H3P32MgXUt7F/bpwbREnrKXoFG33aawavY 35mBTBS8Bz+JhPW/VnBRN0hEuq1BBxGy9gsOpoqkpUKEPK63lWokcQTNXlF4ve3hiyI7 YFg95fkQXhZ1CbpNqcKye1NMMszfxtFzTADj0BXrDjsTt3qepZEMRQgyQq+13gyyo4Ni mhlg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/BlMvvQ3DlEZHE+Wj/jNAiamwbcDTU5VpFFjmPSoBLA=; b=olg/xmjg+dTuCgpg3p/5kSH5zOUhn6QcwKB7z4PToxrIzL3GpolnaAMRVWDza1yN8V PeLKHAsTE6/9vmacbg0qJq4PMFyz/JmYHXhU9k04rIezXdWl7FYei0jPBvlmNtqONLgn 7SkjIsUf3kWuzObQc/PI0ZuubJL2tCMXjosywCrq39xOLqsq2VszdMY9184C4/C3JREw nmbV6HWkf7Y5T9ux0gpxmoR7zFWG4D8PxoY7pgSGT2knwOW31sQpeGgOKidIZoJ1WTjS Iolcg3jewMmwbhmuQCcekIaNmo+xDh5Bpmj3YM5UIIDMk6ZO+o/lVvt39UdAQyVSbks/ dDmg== X-Gm-Message-State: APjAAAUfSPxt4qjnNL9D5S9paG/YQX4Ou4kVr+ueUDnt0iCbMe2TcY4k 8Or7vegVnwEq9dYxa3EsnLXbMXHmmmU= X-Google-Smtp-Source: APXvYqxyfj5ld7ZxEh/4UOlbuIwoQSHwYGHU1CevLJju517Y7aqxDoKT+JjAYR9mv+OjFUr/6Ltc5g== X-Received: by 2002:a1c:c00b:: with SMTP id q11mr371094wmf.38.1554847662452; Tue, 09 Apr 2019 15:07:42 -0700 (PDT) Received: from rywe.jkqxz.net (cpc91242-cmbg18-2-0-cust650.5-4.cable.virginm.net. [82.8.130.139]) by smtp.gmail.com with ESMTPSA id v6sm41224332wrt.56.2019.04.09.15.07.41 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 09 Apr 2019 15:07:41 -0700 (PDT) From: Mark Thompson To: ffmpeg-devel@ffmpeg.org Date: Tue, 9 Apr 2019 23:07:26 +0100 Message-Id: <20190409220730.29311-3-sw@jkqxz.net> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190409220730.29311-1-sw@jkqxz.net> References: <20190409220730.29311-1-sw@jkqxz.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v4 3/7] lavfi/vaapi: Factorise out common code for parameter buffer setup X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Also enables cropping on all VAAPI filters, inherited from the existing support in scale_vaapi. --- libavfilter/vaapi_vpp.c | 55 ++++++++++++++++++++++++++++-- libavfilter/vaapi_vpp.h | 8 ++++- libavfilter/vf_deinterlace_vaapi.c | 33 ++++-------------- libavfilter/vf_misc_vaapi.c | 34 +++--------------- libavfilter/vf_procamp_vaapi.c | 34 +++--------------- libavfilter/vf_scale_vaapi.c | 38 ++++----------------- libavfilter/vf_transpose_vaapi.c | 44 ++++-------------------- 7 files changed, 87 insertions(+), 159 deletions(-) diff --git a/libavfilter/vaapi_vpp.c b/libavfilter/vaapi_vpp.c index c5bbc3b85b..647ddc0811 100644 --- a/libavfilter/vaapi_vpp.c +++ b/libavfilter/vaapi_vpp.c @@ -248,6 +248,52 @@ int ff_vaapi_vpp_colour_standard(enum AVColorSpace av_cs) } } +int ff_vaapi_vpp_init_params(AVFilterContext *avctx, + VAProcPipelineParameterBuffer *params, + const AVFrame *input_frame, + AVFrame *output_frame) +{ + VAAPIVPPContext *ctx = avctx->priv; + VASurfaceID input_surface; + + ctx->input_region = (VARectangle) { + .x = input_frame->crop_left, + .y = input_frame->crop_top, + .width = input_frame->width - + (input_frame->crop_left + input_frame->crop_right), + .height = input_frame->height - + (input_frame->crop_top + input_frame->crop_bottom), + }; + output_frame->crop_top = 0; + output_frame->crop_bottom = 0; + output_frame->crop_left = 0; + output_frame->crop_right = 0; + + input_surface = (VASurfaceID)(uintptr_t)input_frame->data[3], + + *params = (VAProcPipelineParameterBuffer) { + .surface = input_surface, + .surface_region = &ctx->input_region, + .surface_color_standard = + ff_vaapi_vpp_colour_standard(input_frame->colorspace), + .output_region = NULL, + .output_background_color = VAAPI_VPP_BACKGROUND_BLACK, + .output_color_standard = + ff_vaapi_vpp_colour_standard(input_frame->colorspace), + .pipeline_flags = 0, + .filter_flags = VA_FRAME_PICTURE, + + // Filter and reference data filled by the filter itself. + +#if VA_CHECK_VERSION(1, 1, 0) + .rotation_state = VA_ROTATION_NONE, + .mirror_state = VA_MIRROR_NONE, +#endif + }; + + return 0; +} + int ff_vaapi_vpp_make_param_buffers(AVFilterContext *avctx, int type, const void *data, @@ -279,12 +325,15 @@ int ff_vaapi_vpp_make_param_buffers(AVFilterContext *avctx, int ff_vaapi_vpp_render_picture(AVFilterContext *avctx, VAProcPipelineParameterBuffer *params, - VASurfaceID output_surface) + AVFrame *output_frame) { + VAAPIVPPContext *ctx = avctx->priv; + VASurfaceID output_surface; VABufferID params_id; VAStatus vas; - int err = 0; - VAAPIVPPContext *ctx = avctx->priv; + int err; + + output_surface = (VASurfaceID)(uintptr_t)output_frame->data[3]; vas = vaBeginPicture(ctx->hwctx->display, ctx->va_context, output_surface); diff --git a/libavfilter/vaapi_vpp.h b/libavfilter/vaapi_vpp.h index 96f720f07d..1e2b4a1066 100644 --- a/libavfilter/vaapi_vpp.h +++ b/libavfilter/vaapi_vpp.h @@ -42,6 +42,7 @@ typedef struct VAAPIVPPContext { AVBufferRef *input_frames_ref; AVHWFramesContext *input_frames; + VARectangle input_region; enum AVPixelFormat output_format; int output_width; // computed width @@ -69,6 +70,11 @@ int ff_vaapi_vpp_config_output(AVFilterLink *outlink); int ff_vaapi_vpp_colour_standard(enum AVColorSpace av_cs); +int ff_vaapi_vpp_init_params(AVFilterContext *avctx, + VAProcPipelineParameterBuffer *params, + const AVFrame *input_frame, + AVFrame *output_frame); + int ff_vaapi_vpp_make_param_buffers(AVFilterContext *avctx, int type, const void *data, @@ -77,6 +83,6 @@ int ff_vaapi_vpp_make_param_buffers(AVFilterContext *avctx, int ff_vaapi_vpp_render_picture(AVFilterContext *avctx, VAProcPipelineParameterBuffer *params, - VASurfaceID output_surface); + AVFrame *output_frame); #endif /* AVFILTER_VAAPI_VPP_H */ diff --git a/libavfilter/vf_deinterlace_vaapi.c b/libavfilter/vf_deinterlace_vaapi.c index f67a1c8e79..2c147310c9 100644 --- a/libavfilter/vf_deinterlace_vaapi.c +++ b/libavfilter/vf_deinterlace_vaapi.c @@ -181,12 +181,11 @@ static int deint_vaapi_filter_frame(AVFilterLink *inlink, AVFrame *input_frame) VAAPIVPPContext *vpp_ctx = avctx->priv; DeintVAAPIContext *ctx = avctx->priv; AVFrame *output_frame = NULL; - VASurfaceID input_surface, output_surface; + VASurfaceID input_surface; VASurfaceID backward_references[MAX_REFERENCES]; VASurfaceID forward_references[MAX_REFERENCES]; VAProcPipelineParameterBuffer params; VAProcFilterParameterBufferDeinterlacing *filter_params; - VARectangle input_region; VAStatus vas; void *filter_params_addr = NULL; int err, i, field, current_frame_index; @@ -238,30 +237,10 @@ static int deint_vaapi_filter_frame(AVFilterLink *inlink, AVFrame *input_frame) goto fail; } - output_surface = (VASurfaceID)(uintptr_t)output_frame->data[3]; - av_log(avctx, AV_LOG_DEBUG, "Using surface %#x for " - "deinterlace output.\n", output_surface); - - memset(¶ms, 0, sizeof(params)); - - input_region = (VARectangle) { - .x = 0, - .y = 0, - .width = input_frame->width, - .height = input_frame->height, - }; - - params.surface = input_surface; - params.surface_region = &input_region; - params.surface_color_standard = - ff_vaapi_vpp_colour_standard(input_frame->colorspace); - - params.output_region = NULL; - params.output_background_color = VAAPI_VPP_BACKGROUND_BLACK; - params.output_color_standard = params.surface_color_standard; - - params.pipeline_flags = 0; - params.filter_flags = VA_FRAME_PICTURE; + err = ff_vaapi_vpp_init_params(avctx, ¶ms, + input_frame, output_frame); + if (err < 0) + goto fail; if (!ctx->auto_enable || input_frame->interlaced_frame) { vas = vaMapBuffer(vpp_ctx->hwctx->display, vpp_ctx->filter_buffers[0], @@ -301,7 +280,7 @@ static int deint_vaapi_filter_frame(AVFilterLink *inlink, AVFrame *input_frame) params.num_filters = 0; } - err = ff_vaapi_vpp_render_picture(avctx, ¶ms, output_surface); + err = ff_vaapi_vpp_render_picture(avctx, ¶ms, output_frame); if (err < 0) goto fail; diff --git a/libavfilter/vf_misc_vaapi.c b/libavfilter/vf_misc_vaapi.c index e227c9ff6b..6f31a04293 100644 --- a/libavfilter/vf_misc_vaapi.c +++ b/libavfilter/vf_misc_vaapi.c @@ -129,9 +129,6 @@ static int misc_vaapi_filter_frame(AVFilterLink *inlink, AVFrame *input_frame) AVFilterLink *outlink = avctx->outputs[0]; VAAPIVPPContext *vpp_ctx = avctx->priv; AVFrame *output_frame = NULL; - VASurfaceID input_surface, output_surface; - VARectangle input_region; - VAProcPipelineParameterBuffer params; int err; @@ -142,10 +139,6 @@ static int misc_vaapi_filter_frame(AVFilterLink *inlink, AVFrame *input_frame) if (vpp_ctx->va_context == VA_INVALID_ID) return AVERROR(EINVAL); - input_surface = (VASurfaceID)(uintptr_t)input_frame->data[3]; - av_log(avctx, AV_LOG_DEBUG, "Using surface %#x for misc vpp input.\n", - input_surface); - output_frame = ff_get_video_buffer(outlink, vpp_ctx->output_width, vpp_ctx->output_height); if (!output_frame) { @@ -153,34 +146,17 @@ static int misc_vaapi_filter_frame(AVFilterLink *inlink, AVFrame *input_frame) goto fail; } - output_surface = (VASurfaceID)(uintptr_t)output_frame->data[3]; - av_log(avctx, AV_LOG_DEBUG, "Using surface %#x for misc vpp output.\n", - output_surface); - memset(¶ms, 0, sizeof(params)); - input_region = (VARectangle) { - .x = 0, - .y = 0, - .width = input_frame->width, - .height = input_frame->height, - }; + err = ff_vaapi_vpp_init_params(avctx, ¶ms, + input_frame, output_frame); + if (err < 0) + goto fail; if (vpp_ctx->nb_filter_buffers) { params.filters = &vpp_ctx->filter_buffers[0]; params.num_filters = vpp_ctx->nb_filter_buffers; } - params.surface = input_surface; - params.surface_region = &input_region; - params.surface_color_standard = - ff_vaapi_vpp_colour_standard(input_frame->colorspace); - - params.output_region = NULL; - params.output_background_color = VAAPI_VPP_BACKGROUND_BLACK; - params.output_color_standard = params.surface_color_standard; - - params.pipeline_flags = 0; - params.filter_flags = VA_FRAME_PICTURE; - err = ff_vaapi_vpp_render_picture(avctx, ¶ms, output_surface); + err = ff_vaapi_vpp_render_picture(avctx, ¶ms, output_frame); if (err < 0) goto fail; diff --git a/libavfilter/vf_procamp_vaapi.c b/libavfilter/vf_procamp_vaapi.c index 46f3ab6465..03da360669 100644 --- a/libavfilter/vf_procamp_vaapi.c +++ b/libavfilter/vf_procamp_vaapi.c @@ -131,9 +131,7 @@ static int procamp_vaapi_filter_frame(AVFilterLink *inlink, AVFrame *input_frame AVFilterLink *outlink = avctx->outputs[0]; VAAPIVPPContext *vpp_ctx = avctx->priv; AVFrame *output_frame = NULL; - VASurfaceID input_surface, output_surface; VAProcPipelineParameterBuffer params; - VARectangle input_region; int err; av_log(avctx, AV_LOG_DEBUG, "Filter input: %s, %ux%u (%"PRId64").\n", @@ -143,10 +141,6 @@ static int procamp_vaapi_filter_frame(AVFilterLink *inlink, AVFrame *input_frame if (vpp_ctx->va_context == VA_INVALID_ID) return AVERROR(EINVAL); - input_surface = (VASurfaceID)(uintptr_t)input_frame->data[3]; - av_log(avctx, AV_LOG_DEBUG, "Using surface %#x for procamp input.\n", - input_surface); - output_frame = ff_get_video_buffer(outlink, vpp_ctx->output_width, vpp_ctx->output_height); if (!output_frame) { @@ -154,33 +148,15 @@ static int procamp_vaapi_filter_frame(AVFilterLink *inlink, AVFrame *input_frame goto fail; } - output_surface = (VASurfaceID)(uintptr_t)output_frame->data[3]; - av_log(avctx, AV_LOG_DEBUG, "Using surface %#x for procamp output.\n", - output_surface); - memset(¶ms, 0, sizeof(params)); - input_region = (VARectangle) { - .x = 0, - .y = 0, - .width = input_frame->width, - .height = input_frame->height, - }; - - params.surface = input_surface; - params.surface_region = &input_region; - params.surface_color_standard = - ff_vaapi_vpp_colour_standard(input_frame->colorspace); - - params.output_region = NULL; - params.output_background_color = VAAPI_VPP_BACKGROUND_BLACK; - params.output_color_standard = params.surface_color_standard; - - params.pipeline_flags = 0; - params.filter_flags = VA_FRAME_PICTURE; + err = ff_vaapi_vpp_init_params(avctx, ¶ms, + input_frame, output_frame); + if (err < 0) + goto fail; params.filters = &vpp_ctx->filter_buffers[0]; params.num_filters = 1; - err = ff_vaapi_vpp_render_picture(avctx, ¶ms, output_surface); + err = ff_vaapi_vpp_render_picture(avctx, ¶ms, output_frame); if (err < 0) goto fail; diff --git a/libavfilter/vf_scale_vaapi.c b/libavfilter/vf_scale_vaapi.c index 3699363140..369daa787b 100644 --- a/libavfilter/vf_scale_vaapi.c +++ b/libavfilter/vf_scale_vaapi.c @@ -89,9 +89,7 @@ static int scale_vaapi_filter_frame(AVFilterLink *inlink, AVFrame *input_frame) VAAPIVPPContext *vpp_ctx = avctx->priv; ScaleVAAPIContext *ctx = avctx->priv; AVFrame *output_frame = NULL; - VASurfaceID input_surface, output_surface; VAProcPipelineParameterBuffer params; - VARectangle input_region; int err; av_log(avctx, AV_LOG_DEBUG, "Filter input: %s, %ux%u (%"PRId64").\n", @@ -101,10 +99,6 @@ static int scale_vaapi_filter_frame(AVFilterLink *inlink, AVFrame *input_frame) if (vpp_ctx->va_context == VA_INVALID_ID) return AVERROR(EINVAL); - input_surface = (VASurfaceID)(uintptr_t)input_frame->data[3]; - av_log(avctx, AV_LOG_DEBUG, "Using surface %#x for scale input.\n", - input_surface); - output_frame = ff_get_video_buffer(outlink, vpp_ctx->output_width, vpp_ctx->output_height); if (!output_frame) { @@ -112,34 +106,14 @@ static int scale_vaapi_filter_frame(AVFilterLink *inlink, AVFrame *input_frame) goto fail; } - output_surface = (VASurfaceID)(uintptr_t)output_frame->data[3]; - av_log(avctx, AV_LOG_DEBUG, "Using surface %#x for scale output.\n", - output_surface); - - memset(¶ms, 0, sizeof(params)); - - input_region = (VARectangle) { - .x = input_frame->crop_left, - .y = input_frame->crop_top, - .width = input_frame->width - - (input_frame->crop_left + input_frame->crop_right), - .height = input_frame->height - - (input_frame->crop_top + input_frame->crop_bottom), - }; - - params.surface = input_surface; - params.surface_region = &input_region; - params.surface_color_standard = - ff_vaapi_vpp_colour_standard(input_frame->colorspace); - - params.output_region = 0; - params.output_background_color = VAAPI_VPP_BACKGROUND_BLACK; - params.output_color_standard = params.surface_color_standard; + err = ff_vaapi_vpp_init_params(avctx, ¶ms, + input_frame, output_frame); + if (err < 0) + goto fail; - params.pipeline_flags = 0; - params.filter_flags = ctx->mode; + params.filter_flags |= ctx->mode; - err = ff_vaapi_vpp_render_picture(avctx, ¶ms, output_surface); + err = ff_vaapi_vpp_render_picture(avctx, ¶ms, output_frame); if (err < 0) goto fail; diff --git a/libavfilter/vf_transpose_vaapi.c b/libavfilter/vf_transpose_vaapi.c index 0e2acc9983..13c1dd6493 100644 --- a/libavfilter/vf_transpose_vaapi.c +++ b/libavfilter/vf_transpose_vaapi.c @@ -123,9 +123,6 @@ static int transpose_vaapi_filter_frame(AVFilterLink *inlink, AVFrame *input_fra VAAPIVPPContext *vpp_ctx = avctx->priv; TransposeVAAPIContext *ctx = avctx->priv; AVFrame *output_frame = NULL; - VASurfaceID input_surface, output_surface; - VARectangle input_region, output_region; - VAProcPipelineParameterBuffer params; int err; @@ -139,10 +136,6 @@ static int transpose_vaapi_filter_frame(AVFilterLink *inlink, AVFrame *input_fra if (vpp_ctx->va_context == VA_INVALID_ID) return AVERROR(EINVAL); - input_surface = (VASurfaceID)(uintptr_t)input_frame->data[3]; - av_log(avctx, AV_LOG_DEBUG, "Using surface %#x for transpose vpp input.\n", - input_surface); - output_frame = ff_get_video_buffer(outlink, vpp_ctx->output_width, vpp_ctx->output_height); if (!output_frame) { @@ -150,40 +143,15 @@ static int transpose_vaapi_filter_frame(AVFilterLink *inlink, AVFrame *input_fra goto fail; } - output_surface = (VASurfaceID)(uintptr_t)output_frame->data[3]; - av_log(avctx, AV_LOG_DEBUG, "Using surface %#x for transpose vpp output.\n", - output_surface); - memset(¶ms, 0, sizeof(params)); - input_region = (VARectangle) { - .x = 0, - .y = 0, - .width = input_frame->width, - .height = input_frame->height, - }; - - output_region = (VARectangle) { - .x = 0, - .y = 0, - .width = output_frame->width, - .height = output_frame->height, - }; + err = ff_vaapi_vpp_init_params(avctx, ¶ms, + input_frame, output_frame); + if (err < 0) + goto fail; params.rotation_state = ctx->rotation_state; - params.mirror_state = ctx->mirror_state; - - params.filters = &vpp_ctx->filter_buffers[0]; - params.num_filters = vpp_ctx->nb_filter_buffers; - - params.surface = input_surface; - params.surface_region = &input_region; - params.surface_color_standard = - ff_vaapi_vpp_colour_standard(input_frame->colorspace); - - params.output_region = &output_region; - params.output_background_color = VAAPI_VPP_BACKGROUND_BLACK; - params.output_color_standard = params.surface_color_standard; + params.mirror_state = ctx->mirror_state; - err = ff_vaapi_vpp_render_picture(avctx, ¶ms, output_surface); + err = ff_vaapi_vpp_render_picture(avctx, ¶ms, output_frame); if (err < 0) goto fail;