gst/law/: Fix capsnego in all four, remove the unused property functions and simplify the chain functions slightly. I...

Original commit message from CVS:
* gst/law/alaw-decode.c: (alawdec_getcaps), (alawdec_link),
(gst_alawdec_base_init), (gst_alawdec_class_init),
(gst_alawdec_init), (gst_alawdec_chain):
* gst/law/alaw-encode.c: (alawenc_getcaps), (alawenc_link),
(gst_alawenc_base_init), (gst_alawenc_class_init),
(gst_alawenc_init), (gst_alawenc_chain):
* gst/law/mulaw-decode.c: (mulawdec_getcaps), (mulawdec_link),
(gst_mulawdec_base_init), (gst_mulawdec_class_init),
(gst_mulawdec_init), (gst_mulawdec_chain):
* gst/law/mulaw-encode.c: (mulawenc_getcaps), (mulawenc_link),
(gst_mulawenc_base_init), (gst_mulawenc_class_init),
(gst_mulawenc_init), (gst_mulawenc_chain):
Fix capsnego in all four, remove the unused property functions and
simplify the chain functions slightly. I guess we could use macros
or something similar for those, since the code is so similar, but
I'm currently too lazy...
This commit is contained in:
Ronald S. Bultje 2004-03-26 01:56:11 +00:00
parent d21f04ca6f
commit 920ad8773b
5 changed files with 314 additions and 315 deletions

View file

@ -1,3 +1,22 @@
2004-03-25 Ronald Bultje <rbultje@ronald.bitfreak.net>
* gst/law/alaw-decode.c: (alawdec_getcaps), (alawdec_link),
(gst_alawdec_base_init), (gst_alawdec_class_init),
(gst_alawdec_init), (gst_alawdec_chain):
* gst/law/alaw-encode.c: (alawenc_getcaps), (alawenc_link),
(gst_alawenc_base_init), (gst_alawenc_class_init),
(gst_alawenc_init), (gst_alawenc_chain):
* gst/law/mulaw-decode.c: (mulawdec_getcaps), (mulawdec_link),
(gst_mulawdec_base_init), (gst_mulawdec_class_init),
(gst_mulawdec_init), (gst_mulawdec_chain):
* gst/law/mulaw-encode.c: (mulawenc_getcaps), (mulawenc_link),
(gst_mulawenc_base_init), (gst_mulawenc_class_init),
(gst_mulawenc_init), (gst_mulawenc_chain):
Fix capsnego in all four, remove the unused property functions and
simplify the chain functions slightly. I guess we could use macros
or something similar for those, since the code is so similar, but
I'm currently too lazy...
2004-03-24 David Schleef <ds@schleef.org>
* sys/oss/gstosselement.c: (gst_osselement_sync_parms),

View file

@ -27,14 +27,6 @@
extern GstPadTemplate *alawdec_src_template, *alawdec_sink_template;
/* elementfactory information */
static GstElementDetails alawdec_details = {
"A Law to PCM conversion",
"Codec/Decoder/Audio",
"Convert 8bit A law to 16bit PCM",
"Zaheer Merali <zaheer@bellworldwide.net>"
};
/* Stereo signals and args */
enum
{
@ -51,14 +43,8 @@ static void gst_alawdec_class_init (GstALawDecClass * klass);
static void gst_alawdec_base_init (GstALawDecClass * klass);
static void gst_alawdec_init (GstALawDec * alawdec);
static void gst_alawdec_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec);
static void gst_alawdec_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec);
static void gst_alawdec_chain (GstPad * pad, GstData * _data);
static GstElementClass *parent_class = NULL;
/*static guint gst_stereo_signals[LAST_SIGNAL] = { 0 }; */
@ -85,31 +71,73 @@ alaw_to_s16 (guint8 a_val)
return ((a_val & 0x80) ? t : -t);
}
static GstCaps *
alawdec_getcaps (GstPad * pad)
{
GstALawDec *alawdec = GST_ALAWDEC (gst_pad_get_parent (pad));
GstPad *otherpad;
GstCaps *base_caps, *othercaps;
GstStructure *structure;
const GValue *rate, *chans;
if (pad == alawdec->sinkpad) {
otherpad = alawdec->srcpad;
base_caps = gst_caps_new_simple ("audio/x-mulaw", NULL);
} else {
otherpad = alawdec->sinkpad;
base_caps = 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, NULL);
}
othercaps = gst_pad_get_allowed_caps (otherpad);
/* Not fully correct, but usually, all structures in a caps have
* the same samplerate and channels range. */
structure = gst_caps_get_structure (othercaps, 0);
rate = gst_structure_get_value (structure, "rate");
chans = gst_structure_get_value (structure, "channels");
if (!rate || !chans)
return gst_caps_new_empty ();
/* Set the samplerate/channels on the to-be-returned caps */
structure = gst_caps_get_structure (base_caps, 0);
gst_structure_set_value (structure, "rate", rate);
gst_structure_set_value (structure, "channels", chans);
gst_caps_free (othercaps);
return base_caps;
}
static GstPadLinkReturn
alawdec_link (GstPad * pad, const GstCaps * caps)
{
GstCaps *tempcaps;
gint rate, channels;
GstALawDec *alawdec = GST_ALAWDEC (gst_pad_get_parent (pad));
GstPad *otherpad;
GstStructure *structure;
gboolean ret;
GstALawDec *alawdec = GST_ALAWDEC (GST_OBJECT_PARENT (pad));
const GValue *rate, *chans;
GstCaps *base_caps;
structure = gst_caps_get_structure (caps, 0);
ret = gst_structure_get_int (structure, "rate", &rate);
ret &= gst_structure_get_int (structure, "channels", &channels);
if (!ret)
rate = gst_structure_get_value (structure, "rate");
chans = gst_structure_get_value (structure, "channels");
if (!rate || !chans)
return GST_PAD_LINK_REFUSED;
tempcaps = gst_caps_new_simple ("audio/x-raw-int",
"depth", G_TYPE_INT, 16,
"width", G_TYPE_INT, 16,
"signed", G_TYPE_BOOLEAN, TRUE,
"endianness", G_TYPE_INT, G_BYTE_ORDER,
"rate", G_TYPE_INT, rate, "channels", G_TYPE_INT, channels, NULL);
if (pad == alawdec->srcpad) {
otherpad = alawdec->sinkpad;
base_caps = gst_caps_new_simple ("audio/x-mulaw", NULL);
} else {
otherpad = alawdec->srcpad;
base_caps = 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, NULL);
}
return gst_pad_try_set_caps (alawdec->srcpad, tempcaps);
structure = gst_caps_get_structure (base_caps, 0);
gst_structure_set_value (structure, "rate", rate);
gst_structure_set_value (structure, "channels", chans);
return gst_pad_try_set_caps (otherpad, base_caps);
}
GType
@ -141,6 +169,12 @@ static void
gst_alawdec_base_init (GstALawDecClass * klass)
{
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
GstElementDetails alawdec_details = {
"A Law to PCM conversion",
"Codec/Decoder/Audio",
"Convert 8bit A law to 16bit PCM",
"Zaheer Merali <zaheer@bellworldwide.net>"
};
gst_element_class_add_pad_template (element_class, alawdec_src_template);
gst_element_class_add_pad_template (element_class, alawdec_sink_template);
@ -150,27 +184,21 @@ gst_alawdec_base_init (GstALawDecClass * klass)
static void
gst_alawdec_class_init (GstALawDecClass * klass)
{
GObjectClass *gobject_class;
GstElementClass *gstelement_class;
gobject_class = (GObjectClass *) klass;
gstelement_class = (GstElementClass *) klass;
parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
gobject_class->set_property = gst_alawdec_set_property;
gobject_class->get_property = gst_alawdec_get_property;
}
static void
gst_alawdec_init (GstALawDec * alawdec)
{
alawdec->sinkpad = gst_pad_new_from_template (alawdec_sink_template, "sink");
alawdec->srcpad = gst_pad_new_from_template (alawdec_src_template, "src");
gst_pad_set_link_function (alawdec->sinkpad, alawdec_link);
gst_element_add_pad (GST_ELEMENT (alawdec), alawdec->sinkpad);
gst_pad_set_getcaps_function (alawdec->sinkpad, alawdec_getcaps);
gst_pad_set_chain_function (alawdec->sinkpad, gst_alawdec_chain);
gst_element_add_pad (GST_ELEMENT (alawdec), alawdec->sinkpad);
alawdec->srcpad = gst_pad_new_from_template (alawdec_src_template, "src");
gst_pad_set_link_function (alawdec->srcpad, alawdec_link);
gst_pad_set_getcaps_function (alawdec->srcpad, alawdec_getcaps);
gst_element_add_pad (GST_ELEMENT (alawdec), alawdec->srcpad);
}
@ -193,11 +221,11 @@ gst_alawdec_chain (GstPad * pad, GstData * _data)
g_return_if_fail (GST_IS_ALAWDEC (alawdec));
alaw_data = (guint8 *) GST_BUFFER_DATA (buf);
outbuf = gst_buffer_new ();
GST_BUFFER_DATA (outbuf) = (gchar *) g_new (gint16, GST_BUFFER_SIZE (buf));
GST_BUFFER_SIZE (outbuf) = GST_BUFFER_SIZE (buf) * 2;
outbuf = gst_buffer_new_and_alloc (GST_BUFFER_SIZE (buf) * 2);
GST_BUFFER_TIMESTAMP (outbuf) = GST_BUFFER_TIMESTAMP (buf);
GST_BUFFER_DURATION (outbuf) = GST_BUFFER_DURATION (buf);
linear_data = (gint16 *) GST_BUFFER_DATA (outbuf);
for (i = 0; i < GST_BUFFER_SIZE (buf); i++) {
*linear_data = alaw_to_s16 (*alaw_data);
linear_data++;
@ -207,36 +235,3 @@ gst_alawdec_chain (GstPad * pad, GstData * _data)
gst_buffer_unref (buf);
gst_pad_push (alawdec->srcpad, GST_DATA (outbuf));
}
static void
gst_alawdec_set_property (GObject * object, guint prop_id, const GValue * value,
GParamSpec * pspec)
{
GstALawDec *alawdec;
/* it's not null if we got it, but it might not be ours */
g_return_if_fail (GST_IS_ALAWDEC (object));
alawdec = GST_ALAWDEC (object);
switch (prop_id) {
default:
break;
}
}
static void
gst_alawdec_get_property (GObject * object, guint prop_id, GValue * value,
GParamSpec * pspec)
{
GstALawDec *alawdec;
/* it's not null if we got it, but it might not be ours */
g_return_if_fail (GST_IS_ALAWDEC (object));
alawdec = GST_ALAWDEC (object);
switch (prop_id) {
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}

View file

@ -27,14 +27,6 @@
extern GstPadTemplate *alawenc_src_template, *alawenc_sink_template;
/* elementfactory information */
static GstElementDetails alawenc_details = {
"PCM to A Law conversion",
"Codec/Encoder/Audio",
"Convert 16bit PCM to 8bit A law",
"Zaheer Merali <zaheer@bellworldwide.net>"
};
/* Stereo signals and args */
enum
{
@ -51,11 +43,6 @@ static void gst_alawenc_class_init (GstALawEncClass * klass);
static void gst_alawenc_base_init (GstALawEncClass * klass);
static void gst_alawenc_init (GstALawEnc * alawenc);
static void gst_alawenc_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec);
static void gst_alawenc_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec);
static void gst_alawenc_chain (GstPad * pad, GstData * _data);
/*
@ -127,31 +114,73 @@ static GstElementClass *parent_class = NULL;
/*static guint gst_stereo_signals[LAST_SIGNAL] = { 0 }; */
static GstCaps *
alawenc_getcaps (GstPad * pad)
{
GstALawEnc *alawenc = GST_ALAWENC (gst_pad_get_parent (pad));
GstPad *otherpad;
GstCaps *base_caps, *othercaps;
GstStructure *structure;
const GValue *rate, *chans;
if (pad == alawenc->srcpad) {
otherpad = alawenc->sinkpad;
base_caps = gst_caps_new_simple ("audio/x-mulaw", NULL);
} else {
otherpad = alawenc->srcpad;
base_caps = 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, NULL);
}
othercaps = gst_pad_get_allowed_caps (otherpad);
/* Not fully correct, but usually, all structures in a caps have
* the same samplerate and channels range. */
structure = gst_caps_get_structure (othercaps, 0);
rate = gst_structure_get_value (structure, "rate");
chans = gst_structure_get_value (structure, "channels");
if (!rate || !chans)
return gst_caps_new_empty ();
/* Set the samplerate/channels on the to-be-returned caps */
structure = gst_caps_get_structure (base_caps, 0);
gst_structure_set_value (structure, "rate", rate);
gst_structure_set_value (structure, "channels", chans);
gst_caps_free (othercaps);
return base_caps;
}
static GstPadLinkReturn
alawenc_link (GstPad * pad, const GstCaps * caps)
{
GstCaps *tempcaps;
gint rate, channels;
GstALawEnc *alawenc = GST_ALAWENC (gst_pad_get_parent (pad));
GstPad *otherpad;
GstStructure *structure;
gboolean ret;
GstALawEnc *alawenc = GST_ALAWENC (GST_OBJECT_PARENT (pad));
const GValue *rate, *chans;
GstCaps *base_caps;
structure = gst_caps_get_structure (caps, 0);
ret = gst_structure_get_int (structure, "rate", &rate);
ret &= gst_structure_get_int (structure, "channels", &channels);
if (!ret)
rate = gst_structure_get_value (structure, "rate");
chans = gst_structure_get_value (structure, "channels");
if (!rate || !chans)
return GST_PAD_LINK_REFUSED;
tempcaps = gst_caps_new_simple ("audio/x-alaw",
"depth", G_TYPE_INT, 8,
"width", G_TYPE_INT, 8,
"signed", G_TYPE_BOOLEAN, FALSE,
"rate", G_TYPE_INT, rate, "channels", G_TYPE_INT, channels, NULL);
if (pad == alawenc->sinkpad) {
otherpad = alawenc->srcpad;
base_caps = gst_caps_new_simple ("audio/x-mulaw", NULL);
} else {
otherpad = alawenc->sinkpad;
base_caps = 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, NULL);
}
return gst_pad_try_set_caps (alawenc->srcpad, tempcaps);
structure = gst_caps_get_structure (base_caps, 0);
gst_structure_set_value (structure, "rate", rate);
gst_structure_set_value (structure, "channels", chans);
return gst_pad_try_set_caps (otherpad, base_caps);
}
GType
@ -183,6 +212,12 @@ static void
gst_alawenc_base_init (GstALawEncClass * klass)
{
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
GstElementDetails alawenc_details = {
"PCM to A Law conversion",
"Codec/Encoder/Audio",
"Convert 16bit PCM to 8bit A law",
"Zaheer Merali <zaheer@bellworldwide.net>"
};
gst_element_class_add_pad_template (element_class, alawenc_src_template);
gst_element_class_add_pad_template (element_class, alawenc_sink_template);
@ -192,27 +227,21 @@ gst_alawenc_base_init (GstALawEncClass * klass)
static void
gst_alawenc_class_init (GstALawEncClass * klass)
{
GObjectClass *gobject_class;
GstElementClass *gstelement_class;
gobject_class = (GObjectClass *) klass;
gstelement_class = (GstElementClass *) klass;
parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
gobject_class->set_property = gst_alawenc_set_property;
gobject_class->get_property = gst_alawenc_get_property;
}
static void
gst_alawenc_init (GstALawEnc * alawenc)
{
alawenc->sinkpad = gst_pad_new_from_template (alawenc_sink_template, "sink");
alawenc->srcpad = gst_pad_new_from_template (alawenc_src_template, "src");
gst_pad_set_link_function (alawenc->sinkpad, alawenc_link);
gst_element_add_pad (GST_ELEMENT (alawenc), alawenc->sinkpad);
gst_pad_set_getcaps_function (alawenc->sinkpad, alawenc_getcaps);
gst_pad_set_chain_function (alawenc->sinkpad, gst_alawenc_chain);
gst_element_add_pad (GST_ELEMENT (alawenc), alawenc->sinkpad);
alawenc->srcpad = gst_pad_new_from_template (alawenc_src_template, "src");
gst_pad_set_link_function (alawenc->srcpad, alawenc_link);
gst_pad_set_getcaps_function (alawenc->srcpad, alawenc_getcaps);
gst_element_add_pad (GST_ELEMENT (alawenc), alawenc->srcpad);
}
@ -235,51 +264,17 @@ gst_alawenc_chain (GstPad * pad, GstData * _data)
g_return_if_fail (GST_IS_ALAWENC (alawenc));
linear_data = (gint16 *) GST_BUFFER_DATA (buf);
outbuf = gst_buffer_new ();
GST_BUFFER_DATA (outbuf) =
(gchar *) g_new (guint8, GST_BUFFER_SIZE (buf) / 2);
GST_BUFFER_SIZE (outbuf) = GST_BUFFER_SIZE (buf) / 2;
outbuf = gst_buffer_new_and_alloc (GST_BUFFER_SIZE (buf) / 2);
GST_BUFFER_TIMESTAMP (outbuf) = GST_BUFFER_TIMESTAMP (buf);
GST_BUFFER_DURATION (outbuf) = GST_BUFFER_DURATION (buf);
alaw_data = (guint8 *) GST_BUFFER_DATA (outbuf);
for (i = 0; i < GST_BUFFER_SIZE (outbuf); i++) {
*alaw_data = s16_to_alaw (*linear_data);
alaw_data++;
linear_data++;
}
gst_buffer_unref (buf);
gst_pad_push (alawenc->srcpad, GST_DATA (outbuf));
}
static void
gst_alawenc_set_property (GObject * object, guint prop_id, const GValue * value,
GParamSpec * pspec)
{
GstALawEnc *alawenc;
/* it's not null if we got it, but it might not be ours */
g_return_if_fail (GST_IS_ALAWENC (object));
alawenc = GST_ALAWENC (object);
switch (prop_id) {
default:
break;
}
}
static void
gst_alawenc_get_property (GObject * object, guint prop_id, GValue * value,
GParamSpec * pspec)
{
GstALawEnc *alawenc;
/* it's not null if we got it, but it might not be ours */
g_return_if_fail (GST_IS_ALAWENC (object));
alawenc = GST_ALAWENC (object);
switch (prop_id) {
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}

View file

@ -26,14 +26,6 @@
extern GstPadTemplate *mulawdec_src_template, *mulawdec_sink_template;
/* elementfactory information */
static GstElementDetails mulawdec_details = {
"Mu Law to PCM conversion",
"Codec/Decoder/Audio",
"Convert 8bit mu law to 16bit PCM",
"Zaheer Merali <zaheer@bellworldwide.net>"
};
/* Stereo signals and args */
enum
{
@ -50,43 +42,79 @@ static void gst_mulawdec_class_init (GstMuLawDecClass * klass);
static void gst_mulawdec_base_init (GstMuLawDecClass * klass);
static void gst_mulawdec_init (GstMuLawDec * mulawdec);
static void gst_mulawdec_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec);
static void gst_mulawdec_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec);
static void gst_mulawdec_chain (GstPad * pad, GstData * _data);
static GstElementClass *parent_class = NULL;
/*static guint gst_stereo_signals[LAST_SIGNAL] = { 0 };*/
static GstCaps *
mulawdec_getcaps (GstPad * pad)
{
GstMuLawDec *mulawdec = GST_MULAWDEC (gst_pad_get_parent (pad));
GstPad *otherpad;
GstCaps *base_caps, *othercaps;
GstStructure *structure;
const GValue *rate, *chans;
if (pad == mulawdec->sinkpad) {
otherpad = mulawdec->srcpad;
base_caps = gst_caps_new_simple ("audio/x-mulaw", NULL);
} else {
otherpad = mulawdec->sinkpad;
base_caps = 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, NULL);
}
othercaps = gst_pad_get_allowed_caps (otherpad);
/* Not fully correct, but usually, all structures in a caps have
* the same samplerate and channels range. */
structure = gst_caps_get_structure (othercaps, 0);
rate = gst_structure_get_value (structure, "rate");
chans = gst_structure_get_value (structure, "channels");
if (!rate || !chans)
return gst_caps_new_empty ();
/* Set the samplerate/channels on the to-be-returned caps */
structure = gst_caps_get_structure (base_caps, 0);
gst_structure_set_value (structure, "rate", rate);
gst_structure_set_value (structure, "channels", chans);
gst_caps_free (othercaps);
return base_caps;
}
static GstPadLinkReturn
mulawdec_link (GstPad * pad, const GstCaps * caps)
{
GstCaps *tempcaps;
gint rate, channels;
GstMuLawDec *mulawdec = GST_MULAWDEC (gst_pad_get_parent (pad));
GstPad *otherpad;
GstStructure *structure;
gboolean ret;
GstMuLawDec *mulawdec = GST_MULAWDEC (GST_OBJECT_PARENT (pad));
const GValue *rate, *chans;
GstCaps *base_caps;
structure = gst_caps_get_structure (caps, 0);
ret = gst_structure_get_int (structure, "rate", &rate);
ret = gst_structure_get_int (structure, "channels", &channels);
if (!ret)
rate = gst_structure_get_value (structure, "rate");
chans = gst_structure_get_value (structure, "channels");
if (!rate || !chans)
return GST_PAD_LINK_REFUSED;
tempcaps = gst_caps_new_simple ("audio/x-raw-int",
"depth", G_TYPE_INT, 16,
"width", G_TYPE_INT, 16,
"signed", G_TYPE_BOOLEAN, TRUE,
"endianness", G_TYPE_INT, G_BYTE_ORDER,
"rate", G_TYPE_INT, rate, "channels", G_TYPE_INT, channels, NULL);
if (pad == mulawdec->srcpad) {
otherpad = mulawdec->sinkpad;
base_caps = gst_caps_new_simple ("audio/x-mulaw", NULL);
} else {
otherpad = mulawdec->srcpad;
base_caps = 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, NULL);
}
return gst_pad_try_set_caps (mulawdec->srcpad, tempcaps);
structure = gst_caps_get_structure (base_caps, 0);
gst_structure_set_value (structure, "rate", rate);
gst_structure_set_value (structure, "channels", chans);
return gst_pad_try_set_caps (otherpad, base_caps);
}
GType
@ -118,6 +146,12 @@ static void
gst_mulawdec_base_init (GstMuLawDecClass * klass)
{
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
GstElementDetails mulawdec_details = {
"Mu Law to PCM conversion",
"Codec/Decoder/Audio",
"Convert 8bit mu law to 16bit PCM",
"Zaheer Merali <zaheer@bellworldwide.net>"
};
gst_element_class_add_pad_template (element_class, mulawdec_src_template);
gst_element_class_add_pad_template (element_class, mulawdec_sink_template);
@ -127,16 +161,7 @@ gst_mulawdec_base_init (GstMuLawDecClass * klass)
static void
gst_mulawdec_class_init (GstMuLawDecClass * klass)
{
GObjectClass *gobject_class;
GstElementClass *gstelement_class;
gobject_class = (GObjectClass *) klass;
gstelement_class = (GstElementClass *) klass;
parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
gobject_class->set_property = gst_mulawdec_set_property;
gobject_class->get_property = gst_mulawdec_get_property;
}
static void
@ -144,11 +169,14 @@ gst_mulawdec_init (GstMuLawDec * mulawdec)
{
mulawdec->sinkpad =
gst_pad_new_from_template (mulawdec_sink_template, "sink");
mulawdec->srcpad = gst_pad_new_from_template (mulawdec_src_template, "src");
gst_pad_set_link_function (mulawdec->sinkpad, mulawdec_link);
gst_element_add_pad (GST_ELEMENT (mulawdec), mulawdec->sinkpad);
gst_pad_set_getcaps_function (mulawdec->sinkpad, mulawdec_getcaps);
gst_pad_set_chain_function (mulawdec->sinkpad, gst_mulawdec_chain);
gst_element_add_pad (GST_ELEMENT (mulawdec), mulawdec->sinkpad);
mulawdec->srcpad = gst_pad_new_from_template (mulawdec_src_template, "src");
gst_pad_set_link_function (mulawdec->srcpad, mulawdec_link);
gst_pad_set_getcaps_function (mulawdec->srcpad, mulawdec_getcaps);
gst_element_add_pad (GST_ELEMENT (mulawdec), mulawdec->srcpad);
}
@ -170,46 +198,13 @@ gst_mulawdec_chain (GstPad * pad, GstData * _data)
g_return_if_fail (GST_IS_MULAWDEC (mulawdec));
mulaw_data = (guint8 *) GST_BUFFER_DATA (buf);
outbuf = gst_buffer_new ();
GST_BUFFER_DATA (outbuf) = (gchar *) g_new (gint16, GST_BUFFER_SIZE (buf));
GST_BUFFER_SIZE (outbuf) = GST_BUFFER_SIZE (buf) * 2;
outbuf = gst_buffer_new_and_alloc (GST_BUFFER_SIZE (buf) * 2);
GST_BUFFER_TIMESTAMP (outbuf) = GST_BUFFER_TIMESTAMP (buf);
GST_BUFFER_DURATION (outbuf) = GST_BUFFER_DURATION (buf);
linear_data = (gint16 *) GST_BUFFER_DATA (outbuf);
mulaw_decode (mulaw_data, linear_data, GST_BUFFER_SIZE (buf));
gst_buffer_unref (buf);
gst_pad_push (mulawdec->srcpad, GST_DATA (outbuf));
}
static void
gst_mulawdec_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec)
{
GstMuLawDec *mulawdec;
/* it's not null if we got it, but it might not be ours */
g_return_if_fail (GST_IS_MULAWDEC (object));
mulawdec = GST_MULAWDEC (object);
switch (prop_id) {
default:
break;
}
}
static void
gst_mulawdec_get_property (GObject * object, guint prop_id, GValue * value,
GParamSpec * pspec)
{
GstMuLawDec *mulawdec;
/* it's not null if we got it, but it might not be ours */
g_return_if_fail (GST_IS_MULAWDEC (object));
mulawdec = GST_MULAWDEC (object);
switch (prop_id) {
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}

View file

@ -26,14 +26,6 @@
extern GstPadTemplate *mulawenc_src_template, *mulawenc_sink_template;
/* elementfactory information */
static GstElementDetails mulawenc_details = {
"PCM to Mu Law conversion",
"Codec/Encoder/Audio",
"Convert 16bit PCM to 8bit mu law",
"Zaheer Merali <zaheer@bellworldwide.net>"
};
/* Stereo signals and args */
enum
{
@ -50,41 +42,79 @@ static void gst_mulawenc_class_init (GstMuLawEncClass * klass);
static void gst_mulawenc_base_init (GstMuLawEncClass * klass);
static void gst_mulawenc_init (GstMuLawEnc * mulawenc);
static void gst_mulawenc_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec);
static void gst_mulawenc_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec);
static void gst_mulawenc_chain (GstPad * pad, GstData * _data);
static GstElementClass *parent_class = NULL;
/*static guint gst_stereo_signals[LAST_SIGNAL] = { 0 }; */
static GstCaps *
mulawenc_getcaps (GstPad * pad)
{
GstMuLawEnc *mulawenc = GST_MULAWENC (gst_pad_get_parent (pad));
GstPad *otherpad;
GstCaps *base_caps, *othercaps;
GstStructure *structure;
const GValue *rate, *chans;
if (pad == mulawenc->srcpad) {
otherpad = mulawenc->sinkpad;
base_caps = gst_caps_new_simple ("audio/x-mulaw", NULL);
} else {
otherpad = mulawenc->srcpad;
base_caps = 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, NULL);
}
othercaps = gst_pad_get_allowed_caps (otherpad);
/* Not fully correct, but usually, all structures in a caps have
* the same samplerate and channels range. */
structure = gst_caps_get_structure (othercaps, 0);
rate = gst_structure_get_value (structure, "rate");
chans = gst_structure_get_value (structure, "channels");
if (!rate || !chans)
return gst_caps_new_empty ();
/* Set the samplerate/channels on the to-be-returned caps */
structure = gst_caps_get_structure (base_caps, 0);
gst_structure_set_value (structure, "rate", rate);
gst_structure_set_value (structure, "channels", chans);
gst_caps_free (othercaps);
return base_caps;
}
static GstPadLinkReturn
mulawenc_link (GstPad * pad, const GstCaps * caps)
{
GstCaps *tempcaps;
gint rate, channels;
GstMuLawEnc *mulawenc = GST_MULAWENC (gst_pad_get_parent (pad));
GstPad *otherpad;
GstStructure *structure;
gboolean ret;
GstMuLawEnc *mulawenc = GST_MULAWENC (GST_OBJECT_PARENT (pad));
const GValue *rate, *chans;
GstCaps *base_caps;
structure = gst_caps_get_structure (caps, 0);
ret = gst_structure_get_int (structure, "rate", &rate);
ret = gst_structure_get_int (structure, "channels", &channels);
if (!ret)
rate = gst_structure_get_value (structure, "rate");
chans = gst_structure_get_value (structure, "channels");
if (!rate || !chans)
return GST_PAD_LINK_REFUSED;
tempcaps = gst_caps_new_simple ("audio/x-mulaw",
"depth", G_TYPE_INT, 8,
"width", G_TYPE_INT, 8,
"signed", G_TYPE_BOOLEAN, FALSE,
"rate", G_TYPE_INT, rate, "channels", G_TYPE_INT, channels, NULL);
if (pad == mulawenc->sinkpad) {
otherpad = mulawenc->srcpad;
base_caps = gst_caps_new_simple ("audio/x-mulaw", NULL);
} else {
otherpad = mulawenc->sinkpad;
base_caps = 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, NULL);
}
return gst_pad_try_set_caps (mulawenc->srcpad, tempcaps);
structure = gst_caps_get_structure (base_caps, 0);
gst_structure_set_value (structure, "rate", rate);
gst_structure_set_value (structure, "channels", chans);
return gst_pad_try_set_caps (otherpad, base_caps);
}
GType
@ -116,6 +146,12 @@ static void
gst_mulawenc_base_init (GstMuLawEncClass * klass)
{
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
GstElementDetails mulawenc_details = {
"PCM to Mu Law conversion",
"Codec/Encoder/Audio",
"Convert 16bit PCM to 8bit mu law",
"Zaheer Merali <zaheer@bellworldwide.net>"
};
gst_element_class_add_pad_template (element_class, mulawenc_src_template);
gst_element_class_add_pad_template (element_class, mulawenc_sink_template);
@ -125,16 +161,7 @@ gst_mulawenc_base_init (GstMuLawEncClass * klass)
static void
gst_mulawenc_class_init (GstMuLawEncClass * klass)
{
GObjectClass *gobject_class;
GstElementClass *gstelement_class;
gobject_class = (GObjectClass *) klass;
gstelement_class = (GstElementClass *) klass;
parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
gobject_class->set_property = gst_mulawenc_set_property;
gobject_class->get_property = gst_mulawenc_get_property;
}
static void
@ -142,11 +169,14 @@ gst_mulawenc_init (GstMuLawEnc * mulawenc)
{
mulawenc->sinkpad =
gst_pad_new_from_template (mulawenc_sink_template, "sink");
mulawenc->srcpad = gst_pad_new_from_template (mulawenc_src_template, "src");
gst_pad_set_link_function (mulawenc->sinkpad, mulawenc_link);
gst_element_add_pad (GST_ELEMENT (mulawenc), mulawenc->sinkpad);
gst_pad_set_getcaps_function (mulawenc->sinkpad, mulawenc_getcaps);
gst_pad_set_chain_function (mulawenc->sinkpad, gst_mulawenc_chain);
gst_element_add_pad (GST_ELEMENT (mulawenc), mulawenc->sinkpad);
mulawenc->srcpad = gst_pad_new_from_template (mulawenc_src_template, "src");
gst_pad_set_link_function (mulawenc->srcpad, mulawenc_link);
gst_pad_set_getcaps_function (mulawenc->srcpad, mulawenc_getcaps);
gst_element_add_pad (GST_ELEMENT (mulawenc), mulawenc->srcpad);
}
@ -168,47 +198,12 @@ gst_mulawenc_chain (GstPad * pad, GstData * _data)
g_return_if_fail (GST_IS_MULAWENC (mulawenc));
linear_data = (gint16 *) GST_BUFFER_DATA (buf);
outbuf = gst_buffer_new ();
GST_BUFFER_DATA (outbuf) =
(gchar *) g_new (gint16, GST_BUFFER_SIZE (buf) / 4);
GST_BUFFER_SIZE (outbuf) = GST_BUFFER_SIZE (buf) / 2;
outbuf = gst_buffer_new_and_alloc (GST_BUFFER_SIZE (buf) / 2);
GST_BUFFER_TIMESTAMP (outbuf) = GST_BUFFER_TIMESTAMP (buf);
GST_BUFFER_DURATION (outbuf) = GST_BUFFER_DURATION (buf);
mulaw_data = (gint8 *) GST_BUFFER_DATA (outbuf);
mulaw_encode (linear_data, mulaw_data, GST_BUFFER_SIZE (outbuf));
gst_buffer_unref (buf);
gst_pad_push (mulawenc->srcpad, GST_DATA (outbuf));
}
static void
gst_mulawenc_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec)
{
GstMuLawEnc *mulawenc;
/* it's not null if we got it, but it might not be ours */
g_return_if_fail (GST_IS_MULAWENC (object));
mulawenc = GST_MULAWENC (object);
switch (prop_id) {
default:
break;
}
}
static void
gst_mulawenc_get_property (GObject * object, guint prop_id, GValue * value,
GParamSpec * pspec)
{
GstMuLawEnc *mulawenc;
/* it's not null if we got it, but it might not be ours */
g_return_if_fail (GST_IS_MULAWENC (object));
mulawenc = GST_MULAWENC (object);
switch (prop_id) {
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}