From be3aed33bac816ff7147868436bc3b5cb062441c Mon Sep 17 00:00:00 2001 From: Barzan Hayati Date: Tue, 1 Jul 2025 22:39:36 +0000 Subject: [PATCH] Add fps buffer probe second method --- CMakeLists.txt | 3 ++- src/pipeline_manager.cpp | 30 +++++++++++++++++++++--------- src/pipeline_manager.hpp | 2 ++ 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ef13dd4..19b0bdb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -41,6 +41,7 @@ else() link_directories(/usr/local/cuda/lib64) endif() + include_directories(/usr/lib/x86_64-linux-gnu/glib-2.0/include) include_directories(/opt/nvidia/deepstream/deepstream-7.1/sources/includes) include_directories(/usr/include/gstreamer-1.0) @@ -94,4 +95,4 @@ target_link_libraries(${PROJECT_NAME} ${GLIB_LIBRARIES}) target_link_libraries(${PROJECT_NAME} gstbase-1.0 gstreamer-1.0 gstrtp-1.0 gstvideo-1.0 gstrtspserver-1.0) target_link_libraries(${PROJECT_NAME} cudart cuda) target_link_libraries(${PROJECT_NAME} nvdsgst_infer nvds_meta nvds_inferutils - nvds_utils nvdsgst_helper)#nvdsgst_metnvdsa \ No newline at end of file + nvdsgst_meta nvds_utils nvdsgst_helper)#nvdsgst_metnvdsa \ No newline at end of file diff --git a/src/pipeline_manager.cpp b/src/pipeline_manager.cpp index cfbf5fe..8abe47d 100644 --- a/src/pipeline_manager.cpp +++ b/src/pipeline_manager.cpp @@ -69,19 +69,31 @@ GstPadProbeReturn PipelineManager::buffer_probe(GstPad* pad, (void)pad; // This explicitly marks it as unused (void)info; // This explicitly marks it as unused (void)user_data; // This explicitly marks it as unused - static guint frame_count = 0; + static guint64 frame_count = 0; static auto last_time = std::chrono::steady_clock::now(); - frame_count++; - auto current_time = std::chrono::steady_clock::now(); - auto elapsed = std::chrono::duration_cast( - current_time - last_time) - .count(); + GstBuffer* buffer = GST_PAD_PROBE_INFO_BUFFER(info); + NvDsBatchMeta* batch_meta = gst_buffer_get_nvds_batch_meta(buffer); - if (elapsed >= 1000) { // Update every second - g_print("FPS: %ld\n", frame_count * 1000 / elapsed); + if (batch_meta) { + for (NvDsMetaList* l = batch_meta->frame_meta_list; l != NULL; + l = l->next) { + NvDsFrameMeta* frame_meta = (NvDsFrameMeta*)l->data; + (void)frame_meta; // This explicitly marks it as unused + frame_count++; + } + } + + // Calculate FPS + auto now = std::chrono::steady_clock::now(); + auto elapsed = + std::chrono::duration_cast(now - last_time) + .count(); + + if (elapsed >= 1000) { + g_print("FPS: %.2f\n", (double)frame_count * 1000 / elapsed); frame_count = 0; - last_time = current_time; + last_time = now; } return GST_PAD_PROBE_OK; diff --git a/src/pipeline_manager.hpp b/src/pipeline_manager.hpp index 32663ce..8851848 100644 --- a/src/pipeline_manager.hpp +++ b/src/pipeline_manager.hpp @@ -1,8 +1,10 @@ #include #include +#include #include "cuda_runtime_api.h" #include "gstds_example_manager.hpp" +#include "gstnvdsmeta.h" #include "message_handling.hpp" #include "nv_ds_logger_manager.hpp" #include "nv_osd_manager.hpp"