From: Sangchul Lee Date: Wed, 4 May 2022 02:37:58 +0000 (+0900) Subject: webrtc_private: Fix negotiation state bugs X-Git-Tag: submit/tizen_6.5/20220504.090209^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=691eebe2e19d973bad9b689073f32d88c657e1b2;p=platform%2Fcore%2Fapi%2Fwebrtc.git webrtc_private: Fix negotiation state bugs 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.2.167 [Issue Type] Bug fix Change-Id: If91bae0f87397d7b9d7350bdf24f93c34a4e3e7c Signed-off-by: Sangchul Lee --- diff --git a/packaging/capi-media-webrtc.spec b/packaging/capi-media-webrtc.spec index 7289268b..8d9d7aec 100644 --- a/packaging/capi-media-webrtc.spec +++ b/packaging/capi-media-webrtc.spec @@ -1,6 +1,6 @@ Name: capi-media-webrtc Summary: A WebRTC library in Tizen Native API -Version: 0.2.166 +Version: 0.2.167 Release: 0 Group: Multimedia/API License: Apache-2.0 diff --git a/src/webrtc_private.c b/src/webrtc_private.c index 98554ffd..5351add0 100644 --- a/src/webrtc_private.c +++ b/src/webrtc_private.c @@ -248,7 +248,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; @@ -256,17 +256,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; @@ -274,16 +274,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; @@ -291,17 +291,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; @@ -309,11 +309,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"); } } @@ -458,33 +458,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; @@ -920,9 +932,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: @@ -953,9 +964,8 @@ 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; - __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) @@ -969,9 +979,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 @@ -986,9 +995,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); diff --git a/test/webrtc_test.c b/test/webrtc_test.c index 95239dea..4dd03fa7 100644 --- a/test/webrtc_test.c +++ b/test/webrtc_test.c @@ -1883,14 +1883,21 @@ static void _webrtc_unset_ice_candidate_cb(int index) 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); @@ -1901,12 +1908,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) @@ -1991,7 +2006,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); }