]> git.sesse.net Git - ffmpeg/blobdiff - libavfilter/vf_idet.c
Merge commit '3f95f0dda55fca74b646937095a02a8fa9776622'
[ffmpeg] / libavfilter / vf_idet.c
index cc20fac3e16f78720cada2e5aa74bc8669052415..513a8e397a241496cc0e883b32166dc91a7bc409 100644 (file)
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include <float.h> /* FLT_MAX */
+
 #include "libavutil/cpu.h"
 #include "libavutil/common.h"
+#include "libavutil/opt.h"
 #include "libavutil/pixdesc.h"
 #include "avfilter.h"
 #include "internal.h"
 
-#undef NDEBUG
-#include <assert.h>
-
 #define HIST_SIZE 4
 
 typedef enum {
@@ -37,12 +37,13 @@ typedef enum {
 } Type;
 
 typedef struct {
+    const AVClass *class;
     float interlace_threshold;
     float progressive_threshold;
 
     Type last_type;
-    Type prestat[4];
-    Type poststat[4];
+    int prestat[4];
+    int poststat[4];
 
     uint8_t history[HIST_SIZE];
 
@@ -54,6 +55,17 @@ typedef struct {
     const AVPixFmtDescriptor *csp;
 } IDETContext;
 
+#define OFFSET(x) offsetof(IDETContext, x)
+#define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
+
+static const AVOption idet_options[] = {
+    { "intl_thres", "set interlacing threshold", OFFSET(interlace_threshold),   AV_OPT_TYPE_FLOAT, {.dbl = 1.01}, -1, FLT_MAX, FLAGS },
+    { "prog_thres", "set progressive threshold", OFFSET(progressive_threshold), AV_OPT_TYPE_FLOAT, {.dbl = 2.5},  -1, FLT_MAX, FLAGS },
+    { NULL }
+};
+
+AVFILTER_DEFINE_CLASS(idet);
+
 static const char *type2str(Type type)
 {
     switch(type) {
@@ -165,7 +177,7 @@ static void filter(AVFilterContext *ctx)
     av_log(ctx, AV_LOG_DEBUG, "Single frame:%s, Multi frame:%s\n", type2str(type), type2str(idet->last_type));
 }
 
-static int start_frame(AVFilterLink *link, AVFilterBufferRef *picref)
+static int filter_frame(AVFilterLink *link, AVFilterBufferRef *picref)
 {
     AVFilterContext *ctx = link->dst;
     IDETContext *idet = ctx->priv;
@@ -175,7 +187,6 @@ static int start_frame(AVFilterLink *link, AVFilterBufferRef *picref)
     idet->prev = idet->cur;
     idet->cur  = idet->next;
     idet->next = picref;
-    link->cur_buf = NULL;
 
     if (!idet->cur)
         return 0;
@@ -183,17 +194,6 @@ static int start_frame(AVFilterLink *link, AVFilterBufferRef *picref)
     if (!idet->prev)
         idet->prev = avfilter_ref_buffer(idet->cur, ~0);
 
-    return ff_start_frame(ctx->outputs[0], avfilter_ref_buffer(idet->cur, ~0));
-}
-
-static int end_frame(AVFilterLink *link)
-{
-    AVFilterContext *ctx = link->dst;
-    IDETContext *idet = ctx->priv;
-
-    if (!idet->cur)
-        return 0;
-
     if (!idet->csp)
         idet->csp = av_pix_fmt_desc_get(link->format);
     if (idet->csp->comp[0].depth_minus1 / 8 == 1)
@@ -201,8 +201,7 @@ static int end_frame(AVFilterLink *link)
 
     filter(ctx);
 
-    ff_draw_slice(ctx->outputs[0], 0, link->h, 1);
-    return ff_end_frame(ctx->outputs[0]);
+    return ff_filter_frame(ctx->outputs[0], avfilter_ref_buffer(idet->cur, ~0));
 }
 
 static int request_frame(AVFilterLink *link)
@@ -220,23 +219,6 @@ static int request_frame(AVFilterLink *link)
     return 0;
 }
 
-static int poll_frame(AVFilterLink *link)
-{
-    IDETContext *idet = link->src->priv;
-    int ret, val;
-
-    val = ff_poll_frame(link->src->inputs[0]);
-
-    if (val >= 1 && !idet->next) { //FIXME change API to not requre this red tape
-        if ((ret = ff_request_frame(link->src->inputs[0])) < 0)
-            return ret;
-        val = ff_poll_frame(link->src->inputs[0]);
-    }
-    assert(idet->next || !val);
-
-    return val;
-}
-
 static av_cold void uninit(AVFilterContext *ctx)
 {
     IDETContext *idet = ctx->priv;
@@ -292,13 +274,14 @@ static int query_formats(AVFilterContext *ctx)
 static av_cold int init(AVFilterContext *ctx, const char *args)
 {
     IDETContext *idet = ctx->priv;
+    static const char *shorthand[] = { "intl_thres", "prog_thres", NULL };
+    int ret;
 
-    idet->csp = NULL;
-
-    idet->interlace_threshold   = 1.01;
-    idet->progressive_threshold = 2.5;
+    idet->class = &idet_class;
+    av_opt_set_defaults(idet);
 
-    if (args) sscanf(args, "%f:%f", &idet->interlace_threshold, &idet->progressive_threshold);
+    if ((ret = av_opt_set_from_string(idet, args, shorthand, "=", ":")) < 0)
+        return ret;
 
     idet->last_type = UNDETERMINED;
     memset(idet->history, UNDETERMINED, HIST_SIZE);
@@ -308,15 +291,12 @@ static av_cold int init(AVFilterContext *ctx, const char *args)
     return 0;
 }
 
-static int null_draw_slice(AVFilterLink *link, int y, int h, int slice_dir) { return 0; }
 
 static const AVFilterPad idet_inputs[] = {
     {
         .name         = "default",
         .type         = AVMEDIA_TYPE_VIDEO,
-        .start_frame  = start_frame,
-        .draw_slice   = null_draw_slice,
-        .end_frame    = end_frame,
+        .filter_frame = filter_frame,
         .min_perms    = AV_PERM_PRESERVE,
     },
     { NULL }
@@ -327,7 +307,6 @@ static const AVFilterPad idet_outputs[] = {
         .name          = "default",
         .type          = AVMEDIA_TYPE_VIDEO,
         .rej_perms     = AV_PERM_WRITE,
-        .poll_frame    = poll_frame,
         .request_frame = request_frame,
     },
     { NULL }
@@ -343,4 +322,5 @@ AVFilter avfilter_vf_idet = {
     .query_formats = query_formats,
     .inputs        = idet_inputs,
     .outputs       = idet_outputs,
+    .priv_class    = &idet_class,
 };