From patchwork Mon Jan 8 08:41:51 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jun Zhao X-Patchwork-Id: 7202 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.78.2 with SMTP id r2csp2390752jaa; Mon, 8 Jan 2018 00:42:04 -0800 (PST) X-Google-Smtp-Source: ACJfBovc0lkL9uaI/yGGyBcuVtkkU9UQW3fSFnIeYr3TMPLe88AtIyy3Exy+EAoju5usQyMUMtLr X-Received: by 10.28.11.133 with SMTP id 127mr8339131wml.115.1515400924703; Mon, 08 Jan 2018 00:42:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1515400924; cv=none; d=google.com; s=arc-20160816; b=JQ8kwbYerkCX8BM+nHhsMLkoyFU+FnXm5YlDhjAESacMg75CGJQ+Co76BbhLHJvcuW mJSrSgt+CYQXKfNM0xmlCUYutAAoTBPSwVuDZ23h8shZDIIYWDyST+S2AcrVICSjKoya QESvNbBW1AwXUJze4p9Zt7rl+74arp5UHBxnAr+fbuZKdO+pC7d+KOvi/CA7pdkDZzPG NDYhW9RxznfyUqJY834FWexRlpApZzVaE4Qt7x8S8sBU1SDIkBkjy3vIq46vuUUgG68y r3TSfzP2InEYc86SgkCOQwLZe+6WeUZCN2CbdwSQrCd+26t5p3InQjqgANi3UeX+lDQE ma7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:subject :content-language:mime-version:user-agent:date:message-id:from:to :dkim-signature:delivered-to:arc-authentication-results; bh=7YjHHlW4RurO5f+dh6jusw77HkUwgrM+1DE14RZmYH8=; b=y5T5/PQ/Vhs8fMS4wZAWB5+3/pcjhsa/DXY1DPHG5qoRAK21kDwgxE7kjWs5NP3s2o 5ueFDeo9UOBEhBQ8hNgV7W4uAKsfakYA84n7mlwc9H/RQk3t7cEvqrsKOTpNgD4nBxqa qa+K2Kf8B3MN/h5WW4EgXsS+dWSo2JFrGfqZ3PTN2mewlKsFww7Uk95KKuXzgToLtBeC z2UbPWtIP3C13vQW3RjayiAguCnSEAYc+5DBaCfedq29tlghCwMRHPTQBdunqsRoSot3 l1eY217cFaguNGdtiUWnI9GR00m2taF6Lzes+XbkQGDGMlTS0YITCImpvhWzWDIqWeMX kHCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=Z9g5JmML; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id i14si8239198wre.6.2018.01.08.00.42.04; Mon, 08 Jan 2018 00:42:04 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=Z9g5JmML; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0CF0C689E77; Mon, 8 Jan 2018 10:42:02 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pf0-f177.google.com (mail-pf0-f177.google.com [209.85.192.177]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D89C068973A for ; Mon, 8 Jan 2018 10:41:54 +0200 (EET) Received: by mail-pf0-f177.google.com with SMTP id m26so5473600pfj.11 for ; Mon, 08 Jan 2018 00:41:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=to:from:subject:message-id:date:user-agent:mime-version :content-language; bh=hmIfcSBX1KNzngIUClVGkn8Z4JzrRpYxAULWzbci2CU=; b=Z9g5JmMLHEwBFvS8gakNtp4OVtqKNxdUG1QnD3Z8/jrYSRKE5Isz7xJB2PjDt2vcaK Kfi4NVBpoWcTxYEK0TWZoTOAe5tWS6cI643F6uaD5BzOYTh6DGNvCMbjxEp0sPp/8N9e rZo+OLPgmPtrH5IH07QdtMgvKtV3T3miGmYplXvMmHN3U6ftXdfrxJ7/vAZN3ct0Hunb X/RXaKhbh/7HHt1gNhxtpYwLasKkcxNMlJSiUNiTGpEMbMt6bXrJhgKDnWUiluZ+oaUs sTnebkANrsoNE/wDtIUIR2RoaNGSI+cJ5MErsHUw2dVrO5kk8RglHxVHpaYgQ3sPcquO mfew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:from:subject:message-id:date:user-agent :mime-version:content-language; bh=hmIfcSBX1KNzngIUClVGkn8Z4JzrRpYxAULWzbci2CU=; b=LM0YYg8NDafCGqnpCoxy3fkMqSu2m3utwFCB60sIXg2xdkEELYl1/Jj8vcrDmUqEwU VtwdwbRz5vA0/+32XQOOeyTizdUEihZT0TIzANRfekMQgOALiWbv8JQ6Pw+MBEabd7Tg uWiR2C38zoXuFKJMeQILnnzBpe6e8pGuFC9hD/6/lofEcg3UacCgD7V4rL7FebJAGepX NfzJiwDStpXGr/b1s1/4kt9GrH8fdP7aU9YTCieCPgcoRqUqyMib3+vbzQblV/PxAaQU PKlZKACviMBPM9iTuGdzdv0vl0Ssn9N8nf8EghUjYOo5oKPKg40rcKDayGamQypCbFC7 j6uA== X-Gm-Message-State: AKGB3mIerG4S1vqGZ6Tj+qQr3JSHKaYfkeJXFpI+QeFEkdfGPOJo8Rqk /1A9jE+ta4ocIzrtPSOrQjrKVcA6 X-Received: by 10.99.94.193 with SMTP id s184mr8652270pgb.397.1515400914468; Mon, 08 Jan 2018 00:41:54 -0800 (PST) Received: from [10.67.68.34] ([192.55.54.42]) by smtp.gmail.com with ESMTPSA id e12sm22208074pgu.81.2018.01.08.00.41.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 08 Jan 2018 00:41:53 -0800 (PST) To: FFmpeg development discussions and patches , Mark Thompson From: Jun Zhao Message-ID: Date: Mon, 8 Jan 2018 16:41:51 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.5.2 MIME-Version: 1.0 Content-Language: en-US Subject: [FFmpeg-devel] [PATCH 3/5] lavfi: use common VPP infrastructure for vf_deinterlace_vaapi. 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" From 0274a13bc933e4d82a937afb6886b4132834ecff Mon Sep 17 00:00:00 2001 From: Jun Zhao Date: Mon, 8 Jan 2018 16:07:38 +0800 Subject: [PATCH 3/5] lavfi: use common VPP infrastructure for vf_deinterlace_vaapi. Use the common VPP infrastructure re-work vf_deinterlace_vaapi. Signed-off-by: Jun Zhao --- libavfilter/Makefile | 2 +- libavfilter/vf_deinterlace_vaapi.c | 318 ++++++------------------------------- 2 files changed, 51 insertions(+), 269 deletions(-) diff --git a/libavfilter/Makefile b/libavfilter/Makefile index 3d8dd2c890..bbc97a0831 100644 --- a/libavfilter/Makefile +++ b/libavfilter/Makefile @@ -171,7 +171,7 @@ OBJS-$(CONFIG_DECONVOLVE_FILTER) += vf_convolve.o framesync.o OBJS-$(CONFIG_DEFLATE_FILTER) += vf_neighbor.o OBJS-$(CONFIG_DEFLICKER_FILTER) += vf_deflicker.o OBJS-$(CONFIG_DEINTERLACE_QSV_FILTER) += vf_deinterlace_qsv.o -OBJS-$(CONFIG_DEINTERLACE_VAAPI_FILTER) += vf_deinterlace_vaapi.o +OBJS-$(CONFIG_DEINTERLACE_VAAPI_FILTER) += vf_deinterlace_vaapi.o vaapi_vpp.o OBJS-$(CONFIG_DEJUDDER_FILTER) += vf_dejudder.o OBJS-$(CONFIG_DELOGO_FILTER) += vf_delogo.o OBJS-$(CONFIG_DESHAKE_FILTER) += vf_deshake.o diff --git a/libavfilter/vf_deinterlace_vaapi.c b/libavfilter/vf_deinterlace_vaapi.c index 44c5ae7642..f9f5fcd096 100644 --- a/libavfilter/vf_deinterlace_vaapi.c +++ b/libavfilter/vf_deinterlace_vaapi.c @@ -33,31 +33,19 @@ #include "formats.h" #include "internal.h" #include "video.h" +#include "vaapi_vpp.h" #define MAX_REFERENCES 8 typedef struct DeintVAAPIContext { const AVClass *class; - AVVAAPIDeviceContext *hwctx; - AVBufferRef *device_ref; + VAAPIVPPContext *vpp_ctx; int mode; int field_rate; int auto_enable; - int valid_ids; - VAConfigID va_config; - VAContextID va_context; - - AVBufferRef *input_frames_ref; - AVHWFramesContext *input_frames; - - AVBufferRef *output_frames_ref; - AVHWFramesContext *output_frames; - int output_height; - int output_width; - VAProcFilterCapDeinterlacing deint_caps[VAProcDeinterlacingCount]; int nb_deint_caps; @@ -67,8 +55,6 @@ typedef struct DeintVAAPIContext { int queue_count; AVFrame *frame_queue[MAX_REFERENCES]; int extra_delay_for_timestamps; - - VABufferID filter_buffer; } DeintVAAPIContext; static const char *deint_vaapi_mode_name(int mode) @@ -87,80 +73,43 @@ static const char *deint_vaapi_mode_name(int mode) static int deint_vaapi_query_formats(AVFilterContext *avctx) { - enum AVPixelFormat pix_fmts[] = { - AV_PIX_FMT_VAAPI, AV_PIX_FMT_NONE, - }; - int err; - - if ((err = ff_formats_ref(ff_make_format_list(pix_fmts), - &avctx->inputs[0]->out_formats)) < 0) - return err; - if ((err = ff_formats_ref(ff_make_format_list(pix_fmts), - &avctx->outputs[0]->in_formats)) < 0) - return err; - - return 0; + return vaapi_vpp_query_formats(avctx); } static int deint_vaapi_pipeline_uninit(AVFilterContext *avctx) { DeintVAAPIContext *ctx = avctx->priv; + VAAPIVPPContext *vpp_ctx = ctx->vpp_ctx; int i; for (i = 0; i < ctx->queue_count; i++) av_frame_free(&ctx->frame_queue[i]); ctx->queue_count = 0; - if (ctx->filter_buffer != VA_INVALID_ID) { - vaDestroyBuffer(ctx->hwctx->display, ctx->filter_buffer); - ctx->filter_buffer = VA_INVALID_ID; - } - - if (ctx->va_context != VA_INVALID_ID) { - vaDestroyContext(ctx->hwctx->display, ctx->va_context); - ctx->va_context = VA_INVALID_ID; - } - - if (ctx->va_config != VA_INVALID_ID) { - vaDestroyConfig(ctx->hwctx->display, ctx->va_config); - ctx->va_config = VA_INVALID_ID; - } - - av_buffer_unref(&ctx->device_ref); - ctx->hwctx = NULL; - - return 0; + return vaapi_vpp_pipeline_uninit(vpp_ctx); } static int deint_vaapi_config_input(AVFilterLink *inlink) { AVFilterContext *avctx = inlink->dst; - DeintVAAPIContext *ctx = avctx->priv; - - deint_vaapi_pipeline_uninit(avctx); - - if (!inlink->hw_frames_ctx) { - av_log(avctx, AV_LOG_ERROR, "A hardware frames reference is " - "required to associate the processing device.\n"); - return AVERROR(EINVAL); - } + DeintVAAPIContext *ctx = avctx->priv; - ctx->input_frames_ref = av_buffer_ref(inlink->hw_frames_ctx); - ctx->input_frames = (AVHWFramesContext*)ctx->input_frames_ref->data; + VAAPIVPPContext *vpp_ctx = ctx->vpp_ctx; - return 0; + return vaapi_vpp_config_input(inlink, vpp_ctx); } static int deint_vaapi_build_filter_params(AVFilterContext *avctx) { - DeintVAAPIContext *ctx = avctx->priv; + DeintVAAPIContext *ctx = avctx->priv; + VAAPIVPPContext *vpp_ctx = ctx->vpp_ctx; VAStatus vas; VAProcFilterParameterBufferDeinterlacing params; int i; ctx->nb_deint_caps = VAProcDeinterlacingCount; - vas = vaQueryVideoProcFilterCaps(ctx->hwctx->display, - ctx->va_context, + vas = vaQueryVideoProcFilterCaps(vpp_ctx->hwctx->display, + vpp_ctx->va_context, VAProcFilterDeinterlacing, &ctx->deint_caps, &ctx->nb_deint_caps); @@ -194,20 +143,15 @@ static int deint_vaapi_build_filter_params(AVFilterContext *avctx) params.algorithm = ctx->mode; params.flags = 0; - av_assert0(ctx->filter_buffer == VA_INVALID_ID); - vas = vaCreateBuffer(ctx->hwctx->display, ctx->va_context, - VAProcFilterParameterBufferType, - sizeof(params), 1, ¶ms, - &ctx->filter_buffer); - if (vas != VA_STATUS_SUCCESS) { - av_log(avctx, AV_LOG_ERROR, "Failed to create deinterlace " - "parameter buffer: %d (%s).\n", vas, vaErrorStr(vas)); - return AVERROR(EIO); - } + vaapi_vpp_make_param_buffers(vpp_ctx, + VAProcFilterParameterBufferType, + ¶ms, + sizeof(params), + 1); - vas = vaQueryVideoProcPipelineCaps(ctx->hwctx->display, - ctx->va_context, - &ctx->filter_buffer, 1, + vas = vaQueryVideoProcPipelineCaps(vpp_ctx->hwctx->display, + vpp_ctx->va_context, + &vpp_ctx->filter_buffers[0], 1, &ctx->pipeline_caps); if (vas != VA_STATUS_SUCCESS) { av_log(avctx, AV_LOG_ERROR, "Failed to query pipeline " @@ -234,151 +178,35 @@ static int deint_vaapi_build_filter_params(AVFilterContext *avctx) static int deint_vaapi_config_output(AVFilterLink *outlink) { - AVFilterContext *avctx = outlink->src; - AVFilterLink *inlink = avctx->inputs[0]; - DeintVAAPIContext *ctx = avctx->priv; - AVVAAPIHWConfig *hwconfig = NULL; - AVHWFramesConstraints *constraints = NULL; - AVVAAPIFramesContext *va_frames; - VAStatus vas; + AVFilterLink *inlink = outlink->src->inputs[0]; + AVFilterContext *avctx = outlink->src; + DeintVAAPIContext *ctx = avctx->priv; + VAAPIVPPContext *vpp_ctx = ctx->vpp_ctx; int err; - deint_vaapi_pipeline_uninit(avctx); - - av_assert0(ctx->input_frames); - ctx->device_ref = av_buffer_ref(ctx->input_frames->device_ref); - ctx->hwctx = ((AVHWDeviceContext*)ctx->device_ref->data)->hwctx; - - ctx->output_width = ctx->input_frames->width; - ctx->output_height = ctx->input_frames->height; - - av_assert0(ctx->va_config == VA_INVALID_ID); - vas = vaCreateConfig(ctx->hwctx->display, VAProfileNone, - VAEntrypointVideoProc, 0, 0, &ctx->va_config); - if (vas != VA_STATUS_SUCCESS) { - av_log(avctx, AV_LOG_ERROR, "Failed to create processing pipeline " - "config: %d (%s).\n", vas, vaErrorStr(vas)); - err = AVERROR(EIO); - goto fail; - } - - hwconfig = av_hwdevice_hwconfig_alloc(ctx->device_ref); - if (!hwconfig) { - err = AVERROR(ENOMEM); - goto fail; - } - hwconfig->config_id = ctx->va_config; - - constraints = av_hwdevice_get_hwframe_constraints(ctx->device_ref, - hwconfig); - if (!constraints) { - err = AVERROR(ENOMEM); - goto fail; - } - - if (ctx->output_width < constraints->min_width || - ctx->output_height < constraints->min_height || - ctx->output_width > constraints->max_width || - ctx->output_height > constraints->max_height) { - av_log(avctx, AV_LOG_ERROR, "Hardware does not support " - "deinterlacing to size %dx%d " - "(constraints: width %d-%d height %d-%d).\n", - ctx->output_width, ctx->output_height, - constraints->min_width, constraints->max_width, - constraints->min_height, constraints->max_height); - err = AVERROR(EINVAL); - goto fail; - } - - ctx->output_frames_ref = av_hwframe_ctx_alloc(ctx->device_ref); - if (!ctx->output_frames_ref) { - av_log(avctx, AV_LOG_ERROR, "Failed to create HW frame context " - "for output.\n"); - err = AVERROR(ENOMEM); - goto fail; - } - - ctx->output_frames = (AVHWFramesContext*)ctx->output_frames_ref->data; - - ctx->output_frames->format = AV_PIX_FMT_VAAPI; - ctx->output_frames->sw_format = ctx->input_frames->sw_format; - ctx->output_frames->width = ctx->output_width; - ctx->output_frames->height = ctx->output_height; - - // The number of output frames we need is determined by what follows - // the filter. If it's an encoder with complex frame reference - // structures then this could be very high. - ctx->output_frames->initial_pool_size = 10; - - err = av_hwframe_ctx_init(ctx->output_frames_ref); - if (err < 0) { - av_log(avctx, AV_LOG_ERROR, "Failed to initialise VAAPI frame " - "context for output: %d\n", err); - goto fail; - } - - va_frames = ctx->output_frames->hwctx; - - av_assert0(ctx->va_context == VA_INVALID_ID); - vas = vaCreateContext(ctx->hwctx->display, ctx->va_config, - ctx->output_width, ctx->output_height, 0, - va_frames->surface_ids, va_frames->nb_surfaces, - &ctx->va_context); - if (vas != VA_STATUS_SUCCESS) { - av_log(avctx, AV_LOG_ERROR, "Failed to create processing pipeline " - "context: %d (%s).\n", vas, vaErrorStr(vas)); - err = AVERROR(EIO); - goto fail; - } + ctx->vpp_ctx->output_width = avctx->inputs[0]->w; + ctx->vpp_ctx->output_height = avctx->inputs[0]->h; - err = deint_vaapi_build_filter_params(avctx); + err = vaapi_vpp_config_output(outlink, vpp_ctx); if (err < 0) goto fail; - - outlink->w = inlink->w; - outlink->h = inlink->h; - outlink->time_base = av_mul_q(inlink->time_base, (AVRational) { 1, ctx->field_rate }); outlink->frame_rate = av_mul_q(inlink->frame_rate, (AVRational) { ctx->field_rate, 1 }); - outlink->hw_frames_ctx = av_buffer_ref(ctx->output_frames_ref); - if (!outlink->hw_frames_ctx) { - err = AVERROR(ENOMEM); - goto fail; - } - - av_freep(&hwconfig); - av_hwframe_constraints_free(&constraints); return 0; fail: - av_buffer_unref(&ctx->output_frames_ref); - av_freep(&hwconfig); - av_hwframe_constraints_free(&constraints); return err; } -static int vaapi_proc_colour_standard(enum AVColorSpace av_cs) -{ - switch(av_cs) { -#define CS(av, va) case AVCOL_SPC_ ## av: return VAProcColorStandard ## va; - CS(BT709, BT709); - CS(BT470BG, BT470BG); - CS(SMPTE170M, SMPTE170M); - CS(SMPTE240M, SMPTE240M); -#undef CS - default: - return VAProcColorStandardNone; - } -} - static int deint_vaapi_filter_frame(AVFilterLink *inlink, AVFrame *input_frame) { AVFilterContext *avctx = inlink->dst; AVFilterLink *outlink = avctx->outputs[0]; DeintVAAPIContext *ctx = avctx->priv; + VAAPIVPPContext *vpp_ctx = ctx->vpp_ctx; AVFrame *output_frame = NULL; VASurfaceID input_surface, output_surface; VASurfaceID backward_references[MAX_REFERENCES]; @@ -386,7 +214,6 @@ static int deint_vaapi_filter_frame(AVFilterLink *inlink, AVFrame *input_frame) VAProcPipelineParameterBuffer params; VAProcFilterParameterBufferDeinterlacing *filter_params; VARectangle input_region; - VABufferID params_id; VAStatus vas; void *filter_params_addr = NULL; int err, i, field, current_frame_index; @@ -431,8 +258,8 @@ static int deint_vaapi_filter_frame(AVFilterLink *inlink, AVFrame *input_frame) av_log(avctx, AV_LOG_DEBUG, "\n"); for (field = 0; field < ctx->field_rate; field++) { - output_frame = ff_get_video_buffer(outlink, ctx->output_width, - ctx->output_height); + output_frame = ff_get_video_buffer(outlink, vpp_ctx->output_width, + vpp_ctx->output_height); if (!output_frame) { err = AVERROR(ENOMEM); goto fail; @@ -454,7 +281,7 @@ static int deint_vaapi_filter_frame(AVFilterLink *inlink, AVFrame *input_frame) params.surface = input_surface; params.surface_region = &input_region; params.surface_color_standard = - vaapi_proc_colour_standard(input_frame->colorspace); + vaapi_vpp_colour_standard(input_frame->colorspace); params.output_region = NULL; params.output_background_color = 0xff000000; @@ -464,7 +291,7 @@ static int deint_vaapi_filter_frame(AVFilterLink *inlink, AVFrame *input_frame) params.filter_flags = VA_FRAME_PICTURE; if (!ctx->auto_enable || input_frame->interlaced_frame) { - vas = vaMapBuffer(ctx->hwctx->display, ctx->filter_buffer, + vas = vaMapBuffer(vpp_ctx->hwctx->display, vpp_ctx->filter_buffers[0], &filter_params_addr); if (vas != VA_STATUS_SUCCESS) { av_log(avctx, AV_LOG_ERROR, "Failed to map filter parameter " @@ -481,12 +308,12 @@ static int deint_vaapi_filter_frame(AVFilterLink *inlink, AVFrame *input_frame) filter_params->flags |= field ? 0 : VA_DEINTERLACING_BOTTOM_FIELD; } filter_params_addr = NULL; - vas = vaUnmapBuffer(ctx->hwctx->display, ctx->filter_buffer); + vas = vaUnmapBuffer(vpp_ctx->hwctx->display, vpp_ctx->filter_buffers[0]); if (vas != VA_STATUS_SUCCESS) av_log(avctx, AV_LOG_ERROR, "Failed to unmap filter parameter " "buffer: %d (%s).\n", vas, vaErrorStr(vas)); - params.filters = &ctx->filter_buffer; + params.filters = &vpp_ctx->filter_buffers[0]; params.num_filters = 1; params.forward_references = forward_references; @@ -501,53 +328,9 @@ static int deint_vaapi_filter_frame(AVFilterLink *inlink, AVFrame *input_frame) params.num_filters = 0; } - vas = vaBeginPicture(ctx->hwctx->display, - ctx->va_context, output_surface); - if (vas != VA_STATUS_SUCCESS) { - av_log(avctx, AV_LOG_ERROR, "Failed to attach new picture: " - "%d (%s).\n", vas, vaErrorStr(vas)); - err = AVERROR(EIO); + err = vaapi_vpp_render_picture(vpp_ctx, ¶ms, output_surface); + if (err < 0) goto fail; - } - - vas = vaCreateBuffer(ctx->hwctx->display, ctx->va_context, - VAProcPipelineParameterBufferType, - sizeof(params), 1, ¶ms, ¶ms_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 parameter buffer is %#x.\n", - params_id); - - vas = vaRenderPicture(ctx->hwctx->display, ctx->va_context, - ¶ms_id, 1); - if (vas != VA_STATUS_SUCCESS) { - av_log(avctx, AV_LOG_ERROR, "Failed to render parameter buffer: " - "%d (%s).\n", vas, vaErrorStr(vas)); - err = AVERROR(EIO); - goto fail_after_begin; - } - - vas = vaEndPicture(ctx->hwctx->display, ctx->va_context); - if (vas != VA_STATUS_SUCCESS) { - av_log(avctx, AV_LOG_ERROR, "Failed to start picture processing: " - "%d (%s).\n", vas, vaErrorStr(vas)); - err = AVERROR(EIO); - goto fail_after_render; - } - - if (CONFIG_VAAPI_1 || ctx->hwctx->driver_quirks & - AV_VAAPI_DRIVER_QUIRK_RENDER_PARAM_BUFFERS) { - vas = vaDestroyBuffer(ctx->hwctx->display, params_id); - if (vas != VA_STATUS_SUCCESS) { - av_log(avctx, AV_LOG_ERROR, "Failed to free parameter buffer: " - "%d (%s).\n", vas, vaErrorStr(vas)); - // And ignore. - } - } err = av_frame_copy_props(output_frame, input_frame); if (err < 0) @@ -573,13 +356,9 @@ static int deint_vaapi_filter_frame(AVFilterLink *inlink, AVFrame *input_frame) return err; -fail_after_begin: - vaRenderPicture(ctx->hwctx->display, ctx->va_context, ¶ms_id, 1); -fail_after_render: - vaEndPicture(ctx->hwctx->display, ctx->va_context); fail: if (filter_params_addr) - vaUnmapBuffer(ctx->hwctx->display, ctx->filter_buffer); + vaUnmapBuffer(vpp_ctx->hwctx->display, vpp_ctx->filter_buffers[0]); av_frame_free(&output_frame); return err; } @@ -587,11 +366,18 @@ fail: static av_cold int deint_vaapi_init(AVFilterContext *avctx) { DeintVAAPIContext *ctx = avctx->priv; + VAAPIVPPContext *vpp_ctx; + + ctx->vpp_ctx = av_mallocz(sizeof(VAAPIVPPContext)); + if (!ctx->vpp_ctx) + return AVERROR(ENOMEM); - ctx->va_config = VA_INVALID_ID; - ctx->va_context = VA_INVALID_ID; - ctx->filter_buffer = VA_INVALID_ID; - ctx->valid_ids = 1; + vpp_ctx = ctx->vpp_ctx; + + vaapi_vpp_ctx_init(vpp_ctx); + vpp_ctx->pipeline_uninit = deint_vaapi_pipeline_uninit; + vpp_ctx->build_filter_params = deint_vaapi_build_filter_params; + vpp_ctx->output_format = AV_PIX_FMT_NONE; return 0; } @@ -599,13 +385,9 @@ static av_cold int deint_vaapi_init(AVFilterContext *avctx) static av_cold void deint_vaapi_uninit(AVFilterContext *avctx) { DeintVAAPIContext *ctx = avctx->priv; + VAAPIVPPContext *vpp_ctx = ctx->vpp_ctx; - if (ctx->valid_ids) - deint_vaapi_pipeline_uninit(avctx); - - av_buffer_unref(&ctx->input_frames_ref); - av_buffer_unref(&ctx->output_frames_ref); - av_buffer_unref(&ctx->device_ref); + vaapi_vpp_ctx_uninit(avctx, vpp_ctx); } #define OFFSET(x) offsetof(DeintVAAPIContext, x)