Fix frame per second calculation
This commit is contained in:
parent
23cf05662e
commit
3dcf33cca3
@ -1,9 +1,9 @@
|
||||
#include "pipeline_manager.hpp"
|
||||
#define GPU_ID 0
|
||||
|
||||
double PipelineManager::fps_buffer_probe = 0;
|
||||
double PipelineManager::fps_probe = 0;
|
||||
double PipelineManager::fps_osd = 0;
|
||||
double PipelineManager::tee_fps = 0.0;
|
||||
double PipelineManager::video_converter_fps = 0.0;
|
||||
double PipelineManager::osd_fps = 0.0;
|
||||
guint64 PipelineManager::frame_count_osd_sink = 0;
|
||||
guint64 PipelineManager::frame_count_fps_probe = 0;
|
||||
guint64 PipelineManager::frame_count_buffer_probe = 0;
|
||||
@ -16,14 +16,7 @@ std::chrono::time_point<std::chrono::steady_clock>
|
||||
|
||||
PipelineManager::PipelineManager() { ; }
|
||||
|
||||
PipelineManager::PipelineManager(int num_sources, char** url_camera)
|
||||
: csv_fp("csv_fps.csv") {
|
||||
if (!csv_fp.is_open()) {
|
||||
std::cerr << "Failed to open csv_fp csv file.\n";
|
||||
throw std::runtime_error("Failed to open csv_fps_buffer_probe.csv");
|
||||
}
|
||||
// Write CSV header
|
||||
csv_fp << "Name,FPS\n";
|
||||
PipelineManager::PipelineManager(int num_sources, char** url_camera) {
|
||||
g_setenv("GST_DEBUG_DUMP_DOT_DIR", ".", TRUE);
|
||||
gst_init(&num_sources, &url_camera);
|
||||
g_run_forever = atoi("0");
|
||||
@ -72,21 +65,12 @@ char* createName(const char* str, int num) {
|
||||
return result;
|
||||
}
|
||||
|
||||
void PipelineManager::set_row_csv_fps(const std::string& name, double fps) {
|
||||
if (!csv_fp.is_open()) {
|
||||
std::cerr << "Failed to write: stream not open for " << name << "\n";
|
||||
return;
|
||||
} else {
|
||||
csv_fp << name << "," << fps << "\n";
|
||||
// std::cout << "Wrote: " << name << " = " << fps << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
GstPadProbeReturn PipelineManager::osd_sink_pad_buffer_probe(
|
||||
GstPad* pad, GstPadProbeInfo* info, gpointer user_data) {
|
||||
GstPadProbeReturn PipelineManager::osd_sink_fps(GstPad* pad,
|
||||
GstPadProbeInfo* info,
|
||||
gpointer user_data) {
|
||||
(void)pad; // This explicitly marks it as unused
|
||||
(void)user_data; // This explicitly marks it as unused
|
||||
auto* self = static_cast<PipelineManager*>(user_data);
|
||||
// auto* self = static_cast<PipelineManager*>(user_data);
|
||||
|
||||
GstBuffer* buf = (GstBuffer*)info->data;
|
||||
NvDsBatchMeta* batch_meta = gst_buffer_get_nvds_batch_meta(buf);
|
||||
@ -99,9 +83,7 @@ GstPadProbeReturn PipelineManager::osd_sink_pad_buffer_probe(
|
||||
long long ms = std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||
now - last_time_osd_sink)
|
||||
.count();
|
||||
fps_osd = 60000.0 / ms;
|
||||
self->set_row_csv_fps("fps_osd", fps_osd);
|
||||
// std::cout << "Writing fps_osd...\n";
|
||||
osd_fps = 60000.0 / ms;
|
||||
// g_print("FPS_osd_sink: %.2f\n", fps_osd);
|
||||
last_time_osd_sink = now;
|
||||
}
|
||||
@ -112,17 +94,17 @@ 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, this, NULL);
|
||||
gst_pad_add_probe(sink_pad, GST_PAD_PROBE_TYPE_BUFFER, osd_sink_fps, this,
|
||||
NULL);
|
||||
gst_object_unref(sink_pad);
|
||||
gst_object_unref(osd);
|
||||
}
|
||||
|
||||
GstPadProbeReturn PipelineManager::probe_fps(GstPad* pad, GstPadProbeInfo* info,
|
||||
gpointer user_data) {
|
||||
GstPadProbeReturn PipelineManager::video_converter_src_fps(
|
||||
GstPad* pad, GstPadProbeInfo* info, gpointer user_data) {
|
||||
(void)pad; // This explicitly marks it as unused
|
||||
(void)user_data; // This explicitly marks it as unused
|
||||
auto* self = static_cast<PipelineManager*>(user_data);
|
||||
// auto* self = static_cast<PipelineManager*>(user_data);
|
||||
if (GST_PAD_PROBE_INFO_TYPE(info) & GST_PAD_PROBE_TYPE_BUFFER) {
|
||||
frame_count_fps_probe++;
|
||||
|
||||
@ -133,58 +115,56 @@ GstPadProbeReturn PipelineManager::probe_fps(GstPad* pad, GstPadProbeInfo* info,
|
||||
std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||
current_time_fps_probe - last_time_fps_probe)
|
||||
.count();
|
||||
fps_probe = 30000.0 / duration;
|
||||
video_converter_fps = 30000.0 / duration;
|
||||
// g_print("fps_probe FPS: %.2f\n", fps_probe);
|
||||
last_time_fps_probe = current_time_fps_probe;
|
||||
self->set_row_csv_fps("fps_probe", fps_probe);
|
||||
// std::cout << "Writing fps_probe...\n";
|
||||
}
|
||||
}
|
||||
return GST_PAD_PROBE_OK;
|
||||
}
|
||||
|
||||
void PipelineManager::get_fps_probe() {
|
||||
void PipelineManager::get_fps_video_converter() {
|
||||
// 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, probe_fps, this, NULL);
|
||||
gst_pad_add_probe(pad, GST_PAD_PROBE_TYPE_BUFFER, video_converter_src_fps,
|
||||
NULL, NULL);
|
||||
gst_object_unref(pad);
|
||||
gst_object_unref(element);
|
||||
}
|
||||
|
||||
GstPadProbeReturn PipelineManager::buffer_probe(GstPad* pad,
|
||||
GstPadProbeReturn PipelineManager::tee_sink_fps(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
|
||||
|
||||
auto* self = static_cast<PipelineManager*>(user_data);
|
||||
// auto* self = static_cast<PipelineManager*>(user_data);
|
||||
frame_count_buffer_probe++;
|
||||
std::chrono::time_point<std::chrono::steady_clock>
|
||||
current_time_buffer_probe = std::chrono::steady_clock::now();
|
||||
long long elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||
current_time_buffer_probe - last_time_buffer_probe)
|
||||
.count();
|
||||
fps_buffer_probe =
|
||||
(double)(frame_count_buffer_probe * 1000 / (double)elapsed);
|
||||
tee_fps = (double)(frame_count_buffer_probe * 1000 / (double)elapsed);
|
||||
if (elapsed >= 1000) { // Update every second
|
||||
// g_print("FPS_buffer_probe: %.2f\n", fps_buffer_probe);
|
||||
frame_count_buffer_probe = 0;
|
||||
last_time_buffer_probe = current_time_buffer_probe;
|
||||
std::cout << "==================== FPS in tee is "
|
||||
<< std::setprecision(4) << tee_fps
|
||||
<< " ====================" << std::endl;
|
||||
}
|
||||
self->set_row_csv_fps("fps_buffer_probe", fps_buffer_probe);
|
||||
// std::cout << "Writing fps_buffer_probe...\n";
|
||||
|
||||
return GST_PAD_PROBE_OK;
|
||||
}
|
||||
|
||||
void PipelineManager::get_fps_buffer_probe() {
|
||||
void PipelineManager::get_fps_tee() {
|
||||
// --- 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, this,
|
||||
tee_manager->tee, "sink"); // Or any element's pad
|
||||
gst_pad_add_probe(sink_pad, GST_PAD_PROBE_TYPE_BUFFER, tee_sink_fps, this,
|
||||
NULL);
|
||||
gst_object_unref(sink_pad);
|
||||
}
|
||||
@ -633,9 +613,9 @@ bool PipelineManager::create_pipeline_elements(int num_sources,
|
||||
message_handling->create_message_handler(pipeline, g_run_forever, loop);
|
||||
setup_pipeline();
|
||||
|
||||
get_fps_buffer_probe();
|
||||
get_fps_probe();
|
||||
get_fps_video_converter();
|
||||
get_fps_osd();
|
||||
get_fps_tee();
|
||||
|
||||
/* Add probe to get informed of the meta data generated, we add probe to
|
||||
* the source pad of PGIE's next queue element, since by that time, PGIE's
|
||||
|
||||
@ -47,12 +47,9 @@ class PipelineManager {
|
||||
NvMessageConverter *nv_message_converter_manager = new NvMessageConverter();
|
||||
NvMessageBroker *nv_message_broker_manager = new NvMessageBroker();
|
||||
TeeManager *tee_manager = new TeeManager();
|
||||
static double fps_buffer_probe;
|
||||
static double fps_probe;
|
||||
static double fps_osd;
|
||||
std::ofstream csv_fp;
|
||||
|
||||
void set_row_csv_fps(const std::string &, double);
|
||||
static double tee_fps;
|
||||
static double video_converter_fps;
|
||||
static double osd_fps;
|
||||
|
||||
typedef struct {
|
||||
TilerManager *tiler_manager;
|
||||
@ -88,14 +85,15 @@ class PipelineManager {
|
||||
last_time_buffer_probe;
|
||||
static gboolean event_thread_func(gpointer);
|
||||
static gboolean check_pipeline_state(gpointer);
|
||||
static GstPadProbeReturn buffer_probe(GstPad *, GstPadProbeInfo *,
|
||||
static GstPadProbeReturn tee_sink_fps(GstPad *, GstPadProbeInfo *,
|
||||
gpointer);
|
||||
static GstPadProbeReturn probe_fps(GstPad *, GstPadProbeInfo *, gpointer);
|
||||
static GstPadProbeReturn osd_sink_pad_buffer_probe(GstPad *,
|
||||
GstPadProbeInfo *,
|
||||
gpointer);
|
||||
void get_fps_buffer_probe();
|
||||
void get_fps_probe();
|
||||
static GstPadProbeReturn video_converter_src_fps(GstPad *,
|
||||
GstPadProbeInfo *,
|
||||
gpointer);
|
||||
static GstPadProbeReturn osd_sink_fps(GstPad *, GstPadProbeInfo *,
|
||||
gpointer);
|
||||
void get_fps_tee();
|
||||
void get_fps_video_converter();
|
||||
void get_fps_osd();
|
||||
bool check_playing_pipeline();
|
||||
~PipelineManager();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user