Doxygen Book
gsttensor_if.c File Reference

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"
Include dependency graph for gsttensor_if.c:

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 GstTensorPadgst_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_scv
 
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
 

Detailed Description

GStreamer plugin to control flow based on tensor values.

GStreamer/NNStreamer Tensor-IF Copyright (C) 2020 MyungJoo Ham myung.nosp@m.joo..nosp@m.ham@s.nosp@m.amsu.nosp@m.ng.co.nosp@m.m

Date
08 April 2020
See also
https://github.com/nnstreamer/nnstreamer
Author
MyungJoo Ham myung.nosp@m.joo..nosp@m.ham@s.nosp@m.amsu.nosp@m.ng.co.nosp@m.m
Bug:
No known bugs except for NYI items

Definition in file gsttensor_if.c.

Macro Definition Documentation

◆ CAPS_STRING

#define CAPS_STRING   GST_TENSOR_CAP_DEFAULT "; " GST_TENSORS_CAP_DEFAULT

Definition at line 105 of file gsttensor_if.c.

◆ DBG

#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.

◆ GST_CAT_DEFAULT

#define GST_CAT_DEFAULT   gst_tensor_if_debug

Definition at line 103 of file gsttensor_if.c.

◆ gst_tensor_if_parent_class

#define gst_tensor_if_parent_class   parent_class

Definition at line 122 of file gsttensor_if.c.

◆ GST_TYPE_TENSOR_IF_ACT

#define GST_TYPE_TENSOR_IF_ACT   (gst_tensor_if_act_get_type ())

Definition at line 195 of file gsttensor_if.c.

◆ GST_TYPE_TENSOR_IF_CV

#define GST_TYPE_TENSOR_IF_CV   (gst_tensor_if_cv_get_type ())

Definition at line 139 of file gsttensor_if.c.

◆ GST_TYPE_TENSOR_IF_OP

#define GST_TYPE_TENSOR_IF_OP   (gst_tensor_if_op_get_type ())

Definition at line 163 of file gsttensor_if.c.

◆ operator_func

#define operator_func (   cv,
  t,
  op,
  sv1,
  sv2,
  ret 
)
Value:
do { \
switch (op) { \
case TIFOP_EQ: ret = (cv._

Macro for operator function.

Definition at line 813 of file gsttensor_if.c.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

tensor_if properties

Enumerator
PROP_0 
PROP_SILENT 
PROP_CV 

Compared Value, operand 1 (from input tensor(s))

PROP_CV_OPTION 

Compared Value Option

PROP_OP 

Operator

PROP_SV 

Supplied Value, operand 2 (from the properties)

PROP_THEN 

Action if it is TRUE

PROP_THEN_OPTION 

Option for TRUE Action

PROP_ELSE 

Action if it is FALSE

PROP_ELSE_OPTION 

Option for FALSE Action

Definition at line 88 of file gsttensor_if.c.

Function Documentation

◆ G_DEFINE_TYPE()

G_DEFINE_TYPE ( GstTensorIf  ,
gst_tensor_if  ,
GST_TYPE_ELEMENT   
)

◆ GST_DEBUG_CATEGORY_STATIC()

GST_DEBUG_CATEGORY_STATIC ( gst_tensor_if_debug  )

◆ gst_tensor_if_act_get_type()

static GType gst_tensor_if_act_get_type ( void  )
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.

◆ gst_tensor_if_calculate_cv()

static gboolean gst_tensor_if_calculate_cv ( GstTensorIf tensor_if,
GstBuffer *  buf,
tensor_data_s cv 
)
static

Calculate compared value.

Definition at line 939 of file gsttensor_if.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ gst_tensor_if_chain()

static GstFlowReturn gst_tensor_if_chain ( GstPad *  pad,
GstObject *  parent,
GstBuffer *  buf 
)
static

chain function for sink (gst element vmethod)

Definition at line 1125 of file gsttensor_if.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ gst_tensor_if_check_condition()

static gboolean gst_tensor_if_check_condition ( GstTensorIf tensor_if,
GstBuffer *  buf,
gboolean *  result 
)
static

Determining whether a given condition is true or false.

Parameters
tensor_ifTensorIf Object
bufgstbuffer from sink pad
Returns
return TRUE if no error

Definition at line 1070 of file gsttensor_if.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ gst_tensor_if_class_init()

static void gst_tensor_if_class_init ( GstTensorIfClass klass)
static

initialize the tensor_if's class (GST Standard)

Definition at line 222 of file gsttensor_if.c.

Here is the call graph for this function:

◆ gst_tensor_if_combine_flows()

static GstFlowReturn gst_tensor_if_combine_flows ( GstTensorIf tensor_if,
GstTensorPad pad,
GstFlowReturn  ret 
)
static

Check the status among sources in if.

Parameters
tensor_ifTensorIf Object
TensorPadTensorpad
retreturn status of current pad
Returns
return status after check sources

Definition at line 791 of file gsttensor_if.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ gst_tensor_if_configure_custom_prop()

static void gst_tensor_if_configure_custom_prop ( GstTensorIf self)
static

Set custom compared value property.

Definition at line 435 of file gsttensor_if.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ gst_tensor_if_cv_get_type()

static GType gst_tensor_if_cv_get_type ( void  )
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.

◆ gst_tensor_if_dispose()

static void gst_tensor_if_dispose ( GObject *  object)
static

dispose function for tensor if (gst element vmethod)

Definition at line 307 of file gsttensor_if.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ gst_tensor_if_event()

static gboolean gst_tensor_if_event ( GstPad *  pad,
GstObject *  parent,
GstEvent *  event 
)
static

event function for sink (gst element vmethod)

Definition at line 695 of file gsttensor_if.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ gst_tensor_if_get_property()

static void gst_tensor_if_get_property ( GObject *  object,
guint  prop_id,
GValue *  value,
GParamSpec *  pspec 
)
static

Getter for tensor_if properties.

Definition at line 579 of file gsttensor_if.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ gst_tensor_if_get_property_supplied_value()

static void gst_tensor_if_get_property_supplied_value ( GValue *  value,
tensor_if_sv_s sv 
)
static

Convert GValue to supplied value according to delimiters.

Definition at line 547 of file gsttensor_if.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ gst_tensor_if_get_tensor_average()

static gboolean gst_tensor_if_get_tensor_average ( GstTensorIf tensor_if,
GstBuffer *  buf,
tensor_data_s cv,
guint  nth 
)
static

Calculate average value of the nth tensor.

Definition at line 904 of file gsttensor_if.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ gst_tensor_if_get_tensor_pad()

static GstTensorPad* gst_tensor_if_get_tensor_pad ( GstTensorIf tensor_if,
GstTensorsConfig config,
gboolean *  created,
guint  nth 
)
static

Checking if the source pad is created and if not, create TensorPad.

Parameters
tensor_ifTensorIf Object
configTensors Config Data
nthsource ordering
Returns
TensorPad if pad is already created, then return created pad. If not return new pad after creation.

Definition at line 727 of file gsttensor_if.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ gst_tensor_if_init()

static void gst_tensor_if_init ( GstTensorIf tensor_if)
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.

Here is the call graph for this function:

◆ gst_tensor_if_install_properties()

static void gst_tensor_if_install_properties ( GObjectClass *  gobject_class)
static

Installs all the properties for tensor_if.

Parameters
[in]gobject_classGlib object class whose properties will be set

Definition at line 627 of file gsttensor_if.c.

Here is the caller graph for this function:

◆ gst_tensor_if_op_get_type()

static GType gst_tensor_if_op_get_type ( void  )
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.

◆ gst_tensor_if_parse_caps()

static gboolean gst_tensor_if_parse_caps ( GstTensorIf tensor_if,
GstCaps *  caps 
)
static

Parse caps and configure tensors info.

Parameters
tensor_ifGstTensorIf object
capsincoming capability
Returns
TRUE/FALSE (if successfully configured, return TRUE)

Definition at line 679 of file gsttensor_if.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ gst_tensor_if_property_to_string()

static void gst_tensor_if_property_to_string ( GValue *  value,
GList *  prop_list,
guint  prop_id 
)
static

Convert GList to GValue.

Definition at line 503 of file gsttensor_if.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ gst_tensor_if_remove_src_pads()

static void gst_tensor_if_remove_src_pads ( GstTensorIf tensor_if)
static

function to remove srcpad list

Definition at line 290 of file gsttensor_if.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ gst_tensor_if_set_property()

static void gst_tensor_if_set_property ( GObject *  object,
guint  prop_id,
const GValue *  value,
GParamSpec *  pspec 
)
static

Setter for tensor_if properties.

Definition at line 456 of file gsttensor_if.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ gst_tensor_if_set_property_cv_option()

static void gst_tensor_if_set_property_cv_option ( const GValue *  value,
GList **  prop_list 
)
static

Convert GValue to GList for cv option.

Definition at line 354 of file gsttensor_if.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ gst_tensor_if_set_property_glist()

static void gst_tensor_if_set_property_glist ( const GValue *  value,
GList **  prop_list,
const gchar *  delimiters 
)
static

Convert GValue to GList according to delimiters.

Definition at line 328 of file gsttensor_if.c.

Here is the caller graph for this function:

◆ gst_tensor_if_set_property_supplied_value()

static void gst_tensor_if_set_property_supplied_value ( const GValue *  value,
tensor_if_sv_s sv,
const gchar *  delimiters 
)
static

Convert GValue to GList according to delimiters.

Definition at line 400 of file gsttensor_if.c.

Here is the caller graph for this function:

◆ nnstreamer_if_custom_register()

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.

Returns
0 if success. -ERRNO if error.

Definition at line 1023 of file gsttensor_if.c.

Here is the call graph for this function:

◆ nnstreamer_if_custom_unregister()

int nnstreamer_if_custom_unregister ( const gchar *  name)

Unregisters a callback for tensor_if custom condition.

Unregister the custom callback function.

Returns
0 if success. -ERRNO if error.

Definition at line 1049 of file gsttensor_if.c.

Here is the call graph for this function:

◆ switch()

switch ( cv->  type)

Definition at line 851 of file gsttensor_if.c.

Here is the caller graph for this function:

Variable Documentation

◆ cv

case tensor_data_s* cv

Definition at line 838 of file gsttensor_if.c.

◆ data

svtc_2 data = tensor_if->sv->data[0]

Definition at line 844 of file gsttensor_if.c.

◆ result

* result
Initial value:
{
gboolean ret = FALSE

Definition at line 839 of file gsttensor_if.c.

◆ sink_factory

GstStaticPadTemplate sink_factory
static
Initial value:
= GST_STATIC_PAD_TEMPLATE ("sink",
GST_PAD_SINK,
GST_PAD_ALWAYS,
GST_STATIC_CAPS (CAPS_STRING))

The capabilities of the inputs.

Definition at line 109 of file gsttensor_if.c.

◆ src_factory

GstStaticPadTemplate src_factory
static
Initial value:
= GST_STATIC_PAD_TEMPLATE ("src",
GST_PAD_SRC,
GST_PAD_SOMETIMES,
GST_STATIC_CAPS (CAPS_STRING))

The capabilities of the outputs.

Definition at line 117 of file gsttensor_if.c.

◆ svtc_1

Definition at line 841 of file gsttensor_if.c.

◆ svtc_2

Definition at line 841 of file gsttensor_if.c.

◆ TIFOP_NE

case TIFOP_NE

t == sv1._##t) ? TRUE : FALSE; break; \

Definition at line 837 of file gsttensor_if.c.

◆ TRUE

return TRUE

Definition at line 897 of file gsttensor_if.c.

◆ type

svtc_2 type = tensor_if->sv->type

Definition at line 843 of file gsttensor_if.c.

cv
case tensor_data_s * cv
Definition: gsttensor_if.c:838
FALSE
return FALSE
Definition: gsttensor_transform.c:590
TIFOP_EQ
@ TIFOP_EQ
Definition: gsttensor_if.h:61
CAPS_STRING
#define CAPS_STRING
Definition: gsttensor_if.c:105