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 176EA4A422 for ; Tue, 30 Apr 2024 07:13:56 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9466168D5F3; Tue, 30 Apr 2024 10:12:44 +0300 (EEST) Received: from out162-62-57-252.mail.qq.com (out162-62-57-252.mail.qq.com [162.62.57.252]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id CA2D168D5B6 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=t8GRrPziAy/DBR0es5Cliii90QdzrzGP9RaqvJDGK/M=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=wu1bGG3jfz4+xk3EpjlX0cTKvPy9jNkEwelHuNtfT84ta0l2sX2BVrD5pzC9cfkbh YXxDTSOHDau8Mx8gk58O2wVCuhiJqrUNV07rkEyf8XuLUlBha1hxiOwBeIBdJKHd3n CEu+FbOO15RwzEtFdKKU2R5o6CdHFW3qZcrYoDTQ= 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: xmsmtpt1714461136tm199b3rb Message-ID: X-QQ-XMAILINFO: N9lasXYeZMXWZB8t8XXK42e5JSO0nIONeOiQBkeWvxbl+qtMV5202y3HY2i3QP CO8InYXa4/zfSRcRsufIp92hfWGC34c3twlisWF/ybNQpFxWSJZe1lj9KhB6QVUDth4VeHA7Ilxg lA5jvfpL6icXVTfA672nMb/SymNosNBeUd7ejWSXSA8mdNsKzkOqt/dkwBV0Z4asrutYXqpYrP52 17qyuRf7eeeUE0nOIpIlf/TNYHMab7szjxPF7tHtqnWGC99e8ioNtbPl3tqw3ts6u6O7kA025QIp pwqoyJN9oyNpsBeCSdjxSiErrVlGvDc1vEwY36Z15304P1gNZb+8fEht4aDnpB8bdCXwxKol8SXI Vf4JtfXzXllDMIXdwWytO7sC6DgC2xZa/zuqaejMj1hVjiH8erW3QV4RZzpvtU+U1L9Lz/NIUv48 Ag3fOtpDu/UHdGZJ3UHULHml6R/54n1SP6+9epokvUgQlAiuCb76Cv1EVXI/ElZ+1IfxIYT9Pupn /5AHbfvhBdfCUAiaHxkc7t7Ou3SbmuuJAzrRgDE4HxqYwFtMpwKM/uzn5745XHaJERkVhE8Kbyj6 OB1I4gUyZPb4En8MMOh6SaX1a5Uxm9TQRd6i/SD4gAkx/FSFRcLlqZwy7hVLsE6ssGc1ixIB+E1k 4F9bJOyZJp+qD3RLDjnPYkZ5SeEVWgfUtMizvt3jAO/YoM9/ndpADp7OvLHF3iSJn68AY1km/sYy j7rvYLvphyMfaAV+TVH/OSqGxso3uBjK7Y78TzV5JEgYlPopOPNE4crLofg+l2MZvRm9JmC33cIw RIP2568wO5WQhYPnR9JNgTnBwqK46hSFDC24uvsZOP2LfJ5cqz7CVXJ2av6yloXzkmB8OJ7qTlir MKEbL3uAgtQkVCc9Ugl1qGbGCTSTvUeuSuTDqwiGx9lNlRIe3yJcigBBp6YnZHV2rvd9DNy61ILN D3Ae779bg0lbco9uHMyTvKt0ZSW5AdRCKDc4wCXX5OhfgdA+6rC4qCm7REq/1K2Lo4vVxl95sklz gf/IpbsQlEPrORbbw0S9Wvh7zCiDw= X-QQ-XMRINFO: Nq+8W0+stu50PRdwbJxPCL0= From: Zhao Zhili To: ffmpeg-devel@ffmpeg.org Date: Tue, 30 Apr 2024 15:12:05 +0800 X-OQ-MSGID: <20240430071208.126817-8-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 07/10] 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 --- 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 abdef1f178..818ec5b713 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.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".