mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-07-10 08:35:58 +00:00
gst/law/: Make negotiation a bit modern.
Original commit message from CVS: Based on patch by: mersad <mersad at axis dot com> * gst/law/alaw-decode.c: (gst_alaw_dec_sink_setcaps), (gst_alaw_dec_chain), (gst_alaw_dec_change_state): * gst/law/alaw-decode.h: * gst/law/alaw-encode.c: (gst_alaw_enc_chain): * gst/law/mulaw-decode.c: (mulawdec_sink_setcaps), (gst_mulawdec_chain), (gst_mulawdec_change_state): * gst/law/mulaw-decode.h: * gst/law/mulaw-encode.c: (gst_mulawenc_chain): Make negotiation a bit modern. Use pad_alloc. Fixes #525359.
This commit is contained in:
parent
ec5e76cab4
commit
7964bd1ed8
15
ChangeLog
15
ChangeLog
|
@ -1,3 +1,18 @@
|
||||||
|
2008-04-01 Wim Taymans <wim.taymans@collabora.co.uk>
|
||||||
|
|
||||||
|
Based on patch by: mersad <mersad at axis dot com>
|
||||||
|
|
||||||
|
* gst/law/alaw-decode.c: (gst_alaw_dec_sink_setcaps),
|
||||||
|
(gst_alaw_dec_chain), (gst_alaw_dec_change_state):
|
||||||
|
* gst/law/alaw-decode.h:
|
||||||
|
* gst/law/alaw-encode.c: (gst_alaw_enc_chain):
|
||||||
|
* gst/law/mulaw-decode.c: (mulawdec_sink_setcaps),
|
||||||
|
(gst_mulawdec_chain), (gst_mulawdec_change_state):
|
||||||
|
* gst/law/mulaw-decode.h:
|
||||||
|
* gst/law/mulaw-encode.c: (gst_mulawenc_chain):
|
||||||
|
Make negotiation a bit modern.
|
||||||
|
Use pad_alloc. Fixes #525359.
|
||||||
|
|
||||||
2008-03-31 David Schleef <ds@schleef.org>
|
2008-03-31 David Schleef <ds@schleef.org>
|
||||||
|
|
||||||
* gst/goom/xmmx.c: Fix constraints on asm code so that it
|
* gst/goom/xmmx.c: Fix constraints on asm code so that it
|
||||||
|
|
|
@ -111,27 +111,33 @@ gst_alaw_dec_sink_setcaps (GstPad * pad, GstCaps * caps)
|
||||||
GstStructure *structure;
|
GstStructure *structure;
|
||||||
int rate, channels;
|
int rate, channels;
|
||||||
gboolean ret;
|
gboolean ret;
|
||||||
|
GstCaps *outcaps;
|
||||||
|
|
||||||
alawdec = GST_ALAW_DEC (GST_PAD_PARENT (pad));
|
alawdec = GST_ALAW_DEC (GST_PAD_PARENT (pad));
|
||||||
|
|
||||||
structure = gst_caps_get_structure (caps, 0);
|
structure = gst_caps_get_structure (caps, 0);
|
||||||
|
|
||||||
ret = gst_structure_get_int (structure, "rate", &rate);
|
ret = gst_structure_get_int (structure, "rate", &rate);
|
||||||
ret = ret && gst_structure_get_int (structure, "channels", &channels);
|
ret &= gst_structure_get_int (structure, "channels", &channels);
|
||||||
if (!ret)
|
if (!ret)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
if (alawdec->srccaps)
|
outcaps = gst_caps_new_simple ("audio/x-raw-int",
|
||||||
gst_caps_unref (alawdec->srccaps);
|
|
||||||
alawdec->srccaps = gst_caps_new_simple ("audio/x-raw-int",
|
|
||||||
"width", G_TYPE_INT, 16,
|
"width", G_TYPE_INT, 16,
|
||||||
"depth", G_TYPE_INT, 16,
|
"depth", G_TYPE_INT, 16,
|
||||||
"endianness", G_TYPE_INT, G_BYTE_ORDER,
|
"endianness", G_TYPE_INT, G_BYTE_ORDER,
|
||||||
"signed", G_TYPE_BOOLEAN, TRUE,
|
"signed", G_TYPE_BOOLEAN, TRUE,
|
||||||
"rate", G_TYPE_INT, rate, "channels", G_TYPE_INT, channels, NULL);
|
"rate", G_TYPE_INT, rate, "channels", G_TYPE_INT, channels, NULL);
|
||||||
|
|
||||||
GST_DEBUG_OBJECT (alawdec, "rate=%d, channels=%d", rate, channels);
|
ret = gst_pad_set_caps (alawdec->srcpad, outcaps);
|
||||||
|
gst_caps_unref (outcaps);
|
||||||
|
|
||||||
return TRUE;
|
if (ret) {
|
||||||
|
GST_DEBUG_OBJECT (alawdec, "rate=%d, channels=%d", rate, channels);
|
||||||
|
alawdec->rate = rate;
|
||||||
|
alawdec->channels = channels;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -185,7 +191,7 @@ gst_alaw_dec_chain (GstPad * pad, GstBuffer * buffer)
|
||||||
|
|
||||||
alawdec = GST_ALAW_DEC (GST_PAD_PARENT (pad));
|
alawdec = GST_ALAW_DEC (GST_PAD_PARENT (pad));
|
||||||
|
|
||||||
if (G_UNLIKELY (alawdec->srccaps == NULL))
|
if (G_UNLIKELY (alawdec->rate == 0))
|
||||||
goto not_negotiated;
|
goto not_negotiated;
|
||||||
|
|
||||||
GST_LOG_OBJECT (alawdec, "buffer with ts=%" GST_TIME_FORMAT,
|
GST_LOG_OBJECT (alawdec, "buffer with ts=%" GST_TIME_FORMAT,
|
||||||
|
@ -194,7 +200,13 @@ gst_alaw_dec_chain (GstPad * pad, GstBuffer * buffer)
|
||||||
alaw_data = GST_BUFFER_DATA (buffer);
|
alaw_data = GST_BUFFER_DATA (buffer);
|
||||||
alaw_size = GST_BUFFER_SIZE (buffer);
|
alaw_size = GST_BUFFER_SIZE (buffer);
|
||||||
|
|
||||||
outbuf = gst_buffer_new_and_alloc (alaw_size * 2);
|
ret =
|
||||||
|
gst_pad_alloc_buffer_and_set_caps (alawdec->srcpad,
|
||||||
|
GST_BUFFER_OFFSET_NONE, alaw_size * 2, GST_PAD_CAPS (alawdec->srcpad),
|
||||||
|
&outbuf);
|
||||||
|
if (ret != GST_FLOW_OK)
|
||||||
|
goto alloc_failed;
|
||||||
|
|
||||||
linear_data = (gint16 *) GST_BUFFER_DATA (outbuf);
|
linear_data = (gint16 *) GST_BUFFER_DATA (outbuf);
|
||||||
|
|
||||||
/* copy discont flag */
|
/* copy discont flag */
|
||||||
|
@ -203,24 +215,29 @@ gst_alaw_dec_chain (GstPad * pad, GstBuffer * buffer)
|
||||||
|
|
||||||
GST_BUFFER_TIMESTAMP (outbuf) = GST_BUFFER_TIMESTAMP (buffer);
|
GST_BUFFER_TIMESTAMP (outbuf) = GST_BUFFER_TIMESTAMP (buffer);
|
||||||
GST_BUFFER_DURATION (outbuf) = GST_BUFFER_DURATION (buffer);
|
GST_BUFFER_DURATION (outbuf) = GST_BUFFER_DURATION (buffer);
|
||||||
gst_buffer_set_caps (outbuf, alawdec->srccaps);
|
gst_buffer_set_caps (outbuf, GST_PAD_CAPS (alawdec->srcpad));
|
||||||
|
|
||||||
for (i = 0; i < alaw_size; i++) {
|
for (i = 0; i < alaw_size; i++) {
|
||||||
linear_data[i] = alaw_to_s16 (alaw_data[i]);
|
linear_data[i] = alaw_to_s16 (alaw_data[i]);
|
||||||
}
|
}
|
||||||
|
gst_buffer_unref (buffer);
|
||||||
|
|
||||||
ret = gst_pad_push (alawdec->srcpad, outbuf);
|
ret = gst_pad_push (alawdec->srcpad, outbuf);
|
||||||
|
|
||||||
done:
|
|
||||||
|
|
||||||
gst_buffer_unref (buffer);
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
not_negotiated:
|
not_negotiated:
|
||||||
{
|
{
|
||||||
|
gst_buffer_unref (buffer);
|
||||||
|
GST_ERROR_OBJECT (alawdec, "no format negotiated");
|
||||||
ret = GST_FLOW_NOT_NEGOTIATED;
|
ret = GST_FLOW_NOT_NEGOTIATED;
|
||||||
goto done;
|
return ret;
|
||||||
|
}
|
||||||
|
alloc_failed:
|
||||||
|
{
|
||||||
|
gst_buffer_unref (buffer);
|
||||||
|
GST_ERROR_OBJECT (alawdec, "pad alloc failed");
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -241,10 +258,8 @@ gst_alaw_dec_change_state (GstElement * element, GstStateChange transition)
|
||||||
|
|
||||||
switch (transition) {
|
switch (transition) {
|
||||||
case GST_STATE_CHANGE_PAUSED_TO_READY:
|
case GST_STATE_CHANGE_PAUSED_TO_READY:
|
||||||
if (dec->srccaps) {
|
dec->rate = 0;
|
||||||
gst_caps_unref (dec->srccaps);
|
dec->channels = 0;
|
||||||
dec->srccaps = NULL;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -42,7 +42,8 @@ struct _GstALawDec {
|
||||||
GstElement element;
|
GstElement element;
|
||||||
|
|
||||||
GstPad *sinkpad,*srcpad;
|
GstPad *sinkpad,*srcpad;
|
||||||
GstCaps *srccaps;
|
gint rate;
|
||||||
|
gint channels;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _GstALawDecClass {
|
struct _GstALawDecClass {
|
||||||
|
|
|
@ -462,7 +462,13 @@ gst_alaw_enc_chain (GstPad * pad, GstBuffer * buffer)
|
||||||
GST_SECOND, alawenc->rate * alawenc->channels);
|
GST_SECOND, alawenc->rate * alawenc->channels);
|
||||||
}
|
}
|
||||||
|
|
||||||
outbuf = gst_buffer_new_and_alloc (alaw_size);
|
ret =
|
||||||
|
gst_pad_alloc_buffer_and_set_caps (alawenc->srcpad,
|
||||||
|
GST_BUFFER_OFFSET_NONE, alaw_size, GST_PAD_CAPS (alawenc->srcpad),
|
||||||
|
&outbuf);
|
||||||
|
if (ret != GST_FLOW_OK)
|
||||||
|
goto done;
|
||||||
|
|
||||||
alaw_data = (guint8 *) GST_BUFFER_DATA (outbuf);
|
alaw_data = (guint8 *) GST_BUFFER_DATA (outbuf);
|
||||||
|
|
||||||
/* copy discont flag */
|
/* copy discont flag */
|
||||||
|
|
|
@ -55,6 +55,7 @@ mulawdec_sink_setcaps (GstPad * pad, GstCaps * caps)
|
||||||
GstStructure *structure;
|
GstStructure *structure;
|
||||||
int rate, channels;
|
int rate, channels;
|
||||||
gboolean ret;
|
gboolean ret;
|
||||||
|
GstCaps *outcaps;
|
||||||
|
|
||||||
mulawdec = GST_MULAWDEC (GST_PAD_PARENT (pad));
|
mulawdec = GST_MULAWDEC (GST_PAD_PARENT (pad));
|
||||||
|
|
||||||
|
@ -64,19 +65,21 @@ mulawdec_sink_setcaps (GstPad * pad, GstCaps * caps)
|
||||||
if (!ret)
|
if (!ret)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
if (mulawdec->srccaps)
|
outcaps = gst_caps_new_simple ("audio/x-raw-int",
|
||||||
gst_caps_unref (mulawdec->srccaps);
|
|
||||||
mulawdec->srccaps = gst_caps_new_simple ("audio/x-raw-int",
|
|
||||||
"width", G_TYPE_INT, 16,
|
"width", G_TYPE_INT, 16,
|
||||||
"depth", G_TYPE_INT, 16,
|
"depth", G_TYPE_INT, 16,
|
||||||
"endianness", G_TYPE_INT, G_BYTE_ORDER,
|
"endianness", G_TYPE_INT, G_BYTE_ORDER,
|
||||||
"signed", G_TYPE_BOOLEAN, TRUE,
|
"signed", G_TYPE_BOOLEAN, TRUE,
|
||||||
"rate", G_TYPE_INT, rate, "channels", G_TYPE_INT, channels, NULL);
|
"rate", G_TYPE_INT, rate, "channels", G_TYPE_INT, channels, NULL);
|
||||||
|
ret = gst_pad_set_caps (mulawdec->srcpad, outcaps);
|
||||||
|
gst_caps_unref (outcaps);
|
||||||
|
|
||||||
mulawdec->rate = rate;
|
if (ret) {
|
||||||
mulawdec->channels = channels;
|
GST_DEBUG_OBJECT (mulawdec, "rate=%d, channels=%d", rate, channels);
|
||||||
|
mulawdec->rate = rate;
|
||||||
return TRUE;
|
mulawdec->channels = channels;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
GType
|
GType
|
||||||
|
@ -155,15 +158,19 @@ gst_mulawdec_chain (GstPad * pad, GstBuffer * buffer)
|
||||||
|
|
||||||
mulawdec = GST_MULAWDEC (GST_PAD_PARENT (pad));
|
mulawdec = GST_MULAWDEC (GST_PAD_PARENT (pad));
|
||||||
|
|
||||||
if (G_UNLIKELY (mulawdec->srccaps == NULL)) {
|
if (G_UNLIKELY (mulawdec->rate == 0))
|
||||||
gst_buffer_unref (buffer);
|
goto not_negotiated;
|
||||||
return GST_FLOW_NOT_NEGOTIATED;
|
|
||||||
}
|
|
||||||
|
|
||||||
mulaw_data = (guint8 *) GST_BUFFER_DATA (buffer);
|
mulaw_data = (guint8 *) GST_BUFFER_DATA (buffer);
|
||||||
mulaw_size = GST_BUFFER_SIZE (buffer);
|
mulaw_size = GST_BUFFER_SIZE (buffer);
|
||||||
|
|
||||||
outbuf = gst_buffer_new_and_alloc (mulaw_size * 2);
|
ret =
|
||||||
|
gst_pad_alloc_buffer_and_set_caps (mulawdec->srcpad,
|
||||||
|
GST_BUFFER_OFFSET_NONE, mulaw_size * 2, GST_PAD_CAPS (mulawdec->srcpad),
|
||||||
|
&outbuf);
|
||||||
|
if (ret != GST_FLOW_OK)
|
||||||
|
goto alloc_failed;
|
||||||
|
|
||||||
linear_data = (gint16 *) GST_BUFFER_DATA (outbuf);
|
linear_data = (gint16 *) GST_BUFFER_DATA (outbuf);
|
||||||
|
|
||||||
/* copy discont flag */
|
/* copy discont flag */
|
||||||
|
@ -176,7 +183,7 @@ gst_mulawdec_chain (GstPad * pad, GstBuffer * buffer)
|
||||||
mulaw_size * 2, 2 * mulawdec->rate * mulawdec->channels);
|
mulaw_size * 2, 2 * mulawdec->rate * mulawdec->channels);
|
||||||
else
|
else
|
||||||
GST_BUFFER_DURATION (outbuf) = GST_BUFFER_DURATION (buffer);
|
GST_BUFFER_DURATION (outbuf) = GST_BUFFER_DURATION (buffer);
|
||||||
gst_buffer_set_caps (outbuf, mulawdec->srccaps);
|
gst_buffer_set_caps (outbuf, GST_PAD_CAPS (mulawdec->srcpad));
|
||||||
|
|
||||||
mulaw_decode (mulaw_data, linear_data, mulaw_size);
|
mulaw_decode (mulaw_data, linear_data, mulaw_size);
|
||||||
|
|
||||||
|
@ -185,6 +192,20 @@ gst_mulawdec_chain (GstPad * pad, GstBuffer * buffer)
|
||||||
ret = gst_pad_push (mulawdec->srcpad, outbuf);
|
ret = gst_pad_push (mulawdec->srcpad, outbuf);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
|
/* ERRORS */
|
||||||
|
not_negotiated:
|
||||||
|
{
|
||||||
|
GST_ERROR_OBJECT (mulawdec, "no format negotiated");
|
||||||
|
gst_buffer_unref (buffer);
|
||||||
|
return GST_FLOW_NOT_NEGOTIATED;
|
||||||
|
}
|
||||||
|
alloc_failed:
|
||||||
|
{
|
||||||
|
GST_ERROR_OBJECT (mulawdec, "pad alloc failed");
|
||||||
|
gst_buffer_unref (buffer);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static GstStateChangeReturn
|
static GstStateChangeReturn
|
||||||
|
@ -204,10 +225,8 @@ gst_mulawdec_change_state (GstElement * element, GstStateChange transition)
|
||||||
|
|
||||||
switch (transition) {
|
switch (transition) {
|
||||||
case GST_STATE_CHANGE_PAUSED_TO_READY:
|
case GST_STATE_CHANGE_PAUSED_TO_READY:
|
||||||
if (dec->srccaps) {
|
dec->rate = 0;
|
||||||
gst_caps_unref (dec->srccaps);
|
dec->channels = 0;
|
||||||
dec->srccaps = NULL;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -42,7 +42,6 @@ struct _GstMuLawDec {
|
||||||
GstElement element;
|
GstElement element;
|
||||||
|
|
||||||
GstPad *sinkpad,*srcpad;
|
GstPad *sinkpad,*srcpad;
|
||||||
GstCaps *srccaps;
|
|
||||||
|
|
||||||
gint rate;
|
gint rate;
|
||||||
gint channels;
|
gint channels;
|
||||||
|
|
|
@ -230,7 +230,13 @@ gst_mulawenc_chain (GstPad * pad, GstBuffer * buffer)
|
||||||
GST_SECOND, mulawenc->rate * mulawenc->channels);
|
GST_SECOND, mulawenc->rate * mulawenc->channels);
|
||||||
}
|
}
|
||||||
|
|
||||||
outbuf = gst_buffer_new_and_alloc (mulaw_size);
|
ret =
|
||||||
|
gst_pad_alloc_buffer_and_set_caps (mulawenc->srcpad,
|
||||||
|
GST_BUFFER_OFFSET_NONE, mulaw_size, GST_PAD_CAPS (mulawenc->srcpad),
|
||||||
|
&outbuf);
|
||||||
|
if (ret != GST_FLOW_OK)
|
||||||
|
goto alloc_failed;
|
||||||
|
|
||||||
mulaw_data = (guint8 *) GST_BUFFER_DATA (outbuf);
|
mulaw_data = (guint8 *) GST_BUFFER_DATA (outbuf);
|
||||||
|
|
||||||
/* copy discont flag */
|
/* copy discont flag */
|
||||||
|
@ -255,7 +261,15 @@ done:
|
||||||
|
|
||||||
not_negotiated:
|
not_negotiated:
|
||||||
{
|
{
|
||||||
|
GST_DEBUG_OBJECT (mulawenc, "no format negotiated");
|
||||||
ret = GST_FLOW_NOT_NEGOTIATED;
|
ret = GST_FLOW_NOT_NEGOTIATED;
|
||||||
|
gst_buffer_unref (buffer);
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
alloc_failed:
|
||||||
|
{
|
||||||
|
GST_DEBUG_OBJECT (mulawenc, "pad alloc failed");
|
||||||
|
gst_buffer_unref (buffer);
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue