Connect to signals for various states inside of webrtcbin 33/243833/7
authorSangchul Lee <sc11.lee@samsung.com>
Thu, 10 Sep 2020 10:07:45 +0000 (19:07 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Tue, 22 Sep 2020 06:32:22 +0000 (15:32 +0900)
Internal callbacks for state types below are added.
 - peer connection state
 - signaling state
 - ICE gathering state
 - ICE connection state

These are implementation in webrtcbin based on
 - https://w3c.github.io/webrtc-pc/#state-definitions

These will be utilized for dividing current states of this API set
into more steps with further patches.

[Version] 0.1.20
[Issue Type] Improvement

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

index 9f618303296108e33ccf4c68f2a3721da1f3b193..29e450d910b0c49452d9fa21ff0d96754ae8977b 100644 (file)
@@ -1,6 +1,6 @@
 Name:       capi-media-webrtc
 Summary:    A WebRTC library in Tizen Native API
-Version:    0.1.19
+Version:    0.1.20
 Release:    0
 Group:      Multimedia/API
 License:    Apache-2.0
index 2f6a75e587dec3ece12fd62e997c1d8306b67497..6d23d55329672ae5025102ab395583a073d872d7 100644 (file)
@@ -449,7 +449,7 @@ static void __disconnect_signal(gpointer data)
        g_free(sig_data);
 }
 
-static void __webrtcbin_on_negotiation_needed(GstElement *webrtcbin, gpointer user_data)
+static void __webrtcbin_on_negotiation_needed_cb(GstElement *webrtcbin, gpointer user_data)
 {
        webrtc_s *webrtc = (webrtc_s *)user_data;
 
@@ -467,7 +467,7 @@ static void __webrtcbin_on_negotiation_needed(GstElement *webrtcbin, gpointer us
        LOG_DEBUG("<<< end of the callback");
 }
 
-static void __webrtcbin_on_ice_candidate(GstElement *webrtcbin, guint mlineindex, gchar *candidate, gpointer user_data)
+static void __webrtcbin_on_ice_candidate_cb(GstElement *webrtcbin, guint mlineindex, gchar *candidate, gpointer user_data)
 {
        webrtc_s *webrtc = (webrtc_s *)user_data;
        gchar *_candidate;
@@ -492,6 +492,140 @@ static void __webrtcbin_on_ice_candidate(GstElement *webrtcbin, guint mlineindex
        free(_param_candidate);
 }
 
+static void __webrtcbin_peer_connection_state_cb(GstElement *webrtcbin, GParamSpec * pspec, gpointer user_data)
+{
+       webrtc_s *webrtc = (webrtc_s *)user_data;
+       GstWebRTCPeerConnectionState peer_connection_state;
+       const gchar *new_state = "UNKNOWN";
+
+       RET_IF(webrtcbin == NULL, "webrtcbin is NULL");
+       RET_IF(webrtc == NULL, "webrtc is NULL");
+
+       g_object_get(webrtcbin, "connection-state", &peer_connection_state, NULL);
+
+       switch (peer_connection_state) {
+       case GST_WEBRTC_PEER_CONNECTION_STATE_NEW:
+               new_state = "NEW";
+               break;
+       case GST_WEBRTC_PEER_CONNECTION_STATE_CONNECTING:
+               new_state = "CONNECTING";
+               break;
+       case GST_WEBRTC_PEER_CONNECTION_STATE_CONNECTED:
+               new_state = "CONNECTED";
+               break;
+       case GST_WEBRTC_PEER_CONNECTION_STATE_DISCONNECTED:
+               new_state = "DISCONNECTED";
+               break;
+       case GST_WEBRTC_PEER_CONNECTION_STATE_FAILED:
+               new_state = "FAILED";
+               break;
+       case GST_WEBRTC_PEER_CONNECTION_STATE_CLOSED:
+               new_state = "CLOSED";
+               break;
+       }
+
+       LOG_DEBUG("[PeerConnectionState] is changed to [%s]", new_state);
+}
+
+static void __webrtcbin_signaling_state_cb(GstElement *webrtcbin, GParamSpec * pspec, gpointer user_data)
+{
+       webrtc_s *webrtc = (webrtc_s *)user_data;
+       GstWebRTCSignalingState signaling_state;
+       const gchar *new_state = "UNKNOWN";
+
+       RET_IF(webrtcbin == NULL, "webrtcbin is NULL");
+       RET_IF(webrtc == NULL, "webrtc is NULL");
+
+       g_object_get(webrtcbin, "signaling-state", &signaling_state, NULL);
+
+       switch (signaling_state) {
+       case GST_WEBRTC_SIGNALING_STATE_STABLE:
+               new_state = "STABLE";
+               break;
+       case GST_WEBRTC_SIGNALING_STATE_CLOSED:
+               new_state = "CLOSED";
+               break;
+       case GST_WEBRTC_SIGNALING_STATE_HAVE_LOCAL_OFFER:
+               new_state = "HAVE_LOCAL_OFFER";
+               break;
+       case GST_WEBRTC_SIGNALING_STATE_HAVE_REMOTE_OFFER:
+               new_state = "HAVE_REMOTE_OFFER";
+               break;
+       case GST_WEBRTC_SIGNALING_STATE_HAVE_LOCAL_PRANSWER:
+               new_state = "HAVE_LOCAL_PRANSWER";
+               break;
+       case GST_WEBRTC_SIGNALING_STATE_HAVE_REMOTE_PRANSWER:
+               new_state = "HAVE_REMOTE_PRANSWER";
+               break;
+       }
+
+       LOG_DEBUG("[SignalingState] is changed to [%s]", new_state);
+}
+
+static void __webrtcbin_ice_gathering_state_cb(GstElement *webrtcbin, GParamSpec * pspec, gpointer user_data)
+{
+       webrtc_s *webrtc = (webrtc_s *)user_data;
+       GstWebRTCICEGatheringState ice_gathering_state;
+       const gchar *new_state = "UNKNOWN";
+
+       RET_IF(webrtcbin == NULL, "webrtcbin is NULL");
+       RET_IF(webrtc == NULL, "webrtc is NULL");
+
+       g_object_get(webrtcbin, "ice-gathering-state", &ice_gathering_state, NULL);
+
+       switch (ice_gathering_state) {
+       case GST_WEBRTC_ICE_GATHERING_STATE_NEW:
+               new_state = "NEW";
+               break;
+       case GST_WEBRTC_ICE_GATHERING_STATE_GATHERING:
+               new_state = "GATHERING";
+               break;
+       case GST_WEBRTC_ICE_GATHERING_STATE_COMPLETE:
+               new_state = "COMPLETE";
+               break;
+       }
+
+       LOG_DEBUG("[IceGatheringState] is changed to [%s]", new_state);
+}
+
+static void __webrtcbin_ice_connection_state_cb(GstElement *webrtcbin, GParamSpec * pspec, gpointer user_data)
+{
+       webrtc_s *webrtc = (webrtc_s *)user_data;
+       GstWebRTCICEConnectionState ice_connection_state;
+       const gchar *new_state = "UNKNOWN";
+
+       RET_IF(webrtcbin == NULL, "webrtcbin is NULL");
+       RET_IF(webrtc == NULL, "webrtc is NULL");
+
+       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;
+       }
+
+       LOG_DEBUG("[IceConnectionState] is changed to [%s]", new_state);
+}
+
 int _gst_build_pipeline(webrtc_s *webrtc)
 {
        RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL");
@@ -513,8 +647,12 @@ int _gst_build_pipeline(webrtc_s *webrtc)
                LOG_ERROR("failed to create webrtcbin");
                goto error;
        }
-       __connect_and_append_signal(&webrtc->signals, webrtc->gst.webrtcbin, "on-negotiation-needed", G_CALLBACK(__webrtcbin_on_negotiation_needed), webrtc);
-       __connect_and_append_signal(&webrtc->signals, webrtc->gst.webrtcbin, "on-ice-candidate", G_CALLBACK(__webrtcbin_on_ice_candidate), webrtc);
+       __connect_and_append_signal(&webrtc->signals, webrtc->gst.webrtcbin, "on-negotiation-needed", G_CALLBACK(__webrtcbin_on_negotiation_needed_cb), webrtc);
+       __connect_and_append_signal(&webrtc->signals, webrtc->gst.webrtcbin, "on-ice-candidate", G_CALLBACK(__webrtcbin_on_ice_candidate_cb), webrtc);
+       __connect_and_append_signal(&webrtc->signals, webrtc->gst.webrtcbin, "notify::connection-state", G_CALLBACK(__webrtcbin_peer_connection_state_cb), webrtc);
+       __connect_and_append_signal(&webrtc->signals, webrtc->gst.webrtcbin, "notify::signaling-state", G_CALLBACK(__webrtcbin_signaling_state_cb), webrtc);
+       __connect_and_append_signal(&webrtc->signals, webrtc->gst.webrtcbin, "notify::ice-gathering-state", G_CALLBACK(__webrtcbin_ice_gathering_state_cb), webrtc);
+       __connect_and_append_signal(&webrtc->signals, webrtc->gst.webrtcbin, "notify::ice-connection-state", G_CALLBACK(__webrtcbin_ice_connection_state_cb), webrtc);
 
        if (!gst_bin_add(GST_BIN(webrtc->gst.pipeline), webrtc->gst.webrtcbin)) {
                LOG_ERROR("failed to gst_bin_add(), [%s] -> [%s] pipeline", GST_ELEMENT_NAME(webrtc->gst.webrtcbin), GST_ELEMENT_NAME(webrtc->gst.pipeline));