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 10F4D4A9F9 for ; Tue, 7 May 2024 16:09:45 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6541768D7A5; Tue, 7 May 2024 19:08:46 +0300 (EEST) Received: from out162-62-58-216.mail.qq.com (out162-62-58-216.mail.qq.com [162.62.58.216]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1AFCF68D779 for ; Tue, 7 May 2024 19:08:32 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foxmail.com; s=s201512; t=1715098105; bh=rbBsAPqm+C95SO/4m3+vg66kkpOXKkC2n/eR6vLuHGo=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=oc8/nGmduICsZYWa9amPPukt+OvzKuR7hVhns3AMpFZSybF2nbfpZK0XALW8WKrVo vXNosW6M1Txu/8PYGU2oYlkqHRcyznvAjVtq6q0a776HynnIKlPOWmfAg7DCQuD2dA pamSKF3JBilpUoPWrGnFCB+h8SuYJ3iQacCQYzeY= Received: from localhost.localdomain ([113.118.115.105]) by newxmesmtplogicsvrsza10-0.qq.com (NewEsmtp) with SMTP id 2148D2A6; Wed, 08 May 2024 00:08:20 +0800 X-QQ-mid: xmsmtpt1715098104t3acqhlwu Message-ID: X-QQ-XMAILINFO: M6r3I3oyexYhIZuW53UIXbzP/EI55uoPozDXNx8lwKUK9l3GOkiPzETq6JOj9x r6ebS7KWgXJ7ePc5X8At4gc9SnKhErGv+92u9ChZW6FKk7/peyVzeJq6e1hO+l2TdXcQH3SIkC6L 7YTBj/xiYcvHgTGhGKH6I8BwXd5Xrqq2R6MmjFysDVwR5C7NemwiYP4klboT1ph3WEduUqwb56Fe XW+PHXMBjWjNConXEOZ9Fp9V9Bi/FOBW6OXbgSNBsX7SPU5b5RKVaiDfSlZPEdjHYds632p/o5Zk 5fsEzwiy2lLSFQ9HFb/Ue9JZz83bUCCbiOwbFgLQEO28KUmBbfKGxIQcayHrNp1FTwgFFNCIMLWT sgTOjBhOiGghOgJiGZMa6v5vXEAvz3Dki3UvtIN4f4ga9xe2owAeyvfwaC93WLbAi3+r91kgcGGT v2+UBXT5BjQClGGtDjcxQutqo5lBJkUvcVvvClFbe1OajDy8IKhSm5VR9nQS3dr+N9wtj8MA7el3 0R3paA0TqShm6mQ2U5KTT8vo2ENd0+zfbfNeIG/MPDZAnpRR5hHEMBeSc83OqHafdDYsNkj50Avb h/iMOn8sGaHYTdGLtKbNrzJDhvUrwP748tRlbTIbgyHYZOwfETAsxxjP7BmCx+yJeLxfwYZVTpHT PzmAFEuhLTq3Vw+0Ps37YNXVekp22xKnaF/yWUB24cAr44jNOngrVoCZnq206FqlrUUpSn7/RC6S nICZ+zzEDOMalhA3VXOSncrP5o+XGmebCKEnIthzCtJGnt25jnOU8t30jMtCtjmaqEc0M6noUa72 lmaMDlsLqJbXVCUuSCFDqpqPU22tanHhk2redmfeDUS8EqulmaoFSzjkVrwE3rMfFanEzLI378AW FzE9ZpOz+x6RtWPc0JEG3/mnz61F+GAoQv7MBW4Zj+fh0aXVNCTzkBDQ0sZ9xf9hx5qz8qmVgY3u kJJg9Y4pF4AXCwOZ9+/ptoNH12FUO5Fl1dmfVfPm+lBYwm9fG2jmQnhTNYLs81MKfwsPO49fE= X-QQ-XMRINFO: NI4Ajvh11aEj8Xl/2s1/T8w= From: Zhao Zhili To: ffmpeg-devel@ffmpeg.org Date: Wed, 8 May 2024 00:08:15 +0800 X-OQ-MSGID: <20240507160818.71113-9-quinkblack@foxmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240507160818.71113-1-quinkblack@foxmail.com> References: <20240507160818.71113-1-quinkblack@foxmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v4 08/11] 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 Signed-off-by: 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 8b53a3b87a..583ebd7c13 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.34.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".