diff options
author | Sebastian Dröge <slomo@circular-chaos.org> | 2013-05-30 11:40:01 +0200 |
---|---|---|
committer | Sebastian Dröge <slomo@circular-chaos.org> | 2013-05-30 23:56:51 +0200 |
commit | 561ce54b2780a3cc00c793e39bf41f6e1c2f4148 (patch) | |
tree | b5f00e412f27c941314669036b53d3484e073109 /gst/adder | |
parent | 0b933ff87b55ec235c22252cff82c68bcd603b3b (diff) | |
download | gstreamer-plugins-base-561ce54b2780a3cc00c793e39bf41f6e1c2f4148.tar.gz |
adder: Add custom GstPad subclass to hold additional data and properties
This will later allow to set per-stream volumes and mute status.
Diffstat (limited to 'gst/adder')
-rw-r--r-- | gst/adder/gstadder.c | 82 | ||||
-rw-r--r-- | gst/adder/gstadder.h | 24 |
2 files changed, 104 insertions, 2 deletions
diff --git a/gst/adder/gstadder.c b/gst/adder/gstadder.c index bf5b11d70..9b36a905d 100644 --- a/gst/adder/gstadder.c +++ b/gst/adder/gstadder.c @@ -49,6 +49,85 @@ #include <string.h> /* strcmp */ #include "gstadderorc.h" +#define DEFAULT_PAD_VOLUME (1.0) +#define DEFAULT_PAD_MUTE (FALSE) + +enum +{ + PROP_PAD_0, + PROP_PAD_VOLUME, + PROP_PAD_MUTE +}; + +G_DEFINE_TYPE (GstAdderPad, gst_adder_pad, GST_TYPE_PAD); + +static void +gst_adder_pad_get_property (GObject * object, guint prop_id, + GValue * value, GParamSpec * pspec) +{ + GstAdderPad *pad = GST_ADDER_PAD (object); + + switch (prop_id) { + case PROP_PAD_VOLUME: + g_value_set_double (value, pad->volume); + break; + case PROP_PAD_MUTE: + g_value_set_boolean (value, pad->mute); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +gst_adder_pad_set_property (GObject * object, guint prop_id, + const GValue * value, GParamSpec * pspec) +{ + GstAdderPad *pad = GST_ADDER_PAD (object); + + switch (prop_id) { + case PROP_PAD_VOLUME: + GST_OBJECT_LOCK (pad); + pad->volume = g_value_get_double (value); + GST_OBJECT_UNLOCK (pad); + break; + case PROP_PAD_MUTE: + GST_OBJECT_LOCK (pad); + pad->mute = g_value_get_boolean (value); + GST_OBJECT_UNLOCK (pad); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +gst_adder_pad_class_init (GstAdderPadClass * klass) +{ + GObjectClass *gobject_class = (GObjectClass *) klass; + + gobject_class->set_property = gst_adder_pad_set_property; + gobject_class->get_property = gst_adder_pad_get_property; + + g_object_class_install_property (gobject_class, PROP_PAD_VOLUME, + g_param_spec_double ("volume", "Volume", "Volume of this pad", + 0.0, 10.0, DEFAULT_PAD_VOLUME, + G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE | G_PARAM_STATIC_STRINGS)); + g_object_class_install_property (gobject_class, PROP_PAD_MUTE, + g_param_spec_boolean ("mute", "Mute", "Mute this pad", + DEFAULT_PAD_MUTE, + G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE | G_PARAM_STATIC_STRINGS)); +} + +static void +gst_adder_pad_init (GstAdderPad * pad) +{ + pad->volume = DEFAULT_PAD_VOLUME; + pad->mute = DEFAULT_PAD_MUTE; +} + enum { PROP_0, @@ -1032,7 +1111,8 @@ gst_adder_request_new_pad (GstElement * element, GstPadTemplate * templ, padcount = g_atomic_int_add (&adder->padcount, 1); name = g_strdup_printf ("sink_%u", padcount); - newpad = gst_pad_new_from_template (templ, name); + newpad = g_object_new (GST_TYPE_ADDER_PAD, "name", name, "direction", + templ->direction, "template", templ, NULL); GST_DEBUG_OBJECT (adder, "request new pad %s", name); g_free (name); diff --git a/gst/adder/gstadder.h b/gst/adder/gstadder.h index 53048cbef..25248172d 100644 --- a/gst/adder/gstadder.h +++ b/gst/adder/gstadder.h @@ -38,7 +38,9 @@ G_BEGIN_DECLS typedef struct _GstAdder GstAdder; typedef struct _GstAdderClass GstAdderClass; -typedef struct _GstAdderInputChannel GstAdderInputChannel; + +typedef struct _GstAdderPad GstAdderPad; +typedef struct _GstAdderPadClass GstAdderPadClass; typedef void (*GstAdderFunction) (gpointer out, gpointer in, guint size); @@ -91,6 +93,26 @@ struct _GstAdderClass { GType gst_adder_get_type (void); +#define GST_TYPE_ADDER_PAD (gst_adder_pad_get_type()) +#define GST_ADDER_PAD(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_ADDER_PAD,GstAdderPad)) +#define GST_IS_ADDER_PAD(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_ADDER_PAD)) +#define GST_ADDER_PAD_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass) ,GST_TYPE_ADDER_PAD,GstAdderPadClass)) +#define GST_IS_ADDER_PAD_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass) ,GST_TYPE_ADDER_PAD)) +#define GST_ADDER_PAD_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj) ,GST_TYPE_ADDER_PAD,GstAdderPadClass)) + +struct _GstAdderPad { + GstPad parent; + + gdouble volume; + gboolean mute; +}; + +struct _GstAdderPadClass { + GstPadClass parent_class; +}; + +GType gst_adder_pad_get_type (void); + G_END_DECLS |