Doxygen Book
gsttensor_decoder.c File Reference

GStreamer plugin to convert tensors (as a filter for other general neural network filters) to other media types. More...

#include <string.h>
#include "gsttensor_decoder.h"
Include dependency graph for gsttensor_decoder.c:

Go to the source code of this file.

Macros

#define DBG   (!self->silent)
 Macro for debug mode. More...
 
#define GST_CAT_DEFAULT   gst_tensordec_debug
 
#define DEFAULT_SILENT   TRUE
 Flag to print minimized log. More...
 
#define CAPS_STRING   GST_TENSOR_CAP_DEFAULT ";" GST_TENSORS_CAP_DEFAULT ";" GST_TENSORS_FLEX_CAP_DEFAULT
 Support multi-tensor along with single-tensor as the input. More...
 
#define gst_tensordec_parent_class   parent_class
 
#define gst_tensor_decoder_clean_plugin(self)
 Macro to clean sub-plugin data. More...
 
#define PROP_MODE_OPTION(opnum)   case PROP_MODE_OPTION
 A macro to process incoming per-mode option. More...
 
#define PROP_READ_OPTION(opnum)   case PROP_MODE_OPTION
 A macro to read per-mode option. More...
 

Enumerations

enum  {
  PROP_0, PROP_SILENT, PROP_MODE, PROP_MODE_OPTION1,
  PROP_MODE_OPTION2, PROP_MODE_OPTION3, PROP_MODE_OPTION4, PROP_MODE_OPTION5,
  PROP_MODE_OPTION6, PROP_MODE_OPTION7, PROP_MODE_OPTION8, PROP_MODE_OPTION9,
  PROP_SUBPLUGINS, PROP_CONFIG
}
 Properties. More...
 

Functions

 GST_DEBUG_CATEGORY_STATIC (gst_tensordec_debug)
 
 G_DEFINE_TYPE (GstTensorDecoder, gst_tensordec, GST_TYPE_BASE_TRANSFORM)
 
static void gst_tensordec_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
 Set property (GObject vmethod) More...
 
static void gst_tensordec_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
 Get property (GObject vmethod) More...
 
static void gst_tensordec_class_finalize (GObject *object)
 Finalize instance (GObject vmethod) More...
 
static GstFlowReturn gst_tensordec_transform (GstBaseTransform *trans, GstBuffer *inbuf, GstBuffer *outbuf)
 non-ip transform. required vmethod for BaseTransform class. More...
 
static GstCaps * gst_tensordec_transform_caps (GstBaseTransform *trans, GstPadDirection direction, GstCaps *caps, GstCaps *filter)
 configure tensor-srcpad cap from "proposed" cap. More...
 
static GstCaps * gst_tensordec_fixate_caps (GstBaseTransform *trans, GstPadDirection direction, GstCaps *caps, GstCaps *othercaps)
 fixate caps. required vmethod of BaseTransform More...
 
static gboolean gst_tensordec_set_caps (GstBaseTransform *trans, GstCaps *incaps, GstCaps *outcaps)
 set caps. required vmethod of BaseTransform More...
 
static gboolean gst_tensordec_transform_size (GstBaseTransform *trans, GstPadDirection direction, GstCaps *caps, gsize size, GstCaps *othercaps, gsize *othersize)
 Tell the framework the required size of buffer based on the info of the other side pad. optional vmethod of BaseTransform. More...
 
static gboolean nnstreamer_decoder_validate (const GstTensorDecoderDef *decoder)
 Validate decoder sub-plugin's data. More...
 
int nnstreamer_decoder_probe (GstTensorDecoderDef *decoder)
 Decoder's sub-plugin should call this function to register itself. More...
 
void nnstreamer_decoder_exit (const char *name)
 Decoder's sub-plugin may call this to unregister itself. More...
 
const GstTensorDecoderDefnnstreamer_decoder_find (const char *name)
 Find decoder sub-plugin with the name. More...
 
void nnstreamer_decoder_set_custom_property_desc (const char *name, const char *prop,...)
 set custom property description for tensor decoder sub-plugin More...
 
static GstCaps * gst_tensordec_media_caps_from_tensor (GstTensorDecoder *self, const GstTensorsConfig *config)
 Get media caps from tensor config. More...
 
static GstCaps * gst_tensordec_media_caps_from_structure (GstTensorDecoder *self, const GstStructure *structure)
 Parse structure and return media caps. More...
 
static gboolean gst_tensordec_check_consistency (GstTensorDecoder *self, GstTensorsConfig *config)
 Check tensor config is consistent. More...
 
static void gst_tensordec_class_init (GstTensorDecoderClass *klass)
 initialize the tensordec's class More...
 
static void gst_tensordec_init (GstTensorDecoder *self)
 initialize the new element instantiate pads and add them to element set pad callback functions initialize instance structure More...
 
static gboolean gst_tensordec_process_plugin_options (GstTensorDecoder *self, guint opnum)
 Process plugin (self->decoder) with given options if available. More...
 
 g_free (self->option[(opnum) - 1])
 opnum: \ More...
 
 if (!gst_tensordec_process_plugin_options(self,(opnum) - 1)) GST_ERROR_OBJECT(self
 
Configuring option for tensor decoder failed (option %d=%s)"
 
 g_value_set_string (value, self->option[opnum - 1])
 opnum: \ More...
 
static gboolean gst_tensordec_configure (GstTensorDecoder *self, const GstCaps *in_caps, const GstCaps *out_caps)
 Configure tensor metadata from sink caps. More...
 
int nnstreamer_decoder_custom_register (const gchar *name, tensor_decoder_custom func, void *data)
 Registers a callback for tensor_decoder custom condition. More...
 
int nnstreamer_decoder_custom_unregister (const gchar *name)
 Unregisters a callback for tensor_decoder custom condition. More...
 

Variables

static GstStaticPadTemplate sink_factory
 The capabilities of the inputs. More...
 
static GstStaticPadTemplate src_factory
 The capabilities of the outputs. More...
 
self option [(opnum) - 1] = g_value_dup_string (value)
 
Configuring option for tensor decoder opnum
 

Detailed Description

GStreamer plugin to convert tensors (as a filter for other general neural network filters) to other media types.

GStreamer / NNStreamer tensor_decoder main Copyright (C) 2005 Thomas Vander Stichele thoma.nosp@m.s@ap.nosp@m.estaa.nosp@m.rt.o.nosp@m.rg Copyright (C) 2005 Ronald S. Bultje rbult.nosp@m.je@r.nosp@m.onald.nosp@m..bit.nosp@m.freak.nosp@m..net Copyright (C) 2018 Jijoong Moon jijoo.nosp@m.ng.m.nosp@m.oon@s.nosp@m.amsu.nosp@m.ng.co.nosp@m.m

This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; version 2.1 of the License.

This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details.

Date
26 Mar 2018
See also
https://github.com/nnstreamer/nnstreamer
Author
Jijoong Moon jijoo.nosp@m.ng.m.nosp@m.oon@s.nosp@m.amsu.nosp@m.ng.co.nosp@m.m
Bug:

gst_tensordec_transform_size () may be incorrect if direction is SINK.

If configured = TRUE, it holds TRUE until exit. What if configuration changes in run-time?

Definition in file gsttensor_decoder.c.

Macro Definition Documentation

◆ CAPS_STRING

Support multi-tensor along with single-tensor as the input.

Definition at line 89 of file gsttensor_decoder.c.

◆ DBG

#define DBG   (!self->silent)

Macro for debug mode.

SECTION:element-tensordec

A filter that converts tensor stream for NN frameworks to media stream. The input is always in the format of other/tensor

<refsect2> <title>Example launch line</title> |[ gst-launch -v -m fakesink ! tensor_decoder ! fakesrc silent=TRUE ]| </refsect2>

Definition at line 54 of file gsttensor_decoder.c.

◆ DEFAULT_SILENT

#define DEFAULT_SILENT   TRUE

Flag to print minimized log.

Definition at line 84 of file gsttensor_decoder.c.

◆ GST_CAT_DEFAULT

#define GST_CAT_DEFAULT   gst_tensordec_debug

Definition at line 58 of file gsttensor_decoder.c.

◆ gst_tensor_decoder_clean_plugin

#define gst_tensor_decoder_clean_plugin (   self)
Value:
do { \
if (self->decoder) { \
if (self->decoder->exit) \
self->decoder->exit (&self->plugin_data); \
g_free (self->plugin_data); \
self->plugin_data = NULL; \
} \
} while (0)

Macro to clean sub-plugin data.

Definition at line 200 of file gsttensor_decoder.c.

◆ gst_tensordec_parent_class

#define gst_tensordec_parent_class   parent_class

Definition at line 107 of file gsttensor_decoder.c.

◆ PROP_MODE_OPTION

#define PROP_MODE_OPTION (   opnum)    case PROP_MODE_OPTION

A macro to process incoming per-mode option.

Parameters
[in]opnumThe option number (1 to TensorDecMaxOpNum)

Definition at line 457 of file gsttensor_decoder.c.

◆ PROP_READ_OPTION

#define PROP_READ_OPTION (   opnum)    case PROP_MODE_OPTION

A macro to read per-mode option.

Parameters
[in]opnumThe option number (1 to TensorDecMaxOpNum)

Definition at line 556 of file gsttensor_decoder.c.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

Properties.

Enumerator
PROP_0 
PROP_SILENT 
PROP_MODE 
PROP_MODE_OPTION1 
PROP_MODE_OPTION2 
PROP_MODE_OPTION3 
PROP_MODE_OPTION4 
PROP_MODE_OPTION5 
PROP_MODE_OPTION6 
PROP_MODE_OPTION7 
PROP_MODE_OPTION8 
PROP_MODE_OPTION9 
PROP_SUBPLUGINS 
PROP_CONFIG 

Definition at line 63 of file gsttensor_decoder.c.

Function Documentation

◆ failed()

Configuring option for tensor decoder failed ( option d = %s)
Here is the caller graph for this function:

◆ G_DEFINE_TYPE()

G_DEFINE_TYPE ( GstTensorDecoder  ,
gst_tensordec  ,
GST_TYPE_BASE_TRANSFORM   
)

◆ g_free()

g_free ( self->  option[(opnum) - 1])

opnum: \

◆ g_value_set_string()

g_value_set_string ( value  ,
self->  option[opnum - 1] 
)

opnum: \

Here is the caller graph for this function:

◆ GST_DEBUG_CATEGORY_STATIC()

GST_DEBUG_CATEGORY_STATIC ( gst_tensordec_debug  )

◆ gst_tensordec_check_consistency()

static gboolean gst_tensordec_check_consistency ( GstTensorDecoder self,
GstTensorsConfig config 
)
static

Check tensor config is consistent.

Parameters
self"this" pointer to check consistency
t_infonewly configured tensor metadata

not configured yet

Definition at line 269 of file gsttensor_decoder.c.

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

◆ gst_tensordec_class_finalize()

static void gst_tensordec_class_finalize ( GObject *  object)
static

Finalize instance (GObject vmethod)

Definition at line 618 of file gsttensor_decoder.c.

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

◆ gst_tensordec_class_init()

static void gst_tensordec_class_init ( GstTensorDecoderClass klass)
static

initialize the tensordec's class

Refer: https://gstreamer.freedesktop.org/documentation/design/element-transform.html

Processing units

Negotiation units

Allocation units

Definition at line 287 of file gsttensor_decoder.c.

Here is the call graph for this function:

◆ gst_tensordec_configure()

static gboolean gst_tensordec_configure ( GstTensorDecoder self,
const GstCaps *  in_caps,
const GstCaps *  out_caps 
)
static

Configure tensor metadata from sink caps.

This caps is coming from tensor

If previous input configuration is set and is not compatible with incoming caps, get possible media caps from sub-plugin and change input configuration.

Check if outcaps is compatible with new caps

Definition at line 641 of file gsttensor_decoder.c.

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

◆ gst_tensordec_fixate_caps()

static GstCaps * gst_tensordec_fixate_caps ( GstBaseTransform *  trans,
GstPadDirection  direction,
GstCaps *  caps,
GstCaps *  othercaps 
)
static

fixate caps. required vmethod of BaseTransform

In gst_tensordec_transform_caps, we have refused to specify caps if the direction is GST_PAD_SRC. Thus, gstreamer shouldn't fixate it with GST_PAD_SRC. If this happens, it's either internal logic error or GST bUG.

Definition at line 852 of file gsttensor_decoder.c.

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

◆ gst_tensordec_get_property()

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

Get property (GObject vmethod)

Definition at line 565 of file gsttensor_decoder.c.

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

◆ gst_tensordec_init()

static void gst_tensordec_init ( GstTensorDecoder self)
static

initialize the new element instantiate pads and add them to element set pad callback functions initialize instance structure

Definition at line 416 of file gsttensor_decoder.c.

Here is the call graph for this function:

◆ gst_tensordec_media_caps_from_structure()

static GstCaps* gst_tensordec_media_caps_from_structure ( GstTensorDecoder self,
const GstStructure *  structure 
)
static

Parse structure and return media caps.

Parameters
self"this" pointer
structurestructure to be interpreted

Definition at line 245 of file gsttensor_decoder.c.

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

◆ gst_tensordec_media_caps_from_tensor()

static GstCaps* gst_tensordec_media_caps_from_tensor ( GstTensorDecoder self,
const GstTensorsConfig config 
)
static

Get media caps from tensor config.

Parameters
self"this" pointer
configtensor config info
Returns
caps for media type

Definition at line 217 of file gsttensor_decoder.c.

Here is the caller graph for this function:

◆ gst_tensordec_process_plugin_options()

static gboolean gst_tensordec_process_plugin_options ( GstTensorDecoder self,
guint  opnum 
)
static

Process plugin (self->decoder) with given options if available.

Return values
FALSEif error. TRUE if OK (or SKIP)

Definition at line 440 of file gsttensor_decoder.c.

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

◆ gst_tensordec_set_caps()

static gboolean gst_tensordec_set_caps ( GstBaseTransform *  trans,
GstCaps *  incaps,
GstCaps *  outcaps 
)
static

set caps. required vmethod of BaseTransform

Check if outcaps ==equivalent== supposed

Definition at line 913 of file gsttensor_decoder.c.

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

◆ gst_tensordec_set_property()

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

Set property (GObject vmethod)

GObject vmethod implementations

Definition at line 470 of file gsttensor_decoder.c.

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

◆ gst_tensordec_transform()

static GstFlowReturn gst_tensordec_transform ( GstBaseTransform *  trans,
GstBuffer *  inbuf,
GstBuffer *  outbuf 
)
static

non-ip transform. required vmethod for BaseTransform class.

GstBaseTransform vmethod implementations

Internal logic error. Negotiation process should prevent this!

Definition at line 696 of file gsttensor_decoder.c.

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

◆ gst_tensordec_transform_caps()

static GstCaps * gst_tensordec_transform_caps ( GstBaseTransform *  trans,
GstPadDirection  direction,
GstCaps *  caps,
GstCaps *  filter 
)
static

configure tensor-srcpad cap from "proposed" cap.

@trans ("this" pointer) @direction (why do we need this?) @caps sinkpad cap @filter this element's cap (don't know specifically.)

caps = sinkpad (other/tensor) return = srcpad (media)

caps = srcpad (media) return = sinkpad (other/tensor)

Todo:
We may do more specific actions here

Definition at line 786 of file gsttensor_decoder.c.

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

◆ gst_tensordec_transform_size()

static gboolean gst_tensordec_transform_size ( GstBaseTransform *  trans,
GstPadDirection  direction,
GstCaps *  caps,
gsize  size,
GstCaps *  othercaps,
gsize *  othersize 
)
static

Tell the framework the required size of buffer based on the info of the other side pad. optional vmethod of BaseTransform.

This is called when non-ip mode is used.

Todo:
If direction = SRC, you may need different interpretation!

Definition at line 945 of file gsttensor_decoder.c.

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

◆ if()

if ( gst_tensordec_process_plugin_optionsself,(opnum) - 1)
Here is the caller graph for this function:

◆ nnstreamer_decoder_custom_register()

int nnstreamer_decoder_custom_register ( const gchar *  name,
tensor_decoder_custom  func,
void *  data 
)

Registers a callback for tensor_decoder custom condition.

Register the custom callback function.

Returns
0 if success. -ERRNO if error.

Definition at line 972 of file gsttensor_decoder.c.

Here is the call graph for this function:

◆ nnstreamer_decoder_custom_unregister()

int nnstreamer_decoder_custom_unregister ( const gchar *  name)

Unregisters a callback for tensor_decoder custom condition.

Unregister the custom callback function.

Returns
0 if success. -ERRNO if error.

Definition at line 998 of file gsttensor_decoder.c.

Here is the call graph for this function:

◆ nnstreamer_decoder_exit()

void nnstreamer_decoder_exit ( const char *  name)

Decoder's sub-plugin may call this to unregister itself.

Parameters
[in]nameThe name of decoder sub-plugin.

Definition at line 166 of file gsttensor_decoder.c.

Here is the call graph for this function:

◆ nnstreamer_decoder_find()

const GstTensorDecoderDef* nnstreamer_decoder_find ( const char *  name)

Find decoder sub-plugin with the name.

Parameters
[in]nameThe name of decoder sub-plugin.
Returns
NULL if not found or the sub-plugin object has an error.

Definition at line 177 of file gsttensor_decoder.c.

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

◆ nnstreamer_decoder_probe()

int nnstreamer_decoder_probe ( GstTensorDecoderDef decoder)

Decoder's sub-plugin should call this function to register itself.

Parameters
[in]decoderDecoder sub-plugin to be registered.
Returns
TRUE if registered. FALSE is failed or duplicated.

Definition at line 155 of file gsttensor_decoder.c.

Here is the call graph for this function:

◆ nnstreamer_decoder_set_custom_property_desc()

void nnstreamer_decoder_set_custom_property_desc ( const char *  name,
const char *  prop,
  ... 
)

set custom property description for tensor decoder sub-plugin

Definition at line 186 of file gsttensor_decoder.c.

Here is the call graph for this function:

◆ nnstreamer_decoder_validate()

static gboolean nnstreamer_decoder_validate ( const GstTensorDecoderDef decoder)
static

Validate decoder sub-plugin's data.

Definition at line 134 of file gsttensor_decoder.c.

Here is the caller graph for this function:

Variable Documentation

◆ opnum

Configuring option for tensor decoder opnum

Definition at line 463 of file gsttensor_decoder.c.

◆ option

Configuring option for tensor decoder self option = g_value_dup_string (value)

Definition at line 460 of file gsttensor_decoder.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 94 of file gsttensor_decoder.c.

◆ src_factory

GstStaticPadTemplate src_factory
static
Initial value:
= GST_STATIC_PAD_TEMPLATE ("src",
GST_PAD_SRC,
GST_PAD_ALWAYS,
GST_STATIC_CAPS ("ANY"))

The capabilities of the outputs.

Definition at line 102 of file gsttensor_decoder.c.

g_free
g_free(self->option[(opnum) - 1])
opnum: \
CAPS_STRING
#define CAPS_STRING
Support multi-tensor along with single-tensor as the input.
Definition: gsttensor_decoder.c:89