From: Hyunil Date: Wed, 17 Jun 2020 01:57:31 +0000 (+0900) Subject: Change the completion position of MEDIA_STREAMER_STATE_READY for WebRTC X-Git-Tag: submit/tizen/20200714.065000~18 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F09%2F236409%2F7;p=platform%2Fcore%2Fapi%2Fmediastreamer.git Change the completion position of MEDIA_STREAMER_STATE_READY for WebRTC - Only, in case of WebRTC, MEDIA_STREAMER_STATE_READY is set after connecting ICE connection - Add ice-connection-state callback function [Version] 0.1.74 [Issue Type] Improve Change-Id: I76205f2ccd749ee0b0a54f17e58153e3b0a1bd5f Signed-off-by: Hyunil --- diff --git a/include/media_streamer_gst_webrtc.h b/include/media_streamer_gst_webrtc.h index dbaf3a9..fa21aff 100644 --- a/include/media_streamer_gst_webrtc.h +++ b/include/media_streamer_gst_webrtc.h @@ -38,6 +38,8 @@ void ms_webrtcbin_on_ice_candidate_cb(GstElement *webrtcbin, guint mlineindex, g void ms_webrtcbin_on_negotiation_needed_cb(GstElement *webrtcbin, gpointer user_data); +void ms_webrtcbin_notify_ice_connection_state_cb(GstElement *webrtcbin, GParamSpec * pspec, gpointer user_data); + void ms_webrtcbin_on_negotiation_process_answer(GstElement *webrtcbin, media_streamer_node_s *webrtc_node); int ms_webrtcbin_set_remote_session_description(media_streamer_node_s *webrtc_node, const char *sdp_msg); diff --git a/packaging/capi-media-streamer.spec b/packaging/capi-media-streamer.spec index 8d87457..50eca83 100644 --- a/packaging/capi-media-streamer.spec +++ b/packaging/capi-media-streamer.spec @@ -1,6 +1,6 @@ Name: capi-media-streamer Summary: A Media Streamer API -Version: 0.1.73 +Version: 0.1.74 Release: 0 Group: Multimedia/API License: Apache-2.0 diff --git a/src/media_streamer_gst.c b/src/media_streamer_gst.c index 60ee23f..b3a85f9 100644 --- a/src/media_streamer_gst.c +++ b/src/media_streamer_gst.c @@ -1970,6 +1970,24 @@ gboolean ms_element_unlock_state(const GValue *item, GValue *ret, gpointer user_ return TRUE; } +static gboolean __ms_skip_set_state(media_streamer_s *ms_streamer) +{ + media_streamer_node_s *webrtc = NULL; + + ms_retvm_if(ms_streamer == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "ms_streamer is NULL"); + ms_retvm_if(ms_streamer->nodes_table == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "nodes_table is NULL"); + + ms_debug_fenter(); + + webrtc = (media_streamer_node_s *)g_hash_table_lookup(ms_streamer->nodes_table, "webrtc_container"); + if (webrtc && ms_streamer->pend_state == MEDIA_STREAMER_STATE_READY) { + ms_debug_fleave(); + return TRUE; + } + + return FALSE; +} + static gboolean __ms_bus_cb(GstBus *bus, GstMessage *message, gpointer userdata) { int ret = MEDIA_STREAMER_ERROR_NONE; @@ -2015,6 +2033,10 @@ static gboolean __ms_bus_cb(GstBus *bus, GstMessage *message, gpointer userdata) ms_streamer->pend_state = MEDIA_STREAMER_STATE_PAUSED; if (ms_streamer->pend_state != ms_streamer->state) { + if(__ms_skip_set_state(ms_streamer)){ + ms_info("Skip set state, state is set after connecting ICE connection."); + break; + } g_mutex_lock(&ms_streamer->mutex_lock); ms_streamer->state = ms_streamer->pend_state; diff --git a/src/media_streamer_gst_webrtc.c b/src/media_streamer_gst_webrtc.c index 4e071d7..1c1b784 100644 --- a/src/media_streamer_gst_webrtc.c +++ b/src/media_streamer_gst_webrtc.c @@ -82,6 +82,22 @@ end: return ret; } +static void __ms_webrtcbin_update_ms_state(media_streamer_s *ms_streamer) +{ + GstState old_state; + + ms_retm_if(ms_streamer == NULL, "ms_streamer is NULL"); + + old_state = ms_streamer->state; + ms_streamer->state = ms_streamer->pend_state; + + ms_info("Media streamer state changed to [%d] [%d]", old_state, ms_streamer->state); + if (ms_streamer->state_changed_cb.callback) { + media_streamer_state_changed_cb cb = (media_streamer_state_changed_cb) ms_streamer->state_changed_cb.callback; + cb((media_streamer_h) ms_streamer, old_state, ms_streamer->state, ms_streamer->state_changed_cb.user_data); + } +} + static gchar *__make_ice_candidate_message(guint mlineindex, gchar *candidate) { JsonObject *ice, *msg; @@ -403,6 +419,52 @@ void ms_webrtcbin_on_ice_candidate_cb(GstElement *webrtcbin, guint mlineindex, g g_free(ice_candidate_msg); } +void ms_webrtcbin_notify_ice_connection_state_cb(GstElement *webrtcbin, GParamSpec * pspec, gpointer user_data) +{ + GstWebRTCICEConnectionState ice_connection_state; + const gchar *new_state = "UNKNOWN"; + media_streamer_node_s *webrtc_node = (media_streamer_node_s *)user_data; + media_streamer_s *ms_streamer = NULL; + + ms_retm_if(webrtc_node == NULL, "webrtc_node is NULL"); + ms_retm_if(webrtc_node->parent_streamer == NULL, "ms_streamer is NULL"); + + ms_streamer = webrtc_node->parent_streamer; + + g_object_get(webrtcbin, "ice-connection-state", &ice_connection_state, NULL); + + switch (ice_connection_state) { + case GST_WEBRTC_ICE_CONNECTION_STATE_NEW: + new_state = "NEW"; + break; + case GST_WEBRTC_ICE_CONNECTION_STATE_CHECKING: + new_state = "CHECKING"; + break; + case GST_WEBRTC_ICE_CONNECTION_STATE_CONNECTED: + new_state = "CONNECTED"; + break; + case GST_WEBRTC_ICE_CONNECTION_STATE_COMPLETED: + new_state = "COMPLETED"; + break; + case GST_WEBRTC_ICE_CONNECTION_STATE_FAILED: + new_state = "FAILED"; + break; + case GST_WEBRTC_ICE_CONNECTION_STATE_DISCONNECTED: + new_state = "DISCONNECTED"; + break; + case GST_WEBRTC_ICE_CONNECTION_STATE_CLOSED: + new_state = "CLOSED"; + break; + } + + ms_info("ICE connection state changed to [%s]", new_state); + + if (ice_connection_state == GST_WEBRTC_ICE_CONNECTION_STATE_CONNECTED && + ms_streamer->pend_state == MEDIA_STREAMER_STATE_READY) + __ms_webrtcbin_update_ms_state(ms_streamer); +} + + void ms_webrtcbin_notify_ice_gathering_state_cb(GstElement *webrtcbin, GParamSpec * pspec, gpointer user_data) { GstWebRTCICEGatheringState ice_gather_state; diff --git a/src/media_streamer_node.c b/src/media_streamer_node.c index 2e04ba8..a862273 100644 --- a/src/media_streamer_node.c +++ b/src/media_streamer_node.c @@ -1645,9 +1645,10 @@ int ms_webrtc_node_prepare(media_streamer_s *ms_streamer, media_streamer_node_s ms_signal_create(&node->sig_list, webrtcbin, "on-ice-candidate", G_CALLBACK(ms_webrtcbin_on_ice_candidate_cb), node); ms_signal_create(&node->sig_list, webrtcbin, "notify::ice-gathering-state", G_CALLBACK(ms_webrtcbin_notify_ice_gathering_state_cb), NULL); + ms_signal_create(&node->sig_list, webrtcbin, "notify::ice-connection-state", G_CALLBACK(ms_webrtcbin_notify_ice_connection_state_cb), node); if (ms_element_set_state(webrtcbin, GST_STATE_READY)) { - ms_error("Faild to set state to READY"); + ms_error("Failed to set state to READY"); return MEDIA_STREAMER_ERROR_INVALID_OPERATION; }