#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",
"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 */
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
{
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;
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);
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;
+
+ 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);
- GST_DEBUG ("process : got %d bytes, mark %d ts %u seqn %d",
+ 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);
total_size = 0;
pos = 0;
while (total_size < payload_len) {
+ n++;
size = 0;
do {
s = payload[pos++];
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;
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 =
{
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));
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);
}