some initial work on sender pipeline

parents
#pragma once
#include <glib.h>
/*
* For more information
* see: https://tools.ietf.org/html/rfc3551#section-6
*/
typedef struct {
gint payload_type;
gchar* name;
gint clock_rate;
gint channels;
gchar *gst_payloader_name;
gchar *gst_depayloader_name;
gchar *gst_encoder_name;
gchar *gst_decoder_name;
} AudioEncoding;
/* Only include codecs for which gstreamer
has both encoder and decoder
*/
enum {
PCMU,
GSM,
G723,
PCMA,
G722,
L16_2C,
L16_1C,
};
AudioEncoding encodings[] = {
{0, "PCMU", 8000, 1, "rtppcmupay", "rtppcmudepay", "mulawenc", "mulawdec"},
{3, "GSM", 8000, 1, "rtpgsmpay", "rtpgsmdepay", "gsmenc", "gsmdec"},
{4, "G723", 8000, 1, "rtpg723pay", "rtpg723depay", "avenc_g723_1", "avdec_g723_1"},
{8, "PCMA", 8000, 1, "rtppcmapay", "rtppcmadepay", "alawenc", "alawdec"},
{9, "G722", 8000, 1, "rtpg722pay", "rtpg722depay", "avenc_g722", "avdec_g722"},
{10, "L16", 44100, 2, "rtpL16pay", "rtpL16depay", "null", "null"}, // raw stream
{11, "L16", 44100, 1, "rtpL16pay", "rtpL16depay", "null", "null"}, // raw stream
};
#include "rfc3551.h"
#include <gst/gst.h>
/* We want to implement a pipeline like:
gst-launch-1.0 rtpbin name=rtpbin \
pulsesrc ! amrnbenc ! rtpamrpay ! rtpbin.send_rtp_sink_0 \
rtpbin.send_rtp_src_0 ! udpsink host=${REMOTE} port=5002\
rtpbin.send_rtcp_src_0 ! udpsink host=${REMOTE} port=5003 sync=false async=false \
udpsrc port=5007 ! rtpbin.recv_rtcp_sink_0
*/
typedef struct {
GstElement *pipeline;
GstElement *source;
GstElement *rtpbin;
GstElement *encoder;
GstElement *payloader;
GstElement *rtp_udp_sink;
GstElement *rtcp_udp_sink;
GstElement *rtcp_udp_src;
} RtpData;
#define REMOTE "127.0.0.1"
#define CODEC G722
#define RTP_PORT_SINK 5002
#define RTCP_PORT_SINK 5003
#define RTCP_PORT_SRC 5007
static GMainLoop *loop;
int
main (int argc, char**argv) {
RtpData data;
GstBus *bus;
GstStateChangeReturn ret;
AudioEncoding *enc;
/* XXX would need glib-mkenum to get value from string */
const gchar *codec = g_getenv ("CODEC");
const gchar *remote = g_getenv ("REMOTE");
enc = encodings[CODEC];
gst_init (argc, argv);
/* could also use autoaudiosrc in place of pulsesrc*/
data.source = gst_element_factory_make ("pulsesrc", "source");
data.rtpbin = gst_element_factory_make ("rtpbin", "rtpbin");
/* L16 codecs would need special handling, maybe simply drop it */
data.encoder = gst_element_factory_make (enc.gst_encoder_name, "encoder");
data.payloader = gst_element_factory_make (enc.gst_payloader_name, "payloader");
data.rtp_udp_sink = gst_element_factory_make ("udpsink", "rtp-udp-sink");
data.rtcp_udp_sink = gst_element_factory_make ("udpsink", "rtcp-udp-sink");
data.rtcp_udp_src = gst_element_factory_make ("udpsrc", "rtcp-udp-src");
data.pipeline = gst_pipeline_new ("rtp-send-pipeline");
if (!data.pipeline || !data.source || !data.rtpbin ||
!data.encoder || !data.payloader || !data.rtp_udp_sink ||
!data.rtcp_udp_sink || !data.rtcp_udp_src) {
g_error ("Could not create all elements");
return -1;
}
/* set udpsrc/udpsink ports */
g_object_set (data.rtp_sink, "port", RTP_PORT_SINK, NULL);
g_object_set (data.rtcp_sink, "port", RTCP_PORT_SINK, NULL);
g_object_set (data.rtcp_src, "port", RTCP_PORT_SRC, NULL);
loop = g_main_loop_new (NULL, FALSE);
}
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