Commit 3bb40b63 authored by Evangelos Ribeiro Tzaras's avatar Evangelos Ribeiro Tzaras
Browse files

selectable codec

parent 2503a6ce
......@@ -9,12 +9,12 @@ all: sender receiver
sender:
$(CC) $(CC_FLAGS) \
sender.c -o $@ \
sender.c gst-rfc3551.c -o $@ \
$(GST_CFLAGS) $(GST_LDFLAGS)
receiver:
$(CC) $(CC_FLAGS) \
receiver.c -o $@ \
receiver.c gst-rfc3551.c -o $@ \
$(GST_CFLAGS) $(GST_LDFLAGS)
......
#include "gst-rfc3551.h"
#include <glib.h>
GstCodec gst_codecs[] = {
{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
};
GstCodec *
gst_codec_by_name (const gchar *name)
{
for (guint i = 0; i < G_N_ELEMENTS (gst_codecs); i++) {
/* This will break for L16 with 1 channel */
if (g_strcmp0 (name, gst_codecs[i].name) == 0)
return &gst_codecs[i];
}
return NULL;
}
......@@ -16,7 +16,7 @@ typedef struct {
gchar *gst_depayloader_name;
gchar *gst_encoder_name;
gchar *gst_decoder_name;
} AudioEncoding;
} GstCodec;
/* Only include codecs for which gstreamer
has both encoder and decoder
......@@ -32,12 +32,4 @@ enum {
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
};
GstCodec* gst_codec_by_name (const gchar *name);
......@@ -14,7 +14,7 @@ typedef struct {
} RtpData;
#define REMOTE "127.0.0.1"
#define CODEC G722
#define CODEC "G722"
#define RTP_PORT_SRC 5002
#define RTCP_PORT_SRC 5003
#define RTCP_PORT_SINK 5007
......@@ -44,17 +44,21 @@ main (int argc, char **argv)
{
RtpData data;
GstBus *bus;
AudioEncoding *enc;
GstCodec *codec;
GstPad *srcpad, *sinkpad;
GstCaps *caps;
/* XXX would need glib-mkenum to get value from string */
const gchar *codec = g_getenv ("CODEC");
const gchar *codec_name = g_getenv ("CODEC");
const gchar *remote = g_getenv ("REMOTE");
if (!remote)
remote = REMOTE;
enc = &encodings[CODEC];
if (codec_name)
codec = gst_codec_by_name (codec_name);
if (codec == NULL)
codec = gst_codec_by_name (CODEC);
gst_init (&argc, &argv);
......@@ -63,8 +67,8 @@ main (int argc, char **argv)
/* 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.decoder = gst_element_factory_make (codec->gst_decoder_name, "decoder");
data.depayloader = gst_element_factory_make (codec->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");
......
......@@ -31,7 +31,7 @@ typedef struct {
} RtpData;
#define REMOTE "127.0.0.1"
#define CODEC G722
#define CODEC "G722"
#define RTP_PORT_SINK 5002
#define RTCP_PORT_SINK 5003
#define RTCP_PORT_SRC 5007
......@@ -42,16 +42,20 @@ int
main (int argc, char**argv) {
RtpData data;
GstBus *bus;
AudioEncoding *enc;
GstCodec *codec;
GstPad *srcpad, *sinkpad;
/* XXX would need glib-mkenum to get value from string */
const gchar *codec = g_getenv ("CODEC");
const gchar *codec_name = g_getenv ("CODEC");
const gchar *remote = g_getenv ("REMOTE");
if (!remote)
remote = REMOTE;
enc = &encodings[CODEC];
if (codec_name)
codec = gst_codec_by_name (codec_name);
if (codec == NULL)
codec = gst_codec_by_name (CODEC);
gst_init (&argc, &argv);
......@@ -60,8 +64,8 @@ main (int argc, char**argv) {
/* 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.encoder = gst_element_factory_make (enc->gst_encoder_name, "encoder");
data.payloader = gst_element_factory_make (enc->gst_payloader_name, "payloader");
data.encoder = gst_element_factory_make (codec->gst_encoder_name, "encoder");
data.payloader = gst_element_factory_make (codec->gst_payloader_name, "payloader");
data.rtp_sink = gst_element_factory_make ("udpsink", "rtp-udp-sink");
data.rtcp_sink = gst_element_factory_make ("udpsink", "rtcp-udp-sink");
data.rtcp_src = gst_element_factory_make ("udpsrc", "rtcp-udp-src");
......
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