summaryrefslogtreecommitdiffstats
path: root/src/polypsrc.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/polypsrc.c')
-rw-r--r--src/polypsrc.c77
1 files changed, 75 insertions, 2 deletions
diff --git a/src/polypsrc.c b/src/polypsrc.c
index 5bd9e70..306ffff 100644
--- a/src/polypsrc.c
+++ b/src/polypsrc.c
@@ -31,6 +31,7 @@
#include "polypsrc.h"
#include "polyputil.h"
+#include "polypmixerctrl.h"
GST_DEBUG_CATEGORY_EXTERN(polyp_debug);
#define GST_CAT_DEFAULT polyp_debug
@@ -42,6 +43,8 @@ enum {
static GstAudioSrcClass *parent_class = NULL;
+GST_IMPLEMENT_POLYPMIXER_CTRL_METHODS(GstPolypSrc, gst_polypsrc)
+
static void gst_polypsrc_destroy_stream(GstPolypSrc *polypsrc);
static void gst_polypsrc_destroy_context(GstPolypSrc *polypsrc);
@@ -59,12 +62,43 @@ static gboolean gst_polypsrc_unprepare(GstAudioSrc *asrc);
static guint gst_polypsrc_read(GstAudioSrc *asrc, gpointer data, guint length);
static guint gst_polypsrc_delay(GstAudioSrc *asrc);
+static GstStateChangeReturn gst_polypsrc_change_state(GstElement *element, GstStateChange transition);
+
#if (G_BYTE_ORDER == G_LITTLE_ENDIAN)
# define ENDIANNESS "LITTLE_ENDIAN, BIG_ENDIAN"
#else
# define ENDIANNESS "BIG_ENDIAN, LITTLE_ENDIAN"
#endif
+static gboolean gst_polypsrc_interface_supported(GstImplementsInterface* iface, GType interface_type) {
+ GstPolypSrc *this = GST_POLYPSRC(iface);
+
+ if (interface_type == GST_TYPE_MIXER && this->mixer)
+ return TRUE;
+
+ return FALSE;
+}
+
+static void gst_polypsrc_implements_interface_init(GstImplementsInterfaceClass* klass) {
+ klass->supported = gst_polypsrc_interface_supported;
+}
+
+static void gst_polypsrc_init_interfaces(GType type) {
+ static const GInterfaceInfo implements_iface_info = {
+ (GInterfaceInitFunc) gst_polypsrc_implements_interface_init,
+ NULL,
+ NULL,
+ };
+ static const GInterfaceInfo mixer_iface_info = {
+ (GInterfaceInitFunc) gst_polypsrc_mixer_interface_init,
+ NULL,
+ NULL,
+ };
+
+ g_type_add_interface_static(type, GST_TYPE_IMPLEMENTS_INTERFACE, &implements_iface_info);
+ g_type_add_interface_static(type, GST_TYPE_MIXER, &mixer_iface_info);
+}
+
static void gst_polypsrc_base_init(gpointer g_class) {
static GstStaticPadTemplate pad_template = GST_STATIC_PAD_TEMPLATE(
@@ -122,8 +156,11 @@ static void gst_polypsrc_class_init(
GObjectClass *gobject_class = G_OBJECT_CLASS(g_class);
GstAudioSrcClass *gstaudiosrc_class = GST_AUDIO_SRC_CLASS(g_class);
+ GstElementClass *gstelement_class = GST_ELEMENT_CLASS(g_class);
parent_class = g_type_class_peek_parent(g_class);
-
+
+ gstelement_class->change_state = GST_DEBUG_FUNCPTR(gst_polypsrc_change_state);
+
gobject_class->dispose = GST_DEBUG_FUNCPTR(gst_polypsrc_dispose);
gobject_class->finalize = GST_DEBUG_FUNCPTR(gst_polypsrc_finalize);
gobject_class->set_property = GST_DEBUG_FUNCPTR(gst_polypsrc_set_property);
@@ -167,6 +204,8 @@ static void gst_polypsrc_init(
e = pa_threaded_mainloop_start(polypsrc->mainloop);
g_assert(e == 0);
+
+ polypsrc->mixer = NULL;
}
static void gst_polypsrc_destroy_stream(GstPolypSrc* polypsrc) {
@@ -200,6 +239,9 @@ static void gst_polypsrc_finalize(GObject * object) {
pa_threaded_mainloop_free(polypsrc->mainloop);
+ if (polypsrc->mixer)
+ gst_polypmixer_ctrl_free(polypsrc->mixer);
+
G_OBJECT_CLASS(parent_class)->finalize(object);
}
@@ -479,7 +521,6 @@ static guint gst_polypsrc_read(GstAudioSrc *asrc, gpointer data, guint length) {
return sum;
unlock_and_fail:
-
pa_threaded_mainloop_unlock(polypsrc->mainloop);
return 0;
}
@@ -515,6 +556,36 @@ unlock_and_fail:
return 0;
}
+static GstStateChangeReturn gst_polypsrc_change_state(GstElement *element, GstStateChange transition) {
+ GstPolypSrc *this = GST_POLYPSRC(element);
+
+ switch (transition) {
+ case GST_STATE_CHANGE_NULL_TO_READY:
+
+ if (!this->mixer)
+ this->mixer = gst_polypmixer_ctrl_new(this->server, this->device, GST_POLYPMIXER_SOURCE);
+
+ break;
+
+ case GST_STATE_CHANGE_READY_TO_NULL:
+
+ if (this->mixer) {
+ gst_polypmixer_ctrl_free(this->mixer);
+ this->mixer = NULL;
+ }
+
+ break;
+
+ default:
+ ;
+ }
+
+ if (GST_ELEMENT_CLASS(parent_class)->change_state)
+ return GST_ELEMENT_CLASS(parent_class)->change_state(element, transition);
+
+ return GST_STATE_CHANGE_SUCCESS;
+}
+
GType gst_polypsrc_get_type(void) {
static GType polypsrc_type = 0;
@@ -537,6 +608,8 @@ GType gst_polypsrc_get_type(void) {
"GstPolypSrc",
&polypsrc_info,
0);
+
+ gst_polypsrc_init_interfaces(polypsrc_type);
}
return polypsrc_type;