Add fps pad probe

This commit is contained in:
Barzan Hayati 2025-07-01 23:26:43 +00:00
parent 716474f473
commit 3476f2a268
2 changed files with 36 additions and 1 deletions

View File

@ -48,6 +48,39 @@ char* createName(const char* str, int num) {
return result;
}
GstPadProbeReturn PipelineManager::fps_probe(GstPad* pad, GstPadProbeInfo* info,
gpointer user_data) {
(void)pad; // This explicitly marks it as unused
(void)user_data; // This explicitly marks it as unused
static guint64 frame_count_fps_probe = 0;
static auto last_time_fps_probe = std::chrono::steady_clock::now();
if (GST_PAD_PROBE_INFO_TYPE(info) & GST_PAD_PROBE_TYPE_BUFFER) {
frame_count_fps_probe++;
if (frame_count_fps_probe % 30 == 0) { // Calculate FPS every 30 frames
auto current_time = std::chrono::steady_clock::now();
auto duration =
std::chrono::duration_cast<std::chrono::milliseconds>(
current_time - last_time_fps_probe)
.count();
double fps = 30000.0 / duration;
g_print("fps_probe FPS: %.2f\n", fps);
last_time_fps_probe = current_time;
}
}
return GST_PAD_PROBE_OK;
}
void PipelineManager::get_fps() {
// 2. Add pad probe to get FPS
GstElement* element = gst_bin_get_by_name(
GST_BIN(pipeline), "nvvideo-converter"); // or any processing element
GstPad* pad = gst_element_get_static_pad(element, "src");
gst_pad_add_probe(pad, GST_PAD_PROBE_TYPE_BUFFER, fps_probe, NULL, NULL);
gst_object_unref(pad);
gst_object_unref(element);
}
void PipelineManager::playing_pipeline(int num_sources, char** url_camera) {
/* Set the pipeline to "playing" state */
@ -59,7 +92,6 @@ void PipelineManager::playing_pipeline(int num_sources, char** url_camera) {
GST_DEBUG_BIN_TO_DOT_FILE_WITH_TS(GST_BIN(pipeline),
GST_DEBUG_GRAPH_SHOW_ALL,
sink_manager->output_sink.c_str());
gst_element_set_state(pipeline, GST_STATE_PLAYING);
}
@ -246,6 +278,7 @@ bool PipelineManager::create_pipeline_elements(int num_sources,
NULL);
gst_object_unref(sink_pad);
get_fps();
playing_pipeline(num_sources, url_camera);
check_playing_pipeline();

View File

@ -53,6 +53,8 @@ class PipelineManager {
gpointer);
static gboolean event_thread_func(gpointer);
static gboolean check_pipeline_state(gpointer);
static GstPadProbeReturn fps_probe(GstPad *, GstPadProbeInfo *, gpointer);
void get_fps();
void check_playing_pipeline();
~PipelineManager();
};