/**
* @brief String representations for each tensor element type.
*/
-const gchar* tensor_element_typename[] = {
- [_NNS_INT32] = "int32",
- [_NNS_UINT32] = "uint32",
- [_NNS_INT16] = "int16",
- [_NNS_UINT16] = "uint16",
- [_NNS_INT8] = "int8",
- [_NNS_UINT8] = "uint8",
- [_NNS_FLOAT64] = "float64",
- [_NNS_FLOAT32] = "float32",
- [_NNS_END] = NULL,
+const gchar *tensor_element_typename[] = {
+ [_NNS_INT32] = "int32",
+ [_NNS_UINT32] = "uint32",
+ [_NNS_INT16] = "int16",
+ [_NNS_UINT16] = "uint16",
+ [_NNS_INT8] = "int8",
+ [_NNS_UINT8] = "uint8",
+ [_NNS_FLOAT64] = "float64",
+ [_NNS_FLOAT32] = "float32",
+ [_NNS_END] = NULL,
};
* @return Corresponding tensor_type. _NNS_END if unrecognized value is there.
* @param typestr The string type name, supposed to be one of tensor_element_typename[]
*/
-tensor_type get_tensor_type(const gchar* typestr) {
+tensor_type
+get_tensor_type (const gchar * typestr)
+{
int len;
if (!typestr)
return _NNS_END;
- len = strlen(typestr);
+ len = strlen (typestr);
if (typestr[0] == 'u' || typestr[0] == 'U') {
/* Let's believe the developer and the following three letters are "int" (case insensitive) */
- if (len == 6) /* uint16, uint32 */ {
+ if (len == 6) { /* uint16, uint32 */
if (typestr[4] == '1' && typestr[5] == '6')
return _NNS_UINT16;
else if (typestr[4] == '3' && typestr[5] == '2')
return _NNS_UINT32;
- } else if (len == 5) /* uint8 */ {
+ } else if (len == 5) { /* uint8 */
if (typestr[4] == '8')
return _NNS_UINT8;
}
} else if (typestr[0] == 'i' || typestr[0] == 'I') {
/* Let's believe the developer and the following two letters are "nt" (case insensitive) */
- if (len == 5) /* int16, int32 */ {
+ if (len == 5) { /* int16, int32 */
if (typestr[3] == '1' && typestr[4] == '6')
return _NNS_INT16;
else if (typestr[3] == '3' && typestr[4] == '2')
return _NNS_INT32;
- } else if (len == 4) /* int8 */ {
+ } else if (len == 4) { /* int8 */
if (typestr[3] == '8')
return _NNS_INT8;
}
* @param strv Null terminated array of gchar *
* @param key The key string value
*/
-int find_key_strv(const gchar **strv, const gchar *key) {
+int
+find_key_strv (const gchar ** strv, const gchar * key)
+{
int cursor = 0;
- g_assert(strv != NULL);
+ g_assert (strv != NULL);
while (strv[cursor]) {
- if (!g_ascii_strcasecmp(strv[cursor], key))
+ if (!g_ascii_strcasecmp (strv[cursor], key))
return cursor;
cursor++;
}
- return -1; /* Not Found */
+ return -1; /* Not Found */
}
/**
* @return The Rank. 0 if error.
* @param param The parameter string in the format of d1:d2:d3:d4, d1:d2:d3, d1:d2, or d1, where dN is a positive integer and d1 is the innermost dimension; i.e., dim[d4][d3][d2][d1];
*/
-int get_tensor_dimension(const gchar* param, uint32_t dim[NNS_TENSOR_RANK_LIMIT]) {
- gchar **strv = g_strsplit(param, ":", NNS_TENSOR_RANK_LIMIT);
+int
+get_tensor_dimension (const gchar * param, uint32_t dim[NNS_TENSOR_RANK_LIMIT])
+{
+ gchar **strv = g_strsplit (param, ":", NNS_TENSOR_RANK_LIMIT);
int i, retval = 0;
guint64 val;
- g_assert(strv != NULL);
+ g_assert (strv != NULL);
for (i = 0; i < NNS_TENSOR_RANK_LIMIT; i++) {
if (strv[i] == NULL)
break;
- val = g_ascii_strtoull(strv[i], NULL, 10);
+ val = g_ascii_strtoull (strv[i], NULL, 10);
dim[i] = val;
retval = i + 1;
}
for (; i < NNS_TENSOR_RANK_LIMIT; i++)
dim[i] = 1;
- g_strfreev(strv);
+ g_strfreev (strv);
return retval;
}
* @return The number of elements. 0 if error.
* @param dim The tensor dimension
*/
-size_t get_tensor_element_count(uint32_t dim[NNS_TENSOR_RANK_LIMIT]) {
+size_t
+get_tensor_element_count (uint32_t dim[NNS_TENSOR_RANK_LIMIT])
+{
size_t count = 1;
int i;
#define D2 (280)
#define D3 (40)
-typedef struct _pt_data {
+typedef struct _pt_data
+{
uint32_t id; /***< Just for testing */
uint32_t dim[NNS_TENSOR_RANK_LIMIT];
tensor_type type;
} pt_data;
-static void *pt_init() {
- pt_data *data = (pt_data *)malloc(sizeof (pt_data));
+static void *
+pt_init ()
+{
+ pt_data *data = (pt_data *) malloc (sizeof (pt_data));
int i;
data->id = 0;
return data;
}
-static void pt_exit(void *private_data) {
+static void
+pt_exit (void *private_data)
+{
pt_data *data = private_data;
- g_assert(data);
- free(data);
+ g_assert (data);
+ free (data);
}
-static int get_inputDim(void *private_data, uint32_t inputDimension[NNS_TENSOR_RANK_LIMIT], tensor_type *type) {
+static int
+get_inputDim (void *private_data,
+ uint32_t inputDimension[NNS_TENSOR_RANK_LIMIT], tensor_type * type)
+{
pt_data *data = private_data;
int i;
- g_assert(data);
- g_assert(NNS_TENSOR_RANK_LIMIT >= 3);
+ g_assert (data);
+ g_assert (NNS_TENSOR_RANK_LIMIT >= 3);
inputDimension[0] = D1;
inputDimension[1] = D2;
inputDimension[2] = D3;
return 0;
}
-static int get_outputDim(void *private_data, uint32_t outputDimension[NNS_TENSOR_RANK_LIMIT], tensor_type *type) {
+static int
+get_outputDim (void *private_data,
+ uint32_t outputDimension[NNS_TENSOR_RANK_LIMIT], tensor_type * type)
+{
pt_data *data = private_data;
int i;
- g_assert(data);
- g_assert(NNS_TENSOR_RANK_LIMIT >= 3);
+ g_assert (data);
+ g_assert (NNS_TENSOR_RANK_LIMIT >= 3);
outputDimension[0] = D1;
outputDimension[1] = D2;
outputDimension[2] = D3;
return 0;
}
-static int pt_invoke(void *private_data, uint8_t *inptr, uint8_t *outptr) {
+static int
+pt_invoke (void *private_data, uint8_t * inptr, uint8_t * outptr)
+{
pt_data *data = private_data;
size_t size;
- g_assert(data);
- g_assert(inptr);
- g_assert(outptr);
+ g_assert (data);
+ g_assert (inptr);
+ g_assert (outptr);
- size = get_tensor_element_count(data->dim) * tensor_element_size[data->type];
+ size = get_tensor_element_count (data->dim) * tensor_element_size[data->type];
- g_assert(inptr != outptr);
- memcpy(outptr, inptr, size);
+ g_assert (inptr != outptr);
+ memcpy (outptr, inptr, size);
return 0;
}
/* The dyn-loaded object */
NNStreamer_custom_class *NNStreamer_custom = &NNStreamer_custom_body;
-
static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink",
GST_PAD_SINK,
GST_PAD_ALWAYS,
- GST_STATIC_CAPS ("video/x-raw, format = (string) {RGB, BGRx}, views = (int)1, interlace-mode = (string)progressive, framerate = (fraction)[ 0/1, 2147483647/1 ]")
+ GST_STATIC_CAPS
+ ("video/x-raw, format = (string) {RGB, BGRx}, views = (int)1, interlace-mode = (string)progressive, framerate = (fraction)[ 0/1, 2147483647/1 ]")
);
/**
static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
GST_PAD_SRC,
GST_PAD_ALWAYS,
- GST_STATIC_CAPS(GST_TENSOR_CAP_DEFAULT));
+ GST_STATIC_CAPS (GST_TENSOR_CAP_DEFAULT));
#define gst_tensor_converter_parent_class parent_class
-G_DEFINE_TYPE (GstTensor_Converter, gst_tensor_converter, GST_TYPE_BASE_TRANSFORM);
+G_DEFINE_TYPE (GstTensor_Converter, gst_tensor_converter,
+ GST_TYPE_BASE_TRANSFORM);
static void gst_tensor_converter_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec);
GValue * value, GParamSpec * pspec);
/* GstBaseTransformer vmethod implementations */
-static GstFlowReturn gst_tensor_converter_transform(GstBaseTransform *trans,
- GstBuffer *inbuf,
- GstBuffer *outbuf);
-static GstFlowReturn gst_tensor_converter_transform_ip(GstBaseTransform *trans,
- GstBuffer *buf);
-static GstCaps* gst_tensor_converter_transform_caps(GstBaseTransform *trans,
- GstPadDirection direction,
- GstCaps *caps,
- GstCaps *filter);
-static GstCaps* gst_tensor_converter_fixate_caps(GstBaseTransform *trans,
- GstPadDirection direction,
- GstCaps *caps,
- GstCaps *othercaps);
-static gboolean gst_tensor_converter_set_caps(GstBaseTransform *trans,
- GstCaps *incaps,
- GstCaps *outcaps);
+static GstFlowReturn gst_tensor_converter_transform (GstBaseTransform * trans,
+ GstBuffer * inbuf, GstBuffer * outbuf);
+static GstFlowReturn gst_tensor_converter_transform_ip (GstBaseTransform *
+ trans, GstBuffer * buf);
+static GstCaps *gst_tensor_converter_transform_caps (GstBaseTransform * trans,
+ GstPadDirection direction, GstCaps * caps, GstCaps * filter);
+static GstCaps *gst_tensor_converter_fixate_caps (GstBaseTransform * trans,
+ GstPadDirection direction, GstCaps * caps, GstCaps * othercaps);
+static gboolean gst_tensor_converter_set_caps (GstBaseTransform * trans,
+ GstCaps * incaps, GstCaps * outcaps);
/* GObject vmethod implementations */
/**
g_param_spec_boolean ("silent", "Silent", "Produce verbose output ?",
FALSE, G_PARAM_READWRITE));
g_object_class_install_property (gobject_class, PROP_FORCE_MEMCPY,
- g_param_spec_boolean ("force_memcpy", "Force Memcpy", "Disable in-place mode and do memcpy ?",
- FALSE, G_PARAM_READWRITE));
+ g_param_spec_boolean ("force_memcpy", "Force Memcpy",
+ "Disable in-place mode and do memcpy ?", FALSE, G_PARAM_READWRITE));
- gst_element_class_set_details_simple(gstelement_class,
- "Tensor_Converter",
- "Convert media stream to tensor stream",
- "Converts audio or video stream to tensor stream of C-Array for neural network framework filters",
- "MyungJoo Ham <myungjoo.ham@samsung.com>");
+ gst_element_class_set_details_simple (gstelement_class,
+ "Tensor_Converter",
+ "Convert media stream to tensor stream",
+ "Converts audio or video stream to tensor stream of C-Array for neural network framework filters",
+ "MyungJoo Ham <myungjoo.ham@samsung.com>");
gst_element_class_add_pad_template (gstelement_class,
gst_static_pad_template_get (&src_factory));
trans_class->passthrough_on_same_caps = FALSE;
/* Processing units */
- trans_class->transform = GST_DEBUG_FUNCPTR(gst_tensor_converter_transform);
- trans_class->transform_ip = GST_DEBUG_FUNCPTR(gst_tensor_converter_transform_ip);
+ trans_class->transform = GST_DEBUG_FUNCPTR (gst_tensor_converter_transform);
+ trans_class->transform_ip =
+ GST_DEBUG_FUNCPTR (gst_tensor_converter_transform_ip);
/* Negotiation units */
- trans_class->transform_caps = GST_DEBUG_FUNCPTR(gst_tensor_converter_transform_caps);
- trans_class->fixate_caps = GST_DEBUG_FUNCPTR(gst_tensor_converter_fixate_caps);
- trans_class->set_caps = GST_DEBUG_FUNCPTR(gst_tensor_converter_set_caps);
+ trans_class->transform_caps =
+ GST_DEBUG_FUNCPTR (gst_tensor_converter_transform_caps);
+ trans_class->fixate_caps =
+ GST_DEBUG_FUNCPTR (gst_tensor_converter_fixate_caps);
+ trans_class->set_caps = GST_DEBUG_FUNCPTR (gst_tensor_converter_set_caps);
/** Allocation units
* transform_size and get_unit_size are omitted because we do not change
}
/* @brief Return 1 if we need to remove stride per row from the stream data */
-static int remove_stride_padding_per_row(const gchar *format, int width) {
+static int
+remove_stride_padding_per_row (const gchar * format, int width)
+{
/* @TODO The actual list is much longer. fill them (read https://gstreamer.freedesktop.org/documentation/design/mediatype-video-raw.html ) */
- if ((!g_strcmp0(format, "RGB") || !g_strcmp0(format, "BGR") || !g_strcmp0(format, "I420")) && (width % 4))
+ if ((!g_strcmp0 (format, "RGB") || !g_strcmp0 (format, "BGR")
+ || !g_strcmp0 (format, "I420")) && (width % 4))
return 1;
return 0;
}
* @brief Configure tensor metadata from sink caps
*/
static gboolean
-gst_tensor_converter_configure_tensor(const GstCaps *caps, GstTensor_Converter *filter) {
+gst_tensor_converter_configure_tensor (const GstCaps * caps,
+ GstTensor_Converter * filter)
+{
GstStructure *structure;
gint rank;
gint dimension[NNS_TENSOR_RANK_LIMIT];
int i;
/* This caps is coming from video/x-raw */
- structure = gst_caps_get_structure(caps, 0);
- rank = 3; /* [color-space][height][width] */
-
- return_false_if_fail(gst_structure_get_int(structure, "width", &dimension[1]));
- return_false_if_fail(gst_structure_get_int(structure, "height", &dimension[2]));
- return_false_if_fail(gst_structure_get_fraction(structure, "framerate", &framerate_numerator, &framerate_denominator));
- type = _NNS_UINT8; /* Assume color depth per component is 8 bit */
-
- format = gst_structure_get_string(structure, "format");
-
- if (!g_strcmp0(format, "RGB"))
- dimension[0] = 3; /* R G B */
- else if (!g_strcmp0(format, "BGRx"))
- dimension[0] = 4; /* B G R x */
+ structure = gst_caps_get_structure (caps, 0);
+ rank = 3; /* [color-space][height][width] */
+
+ return_false_if_fail (gst_structure_get_int (structure, "width",
+ &dimension[1]));
+ return_false_if_fail (gst_structure_get_int (structure, "height",
+ &dimension[2]));
+ return_false_if_fail (gst_structure_get_fraction (structure, "framerate",
+ &framerate_numerator, &framerate_denominator));
+ type = _NNS_UINT8; /* Assume color depth per component is 8 bit */
+
+ format = gst_structure_get_string (structure, "format");
+
+ if (!g_strcmp0 (format, "RGB"))
+ dimension[0] = 3; /* R G B */
+ else if (!g_strcmp0 (format, "BGRx"))
+ dimension[0] = 4; /* B G R x */
else {
- g_printerr("Format = %s\n", format);
+ g_printerr ("Format = %s\n", format);
return FALSE;
}
/* Emit Warning if RSTRIDE = RU4 (3BPP) && Width % 4 > 0 */
/* @TODO: Add more conditions! */
- if (remove_stride_padding_per_row(format, dimension[1])) {
- g_print(" Width(dim2) is not divisible with 4. The performance won't be good; one more memcpy is added.\n");
- dlog_print(DLOG_WARN, "nnstreamer", "Input video width is not divisible with 4. The performance will not be good.");
+ if (remove_stride_padding_per_row (format, dimension[1])) {
+ g_print
+ (" Width(dim2) is not divisible with 4. The performance won't be good; one more memcpy is added.\n");
+ dlog_print (DLOG_WARN, "nnstreamer",
+ "Input video width is not divisible with 4. The performance will not be good.");
filter->removePadding = TRUE;
}
- dimension[3] = 1; /* This is 3-D Tensor */
- tensorFrameSize = tensor_element_size[type] * dimension[0] * dimension[1] * dimension[2] * dimension[3];
+ dimension[3] = 1; /* This is 3-D Tensor */
+ tensorFrameSize =
+ tensor_element_size[type] * dimension[0] * dimension[1] * dimension[2] *
+ dimension[3];
/* Refer: https://gstreamer.freedesktop.org/documentation/design/mediatype-video-raw.html */
if (filter->tensorConfigured == TRUE) {
/* It has been already configured. Check if they are consistent */
if (rank == filter->rank &&
- type == filter->type &&
- framerate_numerator == filter->framerate_numerator &&
- tensorFrameSize == filter->tensorFrameSize &&
- framerate_denominator == filter->framerate_denominator) {
+ type == filter->type &&
+ framerate_numerator == filter->framerate_numerator &&
+ tensorFrameSize == filter->tensorFrameSize &&
+ framerate_denominator == filter->framerate_denominator) {
for (i = 0; i < NNS_TENSOR_RANK_LIMIT; i++)
if (dimension[i] != filter->dimension[i]) {
- g_printerr(" Dimension %d Mismatch with cached: %d --> %d\n", i, dimension[i], filter->dimension[i]);
- return FALSE;
- }
+ g_printerr (" Dimension %d Mismatch with cached: %d --> %d\n", i,
+ dimension[i], filter->dimension[i]);
+ return FALSE;
+ }
return TRUE;
}
- g_printerr(" Something's wrong. The tensor metadata is inconsistent.\n");
+ g_printerr (" Something's wrong. The tensor metadata is inconsistent.\n");
return FALSE;
}
GST_DEBUG_CATEGORY_INIT (gst_tensor_converter_debug, "tensor_converter",
0, "Template tensor_converter");
- return gst_element_register (tensor_converter, "tensor_converter", GST_RANK_NONE,
- GST_TYPE_TENSOR_CONVERTER);
+ return gst_element_register (tensor_converter, "tensor_converter",
+ GST_RANK_NONE, GST_TYPE_TENSOR_CONVERTER);
}
/* PACKAGE: this is usually set by autotools depending on some _INIT macro
*
* exchange the string 'Template tensor_converter' with your tensor_converter description
*/
-GST_PLUGIN_DEFINE (
- GST_VERSION_MAJOR,
+GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
GST_VERSION_MINOR,
tensor_converter,
"tensor_converter",
tensor_converter_init,
- VERSION,
- "LGPL",
- "GStreamer",
- "http://gstreamer.net/"
-)
-
-static GstFlowReturn gst_c2t_transformer_videoframe(GstTensor_Converter *filter,
- GstBuffer *inbuf, GstBuffer *outbuf)
+ VERSION, "LGPL", "GStreamer", "http://gstreamer.net/")
+
+ static GstFlowReturn gst_c2t_transformer_videoframe (GstTensor_Converter *
+ filter, GstBuffer * inbuf, GstBuffer * outbuf)
{
- size_t sizeB = filter->dimension[0] * filter->dimension[1] * filter->dimension[2] * filter->dimension[3];
+ size_t sizeB =
+ filter->dimension[0] * filter->dimension[1] * filter->dimension[2] *
+ filter->dimension[3];
- g_assert(outbuf);
- g_assert(gst_buffer_get_size(outbuf) >= sizeB);
+ g_assert (outbuf);
+ g_assert (gst_buffer_get_size (outbuf) >= sizeB);
if (filter->removePadding == TRUE) {
int d0, d1;
size_t offset = filter->dimension[0] * filter->dimension[1];
GstMapInfo src_info, dest_info;
- g_assert(offset % 4);
+ g_assert (offset % 4);
// @TODO: We don't know if outbuf is already allocated at this point, yet!
- g_assert(gst_buffer_get_size(outbuf) >= filter->dimension[0] * filter->dimension[1] * filter->dimension[2] * filter->dimension[3]);
+ g_assert (gst_buffer_get_size (outbuf) >=
+ filter->dimension[0] * filter->dimension[1] * filter->dimension[2] *
+ filter->dimension[3]);
if (offset % 4)
offset += 4 - (offset % 4);
- // Refer: https://gstreamer.freedesktop.org/documentation/design/mediatype-video-raw.html
+ // Refer: https://gstreamer.freedesktop.org/documentation/design/mediatype-video-raw.html
- gst_buffer_map(inbuf, &src_info, GST_MAP_READ);
- gst_buffer_map(outbuf, &dest_info, GST_MAP_WRITE);
+ gst_buffer_map (inbuf, &src_info, GST_MAP_READ);
+ gst_buffer_map (outbuf, &dest_info, GST_MAP_WRITE);
srcptr = src_info.data;
destptr = dest_info.data;
- for (d0 = 0; d0 < filter->dimension[3]; d0++) { // Supposed to be 0 only
- g_assert(d0 == 0);
- for (d1 = 0; d1 < filter->dimension[2]; d1++) { // Height
- memcpy(destptr + dest_idx, srcptr + src_idx, size);
- dest_idx += size;
- src_idx += offset;
+ for (d0 = 0; d0 < filter->dimension[3]; d0++) { // Supposed to be 0 only
+ g_assert (d0 == 0);
+ for (d1 = 0; d1 < filter->dimension[2]; d1++) { // Height
+ memcpy (destptr + dest_idx, srcptr + src_idx, size);
+ dest_idx += size;
+ src_idx += offset;
}
}
- gst_buffer_unmap(inbuf, &src_info);
- gst_buffer_unmap(outbuf, &dest_info);
+ gst_buffer_unmap (inbuf, &src_info);
+ gst_buffer_unmap (outbuf, &dest_info);
- g_printerr("\n\n\nYOUR STREAM CONFIGURATION INCURS PERFORMANCE DETERIORATION! (1)\nPlease use 4 x n as image width for inputs.\n\n\n");
+ g_printerr
+ ("\n\n\nYOUR STREAM CONFIGURATION INCURS PERFORMANCE DETERIORATION! (1)\nPlease use 4 x n as image width for inputs.\n\n\n");
return GST_FLOW_OK;
} else {
unsigned char *srcptr, *destptr;
GstMapInfo src_info, dest_info;
- g_assert(gst_buffer_map(inbuf, &src_info, GST_MAP_READ) == TRUE);
- g_assert(gst_buffer_map(outbuf, &dest_info, GST_MAP_WRITE) == TRUE);
+ g_assert (gst_buffer_map (inbuf, &src_info, GST_MAP_READ) == TRUE);
+ g_assert (gst_buffer_map (outbuf, &dest_info, GST_MAP_WRITE) == TRUE);
srcptr = src_info.data;
destptr = dest_info.data;
- memcpy(destptr, srcptr, sizeB);
+ memcpy (destptr, srcptr, sizeB);
- gst_buffer_unmap(inbuf, &src_info);
- gst_buffer_unmap(outbuf, &dest_info);
+ gst_buffer_unmap (inbuf, &src_info);
+ gst_buffer_unmap (outbuf, &dest_info);
return GST_FLOW_OK;
}
return GST_FLOW_ERROR;
}
-static GstFlowReturn gst_tensor_converter_transform(GstBaseTransform *trans,
- GstBuffer *inbuf,
- GstBuffer *outbuf)
+static GstFlowReturn
+gst_tensor_converter_transform (GstBaseTransform * trans,
+ GstBuffer * inbuf, GstBuffer * outbuf)
{
GstFlowReturn res;
- GstTensor_Converter *filter = GST_TENSOR_CONVERTER_CAST(trans);
+ GstTensor_Converter *filter = GST_TENSOR_CONVERTER_CAST (trans);
- if (G_UNLIKELY(!filter->negotiated))
+ if (G_UNLIKELY (!filter->negotiated))
goto unknown_format;
- if (G_UNLIKELY(!filter->tensorConfigured))
+ if (G_UNLIKELY (!filter->tensorConfigured))
goto unknown_tensor;
- switch(filter->input_media_type) {
- case _NNS_VIDEO:
- res = gst_c2t_transformer_videoframe(filter, inbuf, outbuf);
- break;
- /* NOT SUPPORTED */
- case _NNS_AUDIO:
- case _NNS_STRING:
- default:
- g_printerr(" Unsupported Media Type (%d)\n", filter->input_media_type);
- goto unknown_type;
+ switch (filter->input_media_type) {
+ case _NNS_VIDEO:
+ res = gst_c2t_transformer_videoframe (filter, inbuf, outbuf);
+ break;
+ /* NOT SUPPORTED */
+ case _NNS_AUDIO:
+ case _NNS_STRING:
+ default:
+ g_printerr (" Unsupported Media Type (%d)\n", filter->input_media_type);
+ goto unknown_type;
}
return res;
unknown_format:
- GST_ELEMENT_ERROR(filter, CORE, NOT_IMPLEMENTED, (NULL), ("unknown format"));
+ GST_ELEMENT_ERROR (filter, CORE, NOT_IMPLEMENTED, (NULL), ("unknown format"));
return GST_FLOW_NOT_NEGOTIATED;
unknown_tensor:
- GST_ELEMENT_ERROR(filter, CORE, NOT_IMPLEMENTED, (NULL), ("unknown format for tensor"));
+ GST_ELEMENT_ERROR (filter, CORE, NOT_IMPLEMENTED, (NULL),
+ ("unknown format for tensor"));
return GST_FLOW_NOT_NEGOTIATED;
unknown_type:
- GST_ELEMENT_ERROR(filter, CORE, NOT_IMPLEMENTED, (NULL), ("not implemented type of media"));
+ GST_ELEMENT_ERROR (filter, CORE, NOT_IMPLEMENTED, (NULL),
+ ("not implemented type of media"));
return GST_FLOW_NOT_SUPPORTED;
}
-static GstFlowReturn gst_tensor_converter_transform_ip(GstBaseTransform *trans,
- GstBuffer *buf)
+static GstFlowReturn
+gst_tensor_converter_transform_ip (GstBaseTransform * trans, GstBuffer * buf)
{
- GstTensor_Converter *filter = GST_TENSOR_CONVERTER_CAST(trans);
+ GstTensor_Converter *filter = GST_TENSOR_CONVERTER_CAST (trans);
- if (G_UNLIKELY(!filter->negotiated))
+ if (G_UNLIKELY (!filter->negotiated))
goto unknown_format;
- if (G_UNLIKELY(!filter->tensorConfigured))
+ if (G_UNLIKELY (!filter->tensorConfigured))
goto unknown_tensor;
- switch(filter->input_media_type) {
- case _NNS_VIDEO:
- if (filter->removePadding == TRUE) {
- // Remove zero-padding between rows
- unsigned char *ptr;
- unsigned int row, d0;
- unsigned int dest_idx = 0, src_idx = 0;
- size_t size = filter->dimension[0] * filter->dimension[1];
- size_t offset = size;
- GstMapInfo info;
-
- g_assert(offset % 4);
- if (offset % 4)
- offset += 4 - (offset % 4);
+ switch (filter->input_media_type) {
+ case _NNS_VIDEO:
+ if (filter->removePadding == TRUE) {
+ // Remove zero-padding between rows
+ unsigned char *ptr;
+ unsigned int row, d0;
+ unsigned int dest_idx = 0, src_idx = 0;
+ size_t size = filter->dimension[0] * filter->dimension[1];
+ size_t offset = size;
+ GstMapInfo info;
+
+ g_assert (offset % 4);
+ if (offset % 4)
+ offset += 4 - (offset % 4);
// Refer: https://gstreamer.freedesktop.org/documentation/design/mediatype-video-raw.html
- gst_buffer_map(buf, &info, GST_MAP_READWRITE);
- ptr = info.data;
-
- for (d0 = 0; d0 < filter->dimension[3]; d0++) { // Supposed to be 0 only
- g_assert(d0 == 0);
- for (row = 0; row < filter->dimension[2]; row++) { // Height
- if (dest_idx != src_idx)
- memmove(ptr + dest_idx, ptr + src_idx, size);
- dest_idx += size;
- src_idx += offset;
- }
+ gst_buffer_map (buf, &info, GST_MAP_READWRITE);
+ ptr = info.data;
+
+ for (d0 = 0; d0 < filter->dimension[3]; d0++) { // Supposed to be 0 only
+ g_assert (d0 == 0);
+ for (row = 0; row < filter->dimension[2]; row++) { // Height
+ if (dest_idx != src_idx)
+ memmove (ptr + dest_idx, ptr + src_idx, size);
+ dest_idx += size;
+ src_idx += offset;
+ }
+ }
+ // @TODO: Remove the clutter (reduce the size?) after memcpy. (Check if that's really helpful, first)
+ gst_buffer_unmap (buf, &info);
+
+ g_printerr
+ ("\n\n\nYOUR STREAM CONFIGURATION INCURS PERFORMANCE DETERIORATION! (2)\nPlease use 4 x n as image width for inputs.\n\n\n");
}
- // @TODO: Remove the clutter (reduce the size?) after memcpy. (Check if that's really helpful, first)
- gst_buffer_unmap(buf, &info);
-
- g_printerr("\n\n\nYOUR STREAM CONFIGURATION INCURS PERFORMANCE DETERIORATION! (2)\nPlease use 4 x n as image width for inputs.\n\n\n");
- }
- break;
- /* NOT SUPPORTED */
- case _NNS_AUDIO:
- case _NNS_STRING:
- default:
- g_printerr(" Unsupported Media Type (%d)\n", filter->input_media_type);
- goto unknown_type;
+ break;
+ /* NOT SUPPORTED */
+ case _NNS_AUDIO:
+ case _NNS_STRING:
+ default:
+ g_printerr (" Unsupported Media Type (%d)\n", filter->input_media_type);
+ goto unknown_type;
}
/* DO NOTHING. THIS WORKS AS A PASSTHROUGH. We just remove metadata from video */
return GST_FLOW_OK;
unknown_format:
- GST_ELEMENT_ERROR(filter, CORE, NOT_IMPLEMENTED, (NULL), ("unknown format"));
+ GST_ELEMENT_ERROR (filter, CORE, NOT_IMPLEMENTED, (NULL), ("unknown format"));
return GST_FLOW_NOT_NEGOTIATED;
unknown_tensor:
- GST_ELEMENT_ERROR(filter, CORE, NOT_IMPLEMENTED, (NULL), ("unknown format for tensor"));
+ GST_ELEMENT_ERROR (filter, CORE, NOT_IMPLEMENTED, (NULL),
+ ("unknown format for tensor"));
return GST_FLOW_NOT_NEGOTIATED;
unknown_type:
- GST_ELEMENT_ERROR(filter, CORE, NOT_IMPLEMENTED, (NULL), ("not implemented type of media"));
+ GST_ELEMENT_ERROR (filter, CORE, NOT_IMPLEMENTED, (NULL),
+ ("not implemented type of media"));
return GST_FLOW_NOT_SUPPORTED;
}
* @caps sinkpad cap
* @filter this element's cap (don't know specifically.)
*/
-static GstCaps* gst_tensor_converter_transform_caps(GstBaseTransform *trans,
- GstPadDirection direction,
- GstCaps *caps,
- GstCaps *filter)
+static GstCaps *
+gst_tensor_converter_transform_caps (GstBaseTransform * trans,
+ GstPadDirection direction, GstCaps * caps, GstCaps * filter)
{
GstCaps *tmp;
gboolean ret;
- GstTensor_Converter bogusFilter = {0};
+ GstTensor_Converter bogusFilter = { 0 };
bogusFilter.tensorConfigured = FALSE;
- GstTensor_Converter *obj = GST_TENSOR_CONVERTER_CAST(trans);
+ GstTensor_Converter *obj = GST_TENSOR_CONVERTER_CAST (trans);
/* @TODO: Verify if direction == GST_PAD_SINK means caps is sink pad */
if (direction == GST_PAD_SINK) {
/* @TODO CRITICAL: Handle when caps is in range, not fixed */
/* Construct bogusFilter from caps (sinkpad) */
- ret = gst_tensor_converter_configure_tensor(caps, &bogusFilter);
+ ret = gst_tensor_converter_configure_tensor (caps, &bogusFilter);
if (ret == FALSE) {
- GstStructure *structure = gst_caps_get_structure(caps, 0);
- gchar *str = gst_structure_to_string(structure);
+ GstStructure *structure = gst_caps_get_structure (caps, 0);
+ gchar *str = gst_structure_to_string (structure);
gchar str2[2048];
gchar framerate[1024], width[1024], height[1024], colors[1024];
const gchar *format;
int fn = -1, fd, w, h;
- if (TRUE == gst_structure_get_fraction(structure, "framerate", &fn, &fd))
- g_sprintf(framerate, "%d/%d", fn, fd);
+ if (TRUE == gst_structure_get_fraction (structure, "framerate", &fn, &fd))
+ g_sprintf (framerate, "%d/%d", fn, fd);
else
- g_sprintf(framerate, "[ 0/1, 2147483647/1 ]");
+ g_sprintf (framerate, "[ 0/1, 2147483647/1 ]");
- if (TRUE == gst_structure_get_int(structure, "width", &w))
- g_sprintf(width, "%d", w);
+ if (TRUE == gst_structure_get_int (structure, "width", &w))
+ g_sprintf (width, "%d", w);
else
- g_sprintf(width, "[1, 65535]");
+ g_sprintf (width, "[1, 65535]");
- if (TRUE == gst_structure_get_int(structure, "height", &h))
- g_sprintf(height, "%d", h);
+ if (TRUE == gst_structure_get_int (structure, "height", &h))
+ g_sprintf (height, "%d", h);
else
- g_sprintf(height, "[1, 65535]");
+ g_sprintf (height, "[1, 65535]");
- format = gst_structure_get_string(structure, "format");
- if (!g_strcmp0(format, "RGB"))
- g_sprintf(colors, "3");
- else if (!g_strcmp0(format, "BGRx"))
- g_sprintf(colors, "4");
+ format = gst_structure_get_string (structure, "format");
+ if (!g_strcmp0 (format, "RGB"))
+ g_sprintf (colors, "3");
+ else if (!g_strcmp0 (format, "BGRx"))
+ g_sprintf (colors, "4");
else
- g_sprintf(colors, "{3, 4}");
+ g_sprintf (colors, "{3, 4}");
if (obj->silent == FALSE)
- g_printerr("Structure from caps = %s\n", str);
+ g_printerr ("Structure from caps = %s\n", str);
- g_sprintf(str2,
+ g_sprintf (str2,
"other/tensor, "
"rank = (int)3, "
"type = (string)uint8, "
"dim1 = (int) %s, "
"dim2 = (int) %s, "
"dim3 = (int) %s, "
- "dim4 = (int) 1"
- , framerate, colors, width, height);
- tmp = gst_caps_from_string(str2);
+ "dim4 = (int) 1", framerate, colors, width, height);
+ tmp = gst_caps_from_string (str2);
if (obj->silent == FALSE)
- g_printerr("Structure from caps to = %s\n", str2);
+ g_printerr ("Structure from caps to = %s\n", str2);
/* If given caps are in range for width/height,
we cannot configure tensor, however, we may return proper srcpad caps */
/* @TODO: see if the error is from ranging width/height before entering here */
return tmp;
- g_printerr(" Cannot retrieve tensor spec from the given input cap.\n");
- tmp = gst_caps_new_empty();
- return tmp; /* Empty Cap */
+ g_printerr (" Cannot retrieve tensor spec from the given input cap.\n");
+ tmp = gst_caps_new_empty ();
+ return tmp; /* Empty Cap */
}
- g_assert(bogusFilter.tensorConfigured == TRUE);
+ g_assert (bogusFilter.tensorConfigured == TRUE);
/* Construct GstCap (srcpad) from bugusFilter */
- tmp = gst_caps_new_simple("other/tensor",
+ tmp = gst_caps_new_simple ("other/tensor",
"rank", G_TYPE_INT, bogusFilter.rank,
"dim1", G_TYPE_INT, bogusFilter.dimension[0],
"dim2", G_TYPE_INT, bogusFilter.dimension[1],
"dim3", G_TYPE_INT, bogusFilter.dimension[2],
"dim4", G_TYPE_INT, bogusFilter.dimension[3],
"type", G_TYPE_STRING, tensor_element_typename[bogusFilter.type],
- "framerate", GST_TYPE_FRACTION, bogusFilter.framerate_numerator,
- bogusFilter.framerate_denominator,
- NULL);
+ "framerate", GST_TYPE_FRACTION, bogusFilter.framerate_numerator,
+ bogusFilter.framerate_denominator, NULL);
if (filter) {
- GstCaps *tmp2 = gst_caps_intersect_full(filter, tmp, GST_CAPS_INTERSECT_FIRST);
- gst_caps_unref(tmp);
+ GstCaps *tmp2 =
+ gst_caps_intersect_full (filter, tmp, GST_CAPS_INTERSECT_FIRST);
+ gst_caps_unref (tmp);
tmp = tmp2;
}
if (obj->silent == FALSE) {
- structure = gst_caps_get_structure(caps, 0);
- str = gst_structure_to_string(structure);
- g_printerr("From = %s\n", str);
- g_free(str);
- structure = gst_caps_get_structure(tmp, 0);
- str = gst_structure_to_string(structure);
- g_printerr("To = %s\n", str);
- g_free(str);
+ structure = gst_caps_get_structure (caps, 0);
+ str = gst_structure_to_string (structure);
+ g_printerr ("From = %s\n", str);
+ g_free (str);
+ structure = gst_caps_get_structure (tmp, 0);
+ str = gst_structure_to_string (structure);
+ g_printerr ("To = %s\n", str);
+ g_free (str);
}
- GST_DEBUG_OBJECT(trans, "SINK transformed %" GST_PTR_FORMAT " into %"
+ GST_DEBUG_OBJECT (trans, "SINK transformed %" GST_PTR_FORMAT " into %"
GST_PTR_FORMAT, caps, tmp);
return tmp;
} else if (direction == GST_PAD_SRC) {
/* Construct possible GstCap (sinkpad) with src_factory */
/* @TODO This supports video only! */
GstStaticCaps staticcap =
- GST_STATIC_CAPS("video/x-raw, format = (string){RGB, BGRx}, views = (int)1, "
+ GST_STATIC_CAPS
+ ("video/x-raw, format = (string){RGB, BGRx}, views = (int)1, "
"interlace-mode = (string)progressive, "
- "framerate = (fraction)[ 0/1, 2147483647/1 ], "
- "width = (int)[1, 65535], "
- "height = (int)[1, 65535]");
- tmp = gst_static_caps_get(&staticcap);
+ "framerate = (fraction)[ 0/1, 2147483647/1 ], "
+ "width = (int)[1, 65535], " "height = (int)[1, 65535]");
+ tmp = gst_static_caps_get (&staticcap);
if (obj->silent == FALSE) {
- structure = gst_caps_get_structure(caps, 0);
- str = gst_structure_to_string(structure);
- g_printerr("Structure from src = %s\n", str);
- g_free(str);
+ structure = gst_caps_get_structure (caps, 0);
+ str = gst_structure_to_string (structure);
+ g_printerr ("Structure from src = %s\n", str);
+ g_free (str);
}
if (filter) {
GstCaps *tmp2;
if (obj->silent == FALSE) {
- structure = gst_caps_get_structure(filter, 0);
- str = gst_structure_to_string(structure);
- g_printerr("Structure from filter = %s\n", str);
- g_free(str);
+ structure = gst_caps_get_structure (filter, 0);
+ str = gst_structure_to_string (structure);
+ g_printerr ("Structure from filter = %s\n", str);
+ g_free (str);
}
- tmp2 = gst_caps_intersect_full(filter, tmp, GST_CAPS_INTERSECT_FIRST);
+ tmp2 = gst_caps_intersect_full (filter, tmp, GST_CAPS_INTERSECT_FIRST);
if (obj->silent == FALSE) {
- structure = gst_caps_get_structure(tmp2, 0);
- str = gst_structure_to_string(structure);
- g_printerr("Structure from intersection = %s\n", str);
- g_free(str);
+ structure = gst_caps_get_structure (tmp2, 0);
+ str = gst_structure_to_string (structure);
+ g_printerr ("Structure from intersection = %s\n", str);
+ g_free (str);
}
- gst_caps_unref(tmp);
+ gst_caps_unref (tmp);
tmp = tmp2;
}
- GST_DEBUG_OBJECT(trans, "SRC transformed %" GST_PTR_FORMAT " into %"
+ GST_DEBUG_OBJECT (trans, "SRC transformed %" GST_PTR_FORMAT " into %"
GST_PTR_FORMAT, caps, tmp);
return tmp;
}
/* Neither SRC/SINK? Impossible! */
- g_printerr("Direction = %d\n", direction);
- GST_DEBUG_OBJECT(trans, "Error pad direction type. direction: %d", direction);
- g_assert(TRUE == FALSE);
+ g_printerr ("Direction = %d\n", direction);
+ GST_DEBUG_OBJECT (trans, "Error pad direction type. direction: %d",
+ direction);
+ g_assert (TRUE == FALSE);
return NULL;
}
-static GstCaps* gst_tensor_converter_fixate_caps(GstBaseTransform *trans,
- GstPadDirection direction,
- GstCaps *caps,
- GstCaps *othercaps)
+static GstCaps *
+gst_tensor_converter_fixate_caps (GstBaseTransform * trans,
+ GstPadDirection direction, GstCaps * caps, GstCaps * othercaps)
{
- GstCaps *supposed = gst_tensor_converter_transform_caps(trans, direction, caps, NULL);
+ GstCaps *supposed =
+ gst_tensor_converter_transform_caps (trans, direction, caps, NULL);
GstCaps *result;
GST_DEBUG_OBJECT (trans, "trying to fixate othercaps %" GST_PTR_FORMAT
" based on caps %" GST_PTR_FORMAT, othercaps, caps);
- result = gst_caps_intersect(othercaps, supposed);
- if (gst_caps_is_empty(result)) {
- gst_caps_unref(result);
+ result = gst_caps_intersect (othercaps, supposed);
+ if (gst_caps_is_empty (result)) {
+ gst_caps_unref (result);
result = othercaps;
} else {
- gst_caps_unref(othercaps);
+ gst_caps_unref (othercaps);
}
GST_DEBUG_OBJECT (trans, "now fixating %" GST_PTR_FORMAT, result);
- result = gst_caps_make_writable(result);
- result = gst_caps_fixate(result);
+ result = gst_caps_make_writable (result);
+ result = gst_caps_fixate (result);
if (direction == GST_PAD_SINK) {
- if (gst_caps_is_subset(caps, result)) {
- gst_caps_replace(&result, caps);
+ if (gst_caps_is_subset (caps, result)) {
+ gst_caps_replace (&result, caps);
}
}
return result;
}
-static gboolean gst_tensor_converter_set_caps(GstBaseTransform *trans,
- GstCaps *incaps,
- GstCaps *outcaps)
+static gboolean
+gst_tensor_converter_set_caps (GstBaseTransform * trans,
+ GstCaps * incaps, GstCaps * outcaps)
{
/** This is notifier of cap changes for subclass.
* However, we do not have subclass (This is the concrete class)
*/
- GstTensor_Converter *filter = GST_TENSOR_CONVERTER_CAST(trans);
+ GstTensor_Converter *filter = GST_TENSOR_CONVERTER_CAST (trans);
GstVideoInfo in_info;
GST_DEBUG_OBJECT (trans, "converting from %" GST_PTR_FORMAT
/* @TODO Supports video only */
/* input caps */
if (!gst_video_info_from_caps (&in_info, incaps)) {
- g_printerr("Cannot set_caps\n");
+ g_printerr ("Cannot set_caps\n");
return FALSE;
}
filter->in_info.video = in_info;
- gst_base_transform_set_in_place(trans, (filter->disableInPlace == TRUE) ? FALSE : TRUE);
+ gst_base_transform_set_in_place (trans,
+ (filter->disableInPlace == TRUE) ? FALSE : TRUE);
- filter->negotiated = gst_tensor_converter_configure_tensor(incaps, filter);
+ filter->negotiated = gst_tensor_converter_configure_tensor (incaps, filter);
/* @TODO Verity if outcaps and filter conf are compatible */
/* @TODO THIS IS REQUIRED TO FILL IN: Return FALSE if filter is not compatible with outcaps */
/* This caps is coming from tensor */
structure = gst_caps_get_structure (caps, 0);
return_false_if_fail (gst_structure_get_int (structure, "dim1", &i));
- /* @TODO Need to support orther media format (RGB, BRG, YUV,.. etc.). And should support Audio as well.*/
+ /* @TODO Need to support orther media format (RGB, BRG, YUV,.. etc.). And should support Audio as well. */
filter->output_media_type = _NNS_VIDEO;
if (i == 3 || i == 4) {
filter->format = i;
filter->Configured = TRUE;
- /* @TODO Need to specify of video mode*/
+ /* @TODO Need to specify of video mode */
filter->views = 1;
strcpy (interlace, "progressive");
if (!g_strcmp0 (interlace, "progressive")) {
0,
};
-const char* nnfw_names[] = {
+
+const char *nnfw_names[] = {
[_T_F_UNDEFINED] = "Not supported",
[_T_F_CUSTOM] = "custom",
static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink",
GST_PAD_SINK,
GST_PAD_ALWAYS,
- GST_STATIC_CAPS(GST_TENSOR_CAP_DEFAULT));
+ GST_STATIC_CAPS (GST_TENSOR_CAP_DEFAULT));
/**
* @brief The capabilities of the outputs
static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
GST_PAD_SRC,
GST_PAD_ALWAYS,
- GST_STATIC_CAPS(GST_TENSOR_CAP_DEFAULT));
+ GST_STATIC_CAPS (GST_TENSOR_CAP_DEFAULT));
#define gst_tensor_filter_parent_class parent_class
G_DEFINE_TYPE (GstTensor_Filter, gst_tensor_filter, GST_TYPE_BASE_TRANSFORM);
GValue * value, GParamSpec * pspec);
/* GstBaseTransformer vmethod implementations */
-static GstFlowReturn gst_tensor_filter_transform(GstBaseTransform *trans,
- GstBuffer *inbuf,
- GstBuffer *outbuf);
-static GstFlowReturn gst_tensor_filter_transform_ip(GstBaseTransform *trans,
- GstBuffer *buf);
-static GstCaps* gst_tensor_filter_transform_caps(GstBaseTransform *trans,
- GstPadDirection direction,
- GstCaps *caps,
- GstCaps *filter);
-static GstCaps* gst_tensor_filter_fixate_caps(GstBaseTransform *trans,
- GstPadDirection direction,
- GstCaps *caps,
- GstCaps *othercaps);
-static gboolean gst_tensor_filter_set_caps(GstBaseTransform *trans,
- GstCaps *incaps,
- GstCaps *outcaps);
+static GstFlowReturn gst_tensor_filter_transform (GstBaseTransform * trans,
+ GstBuffer * inbuf, GstBuffer * outbuf);
+static GstFlowReturn gst_tensor_filter_transform_ip (GstBaseTransform * trans,
+ GstBuffer * buf);
+static GstCaps *gst_tensor_filter_transform_caps (GstBaseTransform * trans,
+ GstPadDirection direction, GstCaps * caps, GstCaps * filter);
+static GstCaps *gst_tensor_filter_fixate_caps (GstBaseTransform * trans,
+ GstPadDirection direction, GstCaps * caps, GstCaps * othercaps);
+static gboolean gst_tensor_filter_set_caps (GstBaseTransform * trans,
+ GstCaps * incaps, GstCaps * outcaps);
/* GObject vmethod implementations */
/* initialize the tensor_filter's class */
g_param_spec_boolean ("silent", "Silent", "Produce verbose output ?",
FALSE, G_PARAM_READWRITE));
g_object_class_install_property (gobject_class, PROP_FRAMEWORK,
- g_param_spec_string ("framework", "Framework", "Neural network framework ?",
- "", G_PARAM_READWRITE));
+ g_param_spec_string ("framework", "Framework",
+ "Neural network framework ?", "", G_PARAM_READWRITE));
g_object_class_install_property (gobject_class, PROP_MODEL,
- g_param_spec_string ("model", "Model filepath", "Filepath to the model file ?",
- "", G_PARAM_READWRITE));
+ g_param_spec_string ("model", "Model filepath",
+ "Filepath to the model file ?", "", G_PARAM_READWRITE));
g_object_class_install_property (gobject_class, PROP_INPUT,
- g_param_spec_string ("input", "Input dimension", "Input tensor dimension from inner array, upto 4 dimensions ?", "", G_PARAM_READWRITE));
+ g_param_spec_string ("input", "Input dimension",
+ "Input tensor dimension from inner array, upto 4 dimensions ?", "",
+ G_PARAM_READWRITE));
g_object_class_install_property (gobject_class, PROP_INPUTTYPE,
- g_param_spec_string("inputtype", "Input tensor element type", "Type of each element of the input tensor ?", "uint8", G_PARAM_READWRITE));
+ g_param_spec_string ("inputtype", "Input tensor element type",
+ "Type of each element of the input tensor ?", "uint8",
+ G_PARAM_READWRITE));
g_object_class_install_property (gobject_class, PROP_OUTPUT,
- g_param_spec_string("output", "Output dimension", "Output tensor dimension from inner array, upto 4 dimensions ?", "", G_PARAM_READWRITE));
+ g_param_spec_string ("output", "Output dimension",
+ "Output tensor dimension from inner array, upto 4 dimensions ?", "",
+ G_PARAM_READWRITE));
g_object_class_install_property (gobject_class, PROP_OUTPUTTYPE,
- g_param_spec_string("outputtype", "Output tensor element type", "Type of each element of the output tensor ?", "uint8", G_PARAM_READWRITE));
+ g_param_spec_string ("outputtype", "Output tensor element type",
+ "Type of each element of the output tensor ?", "uint8",
+ G_PARAM_READWRITE));
g_object_class_install_property (gobject_class, PROP_DEBUG,
g_param_spec_boolean ("debug", "Debug", "Produce a lot of log messages ?",
FALSE, G_PARAM_READWRITE));
- gst_element_class_set_details_simple(gstelement_class,
- "Tensor_Filter",
- "NN Frameworks (e.g., tensorflow) as Media Filters",
- "Handles NN Frameworks (e.g., tensorflow) as Media Filters with other/tensor type stream",
- "MyungJoo Ham <myungjoo.ham@samsung.com>");
+ gst_element_class_set_details_simple (gstelement_class,
+ "Tensor_Filter",
+ "NN Frameworks (e.g., tensorflow) as Media Filters",
+ "Handles NN Frameworks (e.g., tensorflow) as Media Filters with other/tensor type stream",
+ "MyungJoo Ham <myungjoo.ham@samsung.com>");
gst_element_class_add_pad_template (gstelement_class,
gst_static_pad_template_get (&src_factory));
trans_class->passthrough_on_same_caps = FALSE;
/* Processing units */
- trans_class->transform = GST_DEBUG_FUNCPTR(gst_tensor_filter_transform);
- trans_class->transform_ip = GST_DEBUG_FUNCPTR(gst_tensor_filter_transform_ip);
+ trans_class->transform = GST_DEBUG_FUNCPTR (gst_tensor_filter_transform);
+ trans_class->transform_ip =
+ GST_DEBUG_FUNCPTR (gst_tensor_filter_transform_ip);
/* Negotiation units */
- trans_class->transform_caps = GST_DEBUG_FUNCPTR(gst_tensor_filter_transform_caps);
- trans_class->fixate_caps = GST_DEBUG_FUNCPTR(gst_tensor_filter_fixate_caps);
- trans_class->set_caps = GST_DEBUG_FUNCPTR(gst_tensor_filter_set_caps);
+ trans_class->transform_caps =
+ GST_DEBUG_FUNCPTR (gst_tensor_filter_transform_caps);
+ trans_class->fixate_caps = GST_DEBUG_FUNCPTR (gst_tensor_filter_fixate_caps);
+ trans_class->set_caps = GST_DEBUG_FUNCPTR (gst_tensor_filter_set_caps);
/* Allocation units */
// @TODO Fill these in!
filter->outputConfigured = FALSE;
filter->modelFilename = NULL;
- filter->inputDimension[0] = 1; // innermost
+ filter->inputDimension[0] = 1; // innermost
filter->inputDimension[1] = 1;
filter->inputDimension[2] = 1;
- filter->inputDimension[3] = 1; // out
+ filter->inputDimension[3] = 1; // out
filter->inputType = _NNS_END; // not initialized
filter->inputCapNegotiated = FALSE;
- filter->outputDimension[0] = 1; // innermost
+ filter->outputDimension[0] = 1; // innermost
filter->outputDimension[1] = 1;
filter->outputDimension[2] = 1;
- filter->outputDimension[3] = 1; // out
- filter->outputType = _NNS_END; // not initialized
+ filter->outputDimension[3] = 1; // out
+ filter->outputType = _NNS_END; // not initialized
filter->outputCapNegotiated = FALSE;
- filter->privateData = NULL; // mark not initialized.
+ filter->privateData = NULL; // mark not initialized.
}
/**
* @return the rank value
*/
static int
-gst_tensor_filter_get_rank(uint32_t *dimension) {
+gst_tensor_filter_get_rank (uint32_t * dimension)
+{
int i = 0;
int rank = 0;
- g_assert(dimension);
+ g_assert (dimension);
for (i = 0; i < NNS_TENSOR_RANK_LIMIT; i++) {
- g_assert(dimension[i] > 0);
+ g_assert (dimension[i] > 0);
if (dimension[i] > 1)
rank = i + 1;
}
- if (rank == 0) // a scalar (assume it is 1-dim vector)
+ if (rank == 0) // a scalar (assume it is 1-dim vector)
return 1;
return rank;
}
* This is supposed to be used by set_properties, restrting pad-caps before attaching input/output elements
*/
static GstCaps *
-gst_tensor_filter_fix_caps (GstTensor_Filter *filter, gboolean isInput, GstCaps *targetCaps, gboolean checkOnly) {
+gst_tensor_filter_fix_caps (GstTensor_Filter * filter, gboolean isInput,
+ GstCaps * targetCaps, gboolean checkOnly)
+{
tensor_type *type = NULL;
uint32_t *dimension;
GstCaps *tmp = NULL, *tmp2 = NULL;
}
/* 2. configure caps based on type & dimension */
- rank = gst_tensor_filter_get_rank(dimension);
- tmp = gst_caps_new_simple("other/tensor",
- "rank", G_TYPE_INT, rank,
- "type", G_TYPE_STRING, tensor_element_typename[*type],
- "dim1", G_TYPE_INT, dimension[0],
- "dim2", G_TYPE_INT, dimension[1],
- "dim3", G_TYPE_INT, dimension[2],
- "dim4", G_TYPE_INT, dimension[3],
- "framerate", GST_TYPE_FRACTION, 0, 1, /* @TODO: support other framerates! */
- NULL); /* Framerate is not determined with the given info */
+ rank = gst_tensor_filter_get_rank (dimension);
+ tmp = gst_caps_new_simple ("other/tensor", "rank", G_TYPE_INT, rank, "type", G_TYPE_STRING, tensor_element_typename[*type], "dim1", G_TYPE_INT, dimension[0], "dim2", G_TYPE_INT, dimension[1], "dim3", G_TYPE_INT, dimension[2], "dim4", G_TYPE_INT, dimension[3], "framerate", GST_TYPE_FRACTION, 0, 1, /* @TODO: support other framerates! */
+ NULL); /* Framerate is not determined with the given info */
if (filter->debug == TRUE) {
- gchar *str = gst_caps_to_string(tmp);
- g_printerr("Caps(%s) Narrowing to %s",
- (isInput == TRUE) ? "input/sink" : "output/src", str);
- g_printerr("\n");
- g_free(str);
+ gchar *str = gst_caps_to_string (tmp);
+ g_printerr ("Caps(%s) Narrowing to %s",
+ (isInput == TRUE) ? "input/sink" : "output/src", str);
+ g_printerr ("\n");
+ g_free (str);
}
if (checkOnly == TRUE) {
- gst_caps_unref(tmp);
+ gst_caps_unref (tmp);
return NULL;
}
if (targetCaps) {
gchar *str;
if (filter->debug == TRUE) {
- str = gst_caps_to_string(targetCaps);
- g_printerr("targetCaps: %s\n", str);
- g_free(str);
+ str = gst_caps_to_string (targetCaps);
+ g_printerr ("targetCaps: %s\n", str);
+ g_free (str);
}
- tmp2 = gst_caps_intersect_full(targetCaps, tmp, GST_CAPS_INTERSECT_FIRST);
- gst_caps_unref(tmp);
+ tmp2 = gst_caps_intersect_full (targetCaps, tmp, GST_CAPS_INTERSECT_FIRST);
+ gst_caps_unref (tmp);
tmp = tmp2;
if (filter->debug == TRUE) {
- str = gst_caps_to_string(tmp);
- g_printerr("resultCaps: %s\n", str);
- g_free(str);
+ str = gst_caps_to_string (tmp);
+ g_printerr ("resultCaps: %s\n", str);
+ g_free (str);
}
} else {
if (filter->debug == TRUE) {
- gchar *str = gst_caps_to_string(tmp);
- g_printerr("resultCaps w/o targetCaps: %s\n", str);
- g_free(str);
+ gchar *str = gst_caps_to_string (tmp);
+ g_printerr ("resultCaps w/o targetCaps: %s\n", str);
+ g_free (str);
}
}
/* @TODO 5. Verify with get_input/output_dimension callbacks! */
- return tmp; // @TODO Incorrect. Do "copy"
+ return tmp; // @TODO Incorrect. Do "copy"
}
* This can be done only by looking at input/ouput dimension queries.
*/
static gboolean
-gst_tensor_filter_configure_tensor(const GstCaps *caps, GstTensor_Filter *filter) {
+gst_tensor_filter_configure_tensor (const GstCaps * caps,
+ GstTensor_Filter * filter)
+{
/* @TODO 1: query input/output dims/types */
/* @TODO 2: verify it with current caps */
/* @TODO 3: return value assessment */
GstTensor_Filter *filter = GST_TENSOR_FILTER (object);
if (filter->debug == TRUE) {
- g_printerr("Setting property. for Prop %d.\n", prop_id);
+ g_printerr ("Setting property. for Prop %d.\n", prop_id);
}
switch (prop_id) {
case PROP_DEBUG:
filter->debug = g_value_get_boolean (value);
if (filter->debug == TRUE)
- g_printerr("Debug mode on");
+ g_printerr ("Debug mode on");
break;
case PROP_FRAMEWORK:
- g_assert(filter->nnfw == _T_F_UNDEFINED && value);
+ g_assert (filter->nnfw == _T_F_UNDEFINED && value);
/* Once configures, it cannot be changed in runtime */
- filter->nnfw = find_key_strv(nnfw_names, g_value_get_string(value));
+ filter->nnfw = find_key_strv (nnfw_names, g_value_get_string (value));
if (filter->debug == TRUE)
- g_printerr("Framework = %s\n", g_value_get_string(value));
- g_assert(filter->nnfw != -1);
- g_assert(filter->nnfw != _T_F_UNDEFINED);
- g_assert(nnfw_support_status[filter->nnfw] == TRUE);
+ g_printerr ("Framework = %s\n", g_value_get_string (value));
+ g_assert (filter->nnfw != -1);
+ g_assert (filter->nnfw != _T_F_UNDEFINED);
+ g_assert (nnfw_support_status[filter->nnfw] == TRUE);
filter->fw = tensor_filter_supported[filter->nnfw];
- g_assert(filter->fw != NULL);
+ g_assert (filter->fw != NULL);
break;
case PROP_MODEL:
- g_assert(filter->modelFilename == NULL && value);
+ g_assert (filter->modelFilename == NULL && value);
/* Once configures, it cannot be changed in runtime */
- filter->modelFilename = g_value_dup_string(value);
+ filter->modelFilename = g_value_dup_string (value);
if (filter->debug == TRUE)
- g_printerr("Model = %s\n", filter->modelFilename);
- g_assert(g_file_test(filter->modelFilename, G_FILE_TEST_IS_REGULAR) == TRUE);
+ g_printerr ("Model = %s\n", filter->modelFilename);
+ g_assert (g_file_test (filter->modelFilename,
+ G_FILE_TEST_IS_REGULAR) == TRUE);
break;
case PROP_INPUT:
- g_assert(filter->inputConfigured == FALSE && value);
+ g_assert (filter->inputConfigured == FALSE && value);
/* Once configures, it cannot be changed in runtime */
{
- int rank = get_tensor_dimension(g_value_get_string(value), filter->inputDimension);
- g_assert(rank > 0 && rank <= NNS_TENSOR_RANK_LIMIT);
- filter->inputConfigured = TRUE;
+ int rank =
+ get_tensor_dimension (g_value_get_string (value),
+ filter->inputDimension);
+ g_assert (rank > 0 && rank <= NNS_TENSOR_RANK_LIMIT);
+ filter->inputConfigured = TRUE;
if (filter->debug == TRUE)
- g_printerr("Input Prop: %d:%d:%d:%d Rank %d\n", filter->inputDimension[0], filter->inputDimension[1], filter->inputDimension[2], filter->inputDimension[3], rank);
+ g_printerr ("Input Prop: %d:%d:%d:%d Rank %d\n",
+ filter->inputDimension[0], filter->inputDimension[1],
+ filter->inputDimension[2], filter->inputDimension[3], rank);
}
if (filter->inputType != _NNS_END && filter->debug == TRUE)
- gst_tensor_filter_fix_caps(filter, TRUE, NULL, TRUE);
+ gst_tensor_filter_fix_caps (filter, TRUE, NULL, TRUE);
break;
case PROP_OUTPUT:
- g_assert(filter->outputConfigured == FALSE && value);
+ g_assert (filter->outputConfigured == FALSE && value);
/* Once configures, it cannot be changed in runtime */
{
- int rank = get_tensor_dimension(g_value_get_string(value), filter->outputDimension);
- g_assert(rank > 0 && rank <= NNS_TENSOR_RANK_LIMIT);
- filter->outputConfigured = TRUE;
+ int rank =
+ get_tensor_dimension (g_value_get_string (value),
+ filter->outputDimension);
+ g_assert (rank > 0 && rank <= NNS_TENSOR_RANK_LIMIT);
+ filter->outputConfigured = TRUE;
if (filter->debug == TRUE)
- g_printerr("Output Prop: %d:%d:%d:%d Rank %d\n", filter->outputDimension[0], filter->outputDimension[1], filter->outputDimension[2], filter->outputDimension[3], rank);
+ g_printerr ("Output Prop: %d:%d:%d:%d Rank %d\n",
+ filter->outputDimension[0], filter->outputDimension[1],
+ filter->outputDimension[2], filter->outputDimension[3], rank);
}
if (filter->outputType != _NNS_END && filter->debug == TRUE)
- gst_tensor_filter_fix_caps(filter, FALSE, NULL, TRUE);
+ gst_tensor_filter_fix_caps (filter, FALSE, NULL, TRUE);
break;
case PROP_INPUTTYPE:
- g_assert(filter->inputType == _NNS_END && value);
+ g_assert (filter->inputType == _NNS_END && value);
/* Once configures, it cannot be changed in runtime */
- filter->inputType = get_tensor_type(g_value_get_string(value));
+ filter->inputType = get_tensor_type (g_value_get_string (value));
if (filter->debug == TRUE)
- g_printerr("Output Type: %s -> %d\n", g_value_get_string(value), filter->inputType);
- g_assert(filter->inputType != _NNS_END);
+ g_printerr ("Output Type: %s -> %d\n", g_value_get_string (value),
+ filter->inputType);
+ g_assert (filter->inputType != _NNS_END);
if (filter->inputConfigured == TRUE && filter->debug == TRUE)
- gst_tensor_filter_fix_caps(filter, TRUE, NULL, TRUE);
+ gst_tensor_filter_fix_caps (filter, TRUE, NULL, TRUE);
break;
case PROP_OUTPUTTYPE:
- g_assert(filter->outputType == _NNS_END && value);
+ g_assert (filter->outputType == _NNS_END && value);
/* Once configures, it cannot be changed in runtime */
- filter->outputType = get_tensor_type(g_value_get_string(value));
- g_assert(filter->outputType != _NNS_END);
+ filter->outputType = get_tensor_type (g_value_get_string (value));
+ g_assert (filter->outputType != _NNS_END);
if (filter->outputConfigured == TRUE && filter->debug == TRUE)
- gst_tensor_filter_fix_caps(filter, FALSE, NULL, TRUE);
+ gst_tensor_filter_fix_caps (filter, FALSE, NULL, TRUE);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
GstTensor_Filter *filter = GST_TENSOR_FILTER (object);
if (filter->debug == TRUE) {
- g_printerr("Getting property. for Prop %d.\n", prop_id);
+ g_printerr ("Getting property. for Prop %d.\n", prop_id);
}
switch (prop_id) {
g_value_set_boolean (value, filter->debug);
break;
case PROP_FRAMEWORK:
- g_value_set_string(value, nnfw_names[filter->nnfw]);
+ g_value_set_string (value, nnfw_names[filter->nnfw]);
break;
case PROP_MODEL:
- g_value_set_string(value, filter->modelFilename);
+ g_value_set_string (value, filter->modelFilename);
break;
- case PROP_INPUT: {
- GArray *input = g_array_sized_new(FALSE, FALSE, 4, NNS_TENSOR_RANK_LIMIT);
- int i;
- for (i = 0; i < NNS_TENSOR_RANK_LIMIT; i++)
- g_array_append_val(input, filter->inputDimension[i]);
- g_value_take_boxed(value, input);
- // take function hands the object over from here so that we don't need to free it.
- }
+ case PROP_INPUT:{
+ GArray *input =
+ g_array_sized_new (FALSE, FALSE, 4, NNS_TENSOR_RANK_LIMIT);
+ int i;
+ for (i = 0; i < NNS_TENSOR_RANK_LIMIT; i++)
+ g_array_append_val (input, filter->inputDimension[i]);
+ g_value_take_boxed (value, input);
+ // take function hands the object over from here so that we don't need to free it.
+ }
break;
- case PROP_OUTPUT: {
- GArray *output = g_array_sized_new(FALSE, FALSE, 4, NNS_TENSOR_RANK_LIMIT);
- int i;
- for (i = 0; i < NNS_TENSOR_RANK_LIMIT; i++)
- g_array_append_val(output, filter->outputDimension[i]);
- g_value_take_boxed(value, output);
- // take function hands the object over from here so that we don't need to free it.
- }
+ case PROP_OUTPUT:{
+ GArray *output =
+ g_array_sized_new (FALSE, FALSE, 4, NNS_TENSOR_RANK_LIMIT);
+ int i;
+ for (i = 0; i < NNS_TENSOR_RANK_LIMIT; i++)
+ g_array_append_val (output, filter->outputDimension[i]);
+ g_value_take_boxed (value, output);
+ // take function hands the object over from here so that we don't need to free it.
+ }
break;
case PROP_INPUTTYPE:
- g_value_set_string(value, tensor_element_typename[filter->inputType]);
+ g_value_set_string (value, tensor_element_typename[filter->inputType]);
break;
case PROP_OUTPUTTYPE:
- g_value_set_string(value, tensor_element_typename[filter->outputType]);
+ g_value_set_string (value, tensor_element_typename[filter->outputType]);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
*
* exchange the string 'Template tensor_filter' with your tensor_filter description
*/
-GST_PLUGIN_DEFINE (
- GST_VERSION_MAJOR,
+GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
GST_VERSION_MINOR,
tensor_filter,
"tensor_filter",
- tensor_filter_init,
- VERSION,
- "LGPL",
- "GStreamer",
- "http://gstreamer.net/"
-)
-
-static GstFlowReturn gst_tensor_filter_transform(GstBaseTransform *trans,
- GstBuffer *inbuf,
- GstBuffer *outbuf)
+ tensor_filter_init, VERSION, "LGPL", "GStreamer", "http://gstreamer.net/")
+
+ static GstFlowReturn gst_tensor_filter_transform (GstBaseTransform * trans,
+ GstBuffer * inbuf, GstBuffer * outbuf)
{
- GstTensor_Filter *filter = GST_TENSOR_FILTER_CAST(trans);
+ GstTensor_Filter *filter = GST_TENSOR_FILTER_CAST (trans);
int ret;
uint32_t inputDimChk[NNS_TENSOR_RANK_LIMIT];
uint32_t outputDimChk[NNS_TENSOR_RANK_LIMIT];
uint8_t *inptr, *outptr;
GstMapInfo inInfo, outInfo;
- if (G_UNLIKELY(filter->inputCapNegotiated == FALSE || filter->outputCapNegotiated == FALSE))
+ if (G_UNLIKELY (filter->inputCapNegotiated == FALSE
+ || filter->outputCapNegotiated == FALSE))
goto unknown_format;
- if (G_UNLIKELY(!filter->fw))
+ if (G_UNLIKELY (!filter->fw))
goto unknown_framework;
- if (G_UNLIKELY(!filter->modelFilename))
+ if (G_UNLIKELY (!filter->modelFilename))
goto unknown_model;
- if (G_UNLIKELY(!filter->fw->invoke_NN))
+ if (G_UNLIKELY (!filter->fw->invoke_NN))
goto unknown_invoke;
/* 0. Check all properties and inbuf size. */
if (filter->debug)
- g_printerr("Invoking %s with %s model\n", filter->fw->name, filter->modelFilename);
+ g_printerr ("Invoking %s with %s model\n", filter->fw->name,
+ filter->modelFilename);
if (filter->fw->getInputDimension) {
- ret = filter->fw->getInputDimension(filter, inputDimChk, &inputType);
+ ret = filter->fw->getInputDimension (filter, inputDimChk, &inputType);
/* @TODO check inputDimChk / inputType with filter internal info */
} else {
/* @TODO printout debug msg */
}
if (filter->fw->getOutputDimension) {
- ret = filter->fw->getOutputDimension(filter, outputDimChk, &outputType);
+ ret = filter->fw->getOutputDimension (filter, outputDimChk, &outputType);
/* @TODO check outputDimChk / outputType with filter internal info */
} else {
/* @TODO printout debug msg */
}
/* 1. Allocate outbuf */
- g_assert(outbuf);
+ g_assert (outbuf);
outBufSize = tensor_element_size[filter->inputType] *
- get_tensor_element_count(filter->inputDimension);
- if (gst_buffer_get_size(outbuf) < outBufSize) {
- gst_buffer_set_size(outbuf, outBufSize);
+ get_tensor_element_count (filter->inputDimension);
+ if (gst_buffer_get_size (outbuf) < outBufSize) {
+ gst_buffer_set_size (outbuf, outBufSize);
}
- g_assert(gst_buffer_get_size(outbuf) >= outBufSize);
+ g_assert (gst_buffer_get_size (outbuf) >= outBufSize);
/* 2. Call the filter-subplugin callback, "invoke" */
- gst_buffer_map(inbuf, &inInfo, GST_MAP_READ);
- gst_buffer_map(outbuf, &outInfo, GST_MAP_WRITE);
+ gst_buffer_map (inbuf, &inInfo, GST_MAP_READ);
+ gst_buffer_map (outbuf, &outInfo, GST_MAP_WRITE);
inptr = inInfo.data;
outptr = outInfo.data;
- ret = filter->fw->invoke_NN(filter, inptr, outptr);
+ ret = filter->fw->invoke_NN (filter, inptr, outptr);
- gst_buffer_unmap(inbuf, &inInfo);
- gst_buffer_unmap(outbuf, &outInfo);
+ gst_buffer_unmap (inbuf, &inInfo);
+ gst_buffer_unmap (outbuf, &outInfo);
/* 3. Return result! */
if (ret)
return GST_FLOW_ERROR;
return GST_FLOW_OK;
unknown_format:
- GST_ELEMENT_ERROR(filter, CORE, NOT_IMPLEMENTED, (NULL), ("unknown format"));
+ GST_ELEMENT_ERROR (filter, CORE, NOT_IMPLEMENTED, (NULL), ("unknown format"));
return GST_FLOW_NOT_NEGOTIATED;
unknown_framework:
- GST_ELEMENT_ERROR(filter, CORE, NOT_IMPLEMENTED, (NULL), ("framework not configured"));
+ GST_ELEMENT_ERROR (filter, CORE, NOT_IMPLEMENTED, (NULL),
+ ("framework not configured"));
return GST_FLOW_ERROR;
unknown_model:
- GST_ELEMENT_ERROR(filter, CORE, NOT_IMPLEMENTED, (NULL), ("model filepath not configured"));
+ GST_ELEMENT_ERROR (filter, CORE, NOT_IMPLEMENTED, (NULL),
+ ("model filepath not configured"));
return GST_FLOW_ERROR;
unknown_invoke:
- GST_ELEMENT_ERROR(filter, CORE, NOT_IMPLEMENTED, (NULL), ("invoke function is not defined"));
+ GST_ELEMENT_ERROR (filter, CORE, NOT_IMPLEMENTED, (NULL),
+ ("invoke function is not defined"));
return GST_FLOW_ERROR;
}
-static GstFlowReturn gst_tensor_filter_transform_ip(GstBaseTransform *trans,
- GstBuffer *buf)
+static GstFlowReturn
+gst_tensor_filter_transform_ip (GstBaseTransform * trans, GstBuffer * buf)
{
/* @TODO 0. Check all properties and inbuf size. */
/* @TODO 0-1. This shouldn't reach here if in-place mode if OFF with the subplugin */
/* @TODO 1. Resize buf if output is larger than input */
/* @TODO 2. Call the filter-subplugin callback, "invoke" */
/* @TODO 3. Return result! */
- g_assert(1 == 0);
+ g_assert (1 == 0);
return GST_FLOW_ERROR;
}
* @caps sinkpad cap
* @filter this element's cap (don't know specifically.)
*/
-static GstCaps* gst_tensor_filter_transform_caps(GstBaseTransform *trans,
- GstPadDirection direction,
- GstCaps *caps,
- GstCaps *filter)
+static GstCaps *
+gst_tensor_filter_transform_caps (GstBaseTransform * trans,
+ GstPadDirection direction, GstCaps * caps, GstCaps * filter)
{
- GstTensor_Filter *obj = GST_TENSOR_FILTER_CAST(trans);
+ GstTensor_Filter *obj = GST_TENSOR_FILTER_CAST (trans);
if (direction == GST_PAD_SINK) {
/* caps: sink pad. get src pad info */
/* @TODO 1. Check caps w/ getInputDimension && saved input dimension */
/* @TODO 2. Check returning-caps w/ getOutputDimension && saved output dimension */
- return gst_tensor_filter_fix_caps(obj, FALSE, filter, FALSE);
+ return gst_tensor_filter_fix_caps (obj, FALSE, filter, FALSE);
} else {
/* caps: src pad. get sink pad info */
obj->inputCapNegotiated = TRUE;
/* @TODO 1. Check caps w/ getOutputDimension && saved output dimension */
/* @TODO 2. Check returning-caps w/ getInputDimension && saved input dimension */
- return gst_tensor_filter_fix_caps(obj, TRUE, filter, FALSE);
+ return gst_tensor_filter_fix_caps (obj, TRUE, filter, FALSE);
}
/* @TODO Cannot reach here. Remove them later */
- g_assert(1 == 0);
- gst_tensor_filter_configure_tensor(caps, obj);
+ g_assert (1 == 0);
+ gst_tensor_filter_configure_tensor (caps, obj);
return NULL;
}
-static GstCaps* gst_tensor_filter_fixate_caps(GstBaseTransform *trans,
- GstPadDirection direction,
- GstCaps *caps,
- GstCaps *othercaps)
+static GstCaps *
+gst_tensor_filter_fixate_caps (GstBaseTransform * trans,
+ GstPadDirection direction, GstCaps * caps, GstCaps * othercaps)
{
- GstCaps *supposed = gst_tensor_filter_transform_caps(trans, direction, caps, NULL);
- GstCaps *result = gst_caps_intersect(othercaps, supposed);
- GstTensor_Filter *obj = GST_TENSOR_FILTER_CAST(trans);
+ GstCaps *supposed =
+ gst_tensor_filter_transform_caps (trans, direction, caps, NULL);
+ GstCaps *result = gst_caps_intersect (othercaps, supposed);
+ GstTensor_Filter *obj = GST_TENSOR_FILTER_CAST (trans);
- g_assert(!gst_caps_is_empty(result));
- gst_caps_unref(othercaps);
+ g_assert (!gst_caps_is_empty (result));
+ gst_caps_unref (othercaps);
- result = gst_caps_make_writable(result);
- result = gst_caps_fixate(result);
+ result = gst_caps_make_writable (result);
+ result = gst_caps_fixate (result);
if (direction == GST_PAD_SINK) {
- if (gst_caps_is_subset(caps, result)) {
- gst_caps_replace(&result, caps);
+ if (gst_caps_is_subset (caps, result)) {
+ gst_caps_replace (&result, caps);
}
obj->inputCapNegotiated = TRUE;
} else {
return result;
}
-static gboolean gst_tensor_filter_set_caps(GstBaseTransform *trans,
- GstCaps *incaps,
- GstCaps *outcaps)
+static gboolean
+gst_tensor_filter_set_caps (GstBaseTransform * trans,
+ GstCaps * incaps, GstCaps * outcaps)
{
- GstTensor_Filter *filter = GST_TENSOR_FILTER_CAST(trans);
+ GstTensor_Filter *filter = GST_TENSOR_FILTER_CAST (trans);
/* @TODO This code is for testing only. Not even with proper design / concepts */
- gst_tensor_filter_configure_tensor(incaps, filter); /* we will need to supply outcaps as well */
+ gst_tensor_filter_configure_tensor (incaps, filter); /* we will need to supply outcaps as well */
/* Nothing to do yet. */
return TRUE;
#include <glib.h>
#include <dlfcn.h>
-struct _internal_data {
+struct _internal_data
+{
GstTensor_Filter *parent;
void *handle;
NNStreamer_custom_class *methods;
- void* customFW_private_data;
+ void *customFW_private_data;
};
typedef struct _internal_data internal_data;
* @brief Load the custom library. Will skip loading if it's already loaded.
* @return 0 if successfully loaded. 1 if skipped (already loaded). -1 if error
*/
-static int custom_loadlib(GstTensor_Filter *filter) {
+static int
+custom_loadlib (GstTensor_Filter * filter)
+{
internal_data *ptr;
char *dlsym_error;
return 1;
}
- ptr = g_new0(internal_data, 1); /* Fill Zero! */
+ ptr = g_new0 (internal_data, 1); /* Fill Zero! */
filter->privateData = ptr;
ptr->parent = filter;
/* Load .so if this is the first time for this instance. */
- ptr->handle = dlopen(filter->modelFilename, RTLD_NOW);
+ ptr->handle = dlopen (filter->modelFilename, RTLD_NOW);
if (!ptr->handle) {
- g_free(ptr);
+ g_free (ptr);
filter->privateData = NULL;
return -1;
}
- dlerror();
- ptr->methods = *((NNStreamer_custom_class **) dlsym(ptr->handle, "NNStreamer_custom"));
- dlsym_error = dlerror();
+ dlerror ();
+ ptr->methods =
+ *((NNStreamer_custom_class **) dlsym (ptr->handle, "NNStreamer_custom"));
+ dlsym_error = dlerror ();
if (dlsym_error) {
- g_printerr("tensor_filter_custom:loadlib error: %s\n", dlsym_error);
- dlclose(ptr->handle);
- g_free(ptr);
+ g_printerr ("tensor_filter_custom:loadlib error: %s\n", dlsym_error);
+ dlclose (ptr->handle);
+ g_free (ptr);
filter->privateData = NULL;
return -1;
}
- g_assert(ptr->methods->initfunc);
- ptr->customFW_private_data = ptr->methods->initfunc();
+ g_assert (ptr->methods->initfunc);
+ ptr->customFW_private_data = ptr->methods->initfunc ();
return 0;
}
* @param[in] inptr The input tensor
* @param[out] outptr The output tensor
*/
-static int custom_invoke(GstTensor_Filter *filter, uint8_t *inptr, uint8_t *outptr) {
- int retval = custom_loadlib(filter);
+static int
+custom_invoke (GstTensor_Filter * filter, uint8_t * inptr, uint8_t * outptr)
+{
+ int retval = custom_loadlib (filter);
internal_data *ptr;
/* Actually, tensor_filter must have called getInput/OotputDim first. */
- g_assert(retval != 0);
+ g_assert (retval != 0);
if (retval < 0)
return retval;
- g_assert(filter->privateData);
+ g_assert (filter->privateData);
ptr = filter->privateData;
- return ptr->methods->invoke(ptr->customFW_private_data, inptr, outptr);
+ return ptr->methods->invoke (ptr->customFW_private_data, inptr, outptr);
}
/**
* @brief The optional callback for GstTensor_Filter_Framework
*/
-static int custom_getInputDim(GstTensor_Filter *filter, uint32_t *inputDimension, tensor_type *type) {
- int retval = custom_loadlib(filter);
+static int
+custom_getInputDim (GstTensor_Filter * filter, uint32_t * inputDimension,
+ tensor_type * type)
+{
+ int retval = custom_loadlib (filter);
internal_data *ptr;
if (retval < 0)
return retval;
- g_assert(filter->privateData);
+ g_assert (filter->privateData);
ptr = filter->privateData;
- return ptr->methods->getInputDim(ptr->customFW_private_data, inputDimension, type);
+ return ptr->methods->getInputDim (ptr->customFW_private_data, inputDimension,
+ type);
}
/**
* @brief The optional callback for GstTensor_Filter_Framework
*/
-static int custom_getOutputDim(GstTensor_Filter *filter, uint32_t *outputDimension, tensor_type *type) {
- int retval = custom_loadlib(filter);
+static int
+custom_getOutputDim (GstTensor_Filter * filter, uint32_t * outputDimension,
+ tensor_type * type)
+{
+ int retval = custom_loadlib (filter);
internal_data *ptr;
if (retval < 0)
return retval;
- g_assert(filter->privateData);
+ g_assert (filter->privateData);
ptr = filter->privateData;
- return ptr->methods->getOutputDim(ptr->customFW_private_data, outputDimension, type);
+ return ptr->methods->getOutputDim (ptr->customFW_private_data,
+ outputDimension, type);
}
/**
* @brief Free privateData and move on.
*/
-static void custom_close(GstTensor_Filter *filter) {
+static void
+custom_close (GstTensor_Filter * filter)
+{
internal_data *ptr = filter->privateData;
- ptr->methods->exitfunc(ptr->customFW_private_data);
- g_free(ptr);
+ ptr->methods->exitfunc (ptr->customFW_private_data);
+ g_free (ptr);
filter->privateData = NULL;
}
GstTensor_Filter_Framework NNS_support_custom = {
.name = "custom",
- .allow_in_place = FALSE, // custom cannot support in-place (outptr == inptr).
+ .allow_in_place = FALSE, // custom cannot support in-place (outptr == inptr).
.invoke_NN = custom_invoke,
.getInputDimension = custom_getInputDim,
.getOutputDimension = custom_getOutputDim,
/**
* @brief The mandatory callback for GstTensor_Filter_Framework
*/
-static int tflite_invoke(GstTensor_Filter *filter, uint8_t *inptr, uint8_t *outptr) {
- return 0; // NYI
+static int
+tflite_invoke (GstTensor_Filter * filter, uint8_t * inptr, uint8_t * outptr)
+{
+ return 0; // NYI
}
/**
* @brief The optional callback for GstTensor_Filter_Framework
*/
-static int tflite_getInputDim(GstTensor_Filter *filter, uint32_t *inputDimension, tensor_type *type) {
+static int
+tflite_getInputDim (GstTensor_Filter * filter, uint32_t * inputDimension,
+ tensor_type * type)
+{
// @TODO fill in *inputDimension (uint32_t[MAX_RANK]), *type
- return 0; // NYI
+ return 0; // NYI
}
/**
* @brief The optional callback for GstTensor_Filter_Framework
*/
-static int tflite_getOutputDim(GstTensor_Filter *filter, uint32_t *outputDimension, tensor_type *type) {
+static int
+tflite_getOutputDim (GstTensor_Filter * filter, uint32_t * outputDimension,
+ tensor_type * type)
+{
// @TODO fill in *outputDimension (uint32_t[MAX_RANK]), *type
- return 0; // NYI
+ return 0; // NYI
}
GstTensor_Filter_Framework NNS_support_tensorflow_lite = {
.name = "tensorflow-lite",
- .allow_in_place = FALSE, // Let's not do this yet. @TODO: support this to optimize performance later.
+ .allow_in_place = FALSE, // Let's not do this yet. @TODO: support this to optimize performance later.
.invoke_NN = tflite_invoke,
.getInputDimension = tflite_getInputDim,
.getOutputDimension = tflite_getOutputDim,