### Start Smart Recording Tap on User or Application Demand (Python) Source: https://github.com/prominenceai/deepstream-services-library/blob/master/docs/examples-smart-recording.md This Python example demonstrates how to start a Smart-Record Tap session on user demand, specifically by pressing the 'S' key. It configures the recording to include a specified amount of historical data ('start') and records for a set duration ('duration') after the session begins. The example highlights the importance of managing recording sizes and cache sizes. ```python # ```````````````````````````````````````````````````````````````````````````````````` # This example demonstrates the use of a Smart-Record Tap and how # to start a recording session on user/viewer demand - in this case # by pressing the 'S' key. The xwindow_key_event_handler calls # dsl_tap_record_session_start with: # start: the seconds before the current time (i.e.the amount of # cache/history to include. # duration: the seconds after the current time (i.e. the amount of # time to record after session start is called). # Therefore, a total of start-time + duration seconds of data will be recorded. # # **IMPORTANT!** # 1. The default max_size for all Smart Recordings is set to 600 seconds. The # recording will be truncated if start + duration > max_size. # Use dsl_tap_record_max_size_set to update max_size. # 2. The default cache-size for all recordings is set to 60 seconds. The # recording will be truncated if start > cache_size. # Use dsl_tap_record_cache_size_set to update cache_size. # # Record Tap components tap into RTSP Source components pre-decoder to enable # smart-recording of the incomming (original) H.264 or H.265 stream. # ``` -------------------------------- ### DeepStream Smart Record Sink Examples Source: https://github.com/prominenceai/deepstream-services-library/blob/master/Release Notes/v0.31.alpha.md Python and C++ examples demonstrating how to use the smart record sink to start recording sessions based on ODE occurrences or user demand. ```python import sys import json from dsl import * def main(args): error = dsl_dir_init() if error != DSL_SUCCESS: return error # Define GStreamer pipeline components source = "uri=./video/streams/sample_720p.h264" demuxer = "name=demuxer" nvds_osd = "name=nvds_osd" encoder = "name=encoder ! nvv4l2decoder ! nvv4l2h264enc bitrate=4000000 ! h264parse ! rtph264pay config-interval=1 pt=96" rtsp_sink = "name=rtsp_sink " # Create GStreamer pipeline components error = dsl_source_file_new('source', source) error = dsl_demuxer_new('demuxer', demuxer) error = dsl_osd_new('osd', nvds_osd) error = dsl_encoder_new('encoder', encoder) error = dsl_sink_rtsp_server_new('rtsp-server', rtsp_sink, 8554, "/stream") # Add components to the pipeline error = dsl_pipeline_component_add_many(pipeline, ['source', 'demuxer', 'osd', 'encoder', 'rtsp-server']) # Start the pipeline error = dsl_pipeline_play(pipeline) # Wait for termination signal dsl_main_loop_run() # Cleanup dsl_pipeline_stop(pipeline) dsl_pipeline_delete(pipeline) dsl_source_delete('source') dsl_demuxer_delete('demuxer') dsl_osd_delete('osd') dsl_encoder_delete('encoder') dsl_sink_delete('rtsp-server') dsl_dir_cleanup() return error if __name__ == '__main__': sys.exit(main(sys.argv)) ``` ```cpp #include "dsl.h" #include "dsros.h" #include #include using std::string; int main(int argc, char** argv) { int ret = DSL_SUCCESS; // Create a smart record sink uint64_t record_sink_id = 0; ret = dsl_sink_record_new( "record-sink", // Name of the sink "container=1", // Container format (e.g., MP4, MKV) &record_sink_id ); if (ret != DSL_SUCCESS) { printf("Failed to create record sink\n"); return ret; } // Start a recording session on ODE occurrence uint64_t session_id_ode = 0; ret = dsl_sink_record_session_start_on_ode_occurrence( record_sink_id, // ID of the record sink "ODECallback", // Name of the ODE callback function "output/ode_recording.mp4", // Output file path &session_id_ode ); if (ret != DSL_SUCCESS) { printf("Failed to start record session on ODE occurrence\n"); return ret; } // Start a recording session on user demand uint64_t session_id_user = 0; ret = dsl_sink_record_session_start_on_user_demand( record_sink_id, // ID of the record sink "output/user_recording.mp4", // Output file path &session_id_user ); if (ret != DSL_SUCCESS) { printf("Failed to start record session on user demand\n"); return ret; } // Add the record sink to a pipeline (assuming pipeline is already created) // ret = dsl_pipeline_component_add(pipeline_id, record_sink_id); // ... pipeline setup and execution ... // Stop recording sessions (example) // ret = dsl_sink_record_session_stop(session_id_ode); // ret = dsl_sink_record_session_stop(session_id_user); // Cleanup // dsl_sink_record_delete(record_sink_id); return ret; } ``` -------------------------------- ### Start Smart Recording Sink on User Demand Source: https://github.com/prominenceai/deepstream-services-library/blob/master/docs/examples-smart-recording.md Demonstrates how to start a smart recording session on user demand, specifically by pressing the 'S' key. The xwindow_key_event_handler initiates the recording with specified start and duration parameters, including caching previous frames. Similar to the event-driven example, it uses a basic inference pipeline and overlays display information. ```python # This example demonstrates the use of a Smart-Record Sink and how # to start a recording session on user/viewer demand - in this case # by pressing the 'S' key. The xwindow_key_event_handler calls # dsl_sink_record_session_start with: # start: the seconds before the current time (i.e.the amount of # cache/history to include. # duration: the seconds after the current time (i.e. the amount of # time to record after session start is called). # Therefore, a total of start-time + duration seconds of data will be recorded. # # **IMPORTANT!** # 1. The default max_size for all Smart Recordings is set to 600 seconds. The # recording will be truncated if start + duration > max_size. # Use dsl_sink_record_max_size_set to update max_size. # 2. The default cache-size for all recordings is set to 60 seconds. The # recording will be truncated if start > cache_size. # Use dsl_sink_record_cache_size_set to update cache_size. # # A basic inference Pipeline is used with PGIE, Tracker, OSD, and Window Sink. # # DSL Display Types are used to overlay text ("REC") with a red circle to # indicate when a recording session is in progress. An ODE "Always-Trigger" and an # ODE "Add Display Meta Action" are used to add the text's and circle's metadata # to each frame while the Trigger is enabled. The record_event_listener callback, # called on both DSL_RECORDING_EVENT_START and DSL_RECORDING_EVENT_END, enables ``` -------------------------------- ### Python Example for Starting Recording Session Source: https://github.com/prominenceai/deepstream-services-library/blob/master/docs/api-tap.md Illustrates how to start a recording session using `dsl_tap_record_session_start` in Python. It specifies the record tap name ('my-record-tap'), requests a session ID, sets the start time to 15 seconds before the current time, and records for 900 seconds. ```Python retval, session = dsl_tap_record_session_start('my-record-tap', 15, 900, None) ``` -------------------------------- ### Test RTSP Source Connection with Simple DSL Player (Python) Source: https://github.com/prominenceai/deepstream-services-library/blob/master/docs/examples-diagnaostics-and-utilities.md Provides a simple DSL Player setup with a single RTSP Source and Window Sink to test RTSP connections. It includes example URIs for different camera brands and registers callbacks for key-release, delete-window, and source state change events. ```python # # This example can be used to test your RTSP Source connection. It uses a simple # DSL Player with a single RTSP Source and Window Sink: # # There two example camera URI's below. One for AMCREST and one for HIKVISION. # update one of the URI's with your username and password, or add your own # URI format as needed. # # Ensure that the RTSP Source constructor is using the correct URI. # # The example registers handler callback functions to be notified of: # - key-release events # - delete-window events # - RTSP Source change-of-state events # ``` -------------------------------- ### Start Smart Recording Tap on Object Detection Event Occurrence (Python) Source: https://github.com/prominenceai/deepstream-services-library/blob/master/docs/examples-smart-recording.md This Python example demonstrates starting a Smart-Record Tap session triggered by the occurrence of an Object Detection Event (ODE). It uses an ODE Occurrence Trigger with a 'Start Recording Session Action' to capture a specific duration of cached data. The example also shows how to capture object bounding boxes and overlay 'REC' indicators during recording, and how to manage recording events. ```python # ```````````````````````````````````````````````````````````````````````````````````` # This example demonstrates the use of a Smart-Record Tap and how to start # a recording session on the "occurrence" of an Object Detection Event (ODE). # An ODE Occurrence Trigger, with a limit of 1 event, is used to trigger # on the first detection of a Person object. The Trigger uses an ODE "Start # Recording Session Action" setup with the following parameters: # start: the seconds before the current time (i.e.the amount of # cache/history to include. # duration: the seconds after the current time (i.e. the amount of # time to record after session start is called). # Therefore, a total of start-time + duration seconds of data will be recorded. # # **IMPORTANT!** # 1. The default max_size for all Smart Recordings is set to 600 seconds. The # recording will be truncated if start + duration > max_size. # Use dsl_tap_record_max_size_set to update max_size. # 2. The default cache-size for all recordings is set to 60 seconds. The # recording will be truncated if start > cache_size. # Use dsl_tap_record_cache_size_set to update cache_size. # # Record Tap components tap into RTSP Source components pre-decoder to enable # smart-recording of the incomming (original) H.264 or H.265 stream. # # Additional ODE Actions are added to the Trigger to 1) print the ODE # data (source-id, batch-id, object-id, frame-number, object-dimensions, etc.) # to the console and 2) to capture the object (bounding-box) to a JPEG file. # # A basic inference Pipeline is used with PGIE, Tracker, Tiler, OSD, and Window Sink. # # DSL Display Types are used to overlay text ("REC") with a red circle to # indicate when a recording session is in progress. An ODE "Always-Trigger" and an # ODE "Add Display Meta Action" are used to add the text's and circle's metadata # to each frame while the Trigger is enabled. The record_event_listener callback, # called on both DSL_RECORDING_EVENT_START and DSL_RECORDING_EVENT_END, enables # and disables the "Always Trigger" according to the event received. # # IMPORTANT: the record_event_listener is used to reset the one-shot Occurrence- # Trigger when called with DSL_RECORDING_EVENT_END. This allows a new recording # session to be started on the next occurrence of a Person. # # IMPORTANT: this demonstrates a multi-source Pipeline, each with their own # Smart-Recort Tap. #!/usr/bin/env python ``` -------------------------------- ### Install DSL Shared Library and Python Bindings Source: https://github.com/prominenceai/deepstream-services-library/blob/master/docs/building-dsl.md Builds the `libdsl.so` shared library from the object files created during the test application build and installs it to `/usr/local/lib`. It also copies the DSL Python bindings (`dsl.py`) to the site-packages directory. Root privileges are required for installation. ```bash sudo make install ``` -------------------------------- ### Verify Azure CLI Installation Source: https://github.com/prominenceai/deepstream-services-library/blob/master/docs/proto-lib-azure.md Checks the installed version of the Azure CLI to confirm a successful installation. This command is crucial for ensuring the CLI is ready for use. ```bash az --version ``` -------------------------------- ### Python ODE Intersection Trigger with BBox and Print Actions Example Source: https://github.com/prominenceai/deepstream-services-library/blob/master/docs/examples-ode-services.md This example demonstrates the utilization of two Intersection Triggers, one for the 'Vehicle' class and another for the 'Person' class. It employs a 'Format BBox' action to visually highlight intersecting objects by shading their backgrounds, specifically for Person-Person and Vehicle-Vehicle intersections. Additional criteria for minimum and maximum dimensions are set for the Person and Vehicle triggers, respectively. The pipeline setup includes a URI source, PGIE, IOU Tracker, and OSD. ```python # # This example is used to demonstrate the Use of Two Intersection Triggers, # one for the Vehicle class the other for the Person class. A "Format BBox" # action will be used to shade the background of the Objects intersecting. # Person intersecting with Person and Vehicle intersecting with Vehicle. # # Min and Max Dimensions will set as addional criteria for the Preson and # Vehicle Triggers respecively # # The example uses a basic inference Pipeline consisting of: ``` -------------------------------- ### Install Doxygen on Ubuntu Source: https://github.com/prominenceai/deepstream-services-library/blob/master/docs/installing-dependencies.md Installs the Doxygen documentation system on Ubuntu systems using apt-get. ```bash sudo apt-get install doxygen ``` -------------------------------- ### Install Azure CLI on Jetson (ARM64) Source: https://github.com/prominenceai/deepstream-services-library/blob/master/docs/proto-lib-azure.md Installs the Azure CLI on Jetson devices (ARM64 architecture) by installing it from PyPI using pip. This is the recommended method for ARM-based systems where the standard script may not be compatible. ```bash sudo pip3 install azure-cli ``` -------------------------------- ### Python Example: Pushing Raw Video Buffers with App Source Source: https://github.com/prominenceai/deepstream-services-library/blob/master/docs/examples-basic-pipelines.md This Python example illustrates how to push raw video buffers to a DeepStream DSL Pipeline using an App Source component. It defines need_data_handler and enough_data_handler to manage the data flow. The example requires a pre-generated raw video file (I420 format). ```python # # This example illustrates how to push raw video buffers to a DSL Pipeline # using an App Source component. The example application adds the following # client handlers to control the input of raw buffers to the App Source # * need_data_handler - called when the App Source needs data to process # * enough_data_handler - called when the App Source has enough data to process # # The client handlers add/remove a callback function to read, map, and push data # to the App Source called "read_and_push_data". # # The raw video file used with this example is created by executing the following # gst-launch-1.0 command. # # gst-launch-1.0 uridecodebin # uri=file:///opt/nvidia/deepstream/deepstream/samples/streams/sample_720p.mp4 # ! nvvideoconvert ! 'video/x-raw, format=I420, width=1280, height=720' # ! filesink location=./sample_720p.i420 # # Note: The actual Python code for the DSL pipeline setup and handlers is not provided in the input text. # This is a placeholder to represent the description of the Python example. # Example placeholder code structure (not functional without DSL bindings): # import gi # gi.require_version('Gst', '1.0') # from gi.repository import Gst, GObject # # def need_data_handler(appsrcl, length, user_data): # # Logic to read and push data # pass # # def enough_data_handler(appsrcl, user_data): # # Logic to stop pushing data when buffer is full # pass # # def main(): # Gst.init(None) # pipeline = Gst.Pipeline.new("appsrc-pipeline") # appsrc = Gst.ElementFactory.make("appsrc", "app-source") # # # Configure appsrc properties and signals # appsrc.connect("need-data", need_data_handler, None) # appsrc.connect("enough-data", enough_data_handler, None) # # # Add other pipeline elements (nvtracker, nvosd, nveglglessink, etc.) # # Link elements # # Start pipeline # # if __name__ == '__main__': # main() ``` -------------------------------- ### Install libffi for Azure CLI Source: https://github.com/prominenceai/deepstream-services-library/blob/master/docs/proto-lib-azure.md Installs the necessary libffi development libraries to resolve compilation errors when installing Python packages like cryptography, which is a dependency for Azure CLI. ```bash sudo apt-get install libffi6 libffi-dev ``` -------------------------------- ### Python Azure Device Client Example Source: https://github.com/prominenceai/deepstream-services-library/blob/master/docs/api-msg-broker.md A simple Python example demonstrating how to send a 'hello world' string to an Azure Hub Instance using the DeepStream Message Broker. This example focuses on basic string payloads, with more complex payload handling in Python still under investigation. ```python import json import os import sys import threading import time from azure.iot.device import IoTHubDeviceClient, Message # Define the connection string CONNSTR = os.getenv('IOTHUB_DEVICE_CONNECTION_STRING') def main(): # Create instance of the device client making it connect to ITHub device_client = IoTHubDeviceClient.create_from_connection_string(CONNSTR) # Connect the device client. Take care of the retry logic if any # when the connection is not successful. try: device_client.connect() except Exception as e: print(f"Error connecting to IoT Hub: {e}") return # Send a message to IoT Hub msg = Message("Hello World from DeepStream!") try: device_client.send_message(msg) print("Message successfully sent") except Exception as e: print(f"Error sending message: {e}") # Finally, disconnect the device client print("Disconnecting from IoT Hub...") device_client.disconnect() if __name__ == '__main__': main() ``` -------------------------------- ### Build and Install FFmpeg (Bash) Source: https://github.com/prominenceai/deepstream-services-library/blob/master/docs/installing-dependencies.md Steps to clone, build, and install the latest FFmpeg development libraries from source, necessary for using FFmpeg within a DeepStream Docker Container. ```bash $mkdir ~/ffmpeg; cd ~/ffmpeg $git clone https://github.com/FFmpeg/FFmpeg.git $cd FFmpeg $./configure --enable-shared --disable-lzma $make $sudo make install ``` -------------------------------- ### C++ Example: Raw I420 App Source with Tracker, OSD, and Window Sink Source: https://github.com/prominenceai/deepstream-services-library/blob/master/docs/examples-basic-pipelines.md This C++ example demonstrates pushing raw I420 video buffers into a DeepStream DSL Pipeline using an App Source. It includes client handlers to manage data flow and integrates IOU Tracker, OSD for displaying information, and an EGL Window Sink for output visualization. The example requires a pre-generated raw video file. ```cpp #include #include "deepstream_app.h" #include "deepstream_pipeline.h" #include "deepstream_osd.h" #include "deepstream_tracker.h" #include "deepstream_window_sink.h" int main(int argc, char *argv[]) { GstElement *pipeline = NULL; GstElement *app_src = NULL; GstElement *tracker = NULL; GstElement *osd = NULL; GstElement *sink = NULL; gst_init (NULL, NULL); pipeline = gst_pipeline_new ("deepstream-app-src-pipeline"); app_src = gst_element_factory_make ("appsrc", "app-source"); tracker = gst_element_factory_make ("nvdsosd", "tracker"); // Placeholder, actual tracker element needed osd = gst_element_factory_make ("nvdsosd", "osd"); sink = gst_element_factory_make ("nveglglessink", "egl-window-sink"); if (!pipeline || !app_src || !tracker || !osd || !sink) { g_printerr ("One or more elements could not be created.\n"); return -1; } // Configure appsrc and connect signals (details omitted for brevity) // Configure tracker (details omitted for brevity) // Configure osd (details omitted for brevity) // Configure sink (details omitted for brevity) gst_bin_add_many (GST_BIN (pipeline), app_src, tracker, osd, sink, NULL); // Link elements (details omitted for brevity) // Start pipeline GstStateChangeReturn ret = gst_element_set_state (pipeline, GST_STATE_PLAYING); if (ret == GST_STATE_CHANGE_FAILURE) { g_printerr ("Unable to set the pipeline to the playing state.\n"); return -1; } // Wait until error or EOS GstBus *bus = gst_element_get_bus (pipeline); GstMessage *msg = NULL; while (TRUE) { msg = gst_bus_pop (bus); if (msg) { GError *err = NULL; gchar *debug_info = NULL; switch (GST_MESSAGE_TYPE (msg)) { case GST_MESSAGE_ERROR: gst_message_parse_error (msg, &err, &debug_info); g_printerr ("Error received from element %s: %s\n", GST_OBJECT_NAME (msg->src), err->message); g_printerr ("Debugging information: %s\n", debug_info ? debug_info : "none"); g_clear_error (&err); g_free (debug_info); break; case GST_MESSAGE_EOS: g_print ("End-Of-Stream reached.\n"); break; default: break; } gst_message_unref (msg); } if (msg == NULL) { // Check if we should exit in a loop without messages break; } } gst_object_unref (bus); gst_element_set_state (pipeline, GST_STATE_NULL); gst_object_unref (pipeline); return 0; } ``` -------------------------------- ### Create Primary GIE Component Example (Python) Source: https://github.com/prominenceai/deepstream-services-library/blob/master/docs/api-infer.md A Python example demonstrating the usage of the `dsl_infer_gie_primary_new` function to create a primary GIE component. ```python retval = dsl_infer_gie_primary_new('my-pgie', pgie_config_file, pgie_model_file, 0) ``` -------------------------------- ### Install Azure CLI on Ubuntu (x86) Source: https://github.com/prominenceai/deepstream-services-library/blob/master/docs/proto-lib-azure.md Installs the Azure Command-Line Interface (CLI) on x86 Ubuntu systems using a provided script. This tool is essential for managing Azure resources and devices from the command line. ```bash curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash ``` -------------------------------- ### Get Streammuxer Config File - Python Source: https://github.com/prominenceai/deepstream-services-library/blob/master/docs/api-pipeline.md Python example for getting the Streammuxer configuration file path of a specified pipeline. It returns the status and the config file path. ```Python retval, config_file = dsl_pipeline_streammux_config_file_get('my-pipeline') ``` -------------------------------- ### Clone Repository and Navigate Source: https://github.com/prominenceai/deepstream-services-library/blob/master/docs/building-dsl.md Clones the deepstream-services-library repository and navigates into the root directory. This is the initial step to obtain the necessary source code. ```bash git clone https://github.com/prominenceai/deepstream-services-library.git cd deepstream-services-library ``` -------------------------------- ### Verify json-glib-1.0 Package (Bash) Source: https://github.com/prominenceai/deepstream-services-library/blob/master/docs/installing-dependencies.md Checks the compiler flags for the json-glib-1.0 package, typically used after installation to ensure proper setup for components like the WebRTC Sink. ```bash pkg-config --cflags json-glib-1.0 ``` -------------------------------- ### CSI Source Pipeline with GIE, OSD, and 3D Window Sink (Python) Source: https://github.com/prominenceai/deepstream-services-library/blob/master/docs/examples-basic-pipelines.md Demonstrates a DeepStream pipeline using a CSI camera source, Primary GIE, OSD, and a 3D Window Sink. This example is specific to Jetson hardware. It sets up and runs a basic inference pipeline. ```python # # The simple example demonstrates how to create a set of Pipeline components, # specifically: # - CSI Source # - Primary GST Inference Engine (PGIE) # - On-Screen Display # - 3D Sink # ...and how to add them to a new Pipeline and play. # # IMPORTANT! this examples uses a CSI Camera Source and 3D Sink - Jetson only! # ``` -------------------------------- ### Start Record Tap Action in Python Source: https://github.com/prominenceai/deepstream-services-library/blob/master/docs/api-ode-action.md Python example for the 'Start Record Tap' ODE Action. This function initiates a recording session for a named tap, triggered by an ODE. It takes the action name, record tap name, start time offset, duration, and client data as parameters. ```Python retval = dsl_ode_action_tap_record_start_new('my-start-record-tap-action', 'my-record-tap', 15, 360, Null) ``` -------------------------------- ### Get Multi-Image Source Indices Source: https://github.com/prominenceai/deepstream-services-library/blob/master/docs/api-source.md Retrieves the current start and stop index settings for a Multi-Image source. These indices define the range of images to be played within the sequence. The function requires the source name and outputs the start and stop indices. ```C DslReturnType dsl_source_image_multi_indices_get(const wchar_t* name, int* start_index, int* stop_index); ``` ```Python retval, start_index, stop_index = dsl_source_image_multi_indices_get('my-multi-image-source') ``` -------------------------------- ### Upgrade Pip and Setuptools for Azure CLI Source: https://github.com/prominenceai/deepstream-services-library/blob/master/docs/proto-lib-azure.md Upgrades the setuptools package and pip to their latest versions to resolve 'ModuleNotFoundError: No module named 'setuptools_rust'' during the installation of Python packages required by Azure CLI. ```bash sudo apt-get install python3-setuptools sudo pip3 install --upgrade pip ``` -------------------------------- ### Build DSL Test Application Source: https://github.com/prominenceai/deepstream-services-library/blob/master/docs/building-dsl.md Compiles all source code and test scenarios into object files, linking them into the `dsl-test-app` executable using GNU Make. It utilizes parallel execution with `nproc` for faster building. ```bash make -j$(nproc) ``` -------------------------------- ### Start Record Sink Action in Python Source: https://github.com/prominenceai/deepstream-services-library/blob/master/docs/api-ode-action.md Python example for initiating a recording session using the 'Start Record Sink' ODE Action. This function takes the action name, record sink name, start time offset, duration, and client data as arguments. It's used to automate recording based on detected events. ```Python retval = dsl_ode_action_sink_record_start_new('my-start-record-sink-action', 'my-record-sink', 15, 360, Null) ``` -------------------------------- ### ODE Handler Setup Source: https://github.com/prominenceai/deepstream-services-library/blob/master/docs/overview.md Demonstrates how to create and configure a new ODE handler to manage all ODE triggers, along with their associated areas and actions. It also shows how to add this handler to a Tiler component. ```APIDOC ## ODE Handler Setup ### Description Create and configure a new ODE handler to manage all ODE triggers, areas, and actions. This handler is then added to the sink pad of a Tiler component for processing. ### Method ```APIDOC # Create a new ODE handler retval = dsl_pph_ode_new('ode-handler') # Add multiple ODE triggers to the handler retval = dsl_pph_ode_trigger_add_many('ode-handler', triggers=['any-occurrence-trigger', 'person-occurrence-trigger', None]) # Add the ODE handler to the sink pad of a Tiler retval = dsl_tiler_pph_add('tiler', 'ode-handler', DSL_PAD_SINK) ``` ``` -------------------------------- ### Start and Run DeepStream Pipeline Source: https://github.com/prominenceai/deepstream-services-library/blob/master/docs/overview.md Transitions a DeepStream pipeline to the 'PLAYING' state and enters the main loop to process data. Includes error handling for the play command and ensures resources are freed upon exit. ```python retval = dsl_pipeline_play('my-pipeline') if retval != DSL_RESULT_SUCCESS: # Pipeline failed to play, handle error # join the main loop until stopped. dsl_main_loop_run() # free up all resources dsl_delete_all() ``` -------------------------------- ### Get RTSP Connection Data (Python) Source: https://github.com/prominenceai/deepstream-services-library/blob/master/docs/api-source.md Python example demonstrating how to retrieve and display connection statistics for an RTSP source using the dsl_source_rtsp_connection_data_get function. ```python retval, data = dsl_source_rtsp_connection_data_get('rtsp-source') print('Connection data for source:', 'rtsp-source') print(' is connected: ', data.is_connected) print(' first connected: ', time.ctime(data.first_connected)) print(' last connected: ', time.ctime(data.last_connected)) print(' last disconnected:', time.ctime(data.last_disconnected)) print(' total count: ', data.count) print(' in is reconnect: ', data.is_in_reconnect) print(' retries: ', data.retries) print(' sleep time: ', data.sleep,'seconds') print(' timeout: ', data.timeout, 'seconds') ``` -------------------------------- ### Python: File Source, PGIE, DCF Tracker, 2 SGIEs, OSD, Window Sink Source: https://github.com/prominenceai/deepstream-services-library/blob/master/docs/examples-basic-pipelines.md Demonstrates creating a DeepStream pipeline with a file source, primary inference engine (PGIE), DCF tracker, two secondary inference engines (SGIEs), On-Screen Display (OSD), and a window sink. It includes callback registration for key-release, delete-window, EOS, and state-change events. ```python # # The simple example demonstrates how to create a set of Pipeline components, # specifically: # - File Source # - Primary GST Inference Engine (PGIE) # - DCF Tracker # - 2 Secondary GST Inference Engines (SGIEs) # - On-Screen Display (OSD) # - Window Sink # ...and how to add them to a new Pipeline and play # # The example registers handler callback functions with the Pipeline for: # - key-release events # - delete-window events # - end-of-stream EOS events # - Pipeline change-of-state events # ``` -------------------------------- ### Initialize Primary GIE, Tracker, Tiler, ODE Handler, OSD, and Window Sink Source: https://github.com/prominenceai/deepstream-services-library/blob/master/docs/overview.md This code segment initializes several core DeepStream components: a primary inference engine (GIE), an IOU tracker, a tiler, an Object Detection Event (ODE) pad probe handler, an on-screen display (OSD), and an EGL-based window sink. It configures parameters like inference configuration files, tracker dimensions, tiler dimensions, and OSD display settings. Dependencies include dsl_infer_gie_primary_new, dsl_tracker_new, dsl_tiler_new, dsl_pph_ode_new, dsl_tiler_pph_add, dsl_osd_new, and dsl_sink_window_egl_new. ```python ## New Primary GIE using the filespecs above with interval = 4 retval = dsl_infer_gie_primary_new('primary-gie', primary_infer_config_file, primary_model_engine_file, 4) if retval != DSL_RETURN_SUCCESS: break # New IOU Tracker, setting operational width and hieght retval = dsl_tracker_new('iou-tracker', iou_tracker_config_file, 480, 272) if retval != DSL_RETURN_SUCCESS: break # New Tiler, setting width and height, use default cols/rows set by # the number of sources retval = dsl_tiler_new('tiler', TILER_WIDTH, TILER_HEIGHT) if retval != DSL_RETURN_SUCCESS: break # Object Detection Event (ODE) Pad Probe Handler (PPH) to manage our ODE # Triggers with their ODE Actions retval = dsl_pph_ode_new('ode-handler') if (retval != DSL_RETURN_SUCCESS): break # Add our ODE Pad Probe Handler to the Sink pad of the OSD retval = dsl_tiler_pph_add('tiler', handler='ode-handler', pad=DSL_PAD_SINK) if retval != DSL_RETURN_SUCCESS: break # New OSD with text, clock and bbox display all enabled. retval = dsl_osd_new('on-screen-display', text_enabled=True, clock_enabled=False, bbox_enabled=True, mask_enabled=False) if retval != DSL_RETURN_SUCCESS: break # New Window Sink, 0 x/y offsets and dimensions. retval = dsl_sink_window_egl_new('egl-sink', 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT) if retval != DSL_RETURN_SUCCESS: break ``` -------------------------------- ### Get Streammuxer Batch Size - Python Source: https://github.com/prominenceai/deepstream-services-library/blob/master/docs/api-pipeline.md Python example for obtaining the Streammuxer's `batch_size` for a specific pipeline. It returns the status and the current batch size. ```Python retval, batch_size = dsl_pipeline_streammux_batch_size_get('my-pipeline') ``` -------------------------------- ### Pipeline Diagnostics with Source Meter PPH and Queue Management (Python) Source: https://github.com/prominenceai/deepstream-services-library/blob/master/docs/examples-diagnaostics-and-utilities.md Demonstrates using a Source Meter Pad Probe Handler (PPH) to measure pipeline throughput per source and monitor component queue depths. Includes callbacks for handling metrics, pausing/resuming, and queue overrun notifications. ```python # # This example demostrates how to use a Source Meter Pad Probe Handler (PPH) # that will measure the Pipeline's throughput for each Source - while monitoring # the depth of every component's Queue. # # The Meter PPH is added to the sink (input) pad of the Tiler before tha batched # stream is converted into a single stream as a 2D composite of all Sources. # # The "meter_pph_handler" callback added to the Meter PPH will handle writing # the Avg Session FPS and the Avg Interval FPS measurements to the console. # # # The Key-released-handler callback (below) will disable the meter when pausing # the Pipeline, and # re-enable measurements when the Pipeline is resumed. # # Note: Session averages are reset each time the Meter is disabled and # then re-enabled. # # The callback, called once per second as defined during Meter construction, # is also responsible for polling the components for their queue depths - i.e # using the "dsl_component_queue_current_level_print_many" service. # # Additionally, a Queue Overrun Listener is added to each of the components to # be notified on the event of a queue-overrun. # # https://github.com/prominenceai/deepstream-services-library/blob/master/docs/api-component.md#component-queue-management # ``` -------------------------------- ### Get Record Max Size Source: https://github.com/prominenceai/deepstream-services-library/blob/master/docs/api-tap.md Retrieves the maximum recording size in seconds for a named record tap. The 'max_size' parameter must be greater than 'start' + 'duration' when initiating a recording. ```C++ DslReturnType dsl_tap_record_max_size_get(const wchar_t* name, uint* max_size); ``` ```Python retval, max_size = dsl_tap_record_max_size_get('my-record-tap') ``` -------------------------------- ### Create and Configure Branch 3 Source: https://github.com/prominenceai/deepstream-services-library/blob/master/docs/overview.md Demonstrates the creation of a Branch component with a primary Inference Server (PTIS), an NvDCF Tracker, and a secondary Inference Server (STIS). It also shows how to configure the tracker's operational dimensions. ```APIDOC ## Create Inference Branch 3 ### Description Creates a new Branch component named 'my-branch-3' and adds a primary Inference Server ('my-primary-tis-3'), an NvDCF Tracker ('my-dcf-tracker'), and a secondary Inference Server ('my-secondary-tis') to it. ### Method POST (implied by component creation) ### Endpoint N/A (This is a code snippet for library function calls) ### Parameters #### Request Body - **dsl_infer_tis_primary_new**: Creates a primary Inference Server. Requires a name, config file path, and inference interval. - **dsl_tracker_new**: Creates a tracker. Requires a name, config file path, and operational width/height (multiples of 32). - **dsl_infer_tis_secondary_new**: Creates a secondary Inference Server. Requires a name, config file path, the name of the primary TIS it depends on, and an inference interval. - **dsl_branch_new_component_add_many**: Creates a new Branch component and adds specified components to it. Requires branch name and a list of component names (ending with None). ### Request Example ```python # Create the third PTIS using the third model with an interval of 4 retval = dsl_infer_tis_primary_new('my-primary-tis-3', primary_tis_config_file_3, 4) # New NvDCF Tracker, setting operational width and height # NOTE: width and height paramaters must be multiples of 32 for dcf retval = dsl_tracker_new('my-dcf-tracker', dcf_tracker_config_file, 640, 384) # Create the STIS , with interval = 0 retval = dsl_infer_tis_secondary_new('my-secondary-tis', secondary_infer_config_file, 'my-primary-tis-3', 0) # Create a new Branch Component and add the PTIS, Tracker, and STIS to it. retval = dsl_branch_new_component_add_many('my-branch-3', ['my-primary-tis-3', 'my-dcf-tracker', 'my-secondary-tis', None]) ``` ### Response #### Success Response (200) - **retval** (integer) - Indicates success or failure of the operation. #### Response Example ```json { "retval": 0 } ``` ``` -------------------------------- ### Get Record Sink Cache Size Source: https://github.com/prominenceai/deepstream-services-library/blob/master/docs/api-sink.md Retrieves the video recording cache size, in seconds, for a specified Record Sink. The cache size must be greater than the recording start time. ```C++ DslReturnType dsl_sink_record_cache_size_get(const wchar_t* name, uint* cache_size); ``` ```Python retval, cache_size = dsl_sink_record_cache_size_get('my-record-sink') ``` -------------------------------- ### DeepStream Smart Record Tap Examples Source: https://github.com/prominenceai/deepstream-services-library/blob/master/Release Notes/v0.31.alpha.md Python and C++ examples for the smart record tap, enabling recording sessions triggered by ODE events or user commands. ```python import sys from dsl import * def main(args): error = dsl_dir_init() if error != DSL_SUCCESS: return error # Define GStreamer pipeline components source = "uri=./video/streams/sample_720p.h264" demuxer = "name=demuxer" pgie = "name=primary-gie" tracker = "name=tracker" nvds_osd = "name=nvds_osd" tap = "name=tap" encoder = "name=encoder ! nvv4l2decoder ! nvv4l2h264enc bitrate=4000000 ! h264parse ! rtph264pay config-interval=1 pt=96" rtsp_sink = "name=rtsp_sink " # Create GStreamer pipeline components error = dsl_source_file_new('source', source) error = dsl_demuxer_new('demuxer', demuxer) error = dsl_inference_gie_new('primary-gie', pgie) error = dsl_tracker_new('tracker', tracker) error = dsl_osd_new('osd', nvds_osd) error = dsl_tap_new('tap', tap) error = dsl_encoder_new('encoder', encoder) error = dsl_sink_rtsp_server_new('rtsp-server', rtsp_sink, 8554, "/stream") # Add components to the pipeline error = dsl_pipeline_component_add_many(pipeline, ['source', 'demuxer', 'primary-gie', 'tracker', 'osd', 'tap', 'encoder', 'rtsp-server']) # Start the pipeline error = dsl_pipeline_play(pipeline) # Wait for termination signal dsl_main_loop_run() # Cleanup dsl_pipeline_stop(pipeline) dsl_pipeline_delete(pipeline) dsl_source_delete('source') dsl_demuxer_delete('demuxer') dsl_inference_gie_delete('primary-gie') dsl_tracker_delete('tracker') dsl_osd_delete('osd') dsl_tap_delete('tap') dsl_encoder_delete('encoder') dsl_sink_delete('rtsp-server') dsl_dir_cleanup() return error if __name__ == '__main__': sys.exit(main(sys.argv)) ``` ```cpp #include "dsl.h" #include "dsros.h" #include #include using std::string; int main(int argc, char** argv) { int ret = DSL_SUCCESS; // Create a smart record tap uint64_t record_tap_id = 0; ret = dsl_tap_record_new( "record-tap", // Name of the tap "container=1", // Container format (e.g., MP4, MKV) &record_tap_id ); if (ret != DSL_SUCCESS) { printf("Failed to create record tap\n"); return ret; } // Start a recording session on ODE occurrence uint64_t session_id_ode = 0; ret = dsl_tap_record_session_start_on_ode_occurrence( record_tap_id, // ID of the record tap "ODECallback", // Name of the ODE callback function "output/ode_tap_recording.mp4", // Output file path &session_id_ode ); if (ret != DSL_SUCCESS) { printf("Failed to start record session on ODE occurrence\n"); return ret; } // Start a recording session on user demand uint64_t session_id_user = 0; ret = dsl_tap_record_session_start_on_user_demand( record_tap_id, // ID of the record tap "output/user_tap_recording.mp4", // Output file path &session_id_user ); if (ret != DSL_SUCCESS) { printf("Failed to start record session on user demand\n"); return ret; } // Add the record tap to a pipeline (assuming pipeline is already created) // ret = dsl_pipeline_component_add(pipeline_id, record_tap_id); // ... pipeline setup and execution ... // Stop recording sessions (example) // ret = dsl_tap_record_session_stop(session_id_ode); // ret = dsl_tap_record_session_stop(session_id_user); // Cleanup // dsl_tap_record_delete(record_tap_id); return ret; } ```