From e3d6cdf20b725d367724181761bccf1bfb018a18 Mon Sep 17 00:00:00 2001 From: Gilbok Lee Date: Fri, 27 Mar 2020 16:19:36 +0900 Subject: [PATCH] Add MEDIADEMUXER_RET_VAL_IF macro for code cleanup [Version] 0.1.36 [Issue Type] Code cleanup Change-Id: Iaff8f8cf291d8f02712a0d6c26764af5d1261103 --- include/mediademuxer_port.h | 1 - include/mediademuxer_private.h | 5 +- include/mediademuxer_util.h | 30 +++---- packaging/capi-mediademuxer.spec | 2 +- src/mediademuxer_port.c | 153 +++++++++-------------------------- src/port_gst/mediademuxer_port_gst.c | 3 +- 6 files changed, 62 insertions(+), 132 deletions(-) diff --git a/include/mediademuxer_port.h b/include/mediademuxer_port.h index 34c805f..3e32db9 100644 --- a/include/mediademuxer_port.h +++ b/include/mediademuxer_port.h @@ -32,7 +32,6 @@ #include #include #include -#include #ifdef __cplusplus extern "C" { diff --git a/include/mediademuxer_private.h b/include/mediademuxer_private.h index 5e9a99e..b4bb175 100644 --- a/include/mediademuxer_private.h +++ b/include/mediademuxer_private.h @@ -25,6 +25,7 @@ #include #include #include +#include #ifdef __cplusplus extern "C" { @@ -35,9 +36,9 @@ extern "C" { #endif #define LOG_TAG "TIZEN_N_MEDIADEMUXER" -#define DEMUXER_CHECK_CONDITION(condition, error, msg) \ +#define DEMUXER_CHECK_CONDITION(condition, error, msg) \ if (condition) {} else \ - { LOGE("[%s] %s(0x%08x)", __FUNCTION__, msg, error); return error; }; \ + { MD_E("%s(0x%08x)", msg, error); return error; }; \ #define DEMUXER_INSTANCE_CHECK(demuxer) \ DEMUXER_CHECK_CONDITION(demuxer != NULL, MEDIADEMUXER_ERROR_INVALID_PARAMETER, "DEMUXER_ERROR_INVALID_PARAMETER") diff --git a/include/mediademuxer_util.h b/include/mediademuxer_util.h index 72cdd25..173e0d5 100644 --- a/include/mediademuxer_util.h +++ b/include/mediademuxer_util.h @@ -26,8 +26,6 @@ #include #include #include - -#include #include #include @@ -61,39 +59,43 @@ extern "C" { /* general */ #define MEDIADEMUXER_FREEIF(x) \ - if (x) \ + do { \ g_free(x); \ - x = NULL; + x = NULL; \ + } while (0) -#if 1 #define MEDIADEMUXER_FENTER() MD_FENTER() #define MEDIADEMUXER_FLEAVE() MD_FLEAVE() -#else -#define MEDIADEMUXER_FENTER(); -#define MEDIADEMUXER_FLEAVE(); -#endif #define MEDIADEMUXER_CHECK_NULL(x_var) \ do { \ - if (!x_var) { \ - MD_E("[%s] is NULL\n", #x_var); \ + if (!(x_var)) { \ + MD_E("[%s] is NULL", #x_var); \ return MD_ERROR_INVALID_ARGUMENT; \ } \ } while (0) #define MEDIADEMUXER_CHECK_NULL_VOID(x_var) \ do { \ - if (!x_var) { \ - MD_E("[%s] is NULL\n", #x_var); \ + if (!(x_var)) { \ + MD_E("[%s] is NULL", #x_var); \ return; \ } \ } while (0) +#define MEDIADEMUXER_RET_VAL_IF(x_cond, ret_val, err_text) \ + do { \ + if ((x_cond)) { \ + MD_E("%s", #err_text); \ + return ret_val; \ + }; \ + } while (0) + #define MEDIADEMUXER_CHECK_SET_AND_PRINT(x_var, x_cond, ret, ret_val, err_text) \ do { \ if (x_var != x_cond) { \ ret = ret_val; \ - MD_E("%s\n", #err_text); \ + MD_E("%s", #err_text); \ goto ERROR; \ } \ } while (0) diff --git a/packaging/capi-mediademuxer.spec b/packaging/capi-mediademuxer.spec index 6680dba..57e3962 100644 --- a/packaging/capi-mediademuxer.spec +++ b/packaging/capi-mediademuxer.spec @@ -1,6 +1,6 @@ Name: capi-mediademuxer Summary: A Media Demuxer library in Tizen Native API -Version: 0.1.35 +Version: 0.1.36 Release: 1 Group: Multimedia/API License: Apache-2.0 diff --git a/src/mediademuxer_port.c b/src/mediademuxer_port.c index e49c3cb..5bfb9b4 100644 --- a/src/mediademuxer_port.c +++ b/src/mediademuxer_port.c @@ -155,8 +155,8 @@ bool __md_util_is_sdp_file(const char *path) /* second, if no suffix is there, check it's contents */ if (!ret) /* FIXIT : do it soon */ - g_free(uri); - uri = NULL; + MEDIADEMUXER_FREEIF(uri); + MEDIADEMUXER_FLEAVE(); return ret; } @@ -260,11 +260,7 @@ int _md_util_parse(MMHandleType demuxer, const char *type) MEDIADEMUXER_CHECK_NULL(media_type_string); MD_L("media_type_string allocating %p\n", media_type_string); /*Set media_type depending upon the header of string else consider using file protocol */ - if (new_demuxer->uri_src) { - MD_L("new_demuxer->uri_src deallocating %p\n", new_demuxer->uri_src); - g_free(new_demuxer->uri_src); - new_demuxer->uri_src = NULL; - } + MEDIADEMUXER_FREEIF(new_demuxer->uri_src); new_demuxer->uri_src_media_type = __md_util_media_type(&media_type_string); if (new_demuxer->uri_src_media_type != MEDIADEMUXER_SRC_INVALID) { g_free(new_demuxer->uri_src); @@ -274,13 +270,10 @@ int _md_util_parse(MMHandleType demuxer, const char *type) } else { MD_E("Error while setiing source\n"); MD_E("deallocating media_type_string %p\n", media_type_string); + result = MD_ERROR_INVALID_ARGUMENT; g_free(media_type_string); - goto ERROR; } - MEDIADEMUXER_FLEAVE(); - return result; -ERROR: - result = MD_ERROR_INVALID_ARGUMENT; + MEDIADEMUXER_FLEAVE(); return result; } @@ -291,13 +284,8 @@ int md_set_data_source(MMHandleType demuxer, const char *uri) MEDIADEMUXER_FENTER(); MEDIADEMUXER_CHECK_NULL(demuxer); result = _md_util_parse(demuxer, (const char *)uri); - MEDIADEMUXER_CHECK_SET_AND_PRINT(result, MD_ERROR_NONE, result, - MD_ERROR_INVALID_ARGUMENT, - "error while parsing the file"); - MEDIADEMUXER_FLEAVE(); - return result; -ERROR: - result = MD_ERROR_INVALID_ARGUMENT; + MEDIADEMUXER_RET_VAL_IF(result != MD_ERROR_NONE, MD_ERROR_INVALID_ARGUMENT, + "error while parsing the file"); MEDIADEMUXER_FLEAVE(); return result; } @@ -312,12 +300,8 @@ int md_prepare(MMHandleType demuxer) MEDIADEMUXER_CHECK_NULL(pOps); MEDIADEMUXER_CHECK_NULL(md_handle->uri_src); result = pOps->prepare(md_handle->mdport_handle, md_handle->uri_src); - MEDIADEMUXER_CHECK_SET_AND_PRINT(result, MD_ERROR_NONE, result, - MD_ERROR, "error while doing prepare"); - MEDIADEMUXER_FLEAVE(); - return result; -ERROR: - result = MD_ERROR_INVALID_ARGUMENT; + MEDIADEMUXER_RET_VAL_IF(result != MD_ERROR_NONE, MD_ERROR, + "error while doing prepare"); MEDIADEMUXER_FLEAVE(); return result; } @@ -331,13 +315,8 @@ int md_get_track_count(MMHandleType demuxer, int *count) media_port_demuxer_ops *pOps = md_handle->demuxer_ops; MEDIADEMUXER_CHECK_NULL(pOps); result = pOps->get_track_count(md_handle->mdport_handle, count); - MEDIADEMUXER_CHECK_SET_AND_PRINT(result, MD_ERROR_NONE, - result, MD_ERROR, - "error while getting track count"); - MEDIADEMUXER_FLEAVE(); - return result; -ERROR: - result = MD_ERROR_INVALID_ARGUMENT; + MEDIADEMUXER_RET_VAL_IF(result != MD_ERROR_NONE, MD_ERROR, + "error while getting track count"); MEDIADEMUXER_FLEAVE(); return result; } @@ -351,12 +330,8 @@ int md_select_track(MMHandleType demuxer, int track) media_port_demuxer_ops *pOps = md_handle->demuxer_ops; MEDIADEMUXER_CHECK_NULL(pOps); result = pOps->set_track(md_handle->mdport_handle, track); - MEDIADEMUXER_CHECK_SET_AND_PRINT(result, MD_ERROR_NONE, result, - MD_ERROR, "error select track"); - MEDIADEMUXER_FLEAVE(); - return result; -ERROR: - result = MD_ERROR_INVALID_ARGUMENT; + MEDIADEMUXER_RET_VAL_IF(result != MD_ERROR_NONE, MD_ERROR, + "error select track"); MEDIADEMUXER_FLEAVE(); return result; } @@ -370,12 +345,8 @@ int md_start(MMHandleType demuxer) media_port_demuxer_ops *pOps = md_handle->demuxer_ops; MEDIADEMUXER_CHECK_NULL(pOps); result = pOps->start(md_handle->mdport_handle); - MEDIADEMUXER_CHECK_SET_AND_PRINT(result, MD_ERROR_NONE, result, - MD_ERROR, "error while doing start"); - MEDIADEMUXER_FLEAVE(); - return result; -ERROR: - result = MD_ERROR_INVALID_ARGUMENT; + MEDIADEMUXER_RET_VAL_IF(result != MD_ERROR_NONE, MD_ERROR, + "error while doing start"); MEDIADEMUXER_FLEAVE(); return result; } @@ -389,13 +360,8 @@ int md_get_track_info(MMHandleType demuxer, int track, media_format_h *format) media_port_demuxer_ops *pOps = md_handle->demuxer_ops; MEDIADEMUXER_CHECK_NULL(pOps); result = pOps->get_track_info(md_handle->mdport_handle, format, track); - MEDIADEMUXER_CHECK_SET_AND_PRINT(result, MD_ERROR_NONE, - result, MD_ERROR, - "error while getting track count"); - MEDIADEMUXER_FLEAVE(); - return result; -ERROR: - result = MD_ERROR_INVALID_ARGUMENT; + MEDIADEMUXER_RET_VAL_IF(result != MD_ERROR_NONE, MD_ERROR, + "error while getting track count"); MEDIADEMUXER_FLEAVE(); return result; } @@ -409,15 +375,8 @@ int md_read_sample(MMHandleType demuxer, int track_indx, media_packet_h *outbuf) media_port_demuxer_ops *pOps = md_handle->demuxer_ops; MEDIADEMUXER_CHECK_NULL(pOps); result = pOps->read_sample(md_handle->mdport_handle, outbuf, track_indx); - if (result == MD_ERROR_NONE) { - MEDIADEMUXER_FLEAVE(); - return result; - } else { - MD_E("error while reading sample\n"); - goto ERROR; - } -ERROR: - result = MD_ERROR_INVALID_ARGUMENT; + MEDIADEMUXER_RET_VAL_IF(result != MD_ERROR_NONE, MD_ERROR, + "error while reading sample"); MEDIADEMUXER_FLEAVE(); return result; } @@ -431,12 +390,8 @@ int md_seek(MMHandleType demuxer, int64_t pos) media_port_demuxer_ops *pOps = md_handle->demuxer_ops; MEDIADEMUXER_CHECK_NULL(pOps); result = pOps->seek(md_handle->mdport_handle, pos); - MEDIADEMUXER_CHECK_SET_AND_PRINT(result, MD_ERROR_NONE, result, - MD_ERROR, "error while doing seek"); - MEDIADEMUXER_FLEAVE(); - return result; -ERROR: - result = MD_ERROR_INVALID_ARGUMENT; + MEDIADEMUXER_RET_VAL_IF(result != MD_ERROR_NONE, MD_ERROR, + "error while doing seek"); MEDIADEMUXER_FLEAVE(); return result; } @@ -450,12 +405,8 @@ int md_unselect_track(MMHandleType demuxer, int track) media_port_demuxer_ops *pOps = md_handle->demuxer_ops; MEDIADEMUXER_CHECK_NULL(pOps); result = pOps->unset_track(md_handle->mdport_handle, track); - MEDIADEMUXER_CHECK_SET_AND_PRINT(result, MD_ERROR_NONE, result, - MD_ERROR, "error unselect track"); - MEDIADEMUXER_FLEAVE(); - return result; -ERROR: - result = MD_ERROR_INVALID_ARGUMENT; + MEDIADEMUXER_RET_VAL_IF(result != MD_ERROR_NONE, MD_ERROR, + "error unselect track"); MEDIADEMUXER_FLEAVE(); return result; } @@ -469,12 +420,8 @@ int md_stop(MMHandleType demuxer) media_port_demuxer_ops *pOps = md_handle->demuxer_ops; MEDIADEMUXER_CHECK_NULL(pOps); result = pOps->stop(md_handle->mdport_handle); - MEDIADEMUXER_CHECK_SET_AND_PRINT(result, MD_ERROR_NONE, result, - MD_ERROR, "error while doing stop"); - MEDIADEMUXER_FLEAVE(); - return result; -ERROR: - result = MD_ERROR_INVALID_ARGUMENT; + MEDIADEMUXER_RET_VAL_IF(result != MD_ERROR_NONE, MD_ERROR, + "error while doing stop"); MEDIADEMUXER_FLEAVE(); return result; } @@ -488,12 +435,8 @@ int md_unprepare(MMHandleType demuxer) media_port_demuxer_ops *pOps = md_handle->demuxer_ops; MEDIADEMUXER_CHECK_NULL(pOps); result = pOps->unprepare(md_handle->mdport_handle); - MEDIADEMUXER_CHECK_SET_AND_PRINT(result, MD_ERROR_NONE, result, - MD_ERROR, "error while doing stop"); - MEDIADEMUXER_FLEAVE(); - return result; -ERROR: - result = MD_ERROR_INVALID_ARGUMENT; + MEDIADEMUXER_RET_VAL_IF(result != MD_ERROR_NONE, MD_ERROR, + "error while doing stop"); MEDIADEMUXER_FLEAVE(); return result; } @@ -507,28 +450,20 @@ int md_destroy(MMHandleType demuxer) media_port_demuxer_ops *pOps = md_handle->demuxer_ops; MEDIADEMUXER_CHECK_NULL(pOps); result = pOps->destroy(md_handle->mdport_handle); - MEDIADEMUXER_CHECK_SET_AND_PRINT(result, MD_ERROR_NONE, result, - MD_ERROR, "error while doing destroy"); + MEDIADEMUXER_RET_VAL_IF(result != MD_ERROR_NONE, MD_ERROR, + "error while doing destroy"); /* free mediademuxer structure */ if (md_handle) { - if (md_handle->demuxer_ops) { - MD_I("md_destroy deallocating md_handle->demuxer_ops %p:\n", md_handle->demuxer_ops); - g_free((void *)(md_handle->demuxer_ops)); - } - if (md_handle->uri_src) { - MD_I("md_destroy deallocating md_handle->uri_src %p:\n", - md_handle->uri_src); - g_free((void *)(md_handle->uri_src)); - } - MD_I("md_destroy deallocating md_handle %p:\n", md_handle); - g_free((void *)md_handle); - md_handle = NULL; + MD_I("deallocating md_handle->demuxer_ops %p", md_handle->demuxer_ops); + MEDIADEMUXER_FREEIF(md_handle->demuxer_ops); + MD_I("deallocating md_handle->uri_src %p", md_handle->uri_src); + MEDIADEMUXER_FREEIF(md_handle->uri_src); + MD_I("deallocating md_handle %p", md_handle); + MEDIADEMUXER_FREEIF(md_handle); } - MEDIADEMUXER_FLEAVE(); - return result; -ERROR: + MEDIADEMUXER_FLEAVE(); return result; } @@ -542,12 +477,8 @@ int md_set_error_cb(MMHandleType demuxer, media_port_demuxer_ops *pOps = md_handle->demuxer_ops; MEDIADEMUXER_CHECK_NULL(pOps); result = pOps->set_error_cb(md_handle->mdport_handle, callback, user_data); - MEDIADEMUXER_CHECK_SET_AND_PRINT(result, MD_ERROR_NONE, result, - MD_ERROR, "error while setting error call back"); - MEDIADEMUXER_FLEAVE(); - return result; -ERROR: - result = MD_ERROR_INVALID_ARGUMENT; + MEDIADEMUXER_RET_VAL_IF(result != MD_ERROR_NONE, MD_ERROR, + "error while setting error call back"); MEDIADEMUXER_FLEAVE(); return result; } @@ -562,12 +493,8 @@ int md_set_eos_cb(MMHandleType demuxer, media_port_demuxer_ops *pOps = md_handle->demuxer_ops; MEDIADEMUXER_CHECK_NULL(pOps); result = pOps->set_eos_cb(md_handle->mdport_handle, callback, user_data); - MEDIADEMUXER_CHECK_SET_AND_PRINT(result, MD_ERROR_NONE, result, - MD_ERROR, "error while setting eos call back"); - MEDIADEMUXER_FLEAVE(); - return result; -ERROR: - result = MD_ERROR_INVALID_ARGUMENT; + MEDIADEMUXER_RET_VAL_IF(result != MD_ERROR_NONE, MD_ERROR, + "error while setting eos call back"); MEDIADEMUXER_FLEAVE(); return result; } diff --git a/src/port_gst/mediademuxer_port_gst.c b/src/port_gst/mediademuxer_port_gst.c index 7f28818..00a04f9 100644 --- a/src/port_gst/mediademuxer_port_gst.c +++ b/src/port_gst/mediademuxer_port_gst.c @@ -1845,8 +1845,9 @@ static int gst_demuxer_unprepare(MMHandleType pHandle) source = g_main_context_find_source_by_id(gst_handle->thread_default, gst_handle->bus_watch_id); if (source) { g_source_destroy(source); - LOGD("Deallocation bus watch id"); + MD_I("Deallocation bus watch id"); } + gst_handle->bus_watch_id = 0; } MD_I("gst_demuxer_stop pipeine %p\n", gst_handle->pipeline); -- 2.7.4