Add fps osd sink
This commit is contained in:
parent
3476f2a268
commit
a6efa389f0
@ -48,6 +48,29 @@ char* createName(const char* str, int num) {
|
||||
return result;
|
||||
}
|
||||
|
||||
GstPadProbeReturn PipelineManager::osd_sink_pad_buffer_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_osd_sink = 0;
|
||||
static auto last_time_osd_sink = std::chrono::steady_clock::now();
|
||||
GstBuffer* buf = (GstBuffer*)info->data;
|
||||
NvDsBatchMeta* batch_meta = gst_buffer_get_nvds_batch_meta(buf);
|
||||
|
||||
frame_count_osd_sink += batch_meta->num_frames_in_batch;
|
||||
|
||||
if (frame_count_osd_sink % 60 == 0) {
|
||||
auto now = std::chrono::steady_clock::now();
|
||||
double ms = std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||
now - last_time_osd_sink)
|
||||
.count();
|
||||
double fps = 60000.0 / ms;
|
||||
g_print("FPS_osd_sink: %.2f\n", fps);
|
||||
last_time_osd_sink = now;
|
||||
}
|
||||
return GST_PAD_PROBE_OK;
|
||||
}
|
||||
|
||||
GstPadProbeReturn PipelineManager::fps_probe(GstPad* pad, GstPadProbeInfo* info,
|
||||
gpointer user_data) {
|
||||
(void)pad; // This explicitly marks it as unused
|
||||
@ -81,6 +104,16 @@ 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);
|
||||
gst_object_unref(sink_pad);
|
||||
gst_object_unref(osd);
|
||||
}
|
||||
|
||||
void PipelineManager::playing_pipeline(int num_sources, char** url_camera) {
|
||||
/* Set the pipeline to "playing" state */
|
||||
|
||||
@ -279,6 +312,7 @@ bool PipelineManager::create_pipeline_elements(int num_sources,
|
||||
gst_object_unref(sink_pad);
|
||||
|
||||
get_fps();
|
||||
get_fps_osd();
|
||||
playing_pipeline(num_sources, url_camera);
|
||||
|
||||
check_playing_pipeline();
|
||||
|
||||
@ -54,7 +54,11 @@ class PipelineManager {
|
||||
static gboolean event_thread_func(gpointer);
|
||||
static gboolean check_pipeline_state(gpointer);
|
||||
static GstPadProbeReturn fps_probe(GstPad *, GstPadProbeInfo *, gpointer);
|
||||
static GstPadProbeReturn osd_sink_pad_buffer_probe(GstPad *,
|
||||
GstPadProbeInfo *,
|
||||
gpointer);
|
||||
void get_fps();
|
||||
void get_fps_osd();
|
||||
void check_playing_pipeline();
|
||||
~PipelineManager();
|
||||
};
|
||||
Loading…
x
Reference in New Issue
Block a user