-
Notifications
You must be signed in to change notification settings - Fork 166
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Gvaclassify signal #157
base: master
Are you sure you want to change the base?
Gvaclassify signal #157
Changes from 1 commit
641ece5
52e60e2
5352d2b
6cc82fb
81a5aae
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,14 +17,22 @@ | |
#include <gst/base/gstbasetransform.h> | ||
#include <gst/gst.h> | ||
#include <gst/video/video.h> | ||
#include <gst/video/gstvideometa.h> | ||
|
||
#define ELEMENT_LONG_NAME "Object classification (requires GstVideoRegionOfInterestMeta on input)" | ||
#define ELEMENT_DESCRIPTION ELEMENT_LONG_NAME | ||
#define DEFAULT_SIGNAL_CLASSIFY_ROI FALSE | ||
|
||
enum { | ||
PROP_0, | ||
PROP_OBJECT_CLASS, | ||
PROP_RECLASSIFY_INTERVAL, | ||
PROP_SIGNAL_CLASSIFY_ROI, | ||
}; | ||
|
||
enum { | ||
SIGNAL_CLASSIFY_ROI, | ||
LAST_SIGNAL | ||
}; | ||
|
||
#define DEFAULT_OBJECT_CLASS "" | ||
|
@@ -46,6 +54,8 @@ static void gst_gva_classify_finalize(GObject *); | |
static void gst_gva_classify_cleanup(GstGvaClassify *); | ||
static void on_base_inference_initialized(GvaBaseInference *base_inference); | ||
|
||
static guint gst_classify_signals[LAST_SIGNAL] = { 0 }; | ||
|
||
void gst_gva_classify_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec) { | ||
GstGvaClassify *gvaclassify = (GstGvaClassify *)(object); | ||
|
||
|
@@ -75,6 +85,10 @@ void gst_gva_classify_set_property(GObject *object, guint property_id, const GVa | |
} | ||
break; | ||
} | ||
case PROP_SIGNAL_CLASSIFY_ROI: { | ||
gvaclassify->signal_classify_roi = g_value_get_boolean(value); | ||
break; | ||
} | ||
default: { | ||
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec); | ||
break; | ||
|
@@ -94,6 +108,9 @@ void gst_gva_classify_get_property(GObject *object, guint property_id, GValue *v | |
case PROP_RECLASSIFY_INTERVAL: | ||
g_value_set_uint(value, gvaclassify->reclassify_interval); | ||
break; | ||
case PROP_SIGNAL_CLASSIFY_ROI: | ||
g_value_set_boolean(value, gvaclassify->signal_classify_roi); | ||
break; | ||
default: | ||
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec); | ||
break; | ||
|
@@ -138,6 +155,30 @@ void gst_gva_classify_class_init(GstGvaClassifyClass *gvaclassify_class) { | |
"inference interval)", | ||
DEFAULT_MIN_RECLASSIFY_INTERVAL, DEFAULT_MAX_RECLASSIFY_INTERVAL, DEFAULT_RECLASSIFY_INTERVAL, | ||
(GParamFlags)(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); | ||
|
||
// Property that determines whether or not the "about-to-classify" signal | ||
// should be raised before classifying a tracked object. | ||
g_object_class_install_property( | ||
gobject_class, PROP_SIGNAL_CLASSIFY_ROI, | ||
g_param_spec_boolean( | ||
"signal-classify-roi", "Signal Classify ROI", | ||
"Send a signal before classifying a tracked object.", | ||
DEFAULT_SIGNAL_CLASSIFY_ROI, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); | ||
|
||
// Signal which indicates to a subscriber that classification of the ROI is | ||
// about to occur and allows the subscriber to request that classification | ||
// be skipped due to some aspect of the ROI's metadata. | ||
// Return value: | ||
// FALSE - classification should be run. | ||
// TRUE - classification should be skipped | ||
// Note: g_signal_emit resets the return value to the default, in this | ||
// case FALSE, when a handler is not connected. | ||
gst_classify_signals[SIGNAL_CLASSIFY_ROI] = | ||
g_signal_new( | ||
"classify-roi", G_TYPE_FROM_CLASS (gvaclassify_class), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider renaming to something like "should-skip-roi", since that's the effect of a handler returning There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstGvaClassifyClass, classify_roi), | ||
NULL, NULL, NULL, G_TYPE_BOOLEAN, 1, | ||
GST_VIDEO_REGION_OF_INTEREST_META_API_TYPE | G_SIGNAL_TYPE_STATIC_SCOPE); | ||
} | ||
|
||
void gst_gva_classify_init(GstGvaClassify *gvaclassify) { | ||
|
@@ -151,6 +192,7 @@ void gst_gva_classify_init(GstGvaClassify *gvaclassify) { | |
gvaclassify->base_inference.is_full_frame = FALSE; | ||
gvaclassify->object_class = g_strdup(DEFAULT_OBJECT_CLASS); | ||
gvaclassify->reclassify_interval = DEFAULT_RECLASSIFY_INTERVAL; | ||
gvaclassify->signal_classify_roi_id = gst_classify_signals[SIGNAL_CLASSIFY_ROI]; | ||
gvaclassify->classification_history = create_classification_history(gvaclassify); | ||
if (gvaclassify->classification_history == NULL) | ||
return; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we can address or otherwise eliminate the apparent overhead, then this property can be eliminated.
The 34 ns I measured is at least 5 orders of magnitude below the typical cost of classification. So, we should be fine to always emit the signal, if it turns out that the "0.4% increase in CPU time" was either a measurement error or a real performance problem we can fix.