[CONVERTER] Change custom mode name
authorGichan Jang <gichan2.jang@samsung.com>
Fri, 26 Mar 2021 02:35:21 +0000 (11:35 +0900)
committerMyungJoo Ham <myungjoo.ham@samsung.com>
Tue, 30 Mar 2021 04:25:57 +0000 (13:25 +0900)
Changed custom mode name to custom-code fot callback type.

Signed-off-by: Gichan Jang <gichan2.jang@samsung.com>
ext/nnstreamer/tensor_converter/tensor_converter_flexbuf.cc
gst/nnstreamer/include/tensor_converter_custom.h
gst/nnstreamer/tensor_converter/tensor_converter.c
gst/nnstreamer/tensor_converter/tensor_converter.h
tests/nnstreamer_converter/unittest_converter.cc

index 9a4dd30..3863680 100644 (file)
  *
  * If you want to convert your own binary format of the flexbuffers to tensors,
  * You can use custom mode of the tensor converter.
+ * This is an example of a callback type custom mode.
  * @code
  * // Define custom callback function
  * GstBuffer * tensor_converter_custom_cb (GstBuffer *in_buf,
- *     GstTensorsConfig *config) {
+ *     void *data, GstTensorsConfig *config) {
  *   // Write a code to convert flexbuffers to tensors.
  * }
  *
@@ -48,7 +49,7 @@
  * nnstreamer_converter_custom_register ("tconv", tensor_converter_custom_cb, NULL);
  * ...
  * // Use the custom tensor converter in a pipeline.
- * // E.g., Pipeline of " ... (flexbuffers) ! tensor_converter mode=custom:tconv ! (tensors)... "
+ * // E.g., Pipeline of " ... (flexbuffers) ! tensor_converter mode=custom-code:tconv ! (tensors)... "
  * ...
  * // After everything is done.
  * nnstreamer_converter_custom_unregister ("tconv");
index 4b3b3a9..a9fee47 100644 (file)
@@ -24,11 +24,12 @@ G_BEGIN_DECLS
 /**
  * @brief Convert to tensors as customized operation
  * @param[in] in_buf the input stream buffer
+ * @param[in/out] data private data for the callback
  * @param[out] config tensors config structure to be filled
  * @return output buffer filled by user
  */
 typedef GstBuffer * (* tensor_converter_custom) (GstBuffer *in_buf,
-    GstTensorsConfig *config);
+    void *data, GstTensorsConfig *config);
 
 /**
  * @brief Register the custom callback function.
index d093993..cbd00c0 100644 (file)
@@ -478,8 +478,8 @@ gst_tensor_converter_set_property (GObject * object, guint prop_id,
         break;
       }
 
-      if (g_ascii_strcasecmp (strv[0], "custom") == 0)
-        self->mode = _CONVERTER_MODE_CUSTOM;
+      if (g_ascii_strcasecmp (strv[0], "custom-code") == 0)
+        self->mode = _CONVERTER_MODE_CUSTOM_CODE;
       self->mode_option = g_strdup (strv[1]);
       g_strfreev (strv);
 
@@ -550,7 +550,7 @@ gst_tensor_converter_get_property (GObject * object, guint prop_id,
       if (self->mode_option == NULL)
         mode_str = g_strdup ("");
       else
-        mode_str = g_strdup_printf ("%s:%s", "custom", self->mode_option);
+        mode_str = g_strdup_printf ("%s:%s", "custom-code", self->mode_option);
       g_value_take_string (value, mode_str);
       break;
     }
@@ -1049,14 +1049,14 @@ gst_tensor_converter_chain (GstPad * pad, GstObject * parent, GstBuffer * buf)
       frames_in = buf_size / frame_size;
       break;
     case _NNS_MEDIA_ANY:
-      if (self->mode == _CONVERTER_MODE_CUSTOM) {
+      if (self->mode == _CONVERTER_MODE_CUSTOM_CODE) {
         GstTensorsConfig new_config;
         if (self->custom.func == NULL) {
           nns_loge
               ("custom condition of the tensor_converter is not configured.");
           return GST_FLOW_ERROR;
         }
-        inbuf = self->custom.func (buf, &new_config);
+        inbuf = self->custom.func (buf, self->custom.data, &new_config);
         if (inbuf == NULL) {
           nns_loge ("Failed to run custom tensor converter.");
           gst_buffer_unref (buf);
@@ -1747,7 +1747,7 @@ gst_tensor_converter_parse_caps (GstTensorConverter * self,
   g_return_val_if_fail (gst_caps_is_fixed (caps), FALSE);
 
   structure = gst_caps_get_structure (caps, 0);
-  if (self->mode == _CONVERTER_MODE_CUSTOM) {
+  if (self->mode == _CONVERTER_MODE_CUSTOM_CODE) {
     in_type = _NNS_MEDIA_ANY;
   } else {
     in_type = gst_tensor_media_type_from_structure (structure);
@@ -1800,7 +1800,7 @@ gst_tensor_converter_parse_caps (GstTensorConverter * self,
       break;
     default:
     {
-      if (self->mode == _CONVERTER_MODE_CUSTOM) {
+      if (self->mode == _CONVERTER_MODE_CUSTOM_CODE) {
         gst_tensors_config_init (&config);
 
         /* All tensor info should be updated later in chain function. */
index 4338573..030a4cd 100644 (file)
@@ -66,7 +66,7 @@ typedef struct
  */
 typedef enum {
   _CONVERTER_MODE_NONE = 0,    /**< Normal mode (default) */
-  _CONVERTER_MODE_CUSTOM = 1,  /**<  Custom mode */
+  _CONVERTER_MODE_CUSTOM_CODE = 1,     /**<  Custom mode (callback type) */
 } tensor_converter_mode;
 
 /**
index 99370d8..b845ec9 100644 (file)
@@ -22,7 +22,7 @@ static int data_received;
  * @brief custom callback function\r
  */\r
 GstBuffer * tensor_converter_custom_cb (GstBuffer *in_buf,\r
-    GstTensorsConfig *config) {\r
+    void *data, GstTensorsConfig *config) {\r
   GstMemory *in_mem, *out_mem;\r
   GstBuffer *out_buf = NULL;\r
   GstMapInfo in_info;\r
@@ -117,7 +117,7 @@ TEST (tensorConverterCustom, normal0)
   g_free (str_pipeline);\r
 \r
   str_pipeline = g_strdup_printf (\r
-      "filesrc location=%s blocksize=-1 ! application/octet-stream ! tensor_converter mode=custom:tconv ! "\r
+      "filesrc location=%s blocksize=-1 ! application/octet-stream ! tensor_converter mode=custom-code:tconv ! "\r
       "filesink location=%s buffer-mode=unbuffered sync=false async=false ",\r
       tmp_flex_raw, tmp_flex_to_tensor);\r
 \r