Commit 24460ef5 authored by das-qa's avatar das-qa
Browse files

Add python demo: deepstream-test1, deepstream-test2, deepstream-test3 and deepstream-test4

parent 77e9fc8c
/*
* SPDX-FileCopyrightText: Copyright (c) 2018-2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* SPDX-License-Identifier: LicenseRef-NvidiaProprietary
*
* NVIDIA CORPORATION, its affiliates and licensors retain all intellectual
* property and proprietary rights in and to this material, related
* documentation and any modifications thereto. Any use, reproduction,
* disclosure or distribution of this material and related documentation
* without an express license agreement from NVIDIA CORPORATION or
* its affiliates is strictly prohibited.
*/
#ifndef __NVGSTDS_SINKS_H__
#define __NVGSTDS_SINKS_H__
#ifdef __aarch64__
#define IS_TEGRA
#endif
#include <gst/gst.h>
#ifdef __cplusplus
extern "C"
{
#endif
typedef enum
{
NV_DS_SINK_FAKE = 1,
#ifndef IS_TEGRA
NV_DS_SINK_RENDER_EGL,
#else
NV_DS_SINK_RENDER_3D,
#endif
NV_DS_SINK_ENCODE_FILE,
NV_DS_SINK_UDPSINK,
NV_DS_SINK_RENDER_DRM,
NV_DS_SINK_MSG_CONV_BROKER,
} NvDsSinkType;
typedef enum
{
NV_DS_CONTAINER_MP4 = 1,
NV_DS_CONTAINER_MKV
} NvDsContainerType;
typedef enum
{
NV_DS_ENCODER_H264 = 1,
NV_DS_ENCODER_H265,
NV_DS_ENCODER_MPEG4
} NvDsEncoderType;
typedef enum
{
NV_DS_ENCODER_TYPE_HW,
NV_DS_ENCODER_TYPE_SW
} NvDsEncHwSwType;
typedef enum
{
NV_DS_ENCODER_OUTPUT_IO_MODE_MMAP = 2,
NV_DS_ENCODER_OUTPUT_IO_MODE_DMABUF_IMPORT = 5,
}NvDsEncOutputIOMode;
typedef struct
{
NvDsSinkType type;
NvDsContainerType container;
NvDsEncoderType codec;
NvDsEncHwSwType enc_type;
guint compute_hw;
gint bitrate;
guint profile;
gint sync;
gchar *output_file_path;
guint gpu_id;
guint rtsp_port;
guint udp_port;
guint64 udp_buffer_size;
guint iframeinterval;
guint copy_meta;
NvDsEncOutputIOMode output_io_mode;
gint sw_preset;
} NvDsSinkEncoderConfig;
typedef struct
{
NvDsSinkType type;
gint width;
gint height;
gint sync;
gboolean qos;
gboolean qos_value_specified;
guint gpu_id;
guint nvbuf_memory_type;
guint offset_x;
guint offset_y;
guint color_range;
guint conn_id;
guint plane_id;
gboolean set_mode;
} NvDsSinkRenderConfig;
typedef struct
{
gboolean enable;
/** MsgConv settings */
gchar* config_file_path;
guint conv_payload_type;
gchar* conv_msg2p_lib;
guint conv_comp_id;
gchar* debug_payload_dir;
gboolean multiple_payloads;
gboolean conv_msg2p_new_api;
guint conv_frame_interval;
gboolean conv_dummy_payload;
/** Broker settings */
gchar* proto_lib;
gchar* conn_str;
gchar* topic;
gchar* broker_config_file_path;
guint broker_comp_id;
gboolean disable_msgconv;
gint sync;
gboolean new_api;
guint broker_sleep_time;
} NvDsSinkMsgConvBrokerConfig;
typedef struct
{
gboolean enable;
guint source_id;
gboolean link_to_demux;
NvDsSinkType type;
gint sync;
NvDsSinkEncoderConfig encoder_config;
NvDsSinkRenderConfig render_config;
NvDsSinkMsgConvBrokerConfig msg_conv_broker_config;
} NvDsSinkSubBinConfig;
typedef struct
{
GstElement *bin;
GstElement *queue;
GstElement *transform;
GstElement *cap_filter;
GstElement *enc_caps_filter;
GstElement *encoder;
GstElement *codecparse;
GstElement *mux;
GstElement *sink;
GstElement *rtppay;
gulong sink_buffer_probe;
} NvDsSinkBinSubBin;
typedef struct
{
GstElement *bin;
GstElement *queue;
GstElement *tee;
gint num_bins;
NvDsSinkBinSubBin sub_bins[MAX_SINK_BINS];
} NvDsSinkBin;
/**
* Initialize @ref NvDsSinkBin. It creates and adds sink and
* other elements needed for processing to the bin.
* It also sets properties mentioned in the configuration file under
* group @ref CONFIG_GROUP_SINK
*
* @param[in] num_sub_bins number of sink elements.
* @param[in] config_array array of pointers of type @ref NvDsSinkSubBinConfig
* parsed from configuration file.
* @param[in] bin pointer to @ref NvDsSinkBin to be filled.
* @param[in] index id of source element.
*
* @return true if bin created successfully.
*/
gboolean create_sink_bin (guint num_sub_bins,
NvDsSinkSubBinConfig *config_array, NvDsSinkBin *bin, guint index);
void destroy_sink_bin (void);
gboolean create_demux_sink_bin (guint num_sub_bins,
NvDsSinkSubBinConfig *config_array, NvDsSinkBin *bin, guint index);
void set_rtsp_udp_port_num (guint rtsp_port_num, guint udp_port_num);
#ifdef __cplusplus
}
#endif
#endif
/*
* SPDX-FileCopyrightText: Copyright (c) 2018-2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* SPDX-License-Identifier: LicenseRef-NvidiaProprietary
*
* NVIDIA CORPORATION, its affiliates and licensors retain all intellectual
* property and proprietary rights in and to this material, related
* documentation and any modifications thereto. Any use, reproduction,
* disclosure or distribution of this material and related documentation
* without an express license agreement from NVIDIA CORPORATION or
* its affiliates is strictly prohibited.
*/
#ifndef __NVGSTDS_SOURCES_H__
#define __NVGSTDS_SOURCES_H__
#include <gst/gst.h>
#include "deepstream_dewarper.h"
#include <sys/time.h>
#ifdef __cplusplus
extern "C"
{
#endif
typedef enum
{
NV_DS_SOURCE_CAMERA_V4L2 = 1,
NV_DS_SOURCE_URI,
NV_DS_SOURCE_URI_MULTIPLE,
NV_DS_SOURCE_RTSP,
NV_DS_SOURCE_CAMERA_CSI,
NV_DS_SOURCE_AUDIO_WAV,
NV_DS_SOURCE_AUDIO_URI,
NV_DS_SOURCE_ALSA_SRC,
NV_DS_SOURCE_IPC,
} NvDsSourceType;
typedef struct
{
NvDsSourceType type;
gboolean enable;
gboolean loop;
gboolean live_source;
gboolean Intra_decode;
gboolean low_latency_mode;
guint smart_record;
gint source_width;
gint source_height;
gint source_fps_n;
gint source_fps_d;
gint camera_csi_sensor_id;
gint camera_v4l2_dev_node;
gchar *uri;
gchar *dir_path;
gchar *file_prefix;
gint latency;
guint smart_rec_cache_size;
guint smart_rec_container;
guint smart_rec_def_duration;
guint smart_rec_duration;
guint smart_rec_start_time;
guint smart_rec_interval;
guint num_sources;
guint gpu_id;
guint camera_id;
guint source_id;
guint select_rtp_protocol;
guint num_decode_surfaces;
guint num_extra_surfaces;
guint nvbuf_memory_type;
guint cuda_memory_type;
#if defined(__aarch64__) && !defined(AARCH64_IS_SBSA)
/* copy-hw as VIC applicable only for Jetson */
guint nvvideoconvert_copy_hw;
#endif
NvDsDewarperConfig dewarper_config;
guint drop_frame_interval;
gboolean extract_sei_type5_data;
gint rtsp_reconnect_interval_sec;
guint rtsp_reconnect_attempts;
gboolean rtsp_reconnect_attempt_exceeded;
guint udp_buffer_size;
/** Desired input audio rate to nvinferaudio from PGIE config;
* This config shall be copied over from NvDsGieConfig
* at create_multi_source_bin()*/
guint input_audio_rate;
/** ALSA device, as defined in an asound configuration file */
gchar* alsa_device;
/** Video format to be applied at nvvideoconvert source pad. */
gchar* video_format;
} NvDsSourceConfig;
typedef struct NvDsSrcParentBin NvDsSrcParentBin;
typedef struct
{
GstElement *bin;
GstElement *src_elem;
GstElement *cap_filter;
GstElement *cap_filter1;
GstElement *depay;
GstElement *parser;
GstElement *enc_que;
GstElement *dec_que;
GstElement *decodebin;
GstElement *enc_filter;
GstElement *encbin_que;
GstElement *tee;
GstElement *tee_rtsp_pre_decode;
GstElement *tee_rtsp_post_decode;
GstElement *fakesink_queue;
GstElement *fakesink;
GstElement *nvvidconv;
GstElement *audio_converter;
GstElement *audio_resample;
gboolean do_record;
guint64 pre_event_rec;
GMutex bin_lock;
guint bin_id;
gint rtsp_reconnect_interval_sec;
gint rtsp_reconnect_attempts;
gint num_rtsp_reconnects;
gboolean have_eos;
struct timeval last_buffer_time;
struct timeval last_reconnect_time;
gulong src_buffer_probe;
gulong rtspsrc_monitor_probe;
gpointer bbox_meta;
GstBuffer *inbuf;
gchar *location;
gchar *file;
gchar *direction;
gint latency;
guint udp_buffer_size;
gboolean got_key_frame;
gboolean eos_done;
gboolean reset_done;
gboolean live_source;
gboolean reconfiguring;
gboolean async_state_watch_running;
NvDsDewarperBin dewarper_bin;
gulong probe_id;
guint64 accumulated_base;
guint64 prev_accumulated_base;
guint source_id;
NvDsSourceConfig *config;
NvDsSrcParentBin *parent_bin;
gpointer recordCtx;
} NvDsSrcBin;
struct NvDsSrcParentBin
{
GstElement *bin;
GstElement *streammux;
GstElement *nvmultiurisrcbin;
GThread *reset_thread;
NvDsSrcBin sub_bins[MAX_SOURCE_BINS];
guint num_bins;
guint num_fr_on;
gboolean live_source;
gulong nvstreammux_eosmonitor_probe;
};
gboolean create_source_bin (NvDsSourceConfig *config, NvDsSrcBin *bin);
gboolean create_audio_source_bin (NvDsSourceConfig *config, NvDsSrcBin *bin);
/**
* Initialize @ref NvDsSrcParentBin. It creates and adds source and
* other elements needed for processing to the bin.
* It also sets properties mentioned in the configuration file under
* group @ref CONFIG_GROUP_SOURCE
*
* @param[in] num_sub_bins number of source elements.
* @param[in] configs array of pointers of type @ref NvDsSourceConfig
* parsed from configuration file.
* @param[in] bin pointer to @ref NvDsSrcParentBin to be filled.
*
* @return true if bin created successfully.
*/
gboolean
create_multi_source_bin (guint num_sub_bins, NvDsSourceConfig *configs,
NvDsSrcParentBin *bin);
/**
* Initialize @ref NvDsSrcParentBin. It creates and adds nvmultiurisrcbin
* needed for processing to the bin.
* It also sets properties mentioned in the configuration file under
* group @ref CONFIG_GROUP_SOURCE_LIST, @ref CONFIG_GROUP_SOURCE_ALL
*
* @param[in] num_sub_bins number of source elements.
* @param[in] configs array of pointers of type @ref NvDsSourceConfig
* parsed from configuration file.
* @param[in] bin pointer to @ref NvDsSrcParentBin to be filled.
*
* @return true if bin created successfully.
*/
gboolean
create_nvmultiurisrcbin_bin (guint num_sub_bins, NvDsSourceConfig *configs,
NvDsSrcParentBin *bin);
gboolean reset_source_pipeline (gpointer data);
gboolean set_source_to_playing (gpointer data);
gpointer reset_encodebin (gpointer data);
void destroy_smart_record_bin (gpointer data);
#ifdef __cplusplus
}
#endif
#endif
/*
* SPDX-FileCopyrightText: Copyright (c) 2018-2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* SPDX-License-Identifier: LicenseRef-NvidiaProprietary
*
* NVIDIA CORPORATION, its affiliates and licensors retain all intellectual
* property and proprietary rights in and to this material, related
* documentation and any modifications thereto. Any use, reproduction,
* disclosure or distribution of this material and related documentation
* without an express license agreement from NVIDIA CORPORATION or
* its affiliates is strictly prohibited.
*/
#ifndef _NVGSTDS_STREAMMUX_H_
#define _NVGSTDS_STREAMMUX_H_
#include <gst/gst.h>
#ifdef __cplusplus
extern "C"
{
#endif
typedef struct
{
// Struct members to store config / properties for the element
gint pipeline_width;
gint pipeline_height;
gint buffer_pool_size;
gint batch_size;
gint batched_push_timeout;
gint compute_hw;
gint num_surface_per_frame;
gint interpolation_method;
guint64 frame_duration;
guint gpu_id;
guint nvbuf_memory_type;
gboolean live_source;
gboolean enable_padding;
gboolean is_parsed;
gboolean attach_sys_ts_as_ntp;
gchar* config_file_path;
gboolean sync_inputs;
guint64 max_latency;
gboolean frame_num_reset_on_eos;
gboolean frame_num_reset_on_stream_reset;
gboolean async_process;
gboolean no_pipeline_eos;
gboolean use_nvmultiurisrcbin;
gboolean extract_sei_type5_data;
} NvDsStreammuxConfig;
// Function to create the bin and set properties
gboolean
set_streammux_properties (NvDsStreammuxConfig *config, GstElement *streammux);
#ifdef __cplusplus
}
#endif
#endif /* _NVGSTDS_DSEXAMPLE_H_ */
/*
* SPDX-FileCopyrightText: Copyright (c) 2018-2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* SPDX-License-Identifier: LicenseRef-NvidiaProprietary
*
* NVIDIA CORPORATION, its affiliates and licensors retain all intellectual
* property and proprietary rights in and to this material, related
* documentation and any modifications thereto. Any use, reproduction,
* disclosure or distribution of this material and related documentation
* without an express license agreement from NVIDIA CORPORATION or
* its affiliates is strictly prohibited.
*/
#ifndef __NVGSTDS_TILED_DISPLAY_H__
#define __NVGSTDS_TILED_DISPLAY_H__
#include <gst/gst.h>
#include "nvll_osd_struct.h"
#ifdef __cplusplus
extern "C"
{
#endif
typedef struct
{
GstElement *bin;
GstElement *queue;
GstElement *tiler;
} NvDsTiledDisplayBin;
typedef enum
{
NV_DS_TILED_DISPLAY_DISABLE = 0,
NV_DS_TILED_DISPLAY_ENABLE = 1,
/** When user sets tiler group enable=2,
* all sinks with the key: link-only-to-demux=1
* shall be linked to demuxer's src_[source_id] pad
* where source_id is the key set in this
* corresponding [sink] group
*/
NV_DS_TILED_DISPLAY_ENABLE_WITH_PARALLEL_DEMUX = 2
} NvDsTiledDisplayEnable;
typedef struct
{
NvDsTiledDisplayEnable enable;
guint rows;
guint columns;
guint width;
guint height;
guint gpu_id;
guint nvbuf_memory_type;
/**Compute Scaling HW to use
* Applicable only for Jetson; x86 uses GPU by default
* (0): Default - Default, GPU for Tesla, VIC for Jetson
* (1): GPU - GPU
* (2): VIC - VIC
* */
guint compute_hw;
guint buffer_pool_size;
guint square_seq_grid;
} NvDsTiledDisplayConfig;
/**
* Initialize @ref NvDsTiledDisplayBin. It creates and adds tiling and
* other elements needed for processing to the bin.
* It also sets properties mentioned in the configuration file under
* group @ref CONFIG_GROUP_TILED_DISPLAY
*
* @param[in] config pointer of type @ref NvDsTiledDisplayConfig
* parsed from configuration file.
* @param[in] bin pointer to @ref NvDsTiledDisplayBin to be filled.
*
* @return true if bin created successfully.
*/
gboolean
create_tiled_display_bin (NvDsTiledDisplayConfig * config,
NvDsTiledDisplayBin * bin);
#ifdef __cplusplus
}
#endif
#endif
/*
* SPDX-FileCopyrightText: Copyright (c) 2018-2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* SPDX-License-Identifier: LicenseRef-NvidiaProprietary
*
* NVIDIA CORPORATION, its affiliates and licensors retain all intellectual
* property and proprietary rights in and to this material, related
* documentation and any modifications thereto. Any use, reproduction,
* disclosure or distribution of this material and related documentation
* without an express license agreement from NVIDIA CORPORATION or
* its affiliates is strictly prohibited.
*/
#ifndef __NVGSTDS_TRACKER_H__
#define __NVGSTDS_TRACKER_H__
#include <gst/gst.h>
#include <stdint.h>
#include "nvds_tracker_meta.h"
#ifdef __cplusplus
extern "C"
{
#endif
typedef struct
{
gboolean enable;
gint width;
gint height;
guint gpu_id;
guint tracking_surf_type;
gchar* ll_config_file;
gchar* ll_lib_file;
guint tracking_surface_type;
gboolean display_tracking_id;
guint tracking_id_reset_mode;
gboolean input_tensor_meta;
guint input_tensor_gie_id;
guint compute_hw;
guint user_meta_pool_size;
gchar* sub_batches;
gint sub_batch_err_recovery_trial_cnt;
} NvDsTrackerConfig;
typedef struct
{
GstElement *bin;
GstElement *tracker;
} NvDsTrackerBin;
typedef uint64_t NvDsTrackerStreamId;
/**
* Initialize @ref NvDsTrackerBin. It creates and adds tracker and
* other elements needed for processing to the bin.
* It also sets properties mentioned in the configuration file under
* group @ref CONFIG_GROUP_TRACKER
*
* @param[in] config pointer of type @ref NvDsTrackerConfig
* parsed from configuration file.
* @param[in] bin pointer of type @ref NvDsTrackerBin to be filled.
*
* @return true if bin created successfully.
*/
gboolean
create_tracking_bin (NvDsTrackerConfig * config, NvDsTrackerBin * bin);
#ifdef __cplusplus
}
#endif
#endif
/*
* SPDX-FileCopyrightText: Copyright (c) 2022-2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* SPDX-License-Identifier: LicenseRef-NvidiaProprietary
*
* NVIDIA CORPORATION, its affiliates and licensors retain all intellectual
* property and proprietary rights in and to this material, related
* documentation and any modifications thereto. Any use, reproduction,
* disclosure or distribution of this material and related documentation
* without an express license agreement from NVIDIA CORPORATION or
* its affiliates is strictly prohibited.
*/
#include "deepstream_common.h"
#include "deepstream_config_yaml.h"
#include <string>
#include <cstring>
#include <iostream>
#define _PATH_MAX 1024
/* Separate a config file entry with delimiters
* into strings. */
std::vector<std::string> split_string (std::string input) {
std::vector<int> positions;
for (unsigned int i = 0; i < input.size(); i++) {
if (input[i] == ';')
positions.push_back(i);
}
std::vector<std::string> ret;
int prev = 0;
for (auto &j: positions) {
std::string temp = input.substr(prev, j - prev);
ret.push_back(temp);
prev = j + 1;
}
ret.push_back(input.substr(prev, input.size() - prev));
return ret;
}
/* Get the absolute path of a file mentioned in the config given a
* file path absolute/relative to the config file. */
gboolean
get_absolute_file_path_yaml (
const gchar * cfg_file_path, const gchar * file_path,
char *abs_path_str)
{
gchar abs_cfg_path[PATH_MAX + 1];
gchar abs_real_file_path[PATH_MAX + 1];
gchar *abs_file_path;
gchar *delim;
/* Absolute path. No need to resolve further. */
if (file_path[0] == '/') {
/* Check if the file exists, return error if not. */
if (!realpath (file_path, abs_real_file_path)) {
/* Ignore error if file does not exist and use the unresolved path. */
if (errno != ENOENT)
return FALSE;
}
g_strlcpy (abs_path_str, abs_real_file_path, _PATH_MAX);
return TRUE;
}
/* Get the absolute path of the config file. */
if (!realpath (cfg_file_path, abs_cfg_path)) {
return FALSE;
}
/* Remove the file name from the absolute path to get the directory of the
* config file. */
delim = g_strrstr (abs_cfg_path, "/");
*(delim + 1) = '\0';
/* Get the absolute file path from the config file's directory path and
* relative file path. */
abs_file_path = g_strconcat (abs_cfg_path, file_path, nullptr);
/* Resolve the path.*/
if (realpath (abs_file_path, abs_real_file_path) == nullptr) {
/* Ignore error if file does not exist and use the unresolved path. */
if (errno == ENOENT)
g_strlcpy (abs_real_file_path, abs_file_path, _PATH_MAX);
else {
if (abs_file_path)
g_free (abs_file_path);
return FALSE;
}
}
g_free (abs_file_path);
g_strlcpy (abs_path_str, abs_real_file_path, _PATH_MAX);
return TRUE;
}
/*
* SPDX-FileCopyrightText: Copyright (c) 2022-2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* SPDX-License-Identifier: LicenseRef-NvidiaProprietary
*
* NVIDIA CORPORATION, its affiliates and licensors retain all intellectual
* property and proprietary rights in and to this material, related
* documentation and any modifications thereto. Any use, reproduction,
* disclosure or distribution of this material and related documentation
* without an express license agreement from NVIDIA CORPORATION or
* its affiliates is strictly prohibited.
*/
#include "deepstream_common.h"
#include "deepstream_config_yaml.h"
#include <string>
#include <cstring>
#include <iostream>
using std::cout;
using std::endl;
gboolean
parse_dewarper_yaml (NvDsDewarperConfig * config, std::string group_str, gchar *cfg_file_path)
{
gboolean ret = FALSE;
YAML::Node configyml = YAML::LoadFile(cfg_file_path);
for(YAML::const_iterator itr = configyml[group_str].begin();
itr != configyml[group_str].end(); ++itr)
{
std::string paramKey = itr->first.as<std::string>();
if (paramKey == "enable") {
config->enable = itr->second.as<gboolean>();
} else if (paramKey == "gpu-id") {
config->gpu_id = itr->second.as<guint>();
} else if (paramKey == "source-id") {
config->source_id = itr->second.as<guint>();
} else if (paramKey == "num-output-buffers") {
config->num_out_buffers = itr->second.as<guint>();
} else if (paramKey == "num-batch-buffers") {
config->num_batch_buffers = itr->second.as<guint>();
} else if (paramKey == "config-file") {
std::string temp = itr->second.as<std::string>();
char* str = (char*) malloc(sizeof(char) * 1024);
std::strncpy (str, temp.c_str(), 1023);
config->config_file = (char*) malloc(sizeof(char) * 1024);
if (!get_absolute_file_path_yaml (cfg_file_path, str,
config->config_file)) {
g_printerr ("Error: Could not parse config-file in dewarper.\n");
g_free (str);
goto done;
}
g_free (str);
} else if (paramKey == "nvbuf-memory-type") {
config->nvbuf_memory_type = itr->second.as<guint>();
} else if (paramKey == "num-surfaces-per-frame") {
config->num_surfaces_per_frame = itr->second.as<guint>();
} else {
cout << "[WARNING] Unknown param found in dewarper: " << paramKey << endl;
}
}
ret = TRUE;
done:
if (!ret) {
cout << __func__ << " failed" << endl;
}
return ret;
}
/*
* SPDX-FileCopyrightText: Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* SPDX-License-Identifier: LicenseRef-NvidiaProprietary
*
* NVIDIA CORPORATION, its affiliates and licensors retain all intellectual
* property and proprietary rights in and to this material, related
* documentation and any modifications thereto. Any use, reproduction,
* disclosure or distribution of this material and related documentation
* without an express license agreement from NVIDIA CORPORATION or
* its affiliates is strictly prohibited.
*/
#include "deepstream_common.h"
#include "deepstream_config_yaml.h"
#include <string>
#include <cstring>
#include <iostream>
using std::cout;
using std::endl;
gboolean
parse_dsanalytics_yaml (NvDsDsAnalyticsConfig *config, gchar* cfg_file_path)
{
gboolean ret = FALSE;
YAML::Node configyml = YAML::LoadFile(cfg_file_path);
for(YAML::const_iterator itr = configyml["nvds-analytics"].begin();
itr != configyml["nvds-analytics"].end(); ++itr)
{
std::string paramKey = itr->first.as<std::string>();
if (paramKey == "enable") {
config->enable = itr->second.as<gboolean>();
} else if (paramKey == "config-file") {
std::string temp = itr->second.as<std::string>();
char* str = (char*) malloc(sizeof(char) * 1024);
std::strncpy (str, temp.c_str(), 1023);
config->config_file_path = (char*) malloc(sizeof(char) * 1024);
if (!get_absolute_file_path_yaml (cfg_file_path, str,
config->config_file_path)) {
g_printerr ("Error: Could not parse config-file in dsanalytics.\n");
g_free (str);
goto done;
}
g_free (str);
} else {
cout << "[WARNING] Unknown param found in nvds-analytics: " << paramKey << endl;
}
}
ret = TRUE;
done:
if (!ret) {
cout << __func__ << " failed" << endl;
}
return ret;
}
\ No newline at end of file
/*
* SPDX-FileCopyrightText: Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* SPDX-License-Identifier: LicenseRef-NvidiaProprietary
*
* NVIDIA CORPORATION, its affiliates and licensors retain all intellectual
* property and proprietary rights in and to this material, related
* documentation and any modifications thereto. Any use, reproduction,
* disclosure or distribution of this material and related documentation
* without an express license agreement from NVIDIA CORPORATION or
* its affiliates is strictly prohibited.
*/
#include "deepstream_common.h"
#include "deepstream_config_yaml.h"
#include <string>
#include <cstring>
#include <iostream>
using std::cout;
using std::endl;
gboolean
parse_dsexample_yaml (NvDsDsExampleConfig *config, gchar *cfg_file_path)
{
gboolean ret = FALSE;
YAML::Node configyml = YAML::LoadFile(cfg_file_path);
for(YAML::const_iterator itr = configyml["ds-example"].begin();
itr != configyml["ds-example"].end(); ++itr)
{
std::string paramKey = itr->first.as<std::string>();
if (paramKey == "enable") {
config->enable = itr->second.as<gboolean>();
} else if (paramKey == "full-frame") {
config->full_frame = itr->second.as<gboolean>();
} else if (paramKey == "processing-width") {
config->processing_width = itr->second.as<gint>();
} else if (paramKey == "processing-height") {
config->processing_height = itr->second.as<gint>();
} else if (paramKey == "blur-objects") {
config->blur_objects = itr->second.as<gboolean>();
} else if (paramKey == "unique-id") {
config->unique_id = itr->second.as<guint>();
} else if (paramKey == "gpu-id") {
config->gpu_id = itr->second.as<guint>();
} else if (paramKey == "nvbuf-memory-type") {
config->nvbuf_memory_type = itr->second.as<guint>();
} else {
cout << "[WARNING] Unknown param found in dsexample: " << paramKey << endl;
}
}
ret = TRUE;
if (!ret) {
cout << __func__ << " failed" << endl;
}
return ret;
}
\ No newline at end of file
/*
* SPDX-FileCopyrightText: Copyright (c) 2022-2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* SPDX-License-Identifier: LicenseRef-NvidiaProprietary
*
* NVIDIA CORPORATION, its affiliates and licensors retain all intellectual
* property and proprietary rights in and to this material, related
* documentation and any modifications thereto. Any use, reproduction,
* disclosure or distribution of this material and related documentation
* without an express license agreement from NVIDIA CORPORATION or
* its affiliates is strictly prohibited.
*/
#include "deepstream_common.h"
#include "deepstream_config_file_parser.h"
#include "deepstream_config_yaml.h"
#include <string>
#include <cstring>
#include <iostream>
using std::cout;
using std::endl;
gboolean
parse_gie_yaml (NvDsGieConfig *config, std::string group_str, gchar *cfg_file_path)
{
gboolean ret = FALSE;
YAML::Node configyml = YAML::LoadFile(cfg_file_path);
char *group = (char*) malloc(sizeof(char) * 1024);
std::strncpy (group, group_str.c_str(), 1023);
if (configyml[group_str]["enable"]) {
gboolean val = configyml[group_str]["enable"].as<gboolean>();
if(val == FALSE)
return TRUE;
}
config->bbox_border_color_table = g_hash_table_new (NULL, NULL);
config->bbox_bg_color_table = g_hash_table_new (NULL, NULL);
config->bbox_border_color = (NvOSD_ColorParams) {1, 0, 0, 1};
std::string border_str = "bbox-border-color";
std::string bg_str = "bbox-bg-color";
for(YAML::const_iterator itr = configyml[group_str].begin();
itr != configyml[group_str].end(); ++itr)
{
std::string paramKey = itr->first.as<std::string>();
if (paramKey == "enable") {
config->enable = itr->second.as<gboolean>();
} else if (paramKey == "input-tensor-meta") {
config->input_tensor_meta = itr->second.as<gboolean>();
} else if (paramKey == "operate-on-class-ids") {
std::string str = itr->second.as<std::string>();
std::vector<std::string> vec = split_string (str);
int length = vec.size();
int *arr = (int *) malloc(length * sizeof(int));
for (unsigned int i = 0; i < vec.size(); i++) {
arr[i] = std::stoi(vec[i]);
}
config->list_operate_on_class_ids = arr;
config->num_operate_on_class_ids = length;
} else if (paramKey == "batch-size") {
config->batch_size = itr->second.as<guint>();
config->is_batch_size_set = TRUE;
} else if (paramKey == "model-engine-file") {
std::string temp = itr->second.as<std::string>();
char* str = (char*) malloc(sizeof(char) * 1024);
std::strncpy (str, temp.c_str(), 1023);
config->model_engine_file_path = (char*) malloc(sizeof(char) * 1024);
if (!get_absolute_file_path_yaml (cfg_file_path, str,
config->model_engine_file_path)) {
g_printerr ("Error: Could not parse model-engine-file in %s.\n", group);
g_free (str);
goto done;
}
g_free (str);
} else if (paramKey == "plugin-type") {
config->plugin_type = (NvDsGiePluginType) itr->second.as<guint>();
} else if (paramKey == "audio-transform") {
std::string temp = itr->second.as<std::string>();
config->audio_transform = (char*) malloc(sizeof(char) * 1024);
std::strncpy (config->audio_transform, temp.c_str(), 1023);
} else if (paramKey == "audio-framesize") {
config->frame_size = itr->second.as<guint>();
config->is_frame_size_set = TRUE;
} else if (paramKey == "audio-hopsize") {
config->hop_size = itr->second.as<guint>();
config->is_hop_size_set = TRUE;
} else if (paramKey == "audio-input-rate") {
config->input_audio_rate = itr->second.as<guint>();
config->is_hop_size_set = TRUE;
} else if (paramKey == "labelfile-path") {
std::string temp = itr->second.as<std::string>();
char* str = (char*) malloc(sizeof(char) * 1024);
std::strncpy (str, temp.c_str(), 1023);
config->label_file_path = (char*) malloc(sizeof(char) * 1024);
if (!get_absolute_file_path_yaml (cfg_file_path, str,
config->label_file_path)) {
g_printerr ("Error: Could not parse labelfile-path in %s.\n", group);
g_free (str);
goto done;
}
g_free (str);
} else if (paramKey == "config-file") {
std::string temp = itr->second.as<std::string>();
char* str = (char*) malloc(sizeof(char) * 1024);
std::strncpy (str, temp.c_str(), 1023);
config->config_file_path = (char*) malloc(sizeof(char) * 1024);
if (!get_absolute_file_path_yaml (cfg_file_path, str,
config->config_file_path)) {
g_printerr ("Error: Could not parse config-file in %s.\n", group);
g_free (str);
goto done;
}
g_free (str);
} else if (paramKey == "interval") {
config->interval = itr->second.as<guint>();
config->is_interval_set = TRUE;
} else if (paramKey == "gie-unique-id") {
config->unique_id = itr->second.as<guint>();
config->is_unique_id_set = TRUE;
} else if (paramKey == "operate-on-gie-id") {
config->operate_on_gie_id = itr->second.as<gint>();
config->is_operate_on_gie_id_set = TRUE;
} else if (paramKey.compare(0, border_str.size(), border_str) == 0) {
NvOSD_ColorParams *clr_params;
std::string str = itr->second.as<std::string>();
std::vector<std::string> vec = split_string (str);
if (vec.size() != 4) {
NVGSTDS_ERR_MSG_V
("Number of Color params should be exactly 4 "
"floats {r, g, b, a} between 0 and 1");
goto done;
}
gint64 class_index = -1;
if(paramKey != border_str) {
class_index = std::stoi(paramKey.substr(border_str.size()));
}
gdouble list[4];
for(unsigned int i = 0; i < 4; i++) {
list[i] = std::stod(vec[i]);
}
if (class_index == -1) {
clr_params = &config->bbox_border_color;
} else {
clr_params = (NvOSD_ColorParams*) g_malloc (sizeof (NvOSD_ColorParams));
g_hash_table_insert (config->bbox_border_color_table,
class_index + (gchar *) NULL, clr_params);
}
clr_params->red = list[0];
clr_params->green = list[1];
clr_params->blue = list[2];
clr_params->alpha = list[3];
} else if (paramKey.compare(0, bg_str.size(), bg_str) == 0) {
NvOSD_ColorParams *clr_params;
std::string str = itr->second.as<std::string>();
std::vector<std::string> vec = split_string (str);
if (vec.size() != 4) {
NVGSTDS_ERR_MSG_V
("Number of Color params should be exactly 4 "
"floats {r, g, b, a} between 0 and 1");
goto done;
}
gint64 class_index = -1;
if(paramKey != bg_str) {
class_index = std::stoi(paramKey.substr(bg_str.size()));
}
gdouble list[4];
for(unsigned int i = 0; i < 4; i++) {
list[i] = std::stod(vec[i]);
}
if (class_index == -1) {
clr_params = &config->bbox_bg_color;
config->have_bg_color = TRUE;
} else {
clr_params = (NvOSD_ColorParams*) g_malloc (sizeof (NvOSD_ColorParams));
g_hash_table_insert (config->bbox_bg_color_table, class_index + (gchar *) NULL,
clr_params);
}
clr_params->red = list[0];
clr_params->green = list[1];
clr_params->blue = list[2];
clr_params->alpha = list[3];
} else if (paramKey == "infer-raw-output-dir") {
std::string temp = itr->second.as<std::string>();
char* str = (char*) malloc(sizeof(char) * 1024);
std::strncpy (str, temp.c_str(), 1023);
config->raw_output_directory = (char*) malloc(sizeof(char) * 1024);
if (!get_absolute_file_path_yaml (cfg_file_path, str,
config->raw_output_directory)) {
g_printerr ("Error: Could not parse infer-raw-output-dir in %s.\n", group);
g_free (str);
goto done;
}
g_free (str);
} else if (paramKey == "gpu-id") {
config->gpu_id = itr->second.as<guint>();
config->is_gpu_id_set = TRUE;
} else if (paramKey == "nvbuf-memory-type") {
config->nvbuf_memory_type = itr->second.as<guint>();
} else {
cout << "[WARNING] Unknown param found in gie: " << paramKey << endl;
}
}
if (config->enable && config->label_file_path && !parse_labels_file (config)) {
cout << "Failed while parsing label file " << config->label_file_path << endl;
goto done;
}
if (!config->config_file_path) {
cout << "Config file not provided for group " << group_str << endl;
goto done;
}
ret = TRUE;
if (group) {
g_free (group);
group = NULL;
}
done:
if (!ret) {
cout << __func__ << " failed" << endl;
}
if (group) {
g_free (group);
group = NULL;
}
return ret;
}
/*
* SPDX-FileCopyrightText: Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* SPDX-License-Identifier: LicenseRef-NvidiaProprietary
*
* NVIDIA CORPORATION, its affiliates and licensors retain all intellectual
* property and proprietary rights in and to this material, related
* documentation and any modifications thereto. Any use, reproduction,
* disclosure or distribution of this material and related documentation
* without an express license agreement from NVIDIA CORPORATION or
* its affiliates is strictly prohibited.
*/
#include "deepstream_common.h"
#include "deepstream_config_yaml.h"
#include <string>
#include <cstring>
#include <iostream>
using std::cout;
using std::endl;
gboolean
parse_image_save_yaml (NvDsImageSave *config, gchar *cfg_file_path)
{
gboolean ret = FALSE;
/*Default Values*/
config->enable = FALSE;
config->gpu_id = 0;
config->output_folder_path = NULL;
config->frame_to_skip_rules_path = NULL;
config->min_confidence = 0.0;
config->max_confidence = 1.0;
config->min_box_width = 1;
config->min_box_height = 1;
config->save_image_full_frame = TRUE;
config->save_image_cropped_object = FALSE;
config->second_to_skip_interval = 600;
YAML::Node configyml = YAML::LoadFile(cfg_file_path);
for(YAML::const_iterator itr = configyml["img-save"].begin();
itr != configyml["img-save"].end(); ++itr)
{
std::string paramKey = itr->first.as<std::string>();
if (paramKey == "enable") {
config->enable = itr->second.as<gboolean>();
} else if (paramKey == "gpu-id") {
config->gpu_id = itr->second.as<guint>();
} else if (paramKey == "output-folder-path") {
std::string temp = itr->second.as<std::string>();
config->output_folder_path = (char*) malloc(sizeof(char) * 1024);
std::strncpy (config->output_folder_path, temp.c_str(), 1023);
} else if (paramKey == "frame-to-skip-rules-path") {
std::string temp = itr->second.as<std::string>();
config->frame_to_skip_rules_path = (char*) malloc(sizeof(char) * 1024);
std::strncpy (config->frame_to_skip_rules_path, temp.c_str(), 1023);
} else if (paramKey == "save-img-full-frame") {
config->save_image_full_frame = itr->second.as<gboolean>();
} else if (paramKey == "save-img-cropped-obj") {
config->save_image_cropped_object = itr->second.as<gboolean>();
} else if (paramKey == "second-to-skip-interval") {
config->second_to_skip_interval = itr->second.as<guint>();
} else if (paramKey == "min-confidence") {
config->min_confidence = itr->second.as<gdouble>();
} else if (paramKey == "max-confidence") {
config->max_confidence = itr->second.as<gdouble>();
} else if (paramKey == "min-box-width") {
config->min_box_width = itr->second.as<guint>();
} else if (paramKey == "min-box-height") {
config->min_box_height = itr->second.as<guint>();
} else {
cout << "[WARNING] Unknown param found in image-save: " << paramKey << endl;
}
}
ret = TRUE;
if (!ret) {
cout << __func__ << " failed" << endl;
}
return ret;
}
/*
* SPDX-FileCopyrightText: Copyright (c) 2022-2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* SPDX-License-Identifier: LicenseRef-NvidiaProprietary
*
* NVIDIA CORPORATION, its affiliates and licensors retain all intellectual
* property and proprietary rights in and to this material, related
* documentation and any modifications thereto. Any use, reproduction,
* disclosure or distribution of this material and related documentation
* without an express license agreement from NVIDIA CORPORATION or
* its affiliates is strictly prohibited.
*/
#include "deepstream_common.h"
#include "deepstream_config_yaml.h"
#include <string>
#include <cstring>
#include <iostream>
using std::cout;
using std::endl;
gboolean
parse_msgconsumer_yaml (NvDsMsgConsumerConfig *config, std::string group, gchar *cfg_file_path)
{
gboolean ret = FALSE;
YAML::Node configyml = YAML::LoadFile(cfg_file_path);
for(YAML::const_iterator itr = configyml[group].begin();
itr != configyml[group].end(); ++itr)
{
std::string paramKey = itr->first.as<std::string>();
if (paramKey == "enable") {
config->enable = itr->second.as<gboolean>();
} else if (paramKey == "config-file") {
std::string temp = itr->second.as<std::string>();
config->config_file_path = (char*) malloc(sizeof(char) * 1024);
std::strncpy (config->config_file_path, temp.c_str(), 1023);
} else if (paramKey == "proto-lib") {
std::string temp = itr->second.as<std::string>();
config->proto_lib = (char*) malloc(sizeof(char) * 1024);
std::strncpy (config->proto_lib, temp.c_str(), 1023);
} else if (paramKey == "conn-str") {
std::string temp = itr->second.as<std::string>();
config->conn_str = (char*) malloc(sizeof(char) * 1024);
std::strncpy (config->conn_str, temp.c_str(), 1023);
} else if (paramKey == "sensor-list-file") {
std::string temp = itr->second.as<std::string>();
char* str = (char*) malloc(sizeof(char) * 1024);
std::strncpy (str, temp.c_str(), 1023);
config->sensor_list_file = (char*) malloc(sizeof(char) * 1024);
if (!get_absolute_file_path_yaml (cfg_file_path, str,
config->sensor_list_file)) {
g_printerr ("Error: Could not parse labels file path\n");
g_free (str);
goto done;
}
g_free (str);
} else if (paramKey == "subscribe-topic-list") {
gchar **topicList;
std::string temp = itr->second.as<std::string>();
std::vector<std::string> vec = split_string (temp);
int length = (int) vec.size();
topicList = g_new (gchar *, length + 1);
for (int i = 0; i < length; i++) {
char* str2 = (char*) malloc(sizeof(char) * _MAX_STR_LENGTH);
std::strncpy (str2, vec[i].c_str(), _MAX_STR_LENGTH - 1);
topicList[i] = str2;
}
topicList[length] = NULL;
if (length < 1) {
NVGSTDS_ERR_MSG_V ("%s at least one topic must be provided", __func__);
g_strfreev (topicList);
goto done;
}
if (config->topicList)
g_ptr_array_unref (config->topicList);
config->topicList = g_ptr_array_new_full (length, g_free);
for (int i = 0; i < length; i++) {
g_ptr_array_add (config->topicList, g_strdup (topicList[i]));
}
g_strfreev (topicList);
} else {
cout << "[WARNING] Unknown param found in msgconsumer: " << paramKey << endl;
}
}
ret = TRUE;
done:
if (!ret) {
cout << __func__ << " failed" << endl;
}
return ret;
}
/*
* SPDX-FileCopyrightText: Copyright (c) 2022-2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* SPDX-License-Identifier: LicenseRef-NvidiaProprietary
*
* NVIDIA CORPORATION, its affiliates and licensors retain all intellectual
* property and proprietary rights in and to this material, related
* documentation and any modifications thereto. Any use, reproduction,
* disclosure or distribution of this material and related documentation
* without an express license agreement from NVIDIA CORPORATION or
* its affiliates is strictly prohibited.
*/
#include "deepstream_common.h"
#include "deepstream_config_yaml.h"
#include <string>
#include <cstring>
#include <iostream>
using std::cout;
using std::endl;
gboolean
parse_msgconv_yaml (NvDsSinkMsgConvBrokerConfig *config, std::string group_str, gchar *cfg_file_path)
{
gboolean ret = FALSE;
YAML::Node configyml = YAML::LoadFile(cfg_file_path);
char *group = (char*) malloc(sizeof(char) * 1024);
std::strncpy (group, group_str.c_str(), 1023);
for(YAML::const_iterator itr = configyml[group_str].begin();
itr != configyml[group_str].end(); ++itr)
{
std::string paramKey = itr->first.as<std::string>();
if (paramKey == "enable") {
config->enable = itr->second.as<gboolean>();
} else if (paramKey == "msg-conv-config") {
std::string temp = itr->second.as<std::string>();
char* str = (char*) malloc(sizeof(char) * 1024);
std::strncpy (str, temp.c_str(), 1023);
config->config_file_path = (char*) malloc(sizeof(char) * 1024);
if (!get_absolute_file_path_yaml (cfg_file_path, str,
config->config_file_path)) {
g_printerr ("Error: Could not parse msg-conv-config in %s.\n", group);
g_free (str);
goto done;
}
g_free (str);
} else if (paramKey == "msg-conv-payload-type") {
config->conv_payload_type = itr->second.as<guint>();
} else if (paramKey == "msg-conv-msg2p-lib") {
std::string temp = itr->second.as<std::string>();
char* str = (char*) malloc(sizeof(char) * 1024);
std::strncpy (str, temp.c_str(), 1023);
config->conv_msg2p_lib = (char*) malloc(sizeof(char) * 1024);
if (!get_absolute_file_path_yaml (cfg_file_path, str,
config->conv_msg2p_lib)) {
g_printerr ("Error: Could not parse msg-conv-msg2p-lib in %s.\n", group);
g_free (str);
goto done;
}
g_free (str);
} else if (paramKey == "msg-conv-comp-id") {
config->conv_comp_id = itr->second.as<guint>();
} else if (paramKey == "debug-payload-dir") {
std::string temp = itr->second.as<std::string>();
char* str = (char*) malloc(sizeof(char) * 1024);
std::strncpy (str, temp.c_str(), 1023);
config->debug_payload_dir = (char*) malloc(sizeof(char) * 1024);
if (!get_absolute_file_path_yaml (cfg_file_path, str,
config->debug_payload_dir)) {
g_printerr ("Error: Could not parse debug-payload-dir in %s.\n", group);
g_free (str);
goto done;
}
g_free (str);
} else if (paramKey == "multiple-payloads") {
config->multiple_payloads = itr->second.as<gboolean>();
} else if (paramKey == "msg-conv-msg2p-new-api") {
config->conv_msg2p_new_api = itr->second.as<gboolean>();
} else if (paramKey == "msg-conv-frame-interval") {
config->conv_frame_interval = itr->second.as<guint>();
} else if (paramKey == "msg-conv-dummy-payload") {
config->conv_dummy_payload = itr->second.as<gboolean>();
}
}
ret = TRUE;
done:
if (!ret) {
cout << __func__ << " failed" << endl;
}
if (group) {
g_free (group);
}
return ret;
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment