From 8fa4c8f2f068c9d0f6d39b10012c955e50ed109a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Cr=C3=AAte?= Date: Thu, 25 Jan 2024 01:09:13 -0500 Subject: [PATCH] tensordecoders: Move decoder out of the ONNX plugin Part-of: --- .../docs/plugins/gst_plugins_cache.json | 80 +++++++++++++++++++ .../gst-plugins-bad/ext/onnx/gstonnx.c | 6 +- .../gst-plugins-bad/ext/onnx/meson.build | 3 +- subprojects/gst-plugins-bad/gst/meson.build | 2 +- .../tensordecoders}/gstssdobjectdetector.c | 2 +- .../tensordecoders}/gstssdobjectdetector.h | 0 .../gst/tensordecoders/gsttensordecoders.c | 49 ++++++++++++ .../gst/tensordecoders/meson.build | 14 ++++ subprojects/gst-plugins-bad/meson_options.txt | 1 + 9 files changed, 148 insertions(+), 9 deletions(-) rename subprojects/gst-plugins-bad/{ext/onnx/decoders => gst/tensordecoders}/gstssdobjectdetector.c (99%) rename subprojects/gst-plugins-bad/{ext/onnx/decoders => gst/tensordecoders}/gstssdobjectdetector.h (100%) create mode 100644 subprojects/gst-plugins-bad/gst/tensordecoders/gsttensordecoders.c create mode 100644 subprojects/gst-plugins-bad/gst/tensordecoders/meson.build diff --git a/subprojects/gst-plugins-bad/docs/plugins/gst_plugins_cache.json b/subprojects/gst-plugins-bad/docs/plugins/gst_plugins_cache.json index 2170341484..0ebe83ad04 100644 --- a/subprojects/gst-plugins-bad/docs/plugins/gst_plugins_cache.json +++ b/subprojects/gst-plugins-bad/docs/plugins/gst_plugins_cache.json @@ -245050,6 +245050,86 @@ "tracers": {}, "url": "Unknown package origin" }, + "tensordecoders": { + "description": "Tensor decoders elements", + "elements": { + "ssdobjectdetector": { + "author": "Aaron Boxer , Marcus Edel ", + "description": "Apply tensor output from inference to detect objects in video frames", + "hierarchy": [ + "GstSsdObjectDetector", + "GstBaseTransform", + "GstElement", + "GstObject", + "GInitiallyUnowned", + "GObject" + ], + "klass": "TensorDecoder/Video", + "pad-templates": { + "sink": { + "caps": "video/x-raw:\n", + "direction": "sink", + "presence": "always" + }, + "src": { + "caps": "video/x-raw:\n", + "direction": "src", + "presence": "always" + } + }, + "properties": { + "label-file": { + "blurb": "Label file", + "conditionally-available": false, + "construct": false, + "construct-only": false, + "controllable": false, + "default": "NULL", + "mutable": "null", + "readable": true, + "type": "gchararray", + "writable": true + }, + "score-threshold": { + "blurb": "Threshold for deciding when to remove boxes based on score", + "conditionally-available": false, + "construct": false, + "construct-only": false, + "controllable": false, + "default": "0.3", + "max": "1", + "min": "0", + "mutable": "null", + "readable": true, + "type": "gfloat", + "writable": true + }, + "size-threshold": { + "blurb": "Threshold for deciding when to remove boxes based on proportion of the image", + "conditionally-available": false, + "construct": false, + "construct-only": false, + "controllable": false, + "default": "0.9", + "max": "1", + "min": "0", + "mutable": "null", + "readable": true, + "type": "gfloat", + "writable": true + } + }, + "rank": "primary" + } + }, + "filename": "gsttensordecoders", + "license": "LGPL", + "other-types": {}, + "package": "GStreamer Bad Plug-ins", + "source": "gst-plugins-bad", + "tracers": {}, + "url": "Unknown package origin" + }, "timecode": { "description": "Timecode-related elements", "elements": { diff --git a/subprojects/gst-plugins-bad/ext/onnx/gstonnx.c b/subprojects/gst-plugins-bad/ext/onnx/gstonnx.c index f7ba3fc51a..d21f2ccfbd 100644 --- a/subprojects/gst-plugins-bad/ext/onnx/gstonnx.c +++ b/subprojects/gst-plugins-bad/ext/onnx/gstonnx.c @@ -24,16 +24,12 @@ #include "config.h" #endif -#include "decoders/gstssdobjectdetector.h" #include "gstonnxinference.h" static gboolean plugin_init (GstPlugin * plugin) { - gboolean success = GST_ELEMENT_REGISTER (ssd_object_detector, plugin); - success |= GST_ELEMENT_REGISTER (onnx_inference, plugin); - - return success; + return GST_ELEMENT_REGISTER (onnx_inference, plugin); } GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, diff --git a/subprojects/gst-plugins-bad/ext/onnx/meson.build b/subprojects/gst-plugins-bad/ext/onnx/meson.build index 58c3430dec..001d3f4648 100644 --- a/subprojects/gst-plugins-bad/ext/onnx/meson.build +++ b/subprojects/gst-plugins-bad/ext/onnx/meson.build @@ -15,7 +15,6 @@ endif if onnxrt_dep.found() gstonnx = library('gstonnx', 'gstonnx.c', - 'decoders/gstssdobjectdetector.c', 'gstonnxinference.cpp', 'gstonnxclient.cpp', c_args : gst_plugins_bad_args + extra_args, @@ -23,7 +22,7 @@ if onnxrt_dep.found() link_args : noseh_link_args, include_directories : [configinc, libsinc, cuda_stubinc], dependencies : [gstbase_dep, gstvideo_dep, gstanalytics_dep, onnxrt_dep, - libm, gio_dep] + extra_deps, + libm] + extra_deps, install : true, install_dir : plugins_install_dir, ) diff --git a/subprojects/gst-plugins-bad/gst/meson.build b/subprojects/gst-plugins-bad/gst/meson.build index 4232a34aef..642563e2a0 100644 --- a/subprojects/gst-plugins-bad/gst/meson.build +++ b/subprojects/gst-plugins-bad/gst/meson.build @@ -11,7 +11,7 @@ foreach plugin : ['accurip', 'adpcmdec', 'adpcmenc', 'aiff', 'asfmux', 'mse', 'mxf', 'netsim', 'onvif', 'pcapparse', 'pnm', 'proxy', 'rawparse', 'removesilence', 'rist', 'rtmp2', 'rtp', 'sdp', 'segmentclip', 'siren', 'smooth', 'speed', 'subenc', 'switchbin', - 'timecode', 'transcode', 'unixfd', 'videofilters', + 'tensordecoders', 'timecode', 'transcode', 'unixfd', 'videofilters', 'videoframe_audiolevel', 'videoparsers', 'videosignal', 'vmnc', 'y4m'] if not get_option(plugin).disabled() diff --git a/subprojects/gst-plugins-bad/ext/onnx/decoders/gstssdobjectdetector.c b/subprojects/gst-plugins-bad/gst/tensordecoders/gstssdobjectdetector.c similarity index 99% rename from subprojects/gst-plugins-bad/ext/onnx/decoders/gstssdobjectdetector.c rename to subprojects/gst-plugins-bad/gst/tensordecoders/gstssdobjectdetector.c index fd9c0770e6..e1ce336ed1 100644 --- a/subprojects/gst-plugins-bad/ext/onnx/decoders/gstssdobjectdetector.c +++ b/subprojects/gst-plugins-bad/gst/tensordecoders/gstssdobjectdetector.c @@ -2,7 +2,7 @@ * GStreamer gstreamer-ssdobjectdetector * Copyright (C) 2021 Collabora Ltd. * - * gstssdobjectdetector.cpp + * gstssdobjectdetector.c * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public diff --git a/subprojects/gst-plugins-bad/ext/onnx/decoders/gstssdobjectdetector.h b/subprojects/gst-plugins-bad/gst/tensordecoders/gstssdobjectdetector.h similarity index 100% rename from subprojects/gst-plugins-bad/ext/onnx/decoders/gstssdobjectdetector.h rename to subprojects/gst-plugins-bad/gst/tensordecoders/gstssdobjectdetector.h diff --git a/subprojects/gst-plugins-bad/gst/tensordecoders/gsttensordecoders.c b/subprojects/gst-plugins-bad/gst/tensordecoders/gsttensordecoders.c new file mode 100644 index 0000000000..258afe84cb --- /dev/null +++ b/subprojects/gst-plugins-bad/gst/tensordecoders/gsttensordecoders.c @@ -0,0 +1,49 @@ +/* GStreamer object detection overlay + * Copyright (C) <2024> Collabora Ltd. + * @author: Daniel Morin + * + * gsttensordecoders.c + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "gstssdobjectdetector.h" + +/** + * SECTION:plugin-tensordecoders + * + * Tensor decoders + * + * Since: 1.26 + */ +static gboolean +plugin_init (GstPlugin * plugin) +{ + gboolean ret = FALSE; + ret |= GST_ELEMENT_REGISTER (ssd_object_detector, plugin); + + return ret; +} + +GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, + GST_VERSION_MINOR, + tensordecoders, + "Tensor decoders elements", + plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN) diff --git a/subprojects/gst-plugins-bad/gst/tensordecoders/meson.build b/subprojects/gst-plugins-bad/gst/tensordecoders/meson.build new file mode 100644 index 0000000000..8c4d2bd648 --- /dev/null +++ b/subprojects/gst-plugins-bad/gst/tensordecoders/meson.build @@ -0,0 +1,14 @@ +tensordecoders_sources = [ + 'gsttensordecoders.c', + 'gstssdobjectdetector.c' +] + +gsttensordecoders = library('gsttensordecoders', + tensordecoders_sources, + c_args : gst_plugins_bad_args, + include_directories : [configinc], + dependencies : [gstbase_dep, gstvideo_dep, gstanalytics_dep, gio_dep, libm], + install : true, + install_dir : plugins_install_dir, +) +plugins += [gsttensordecoders] diff --git a/subprojects/gst-plugins-bad/meson_options.txt b/subprojects/gst-plugins-bad/meson_options.txt index 5ffbcc2a53..c49dad4ad5 100644 --- a/subprojects/gst-plugins-bad/meson_options.txt +++ b/subprojects/gst-plugins-bad/meson_options.txt @@ -67,6 +67,7 @@ option('smooth', type : 'feature', value : 'auto') option('speed', type : 'feature', value : 'auto') option('subenc', type : 'feature', value : 'auto') option('switchbin', type : 'feature', value : 'auto') +option('tensordecoders', type : 'feature', value : 'auto') option('timecode', type : 'feature', value : 'auto') option('unixfd', type : 'feature', value : 'auto') option('videofilters', type : 'feature', value : 'auto')