Doxygen Book
tensor_common.h
Go to the documentation of this file.
1 
25 #ifndef __GST_TENSOR_COMMON_H__
26 #define __GST_TENSOR_COMMON_H__
27 
28 #ifdef HAVE_CONFIG_H
29 #include <config.h>
30 #endif
31 
32 #include <glib.h>
33 #include <stdint.h>
34 #include <gst/gst.h>
35 #include <gst/base/gstadapter.h>
36 #include <gst/base/gstcollectpads.h>
37 
38 #include "tensor_typedef.h"
39 #include "nnstreamer_log.h"
40 #include "nnstreamer_plugin_api.h"
41 
42 #ifdef HAVE_ORC
43 #include <orc/orcfunctions.h>
44 
45 #define nns_memcpy(d,s,n) do { \
46  if ((n) > 100) orc_memcpy ((d), (s), (n)); \
47  else memcpy ((d), (s), (n)); \
48  } while (0)
49 
50 #define nns_memset orc_memset
51 #else
52 #define nns_memcpy memcpy
53 #define nns_memset memset
54 #endif
55 
56 G_BEGIN_DECLS
57 
62 typedef enum
63 {
70 
75  guint sink_id;
76  GstClockTime duration;
78 
82 typedef struct _tensor_time_sync_data {
84  gchar *option;
85  union {
87  };
89 
93 typedef struct
94 {
95  GstCollectData collect;
96  GstBuffer *buffer;
98 
102 typedef struct
103 {
104  GstPad *pad;
105  GstClockTime last_ts;
106  GstFlowReturn last_ret;
107  guint nth;
108 } GstTensorPad;
109 
122 extern void
123 gst_tensor_parse_config_file (const gchar *config_path, const GObject *object);
124 
131 gst_tensor_time_sync_get_mode (const gchar * str);
132 
137 extern const gchar *
139 
145 extern gboolean
147 
158 extern gboolean
159 gst_tensor_time_sync_get_current_time (GstCollectPads * collect, tensor_time_sync_data * sync, GstClockTime * current_time, GstBuffer * tensors_buf);
160 
166 extern void
167 gst_tensor_time_sync_flush (GstCollectPads * collect);
168 
180 extern gboolean
181 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);
182 
192 extern GstBuffer *
193 gst_tensor_buffer_from_config (GstBuffer * in, GstTensorsConfig * config);
194 
201 extern GstCaps *
202 gst_tensor_pad_caps_from_config (GstPad * pad, const GstTensorsConfig * config);
203 
210 extern GstCaps *
211 gst_tensor_pad_possible_caps_from_config (GstPad * pad, const GstTensorsConfig * config);
212 
220 extern tensor_format
221 gst_tensor_pad_get_format (GstPad *pad);
222 
226 #define gst_tensor_pad_caps_is_static(p) (gst_tensor_pad_get_format (p) == _NNS_TENSOR_FORMAT_STATIC)
227 
231 #define gst_tensor_pad_caps_is_flexible(p) (gst_tensor_pad_get_format (p) == _NNS_TENSOR_FORMAT_FLEXIBLE)
232 
236 #define gst_tensor_pad_caps_is_sparse(p) (gst_tensor_pad_get_format (p) == _NNS_TENSOR_FORMAT_SPARSE)
237 
242 extern GHashTable *
244 
250 extern void
251 gst_tensor_aggregation_clear (GHashTable * table, const guint32 key);
252 
257 extern void
258 gst_tensor_aggregation_clear_all (GHashTable * table);
259 
266 extern GstAdapter *
267 gst_tensor_aggregation_get_adapter (GHashTable * table, const guint32 key);
268 
269 /******************************************************
270  ************ Commonly used debugging macros **********
271  ******************************************************
272  */
276 #define silent_debug(self, ...) do { \
277  if (DBG) { \
278  GST_DEBUG_OBJECT (self, __VA_ARGS__); \
279  } \
280  } while (0)
281 
285 #define silent_debug_caps(self, caps, msg) do { \
286  if (DBG) { \
287  if (caps) { \
288  gchar *caps_s_string = gst_caps_to_string (caps); \
289  GST_DEBUG_OBJECT (self, msg " = %s\n", caps_s_string); \
290  g_free (caps_s_string); \
291  } \
292  } \
293 } while (0)
294 
295 G_END_DECLS
296 #endif /* __GST_TENSOR_COMMON_H__ */
SYNC_BASEPAD
@ SYNC_BASEPAD
Definition: tensor_common.h:66
tensor_sync_basepad_data
struct _tensor_sync_basepad_data tensor_sync_basepad_data
Tensor Merge/Mux sync data for baspad mode.
SYNC_NOSYNC
@ SYNC_NOSYNC
Definition: tensor_common.h:64
_tensor_time_sync_data::data_basepad
tensor_sync_basepad_data data_basepad
Definition: tensor_common.h:86
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(),...
Definition: nnstreamer_plugin_api_impl.c:1286
GstTensorPad
Internal data structure for pad in demux / split.
Definition: tensor_common.h:102
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.
Definition: nnstreamer_plugin_api_impl.c:101
gst_tensor_aggregation_init
GHashTable * gst_tensor_aggregation_init(void)
Gets new hash table for tensor aggregation.
Definition: nnstreamer_plugin_api_impl.c:737
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.
Definition: nnstreamer_plugin_api_impl.c:115
_tensor_time_sync_data
Tensor Merge/Mux time sync data.
Definition: tensor_common.h:82
nnstreamer_log.h
Internal log util for NNStreamer plugins and native APIs.
gst_tensor_aggregation_clear_all
void gst_tensor_aggregation_clear_all(GHashTable *table)
Clears buffers from all adapters in hash table.
Definition: nnstreamer_plugin_api_impl.c:778
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 tenso...
Definition: nnstreamer_plugin_api_impl.c:535
SYNC_END
@ SYNC_END
Definition: tensor_common.h:68
SYNC_SLOWEST
@ SYNC_SLOWEST
Definition: tensor_common.h:65
GstTensorPad::last_ts
GstClockTime last_ts
Definition: tensor_common.h:105
gst_tensor_aggregation_clear
void gst_tensor_aggregation_clear(GHashTable *table, const guint32 key)
Clears buffers from adapter.
Definition: nnstreamer_plugin_api_impl.c:763
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.
Definition: nnstreamer_plugin_api_impl.c:1209
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...
Definition: nnstreamer_plugin_api_impl.c:203
tensor_format
enum _tensor_format tensor_format
Data format of tensor stream in the pipeline.
_tensor_sync_basepad_data::duration
GstClockTime duration
Definition: tensor_common.h:76
GstTensorCollectPadData::collect
GstCollectData collect
Definition: tensor_common.h:95
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 accord...
Definition: nnstreamer_plugin_api_impl.c:332
_tensor_sync_basepad_data
Tensor Merge/Mux sync data for baspad mode.
Definition: tensor_common.h:74
gst_tensor_aggregation_get_adapter
GstAdapter * gst_tensor_aggregation_get_adapter(GHashTable *table, const guint32 key)
Gets adapter from hash table.
Definition: nnstreamer_plugin_api_impl.c:790
GstTensorsConfig
Internal data structure for configured tensors info (for other/tensors).
Definition: tensor_typedef.h:284
GstTensorCollectPadData::buffer
GstBuffer * buffer
Definition: tensor_common.h:96
_tensor_sync_basepad_data::sink_id
guint sink_id
Definition: tensor_common.h:75
tensor_typedef.h
Common header file for NNStreamer, the GStreamer plugin for neural networks.
GstTensorCollectPadData
Internal data structure for Collect Pad in mux / merge.
Definition: tensor_common.h:93
_tensor_time_sync_data::mode
tensor_time_sync_mode mode
Definition: tensor_common.h:83
_tensor_time_sync_data::option
gchar * option
Definition: tensor_common.h:84
GstTensorPad::pad
GstPad * pad
Definition: tensor_common.h:104
GstTensorPad::nth
guint nth
Definition: tensor_common.h:107
tensor_time_sync_data
struct _tensor_time_sync_data tensor_time_sync_data
Tensor Merge/Mux time sync data.
tensor_time_sync_mode
tensor_time_sync_mode
time synchronization options
Definition: tensor_common.h:62
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.
Definition: nnstreamer_plugin_api_impl.c:1902
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 d...
Definition: nnstreamer_plugin_api_impl.c:263
gst_tensor_time_sync_set_option_data
gboolean gst_tensor_time_sync_set_option_data(tensor_time_sync_data *sync)
Setup time sync option.
Definition: nnstreamer_plugin_api_impl.c:126
GstTensorPad::last_ret
GstFlowReturn last_ret
Definition: tensor_common.h:106
gst_tensor_pad_get_format
tensor_format gst_tensor_pad_get_format(GstPad *pad)
Get tensor format of current pad caps.
Definition: nnstreamer_plugin_api_impl.c:1343
SYNC_REFRESH
@ SYNC_REFRESH
Definition: tensor_common.h:67
nnstreamer_plugin_api.h
Optional/Additional NNStreamer APIs for sub-plugin writers. (Need Gst devel)