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 C465B49A63 for ; Sat, 27 Apr 2024 16:43:43 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D792A68D418; Sat, 27 Apr 2024 19:42:30 +0300 (EEST) Received: from out203-205-221-240.mail.qq.com (out203-205-221-240.mail.qq.com [203.205.221.240]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2813768D2F6 for ; Sat, 27 Apr 2024 19:42:15 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foxmail.com; s=s201512; t=1714236126; bh=kxUEKzo6yMwU2IjG45iacQijIia61Nk5SRdMXJQb0dw=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=I9NFg6+SlFKmWQ+mwFYAWo+YoJDF6h39bVbMJJa6NzKE6Y1jbaqNhpaHyONZgZzsb j7xCZPD53NNzWCnPMR8xn9cfLmAGKKNLFlUwPA6jk63lFkxMT6LG4eCSaE7oCYSm+y S9KJ8xQzI91jpZHZ5sk41dM50BvbF7VikGd9GNUo= 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: xmsmtpt1714236126te19h7bm3 Message-ID: X-QQ-XMAILINFO: NHgT31LhP5vD2Jf9L9sUIZJ9hJ9D1RBsrW0L1gFHOP3vLffsjDnaGMIVliJuBU HQ6azrZ235EazlIraffJV7DukvQs8Qavk0n5al9plZlkAbGJncRezIigy7pmCBFslp7afMOxA15V LELzFRcuZ45Otw/WShqaIoNn1SyyB7deZ8/9YJD15whhs9wyeonH9oyiF7CJj+h2C1XDUFlcHLBr EPgeZ9FQMFwusMu8Xsa/11fN31PCv9L8DLwDkCNPsiRgUN7j73OK78CU7kGtAVajlDe6DIl1Vu9e qxX1ztHtd7clI3pTY3vaRL5fXyl6p6yjFmW9IJBq9CEt/tQFdQF45EzhaupOC9j/IVf4GSrI3lue 1gmh3rJJPIDDwdtqM7pGxoFjRvaw4PBgzctWDCktKZxNayaA57W9kQz4jrVuqXs+z/7siVU6O++a 8grApDJk7uuGx0YEPzDPXFhPAryqOkDCZv+jc5nYSmJGrbhP0OTVzuncl3PlT3UL0yC3HU7NkNZn IPe4gK016erNHthIoE0GjB9D+LQQXrXNCRVBU4mAMwe37EoxSvF4ftm7EZfDsbN5SfYFAdxgeeQm 4HrGI4xBs3cWsbJqlipYtA/iz5Yhs312lvJxxUqzxdEUWBiRwED9og3kIXiNIGSn1h1OY3kZkET8 yVlJ9ddO1LGKNy5+2dxD+iGLamDCvqC2/OlGl6RUobx+YFNnLqQdIaU2z4KJA8U9sqJr7vaHA5Zj PK+fkOzqBKUXgbqm1KIpprKIO+mv57+G4jrQgDR3LE7GQZEI2CCfI3++ZZfPJlEFZNYFVfHtK8jl XTA1/bdARV+4pHiVxE0yT/t/4FgFgYazpRCjWyIAo17dUuyyzn9xkXVNMH27CpkGlC/qbvhhU0PZ gLl+B+k6yGLgWDKY2WTVnP9xwXAH0cdWKAXkwj7QBYXcu4iKCHiiqhYdx4PY4+2vESyZUvGfiCdS oYIgx2lA1BLYep+y+0q0rua97ca4pQY72dVjsKzil634mxmCvDu2geEGI1POQwqk+3SPSHN4uMJC iVAZmnTA== X-QQ-XMRINFO: NS+P29fieYNw95Bth2bWPxk= From: Zhao Zhili To: ffmpeg-devel@ffmpeg.org Date: Sun, 28 Apr 2024 00:41:57 +0800 X-OQ-MSGID: <20240427164159.82771-8-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 7/9] 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.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".