Doxygen Book
tensor_common.h File Reference

Common header file for NNStreamer, the GStreamer plugin for neural networks. More...

#include <glib.h>
#include <stdint.h>
#include <gst/gst.h>
#include <gst/base/gstadapter.h>
#include <gst/base/gstcollectpads.h>
#include "tensor_typedef.h"
#include "nnstreamer_log.h"
#include "nnstreamer_plugin_api.h"
Include dependency graph for tensor_common.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _tensor_sync_basepad_data
 Tensor Merge/Mux sync data for baspad mode. More...
 
struct  _tensor_time_sync_data
 Tensor Merge/Mux time sync data. More...
 
struct  GstTensorCollectPadData
 Internal data structure for Collect Pad in mux / merge. More...
 
struct  GstTensorPad
 Internal data structure for pad in demux / split. More...
 

Macros

#define nns_memcpy   memcpy
 
#define nns_memset   memset
 
#define gst_tensor_pad_caps_is_static(p)   (gst_tensor_pad_get_format (p) == _NNS_TENSOR_FORMAT_STATIC)
 Macro to check current pad caps is static tensor. More...
 
#define gst_tensor_pad_caps_is_flexible(p)   (gst_tensor_pad_get_format (p) == _NNS_TENSOR_FORMAT_FLEXIBLE)
 Macro to check current pad caps is flexible tensor. More...
 
#define gst_tensor_pad_caps_is_sparse(p)   (gst_tensor_pad_get_format (p) == _NNS_TENSOR_FORMAT_SPARSE)
 Macro to check current pad caps is sparse tensor. More...
 
#define silent_debug(self, ...)
 Macro for debug message. More...
 
#define silent_debug_caps(self, caps, msg)
 Macro for capability debug message. More...
 

Typedefs

typedef struct _tensor_sync_basepad_data tensor_sync_basepad_data
 Tensor Merge/Mux sync data for baspad mode. More...
 
typedef struct _tensor_time_sync_data tensor_time_sync_data
 Tensor Merge/Mux time sync data. More...
 

Enumerations

enum  tensor_time_sync_mode {
  SYNC_NOSYNC = 0, SYNC_SLOWEST = 1, SYNC_BASEPAD = 2, SYNC_REFRESH = 3,
  SYNC_END
}
 time synchronization options More...
 

Functions

void gst_tensor_parse_config_file (const gchar *config_path, const GObject *object)
 Parses a configuration file and sets the corresponding properties on a GObject. More...
 
tensor_time_sync_mode gst_tensor_time_sync_get_mode (const gchar *str)
 Get the corresponding mode from the string value. More...
 
const gchar * gst_tensor_time_sync_get_mode_string (tensor_time_sync_mode mode)
 Get the time-sync mode string. More...
 
gboolean gst_tensor_time_sync_set_option_data (tensor_time_sync_data *sync)
 Setup time sync option. More...
 
gboolean gst_tensor_time_sync_get_current_time (GstCollectPads *collect, tensor_time_sync_data *sync, GstClockTime *current_time, GstBuffer *tensors_buf)
 A function call to decide current timestamp among collected pads based on PTS. It will decide current timestamp according to sync option. GstMeta is also copied with same sync mode. More...
 
void gst_tensor_time_sync_flush (GstCollectPads *collect)
 A function to be called while processing a flushing event. It should clear old buffer and reset pad data. More...
 
gboolean gst_tensor_time_sync_buffer_from_collectpad (GstCollectPads *collect, tensor_time_sync_data *sync, GstClockTime current_time, GstBuffer *tensors_buf, GstTensorsConfig *configs, gboolean *is_eos)
 A function call to make tensors from collected pads It decide which buffer is going to be used according to sync option. More...
 
GstBuffer * gst_tensor_buffer_from_config (GstBuffer *in, GstTensorsConfig *config)
 Configure gst-buffer with tensors information. NNStreamer handles single memory chunk as single tensor. If incoming buffer has invalid memories, separate it and generate new gst-buffer using tensors information. Note that this function always takes the ownership of input buffer. More...
 
GstCaps * gst_tensor_pad_caps_from_config (GstPad *pad, const GstTensorsConfig *config)
 Get pad caps from tensors config and caps of the peer connected to the pad. More...
 
GstCaps * gst_tensor_pad_possible_caps_from_config (GstPad *pad, const GstTensorsConfig *config)
 Get all possible caps from tensors config. Unlike gst_tensor_pad_caps_from_config(), this function does not check peer caps. More...
 
tensor_format gst_tensor_pad_get_format (GstPad *pad)
 Get tensor format of current pad caps. More...
 
GHashTable * gst_tensor_aggregation_init (void)
 Gets new hash table for tensor aggregation. More...
 
void gst_tensor_aggregation_clear (GHashTable *table, const guint32 key)
 Clears buffers from adapter. More...
 
void gst_tensor_aggregation_clear_all (GHashTable *table)
 Clears buffers from all adapters in hash table. More...
 
GstAdapter * gst_tensor_aggregation_get_adapter (GHashTable *table, const guint32 key)
 Gets adapter from hash table. More...
 

Detailed Description

Common header file for NNStreamer, the GStreamer plugin for neural networks.

NNStreamer Common Header Copyright (C) 2018 MyungJoo Ham myung.nosp@m.joo..nosp@m.ham@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
23 May 2018
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 tensor_common.h.

Macro Definition Documentation

◆ gst_tensor_pad_caps_is_flexible

#define gst_tensor_pad_caps_is_flexible (   p)    (gst_tensor_pad_get_format (p) == _NNS_TENSOR_FORMAT_FLEXIBLE)

Macro to check current pad caps is flexible tensor.

Definition at line 231 of file tensor_common.h.

◆ gst_tensor_pad_caps_is_sparse

#define gst_tensor_pad_caps_is_sparse (   p)    (gst_tensor_pad_get_format (p) == _NNS_TENSOR_FORMAT_SPARSE)

Macro to check current pad caps is sparse tensor.

Definition at line 236 of file tensor_common.h.

◆ gst_tensor_pad_caps_is_static

#define gst_tensor_pad_caps_is_static (   p)    (gst_tensor_pad_get_format (p) == _NNS_TENSOR_FORMAT_STATIC)

Macro to check current pad caps is static tensor.

Definition at line 226 of file tensor_common.h.

◆ nns_memcpy

#define nns_memcpy   memcpy

Definition at line 52 of file tensor_common.h.

◆ nns_memset

#define nns_memset   memset

Definition at line 53 of file tensor_common.h.

◆ silent_debug

#define silent_debug (   self,
  ... 
)
Value:
do { \
if (DBG) { \
GST_DEBUG_OBJECT (self, __VA_ARGS__); \
} \
} while (0)

Macro for debug message.

Definition at line 276 of file tensor_common.h.

◆ silent_debug_caps

#define silent_debug_caps (   self,
  caps,
  msg 
)
Value:
do { \
if (DBG) { \
if (caps) { \
gchar *caps_s_string = gst_caps_to_string (caps); \
GST_DEBUG_OBJECT (self, msg " = %s\n", caps_s_string); \
g_free (caps_s_string); \
} \
} \
} while (0)

Macro for capability debug message.

Definition at line 285 of file tensor_common.h.

Typedef Documentation

◆ tensor_sync_basepad_data

Tensor Merge/Mux sync data for baspad mode.

◆ tensor_time_sync_data

Tensor Merge/Mux time sync data.

Enumeration Type Documentation

◆ tensor_time_sync_mode

time synchronization options

See also
https://github.com/nnstreamer/nnstreamer/wiki/Synchronization-Policies-at-Mux-and-Merge
Enumerator
SYNC_NOSYNC 
SYNC_SLOWEST 
SYNC_BASEPAD 
SYNC_REFRESH 
SYNC_END 

Definition at line 62 of file tensor_common.h.

Function Documentation

◆ gst_tensor_aggregation_clear()

void gst_tensor_aggregation_clear ( GHashTable *  table,
const guint32  key 
)

Clears buffers from adapter.

Parameters
tablea hash table instance initialized with gst_tensor_aggregation_init()
keythe key to look up (set null to get default adapter)

Definition at line 763 of file nnstreamer_plugin_api_impl.c.

Here is the call graph for this function:

◆ gst_tensor_aggregation_clear_all()

void gst_tensor_aggregation_clear_all ( GHashTable *  table)

Clears buffers from all adapters in hash table.

Parameters
tablea hash table instance initialized with gst_tensor_aggregation_init()

Definition at line 778 of file nnstreamer_plugin_api_impl.c.

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

◆ gst_tensor_aggregation_get_adapter()

GstAdapter* gst_tensor_aggregation_get_adapter ( GHashTable *  table,
const guint32  key 
)

Gets adapter from hash table.

Parameters
tablea hash table instance initialized with gst_tensor_aggregation_init()
keythe key to look up (set null to get default adapter)
Returns
gst-adapter instance. DO NOT release this instance.

Definition at line 790 of file nnstreamer_plugin_api_impl.c.

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

◆ gst_tensor_aggregation_init()

GHashTable* gst_tensor_aggregation_init ( void  )

Gets new hash table for tensor aggregation.

Returns
Newly allocated hash table, caller should release this using g_hash_table_destroy().

Add default adapter (for the case if buffer has no specific id). If gst-buffer has tensor-meta which includes client-id, e.g., aggregation frames from multiple clients on query-server pipeline, nnstreamer element should parse meta and request adapter with this id. However, on normal pipeline, gst-buffer does not contain tensor-meta, then the element may request adapter with null key string.

Definition at line 737 of file nnstreamer_plugin_api_impl.c.

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

◆ gst_tensor_buffer_from_config()

GstBuffer* gst_tensor_buffer_from_config ( GstBuffer *  in,
GstTensorsConfig config 
)

Configure gst-buffer with tensors information. NNStreamer handles single memory chunk as single tensor. If incoming buffer has invalid memories, separate it and generate new gst-buffer using tensors information. Note that this function always takes the ownership of input buffer.

Parameters
ininput buffer
configtensors config structure
Returns
Newly allocated buffer. Null if failed. Caller should unref the buffer using gst_buffer_unref().

Definition at line 535 of file nnstreamer_plugin_api_impl.c.

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

◆ gst_tensor_pad_caps_from_config()

GstCaps* gst_tensor_pad_caps_from_config ( GstPad *  pad,
const GstTensorsConfig config 
)

Get pad caps from tensors config and caps of the peer connected to the pad.

Parameters
padGstPad to get possible caps
configtensors config structure
Returns
caps for given config. Caller is responsible for unreffing the returned caps.

Definition at line 1209 of file nnstreamer_plugin_api_impl.c.

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

◆ gst_tensor_pad_get_format()

tensor_format gst_tensor_pad_get_format ( GstPad *  pad)

Get tensor format of current pad caps.

Parameters
padGstPad to check current caps.
Returns
The tensor_format of current pad caps.

If pad does not have tensor caps return _NNS_TENSOR_FORMAT_END

Definition at line 1343 of file nnstreamer_plugin_api_impl.c.

Here is the call graph for this function:

◆ gst_tensor_pad_possible_caps_from_config()

GstCaps* gst_tensor_pad_possible_caps_from_config ( GstPad *  pad,
const GstTensorsConfig config 
)

Get all possible caps from tensors config. Unlike gst_tensor_pad_caps_from_config(), this function does not check peer caps.

Parameters
padGstPad to get possible caps
configtensors config structure
Returns
caps for given config. Caller is responsible for unreffing the returned caps.

Definition at line 1286 of file nnstreamer_plugin_api_impl.c.

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

◆ gst_tensor_parse_config_file()

void gst_tensor_parse_config_file ( const gchar *  config_path,
const GObject *  object 
)

Parses a configuration file and sets the corresponding properties on a GObject.

This function reads the contents of the configuration file located at the given path and sets the properties of the specified GObject based on the configuration data.

Parameters
config_pathThe path to the configuration file.
objectThe GObject on which to set the properties.
Note
The responsibility of managing the memory of the GObject passed as a parameter lies outside this function.

Iterate over each line

Definition at line 1902 of file nnstreamer_plugin_api_impl.c.

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

◆ gst_tensor_time_sync_buffer_from_collectpad()

gboolean gst_tensor_time_sync_buffer_from_collectpad ( GstCollectPads *  collect,
tensor_time_sync_data sync,
GstClockTime  current_time,
GstBuffer *  tensors_buf,
GstTensorsConfig configs,
gboolean *  is_eos 
)

A function call to make tensors from collected pads It decide which buffer is going to be used according to sync option.

Returns
True to push buffer.
Parameters
collectCollect pad.
syncSynchronization Option (NOSYNC, SLOWEST, BASEPAD, END)
current_timeCurrent Timestamp
tensors_bufGenerated GstBuffer for Collected Buffer
configsConfiguration Info for Collected Buffer
is_eosTrue when EOS (end-of-stream)

A function call to make tensors from collected pads It decide which buffer is going to be used according to sync option.

Returns
True to push buffer.

This would be an internal logic error. in_configs should be already confirmed valid at the negotiation phase and this function should be called in a running pipeline. If new sync mode is enabled (e.g., handle output when a pad gets new buffer), this may cause unexpected exception.

These are internal logic error. If given inputs are incorrect, the negotiation should have been failed before this stage.

Definition at line 332 of file nnstreamer_plugin_api_impl.c.

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

◆ gst_tensor_time_sync_flush()

void gst_tensor_time_sync_flush ( GstCollectPads *  collect)

A function to be called while processing a flushing event. It should clear old buffer and reset pad data.

Parameters
collectCollect pad.

Definition at line 263 of file nnstreamer_plugin_api_impl.c.

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

◆ gst_tensor_time_sync_get_current_time()

gboolean gst_tensor_time_sync_get_current_time ( GstCollectPads *  collect,
tensor_time_sync_data sync,
GstClockTime *  current_time,
GstBuffer *  tensors_buf 
)

A function call to decide current timestamp among collected pads based on PTS. It will decide current timestamp according to sync option. GstMeta is also copied with same sync mode.

Returns
True / False. If EOS, it return TRUE.
Parameters
collectCollect pad.
syncSynchronization Option (NOSYNC, SLOWEST, BASEPAD, END)
current_timeCurrent time
tensors_bufGenerated GstBuffer for Collected Buffer

Definition at line 203 of file nnstreamer_plugin_api_impl.c.

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

◆ gst_tensor_time_sync_get_mode()

tensor_time_sync_mode gst_tensor_time_sync_get_mode ( const gchar *  str)

Get the corresponding mode from the string value.

Parameters
[in]strThe string value for the mode.
Returns
Corresponding mode for the string. SYNC_END for errors.

Definition at line 101 of file nnstreamer_plugin_api_impl.c.

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

◆ gst_tensor_time_sync_get_mode_string()

const gchar* gst_tensor_time_sync_get_mode_string ( tensor_time_sync_mode  mode)

Get the time-sync mode string.

Returns
Corresponding mode string.

Definition at line 115 of file nnstreamer_plugin_api_impl.c.

Here is the caller graph for this function:

◆ gst_tensor_time_sync_set_option_data()

gboolean gst_tensor_time_sync_set_option_data ( tensor_time_sync_data sync)

Setup time sync option.

Parameters
[in/out]filter "this" pointer. Sync mode & option MUST BE set already.
Returns
True if successfully set the option.

Definition at line 126 of file nnstreamer_plugin_api_impl.c.

Here is the caller graph for this function:
DBG
#define DBG
Macro for debug mode.
Definition: gsttensor_aggregator.c:42