diff options
Diffstat (limited to 'src/polypsrc.c')
-rw-r--r-- | src/polypsrc.c | 388 |
1 files changed, 194 insertions, 194 deletions
diff --git a/src/polypsrc.c b/src/polypsrc.c index 306ffff..c830ca8 100644 --- a/src/polypsrc.c +++ b/src/polypsrc.c @@ -1,20 +1,20 @@ /* $Id$ */ /*** - This file is part of gst-polyp. + This file is part of gst-pulse. - gst-polyp is free software; you can redistribute it and/or modify + gst-pulse is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. - gst-polyp is distributed in the hope that it will be useful, but + gst-pulse is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public - License along with gst-polyp; if not, write to the Free Software + License along with gst-pulse; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. ***/ @@ -29,12 +29,12 @@ #include <gst/base/gstbasesrc.h> #include <gst/gsttaglist.h> -#include "polypsrc.h" -#include "polyputil.h" -#include "polypmixerctrl.h" +#include "pulsesrc.h" +#include "pulseutil.h" +#include "pulsemixerctrl.h" -GST_DEBUG_CATEGORY_EXTERN(polyp_debug); -#define GST_CAT_DEFAULT polyp_debug +GST_DEBUG_CATEGORY_EXTERN(pulse_debug); +#define GST_CAT_DEFAULT pulse_debug enum { PROP_SERVER = 1, @@ -43,26 +43,26 @@ enum { static GstAudioSrcClass *parent_class = NULL; -GST_IMPLEMENT_POLYPMIXER_CTRL_METHODS(GstPolypSrc, gst_polypsrc) +GST_IMPLEMENT_PULSEMIXER_CTRL_METHODS(GstPolypSrc, gst_pulsesrc) -static void gst_polypsrc_destroy_stream(GstPolypSrc *polypsrc); -static void gst_polypsrc_destroy_context(GstPolypSrc *polypsrc); +static void gst_pulsesrc_destroy_stream(GstPolypSrc *pulsesrc); +static void gst_pulsesrc_destroy_context(GstPolypSrc *pulsesrc); -static void gst_polypsrc_set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec); -static void gst_polypsrc_get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec); -static void gst_polypsrc_finalize(GObject *object); -static void gst_polypsrc_dispose(GObject *object); +static void gst_pulsesrc_set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec); +static void gst_pulsesrc_get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec); +static void gst_pulsesrc_finalize(GObject *object); +static void gst_pulsesrc_dispose(GObject *object); -static gboolean gst_polypsrc_open(GstAudioSrc *asrc); -static gboolean gst_polypsrc_close(GstAudioSrc *asrc); +static gboolean gst_pulsesrc_open(GstAudioSrc *asrc); +static gboolean gst_pulsesrc_close(GstAudioSrc *asrc); -static gboolean gst_polypsrc_prepare(GstAudioSrc *asrc, GstRingBufferSpec *spec); -static gboolean gst_polypsrc_unprepare(GstAudioSrc *asrc); +static gboolean gst_pulsesrc_prepare(GstAudioSrc *asrc, GstRingBufferSpec *spec); +static gboolean gst_pulsesrc_unprepare(GstAudioSrc *asrc); -static guint gst_polypsrc_read(GstAudioSrc *asrc, gpointer data, guint length); -static guint gst_polypsrc_delay(GstAudioSrc *asrc); +static guint gst_pulsesrc_read(GstAudioSrc *asrc, gpointer data, guint length); +static guint gst_pulsesrc_delay(GstAudioSrc *asrc); -static GstStateChangeReturn gst_polypsrc_change_state(GstElement *element, GstStateChange transition); +static GstStateChangeReturn gst_pulsesrc_change_state(GstElement *element, GstStateChange transition); #if (G_BYTE_ORDER == G_LITTLE_ENDIAN) # define ENDIANNESS "LITTLE_ENDIAN, BIG_ENDIAN" @@ -70,8 +70,8 @@ static GstStateChangeReturn gst_polypsrc_change_state(GstElement *element, GstSt # define ENDIANNESS "BIG_ENDIAN, LITTLE_ENDIAN" #endif -static gboolean gst_polypsrc_interface_supported(GstImplementsInterface* iface, GType interface_type) { - GstPolypSrc *this = GST_POLYPSRC(iface); +static gboolean gst_pulsesrc_interface_supported(GstImplementsInterface* iface, GType interface_type) { + GstPolypSrc *this = GST_PULSESRC(iface); if (interface_type == GST_TYPE_MIXER && this->mixer) return TRUE; @@ -79,18 +79,18 @@ static gboolean gst_polypsrc_interface_supported(GstImplementsInterface* iface, return FALSE; } -static void gst_polypsrc_implements_interface_init(GstImplementsInterfaceClass* klass) { - klass->supported = gst_polypsrc_interface_supported; +static void gst_pulsesrc_implements_interface_init(GstImplementsInterfaceClass* klass) { + klass->supported = gst_pulsesrc_interface_supported; } -static void gst_polypsrc_init_interfaces(GType type) { +static void gst_pulsesrc_init_interfaces(GType type) { static const GInterfaceInfo implements_iface_info = { - (GInterfaceInitFunc) gst_polypsrc_implements_interface_init, + (GInterfaceInitFunc) gst_pulsesrc_implements_interface_init, NULL, NULL, }; static const GInterfaceInfo mixer_iface_info = { - (GInterfaceInitFunc) gst_polypsrc_mixer_interface_init, + (GInterfaceInitFunc) gst_pulsesrc_mixer_interface_init, NULL, NULL, }; @@ -99,7 +99,7 @@ static void gst_polypsrc_init_interfaces(GType type) { g_type_add_interface_static(type, GST_TYPE_MIXER, &mixer_iface_info); } -static void gst_polypsrc_base_init(gpointer g_class) { +static void gst_pulsesrc_base_init(gpointer g_class) { static GstStaticPadTemplate pad_template = GST_STATIC_PAD_TEMPLATE( "src", @@ -139,9 +139,9 @@ static void gst_polypsrc_base_init(gpointer g_class) { static const GstElementDetails details = GST_ELEMENT_DETAILS( - "Polypaudio Audio Source", + "PulseAudio Audio Source", "Source/Audio", - "Captures audio from a Polypaudio server", + "Captures audio from a PulseAudio server", "Lennart Poettering"); GstElementClass *element_class = GST_ELEMENT_CLASS(g_class); @@ -150,7 +150,7 @@ static void gst_polypsrc_base_init(gpointer g_class) { gst_element_class_add_pad_template(element_class, gst_static_pad_template_get(&pad_template)); } -static void gst_polypsrc_class_init( +static void gst_pulsesrc_class_init( gpointer g_class, gpointer class_data) { @@ -159,113 +159,113 @@ static void gst_polypsrc_class_init( 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); + gstelement_class->change_state = GST_DEBUG_FUNCPTR(gst_pulsesrc_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); - gobject_class->get_property = GST_DEBUG_FUNCPTR(gst_polypsrc_get_property); + gobject_class->dispose = GST_DEBUG_FUNCPTR(gst_pulsesrc_dispose); + gobject_class->finalize = GST_DEBUG_FUNCPTR(gst_pulsesrc_finalize); + gobject_class->set_property = GST_DEBUG_FUNCPTR(gst_pulsesrc_set_property); + gobject_class->get_property = GST_DEBUG_FUNCPTR(gst_pulsesrc_get_property); - gstaudiosrc_class->open = GST_DEBUG_FUNCPTR(gst_polypsrc_open); - gstaudiosrc_class->close = GST_DEBUG_FUNCPTR(gst_polypsrc_close); - gstaudiosrc_class->prepare = GST_DEBUG_FUNCPTR(gst_polypsrc_prepare); - gstaudiosrc_class->unprepare = GST_DEBUG_FUNCPTR(gst_polypsrc_unprepare); - gstaudiosrc_class->read = GST_DEBUG_FUNCPTR(gst_polypsrc_read); - gstaudiosrc_class->delay = GST_DEBUG_FUNCPTR(gst_polypsrc_delay); + gstaudiosrc_class->open = GST_DEBUG_FUNCPTR(gst_pulsesrc_open); + gstaudiosrc_class->close = GST_DEBUG_FUNCPTR(gst_pulsesrc_close); + gstaudiosrc_class->prepare = GST_DEBUG_FUNCPTR(gst_pulsesrc_prepare); + gstaudiosrc_class->unprepare = GST_DEBUG_FUNCPTR(gst_pulsesrc_unprepare); + gstaudiosrc_class->read = GST_DEBUG_FUNCPTR(gst_pulsesrc_read); + gstaudiosrc_class->delay = GST_DEBUG_FUNCPTR(gst_pulsesrc_delay); /* Overwrite GObject fields */ g_object_class_install_property( gobject_class, PROP_SERVER, - g_param_spec_string("server", "Server", "The Polypaudio server to connect to", NULL, G_PARAM_READWRITE)); + g_param_spec_string("server", "Server", "The PulseAudio server to connect to", NULL, G_PARAM_READWRITE)); g_object_class_install_property( gobject_class, PROP_DEVICE, - g_param_spec_string("device", "Source", "The Polypaudio source device to connect to", NULL, G_PARAM_READWRITE)); + g_param_spec_string("device", "Source", "The PulseAudio source device to connect to", NULL, G_PARAM_READWRITE)); } -static void gst_polypsrc_init( +static void gst_pulsesrc_init( GTypeInstance * instance, gpointer g_class) { - GstPolypSrc *polypsrc = GST_POLYPSRC(instance); + GstPolypSrc *pulsesrc = GST_PULSESRC(instance); int e; - polypsrc->server = polypsrc->device = NULL; + pulsesrc->server = pulsesrc->device = NULL; - polypsrc->context = NULL; - polypsrc->stream = NULL; + pulsesrc->context = NULL; + pulsesrc->stream = NULL; - polypsrc->read_buffer = NULL; - polypsrc->read_buffer_length = 0; + pulsesrc->read_buffer = NULL; + pulsesrc->read_buffer_length = 0; - polypsrc->mainloop = pa_threaded_mainloop_new(); - g_assert(polypsrc->mainloop); + pulsesrc->mainloop = pa_threaded_mainloop_new(); + g_assert(pulsesrc->mainloop); - e = pa_threaded_mainloop_start(polypsrc->mainloop); + e = pa_threaded_mainloop_start(pulsesrc->mainloop); g_assert(e == 0); - polypsrc->mixer = NULL; + pulsesrc->mixer = NULL; } -static void gst_polypsrc_destroy_stream(GstPolypSrc* polypsrc) { - if (polypsrc->stream) { - pa_stream_disconnect(polypsrc->stream); - pa_stream_unref(polypsrc->stream); - polypsrc->stream = NULL; +static void gst_pulsesrc_destroy_stream(GstPolypSrc* pulsesrc) { + if (pulsesrc->stream) { + pa_stream_disconnect(pulsesrc->stream); + pa_stream_unref(pulsesrc->stream); + pulsesrc->stream = NULL; } } -static void gst_polypsrc_destroy_context(GstPolypSrc* polypsrc) { +static void gst_pulsesrc_destroy_context(GstPolypSrc* pulsesrc) { - gst_polypsrc_destroy_stream(polypsrc); + gst_pulsesrc_destroy_stream(pulsesrc); - if (polypsrc->context) { - pa_context_disconnect(polypsrc->context); - pa_context_unref(polypsrc->context); - polypsrc->context = NULL; + if (pulsesrc->context) { + pa_context_disconnect(pulsesrc->context); + pa_context_unref(pulsesrc->context); + pulsesrc->context = NULL; } } -static void gst_polypsrc_finalize(GObject * object) { - GstPolypSrc *polypsrc = GST_POLYPSRC(object); +static void gst_pulsesrc_finalize(GObject * object) { + GstPolypSrc *pulsesrc = GST_PULSESRC(object); - pa_threaded_mainloop_stop(polypsrc->mainloop); + pa_threaded_mainloop_stop(pulsesrc->mainloop); - gst_polypsrc_destroy_context(polypsrc); + gst_pulsesrc_destroy_context(pulsesrc); - g_free(polypsrc->server); - g_free(polypsrc->device); + g_free(pulsesrc->server); + g_free(pulsesrc->device); - pa_threaded_mainloop_free(polypsrc->mainloop); + pa_threaded_mainloop_free(pulsesrc->mainloop); - if (polypsrc->mixer) - gst_polypmixer_ctrl_free(polypsrc->mixer); + if (pulsesrc->mixer) + gst_pulsemixer_ctrl_free(pulsesrc->mixer); G_OBJECT_CLASS(parent_class)->finalize(object); } -static void gst_polypsrc_dispose(GObject * object) { +static void gst_pulsesrc_dispose(GObject * object) { G_OBJECT_CLASS(parent_class)->dispose(object); } -static void gst_polypsrc_set_property( +static void gst_pulsesrc_set_property( GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec) { - GstPolypSrc *polypsrc = GST_POLYPSRC(object); + GstPolypSrc *pulsesrc = GST_PULSESRC(object); switch (prop_id) { case PROP_SERVER: - g_free(polypsrc->server); - polypsrc->server = g_value_dup_string(value); + g_free(pulsesrc->server); + pulsesrc->server = g_value_dup_string(value); break; case PROP_DEVICE: - g_free(polypsrc->device); - polypsrc->device = g_value_dup_string(value); + g_free(pulsesrc->device); + pulsesrc->device = g_value_dup_string(value); break; default: @@ -274,21 +274,21 @@ static void gst_polypsrc_set_property( } } -static void gst_polypsrc_get_property( +static void gst_pulsesrc_get_property( GObject * object, guint prop_id, GValue * value, GParamSpec * pspec) { - GstPolypSrc *polypsrc = GST_POLYPSRC(object); + GstPolypSrc *pulsesrc = GST_PULSESRC(object); switch(prop_id) { case PROP_SERVER: - g_value_set_string(value, polypsrc->server); + g_value_set_string(value, pulsesrc->server); break; case PROP_DEVICE: - g_value_set_string(value, polypsrc->device); + g_value_set_string(value, pulsesrc->device); break; default: @@ -297,14 +297,14 @@ static void gst_polypsrc_get_property( } } -static void gst_polypsrc_context_state_cb(pa_context *c, void *userdata) { - GstPolypSrc *polypsrc = GST_POLYPSRC(userdata); +static void gst_pulsesrc_context_state_cb(pa_context *c, void *userdata) { + GstPolypSrc *pulsesrc = GST_PULSESRC(userdata); switch (pa_context_get_state(c)) { case PA_CONTEXT_READY: case PA_CONTEXT_TERMINATED: case PA_CONTEXT_FAILED: - pa_threaded_mainloop_signal(polypsrc->mainloop, 0); + pa_threaded_mainloop_signal(pulsesrc->mainloop, 0); break; case PA_CONTEXT_UNCONNECTED: @@ -315,15 +315,15 @@ static void gst_polypsrc_context_state_cb(pa_context *c, void *userdata) { } } -static void gst_polypsrc_stream_state_cb(pa_stream *s, void * userdata) { - GstPolypSrc *polypsrc = GST_POLYPSRC(userdata); +static void gst_pulsesrc_stream_state_cb(pa_stream *s, void * userdata) { + GstPolypSrc *pulsesrc = GST_PULSESRC(userdata); switch (pa_stream_get_state(s)) { case PA_STREAM_READY: case PA_STREAM_FAILED: case PA_STREAM_TERMINATED: - pa_threaded_mainloop_signal(polypsrc->mainloop, 0); + pa_threaded_mainloop_signal(pulsesrc->mainloop, 0); break; case PA_STREAM_UNCONNECTED: @@ -332,212 +332,212 @@ static void gst_polypsrc_stream_state_cb(pa_stream *s, void * userdata) { } } -static void gst_polypsrc_stream_request_cb(pa_stream *s, size_t length, void *userdata) { - GstPolypSrc *polypsrc = GST_POLYPSRC(userdata); +static void gst_pulsesrc_stream_request_cb(pa_stream *s, size_t length, void *userdata) { + GstPolypSrc *pulsesrc = GST_PULSESRC(userdata); - pa_threaded_mainloop_signal(polypsrc->mainloop, 0); + pa_threaded_mainloop_signal(pulsesrc->mainloop, 0); } -static gboolean gst_polypsrc_open(GstAudioSrc *asrc) { - GstPolypSrc *polypsrc = GST_POLYPSRC(asrc); - gchar *name = gst_polyp_client_name(); +static gboolean gst_pulsesrc_open(GstAudioSrc *asrc) { + GstPolypSrc *pulsesrc = GST_PULSESRC(asrc); + gchar *name = gst_pulse_client_name(); - pa_threaded_mainloop_lock(polypsrc->mainloop); + pa_threaded_mainloop_lock(pulsesrc->mainloop); - if (!(polypsrc->context = pa_context_new(pa_threaded_mainloop_get_api(polypsrc->mainloop), name))) { - GST_ELEMENT_ERROR(polypsrc, RESOURCE, FAILED, ("Failed to create context"), (NULL)); + if (!(pulsesrc->context = pa_context_new(pa_threaded_mainloop_get_api(pulsesrc->mainloop), name))) { + GST_ELEMENT_ERROR(pulsesrc, RESOURCE, FAILED, ("Failed to create context"), (NULL)); goto unlock_and_fail; } - pa_context_set_state_callback(polypsrc->context, gst_polypsrc_context_state_cb, polypsrc); + pa_context_set_state_callback(pulsesrc->context, gst_pulsesrc_context_state_cb, pulsesrc); - if (pa_context_connect(polypsrc->context, polypsrc->server, 0, NULL) < 0) { - GST_ELEMENT_ERROR(polypsrc, RESOURCE, FAILED, ("Failed to connect: %s", pa_strerror(pa_context_errno(polypsrc->context))), (NULL)); + if (pa_context_connect(pulsesrc->context, pulsesrc->server, 0, NULL) < 0) { + GST_ELEMENT_ERROR(pulsesrc, RESOURCE, FAILED, ("Failed to connect: %s", pa_strerror(pa_context_errno(pulsesrc->context))), (NULL)); goto unlock_and_fail; } /* Wait until the context is ready */ - pa_threaded_mainloop_wait(polypsrc->mainloop); + pa_threaded_mainloop_wait(pulsesrc->mainloop); - if (pa_context_get_state(polypsrc->context) != PA_CONTEXT_READY) { - GST_ELEMENT_ERROR(polypsrc, RESOURCE, FAILED, ("Failed to connect: %s", pa_strerror(pa_context_errno(polypsrc->context))), (NULL)); + if (pa_context_get_state(pulsesrc->context) != PA_CONTEXT_READY) { + GST_ELEMENT_ERROR(pulsesrc, RESOURCE, FAILED, ("Failed to connect: %s", pa_strerror(pa_context_errno(pulsesrc->context))), (NULL)); goto unlock_and_fail; } - pa_threaded_mainloop_unlock(polypsrc->mainloop); + pa_threaded_mainloop_unlock(pulsesrc->mainloop); g_free(name); return TRUE; unlock_and_fail: - pa_threaded_mainloop_unlock(polypsrc->mainloop); + pa_threaded_mainloop_unlock(pulsesrc->mainloop); g_free(name); return FALSE; } -static gboolean gst_polypsrc_close(GstAudioSrc *asrc) { - GstPolypSrc *polypsrc = GST_POLYPSRC(asrc); +static gboolean gst_pulsesrc_close(GstAudioSrc *asrc) { + GstPolypSrc *pulsesrc = GST_PULSESRC(asrc); - pa_threaded_mainloop_lock(polypsrc->mainloop); - gst_polypsrc_destroy_context(polypsrc); - pa_threaded_mainloop_unlock(polypsrc->mainloop); + pa_threaded_mainloop_lock(pulsesrc->mainloop); + gst_pulsesrc_destroy_context(pulsesrc); + pa_threaded_mainloop_unlock(pulsesrc->mainloop); return TRUE; } -static gboolean gst_polypsrc_prepare(GstAudioSrc *asrc, GstRingBufferSpec *spec) { +static gboolean gst_pulsesrc_prepare(GstAudioSrc *asrc, GstRingBufferSpec *spec) { pa_buffer_attr buf_attr; - GstPolypSrc *polypsrc = GST_POLYPSRC(asrc); + GstPolypSrc *pulsesrc = GST_PULSESRC(asrc); - if (!gst_polyp_fill_sample_spec(spec, &polypsrc->sample_spec)) { - GST_ELEMENT_ERROR(polypsrc, RESOURCE, SETTINGS, ("Invalid sample specification."), (NULL)); + if (!gst_pulse_fill_sample_spec(spec, &pulsesrc->sample_spec)) { + GST_ELEMENT_ERROR(pulsesrc, RESOURCE, SETTINGS, ("Invalid sample specification."), (NULL)); goto unlock_and_fail; } - pa_threaded_mainloop_lock(polypsrc->mainloop); + pa_threaded_mainloop_lock(pulsesrc->mainloop); - if (!polypsrc->context || pa_context_get_state(polypsrc->context) != PA_CONTEXT_READY) { - GST_ELEMENT_ERROR(polypsrc, RESOURCE, FAILED, ("Bad context state: %s", polypsrc->context ? pa_strerror(pa_context_errno(polypsrc->context)) : NULL), (NULL)); + if (!pulsesrc->context || pa_context_get_state(pulsesrc->context) != PA_CONTEXT_READY) { + GST_ELEMENT_ERROR(pulsesrc, RESOURCE, FAILED, ("Bad context state: %s", pulsesrc->context ? pa_strerror(pa_context_errno(pulsesrc->context)) : NULL), (NULL)); goto unlock_and_fail; } - if (!(polypsrc->stream = pa_stream_new(polypsrc->context, "Record Stream", &polypsrc->sample_spec, NULL))) { - GST_ELEMENT_ERROR(polypsrc, RESOURCE, FAILED, ("Failed to create stream: %s", pa_strerror(pa_context_errno(polypsrc->context))), (NULL)); + if (!(pulsesrc->stream = pa_stream_new(pulsesrc->context, "Record Stream", &pulsesrc->sample_spec, NULL))) { + GST_ELEMENT_ERROR(pulsesrc, RESOURCE, FAILED, ("Failed to create stream: %s", pa_strerror(pa_context_errno(pulsesrc->context))), (NULL)); goto unlock_and_fail; } - pa_stream_set_state_callback(polypsrc->stream, gst_polypsrc_stream_state_cb, polypsrc); - pa_stream_set_read_callback(polypsrc->stream, gst_polypsrc_stream_request_cb, polypsrc); + pa_stream_set_state_callback(pulsesrc->stream, gst_pulsesrc_stream_state_cb, pulsesrc); + pa_stream_set_read_callback(pulsesrc->stream, gst_pulsesrc_stream_request_cb, pulsesrc); memset(&buf_attr, 0, sizeof(buf_attr)); buf_attr.maxlength = spec->segtotal*spec->segsize*2; buf_attr.fragsize = spec->segsize; - if (pa_stream_connect_record(polypsrc->stream, polypsrc->device, &buf_attr, PA_STREAM_INTERPOLATE_TIMING|PA_STREAM_AUTO_TIMING_UPDATE|PA_STREAM_NOT_MONOTONOUS) < 0) { - GST_ELEMENT_ERROR(polypsrc, RESOURCE, FAILED, ("Failed to connect stream: %s", pa_strerror(pa_context_errno(polypsrc->context))), (NULL)); + if (pa_stream_connect_record(pulsesrc->stream, pulsesrc->device, &buf_attr, PA_STREAM_INTERPOLATE_TIMING|PA_STREAM_AUTO_TIMING_UPDATE|PA_STREAM_NOT_MONOTONOUS) < 0) { + GST_ELEMENT_ERROR(pulsesrc, RESOURCE, FAILED, ("Failed to connect stream: %s", pa_strerror(pa_context_errno(pulsesrc->context))), (NULL)); goto unlock_and_fail; } /* Wait until the stream is ready */ - pa_threaded_mainloop_wait(polypsrc->mainloop); + pa_threaded_mainloop_wait(pulsesrc->mainloop); - if (pa_stream_get_state(polypsrc->stream) != PA_STREAM_READY) { - GST_ELEMENT_ERROR(polypsrc, RESOURCE, FAILED, ("Failed to connect stream: %s", pa_strerror(pa_context_errno(polypsrc->context))), (NULL)); + if (pa_stream_get_state(pulsesrc->stream) != PA_STREAM_READY) { + GST_ELEMENT_ERROR(pulsesrc, RESOURCE, FAILED, ("Failed to connect stream: %s", pa_strerror(pa_context_errno(pulsesrc->context))), (NULL)); goto unlock_and_fail; } - pa_threaded_mainloop_unlock(polypsrc->mainloop); + pa_threaded_mainloop_unlock(pulsesrc->mainloop); - spec->bytes_per_sample = pa_frame_size(&polypsrc->sample_spec); + spec->bytes_per_sample = pa_frame_size(&pulsesrc->sample_spec); memset(spec->silence_sample, 0, spec->bytes_per_sample); return TRUE; unlock_and_fail: - pa_threaded_mainloop_unlock(polypsrc->mainloop); + pa_threaded_mainloop_unlock(pulsesrc->mainloop); return FALSE; } -static gboolean gst_polypsrc_unprepare(GstAudioSrc * asrc) { - GstPolypSrc *polypsrc = GST_POLYPSRC(asrc); +static gboolean gst_pulsesrc_unprepare(GstAudioSrc * asrc) { + GstPolypSrc *pulsesrc = GST_PULSESRC(asrc); - pa_threaded_mainloop_lock(polypsrc->mainloop); - gst_polypsrc_destroy_stream(polypsrc); + pa_threaded_mainloop_lock(pulsesrc->mainloop); + gst_pulsesrc_destroy_stream(pulsesrc); - pa_threaded_mainloop_unlock(polypsrc->mainloop); + pa_threaded_mainloop_unlock(pulsesrc->mainloop); - polypsrc->read_buffer = NULL; - polypsrc->read_buffer_length = 0; + pulsesrc->read_buffer = NULL; + pulsesrc->read_buffer_length = 0; return TRUE; } -#define CHECK_DEAD_GOTO(polypsrc, label) \ -if (!(polypsrc)->context || pa_context_get_state((polypsrc)->context) != PA_CONTEXT_READY || \ - !(polypsrc)->stream || pa_stream_get_state((polypsrc)->stream) != PA_STREAM_READY) { \ - GST_ELEMENT_ERROR((polypsrc), RESOURCE, FAILED, ("Disconnected: %s", (polypsrc)->context ? pa_strerror(pa_context_errno((polypsrc)->context)) : NULL), (NULL)); \ +#define CHECK_DEAD_GOTO(pulsesrc, label) \ +if (!(pulsesrc)->context || pa_context_get_state((pulsesrc)->context) != PA_CONTEXT_READY || \ + !(pulsesrc)->stream || pa_stream_get_state((pulsesrc)->stream) != PA_STREAM_READY) { \ + GST_ELEMENT_ERROR((pulsesrc), RESOURCE, FAILED, ("Disconnected: %s", (pulsesrc)->context ? pa_strerror(pa_context_errno((pulsesrc)->context)) : NULL), (NULL)); \ goto label; \ } -static guint gst_polypsrc_read(GstAudioSrc *asrc, gpointer data, guint length) { - GstPolypSrc *polypsrc = GST_POLYPSRC(asrc); +static guint gst_pulsesrc_read(GstAudioSrc *asrc, gpointer data, guint length) { + GstPolypSrc *pulsesrc = GST_PULSESRC(asrc); size_t sum = 0; - pa_threaded_mainloop_lock(polypsrc->mainloop); + pa_threaded_mainloop_lock(pulsesrc->mainloop); - CHECK_DEAD_GOTO(polypsrc, unlock_and_fail); + CHECK_DEAD_GOTO(pulsesrc, unlock_and_fail); while (length > 0) { size_t l; - if (!polypsrc->read_buffer) { + if (!pulsesrc->read_buffer) { for (;;) { - if (pa_stream_peek(polypsrc->stream, &polypsrc->read_buffer, &polypsrc->read_buffer_length) < 0) { - GST_ELEMENT_ERROR(polypsrc, RESOURCE, FAILED, ("pa_stream_peek() failed: %s", pa_strerror(pa_context_errno(polypsrc->context))), (NULL)); + if (pa_stream_peek(pulsesrc->stream, &pulsesrc->read_buffer, &pulsesrc->read_buffer_length) < 0) { + GST_ELEMENT_ERROR(pulsesrc, RESOURCE, FAILED, ("pa_stream_peek() failed: %s", pa_strerror(pa_context_errno(pulsesrc->context))), (NULL)); goto unlock_and_fail; } - if (polypsrc->read_buffer) + if (pulsesrc->read_buffer) break; - pa_threaded_mainloop_wait(polypsrc->mainloop); + pa_threaded_mainloop_wait(pulsesrc->mainloop); - CHECK_DEAD_GOTO(polypsrc, unlock_and_fail); + CHECK_DEAD_GOTO(pulsesrc, unlock_and_fail); } } - g_assert(polypsrc->read_buffer && polypsrc->read_buffer_length); + g_assert(pulsesrc->read_buffer && pulsesrc->read_buffer_length); - l = polypsrc->read_buffer_length > length ? length : polypsrc->read_buffer_length; + l = pulsesrc->read_buffer_length > length ? length : pulsesrc->read_buffer_length; - memcpy(data, polypsrc->read_buffer, l); + memcpy(data, pulsesrc->read_buffer, l); - polypsrc->read_buffer = (const guint8*) polypsrc->read_buffer + l; - polypsrc->read_buffer_length -= l; + pulsesrc->read_buffer = (const guint8*) pulsesrc->read_buffer + l; + pulsesrc->read_buffer_length -= l; data = (guint8*) data + l; length -= l; sum += l; - if (polypsrc->read_buffer_length <= 0) { + if (pulsesrc->read_buffer_length <= 0) { - if (pa_stream_drop(polypsrc->stream) < 0) { - GST_ELEMENT_ERROR(polypsrc, RESOURCE, FAILED, ("pa_stream_drop() failed: %s", pa_strerror(pa_context_errno(polypsrc->context))), (NULL)); + if (pa_stream_drop(pulsesrc->stream) < 0) { + GST_ELEMENT_ERROR(pulsesrc, RESOURCE, FAILED, ("pa_stream_drop() failed: %s", pa_strerror(pa_context_errno(pulsesrc->context))), (NULL)); goto unlock_and_fail; } - polypsrc->read_buffer = NULL; - polypsrc->read_buffer_length = 0; + pulsesrc->read_buffer = NULL; + pulsesrc->read_buffer_length = 0; } } - pa_threaded_mainloop_unlock(polypsrc->mainloop); + pa_threaded_mainloop_unlock(pulsesrc->mainloop); return sum; unlock_and_fail: - pa_threaded_mainloop_unlock(polypsrc->mainloop); + pa_threaded_mainloop_unlock(pulsesrc->mainloop); return 0; } -static guint gst_polypsrc_delay(GstAudioSrc *asrc) { - GstPolypSrc *polypsrc = GST_POLYPSRC(asrc); +static guint gst_pulsesrc_delay(GstAudioSrc *asrc) { + GstPolypSrc *pulsesrc = GST_PULSESRC(asrc); pa_usec_t t; int negative; - pa_threaded_mainloop_lock(polypsrc->mainloop); + pa_threaded_mainloop_lock(pulsesrc->mainloop); - CHECK_DEAD_GOTO(polypsrc, unlock_and_fail); + CHECK_DEAD_GOTO(pulsesrc, unlock_and_fail); - if (pa_stream_get_latency(polypsrc->stream, &t, &negative) < 0) { + if (pa_stream_get_latency(pulsesrc->stream, &t, &negative) < 0) { - if (pa_context_errno(polypsrc->context) != PA_ERR_NODATA) { - GST_ELEMENT_ERROR(polypsrc, RESOURCE, FAILED, ("pa_stream_get_latency() failed: %s", pa_strerror(pa_context_errno(polypsrc->context))), (NULL)); + if (pa_context_errno(pulsesrc->context) != PA_ERR_NODATA) { + GST_ELEMENT_ERROR(pulsesrc, RESOURCE, FAILED, ("pa_stream_get_latency() failed: %s", pa_strerror(pa_context_errno(pulsesrc->context))), (NULL)); goto unlock_and_fail; } @@ -546,31 +546,31 @@ static guint gst_polypsrc_delay(GstAudioSrc *asrc) { } else if (negative) t = 0; - pa_threaded_mainloop_unlock(polypsrc->mainloop); + pa_threaded_mainloop_unlock(pulsesrc->mainloop); - return (guint) ((t * polypsrc->sample_spec.rate) / 1000000LL); + return (guint) ((t * pulsesrc->sample_spec.rate) / 1000000LL); unlock_and_fail: - pa_threaded_mainloop_unlock(polypsrc->mainloop); + pa_threaded_mainloop_unlock(pulsesrc->mainloop); return 0; } -static GstStateChangeReturn gst_polypsrc_change_state(GstElement *element, GstStateChange transition) { - GstPolypSrc *this = GST_POLYPSRC(element); +static GstStateChangeReturn gst_pulsesrc_change_state(GstElement *element, GstStateChange transition) { + GstPolypSrc *this = GST_PULSESRC(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); + this->mixer = gst_pulsemixer_ctrl_new(this->server, this->device, GST_PULSEMIXER_SOURCE); break; case GST_STATE_CHANGE_READY_TO_NULL: if (this->mixer) { - gst_polypmixer_ctrl_free(this->mixer); + gst_pulsemixer_ctrl_free(this->mixer); this->mixer = NULL; } @@ -586,31 +586,31 @@ static GstStateChangeReturn gst_polypsrc_change_state(GstElement *element, GstSt return GST_STATE_CHANGE_SUCCESS; } -GType gst_polypsrc_get_type(void) { - static GType polypsrc_type = 0; +GType gst_pulsesrc_get_type(void) { + static GType pulsesrc_type = 0; - if (!polypsrc_type) { + if (!pulsesrc_type) { - static const GTypeInfo polypsrc_info = { + static const GTypeInfo pulsesrc_info = { sizeof(GstPolypSrcClass), - gst_polypsrc_base_init, + gst_pulsesrc_base_init, NULL, - gst_polypsrc_class_init, + gst_pulsesrc_class_init, NULL, NULL, sizeof(GstPolypSrc), 0, - gst_polypsrc_init, + gst_pulsesrc_init, }; - polypsrc_type = g_type_register_static( + pulsesrc_type = g_type_register_static( GST_TYPE_AUDIO_SRC, "GstPolypSrc", - &polypsrc_info, + &pulsesrc_info, 0); - gst_polypsrc_init_interfaces(polypsrc_type); + gst_pulsesrc_init_interfaces(pulsesrc_type); } - return polypsrc_type; + return pulsesrc_type; } |