[Sink] update test example / macro for debug
authorjy1210.jung <jy1210.jung@samsung.com>
Tue, 7 Aug 2018 11:32:07 +0000 (20:32 +0900)
committer정재윤/언어이해Lab(SR)/Staff Engineer/삼성전자 <jy1210.jung@samsung.com>
Fri, 10 Aug 2018 06:09:49 +0000 (15:09 +0900)
1. add test pipeline to test audio stream in sink example
   (default type 0 for video stream)
2. add definition for debug
3. fix pad caps for other/tensors

Do not use GstStaticCaps and gst_static_caps_get() as local variable

**Self evaluation:**
1. Build test: [ ]Passed [ ]Failed [*]Skipped
2. Run test: [ ]Passed [ ]Failed [*]Skipped

Signed-off-by: Jaeyun Jung <jy1210.jung@samsung.com>
gst/tensor_sink/tensor_sink.c
nnstreamer_example/example_sink/nnstreamer_sink_example.c
tests/nnstreamer_sink/unittest_sink.cpp

index 6028c8e..c87be8e 100644 (file)
@@ -38,7 +38,9 @@
 /**
  * @brief Macro for debug mode.
  */
+#ifndef DBG
 #define DBG (!_tensor_sink_get_silent (self))
+#endif
 
 /**
  * @brief Macro for debug message.
@@ -104,6 +106,14 @@ enum
 #define DEFAULT_LATENESS (30 * GST_MSECOND)
 
 /**
+ * @brief Template for sink pad.
+ */
+static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE ("sink",
+    GST_PAD_SINK,
+    GST_PAD_ALWAYS,
+    GST_STATIC_CAPS (GST_TENSOR_CAP_DEFAULT "; " GST_TENSORS_CAP_DEFAULT));
+
+/**
  * @brief Variable for signal ids.
  */
 static guint _tensor_sink_signals[LAST_SIGNAL] = { 0 };
@@ -129,7 +139,6 @@ static gboolean gst_tensor_sink_set_caps (GstBaseSink * sink, GstCaps * caps);
 static GstCaps *gst_tensor_sink_get_caps (GstBaseSink * sink, GstCaps * filter);
 
 /** internal functions */
-static GstCaps *_tensor_sink_get_tensor_caps (void);
 static void _tensor_sink_render_buffer (GstTensorSink * self,
     GstBuffer * buffer);
 static void _tensor_sink_set_last_render_time (GstTensorSink * self,
@@ -157,8 +166,6 @@ gst_tensor_sink_class_init (GstTensorSinkClass * klass)
   GObjectClass *gobject_class;
   GstElementClass *element_class;
   GstBaseSinkClass *bsink_class;
-  GstPadTemplate *pad_template;
-  GstCaps *pad_caps;
 
   gobject_class = G_OBJECT_CLASS (klass);
   element_class = GST_ELEMENT_CLASS (klass);
@@ -207,11 +214,7 @@ gst_tensor_sink_class_init (GstTensorSinkClass * klass)
       "Sink element to handle tensor stream", "Samsung Electronics Co., Ltd.");
 
   /** pad template */
-  pad_caps = _tensor_sink_get_tensor_caps ();
-  pad_template = gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS,
-      pad_caps);
-  gst_caps_unref (pad_caps);
-  gst_element_class_add_pad_template (element_class, pad_template);
+  gst_element_class_add_static_pad_template (element_class, &sink_template);
 
   /** GstBaseSink methods */
   bsink_class->start = GST_DEBUG_FUNCPTR (gst_tensor_sink_start);
@@ -544,22 +547,6 @@ gst_tensor_sink_get_caps (GstBaseSink * sink, GstCaps * filter)
 }
 
 /**
- * @brief Get merged tensor caps.
- */
-static GstCaps *
-_tensor_sink_get_tensor_caps (void)
-{
-  GstCaps *caps;
-  GstStaticCaps caps_tensor = GST_STATIC_CAPS (GST_TENSOR_CAP_DEFAULT);
-  GstStaticCaps caps_tensors = GST_STATIC_CAPS (GST_TENSORS_CAP_DEFAULT);
-
-  caps = gst_caps_merge (gst_static_caps_get (&caps_tensor),
-      gst_static_caps_get (&caps_tensors));
-
-  return gst_caps_simplify (caps);
-}
-
-/**
  * @brief Handle buffer data.
  * @return None
  * @param self pointer to GstTensorSink
index 6fb60d6..3c82914 100644 (file)
@@ -238,15 +238,44 @@ _eos_cb (GstElement * element, GstBuffer * buffer, gpointer user_data)
 }
 
 /**
+ * @brief Test pipeline for given type.
+ * @param type 0 for video test, 1 for audio test
+ */
+static gchar *
+_test_pipeline (guint type)
+{
+  gchar *str_pipeline;
+
+  switch (type) {
+    case 0:
+      /** video 640x480 30fps 100 buffers */
+      str_pipeline =
+          g_strdup_printf
+          ("videotestsrc num-buffers=100 ! video/x-raw,format=RGB,width=640,height=480 ! "
+          "tensor_converter ! tensor_sink name=tensor_sink");
+      break;
+
+    case 1:
+      /** audio sample rate 16000 10 buffers */
+      str_pipeline =
+          g_strdup_printf
+          ("audiotestsrc num-buffers=10 samplesperbuffer=16000 ! audio/x-raw,rate=16000 ! "
+          "tensor_converter ! tensor_sink name=tensor_sink");
+      break;
+
+    default:
+      return NULL;
+  }
+
+  return str_pipeline;
+}
+
+/**
  * @brief Main function.
  */
 int
 main (int argc, char **argv)
 {
-  const guint num_buffers = 100;
-  const guint width = 640;
-  const guint height = 480;
-
   gchar *str_pipeline;
   gulong handle_id;
   GstStateChangeReturn state_ret;
@@ -262,12 +291,8 @@ main (int argc, char **argv)
   g_app.loop = g_main_loop_new (NULL, FALSE);
   _check_cond_err (g_app.loop != NULL);
 
-  /** 640x480 30fps for test */
-  str_pipeline =
-      g_strdup_printf
-      ("videotestsrc num-buffers=%d ! video/x-raw,format=RGB,width=%d,height=%d ! "
-      "tensor_converter ! tensor_sink name=tensor_sink",
-      num_buffers, width, height);
+  /** set type 1 for audio test */
+  str_pipeline = _test_pipeline (0);
   g_app.pipeline = gst_parse_launch (str_pipeline, NULL);
   g_free (str_pipeline);
   _check_cond_err (g_app.pipeline != NULL);
index 72b70e8..91530a6 100644 (file)
@@ -14,7 +14,9 @@
 /**
  * @brief Macro for debug mode.
  */
+#ifndef DBG
 #define DBG FALSE
+#endif
 
 /**
  * @brief Macro for debug message.