webrtc_private: Fix negotiation state bugs 26/274626/2 submit/tizen/20220505.151051
authorSangchul Lee <sc11.lee@samsung.com>
Wed, 4 May 2022 02:37:58 +0000 (11:37 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Wed, 4 May 2022 02:59:37 +0000 (11:59 +0900)
Setting the result state is moved inside __idle_cb().
Invalid converting enums are also fixed.
Getting the state in the callback is added to webrtc_test.

[Version] 0.3.99
[Issue Type] Bug fix

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

index 559bd48766472dd180440da7e7d85ddcb6144c53..6dd731b0c47dfea1929a3dab16dfadbd9f403997 100644 (file)
@@ -1,6 +1,6 @@
 Name:       capi-media-webrtc
 Summary:    A WebRTC library in Tizen Native API
-Version:    0.3.98
+Version:    0.3.99
 Release:    0
 Group:      Multimedia/API
 License:    Apache-2.0
index 8174d22072f3e3205c5e417cdafd89f0ce2fc0df..e1133e65b199fb6cc416432d0811bef21a52c89b 100644 (file)
@@ -399,7 +399,7 @@ static void __invoke_error_cb(webrtc_s *webrtc, webrtc_error_e error)
        }
 }
 
-static void __invoke_peer_connection_state_change_cb(webrtc_s *webrtc, GstWebRTCPeerConnectionState state)
+static void __invoke_peer_connection_state_change_cb(webrtc_s *webrtc, webrtc_peer_connection_state_e state)
 {
        webrtc_callbacks_s *cb;
 
@@ -407,17 +407,17 @@ static void __invoke_peer_connection_state_change_cb(webrtc_s *webrtc, GstWebRTC
 
        cb = &webrtc->peer_connection_state_change_cb;
 
-       LOG_INFO("webrtc[%p] peer connection state is changed to [%s]", webrtc, __peer_connection_state_info[state].str);
+       LOG_INFO("webrtc[%p] peer connection state is changed to [%u]", webrtc, state);
 
        if (cb->callback) {
                LOG_DEBUG(">>> callback[%p] user_data[%p]", cb->callback, cb->user_data);
-               ((webrtc_peer_connection_state_change_cb)(cb->callback))((webrtc_h)webrtc, __peer_connection_state_info[state].state, cb->user_data);
+               ((webrtc_peer_connection_state_change_cb)(cb->callback))((webrtc_h)webrtc, state, cb->user_data);
                LOG_DEBUG("<<< end of the callback");
        }
 }
 //LCOV_EXCL_STOP
 
-static void __invoke_signaling_state_change_cb(webrtc_s *webrtc, GstWebRTCPeerConnectionState state)
+static void __invoke_signaling_state_change_cb(webrtc_s *webrtc, webrtc_signaling_state_e state)
 {
        webrtc_callbacks_s *cb;
 
@@ -425,16 +425,16 @@ static void __invoke_signaling_state_change_cb(webrtc_s *webrtc, GstWebRTCPeerCo
 
        cb = &webrtc->signaling_state_change_cb;
 
-       LOG_INFO("webrtc[%p] signaling state is changed to [%s]", webrtc, __signaling_state_info[state].str);
+       LOG_INFO("webrtc[%p] signaling state is changed to [%u]", webrtc, state);
 
        if (cb->callback) {
                LOG_DEBUG(">>> callback[%p] user_data[%p]", cb->callback, cb->user_data);
-               ((webrtc_signaling_state_change_cb)(cb->callback))((webrtc_h)webrtc, __signaling_state_info[state].state, cb->user_data);
+               ((webrtc_signaling_state_change_cb)(cb->callback))((webrtc_h)webrtc, state, cb->user_data);
                LOG_DEBUG("<<< end of the callback");
        }
 }
 
-static void __invoke_ice_gathering_state_change_cb(webrtc_s *webrtc, GstWebRTCICEGatheringState state)
+static void __invoke_ice_gathering_state_change_cb(webrtc_s *webrtc, webrtc_ice_gathering_state_e state)
 {
        webrtc_callbacks_s *cb;
 
@@ -442,17 +442,17 @@ static void __invoke_ice_gathering_state_change_cb(webrtc_s *webrtc, GstWebRTCIC
 
        cb = &webrtc->ice_gathering_state_change_cb;
 
-       LOG_INFO("webrtc[%p] ICE gathering state is changed to [%s]", webrtc, __ice_gathering_state_info[state].str);
+       LOG_INFO("webrtc[%p] ICE gathering state is changed to [%u]", webrtc, state);
 
        if (cb->callback) {
                LOG_DEBUG(">>> callback[%p] user_data[%p]", cb->callback, cb->user_data);
-               ((webrtc_ice_gathering_state_change_cb)(cb->callback))((webrtc_h)webrtc, __ice_gathering_state_info[state].state, cb->user_data);
+               ((webrtc_ice_gathering_state_change_cb)(cb->callback))((webrtc_h)webrtc, state, cb->user_data);
                LOG_DEBUG("<<< end of the callback");
        }
 }
 
 //LCOV_EXCL_START
-static void __invoke_ice_connection_state_change_cb(webrtc_s *webrtc, GstWebRTCICEConnectionState state)
+static void __invoke_ice_connection_state_change_cb(webrtc_s *webrtc, webrtc_ice_connection_state_e state)
 {
        webrtc_callbacks_s *cb;
 
@@ -460,11 +460,11 @@ static void __invoke_ice_connection_state_change_cb(webrtc_s *webrtc, GstWebRTCI
 
        cb = &webrtc->ice_connection_state_change_cb;
 
-       LOG_INFO("webrtc[%p] ICE connection state is changed to [%s]", webrtc, __ice_connection_state_info[state].str);
+       LOG_INFO("webrtc[%p] ICE connection state is changed to [%u]", webrtc, state);
 
        if (cb->callback) {
                LOG_DEBUG(">>> callback[%p] user_data[%p]", cb->callback, cb->user_data);
-               ((webrtc_ice_connection_state_change_cb)(cb->callback))((webrtc_h)webrtc, __ice_connection_state_info[state].state, cb->user_data);
+               ((webrtc_ice_connection_state_change_cb)(cb->callback))((webrtc_h)webrtc, state, cb->user_data);
                LOG_DEBUG("<<< end of the callback");
        }
 }
@@ -610,33 +610,45 @@ static gboolean __idle_cb(gpointer user_data)
                break;
 
        case IDLE_CB_TYPE_PEER_CONNECTION_STATE_CHANGE:
+               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);
+               webrtc->negotiation_states.peer_connection_state = data->new.peer_connection_state;
+               g_mutex_unlock(&webrtc->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->mutex);
                g_mutex_lock(&webrtc->event_src_mutex);
                webrtc->idle_cb_event_source_ids[data->type] = 0;
                g_mutex_unlock(&webrtc->event_src_mutex);
+               webrtc->negotiation_states.signaling_state = data->new.signaling_state;
+               g_mutex_unlock(&webrtc->mutex);
 
                __invoke_signaling_state_change_cb(webrtc, data->new.signaling_state);
                break;
 
        case IDLE_CB_TYPE_ICE_GATHERING_STATE_CHANGE:
+               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);
+               webrtc->negotiation_states.ice_gathering_state = data->new.ice_gathering_state;
+               g_mutex_unlock(&webrtc->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->mutex);
                g_mutex_lock(&webrtc->event_src_mutex);
                webrtc->idle_cb_event_source_ids[data->type] = 0;
                g_mutex_unlock(&webrtc->event_src_mutex);
+               webrtc->negotiation_states.ice_connection_state = data->new.ice_connection_state;
+               g_mutex_unlock(&webrtc->mutex);
 
                __invoke_ice_connection_state_change_cb(webrtc, data->new.ice_connection_state);
                break;
@@ -1072,9 +1084,8 @@ static void __webrtcbin_peer_connection_state_cb(GstElement *webrtcbin, GParamSp
        g_object_get(webrtcbin, "connection-state", &state, NULL);
 
        LOG_DEBUG("webrtc[%p] [PeerConnectionState] is changed to [%s]", webrtc, __peer_connection_state_info[state].str);
-       webrtc->negotiation_states.peer_connection_state = __peer_connection_state_info[state].state;
 
-       __post_peer_connection_state_change_cb_in_idle(webrtc, state);
+       __post_peer_connection_state_change_cb_in_idle(webrtc, __peer_connection_state_info[state].state);
 
        switch (state) {
        case GST_WEBRTC_PEER_CONNECTION_STATE_CONNECTED:
@@ -1105,13 +1116,12 @@ static void __webrtcbin_signaling_state_cb(GstElement *webrtcbin, GParamSpec * p
        g_object_get(webrtcbin, "signaling-state", &state, NULL);
 
        LOG_DEBUG("webrtc[%p] [SignalingState] is changed to [%s]", webrtc, __signaling_state_info[state].str);
-       webrtc->negotiation_states.signaling_state = __signaling_state_info[state].state;
 
        if (state == GST_WEBRTC_SIGNALING_STATE_HAVE_REMOTE_OFFER ||
                state == GST_WEBRTC_SIGNALING_STATE_STABLE)
                __update_data_recovery_type_from_remote_description(webrtc);
 
-       __post_signaling_state_change_cb_in_idle(webrtc, state);
+       __post_signaling_state_change_cb_in_idle(webrtc, __signaling_state_info[state].state);
 }
 
 static void __webrtcbin_ice_gathering_state_cb(GstElement *webrtcbin, GParamSpec * pspec, gpointer user_data)
@@ -1125,9 +1135,8 @@ static void __webrtcbin_ice_gathering_state_cb(GstElement *webrtcbin, GParamSpec
        g_object_get(webrtcbin, "ice-gathering-state", &state, NULL);
 
        LOG_DEBUG("webrtc[%p] [IceGatheringState] is changed to [%s]", webrtc, __ice_gathering_state_info[state].str);
-       webrtc->negotiation_states.ice_gathering_state = __ice_gathering_state_info[state].state;
 
-       __post_ice_gathering_state_change_cb_in_idle(webrtc, state);
+       __post_ice_gathering_state_change_cb_in_idle(webrtc, __ice_gathering_state_info[state].state);
 }
 
 //LCOV_EXCL_START
@@ -1142,9 +1151,8 @@ static void __webrtcbin_ice_connection_state_cb(GstElement *webrtcbin, GParamSpe
        g_object_get(webrtcbin, "ice-connection-state", &state, NULL);
 
        LOG_DEBUG("webrtc[%p] [IceConnectionState] is changed to [%s]", webrtc, __ice_connection_state_info[state].str);
-       webrtc->negotiation_states.ice_connection_state = __ice_connection_state_info[state].state;
 
-       __post_ice_connection_state_change_cb_in_idle(webrtc, state);
+       __post_ice_connection_state_change_cb_in_idle(webrtc, __ice_connection_state_info[state].state);
 
        if (state == GST_WEBRTC_ICE_CONNECTION_STATE_FAILED)
                __invoke_error_cb(webrtc, WEBRTC_ERROR_CONNECTION_FAILED);
index 266405b7429186fa14028519880039e4de9d3aaf..d9a291e13d32a1d40c94fc93e8256342cd43055c 100644 (file)
@@ -2067,7 +2067,7 @@ static void _webrtc_foreach_stats(int index, int selected)
 
 static void __error_cb(webrtc_h webrtc, webrtc_error_e error, webrtc_state_e state, void *user_data)
 {
-       g_print("__error_cb() is invoked, webrtc[%p], error[0x%x], state[%d], user_data[%p]\n",
+       g_print("__error_cb() is invoked, webrtc[%p], error[0x%x], state[%u], user_data[%p]\n",
                webrtc, error, state, user_data);
 }
 
@@ -2225,14 +2225,21 @@ static void __ice_candidate_cb(webrtc_h webrtc, const char *candidate, void *use
 
 static void __peer_connection_state_change_cb(webrtc_h webrtc, webrtc_peer_connection_state_e state, void *user_data)
 {
-       g_print("__peer_connection_state_change_cb() is invoked, state[%d]\n", state);
+       webrtc_peer_connection_state_e _state;
+
+       webrtc_get_peer_connection_state(webrtc, &_state);
+
+       g_print("__peer_connection_state_change_cb() is invoked, state[%u, %u]\n", state, _state);
 }
 
 static void __signaling_state_change_cb(webrtc_h webrtc, webrtc_signaling_state_e state, void *user_data)
 {
        connection_s *conn = (connection_s *)user_data;
+       webrtc_signaling_state_e _state;
 
-       g_print("__signaling_state_change_cb() is invoked, state[%d]\n", state);
+       webrtc_get_signaling_state(webrtc, &_state);
+
+       g_print("__signaling_state_change_cb() is invoked, state[%u, %u]\n", state, _state);
 
        if (conn->is_for_room && state == WEBRTC_SIGNALING_STATE_HAVE_REMOTE_OFFER) {
                _webrtc_create_answer(conn, false);
@@ -2243,12 +2250,20 @@ static void __signaling_state_change_cb(webrtc_h webrtc, webrtc_signaling_state_
 
 static void __ice_gathering_state_change_cb(webrtc_h webrtc, webrtc_ice_gathering_state_e state, void *user_data)
 {
-       g_print("__ice_gathering_state_change_cb() is invoked, state[%d]\n", state);
+       webrtc_ice_gathering_state_e _state;
+
+       webrtc_get_ice_gathering_state(webrtc, &_state);
+
+       g_print("__ice_gathering_state_change_cb() is invoked, state[%u, %u]\n", state, _state);
 }
 
 static void __ice_connection_state_change_cb(webrtc_h webrtc, webrtc_ice_connection_state_e state, void *user_data)
 {
-       g_print("__ice_connection_state_change_cb() is invoked, state[%d]\n", state);
+       webrtc_ice_connection_state_e _state;
+
+       webrtc_get_ice_connection_state(webrtc, &_state);
+
+       g_print("__ice_connection_state_change_cb() is invoked, state[%u, %u]\n", state, _state);
 }
 
 static void _webrtc_set_all_negotiation_state_change_cbs(int index)
@@ -2329,7 +2344,7 @@ static void _webrtc_get_all_negotiation_states(int index)
        if (ret != WEBRTC_ERROR_NONE)
                g_print("failed to webrtc_get_ice_connection_state()\n");
 
-       g_print("peer_conn_state[%d] signaling_state[%d] ice_gathering_state[%d] ice_conn_state[%d]\n",
+       g_print("peer_conn_state[%u] signaling_state[%u] ice_gathering_state[%u] ice_conn_state[%u]\n",
                peer_conn_state, signaling_state, ice_gathering_state, ice_conn_state);
 }