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) 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_osd_yaml (NvDsOSDConfig *config, gchar *cfg_file_path)
{
gboolean ret = FALSE;
/** Default values */
config->draw_text = TRUE;
config->draw_bbox = TRUE;
config->draw_mask = FALSE;
YAML::Node configyml = YAML::LoadFile(cfg_file_path);
for(YAML::const_iterator itr = configyml["osd"].begin();
itr != configyml["osd"].end(); ++itr)
{
std::string paramKey = itr->first.as<std::string>();
if (paramKey == "enable") {
config->enable = itr->second.as<gboolean>();
} else if (paramKey == "process-mode") {
config->mode =
(NvOSD_Mode) itr->second.as<int>();
} else if (paramKey == "border-width") {
config->border_width = itr->second.as<gint>();
} else if (paramKey == "text-size") {
config->text_size = itr->second.as<gint>();
} else if (paramKey == "text-color") {
std::string str = itr->second.as<std::string>();
std::vector<std::string> vec = split_string (str);
if (vec.size() != 4) {
NVGSTDS_ERR_MSG_V
("Color params should be exactly 4 floats {r, g, b, a} between 0 and 1");
goto done;
}
std::vector<int> temp;
for(int i = 0; i < 4; i++) {
int temp1 = std::stoi(vec[i]);
temp.push_back(temp1);
}
config->text_color.red = temp[0];
config->text_color.green = temp[1];
config->text_color.blue = temp[2];
config->text_color.alpha = temp[3];
} else if (paramKey == "text-bg-color") {
std::string str = itr->second.as<std::string>();
std::vector<std::string> vec = split_string (str);
if (vec.size() != 4) {
NVGSTDS_ERR_MSG_V
("Color params should be exactly 4 floats {r, g, b, a} between 0 and 1");
goto done;
}
std::vector<int> temp;
for(int i = 0; i < 4; i++) {
int temp1 = std::stoi(vec[i]);
temp.push_back(temp1);
}
config->text_bg_color.red = temp[0];
config->text_bg_color.green = temp[1];
config->text_bg_color.blue = temp[2];
config->text_bg_color.alpha = temp[3];
if (config->text_bg_color.red > 0 || config->text_bg_color.green > 0
|| config->text_bg_color.blue > 0 || config->text_bg_color.alpha > 0)
config->text_has_bg = TRUE;
} else if (paramKey == "font") {
std::string temp = itr->second.as<std::string>();
config->font = (char*) malloc(sizeof(char) * 1024);
std::strncpy (config->font, temp.c_str(), 1023);
} else if (paramKey == "show-clock") {
config->enable_clock = itr->second.as<gboolean>();
} else if (paramKey == "clock-x-offset") {
config->clock_x_offset = itr->second.as<gint>();
} else if (paramKey == "clock-y-offset") {
config->clock_y_offset = itr->second.as<gint>();
} else if (paramKey == "clock-text-size") {
config->clock_text_size = itr->second.as<gint>();
} else if (paramKey == "hw-blend-color-attr") {
std::string temp = itr->second.as<std::string>();
config->hw_blend_color_attr = (char*) malloc(sizeof(char) * 1024);
std::strncpy (config->hw_blend_color_attr, temp.c_str(), 1023);
} else if (paramKey == "nvbuf-memory-type") {
config->nvbuf_memory_type = itr->second.as<guint>();
} else if (paramKey == "clock-color") {
std::string str = itr->second.as<std::string>();
std::vector<std::string> vec = split_string (str);
if (vec.size() != 4) {
NVGSTDS_ERR_MSG_V
("Color params should be exactly 4 floats {r, g, b, a} between 0 and 1");
goto done;
}
std::vector<int> temp;
for(int i = 0; i < 4; i++) {
int temp1 = std::stoi(vec[i]);
temp.push_back(temp1);
}
config->clock_color.red = temp[0];
config->clock_color.green = temp[1];
config->clock_color.blue = temp[2];
config->clock_color.alpha = temp[3];
} else if (paramKey == "gpu-id") {
config->gpu_id = itr->second.as<guint>();
} else if (paramKey == "display-text") {
config->draw_text = itr->second.as<gboolean>();
} else if (paramKey == "display-bbox") {
config->draw_bbox = itr->second.as<gboolean>();
} else if (paramKey == "display-mask") {
config->draw_mask = itr->second.as<gboolean>();
} else {
cout << "[WARNING] Unknown param found in osd: " << 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_preprocess_yaml (NvDsPreProcessConfig *config, gchar* cfg_file_path)
{
gboolean ret = FALSE;
YAML::Node configyml = YAML::LoadFile(cfg_file_path);
for(YAML::const_iterator itr = configyml["pre-process"].begin();
itr != configyml["pre-process"].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-path in preprocess.\n");
g_free (str);
goto done;
}
g_free (str);
} else {
cout << "[WARNING] Unknown param found in preprocess: " << paramKey << endl;
}
}
ret = TRUE;
done:
if (!ret) {
cout << __func__ << " failed" << endl;
}
return ret;
}
\ No newline at end of file
/*
* SPDX-FileCopyrightText: Copyright (c) 2023 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;
#define SEG_OUTPUT_WIDTH 1280
#define SEG_OUTPUT_HEIGHT 720
gboolean
parse_segvisual_yaml (NvDsSegVisualConfig *config, gchar *cfg_file_path)
{
gboolean ret = FALSE;
/** Default values */
config->height = SEG_OUTPUT_HEIGHT;
config->width = SEG_OUTPUT_WIDTH;
config->gpu_id = 0;
config->max_batch_size = 1;
config->nvbuf_memory_type = 0;
YAML::Node configyml = YAML::LoadFile(cfg_file_path);
for(YAML::const_iterator itr = configyml["segvisual"].begin();
itr != configyml["segvisual"].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 == "batch-size") {
config->max_batch_size = itr->second.as<guint>();
} else if (paramKey == "width") {
config->width = itr->second.as<guint>();
} else if (paramKey == "height") {
config->height = 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 segvisual: " << 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_sink_yaml (NvDsSinkSubBinConfig *config, std::string group_str, gchar * cfg_file_path)
{
gboolean ret = FALSE;
YAML::Node configyml = YAML::LoadFile(cfg_file_path);
config->encoder_config.rtsp_port = 8554;
config->encoder_config.udp_port = 5000;
config->encoder_config.codec = NV_DS_ENCODER_H264;
config->encoder_config.container = NV_DS_CONTAINER_MP4;
config->encoder_config.compute_hw = 0;
config->render_config.qos = FALSE;
config->link_to_demux = FALSE;
config->msg_conv_broker_config.new_api = FALSE;
config->msg_conv_broker_config.conv_msg2p_new_api = FALSE;
config->msg_conv_broker_config.conv_frame_interval = 30;
if (configyml[group_str]["enable"]) {
gboolean val= configyml[group_str]["enable"].as<gboolean>();
if(val == FALSE)
return TRUE;
}
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 == "type") {
config->type =
(NvDsSinkType) itr->second.as<int>();
} else if (paramKey == "link-to-demux") {
config->link_to_demux = itr->second.as<gboolean>();
} else if (paramKey == "width") {
config->render_config.width = itr->second.as<gint>();
} else if (paramKey == "height") {
config->render_config.height = itr->second.as<gint>();
} else if (paramKey == "qos") {
config->render_config.qos = itr->second.as<gboolean>();
config->render_config.qos_value_specified = TRUE;
} else if (paramKey == "sync") {
config->sync = itr->second.as<gint>();
} else if (paramKey == "nvbuf-memory-type") {
config->render_config.nvbuf_memory_type =
itr->second.as<guint>();
} else if (paramKey == "container") {
config->encoder_config.container =
(NvDsContainerType) itr->second.as<int>();
} else if (paramKey == "codec") {
config->encoder_config.codec =
(NvDsEncoderType) itr->second.as<int>();
} else if (paramKey == "compute-hw") {
config->encoder_config.compute_hw =
itr->second.as<int>();
} else if (paramKey == "enc-type") {
config->encoder_config.enc_type =
(NvDsEncHwSwType) itr->second.as<int>();
} else if (paramKey == "bitrate") {
config->encoder_config.bitrate =
itr->second.as<gint>();
} else if (paramKey == "profile") {
config->encoder_config.profile =
itr->second.as<guint>();
} else if (paramKey == "iframeinterval") {
config->encoder_config.iframeinterval =
itr->second.as<guint>();
} else if (paramKey == "output-file") {
std::string temp = itr->second.as<std::string>();
config->encoder_config.output_file_path = (char*) malloc(sizeof(char) * 1024);
std::strncpy (config->encoder_config.output_file_path, temp.c_str(), 1023);
} else if (paramKey == "source-id") {
config->source_id =
itr->second.as<guint>();
} else if (paramKey == "rtsp-port") {
config->encoder_config.rtsp_port =
itr->second.as<guint>();
} else if (paramKey == "udp-port") {
config->encoder_config.udp_port =
itr->second.as<guint>();
} else if (paramKey == "udp-buffer-size") {
config->encoder_config.udp_buffer_size =
itr->second.as<guint64>();
} else if (paramKey == "color-range") {
config->render_config.color_range =
itr->second.as<guint>();
} else if (paramKey == "conn-id") {
config->render_config.conn_id =
itr->second.as<guint>();
} else if (paramKey == "plane-id") {
config->render_config.plane_id =
itr->second.as<guint>();
} else if (paramKey == "set-mode") {
config->render_config.set_mode =
itr->second.as<gboolean>();
} else if (paramKey == "gpu-id") {
config->encoder_config.gpu_id = config->render_config.gpu_id =
itr->second.as<guint>();
} else if (paramKey == "msg-conv-config" ||
paramKey == "msg-conv-payload-type" ||
paramKey == "msg-conv-msg2p-lib" ||
paramKey == "msg-conv-comp-id" ||
paramKey == "debug-payload-dir" ||
paramKey == "multiple-payloads" ||
paramKey == "msg-conv-msg2p-new-api" ||
paramKey == "msg-conv-frame-interval" ||
paramKey == "msg-conv-dummy-payload") {
ret = parse_msgconv_yaml (&config->msg_conv_broker_config, group_str, cfg_file_path);
if (!ret)
goto done;
} else if (paramKey == "msg-broker-proto-lib") {
std::string temp = itr->second.as<std::string>();
config->msg_conv_broker_config.proto_lib = (char*) malloc(sizeof(char) * 1024);
std::strncpy (config->msg_conv_broker_config.proto_lib, temp.c_str(), 1023);
} else if (paramKey == "msg-broker-conn-str") {
std::string temp = itr->second.as<std::string>();
config->msg_conv_broker_config.conn_str = (char*) malloc(sizeof(char) * 1024);
std::strncpy (config->msg_conv_broker_config.conn_str, temp.c_str(), 1023);
} else if (paramKey == "topic") {
std::string temp = itr->second.as<std::string>();
config->msg_conv_broker_config.topic = (char*) malloc(sizeof(char) * 1024);
std::strncpy (config->msg_conv_broker_config.topic, temp.c_str(), 1023);
} else if (paramKey == "msg-broker-config") {
std::string temp = itr->second.as<std::string>();
char* str = (char*) malloc(sizeof(char) * 1024);
std::strncpy (str, temp.c_str(), 1023);
config->msg_conv_broker_config.broker_config_file_path = (char*) malloc(sizeof(char) * 1024);
if (!get_absolute_file_path_yaml (cfg_file_path, str,
config->msg_conv_broker_config.broker_config_file_path)) {
g_printerr ("Error: Could not parse msg-broker-config in sink.\n");
g_free (str);
goto done;
}
g_free (str);
} else if (paramKey == "msg-broker-comp-id") {
config->msg_conv_broker_config.broker_comp_id =
itr->second.as<guint>();
} else if (paramKey == "disable-msgconv") {
config->msg_conv_broker_config.disable_msgconv =
itr->second.as<gboolean>();
} else if (paramKey == "new-api") {
config->msg_conv_broker_config.new_api =
itr->second.as<gboolean>();
} else {
cout << "[WARNING] Unknown param found in sink: " << paramKey << endl;
}
}
ret = TRUE;
done:
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_yaml.h"
#include <string>
#include <cstring>
#include <iostream>
#include <unistd.h>
using std::cout;
using std::endl;
#define N_DECODE_SURFACES 16
#define N_EXTRA_SURFACES 1
gboolean
parse_source_yaml (NvDsSourceConfig *config, std::vector<std::string> headers,
std::vector<std::string> source_values, gchar *cfg_file_path)
{
gboolean ret = FALSE;
config->latency = 100;
config->num_decode_surfaces = N_DECODE_SURFACES;
config->num_extra_surfaces = N_EXTRA_SURFACES;
for(unsigned int i = 0; i < headers.size(); i++)
{
std::string paramKey = headers[i];
if (paramKey == "type") {
gint temp = std::stoi(source_values[i]);
config->type = (NvDsSourceType) temp;
} else if (paramKey == "enable") {
config->enable = std::stoul(source_values[i]);
} else if (paramKey == "camera-width") {
config->source_width = std::stoi(source_values[i]);
} else if (paramKey == "camera-height") {
config->source_height = std::stoi(source_values[i]);
} else if (paramKey == "camera-fps-n") {
config->source_fps_n = std::stoi(source_values[i]);
} else if (paramKey == "camera-fps-d") {
config->source_fps_d = std::stoi(source_values[i]);
} else if (paramKey == "camera-csi-sensor-id") {
config->camera_csi_sensor_id = std::stoi(source_values[i]);
} else if (paramKey == "camera-v4l2-dev-node") {
config->camera_v4l2_dev_node =
std::stoi(source_values[i]);;
} else if (paramKey == "udp-buffer-size") {
config->udp_buffer_size = std::stoi(source_values[i]);
} else if (paramKey == "alsa-device") {
std::string temp = source_values[i];
config->alsa_device = (char*) malloc(sizeof(char) * 1024);
std::strncpy (config->alsa_device, temp.c_str(), 1023);
} else if (paramKey == "video-format") {
std::string temp = source_values[i];
config->video_format = (char*) malloc(sizeof(char) * 1024);
std::strncpy (config->video_format, temp.c_str(), 1023);
} else if (paramKey == "uri") {
std::string temp = source_values[i];
char* uri = (char*) malloc(sizeof(char) * 1024);
std::strncpy (uri, temp.c_str(), 1023);
char *str;
if (g_str_has_prefix (uri, "file://")) {
str = g_strdup (uri + 7);
config->uri = (char*) malloc(sizeof(char) * 1024);
get_absolute_file_path_yaml (cfg_file_path, str, config->uri);
config->uri = g_strdup_printf ("file://%s", config->uri);
g_free (uri);
g_free (str);
} else {
config->uri = uri;
}
} else if (paramKey == "latency") {
config->latency = std::stoi(source_values[i]);
} else if (paramKey == "num-sources") {
config->num_sources = std::stoul(source_values[i]);
if (config->num_sources < 1) {
config->num_sources = 1;
}
} else if (paramKey == "gpu-id") {
config->gpu_id = std::stoul(source_values[i]);
} else if (paramKey == "num-decode-surfaces") {
config->num_decode_surfaces = std::stoul(source_values[i]);
} else if (paramKey == "num-extra-surfaces") {
config->num_extra_surfaces = std::stoul(source_values[i]);
} else if (paramKey == "drop-frame-interval") {
config->drop_frame_interval = std::stoul(source_values[i]);
} else if (paramKey == "camera-id") {
config->camera_id = std::stoul(source_values[i]);
} else if (paramKey == "rtsp-reconnect-interval-sec") {
config->rtsp_reconnect_interval_sec =
std::stoi(source_values[i]);
} else if (paramKey == "rtsp-reconnect-attempts") {
config->rtsp_reconnect_attempts =
std::stoul(source_values[i]);
} else if (paramKey == "intra-decode-enable") {
config->Intra_decode = (gboolean) std::stoul(source_values[i]);
} else if (paramKey == "cudadec-memtype") {
config->cuda_memory_type =
std::stoul(source_values[i]);
} else if (paramKey == "nvbuf-memory-type") {
config->nvbuf_memory_type =
std::stoul(source_values[i]);
} else if (paramKey == "select-rtp-protocol") {
config->select_rtp_protocol =
std::stoul(source_values[i]);
} else if (paramKey == "source-id") {
config->source_id = std::stoul(source_values[i]);
} else if (paramKey == "smart-record") {
config->smart_record = std::stoul(source_values[i]);
} else if (paramKey == "smart-rec-dir-path") {
std::string temp = source_values[i];
config->dir_path = (char*) malloc(sizeof(char) * 1024);
std::strncpy (config->dir_path, temp.c_str(), 1023);
if (access (config->dir_path, 2)) {
if (errno == ENOENT || errno == ENOTDIR) {
g_print ("ERROR: Directory (%s) doesn't exist.\n", config->dir_path);
} else if (errno == EACCES) {
g_print ("ERROR: No write permission in %s\n", config->dir_path);
}
goto done;
}
} else if (paramKey == "smart-rec-file-prefix") {
std::string temp = source_values[i];
config->file_prefix = (char*) malloc(sizeof(char) * 1024);
std::strncpy (config->file_prefix, temp.c_str(), 1023);
} else if (paramKey == "smart-rec-video-cache") {
cout << "Deprecated config smart-rec-video-cache used in source. Use smart-rec-cache instead" << endl;
config->smart_rec_cache_size = std::stoul(source_values[i]);
} else if (paramKey == "smart-rec-cache") {
config->smart_rec_cache_size =
std::stoul(source_values[i]);
} else if (paramKey == "smart-rec-container") {
config->smart_rec_container = std::stoul(source_values[i]);
} else if (paramKey == "smart-rec-start-time") {
config->smart_rec_start_time = std::stoul(source_values[i]);
} else if (paramKey == "smart-rec-default-duration") {
config->smart_rec_def_duration = std::stoul(source_values[i]);
} else if (paramKey == "smart-rec-duration") {
config->smart_rec_duration = std::stoul(source_values[i]);
} else if (paramKey == "smart-rec-interval") {
config->smart_rec_interval = std::stoul(source_values[i]);
}
#if defined(__aarch64__) && !defined(AARCH64_IS_SBSA)
else if (paramKey == "copy-hw") {
config->nvvideoconvert_copy_hw = std::stoul(source_values[i]);
}
#endif
else {
cout << "[WARNING] Unknown param found in source : " << 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_streammux_yaml (NvDsStreammuxConfig *config, gchar *cfg_file_path)
{
gboolean ret = FALSE;
config->frame_duration = -1;
config->batched_push_timeout = -1;
config->attach_sys_ts_as_ntp = TRUE;
config->async_process = TRUE;
config->no_pipeline_eos = FALSE;
YAML::Node configyml = YAML::LoadFile(cfg_file_path);
for(YAML::const_iterator itr = configyml["streammux"].begin(); itr != configyml["streammux"].end(); ++itr)
{
std::string paramKey = itr->first.as<std::string>();
if(paramKey == "width") {
config->pipeline_width = itr->second.as<gint>();
}
else if (paramKey == "height") {
config->pipeline_height = itr->second.as<gint>();
}
else if (paramKey == "gpu-id") {
config->gpu_id = itr->second.as<guint>();
}
else if (paramKey == "live-source") {
config->live_source = itr->second.as<gboolean>();
}
else if (paramKey == "buffer-pool-size") {
config->buffer_pool_size = itr->second.as<gint>();
}
else if (paramKey == "batch-size") {
config->batch_size = itr->second.as<gint>();
}
else if (paramKey == "batched-push-timeout") {
config->batched_push_timeout = itr->second.as<gint>();
}
else if (paramKey == "enable-padding") {
config->enable_padding = itr->second.as<gboolean>();
}
else if (paramKey == "frame-duration") {
config->frame_duration = itr->second.as<guint64>();
}
else if (paramKey == "nvbuf-memory-type") {
config->nvbuf_memory_type = 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_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 streammux\n");
g_free (str);
goto done;
}
g_free (str);
}
else if (paramKey == "compute-hw") {
config->compute_hw = itr->second.as<gint>();
}
else if (paramKey == "attach-sys-ts") {
config->attach_sys_ts_as_ntp = itr->second.as<gboolean>();
}
else if (paramKey == "frame-num-reset-on-stream-reset") {
config->frame_num_reset_on_stream_reset = itr->second.as<gboolean>();
}
else if (paramKey == "frame-num-reset-on-eos") {
config->frame_num_reset_on_eos = itr->second.as<gboolean>();
}
else if (paramKey == "num-surfaces-per-frame") {
config->num_surface_per_frame = itr->second.as<gint>();
}
else if (paramKey == "interpolation-method") {
config->interpolation_method = itr->second.as<gint>();
}
else if (paramKey == "sync-inputs") {
config->sync_inputs = itr->second.as<gboolean>();
}
else if (paramKey == "max-latency") {
config->max_latency = itr->second.as<guint64>();
}
else if (paramKey == "async-process") {
config->async_process = itr->second.as<gboolean>();
}
else if (paramKey == "drop-pipeline-eos") {
config->no_pipeline_eos = itr->second.as<gboolean>();
}
else {
cout << "[WARNING] Unknown param found in streammux: " << paramKey << endl;
goto done;
}
}
config->is_parsed = TRUE;
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 <iostream>
using std::cout;
using std::endl;
gboolean
parse_tiled_display_yaml (NvDsTiledDisplayConfig *config, gchar *cfg_file_path)
{
gboolean ret = FALSE;
YAML::Node configyml = YAML::LoadFile(cfg_file_path);
for(YAML::const_iterator itr = configyml["tiled-display"].begin();
itr != configyml["tiled-display"].end(); ++itr)
{
std::string paramKey = itr->first.as<std::string>();
if (paramKey == "enable") {
config->enable =
(NvDsTiledDisplayEnable) itr->second.as<int>();
} else if (paramKey == "rows") {
config->rows = itr->second.as<guint>();
} else if (paramKey == "columns") {
config->columns = itr->second.as<guint>();
} else if (paramKey == "width") {
config->width = itr->second.as<guint>();
} else if (paramKey == "height") {
config->height = 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 if (paramKey == "compute-hw") {
config->compute_hw = itr->second.as<guint>();
} else if (paramKey == "buffer-pool-size") {
config->buffer_pool_size = itr->second.as<guint>();
} else if (paramKey == "square-seq-grid") {
config->square_seq_grid = itr->second.as<gboolean>();
} else {
cout << "[WARNING] Unknown param found in tiled-display: " << 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_tracker_yaml (NvDsTrackerConfig *config, gchar *cfg_file_path)
{
gboolean ret = FALSE;
YAML::Node configyml = YAML::LoadFile(cfg_file_path);
config->display_tracking_id = TRUE;
config->tracking_id_reset_mode = 0;
config->input_tensor_meta = FALSE;
config->input_tensor_gie_id = 0;
config->compute_hw = 0;
config->user_meta_pool_size = 32;
config->sub_batches = {};
config->sub_batch_err_recovery_trial_cnt = 0;
for(YAML::const_iterator itr = configyml["tracker"].begin();
itr != configyml["tracker"].end(); ++itr)
{
std::string paramKey = itr->first.as<std::string>();
if (paramKey == "enable") {
config->enable = itr->second.as<gboolean>();
} else if (paramKey == "tracker-width") {
config->width = itr->second.as<gint>();
} else if (paramKey == "tracker-height") {
config->height = itr->second.as<gint>();
} else if (paramKey == "gpu-id") {
config->gpu_id = itr->second.as<guint>();
} else if (paramKey == "tracker-surface-type") {
config->tracking_surf_type = itr->second.as<guint>();
} else if (paramKey == "ll-config-file") {
std::string llConfigString = itr->second.as<std::string>();
std::stringstream ss(llConfigString);
std::string temp;
std::stringstream ssFinal;
char* str = (char*) malloc(sizeof(char) * 1024);
char* str_out = (char*) malloc(sizeof(char) * 1024);
while(std::getline(ss, temp, ';')){
std::strncpy (str, temp.c_str(), 1023);
if (!get_absolute_file_path_yaml (cfg_file_path, str, str_out)){
g_printerr ("Error: Could not parse ll-config-file in tracker.\n");
g_free (str); g_free (str_out);
goto done;
}
ssFinal << str_out << ";";
}
config->ll_config_file = g_strdup(ssFinal.str().c_str());
g_free (str); g_free (str_out);
} else if (paramKey == "ll-lib-file") {
std::string temp = itr->second.as<std::string>();
char* str = (char*) malloc(sizeof(char) * 1024);
std::strncpy (str, temp.c_str(), 1023);
config->ll_lib_file = (char*) malloc(sizeof(char) * 1024);
if (!get_absolute_file_path_yaml (cfg_file_path, str,
config->ll_lib_file)) {
g_printerr ("Error: Could not parse ll-lib-file in tracker.\n");
g_free (str);
goto done;
}
g_free (str);
} else if (paramKey == "tracking-surface-type") {
//Diff b/w this and tracking_surf_type
config->tracking_surface_type = itr->second.as<guint>();
} else if(paramKey == "display-tracking-id"){
config->display_tracking_id = itr->second.as<gboolean>();
} else if(paramKey == "tracking-id-reset-mode"){
config->tracking_id_reset_mode = itr->second.as<guint>();
} else if(paramKey == "input-tensor-meta"){
config->input_tensor_meta = itr->second.as<gboolean>();
} else if(paramKey == "tensor-meta-gie-id"){
config->input_tensor_gie_id = itr->second.as<guint>();
} else if(paramKey == "compute-hw"){
config->compute_hw = itr->second.as<guint>();
} else if(paramKey == "user-meta-pool-size"){
config->user_meta_pool_size = itr->second.as<guint>();
} else if(paramKey == "sub-batches"){
std::string temp = itr->second.as<std::string>();
config->sub_batches = (char*) malloc(sizeof(char) * temp.size());
std::strncpy (config->sub_batches, temp.c_str(), temp.size());
} else if(paramKey == "sub-batch-err-recovery-trial-cnt"){
config->sub_batch_err_recovery_trial_cnt = itr->second.as<gint>();
} else {
cout << "Unknown key " << paramKey << " for tracker" << endl;
}
}
ret = TRUE;
done:
if (!ret) {
cout << __func__ << " failed" << endl;
}
return ret;
}
/*
* SPDX-FileCopyrightText: Copyright (c) 2020-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 <linux/limits.h> /* For PATH_MAX */
#include <stdio.h>
#include <string.h>
#include "deepstream_common.h"
#include "deepstream_audio_classifier.h"
static void
write_infer_output_to_file (GstBuffer * buf,
NvDsInferNetworkInfo * network_info, NvDsInferLayerInfo * layers_info,
guint num_layers, guint batch_size, gpointer user_data)
{
NvDsGieConfig *config = (NvDsGieConfig *) user_data;
guint i;
/* "gst_buffer_get_nvstream_meta()" can be called on the GstBuffer to get more
* information about the buffer.*/
for (i = 0; i < num_layers; i++) {
NvDsInferLayerInfo *info = &layers_info[i];
guint element_size = 0;
guint j;
FILE *file;
gchar file_name[PATH_MAX];
gchar layer_name[128];
switch (info->dataType) {
case FLOAT:
element_size = 4;
break;
case HALF:
element_size = 2;
break;
case INT32:
element_size = 4;
break;
case INT8:
element_size = 1;
break;
case INT64:
element_size = 8;
break;
}
g_strlcpy (layer_name, info->layerName, 128);
for (j = 0; layer_name[j] != '\0'; j++) {
layer_name[j] = (layer_name[j] == '/') ? '_' : layer_name[j];
}
g_snprintf (file_name, PATH_MAX,
"%s/%s_batch%010lu_batchsize%02d.bin",
config->raw_output_directory, layer_name,
config->file_write_frame_num, batch_size);
file_name[PATH_MAX - 1] = '\0';
file = fopen (file_name, "w");
if (!file) {
g_printerr ("Could not open file '%s' for writing:%s\n",
file_name, strerror (errno));
continue;
}
fwrite (info->buffer, element_size,
info->inferDims.numElements * batch_size, file);
fclose (file);
}
config->file_write_frame_num++;
}
gboolean
create_audio_classifier_bin (NvDsGieConfig * config,
NvDsAudioClassifierBin * bin)
{
gboolean ret = FALSE;
gst_nvinfer_raw_output_generated_callback out_callback =
write_infer_output_to_file;
bin->bin = gst_bin_new ("audio_classifier_bin");
if (!bin->bin) {
NVGSTDS_ERR_MSG_V ("Failed to create 'audio_classifier_bin'");
goto done;
}
bin->queue = gst_element_factory_make (NVDS_ELEM_QUEUE, "classifier_queue");
if (!bin->queue) {
NVGSTDS_ERR_MSG_V ("Failed to create 'classifier_queue'");
goto done;
}
bin->classifier =
gst_element_factory_make (NVDS_ELEM_INFER_AUDIO, "audio_classifier");
if (!bin->classifier) {
NVGSTDS_ERR_MSG_V ("Failed to create 'audio_classifier'");
goto done;
}
g_object_set (G_OBJECT (bin->classifier),
"config-file-path", GET_FILE_PATH (config->config_file_path), NULL);
if (config->is_batch_size_set)
g_object_set (G_OBJECT (bin->classifier),
"batch-size", config->batch_size, NULL);
if (config->is_unique_id_set)
g_object_set (G_OBJECT (bin->classifier),
"unique-id", config->unique_id, NULL);
if (config->is_gpu_id_set)
g_object_set (G_OBJECT (bin->classifier), "gpu-id", config->gpu_id, NULL);
if (config->model_engine_file_path)
g_object_set (G_OBJECT (bin->classifier), "model-engine-file",
GET_FILE_PATH (config->model_engine_file_path), NULL);
if (config->is_frame_size_set)
g_object_set (G_OBJECT (bin->classifier),
"audio-framesize", config->frame_size, NULL);
if (config->is_hop_size_set)
g_object_set (G_OBJECT (bin->classifier),
"audio-hopsize", config->hop_size, NULL);
if (config->audio_transform) {
GstStructure *p;
p = gst_structure_from_string (config->audio_transform, NULL);
g_object_set (G_OBJECT (bin->classifier), "audio-transform", p, NULL);
}
if (config->raw_output_directory) {
g_object_set (G_OBJECT (bin->classifier),
"raw-output-generated-callback", out_callback,
"raw-output-generated-userdata", config, NULL);
}
gst_bin_add_many (GST_BIN (bin->bin), bin->queue, bin->classifier, NULL);
NVGSTDS_LINK_ELEMENT (bin->queue, bin->classifier);
NVGSTDS_BIN_ADD_GHOST_PAD (bin->bin, bin->classifier, "src");
NVGSTDS_BIN_ADD_GHOST_PAD (bin->bin, bin->queue, "sink");
ret = TRUE;
done:
if (!ret) {
NVGSTDS_ERR_MSG_V ("%s failed", __func__);
}
return ret;
}
/*
* SPDX-FileCopyrightText: Copyright (c) 2020 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 <dlfcn.h>
#include <stdlib.h>
#include "deepstream_c2d_msg.h"
#include "deepstream_c2d_msg_util.h"
#include "deepstream_common.h"
#include "deepstream_sources.h"
#include "gst-nvdssr.h"
static void
connect_cb (NvMsgBrokerClientHandle h_ptr, NvMsgBrokerErrorType status)
{
}
static void
subscribe_cb (NvMsgBrokerErrorType flag, void *msg, int msg_len, char *topic,
void *uData)
{
NvDsC2DMsg *parsedMsg = NULL;
if (flag == NV_MSGBROKER_API_ERR) {
NVGSTDS_ERR_MSG_V ("Error in consuming message.");
} else {
GST_DEBUG ("Consuming message, on topic[%s]. Payload =%.*s\n\n", topic,
msg_len, (char *) msg);
}
if (uData) {
NvDsC2DContext *ctx = (NvDsC2DContext *) uData;
if (ctx->subscribeCb) {
return ctx->subscribeCb (flag, msg, msg_len, topic, ctx->uData);
} else {
NvDsSrcParentBin *pBin = (NvDsSrcParentBin *) ctx->uData;
if (!pBin) {
NVGSTDS_WARN_MSG_V ("Null user data");
return;
}
parsedMsg = nvds_c2d_parse_cloud_message (msg, msg_len);
if (parsedMsg == NULL) {
NVGSTDS_WARN_MSG_V ("error in message parsing \n");
return;
}
if (parsedMsg->type == NVDS_C2D_MSG_SR_START ||
parsedMsg->type == NVDS_C2D_MSG_SR_STOP) {
NvDsSRSessionId sessId = 0;
gint sensorId;
NvDsSRContext *srCtx = NULL;
NvDsC2DMsgSR *msgSR = (NvDsC2DMsgSR *) parsedMsg->message;
if (ctx->hashMap) {
gpointer keyVal =
g_hash_table_lookup (ctx->hashMap, msgSR->sensorStr);
if (keyVal) {
sensorId = *(int *) keyVal;
} else {
NVGSTDS_WARN_MSG_V ("%s: Sensor id not found", msgSR->sensorStr);
goto error;
}
} else {
sensorId = atoi (msgSR->sensorStr);
}
srCtx = (NvDsSRContext *) pBin->sub_bins[sensorId].recordCtx;
if (!srCtx) {
NVGSTDS_WARN_MSG_V ("Null SR context handle.");
goto error;
}
if (parsedMsg->type == NVDS_C2D_MSG_SR_START) {
NvDsSRStart (srCtx, &sessId, msgSR->startTime, msgSR->duration, NULL);
} else {
NvDsSRStop (srCtx, sessId);
}
} else {
NVGSTDS_WARN_MSG_V ("Unknown message type.");
}
}
}
error:
if (parsedMsg) {
nvds_c2d_release_message (parsedMsg);
parsedMsg = NULL;
}
return;
}
NvDsC2DContext *
start_cloud_to_device_messaging (NvDsMsgConsumerConfig * config,
nv_msgbroker_subscribe_cb_t subscribeCb, void *uData)
{
NvDsC2DContext *ctx = NULL;
gchar **topicList = NULL;
gint i, numTopic;
if (!config->conn_str || !config->proto_lib || !config->topicList) {
NVGSTDS_ERR_MSG_V ("NULL parameters");
return NULL;
}
ctx = g_new0 (NvDsC2DContext, 1);
ctx->protoLib = g_strdup (config->proto_lib);
ctx->connStr = g_strdup (config->conn_str);
ctx->configFile = g_strdup (config->config_file_path);
if (subscribeCb)
ctx->subscribeCb = subscribeCb;
if (uData)
ctx->uData = uData;
if (config->sensor_list_file) {
ctx->hashMap =
g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
if (!nvds_c2d_parse_sensor (ctx, config->sensor_list_file)) {
NVGSTDS_ERR_MSG_V ("Failed to parse sensor list file");
goto error;
}
}
ctx->connHandle = nv_msgbroker_connect (ctx->connStr,
ctx->protoLib, connect_cb, ctx->configFile);
if (!ctx->connHandle) {
NVGSTDS_ERR_MSG_V ("Failed to connect to broker.");
goto error;
}
numTopic = config->topicList->len;
topicList = g_new0 (gchar *, numTopic);
for (i = 0; i < numTopic; i++) {
topicList[i] = (gchar *) g_ptr_array_index (config->topicList, i);
}
if (nv_msgbroker_subscribe (ctx->connHandle, topicList, numTopic,
subscribe_cb, (gpointer) ctx) != NV_MSGBROKER_API_OK) {
NVGSTDS_ERR_MSG_V ("Subscription to topic[s] failed\n");
goto error;
}
g_free (topicList);
topicList = NULL;
return ctx;
error:
if (ctx) {
if (ctx->hashMap) {
g_hash_table_unref (ctx->hashMap);
ctx->hashMap = NULL;
}
g_free (ctx->configFile);
g_free (ctx->connStr);
g_free (ctx->protoLib);
g_free (ctx);
ctx = NULL;
}
if (topicList)
g_free (topicList);
return ctx;
}
gboolean
stop_cloud_to_device_messaging (NvDsC2DContext * ctx)
{
NvMsgBrokerErrorType err;
gboolean ret = TRUE;
g_return_val_if_fail (ctx, FALSE);
err = nv_msgbroker_disconnect (ctx->connHandle);
if (err != NV_MSGBROKER_API_OK) {
NVGSTDS_ERR_MSG_V ("error(%d) in disconnect\n", err);
ret = FALSE;
}
ctx->connHandle = NULL;
if (ctx->hashMap) {
g_hash_table_unref (ctx->hashMap);
ctx->hashMap = NULL;
}
g_free (ctx->configFile);
g_free (ctx->connStr);
g_free (ctx->protoLib);
g_free (ctx);
return ret;
}
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