From e19f854c0717f4327088ff1ab5993356aa725819 Mon Sep 17 00:00:00 2001 From: Jaeyun Date: Tue, 28 May 2019 17:56:44 +0900 Subject: [PATCH] [Api/Tizen] add macro for logging add macros for dlog message and replace all dlog_print() Signed-off-by: Jaeyun Jung --- tizen-api/src/tizen-api-pipeline.c | 157 ++++++++++++++++--------------------- 1 file changed, 68 insertions(+), 89 deletions(-) diff --git a/tizen-api/src/tizen-api-pipeline.c b/tizen-api/src/tizen-api-pipeline.c index 15b2eef..3fabc56 100644 --- a/tizen-api/src/tizen-api-pipeline.c +++ b/tizen-api/src/tizen-api-pipeline.c @@ -34,22 +34,29 @@ #define DLOG_TAG "nnstreamer-capi-pipeline" +#define dlogi(...) \ + dlog_print (DLOG_INFO, DLOG_TAG, __VA_ARGS__) + +#define dlogw(...) \ + dlog_print (DLOG_WARN, DLOG_TAG, __VA_ARGS__) + +#define dloge(...) \ + dlog_print (DLOG_ERROR, DLOG_TAG, __VA_ARGS__) + #define handle_init(type, name, h) \ nns_##type *name= (h); \ nns_pipeline *p; \ element *elem; \ int ret = NNS_ERROR_NONE; \ if (h == NULL) { \ - dlog_print (DLOG_ERROR, DLOG_TAG, \ - "The given handle is invalid"); \ + dloge ("The given handle is invalid"); \ return NNS_ERROR_INVALID_PARAMETER; \ } \ \ p = name->pipe; \ elem = name->element; \ if (p == NULL || elem == NULL || p != elem->pipe) { \ - dlog_print (DLOG_ERROR, DLOG_TAG, \ - "The handle appears to be broken."); \ + dloge ("The handle appears to be broken."); \ return NNS_ERROR_INVALID_PARAMETER; \ } \ \ @@ -57,8 +64,7 @@ g_mutex_lock (&elem->lock); \ \ if (NULL == g_list_find (elem->handles, name)) { \ - dlog_print (DLOG_ERROR, DLOG_TAG, \ - "The handle does not exists."); \ + dloge ("The handle does not exists."); \ ret = NNS_ERROR_INVALID_PARAMETER; \ goto unlock_return; \ } @@ -99,7 +105,7 @@ 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!"); + dloge ("GstTensorsInfo should not be NULL!"); return NNS_ERROR_INVALID_PARAMETER; } @@ -132,8 +138,7 @@ cb_sink_event (GstElement * e, GstBuffer * b, gpointer data) num_mems = gst_buffer_n_memory (b); if (num_mems > NNS_TENSOR_SIZE_LIMIT) { - dlog_print (DLOG_ERROR, DLOG_TAG, - "Number of memory chunks in a GstBuffer exceed the limit: %u > %u", + dloge ("Number of memory chunks in a GstBuffer exceed the limit: %u > %u", num_mems, NNS_TENSOR_SIZE_LIMIT); return; } @@ -175,8 +180,8 @@ cb_sink_event (GstElement * e, GstBuffer * b, gpointer data) elem->size = 0; if (elem->tensorsinfo.num_tensors != num_mems) { - dlog_print (DLOG_ERROR, DLOG_TAG, - "The sink event of [%s] cannot be handled because the tensor type mismatches.", + dloge + ("The sink event of [%s] cannot be handled because the tensor type mismatches.", elem->name); gst_caps_unref (caps); elem->sink = NULL; @@ -189,8 +194,8 @@ cb_sink_event (GstElement * e, GstBuffer * b, gpointer data) size_t sz = gst_tensor_info_get_size (&elem->tensorsinfo.info[i]); if (sz != size[i]) { - dlog_print (DLOG_ERROR, DLOG_TAG, - "The sink event of [%s] cannot be handled because the tensor dimension mismatches.", + dloge + ("The sink event of [%s] cannot be handled because the tensor dimension mismatches.", elem->name); gst_caps_unref (caps); elem->sink = NULL; @@ -214,8 +219,8 @@ cb_sink_event (GstElement * e, GstBuffer * b, gpointer data) /* Get the data! */ if (gst_buffer_get_size (b) != total_size || (elem->size > 0 && total_size != elem->size)) { - dlog_print (DLOG_ERROR, DLOG_TAG, - "The buffersize mismatches. All the three values must be the same: %zu, %zu, %zu", + dloge + ("The buffersize mismatches. All the three values must be the same: %zu, %zu, %zu", total_size, elem->size, gst_buffer_get_size (b)); g_mutex_unlock (&elem->lock); return; @@ -283,12 +288,10 @@ nns_pipeline_construct (const char *pipeline_description, nns_pipeline_h * pipe) if (FALSE == gst_init_check (NULL, NULL, &err)) { if (err) { - dlog_print (DLOG_ERROR, DLOG_TAG, - "GStreamer has the following error: %s", err->message); + dloge ("GStreamer has the following error: %s", err->message); g_error_free (err); } else { - dlog_print (DLOG_ERROR, DLOG_TAG, - "Cannot initialize GStreamer. Unknown reason."); + dloge ("Cannot initialize GStreamer. Unknown reason."); } return NNS_ERROR_STREAMS_PIPE; } @@ -296,13 +299,12 @@ nns_pipeline_construct (const char *pipeline_description, nns_pipeline_h * pipe) pipeline = gst_parse_launch (pipeline_description, &err); if (pipeline == NULL || err) { if (err) { - dlog_print (DLOG_ERROR, DLOG_TAG, - "Cannot parse and launch the given pipeline = [%s], %s", + dloge ("Cannot parse and launch the given pipeline = [%s], %s", pipeline_description, err->message); g_error_free (err); } else { - dlog_print (DLOG_ERROR, DLOG_TAG, - "Cannot parse and launch the given pipeline = [%s], unknown reason", + dloge + ("Cannot parse and launch the given pipeline = [%s], unknown reason", pipeline_description); } return NNS_ERROR_STREAMS_PIPE; @@ -373,8 +375,8 @@ nns_pipeline_construct (const char *pipeline_description, nns_pipeline_h * pipe) break; case GST_ITERATOR_RESYNC: case GST_ITERATOR_ERROR: - dlog_print (DLOG_WARN, DLOG_TAG, - "There is an error or a resync-event while inspecting a pipeline. However, we can still execute the pipeline."); + dlogw + ("There is an error or a resync-event while inspecting a pipeline. However, we can still execute the pipeline."); case GST_ITERATOR_DONE: done = TRUE; } @@ -524,14 +526,12 @@ nns_pipeline_sink_register (nns_pipeline_h pipe, const char *sinkname, int ret = NNS_ERROR_NONE; if (pipe == NULL) { - dlog_print (DLOG_ERROR, DLOG_TAG, - "The first argument, pipeline handle is not valid."); + dloge ("The first argument, pipeline handle is not valid."); return NNS_ERROR_INVALID_PARAMETER; } if (cb == NULL) { - dlog_print (DLOG_ERROR, DLOG_TAG, - "The callback argument, cb, is not valid."); + dloge ("The callback argument, cb, is not valid."); return NNS_ERROR_INVALID_PARAMETER; } @@ -539,15 +539,13 @@ nns_pipeline_sink_register (nns_pipeline_h pipe, const char *sinkname, elem = g_hash_table_lookup (p->namednodes, sinkname); if (elem == NULL) { - dlog_print (DLOG_ERROR, DLOG_TAG, - "There is no element named [%s] in the pipeline.", sinkname); + dloge ("There is no element named [%s] in the pipeline.", sinkname); ret = NNS_ERROR_INVALID_PARAMETER; goto unlock_return; } if (elem->type != NNSAPI_SINK) { - dlog_print (DLOG_ERROR, DLOG_TAG, - "The element [%s] in the pipeline is not a tensor_sink.", sinkname); + dloge ("The element [%s] in the pipeline is not a tensor_sink.", sinkname); ret = NNS_ERROR_INVALID_PARAMETER; goto unlock_return; } @@ -627,8 +625,7 @@ nns_pipeline_src_get_handle (nns_pipeline_h pipe, const char *srcname, int ret = NNS_ERROR_NONE, i; if (pipe == NULL) { - dlog_print (DLOG_ERROR, DLOG_TAG, - "The first argument, pipeline handle is not valid."); + dloge ("The first argument, pipeline handle is not valid."); return NNS_ERROR_INVALID_PARAMETER; } @@ -637,15 +634,13 @@ nns_pipeline_src_get_handle (nns_pipeline_h pipe, const char *srcname, elem = g_hash_table_lookup (p->namednodes, srcname); if (elem == NULL) { - dlog_print (DLOG_ERROR, DLOG_TAG, - "There is no element named [%s] in the pipeline.", srcname); + dloge ("There is no element named [%s] in the pipeline.", srcname); ret = NNS_ERROR_INVALID_PARAMETER; goto unlock_return; } if (elem->type != NNSAPI_SRC) { - dlog_print (DLOG_ERROR, DLOG_TAG, - "The element [%s] in the pipeline is not a tensor_src.", srcname); + dloge ("The element [%s] in the pipeline is not a tensor_src.", srcname); ret = NNS_ERROR_INVALID_PARAMETER; goto unlock_return; } @@ -659,8 +654,8 @@ nns_pipeline_src_get_handle (nns_pipeline_h pipe, const char *srcname, /** @todo caps may be NULL for prerolling */ if (caps == NULL) { - dlog_print (DLOG_WARN, DLOG_TAG, - "Cannot find caps. The pipeline is not yet negotiated for tensor_src, [%s].", + dlogw + ("Cannot find caps. The pipeline is not yet negotiated for tensor_src, [%s].", srcname); } else { guint n_caps = gst_caps_get_size (caps); @@ -742,8 +737,7 @@ nns_pipeline_src_input_data (nns_src_h h, handle_init (src, src, h); if (num_tensors < 1 || num_tensors > NNS_TENSOR_SIZE_LIMIT) { - dlog_print (DLOG_ERROR, DLOG_TAG, - "The tensor size if invalid. It should be 1 ~ %u; where it is %u", + dloge ("The tensor size if invalid. It should be 1 ~ %u; where it is %u", NNS_TENSOR_SIZE_LIMIT, num_tensors); ret = NNS_ERROR_INVALID_PARAMETER; goto unlock_return; @@ -777,8 +771,8 @@ nns_pipeline_src_input_data (nns_src_h h, elem->size = 0; if (elem->tensorsinfo.num_tensors != num_tensors) { - dlog_print (DLOG_ERROR, DLOG_TAG, - "The src push of [%s] cannot be handled because the number of tensors in a frame mismatches. %u != %u", + dloge + ("The src push of [%s] cannot be handled because the number of tensors in a frame mismatches. %u != %u", elem->name, elem->tensorsinfo.num_tensors, num_tensors); gst_caps_unref (caps); elem->sink = NULL; @@ -790,8 +784,8 @@ nns_pipeline_src_input_data (nns_src_h h, size_t sz = gst_tensor_info_get_size (&elem->tensorsinfo.info[i]); if (sz != size[i]) { - dlog_print (DLOG_ERROR, DLOG_TAG, - "The sink event of [%s] cannot be handled because the tensor dimension mismatches.", + dloge + ("The sink event of [%s] cannot be handled because the tensor dimension mismatches.", elem->name); gst_caps_unref (caps); elem->sink = NULL; @@ -802,8 +796,8 @@ nns_pipeline_src_input_data (nns_src_h h, elem->size += sz; if (sz != size[i]) { - dlog_print (DLOG_ERROR, DLOG_TAG, - "The given input tensor size (%d'th, %zu bytes) mismatches the source pad (%zu bytes)", + dloge + ("The given input tensor size (%d'th, %zu bytes) mismatches the source pad (%zu bytes)", i, size[i], sz); gst_caps_unref (caps); elem->sink = NULL; @@ -820,8 +814,7 @@ nns_pipeline_src_input_data (nns_src_h h, } if (elem->size == 0) { - dlog_print (DLOG_WARN, DLOG_TAG, - "The pipeline is not ready to accept inputs. The input is ignored."); + dlogw ("The pipeline is not ready to accept inputs. The input is ignored."); ret = NNS_ERROR_TRY_AGAIN; goto unlock_return; } @@ -842,12 +835,10 @@ nns_pipeline_src_input_data (nns_src_h h, gret = gst_app_src_push_buffer (GST_APP_SRC (elem->element), buffer); if (gret == GST_FLOW_FLUSHING) { - dlog_print (DLOG_WARN, DLOG_TAG, - "The pipeline is not in PAUSED/PLAYING. The input may be ignored."); + dlogw ("The pipeline is not in PAUSED/PLAYING. The input may be ignored."); ret = NNS_ERROR_TRY_AGAIN; } else if (gret == GST_FLOW_EOS) { - dlog_print (DLOG_WARN, DLOG_TAG, - "THe pipeline is in EOS state. The input is ignored."); + dlogw ("THe pipeline is in EOS state. The input is ignored."); ret = NNS_ERROR_STREAMS_PIPE; } @@ -871,14 +862,12 @@ nns_pipeline_switch_get_handle (nns_pipeline_h pipe, const char *switchname, int ret = NNS_ERROR_NONE; if (pipe == NULL) { - dlog_print (DLOG_ERROR, DLOG_TAG, - "The first argument, pipeline handle, is not valid."); + dloge ("The first argument, pipeline handle, is not valid."); return NNS_ERROR_INVALID_PARAMETER; } if (switchname == NULL) { - dlog_print (DLOG_ERROR, DLOG_TAG, - "The second argument, switchname, is not valid."); + dloge ("The second argument, switchname, is not valid."); return NNS_ERROR_INVALID_PARAMETER; } @@ -886,15 +875,15 @@ nns_pipeline_switch_get_handle (nns_pipeline_h pipe, const char *switchname, elem = g_hash_table_lookup (p->namednodes, switchname); if (elem == NULL) { - dlog_print (DLOG_ERROR, DLOG_TAG, - "There is no switch element named [%s] in the pipeline.", switchname); + dloge ("There is no switch element named [%s] in the pipeline.", + switchname); ret = NNS_ERROR_INVALID_PARAMETER; goto unlock_return; } if (elem->type != NNSAPI_SWITCH_INPUT && elem->type != NNSAPI_SWITCH_OUTPUT) { - dlog_print (DLOG_ERROR, DLOG_TAG, - "There is an element named [%s] in the pipeline, but it is not an input/output switch", + dloge + ("There is an element named [%s] in the pipeline, but it is not an input/output switch", switchname); ret = NNS_ERROR_INVALID_PARAMETER; goto unlock_return; @@ -912,8 +901,7 @@ nns_pipeline_switch_get_handle (nns_pipeline_h pipe, const char *switchname, else if (elem->type == NNSAPI_SWITCH_OUTPUT) *type = NNS_SWITCH_OUTPUTSELECTOR; else { - dlog_print (DLOG_ERROR, DLOG_TAG, - "Internal data of switch-handle [%s] is broken. It is fatal.", + dloge ("Internal data of switch-handle [%s] is broken. It is fatal.", elem->name); ret = NNS_ERROR_INVALID_PARAMETER; goto unlock_return; @@ -961,8 +949,7 @@ nns_pipeline_switch_select (nns_switch_h h, const char *padname) active_name = gst_pad_get_name (active_pad); if (!g_strcmp0 (padname, active_name)) { - dlog_print (DLOG_INFO, DLOG_TAG, - "Switch is called, but there is no effective changes: %s->%s.", + dlogi ("Switch is called, but there is no effective changes: %s->%s.", active_name, padname); g_free (active_name); gst_object_unref (active_pad); @@ -976,8 +963,7 @@ nns_pipeline_switch_select (nns_switch_h h, const char *padname) new_pad = gst_element_get_static_pad (elem->element, padname); if (new_pad == NULL) { /* Not Found! */ - dlog_print (DLOG_ERROR, DLOG_TAG, - "Cannot find the pad, [%s], from the switch, [%s].", + dloge ("Cannot find the pad, [%s], from the switch, [%s].", padname, elem->name); ret = NNS_ERROR_INVALID_PARAMETER; goto unlock_return; @@ -986,8 +972,7 @@ nns_pipeline_switch_select (nns_switch_h h, const char *padname) g_object_set (G_OBJECT (elem->element), "active-pad", new_pad, NULL); gst_object_unref (new_pad); - dlog_print (DLOG_INFO, DLOG_TAG, - "Switched to [%s] successfully at switch [%s].", padname, elem->name); + dlogi ("Switched to [%s] successfully at switch [%s].", padname, elem->name); handle_exit (h); } @@ -1012,8 +997,8 @@ nns_pipeline_switch_nodelist (nns_switch_h h, char ***list) else if (elem->type == NNSAPI_SWITCH_OUTPUT) it = gst_element_iterate_src_pads (elem->element); else { - dlog_print (DLOG_ERROR, DLOG_TAG, - "The element, [%s], is supposed to be input/output switch, but it is not. Internal data structure is broken.", + dloge + ("The element, [%s], is supposed to be input/output switch, but it is not. Internal data structure is broken.", elem->name); ret = NNS_ERROR_STREAMS_PIPE; goto unlock_return; @@ -1034,8 +1019,7 @@ nns_pipeline_switch_nodelist (nns_switch_h h, char ***list) gst_iterator_resync (it); break; case GST_ITERATOR_ERROR: - dlog_print (DLOG_ERROR, DLOG_TAG, - "Cannot access the list of pad properly of a switch, [%s].", + dloge ("Cannot access the list of pad properly of a switch, [%s].", elem->name); ret = NNS_ERROR_STREAMS_PIPE; break; @@ -1060,8 +1044,8 @@ nns_pipeline_switch_nodelist (nns_switch_h h, char ***list) g_list_free_full (dllist, g_free); /* This frees all strings as well */ g_free (list); - dlog_print (DLOG_ERROR, DLOG_TAG, - "Internal data inconsistency. This could be a bug in nnstreamer. Switch [%s].", + dloge + ("Internal data inconsistency. This could be a bug in nnstreamer. Switch [%s].", elem->name); ret = NNS_ERROR_STREAMS_PIPE; goto unlock_return; @@ -1086,14 +1070,12 @@ nns_pipeline_valve_get_handle (nns_pipeline_h pipe, const char *valvename, int ret = NNS_ERROR_NONE; if (pipe == NULL) { - dlog_print (DLOG_ERROR, DLOG_TAG, - "The first argument, pipeline handle, is not valid."); + dloge ("The first argument, pipeline handle, is not valid."); return NNS_ERROR_INVALID_PARAMETER; } if (valvename == NULL) { - dlog_print (DLOG_ERROR, DLOG_TAG, - "The second argument, valvename, is not valid."); + dloge ("The second argument, valvename, is not valid."); return NNS_ERROR_INVALID_PARAMETER; } @@ -1101,15 +1083,14 @@ nns_pipeline_valve_get_handle (nns_pipeline_h pipe, const char *valvename, elem = g_hash_table_lookup (p->namednodes, valvename); if (elem == NULL) { - dlog_print (DLOG_ERROR, DLOG_TAG, - "There is no valve element named [%s] in the pipeline.", valvename); + dloge ("There is no valve element named [%s] in the pipeline.", valvename); ret = NNS_ERROR_INVALID_PARAMETER; goto unlock_return; } if (elem->type != NNSAPI_VALVE) { - dlog_print (DLOG_ERROR, DLOG_TAG, - "There is an element named [%s] in the pipeline, but it is not a valve", + dloge + ("There is an element named [%s] in the pipeline, but it is not a valve", valvename); ret = NNS_ERROR_INVALID_PARAMETER; goto unlock_return; @@ -1160,15 +1141,13 @@ nns_pipeline_valve_control (nns_valve_h h, int valve_drop) if ((valve_drop != 0) == (drop != FALSE)) { /* Nothing to do */ - dlog_print (DLOG_INFO, DLOG_TAG, - "Valve is called, but there is no effective changes: %d->%d", + dlogi ("Valve is called, but there is no effective changes: %d->%d", ! !drop, ! !valve_drop); goto unlock_return; } g_object_set (G_OBJECT (elem->element), "drop", ! !valve_drop, NULL); - dlog_print (DLOG_INFO, DLOG_TAG, - "Valve is changed: %d->%d", ! !drop, ! !valve_drop); + dlogi ("Valve is changed: %d->%d", ! !drop, ! !valve_drop); handle_exit (h); } -- 2.7.4