Commit 540bb7bd authored by Evangelos Ribeiro Tzaras's avatar Evangelos Ribeiro Tzaras
Browse files

use separate pipelines for each direction

parent c955775b
......@@ -3,10 +3,12 @@
#include <gst/gst.h>
typedef struct {
GstElement *pipeline;
GstElement *send_pipeline;
GstElement *recv_pipeline;
GstElement *audiosrc;
GstElement *audiosink;
GstElement *rtpbin;
GstElement *send_rtpbin;
GstElement *recv_rtpbin;
GstElement *encoder;
GstElement *decoder;
GstElement *payloader;
......@@ -77,7 +79,8 @@ main (int argc, char **argv)
data.audiosink = gst_element_factory_make ("pulsesink", "sink");
data.audiosrc = gst_element_factory_make ("pulsesrc", "source");
/* maybe we need to also explicitly add audioconvert and audioresample elements */
data.rtpbin = gst_element_factory_make ("rtpbin", "rtpbin");
data.send_rtpbin = gst_element_factory_make ("rtpbin", "send-rtpbin");
data.recv_rtpbin = gst_element_factory_make ("rtpbin", "recv-rtpbin");
/* L16 codecs would need special handling, maybe simply drop it */
data.decoder = gst_element_factory_make (codec->gst_decoder_name, "decoder");
data.depayloader = gst_element_factory_make (codec->gst_depayloader_name, "depayloader");
......@@ -90,9 +93,11 @@ main (int argc, char **argv)
data.rtcp_send_sink = gst_element_factory_make ("udpsink", "rtcp-udp-send-sink");
data.rtcp_send_src = gst_element_factory_make ("udpsrc", "rtcp-udp-send-src");
data.pipeline = gst_pipeline_new ("rtp-combined-pipeline");
data.send_pipeline = gst_pipeline_new ("rtp-send-pipeline");
data.recv_pipeline = gst_pipeline_new ("rtp-recv-pipeline");
if (!data.pipeline || !data.audiosink || !data.audiosrc || !data.rtpbin ||
if (!data.send_pipeline || !data.recv_pipeline ||
!data.audiosink || !data.audiosrc || !data.send_rtpbin || !data.recv_rtpbin ||
!data.decoder || !data.encoder || !data.depayloader || !data.payloader ||
!data.rtp_src || !data.rtcp_recv_src || !data.rtcp_recv_sink ||
!data.rtp_sink || !data.rtcp_send_src || !data.rtcp_send_sink) {
......@@ -100,9 +105,9 @@ main (int argc, char **argv)
return -1;
}
gst_bin_add_many (GST_BIN (data.pipeline), data.depayloader, data.decoder,
gst_bin_add_many (GST_BIN (data.recv_pipeline), data.depayloader, data.decoder,
data.audiosink, NULL);
gst_bin_add_many (GST_BIN (data.pipeline), data.payloader, data.encoder,
gst_bin_add_many (GST_BIN (data.send_pipeline), data.payloader, data.encoder,
data.audiosrc, NULL);
if (!gst_element_link_many (data.depayloader, data.decoder, data.audiosink, NULL))
g_error ("Failed to link depayloader decoder and audiosink");
......@@ -110,7 +115,8 @@ main (int argc, char **argv)
if (!gst_element_link_many (data.audiosrc, data.encoder, data.payloader, NULL))
g_error ("Failed to link audiosrc encoder and payloader");
gst_bin_add (GST_BIN (data.pipeline), data.rtpbin);
gst_bin_add (GST_BIN (data.send_pipeline), data.send_rtpbin);
gst_bin_add (GST_BIN (data.recv_pipeline), data.recv_rtpbin);
caps = gst_caps_from_string (CAPS);
/* set udp sinks and sources for RTP and RTCP */
......@@ -148,37 +154,41 @@ main (int argc, char **argv)
"sync", FALSE,
NULL);
gst_bin_add_many (GST_BIN (data.pipeline), data.rtp_src, data.rtp_sink,
data.rtcp_recv_src, data.rtcp_recv_sink,
gst_bin_add_many (GST_BIN (data.send_pipeline), data.rtp_sink,
data.rtcp_send_src, data.rtcp_send_sink, NULL);
gst_bin_add_many (GST_BIN (data.recv_pipeline), data.rtp_src,
data.rtcp_recv_src, data.rtcp_recv_sink, NULL);
/* in/receive direction */
/* request and link the pads */
srcpad = gst_element_get_static_pad (data.rtp_src, "src");
sinkpad = gst_element_get_request_pad (data.rtpbin, "recv_rtp_sink_0");
sinkpad = gst_element_get_request_pad (data.recv_rtpbin, "recv_rtp_sink_0");
if (gst_pad_link (srcpad, sinkpad) != GST_PAD_LINK_OK)
g_error ("Failed to link rtpsrc to rtpbin");
gst_object_unref (srcpad);
gst_object_unref (sinkpad);
srcpad = gst_element_get_static_pad (data.rtcp_recv_src, "src");
sinkpad = gst_element_get_request_pad (data.rtpbin, "recv_rtcp_sink_0");
sinkpad = gst_element_get_request_pad (data.recv_rtpbin, "recv_rtcp_sink_0");
if (gst_pad_link (srcpad, sinkpad) != GST_PAD_LINK_OK)
g_error ("Failed to link rtcpsrc to rtpbin");
gst_object_unref (srcpad);
gst_object_unref (sinkpad);
srcpad = gst_element_get_request_pad (data.rtpbin, "send_rtcp_src_0");
srcpad = gst_element_get_request_pad (data.recv_rtpbin, "send_rtcp_src_0");
sinkpad = gst_element_get_static_pad (data.rtcp_recv_sink, "sink");
if (gst_pad_link (srcpad, sinkpad) != GST_PAD_LINK_OK)
g_error ("Failed to link rtpbin to rtcpsink");
gst_object_unref (srcpad);
gst_object_unref (sinkpad);
/* need to link RTP pad to the depayloader */
g_signal_connect (data.recv_rtpbin, "pad-added", G_CALLBACK (pad_added_cb), data.depayloader);
/* out/send direction */
/* link payloader src to RTP sink pad */
sinkpad = gst_element_get_request_pad (data.rtpbin, "send_rtp_sink_1");
sinkpad = gst_element_get_request_pad (data.send_rtpbin, "send_rtp_sink_0");
srcpad = gst_element_get_static_pad (data.payloader, "src");
if (gst_pad_link (srcpad, sinkpad) != GST_PAD_LINK_OK)
g_error ("Failed to link payloader to rtpbin");
......@@ -186,7 +196,7 @@ main (int argc, char **argv)
gst_object_unref (sinkpad);
/* link RTP srcpad to udpsink */
srcpad = gst_element_get_static_pad (data.rtpbin, "send_rtp_src_1");
srcpad = gst_element_get_static_pad (data.send_rtpbin, "send_rtp_src_0");
sinkpad = gst_element_get_static_pad (data.rtp_sink, "sink");
if (gst_pad_link (srcpad, sinkpad) != GST_PAD_LINK_OK)
g_error ("Failed to link rtpbin to rtpsink");
......@@ -194,7 +204,7 @@ main (int argc, char **argv)
gst_object_unref (sinkpad);
/* RTCP srcpad to udpsink */
srcpad = gst_element_get_request_pad (data.rtpbin, "send_rtcp_src_1");
srcpad = gst_element_get_request_pad (data.send_rtpbin, "send_rtcp_src_0");
sinkpad = gst_element_get_static_pad (data.rtcp_send_sink, "sink");
if (gst_pad_link (srcpad, sinkpad) != GST_PAD_LINK_OK)
g_error ("Failed to link rtpbin to rtcpsink");
......@@ -203,26 +213,30 @@ main (int argc, char **argv)
/* receive RTCP */
srcpad = gst_element_get_static_pad (data.rtcp_send_src, "src");
sinkpad = gst_element_get_request_pad (data.rtpbin, "recv_rtcp_sink_1");
sinkpad = gst_element_get_request_pad (data.send_rtpbin, "recv_rtcp_sink_0");
if (gst_pad_link (srcpad, sinkpad) != GST_PAD_LINK_OK)
g_error ("Failed to link rtcpsrc to rtpbin");
gst_object_unref (srcpad);
gst_object_unref (sinkpad);
/* need to link RTP pad to the depayloader */
g_signal_connect (data.rtpbin, "pad-added", G_CALLBACK (pad_added_cb), data.depayloader);
/* start the pipeline */
/* start the pipelines */
g_print ("Starting sender pipeline\n");
gst_element_set_state (data.pipeline, GST_STATE_PLAYING);
gst_element_set_state (data.send_pipeline, GST_STATE_PLAYING);
g_print ("Starting receiver pipeline\n");
gst_element_set_state (data.recv_pipeline, GST_STATE_PLAYING);
loop = g_main_loop_new (NULL, FALSE);
g_main_loop_run (loop);
g_print ("Stopping sender pipeline\n");
gst_element_set_state (data.pipeline, GST_STATE_NULL);
gst_element_set_state (data.send_pipeline, GST_STATE_NULL);
g_print ("Stopping receiver pipeline\n");
gst_element_set_state (data.recv_pipeline, GST_STATE_NULL);
gst_object_unref (data.pipeline);
gst_object_unref (data.send_pipeline);
gst_object_unref (data.recv_pipeline);
return 0;
}
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