Correct fps buffer probe
This commit is contained in:
parent
6126025eac
commit
2e25249117
@ -71,6 +71,16 @@ GstPadProbeReturn PipelineManager::osd_sink_pad_buffer_probe(
|
|||||||
return GST_PAD_PROBE_OK;
|
return GST_PAD_PROBE_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PipelineManager::get_fps_osd() {
|
||||||
|
GstElement* osd = gst_bin_get_by_name(
|
||||||
|
GST_BIN(pipeline), "nv-onscreendisplay"); // Or "nvinfer", etc.
|
||||||
|
GstPad* sink_pad = gst_element_get_static_pad(osd, "sink");
|
||||||
|
gst_pad_add_probe(sink_pad, GST_PAD_PROBE_TYPE_BUFFER,
|
||||||
|
osd_sink_pad_buffer_probe, NULL, NULL);
|
||||||
|
gst_object_unref(sink_pad);
|
||||||
|
gst_object_unref(osd);
|
||||||
|
}
|
||||||
|
|
||||||
GstPadProbeReturn PipelineManager::fps_probe(GstPad* pad, GstPadProbeInfo* info,
|
GstPadProbeReturn PipelineManager::fps_probe(GstPad* pad, GstPadProbeInfo* info,
|
||||||
gpointer user_data) {
|
gpointer user_data) {
|
||||||
(void)pad; // This explicitly marks it as unused
|
(void)pad; // This explicitly marks it as unused
|
||||||
@ -81,20 +91,20 @@ GstPadProbeReturn PipelineManager::fps_probe(GstPad* pad, GstPadProbeInfo* info,
|
|||||||
frame_count_fps_probe++;
|
frame_count_fps_probe++;
|
||||||
|
|
||||||
if (frame_count_fps_probe % 30 == 0) { // Calculate FPS every 30 frames
|
if (frame_count_fps_probe % 30 == 0) { // Calculate FPS every 30 frames
|
||||||
auto current_time = std::chrono::steady_clock::now();
|
auto current_time_fps_probe = std::chrono::steady_clock::now();
|
||||||
auto duration =
|
auto duration =
|
||||||
std::chrono::duration_cast<std::chrono::milliseconds>(
|
std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||||
current_time - last_time_fps_probe)
|
current_time_fps_probe - last_time_fps_probe)
|
||||||
.count();
|
.count();
|
||||||
double fps = 30000.0 / duration;
|
double fps = 30000.0 / duration;
|
||||||
g_print("fps_probe FPS: %.2f\n", fps);
|
g_print("fps_probe FPS: %.2f\n", fps);
|
||||||
last_time_fps_probe = current_time;
|
last_time_fps_probe = current_time_fps_probe;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return GST_PAD_PROBE_OK;
|
return GST_PAD_PROBE_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PipelineManager::get_fps() {
|
void PipelineManager::get_fps_probe() {
|
||||||
// 2. Add pad probe to get FPS
|
// 2. Add pad probe to get FPS
|
||||||
GstElement* element = gst_bin_get_by_name(
|
GstElement* element = gst_bin_get_by_name(
|
||||||
GST_BIN(pipeline), "nvvideo-converter"); // or any processing element
|
GST_BIN(pipeline), "nvvideo-converter"); // or any processing element
|
||||||
@ -104,14 +114,38 @@ void PipelineManager::get_fps() {
|
|||||||
gst_object_unref(element);
|
gst_object_unref(element);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PipelineManager::get_fps_osd() {
|
GstPadProbeReturn PipelineManager::buffer_probe(GstPad* pad,
|
||||||
GstElement* osd = gst_bin_get_by_name(
|
GstPadProbeInfo* info,
|
||||||
GST_BIN(pipeline), "nv-onscreendisplay"); // Or "nvinfer", etc.
|
gpointer user_data) {
|
||||||
GstPad* sink_pad = gst_element_get_static_pad(osd, "sink");
|
(void)pad; // This explicitly marks it as unused
|
||||||
gst_pad_add_probe(sink_pad, GST_PAD_PROBE_TYPE_BUFFER,
|
(void)info; // This explicitly marks it as unused
|
||||||
osd_sink_pad_buffer_probe, NULL, NULL);
|
(void)user_data; // This explicitly marks it as unused
|
||||||
|
static guint frame_count_buffer_probe = 0;
|
||||||
|
static auto last_time_buffer_probe = std::chrono::steady_clock::now();
|
||||||
|
|
||||||
|
frame_count_buffer_probe++;
|
||||||
|
auto current_time_buffer_probe = std::chrono::steady_clock::now();
|
||||||
|
auto elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||||
|
current_time_buffer_probe - last_time_buffer_probe)
|
||||||
|
.count();
|
||||||
|
|
||||||
|
if (elapsed >= 1000) { // Update every second
|
||||||
|
g_print("FPS_buffer_probe: %ld\n",
|
||||||
|
frame_count_buffer_probe * 1000 / elapsed);
|
||||||
|
frame_count_buffer_probe = 0;
|
||||||
|
last_time_buffer_probe = current_time_buffer_probe;
|
||||||
|
}
|
||||||
|
|
||||||
|
return GST_PAD_PROBE_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PipelineManager::get_fps_buffer_probe() {
|
||||||
|
// --- BUFFER PROBE FOR FPS ---
|
||||||
|
GstPad* sink_pad = gst_element_get_static_pad(
|
||||||
|
nv_video_convert_manager->nvvidconv, "src"); // Or any element's pad
|
||||||
|
gst_pad_add_probe(sink_pad, GST_PAD_PROBE_TYPE_BUFFER, buffer_probe, NULL,
|
||||||
|
NULL);
|
||||||
gst_object_unref(sink_pad);
|
gst_object_unref(sink_pad);
|
||||||
gst_object_unref(osd);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PipelineManager::playing_pipeline(int num_sources, char** url_camera) {
|
void PipelineManager::playing_pipeline(int num_sources, char** url_camera) {
|
||||||
@ -268,7 +302,8 @@ bool PipelineManager::create_pipeline_elements(int num_sources,
|
|||||||
message_handling->create_message_handler(pipeline, g_run_forever, loop);
|
message_handling->create_message_handler(pipeline, g_run_forever, loop);
|
||||||
setup_pipeline();
|
setup_pipeline();
|
||||||
|
|
||||||
get_fps();
|
get_fps_buffer_probe();
|
||||||
|
get_fps_probe();
|
||||||
get_fps_osd();
|
get_fps_osd();
|
||||||
playing_pipeline(num_sources, url_camera);
|
playing_pipeline(num_sources, url_camera);
|
||||||
|
|
||||||
|
|||||||
@ -51,11 +51,14 @@ class PipelineManager {
|
|||||||
void set_cuda_device();
|
void set_cuda_device();
|
||||||
static gboolean event_thread_func(gpointer);
|
static gboolean event_thread_func(gpointer);
|
||||||
static gboolean check_pipeline_state(gpointer);
|
static gboolean check_pipeline_state(gpointer);
|
||||||
|
static GstPadProbeReturn buffer_probe(GstPad *, GstPadProbeInfo *,
|
||||||
|
gpointer);
|
||||||
static GstPadProbeReturn fps_probe(GstPad *, GstPadProbeInfo *, gpointer);
|
static GstPadProbeReturn fps_probe(GstPad *, GstPadProbeInfo *, gpointer);
|
||||||
static GstPadProbeReturn osd_sink_pad_buffer_probe(GstPad *,
|
static GstPadProbeReturn osd_sink_pad_buffer_probe(GstPad *,
|
||||||
GstPadProbeInfo *,
|
GstPadProbeInfo *,
|
||||||
gpointer);
|
gpointer);
|
||||||
void get_fps();
|
void get_fps_buffer_probe();
|
||||||
|
void get_fps_probe();
|
||||||
void get_fps_osd();
|
void get_fps_osd();
|
||||||
void check_playing_pipeline();
|
void check_playing_pipeline();
|
||||||
~PipelineManager();
|
~PipelineManager();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user