Commit 7964bd1e authored by mersad's avatar mersad Committed by Wim Taymans

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.
parent ec5e76ca
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>
* 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;
int rate, channels;
gboolean ret;
GstCaps *outcaps;
alawdec = GST_ALAW_DEC (GST_PAD_PARENT (pad));
structure = gst_caps_get_structure (caps, 0);
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)
return FALSE;
if (alawdec->srccaps)
gst_caps_unref (alawdec->srccaps);
alawdec->srccaps = gst_caps_new_simple ("audio/x-raw-int",
outcaps = gst_caps_new_simple ("audio/x-raw-int",
"width", G_TYPE_INT, 16,
"depth", G_TYPE_INT, 16,
"endianness", G_TYPE_INT, G_BYTE_ORDER,
"signed", G_TYPE_BOOLEAN, TRUE,
"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
......@@ -185,7 +191,7 @@ gst_alaw_dec_chain (GstPad * pad, GstBuffer * buffer)
alawdec = GST_ALAW_DEC (GST_PAD_PARENT (pad));
if (G_UNLIKELY (alawdec->srccaps == NULL))
if (G_UNLIKELY (alawdec->rate == 0))
goto not_negotiated;
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_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);
/* 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_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++) {
linear_data[i] = alaw_to_s16 (alaw_data[i]);
}
gst_buffer_unref (buffer);
ret = gst_pad_push (alawdec->srcpad, outbuf);
done:
gst_buffer_unref (buffer);
return ret;
not_negotiated:
{
gst_buffer_unref (buffer);
GST_ERROR_OBJECT (alawdec, "no format 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) {
case GST_STATE_CHANGE_PAUSED_TO_READY:
if (dec->srccaps) {
gst_caps_unref (dec->srccaps);
dec->srccaps = NULL;
}
dec->rate = 0;
dec->channels = 0;
break;
default:
break;
......
......@@ -42,7 +42,8 @@ struct _GstALawDec {
GstElement element;
GstPad *sinkpad,*srcpad;
GstCaps *srccaps;
gint rate;
gint channels;
};
struct _GstALawDecClass {
......
......@@ -462,7 +462,13 @@ gst_alaw_enc_chain (GstPad * pad, GstBuffer * buffer)
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);
/* copy discont flag */
......
......@@ -55,6 +55,7 @@ mulawdec_sink_setcaps (GstPad * pad, GstCaps * caps)
GstStructure *structure;
int rate, channels;
gboolean ret;
GstCaps *outcaps;
mulawdec = GST_MULAWDEC (GST_PAD_PARENT (pad));
......@@ -64,19 +65,21 @@ mulawdec_sink_setcaps (GstPad * pad, GstCaps * caps)
if (!ret)
return FALSE;
if (mulawdec->srccaps)
gst_caps_unref (mulawdec->srccaps);
mulawdec->srccaps = gst_caps_new_simple ("audio/x-raw-int",
outcaps = gst_caps_new_simple ("audio/x-raw-int",
"width", G_TYPE_INT, 16,
"depth", G_TYPE_INT, 16,
"endianness", G_TYPE_INT, G_BYTE_ORDER,
"signed", G_TYPE_BOOLEAN, TRUE,
"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;
mulawdec->channels = channels;
return TRUE;
if (ret) {
GST_DEBUG_OBJECT (mulawdec, "rate=%d, channels=%d", rate, channels);
mulawdec->rate = rate;
mulawdec->channels = channels;
}
return ret;
}
GType
......@@ -155,15 +158,19 @@ gst_mulawdec_chain (GstPad * pad, GstBuffer * buffer)
mulawdec = GST_MULAWDEC (GST_PAD_PARENT (pad));
if (G_UNLIKELY (mulawdec->srccaps == NULL)) {
gst_buffer_unref (buffer);
return GST_FLOW_NOT_NEGOTIATED;
}
if (G_UNLIKELY (mulawdec->rate == 0))
goto not_negotiated;
mulaw_data = (guint8 *) GST_BUFFER_DATA (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);
/* copy discont flag */
......@@ -176,7 +183,7 @@ gst_mulawdec_chain (GstPad * pad, GstBuffer * buffer)
mulaw_size * 2, 2 * mulawdec->rate * mulawdec->channels);
else
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);
......@@ -185,6 +192,20 @@ gst_mulawdec_chain (GstPad * pad, GstBuffer * buffer)
ret = gst_pad_push (mulawdec->srcpad, outbuf);
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
......@@ -204,10 +225,8 @@ gst_mulawdec_change_state (GstElement * element, GstStateChange transition)
switch (transition) {
case GST_STATE_CHANGE_PAUSED_TO_READY:
if (dec->srccaps) {
gst_caps_unref (dec->srccaps);
dec->srccaps = NULL;
}
dec->rate = 0;
dec->channels = 0;
break;
default:
break;
......
......@@ -42,7 +42,6 @@ struct _GstMuLawDec {
GstElement element;
GstPad *sinkpad,*srcpad;
GstCaps *srccaps;
gint rate;
gint channels;
......
......@@ -230,7 +230,13 @@ gst_mulawenc_chain (GstPad * pad, GstBuffer * buffer)
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);
/* copy discont flag */
......@@ -255,7 +261,15 @@ done:
not_negotiated:
{
GST_DEBUG_OBJECT (mulawenc, "no format 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;
}
}
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