From 13db60ebaf2a2ee4e3be9764eb2814040fa8b030 Mon Sep 17 00:00:00 2001 From: Jeongmo Yang Date: Wed, 28 Apr 2021 09:17:27 +0900 Subject: [PATCH] media_bridge: Revise code - Change data type of sink_count from "int" to "unsigned int". - Use designated initializer for name table of module. - Change name of function for thread to push packet to sink modules. - Replace strings by single structure pointer. [Version] 0.1.47 [Issue Type] Revise Change-Id: Iab7a7f4afa28a7b5e53d79460e56f90b0bc26014 Signed-off-by: Jeongmo Yang --- include/media_bridge_private.h | 2 +- packaging/capi-media-tool.spec | 2 +- src/media_bridge.c | 90 ++++++++++++++++------------------ 3 files changed, 43 insertions(+), 51 deletions(-) diff --git a/include/media_bridge_private.h b/include/media_bridge_private.h index 23bed56..126c215 100644 --- a/include/media_bridge_private.h +++ b/include/media_bridge_private.h @@ -67,7 +67,7 @@ typedef struct _media_bridge_s { media_bridge_source_s src; media_bridge_sink_s sink[MEDIA_BRIDGE_SINK_MAX]; - int sink_count; + unsigned int sink_count; } media_bridge_s; typedef struct _media_bridge_module_name_table { diff --git a/packaging/capi-media-tool.spec b/packaging/capi-media-tool.spec index 82cc295..814d46e 100755 --- a/packaging/capi-media-tool.spec +++ b/packaging/capi-media-tool.spec @@ -1,6 +1,6 @@ Name: capi-media-tool Summary: A Core API media tool library in Tizen Native API -Version: 0.1.46 +Version: 0.1.47 Release: 0 Group: Multimedia/API License: Apache-2.0 diff --git a/src/media_bridge.c b/src/media_bridge.c index aeda57e..458d6bc 100644 --- a/src/media_bridge.c +++ b/src/media_bridge.c @@ -23,28 +23,28 @@ static media_bridge_module_name_table g_media_bridge_module_name_table[MEDIA_BRIDGE_MODULE_NUM] = { - /* MEDIA_BRIDGE_MODULE_CAMERA */ - {PATH_LIBDIR"/libcapi-media-camera.so.0", + [MEDIA_BRIDGE_MODULE_CAMERA] = { + PATH_LIBDIR"/libcapi-media-camera.so.0", "camera_media_bridge_set_bridge", "camera_media_bridge_unset_bridge", NULL}, - /* MEDIA_BRIDGE_MODULE_PLAYER */ - {PATH_LIBDIR"/libcapi-media-player.so.0", + [MEDIA_BRIDGE_MODULE_PLAYER] = { + PATH_LIBDIR"/libcapi-media-player.so.0", NULL, NULL, NULL}, - /* MEDIA_BRIDGE_MODULE_VISION */ - {PATH_LIBDIR"/libmv_common.so", + [MEDIA_BRIDGE_MODULE_VISION] = { + PATH_LIBDIR"/libmv_common.so", NULL, NULL, NULL}, - /* MEDIA_BRIDGE_MODULE_CODEC */ - {PATH_LIBDIR"/libcapi-media-codec.so.0", + [MEDIA_BRIDGE_MODULE_CODEC] = { + PATH_LIBDIR"/libcapi-media-codec.so.0", NULL, NULL, NULL}, - /* MEDIA_BRIDGE_MODULE_WEBRTC */ - {PATH_LIBDIR"/libcapi-media-webrtc.so.0", + [MEDIA_BRIDGE_MODULE_WEBRTC] = { + PATH_LIBDIR"/libcapi-media-webrtc.so.0", NULL, NULL, "webrtc_media_bridge_push_packet"} @@ -116,11 +116,11 @@ static int __media_bridge_remove_all_sink_no_lock(media_bridge_s *handle) } -static gpointer __media_bridge_push_packet_func(gpointer data) +static gpointer __media_bridge_push_packet_thread_func(gpointer data) { int id = 0; - int push_count = 0; int ret = 0; + unsigned int pushed_count = 0; media_bridge_s *handle = (media_bridge_s *)data; media_packet_h packet = NULL; media_bridge_sink_s *sink = NULL; @@ -146,9 +146,9 @@ static gpointer __media_bridge_push_packet_func(gpointer data) g_mutex_unlock(&handle->lock); - LOGD("[%p] push packet[%p] to sink[count:%d]", handle, packet, handle->sink_count); + LOGD("[%p] push packet[%p] to sink[count:%u]", handle, packet, handle->sink_count); - push_count = 0; + pushed_count = 0; for (id = 0 ; id < MEDIA_BRIDGE_SINK_MAX ; id++) { sink = &handle->sink[id]; @@ -171,14 +171,14 @@ static gpointer __media_bridge_push_packet_func(gpointer data) continue; } - push_count++; + pushed_count++; } media_packet_unref(packet); packet = NULL; - if (handle->sink_count != push_count) - LOGW("something wrong[sink count:%d vs push count:%d]", handle->sink_count, push_count); + if (handle->sink_count != pushed_count) + LOGW("something wrong[sink count:%u vs pushed count:%u]", handle->sink_count, pushed_count); g_mutex_lock(&handle->lock); } @@ -206,7 +206,7 @@ int media_bridge_create(media_bridge_h *bridge) g_cond_init(&new_handle->cond); new_handle->push_packet_thread = g_thread_try_new("media_bridge_push_packet_thread", - __media_bridge_push_packet_func, (gpointer)new_handle, NULL); + __media_bridge_push_packet_thread_func, (gpointer)new_handle, NULL); if (!new_handle->push_packet_thread) { LOGE("push_packet_thread failed"); goto _CREATE_FAILED; @@ -283,9 +283,7 @@ int media_bridge_set_source(media_bridge_h bridge, media_bridge_module_e module, void *dl_handle = NULL; module_media_bridge_set_bridge_func set_bridge_func = NULL; module_media_bridge_unset_bridge_func unset_bridge_func = NULL; - const char *library_path = NULL; - const char *set_bridge = NULL; - const char *unset_bridge = NULL; + media_bridge_module_name_table *table_p = NULL; MEDIA_BRIDGE_NULL_CHECK(handle); MEDIA_BRIDGE_NULL_CHECK(module_handle); @@ -309,31 +307,28 @@ int media_bridge_set_source(media_bridge_h bridge, media_bridge_module_e module, goto _SET_SOURCE_OUT; } - library_path = g_media_bridge_module_name_table[module].library_path; - set_bridge = g_media_bridge_module_name_table[module].set_bridge; - unset_bridge = g_media_bridge_module_name_table[module].unset_bridge; - - if (!library_path || !set_bridge || !unset_bridge) { + table_p = &g_media_bridge_module_name_table[module]; + if (!table_p->library_path || !table_p->set_bridge || !table_p->unset_bridge) { LOGE("module[%d] is not supported[%s,%s,%s] for source", - module, library_path, set_bridge, unset_bridge); + module, table_p->library_path, table_p->set_bridge, table_p->unset_bridge); ret = MEDIA_BRIDGE_ERROR_NOT_SUPPORTED; goto _SET_SOURCE_OUT; } - LOGI("open[%s]", library_path); + LOGI("open[%s]", table_p->library_path); - dl_handle = dlopen(library_path, RTLD_NOW); + dl_handle = dlopen(table_p->library_path, RTLD_NOW); if (!dl_handle) { - LOGE("open[%s] failed[errno:%d]", library_path, errno); + LOGE("open[%s] failed[errno:%d]", table_p->library_path, errno); ret = MEDIA_BRIDGE_ERROR_INVALID_OPERATION; goto _SET_SOURCE_OUT; } - set_bridge_func = dlsym(dl_handle, set_bridge); - unset_bridge_func = dlsym(dl_handle, unset_bridge); + set_bridge_func = dlsym(dl_handle, table_p->set_bridge); + unset_bridge_func = dlsym(dl_handle, table_p->unset_bridge); if (!set_bridge_func || !unset_bridge_func) { LOGE("module[%d] symbol[%s,%s] failed[%s]", - module, set_bridge, unset_bridge, dlerror()); + module, table_p->set_bridge, table_p->unset_bridge, dlerror()); ret = MEDIA_BRIDGE_ERROR_INVALID_OPERATION; goto _SET_SOURCE_OUT; } @@ -400,8 +395,7 @@ int media_bridge_add_sink(media_bridge_h bridge, media_bridge_module_e module, v media_bridge_s *handle = (media_bridge_s *)bridge; media_bridge_sink_s *sink = NULL; module_media_bridge_push_packet_func push_packet_func = NULL; - const char *library_path = NULL; - const char *push_packet = NULL; + media_bridge_module_name_table *table_p = NULL; MEDIA_BRIDGE_NULL_CHECK(handle); MEDIA_BRIDGE_NULL_CHECK(module_handle); @@ -434,27 +428,25 @@ int media_bridge_add_sink(media_bridge_h bridge, media_bridge_module_e module, v goto _ADD_SINK_OUT; } - library_path = g_media_bridge_module_name_table[module].library_path; - push_packet = g_media_bridge_module_name_table[module].push_packet; - - if (!library_path || !push_packet) { - LOGE("module[%d] is not supported[%s,%s] for sink", module, library_path, push_packet); + table_p = &g_media_bridge_module_name_table[module]; + if (!table_p->library_path || !table_p->push_packet) { + LOGE("module[%d] is not supported[%s,%s] for sink", module, table_p->library_path, table_p->push_packet); ret = MEDIA_BRIDGE_ERROR_NOT_SUPPORTED; goto _ADD_SINK_OUT; } - LOGI("open[%s]", library_path); + LOGI("open[%s]", table_p->library_path); - dl_handle = dlopen(library_path, RTLD_NOW); + dl_handle = dlopen(table_p->library_path, RTLD_NOW); if (!dl_handle) { - LOGE("open[%s] failed[errno:%d]", library_path, errno); + LOGE("open[%s] failed[errno:%d]", table_p->library_path, errno); ret = MEDIA_BRIDGE_ERROR_INVALID_OPERATION; goto _ADD_SINK_OUT; } - push_packet_func = dlsym(dl_handle, push_packet); + push_packet_func = dlsym(dl_handle, table_p->push_packet); if (!push_packet_func) { - LOGE("module[%d] symbol[%s] failed[%s]", module, push_packet, dlerror()); + LOGE("module[%d] symbol[%s] failed[%s]", module, table_p->push_packet, dlerror()); ret = MEDIA_BRIDGE_ERROR_INVALID_OPERATION; goto _ADD_SINK_OUT; } @@ -468,7 +460,7 @@ int media_bridge_add_sink(media_bridge_h bridge, media_bridge_module_e module, v *sink_id = id; - LOGI("[%p] sink added[module:%d,%p, id:%d] count[%d]", + LOGI("[%p] sink added[module:%d,%p, id:%d] count[%u]", handle, module, module_handle, id, handle->sink_count); _ADD_SINK_OUT: @@ -514,7 +506,7 @@ int media_bridge_remove_sink(media_bridge_h bridge, int sink_id) handle->sink_count--; - LOGI("[%p] sink removed[id:%d,count:%d]", sink_id, handle->sink_count); + LOGI("[%p] sink removed[id:%d,count:%u]", sink_id, handle->sink_count); _REMOVE_SINK_OUT: g_mutex_unlock(&handle->lock); @@ -537,7 +529,7 @@ int media_bridge_start(media_bridge_h bridge) return MEDIA_BRIDGE_ERROR_INVALID_STATE; } - if (handle->sink_count < 1) { + if (handle->sink_count == 0) { LOGE("no sink is added"); g_mutex_unlock(&handle->lock); return MEDIA_BRIDGE_ERROR_INVALID_OPERATION; @@ -608,7 +600,7 @@ int media_bridge_push_packet(media_bridge_h bridge, media_packet_h packet) goto _PUSH_PACKET_OUT; } - if (handle->sink_count < 1) { + if (handle->sink_count == 0) { LOGW("no sink is added"); goto _PUSH_PACKET_OUT; } -- 2.34.1