Fix missing .unit designator on the torch const AVOption entry in
vf_dnn_processing.c, and replace the hardcoded single request item in
dnn_load_model_th with a ctx->nireq-driven pool matching the TF/OpenVINO 
backends.

This is also the qualification task for the LibTorch Backend Project for
GSoC 2026.
---
 libavfilter/dnn/dnn_backend_torch.cpp | 43 ++++++++++++++++++---------
 libavfilter/vf_dnn_processing.c       |  2 +-
 2 files changed, 30 insertions(+), 15 deletions(-)

diff --git a/libavfilter/dnn/dnn_backend_torch.cpp 
b/libavfilter/dnn/dnn_backend_torch.cpp
index 99f55165f2..3c84eb33a8 100644
--- a/libavfilter/dnn/dnn_backend_torch.cpp
+++ b/libavfilter/dnn/dnn_backend_torch.cpp
@@ -29,6 +29,7 @@
 extern "C" {
 #include "dnn_io_proc.h"
 #include "dnn_backend_common.h"
+#include "libavutil/cpu.h"
 #include "libavutil/opt.h"
 #include "libavutil/mem.h"
 #include "queue.h"
@@ -453,28 +454,42 @@ static DNNModel *dnn_load_model_th(DnnContext *ctx, 
DNNFunctionType func_type, A
         goto fail;
     }
 
+    if (ctx->nireq <= 0)
+        ctx->nireq = av_cpu_count() / 2 + 1;
+
+#if !HAVE_PTHREAD_CANCEL
+    if (ctx->nireq != 1) {
+        ctx->nireq = 1;
+        av_log(ctx, AV_LOG_WARNING, "pthread is not supported, only one 
request is used\n");
+    }
+#endif
+
     th_model->request_queue = ff_safe_queue_create();
     if (!th_model->request_queue) {
         goto fail;
     }
 
-    item = (THRequestItem *)av_mallocz(sizeof(THRequestItem));
-    if (!item) {
-        goto fail;
-    }
-    item->infer_request = th_create_inference_request();
-    if (!item->infer_request) {
-        goto fail;
-    }
+    for (int i = 0; i < ctx->nireq; i++) {
+        item = (THRequestItem *)av_mallocz(sizeof(THRequestItem));
+        if (!item) {
+            goto fail;
+        }
+        item->infer_request = th_create_inference_request();
+        if (!item->infer_request) {
+            av_freep(&item);
+            goto fail;
+        }
 
-    item->exec_module.start_inference = &th_start_inference;
-    item->exec_module.callback = &infer_completion_callback;
-    item->exec_module.args = item;
+        item->exec_module.start_inference = &th_start_inference;
+        item->exec_module.callback = &infer_completion_callback;
+        item->exec_module.args = item;
 
-    if (ff_safe_queue_push_back(th_model->request_queue, item) < 0) {
-        goto fail;
+        if (ff_safe_queue_push_back(th_model->request_queue, item) < 0) {
+            destroy_request_item(&item);
+            goto fail;
+        }
+        item = NULL;
     }
-    item = NULL;
 
     th_model->task_queue = ff_queue_create();
     th_model->lltask_queue = ff_queue_create();
diff --git a/libavfilter/vf_dnn_processing.c b/libavfilter/vf_dnn_processing.c
index 0771ceb5fc..5690cc5cd7 100644
--- a/libavfilter/vf_dnn_processing.c
+++ b/libavfilter/vf_dnn_processing.c
@@ -51,7 +51,7 @@ static const AVOption dnn_processing_options[] = {
     { "openvino",    "openvino backend flag",      0,                        
AV_OPT_TYPE_CONST,     { .i64 = DNN_OV },    0, 0, FLAGS, .unit = "backend" },
 #endif
 #if (CONFIG_LIBTORCH == 1)
-    { "torch",       "torch backend flag",         0,                        
AV_OPT_TYPE_CONST,     { .i64 = DNN_TH },    0, 0, FLAGS, "backend" },
+    { "torch",       "torch backend flag",         0,                        
AV_OPT_TYPE_CONST,     { .i64 = DNN_TH },    0, 0, FLAGS, .unit = "backend" },
 #endif
     { NULL }
 };
-- 
2.52.0

_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to