Add more mutex guard for callbacks 00/271900/1
authorSangchul Lee <sc11.lee@samsung.com>
Fri, 18 Feb 2022 10:25:46 +0000 (19:25 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Thu, 3 Mar 2022 03:56:51 +0000 (12:56 +0900)
[Version] 0.2.161
[Issue Type] Improvement

Change-Id: I1f536532c3c4bac4101d68c125197d80b267856f
Signed-off-by: Sangchul Lee <sc11.lee@samsung.com>
include/webrtc_private.h
packaging/capi-media-webrtc.spec
src/webrtc.c
src/webrtc_private.c

index 281aaef396e559ddde51bb884c7d993ef647e4e7..424857814be492680bcf2f1e4f6f4ceca9ab0b82 100644 (file)
@@ -416,6 +416,7 @@ typedef struct _webrtc_s {
        guint stats_timer_src;
 
        GMutex mutex;
+       GMutex event_src_mutex;
        GMutex desc_mutex;
        GCond desc_cond;
 
index 81459057aa51cf608ff529f10b4347583c656345..1b38d242f5c4f06c6cabca36049dc8b48ef5d836 100644 (file)
@@ -1,6 +1,6 @@
 Name:       capi-media-webrtc
 Summary:    A WebRTC library in Tizen Native API
-Version:    0.2.160
+Version:    0.2.161
 Release:    0
 Group:      Multimedia/API
 License:    Apache-2.0
index 9406af9b593d51a6a52a19affd9f053b42b9f955..2a67eea19e44008cae48916b39f0a9faa1e4c02d 100644 (file)
@@ -82,7 +82,7 @@ int webrtc_create(webrtc_h *webrtc)
 
        g_mutex_init(&_webrtc->mutex);
        locker = g_mutex_locker_new(&_webrtc->mutex);
-
+       g_mutex_init(&_webrtc->event_src_mutex);
        g_mutex_init(&_webrtc->desc_mutex);
        g_cond_init(&_webrtc->desc_cond);
 
@@ -149,8 +149,9 @@ int webrtc_destroy(webrtc_h webrtc)
        _gst_destroy_pipeline(_webrtc);
        _unload_ini(_webrtc);
 
-       g_mutex_clear(&_webrtc->desc_mutex);
        g_cond_clear(&_webrtc->desc_cond);
+       g_mutex_clear(&_webrtc->desc_mutex);
+       g_mutex_clear(&_webrtc->event_src_mutex);
 
        LOG_INFO("webrtc[%p] is destroyed", webrtc);
 
index eebcadf5af067580997b6383bbcea2fbf626eba5..62a91e5eef71684c142ccbdb60e4e02457976b84 100644 (file)
@@ -438,36 +438,57 @@ static gboolean __idle_cb(gpointer user_data)
                webrtc_state_e old_state;
 
                g_mutex_lock(&webrtc->mutex);
-
+               g_mutex_lock(&webrtc->event_src_mutex);
                webrtc->idle_cb_event_source_ids[data->type] = 0;
+               g_mutex_unlock(&webrtc->event_src_mutex);
                old_state = webrtc->state;
                webrtc->state = data->new.state;
-
                g_mutex_unlock(&webrtc->mutex);
 
                _invoke_state_changed_cb(webrtc, old_state, webrtc->state);
                break;
        }
+
        case IDLE_CB_TYPE_ERROR:
+               g_mutex_lock(&webrtc->event_src_mutex);
                webrtc->idle_cb_event_source_ids[data->type] = 0;
+               g_mutex_unlock(&webrtc->event_src_mutex);
+
                __invoke_error_cb(webrtc, data->new.error);
                break;
+
        case IDLE_CB_TYPE_PEER_CONNECTION_STATE_CHANGE:
+               g_mutex_lock(&webrtc->event_src_mutex);
                webrtc->idle_cb_event_source_ids[data->type] = 0;
+               g_mutex_unlock(&webrtc->event_src_mutex);
+
                __invoke_peer_connection_state_change_cb(webrtc, data->new.peer_connection_state);
                break;
+
        case IDLE_CB_TYPE_SIGNALING_STATE_CHANGE:
+               g_mutex_lock(&webrtc->event_src_mutex);
                webrtc->idle_cb_event_source_ids[data->type] = 0;
+               g_mutex_unlock(&webrtc->event_src_mutex);
+
                __invoke_signaling_state_change_cb(webrtc, data->new.signaling_state);
                break;
+
        case IDLE_CB_TYPE_ICE_GATHERING_STATE_CHANGE:
+               g_mutex_lock(&webrtc->event_src_mutex);
                webrtc->idle_cb_event_source_ids[data->type] = 0;
+               g_mutex_unlock(&webrtc->event_src_mutex);
+
                __invoke_ice_gathering_state_change_cb(webrtc, data->new.ice_gathering_state);
                break;
+
        case IDLE_CB_TYPE_ICE_CONNECTION_STATE_CHANGE:
+               g_mutex_lock(&webrtc->event_src_mutex);
                webrtc->idle_cb_event_source_ids[data->type] = 0;
+               g_mutex_unlock(&webrtc->event_src_mutex);
+
                __invoke_ice_connection_state_change_cb(webrtc, data->new.ice_connection_state);
                break;
+
        default:
                LOG_ERROR_IF_REACHED("type(%d)", data->type);
        }
@@ -505,7 +526,9 @@ void _post_state_cb_in_idle(webrtc_s *webrtc, webrtc_state_e new_state)
 
        webrtc->pend_state = new_state;
 
+       g_mutex_lock(&webrtc->event_src_mutex);
        webrtc->idle_cb_event_source_ids[data->type] = g_idle_add_full(G_PRIORITY_DEFAULT_IDLE, __idle_cb, data, g_free);
+       g_mutex_unlock(&webrtc->event_src_mutex);
 
        LOG_DEBUG("state will be changed [%s] -> [%s], source id[%u]",
                __state_str[webrtc->state], __state_str[new_state], webrtc->idle_cb_event_source_ids[data->type]);
@@ -523,7 +546,9 @@ void _post_error_cb_in_idle(webrtc_s *webrtc, webrtc_error_e error)
        data->type = IDLE_CB_TYPE_ERROR;
        data->new.error = error;
 
+       g_mutex_lock(&webrtc->event_src_mutex);
        webrtc->idle_cb_event_source_ids[data->type] = g_idle_add_full(G_PRIORITY_DEFAULT_IDLE, __idle_cb, data, g_free);
+       g_mutex_unlock(&webrtc->event_src_mutex);
 
        LOG_DEBUG("error will occur [0x%x], source id[%u]", error, webrtc->idle_cb_event_source_ids[data->type]);
 }
@@ -539,7 +564,9 @@ static void __post_peer_connection_state_change_cb_in_idle(webrtc_s *webrtc, web
        data->type = IDLE_CB_TYPE_PEER_CONNECTION_STATE_CHANGE;
        data->new.peer_connection_state = state;
 
+       g_mutex_lock(&webrtc->event_src_mutex);
        webrtc->idle_cb_event_source_ids[data->type] = g_idle_add_full(G_PRIORITY_DEFAULT_IDLE, __idle_cb, data, g_free);
+       g_mutex_unlock(&webrtc->event_src_mutex);
 
        LOG_DEBUG("connection state will be changed to [%u], source id[%u]", state, webrtc->idle_cb_event_source_ids[data->type]);
 }
@@ -556,7 +583,9 @@ static void __post_signaling_state_change_cb_in_idle(webrtc_s *webrtc, webrtc_si
        data->type = IDLE_CB_TYPE_SIGNALING_STATE_CHANGE;
        data->new.signaling_state = state;
 
+       g_mutex_lock(&webrtc->event_src_mutex);
        webrtc->idle_cb_event_source_ids[data->type] = g_idle_add_full(G_PRIORITY_DEFAULT_IDLE, __idle_cb, data, g_free);
+       g_mutex_unlock(&webrtc->event_src_mutex);
 
        LOG_DEBUG("signaling state will be changed to [%u], source id[%u]", state, webrtc->idle_cb_event_source_ids[data->type]);
 }
@@ -572,7 +601,9 @@ static void __post_ice_gathering_state_change_cb_in_idle(webrtc_s *webrtc, webrt
        data->type = IDLE_CB_TYPE_ICE_GATHERING_STATE_CHANGE;
        data->new.ice_gathering_state = state;
 
+       g_mutex_lock(&webrtc->event_src_mutex);
        webrtc->idle_cb_event_source_ids[data->type] = g_idle_add_full(G_PRIORITY_DEFAULT_IDLE, __idle_cb, data, g_free);
+       g_mutex_unlock(&webrtc->event_src_mutex);
 
        LOG_DEBUG("ICE gathering state will be changed to [%u], source id[%u]", state, webrtc->idle_cb_event_source_ids[data->type]);
 }
@@ -589,7 +620,9 @@ static void __post_ice_connection_state_change_cb_in_idle(webrtc_s *webrtc, webr
        data->type = IDLE_CB_TYPE_ICE_CONNECTION_STATE_CHANGE;
        data->new.ice_connection_state = state;
 
+       g_mutex_lock(&webrtc->event_src_mutex);
        webrtc->idle_cb_event_source_ids[data->type] = g_idle_add_full(G_PRIORITY_DEFAULT_IDLE, __idle_cb, data, g_free);
+       g_mutex_unlock(&webrtc->event_src_mutex);
 
        LOG_DEBUG("ICE connection state will be changed to [%u], source id[%u]", state, webrtc->idle_cb_event_source_ids[data->type]);
 }