GStreamer plugin to convert media types to tensors (as a filter for other general neural network filters) More...
#include <string.h>
#include "gsttensor_converter.h"
#include "tensor_meta.h"
#include "gsttensor_converter_media_info_video.h"
#include "gsttensor_converter_media_info_audio.h"
#include <nnstreamer_log.h>
#include <nnstreamer_subplugin.h>
#include <nnstreamer_util.h>
Go to the source code of this file.
Macros | |
#define | TEXT_CAPS_STR "text/x-raw, format = (string) utf8" |
Caps string for text input. More... | |
#define | append_text_caps_template(caps) gst_caps_append (caps, gst_caps_from_string (TEXT_CAPS_STR)) |
#define | OCTET_CAPS_STR "application/octet-stream" |
Caps string for binary stream. More... | |
#define | append_octet_caps_template(caps) gst_caps_append (caps, gst_caps_from_string (OCTET_CAPS_STR)) |
#define | append_flex_tensor_caps_template(caps) gst_caps_append (caps, gst_caps_from_string (GST_TENSORS_FLEX_CAP_DEFAULT)) |
Macro to append template caps for flexible tensor. More... | |
#define | DBG (!self->silent) |
Macro for debug mode. More... | |
#define | silent_debug_timestamp(self, buf) |
#define | GST_CAT_DEFAULT gst_tensor_converter_debug |
#define | STRING_CUSTOM_MODE(self) |
#define | DEFAULT_SET_TIMESTAMP TRUE |
Flag to set timestamp when received a buffer with invalid timestamp. More... | |
#define | DEFAULT_SILENT TRUE |
Flag to print minimized log. More... | |
#define | DEFAULT_FRAMES_PER_TENSOR 1 |
Frames in output tensor. More... | |
#define | gst_tensor_converter_parent_class parent_class |
Enumerations | |
enum | { PROP_0, PROP_INPUT_DIMENSION, PROP_INPUT_TYPE, PROP_FRAMES_PER_TENSOR, PROP_SET_TIMESTAMP, PROP_SUBPLUGINS, PROP_SILENT, PROP_MODE } |
tensor_converter properties More... | |
Functions | |
GST_DEBUG_CATEGORY_STATIC (gst_tensor_converter_debug) | |
G_DEFINE_TYPE (GstTensorConverter, gst_tensor_converter, GST_TYPE_ELEMENT) | |
static void | gst_tensor_converter_finalize (GObject *object) |
Function to finalize instance. More... | |
static void | gst_tensor_converter_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) |
Setter for tensor_converter properties. More... | |
static void | gst_tensor_converter_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) |
Getter for tensor_converter properties. More... | |
static gboolean | gst_tensor_converter_sink_event (GstPad *pad, GstObject *parent, GstEvent *event) |
This function handles sink event. More... | |
static gboolean | gst_tensor_converter_sink_query (GstPad *pad, GstObject *parent, GstQuery *query) |
This function handles sink pad query. More... | |
static gboolean | gst_tensor_converter_src_query (GstPad *pad, GstObject *parent, GstQuery *query) |
This function handles src pad query. More... | |
static GstFlowReturn | gst_tensor_converter_chain (GstPad *pad, GstObject *parent, GstBuffer *buf) |
Chain function, this function does the actual processing. More... | |
static GstStateChangeReturn | gst_tensor_converter_change_state (GstElement *element, GstStateChange transition) |
Called to perform state change. More... | |
static void | gst_tensor_converter_reset (GstTensorConverter *self) |
Clear and reset data. More... | |
static GstCaps * | gst_tensor_converter_query_caps (GstTensorConverter *self, GstPad *pad, GstCaps *filter) |
Get pad caps for caps negotiation. More... | |
static gboolean | gst_tensor_converter_parse_caps (GstTensorConverter *self, const GstCaps *caps) |
Parse caps and set tensors info. More... | |
static void | gst_tensor_converter_update_caps (GstTensorConverter *self) |
Update src pad caps from tensors config. More... | |
static const NNStreamerExternalConverter * | findExternalConverter (const char *media_type) |
Internal static function to find registered subplugins. More... | |
static void | gst_tensor_converter_class_init (GstTensorConverterClass *klass) |
Initialize the tensor_converter's class. More... | |
static void | gst_tensor_converter_init (GstTensorConverter *self) |
Initialize tensor_converter element. More... | |
static GstAdapter * | gst_tensor_converter_get_adapter (GstTensorConverter *self, GstBuffer *buf) |
Internal function to get adapter. More... | |
static void | _gst_tensor_converter_chain_segment (GstTensorConverter *self, gsize frame_size) |
Chain function's private routine. More... | |
static void | _gst_tensor_converter_chain_timestamp (GstTensorConverter *self, GstBuffer *inbuf, guint frames_in) |
Chain function's private routine. More... | |
static GstBuffer * | _gst_tensor_converter_chain_octet (GstTensorConverter *self, GstBuffer *buf) |
Chain function's private routine to process octet stream. More... | |
static GstBuffer * | _gst_tensor_converter_chain_flex_tensor (GstTensorConverter *self, GstBuffer *buf) |
Chain function's private routine to process flex tensor. More... | |
static GstFlowReturn | _gst_tensor_converter_chain_push (GstTensorConverter *self, GstBuffer *buf) |
Chain function's private routine to push buffer into src pad. More... | |
static GstFlowReturn | _gst_tensor_converter_chain_chunk (GstTensorConverter *self, GstBuffer *inbuf, guint frames_in, guint frames_out, gsize frame_size) |
Chain function's private routine to push multiple buffers. More... | |
static void | gst_tensor_converter_get_format_list (GValue *list,...) |
Get supported format list. More... | |
static gboolean | gst_tensor_converter_video_stride (GstVideoFormat format, gint width) |
Determine if we need zero-padding. More... | |
static gboolean | gst_tensor_converter_parse_video (GstTensorConverter *self, const GstCaps *caps, GstTensorsConfig *config) |
Set the tensors config structure from video info (internal static function) More... | |
static gboolean | gst_tensor_converter_parse_audio (GstTensorConverter *self, const GstCaps *caps, GstTensorsConfig *config) |
Set the tensors config structure from audio info (internal static function) More... | |
static gboolean | gst_tensor_converter_parse_text (GstTensorConverter *self, GstTensorsConfig *config, const GstStructure *structure) |
Set the tensors config structure from text info (internal static function) More... | |
static gboolean | gst_tensor_converter_parse_octet (GstTensorConverter *self, GstTensorsConfig *config, const GstStructure *structure) |
Set the tensors configs structure from octet stream (internal static function) More... | |
static gboolean | gst_tensor_converter_parse_tensor (GstTensorConverter *self, GstTensorsConfig *config, const GstStructure *structure) |
Set the tensors configs structure from fliex tensor stream (internal static function) More... | |
static gboolean | gst_tensor_converter_parse_custom (GstTensorConverter *self, GstTensorsConfig *config, const GstCaps *caps) |
Set the tensors config structure from caps (internal static function for custom mode) More... | |
static GstCaps * | gst_tensor_converter_get_possible_media_caps (GstTensorConverter *self) |
Get possible media-caps from downstream element. More... | |
const NNStreamerExternalConverter * | nnstreamer_converter_find (const char *name) |
Find converter sub-plugin with the name. More... | |
static gboolean | nnstreamer_converter_validate (const NNStreamerExternalConverter *converter) |
Validate converter sub-plugin's data. More... | |
int | registerExternalConverter (NNStreamerExternalConverter *ex) |
Converter's external subplugins should call this at init. More... | |
void | unregisterExternalConverter (const char *name) |
Converter's external subplugins should call this at exit. More... | |
void | nnstreamer_converter_set_custom_property_desc (const char *name, const char *prop,...) |
set custom property description for tensor converter sub-plugin More... | |
int | nnstreamer_converter_custom_register (const gchar *name, tensor_converter_custom func, void *data) |
Registers a callback for tensor_converter custom condition. More... | |
int | nnstreamer_converter_custom_unregister (const gchar *name) |
Unregisters a callback for tensor_converter custom condition. More... | |
GStreamer plugin to convert media types to tensors (as a filter for other general neural network filters)
GStreamer Copyright (C) 2005 Thomas Vander Stichele thoma Copyright (C) 2005 Ronald S. Bultje s@ap estaa rt.o rgrbult Copyright (C) 2018 MyungJoo Ham je@r onald .bit freak .netmyung joo. ham@s amsu ng.co 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.
For flatbuffers, support other/tensors with properties
Subplugins are not tested, yet.
Definition in file gsttensor_converter.c.
#define append_flex_tensor_caps_template | ( | caps | ) | gst_caps_append (caps, gst_caps_from_string (GST_TENSORS_FLEX_CAP_DEFAULT)) |
Macro to append template caps for flexible tensor.
Definition at line 85 of file gsttensor_converter.c.
#define append_octet_caps_template | ( | caps | ) | gst_caps_append (caps, gst_caps_from_string (OCTET_CAPS_STR)) |
Definition at line 79 of file gsttensor_converter.c.
#define append_text_caps_template | ( | caps | ) | gst_caps_append (caps, gst_caps_from_string (TEXT_CAPS_STR)) |
Definition at line 71 of file gsttensor_converter.c.
#define DBG (!self->silent) |
Macro for debug mode.
Definition at line 92 of file gsttensor_converter.c.
#define DEFAULT_FRAMES_PER_TENSOR 1 |
Frames in output tensor.
Definition at line 142 of file gsttensor_converter.c.
#define DEFAULT_SET_TIMESTAMP TRUE |
Flag to set timestamp when received a buffer with invalid timestamp.
Definition at line 132 of file gsttensor_converter.c.
#define DEFAULT_SILENT TRUE |
Flag to print minimized log.
Definition at line 137 of file gsttensor_converter.c.
#define GST_CAT_DEFAULT gst_tensor_converter_debug |
Definition at line 104 of file gsttensor_converter.c.
#define gst_tensor_converter_parent_class parent_class |
Definition at line 144 of file gsttensor_converter.c.
#define OCTET_CAPS_STR "application/octet-stream" |
Caps string for binary stream.
Definition at line 77 of file gsttensor_converter.c.
#define silent_debug_timestamp | ( | self, | |
buf | |||
) |
Definition at line 95 of file gsttensor_converter.c.
#define STRING_CUSTOM_MODE | ( | self | ) |
Definition at line 106 of file gsttensor_converter.c.
#define TEXT_CAPS_STR "text/x-raw, format = (string) utf8" |
Caps string for text input.
SECTION:element-tensor_converter
A filter that converts media stream to tensor stream for NN frameworks. The output is always in the format of other/tensor or other/tensors.
<refsect2> <title>Example launch line</title> |[ gst-launch-1.0 videotestsrc ! video/x-raw,format=RGB,width=640,height=480 ! tensor_converter ! tensor_sink ]| </refsect2>
Definition at line 69 of file gsttensor_converter.c.
anonymous enum |
tensor_converter properties
Enumerator | |
---|---|
PROP_0 | |
PROP_INPUT_DIMENSION | |
PROP_INPUT_TYPE | |
PROP_FRAMES_PER_TENSOR | |
PROP_SET_TIMESTAMP | |
PROP_SUBPLUGINS | |
PROP_SILENT | |
PROP_MODE |
Definition at line 117 of file gsttensor_converter.c.
|
static |
Chain function's private routine to push multiple buffers.
supposed same duration for incoming buffer
Update timestamp. If frames-in is larger then frames-out, the same timestamp (pts and dts) would be returned.
set timestamp
Definition at line 959 of file gsttensor_converter.c.
|
static |
Chain function's private routine to process flex tensor.
Definition at line 893 of file gsttensor_converter.c.
|
static |
Chain function's private routine to process octet stream.
Definition at line 847 of file gsttensor_converter.c.
|
static |
Chain function's private routine to push buffer into src pad.
Definition at line 938 of file gsttensor_converter.c.
|
static |
Chain function's private routine.
This is an internal logic error.
Definition at line 754 of file gsttensor_converter.c.
|
static |
Chain function's private routine.
Definition at line 787 of file gsttensor_converter.c.
|
static |
Internal static function to find registered subplugins.
Definition at line 2408 of file gsttensor_converter.c.
G_DEFINE_TYPE | ( | GstTensorConverter | , |
gst_tensor_converter | , | ||
GST_TYPE_ELEMENT | |||
) |
GST_DEBUG_CATEGORY_STATIC | ( | gst_tensor_converter_debug | ) |
|
static |
Chain function, this function does the actual processing.
This is an internal logic error.
Supposed 1 frame in buffer (default). Update frame size for each media type.
type * colorspace * width * height
supposed 1 frame in buffer
Refer: https://gstreamer.freedesktop.org/documentation/design/mediatype-video-raw.html
Internal logic error!
copy timestamps
copy timestamps
convert format (bytes > time) and push segment event. It will push event if needed (self->need_segment is true).
configures timestamp if required (self->set_timestamp is true)
do nothing, push the incoming buffer
Definition at line 1028 of file gsttensor_converter.c.
|
static |
Called to perform state change.
Definition at line 1336 of file gsttensor_converter.c.
|
static |
Initialize the tensor_converter's class.
GstTensorConverter::input-dim:
Input tensor dimension from inner array. Generally this property is used to set tensor configuration for byte-stream (application/octet-stream). When setting this property and input media type is video or audio stream, GstTensorConverter will compare the media info with this. (If it is different, it will be failed.)
GstTensorConverter::input-type:
Type of each element of the input tensor. Generally this property is used to set tensor configuration for byte-stream (application/octet-stream). When setting this property and input media type is video or audio stream, GstTensorConverter will compare the media info with this. (If it is different, it will be failed.)
GstTensorConverter::frames-per-tensor:
The number of frames in outgoing buffer. (buffer is a single tensor instance) GstTensorConverter can push a buffer with multiple media frames.
GstTensorConverter::set-timestamp:
The flag to set timestamp when received a buffer with invalid timestamp.
GstTensorConverter::sub-plugins:
Registrable sub-plugins list of tensor-converter.
The flag to enable/disable debugging messages.
Generally this property is used to set tensor converter custom mode.
Definition at line 178 of file gsttensor_converter.c.
|
static |
Function to finalize instance.
Definition at line 381 of file gsttensor_converter.c.
|
static |
Internal function to get adapter.
Definition at line 706 of file gsttensor_converter.c.
|
static |
Get supported format list.
Definition at line 1385 of file gsttensor_converter.c.
|
static |
Get possible media-caps from downstream element.
Definition at line 1972 of file gsttensor_converter.c.
|
static |
Getter for tensor_converter properties.
Definition at line 514 of file gsttensor_converter.c.
|
static |
Initialize tensor_converter element.
setup sink pad
setup src pad
init properties
Definition at line 331 of file gsttensor_converter.c.
|
static |
Set the tensors config structure from audio info (internal static function)
self | this pointer to GstTensorConverter |
caps | caps for media stream |
config | tensors config structure to be filled |
Refer: https://www.tensorflow.org/api_docs/python/tf/summary/audio A 3-D float32 Tensor of shape [batch_size, frames, channels] or a 2-D float32 Tensor of shape [batch_size, frames].
Definition at line 1582 of file gsttensor_converter.c.
|
static |
Parse caps and set tensors info.
dimension index of frames in configured tensors
set the number of frames in dimension
not fully configured. the resulting config is weird.
compare tensor info
Definition at line 2190 of file gsttensor_converter.c.
|
static |
Set the tensors config structure from caps (internal static function for custom mode)
self | this pointer to GstTensorConverter |
config | tensors config structure to be filled |
caps | incoming caps |
Definition at line 1889 of file gsttensor_converter.c.
|
static |
Set the tensors configs structure from octet stream (internal static function)
self | this pointer to GstTensorConverter |
config | tensors config structure to be filled |
structure | caps structure |
Failure case when octet-stream has multi tensors and multi frames.
Raw byte-stream (application/octet-stream) We cannot get the exact tensors info from caps. All tensors info should be updated. If output is flexible, dimension should be updated in chain function with buffer size. (data format for tensor: [size])
Definition at line 1741 of file gsttensor_converter.c.
|
static |
Set the tensors configs structure from fliex tensor stream (internal static function)
self | this pointer to GstTensorConverter |
config | tensors config structure to be filled |
structure | caps structure |
We cannot get the exact tensors info from caps. All tensors info should be updated in chain function. (data format for tensor: [size])
Definition at line 1834 of file gsttensor_converter.c.
|
static |
Set the tensors config structure from text info (internal static function)
self | this pointer to GstTensorConverter |
config | tensors config structure to be filled |
structure | caps structure |
Refer: https://www.tensorflow.org/api_docs/python/tf/summary/text A string-type Tensor
Definition at line 1670 of file gsttensor_converter.c.
|
static |
Set the tensors config structure from video info (internal static function)
self | this pointer to GstTensorConverter |
caps | caps for media stream |
config | tensors config structure to be filled |
Refer: https://www.tensorflow.org/api_docs/python/tf/summary/image A 4-D uint8 or float32 Tensor of shape [batch_size, height, width, channels] where channels is 1, 3, or 4.
Emit Warning if RSTRIDE = RU4 (3BPP) && Width % 4 > 0
Definition at line 1444 of file gsttensor_converter.c.
|
static |
Get pad caps for caps negotiation.
Definition at line 2144 of file gsttensor_converter.c.
|
static |
Clear and reset data.
Definition at line 1369 of file gsttensor_converter.c.
|
static |
Setter for tensor_converter properties.
Definition at line 406 of file gsttensor_converter.c.
|
static |
This function handles sink event.
Definition at line 586 of file gsttensor_converter.c.
|
static |
This function handles sink pad query.
Definition at line 654 of file gsttensor_converter.c.
|
static |
This function handles src pad query.
Definition at line 722 of file gsttensor_converter.c.
|
static |
Update src pad caps from tensors config.
Definition at line 2333 of file gsttensor_converter.c.
|
static |
Determine if we need zero-padding.
Definition at line 1409 of file gsttensor_converter.c.
int nnstreamer_converter_custom_register | ( | const gchar * | name, |
tensor_converter_custom | func, | ||
void * | data | ||
) |
Registers a callback for tensor_converter custom condition.
Register the custom callback function.
Definition at line 2473 of file gsttensor_converter.c.
int nnstreamer_converter_custom_unregister | ( | const gchar * | name | ) |
Unregisters a callback for tensor_converter custom condition.
Unregister the custom callback function.
Definition at line 2500 of file gsttensor_converter.c.
const NNStreamerExternalConverter* nnstreamer_converter_find | ( | const char * | name | ) |
Find converter sub-plugin with the name.
[in] | name | The name of converter sub-plugin. |
Definition at line 2360 of file gsttensor_converter.c.
void nnstreamer_converter_set_custom_property_desc | ( | const char * | name, |
const char * | prop, | ||
... | |||
) |
set custom property description for tensor converter sub-plugin
Definition at line 2457 of file gsttensor_converter.c.
|
static |
Validate converter sub-plugin's data.
Definition at line 2369 of file gsttensor_converter.c.
int registerExternalConverter | ( | NNStreamerExternalConverter * | ex | ) |
Converter's external subplugins should call this at init.
Converter's sub-plugin should call this function to register itself.
Definition at line 2389 of file gsttensor_converter.c.
void unregisterExternalConverter | ( | const char * | name | ) |
Converter's external subplugins should call this at exit.
Converter's sub-plugin may call this to unregister itself.
Definition at line 2399 of file gsttensor_converter.c.