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 2C7B649A78 for ; Sat, 27 Apr 2024 16:42:53 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C17A268D3AF; Sat, 27 Apr 2024 19:42:24 +0300 (EEST) Received: from out203-205-251-82.mail.qq.com (out203-205-251-82.mail.qq.com [203.205.251.82]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B983168D220 for ; Sat, 27 Apr 2024 19:42:14 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foxmail.com; s=s201512; t=1714236126; bh=4EMMI4aobqVThNJSmZXynEn2P4p5anzkIo5UKlmJIcc=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=dglaEV3kWSUjiYR3R/NaBYvQ4ZW9RwCbRk7ykoY7BnLYX/+0VDsKiUJSPBGJxWyMI 1tn3R/V53j8AZrJaNfFeCuOyI2xMXzBHl74Zy0lN4r7fl7d80A/82jHGKE/0p0mfjy YQPoxLyLD50XheZM/o4KkQ21G+s9PCGeS/QE/6ZE= Received: from localhost.localdomain ([113.118.107.199]) by newxmesmtplogicsvrszc19-0.qq.com (NewEsmtp) with SMTP id A8200E2A; Sun, 28 Apr 2024 00:42:02 +0800 X-QQ-mid: xmsmtpt1714236125tdeb6c7gz Message-ID: X-QQ-XMAILINFO: OQhZ3T0tjf0aNQtsHtgPWXtrTc3o8qC8fZhZrg3cT87OqUJdFWSRb9NgGW9H+X 1VhddKxCsoxKEnrIbWmxKHlsCK1TYENroTtlmIAHqiMiM9tTmAqD0jqbAL13eM6IGEzlJSyjc1Io fWy6XAwdJJFQoakGGr0vPjLii227x1ckYETrUsyQqLJM0EMca2D929Huqyu1gEF5v1r9wORQLvFg ZB5jxXwDSeu3vqsGXnRF3bg3LqskKdU33g2RBr61EhVUdemh76JjwGZfiQ2u62Bd/MzA8dHf/oLf 1guhIKtbAov1pZBB5Q24WLmeG4H6YhJ0wdhCaKFAd4TikkZ9ipKJaQe6zErVnC3ixuOpfz0sSZB8 XoGtQHPk7AhBuTONM1O5u5bHnboLTp+TbXjyg6r1CshGXgLJV9hUHZHOrKfYBGQk5MWzHti22p5L u0v4N6PhWU0wvZsJLndhmN8ceNFoJqgjPZlpncxdvsNYp8TnR5fylz+D161mKCJ9MBq3Aq1DXwmE U+GElbtRVvcPf5Du/l2tLGq1vLZiOuLPCJ18Dw2p1BKwWXfm2RQZhsQ9/PaBP8q7xS2nWhflDdCg QV+EXcf6YjAZexdef9sDCfxnV9ybgDmHJ+9rSGC5NijZVrZAKwUXdXd5F8a/SzNlevPIeZoOo2Zt ZZ3Vp2NGaOYI6iv3jJ7w4lmvdG//ZPP+flKyp2XFJn0o518S/fe8eELI5xrpVvsDX1cXHEXpzCZq b0sYTXA/bLSBUHEK3c7b7fRlSAmFFr50MRyq/dxuzSCEbEnrYIm7HKqg377a4CCpnUAIeOj6H3Uq uFUrhMH6A6i7atKRI7draxLai+csoE6efzR+fHbv6lM2BEnaCcNZEkxeDk7IJHasjc1G7i4ZZd4y h3y6Se+JaE+m/b+Q0XY1Ju9paYg+NikjA0fzGl/L8NTtdP6iooXP9GRytMZp/tZgSuqClcwekzqf PwlFPanxBNvAaLw2SIENEwg0jI5GxXPw71jmOXtst6w7kbUZ65UNJgJFbT/uN5qd6kJ+FcKu4= X-QQ-XMRINFO: M/715EihBoGSf6IYSX1iLFg= From: Zhao Zhili To: ffmpeg-devel@ffmpeg.org Date: Sun, 28 Apr 2024 00:41:56 +0800 X-OQ-MSGID: <20240427164159.82771-7-quinkblack@foxmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240427164159.82771-1-quinkblack@foxmail.com> References: <20240427164159.82771-1-quinkblack@foxmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH WIP 6/9] 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.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".