trying combined sender+receiver

parent 9ee04999
sender
receiver
combined
......@@ -5,7 +5,7 @@ GST_CFLAGS = $(shell $(PKGCONFIG) --cflags gstreamer-1.0)
GST_LDFLAGS = $(shell $(PKGCONFIG) --libs gstreamer-1.0)
all: sender receiver
all: sender receiver combined
sender:
$(CC) $(CC_FLAGS) \
......@@ -17,7 +17,13 @@ receiver:
receiver.c gst-rfc3551.c -o $@ \
$(GST_CFLAGS) $(GST_LDFLAGS)
combined:
$(CC) $(CC_FLAGS) \
combined.c gst-rfc3551.c -o $@ \
$(GST_CFLAGS) $(GST_LDFLAGS)
clean:
rm -f sender
rm -f receiver
rm -f combined
#include "gst-rfc3551.h"
#include <gst/gst.h>
typedef struct {
GstElement *pipeline;
GstElement *audiosrc;
GstElement *audiosink;
GstElement *rtpbin;
GstElement *encoder;
GstElement *decoder;
GstElement *payloader;
GstElement *depayloader;
GstElement *rtp_src;
GstElement *rtp_sink;
GstElement *rtcp_send_sink;
GstElement *rtcp_send_src;
GstElement *rtcp_recv_sink;
GstElement *rtcp_recv_src;
} RtpData;
#define REMOTE "127.0.0.1"
#define CODEC "G722"
/* receiver */
#define RTP_PORT_SRC 5002
#define RTCP_PORT_SEND_SRC 5003
#define RTCP_PORT_SEND_SINK 5007
/* sender */
#define RTP_PORT_SINK 5002
#define RTCP_PORT_RECV_SINK 5003
#define RTCP_PORT_RECV_SRC 5007
// get this from gst-rfc3551.h
#define CAPS "application/x-rtp,media=(string)audio,clock-rate=(int)8000,encoding-name=(string)G722,payload=(int)9"
static GMainLoop *loop;
/* rtpbin adds a pad once the payload is verified */
static void
pad_added_cb (GstElement *rtpbin, GstPad *srcpad, GstElement *depayloader)
{
GstPad *sinkpad;
g_debug ("%s", GST_PAD_NAME (srcpad));
sinkpad = gst_element_get_static_pad (depayloader, "sink");
if (gst_pad_link (srcpad, sinkpad) != GST_PAD_LINK_OK)
g_error ("Failed to link rtpbin to depayloader");
gst_object_unref (sinkpad);
}
int
main (int argc, char **argv)
{
RtpData data;
GstBus *bus;
GstCodec *codec = NULL;
GstPad *srcpad, *sinkpad;
GstCaps *caps;
const gchar *codec_name = g_getenv ("CODEC");
const gchar *remote = g_getenv ("REMOTE");
if (!remote)
remote = REMOTE;
if (codec_name)
codec = gst_codec_by_name (codec_name);
if (codec == NULL)
codec = gst_codec_by_name (CODEC);
gst_init (&argc, &argv);
/* could also use autoaudiosink instead of pulsesink */
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");
/* 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");
data.encoder = gst_element_factory_make (codec->gst_encoder_name, "encoder");
data.payloader = gst_element_factory_make (codec->gst_payloader_name, "payloader");
data.rtp_src = gst_element_factory_make ("udpsrc", "rtp-udp-src");
data.rtp_sink = gst_element_factory_make ("udpsink", "rtp-udp-sink");
data.rtcp_recv_sink = gst_element_factory_make ("udpsink", "rtcp-udp-recv-sink");
data.rtcp_recv_src = gst_element_factory_make ("udpsrc", "rtcp-udp-recv-src");
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");
if (!data.pipeline || !data.audiosink || !data.audiosrc || !data.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) {
g_error ("Could not create all elements!");
return -1;
}
gst_bin_add_many (GST_BIN (data.pipeline), data.depayloader, data.decoder,
data.audiosink, NULL);
gst_bin_add_many (GST_BIN (data.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");
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);
caps = gst_caps_from_string (CAPS);
/* set udp sinks and sources for RTP and RTCP */
/* receive/in direction */
g_object_set (data.rtp_src,
"port", RTP_PORT_SRC,
"caps", caps,
NULL);
g_object_set (data.rtcp_recv_sink,
"port", RTCP_PORT_RECV_SINK,
"host", REMOTE,
"async", FALSE,
"sync", FALSE,
NULL);
g_object_set (data.rtcp_recv_src,
"port", RTCP_PORT_RECV_SRC,
NULL);
/* send/out direction */
g_object_set (data.rtp_sink,
"port", RTP_PORT_SINK,
"host", REMOTE,
NULL);
g_object_set (data.rtcp_send_src,
"port", RTCP_PORT_SEND_SRC,
NULL);
g_object_set (data.rtcp_send_sink,
"port", RTCP_PORT_SEND_SINK,
"host", REMOTE,
"async", FALSE,
"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,
data.rtcp_send_src, data.rtcp_send_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");
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");
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");
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);
/* out/send direction */
/* link payloader src to RTP sink pad */
sinkpad = gst_element_get_request_pad (data.rtpbin, "send_rtp_sink_1");
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");
gst_object_unref (srcpad);
gst_object_unref (sinkpad);
/* link RTP srcpad to udpsink */
srcpad = gst_element_get_static_pad (data.rtpbin, "send_rtp_src_1");
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");
gst_object_unref (srcpad);
gst_object_unref (sinkpad);
/* RTCP srcpad to udpsink */
srcpad = gst_element_get_request_pad (data.rtpbin, "send_rtcp_src_1");
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");
gst_object_unref (srcpad);
gst_object_unref (sinkpad);
/* 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");
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 */
g_print ("Starting sender pipeline\n");
gst_element_set_state (data.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_object_unref (data.pipeline);
return 0;
}
......@@ -44,7 +44,7 @@ main (int argc, char **argv)
{
RtpData data;
GstBus *bus;
GstCodec *codec;
GstCodec *codec = NULL;
GstPad *srcpad, *sinkpad;
GstCaps *caps;
/* XXX would need glib-mkenum to get value from string */
......
......@@ -42,7 +42,7 @@ int
main (int argc, char**argv) {
RtpData data;
GstBus *bus;
GstCodec *codec;
GstCodec *codec = NULL;
GstPad *srcpad, *sinkpad;
/* XXX would need glib-mkenum to get value from string */
const gchar *codec_name = g_getenv ("CODEC");
......@@ -107,8 +107,8 @@ main (int argc, char**argv) {
data.rtcp_src, NULL);
/* request and link the pads, start getting a RTP sinkpad */
sinkpad = gst_element_get_request_pad (data.rtpbin, "send_rtp_sink_0");
srcpad = gst_element_get_static_pad (data.payloader, "src");
sinkpad = gst_element_get_request_pad (data.rtpbin, "send_rtp_sink_0");
if (gst_pad_link (srcpad, sinkpad) != GST_PAD_LINK_OK)
g_error ("Failed to link payloader to rtpbin");
gst_object_unref (srcpad);
......
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