[Transform] Skeleton with dimchg mode.
authorMyungJoo Ham <myungjoo.ham@samsung.com>
Tue, 10 Jul 2018 09:24:52 +0000 (18:24 +0900)
committer오세원/Data Service Lab(SR)/Engineer/삼성전자 <sewon.oh@samsung.com>
Wed, 11 Jul 2018 05:46:10 +0000 (14:46 +0900)
other/tensor result of tensor_converter from video/x-raw is
not compatible with most neural network image input dimensions.

Thus, we need tensor-transform ASAP to test with real
NN models.

This prepares such cases.
Cap negotiation codes will follow soon as another commits.

Partially addresses #248

Signed-off-by: MyungJoo Ham <myungjoo.ham@samsung.com>
CMakeLists.txt
gst/tensor_transform/CMakeLists.txt [new file with mode: 0644]
gst/tensor_transform/tensor_transform.c [new file with mode: 0644]
gst/tensor_transform/tensor_transform.h [new file with mode: 0644]

index 9c3b39a..0ed5e7a 100644 (file)
@@ -89,6 +89,7 @@ ADD_SUBDIRECTORY(gst/tensor_filter)
 ADD_SUBDIRECTORY(gst/tensor_decoder)
 ADD_SUBDIRECTORY(gst/tensor_sink)
 ADD_SUBDIRECTORY(gst/tensor_mux)
+ADD_SUBDIRECTORY(gst/tensor_transform)
 ADD_SUBDIRECTORY(nnstreamer_example)
 ADD_SUBDIRECTORY(tests/nnstreamer_tensors/tensors_test)
 enable_testing()
diff --git a/gst/tensor_transform/CMakeLists.txt b/gst/tensor_transform/CMakeLists.txt
new file mode 100644 (file)
index 0000000..beed39f
--- /dev/null
@@ -0,0 +1,17 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
+
+ADD_LIBRARY(tensor_transform SHARED tensor_transform.c)
+ADD_LIBRARY(tensor_transformStatic STATIC tensor_transform.c)
+
+TARGET_LINK_LIBRARIES(tensor_transform ${pkgs_LIBRARIES})
+TARGET_INCLUDE_DIRECTORIES(tensor_transform PUBLIC ${pkgs_INCLUDE_DIRS})
+TARGET_COMPILE_OPTIONS(tensor_transform PUBLIC ${pkgs_CFLAGS_OTHER})
+TARGET_LINK_LIBRARIES(tensor_transformStatic ${pkgs_LIBRARIES})
+TARGET_INCLUDE_DIRECTORIES(tensor_transformStatic PUBLIC ${pkgs_INCLUDE_DIRS})
+TARGET_COMPILE_OPTIONS(tensor_transformStatic PUBLIC ${pkgs_CFLAGS_OTHER})
+
+INSTALL(TARGETS tensor_transform tensor_transformStatic
+       RUNTIME DESTINATION ${EXEC_PREFIX}
+       LIBRARY DESTINATION ${LIB_INSTALL_DIR}
+       ARCHIVE DESTINATION ${LIB_INSTALL_DIR}
+       )
diff --git a/gst/tensor_transform/tensor_transform.c b/gst/tensor_transform/tensor_transform.c
new file mode 100644 (file)
index 0000000..57e2126
--- /dev/null
@@ -0,0 +1,544 @@
+/**
+ * GStreamer
+ * Copyright (C) 2005 Thomas Vander Stichele <thomas@apestaart.org>
+ * Copyright (C) 2005 Ronald S. Bultje <rbultje@ronald.bitfreak.net>
+ * Copyright (C) 2018 MyungJoo Ham <myungjoo.ham@samsung.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Alternatively, the contents of this file may be used under the
+ * GNU Lesser General Public License Version 2.1 (the "LGPL"), in
+ * which case the following provisions apply instead of the ones
+ * mentioned above:
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+/**
+ * @file       tensor_transform.c
+ * @date       10 Jul 2018
+ * @brief      GStreamer plugin to transform other/tensor dimensions
+ * @see                http://github.com/nnsuite/nnstreamer
+ * @see                https://github.sec.samsung.net/STAR/nnstreamer
+ * @author     MyungJoo Ham <myungjoo.ham@samsung.com>
+ * @bug                This is NYI.
+ *
+ */
+
+/**
+ * SECTION:element-tensor_transform
+ *
+ * A filter that converts media stream to tensor stream for NN frameworks.
+ * The output is always in the format of other/tensor
+ *
+ * <refsect2>
+ * <title>Example launch line</title>
+ * |[
+ * gst-launch -v -m fakesrc ! tensor_converter ! tensor_transform mode=dimchg option=0:2 ! fakesink silent=TRUE
+ * ]|
+ * <title>How to use dimchg</title>
+ * |[
+ * option=0:2 # Move 0th dim to 2nd dim. I.e., [a][H][W][C] ==> [a][C][H][W]
+ * ]|
+ * </refsect2>
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <string.h>
+#include <gst/gst.h>
+#include <glib.h>
+
+#include "tensor_transform.h"
+
+GST_DEBUG_CATEGORY_STATIC (gst_tensor_transform_debug);
+#define GST_CAT_DEFAULT gst_tensor_transform_debug
+
+/* Filter signals and args */
+enum
+{
+  /* FILL ME */
+  LAST_SIGNAL
+};
+
+enum
+{
+  PROP_0,
+  PROP_SILENT,
+  PROP_MODE,
+  PROP_OPTION,
+};
+
+#define silent_debug(...) debug_print (!filter->silent, __VA_ARGS__)
+
+/* the capabilities of the inputs
+ *
+ * In v0.0.1, this is "bitmap" image stream
+ */
+static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink",
+    GST_PAD_SINK,
+    GST_PAD_ALWAYS,
+    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));
+
+#define gst_tensor_transform_parent_class parent_class
+G_DEFINE_TYPE (GstTensor_Transform, gst_tensor_transform,
+    GST_TYPE_BASE_TRANSFORM);
+
+static void gst_tensor_transform_set_property (GObject * object, guint prop_id,
+    const GValue * value, GParamSpec * pspec);
+static void gst_tensor_transform_get_property (GObject * object, guint prop_id,
+    GValue * value, GParamSpec * pspec);
+
+/* GstBaseTransformer vmethod implementations */
+static GstFlowReturn gst_tensor_transform_transform (GstBaseTransform * trans,
+    GstBuffer * inbuf, GstBuffer * outbuf);
+static GstCaps *gst_tensor_transform_transform_caps (GstBaseTransform * trans,
+    GstPadDirection direction, GstCaps * caps, GstCaps * filter);
+static GstCaps *gst_tensor_transform_fixate_caps (GstBaseTransform * trans,
+    GstPadDirection direction, GstCaps * caps, GstCaps * othercaps);
+static gboolean gst_tensor_transform_set_caps (GstBaseTransform * trans,
+    GstCaps * incaps, GstCaps * outcaps);
+static gboolean gst_tensor_transform_transform_size (GstBaseTransform * trans,
+    GstPadDirection direction, GstCaps * caps, gsize size,
+    GstCaps * othercaps, gsize * othersize);
+/* GObject vmethod implementations */
+
+/**
+ * @brief initialize the tensor_transform's class
+ */
+static void
+gst_tensor_transform_class_init (GstTensor_TransformClass * g_class)
+{
+  GObjectClass *gobject_class;
+  GstElementClass *gstelement_class;
+  GstBaseTransformClass *trans_class;
+  GstTensor_TransformClass *klass;
+
+  klass = (GstTensor_TransformClass *) g_class;
+  trans_class = (GstBaseTransformClass *) klass;
+  gstelement_class = (GstElementClass *) trans_class;
+  gobject_class = (GObjectClass *) gstelement_class;
+
+  gobject_class->set_property = gst_tensor_transform_set_property;
+  gobject_class->get_property = gst_tensor_transform_get_property;
+
+  g_object_class_install_property (gobject_class, PROP_SILENT,
+      g_param_spec_boolean ("silent", "Silent", "Produce verbose output ?",
+          FALSE, G_PARAM_READWRITE));
+  g_object_class_install_property (gobject_class, PROP_MODE,
+      g_param_spec_string ("mode", "Mode", "Tensor transform mode ?",
+          "", G_PARAM_READWRITE));
+  g_object_class_install_property (gobject_class, PROP_OPTION,
+      g_param_spec_string ("option", "Option",
+          "Option for the tensor transform mode ?", "", G_PARAM_READWRITE));
+
+  gst_element_class_set_details_simple (gstelement_class,
+      "Tensor_Transform",
+      "Transform other/tensor dimensions",
+      "Transforms other/tensor dimensions for different models or frameworks",
+      "MyungJoo Ham <myungjoo.ham@samsung.com>");
+
+  gst_element_class_add_pad_template (gstelement_class,
+      gst_static_pad_template_get (&src_factory));
+  gst_element_class_add_pad_template (gstelement_class,
+      gst_static_pad_template_get (&sink_factory));
+  /* Refer: https://gstreamer.freedesktop.org/documentation/design/element-transform.html */
+  trans_class->passthrough_on_same_caps = FALSE;
+
+  /* Processing units */
+  trans_class->transform = GST_DEBUG_FUNCPTR (gst_tensor_transform_transform);
+
+  /* Negotiation units */
+  trans_class->transform_caps =
+      GST_DEBUG_FUNCPTR (gst_tensor_transform_transform_caps);
+  trans_class->fixate_caps =
+      GST_DEBUG_FUNCPTR (gst_tensor_transform_fixate_caps);
+  trans_class->set_caps = GST_DEBUG_FUNCPTR (gst_tensor_transform_set_caps);
+
+  /* Allocation units */
+  trans_class->transform_size =
+      GST_DEBUG_FUNCPTR (gst_tensor_transform_transform_size);
+}
+
+/**
+ * @brief initialize the new element (G_DEFINE_TYPE requires this)
+ * instantiate pads and add them to element
+ * set pad calback functions
+ * initialize instance structure
+ */
+static void
+gst_tensor_transform_init (GstTensor_Transform * filter)
+{
+  filter->silent = TRUE;
+  filter->mode = GTT_END;
+  filter->option = NULL;
+  filter->loaded = FALSE;
+}
+
+static const gchar *gst_tensor_transform_mode_string[] = {
+  [GTT_DIMCHG] = "dimchg",
+  [GTT_END] = "error",
+};
+
+/**
+ * @brief Get the corresponding mode from the string value
+ * @param[in] str The string value for the mode
+ * @return corresponding mode for the string. GTT_END for errors
+ */
+static tensor_transform_mode
+gst_tensor_transform_get_mode (const gchar * str)
+{
+  int i;
+
+  for (i = 0; i < GTT_END; i++) {
+    if (!g_ascii_strcasecmp (gst_tensor_transform_mode_string[i], str))
+      return i;
+  }
+  return GTT_END;
+}
+
+/**
+ * @brief Setup internal data (data_* in GstTensor_Transform)
+ * @param[in/out] filter "this" pointer. mode & option MUST BE set already.
+ */
+static void
+gst_tensor_transform_set_option_data (GstTensor_Transform * filter)
+{
+  if (filter->mode == GTT_END || filter->option == NULL)
+    return;
+  switch (filter->mode) {
+    case GTT_DIMCHG:
+    {
+      int a, b;
+      gchar **strv = g_strsplit (filter->option, ":", 2);
+      if (strv[0] != NULL)
+        a = g_ascii_strtoull (strv[0], NULL, 10);
+      else
+        a = 0;
+      if (strv[1] != NULL)
+        b = g_ascii_strtoull (strv[1], NULL, 10);
+      else
+        b = 0;
+      filter->data_dimchg.from = a;
+      filter->data_dimchg.to = b;
+      filter->loaded = TRUE;
+    }
+      break;
+    default:
+      g_printerr ("Cannot identify mode\n");
+      g_assert (0);
+  }
+}
+
+/**
+ * @brief Set property (gst element vmethod)
+ */
+static void
+gst_tensor_transform_set_property (GObject * object, guint prop_id,
+    const GValue * value, GParamSpec * pspec)
+{
+  GstTensor_Transform *filter = GST_TENSOR_TRANSFORM (object);
+
+  switch (prop_id) {
+    case PROP_SILENT:
+      filter->silent = g_value_get_boolean (value);
+      break;
+    case PROP_MODE:
+      filter->mode = gst_tensor_transform_get_mode (g_value_get_string (value));
+      g_assert (filter->mode != GTT_END);
+      silent_debug ("Mode = %d(%s)\n", filter->mode,
+          gst_tensor_transform_mode_string[filter->mode]);
+      gst_tensor_transform_set_option_data (filter);
+      break;
+    case PROP_OPTION:
+      filter->option = g_value_dup_string (value);
+      silent_debug ("Option = %s\n", filter->option);
+      gst_tensor_transform_set_option_data (filter);
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+  }
+}
+
+/**
+ * @brief Get property (gst element vmethod)
+ */
+static void
+gst_tensor_transform_get_property (GObject * object, guint prop_id,
+    GValue * value, GParamSpec * pspec)
+{
+  GstTensor_Transform *filter = GST_TENSOR_TRANSFORM (object);
+
+  switch (prop_id) {
+    case PROP_SILENT:
+      g_value_set_boolean (value, filter->silent);
+      break;
+    case PROP_MODE:
+      g_value_set_string (value,
+          gst_tensor_transform_mode_string[filter->mode]);
+      break;
+    case PROP_OPTION:
+      g_value_set_string (value, filter->option);
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+  }
+}
+
+/******************************************************************
+ * GstElement vmethod implementations
+ */
+
+#define return_false_if_fail(x)        \
+  ret = (x); \
+  if (!ret) \
+    return FALSE; \
+  ;
+
+/**
+ * @brief entry point to initialize the plug-in
+ * initialize the plug-in itself
+ * register the element factories and other features
+ */
+static gboolean
+tensor_transform_init (GstPlugin * tensor_transform)
+{
+  /* debug category for fltering log messages
+   *
+   * exchange the string 'Template tensor_transform' with your description
+   */
+  GST_DEBUG_CATEGORY_INIT (gst_tensor_transform_debug, "tensor_transform",
+      0, "Template tensor_transform");
+
+  return gst_element_register (tensor_transform, "tensor_transform",
+      GST_RANK_NONE, GST_TYPE_TENSOR_TRANSFORM);
+}
+
+/**
+ * PACKAGE: this is usually set by autotools depending on some _INIT macro
+ * in configure.ac and then written into and defined in config.h, but we can
+ * just set it ourselves here in case someone doesn't use autotools to
+ * compile this code. GST_PLUGIN_DEFINE needs PACKAGE to be defined.
+ */
+#ifndef PACKAGE
+#define PACKAGE "tensor_transform"
+#endif
+
+/* gstreamer looks for this structure to register tensor_transforms
+ *
+ * exchange the string 'Template tensor_transform' with your tensor_transform description
+ */
+GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
+    GST_VERSION_MINOR,
+    tensor_transform,
+    "tensor_transform",
+    tensor_transform_init,
+    VERSION, "LGPL", "GStreamer", "http://gstreamer.net/");
+
+/**
+ * @brief subrouting for tensor-tranform, "dimchg" case.
+ * @param[in/out] filter "this" pointer
+ * @param[in] inptr input tensor
+ * @param[out] outptr output tensor
+ * @return Gst flow status
+ */
+static GstFlowReturn
+gst_tensor_transform_dimchg (GstTensor_Transform * filter,
+    const uint8_t * inptr, uint8_t * outptr)
+{
+  /* @todo NYI */
+  uint32_t *fromDim = filter->fromDim;
+  uint32_t *toDim = filter->toDim;
+  int from = filter->data_dimchg.from;
+  int to = filter->data_dimchg.to;
+  int i, j, k;
+  unsigned int loopLimit = 1;
+  size_t loopBlockSize = tensor_element_size[filter->type];
+
+  size_t copyblocksize = tensor_element_size[filter->type];
+  size_t copyblocklimit = 1;
+
+
+  if (from == to) {
+    /* Useless memcpy. Do not call this or @todo do "IP" operation */
+    memcpy (outptr, inptr, get_tensor_element_count (filter->fromDim) *
+        tensor_element_size[filter->type]);
+    g_printerr
+        ("Calling tensor_transform with high memcpy overhead WITHOUT any effects! Check your stream wheter you really need tensor_transform.\n");
+    return GST_FLOW_OK;
+  }
+
+  g_assert (from >= 0 && from < NNS_TENSOR_RANK_LIMIT);
+  g_assert (to >= 0 && to < NNS_TENSOR_RANK_LIMIT);
+  g_assert (fromDim[from] == toDim[to]);
+
+  if (from < to) {
+    /* Smaller-loop-ed a to larger-loop-ed b */
+    /* E.g., [N][H][W][c] (c:W:H:N) --> [N][c][H][W] (W:H:c:N) */
+
+    /* @todo CRITICAL-TODO: Optimize the performance! */
+    for (i = NNS_TENSOR_RANK_LIMIT - 1; i > to; i--)
+      loopLimit *= toDim[i];
+    for (i = 0; i < to; i++)
+      loopBlockSize *= toDim[i];
+
+    for (i = 0; i < from; i++)
+      copyblocksize *= fromDim[i];
+    for (i = 0; i < to; i++)
+      copyblocklimit *= toDim[i];
+
+    for (i = 0; i < loopLimit; i++) {
+      /* [i1][i2][...][iN][b][...] i = i1 x i2 x ... x iN */
+      uint8_t *destptr = outptr + loopBlockSize * toDim[to] * i;
+      const uint8_t *srcptr = inptr + loopBlockSize * toDim[to] * i;
+
+      for (j = 0; j < toDim[to]; j++) {
+        uint8_t *j_destptr = destptr + loopBlockSize * j;
+        for (k = 0; k < copyblocklimit; k++) {
+          memcpy (j_destptr + copyblocksize * k,
+              srcptr + k * copyblocksize * toDim[to] + j * copyblocksize,
+              copyblocksize);
+        }
+      }
+    }
+  } else {
+    /* Larger-loop-ed a to smaller-loop-ed b */
+    /* E.g., [N][c][H][W] (W:H:c:N) --> [N][H][W][c] (c:W:H:N) */
+    /* @todo NYI */
+    g_assert (0);
+  }
+
+  return GST_FLOW_OK;
+}
+
+/**
+ * @brief non-ip transform. required vmethod for BaseTransform class.
+ * @param[in/out] trans "super" pointer
+ * @param[in] inbuf The input gst buffer
+ * @param[out] outbuf The output gst buffer
+ * @return Gst Flow Status
+ */
+static GstFlowReturn
+gst_tensor_transform_transform (GstBaseTransform * trans,
+    GstBuffer * inbuf, GstBuffer * outbuf)
+{
+  GstFlowReturn res;
+  GstTensor_Transform *filter = GST_TENSOR_TRANSFORM_CAST (trans);
+
+  uint8_t *inptr, *outptr;
+  GstMapInfo inInfo, outInfo;
+
+  gst_buffer_map (inbuf, &inInfo, GST_MAP_READ);
+  gst_buffer_map (outbuf, &outInfo, GST_MAP_WRITE);
+  inptr = inInfo.data;
+  outptr = outInfo.data;
+
+  switch (filter->mode) {
+    case GTT_DIMCHG:
+      res = gst_tensor_transform_dimchg (filter, inptr, outptr);
+      break;
+    default:
+      res = GST_FLOW_NOT_SUPPORTED;
+  }
+
+  gst_buffer_unmap (inbuf, &inInfo);
+  gst_buffer_unmap (outbuf, &outInfo);
+
+  return res;
+}
+
+/**
+ * @brief configure srcpad cap from "proposed" cap. (required vmethod for BaseTransform)
+ *
+ * @param trans ("this" pointer)
+ * @param direction (why do we need this?)
+ * @param caps sinkpad cap
+ * @param filter this element's cap (don't know specifically.)
+ */
+static GstCaps *
+gst_tensor_transform_transform_caps (GstBaseTransform * trans,
+    GstPadDirection direction, GstCaps * caps, GstCaps * filter)
+{
+  /* @todo NYI */
+
+  if (direction == GST_PAD_SINK) {
+  } else {
+  }
+  return NULL;
+}
+
+/**
+ * @brief fixate caps. required vmethod of BaseTransform
+ */
+static GstCaps *
+gst_tensor_transform_fixate_caps (GstBaseTransform * trans,
+    GstPadDirection direction, GstCaps * caps, GstCaps * othercaps)
+{
+  /* @todo NYI */
+  return NULL;
+}
+
+/**
+ * @brief set caps. required vmethod of BaseTransform
+ */
+static gboolean
+gst_tensor_transform_set_caps (GstBaseTransform * trans,
+    GstCaps * incaps, GstCaps * outcaps)
+{
+  /* @todo NYI */
+  return FALSE;
+}
+
+/**
+ * @brief Tell the framework the required size of buffer based on the info of the other side pad. Note that this is always the same with the input. optional vmethod of BaseTransform
+ */
+static gboolean
+gst_tensor_transform_transform_size (GstBaseTransform * trans,
+    GstPadDirection direction, GstCaps * caps, gsize size,
+    GstCaps * othercaps, gsize * othersize)
+{
+  *othersize = size;            /* size of input = size of output */
+  return TRUE;
+
+  /* @todo add verificastion procedure */
+}
diff --git a/gst/tensor_transform/tensor_transform.h b/gst/tensor_transform/tensor_transform.h
new file mode 100644 (file)
index 0000000..4011c3a
--- /dev/null
@@ -0,0 +1,133 @@
+/*
+ * GStreamer
+ * Copyright (C) 2005 Thomas Vander Stichele <thomas@apestaart.org>
+ * Copyright (C) 2005 Ronald S. Bultje <rbultje@ronald.bitfreak.net>
+ * Copyright (C) 2018 MyungJoo Ham <myungjoo.ham@samsung.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Alternatively, the contents of this file may be used under the
+ * GNU Lesser General Public License Version 2.1 (the "LGPL"), in
+ * which case the following provisions apply instead of the ones
+ * mentioned above:
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * @file       tensor_transform.c
+ * @date       10 Jul 2018
+ * @brief      GStreamer plugin to transform other/tensor dimensions
+ *
+ * @see                http://github.com/nnsuite/nnstreamer
+ * @see                https://github.sec.samsung.net/STAR/nnstreamer
+ * @author     MyungJoo Ham <myungjoo.ham@samsung.com>
+ * @bug                No known bugs.
+ *
+ */
+
+#ifndef __GST_TENSOR_TRANSFORM_H__
+#define __GST_TENSOR_TRANSFORM_H__
+
+#include <gst/gst.h>
+#include <gst/base/gstbasetransform.h>
+#include <tensor_common.h>
+
+G_BEGIN_DECLS
+
+/* #defines don't like whitespacey bits */
+#define GST_TYPE_TENSOR_TRANSFORM \
+  (gst_tensor_transform_get_type())
+#define GST_TENSOR_TRANSFORM(obj) \
+  (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_TENSOR_TRANSFORM,GstTensor_Transform))
+#define GST_TENSOR_TRANSFORM_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_TENSOR_TRANSFORM,GstTensor_TransformClass))
+#define GST_IS_TENSOR_TRANSFORM(obj) \
+  (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_TENSOR_TRANSFORM))
+#define GST_IS_TENSOR_TRANSFORM_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_TENSOR_TRANSFORM))
+#define GST_TENSOR_TRANSFORM_CAST(obj)  ((GstTensor_Transform *)(obj))
+
+typedef struct _GstTensor_Transform GstTensor_Transform;
+
+typedef struct _GstTensor_TransformClass GstTensor_TransformClass;
+
+typedef enum {
+  GTT_DIMCHG = 0, /* Dimension Change. "dimchg" */
+
+
+  GTT_END,
+} tensor_transform_mode;
+
+typedef struct _tensor_transform_dimchg {
+  int from;
+  int to;
+} tensor_transform_dimchg;
+
+/**
+ * @brief Internal data structure for tensor_transform instances.
+ */
+struct _GstTensor_Transform
+{
+  GstBaseTransform element;    /**< This is the parent object */
+
+  gboolean silent;     /**< True if logging is minimized */
+  tensor_transform_mode mode; /**< Transform mode. GTT_END if invalid */
+  gchar *option; /**< Stored option value */
+  union {
+    tensor_transform_dimchg data_dimchg; /**< Parsed option value for "dimchg" mode */
+  };
+  gboolean loaded; /**< TRUE if mode & option are loaded */
+
+  tensor_dim fromDim; /**< Input dimension */
+  tensor_dim toDim; /**< Output dimension */
+  tensor_type type; /**< tensor_type of both input and output. They share the same type. */
+};
+
+/*
+ * @brief GstTensor_TransformClass inherits GstBaseTransformClass.
+ *
+ * Referring another child (sibiling), GstVideoFilter (abstract class) and
+ * its child (concrete class) GstVideoTransform.
+ * Note that GstTensor_TransformClass is a concrete class; thus we need to look at both.
+ */
+struct _GstTensor_TransformClass
+{
+  GstBaseTransformClass parent_class;  /**< Inherits GstBaseTransformClass */
+};
+
+/*
+ * @brief Get Type function required for gst elements
+ */
+GType gst_tensor_transform_get_type (void);
+
+G_END_DECLS
+
+#endif /* __GST_TENSOR_TRANSFORM_H__ */