[Repo] Use GST_DEBUG instead of silent_debug
authorjijoong.moon <jijoong.moon@samsung.com>
Fri, 23 Nov 2018 02:53:29 +0000 (11:53 +0900)
committerMyungJoo Ham <myungjoo.ham@gmail.com>
Tue, 27 Nov 2018 09:36:23 +0000 (09:36 +0000)
Replace custom debug/error/warning macro to GST_*

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

Signed-off-by: jijoong.moon <jijoong.moon@samsung.com>
gst/nnstreamer/tensor_repo.c
gst/tensor_reposink/tensor_reposink.c
gst/tensor_reposrc/tensor_reposrc.c
gst/tensor_reposrc/tensor_reposrc.h

index aba6d3c..a406c75 100644 (file)
@@ -30,8 +30,6 @@
 #define DBG FALSE
 #endif
 
-#define _print_log(...) if (DBG) g_message(__VA_ARGS__)
-
 /**
  * @brief tensor repo global variable with init.
  */
@@ -44,9 +42,8 @@ GstTensorRepoData *
 gst_tensor_repo_get_repodata (guint nth)
 {
   GstTensorRepoData *data;
-  gpointer *p = g_hash_table_lookup (_repo.hash, GINT_TO_POINTER (nth));
+  gpointer p = g_hash_table_lookup (_repo.hash, GINT_TO_POINTER (nth));
   data = (GstTensorRepoData *) p;
-  g_return_val_if_fail (data != NULL, NULL);
   return data;
 }
 
@@ -60,7 +57,7 @@ gst_tensor_repo_add_repodata (guint nth)
   GstTensorRepoData *new;
 
   GST_REPO_LOCK ();
-  gpointer *check = g_hash_table_lookup (_repo.hash, GINT_TO_POINTER (nth));
+  gpointer check = g_hash_table_lookup (_repo.hash, GINT_TO_POINTER (nth));
 
   if (check != NULL) {
     return TRUE;
@@ -75,7 +72,8 @@ gst_tensor_repo_add_repodata (guint nth)
   ret = g_hash_table_insert (_repo.hash, GINT_TO_POINTER (nth), new);
   g_assert (ret);
 
-  _print_log ("Successfully added in hash table with key[%d]", nth);
+  if (DBG)
+    GST_DEBUG ("Successfully added in hash table with key[%d]", nth);
 
   _repo.num_data++;
   GST_REPO_UNLOCK ();
@@ -94,8 +92,10 @@ gst_tensor_repo_set_buffer (guint nth, GstBuffer * buffer)
   g_return_val_if_fail (data != NULL, FALSE);
 
   data->buffer = buffer;
-  _print_log ("Pushed [%d] (size : %lu)\n", nth,
-      gst_buffer_get_size (data->buffer));
+  if (DBG) {
+    unsigned long size = gst_buffer_get_size (data->buffer);
+    GST_DEBUG ("Pushed [%d] (size : %lu)\n", nth, size);
+  }
 
   GST_TENSOR_REPO_SIGNAL (nth);
   GST_TENSOR_REPO_UNLOCK (nth);
@@ -109,8 +109,9 @@ gboolean
 gst_tensor_repo_check_eos (guint nth)
 {
   GstTensorRepoData *data = gst_tensor_repo_get_repodata (nth);
-  if (data == NULL || data->eos) {
-    _print_log ("check eos done [%s]\n", data->eos ? "TRUE" : "FALSE");
+  if (data->eos) {
+    if (DBG)
+      GST_DEBUG ("check eos done [%s]\n", data->eos ? "TRUE" : "FALSE");
   }
   return data->eos;
 }
@@ -124,9 +125,6 @@ gst_tensor_repo_set_eos (guint nth)
   GST_TENSOR_REPO_LOCK (nth);
   GstTensorRepoData *data = gst_tensor_repo_get_repodata (nth);
   data->eos = TRUE;
-  if (data->buffer)
-    gst_buffer_unref (data->buffer);
-
   GST_TENSOR_REPO_SIGNAL (nth);
   GST_TENSOR_REPO_UNLOCK (nth);
   return data->eos;
@@ -153,11 +151,15 @@ gst_tensor_repo_get_buffer (guint nth)
     GST_TENSOR_REPO_WAIT (nth);
   }
   if (eos) {
-    _print_log ("Get EOS Signal while waiting\n");
+    if (DBG)
+      GST_DEBUG ("Get EOS Signal while waiting\n");
     buf = NULL;
   } else {
     buf = gst_buffer_copy_deep (current_data->buffer);
-    _print_log ("Popped [ %d ] (size: %lu)\n", nth, gst_buffer_get_size (buf));
+    if (DBG) {
+      unsigned long size = gst_buffer_get_size (buf);
+      GST_DEBUG ("Popped [ %d ] (size: %lu)\n", nth, size);
+    }
   }
   current_data->buffer = NULL;
   GST_TENSOR_REPO_UNLOCK (nth);
@@ -171,7 +173,6 @@ gboolean
 gst_tensor_repo_remove_repodata (guint nth)
 {
   gboolean ret;
-  printf ("removeing .... \n");
   GST_REPO_LOCK ();
   g_mutex_clear (GST_TENSOR_REPO_GET_LOCK (nth));
   g_cond_clear (GST_TENSOR_REPO_GET_COND (nth));
@@ -180,7 +181,12 @@ gst_tensor_repo_remove_repodata (guint nth)
 
   if (ret) {
     _repo.num_data--;
-    _print_log ("key[%d] is removed\n", nth);
+    if (DBG)
+      GST_DEBUG ("key[%d] is removed\n", nth);
+  }
+
+  if (!_repo.num_data) {
+    g_hash_table_destroy (_repo.hash);
   }
 
   GST_REPO_UNLOCK ();
index 29d5b84..e1e8f37 100644 (file)
@@ -39,7 +39,6 @@
  */
 extern GstTensorRepo _repo;
 
-
 GST_DEBUG_CATEGORY_STATIC (gst_tensor_reposink_debug);
 #define GST_CAT_DEFAULT gst_tensor_reposink_debug
 
@@ -153,7 +152,7 @@ gst_tensor_reposink_init (GstTensorRepoSink * self)
 
   gst_tensor_repo_init ();
 
-  silent_debug ("GstTensorRepo is sucessfully initailzed");
+  GST_DEBUG_OBJECT (self, "GstTensorRepo is sucessfully initailzed");
 
   self->silent = DEFAULT_SILENT;
   self->signal_rate = DEFAULT_SIGNAL_RATE;
@@ -261,7 +260,7 @@ gst_tensor_reposink_event (GstBaseSink * sink, GstEvent * event)
   self = GST_TENSOR_REPOSINK (sink);
   type = GST_EVENT_TYPE (event);
 
-  silent_debug ("received event %s", GST_EVENT_TYPE_NAME (event));
+  GST_DEBUG_OBJECT (self, "received event %s", GST_EVENT_TYPE_NAME (event));
 
   switch (type) {
     case GST_EVENT_EOS:
@@ -287,6 +286,7 @@ gst_tensor_reposink_query (GstBaseSink * sink, GstQuery * query)
   self = GST_TENSOR_REPOSINK (sink);
   type = GST_QUERY_TYPE (query);
 
+  GST_DEBUG_OBJECT (self, "received query %s", GST_QUERY_TYPE_NAME (query));
   switch (type) {
     case GST_QUERY_SEEKING:
       gst_query_parse_seeking (query, &format, NULL, NULL, NULL);
@@ -389,6 +389,21 @@ gst_tensor_reposink_set_caps (GstBaseSink * sink, GstCaps * caps)
   self = GST_TENSOR_REPOSINK (sink);
   gst_caps_replace (&self->in_caps, caps);
 
+  if (!self->silent) {
+    guint caps_size, i;
+
+    caps_size = gst_caps_get_size (caps);
+    GST_DEBUG_OBJECT (self, "set caps, size is %d", caps_size);
+
+    for (i = 0; i < caps_size; i++) {
+      GstStructure *structure = gst_caps_get_structure (caps, i);
+      gchar *str = gst_structure_to_string (structure);
+
+      GST_DEBUG_OBJECT (self, "[%d] %s", i, str);
+      g_free (str);
+    }
+  }
+
   return TRUE;
 }
 
index 2961a2e..389ff82 100644 (file)
 #include <config.h>
 #endif
 
+#include <string.h>
 #include "tensor_reposrc.h"
 
-/**
- * @brief Macro for debug mode.
- */
-#ifndef DBG
-#define DBG (!self->silent)
-#endif
-
-/**
- * @brief Macro for debug message.
- */
-#define silent_debug(...) \
-    debug_print (DBG, __VA_ARGS__)
-
 GST_DEBUG_CATEGORY_STATIC (gst_tensor_reposrc_debug);
 #define GST_CAT_DEFAULT gst_tensor_reposrc_debug
 
@@ -286,10 +274,17 @@ gst_tensor_reposrc_create (GstPushSrc * src, GstBuffer ** buffer)
     int i;
     guint num_tensors = self->config.info.num_tensors;
     gsize size = 0;
-    for (i = 0; i < num_tensors; i++)
-      size += gst_tensor_info_get_size (&self->config.info.info[i]);
-    buf = gst_buffer_new_and_alloc (size);
-    gst_buffer_memset (buf, 0, 0, size);
+    buf = gst_buffer_new ();
+    for (i = 0; i < num_tensors; i++) {
+      GstMemory *mem;
+      GstMapInfo info;
+      size = gst_tensor_info_get_size (&self->config.info.info[i]);
+      mem = gst_allocator_alloc (NULL, size, NULL);
+      gst_memory_map (mem, &info, GST_MAP_WRITE);
+      memset (info.data, 0, size);
+      gst_memory_unmap (mem, &info);
+      gst_buffer_append_memory (buf, mem);
+    }
     self->ini = TRUE;
   } else {
     buf = gst_tensor_repo_get_buffer (self->myid);
index cdc9032..5bdf6fa 100644 (file)
@@ -48,12 +48,11 @@ typedef struct _GstTensorRepoSrcClass GstTensorRepoSrcClass;
 /**
  * @brief GstTensorRepoSrc data structure.
  *
- * GstTensorRepoSrc inherits GstBaseSink.
+ * GstTensorRepoSrc inherits GstPushSrc
  */
 struct _GstTensorRepoSrc
 {
   GstPushSrc parent;
-  GstBaseSink element;
   GstTensorsConfig config;
   gboolean silent;
   guint myid;
@@ -65,7 +64,7 @@ struct _GstTensorRepoSrc
 /**
  * @brief GstTensorRepoSrcClass data structure.
  *
- * GstTensorRepoSrc inherits GstBaseSink.
+ * GstTensorRepoSrc inherits GstPushSrc
  */
 struct _GstTensorRepoSrcClass
 {