From patchwork Thu Aug 5 08:19:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Xiang, Haihao" X-Patchwork-Id: 29281 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:6c0f:0:0:0:0:0 with SMTP id a15csp192063ioh; Thu, 5 Aug 2021 01:24:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwy1RphJIdMtbVoPNzOLnJJGRBUy8N/5Ez2lVhsAwshcoHOvrMqfxa0axE3D7+qOACKJJlO X-Received: by 2002:a50:f61b:: with SMTP id c27mr4934612edn.96.1628151883835; Thu, 05 Aug 2021 01:24:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628151883; cv=none; d=google.com; s=arc-20160816; b=SU1g7Dr1MB0YGXmKJgtvjQurr/KAIxvWUOrZyc3+g3oho5NoaD1ApfyicO8isz4Leq Zquf/a+BUehIPP2MSVzY4fNDn7O1fj4V76Uz/MT8VOuK77gY8GHnNKbpx///uR3oi47i oP0UsAyg3CALSu0gvY+ptPt8OiFJkIaY5bY976Te8J4WB2PR7oDnDF2srqNg7uKX/g0l +BNghMPeMKjP1D2UCfpNS3ZVEPSIxQIuUWSMI/E1coUgIYFZ4CiRZR8WkLklJip15j9m 7V6kZi5ZWf7+w2SuFCu6TPvjNFs1Qh2dQA2xkE28xUzO2jR8iMYY7tIVLmFdC6vQxynn QdXw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:delivered-to; bh=+k562qXJQtrsZu7eMGTv/K1BxPwmhB33i8a8xkeFVmY=; b=Mz+Lctm4BSM+t9Lb0LBoY+/XVxj/OwQEyw395XtoVMLDMPuxm9+7/f8fAlwj5Vg62I BAEWuyldKr4CiGLCcay28Iwbb2Dsez7vMftI2m89ckT296A7ZHGlh7CZs9ANv7HQtTAz jGr95M1YNHg/J/EY25jP2LDyBMYazelZnboO+8CCfN0PK9wkmI0rVoEQ2Z9HKY772ACY F7oHeiay8syEizATC6+sQQbZdwmDFtaRsKkS+56QLFibS/QH9qo1CaDeDkPMlpbc3YOw Am5MafBei+aZ+iKr+W0H/FErwWJbFhuxws8pnZCHVsbgjqiwMmhh/hj1cy2kIqzXvtZP i6Xg== ARC-Authentication-Results: i=1; mx.google.com; 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=intel.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id e9si4705827eja.746.2021.08.05.01.24.43; Thu, 05 Aug 2021 01:24:43 -0700 (PDT) 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; 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=intel.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0CA6168A4C2; Thu, 5 Aug 2021 11:21:40 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id DE58168A4EC for ; Thu, 5 Aug 2021 11:21:31 +0300 (EEST) X-IronPort-AV: E=McAfee;i="6200,9189,10066"; a="236062069" X-IronPort-AV: E=Sophos;i="5.84,296,1620716400"; d="scan'208";a="236062069" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Aug 2021 01:19:58 -0700 X-IronPort-AV: E=Sophos;i="5.84,296,1620716400"; d="scan'208";a="522442446" Received: from xhh-dg164.sh.intel.com ([10.239.159.167]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Aug 2021 01:19:57 -0700 From: Haihao Xiang To: ffmpeg-devel@ffmpeg.org Date: Thu, 5 Aug 2021 16:19:08 +0800 Message-Id: <20210805081910.9386-19-haihao.xiang@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210805081910.9386-1-haihao.xiang@intel.com> References: <20210805081910.9386-1-haihao.xiang@intel.com> Subject: [FFmpeg-devel] [PATCH v5 18/20] lavfi/deinterlace_qsv: re-use VPPContext for deinterlace_qsv filter X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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 Cc: Haihao Xiang MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: i9Q/QKtDOVQb All features are implemented in vpp_qsv filter now, so deinterlace_qsv can be taken as a specical case of vpp_qsv filter, we re-use VPPContext with a different option array and pix formats for deinterlace_qsv filter A new option -rate is used to control the output frame rate, by default it will output frame for each field --- libavfilter/Makefile | 2 +- libavfilter/vf_deinterlace_qsv.c | 179 ------------------------------- libavfilter/vf_vpp_qsv.c | 35 +++++- 3 files changed, 35 insertions(+), 181 deletions(-) delete mode 100644 libavfilter/vf_deinterlace_qsv.c diff --git a/libavfilter/Makefile b/libavfilter/Makefile index 760099ba2c..dafd0c610c 100644 --- a/libavfilter/Makefile +++ b/libavfilter/Makefile @@ -230,7 +230,7 @@ OBJS-$(CONFIG_DECONVOLVE_FILTER) += vf_convolve.o framesync.o OBJS-$(CONFIG_DEDOT_FILTER) += vf_dedot.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_QSV_FILTER) += vf_vpp_qsv.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 diff --git a/libavfilter/vf_deinterlace_qsv.c b/libavfilter/vf_deinterlace_qsv.c deleted file mode 100644 index 50ff553e6a..0000000000 --- a/libavfilter/vf_deinterlace_qsv.c +++ /dev/null @@ -1,179 +0,0 @@ -/* - * This file is part of FFmpeg. - * - * FFmpeg is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * FFmpeg is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -/** - * @file - * deinterlace video filter - QSV - */ - -#include - -#include -#include - -#include "libavutil/avstring.h" -#include "libavutil/common.h" -#include "libavutil/hwcontext.h" -#include "libavutil/hwcontext_qsv.h" -#include "libavutil/internal.h" -#include "libavutil/mathematics.h" -#include "libavutil/opt.h" -#include "libavutil/pixdesc.h" -#include "libavutil/time.h" -#include "libavfilter/qsvvpp.h" - -#include "avfilter.h" -#include "formats.h" -#include "internal.h" -#include "video.h" - -typedef struct QSVDeintContext { - QSVVPPContext qsv; - - mfxExtVPPDeinterlacing deint_conf; - - /* option for Deinterlacing algorithm to be used */ - int mode; -} QSVDeintContext; - -static av_cold void qsvdeint_uninit(AVFilterContext *ctx) -{ - ff_qsvvpp_close(ctx); -} - -static int qsvdeint_query_formats(AVFilterContext *ctx) -{ - static const enum AVPixelFormat pixel_formats[] = { - AV_PIX_FMT_QSV, AV_PIX_FMT_NONE, - }; - AVFilterFormats *pix_fmts = ff_make_format_list(pixel_formats); - int ret; - - if ((ret = ff_set_common_formats(ctx, pix_fmts)) < 0) - return ret; - - return 0; -} - -static int qsvdeint_config_props(AVFilterLink *outlink) -{ - AVFilterContext *ctx = outlink->src; - AVFilterLink *inlink = ctx->inputs[0]; - QSVDeintContext *s = ctx->priv; - QSVVPPParam param = { NULL }; - mfxExtBuffer *ext_buf[1]; - enum AVPixelFormat in_format; - - qsvdeint_uninit(ctx); - - outlink->w = inlink->w; - outlink->h = inlink->h; - outlink->frame_rate = av_mul_q(inlink->frame_rate, - (AVRational){ 2, 1 }); - outlink->time_base = av_mul_q(inlink->time_base, - (AVRational){ 1, 2 }); - - if (inlink->format == AV_PIX_FMT_QSV) { - if (!inlink->hw_frames_ctx || !inlink->hw_frames_ctx->data) - return AVERROR(EINVAL); - else - in_format = ((AVHWFramesContext*)inlink->hw_frames_ctx->data)->sw_format; - } else - in_format = inlink->format; - - param.out_sw_format = in_format; - param.ext_buf = ext_buf; - - memset(&s->deint_conf, 0, sizeof(mfxExtVPPDeinterlacing)); - s->deint_conf.Header.BufferId = MFX_EXTBUFF_VPP_DEINTERLACING; - s->deint_conf.Header.BufferSz = sizeof(s->deint_conf); - s->deint_conf.Mode = s->mode; - param.ext_buf[param.num_ext_buf++] = (mfxExtBuffer*)&s->deint_conf; - - return ff_qsvvpp_init(ctx, ¶m); -} - -static int qsvdeint_filter_frame(AVFilterLink *link, AVFrame *in) -{ - AVFilterContext *ctx = link->dst; - QSVVPPContext *qsv = ctx->priv; - int ret = 0; - - ret = ff_qsvvpp_filter_frame(qsv, link, in); - av_frame_free(&in); - - return ret; -} - -static int qsvdeint_request_frame(AVFilterLink *outlink) -{ - AVFilterContext *ctx = outlink->src; - - return ff_request_frame(ctx->inputs[0]); -} - -#define OFFSET(x) offsetof(QSVDeintContext, x) -#define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM -static const AVOption options[] = { - { "mode", "set deinterlace mode", OFFSET(mode), AV_OPT_TYPE_INT, {.i64 = MFX_DEINTERLACING_ADVANCED}, MFX_DEINTERLACING_BOB, MFX_DEINTERLACING_ADVANCED, FLAGS, "mode"}, - { "bob", "bob algorithm", 0, AV_OPT_TYPE_CONST, {.i64 = MFX_DEINTERLACING_BOB}, MFX_DEINTERLACING_BOB, MFX_DEINTERLACING_ADVANCED, FLAGS, "mode"}, - { "advanced", "Motion adaptive algorithm", 0, AV_OPT_TYPE_CONST, {.i64 = MFX_DEINTERLACING_ADVANCED}, MFX_DEINTERLACING_BOB, MFX_DEINTERLACING_ADVANCED, FLAGS, "mode"}, - { NULL }, -}; - -static const AVClass qsvdeint_class = { - .class_name = "deinterlace_qsv", - .item_name = av_default_item_name, - .option = options, - .version = LIBAVUTIL_VERSION_INT, -}; - -static const AVFilterPad qsvdeint_inputs[] = { - { - .name = "default", - .type = AVMEDIA_TYPE_VIDEO, - .filter_frame = qsvdeint_filter_frame, - }, - { NULL } -}; - -static const AVFilterPad qsvdeint_outputs[] = { - { - .name = "default", - .type = AVMEDIA_TYPE_VIDEO, - .config_props = qsvdeint_config_props, - .request_frame = qsvdeint_request_frame, - }, - { NULL } -}; - -const AVFilter ff_vf_deinterlace_qsv = { - .name = "deinterlace_qsv", - .description = NULL_IF_CONFIG_SMALL("QuickSync video deinterlacing"), - - .uninit = qsvdeint_uninit, - .query_formats = qsvdeint_query_formats, - - .priv_size = sizeof(QSVDeintContext), - .priv_class = &qsvdeint_class, - - .inputs = qsvdeint_inputs, - .outputs = qsvdeint_outputs, - - .flags_internal = FF_FILTER_FLAG_HWFRAME_AWARE, -}; diff --git a/libavfilter/vf_vpp_qsv.c b/libavfilter/vf_vpp_qsv.c index f7854f81bf..518595d91e 100644 --- a/libavfilter/vf_vpp_qsv.c +++ b/libavfilter/vf_vpp_qsv.c @@ -102,6 +102,8 @@ typedef struct VPPContext{ char *cx, *cy, *cw, *ch; char *ow, *oh; char *output_format_str; + + int field_rate; /* deinterlace mode */ } VPPContext; static const char *const var_names[] = { @@ -226,6 +228,7 @@ static av_cold int vpp_preinit(AVFilterContext *ctx) vpp->saturation = 1.0; vpp->contrast = 1.0; vpp->transpose = -1; + vpp->field_rate = 1; return 0; } @@ -257,7 +260,10 @@ static int config_input(AVFilterLink *inlink) if (vpp->framerate.den == 0 || vpp->framerate.num == 0) vpp->framerate = inlink->frame_rate; - if (av_cmp_q(vpp->framerate, inlink->frame_rate)) + if (vpp->field_rate == 2) + vpp->framerate = av_mul_q(inlink->frame_rate, + (AVRational){ 2, 1 }); + else if (av_cmp_q(vpp->framerate, inlink->frame_rate)) vpp->use_frc = 1; ret = eval_expr(ctx); @@ -711,3 +717,30 @@ static const AVOption qsvscale_options[] = { }; DEFINE_QSV_FILTER(qsvscale, scale, "scaling and format conversion") + +static const AVOption qsvdeint_options[] = { + { "mode", "set deinterlace mode", OFFSET(deinterlace), AV_OPT_TYPE_INT, {.i64 = MFX_DEINTERLACING_ADVANCED}, MFX_DEINTERLACING_BOB, MFX_DEINTERLACING_ADVANCED, FLAGS, "mode"}, + { "bob", "bob algorithm", 0, AV_OPT_TYPE_CONST, {.i64 = MFX_DEINTERLACING_BOB}, MFX_DEINTERLACING_BOB, MFX_DEINTERLACING_ADVANCED, FLAGS, "mode"}, + { "advanced", "Motion adaptive algorithm", 0, AV_OPT_TYPE_CONST, {.i64 = MFX_DEINTERLACING_ADVANCED}, MFX_DEINTERLACING_BOB, MFX_DEINTERLACING_ADVANCED, FLAGS, "mode"}, + + { "rate", "Generate output at frame rate or field rate", + OFFSET(field_rate), AV_OPT_TYPE_INT, { .i64 = 2 }, 1, 2, FLAGS, "rate" }, + { "frame", "Output at frame rate (one frame of output for each field-pair)", + 0, AV_OPT_TYPE_CONST, { .i64 = 1 }, 0, 0, FLAGS, "rate" }, + { "field", "Output at field rate (one frame of output for each field)", + 0, AV_OPT_TYPE_CONST, { .i64 = 2 }, 0, 0, FLAGS, "rate" }, + + { NULL }, +}; + +static int qsvdeint_query_formats(AVFilterContext *ctx) +{ + static const enum AVPixelFormat pixel_formats[] = { + AV_PIX_FMT_QSV, AV_PIX_FMT_NONE, + }; + AVFilterFormats *pix_fmts = ff_make_format_list(pixel_formats); + + return ff_set_common_formats(ctx, pix_fmts); +} + +DEFINE_QSV_FILTER(qsvdeint, deinterlace, "deinterlacing") \ No newline at end of file