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 944354A9F9 for ; Tue, 7 May 2024 16:09:56 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6863368D7AD; Tue, 7 May 2024 19:08:47 +0300 (EEST) Received: from out162-62-57-210.mail.qq.com (out162-62-57-210.mail.qq.com [162.62.57.210]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0228168D782 for ; Tue, 7 May 2024 19:08:38 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foxmail.com; s=s201512; t=1715098106; bh=OW62230M3TMmwk2FikgWl787HzqIggUmvkjd6D28wc0=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=t6GoeiBKxkcs/SNHJK0P6YDmenvnO6aIyJzeLIF9XvGKEGR+sj2oZlU+YaUBMSnDo OL7X+8Lw6VXdheVYJWSUqwvIQgCIZgEZiLGvFGtBAlFWRqX6YpcGiQ/uI3G3uC2wWZ lIOAzQi5axX3G1liqr/OdLlRb+zsqgS+KCZXKaYk= 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: xmsmtpt1715098105t5kmqd1k0 Message-ID: X-QQ-XMAILINFO: N4ySfEzOscB6HbDpIHPfO/bLee2+W8LST3h62FxKS3YZrOqgXgR0XjuNw7FM8y oqCl0drP5tligT7xV6WwukF8sz89UJBuhWczD2rHDaJaEEs2M/Yxrk9rWbh0l9zlqeFpJsiu9GL8 dJY1DOdjtpudSpcvppNlgGkbypR2zyNvAh4m62ltGKcfjsREufMTCRlQCuXQ/9ZjmjcaAyNipJnT H+vOg67uTfZaBQqcM1nTsVJ4kiYOermrmVJyRCios+7Fh8CLH0uVLBm0Y3GTA/OQP7gNDoUTLxaI Hxg8k3J4uD4lXmhMjAEys0vbO7GyGLW7u4t3Ggh3tWZyD8SxH+SogaN2+5WJ81CuRiNS0LPJ6Cq/ ZXw5IknBnIhk4uaigiRAgeympOyRBg8e5ZbP3Ep3xQuPDulXWWOsD4ZoTk0/MlkDivllmoBcW1QM iUyOuYA0N/9BrWEcXy0OTRCHwlNDoumBxynmUPtE9Zf+ovFUcE0ll9KQhU+jZGMcx9MWVXQ3Yub9 Z2fmJl/t250rqAz/CfO5FhpGVBZHKoCn9ioivuNVqpIip6KXUnkwjgLOODF/6R76mVF6eRI13iTm ZDZqeVKlLkXo9KLUqaJMhi76MAgPSwM0Rj3r1HR0PvybO6EcKhnRf/zEUSyLMzYNL9pGtsJ98I8N 1SMDyeY0FTtYkvDBZSnSbpVYM0/gA6jnbkrNs5rFbPIgGGYx7afnQM52LftgWGUjzqxBJHcF1lc6 3vgr37qrJTegtWu++UxNShRUnK3q/wdkSjA4qUbB3YGxlQe0VMHZrhU5LKAjO+LAn2LiCp1oCoci mlxsEHDEgAwkA6dWbvc7f0TlEgBbIph3Z4uqLYCrPb0HyzkRzat1ycIlkZMJEbIcdKBs4LyowkSF 5FZwZDSGNBF85h3N/VA6Bj/OQVPB0x8c6eMprH69Dnyi1O/1lDR4c+iMoMTR666ZGXvDSgb+74Yh AMox+l8vNp+dlwLPujwpKomSOrE2NmX9XZZL8o+4L2LYD/QJR0Wko5htTHF4dDsjxRjSAWe/Y= X-QQ-XMRINFO: Mp0Kj//9VHAxr69bL5MkOOs= From: Zhao Zhili To: ffmpeg-devel@ffmpeg.org Date: Wed, 8 May 2024 00:08:16 +0800 X-OQ-MSGID: <20240507160818.71113-10-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 09/11] avfilter/dnn_backend_torch: 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_torch.cpp | 31 +++++++++++---------------- 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/libavfilter/dnn/dnn_backend_torch.cpp b/libavfilter/dnn/dnn_backend_torch.cpp index b70e4db600..0aa0b95269 100644 --- a/libavfilter/dnn/dnn_backend_torch.cpp +++ b/libavfilter/dnn/dnn_backend_torch.cpp @@ -37,8 +37,8 @@ extern "C" { } typedef struct THModel { + DNNModel model; DnnContext *ctx; - DNNModel *model; torch::jit::Module *jit_model; SafeQueue *request_queue; Queue *task_queue; @@ -141,7 +141,7 @@ static void dnn_free_model_th(DNNModel **model) ff_queue_destroy(th_model->task_queue); delete th_model->jit_model; av_freep(&th_model); - av_freep(model); + *model = NULL; } static int get_input_th(void *model, DNNData *input, const char *input_name) @@ -195,19 +195,19 @@ static int fill_model_input_th(THModel *th_model, THRequestItem *request) infer_request->input_tensor = new torch::Tensor(); infer_request->output = new torch::Tensor(); - switch (th_model->model->func_type) { + switch (th_model->model.func_type) { case DFT_PROCESS_FRAME: input.scale = 255; if (task->do_ioproc) { - if (th_model->model->frame_pre_proc != NULL) { - th_model->model->frame_pre_proc(task->in_frame, &input, th_model->model->filter_ctx); + if (th_model->model.frame_pre_proc != NULL) { + th_model->model.frame_pre_proc(task->in_frame, &input, th_model->model.filter_ctx); } else { ff_proc_from_frame_to_dnn(task->in_frame, &input, ctx); } } break; default: - avpriv_report_missing_feature(NULL, "model function type %d", th_model->model->func_type); + avpriv_report_missing_feature(NULL, "model function type %d", th_model->model.func_type); break; } *infer_request->input_tensor = torch::from_blob(input.data, @@ -282,13 +282,13 @@ static void infer_completion_callback(void *args) { goto err; } - switch (th_model->model->func_type) { + switch (th_model->model.func_type) { case DFT_PROCESS_FRAME: if (task->do_ioproc) { outputs.scale = 255; outputs.data = output->data_ptr(); - if (th_model->model->frame_post_proc != NULL) { - th_model->model->frame_post_proc(task->out_frame, &outputs, th_model->model->filter_ctx); + if (th_model->model.frame_post_proc != NULL) { + th_model->model.frame_post_proc(task->out_frame, &outputs, th_model->model.filter_ctx); } else { ff_proc_from_dnn_to_frame(task->out_frame, &outputs, th_model->ctx); } @@ -298,7 +298,7 @@ static void infer_completion_callback(void *args) { } break; default: - avpriv_report_missing_feature(th_model->ctx, "model function type %d", th_model->model->func_type); + avpriv_report_missing_feature(th_model->ctx, "model function type %d", th_model->model.func_type); goto err; } task->inference_done++; @@ -417,17 +417,10 @@ static DNNModel *dnn_load_model_th(DnnContext *ctx, DNNFunctionType func_type, A THRequestItem *item = NULL; const char *device_name = ctx->device ? ctx->device : "cpu"; - model = (DNNModel *)av_mallocz(sizeof(DNNModel)); - if (!model) { - return NULL; - } - th_model = (THModel *)av_mallocz(sizeof(THModel)); - if (!th_model) { - av_freep(&model); + if (!th_model) return NULL; - } - th_model->model = model; + model = &th_model->model; model->model = th_model; th_model->ctx = ctx; -- 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".