media_bridge: Revise code 81/257581/2
authorJeongmo Yang <jm80.yang@samsung.com>
Wed, 28 Apr 2021 00:17:27 +0000 (09:17 +0900)
committerJeongmo Yang <jm80.yang@samsung.com>
Wed, 28 Apr 2021 01:00:07 +0000 (10:00 +0900)
- 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 <jm80.yang@samsung.com>
include/media_bridge_private.h
packaging/capi-media-tool.spec
src/media_bridge.c

index 23bed56d4654c624fa45f04a81e7bdc5dc653627..126c215720bf23cd6be108d4a7852412791f2e4e 100644 (file)
@@ -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 {
index 82cc2955c08980454981d4c89209c0b20a7548a0..814d46e323a9b46fc1200523e7d06a9b61f64a83 100755 (executable)
@@ -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
index aeda57efd3758482b664257cbffe628e64b7805d..458d6bc7da055fac2c916f126e150da4884dbbc0 100644 (file)
 
 
 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;
        }