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 5533F48DE9 for ; Sun, 28 Apr 2024 06:47:33 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id B2D0F68D374; Sun, 28 Apr 2024 09:47:19 +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 6E7EE68D2F9 for ; Sun, 28 Apr 2024 09:47:10 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foxmail.com; s=s201512; t=1714286821; bh=t8GRrPziAy/DBR0es5Cliii90QdzrzGP9RaqvJDGK/M=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=ciFurZqmEswvI5pMKMNB+h2v9VEqQNeuASbCF41SSacBr6UrtIVKnBF1ruw8gk7pA x0uBiuF8I+hWmGqRipc5MD3vKbFZ2VPZ9ycYY1Q1S+7pjNHSqepPJ06kuE2YX2zT/9 YySIrJ0NfX379dY14XNZ+8Lgb4JUvzS5G4RmKEhI= Received: from localhost.localdomain ([119.147.10.207]) by newxmesmtplogicsvrszc5-2.qq.com (NewEsmtp) with SMTP id BB93D84A; Sun, 28 Apr 2024 14:46:57 +0800 X-QQ-mid: xmsmtpt1714286820tp4ysgr8a Message-ID: X-QQ-XMAILINFO: M7uElAZZZMmFS0fmYMjT6XV2NUlFifYb8X0I/BUm1eikeAF6enDvuGSBPnToBC dZLrgDIADrUVbkBZCStisR9iy3J4HQu6ligOazShlvu3kNo78Y+Egbjk7gJijmxo9B4Z7pQ5CK8H bsEfh71fPTWzKlKhpX9l4SBRixatBebHgam88HWCngeOEWliAd7O/T4bGiaBmn1d0A560T3d3ncU ei3NZnYkleArz19LwiaDgT5PmfGjagceTLA41E2Q6DSe8waEQBA3rLMEWPzGVrH3H5++Lc+7z0uJ 6pmJaH4nyGzRo9QSayhL9Uhvh5d9Z1Q3wi8U4rTTaZetz0eSCgFCJlhF0G6M8opUJFmVWf9UjdOo qS95bpR7eQUtQEFFm2jBPOlIfOgfpFWqNAszPTZSy4km9ZbxJyNESwJsnk3YU/+Z/zbVMQ+tw6cF 6l1sdWOZIuKNtbyioA83Xgi78JBN3n//4y0m50sn7uvDE2hXRjx0MMqoOtfrANZA3G8CFKhqEcfd ugtHPBD3uL5T0C2ke0fWEnSOnguIDvZ/5rl2czJXh4X2SAo5hVm8qszC0FulHFpQ0g2HMQmO1PId /srpjm3itYnuxYdooIRt5rT1f1YtWYaI7hxZqJ2mxxbec6F1xPHwxcopVAvk7NV7X/gXasqZwakO 6Si8O9TaqYSeYUDIIQC58qwK021UNfJupeAlFi1v1cHnV4SjaqpYc2tN88wF2PZ7NquoEysu1skY Kgs0oXzqVRt3YgJUoNesB1gSfRT3ITZ0aMXE56JNyGePENOBU5x2BxeEcTW5zmGuV6u2zOew5l4j zTR6KZIqIB5hSAWZqTOsEr7r5BJxhKa+0SB0sGPXPwntnYrivXwDXZXHCIvnBoq+ftUFekDiSFyp majoe+lc4d6fKyYBfl4q5UVEbRTjlUAqz52A9y5d5O641IA4U/m2bQvsVvlynjkEhX9BYPLCaMPV th/RlmeTTI+7/fi0e8LiHjAXLlXlIEBTJwjeJs5P0cWKbKqAXaGZJJ7qK5/aE26rrRrUktSDIafm 5eGXySh1Z5C7eIfpohWPVoRgoYQ0A= X-QQ-XMRINFO: M/715EihBoGSf6IYSX1iLFg= From: Zhao Zhili To: ffmpeg-devel@ffmpeg.org Date: Sun, 28 Apr 2024 14:46:53 +0800 X-OQ-MSGID: <20240428064655.106853-7-quinkblack@foxmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240428064655.106853-1-quinkblack@foxmail.com> References: <20240428064655.106853-1-quinkblack@foxmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH WIP v2 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.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".