return meta->num_tensors;
}
+/**
+ * @brief Utility function to parse string
+ * @param str input string to parse
+ * @param delim delimitor
+ * @param arr output array to store parsed string
+ * @return gint number of parsed string
+ */
+static gint
+parse_string (const gchar * str, const char *delim, char ***arr)
+{
+ char *pch, *buf;
+ int count = 0;
+ buf = strdup (str);
+ pch = strtok (buf, delim);
+ while (pch != NULL) {
+ pch = strtok (NULL, delim);
+ count++;
+ }
+ free (buf);
+
+ (*arr) = (char **) malloc (sizeof (char *) * count);
+
+ count = 0;
+ pch = NULL;
+ buf = strdup (str);
+ pch = strtok (buf, delim);
+ while (pch != NULL) {
+ (*arr)[count] = strdup (pch);
+ pch = strtok (NULL, delim);
+ count++;
+ }
+ free (buf);
+ return count;
+}
+
GArray *
parse_dimensions (const gchar * dim_string)
{
GArray *dimensions;
gint num_tensors;
- gchar *tempbuf;
char **arr;
+ unsigned int i;
- char *pch;
- num_tensors = 0;
- tempbuf = strdup (dim_string);
- pch = strtok (tempbuf, " ,");
- while (pch != NULL) {
- pch = strtok (NULL, " ,");
- num_tensors++;
- }
+ num_tensors = parse_string (dim_string, " ,.;/", &arr);
dimensions =
g_array_sized_new (FALSE, FALSE, sizeof (tensor_dim *), num_tensors);
- arr = (char **) malloc (sizeof (char *) * num_tensors);
-
- num_tensors = 0;
- pch = NULL;
- tempbuf = strdup (dim_string);
-
- pch = strtok (tempbuf, " ,");
- while (pch != NULL) {
- arr[num_tensors] = strdup (pch);
- pch = strtok (NULL, " ,");
- num_tensors++;
- }
- for (int i = 0; i < num_tensors; i++) {
+ for (i = 0; i < num_tensors; i++) {
char *p = strtok (arr[i], " :");
int c = 0;
tensor_dim *d = g_new0 (tensor_dim, 1);
g_array_append_val (dimensions, d);
}
+ for (i = 0; i < num_tensors; i++)
+ free (arr[i]);
free (arr);
return dimensions;
+}
+
+GArray *
+parse_types (const gchar * types_string)
+{
+ char **charbuf;
+ int num_type;
+ unsigned int i;
+ num_type = parse_string (types_string, " ,.:/", &charbuf);
+ GArray *types =
+ g_array_sized_new (FALSE, FALSE, sizeof (tensor_type *), num_type);
+
+ for (i = 0; i < num_type; i++) {
+ tensor_type *t = g_new0 (tensor_type, 1);
+ (*t) = get_tensor_type (charbuf[i]);
+ g_array_append_val (types, t);
+ }
+ for (i = 0; i < num_type; i++)
+ free (charbuf[i]);
+ free (charbuf);
+ return types;
}
"other/tensors, " \
"rank = (int) [ 1, 4 ], " \
"num_tensors = (int) [1, 65535], "\
- "type = (string) { float32, float64, int32, uint32, int16, uint16, int8, uint8 }, " \
"framerate = (fraction) [ 0/1, 2147483647/1 ]"
+ /* type should be one of { float32, float64, int32, uint32, int16, uint16, int8, uint8 } */
+ /* "types = (string) uint8, uint8, uint8" \ */
/* Dimensions of Tensors for negotiation. It's comment out here,
but when we call gst_structure_get_string, it actually is working well.*/
/* "dimensions = (string) dim1:dim2:dim3:dim4, dim1:dim2:dim3:dim4" \ */
*/
gint gst_get_num_tensors (GstBuffer *buffer);
+/**
+ * @brief Utility function to get parse the dimension of tensors
+ * @param dim_string Input String to parse
+ * @return GArray Array which includes tensor_dim for each tensor
+ */
GArray * parse_dimensions (const gchar* dim_string);
+/**
+ * @brief Utility function to get parse the type of tensors
+ * @param type_string Input String to parse
+ * @return GArray Array which includes tensor_type for each tensor
+ */
+GArray * parse_types (const gchar* type_string);
+
G_END_DECLS
#endif /* __GST_TENSOR_META_H__ */
gint dim;
GstCaps *othercaps;
const gchar *dim_string;
+ const gchar *types;
+ int i;
GstStructure *s = gst_caps_get_structure (caps, 0);
gst_structure_get_int (s, "rank", &filter->rank);
if (dim_string) {
debug_print (!filter->silent, "dimension sting : %s\n", dim_string);
filter->dimensions = parse_dimensions (dim_string);
- for (int i = 0; i < filter->num_tensors; i++) {
+ for (i = 0; i < filter->num_tensors; i++) {
tensor_dim *d = g_array_index (filter->dimensions, tensor_dim *, i);
debug_print (!filter->silent, "dimensions[%d] %d %d %d %d\n", i, (*d)[0],
(*d)[1], (*d)[2], (*d)[3]);
}
gst_structure_get_fraction (s, "framerate", &filter->framerate_numerator,
&filter->framerate_denominator);
- filter->type = _NNS_UINT8;
+ types = gst_structure_get_string (s, "types");
+ if (types) {
+ debug_print (!filter->silent, "types string : %s\n", types);
+ filter->types = parse_types (types);
+ for (i = 0; i < filter->num_tensors; i++) {
+ tensor_type *t = g_array_index (filter->types, tensor_type *, i);
+ debug_print (!filter->silent, "types[%d] %s\n", i,
+ tensor_element_typename[(*t)]);
+ }
+ } else {
+ err_print ("Cannot get types for negotiation!\n");
+ }
tensor_dim *d = g_array_index (filter->dimensions, tensor_dim *, 0);
+ tensor_type *t = g_array_index (filter->types, tensor_type *, 0);
othercaps = gst_caps_new_simple ("other/tensor",
"rank", G_TYPE_INT, filter->rank,
"dim1", G_TYPE_INT, (*d)[0],
"dim2", G_TYPE_INT, (*d)[1],
"dim3", G_TYPE_INT, (*d)[2],
"dim4", G_TYPE_INT, (*d)[3],
- "type", G_TYPE_STRING, tensor_element_typename[filter->type],
+ "type", G_TYPE_STRING, tensor_element_typename[*t],
"framerate", GST_TYPE_FRACTION, filter->framerate_numerator,
filter->framerate_denominator, NULL);
ret = gst_pad_set_caps (filter->srcpad, othercaps);
GstMapInfo info, src_info, dest_info;
GstMemory *buffer_mem;
tensor_dim *dim;
- unsigned int d0, d1, d2;
+ unsigned int d0, d1, d2, i;
gboolean ret;
/* Mapping input buffer (tensors) into src_info */
/* Get number of tensors */
num_tensors = gst_get_num_tensors (inbuf);
debug_print (!filter->silent, "Number of Tensors : %d\n", num_tensors);
- for (int i = 0; i < num_tensors; i++) {
+ for (i = 0; i < num_tensors; i++) {
GstMemory *mem = gst_get_tensor (inbuf, i);
if (!mem)
debug_print (!filter->silent, "Cannot get memory\n");
GArray *dimensions;
gint num_tensors;
gint rank;
- tensor_type type;
+ GArray *types;
gint framerate_numerator;
gint framerate_denominator;
gboolean passthrough;
#include <gst/gst.h>
#include "gsttesttensors.h"
+#include <string.h>
GST_DEBUG_CATEGORY_STATIC (gst_testtensors_debug);
#define GST_CAT_DEFAULT gst_testtensors_debug
gint dim;
GstCaps *othercaps;
gboolean ret;
+ unsigned int i;
GstStructure *s = gst_caps_get_structure (caps, 0);
filter->type = _NNS_UINT8;
filter->rank = 3;
+ char str[256];
+ strcpy (str, tensor_element_typename[filter->type]);
+ for (i = 1; i < filter->num_tensors; i++) {
+ strcat (str, ",");
+ strcat (str, tensor_element_typename[filter->type]);
+ }
+
othercaps = gst_caps_new_simple ("other/tensors",
"rank", G_TYPE_INT, filter->rank,
"num_tensors", G_TYPE_INT, filter->num_tensors,
- "type", G_TYPE_STRING, tensor_element_typename[filter->type],
+ "types", G_TYPE_STRING, str,
"framerate", GST_TYPE_FRACTION, filter->framerate_numerator,
filter->framerate_denominator, "dimensions", G_TYPE_STRING,
"1:640:480:1 ,1:640:480:3 ,1:640:480:1", NULL);