Commit ccf2d11e authored by Olivier Crête's avatar Olivier Crête

Remove unneeded SDP munging

Instead use the add-transceiver API and only connect to the rest of the bin
when the connection is established.
parent 72da45d5
...@@ -48,35 +48,39 @@ get_webrtcbin_for_client (GstBin *pipeline, MssClientId client_id) ...@@ -48,35 +48,39 @@ get_webrtcbin_for_client (GstBin *pipeline, MssClientId client_id)
return webrtcbin; return webrtcbin;
} }
static void
connect_webrtc_to_tee (GstElement *webrtcbin)
{
GstElement *pipeline;
GstElement *tee;
GstPad *srcpad;
GstPad *sinkpad;
GstPadLinkReturn ret;
pipeline = GST_ELEMENT (gst_element_get_parent (webrtcbin));
if (pipeline == NULL)
return;
tee = gst_bin_get_by_name (GST_BIN (pipeline), "webrtctee");
srcpad = gst_element_get_request_pad (tee, "src_%u");
sinkpad = gst_element_get_request_pad (webrtcbin, "sink_0");
ret = gst_pad_link (srcpad, sinkpad);
g_assert (ret == GST_PAD_LINK_OK);
gst_object_unref (srcpad);
gst_object_unref (sinkpad);
gst_object_unref (tee);
gst_object_unref (pipeline);
}
static void static void
on_offer_created (GstPromise *promise, GstElement *webrtcbin) on_offer_created (GstPromise *promise, GstElement *webrtcbin)
{ {
GstWebRTCSessionDescription *offer = NULL; GstWebRTCSessionDescription *offer = NULL;
gchar *sdp; gchar *sdp;
GstSDPMedia *media;
guint i;
gst_structure_get (gst_promise_get_reply (promise), gst_structure_get (gst_promise_get_reply (promise),
"offer", GST_TYPE_WEBRTC_SESSION_DESCRIPTION, &offer, NULL); "offer", GST_TYPE_WEBRTC_SESSION_DESCRIPTION, &offer, NULL);
gst_promise_unref (promise); gst_promise_unref (promise);
media = (GstSDPMedia *) gst_sdp_message_get_media (offer->sdp, 0);
for (i = 0; i < gst_sdp_media_attributes_len (media); i++) {
const GstSDPAttribute *a = gst_sdp_media_get_attribute (media, i);
if (!strcmp (a->key, "sendrecv")) {
GstSDPAttribute newa;
newa.key = g_strdup ("sendonly");
newa.value = g_strdup ("");
gst_sdp_media_replace_attribute (media, i, &newa);
break;
}
}
gst_sdp_media_add_attribute (media, "fmtp",
"96 packetization-mode=1;profile-level-id=42e01f");
g_signal_emit_by_name (webrtcbin, "set-local-description", offer, NULL); g_signal_emit_by_name (webrtcbin, "set-local-description", offer, NULL);
sdp = gst_sdp_message_as_text (offer->sdp); sdp = gst_sdp_message_as_text (offer->sdp);
...@@ -86,6 +90,8 @@ on_offer_created (GstPromise *promise, GstElement *webrtcbin) ...@@ -86,6 +90,8 @@ on_offer_created (GstPromise *promise, GstElement *webrtcbin)
g_free (sdp); g_free (sdp);
gst_webrtc_session_description_free (offer); gst_webrtc_session_description_free (offer);
connect_webrtc_to_tee (webrtcbin);
} }
static void static void
...@@ -102,10 +108,8 @@ webrtc_client_connected_cb (MssHttpServer *server, MssClientId client_id, ...@@ -102,10 +108,8 @@ webrtc_client_connected_cb (MssHttpServer *server, MssClientId client_id,
GstBin *pipeline) GstBin *pipeline)
{ {
gchar *name; gchar *name;
GstElement *tee;
GstElement *webrtcbin; GstElement *webrtcbin;
GstPad *srcpad; GstCaps *caps;
GstPad *sinkpad;
name = g_strdup_printf ("webrtcbin_%p", client_id); name = g_strdup_printf ("webrtcbin_%p", client_id);
...@@ -117,13 +121,12 @@ webrtc_client_connected_cb (MssHttpServer *server, MssClientId client_id, ...@@ -117,13 +121,12 @@ webrtc_client_connected_cb (MssHttpServer *server, MssClientId client_id,
g_signal_connect (webrtcbin, "on-ice-candidate", g_signal_connect (webrtcbin, "on-ice-candidate",
G_CALLBACK (webrtc_on_ice_candidate_cb), NULL); G_CALLBACK (webrtc_on_ice_candidate_cb), NULL);
tee = gst_bin_get_by_name (pipeline, "webrtctee"); caps = gst_caps_from_string ("application/x-rtp, payload=96,encoding-name=H264,clock-rate=90000,media=video,packetization-mode=(string)1,profile-level-id=(string)42e01f");
srcpad = gst_element_get_request_pad (tee, "src_%u"); g_signal_emit_by_name (webrtcbin, "add-transceiver",
sinkpad = gst_element_get_request_pad (webrtcbin, "sink_%u"); GST_WEBRTC_RTP_TRANSCEIVER_DIRECTION_SENDONLY,
gst_pad_link (srcpad, sinkpad); caps);
gst_object_unref (srcpad);
gst_object_unref (sinkpad); gst_caps_unref (caps);
gst_object_unref (tee);
g_signal_emit_by_name (webrtcbin, "create-offer", NULL, g_signal_emit_by_name (webrtcbin, "create-offer", NULL,
...@@ -141,17 +144,8 @@ webrtc_sdp_answer_cb (MssHttpServer *server, MssClientId client_id, ...@@ -141,17 +144,8 @@ webrtc_sdp_answer_cb (MssHttpServer *server, MssClientId client_id,
{ {
GstSDPMessage *sdp_msg = NULL; GstSDPMessage *sdp_msg = NULL;
GstWebRTCSessionDescription *desc = NULL; GstWebRTCSessionDescription *desc = NULL;
gchar *sdp_tmp;
char **split;
// TODO needed?
split = g_strsplit(sdp, "a=recvonly", -1);
sdp_tmp = g_strjoinv("a=sendrecv", split);
g_strfreev(split);
g_debug ("ANSWER: %s", sdp_tmp);
if (gst_sdp_message_new_from_text (sdp_tmp, &sdp_msg) != GST_SDP_OK) { if (gst_sdp_message_new_from_text (sdp, &sdp_msg) != GST_SDP_OK) {
g_debug ("Error parsing SDP description"); g_debug ("Error parsing SDP description");
goto out; goto out;
} }
...@@ -179,7 +173,6 @@ webrtc_sdp_answer_cb (MssHttpServer *server, MssClientId client_id, ...@@ -179,7 +173,6 @@ webrtc_sdp_answer_cb (MssHttpServer *server, MssClientId client_id,
} }
out: out:
g_free (sdp_tmp);
g_clear_pointer (&desc, gst_webrtc_session_description_free); g_clear_pointer (&desc, gst_webrtc_session_description_free);
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment