Change the completion position of MEDIA_STREAMER_STATE_READY for WebRTC 09/236409/7
authorHyunil <hyunil46.park@samsung.com>
Wed, 17 Jun 2020 01:57:31 +0000 (10:57 +0900)
committerHyunil <hyunil46.park@samsung.com>
Thu, 25 Jun 2020 06:11:59 +0000 (15:11 +0900)
- 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 <hyunil46.park@samsung.com>
include/media_streamer_gst_webrtc.h
packaging/capi-media-streamer.spec
src/media_streamer_gst.c
src/media_streamer_gst_webrtc.c
src/media_streamer_node.c

index dbaf3a9b0939571c38e06a4fd3f41b5ef8c075a3..fa21aff81aef70dfedcb50b881587ce53ae78a9d 100644 (file)
@@ -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);
index 8d8745748f391e5182d4efa6a2e35b8f2ac05093..50eca83d753ce8c009a0a31f273a6ec937a4526b 100644 (file)
@@ -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
index 60ee23f0c0c00d69bc437e2d8e5a21506850547d..b3a85f9050fe51644f2e86b2c1e350f55e26c7b6 100644 (file)
@@ -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;
index 4e071d7025f7df57728d5d04a2e73d48663b7f6c..1c1b784e010d9b236863c5a0ec4f69cdca1d2aeb 100644 (file)
@@ -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;
index 2e04ba84257218a511557b8462d3ba42d572db3f..a86227378c825a05721406a1b5fc13f6aa09aa51 100644 (file)
@@ -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;
        }