diff mbox series

[FFmpeg-devel,3/6] libavfilter: Remove synchronous functions from DNN filters

Message ID 20210820142103.14953-3-shubhanshu.e01@gmail.com
State Superseded
Headers show
Series [FFmpeg-devel,1/6] lavfi/dnn: Task-based Inference in Native Backend | expand

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

Shubhanshu Saxena Aug. 20, 2021, 2:21 p.m. UTC
This commit removes the unused sync mode specific code from the DNN
filters since the sync and async mode are now unified from the
filters' perspective.

Signed-off-by: Shubhanshu Saxena <shubhanshu.e01@gmail.com>
---
 libavfilter/vf_dnn_detect.c     | 71 +---------------------------
 libavfilter/vf_dnn_processing.c | 84 +--------------------------------
 2 files changed, 4 insertions(+), 151 deletions(-)
diff mbox series

Patch

diff --git a/libavfilter/vf_dnn_detect.c b/libavfilter/vf_dnn_detect.c
index 2666abfcdc..809d70b930 100644
--- a/libavfilter/vf_dnn_detect.c
+++ b/libavfilter/vf_dnn_detect.c
@@ -353,63 +353,6 @@  static int dnn_detect_query_formats(AVFilterContext *context)
     return ff_set_common_formats_from_list(context, pix_fmts);
 }
 
-static int dnn_detect_filter_frame(AVFilterLink *inlink, AVFrame *in)
-{
-    AVFilterContext *context  = inlink->dst;
-    AVFilterLink *outlink = context->outputs[0];
-    DnnDetectContext *ctx = context->priv;
-    DNNReturnType dnn_result;
-
-    dnn_result = ff_dnn_execute_model(&ctx->dnnctx, in, in);
-    if (dnn_result != DNN_SUCCESS){
-        av_log(ctx, AV_LOG_ERROR, "failed to execute model\n");
-        av_frame_free(&in);
-        return AVERROR(EIO);
-    }
-
-    return ff_filter_frame(outlink, in);
-}
-
-static int dnn_detect_activate_sync(AVFilterContext *filter_ctx)
-{
-    AVFilterLink *inlink = filter_ctx->inputs[0];
-    AVFilterLink *outlink = filter_ctx->outputs[0];
-    AVFrame *in = NULL;
-    int64_t pts;
-    int ret, status;
-    int got_frame = 0;
-
-    FF_FILTER_FORWARD_STATUS_BACK(outlink, inlink);
-
-    do {
-        // drain all input frames
-        ret = ff_inlink_consume_frame(inlink, &in);
-        if (ret < 0)
-            return ret;
-        if (ret > 0) {
-            ret = dnn_detect_filter_frame(inlink, in);
-            if (ret < 0)
-                return ret;
-            got_frame = 1;
-        }
-    } while (ret > 0);
-
-    // if frame got, schedule to next filter
-    if (got_frame)
-        return 0;
-
-    if (ff_inlink_acknowledge_status(inlink, &status, &pts)) {
-        if (status == AVERROR_EOF) {
-            ff_outlink_set_status(outlink, status, pts);
-            return ret;
-        }
-    }
-
-    FF_FILTER_FORWARD_WANTED(outlink, inlink);
-
-    return FFERROR_NOT_READY;
-}
-
 static int dnn_detect_flush_frame(AVFilterLink *outlink, int64_t pts, int64_t *out_pts)
 {
     DnnDetectContext *ctx = outlink->src->priv;
@@ -439,7 +382,7 @@  static int dnn_detect_flush_frame(AVFilterLink *outlink, int64_t pts, int64_t *o
     return 0;
 }
 
-static int dnn_detect_activate_async(AVFilterContext *filter_ctx)
+static int dnn_detect_activate(AVFilterContext *filter_ctx)
 {
     AVFilterLink *inlink = filter_ctx->inputs[0];
     AVFilterLink *outlink = filter_ctx->outputs[0];
@@ -496,16 +439,6 @@  static int dnn_detect_activate_async(AVFilterContext *filter_ctx)
     return 0;
 }
 
-static int dnn_detect_activate(AVFilterContext *filter_ctx)
-{
-    DnnDetectContext *ctx = filter_ctx->priv;
-
-    if (ctx->dnnctx.async)
-        return dnn_detect_activate_async(filter_ctx);
-    else
-        return dnn_detect_activate_sync(filter_ctx);
-}
-
 static av_cold void dnn_detect_uninit(AVFilterContext *context)
 {
     DnnDetectContext *ctx = context->priv;
@@ -537,5 +470,5 @@  const AVFilter ff_vf_dnn_detect = {
     FILTER_INPUTS(dnn_detect_inputs),
     FILTER_OUTPUTS(dnn_detect_outputs),
     .priv_class    = &dnn_detect_class,
-    .activate      = dnn_detect_activate_async,
+    .activate      = dnn_detect_activate,
 };
diff --git a/libavfilter/vf_dnn_processing.c b/libavfilter/vf_dnn_processing.c
index 410cc887dc..55634efde5 100644
--- a/libavfilter/vf_dnn_processing.c
+++ b/libavfilter/vf_dnn_processing.c
@@ -244,76 +244,6 @@  static int copy_uv_planes(DnnProcessingContext *ctx, AVFrame *out, const AVFrame
     return 0;
 }
 
-static int filter_frame(AVFilterLink *inlink, AVFrame *in)
-{
-    AVFilterContext *context  = inlink->dst;
-    AVFilterLink *outlink = context->outputs[0];
-    DnnProcessingContext *ctx = context->priv;
-    DNNReturnType dnn_result;
-    AVFrame *out;
-
-    out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
-    if (!out) {
-        av_frame_free(&in);
-        return AVERROR(ENOMEM);
-    }
-    av_frame_copy_props(out, in);
-
-    dnn_result = ff_dnn_execute_model(&ctx->dnnctx, in, out);
-    if (dnn_result != DNN_SUCCESS){
-        av_log(ctx, AV_LOG_ERROR, "failed to execute model\n");
-        av_frame_free(&in);
-        av_frame_free(&out);
-        return AVERROR(EIO);
-    }
-
-    if (isPlanarYUV(in->format))
-        copy_uv_planes(ctx, out, in);
-
-    av_frame_free(&in);
-    return ff_filter_frame(outlink, out);
-}
-
-static int activate_sync(AVFilterContext *filter_ctx)
-{
-    AVFilterLink *inlink = filter_ctx->inputs[0];
-    AVFilterLink *outlink = filter_ctx->outputs[0];
-    AVFrame *in = NULL;
-    int64_t pts;
-    int ret, status;
-    int got_frame = 0;
-
-    FF_FILTER_FORWARD_STATUS_BACK(outlink, inlink);
-
-    do {
-        // drain all input frames
-        ret = ff_inlink_consume_frame(inlink, &in);
-        if (ret < 0)
-            return ret;
-        if (ret > 0) {
-            ret = filter_frame(inlink, in);
-            if (ret < 0)
-                return ret;
-            got_frame = 1;
-        }
-    } while (ret > 0);
-
-    // if frame got, schedule to next filter
-    if (got_frame)
-        return 0;
-
-    if (ff_inlink_acknowledge_status(inlink, &status, &pts)) {
-        if (status == AVERROR_EOF) {
-            ff_outlink_set_status(outlink, status, pts);
-            return ret;
-        }
-    }
-
-    FF_FILTER_FORWARD_WANTED(outlink, inlink);
-
-    return FFERROR_NOT_READY;
-}
-
 static int flush_frame(AVFilterLink *outlink, int64_t pts, int64_t *out_pts)
 {
     DnnProcessingContext *ctx = outlink->src->priv;
@@ -345,7 +275,7 @@  static int flush_frame(AVFilterLink *outlink, int64_t pts, int64_t *out_pts)
     return 0;
 }
 
-static int activate_async(AVFilterContext *filter_ctx)
+static int activate(AVFilterContext *filter_ctx)
 {
     AVFilterLink *inlink = filter_ctx->inputs[0];
     AVFilterLink *outlink = filter_ctx->outputs[0];
@@ -410,16 +340,6 @@  static int activate_async(AVFilterContext *filter_ctx)
     return 0;
 }
 
-static int activate(AVFilterContext *filter_ctx)
-{
-    DnnProcessingContext *ctx = filter_ctx->priv;
-
-    if (ctx->dnnctx.async)
-        return activate_async(filter_ctx);
-    else
-        return activate_sync(filter_ctx);
-}
-
 static av_cold void uninit(AVFilterContext *ctx)
 {
     DnnProcessingContext *context = ctx->priv;
@@ -454,5 +374,5 @@  const AVFilter ff_vf_dnn_processing = {
     FILTER_INPUTS(dnn_processing_inputs),
     FILTER_OUTPUTS(dnn_processing_outputs),
     .priv_class    = &dnn_processing_class,
-    .activate      = activate_async,
+    .activate      = activate,
 };