Gst-nvdsdynamicsrcbin (developer preview)
The Gst-nvdsdynamicsrcbin plugin is a custom GStreamer element designed for high decoder throughput scenarios. It creates a single pipeline that keeps the decoder active at all times, eliminating decoder initialization overhead when switching between multiple video streams.
The plugin accepts video files as input sources and dynamically manages them through signals. The Gst-nvdsdynamicsrcbin plugin performs dynamic source management, enabling seamless switching between multiple video streams without pipeline reconstruction.
Key Features:
- Single active decoder instance for multiple sources
- Dynamic source addition and removal via signals
- Custom events for source change tracking
- Thread-safe source queue management
- Hardware decoding with nvv4l2decoder
The plugin maintains internal queues and maps to track active sources and their corresponding file paths, enabling seamless switching between multiple video streams.
Inputs and Outputs
This section summarizes the inputs, outputs, and communication facilities of the Gst-nvdsdynamicsrcbin plugin.
-
Inputs
- Video files (any format supported by GStreamer parsebin)
- Dynamic source addition signals (add-source)
- Source removal signals (remove-source)
- Termination signals (terminate)
-
Control parameters
Gst-nvdsdynamicsrcbin gets control parameters from signals and GObject properties. The following control parameters can be set through GObject properties:
-
GPU ID for hardware decoding
-
Current file being processed (read-only)
-
Current source ID being processed (read-only)
-
Outputs
- Gst Buffer with decoded video frames
- Custom metadata containing source identification
- Custom events for source change tracking
- Application messages for dynamic source changes
Features
The following table summarizes the features of the plugin.
Gst-nvdsdynamicsrcbin plugin features
Element Architecture
The nvdsdynamicsrcbin element contains the following internal elements:
- filesrc: Source element for reading video files
- queue_filesrc: Buffering queue for source data
- parsebin: Media format detection and parsing
- queue_parsebin: Buffering queue for parsed data
- nvv4l2decoder: Hardware decoder (kept active throughout)
The element maintains internal queues and maps to track active sources and their corresponding file paths, enabling seamless switching between multiple video streams.
Supported Signals
The nvdsdynamicsrcbin element supports three key signals for dynamic source management:
-
add-source Signal: Purpose: Adds a new video source to the dynamic source bin Parameters: file_path (string), source_id (integer) Usage: g_signal_emit_by_name(dynamicsrcbin, “add-source”, “/path/to/video.mp4”, source_id); Behavior: Validates file path, prevents duplicate source IDs, stores mapping, adds to internal queues, links elements for first source
-
remove-source Signal: Purpose: Removes a video source from the dynamic source bin Parameters: source_id (integer) Usage: g_signal_emit_by_name(dynamicsrcbin, “remove-source”, source_id); Behavior: Sends EOS for active sources, removes from tracking for queued sources, cleans up data structures, posts file change message
-
terminate Signal: Purpose: Terminates the entire pipeline gracefully Parameters: None Usage: g_signal_emit_by_name(dynamicsrcbin, “terminate”); Behavior: Sends EOS event from decoder, posts termination message, cleans up resources
Custom Events and Metadata
-
Custom Stream Start Event: Event Name: “custom-stream-start-event” Contains: source-id parameter Purpose: Notifies downstream elements when a new source begins processing
-
Custom EOS Event: Event Name: “custom-eos-event” Contains: source-id parameter Purpose: Notifies when a source completes processing
-
Source Metadata: The element attaches custom metadata to each buffer containing:
- chunk_id: The source ID that generated the buffer
- frame_id: Sequential frame counter for the current source
Gst Properties
The following table describes the Gst-nvdsdynamicsrcbin plugin’s Gst properties.
Gst-nvdsdynamicsrcbin Gst Properties
Performance Benefits
-
Eliminates Decoder Initialization Overhead: When you add N streams to a traditional pipeline, each stream typically requires its own decoder instance with initialization time. The nvdsdynamicsrcbin element maintains a single active decoder, significantly reducing latency when switching between streams.
-
Improved Throughput: By keeping the decoder warm and ready, the element can handle rapid stream switching without the performance penalty of repeated decoder initialization.
-
Dynamic Source Management: The element supports real-time addition and removal of video sources without pipeline reconstruction.
-
Reduced Latency: Maintains single active decoder instance for improved performance in multi-stream scenarios.
-
Rapid Source Switching: Enables switching between streams without performance penalty.
Usage Examples
The following example demonstrates how to use the nvdsdynamicsrcbin element in a GStreamer pipeline:
Basic Pipeline Setup:
Dynamic Source Management:
Monitoring Source Changes:
Sink Input Buffer Callback:
Dynamic Source Message Handler:
Important: The handle_dynamic_source_message function is required for the nvdsdynamicsrcbin element to work properly. This function handles the cleanup of old elements and loading of new sources when dynamic source changes occur. Without proper implementation of this handler, the element will not function correctly and may cause pipeline failures.
Bus Message Handling:
Technical Notes
- The element uses GStreamer’s parsebin for automatic format detection
- Hardware decoding is performed using nvv4l2decoder
- Custom metadata is attached to buffers for source tracking
- Thread-safe operations ensure concurrent signal handling
- The element posts application messages for source change notifications
- Internal queues and maps track active sources and file paths
- Mutex protection ensures thread-safe source operations
Compilation and Installation
To compile and install the plugin:
-
Export or set in Makefile the appropriate CUDA version using CUDA_VER=13.2
-
Run make and sudo make install:
Note: To compile the sources, run make with “sudo” or root permission.
Testing
Test with Sample Application:
The sample application demonstrates:
- Pipeline setup with nvdsdynamicsrcbin and fakesink
- Dynamic source addition with unique IDs
- Sequential processing with active decoder
- Frame processing monitoring
- Source change tracking
- Graceful pipeline termination
Configuration
- Modify
N_CHUNKSin the source code to change the number of sources - Update
VIDEO_FILEpath to use different video files - Adjust timing parameters in the signal thread for different test scenarios
- Configure GPU ID for hardware decoding
- Set queue buffer sizes for optimal performance
The plugin is particularly useful for:
- Multi-stream video processing applications
- Real-time video source switching
- High-throughput video decoding scenarios
- Applications requiring minimal latency between stream changes
- Video streaming services with dynamic content