celtpay/depay: Negotiate parameters through caps

celtdepay : added default framesize(480) channels(1) and clockrate(32000)
            depay_setcaps : now gets channels and framesize from string with default value
            depay_process : now adds timestamp to outbuf
            Added frame_size to GstRtpCeltDepay
            Changed some GST_DEBUG to GST_DEBUG_OBJECT or GST_LOG_OBJECT
celtpay : getcaps : gets channel and framesize and sets caps
          Added frame-size to static caps for audio/x-celt
This commit is contained in:
Gabriel Millaire 2009-10-02 17:04:43 -04:00 committed by Olivier Crête
parent 1636bb0800
commit ac90398092
3 changed files with 65 additions and 12 deletions

View file

@ -27,6 +27,9 @@
#include "gstrtpceltdepay.h"
GST_DEBUG_CATEGORY_STATIC (rtpceltdepay_debug);
#define GST_CAT_DEFAULT (rtpceltdepay_debug)
/* elementfactory information */
static const GstElementDetails gst_rtp_celtdepay_details =
GST_ELEMENT_DETAILS ("RTP CELT depayloader",
@ -35,6 +38,11 @@ GST_ELEMENT_DETAILS ("RTP CELT depayloader",
"Wim Taymans <wim.taymans@gmail.com>");
/* RtpCELTDepay signals and args */
#define DEFAULT_FRAMESIZE 480
#define DEFAULT_CHANNELS 1
#define DEFAULT_CLOCKRATE 32000
enum
{
/* FILL ME */
@ -82,6 +90,9 @@ gst_rtp_celt_depay_base_init (gpointer klass)
gst_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&gst_rtp_celt_depay_sink_template));
gst_element_class_set_details (element_class, &gst_rtp_celtdepay_details);
GST_DEBUG_CATEGORY_INIT (rtpceltdepay_debug, "rtpceltdepay", 0,
"CELT RTP Depayloader");
}
static void
@ -113,7 +124,7 @@ gst_rtp_celt_depay_setcaps (GstBaseRTPDepayload * depayload, GstCaps * caps)
{
GstStructure *structure;
GstRtpCELTDepay *rtpceltdepay;
gint clock_rate, nb_channels, frame_size;
gint clock_rate, nb_channels = 0, frame_size = 0;
GstBuffer *buf;
guint8 *data;
const gchar *params;
@ -128,17 +139,19 @@ gst_rtp_celt_depay_setcaps (GstBaseRTPDepayload * depayload, GstCaps * caps)
goto no_clockrate;
depayload->clock_rate = clock_rate;
if (!(params = gst_structure_get_string (structure, "encoding-params")))
nb_channels = 1;
else {
if ((params = gst_structure_get_string (structure, "encoding-params")))
nb_channels = atoi (params);
}
if (!nb_channels)
nb_channels = DEFAULT_CHANNELS;
if (!(params = gst_structure_get_string (structure, "frame-size")))
frame_size = 480;
else {
if ((params = gst_structure_get_string (structure, "frame-size")))
frame_size = atoi (params);
}
if (!frame_size)
frame_size = DEFAULT_FRAMESIZE;
rtpceltdepay->frame_size = frame_size;
GST_DEBUG_OBJECT (depayload, "clock-rate=%d channels=%d frame-size=%d",
clock_rate, nb_channels, frame_size);
/* construct minimal header and comment packet for the decoder */
buf = gst_buffer_new_and_alloc (60);
@ -194,12 +207,27 @@ gst_rtp_celt_depay_process (GstBaseRTPDepayload * depayload, GstBuffer * buf)
guint8 *payload;
guint offset, pos, payload_len, total_size, size;
guint8 s;
gint clock_rate = 0, frame_size = 0;
GstClockTime framesize_ns = 0, timestamp;
guint n = 0;
GstRtpCELTDepay *rtpceltdepay;
GST_DEBUG ("process : got %d bytes, mark %d ts %u seqn %d",
rtpceltdepay = GST_RTP_CELT_DEPAY (depayload);
clock_rate = depayload->clock_rate;
frame_size = rtpceltdepay->frame_size;
framesize_ns = gst_util_uint64_scale_int (frame_size, GST_SECOND, clock_rate);
timestamp = GST_BUFFER_TIMESTAMP (buf);
GST_DEBUG_OBJECT (depayload, "process : got %d bytes, mark %d ts %u seqn %d",
GST_BUFFER_SIZE (buf),
gst_rtp_buffer_get_marker (buf),
gst_rtp_buffer_get_timestamp (buf), gst_rtp_buffer_get_seq (buf));
GST_LOG_OBJECT (depayload, "got clock-rate=%d, frame_size=%d, "
"_ns=%" GST_TIME_FORMAT ", timestamp=%" GST_TIME_FORMAT, clock_rate,
frame_size, GST_TIME_ARGS (framesize_ns), GST_TIME_ARGS (timestamp));
payload = gst_rtp_buffer_get_payload (buf);
payload_len = gst_rtp_buffer_get_payload_len (buf);
@ -218,6 +246,7 @@ gst_rtp_celt_depay_process (GstBaseRTPDepayload * depayload, GstBuffer * buf)
total_size = 0;
pos = 0;
while (total_size < payload_len) {
n++;
size = 0;
do {
s = payload[pos++];
@ -228,6 +257,15 @@ gst_rtp_celt_depay_process (GstBaseRTPDepayload * depayload, GstBuffer * buf)
outbuf = gst_rtp_buffer_get_payload_subbuffer (buf, offset, size);
offset += size;
if (frame_size != -1 && clock_rate != -1) {
GST_BUFFER_TIMESTAMP (outbuf) = timestamp + framesize_ns * n;
GST_BUFFER_DURATION (outbuf) = framesize_ns;
}
GST_LOG_OBJECT (depayload, "push timestamp=%"
GST_TIME_FORMAT ", duration=%" GST_TIME_FORMAT,
GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (outbuf)),
GST_TIME_ARGS (GST_BUFFER_DURATION (outbuf)));
gst_base_rtp_depayload_push (depayload, outbuf);
}
return NULL;

View file

@ -37,6 +37,7 @@ typedef struct _GstRtpCELTDepayClass GstRtpCELTDepayClass;
struct _GstRtpCELTDepay
{
GstBaseRTPDepayload depayload;
gint frame_size;
};
struct _GstRtpCELTDepayClass

View file

@ -42,7 +42,8 @@ GST_STATIC_PAD_TEMPLATE ("sink",
GST_PAD_SINK,
GST_PAD_ALWAYS,
GST_STATIC_CAPS ("audio/x-celt, "
"rate = (int) [ 32000, 64000 ], " "channels = (int) [1, 2]")
"rate = (int) [ 32000, 64000 ], "
"channels = (int) [1, 2], " "frame-size = (int) [ 64, 512 ]")
);
static GstStaticPadTemplate gst_rtp_celt_pay_src_template =
@ -160,6 +161,7 @@ gst_rtp_celt_pay_getcaps (GstBaseRTPPayload * payload, GstPad * pad)
{
GstCaps *otherpadcaps;
GstCaps *caps;
const gchar *params;
otherpadcaps = gst_pad_get_allowed_caps (payload->srcpad);
caps = gst_caps_copy (gst_pad_get_pad_template_caps (pad));
@ -168,11 +170,23 @@ gst_rtp_celt_pay_getcaps (GstBaseRTPPayload * payload, GstPad * pad)
if (!gst_caps_is_empty (otherpadcaps)) {
GstStructure *ps = gst_caps_get_structure (otherpadcaps, 0);
GstStructure *s = gst_caps_get_structure (caps, 0);
gint clock_rate;
gint clock_rate = 0, frame_size = 0, channels = 1;
if (gst_structure_get_int (ps, "clock-rate", &clock_rate)) {
gst_structure_fixate_field_nearest_int (s, "rate", clock_rate);
}
if ((params = gst_structure_get_string (ps, "frame-size")))
frame_size = atoi (params);
if (frame_size)
gst_structure_set (s, "frame-size", G_TYPE_INT, frame_size, NULL);
if ((params = gst_structure_get_string (ps, "encoding-params")))
channels = atoi (params);
gst_structure_fixate_field_nearest_int (s, "channels", channels);
GST_DEBUG_OBJECT (payload, "clock-rate=%d frame-size=%d channels=%d",
clock_rate, frame_size, channels);
}
gst_caps_unref (otherpadcaps);
}