Fix to set timestamp on buffer, it was tested with RTP G711 elements.

Original commit message from CVS:
Fix to set timestamp on buffer, it was tested with RTP G711 elements.
This commit is contained in:
Flavio Oliveira 2005-10-27 18:46:32 +00:00
parent e7a14b7a00
commit 3a08bb8732
5 changed files with 74 additions and 20 deletions

View file

@ -1,3 +1,14 @@
2005-10-27 Edgard Lima Edgard Lima <edgard.lima@indt.org.br>
* gst/law/alaw-encode.c: (gst_alawenc_init),
(alawenc_setcaps), (gst_alawenc_chain)
* gst/law/alaw-encode.h:
* gst/law/mulaw-encode.c: (gst_mulawenc_init),
(mulawenc_setcaps), (gst_mulawenc_chain)
* gst/law/mulaw-encode.h:
Set timestamp on buffer and it allows RTP G711 elements
work properly.
2005-10-27 Wim Taymans <wim@fluendo.com> 2005-10-27 Wim Taymans <wim@fluendo.com>
* sys/oss/gstosssrc.c: (gst_oss_src_prepare): * sys/oss/gstosssrc.c: (gst_oss_src_prepare):

View file

@ -171,16 +171,13 @@ alawenc_setcaps (GstPad * pad, GstCaps * caps)
GstALawEnc *alawenc; GstALawEnc *alawenc;
GstPad *otherpad; GstPad *otherpad;
GstStructure *structure; GstStructure *structure;
const GValue *rate, *chans;
GstCaps *base_caps; GstCaps *base_caps;
alawenc = GST_ALAWENC (GST_PAD_PARENT (pad)); alawenc = GST_ALAWENC (GST_PAD_PARENT (pad));
structure = gst_caps_get_structure (caps, 0); structure = gst_caps_get_structure (caps, 0);
rate = gst_structure_get_value (structure, "rate"); gst_structure_get_int (structure, "channels", &alawenc->channels);
chans = gst_structure_get_value (structure, "channels"); gst_structure_get_int (structure, "rate", &alawenc->rate);
if (!rate || !chans)
return FALSE;
if (pad == alawenc->sinkpad) { if (pad == alawenc->sinkpad) {
otherpad = alawenc->srcpad; otherpad = alawenc->srcpad;
@ -190,8 +187,9 @@ alawenc_setcaps (GstPad * pad, GstCaps * caps)
base_caps = gst_caps_copy (gst_pad_get_pad_template_caps (otherpad)); base_caps = gst_caps_copy (gst_pad_get_pad_template_caps (otherpad));
structure = gst_caps_get_structure (base_caps, 0); structure = gst_caps_get_structure (base_caps, 0);
gst_structure_set_value (structure, "rate", rate); gst_structure_set (structure, "rate", G_TYPE_INT, alawenc->rate, NULL);
gst_structure_set_value (structure, "channels", chans); gst_structure_set (structure, "channels", G_TYPE_INT, alawenc->channels,
NULL);
gst_pad_set_caps (otherpad, base_caps); gst_pad_set_caps (otherpad, base_caps);
@ -260,6 +258,11 @@ gst_alawenc_init (GstALawEnc * alawenc)
gst_pad_set_setcaps_function (alawenc->srcpad, alawenc_setcaps); gst_pad_set_setcaps_function (alawenc->srcpad, alawenc_setcaps);
gst_pad_set_getcaps_function (alawenc->srcpad, alawenc_getcaps); gst_pad_set_getcaps_function (alawenc->srcpad, alawenc_getcaps);
gst_element_add_pad (GST_ELEMENT (alawenc), alawenc->srcpad); gst_element_add_pad (GST_ELEMENT (alawenc), alawenc->srcpad);
/* init rest */
alawenc->channels = 0;
alawenc->rate = 0;
alawenc->ts = 0;
} }
static GstFlowReturn static GstFlowReturn
@ -269,14 +272,23 @@ gst_alawenc_chain (GstPad * pad, GstBuffer * buffer)
gint16 *linear_data; gint16 *linear_data;
guint8 *alaw_data; guint8 *alaw_data;
GstBuffer *outbuf; GstBuffer *outbuf;
gint bufsize;
gint i; gint i;
alawenc = GST_ALAWENC (GST_OBJECT_PARENT (pad)); alawenc = GST_ALAWENC (GST_OBJECT_PARENT (pad));
if (!alawenc->rate || !alawenc->channels)
goto not_negotiated;
linear_data = (gint16 *) GST_BUFFER_DATA (buffer); linear_data = (gint16 *) GST_BUFFER_DATA (buffer);
outbuf = gst_buffer_new_and_alloc (GST_BUFFER_SIZE (buffer) / 2); bufsize = GST_BUFFER_SIZE (buffer) / 2;
GST_BUFFER_TIMESTAMP (outbuf) = GST_BUFFER_TIMESTAMP (buffer); outbuf = gst_buffer_new_and_alloc (bufsize);
GST_BUFFER_DURATION (outbuf) = GST_BUFFER_DURATION (buffer);
GST_BUFFER_DURATION (outbuf) = GST_SECOND * (bufsize) /
(alawenc->rate * alawenc->channels);
GST_BUFFER_TIMESTAMP (outbuf) = alawenc->ts;
alawenc->ts += GST_BUFFER_DURATION (outbuf);
gst_buffer_set_caps (outbuf, GST_PAD_CAPS (alawenc->srcpad)); gst_buffer_set_caps (outbuf, GST_PAD_CAPS (alawenc->srcpad));
alaw_data = (guint8 *) GST_BUFFER_DATA (outbuf); alaw_data = (guint8 *) GST_BUFFER_DATA (outbuf);
@ -289,4 +301,9 @@ gst_alawenc_chain (GstPad * pad, GstBuffer * buffer)
gst_buffer_unref (buffer); gst_buffer_unref (buffer);
return gst_pad_push (alawenc->srcpad, outbuf); return gst_pad_push (alawenc->srcpad, outbuf);
not_negotiated:
{
return GST_FLOW_NOT_NEGOTIATED;
}
} }

View file

@ -49,6 +49,10 @@ struct _GstALawEnc {
GstElement element; GstElement element;
GstPad *sinkpad,*srcpad; GstPad *sinkpad,*srcpad;
guint64 ts;
gint channels;
gint rate;
/*MetaAudioRaw meta; */ /*MetaAudioRaw meta; */

View file

@ -104,16 +104,13 @@ mulawenc_setcaps (GstPad * pad, GstCaps * caps)
GstMuLawEnc *mulawenc; GstMuLawEnc *mulawenc;
GstPad *otherpad; GstPad *otherpad;
GstStructure *structure; GstStructure *structure;
const GValue *rate, *chans;
GstCaps *base_caps; GstCaps *base_caps;
mulawenc = GST_MULAWENC (gst_pad_get_parent (pad)); mulawenc = GST_MULAWENC (gst_pad_get_parent (pad));
structure = gst_caps_get_structure (caps, 0); structure = gst_caps_get_structure (caps, 0);
rate = gst_structure_get_value (structure, "rate"); gst_structure_get_int (structure, "channels", &mulawenc->channels);
chans = gst_structure_get_value (structure, "channels"); gst_structure_get_int (structure, "rate", &mulawenc->rate);
if (!rate || !chans)
return FALSE;
if (pad == mulawenc->sinkpad) { if (pad == mulawenc->sinkpad) {
otherpad = mulawenc->srcpad; otherpad = mulawenc->srcpad;
@ -123,10 +120,12 @@ mulawenc_setcaps (GstPad * pad, GstCaps * caps)
base_caps = gst_caps_copy (gst_pad_get_pad_template_caps (otherpad)); base_caps = gst_caps_copy (gst_pad_get_pad_template_caps (otherpad));
structure = gst_caps_get_structure (base_caps, 0); structure = gst_caps_get_structure (base_caps, 0);
gst_structure_set_value (structure, "rate", rate); gst_structure_set (structure, "rate", G_TYPE_INT, mulawenc->rate, NULL);
gst_structure_set_value (structure, "channels", chans); gst_structure_set (structure, "channels", G_TYPE_INT, mulawenc->channels,
NULL);
gst_pad_set_caps (otherpad, base_caps); gst_pad_set_caps (otherpad, base_caps);
gst_caps_unref (base_caps); gst_caps_unref (base_caps);
return TRUE; return TRUE;
@ -193,6 +192,11 @@ gst_mulawenc_init (GstMuLawEnc * mulawenc)
gst_pad_set_setcaps_function (mulawenc->srcpad, mulawenc_setcaps); gst_pad_set_setcaps_function (mulawenc->srcpad, mulawenc_setcaps);
gst_pad_set_getcaps_function (mulawenc->srcpad, mulawenc_getcaps); gst_pad_set_getcaps_function (mulawenc->srcpad, mulawenc_getcaps);
gst_element_add_pad (GST_ELEMENT (mulawenc), mulawenc->srcpad); gst_element_add_pad (GST_ELEMENT (mulawenc), mulawenc->srcpad);
/* init rest */
mulawenc->channels = 0;
mulawenc->rate = 0;
mulawenc->ts = 0;
} }
static GstFlowReturn static GstFlowReturn
@ -202,13 +206,22 @@ gst_mulawenc_chain (GstPad * pad, GstBuffer * buffer)
gint16 *linear_data; gint16 *linear_data;
guint8 *mulaw_data; guint8 *mulaw_data;
GstBuffer *outbuf; GstBuffer *outbuf;
gint bufsize;
mulawenc = GST_MULAWENC (GST_OBJECT_PARENT (pad)); mulawenc = GST_MULAWENC (GST_OBJECT_PARENT (pad));
if (!mulawenc->rate || !mulawenc->channels)
goto not_negotiated;
linear_data = (gint16 *) GST_BUFFER_DATA (buffer); linear_data = (gint16 *) GST_BUFFER_DATA (buffer);
outbuf = gst_buffer_new_and_alloc (GST_BUFFER_SIZE (buffer) / 2); bufsize = GST_BUFFER_SIZE (buffer) / 2;
GST_BUFFER_TIMESTAMP (outbuf) = GST_BUFFER_TIMESTAMP (buffer); outbuf = gst_buffer_new_and_alloc (bufsize);
GST_BUFFER_DURATION (outbuf) = GST_BUFFER_DURATION (buffer);
GST_BUFFER_DURATION (outbuf) = GST_SECOND * (bufsize) /
(mulawenc->rate * mulawenc->channels);
GST_BUFFER_TIMESTAMP (outbuf) = mulawenc->ts;
mulawenc->ts += GST_BUFFER_DURATION (outbuf);
gst_buffer_set_caps (outbuf, GST_PAD_CAPS (mulawenc->srcpad)); gst_buffer_set_caps (outbuf, GST_PAD_CAPS (mulawenc->srcpad));
mulaw_data = (guint8 *) GST_BUFFER_DATA (outbuf); mulaw_data = (guint8 *) GST_BUFFER_DATA (outbuf);
@ -217,4 +230,9 @@ gst_mulawenc_chain (GstPad * pad, GstBuffer * buffer)
gst_buffer_unref (buffer); gst_buffer_unref (buffer);
return gst_pad_push (mulawenc->srcpad, outbuf); return gst_pad_push (mulawenc->srcpad, outbuf);
not_negotiated:
{
return GST_FLOW_NOT_NEGOTIATED;
}
} }

View file

@ -50,6 +50,10 @@ struct _GstMuLawEnc {
GstPad *sinkpad,*srcpad; GstPad *sinkpad,*srcpad;
guint64 ts;
gint channels;
gint rate;
/*MetaAudioRaw meta; */ /*MetaAudioRaw meta; */
}; };