From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 8E8F44A435 for ; Tue, 30 Apr 2024 07:13:14 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 13B1E68D5E0; Tue, 30 Apr 2024 10:12:38 +0300 (EEST) Received: from out162-62-58-211.mail.qq.com (out162-62-58-211.mail.qq.com [162.62.58.211]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7EADC68D5AA for ; Tue, 30 Apr 2024 10:12:24 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foxmail.com; s=s201512; t=1714461136; bh=PxeaxHxaSPHlb8fmcLD367j4TZd/T8OvN3kDxoDx0Ac=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=WdopVTPYvmtZ7fz8F4VogApcV+XIz3Blrf3o9kAqA4CN/ZMIrq+XgSmfor6t3cpCu cH4M5VSldCZeEF5LIsUGIgycAuIViIAI1mNw3xBpSnQRo7pwWX/tKH7NhmUU+O9/Dx AcYgcVKb36dSKJA0M4J5IeosedgJSTIa1BUbT8rA= Received: from localhost.localdomain ([113.108.77.51]) by newxmesmtplogicsvrsza10-0.qq.com (NewEsmtp) with SMTP id 3091B0E9; Tue, 30 Apr 2024 15:12:09 +0800 X-QQ-mid: xmsmtpt1714461135tvi3gf257 Message-ID: X-QQ-XMAILINFO: OKKHiI6c9SH3vxT3aH57sf3UKdkJGmuzfJHnaymo5u/rj7xkVCPrSYYtuHNPg3 QOf/nKwXqw9nCVXlXHUFrDZSz8YMsGvcQjwbN9tBCNpQZ+mAyoaZt7pvLtOKYVmeQ6ZG1s+QF2Je E9f+vs9kW8G9mNsWJtENVQ5KRz/R0wJBEqpxXYkk78EM0ybfXVP8vibqo6zF6lOUzU4hjoe/FI3f QUY57bh/zwQK4FxgqPHV21EPY1ZLGfFz1n6jKn7jMjJUtw2iw5VU/cAk2dWdvoStKpSgtlXzGrwf 7h/mfKaEgzYdHzqf86ji4a44QDZlJ50fCnAsm4XxvQWorNN9iXrJbyBs5xVZADhcKXg/1T19bYkZ 8obPweS9VtPEZCyrjeuT++P2argI5QVDAA5mQs0xPgNfJ1WQFGWNm+tugZd3tv5odcws6D6lBM0y 9WhEg3mZW9Jqk5oqo6FzSBL+fNWojSYR0tzQgeu4biKZ07VosYlUKUgDUjIiD8w2ij24/MsFEhFB ss5cTicE6VkuyYV9JOSbET9xB18uPFDpFiiLBaHkcxLOx1/ooUVmgVTu9kLRAHsByZ+PZP5h8ke9 NnMpvB875Y0D6GNbbAzQ3CtBPJx9Jj9WQUuU58Ke8T0n0yvQMgSktIOV9A5jftJYYd24wxS27J85 zbbx4VmEL1yk61OLAxcRlcNjEidBtwz55CaLO2bDhQQIyIFkmqyr1wCPKx9sdUHgJIPGrbNFgrlS fUuZzIKaAFHyVFzs816+MfOrVRb5VboO5MDGQfKsyiqF88Nj+1Y32+HUms4C+GJS8mm3SJhq/jXc HujfIG/lH0qDSR+kOaaGWSp+Ryjmg2Y5OdDQHweyJ+hcI7oSSUx0crBg2I1iuVySN0O6x8x5lVgK YP1xkpzJUoDWBTZym+Jk5Cg1dOzWguDwjJZWJc4xfxEvHRzEbnXXSIdeBi9EtcmcWEGjFw6Zyld1 V6Tny+JBkSHYRBiag4sTwR9ZIep9WzSf6nPhkujpR0RS2NrH6bLe1oYzjK28xDeFSakKBzaFV19I VULcsIHc/dH0awQkco X-QQ-XMRINFO: MPJ6Tf5t3I/ycC2BItcBVIA= From: Zhao Zhili To: ffmpeg-devel@ffmpeg.org Date: Tue, 30 Apr 2024 15:12:04 +0800 X-OQ-MSGID: <20240430071208.126817-7-quinkblack@foxmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240430071208.126817-1-quinkblack@foxmail.com> References: <20240430071208.126817-1-quinkblack@foxmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v3 06/10] avfilter/dnn_backend_tf: Simplify memory allocation X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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: Zhao Zhili Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: From: Zhao Zhili --- libavfilter/dnn/dnn_backend_tf.c | 33 +++++++++++++------------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/libavfilter/dnn/dnn_backend_tf.c b/libavfilter/dnn/dnn_backend_tf.c index 3b4de6d13f..c7716e696d 100644 --- a/libavfilter/dnn/dnn_backend_tf.c +++ b/libavfilter/dnn/dnn_backend_tf.c @@ -37,8 +37,8 @@ #include typedef struct TFModel { + DNNModel model; DnnContext *ctx; - DNNModel *model; TF_Graph *graph; TF_Session *session; TF_Status *status; @@ -518,7 +518,7 @@ static void dnn_free_model_tf(DNNModel **model) TF_DeleteStatus(tf_model->status); } av_freep(&tf_model); - av_freep(&model); + *model = NULL; } static DNNModel *dnn_load_model_tf(DnnContext *ctx, DNNFunctionType func_type, AVFilterContext *filter_ctx) @@ -526,18 +526,11 @@ static DNNModel *dnn_load_model_tf(DnnContext *ctx, DNNFunctionType func_type, A DNNModel *model = NULL; TFModel *tf_model = NULL; - model = av_mallocz(sizeof(DNNModel)); - if (!model){ - return NULL; - } - tf_model = av_mallocz(sizeof(TFModel)); - if (!tf_model){ - av_freep(&model); + if (!tf_model) return NULL; - } + model = &tf_model->model; model->model = tf_model; - tf_model->model = model; tf_model->ctx = ctx; if (load_tf_model(tf_model, ctx->model_filename) != 0){ @@ -650,11 +643,11 @@ static int fill_model_input_tf(TFModel *tf_model, TFRequestItem *request) { } input.data = (float *)TF_TensorData(infer_request->input_tensor); - switch (tf_model->model->func_type) { + switch (tf_model->model.func_type) { case DFT_PROCESS_FRAME: if (task->do_ioproc) { - if (tf_model->model->frame_pre_proc != NULL) { - tf_model->model->frame_pre_proc(task->in_frame, &input, tf_model->model->filter_ctx); + if (tf_model->model.frame_pre_proc != NULL) { + tf_model->model.frame_pre_proc(task->in_frame, &input, tf_model->model.filter_ctx); } else { ff_proc_from_frame_to_dnn(task->in_frame, &input, ctx); } @@ -664,7 +657,7 @@ static int fill_model_input_tf(TFModel *tf_model, TFRequestItem *request) { ff_frame_to_dnn_detect(task->in_frame, &input, ctx); break; default: - avpriv_report_missing_feature(ctx, "model function type %d", tf_model->model->func_type); + avpriv_report_missing_feature(ctx, "model function type %d", tf_model->model.func_type); break; } @@ -724,12 +717,12 @@ static void infer_completion_callback(void *args) { outputs[i].data = TF_TensorData(infer_request->output_tensors[i]); outputs[i].dt = (DNNDataType)TF_TensorType(infer_request->output_tensors[i]); } - switch (tf_model->model->func_type) { + switch (tf_model->model.func_type) { case DFT_PROCESS_FRAME: //it only support 1 output if it's frame in & frame out if (task->do_ioproc) { - if (tf_model->model->frame_post_proc != NULL) { - tf_model->model->frame_post_proc(task->out_frame, outputs, tf_model->model->filter_ctx); + if (tf_model->model.frame_post_proc != NULL) { + tf_model->model.frame_post_proc(task->out_frame, outputs, tf_model->model.filter_ctx); } else { ff_proc_from_dnn_to_frame(task->out_frame, outputs, ctx); } @@ -741,11 +734,11 @@ static void infer_completion_callback(void *args) { } break; case DFT_ANALYTICS_DETECT: - if (!tf_model->model->detect_post_proc) { + if (!tf_model->model.detect_post_proc) { av_log(ctx, AV_LOG_ERROR, "Detect filter needs provide post proc\n"); return; } - tf_model->model->detect_post_proc(task->in_frame, outputs, task->nb_output, tf_model->model->filter_ctx); + tf_model->model.detect_post_proc(task->in_frame, outputs, task->nb_output, tf_model->model.filter_ctx); break; default: av_log(ctx, AV_LOG_ERROR, "Tensorflow backend does not support this kind of dnn filter now\n"); -- 2.25.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".