[Tizen/API] Remove dependency 'tensor_typedef.h'
authorSangjung Woo <sangjung.woo@samsung.com>
Mon, 15 Apr 2019 03:55:11 +0000 (12:55 +0900)
committerMyungJoo Ham <myungjoo.ham@samsung.com>
Tue, 16 Apr 2019 03:11:16 +0000 (12:11 +0900)
In order to pass the ACR process, 'tensor_typedef.h' in tizen-api.h
should be removed and its related thing also be updated. This patch
handles that issue. Detailed modification are as below.

* Remove dependency for 'nnstreamer/tensor_typedef.h' header
* Add necessary constant and enum variables such as
  NNS_TENSOR_RANK_LIMIT and nns_tensors_info.
* Use nns_tensors_info structure instead of GstTensorsInfo

Signed-off-by: Sangjung Woo <sangjung.woo@samsung.com>
tests/tizen_capi/unittest_tizen_capi.cpp
tizen-api/include/tizen-api.h
tizen-api/src/tizen-api-pipeline.c

index 2fe0654..bd7a071 100644 (file)
@@ -237,7 +237,7 @@ TEST (nnstreamer_capi_valve, test01)
  * @brief A tensor-sink callback for sink handle in a pipeline
  */
 static void nns_sink_callback_dm01 (const char *buf[], const size_t size[],
-    const GstTensorsInfo *tensorsinfo, void *pdata)
+    const nns_tensors_info_s *tensorsinfo, void *pdata)
 {
   gchar *filepath = (gchar *) pdata;
   FILE *fp = g_fopen (filepath, "a");
@@ -361,7 +361,8 @@ TEST (nnstreamer_capi_src, dummy_01)
   nns_pipeline_state_e state;
   nns_src_h srchandle;
   int status = nns_pipeline_construct (pipeline, &handle);
-  GstTensorsInfo tensorsinfo;
+  nns_tensors_info_s tensorsinfo;
+
   int i;
   char *uintarray2[10];
   uint8_t *content;
@@ -400,14 +401,14 @@ TEST (nnstreamer_capi_src, dummy_01)
   EXPECT_EQ (status, NNS_ERROR_NONE);
 
   EXPECT_EQ (tensorsinfo.num_tensors, 1);
-  EXPECT_EQ (tensorsinfo.info[0].type, _NNS_UINT8);
+  EXPECT_EQ (tensorsinfo.info[0].type, NNS_UINT8);
   EXPECT_EQ (tensorsinfo.info[0].dimension[0], 4);
   EXPECT_EQ (tensorsinfo.info[0].dimension[1], 1);
   EXPECT_EQ (tensorsinfo.info[0].dimension[2], 1);
   EXPECT_EQ (tensorsinfo.info[0].dimension[3], 1);
 
   tensorsinfo.num_tensors = 1;
-  tensorsinfo.info[0].type = _NNS_UINT8;
+  tensorsinfo.info[0].type = NNS_UINT8;
   tensorsinfo.info[0].dimension[0] = 4;
   tensorsinfo.info[0].dimension[1] = 1;
   tensorsinfo.info[0].dimension[2] = 1;
@@ -426,7 +427,7 @@ TEST (nnstreamer_capi_src, dummy_01)
   EXPECT_EQ (status, NNS_ERROR_NONE);
 
   EXPECT_EQ (tensorsinfo.num_tensors, 1);
-  EXPECT_EQ (tensorsinfo.info[0].type, _NNS_UINT8);
+  EXPECT_EQ (tensorsinfo.info[0].type, NNS_UINT8);
   EXPECT_EQ (tensorsinfo.info[0].dimension[0], 4);
   EXPECT_EQ (tensorsinfo.info[0].dimension[1], 1);
   EXPECT_EQ (tensorsinfo.info[0].dimension[2], 1);
index 1e44131..7266b39 100644 (file)
@@ -26,8 +26,8 @@
 #ifndef __TIZEN_MACHINELEARNING_NNSTREAMER_TIZEN_API_H__
 #define __TIZEN_MACHINELEARNING_NNSTREAMER_TIZEN_API_H__
 
+#include <stddef.h>
 #include <tizen_error.h>
-#include <nnstreamer/tensor_typedef.h>
 
 #ifdef __cplusplus
 extern "C" {
@@ -38,6 +38,24 @@ extern "C" {
  */
 
 /**
+ * @brief The maximum rank that NNStreamer supports with Tizen APIs.
+ * @since_tizen 5.5
+ */
+#define NNS_TENSOR_RANK_LIMIT  (4)
+
+/**
+ * @brief The maximum number of other/tensor instances that other/tensors may have.
+ * @since_tizen 5.5
+ */
+#define NNS_TENSOR_SIZE_LIMIT  (16)
+
+/**
+ * @brief Dimemsion information that NNStreamer support.
+ * @since_tizen 5.5
+ */
+typedef unsigned int tensor_dim[NNS_TENSOR_RANK_LIMIT];
+
+/**
  * @brief A handle of an NNStreamer pipeline.
  * @since_tizen 5.5
  */
@@ -68,6 +86,24 @@ typedef void *nns_switch_h;
 typedef void *nns_valve_h;
 
 /**
+ * @brief Possible data element types of Tensor in NNStreamer.
+ * @since_tizen 5.5
+ */
+typedef enum _nns_tensor_type_e
+{
+  NNS_INT32 = 0,      /**< Integer 32bit */
+  NNS_UINT32,         /**< Unsigned integer 32bit */
+  NNS_INT16,          /**< Integer 16bit */
+  NNS_UINT16,         /**< Unsigned integer 16bit */
+  NNS_INT8,           /**< Integer 8bit */
+  NNS_UINT8,          /**< Unsigned integer 8bit */
+  NNS_FLOAT64,        /**< Float 64bit */
+  NNS_FLOAT32,        /**< Float 32bit */
+  NNS_INT64,          /**< Integer 64bit */
+  NNS_UINT64,         /**< Unsigned integer 64bit */
+} nns_tensor_type_e;
+
+/**
  * @brief Enumeration for the error codes of NNStreamer Pipelines.
  * @since_tizen 5.5
  * @todo The list is to be filled! (NYI)
@@ -135,16 +171,35 @@ typedef enum {
 } nns_switch_type_e;
 
 /**
+ * @brief Data structure for Tensor Information.
+ * @since_tizen 5.5
+ */
+typedef struct {
+  char * name;              /**< Name of each element in the tensor. */
+  nns_tensor_type_e type;   /**< Type of each element in the tensor. */
+  tensor_dim dimension;     /**< Dimension information. */
+} nns_tensor_info_s;
+
+/**
+ * @brief Data structure for Tensors Information, which contains multiple tensors.
+ * @since_tizen 5.5
+ */
+typedef struct {
+  unsigned int num_tensors; /**< The number of tensors */
+  nns_tensor_info_s info[NNS_TENSOR_SIZE_LIMIT];  /**< The list of tensor info */
+} nns_tensors_info_s;
+
+/**
  * @brief Callback for sink (tensor_sink) of nnstreamer pipelines (nnstreamer's output)
  * @detail If an application wants to accept data outputs of an nnstreamer stream, use this callback to get data from the stream. Note that the buffer may be deallocated after the return and this is synchronously called. Thus, if you need the data afterwards, copy the data to another buffer and return fast. Do not hold too much time in the callback. It is recommended to use very small tensors at sinks.
  * @since_tizen 5.5
  * @param[in] buf The contents of the tensor output (a single frame. tensor/tensors). Number of buf is determined by tensorsinfo->num_tensors.
  * @param[in] size The size of the buffer. Number of size is determined by tensorsinfo->num_tensors. Note that max num_tensors is 16 (NNS_TENSOR_SIZE_LIMIT).
- * @param[in] tensorsinfo The cardinality, dimension, and type of given tensor/tensors.
+ * @param[in] tensors_info The cardinality, dimension, and type of given tensor/tensors.
  * @param[in,out] pdata User Application's Private Data
  */
 typedef void (*nns_sink_cb)
-(const char *buf[], const size_t size[], const GstTensorsInfo *tensorsinfo, void *pdata);
+(const char *buf[], const size_t size[], const nns_tensors_info_s *tensors_info, void *pdata);
 
 /****************************************************
  ** NNStreamer Pipeline Construction (gst-parse)   **
@@ -247,14 +302,14 @@ int nns_pipeline_sink_unregister (nns_sink_h h);
  * @since_tizen 5.5
  * @param[in] pipe The pipeline to be attached with a src node.
  * @param[in] srcname The name of src node, described with nns_pipeline_construct().
- * @param[out] tensorsinfo The cardinality, dimension, and type of given tensor/tensors.
+ * @param[out] tensors_info The cardinality, dimension, and type of given tensor/tensors.
  * @param[out] h The src handle.
  * @return 0 on success (buf is filled). otherwise a negative error value.
  * @retval #NNS_ERROR_NONE Successful
  * @retval #NNS_ERROR_INVALID_PARAMETER Given parameter is invalid.
  */
 int nns_pipeline_src_gethandle
-(nns_pipeline_h pipe, const char *srcname, GstTensorsInfo *tensorsinfo, nns_src_h *h);
+(nns_pipeline_h pipe, const char *srcname, nns_tensors_info_s *tensors_info, nns_src_h *h);
 
 /**
  * @brief Close the given handle of a src node of nnstreamer pipelines.
index 9cbfa29..90c285d 100644 (file)
@@ -94,6 +94,25 @@ construct_element (GstElement * e, nns_pipeline * p, const char *name,
 }
 
 /**
+ * @brief Internal function to convert GstTensorsInfo into nns_tensors_info_s structure.
+ */
+static int
+get_tensors_info_from_GstTensorsInfo (GstTensorsInfo *gst_tensorsinfo,
+  nns_tensors_info_s *tensors_info)
+{
+  if (!gst_tensorsinfo) {
+    dlog_print (DLOG_ERROR, DLOG_TAG, "GstTensorsInfo should not be NULL!");
+    return NNS_ERROR_INVALID_PARAMETER;
+  }
+
+  /** Currently, the data structures of GstTensorsInfo are
+   * completely same as that of nns_tensors_info_s. */
+  memcpy (tensors_info, gst_tensorsinfo, sizeof(GstTensorsInfo));
+
+  return NNS_ERROR_NONE;
+}
+
+/**
  * @brief Handle a sink element for registered nns_sink_cb
  */
 static void
@@ -206,10 +225,13 @@ cb_sink_event (GstElement * e, GstBuffer * b, gpointer data)
 
   /* Iterate e->handles, pass the data to them */
   for (l = elem->handles; l != NULL; l = l->next) {
+    nns_tensors_info_s tensors_info;
     nns_sink *sink = l->data;
     nns_sink_cb callback = sink->cb;
 
-    callback (buf, size, &elem->tensorsinfo, sink->pdata);
+    get_tensors_info_from_GstTensorsInfo (&elem->tensorsinfo, &tensors_info);
+
+    callback (buf, size, &tensors_info, sink->pdata);
 
     /** @todo Measure time. Warn if it takes long. Kill if it takes too long. */
   }
@@ -598,7 +620,7 @@ static const GDestroyNotify bufpolicy[NNS_BUF_POLICY_MAX] = {
  * @brief Get a handle to operate a src (more info in tizen-api.h)
  */
 int nns_pipeline_src_gethandle
-    (nns_pipeline_h pipe, const char *srcname, GstTensorsInfo * tensorsinfo,
+    (nns_pipeline_h pipe, const char *srcname, nns_tensors_info_s *tensors_info,
     nns_src_h * h)
 {
   nns_pipeline *p = pipe;
@@ -669,7 +691,9 @@ int nns_pipeline_src_gethandle
     goto unlock_return;
   }
 
-  memcpy (tensorsinfo, &elem->tensorsinfo, sizeof (GstTensorsInfo));
+  ret = get_tensors_info_from_GstTensorsInfo (&elem->tensorsinfo, tensors_info);
+  if (ret != NNS_ERROR_NONE)
+    goto unlock_return;
 
   *h = g_new (nns_src, 1);
   src = *h;