[Common/Refactor] Remove rank from pad cap
authorMyungJoo Ham <myungjoo.ham@samsung.com>
Mon, 10 Sep 2018 02:41:10 +0000 (11:41 +0900)
committerMyungJoo Ham <myungjoo.ham@gmail.com>
Mon, 10 Sep 2018 07:48:01 +0000 (16:48 +0900)
- Remove rank from pad cap of other/tensor and other/tensors
- Remove dependencies on rank info from plugins

Signed-off-by: MyungJoo Ham <myungjoo.ham@samsung.com>
common/tensor_common.c
gst/tensor_demux/gsttensordemux.c
gst/tensor_filter/tensor_filter.c
gst/tensor_mux/gsttensormux.c
gst/tensor_transform/tensor_transform.c
include/tensor_common.h

index 9dca6a1..7ea837f 100644 (file)
@@ -344,7 +344,6 @@ gst_tensor_config_init (GstTensorConfig * config)
 
   g_return_if_fail (config != NULL);
 
-  config->rank = 0;
   config->type = _NNS_END;
 
   for (i = 0; i < NNS_TENSOR_RANK_LIMIT; i++) {
@@ -367,10 +366,6 @@ gst_tensor_config_validate (const GstTensorConfig * config)
 
   g_return_val_if_fail (config != NULL, FALSE);
 
-  if (config->rank == 0) {
-    return FALSE;
-  }
-
   if (config->type == _NNS_END) {
     return FALSE;
   }
@@ -401,10 +396,6 @@ gst_tensor_config_is_same (const GstTensorConfig * c1,
   g_return_val_if_fail (c1 != NULL, FALSE);
   g_return_val_if_fail (c2 != NULL, FALSE);
 
-  if (c1->rank != c2->rank) {
-    return FALSE;
-  }
-
   if (c1->type != c2->type) {
     return FALSE;
   }
@@ -445,7 +436,6 @@ gst_tensor_config_from_tensor_structure (GstTensorConfig * config,
     return FALSE;
   }
 
-  gst_structure_get_int (structure, "rank", &config->rank);
   gst_structure_get_int (structure, "dim1", (gint *) (&config->dimension[0]));
   gst_structure_get_int (structure, "dim2", (gint *) (&config->dimension[1]));
   gst_structure_get_int (structure, "dim3", (gint *) (&config->dimension[2]));
@@ -568,9 +558,6 @@ gst_tensor_config_from_video_info (GstTensorConfig * config,
 
   gst_tensor_config_init (config);
 
-  /** @todo remove rank */
-  config->rank = 3;
-
   /** [color-space][width][height][frames] */
   switch (v_info->format) {
     case GST_VIDEO_FORMAT_GRAY8:
@@ -622,9 +609,6 @@ gst_tensor_config_from_audio_info (GstTensorConfig * config,
 
   gst_tensor_config_init (config);
 
-  /** @todo remove rank */
-  config->rank = 2;
-
   /** [channels][frames] */
   switch (a_info->format) {
     case GST_AUDIO_FORMAT_S8:
@@ -678,9 +662,6 @@ gst_tensor_config_from_text_info (GstTensorConfig * config,
 
   gst_tensor_config_init (config);
 
-  /** @todo remove rank */
-  config->rank = 2;
-
   /** [size][frames] */
   switch (t_info->format) {
     case 1:
@@ -719,10 +700,6 @@ gst_tensor_caps_from_config (const GstTensorConfig * config)
 
   caps = gst_caps_from_string (GST_TENSOR_CAP_DEFAULT);
 
-  if (config->rank > 0) {
-    gst_caps_set_simple (caps, "rank", G_TYPE_INT, config->rank, NULL);
-  }
-
   if (config->dimension[0] > 0) {
     gst_caps_set_simple (caps, "dim1", G_TYPE_INT, config->dimension[0], NULL);
   }
@@ -921,8 +898,6 @@ get_tensor_from_structure (const GstStructure * str, tensor_dim dim,
 {
   GstTensor_Filter_CheckStatus ret = _TFC_INIT;
   const gchar *strval;
-  int rank;
-  int j;
   gint fn, fd;
 
   if (!gst_structure_has_name (str, "other/tensor"))
@@ -933,10 +908,6 @@ get_tensor_from_structure (const GstStructure * str, tensor_dim dim,
       gst_structure_get_int (str, "dim3", (int *) &dim[2]) &&
       gst_structure_get_int (str, "dim4", (int *) &dim[3])) {
     ret |= _TFC_DIMENSION;
-    if (gst_structure_get_int (str, "rank", &rank)) {
-      for (j = rank; j < NNS_TENSOR_RANK_LIMIT; j++)
-        g_assert (dim[j] == 1);
-    }
   }
   strval = gst_structure_get_string (str, "type");
   if (strval) {
@@ -994,22 +965,6 @@ get_tensors_from_structure (const GstStructure * str,
 
   meta->num_tensors = num;
 
-  strval = gst_structure_get_string (str, "rank");
-
-  strv = g_strsplit (strval, ",./", -1);
-  counter = 0;
-  while (strv[counter]) {
-    rank[counter] = g_ascii_strtod (strv[counter], NULL);
-    if (rank[counter] != NNS_TENSOR_RANK_LIMIT) {
-      err_print ("rank value of other/tensors incorrect.\n");
-      rank[counter] = 0;
-      return 0;
-    }
-    counter++;
-  }
-
-  g_strfreev (strv);
-
   if (gst_structure_get_fraction (str, "framerate", &fn, &fd)) {
     if (framerate_num)
       *framerate_num = fn;
index 1285577..8e03929 100644 (file)
@@ -353,7 +353,6 @@ gst_get_tensor_pad (GstTensorDemux * tensor_demux, GstBuffer * inbuf,
   gst_event_unref (event);
 
   caps_string = g_strdup_printf ("other/tensor, "
-      "rank = (int)4, "
       "type = (string)%s,"
       "framerate = (fraction) %d/%d, "
       "dim1 = (int) %d, "
index c73aad4..68b19bb 100644 (file)
@@ -303,27 +303,6 @@ gst_tensor_filter_init (GstTensor_Filter * filter)
       filter->prop.fw->fwClosed = TRUE; \
     } while (0);
 
-/**
- * @brief Calculate the rank of a tensor
- * @param dimension The dimension vector (tensor_dim = uint32_t[NNS_TENSOR_RANK_LIMIT]) of tensor.
- * @return the rank value
- */
-static int
-gst_tensor_filter_get_rank (const tensor_dim dimension)
-{
-  int i = 0;
-  int rank = 0;
-  g_assert (dimension);
-  for (i = 0; i < NNS_TENSOR_RANK_LIMIT; i++) {
-    g_assert (dimension[i] > 0);
-    if (dimension[i] > 1)
-      rank = i + 1;
-  }
-  if (rank == 0)                /* a scalar (assume it is 1-dim vector) */
-    return 1;
-  return rank;
-}
-
 static GstTensor_Filter_CheckStatus
 gst_tensor_filter_generate_dim_from_cap (GstCaps * caps, const tensor_dim dim,
     tensor_type * type);
@@ -350,7 +329,6 @@ gst_tensor_filter_fix_caps (GstTensor_Filter * filter, gboolean isInput,
   GstTensor_Filter_Properties *prop = &filter->prop;
   GstCaps *tmp = NULL, *tmp2 = NULL, *staticcap = NULL, *resultCaps = NULL;
   GstStaticCaps rawcap = GST_STATIC_CAPS (GST_TENSOR_CAP_DEFAULT);
-  int rank;
   staticcap = gst_static_caps_get (&rawcap);
 
   if (isInput == TRUE) {
@@ -371,18 +349,16 @@ gst_tensor_filter_fix_caps (GstTensor_Filter * filter, gboolean isInput,
 
   /* 2. configure caps based on type & dimension */
   if (configured == _TFC_ALL) {
-    rank = gst_tensor_filter_get_rank (dimension[0]);
     tmp2 =
-        gst_caps_new_simple ("other/tensor", "rank", G_TYPE_INT, rank, "type",
+        gst_caps_new_simple ("other/tensor", "type",
         G_TYPE_STRING, tensor_element_typename[type[0]], "dim1", G_TYPE_INT,
         dimension[0][0], "dim2", G_TYPE_INT, dimension[0][1], "dim3",
         G_TYPE_INT, dimension[0][2], "dim4", G_TYPE_INT, dimension[0][3], NULL);
     tmp = gst_caps_intersect_full (staticcap, tmp2, GST_CAPS_INTERSECT_FIRST);
     gst_caps_unref (tmp2);
   } else if (configured == _TFC_DIMENSION) {
-    rank = gst_tensor_filter_get_rank (dimension[0]);
     tmp2 =
-        gst_caps_new_simple ("other/tensor", "rank", G_TYPE_INT, rank, "dim1",
+        gst_caps_new_simple ("other/tensor", "dim1",
         G_TYPE_INT, dimension[0][0], "dim2", G_TYPE_INT, dimension[0][1],
         "dim3", G_TYPE_INT, dimension[0][2], "dim4", G_TYPE_INT,
         dimension[0][3], NULL);
@@ -463,9 +439,8 @@ gst_tensor_filter_fix_caps (GstTensor_Filter * filter, gboolean isInput,
 
     /* 3-1.2. Configure resultCap from rdim/rtype */
     if (resultCaps == NULL) {
-      rank = gst_tensor_filter_get_rank (outputMeta.dims[0]);
       resultCaps =
-          gst_caps_new_simple ("other/tensor", "rank", G_TYPE_INT, rank, "type",
+          gst_caps_new_simple ("other/tensor", "type",
           G_TYPE_STRING, tensor_element_typename[outputMeta.types[0]], "dim1",
           G_TYPE_INT, outputMeta.dims[0][0], "dim2", G_TYPE_INT,
           outputMeta.dims[0][1], "dim3", G_TYPE_INT, outputMeta.dims[0][2],
@@ -491,9 +466,8 @@ gst_tensor_filter_fix_caps (GstTensor_Filter * filter, gboolean isInput,
 
     /* 3-1.2. Configure resultCap from rdim/rtype */
     if (resultCaps == NULL) {
-      rank = gst_tensor_filter_get_rank (meta.dims[0]);
       resultCaps =
-          gst_caps_new_simple ("other/tensor", "rank", G_TYPE_INT, rank,
+          gst_caps_new_simple ("other/tensor",
           "type", G_TYPE_STRING, tensor_element_typename[meta.types[0]], "dim1",
           G_TYPE_INT, meta.dims[0][0], "dim2", G_TYPE_INT, meta.dims[0][1],
           "dim3", G_TYPE_INT, meta.dims[0][2], "dim4", G_TYPE_INT,
@@ -1018,7 +992,6 @@ gst_tensor_filter_generate_dim_from_cap (GstCaps * caps, const tensor_dim dim,
   unsigned int i, capsize;
   const GstStructure *str;
   GstTensor_Filter_CheckStatus ret = _TFC_INIT;
-  int rank;
   const gchar *strval;
 
   if (!caps) {
@@ -1033,12 +1006,7 @@ gst_tensor_filter_generate_dim_from_cap (GstCaps * caps, const tensor_dim dim,
         gst_structure_get_int (str, "dim2", (int *) &dim[1]) &&
         gst_structure_get_int (str, "dim3", (int *) &dim[2]) &&
         gst_structure_get_int (str, "dim4", (int *) &dim[3])) {
-      int j;
       ret |= _TFC_DIMENSION;
-      if (gst_structure_get_int (str, "rank", &rank)) {
-        for (j = rank; j < NNS_TENSOR_RANK_LIMIT; j++)
-          g_assert (dim[j] == 1);
-      }
     }
     strval = gst_structure_get_string (str, "type");
     if (strval) {
index 5fd51b3..05fc886 100644 (file)
@@ -453,8 +453,8 @@ gst_tensor_mux_collected (GstCollectPads * pads, GstTensorMux * tensor_mux)
   if (!tensor_mux->negotiated) {
     GstCaps *newcaps;
     newcaps =
-        gst_caps_new_simple ("other/tensors", "rank", G_TYPE_INT,
-        tensor_mux->rank, "num_tensors", G_TYPE_INT,
+        gst_caps_new_simple ("other/tensors",
+        "num_tensors", G_TYPE_INT,
         tensor_mux->num_tensors, "types", G_TYPE_STRING,
         types->str, "framerate", GST_TYPE_FRACTION,
         tensor_mux->framerate_numerator, tensor_mux->framerate_denominator,
index 6ff3d2e..f3b76f1 100644 (file)
@@ -594,27 +594,6 @@ gst_tensor_read_cap (GstCaps * caps, tensor_dim dim, tensor_type * type,
 }
 
 /**
- * @brief Calculate the rank of a tensor
- * @param dimension The dimension vector (tensor_dim = uint32_t[NNS_TENSOR_RANK_LIMIT]) of tensor.
- * @return the rank value
- */
-static int
-get_rank (const tensor_dim dimension)
-{
-  int i = 0;
-  int rank = 0;
-  g_assert (dimension);
-  for (i = 0; i < NNS_TENSOR_RANK_LIMIT; i++) {
-    g_assert (dimension[i] > 0);
-    if (dimension[i] > 1)
-      rank = i + 1;
-  }
-  if (rank == 0)                /* a scalar (assume it is 1-dim vector) */
-    return 1;
-  return rank;
-}
-
-/**
  * @brief Write cap from the given dim/type. You need to free the returned value
  * @param[in] dim The given tensor dimension
  * @param[in] type The given tensor element type
@@ -625,7 +604,6 @@ get_rank (const tensor_dim dimension)
 static GstCaps *
 gst_tensor_write_cap (const tensor_dim dim, tensor_type type, gint fn, gint fd)
 {
-  int rank = get_rank (dim);
   GstStaticCaps rawcap = GST_STATIC_CAPS (GST_TENSOR_CAP_DEFAULT);
   GstCaps *tmp, *tmp2;
   GstCaps *staticcap = gst_static_caps_get (&rawcap);
@@ -634,13 +612,13 @@ gst_tensor_write_cap (const tensor_dim dim, tensor_type type, gint fn, gint fd)
     /* type: certain. dim: uncertain */
     if (fn != -1 && fd != -1) {
       tmp2 =
-          gst_caps_new_simple ("other/tensor", "rank", G_TYPE_INT, rank,
+          gst_caps_new_simple ("other/tensor",
           "dim1", G_TYPE_INT, dim[0], "dim2", G_TYPE_INT, dim[1],
           "dim3", G_TYPE_INT, dim[2], "dim4", G_TYPE_INT, dim[3],
           "framerate", GST_TYPE_FRACTION, fn, fd, NULL);
     } else {
       tmp2 =
-          gst_caps_new_simple ("other/tensor", "rank", G_TYPE_INT, rank,
+          gst_caps_new_simple ("other/tensor",
           "dim1", G_TYPE_INT, dim[0], "dim2", G_TYPE_INT, dim[1],
           "dim3", G_TYPE_INT, dim[2], "dim4", G_TYPE_INT, dim[3], NULL);
     }
@@ -648,14 +626,14 @@ gst_tensor_write_cap (const tensor_dim dim, tensor_type type, gint fn, gint fd)
     /* type: certain. dim: certain */
     if (fn != -1 && fd != -1) {
       tmp2 =
-          gst_caps_new_simple ("other/tensor", "rank", G_TYPE_INT, rank, "type",
+          gst_caps_new_simple ("other/tensor", "type",
           G_TYPE_STRING, tensor_element_typename[type], "dim1", G_TYPE_INT,
           dim[0], "dim2", G_TYPE_INT, dim[1], "dim3", G_TYPE_INT,
           dim[2], "dim4", G_TYPE_INT, dim[3],
           "framerate", GST_TYPE_FRACTION, fn, fd, NULL);
     } else {
       tmp2 =
-          gst_caps_new_simple ("other/tensor", "rank", G_TYPE_INT, rank, "type",
+          gst_caps_new_simple ("other/tensor", "type",
           G_TYPE_STRING, tensor_element_typename[type], "dim1", G_TYPE_INT,
           dim[0], "dim2", G_TYPE_INT, dim[1], "dim3", G_TYPE_INT,
           dim[2], "dim4", G_TYPE_INT, dim[3], NULL);
index f6ce087..5744db8 100644 (file)
@@ -63,14 +63,12 @@ G_BEGIN_DECLS
     GST_TENSOR_TEXT_CAPS_STR
 
 /** @todo I'm not sure if the range is to be 1, 65535 or larger */
-#define GST_TENSOR_RANK_RANGE "(int) [ 1, 4 ]"
 #define GST_TENSOR_DIM_RANGE "(int) [ 1, 65535 ]"
 #define GST_TENSOR_RATE_RANGE "(fraction) [ 0/1, 2147483647/1 ]"
 #define GST_TENSOR_TYPE_ALL "{ float32, float64, int64, uint64, int32, uint32, int16, uint16, int8, uint8 }"
 
 #define GST_TENSOR_CAP_DEFAULT \
     "other/tensor, " \
-    "rank = " GST_TENSOR_RANK_RANGE ", " \
     "dim1 = " GST_TENSOR_DIM_RANGE ", " \
     "dim2 = " GST_TENSOR_DIM_RANGE ", " \
     "dim3 = " GST_TENSOR_DIM_RANGE ", " \
@@ -97,7 +95,6 @@ G_BEGIN_DECLS
  */
 #define GST_TENSORS_CAP_DEFAULT \
     "other/tensors, " \
-    "rank = " GST_TENSOR_RANK_RANGE ", " \
     "num_tensors = " GST_TENSOR_NUM_TENSORS_RANGE ", "\
     "framerate = " GST_TENSOR_RATE_RANGE
     /**
@@ -163,10 +160,6 @@ typedef struct
  */
 typedef struct
 {
-  /**
-   * @todo remove rank.
-   */
-  gint rank; /**< Tensor Rank (# dimensions) */
   tensor_type type; /**< Type of each element in the tensor. User must designate this. Otherwise, this is UINT8 for video/x-raw byte stream */
   tensor_dim dimension; /**< Dimensions. We support up to 4th ranks.  */
   gint rate_n; /**< framerate is in fraction, which is numerator/denominator */