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;
|
||||
}
|
||||
|
||||
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,
|
||||
gpointer user_data) {
|
||||
(void)pad; // This explicitly marks it as unused
|
||||
@ -81,20 +91,20 @@ GstPadProbeReturn PipelineManager::fps_probe(GstPad* pad, GstPadProbeInfo* info,
|
||||
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 current_time_fps_probe = std::chrono::steady_clock::now();
|
||||
auto duration =
|
||||
std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||
current_time - last_time_fps_probe)
|
||||
current_time_fps_probe - last_time_fps_probe)
|
||||
.count();
|
||||
double fps = 30000.0 / duration;
|
||||
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;
|
||||
}
|
||||
|
||||
void PipelineManager::get_fps() {
|
||||
void PipelineManager::get_fps_probe() {
|
||||
// 2. Add pad probe to get FPS
|
||||
GstElement* element = gst_bin_get_by_name(
|
||||
GST_BIN(pipeline), "nvvideo-converter"); // or any processing element
|
||||
@ -104,14 +114,38 @@ void PipelineManager::get_fps() {
|
||||
gst_object_unref(element);
|
||||
}
|
||||
|
||||
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);
|
||||
GstPadProbeReturn PipelineManager::buffer_probe(GstPad* pad,
|
||||
GstPadProbeInfo* info,
|
||||
gpointer user_data) {
|
||||
(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_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(osd);
|
||||
}
|
||||
|
||||
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);
|
||||
setup_pipeline();
|
||||
|
||||
get_fps();
|
||||
get_fps_buffer_probe();
|
||||
get_fps_probe();
|
||||
get_fps_osd();
|
||||
playing_pipeline(num_sources, url_camera);
|
||||
|
||||
|
||||
@ -51,11 +51,14 @@ class PipelineManager {
|
||||
void set_cuda_device();
|
||||
static gboolean event_thread_func(gpointer);
|
||||
static gboolean check_pipeline_state(gpointer);
|
||||
static GstPadProbeReturn buffer_probe(GstPad *, GstPadProbeInfo *,
|
||||
gpointer);
|
||||
static GstPadProbeReturn fps_probe(GstPad *, GstPadProbeInfo *, gpointer);
|
||||
static GstPadProbeReturn osd_sink_pad_buffer_probe(GstPad *,
|
||||
GstPadProbeInfo *,
|
||||
gpointer);
|
||||
void get_fps();
|
||||
void get_fps_buffer_probe();
|
||||
void get_fps_probe();
|
||||
void get_fps_osd();
|
||||
void check_playing_pipeline();
|
||||
~PipelineManager();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user