From patchwork Mon Mar 8 05:05:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Guo, Yejun" X-Patchwork-Id: 26244 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 999514489AF for ; Mon, 8 Mar 2021 07:16:20 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 66B996899EB; Mon, 8 Mar 2021 07:16:20 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 97DD2680911 for ; Mon, 8 Mar 2021 07:16:13 +0200 (EET) IronPort-SDR: NU3dcM/iUCq9C2hp1v9T1GkMWjaN+VBES2nvWrH3mCkr/uY6Njov3o1iNggMEsG+Puvd6oG5JF XTo7H5qQ6o4Q== X-IronPort-AV: E=McAfee;i="6000,8403,9916"; a="167235595" X-IronPort-AV: E=Sophos;i="5.81,231,1610438400"; d="scan'208";a="167235595" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Mar 2021 21:16:10 -0800 IronPort-SDR: XmFAsbI/ST2cvQSkyMQ6M4yNPRobFz78Jv+3JvgBi4/NUK9+C4Ahyv7E5Wf1mZSjUpevda6vr2 30ZJ4OgiSHEA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.81,231,1610438400"; d="scan'208";a="598718716" Received: from yguo18-skl-u1604.sh.intel.com ([10.239.159.53]) by fmsmga006.fm.intel.com with ESMTP; 07 Mar 2021 21:16:09 -0800 From: "Guo, Yejun" To: ffmpeg-devel@ffmpeg.org Date: Mon, 8 Mar 2021 13:05:18 +0800 Message-Id: <20210308050522.9396-1-yejun.guo@intel.com> X-Mailer: git-send-email 2.17.1 Subject: [FFmpeg-devel] [PATCH V5 1/5] libavfilter/dnn: add ff_dnn_set_proc to set pre/post proc X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: yejun.guo@intel.com MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Guo, Yejun --- libavfilter/dnn_filter_common.c | 7 +++++++ libavfilter/dnn_filter_common.h | 1 + libavfilter/dnn_interface.h | 6 ++++-- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/libavfilter/dnn_filter_common.c b/libavfilter/dnn_filter_common.c index 413adba406..2a1d045be1 100644 --- a/libavfilter/dnn_filter_common.c +++ b/libavfilter/dnn_filter_common.c @@ -64,6 +64,13 @@ int ff_dnn_init(DnnContext *ctx, DNNFunctionType func_type, AVFilterContext *fil return 0; } +int ff_dnn_set_proc(DnnContext *ctx, PrePostProc pre_proc, PrePostProc post_proc) +{ + ctx->model->pre_proc = pre_proc; + ctx->model->post_proc = post_proc; + return 0; +} + DNNReturnType ff_dnn_get_input(DnnContext *ctx, DNNData *input) { return ctx->model->get_input(ctx->model->model, input, ctx->model_inputname); diff --git a/libavfilter/dnn_filter_common.h b/libavfilter/dnn_filter_common.h index 79c4d3efe3..4810c7baaf 100644 --- a/libavfilter/dnn_filter_common.h +++ b/libavfilter/dnn_filter_common.h @@ -48,6 +48,7 @@ typedef struct DnnContext { int ff_dnn_init(DnnContext *ctx, DNNFunctionType func_type, AVFilterContext *filter_ctx); +int ff_dnn_set_proc(DnnContext *ctx, PrePostProc pre_proc, PrePostProc post_proc); DNNReturnType ff_dnn_get_input(DnnContext *ctx, DNNData *input); DNNReturnType ff_dnn_get_output(DnnContext *ctx, int input_width, int input_height, int *output_width, int *output_height); DNNReturnType ff_dnn_execute_model(DnnContext *ctx, AVFrame *in_frame, AVFrame *out_frame); diff --git a/libavfilter/dnn_interface.h b/libavfilter/dnn_interface.h index d3a0c58a61..c92434ee55 100644 --- a/libavfilter/dnn_interface.h +++ b/libavfilter/dnn_interface.h @@ -63,6 +63,8 @@ typedef struct DNNData{ DNNColorOrder order; } DNNData; +typedef int (*PrePostProc)(AVFrame *frame, DNNData *model, AVFilterContext *filter_ctx); + typedef struct DNNModel{ // Stores model that can be different for different backends. void *model; @@ -80,10 +82,10 @@ typedef struct DNNModel{ const char *output_name, int *output_width, int *output_height); // set the pre process to transfer data from AVFrame to DNNData // the default implementation within DNN is used if it is not provided by the filter - int (*pre_proc)(AVFrame *frame_in, DNNData *model_input, AVFilterContext *filter_ctx); + PrePostProc pre_proc; // set the post process to transfer data from DNNData to AVFrame // the default implementation within DNN is used if it is not provided by the filter - int (*post_proc)(AVFrame *frame_out, DNNData *model_output, AVFilterContext *filter_ctx); + PrePostProc post_proc; } DNNModel; // Stores pointers to functions for loading, executing, freeing DNN models for one of the backends.