summaryrefslogtreecommitdiffstats
path: root/src/pulsesrc.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/pulsesrc.c')
-rw-r--r--src/pulsesrc.c88
1 files changed, 44 insertions, 44 deletions
diff --git a/src/pulsesrc.c b/src/pulsesrc.c
index a66acdc..faf6def 100644
--- a/src/pulsesrc.c
+++ b/src/pulsesrc.c
@@ -2,17 +2,17 @@
/***
This file is part of gst-pulse.
-
+
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-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-pulse; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
@@ -72,7 +72,7 @@ static GstStateChangeReturn gst_pulsesrc_change_state(GstElement *element, GstSt
static gboolean gst_pulsesrc_interface_supported(GstImplementsInterface* iface, GType interface_type) {
GstPulseSrc *this = GST_PULSESRC(iface);
-
+
if (interface_type == GST_TYPE_MIXER && this->mixer)
return TRUE;
@@ -94,7 +94,7 @@ static void gst_pulsesrc_init_interfaces(GType type) {
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);
}
@@ -113,7 +113,7 @@ static void gst_pulsesrc_base_init(gpointer g_class) {
"depth = (int) 16, "
"rate = (int) [ 1, MAX ], "
"channels = (int) [ 1, 16 ];"
-
+
"audio/x-raw-int, "
"signed = (boolean) FALSE, "
"width = (int) 8, "
@@ -136,7 +136,7 @@ static void gst_pulsesrc_base_init(gpointer g_class) {
"channels = (int) [ 1, 16 ]"
)
);
-
+
static const GstElementDetails details =
GST_ELEMENT_DETAILS(
"PulseAudio Audio Source",
@@ -145,7 +145,7 @@ static void gst_pulsesrc_base_init(gpointer g_class) {
"Lennart Poettering");
GstElementClass *element_class = GST_ELEMENT_CLASS(g_class);
-
+
gst_element_class_set_details(element_class, &details);
gst_element_class_add_pad_template(element_class, gst_static_pad_template_get(&pad_template));
}
@@ -153,7 +153,7 @@ static void gst_pulsesrc_base_init(gpointer g_class) {
static void gst_pulsesrc_class_init(
gpointer g_class,
gpointer class_data) {
-
+
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);
@@ -187,12 +187,12 @@ static void gst_pulsesrc_class_init(
static void gst_pulsesrc_init(
GTypeInstance * instance,
gpointer g_class) {
-
+
GstPulseSrc *pulsesrc = GST_PULSESRC(instance);
int e;
pulsesrc->server = pulsesrc->device = NULL;
-
+
pulsesrc->context = NULL;
pulsesrc->stream = NULL;
@@ -254,7 +254,7 @@ static void gst_pulsesrc_set_property(
guint prop_id,
const GValue * value,
GParamSpec * pspec) {
-
+
GstPulseSrc *pulsesrc = GST_PULSESRC(object);
switch (prop_id) {
@@ -279,7 +279,7 @@ static void gst_pulsesrc_get_property(
guint prop_id,
GValue * value,
GParamSpec * pspec) {
-
+
GstPulseSrc *pulsesrc = GST_PULSESRC(object);
switch(prop_id) {
@@ -350,7 +350,7 @@ static gboolean gst_pulsesrc_open(GstAudioSrc *asrc) {
}
pa_context_set_state_callback(pulsesrc->context, gst_pulsesrc_context_state_cb, pulsesrc);
-
+
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;
@@ -370,7 +370,7 @@ static gboolean gst_pulsesrc_open(GstAudioSrc *asrc) {
return TRUE;
unlock_and_fail:
-
+
pa_threaded_mainloop_unlock(pulsesrc->mainloop);
g_free(name);
@@ -388,7 +388,7 @@ static gboolean gst_pulsesrc_close(GstAudioSrc *asrc) {
}
static gboolean gst_pulsesrc_prepare(GstAudioSrc *asrc, GstRingBufferSpec *spec) {
pa_buffer_attr buf_attr;
-
+
GstPulseSrc *pulsesrc = GST_PULSESRC(asrc);
if (!gst_pulse_fill_sample_spec(spec, &pulsesrc->sample_spec)) {
@@ -402,7 +402,7 @@ static gboolean gst_pulsesrc_prepare(GstAudioSrc *asrc, GstRingBufferSpec *spec)
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 (!(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;
@@ -414,7 +414,7 @@ static gboolean gst_pulsesrc_prepare(GstAudioSrc *asrc, GstRingBufferSpec *spec)
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(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;
@@ -432,11 +432,11 @@ static gboolean gst_pulsesrc_prepare(GstAudioSrc *asrc, GstRingBufferSpec *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(pulsesrc->mainloop);
return FALSE;
}
@@ -451,7 +451,7 @@ static gboolean gst_pulsesrc_unprepare(GstAudioSrc * asrc) {
pulsesrc->read_buffer = NULL;
pulsesrc->read_buffer_length = 0;
-
+
return TRUE;
}
@@ -472,54 +472,54 @@ static guint gst_pulsesrc_read(GstAudioSrc *asrc, gpointer data, guint length) {
while (length > 0) {
size_t l;
-
+
if (!pulsesrc->read_buffer) {
-
+
for (;;) {
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 (pulsesrc->read_buffer)
break;
-
+
pa_threaded_mainloop_wait(pulsesrc->mainloop);
-
+
CHECK_DEAD_GOTO(pulsesrc, unlock_and_fail);
}
}
g_assert(pulsesrc->read_buffer && pulsesrc->read_buffer_length);
-
+
l = pulsesrc->read_buffer_length > length ? length : pulsesrc->read_buffer_length;
-
+
memcpy(data, pulsesrc->read_buffer, l);
-
+
pulsesrc->read_buffer = (const guint8*) pulsesrc->read_buffer + l;
pulsesrc->read_buffer_length -= l;
data = (guint8*) data + l;
length -= l;
-
+
sum += l;
if (pulsesrc->read_buffer_length <= 0) {
-
+
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;
}
-
+
pulsesrc->read_buffer = NULL;
pulsesrc->read_buffer_length = 0;
}
}
-
+
pa_threaded_mainloop_unlock(pulsesrc->mainloop);
-
+
return sum;
-
+
unlock_and_fail:
pa_threaded_mainloop_unlock(pulsesrc->mainloop);
return 0;
@@ -547,48 +547,48 @@ static guint gst_pulsesrc_delay(GstAudioSrc *asrc) {
t = 0;
pa_threaded_mainloop_unlock(pulsesrc->mainloop);
-
+
return (guint) ((t * pulsesrc->sample_spec.rate) / 1000000LL);
unlock_and_fail:
-
+
pa_threaded_mainloop_unlock(pulsesrc->mainloop);
return 0;
}
static GstStateChangeReturn gst_pulsesrc_change_state(GstElement *element, GstStateChange transition) {
GstPulseSrc *this = GST_PULSESRC(element);
-
+
switch (transition) {
case GST_STATE_CHANGE_NULL_TO_READY:
if (!this->mixer)
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_pulsemixer_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_pulsesrc_get_type(void) {
static GType pulsesrc_type = 0;
-
+
if (!pulsesrc_type) {
static const GTypeInfo pulsesrc_info = {