From patchwork Mon Jan 30 01:37:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Xiang, Haihao" X-Patchwork-Id: 40173 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:3ca3:b0:b9:1511:ac2c with SMTP id b35csp3058797pzj; Sun, 29 Jan 2023 17:37:53 -0800 (PST) X-Google-Smtp-Source: AMrXdXvlfBZzVfYBiN3ws1hi+e2wvvlPHoZd+LibFFzWfHi97ZtnPfnh8kl3ASB5HK0m8HH9uPnv X-Received: by 2002:a17:906:38c3:b0:872:82d3:4162 with SMTP id r3-20020a17090638c300b0087282d34162mr46076840ejd.44.1675042673174; Sun, 29 Jan 2023 17:37:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675042673; cv=none; d=google.com; s=arc-20160816; b=psC3ehjseJNnwOy227JlgskxL8XE2J7dS8vxtRZUz6FIs94GfkFJPt+iV80jUQPFWv gOY+9jMjm/FZoMvLbqwwWe5E8kfTMK2ziE6uKyo3WgUG+9SUQwQ99FA2/cPz4y4V51Hl qSYn7xe1zm0dQuq2LtI1cC2+QMSbxB4F9CodHf9mztzrtzc+W+Y9zW0fS/nd2i4ycXKP uLSVU69/7rxQvie2t95mgmC1vzKp9VE2qpNE0uaxbYh6Xya7JkaSO27MzzkNT50SyTBE K0sBYMBq7ukD+ffXThl04b+3s5kSCYnC5RdHozjeAiXwE8Dyv8WAFnvb/5juIejX+058 dX9Q== 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:message-id:date:to:from:dkim-signature :delivered-to; bh=cDpaulSCuhpdhRYWnhub4GRDq5kqgDRspFJzdaNRLOI=; b=hyTNtnJ1A75tq+lnDhUQmfghh/rMrHuc11fHnELjNbO8ic3CybEaXDf6kZJKj+14ZG ctfuyx5ngRCtoMnmr2aMdmib8hITrWunQn0YyLNRKTtRyd7LEQsaqvoJEdL/ImCcnQ+6 wmqQpRhGQA1/ymEp8tPhhzT5Y7Ea6dBMs7uDyLtuYBAoQPwVhzhq8K/6TUNTEUmZvVaY REN+j5ikvvRgFWSyVNIjda50j8z8u3Y8quAQt5WIcByix8FhvrFM+/4KS5AlLR1Jz0BQ jcZo6Jr3ECf4l71EXvjGypYdxmbHKaWoE3XBKJsA3EKrW5A8f3vapruiJ5/WTn9OGniD 1pXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@intel.com header.s=Intel header.b=XUuOrpjO; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id 6-20020a170906018600b008722dfb9f4bsi14636103ejb.726.2023.01.29.17.37.52; Sun, 29 Jan 2023 17:37:53 -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=@intel.com header.s=Intel header.b=XUuOrpjO; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6075068BD6C; Mon, 30 Jan 2023 03:37:48 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2586B680BA3 for ; Mon, 30 Jan 2023 03:37:40 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1675042666; x=1706578666; h=from:to:cc:subject:date:message-id; bh=pjtbHuHjDShp3nHMjFhuaKiJWVmAP+SyPEKQ4MynvDc=; b=XUuOrpjOTYbhl/V+2JhbpdRSoJW6oWndP0czZ/D2/JnjOLFyORuvzMKn 0NHGnyYFwo7ZI5QEi9JIXX9AsBhmZrV/YmUsDTZeiAv9GRMeJyFewOxOp SJmxRF2ABNRkii1nh3du7EwJzm49p7k79UHXVlH7bUrpwn9atNR03EX69 0cIBx8zJPVoJOuLe/Rw+F3Gamq0P7fra9t7Dtcuf4imfvbcJlPDA5CFQ8 ZoU0os70pXqP9vcckBzcwv+mEvPR0IttGa+70sA3LssfgPd5osaiAqjTN K1AWi26aHo/jHs3YEDvfFj4+seAHtyi3hHqXGm4eC4pY80odPjSQshwP7 A==; X-IronPort-AV: E=McAfee;i="6500,9779,10605"; a="307798847" X-IronPort-AV: E=Sophos;i="5.97,256,1669104000"; d="scan'208";a="307798847" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Jan 2023 17:37:38 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10605"; a="772305350" X-IronPort-AV: E=Sophos;i="5.97,256,1669104000"; d="scan'208";a="772305350" Received: from xhh-dg164.sh.intel.com ([10.238.5.169]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Jan 2023 17:37:36 -0800 From: "Xiang, Haihao" To: ffmpeg-devel@ffmpeg.org Date: Mon, 30 Jan 2023 09:37:17 +0800 Message-Id: <20230130013719.7167-1-haihao.xiang@intel.com> X-Mailer: git-send-email 2.17.1 Subject: [FFmpeg-devel] [PATCH 1/3] lavfi/vpp_qsv: add rate option 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: mzYDRpgf6/9F From: Haihao Xiang This is used to control the output at frame rate or field rate when deinterlace is expected and framerate is not specified. Signed-off-by: Haihao Xiang --- libavfilter/vf_vpp_qsv.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/libavfilter/vf_vpp_qsv.c b/libavfilter/vf_vpp_qsv.c index 34e530e244..aac0a234c3 100644 --- a/libavfilter/vf_vpp_qsv.c +++ b/libavfilter/vf_vpp_qsv.c @@ -101,6 +101,7 @@ typedef struct VPPContext{ char *output_format_str; int has_passthrough; /* apply pass through mode if possible */ + int field_rate; /* Generate output at frame rate or field rate for deinterlace mode, 0: frame, 1: field */ } VPPContext; static const char *const var_names[] = { @@ -255,9 +256,14 @@ static int config_input(AVFilterLink *inlink) int ret; int64_t ow, oh; - if (vpp->framerate.den == 0 || vpp->framerate.num == 0) + if (vpp->framerate.den == 0 || vpp->framerate.num == 0) { vpp->framerate = inlink->frame_rate; + if (vpp->deinterlace && vpp->field_rate) + vpp->framerate = av_mul_q(inlink->frame_rate, + (AVRational){ 2, 1 }); + } + if (av_cmp_q(vpp->framerate, inlink->frame_rate)) vpp->use_frc = 1; @@ -352,7 +358,7 @@ static int config_output(AVFilterLink *outlink) outlink->w = vpp->out_width; outlink->h = vpp->out_height; outlink->frame_rate = vpp->framerate; - outlink->time_base = inlink->time_base; + outlink->time_base = av_inv_q(vpp->framerate); param.filter_frame = NULL; param.num_ext_buf = 0; @@ -678,6 +684,13 @@ static const AVOption vpp_options[] = { { "low_power", "low power mode", 0, AV_OPT_TYPE_CONST, { .i64 = MFX_SCALING_MODE_LOWPOWER}, INT_MIN, INT_MAX, FLAGS, "scale mode"}, { "hq", "high quality mode", 0, AV_OPT_TYPE_CONST, { .i64 = MFX_SCALING_MODE_QUALITY}, INT_MIN, INT_MAX, FLAGS, "scale mode"}, + { "rate", "Generate output at frame rate or field rate, available only for deinterlace mode", + OFFSET(field_rate), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, FLAGS, "rate" }, + { "frame", "Output at frame rate (one frame of output for each field-pair)", + 0, AV_OPT_TYPE_CONST, { .i64 = 0 }, 0, 0, FLAGS, "rate" }, + { "field", "Output at field rate (one frame of output for each field)", + 0, AV_OPT_TYPE_CONST, { .i64 = 1 }, 0, 0, FLAGS, "rate" }, + { NULL } }; From patchwork Mon Jan 30 01:37:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Xiang, Haihao" X-Patchwork-Id: 40174 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:3ca3:b0:b9:1511:ac2c with SMTP id b35csp3058891pzj; Sun, 29 Jan 2023 17:38:03 -0800 (PST) X-Google-Smtp-Source: AMrXdXv95i6SKdrU26qXTxA1jpOhK+7+XQAPtCyttf7nyytlYXmmq1X/JfqwRjPF0LokA/IVM7sN X-Received: by 2002:a05:6402:2b97:b0:479:ab7d:1dad with SMTP id fj23-20020a0564022b9700b00479ab7d1dadmr55538079edb.32.1675042683099; Sun, 29 Jan 2023 17:38:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675042683; cv=none; d=google.com; s=arc-20160816; b=Y/3Ll3gjaoUe+BfR1Xjtf0EWbM/z6ulSPIrFoxrCQ82mKUv/ATamlA3JNEIB+xv51j Egm218GW0WxT4/sQ+NjnxVmuzf6rD2L/ieF582F44Vaj7U1RFnEbdKGYjyHUCXzrLvQk 90fCYthl95dwLMtC/d1gn2KwEqWFNDB39ONwvZ8C266vssyZVYtLgJpOneeChVD9EIVa PGOui1yG5O07EuQaH32ZqGdBfP5Bi37Jlvt6ZaQS8+ccnTIG3xzKGsIp5JnzMwyLHShI dtOIToVONVnx2AHgT0zT/gN9du7pf9cCIH5YGX1k8QYSKub62VB9EKQfPMOIJD2E7yrB 2o5w== 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:dkim-signature:delivered-to; bh=mrCu28R13Tb0SXBWnAThMYUCsdXQodD0nzuIKb4Gmhc=; b=tGq0ZBxNoLFWsGf7P16eprx41IbgiNTbxnCyh96x9OmmtdAXeJXi+gUctGKhKrUa2l 3JtMvvGXV9v2ZFlie8BW6AqCEIZogpvCAxnAQ59XCTOCELAkpUVC0MYd6K/q8TT88qY7 AJYrgaR+Zd6JakWiBfNLvzkj1ghBtVZUxMXa9wpTQDQh6ZuWQMaa68vh/PzKa/wZLsyY RiGcvwCfdJgmCX757ylJOMcq7cGSNs/XIUB3xKyh6ky0zm1rT7Jn9RUprOqKk+8GIH51 3F8auec98q7HFtDUE/GETM2ycbtGyCwlrrPPQaCLb5jl/moX6At6PuXQxslKH/1ouzS7 BjKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@intel.com header.s=Intel header.b=lCTv+GQG; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id p15-20020a056402074f00b0049b935e07e4si12578630edy.207.2023.01.29.17.38.02; Sun, 29 Jan 2023 17:38:03 -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=@intel.com header.s=Intel header.b=lCTv+GQG; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 94A0168BD96; Mon, 30 Jan 2023 03:37:50 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5E9DF68BD6B for ; Mon, 30 Jan 2023 03:37:43 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1675042668; x=1706578668; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=AvzM1healojQ6U5+c1f43r023t4Z88bpJmjq1xDp60g=; b=lCTv+GQGjSOrQ8pc+NmXut7oQYkOb8HO3mvjiqlpDT1EPLqcxU13kMfD gv3Ua/0KQ7845e2oFU4SHHJssamonyesnJOeuuxcP4q+xcYwG4N/5WVBs LN5yzJPN6bAeVx1bNGDGEuLsIWSzx91ewY/6fqgv16lSYff99O879xxkS 0Mro47H1RxTgjzEnHOCb6+2dh1tZ7X+RjX2gkv9HnnxIgPkteB8Y77O2S Wjdc/xAG+LyK5hbwMDmW+k6y5EMzw2MxHBD4nsG6HXP2C3Dv23g0s4C7P M00aBjZ6U+RPD6uBk29pGcgejrYyE8nB0fVlRZ/VE/mSKH+zV8YC+Ua26 A==; X-IronPort-AV: E=McAfee;i="6500,9779,10605"; a="307798854" X-IronPort-AV: E=Sophos;i="5.97,256,1669104000"; d="scan'208";a="307798854" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Jan 2023 17:37:40 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10605"; a="772305360" X-IronPort-AV: E=Sophos;i="5.97,256,1669104000"; d="scan'208";a="772305360" Received: from xhh-dg164.sh.intel.com ([10.238.5.169]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Jan 2023 17:37:38 -0800 From: "Xiang, Haihao" To: ffmpeg-devel@ffmpeg.org Date: Mon, 30 Jan 2023 09:37:18 +0800 Message-Id: <20230130013719.7167-2-haihao.xiang@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230130013719.7167-1-haihao.xiang@intel.com> References: <20230130013719.7167-1-haihao.xiang@intel.com> Subject: [FFmpeg-devel] [PATCH 2/3] lavfi/deinterlace_qsv: simplify 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: BUwsGrON7Mwo From: Haihao Xiang Like what we did for scale_qsv filter, we use QSVVPPContext as a base context to manage MFX session for deinterlace_qsv filter. Signed-off-by: Haihao Xiang --- configure | 1 + libavfilter/vf_deinterlace_qsv.c | 505 ++----------------------------- 2 files changed, 31 insertions(+), 475 deletions(-) diff --git a/configure b/configure index 47790d10f5..53236f54c8 100755 --- a/configure +++ b/configure @@ -3648,6 +3648,7 @@ coreimagesrc_filter_extralibs="-framework OpenGL" cover_rect_filter_deps="avcodec avformat gpl" cropdetect_filter_deps="gpl" deinterlace_qsv_filter_deps="libmfx" +deinterlace_qsv_filter_select="qsvvpp" deinterlace_vaapi_filter_deps="vaapi" delogo_filter_deps="gpl" denoise_vaapi_filter_deps="vaapi" diff --git a/libavfilter/vf_deinterlace_qsv.c b/libavfilter/vf_deinterlace_qsv.c index 6c94923f02..8173386780 100644 --- a/libavfilter/vf_deinterlace_qsv.c +++ b/libavfilter/vf_deinterlace_qsv.c @@ -44,36 +44,10 @@ #define MFX_IMPL_VIA_MASK(impl) (0x0f00 & (impl)) -enum { - QSVDEINT_MORE_OUTPUT = 1, - QSVDEINT_MORE_INPUT, -}; - typedef struct QSVDeintContext { - const AVClass *class; - - AVBufferRef *hw_frames_ctx; - /* a clone of the main session, used internally for deinterlacing */ - mfxSession session; - - mfxMemId *mem_ids; - int nb_mem_ids; - - mfxFrameSurface1 **surface_ptrs; - int nb_surface_ptrs; - -#if QSV_HAVE_OPAQUE - mfxExtOpaqueSurfaceAlloc opaque_alloc; -#endif - mfxExtVPPDeinterlacing deint_conf; - mfxExtBuffer *ext_buffers[2]; - int num_ext_buffers; - - QSVFrame *work_frames; + QSVVPPContext qsv; - int64_t last_pts; - - int eof; + mfxExtVPPDeinterlacing deint_conf; /* option for Deinterlacing algorithm to be used */ int mode; @@ -81,476 +55,57 @@ typedef struct QSVDeintContext { static av_cold void qsvdeint_uninit(AVFilterContext *ctx) { - QSVDeintContext *s = ctx->priv; - QSVFrame *cur; - - if (s->session) { - MFXClose(s->session); - s->session = NULL; - } - av_buffer_unref(&s->hw_frames_ctx); - - cur = s->work_frames; - while (cur) { - s->work_frames = cur->next; - av_frame_free(&cur->frame); - av_freep(&cur); - cur = s->work_frames; - } - - av_freep(&s->mem_ids); - s->nb_mem_ids = 0; - - av_freep(&s->surface_ptrs); - s->nb_surface_ptrs = 0; -} - -static mfxStatus frame_alloc(mfxHDL pthis, mfxFrameAllocRequest *req, - mfxFrameAllocResponse *resp) -{ - AVFilterContext *ctx = pthis; - QSVDeintContext *s = ctx->priv; - - if (!(req->Type & MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET) || - !(req->Type & (MFX_MEMTYPE_FROM_VPPIN | MFX_MEMTYPE_FROM_VPPOUT)) || - !(req->Type & MFX_MEMTYPE_EXTERNAL_FRAME)) - return MFX_ERR_UNSUPPORTED; - - resp->mids = s->mem_ids; - resp->NumFrameActual = s->nb_mem_ids; - - return MFX_ERR_NONE; -} - -static mfxStatus frame_free(mfxHDL pthis, mfxFrameAllocResponse *resp) -{ - return MFX_ERR_NONE; -} - -static mfxStatus frame_lock(mfxHDL pthis, mfxMemId mid, mfxFrameData *ptr) -{ - return MFX_ERR_UNSUPPORTED; -} - -static mfxStatus frame_unlock(mfxHDL pthis, mfxMemId mid, mfxFrameData *ptr) -{ - return MFX_ERR_UNSUPPORTED; -} - -static mfxStatus frame_get_hdl(mfxHDL pthis, mfxMemId mid, mfxHDL *hdl) -{ - mfxHDLPair *pair_dst = (mfxHDLPair*)hdl; - mfxHDLPair *pair_src = (mfxHDLPair*)mid; - - pair_dst->first = pair_src->first; - - if (pair_src->second != (mfxMemId)MFX_INFINITE) - pair_dst->second = pair_src->second; - return MFX_ERR_NONE; -} - -static int init_out_session(AVFilterContext *ctx) -{ - - QSVDeintContext *s = ctx->priv; - AVHWFramesContext *hw_frames_ctx = (AVHWFramesContext*)s->hw_frames_ctx->data; - AVQSVFramesContext *hw_frames_hwctx = hw_frames_ctx->hwctx; - AVQSVDeviceContext *device_hwctx = hw_frames_ctx->device_ctx->hwctx; - int opaque = 0; - mfxHDL handle = NULL; - mfxHandleType handle_type; - mfxVersion ver; - mfxIMPL impl; - mfxVideoParam par; - mfxStatus err; - int i, ret; - -#if QSV_HAVE_OPAQUE - opaque = !!(hw_frames_hwctx->frame_type & MFX_MEMTYPE_OPAQUE_FRAME); -#endif - /* extract the properties of the "master" session given to us */ - err = MFXQueryIMPL(device_hwctx->session, &impl); - if (err == MFX_ERR_NONE) - err = MFXQueryVersion(device_hwctx->session, &ver); - if (err != MFX_ERR_NONE) { - av_log(ctx, AV_LOG_ERROR, "Error querying the session attributes\n"); - return AVERROR_UNKNOWN; - } - - if (MFX_IMPL_VIA_VAAPI == MFX_IMPL_VIA_MASK(impl)) { - handle_type = MFX_HANDLE_VA_DISPLAY; - } else if (MFX_IMPL_VIA_D3D11 == MFX_IMPL_VIA_MASK(impl)) { - handle_type = MFX_HANDLE_D3D11_DEVICE; - } else if (MFX_IMPL_VIA_D3D9 == MFX_IMPL_VIA_MASK(impl)) { - handle_type = MFX_HANDLE_D3D9_DEVICE_MANAGER; - } else { - av_log(ctx, AV_LOG_ERROR, "Error unsupported handle type\n"); - return AVERROR_UNKNOWN; - } - - err = MFXVideoCORE_GetHandle(device_hwctx->session, handle_type, &handle); - if (err < 0) - return ff_qsvvpp_print_error(ctx, err, "Error getting the session handle"); - else if (err > 0) { - ff_qsvvpp_print_warning(ctx, err, "Warning in getting the session handle"); - return AVERROR_UNKNOWN; - } - - /* create a "slave" session with those same properties, to be used for - * actual deinterlacing */ - ret = ff_qsvvpp_create_mfx_session(ctx, device_hwctx->loader, impl, &ver, - &s->session); - if (ret) - return ret; - - if (handle) { - err = MFXVideoCORE_SetHandle(s->session, handle_type, handle); - if (err != MFX_ERR_NONE) - return AVERROR_UNKNOWN; - } - - if (QSV_RUNTIME_VERSION_ATLEAST(ver, 1, 25)) { - err = MFXJoinSession(device_hwctx->session, s->session); - if (err != MFX_ERR_NONE) - return AVERROR_UNKNOWN; - } - - memset(&par, 0, sizeof(par)); - - s->deint_conf.Header.BufferId = MFX_EXTBUFF_VPP_DEINTERLACING; - s->deint_conf.Header.BufferSz = sizeof(s->deint_conf); - s->deint_conf.Mode = s->mode; - - s->ext_buffers[s->num_ext_buffers++] = (mfxExtBuffer *)&s->deint_conf; - - if (!opaque) { - mfxFrameAllocator frame_allocator = { - .pthis = ctx, - .Alloc = frame_alloc, - .Lock = frame_lock, - .Unlock = frame_unlock, - .GetHDL = frame_get_hdl, - .Free = frame_free, - }; - - s->mem_ids = av_calloc(hw_frames_hwctx->nb_surfaces, - sizeof(*s->mem_ids)); - if (!s->mem_ids) - return AVERROR(ENOMEM); - for (i = 0; i < hw_frames_hwctx->nb_surfaces; i++) - s->mem_ids[i] = hw_frames_hwctx->surfaces[i].Data.MemId; - s->nb_mem_ids = hw_frames_hwctx->nb_surfaces; - - err = MFXVideoCORE_SetFrameAllocator(s->session, &frame_allocator); - if (err != MFX_ERR_NONE) - return AVERROR_UNKNOWN; - - par.IOPattern = MFX_IOPATTERN_IN_VIDEO_MEMORY | MFX_IOPATTERN_OUT_VIDEO_MEMORY; - } -#if QSV_HAVE_OPAQUE - else { - s->surface_ptrs = av_calloc(hw_frames_hwctx->nb_surfaces, - sizeof(*s->surface_ptrs)); - - if (!s->surface_ptrs) - return AVERROR(ENOMEM); - for (i = 0; i < hw_frames_hwctx->nb_surfaces; i++) - s->surface_ptrs[i] = hw_frames_hwctx->surfaces + i; - s->nb_surface_ptrs = hw_frames_hwctx->nb_surfaces; - - s->opaque_alloc.In.Surfaces = s->surface_ptrs; - s->opaque_alloc.In.NumSurface = s->nb_surface_ptrs; - s->opaque_alloc.In.Type = hw_frames_hwctx->frame_type; - - s->opaque_alloc.Out = s->opaque_alloc.In; - - s->opaque_alloc.Header.BufferId = MFX_EXTBUFF_OPAQUE_SURFACE_ALLOCATION; - s->opaque_alloc.Header.BufferSz = sizeof(s->opaque_alloc); - - s->ext_buffers[s->num_ext_buffers++] = (mfxExtBuffer *)&s->opaque_alloc; - - par.IOPattern = MFX_IOPATTERN_IN_OPAQUE_MEMORY | MFX_IOPATTERN_OUT_OPAQUE_MEMORY; - } -#endif - - par.ExtParam = s->ext_buffers; - par.NumExtParam = s->num_ext_buffers; - - par.AsyncDepth = 1; // TODO async - - par.vpp.In = hw_frames_hwctx->surfaces[0].Info; - - par.vpp.In.CropW = ctx->inputs[0]->w; - par.vpp.In.CropH = ctx->inputs[0]->h; - - if (ctx->inputs[0]->frame_rate.num) { - par.vpp.In.FrameRateExtN = ctx->inputs[0]->frame_rate.num; - par.vpp.In.FrameRateExtD = ctx->inputs[0]->frame_rate.den; - } else { - par.vpp.In.FrameRateExtN = ctx->inputs[0]->time_base.num; - par.vpp.In.FrameRateExtD = ctx->inputs[0]->time_base.den; - } - - par.vpp.Out = par.vpp.In; - - if (ctx->outputs[0]->frame_rate.num) { - par.vpp.Out.FrameRateExtN = ctx->outputs[0]->frame_rate.num; - par.vpp.Out.FrameRateExtD = ctx->outputs[0]->frame_rate.den; - } else { - par.vpp.Out.FrameRateExtN = ctx->outputs[0]->time_base.num; - par.vpp.Out.FrameRateExtD = ctx->outputs[0]->time_base.den; - } - - /* Print input memory mode */ - ff_qsvvpp_print_iopattern(ctx, par.IOPattern & 0x0F, "VPP"); - /* Print output memory mode */ - ff_qsvvpp_print_iopattern(ctx, par.IOPattern & 0xF0, "VPP"); - err = MFXVideoVPP_Init(s->session, &par); - if (err < 0) - return ff_qsvvpp_print_error(ctx, err, - "Error opening the VPP for deinterlacing"); - else if (err > 0) { - ff_qsvvpp_print_warning(ctx, err, - "Warning in VPP initialization"); - return AVERROR_UNKNOWN; - } - - return 0; + ff_qsvvpp_close(ctx); } static int qsvdeint_config_props(AVFilterLink *outlink) { AVFilterContext *ctx = outlink->src; AVFilterLink *inlink = ctx->inputs[0]; - QSVDeintContext *s = ctx->priv; - int ret; + QSVDeintContext *s = ctx->priv; + QSVVPPParam param = { NULL }; + mfxExtBuffer *ext_buf[1]; + enum AVPixelFormat in_format; qsvdeint_uninit(ctx); - s->last_pts = AV_NOPTS_VALUE; + 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 }); - /* check that we have a hw context */ - if (!inlink->hw_frames_ctx) { - av_log(ctx, AV_LOG_ERROR, "No hw context provided on input\n"); - return AVERROR(EINVAL); - } - - s->hw_frames_ctx = av_buffer_ref(inlink->hw_frames_ctx); - if (!s->hw_frames_ctx) - return AVERROR(ENOMEM); - - av_buffer_unref(&outlink->hw_frames_ctx); - outlink->hw_frames_ctx = av_buffer_ref(inlink->hw_frames_ctx); - if (!outlink->hw_frames_ctx) { - qsvdeint_uninit(ctx); - return AVERROR(ENOMEM); - } - - ret = init_out_session(ctx); - if (ret < 0) - return ret; - - - return 0; -} - -static void clear_unused_frames(QSVDeintContext *s) -{ - QSVFrame *cur = s->work_frames; - while (cur) { - if (!cur->surface.Data.Locked) { - av_frame_free(&cur->frame); - cur->queued = 0; - } - cur = cur->next; - } -} - -static int get_free_frame(QSVDeintContext *s, QSVFrame **f) -{ - QSVFrame *frame, **last; - - clear_unused_frames(s); - - frame = s->work_frames; - last = &s->work_frames; - while (frame) { - if (!frame->queued) { - *f = frame; - return 0; - } - - last = &frame->next; - frame = frame->next; - } - - frame = av_mallocz(sizeof(*frame)); - if (!frame) - return AVERROR(ENOMEM); - *last = frame; - *f = frame; - - return 0; -} - -static int submit_frame(AVFilterContext *ctx, AVFrame *frame, - mfxFrameSurface1 **surface) -{ - QSVDeintContext *s = ctx->priv; - QSVFrame *qf; - int ret; - - ret = get_free_frame(s, &qf); - if (ret < 0) - return ret; - - qf->frame = frame; - - qf->surface = *(mfxFrameSurface1*)qf->frame->data[3]; - - qf->surface.Data.Locked = 0; - qf->surface.Info.CropW = qf->frame->width; - qf->surface.Info.CropH = qf->frame->height; - - qf->surface.Info.PicStruct = !qf->frame->interlaced_frame ? MFX_PICSTRUCT_PROGRESSIVE : - (qf->frame->top_field_first ? MFX_PICSTRUCT_FIELD_TFF : - MFX_PICSTRUCT_FIELD_BFF); - if (qf->frame->repeat_pict == 1) { - qf->surface.Info.PicStruct |= MFX_PICSTRUCT_FIELD_REPEATED; - qf->surface.Info.PicStruct |= qf->frame->top_field_first ? MFX_PICSTRUCT_FIELD_TFF : - MFX_PICSTRUCT_FIELD_BFF; - } else if (qf->frame->repeat_pict == 2) - qf->surface.Info.PicStruct |= MFX_PICSTRUCT_FRAME_DOUBLING; - else if (qf->frame->repeat_pict == 4) - qf->surface.Info.PicStruct |= MFX_PICSTRUCT_FRAME_TRIPLING; - - if (ctx->inputs[0]->frame_rate.num) { - qf->surface.Info.FrameRateExtN = ctx->inputs[0]->frame_rate.num; - qf->surface.Info.FrameRateExtD = ctx->inputs[0]->frame_rate.den; - } else { - qf->surface.Info.FrameRateExtN = ctx->inputs[0]->time_base.num; - qf->surface.Info.FrameRateExtD = ctx->inputs[0]->time_base.den; - } - - qf->surface.Data.TimeStamp = av_rescale_q(qf->frame->pts, - ctx->inputs[0]->time_base, - (AVRational){1, 90000}); - - *surface = &qf->surface; - qf->queued = 1; - - return 0; -} - -static int process_frame(AVFilterContext *ctx, const AVFrame *in, - mfxFrameSurface1 *surf_in) -{ - QSVDeintContext *s = ctx->priv; - AVFilterLink *inlink = ctx->inputs[0]; - AVFilterLink *outlink = ctx->outputs[0]; - - AVFrame *out; - mfxFrameSurface1 *surf_out; - mfxSyncPoint sync = NULL; - mfxStatus err; - int ret, again = 0; + 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; - out = ff_get_video_buffer(outlink, outlink->w, outlink->h); - if (!out) { - ret = AVERROR(ENOMEM); - goto fail; - } + param.out_sw_format = in_format; + param.ext_buf = ext_buf; - surf_out = (mfxFrameSurface1*)out->data[3]; - surf_out->Info.CropW = outlink->w; - surf_out->Info.CropH = outlink->h; - surf_out->Info.PicStruct = MFX_PICSTRUCT_PROGRESSIVE; + 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; - do { - err = MFXVideoVPP_RunFrameVPPAsync(s->session, surf_in, surf_out, - NULL, &sync); - if (err == MFX_WRN_DEVICE_BUSY) - av_usleep(1); - } while (err == MFX_WRN_DEVICE_BUSY); - - if (err == MFX_ERR_MORE_DATA) { - av_frame_free(&out); - return QSVDEINT_MORE_INPUT; - } - - if (err < 0 && err != MFX_ERR_MORE_SURFACE) { - ret = ff_qsvvpp_print_error(ctx, err, "Error during deinterlacing"); - goto fail; - } - - if (!sync) { - av_log(ctx, AV_LOG_ERROR, "No sync during deinterlacing\n"); - ret = AVERROR_UNKNOWN; - goto fail; - } - if (err == MFX_ERR_MORE_SURFACE) - again = 1; - - do { - err = MFXVideoCORE_SyncOperation(s->session, sync, 1000); - } while (err == MFX_WRN_IN_EXECUTION); - if (err < 0) { - ret = ff_qsvvpp_print_error(ctx, err, "Error synchronizing the operation"); - goto fail; - } - - ret = av_frame_copy_props(out, in); - if (ret < 0) - goto fail; - - out->width = outlink->w; - out->height = outlink->h; - out->interlaced_frame = 0; - - out->pts = av_rescale_q(out->pts, inlink->time_base, outlink->time_base); - if (out->pts == s->last_pts) - out->pts++; - s->last_pts = out->pts; - - if (outlink->frame_rate.num && outlink->frame_rate.den) - out->duration = av_rescale_q(1, av_inv_q(outlink->frame_rate), outlink->time_base); - else - out->duration = 0; - - ret = ff_filter_frame(outlink, out); - if (ret < 0) - return ret; - - return again ? QSVDEINT_MORE_OUTPUT : 0; -fail: - av_frame_free(&out); - return ret; + return ff_qsvvpp_init(ctx, ¶m); } static int qsvdeint_filter_frame(AVFilterLink *link, AVFrame *in) { - AVFilterContext *ctx = link->dst; + AVFilterContext *ctx = link->dst; + QSVVPPContext *qsv = ctx->priv; + int ret = 0; - mfxFrameSurface1 *surf_in; - int ret; + ret = ff_qsvvpp_filter_frame(qsv, link, in); + av_frame_free(&in); - ret = submit_frame(ctx, in, &surf_in); - if (ret < 0) { - av_frame_free(&in); - return ret; - } - - do { - ret = process_frame(ctx, in, surf_in); - if (ret < 0) - return ret; - } while (ret == QSVDEINT_MORE_OUTPUT); - - return 0; + return ret; } static int qsvdeint_request_frame(AVFilterLink *outlink) From patchwork Mon Jan 30 01:37:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Xiang, Haihao" X-Patchwork-Id: 40175 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:3ca3:b0:b9:1511:ac2c with SMTP id b35csp3058952pzj; Sun, 29 Jan 2023 17:38:12 -0800 (PST) X-Google-Smtp-Source: AK7set/iPnYKk9WdL6PSUssoEG0k+RggEVgQ/qFzs5ozXkVzlN1O9v2Ji/mDhb4qsl8MqLyTrCfK X-Received: by 2002:a17:906:a408:b0:878:8073:4915 with SMTP id l8-20020a170906a40800b0087880734915mr12352871ejz.15.1675042691945; Sun, 29 Jan 2023 17:38:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675042691; cv=none; d=google.com; s=arc-20160816; b=fvYbY9CAJeLjc1nX1lE4QT+rGFZRb29OKQjervxjz/OHQNaofRcaZazg9PfSaDa9pI fWPy4tFX0c7JPBADz2ZCuDh4ID0a5DZL6ut/mOLq2+Xt4kYNIYwPMEv7p+R29e2t6tPt zWoafzSaKZf5eurgolHXfVoOZmPitQCGfZToGehjFi9KGK8VZ4VtKBaThd47X1GQToi3 mZBKm9N9POmXdTzQ2YseIUCZmcVqSHkSDVjtjx0B8Tl/L3vQ1oLOiVy5bOr8igAgSTeJ h4JsZNQxrNVkZiM+NgxOGll2iL8tfBidDeikISRSN5hDIPGHOoatA7F/DqtiXHHKv11m uH7g== 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:dkim-signature:delivered-to; bh=4V4vWBWxDS5YktvMUEEuchFMbaQ7cuR8nMIHm1ohAio=; b=vlllGnOXD/BGJaHqIfJHyLf8IoDEZ0mRW1NlPZb1fQ9UkBdfsr1iCt1IQ6lpfNiiol Y/hyz9g8q2x9rZ9VMCJd+mXjjWcy78AbFfy7cGwwzFP+YfZ9r15kUd+NaHAcJBj4WBqv EdGtEVuXQdOpQE7ruBthTJipk+VpigDoysnVr0SvYShy/i/Qm773IGZRuVUMxhCumSkF cbkL1kOARUD/UTxJ6Gnv3KOVKKkNSmMfHVuTLUQuUh83V/yCxnpeqztqWloqJi5dFaE7 C2SalON4nlyr2ibmdTNJKa6PVa2cSqye7FneYG1Yb8uwytAM4KWC5ahARcNFL2b9gAtx UXag== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@intel.com header.s=Intel header.b=YVtIIe0R; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id gk24-20020a17090790d800b008798751cd4bsi9727215ejb.714.2023.01.29.17.38.11; Sun, 29 Jan 2023 17:38:11 -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=@intel.com header.s=Intel header.b=YVtIIe0R; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id CB44168BDB2; Mon, 30 Jan 2023 03:37:53 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1315568BD9A for ; Mon, 30 Jan 2023 03:37:46 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1675042672; x=1706578672; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=l0v2Q3fhWIZjOHue9mKuvdKXqneJPa7nR5mh8s4jZA0=; b=YVtIIe0Ru2ct9RX7MHM0DanLmgFqhYYpEwSeb98U6PrcQ3/6wOwzUg2l y0/wncKAax5FwQ5N79VVpOREWItkp8QJ+QvZPSX9nneJqsVSORujpTLGc 5Koa1716AeK4V1gHYEYASPz72LP9b/XtAETF5BxiWJiIEBbjpVA9Pod5T t2hawhJ71dsIQ1Ye9HfuLqAAYnxI1cc4+q3ggCDCOdlFeDBNf7bWikOTK Dqb342gpfbYoLHPYnB0DXsxQCRNqcm8T8d+8gsPTDsWmG43/5dEpVnC81 kOXmkKkax+Wm9qrcBUlxaE0sDFqQUEm4fo64or7Y8z8rueGyIrK6m1jhY A==; X-IronPort-AV: E=McAfee;i="6500,9779,10605"; a="307798855" X-IronPort-AV: E=Sophos;i="5.97,256,1669104000"; d="scan'208";a="307798855" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Jan 2023 17:37:41 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10605"; a="772305366" X-IronPort-AV: E=Sophos;i="5.97,256,1669104000"; d="scan'208";a="772305366" Received: from xhh-dg164.sh.intel.com ([10.238.5.169]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Jan 2023 17:37:40 -0800 From: "Xiang, Haihao" To: ffmpeg-devel@ffmpeg.org Date: Mon, 30 Jan 2023 09:37:19 +0800 Message-Id: <20230130013719.7167-3-haihao.xiang@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230130013719.7167-1-haihao.xiang@intel.com> References: <20230130013719.7167-1-haihao.xiang@intel.com> Subject: [FFmpeg-devel] [PATCH 3/3] 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: lESAm+LGG3G9 From: Haihao Xiang QSVDeintContext and VPPContext have the same base context, and all features in deinterlace_qsv are implemented in vpp_qsv filter, so deinterlace_qsv can be taken as a special case of vpp_qsv filter, and we may use VPPContext with a different option array, preinit callback and support pixel formats to implement deinterlace_qsv, then remove QSVDeintContext. Signed-off-by: Haihao Xiang --- libavfilter/Makefile | 2 +- libavfilter/vf_deinterlace_qsv.c | 166 ------------------------------- libavfilter/vf_vpp_qsv.c | 25 +++++ 3 files changed, 26 insertions(+), 167 deletions(-) delete mode 100644 libavfilter/vf_deinterlace_qsv.c diff --git a/libavfilter/Makefile b/libavfilter/Makefile index b45dcd00fc..0173b11870 100644 --- a/libavfilter/Makefile +++ b/libavfilter/Makefile @@ -260,7 +260,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 8173386780..0000000000 --- a/libavfilter/vf_deinterlace_qsv.c +++ /dev/null @@ -1,166 +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" - -#define MFX_IMPL_VIA_MASK(impl) (0x0f00 & (impl)) - -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_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, - .get_buffer.video = ff_qsvvpp_get_video_buffer, - }, -}; - -static const AVFilterPad qsvdeint_outputs[] = { - { - .name = "default", - .type = AVMEDIA_TYPE_VIDEO, - .config_props = qsvdeint_config_props, - .request_frame = qsvdeint_request_frame, - }, -}; - -const AVFilter ff_vf_deinterlace_qsv = { - .name = "deinterlace_qsv", - .description = NULL_IF_CONFIG_SMALL("QuickSync video deinterlacing"), - - .uninit = qsvdeint_uninit, - - .priv_size = sizeof(QSVDeintContext), - .priv_class = &qsvdeint_class, - - FILTER_INPUTS(qsvdeint_inputs), - FILTER_OUTPUTS(qsvdeint_outputs), - FILTER_SINGLE_PIXFMT(AV_PIX_FMT_QSV), - - .flags_internal = FF_FILTER_FLAG_HWFRAME_AWARE, -}; diff --git a/libavfilter/vf_vpp_qsv.c b/libavfilter/vf_vpp_qsv.c index aac0a234c3..010b69943a 100644 --- a/libavfilter/vf_vpp_qsv.c +++ b/libavfilter/vf_vpp_qsv.c @@ -752,3 +752,28 @@ static av_cold int qsvscale_preinit(AVFilterContext *ctx) DEFINE_QSV_FILTER(qsvscale, scale, "scaling and format conversion", FILTER_SINGLE_PIXFMT(AV_PIX_FMT_QSV)); #endif + +#if CONFIG_DEINTERLACE_QSV_FILTER + +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"}, + + { NULL }, +}; + +static av_cold int qsvdeint_preinit(AVFilterContext *ctx) +{ + VPPContext *vpp = ctx->priv; + + vpp_preinit(ctx); + vpp->has_passthrough = 0; + vpp->field_rate = 1; + + return 0; +} + +DEFINE_QSV_FILTER(qsvdeint, deinterlace, "deinterlacing", FILTER_SINGLE_PIXFMT(AV_PIX_FMT_QSV)) + +#endif