Nvurisrcbin

This commit is contained in:
Barzan Hayati 2025-07-07 00:26:41 +00:00
parent 3986bcf378
commit 71bcd6ef1e
3 changed files with 19 additions and 21 deletions

View File

@ -16,9 +16,8 @@ std::chrono::time_point<std::chrono::steady_clock>
PipelineManager::PipelineManager() { ; } PipelineManager::PipelineManager() { ; }
PipelineManager::PipelineManager(int num_sources, char** url_camera) PipelineManager::PipelineManager(int num_sources, char** url_camera)
: csv_fp("csv_fps.csv") : csv_fp("csv_fps.csv") {
{ if (!csv_fp.is_open()) {
if (!csv_fp.is_open()) {
std::cerr << "Failed to open csv_fp csv file.\n"; std::cerr << "Failed to open csv_fp csv file.\n";
throw std::runtime_error("Failed to open csv_fps_buffer_probe.csv"); throw std::runtime_error("Failed to open csv_fps_buffer_probe.csv");
} }
@ -69,18 +68,16 @@ char* createName(const char* str, int num) {
return result; return result;
} }
void PipelineManager::set_row_csv_fps(const std::string& name, double fps){ void PipelineManager::set_row_csv_fps(const std::string& name, double fps) {
if (!csv_fp.is_open()) { if (!csv_fp.is_open()) {
std::cerr << "Failed to write: stream not open for " << name << "\n"; std::cerr << "Failed to write: stream not open for " << name << "\n";
return; return;
} } else {
else{
csv_fp << name << "," << fps << "\n"; csv_fp << name << "," << fps << "\n";
std::cout << "Wrote: " << name << " = " << fps << "\n"; std::cout << "Wrote: " << name << " = " << fps << "\n";
} }
} }
GstPadProbeReturn PipelineManager::osd_sink_pad_buffer_probe( GstPadProbeReturn PipelineManager::osd_sink_pad_buffer_probe(
GstPad* pad, GstPadProbeInfo* info, gpointer user_data) { GstPad* pad, GstPadProbeInfo* info, gpointer user_data) {
(void)pad; // This explicitly marks it as unused (void)pad; // This explicitly marks it as unused
@ -166,7 +163,8 @@ GstPadProbeReturn PipelineManager::buffer_probe(GstPad* pad,
long long elapsed = std::chrono::duration_cast<std::chrono::milliseconds>( long long elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(
current_time_buffer_probe - last_time_buffer_probe) current_time_buffer_probe - last_time_buffer_probe)
.count(); .count();
fps_buffer_probe = (double)(frame_count_buffer_probe * 1000 / (double)elapsed); fps_buffer_probe =
(double)(frame_count_buffer_probe * 1000 / (double)elapsed);
if (elapsed >= 1000) { // Update every second if (elapsed >= 1000) { // Update every second
g_print("FPS_buffer_probe: %.2f\n", fps_buffer_probe); g_print("FPS_buffer_probe: %.2f\n", fps_buffer_probe);
frame_count_buffer_probe = 0; frame_count_buffer_probe = 0;
@ -201,7 +199,7 @@ bool PipelineManager::playing_pipeline(int num_sources, char** url_camera) {
gst_element_set_state(pipeline, GST_STATE_PLAYING); gst_element_set_state(pipeline, GST_STATE_PLAYING);
GstStateChangeReturn ret = GstStateChangeReturn ret =
gst_element_set_state(pipeline, GST_STATE_PLAYING); gst_element_set_state(pipeline, GST_STATE_PLAYING);
if(ret == GST_STATE_CHANGE_FAILURE) { if (ret == GST_STATE_CHANGE_FAILURE) {
g_printerr("Unable to set pipeline to playing.\n"); g_printerr("Unable to set pipeline to playing.\n");
gst_object_unref(pipeline); gst_object_unref(pipeline);
return false; return false;
@ -316,11 +314,11 @@ bool PipelineManager::create_pipeline_elements(int num_sources,
for (guint i = 0; i < (guint)num_sources; i++) { for (guint i = 0; i < (guint)num_sources; i++) {
GstElement* source_bin; GstElement* source_bin;
// GstElement *source_bin = create_uridecode_bin (i, // GstElement *source_bin = create_nvurisrc_bin (i,
// const_cast<char*>(first_video.c_str())); // const_cast<char*>(first_video.c_str()));
g_print("Trying to create uridecode_bin for %s \n", url_camera[i + 1]); g_print("Trying to create nvurisrc_bin for %s \n", url_camera[i + 1]);
source_bin = SourceBin::create_uridecode_bin( source_bin = SourceBin::create_nvurisrc_bin(
i, url_camera[i + 1], streammux_manager->streammux, prop); i, url_camera[i + 1], streammux_manager->streammux, prop);
if (!source_bin) { if (!source_bin) {
g_printerr("Failed to create source bin for %s. Exiting.\n", g_printerr("Failed to create source bin for %s. Exiting.\n",

View File

@ -86,20 +86,20 @@ void SourceBin::cb_newpad(GstElement *decodebin, GstPad *pad,
} }
// Definition of static function // Definition of static function
GstElement *SourceBin::create_uridecode_bin(guint index, gchar *filename, GstElement *SourceBin::create_nvurisrc_bin(guint index, gchar *filename,
GstElement *streammux, GstElement *streammux,
cudaDeviceProp prop) { cudaDeviceProp prop) {
GstElement *decodebin = NULL; GstElement *decodebin = NULL;
gchar decodebin_name[16] = {}; gchar decodebin_name[16] = {};
// Create data structure for callbacks // Create data structure for callbacks
StreamData *stream_data = new StreamData{(int)index, streammux, prop}; StreamData *stream_data = new StreamData{(int)index, streammux, prop};
// g_print ("creating uridecodebin for [%s]\n", filename); // g_print ("creating nvurisrcbin for [%s]\n", filename);
g_print("Creating uridecodebin for stream_id %d or stream %s \n", index, g_print("Creating nvurisrcbin for stream_id %d or stream %s \n", index,
filename); filename);
// g_source_id_list[index] = index; // g_source_id_list[index] = index;
g_snprintf(decodebin_name, 15, "source-bin-%02d", index); g_snprintf(decodebin_name, 15, "source-bin-%02d", index);
decodebin = gst_element_factory_make("uridecodebin", decodebin_name); decodebin = gst_element_factory_make("nvurisrcbin", decodebin_name);
g_object_set(G_OBJECT(decodebin), "uri", filename, NULL); g_object_set(G_OBJECT(decodebin), "uri", filename, NULL);
g_signal_connect(G_OBJECT(decodebin), "pad-added", G_CALLBACK(cb_newpad), g_signal_connect(G_OBJECT(decodebin), "pad-added", G_CALLBACK(cb_newpad),
stream_data); //&g_source_id_list[index] stream_data); //&g_source_id_list[index]

View File

@ -21,8 +21,8 @@ class SourceBin {
static void decodebin_child_added(GstChildProxy *, GObject *, gchar *, static void decodebin_child_added(GstChildProxy *, GObject *, gchar *,
gpointer); gpointer);
static void cb_newpad(GstElement *, GstPad *, gpointer, gboolean *); static void cb_newpad(GstElement *, GstPad *, gpointer, gboolean *);
static GstElement *create_uridecode_bin(guint, gchar *, GstElement *, static GstElement *create_nvurisrc_bin(guint, gchar *, GstElement *,
cudaDeviceProp prop); cudaDeviceProp prop);
private: private:
// Static data member (if needed) // Static data member (if needed)