X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavfilter%2Fvf_delogo.c;h=a80b1fe571b9c4484123a44f7e1641f67e2cb612;hb=419e1b746354afaba4f496a5a8fcf388cd05adda;hp=fbc5bf6c0cf607bb0c26f07699b55fbcdd2608c0;hpb=dfa07e89289b25d44b6f2b959130077913921e0a;p=ffmpeg diff --git a/libavfilter/vf_delogo.c b/libavfilter/vf_delogo.c index fbc5bf6c0cf..a80b1fe571b 100644 --- a/libavfilter/vf_delogo.c +++ b/libavfilter/vf_delogo.c @@ -29,6 +29,9 @@ #include "libavutil/opt.h" #include "libavutil/pixdesc.h" #include "avfilter.h" +#include "formats.h" +#include "internal.h" +#include "video.h" /** * Apply a simple delogo algorithm to the image in dst and put the @@ -148,16 +151,7 @@ static const AVOption delogo_options[]= { {NULL}, }; -static const char *delogo_get_name(void *ctx) -{ - return "delogo"; -} - -static const AVClass delogo_class = { - .class_name = "DelogoContext", - .item_name = delogo_get_name, - .option = delogo_options, -}; +AVFILTER_DEFINE_CLASS(delogo); static int query_formats(AVFilterContext *ctx) { @@ -168,11 +162,11 @@ static int query_formats(AVFilterContext *ctx) PIX_FMT_NONE }; - avfilter_set_common_pixel_formats(ctx, avfilter_make_format_list(pix_fmts)); + ff_set_common_formats(ctx, ff_make_format_list(pix_fmts)); return 0; } -static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque) +static av_cold int init(AVFilterContext *ctx, const char *args) { DelogoContext *delogo = ctx->priv; int ret = 0; @@ -186,10 +180,8 @@ static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque) if (ret == 5) { if (delogo->band < 0) delogo->show = 1; - } else if ((ret = (av_set_options_string(delogo, args, "=", ":"))) < 0) { - av_log(ctx, AV_LOG_ERROR, "Error parsing options string: '%s'\n", args); + } else if ((ret = (av_set_options_string(delogo, args, "=", ":"))) < 0) return ret; - } #define CHECK_UNSET_OPT(opt) \ if (delogo->opt == -1) { \ @@ -204,7 +196,7 @@ static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque) if (delogo->show) delogo->band = 4; - av_log(ctx, AV_LOG_INFO, "x:%d y:%d, w:%d h:%d band:%d show:%d\n", + av_log(ctx, AV_LOG_VERBOSE, "x:%d y:%d, w:%d h:%d band:%d show:%d\n", delogo->x, delogo->y, delogo->w, delogo->h, delogo->band, delogo->show); delogo->w += delogo->band*2; @@ -215,36 +207,22 @@ static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque) return 0; } -static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *inpicref) +static int null_draw_slice(AVFilterLink *link, int y, int h, int slice_dir) { - AVFilterLink *outlink = inlink->dst->outputs[0]; - AVFilterBufferRef *outpicref; - - if (inpicref->perms & AV_PERM_PRESERVE) { - outpicref = avfilter_get_video_buffer(outlink, AV_PERM_WRITE, - outlink->w, outlink->h); - avfilter_copy_buffer_ref_props(outpicref, inpicref); - outpicref->video->w = outlink->w; - outpicref->video->h = outlink->h; - } else - outpicref = inpicref; - - outlink->out_buf = outpicref; - avfilter_start_frame(outlink, avfilter_ref_buffer(outpicref, ~0)); + return 0; } -static void null_draw_slice(AVFilterLink *link, int y, int h, int slice_dir) { } - -static void end_frame(AVFilterLink *inlink) +static int end_frame(AVFilterLink *inlink) { DelogoContext *delogo = inlink->dst->priv; AVFilterLink *outlink = inlink->dst->outputs[0]; AVFilterBufferRef *inpicref = inlink ->cur_buf; AVFilterBufferRef *outpicref = outlink->out_buf; - int direct = inpicref == outpicref; + int direct = inpicref->buf == outpicref->buf; int hsub0 = av_pix_fmt_descriptors[inlink->format].log2_chroma_w; int vsub0 = av_pix_fmt_descriptors[inlink->format].log2_chroma_h; int plane; + int ret; for (plane = 0; plane < 4 && inpicref->data[plane]; plane++) { int hsub = plane == 1 || plane == 2 ? hsub0 : 0; @@ -259,11 +237,10 @@ static void end_frame(AVFilterLink *inlink) delogo->show, direct); } - avfilter_draw_slice(outlink, 0, inlink->h, 1); - avfilter_end_frame(outlink); - avfilter_unref_buffer(inpicref); - if (!direct) - avfilter_unref_buffer(outpicref); + if ((ret = ff_draw_slice(outlink, 0, inlink->h, 1)) < 0 || + (ret = ff_end_frame(outlink)) < 0) + return ret; + return 0; } AVFilter avfilter_vf_delogo = { @@ -273,16 +250,16 @@ AVFilter avfilter_vf_delogo = { .init = init, .query_formats = query_formats, - .inputs = (const AVFilterPad[]) {{ .name = "default", - .type = AVMEDIA_TYPE_VIDEO, - .get_video_buffer = avfilter_null_get_video_buffer, - .start_frame = start_frame, - .draw_slice = null_draw_slice, - .end_frame = end_frame, - .min_perms = AV_PERM_WRITE | AV_PERM_READ, - .rej_perms = AV_PERM_PRESERVE }, - { .name = NULL}}, - .outputs = (const AVFilterPad[]) {{ .name = "default", - .type = AVMEDIA_TYPE_VIDEO, }, - { .name = NULL}}, + .inputs = (const AVFilterPad[]) {{ .name = "default", + .type = AVMEDIA_TYPE_VIDEO, + .get_video_buffer = ff_null_get_video_buffer, + .start_frame = ff_inplace_start_frame, + .draw_slice = null_draw_slice, + .end_frame = end_frame, + .min_perms = AV_PERM_WRITE | AV_PERM_READ, + .rej_perms = AV_PERM_PRESERVE }, + { .name = NULL}}, + .outputs = (const AVFilterPad[]) {{ .name = "default", + .type = AVMEDIA_TYPE_VIDEO, }, + { .name = NULL}}, };