NVIDIA DeepStream SDK API Reference

9.2 Release
sources/gst-plugins/gst-nvmodelmux/gstnvmodelmux.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3  * SPDX-License-Identifier: Apache-2.0
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
56 #ifndef __GST_NVMODELMUX_H__
57 #define __GST_NVMODELMUX_H__
58 
59 #include <gst/gst.h>
60 #include "gstnvmodelmux_priv.h" /* ModelMuxConfig, ModelMuxBin, bin API */
61 
62 G_BEGIN_DECLS
63 
64 #define GST_TYPE_NVMODELMUX (gst_modelmux_get_type ())
65 #define GST_NVMODELMUX(obj) \
66  (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_NVMODELMUX, GstNvModelMux))
67 #define GST_NVMODELMUX_CLASS(klass) \
68  (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_NVMODELMUX, GstNvModelMuxClass))
69 #define GST_IS_NVMODELMUX(obj) \
70  (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_NVMODELMUX))
71 #define GST_IS_NVMODELMUX_CLASS(klass) \
72  (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_NVMODELMUX))
73 
76 
77 /* GObject property ids. Public (in the header, nvinfer convention) so the config
78  * parser can consult is_prop_set[] -- an explicitly-set property OVERRIDES the
79  * config-file value. Keep PROP_LAST last: it sizes is_prop_set[]. */
80 enum
81 {
94 };
95 
104 {
105  GstBin parent;
109 
113 
115  GstElement *passthru;
116 
123 
125  GstPad *sinkpad;
126  GstPad *srcpad;
127 
129  gboolean built;
130 
133 
143 
150 
155  GHashTable *source_attach_state;
161  guint64 batch_idx;
162 
164  GstBus *bus;
166  gulong bus_sync_id;
171 
172 
177 
179  gboolean enable;
183  guint batch_size;
187  gboolean unified_batch;
188 
194  gboolean model_sharding;
198  gchar *shadow_model;
199 };
200 
202 {
203  GstBinClass parent_class;
204 };
205 
206 GType gst_modelmux_get_type (void);
207 
208 /* Parse the config-file into self->config, then reconcile with the GObject properties:
209  * an EXPLICITLY-set property (self->is_prop_set[PROP_*]) overrides the file value; an
210  * unset property is FILLED from the file (so a read-back reflects the effective config).
211  * Returns FALSE if the path is missing/empty or the file cannot be parsed. Takes the
212  * element (nvinfer convention) so it can update both self->config and the property
213  * fields in one place. Defined in gstnvmodelmux_config.c. */
214 gboolean gst_modelmux_parse_config_file (GstNvModelMux * self, const gchar * cfg_file);
215 
216 /* --- peer-stage traversal (gstnvmodelmux.c) ---
217  * Visit every OTHER nvmodelmux in this element's pipeline. This is how EVERY
218  * cross-stage question is answered -- config-time name/id conflicts, and at runtime
219  * the model-plane and GET-plane fan-out -- because pads describe the DATA topology
220  * and stages are not necessarily wired in series (deepstream-app hangs sibling
221  * secondaries off one tee, so a forwarded query reaches only the first). Walking the
222  * pipeline finds them however they are wired. @fn returns FALSE to stop early. */
223 typedef gboolean (*ModelMuxPeerStageFunc) (GstNvModelMux * self,
224  GstNvModelMux * peer, gpointer udata);
225 G_GNUC_INTERNAL void modelmux_foreach_peer_stage (GstNvModelMux * self,
227  gpointer udata);
228 
229 /* Deliver @q to @peer's own query probe and return TRUE if it answered.
230  * The copy handed over is MARKED, so the peer answers for itself and does not fan
231  * out again -- one level of delegation, no cycles however many stages there are.
232  * @q itself is never modified; the caller reads the answer from @out. */
233 G_GNUC_INTERNAL gboolean modelmux_stage_ask_peer (GstNvModelMux * peer, GstQuery * q,
234  GstQuery ** out);
235 /* TRUE when this query is one a peer stage handed us: answer for THIS stage only. */
236 G_GNUC_INTERNAL gboolean modelmux_stage_query_is_delegated (GstQuery * q);
237 
238 /* --- native-REST control plane (gstnvmodelmux_control.c) ---
239  * Make the element self-contained: subscribe to the pipeline bus so the
240  * nvmultiurisrcbin native-REST messages (stream/add|remove, model/load|unload|
241  * update) are parsed and executed INTERNALLY -- the host app needs no glue.
242  * Attached when the inference bin is built; detached on teardown. */
245 /* Wire the control plane's bin-invoked callbacks (OTA rollback follow-up)
246  * into a freshly-built bin, before it is published to self->modelmux_bin. */
248 /* Per-stream model-selection metadata parser (gstnvmodelmux_control_metadata.c;
249  * called by the control plane). Declared here -- the one header BOTH files
250  * include -- so the definition sees a prototype (tmake: -Werror=missing-prototypes). */
251 G_GNUC_INTERNAL void modelmux_control_parse_model_metadata (GstNvModelMux * self,
252  const gchar * json, gchar ** primary_model_name, gchar ** primary_model_version,
253  gint * primary_model_gpu, gchar ** shadow_model_name, gchar ** shadow_model_version,
254  gint * shadow_model_gpu);
255 
256 G_END_DECLS
257 
258 #endif /* __GST_NVMODELMUX_H__ */
gstnvmodelmux_priv.h
_GstNvModelMux::initial_default_load_started
gboolean initial_default_load_started
default-model warm-up KICKED OFF at first PLAYING (once); reset on teardown.
Definition: sources/gst-plugins/gst-nvmodelmux/gstnvmodelmux.h:132
ModelMuxPeerStageFunc
gboolean(* ModelMuxPeerStageFunc)(GstNvModelMux *self, GstNvModelMux *peer, gpointer udata)
Definition: sources/gst-plugins/gst-nvmodelmux/gstnvmodelmux.h:223
_GstNvModelMux::primary_model
gchar * primary_model
default primary model "name;version;config"
Definition: sources/gst-plugins/gst-nvmodelmux/gstnvmodelmux.h:196
_GstNvModelMux::compact_idle_models_across_pools
gboolean compact_idle_models_across_pools
flag to compact idle models across pools on idle (dedup-on-idle)
Definition: sources/gst-plugins/gst-nvmodelmux/gstnvmodelmux.h:192
_GstNvModelMux::source_attach_state
GHashTable * source_attach_state
source_id -> ModelMuxSourceAttachState (attach lifecycle; driven by stream/add -> GST_NVEVENT_PAD_ADD...
Definition: sources/gst-plugins/gst-nvmodelmux/gstnvmodelmux.h:155
modelmux_foreach_peer_stage
G_GNUC_INTERNAL void modelmux_foreach_peer_stage(GstNvModelMux *self, ModelMuxPeerStageFunc fn, gpointer udata)
_GstNvModelMux::per_model_batch_size
guint per_model_batch_size
per-model nvstreammux batch cap (0=def)
Definition: sources/gst-plugins/gst-nvmodelmux/gstnvmodelmux.h:185
_GstNvModelMux::sink_event_probe_id
gulong sink_event_probe_id
PAD_ADDED/PAD_DELETED/STREAM_EOS event probe on the sink.
Definition: sources/gst-plugins/gst-nvmodelmux/gstnvmodelmux.h:135
_GstNvModelMux::modelmux_sgie_bin
ModelMuxSgieBin * modelmux_sgie_bin
the SECONDARY-stage inference bin, built instead of @modelmux_bin when process-mode=2 (NULL at a prim...
Definition: sources/gst-plugins/gst-nvmodelmux/gstnvmodelmux.h:112
PROP_PER_MODEL_BATCH_SIZE
@ PROP_PER_MODEL_BATCH_SIZE
Definition: sources/gst-plugins/gst-nvmodelmux/gstnvmodelmux.h:86
_GstNvModelMux::unified_batch
gboolean unified_batch
flag to enable unified A/B display batch
Definition: sources/gst-plugins/gst-nvmodelmux/gstnvmodelmux.h:187
_GstNvModelMux::sink_status_query_id
gulong sink_status_query_id
QUERY probes on the sink: model/status + model/routing GET, and the synchronous control admission.
Definition: sources/gst-plugins/gst-nvmodelmux/gstnvmodelmux.h:141
gst_modelmux_get_type
GType gst_modelmux_get_type(void)
PROP_LAST
@ PROP_LAST
Definition: sources/gst-plugins/gst-nvmodelmux/gstnvmodelmux.h:93
_GstNvModelMux::parent
GstBin parent
we are a bin
Definition: sources/gst-plugins/gst-nvmodelmux/gstnvmodelmux.h:105
_GstNvModelMux::config_file_path
gchar * config_file_path
multimodel config (defaults, behaviour, [stream-model-<id>] bindings); parsed by the plugin.
Definition: sources/gst-plugins/gst-nvmodelmux/gstnvmodelmux.h:181
PROP_0
@ PROP_0
Definition: sources/gst-plugins/gst-nvmodelmux/gstnvmodelmux.h:82
_GstNvModelMux::sink_control_query_id
gulong sink_control_query_id
Definition: sources/gst-plugins/gst-nvmodelmux/gstnvmodelmux.h:142
json
nlohmann::json json
Definition: sources/gst-plugins/gst-nvdsvideotemplate/ds-sparse4d/preprocess/calibration_parser.h:32
PROP_PROCESS_MODE
@ PROP_PROCESS_MODE
Definition: sources/gst-plugins/gst-nvmodelmux/gstnvmodelmux.h:92
_GstNvModelMux::requested_binding_info
GHashTable * requested_binding_info
source_id -> ModelMuxRequestedBindingInfo (per-stream model binding from the in-band GST_NVEVENT_STRE...
Definition: sources/gst-plugins/gst-nvmodelmux/gstnvmodelmux.h:159
ModelMuxSgieBin
struct _ModelMuxSgieBin ModelMuxSgieBin
Definition: sources/gst-plugins/gst-nvmodelmux/gstnvmodelmux_priv.h:1200
_GstNvModelMux::sink_probe_id
gulong sink_probe_id
buffer probe: drop a source's buffers until it is attached (safety net)
Definition: sources/gst-plugins/gst-nvmodelmux/gstnvmodelmux.h:137
modelmux_control_parse_model_metadata
G_GNUC_INTERNAL void modelmux_control_parse_model_metadata(GstNvModelMux *self, const gchar *json, gchar **primary_model_name, gchar **primary_model_version, gint *primary_model_gpu, gchar **shadow_model_name, gchar **shadow_model_version, gint *shadow_model_gpu)
_GstNvModelMux
ModelMuxInstance struct.
Definition: sources/gst-plugins/gst-nvmodelmux/gstnvmodelmux.h:103
_GstNvModelMux::enable
gboolean enable
flag to enable inference (TRUE) vs passthrough (FALSE)
Definition: sources/gst-plugins/gst-nvmodelmux/gstnvmodelmux.h:179
_GstNvModelMux::sinkpad
GstPad * sinkpad
ghost sink/src pad (no-target until the sub-graph is built)
Definition: sources/gst-plugins/gst-nvmodelmux/gstnvmodelmux.h:125
_GstNvModelMux::bus
GstBus * bus
pipeline bus (ref held for the "sync-message" subscription)
Definition: sources/gst-plugins/gst-nvmodelmux/gstnvmodelmux.h:164
gst_modelmux_parse_config_file
gboolean gst_modelmux_parse_config_file(GstNvModelMux *self, const gchar *cfg_file)
PROP_SHADOW_MODEL
@ PROP_SHADOW_MODEL
Definition: sources/gst-plugins/gst-nvmodelmux/gstnvmodelmux.h:89
_GstNvModelMux::built
gboolean built
TRUE once the sub-graph has been materialised.
Definition: sources/gst-plugins/gst-nvmodelmux/gstnvmodelmux.h:129
PROP_PRIMARY_MODEL
@ PROP_PRIMARY_MODEL
Definition: sources/gst-plugins/gst-nvmodelmux/gstnvmodelmux.h:88
_GstNvModelMux::config
ModelMuxConfig config
assembled configuration (owned)
Definition: sources/gst-plugins/gst-nvmodelmux/gstnvmodelmux.h:174
_GstNvModelMux::is_prop_set
gboolean is_prop_set[PROP_LAST]
properties the user set (by PROP_*); a set property overrides the config-file value.
Definition: sources/gst-plugins/gst-nvmodelmux/gstnvmodelmux.h:176
gst_modelmux_control_attach
void gst_modelmux_control_attach(GstNvModelMux *self)
_GstNvModelMux::process_mode
gint process_mode
which GIE position (1=primary full frame, 2=secondary objects)
Definition: sources/gst-plugins/gst-nvmodelmux/gstnvmodelmux.h:190
modelmux_stage_query_is_delegated
G_GNUC_INTERNAL gboolean modelmux_stage_query_is_delegated(GstQuery *q)
gst_modelmux_control_wire_ota_rollback
void gst_modelmux_control_wire_ota_rollback(GstNvModelMux *self, ModelMuxBin *mm)
gst_modelmux_control_detach
void gst_modelmux_control_detach(GstNvModelMux *self)
PROP_COMPACT_IDLE_MODELS_ACROSS_POOLS
@ PROP_COMPACT_IDLE_MODELS_ACROSS_POOLS
Definition: sources/gst-plugins/gst-nvmodelmux/gstnvmodelmux.h:90
ModelMuxConfig
Definition: sources/gst-plugins/gst-nvmodelmux/gstnvmodelmux_priv.h:286
_GstNvModelMuxClass
Definition: sources/gst-plugins/gst-nvmodelmux/gstnvmodelmux.h:201
_GstNvModelMux::batch_idx
guint64 batch_idx
batches seen on the sink (for staleness detection)
Definition: sources/gst-plugins/gst-nvmodelmux/gstnvmodelmux.h:161
PROP_BATCH_SIZE
@ PROP_BATCH_SIZE
Definition: sources/gst-plugins/gst-nvmodelmux/gstnvmodelmux.h:85
_GstNvModelMux::pending_poll_id
guint pending_poll_id
g_timeout id for the deferred pending-reroute poller (0 = not running)
Definition: sources/gst-plugins/gst-nvmodelmux/gstnvmodelmux.h:170
PROP_CONFIG_FILE_PATH
@ PROP_CONFIG_FILE_PATH
Definition: sources/gst-plugins/gst-nvmodelmux/gstnvmodelmux.h:84
_GstNvModelMux::bus_sync_id
gulong bus_sync_id
"sync-message" handler id (0 = not connected)
Definition: sources/gst-plugins/gst-nvmodelmux/gstnvmodelmux.h:166
_GstNvModelMux::model_sharding
gboolean model_sharding
flag to enable model sharding on overflow
Definition: sources/gst-plugins/gst-nvmodelmux/gstnvmodelmux.h:194
_GstNvModelMux::passthru
GstElement * passthru
identity element, used when enable=FALSE (transparent passthrough)
Definition: sources/gst-plugins/gst-nvmodelmux/gstnvmodelmux.h:115
PROP_UNIFIED_BATCH
@ PROP_UNIFIED_BATCH
Definition: sources/gst-plugins/gst-nvmodelmux/gstnvmodelmux.h:87
PROP_MODEL_SHARDING
@ PROP_MODEL_SHARDING
Definition: sources/gst-plugins/gst-nvmodelmux/gstnvmodelmux.h:91
_GstNvModelMux::modelmux_bin
ModelMuxBin * modelmux_bin
the PRIMARY-stage inference bin (NULL until built, or in passthrough mode)
Definition: sources/gst-plugins/gst-nvmodelmux/gstnvmodelmux.h:108
_GstNvModelMux::rev_shared
ModelMuxRevShared * rev_shared
the routing revision SHARED by every nvmodelmux stage in this pipeline, negotiated at NULL->READY thr...
Definition: sources/gst-plugins/gst-nvmodelmux/gstnvmodelmux.h:122
_GstNvModelMux::pending_reroutes
GList * pending_reroutes
ModelMuxPendingReroute*: model/update flips deferred until the target warms up.
Definition: sources/gst-plugins/gst-nvmodelmux/gstnvmodelmux.h:168
ModelMuxRevShared
struct _ModelMuxRevShared ModelMuxRevShared
The counter itself: refcounted (each stage holds one ref) and self-locking, so it can be read while a...
Definition: sources/gst-plugins/gst-nvmodelmux/gstnvmodelmux_priv.h:119
modelmux_stage_ask_peer
G_GNUC_INTERNAL gboolean modelmux_stage_ask_peer(GstNvModelMux *peer, GstQuery *q, GstQuery **out)
ModelMuxBin
Definition: sources/gst-plugins/gst-nvmodelmux/gstnvmodelmux_priv.h:901
_GstNvModelMux::srcpad
GstPad * srcpad
Definition: sources/gst-plugins/gst-nvmodelmux/gstnvmodelmux.h:126
_GstNvModelMux::batch_size
guint batch_size
max concurrent streams batch cap
Definition: sources/gst-plugins/gst-nvmodelmux/gstnvmodelmux.h:183
_GstNvModelMux::source_state_lock
GMutex source_state_lock
guards source_attach_state + requested_binding_info
Definition: sources/gst-plugins/gst-nvmodelmux/gstnvmodelmux.h:152
_GstNvModelMux::api_control_lock
GMutex api_control_lock
serializes every control-plane ENTRY POINT (action signals, REST dispatch, pending-reroute poller) ag...
Definition: sources/gst-plugins/gst-nvmodelmux/gstnvmodelmux.h:149
_GstNvModelMuxClass::parent_class
GstBinClass parent_class
Definition: sources/gst-plugins/gst-nvmodelmux/gstnvmodelmux.h:203
_GstNvModelMux::shadow_model
gchar * shadow_model
default shadow model "name;version;config"
Definition: sources/gst-plugins/gst-nvmodelmux/gstnvmodelmux.h:198
PROP_ENABLE
@ PROP_ENABLE
Definition: sources/gst-plugins/gst-nvmodelmux/gstnvmodelmux.h:83