diff --git a/src/gstds_example_manager.cpp b/src/gstds_example_manager.cpp index 8e6bdff..d344986 100644 --- a/src/gstds_example_manager.cpp +++ b/src/gstds_example_manager.cpp @@ -1,5 +1,10 @@ #include "gstds_example_manager.hpp" +#define MAX_DISPLAY_LEN 64 +#define PGIE_CLASS_ID_PERSON 0 + +gint GstdsExampleManager::frame_number = 0; + GstdsExampleManager::GstdsExampleManager() {} bool GstdsExampleManager::create_gstds_example() { @@ -10,4 +15,75 @@ bool GstdsExampleManager::create_gstds_example() { return false; } return true; -} \ No newline at end of file +} + +// Attach probe to a pad in the pipeline +void GstdsExampleManager::attach_probe_to_element() { + GstPad *src_pad = gst_element_get_static_pad(custom_plugin, "src"); + if (!src_pad) { + std::cerr << "Unable to get gst ds example src pad\n"; + return; + } + + gst_pad_add_probe(src_pad, GST_PAD_PROBE_TYPE_BUFFER, + gstds_example_src_pad_buffer_probe, NULL, NULL); + gst_object_unref(src_pad); +} + +/* This is the buffer probe function that we have registered on the src pad + * of the gstds_example element. All the infer elements in the pipeline shall + * attach their metadata to the GstBuffer, here we will iterate & process the + * metadata forex: class ids to strings, counting of class_id objects etc. */ +GstPadProbeReturn GstdsExampleManager::gstds_example_src_pad_buffer_probe( + GstPad *pad, GstPadProbeInfo *info, gpointer u_data) { + (void)pad; + (void)u_data; + GstBuffer *buf = (GstBuffer *)info->data; + guint num_rects = 0; + guint person_count = 0; + NvDsObjectMeta *obj_meta = NULL; + NvDsMetaList *l_frame = NULL; + NvDsMetaList *l_obj = NULL; + NvDsDisplayMeta *display_meta = NULL; + + NvDsBatchMeta *batch_meta = gst_buffer_get_nvds_batch_meta(buf); + + for (l_frame = batch_meta->frame_meta_list; l_frame != NULL; + l_frame = l_frame->next) { + NvDsFrameMeta *frame_meta = (NvDsFrameMeta *)(l_frame->data); + int offset = 0; + for (l_obj = frame_meta->obj_meta_list; l_obj != NULL; + l_obj = l_obj->next) { + obj_meta = (NvDsObjectMeta *)(l_obj->data); + if (obj_meta->class_id == PGIE_CLASS_ID_PERSON) { + person_count++; + num_rects++; + std::cout << "In GstdsExample src " + << "x = " << obj_meta->rect_params.left + << " y = " << obj_meta->rect_params.top + << " w = " << obj_meta->rect_params.width + << " h = " << obj_meta->rect_params.height + << " score = " << obj_meta->confidence + << " Object ID: " << obj_meta->object_id + << std::endl; + } + } + display_meta = nvds_acquire_display_meta_from_pool(batch_meta); + NvOSD_TextParams *txt_params = &display_meta->text_params[0]; + display_meta->num_labels = 1; + txt_params->display_text = (gchar *)g_malloc0(MAX_DISPLAY_LEN); + offset = snprintf(txt_params->display_text, MAX_DISPLAY_LEN, + "Person = %d ", person_count); + (void)offset; + + nvds_add_display_meta_to_frame(frame_meta, display_meta); + } + g_print( + "In GstdsExample src " + "Frame Number = %d " + "Person Count = %d\n", + frame_number, person_count); + + frame_number++; + return GST_PAD_PROBE_OK; +} diff --git a/src/gstds_example_manager.hpp b/src/gstds_example_manager.hpp index e6dbb02..5486b5c 100644 --- a/src/gstds_example_manager.hpp +++ b/src/gstds_example_manager.hpp @@ -1,5 +1,9 @@ #include +#include +#include + +#include "gstnvdsmeta.h" class GstdsExampleManager { private: public: @@ -7,4 +11,8 @@ class GstdsExampleManager { GstdsExampleManager(); bool create_gstds_example(); ~GstdsExampleManager(); + static gint frame_number; + void attach_probe_to_element(); + static GstPadProbeReturn gstds_example_src_pad_buffer_probe( + GstPad *, GstPadProbeInfo *, gpointer); }; \ No newline at end of file diff --git a/src/nv_infer_server_manager.cpp b/src/nv_infer_server_manager.cpp index 0ba773d..d8b7673 100644 --- a/src/nv_infer_server_manager.cpp +++ b/src/nv_infer_server_manager.cpp @@ -60,137 +60,140 @@ bool NvInferServerManager::create_nv_infer_server(int num_sources) { // Probe function to inspect NvDsObjectMeta -GstPadProbeReturn NvInferServerManager::osd_sink_pad_buffer_probe( - GstPad *pad, GstPadProbeInfo *info, gpointer user_data) { - (void)pad; - (void)user_data; - GstBuffer *buf = (GstBuffer *)info->data; +// GstPadProbeReturn NvInferServerManager::osd_sink_pad_buffer_probe( +// GstPad *pad, GstPadProbeInfo *info, gpointer user_data) { +// (void)pad; +// (void)user_data; +// GstBuffer *buf = (GstBuffer *)info->data; - // Retrieve batch metadata from buffer - NvDsBatchMeta *batch_meta = gst_buffer_get_nvds_batch_meta(buf); - if (!batch_meta) { - std::cerr << "No batch metadata found\n"; - return GST_PAD_PROBE_OK; - } +// // Retrieve batch metadata from buffer +// NvDsBatchMeta *batch_meta = gst_buffer_get_nvds_batch_meta(buf); +// if (!batch_meta) { +// std::cerr << "No batch metadata found\n"; +// return GST_PAD_PROBE_OK; +// } - // probe sees the frame metadata (NvDsFrameMeta) — - // but no object metadata (NvDsObjectMeta) was attached to that frame. +// // probe sees the frame metadata (NvDsFrameMeta) — +// // but no object metadata (NvDsObjectMeta) was attached to that frame. - for (NvDsMetaList *l_frame = batch_meta->frame_meta_list; l_frame != NULL; - l_frame = l_frame->next) { - NvDsFrameMeta *frame_meta = (NvDsFrameMeta *)(l_frame->data); - // std::cout << "Frame number: " << frame_meta->frame_num << std::endl; - // if (frame_meta->obj_meta_list == NULL) { - // std::cout << " ⚠️ No object metadata for this frame.\n"; - // } +// for (NvDsMetaList *l_frame = batch_meta->frame_meta_list; l_frame != +// NULL; +// l_frame = l_frame->next) { +// NvDsFrameMeta *frame_meta = (NvDsFrameMeta *)(l_frame->data); +// // std::cout << "Frame number: " << frame_meta->frame_num << +// std::endl; +// // if (frame_meta->obj_meta_list == NULL) { +// // std::cout << " ⚠️ No object metadata for this frame.\n"; +// // } - for (NvDsMetaList *l_obj = frame_meta->obj_meta_list; l_obj != NULL; - l_obj = l_obj->next) { - NvDsObjectMeta *obj_meta = (NvDsObjectMeta *)(l_obj->data); +// for (NvDsMetaList *l_obj = frame_meta->obj_meta_list; l_obj != NULL; +// l_obj = l_obj->next) { +// NvDsObjectMeta *obj_meta = (NvDsObjectMeta *)(l_obj->data); - std::cout << " Object ID: " << obj_meta->object_id << std::endl; - std::cout << " Class ID: " << obj_meta->class_id << std::endl; - std::cout << " Label: " - << (obj_meta->obj_label ? obj_meta->obj_label : "N/A") - << std::endl; - std::cout << " BBox: x=" << obj_meta->rect_params.left - << " y=" << obj_meta->rect_params.top - << " w=" << obj_meta->rect_params.width - << " h=" << obj_meta->rect_params.height << std::endl; - } - } - return GST_PAD_PROBE_OK; -} +// std::cout << " Object ID: " << obj_meta->object_id << std::endl; +// std::cout << " Class ID: " << obj_meta->class_id << std::endl; +// std::cout << " Label: " +// << (obj_meta->obj_label ? obj_meta->obj_label : "N/A") +// << std::endl; +// std::cout << " BBox: x=" << obj_meta->rect_params.left +// << " y=" << obj_meta->rect_params.top +// << " w=" << obj_meta->rect_params.width +// << " h=" << obj_meta->rect_params.height << std::endl; +// } +// } +// return GST_PAD_PROBE_OK; +// } -// Attach probe to a pad in the pipeline -void NvInferServerManager::attach_probe_to_element(GstElement *nvosd) { - GstPad *sink_pad = gst_element_get_static_pad(nvosd, "sink"); - if (!sink_pad) { - std::cerr << "Unable to get nvosd sink pad\n"; - return; - } +// // Attach probe to a pad in the pipeline +// void NvInferServerManager::attach_probe_to_element(GstElement *nvosd) { +// GstPad *sink_pad = gst_element_get_static_pad(nvosd, "src"); +// if (!sink_pad) { +// std::cerr << "Unable to get nvosd sink pad\n"; +// return; +// } - gst_pad_add_probe(sink_pad, GST_PAD_PROBE_TYPE_BUFFER, - osd_sink_pad_buffer_probe_new, NULL, NULL); - gst_object_unref(sink_pad); -} +// gst_pad_add_probe(sink_pad, GST_PAD_PROBE_TYPE_BUFFER, +// osd_sink_pad_buffer_probe_new, NULL, NULL); +// gst_object_unref(sink_pad); +// } -/* This is the buffer probe function that we have registered on the sink pad - * of the OSD element. All the infer elements in the pipeline shall attach - * their metadata to the GstBuffer, here we will iterate & process the metadata - * forex: class ids to strings, counting of class_id objects etc. */ -GstPadProbeReturn NvInferServerManager::osd_sink_pad_buffer_probe_new( - GstPad *pad, GstPadProbeInfo *info, gpointer u_data) { - (void)pad; - (void)u_data; - GstBuffer *buf = (GstBuffer *)info->data; - guint num_rects = 0; - guint person_count = 0; - NvDsObjectMeta *obj_meta = NULL; - NvDsMetaList *l_frame = NULL; - NvDsMetaList *l_obj = NULL; - NvDsDisplayMeta *display_meta = NULL; +// /* This is the buffer probe function that we have registered on the sink pad +// * of the OSD element. All the infer elements in the pipeline shall attach +// * their metadata to the GstBuffer, here we will iterate & process the +// metadata +// * forex: class ids to strings, counting of class_id objects etc. */ +// GstPadProbeReturn NvInferServerManager::osd_sink_pad_buffer_probe_new( +// GstPad *pad, GstPadProbeInfo *info, gpointer u_data) { +// (void)pad; +// (void)u_data; +// GstBuffer *buf = (GstBuffer *)info->data; +// guint num_rects = 0; +// guint person_count = 0; +// NvDsObjectMeta *obj_meta = NULL; +// NvDsMetaList *l_frame = NULL; +// NvDsMetaList *l_obj = NULL; +// NvDsDisplayMeta *display_meta = NULL; - NvDsBatchMeta *batch_meta = gst_buffer_get_nvds_batch_meta(buf); +// NvDsBatchMeta *batch_meta = gst_buffer_get_nvds_batch_meta(buf); - for (l_frame = batch_meta->frame_meta_list; l_frame != NULL; - l_frame = l_frame->next) { - NvDsFrameMeta *frame_meta = (NvDsFrameMeta *)(l_frame->data); - int offset = 0; - for (l_obj = frame_meta->obj_meta_list; l_obj != NULL; - l_obj = l_obj->next) { - obj_meta = (NvDsObjectMeta *)(l_obj->data); - if (obj_meta->class_id == PGIE_CLASS_ID_PERSON) { - person_count++; - num_rects++; - std::cout << "In OSD sink " - << "x = " << obj_meta->rect_params.left - << " y = " << obj_meta->rect_params.top - << " w = " << obj_meta->rect_params.width - << " h = " << obj_meta->rect_params.height - << " score = " << obj_meta->confidence - << " Object ID: " << obj_meta->object_id - << std::endl; - } - } - display_meta = nvds_acquire_display_meta_from_pool(batch_meta); - NvOSD_TextParams *txt_params = &display_meta->text_params[0]; - display_meta->num_labels = 1; - txt_params->display_text = (gchar *)g_malloc0(MAX_DISPLAY_LEN); - offset = snprintf(txt_params->display_text, MAX_DISPLAY_LEN, - "Person = %d ", person_count); - (void)offset; +// for (l_frame = batch_meta->frame_meta_list; l_frame != NULL; +// l_frame = l_frame->next) { +// NvDsFrameMeta *frame_meta = (NvDsFrameMeta *)(l_frame->data); +// int offset = 0; +// for (l_obj = frame_meta->obj_meta_list; l_obj != NULL; +// l_obj = l_obj->next) { +// obj_meta = (NvDsObjectMeta *)(l_obj->data); +// if (obj_meta->class_id == PGIE_CLASS_ID_PERSON) { +// person_count++; +// num_rects++; +// std::cout << "In OSD sink " +// << "x = " << obj_meta->rect_params.left +// << " y = " << obj_meta->rect_params.top +// << " w = " << obj_meta->rect_params.width +// << " h = " << obj_meta->rect_params.height +// << " score = " << obj_meta->confidence +// << " Object ID: " << obj_meta->object_id +// << std::endl; +// } +// } +// display_meta = nvds_acquire_display_meta_from_pool(batch_meta); +// NvOSD_TextParams *txt_params = &display_meta->text_params[0]; +// display_meta->num_labels = 1; +// txt_params->display_text = (gchar *)g_malloc0(MAX_DISPLAY_LEN); +// offset = snprintf(txt_params->display_text, MAX_DISPLAY_LEN, +// "Person = %d ", person_count); +// (void)offset; - /* Now set the offsets where the string should appear */ - txt_params->x_offset = 10; - txt_params->y_offset = 12; +// /* Now set the offsets where the string should appear */ +// txt_params->x_offset = 10; +// txt_params->y_offset = 12; - /* Font , font-color and font-size */ - txt_params->font_params.font_name = (gchar *)"Serif"; - txt_params->font_params.font_size = 10; - txt_params->font_params.font_color.red = 1.0; - txt_params->font_params.font_color.green = 1.0; - txt_params->font_params.font_color.blue = 1.0; - txt_params->font_params.font_color.alpha = 1.0; +// /* Font , font-color and font-size */ +// txt_params->font_params.font_name = (gchar *)"Serif"; +// txt_params->font_params.font_size = 10; +// txt_params->font_params.font_color.red = 1.0; +// txt_params->font_params.font_color.green = 1.0; +// txt_params->font_params.font_color.blue = 1.0; +// txt_params->font_params.font_color.alpha = 1.0; - /* Text background color */ - txt_params->set_bg_clr = 1; - txt_params->text_bg_clr.red = 0.0; - txt_params->text_bg_clr.green = 0.0; - txt_params->text_bg_clr.blue = 0.0; - txt_params->text_bg_clr.alpha = 1.0; +// /* Text background color */ +// txt_params->set_bg_clr = 1; +// txt_params->text_bg_clr.red = 0.0; +// txt_params->text_bg_clr.green = 0.0; +// txt_params->text_bg_clr.blue = 0.0; +// txt_params->text_bg_clr.alpha = 1.0; - nvds_add_display_meta_to_frame(frame_meta, display_meta); - } - g_print( - "In OSD sink " - "Frame Number = %d " - "Person Count = %d\n", - frame_number, person_count); +// nvds_add_display_meta_to_frame(frame_meta, display_meta); +// } +// g_print( +// "In OSD sink " +// "Frame Number = %d " +// "Person Count = %d\n", +// frame_number, person_count); - frame_number++; - return GST_PAD_PROBE_OK; -} +// frame_number++; +// return GST_PAD_PROBE_OK; +// } /* This is the buffer probe function that we have registered on the src pad * of the PGIE's next queue element. PGIE element in the pipeline shall attach @@ -295,15 +298,16 @@ GstPadProbeReturn NvInferServerManager::pgie_pad_buffer_probe( uint detected_persons = 0; float *data = static_cast(layer.buffer); - for (unsigned int jkl = 0; jkl < 100; jkl+=4) { // 100 persons for each frame + for (unsigned int jkl = 0; jkl < 100; + jkl += 4) { // 100 persons for each frame if (data[jkl * 57 + 4] > threshold_body_detection) { detected_persons++; - std::cout << "first for x = " << data[jkl * 57 + 0] - << " y = " << data[jkl * 57 + 1] - << " w = " << data[jkl * 57 + 2] - << " h = " << data[jkl * 57 + 3] - << " score = " << data[jkl * 57 + 4] << - std::endl; + std::cout + << "nvinferserver first for x = " << data[jkl * 57 + 0] + << " y = " << data[jkl * 57 + 1] + << " w = " << data[jkl * 57 + 2] + << " h = " << data[jkl * 57 + 3] + << " score = " << data[jkl * 57 + 4] << std::endl; for (unsigned int mno = 0; mno < 5; ++mno) { float value = data[jkl * 57 + mno]; (void)value; @@ -323,25 +327,23 @@ GstPadProbeReturn NvInferServerManager::pgie_pad_buffer_probe( NvOSD_RectParams &rect_params = obj_meta->rect_params; NvOSD_TextParams &text_params = obj_meta->text_params; /* Assign bounding box coordinates. */ - rect_params.left = - int(data[index * 57 + 0] * MUXER_OUTPUT_WIDTH / PGIE_NET_WIDTH); - rect_params.top = int(data[index * 57 + 1] * MUXER_OUTPUT_HEIGHT / - PGIE_NET_HEIGHT); + rect_params.left = int(data[index * 57 + 0] * + MUXER_OUTPUT_WIDTH / PGIE_NET_WIDTH); + rect_params.top = int(data[index * 57 + 1] * + MUXER_OUTPUT_HEIGHT / PGIE_NET_HEIGHT); rect_params.width = int((data[index * 57 + 2] - data[index * 57 + 0]) * - MUXER_OUTPUT_WIDTH / PGIE_NET_WIDTH); + MUXER_OUTPUT_WIDTH / PGIE_NET_WIDTH); rect_params.height = int((data[index * 57 + 3] - data[index * 57 + 1]) * - MUXER_OUTPUT_HEIGHT / PGIE_NET_HEIGHT); - + MUXER_OUTPUT_HEIGHT / PGIE_NET_HEIGHT); + + std::cout << "nvinferserver second for x = " << rect_params.left + << " y = " << rect_params.top + << " w = " << rect_params.width + << " h = " << rect_params.height + << " score = " << obj_meta->confidence << std::endl; - std::cout << "second for x = " << rect_params.left - << " y = " << rect_params.top - << " w = " << rect_params.top - << " h = " << rect_params.width - << " score = " << obj_meta->confidence << - std::endl; - /* Border of width 3. */ rect_params.border_width = 3; rect_params.has_bg_color = 0; diff --git a/src/nv_infer_server_manager.hpp b/src/nv_infer_server_manager.hpp index 26abbdc..0044759 100644 --- a/src/nv_infer_server_manager.hpp +++ b/src/nv_infer_server_manager.hpp @@ -26,13 +26,13 @@ class NvInferServerManager { NvInferServerManager(); bool create_nv_infer_server(int); ~NvInferServerManager(); - static GstPadProbeReturn osd_sink_pad_buffer_probe(GstPad *, - GstPadProbeInfo *, - gpointer); - void attach_probe_to_element(GstElement *); + // static GstPadProbeReturn osd_sink_pad_buffer_probe(GstPad *, + // GstPadProbeInfo *, + // gpointer); + // void attach_probe_to_element(GstElement *); static GstPadProbeReturn pgie_pad_buffer_probe(GstPad *, GstPadProbeInfo *, gpointer); - static GstPadProbeReturn osd_sink_pad_buffer_probe_new(GstPad *, - GstPadProbeInfo *, - gpointer); + // static GstPadProbeReturn osd_sink_pad_buffer_probe_new(GstPad *, + // GstPadProbeInfo + // *, gpointer); }; \ No newline at end of file diff --git a/src/nv_osd_manager.cpp b/src/nv_osd_manager.cpp index 81da4b4..17c82ee 100644 --- a/src/nv_osd_manager.cpp +++ b/src/nv_osd_manager.cpp @@ -7,6 +7,10 @@ 1 // use GPU to draw rectangles, keypoints and text on frame if // OSD_PROCESS_MODE set to 1 #define OSD_DISPLAY_TEXT 1 +#define MAX_DISPLAY_LEN 64 +#define PGIE_CLASS_ID_PERSON 0 + +gint NvOsdManager::frame_number = 0; NvOsdManager::NvOsdManager() {} @@ -23,4 +27,95 @@ bool NvOsdManager::create_nv_osd() { return false; } return true; -} \ No newline at end of file +} + +// Attach probe to a pad in the pipeline +void NvOsdManager::attach_probe_to_element() { + GstPad *src_pad = gst_element_get_static_pad(nvosd, "src"); + if (!src_pad) { + std::cerr << "Unable to get nvosd src pad\n"; + return; + } + + gst_pad_add_probe(src_pad, GST_PAD_PROBE_TYPE_BUFFER, + osd_src_pad_buffer_probe, NULL, NULL); + gst_object_unref(src_pad); +} + +/* This is the buffer probe function that we have registered on the sink pad + * of the OSD element. All the infer elements in the pipeline shall attach + * their metadata to the GstBuffer, here we will iterate & process the metadata + * forex: class ids to strings, counting of class_id objects etc. */ +GstPadProbeReturn NvOsdManager::osd_src_pad_buffer_probe(GstPad *pad, + GstPadProbeInfo *info, + gpointer u_data) { + (void)pad; + (void)u_data; + GstBuffer *buf = (GstBuffer *)info->data; + guint num_rects = 0; + guint person_count = 0; + NvDsObjectMeta *obj_meta = NULL; + NvDsMetaList *l_frame = NULL; + NvDsMetaList *l_obj = NULL; + NvDsDisplayMeta *display_meta = NULL; + + NvDsBatchMeta *batch_meta = gst_buffer_get_nvds_batch_meta(buf); + + for (l_frame = batch_meta->frame_meta_list; l_frame != NULL; + l_frame = l_frame->next) { + NvDsFrameMeta *frame_meta = (NvDsFrameMeta *)(l_frame->data); + int offset = 0; + for (l_obj = frame_meta->obj_meta_list; l_obj != NULL; + l_obj = l_obj->next) { + obj_meta = (NvDsObjectMeta *)(l_obj->data); + if (obj_meta->class_id == PGIE_CLASS_ID_PERSON) { + person_count++; + num_rects++; + std::cout << "In OSD sink " + << "x = " << obj_meta->rect_params.left + << " y = " << obj_meta->rect_params.top + << " w = " << obj_meta->rect_params.width + << " h = " << obj_meta->rect_params.height + << " score = " << obj_meta->confidence + << " Object ID: " << obj_meta->object_id + << std::endl; + } + } + display_meta = nvds_acquire_display_meta_from_pool(batch_meta); + NvOSD_TextParams *txt_params = &display_meta->text_params[0]; + display_meta->num_labels = 1; + txt_params->display_text = (gchar *)g_malloc0(MAX_DISPLAY_LEN); + offset = snprintf(txt_params->display_text, MAX_DISPLAY_LEN, + "Person = %d ", person_count); + (void)offset; + + /* Now set the offsets where the string should appear */ + txt_params->x_offset = 10; + txt_params->y_offset = 12; + + /* Font , font-color and font-size */ + txt_params->font_params.font_name = (gchar *)"Serif"; + txt_params->font_params.font_size = 10; + txt_params->font_params.font_color.red = 1.0; + txt_params->font_params.font_color.green = 1.0; + txt_params->font_params.font_color.blue = 1.0; + txt_params->font_params.font_color.alpha = 1.0; + + /* Text background color */ + txt_params->set_bg_clr = 1; + txt_params->text_bg_clr.red = 0.0; + txt_params->text_bg_clr.green = 0.0; + txt_params->text_bg_clr.blue = 0.0; + txt_params->text_bg_clr.alpha = 1.0; + + nvds_add_display_meta_to_frame(frame_meta, display_meta); + } + g_print( + "In OSD sink " + "Frame Number = %d " + "Person Count = %d\n", + frame_number, person_count); + + frame_number++; + return GST_PAD_PROBE_OK; +} diff --git a/src/nv_osd_manager.hpp b/src/nv_osd_manager.hpp index c2f76da..cca3444 100644 --- a/src/nv_osd_manager.hpp +++ b/src/nv_osd_manager.hpp @@ -1,5 +1,10 @@ #include +#include +#include + +#include "gstnvdsmeta.h" + class NvOsdManager { private: public: @@ -7,4 +12,9 @@ class NvOsdManager { NvOsdManager(); bool create_nv_osd(); ~NvOsdManager(); + static gint frame_number; + void attach_probe_to_element(); + static GstPadProbeReturn osd_src_pad_buffer_probe(GstPad *, + GstPadProbeInfo *, + gpointer); }; \ No newline at end of file diff --git a/src/nv_tracker_manager.cpp b/src/nv_tracker_manager.cpp index a2e2488..18ad201 100644 --- a/src/nv_tracker_manager.cpp +++ b/src/nv_tracker_manager.cpp @@ -5,7 +5,6 @@ #define GPU_ID 0 #define MAX_DISPLAY_LEN 64 #define PGIE_CLASS_ID_PERSON 0 -#define PGIE_DETECTED_CLASS_NUM 1 gint NvTrackerManager::frame_number = 0; @@ -32,23 +31,23 @@ bool NvTrackerManager::create_nv_tracker() { } // Attach probe to a pad in the pipeline -void NvTrackerManager::attach_probe_to_element(GstElement *nvosd) { - GstPad *sink_pad = gst_element_get_static_pad(nvosd, "src"); - if (!sink_pad) { - std::cerr << "Unable to get nvosd sink pad\n"; +void NvTrackerManager::attach_probe_to_element() { + GstPad *src_pad = gst_element_get_static_pad(tracker, "src"); + if (!src_pad) { + std::cerr << "Unable to get nvosd src pad\n"; return; } - gst_pad_add_probe(sink_pad, GST_PAD_PROBE_TYPE_BUFFER, - tracker_sink_pad_buffer_probe, NULL, NULL); - gst_object_unref(sink_pad); + gst_pad_add_probe(src_pad, GST_PAD_PROBE_TYPE_BUFFER, + tracker_src_pad_buffer_probe, NULL, NULL); + gst_object_unref(src_pad); } /* This is the buffer probe function that we have registered on the sink pad * of the OSD element. All the infer elements in the pipeline shall attach * their metadata to the GstBuffer, here we will iterate & process the metadata * forex: class ids to strings, counting of class_id objects etc. */ -GstPadProbeReturn NvTrackerManager::tracker_sink_pad_buffer_probe( +GstPadProbeReturn NvTrackerManager::tracker_src_pad_buffer_probe( GstPad *pad, GstPadProbeInfo *info, gpointer u_data) { (void)pad; (void)u_data; diff --git a/src/nv_tracker_manager.hpp b/src/nv_tracker_manager.hpp index 2ce9878..0fc6499 100644 --- a/src/nv_tracker_manager.hpp +++ b/src/nv_tracker_manager.hpp @@ -16,8 +16,8 @@ class NvTrackerManager { NvTrackerManager(); ~NvTrackerManager(); bool create_nv_tracker(); - void attach_probe_to_element(GstElement *); - static GstPadProbeReturn tracker_sink_pad_buffer_probe(GstPad *, - GstPadProbeInfo *, - gpointer); + void attach_probe_to_element(); + static GstPadProbeReturn tracker_src_pad_buffer_probe(GstPad *, + GstPadProbeInfo *, + gpointer); }; \ No newline at end of file diff --git a/src/pipeline_manager.cpp b/src/pipeline_manager.cpp index 3573922..37c3312 100644 --- a/src/pipeline_manager.cpp +++ b/src/pipeline_manager.cpp @@ -330,6 +330,8 @@ bool PipelineManager::create_pipeline_elements(int num_sources, } gstds_example_manager->create_gstds_example(); + gstds_example_manager->attach_probe_to_element(); + tiler_manager->create_tiler(num_sources, streammux_manager->MUXER_OUTPUT_WIDTH, streammux_manager->MUXER_OUTPUT_HEIGHT); @@ -350,14 +352,17 @@ bool PipelineManager::create_pipeline_elements(int num_sources, // GstElement *nvinfer = gst_bin_get_by_name(GST_BIN(pipeline), // "primary-nvinference-engine"); - nv_infer_server_manager->attach_probe_to_element( - nv_osd_manager->nvosd); // nvinfer Or use "nvtracker" if after - // tracker + // nv_infer_server_manager->attach_probe_to_element( + // nv_osd_manager->nvosd); // nvinfer Or use "nvtracker" if after + // tracker // gst_object_unref(nvinfer); nv_tracker_manager->create_nv_tracker(); - nv_tracker_manager->attach_probe_to_element( - nv_tracker_manager->tracker); // nvinfer Or use "nvtracker" if after + nv_tracker_manager + ->attach_probe_to_element(); // nvinfer Or use "nvtracker" if after + + nv_osd_manager + ->attach_probe_to_element(); // nvinfer Or use "nvtracker" if after message_handling->create_message_handler(pipeline, g_run_forever, loop); setup_pipeline();