Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/gst/elements/gvafpscounter/fpscounter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#include <cmath>
#include <numeric>

#include <gst/analytics/analytics.h>

namespace {
constexpr double TIME_THRESHOLD = 0.1;
using seconds_double = std::chrono::duration<double>;
Expand All @@ -35,6 +37,22 @@ bool IterativeFpsCounter::NewFrame(const std::string &element_name, FILE *output
if (output == nullptr)
return false;

// Count detected regions of interest
GstAnalyticsRelationMeta *relation_meta = gst_buffer_get_analytics_relation_meta(buffer);
if (relation_meta) {
gpointer state = NULL;
GstAnalyticsODMtd od_mtd;
size_t count = 0;

while (
gst_analytics_relation_meta_iterate(relation_meta, &state, gst_analytics_od_mtd_get_mtd_type(), &od_mtd)) {
++count;
}

detections += count;
}


auto now = std::chrono::high_resolution_clock::now();
if (print_std_dev) {
double millis = std::chrono::duration_cast<std::chrono::microseconds>(now - last_time).count() * MICRO_TO_MILLI;
Expand Down
7 changes: 6 additions & 1 deletion src/gst/elements/gvafpscounter/fpscounter.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class IterativeFpsCounter : public FpsCounter {
IterativeFpsCounter(unsigned starting_frame, unsigned interval, bool average, bool print_std_dev,
bool print_latency)
: starting_frame(starting_frame), interval(interval), average(average), print_each_stream(true),
total_frames(0), avg_fps(0.0), eos_result_reported(false), print_std_dev(print_std_dev),
total_frames(0), detections(0), avg_fps(0.0), eos_result_reported(false), print_std_dev(print_std_dev),
print_latency(print_latency) {
}
bool NewFrame(const std::string &element_name, FILE *output, GstBuffer *buffer) override;
Expand All @@ -40,13 +40,18 @@ class IterativeFpsCounter : public FpsCounter {
std::lock_guard<std::mutex> lock(mutex);
return avg_fps;
}
unsigned get_detections() {
std::lock_guard<std::mutex> lock(mutex);
return detections;
}

protected:
unsigned starting_frame;
unsigned interval;
bool average;
bool print_each_stream;
unsigned total_frames;
unsigned detections;
float avg_fps;
std::chrono::time_point<std::chrono::high_resolution_clock> init_time;
std::chrono::time_point<std::chrono::high_resolution_clock> last_time;
Expand Down
4 changes: 3 additions & 1 deletion src/gst/elements/gvafpscounter/fpscounter_c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,10 @@ void fps_counter_new_frame(GstBuffer *buffer, const char *element_name, void *gs
counter->second->NewFrame(element_name, output, buffer);
if (gstgvafpscounter && counter->first == "average") {
auto iterative_counter = std::dynamic_pointer_cast<IterativeFpsCounter>(counter->second);
if (iterative_counter)
if (iterative_counter) {
((GstGvaFpscounter *)gstgvafpscounter)->avg_fps = iterative_counter->get_avg_fps();
((GstGvaFpscounter *)gstgvafpscounter)->detections = iterative_counter->get_detections();
}
}
}
} catch (std::exception &e) {
Expand Down
15 changes: 14 additions & 1 deletion src/gst/elements/gvafpscounter/gstgvafpscounter.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ enum {
PROP_READ_PIPE,
PROP_PRINT_STD_DEV,
PROP_PRINT_LATENCY,
PROP_AVG_FPS
PROP_AVG_FPS,
PROP_DETECTIONS
};

#define DEFAULT_INTERVAL "1"
Expand All @@ -47,6 +48,9 @@ enum {
#define DEFAULT_AVG_FPS 0.0
#define DEFAULT_AVG_FPS_MIN 0.0
#define DEFAULT_AVG_FPS_MAX G_MAXFLOAT
#define DEFAULT_DETECTIONS 0
#define DEFAULT_MIN_DETECTIONS 0
#define DEFAULT_MAX_DETECTIONS UINT_MAX

/* prototypes */
static void gst_gva_fpscounter_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec);
Expand Down Expand Up @@ -123,6 +127,11 @@ static void gst_gva_fpscounter_class_init(GstGvaFpscounterClass *klass) {
"The average frames per second, read-only parameter",
DEFAULT_AVG_FPS_MIN, DEFAULT_AVG_FPS_MAX, DEFAULT_AVG_FPS,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property(gobject_class, PROP_DETECTIONS,
g_param_spec_uint("detections", "For internal use only",
"For internal use only",
DEFAULT_MIN_DETECTIONS, DEFAULT_MAX_DETECTIONS, DEFAULT_DETECTIONS,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
}

static void gst_gva_fpscounter_init(GstGvaFpscounter *gva_fpscounter) {
Expand All @@ -137,6 +146,7 @@ static void gst_gva_fpscounter_init(GstGvaFpscounter *gva_fpscounter) {
gva_fpscounter->print_std_dev = DEFAULT_PRINT_STD_DEV;
gva_fpscounter->print_latency = DEFAULT_PRINT_LATENCY;
gva_fpscounter->avg_fps = DEFAULT_AVG_FPS;
gva_fpscounter->detections = DEFAULT_DETECTIONS;
}

void gst_gva_fpscounter_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec) {
Expand Down Expand Up @@ -165,6 +175,9 @@ void gst_gva_fpscounter_get_property(GObject *object, guint property_id, GValue
case PROP_AVG_FPS:
g_value_set_float(value, gvafpscounter->avg_fps);
break;
case PROP_DETECTIONS:
g_value_set_uint(value, gvafpscounter->detections);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
break;
Expand Down
1 change: 1 addition & 0 deletions src/gst/elements/gvafpscounter/gstgvafpscounter.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ struct _GstGvaFpscounter {
GstBaseTransform base_gvafpscounter;
gchar *interval;
guint starting_frame;
guint detections;
gfloat avg_fps;
gchar *write_pipe;
gchar *read_pipe;
Expand Down
Loading