From 6b47e5421f8c246656e3d61c63455b81196b6a70 Mon Sep 17 00:00:00 2001 From: Sangchul Lee Date: Thu, 10 Sep 2020 19:07:45 +0900 Subject: [PATCH] Connect to signals for various states inside of webrtcbin 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 --- packaging/capi-media-webrtc.spec | 2 +- src/webrtc_private.c | 146 ++++++++++++++++++++++++++++++- 2 files changed, 143 insertions(+), 5 deletions(-) diff --git a/packaging/capi-media-webrtc.spec b/packaging/capi-media-webrtc.spec index 9f618303..29e450d9 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.1.19 +Version: 0.1.20 Release: 0 Group: Multimedia/API License: Apache-2.0 diff --git a/src/webrtc_private.c b/src/webrtc_private.c index 2f6a75e5..6d23d553 100644 --- a/src/webrtc_private.c +++ b/src/webrtc_private.c @@ -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)); -- 2.34.1