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;
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;
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;
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;
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;
}