GStreamer plugin to control flow based on tensor values. More...
#include <nnstreamer_log.h>
#include <string.h>
#include <nnstreamer_subplugin.h>
#include <nnstreamer_util.h>
#include "gsttensor_if.h"
Go to the source code of this file.
Macros | |
#define | DBG (!tensor_if->silent) |
Macro for debug mode. More... | |
#define | GST_CAT_DEFAULT gst_tensor_if_debug |
#define | CAPS_STRING GST_TENSOR_CAP_DEFAULT "; " GST_TENSORS_CAP_DEFAULT |
#define | gst_tensor_if_parent_class parent_class |
#define | GST_TYPE_TENSOR_IF_CV (gst_tensor_if_cv_get_type ()) |
#define | GST_TYPE_TENSOR_IF_OP (gst_tensor_if_op_get_type ()) |
#define | GST_TYPE_TENSOR_IF_ACT (gst_tensor_if_act_get_type ()) |
#define | operator_func(cv, t, op, sv1, sv2, ret) |
Macro for operator function. More... | |
Enumerations | |
enum | { PROP_0, PROP_SILENT, PROP_CV, PROP_CV_OPTION, PROP_OP, PROP_SV, PROP_THEN, PROP_THEN_OPTION, PROP_ELSE, PROP_ELSE_OPTION } |
tensor_if properties More... | |
Functions | |
GST_DEBUG_CATEGORY_STATIC (gst_tensor_if_debug) | |
G_DEFINE_TYPE (GstTensorIf, gst_tensor_if, GST_TYPE_ELEMENT) | |
static void | gst_tensor_if_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) |
Setter for tensor_if properties. More... | |
static void | gst_tensor_if_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) |
Getter for tensor_if properties. More... | |
static GstFlowReturn | gst_tensor_if_chain (GstPad *pad, GstObject *parent, GstBuffer *buf) |
chain function for sink (gst element vmethod) More... | |
static gboolean | gst_tensor_if_event (GstPad *pad, GstObject *parent, GstEvent *event) |
event function for sink (gst element vmethod) More... | |
static void | gst_tensor_if_dispose (GObject *object) |
dispose function for tensor if (gst element vmethod) More... | |
static void | gst_tensor_if_install_properties (GObjectClass *gobject_class) |
Installs all the properties for tensor_if. More... | |
static GType | gst_tensor_if_cv_get_type (void) |
A private function to register GEnumValue array for the 'compared-value' property to a GType and return it. More... | |
static GType | gst_tensor_if_op_get_type (void) |
A private function to register GEnumValue array for the 'operator' property to a GType and return it. More... | |
static GType | gst_tensor_if_act_get_type (void) |
A private function to register GEnumValue array for the 'then' and 'else' properties to a GType and return it. More... | |
static void | gst_tensor_if_class_init (GstTensorIfClass *klass) |
initialize the tensor_if's class (GST Standard) More... | |
static void | gst_tensor_if_init (GstTensorIf *tensor_if) |
initialize the new element (GST Standard) instantiate pads and add them to element set pad callback functions initialize instance structure More... | |
static void | gst_tensor_if_remove_src_pads (GstTensorIf *tensor_if) |
function to remove srcpad list More... | |
static void | gst_tensor_if_set_property_glist (const GValue *value, GList **prop_list, const gchar *delimiters) |
Convert GValue to GList according to delimiters. More... | |
static void | gst_tensor_if_set_property_cv_option (const GValue *value, GList **prop_list) |
Convert GValue to GList for cv option. More... | |
static void | gst_tensor_if_set_property_supplied_value (const GValue *value, tensor_if_sv_s *sv, const gchar *delimiters) |
Convert GValue to GList according to delimiters. More... | |
static void | gst_tensor_if_configure_custom_prop (GstTensorIf *self) |
Set custom compared value property. More... | |
static void | gst_tensor_if_property_to_string (GValue *value, GList *prop_list, guint prop_id) |
Convert GList to GValue. More... | |
static void | gst_tensor_if_get_property_supplied_value (GValue *value, tensor_if_sv_s *sv) |
Convert GValue to supplied value according to delimiters. More... | |
static gboolean | gst_tensor_if_parse_caps (GstTensorIf *tensor_if, GstCaps *caps) |
Parse caps and configure tensors info. More... | |
static GstTensorPad * | gst_tensor_if_get_tensor_pad (GstTensorIf *tensor_if, GstTensorsConfig *config, gboolean *created, guint nth) |
Checking if the source pad is created and if not, create TensorPad. More... | |
static GstFlowReturn | gst_tensor_if_combine_flows (GstTensorIf *tensor_if, GstTensorPad *pad, GstFlowReturn ret) |
Check the status among sources in if. More... | |
switch (cv->type) | |
static gboolean | gst_tensor_if_get_tensor_average (GstTensorIf *tensor_if, GstBuffer *buf, tensor_data_s *cv, guint nth) |
Calculate average value of the nth tensor. More... | |
static gboolean | gst_tensor_if_calculate_cv (GstTensorIf *tensor_if, GstBuffer *buf, tensor_data_s *cv) |
Calculate compared value. More... | |
int | nnstreamer_if_custom_register (const gchar *name, tensor_if_custom func, void *data) |
Registers a callback for tensor_if custom condition. More... | |
int | nnstreamer_if_custom_unregister (const gchar *name) |
Unregisters a callback for tensor_if custom condition. More... | |
static gboolean | gst_tensor_if_check_condition (GstTensorIf *tensor_if, GstBuffer *buf, gboolean *result) |
Determining whether a given condition is true or false. More... | |
Variables | |
static GstStaticPadTemplate | sink_factory |
The capabilities of the inputs. More... | |
static GstStaticPadTemplate | src_factory |
The capabilities of the outputs. More... | |
case | TIFOP_NE |
t == sv1._##t) ? TRUE : FALSE; break; \ More... | |
case tensor_data_s * | cv |
case tensor_data_s gboolean * | result |
tensor_data_s | svtc_1 |
tensor_data_s | svtc_2 |
svtc_1 | type = tensor_if->sv->type |
svtc_1 | data = tensor_if->sv->data[0] |
return | TRUE |
GStreamer plugin to control flow based on tensor values.
GStreamer/NNStreamer Tensor-IF Copyright (C) 2020 MyungJoo Ham myung joo. ham@s amsu ng.co m
Definition in file gsttensor_if.c.
#define CAPS_STRING GST_TENSOR_CAP_DEFAULT "; " GST_TENSORS_CAP_DEFAULT |
Definition at line 105 of file gsttensor_if.c.
#define DBG (!tensor_if->silent) |
Macro for debug mode.
SECTION:element-tensor_if
A filter that controls its src-pad based on the values (other/tensor(s)) of its sink-pad. For example, you may skip frames if there is no object detected with high confidence.
The format of statement with tensor-if is: if (Compared_Value OPERATOR Supplied_Value(s))) then THEN else ELSE Compared_Value and Supplied_Value are the operands. Compared_Value is a value from input tensor(s). Supplied_Value is a value from tensor-if properties.
If the given if-condition is simple enough (e.g., if a specific element is between a given range in a tensor frame), it can be expressed as: <refsect2> <title>Example launch line with simple if condition</title> gst-launch ... (some tensor stream) ! tensor_if name=tif compared-value=A_VALUE compared-value-option=3:4:2:5,0 operator=RANGE_INCLUSIVE supplied-value=10,100 then=PASSTHROUGH else=TENSORPICK else-option=1 tif.src_0 ! queue ! (tensor(s) stream for TRUE action) ... tif.src_1 ! queue ! (tensor(s) stream for FALSE action) ... </refsect2>
However, if the if-condition is complex and cannot be expressed with tensor-if expressions, you may create a corresponding custom filter with tensor-filter, whose output is other/tensors with an additional tensor that is "1:1:1:1, uint8", which is 1 (true) or 0 (false) as the first tensor of other/tensors and the input tensor/tensors. Then, you can create a pipeline as follows: <refsect2> <title>Example launch line with complex if condition</title> gst-launch ... (some tensor stream) ! tensor_filter framework=custom name=your_code.so ! tensor_if compared-value=A_VALUE compared-value-option=0:0:0:0,0 # 1st tensor's [0][0][0][0]. operator=EQ supplied-value=1 then=PASSTHROUGH # or whatsoever you want else=SKIP # or whatsoever you want ! tensor_demux name=d d.src_0 ! queue ! fakesink # throw away the 1/0 value. d.src_1 ! queue ! do whatever you want here... ... </refsect2>
Definition at line 82 of file gsttensor_if.c.
#define GST_CAT_DEFAULT gst_tensor_if_debug |
Definition at line 103 of file gsttensor_if.c.
#define gst_tensor_if_parent_class parent_class |
Definition at line 122 of file gsttensor_if.c.
#define GST_TYPE_TENSOR_IF_ACT (gst_tensor_if_act_get_type ()) |
Definition at line 195 of file gsttensor_if.c.
#define GST_TYPE_TENSOR_IF_CV (gst_tensor_if_cv_get_type ()) |
Definition at line 139 of file gsttensor_if.c.
#define GST_TYPE_TENSOR_IF_OP (gst_tensor_if_op_get_type ()) |
Definition at line 163 of file gsttensor_if.c.
#define operator_func | ( | cv, | |
t, | |||
op, | |||
sv1, | |||
sv2, | |||
ret | |||
) |
Macro for operator function.
Definition at line 813 of file gsttensor_if.c.
anonymous enum |
tensor_if properties
Definition at line 88 of file gsttensor_if.c.
G_DEFINE_TYPE | ( | GstTensorIf | , |
gst_tensor_if | , | ||
GST_TYPE_ELEMENT | |||
) |
GST_DEBUG_CATEGORY_STATIC | ( | gst_tensor_if_debug | ) |
|
static |
A private function to register GEnumValue array for the 'then' and 'else' properties to a GType and return it.
Definition at line 201 of file gsttensor_if.c.
|
static |
Calculate compared value.
Definition at line 939 of file gsttensor_if.c.
|
static |
chain function for sink (gst element vmethod)
Definition at line 1125 of file gsttensor_if.c.
|
static |
Determining whether a given condition is true or false.
tensor_if | TensorIf Object |
buf | gstbuffer from sink pad |
Definition at line 1070 of file gsttensor_if.c.
|
static |
initialize the tensor_if's class (GST Standard)
Definition at line 222 of file gsttensor_if.c.
|
static |
Check the status among sources in if.
tensor_if | TensorIf Object |
TensorPad | Tensorpad |
ret | return status of current pad |
Definition at line 791 of file gsttensor_if.c.
|
static |
Set custom compared value property.
Definition at line 435 of file gsttensor_if.c.
|
static |
A private function to register GEnumValue array for the 'compared-value' property to a GType and return it.
Definition at line 145 of file gsttensor_if.c.
|
static |
dispose function for tensor if (gst element vmethod)
Definition at line 307 of file gsttensor_if.c.
|
static |
event function for sink (gst element vmethod)
Definition at line 695 of file gsttensor_if.c.
|
static |
Getter for tensor_if properties.
Definition at line 579 of file gsttensor_if.c.
|
static |
Convert GValue to supplied value according to delimiters.
Definition at line 547 of file gsttensor_if.c.
|
static |
Calculate average value of the nth tensor.
Definition at line 904 of file gsttensor_if.c.
|
static |
Checking if the source pad is created and if not, create TensorPad.
tensor_if | TensorIf Object |
config | Tensors Config Data |
nth | source ordering |
Definition at line 727 of file gsttensor_if.c.
|
static |
initialize the new element (GST Standard) instantiate pads and add them to element set pad callback functions initialize instance structure
Definition at line 260 of file gsttensor_if.c.
|
static |
Installs all the properties for tensor_if.
[in] | gobject_class | Glib object class whose properties will be set |
Definition at line 627 of file gsttensor_if.c.
|
static |
A private function to register GEnumValue array for the 'operator' property to a GType and return it.
Definition at line 169 of file gsttensor_if.c.
|
static |
Parse caps and configure tensors info.
tensor_if | GstTensorIf object |
caps | incoming capability |
Definition at line 679 of file gsttensor_if.c.
|
static |
Convert GList to GValue.
Definition at line 503 of file gsttensor_if.c.
|
static |
function to remove srcpad list
Definition at line 290 of file gsttensor_if.c.
|
static |
Setter for tensor_if properties.
Definition at line 456 of file gsttensor_if.c.
|
static |
Convert GValue to GList for cv option.
Definition at line 354 of file gsttensor_if.c.
|
static |
Convert GValue to GList according to delimiters.
Definition at line 328 of file gsttensor_if.c.
|
static |
Convert GValue to GList according to delimiters.
Definition at line 400 of file gsttensor_if.c.
int nnstreamer_if_custom_register | ( | const gchar * | name, |
tensor_if_custom | func, | ||
void * | data | ||
) |
Registers a callback for tensor_if custom condition.
Register the custom callback function.
Definition at line 1023 of file gsttensor_if.c.
int nnstreamer_if_custom_unregister | ( | const gchar * | name | ) |
Unregisters a callback for tensor_if custom condition.
Unregister the custom callback function.
Definition at line 1049 of file gsttensor_if.c.
switch | ( | cv-> | type | ) |
case tensor_data_s* cv |
Definition at line 838 of file gsttensor_if.c.
svtc_2 data = tensor_if->sv->data[0] |
Definition at line 844 of file gsttensor_if.c.
* result |
Definition at line 839 of file gsttensor_if.c.
|
static |
The capabilities of the inputs.
Definition at line 109 of file gsttensor_if.c.
|
static |
The capabilities of the outputs.
Definition at line 117 of file gsttensor_if.c.
gst_tensor_data_typecast & svtc_1 |
Definition at line 841 of file gsttensor_if.c.
gst_tensor_data_typecast & svtc_2 |
Definition at line 841 of file gsttensor_if.c.
case TIFOP_NE |
t == sv1._##t) ? TRUE : FALSE; break; \
Definition at line 837 of file gsttensor_if.c.
return TRUE |
Definition at line 897 of file gsttensor_if.c.
svtc_2 type = tensor_if->sv->type |
Definition at line 843 of file gsttensor_if.c.