summaryrefslogtreecommitdiffstats
path: root/gst/law/mulaw-encode.c
diff options
context:
space:
mode:
authorRonald S. Bultje <rbultje@ronald.bitfreak.net>2004-03-26 01:56:11 +0000
committerRonald S. Bultje <rbultje@ronald.bitfreak.net>2004-03-26 01:56:11 +0000
commit920ad8773bb23016eb882b1a23c665032a82b243 (patch)
tree4ccb58d00b979086cbf5751b8faa3258d7cadef2 /gst/law/mulaw-encode.c
parentd21f04ca6fb0e4d3f912834542aa13d0d79fdf94 (diff)
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...
Diffstat (limited to 'gst/law/mulaw-encode.c')
-rw-r--r--gst/law/mulaw-encode.c151
1 files changed, 73 insertions, 78 deletions
diff --git a/gst/law/mulaw-encode.c b/gst/law/mulaw-encode.c
index 0c002c5d..834f9827 100644
--- a/gst/law/mulaw-encode.c
+++ b/gst/law/mulaw-encode.c
@@ -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);
+ }
+
+ 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 (mulawenc->srcpad, tempcaps);
+ 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;
- }
-}