lavfi/deinterlace_qsv: re-use VPPContext for deinterlace_qsv filter
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 <haihao.xiang@intel.com>
This commit is contained in:
parent
a48c95d3c9
commit
b92028346c
@ -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
|
||||
|
@ -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 <mfxvideo.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#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,
|
||||
};
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user