mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-18 07:47:17 +00:00
adder: Add custom GstPad subclass to hold additional data and properties
This will later allow to set per-stream volumes and mute status.
This commit is contained in:
parent
0b933ff87b
commit
561ce54b27
2 changed files with 104 additions and 2 deletions
|
@ -49,6 +49,85 @@
|
||||||
#include <string.h> /* strcmp */
|
#include <string.h> /* strcmp */
|
||||||
#include "gstadderorc.h"
|
#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
|
enum
|
||||||
{
|
{
|
||||||
PROP_0,
|
PROP_0,
|
||||||
|
@ -1032,7 +1111,8 @@ gst_adder_request_new_pad (GstElement * element, GstPadTemplate * templ,
|
||||||
padcount = g_atomic_int_add (&adder->padcount, 1);
|
padcount = g_atomic_int_add (&adder->padcount, 1);
|
||||||
|
|
||||||
name = g_strdup_printf ("sink_%u", padcount);
|
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);
|
GST_DEBUG_OBJECT (adder, "request new pad %s", name);
|
||||||
g_free (name);
|
g_free (name);
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,9 @@ G_BEGIN_DECLS
|
||||||
|
|
||||||
typedef struct _GstAdder GstAdder;
|
typedef struct _GstAdder GstAdder;
|
||||||
typedef struct _GstAdderClass GstAdderClass;
|
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);
|
typedef void (*GstAdderFunction) (gpointer out, gpointer in, guint size);
|
||||||
|
|
||||||
|
@ -91,6 +93,26 @@ struct _GstAdderClass {
|
||||||
|
|
||||||
GType gst_adder_get_type (void);
|
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
|
G_END_DECLS
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue