trying to implement receiver

parent e1054fe6
......@@ -5,13 +5,19 @@ GST_CFLAGS = $(shell $(PKGCONFIG) --cflags gstreamer-1.0)
GST_LDFLAGS = $(shell $(PKGCONFIG) --libs gstreamer-1.0)
all: sender
all: sender receiver
sender:
$(CC) $(CC_FLAGS) \
sender.c -o $@ \
$(GST_CFLAGS) $(GST_LDFLAGS)
receiver:
$(CC) $(CC_FLAGS) \
receiver.c -o $@ \
$(GST_CFLAGS) $(GST_LDFLAGS)
clean:
rm -f sender
rm -f receiver
#include "gst-rfc3551.h"
#include <gst/gst.h>
typedef struct {
GstElement *pipeline;
GstElement *sink;
GstElement *rtpbin;
GstElement *decoder;
GstElement *depayloader;
GstElement *rtp_src;
GstElement *rtcp_sink;
GstElement *rtcp_src;
} RtpData;
#define REMOTE "127.0.0.1"
#define CODEC G722
#define RTP_PORT_SRC 5002
#define RTCP_PORT_SRC 5003
#define RTCP_PORT_SINK 5007
// get this from gst-rfc3551.h
#define CAPS "application/x-rtp,media=(string)audio,clock-rate=(int)8000,encoding-name=(string)G722"
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;
sinkpad = gst_element_get_static_pad (depayloader, "src");
if (!gst_pad_link (srcpad, sinkpad))
g_error ("Failed to link rtpbin to depayloader");
gst_object_unref (srcpad);
gst_object_unref (sinkpad);
}
int
main (int argc, char **argv)
{
RtpData data;
GstBus *bus;
AudioEncoding *enc;
GstPad *srcpad, *sinkpad;
GstCaps *caps;
/* XXX would need glib-mkenum to get value from string */
const gchar *codec = g_getenv ("CODEC");
const gchar *remote = g_getenv ("REMOTE");
if (!remote)
remote = REMOTE;
enc = &encodings[CODEC];
gst_init (&argc, &argv);
/* could also use autoaudiosink instead of pulsesink */
data.sink = gst_element_factory_make ("pulsesink", "sink");
/* 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 (enc->gst_decoder_name, "decoder");
data.depayloader = gst_element_factory_make (enc->gst_depayloader_name, "depayloader");
data.rtp_src = gst_element_factory_make ("udpsrc", "rtp-udp-src");
data.rtcp_sink = gst_element_factory_make ("udpsink", "rtcp-udp-sink");
data.rtcp_src = gst_element_factory_make ("udpsrc", "rtcp-udp-src");
data.pipeline = gst_pipeline_new ("rtp-recv-pipeline");
if (!data.pipeline || !data.sink || !data.rtpbin ||
!data.decoder || !data.depayloader || !data.rtp_src ||
!data.rtcp_sink || !data.rtcp_src) {
g_error ("Could not create all elements");
return -1;
}
gst_bin_add_many (GST_BIN (data.pipeline), data.depayloader, data.decoder,
data.sink, NULL);
if (!gst_element_link_many (data.depayloader, data.decoder, data.sink, NULL))
g_error ("Failed to link depayloader decoder and audiosink");
gst_bin_add (GST_BIN (data.pipeline), data.rtpbin);
caps = gst_caps_from_string (CAPS);
/* set udp sinks and sources for RTP and RTCP */
g_object_set (data.rtp_src, "port", RTP_PORT_SRC,
"caps", caps, NULL);
g_object_set (data.rtcp_sink, "port", RTCP_PORT_SINK,
"host", REMOTE, NULL);
g_object_set (data.rtcp_src, "port", RTCP_PORT_SRC, NULL);
g_object_set (data.rtcp_sink, "async", FALSE, "sync", FALSE, NULL);
gst_bin_add_many (GST_BIN (data.pipeline), data.rtp_src, data.rtcp_src,
data.rtcp_sink, NULL);
/* 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_src, "src");
sinkpad = gst_element_get_static_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_static_pad (data.rtpbin, "recv_rtcp_src_0");
sinkpad = gst_element_get_static_pad (data.rtcp_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 payloader */
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");
gst_element_set_state (data.pipeline, GST_STATE_NULL);
gst_object_unref (data.pipeline);
return 0;
}
#include "rfc3551.h"
#include "gst-rfc3551.h"
#include <gst/gst.h>
......@@ -42,7 +42,6 @@ int
main (int argc, char**argv) {
RtpData data;
GstBus *bus;
GstStateChangeReturn ret;
AudioEncoding *enc;
GstPad *srcpad, *sinkpad;
/* XXX would need glib-mkenum to get value from string */
......
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