std::string SdpEndpointImpl::processAnswer (const std::string &answer) { GstSDPMessage *answerSdp; std::string resultStr; bool expected = true; bool expected_false = false; if (!waitingAnswer.compare_exchange_strong (expected, true) ) { //offer not generated throw KurentoException (SDP_END_POINT_NOT_OFFER_GENERATED, "Offer not generated. It is not possible to process an answer."); } if (!answerProcessed.compare_exchange_strong (expected_false, true) ) { //the endpoint is already negotiated throw KurentoException (SDP_END_POINT_ANSWER_ALREADY_PROCCESED, "Sdp Answer already processed"); } answerSdp = str_to_sdp (answer); g_signal_emit_by_name (element, "process-answer", answerSdp, NULL); gst_sdp_message_free (answerSdp); MediaSessionStarted event (shared_from_this(), MediaSessionStarted::getName() ); signalMediaSessionStarted (event); return getLocalSessionDescriptor (); }
std::string SdpEndpointImpl::processOffer (const std::string &offer) { GstSDPMessage *offerSdp = NULL, *result = NULL; std::string offerSdpStr; bool expected = false; if (!offerInProcess.compare_exchange_strong (expected, true) ) { //the endpoint is already negotiated throw KurentoException (SDP_END_POINT_ALREADY_NEGOTIATED, "Endpoint already negotiated"); } offerSdp = str_to_sdp (offer); g_signal_emit_by_name (element, "process-offer", offerSdp, &result); gst_sdp_message_free (offerSdp); if (result == NULL) { offerInProcess = false; throw KurentoException (SDP_END_POINT_PROCESS_OFFER_ERROR, "Error processing offer"); } sdp_to_str (offerSdpStr, result); gst_sdp_message_free (result); MediaSessionStarted event (shared_from_this(), MediaSessionStarted::getName() ); signalMediaSessionStarted (event); return offerSdpStr; }
std::string SdpEndpointImpl::processAnswer (const std::string &answer) { GstSDPMessage *answerSdp; std::string resultStr; answerSdp = str_to_sdp (answer); g_signal_emit_by_name (element, "process-answer", answerSdp, NULL); gst_sdp_message_free (answerSdp); MediaSessionStarted event (shared_from_this(), MediaSessionStarted::getName() ); signalMediaSessionStarted (event); return getLocalSessionDescriptor (); }
std::string SdpEndpointImpl::processOffer (const std::string &offer) { GstSDPMessage *offerSdp = NULL, *result = NULL; std::string offerSdpStr; offerSdp = str_to_sdp (offer); g_signal_emit_by_name (element, "process-offer", offerSdp, &result); gst_sdp_message_free (offerSdp); if (result == NULL) { throw KurentoException (SDP_END_POINT_PROCESS_OFFER_ERROR, "Error processing offer"); } sdp_to_str (offerSdpStr, result); gst_sdp_message_free (result); MediaSessionStarted event (shared_from_this(), MediaSessionStarted::getName() ); signalMediaSessionStarted (event); return offerSdpStr; }
HttpEndpointImpl::HttpEndpointImpl (const boost::property_tree::ptree &conf, std::shared_ptr< MediaObjectImpl > parent, int disconnectionTimeout, const std::string &factoryName) : SessionEndpointImpl (conf, parent, factoryName) { this->disconnectionTimeout = disconnectionTimeout; actionRequestedLambda = [&] (const gchar * uri, KmsHttpEndPointAction action) { std::string uriStr = uri; GST_DEBUG ("Action requested URI %s", uriStr.c_str() ); if (url.size() <= uriStr.size() ) { return; } /* Remove the initial "http://host:port" to compare the uri */ std::string substr = url.substr (url.size() - uriStr.size(), std::string::npos); if (substr.compare (uriStr) != 0) { return; } /* Send event */ if (!g_atomic_int_compare_and_exchange (& (sessionStarted), 0, 1) ) { return; } if (action == KMS_HTTP_END_POINT_ACTION_UNDEFINED) { std::string errorMessage = "Invalid or unexpected request received"; try { Error error (shared_from_this(), "Invalid Uri", 0, "INVALID_URI"); GST_ERROR ("%s", errorMessage.c_str() ); signalError (error); } catch (std::bad_weak_ptr &e) { } } else { try { MediaSessionStarted event (shared_from_this(), MediaSessionStarted::getName() ); signalMediaSessionStarted (event); } catch (std::bad_weak_ptr &e) { } } }; sessionTerminatedLambda = [&] (const gchar * uri) { std::string uriStr = uri; if (url.size() <= uriStr.size() ) { return; } /* Remove the initial "http://host:port" to compare the uri */ std::string substr = url.substr (url.size() - uriStr.size(), std::string::npos); if (substr.compare (uriStr) != 0) { return; } GST_DEBUG ("Session terminated URI %s", uriStr.c_str() ); if (actionRequestedHandlerId > 0) { server->disconnectSignal ( actionRequestedHandlerId); actionRequestedHandlerId = 0; } if (urlExpiredHandlerId > 0) { server->disconnectSignal ( urlExpiredHandlerId); urlExpiredHandlerId = 0; } if (urlRemovedHandlerId > 0) { server->disconnectSignal ( urlRemovedHandlerId); urlRemovedHandlerId = 0; } unregister_end_point (); if (!g_atomic_int_compare_and_exchange (& (sessionStarted), 1, 0) ) { return; } try { MediaSessionTerminated event (shared_from_this(), MediaSessionTerminated::getName() ); signalMediaSessionTerminated (event); } catch (std::bad_weak_ptr &e) { } }; server = HttpEndPointServer::getHttpEndPointServer ( getConfigValue<int, HttpEndpoint> (HTTP_SERVICE_PORT, HttpEndPointServer::DEFAULT_PORT), getConfigValue<std::string, HttpEndpoint> (HTTP_SERVICE_ADDRESS, ""), getConfigValue<std::string, HttpEndpoint> (HTTP_SERVICE_ANNOUNCED_ADDRESS, "") ); if (server == NULL) { throw KurentoException (HTTP_END_POINT_REGISTRATION_ERROR , "HttpServer is not created"); } }