avfilter/yadif_common: factorize some part of the config_output and the uninit functions
This unifies slightly diverged code and ensures that cc_fifo is always initialized. Signed-off-by: Marton Balint <cus@passwd.hu>
This commit is contained in:
parent
8fccd6d510
commit
268062fa15
@ -137,17 +137,6 @@ static void filter(AVFilterContext *ctx, AVFrame *dstpic,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static av_cold void uninit(AVFilterContext *ctx)
|
|
||||||
{
|
|
||||||
BWDIFContext *bwdif = ctx->priv;
|
|
||||||
YADIFContext *yadif = &bwdif->yadif;
|
|
||||||
|
|
||||||
av_frame_free(&yadif->prev);
|
|
||||||
av_frame_free(&yadif->cur );
|
|
||||||
av_frame_free(&yadif->next);
|
|
||||||
ff_ccfifo_uninit(&yadif->cc_fifo);
|
|
||||||
}
|
|
||||||
|
|
||||||
static const enum AVPixelFormat pix_fmts[] = {
|
static const enum AVPixelFormat pix_fmts[] = {
|
||||||
AV_PIX_FMT_YUV410P, AV_PIX_FMT_YUV411P, AV_PIX_FMT_YUV420P,
|
AV_PIX_FMT_YUV410P, AV_PIX_FMT_YUV411P, AV_PIX_FMT_YUV420P,
|
||||||
AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV440P, AV_PIX_FMT_YUV444P,
|
AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV440P, AV_PIX_FMT_YUV444P,
|
||||||
@ -176,20 +165,9 @@ static int config_props(AVFilterLink *link)
|
|||||||
YADIFContext *yadif = &s->yadif;
|
YADIFContext *yadif = &s->yadif;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
link->time_base = av_mul_q(ctx->inputs[0]->time_base, (AVRational){1, 2});
|
ret = ff_yadif_config_output_common(link);
|
||||||
link->w = link->src->inputs[0]->w;
|
if (ret < 0)
|
||||||
link->h = link->src->inputs[0]->h;
|
return AVERROR(EINVAL);
|
||||||
|
|
||||||
if(yadif->mode&1)
|
|
||||||
link->frame_rate = av_mul_q(link->src->inputs[0]->frame_rate, (AVRational){2,1});
|
|
||||||
else
|
|
||||||
link->frame_rate = ctx->inputs[0]->frame_rate;
|
|
||||||
|
|
||||||
ret = ff_ccfifo_init(&yadif->cc_fifo, link->frame_rate, ctx);
|
|
||||||
if (ret < 0 ) {
|
|
||||||
av_log(ctx, AV_LOG_ERROR, "Failure to setup CC FIFO queue\n");
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
yadif->csp = av_pix_fmt_desc_get(link->format);
|
yadif->csp = av_pix_fmt_desc_get(link->format);
|
||||||
yadif->filter = filter;
|
yadif->filter = filter;
|
||||||
@ -251,7 +229,7 @@ const AVFilter ff_vf_bwdif = {
|
|||||||
.description = NULL_IF_CONFIG_SMALL("Deinterlace the input image."),
|
.description = NULL_IF_CONFIG_SMALL("Deinterlace the input image."),
|
||||||
.priv_size = sizeof(BWDIFContext),
|
.priv_size = sizeof(BWDIFContext),
|
||||||
.priv_class = &bwdif_class,
|
.priv_class = &bwdif_class,
|
||||||
.uninit = uninit,
|
.uninit = ff_yadif_uninit,
|
||||||
FILTER_INPUTS(avfilter_vf_bwdif_inputs),
|
FILTER_INPUTS(avfilter_vf_bwdif_inputs),
|
||||||
FILTER_OUTPUTS(avfilter_vf_bwdif_outputs),
|
FILTER_OUTPUTS(avfilter_vf_bwdif_outputs),
|
||||||
FILTER_PIXFMTS_ARRAY(pix_fmts),
|
FILTER_PIXFMTS_ARRAY(pix_fmts),
|
||||||
|
@ -208,9 +208,7 @@ static av_cold void deint_cuda_uninit(AVFilterContext *ctx)
|
|||||||
CHECK_CU(cu->cuCtxPopCurrent(&dummy));
|
CHECK_CU(cu->cuCtxPopCurrent(&dummy));
|
||||||
}
|
}
|
||||||
|
|
||||||
av_frame_free(&y->prev);
|
ff_yadif_uninit(ctx);
|
||||||
av_frame_free(&y->cur);
|
|
||||||
av_frame_free(&y->next);
|
|
||||||
|
|
||||||
av_buffer_unref(&s->device_ref);
|
av_buffer_unref(&s->device_ref);
|
||||||
s->hwctx = NULL;
|
s->hwctx = NULL;
|
||||||
@ -288,14 +286,9 @@ static int config_output(AVFilterLink *link)
|
|||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
link->time_base = av_mul_q(ctx->inputs[0]->time_base, (AVRational){1, 2});
|
ret = ff_yadif_config_output_common(link);
|
||||||
link->w = ctx->inputs[0]->w;
|
if (ret < 0)
|
||||||
link->h = ctx->inputs[0]->h;
|
goto exit;
|
||||||
|
|
||||||
if(y->mode & 1)
|
|
||||||
link->frame_rate = av_mul_q(ctx->inputs[0]->frame_rate,
|
|
||||||
(AVRational){2, 1});
|
|
||||||
|
|
||||||
|
|
||||||
y->csp = av_pix_fmt_desc_get(output_frames->sw_format);
|
y->csp = av_pix_fmt_desc_get(output_frames->sw_format);
|
||||||
y->filter = filter;
|
y->filter = filter;
|
||||||
|
@ -296,6 +296,8 @@ static void bwdif_vulkan_uninit(AVFilterContext *avctx)
|
|||||||
|
|
||||||
ff_vk_uninit(&s->vkctx);
|
ff_vk_uninit(&s->vkctx);
|
||||||
|
|
||||||
|
ff_yadif_uninit(avctx);
|
||||||
|
|
||||||
s->initialized = 0;
|
s->initialized = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -354,13 +356,9 @@ static int bwdif_vulkan_config_output(AVFilterLink *outlink)
|
|||||||
if (!outlink->hw_frames_ctx)
|
if (!outlink->hw_frames_ctx)
|
||||||
return AVERROR(ENOMEM);
|
return AVERROR(ENOMEM);
|
||||||
|
|
||||||
outlink->time_base = av_mul_q(avctx->inputs[0]->time_base, (AVRational){1, 2});
|
err = ff_yadif_config_output_common(outlink);
|
||||||
outlink->w = vkctx->output_width;
|
if (err < 0)
|
||||||
outlink->h = vkctx->output_height;
|
return err;
|
||||||
|
|
||||||
if (y->mode & 1)
|
|
||||||
outlink->frame_rate = av_mul_q(avctx->inputs[0]->frame_rate,
|
|
||||||
(AVRational){2, 1});
|
|
||||||
|
|
||||||
y->csp = av_pix_fmt_desc_get(vkctx->frames->sw_format);
|
y->csp = av_pix_fmt_desc_get(vkctx->frames->sw_format);
|
||||||
y->filter = bwdif_vulkan_filter_frame;
|
y->filter = bwdif_vulkan_filter_frame;
|
||||||
|
@ -251,16 +251,6 @@ static void filter(AVFilterContext *ctx, AVFrame *dstpic,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static av_cold void uninit(AVFilterContext *ctx)
|
|
||||||
{
|
|
||||||
YADIFContext *yadif = ctx->priv;
|
|
||||||
|
|
||||||
av_frame_free(&yadif->prev);
|
|
||||||
av_frame_free(&yadif->cur );
|
|
||||||
av_frame_free(&yadif->next);
|
|
||||||
ff_ccfifo_uninit(&yadif->cc_fifo);
|
|
||||||
}
|
|
||||||
|
|
||||||
static const enum AVPixelFormat pix_fmts[] = {
|
static const enum AVPixelFormat pix_fmts[] = {
|
||||||
AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV444P,
|
AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV444P,
|
||||||
AV_PIX_FMT_YUV410P, AV_PIX_FMT_YUV411P, AV_PIX_FMT_YUV440P,
|
AV_PIX_FMT_YUV410P, AV_PIX_FMT_YUV411P, AV_PIX_FMT_YUV440P,
|
||||||
@ -285,26 +275,9 @@ static int config_output(AVFilterLink *outlink)
|
|||||||
YADIFContext *s = ctx->priv;
|
YADIFContext *s = ctx->priv;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
outlink->time_base = av_mul_q(ctx->inputs[0]->time_base, (AVRational){1, 2});
|
ret = ff_yadif_config_output_common(outlink);
|
||||||
outlink->w = ctx->inputs[0]->w;
|
if (ret < 0)
|
||||||
outlink->h = ctx->inputs[0]->h;
|
|
||||||
|
|
||||||
if(s->mode & 1)
|
|
||||||
outlink->frame_rate = av_mul_q(ctx->inputs[0]->frame_rate,
|
|
||||||
(AVRational){2, 1});
|
|
||||||
else
|
|
||||||
outlink->frame_rate = ctx->inputs[0]->frame_rate;
|
|
||||||
|
|
||||||
ret = ff_ccfifo_init(&s->cc_fifo, outlink->frame_rate, ctx);
|
|
||||||
if (ret < 0) {
|
|
||||||
av_log(ctx, AV_LOG_ERROR, "Failure to setup CC FIFO queue\n");
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
|
||||||
|
|
||||||
if (outlink->w < 3 || outlink->h < 3) {
|
|
||||||
av_log(ctx, AV_LOG_ERROR, "Video of less than 3 columns or lines is not supported\n");
|
|
||||||
return AVERROR(EINVAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
s->csp = av_pix_fmt_desc_get(outlink->format);
|
s->csp = av_pix_fmt_desc_get(outlink->format);
|
||||||
s->filter = filter;
|
s->filter = filter;
|
||||||
@ -354,7 +327,7 @@ const AVFilter ff_vf_yadif = {
|
|||||||
.description = NULL_IF_CONFIG_SMALL("Deinterlace the input image."),
|
.description = NULL_IF_CONFIG_SMALL("Deinterlace the input image."),
|
||||||
.priv_size = sizeof(YADIFContext),
|
.priv_size = sizeof(YADIFContext),
|
||||||
.priv_class = &yadif_class,
|
.priv_class = &yadif_class,
|
||||||
.uninit = uninit,
|
.uninit = ff_yadif_uninit,
|
||||||
FILTER_INPUTS(avfilter_vf_yadif_inputs),
|
FILTER_INPUTS(avfilter_vf_yadif_inputs),
|
||||||
FILTER_OUTPUTS(avfilter_vf_yadif_outputs),
|
FILTER_OUTPUTS(avfilter_vf_yadif_outputs),
|
||||||
FILTER_PIXFMTS_ARRAY(pix_fmts),
|
FILTER_PIXFMTS_ARRAY(pix_fmts),
|
||||||
|
@ -200,10 +200,7 @@ static av_cold void deint_cuda_uninit(AVFilterContext *ctx)
|
|||||||
CHECK_CU(cu->cuCtxPopCurrent(&dummy));
|
CHECK_CU(cu->cuCtxPopCurrent(&dummy));
|
||||||
}
|
}
|
||||||
|
|
||||||
av_frame_free(&y->prev);
|
ff_yadif_uninit(ctx);
|
||||||
av_frame_free(&y->cur);
|
|
||||||
av_frame_free(&y->next);
|
|
||||||
ff_ccfifo_uninit(&y->cc_fifo);
|
|
||||||
|
|
||||||
av_buffer_unref(&s->device_ref);
|
av_buffer_unref(&s->device_ref);
|
||||||
s->hwctx = NULL;
|
s->hwctx = NULL;
|
||||||
@ -281,27 +278,9 @@ static int config_output(AVFilterLink *link)
|
|||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
link->time_base = av_mul_q(ctx->inputs[0]->time_base, (AVRational){1, 2});
|
ret = ff_yadif_config_output_common(link);
|
||||||
link->w = ctx->inputs[0]->w;
|
if (ret < 0)
|
||||||
link->h = ctx->inputs[0]->h;
|
|
||||||
|
|
||||||
if(y->mode & 1)
|
|
||||||
link->frame_rate = av_mul_q(ctx->inputs[0]->frame_rate,
|
|
||||||
(AVRational){2, 1});
|
|
||||||
else
|
|
||||||
link->frame_rate = ctx->inputs[0]->frame_rate;
|
|
||||||
|
|
||||||
ret = ff_ccfifo_init(&y->cc_fifo, link->frame_rate, ctx);
|
|
||||||
if (ret < 0) {
|
|
||||||
av_log(ctx, AV_LOG_ERROR, "Failure to setup CC FIFO queue\n");
|
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
|
||||||
|
|
||||||
if (link->w < 3 || link->h < 3) {
|
|
||||||
av_log(ctx, AV_LOG_ERROR, "Video of less than 3 columns or lines is not supported\n");
|
|
||||||
ret = AVERROR(EINVAL);
|
|
||||||
goto exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
y->csp = av_pix_fmt_desc_get(output_frames->sw_format);
|
y->csp = av_pix_fmt_desc_get(output_frames->sw_format);
|
||||||
y->filter = filter;
|
y->filter = filter;
|
||||||
|
@ -174,9 +174,7 @@ static av_cold void do_uninit(AVFilterContext *ctx) API_AVAILABLE(macos(10.11),
|
|||||||
YADIFVTContext *s = ctx->priv;
|
YADIFVTContext *s = ctx->priv;
|
||||||
YADIFContext *y = &s->yadif;
|
YADIFContext *y = &s->yadif;
|
||||||
|
|
||||||
av_frame_free(&y->prev);
|
ff_yadif_uninit(ctx);
|
||||||
av_frame_free(&y->cur);
|
|
||||||
av_frame_free(&y->next);
|
|
||||||
|
|
||||||
av_buffer_unref(&s->device_ref);
|
av_buffer_unref(&s->device_ref);
|
||||||
av_buffer_unref(&s->input_frames_ref);
|
av_buffer_unref(&s->input_frames_ref);
|
||||||
@ -363,20 +361,9 @@ static int do_config_output(AVFilterLink *link) API_AVAILABLE(macos(10.11), ios(
|
|||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
link->time_base.num = ctx->inputs[0]->time_base.num;
|
ret = ff_yadif_config_output_common(link);
|
||||||
link->time_base.den = ctx->inputs[0]->time_base.den * 2;
|
if (ret < 0)
|
||||||
link->w = ctx->inputs[0]->w;
|
|
||||||
link->h = ctx->inputs[0]->h;
|
|
||||||
|
|
||||||
if(y->mode & 1)
|
|
||||||
link->frame_rate = av_mul_q(ctx->inputs[0]->frame_rate,
|
|
||||||
(AVRational){2, 1});
|
|
||||||
|
|
||||||
if (link->w < 3 || link->h < 3) {
|
|
||||||
av_log(ctx, AV_LOG_ERROR, "Video of less than 3 columns or lines is not supported\n");
|
|
||||||
ret = AVERROR(EINVAL);
|
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
|
||||||
|
|
||||||
y->csp = av_pix_fmt_desc_get(output_frames->sw_format);
|
y->csp = av_pix_fmt_desc_get(output_frames->sw_format);
|
||||||
y->filter = filter;
|
y->filter = filter;
|
||||||
|
@ -94,6 +94,10 @@ int ff_yadif_filter_frame(AVFilterLink *link, AVFrame *frame);
|
|||||||
|
|
||||||
int ff_yadif_request_frame(AVFilterLink *link);
|
int ff_yadif_request_frame(AVFilterLink *link);
|
||||||
|
|
||||||
|
int ff_yadif_config_output_common(AVFilterLink *outlink);
|
||||||
|
|
||||||
|
void ff_yadif_uninit(AVFilterContext *ctx);
|
||||||
|
|
||||||
extern const AVOption ff_yadif_options[];
|
extern const AVOption ff_yadif_options[];
|
||||||
|
|
||||||
#endif /* AVFILTER_YADIF_H */
|
#endif /* AVFILTER_YADIF_H */
|
||||||
|
@ -209,6 +209,46 @@ int ff_yadif_request_frame(AVFilterLink *link)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ff_yadif_config_output_common(AVFilterLink *outlink)
|
||||||
|
{
|
||||||
|
AVFilterContext *ctx = outlink->src;
|
||||||
|
YADIFContext *yadif = ctx->priv;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
outlink->time_base = av_mul_q(ctx->inputs[0]->time_base, (AVRational){1, 2});
|
||||||
|
outlink->w = ctx->inputs[0]->w;
|
||||||
|
outlink->h = ctx->inputs[0]->h;
|
||||||
|
|
||||||
|
if (outlink->w < 3 || outlink->h < 3) {
|
||||||
|
av_log(ctx, AV_LOG_ERROR, "Video of less than 3 columns or lines is not supported\n");
|
||||||
|
return AVERROR(EINVAL);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(yadif->mode & 1)
|
||||||
|
outlink->frame_rate = av_mul_q(ctx->inputs[0]->frame_rate,
|
||||||
|
(AVRational){2, 1});
|
||||||
|
else
|
||||||
|
outlink->frame_rate = ctx->inputs[0]->frame_rate;
|
||||||
|
|
||||||
|
ret = ff_ccfifo_init(&yadif->cc_fifo, outlink->frame_rate, ctx);
|
||||||
|
if (ret < 0) {
|
||||||
|
av_log(ctx, AV_LOG_ERROR, "Failure to setup CC FIFO queue\n");
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ff_yadif_uninit(AVFilterContext *ctx)
|
||||||
|
{
|
||||||
|
YADIFContext *yadif = ctx->priv;
|
||||||
|
|
||||||
|
av_frame_free(&yadif->prev);
|
||||||
|
av_frame_free(&yadif->cur );
|
||||||
|
av_frame_free(&yadif->next);
|
||||||
|
ff_ccfifo_uninit(&yadif->cc_fifo);
|
||||||
|
}
|
||||||
|
|
||||||
#define OFFSET(x) offsetof(YADIFContext, x)
|
#define OFFSET(x) offsetof(YADIFContext, x)
|
||||||
#define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
|
#define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user