gboolean kms_webrtc_session_set_remote_ice_candidate (KmsWebrtcSession * self, KmsIceCandidate * candidate) { KmsSdpSession *sdp_sess = KMS_SDP_SESSION (self); SdpMessageContext *local_sdp_ctx = sdp_sess->local_sdp_ctx; guint8 index; GSList *medias; SdpMediaConfig *mconf; gboolean ret; if (local_sdp_ctx == NULL) { GST_INFO_OBJECT (self, "Cannot add candidate until local SDP is generated."); return TRUE; /* We do not know if the candidate is valid until it is set */ } medias = kms_sdp_message_context_get_medias (local_sdp_ctx); index = kms_ice_candidate_get_sdp_m_line_index (candidate); mconf = g_slist_nth_data (medias, index); if (mconf == NULL) { GST_WARNING_OBJECT (self, "Media not found in local SDP for index %" G_GUINT16_FORMAT, index); return FALSE; } else if (kms_sdp_media_config_is_inactive (mconf)) { GST_DEBUG_OBJECT (self, "Media inactive for index %" G_GUINT16_FORMAT, index); return TRUE; } else { gchar *stream_id; stream_id = kms_webrtc_session_get_stream_id (self, mconf); if (stream_id == NULL) { return FALSE; } if (!kms_ice_base_agent_add_ice_candidate (self->agent, candidate, stream_id)) { GST_WARNING_OBJECT (self, "Cannot add candidate: '%s'in stream_id: %s.", kms_ice_candidate_get_candidate (candidate), stream_id); ret = FALSE; } else { GST_TRACE_OBJECT (self, "Candidate added: '%s' in stream_id: %s.", kms_ice_candidate_get_candidate (candidate), stream_id); ret = TRUE; } } return ret; }
static gboolean kms_ice_nice_agent_add_ice_candidate (KmsIceBaseAgent * self, KmsIceCandidate * candidate, const char *stream_id) { KmsIceNiceAgent *nice_agent = KMS_ICE_NICE_AGENT (self); NiceCandidate *nice_cand; guint id = atoi (stream_id); gboolean ret; GSList *candidates; const gchar *cand_str; GST_DEBUG_OBJECT (self, "Add ICE candidate '%s'", kms_ice_candidate_get_candidate (candidate)); ret = kms_ice_candidate_create_nice (candidate, &nice_cand); if (nice_cand == NULL) { return ret; } nice_cand->stream_id = id; cand_str = kms_ice_candidate_get_candidate (candidate); candidates = g_slist_append (NULL, nice_cand); if (nice_agent_set_remote_candidates (nice_agent->priv->agent, nice_cand->stream_id, nice_cand->component_id, candidates) < 0) { GST_WARNING_OBJECT (self, "Cannot add candidate: '%s'in stream_id: %d.", cand_str, nice_cand->stream_id); ret = FALSE; } else { GST_TRACE_OBJECT (self, "Candidate added: '%s' in stream_id: %d.", cand_str, nice_cand->stream_id); ret = TRUE; } g_slist_free (candidates); nice_candidate_free (nice_cand); return ret; }
void WebRtcEndpointImpl::onIceCandidate (KmsIceCandidate *candidate) { try { std::string cand_str (kms_ice_candidate_get_candidate (candidate) ); std::string mid_str (kms_ice_candidate_get_sdp_mid (candidate) ); int sdp_m_line_index = kms_ice_candidate_get_sdp_m_line_index (candidate); std::shared_ptr <IceCandidate> cand ( new IceCandidate (cand_str, mid_str, sdp_m_line_index) ); OnIceCandidate event (shared_from_this(), OnIceCandidate::getName(), cand); signalOnIceCandidate (event); } catch (std::bad_weak_ptr &e) { } }
static gboolean kms_webrtc_session_add_ice_candidate (KmsWebrtcSession * self, KmsIceCandidate * candidate) { guint8 index; gboolean ret; GST_DEBUG_OBJECT (self, "Add ICE candidate '%s'", kms_ice_candidate_get_candidate (candidate)); KMS_SDP_SESSION_LOCK (self); self->remote_candidates = g_slist_append (self->remote_candidates, g_object_ref (candidate)); ret = kms_webrtc_session_set_remote_ice_candidate (self, candidate); index = kms_ice_candidate_get_sdp_m_line_index (candidate); kms_webrtc_session_remote_sdp_add_ice_candidate (self, candidate, index); KMS_SDP_SESSION_UNLOCK (self); return ret; }
static gchar * kms_ice_nice_agent_generate_local_candidate_sdp (KmsIceBaseAgent * self, KmsIceCandidate * candidate) { KmsIceNiceAgent *nice_agent = KMS_ICE_NICE_AGENT (self); NiceCandidate *nice_cand; gchar *ret; GST_DEBUG_OBJECT (self, "Add ICE candidate '%s'", kms_ice_candidate_get_candidate (candidate)); kms_ice_candidate_create_nice (candidate, &nice_cand); if (nice_cand == NULL) { return NULL; } ret = nice_agent_generate_local_candidate_sdp (nice_agent->priv->agent, nice_cand); nice_candidate_free (nice_cand); return ret; }