summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2006-05-09 15:29:27 +0000
committerLennart Poettering <lennart@poettering.net>2006-05-09 15:29:27 +0000
commit218ba9bee9f7a1cee34e1963f6d0b2d75499e58e (patch)
tree3a63894d7c0fd8f75e3ec5850918a193aa77c0b8
parent007f36899a324c678270a6e924393aa22495bc3f (diff)
* use the same gst_polyp_fill_sample_spec() implementation by both the sink and the source
* pass a sensible client name to Polypaudio git-svn-id: file:///home/lennart/svn/public/gst-pulse/trunk@18 bb39ca4e-bce3-0310-b5d4-eea78a553289
-rw-r--r--src/Makefile.am3
-rw-r--r--src/polypsink.c36
-rw-r--r--src/polypsink.h2
-rw-r--r--src/polypsrc.c39
-rw-r--r--src/polypsrc.h2
-rw-r--r--src/polyputil.c68
-rw-r--r--src/polyputil.h33
7 files changed, 119 insertions, 64 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 7adbffd..bb55802 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -22,7 +22,8 @@ pkglib_LTLIBRARIES = libgstpolyp.la
libgstpolyp_la_SOURCES = \
plugin.c \
polypsink.c polypsink.h \
- polypsrc.c polypsrc.h
+ polypsrc.c polypsrc.h \
+ polyputil.c polyputil.h
libgstpolyp_la_CFLAGS = $(GST_CFLAGS) $(POLYP_CFLAGS)
libgstpolyp_la_LIBADD = $(POLYP_LIBS) $(GST_LIBS) -lgstaudio-0.10
diff --git a/src/polypsink.c b/src/polypsink.c
index 8859edb..e154e37 100644
--- a/src/polypsink.c
+++ b/src/polypsink.c
@@ -30,6 +30,7 @@
#include <gst/gsttaglist.h>
#include "polypsink.h"
+#include "polyputil.h"
GST_DEBUG_CATEGORY_EXTERN(polyp_debug);
#define GST_CAT_DEFAULT polyp_debug
@@ -306,10 +307,11 @@ static void gst_polypsink_stream_request_cb(pa_stream *s, size_t length, void *u
static gboolean gst_polypsink_open(GstAudioSink *asink) {
GstPolypSink *polypsink = GST_POLYPSINK(asink);
+ gchar *name = gst_polyp_client_name();
pa_threaded_mainloop_lock(polypsink->mainloop);
- if (!(polypsink->context = pa_context_new(pa_threaded_mainloop_get_api(polypsink->mainloop), "gstreamer"))) {
+ if (!(polypsink->context = pa_context_new(pa_threaded_mainloop_get_api(polypsink->mainloop), name))) {
GST_ELEMENT_ERROR(polypsink, RESOURCE, FAILED, ("Failed to create context"), (NULL));
goto unlock_and_fail;
}
@@ -330,11 +332,13 @@ static gboolean gst_polypsink_open(GstAudioSink *asink) {
}
pa_threaded_mainloop_unlock(polypsink->mainloop);
+ g_free(name);
return TRUE;
unlock_and_fail:
pa_threaded_mainloop_unlock(polypsink->mainloop);
+ g_free(name);
return FALSE;
}
@@ -348,40 +352,12 @@ static gboolean gst_polypsink_close(GstAudioSink *asink) {
return TRUE;
}
-static gboolean gst_polypsink_fill_sample_spec(GstRingBufferSpec *spec, pa_sample_spec *ss) {
-
- if (spec->format == GST_MU_LAW && spec->width == 8)
- ss->format = PA_SAMPLE_ULAW;
- else if (spec->format == GST_A_LAW && spec->width == 8)
- ss->format = PA_SAMPLE_ALAW;
- else if (spec->format == GST_U8 && spec->width == 8)
- ss->format = PA_SAMPLE_U8;
- else if (spec->format == GST_S16_LE && spec->width == 16)
- ss->format = PA_SAMPLE_S16LE;
- else if (spec->format == GST_S16_BE && spec->width == 16)
- ss->format = PA_SAMPLE_S16BE;
- else if (spec->format == GST_FLOAT32_LE && spec->width == 32)
- ss->format = PA_SAMPLE_FLOAT32LE;
- else if (spec->format == GST_FLOAT32_BE && spec->width == 32)
- ss->format = PA_SAMPLE_FLOAT32BE;
- else
- return FALSE;
-
- ss->channels = spec->channels;
- ss->rate = spec->rate;
-
- if (!pa_sample_spec_valid(ss))
- return FALSE;
-
- return TRUE;
-}
-
static gboolean gst_polypsink_prepare(GstAudioSink *asink, GstRingBufferSpec *spec) {
pa_buffer_attr buf_attr;
GstPolypSink *polypsink = GST_POLYPSINK(asink);
- if (!gst_polypsink_fill_sample_spec(spec, &polypsink->sample_spec)) {
+ if (!gst_polyp_fill_sample_spec(spec, &polypsink->sample_spec)) {
GST_ELEMENT_ERROR(polypsink, RESOURCE, SETTINGS, ("Invalid sample specification."), (NULL));
goto unlock_and_fail;
}
diff --git a/src/polypsink.h b/src/polypsink.h
index e5e98d0..e66169e 100644
--- a/src/polypsink.h
+++ b/src/polypsink.h
@@ -23,7 +23,7 @@
***/
#include <gst/gst.h>
-#include </usr/include/gstreamer-0.10/gst/audio/gstaudiosink.h>
+#include <gst/audio/gstaudiosink.h>
#include <polyp/polypaudio.h>
#include <polyp/thread-mainloop.h>
diff --git a/src/polypsrc.c b/src/polypsrc.c
index b396e3d..a790e6d 100644
--- a/src/polypsrc.c
+++ b/src/polypsrc.c
@@ -30,6 +30,7 @@
#include <gst/gsttaglist.h>
#include "polypsrc.h"
+#include "polyputil.h"
GST_DEBUG_CATEGORY_EXTERN(polyp_debug);
#define GST_CAT_DEFAULT polyp_debug
@@ -298,10 +299,11 @@ static void gst_polypsrc_stream_request_cb(pa_stream *s, size_t length, void *us
static gboolean gst_polypsrc_open(GstAudioSrc *asrc) {
GstPolypSrc *polypsrc = GST_POLYPSRC(asrc);
+ gchar *name = gst_polyp_client_name();
pa_threaded_mainloop_lock(polypsrc->mainloop);
- if (!(polypsrc->context = pa_context_new(pa_threaded_mainloop_get_api(polypsrc->mainloop), "gstreamer"))) {
+ 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));
goto unlock_and_fail;
}
@@ -322,11 +324,15 @@ static gboolean gst_polypsrc_open(GstAudioSrc *asrc) {
}
pa_threaded_mainloop_unlock(polypsrc->mainloop);
+
+ g_free(name);
return TRUE;
unlock_and_fail:
pa_threaded_mainloop_unlock(polypsrc->mainloop);
+
+ g_free(name);
return FALSE;
}
@@ -339,41 +345,12 @@ static gboolean gst_polypsrc_close(GstAudioSrc *asrc) {
return TRUE;
}
-
-static gboolean gst_polypsrc_fill_sample_spec(GstRingBufferSpec *spec, pa_sample_spec *ss) {
-
- if (spec->format == GST_MU_LAW && spec->width == 8)
- ss->format = PA_SAMPLE_ULAW;
- else if (spec->format == GST_A_LAW && spec->width == 8)
- ss->format = PA_SAMPLE_ALAW;
- else if (spec->format == GST_U8 && spec->width == 8)
- ss->format = PA_SAMPLE_U8;
- else if (spec->format == GST_S16_LE && spec->width == 16)
- ss->format = PA_SAMPLE_S16LE;
- else if (spec->format == GST_S16_BE && spec->width == 16)
- ss->format = PA_SAMPLE_S16BE;
- else if (spec->format == GST_FLOAT32_LE && spec->width == 32)
- ss->format = PA_SAMPLE_FLOAT32LE;
- else if (spec->format == GST_FLOAT32_BE && spec->width == 32)
- ss->format = PA_SAMPLE_FLOAT32BE;
- else
- return FALSE;
-
- ss->channels = spec->channels;
- ss->rate = spec->rate;
-
- if (!pa_sample_spec_valid(ss))
- return FALSE;
-
- return TRUE;
-}
-
static gboolean gst_polypsrc_prepare(GstAudioSrc *asrc, GstRingBufferSpec *spec) {
pa_buffer_attr buf_attr;
GstPolypSrc *polypsrc = GST_POLYPSRC(asrc);
- if (!gst_polypsrc_fill_sample_spec(spec, &polypsrc->sample_spec)) {
+ if (!gst_polyp_fill_sample_spec(spec, &polypsrc->sample_spec)) {
GST_ELEMENT_ERROR(polypsrc, RESOURCE, SETTINGS, ("Invalid sample specification."), (NULL));
goto unlock_and_fail;
}
diff --git a/src/polypsrc.h b/src/polypsrc.h
index c8339ee..0f77c8f 100644
--- a/src/polypsrc.h
+++ b/src/polypsrc.h
@@ -23,7 +23,7 @@
***/
#include <gst/gst.h>
-#include </usr/include/gstreamer-0.10/gst/audio/gstaudiosrc.h>
+#include <gst/audio/gstaudiosrc.h>
#include <polyp/polypaudio.h>
#include <polyp/thread-mainloop.h>
diff --git a/src/polyputil.c b/src/polyputil.c
new file mode 100644
index 0000000..30dbe08
--- /dev/null
+++ b/src/polyputil.c
@@ -0,0 +1,68 @@
+/* $Id$ */
+
+/***
+ This file is part of gst-polyp.
+
+ gst-polyp 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
+ 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
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ USA.
+***/
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "polyputil.h"
+
+gboolean gst_polyp_fill_sample_spec(GstRingBufferSpec *spec, pa_sample_spec *ss) {
+
+ if (spec->format == GST_MU_LAW && spec->width == 8)
+ ss->format = PA_SAMPLE_ULAW;
+ else if (spec->format == GST_A_LAW && spec->width == 8)
+ ss->format = PA_SAMPLE_ALAW;
+ else if (spec->format == GST_U8 && spec->width == 8)
+ ss->format = PA_SAMPLE_U8;
+ else if (spec->format == GST_S16_LE && spec->width == 16)
+ ss->format = PA_SAMPLE_S16LE;
+ else if (spec->format == GST_S16_BE && spec->width == 16)
+ ss->format = PA_SAMPLE_S16BE;
+ else if (spec->format == GST_FLOAT32_LE && spec->width == 32)
+ ss->format = PA_SAMPLE_FLOAT32LE;
+ else if (spec->format == GST_FLOAT32_BE && spec->width == 32)
+ ss->format = PA_SAMPLE_FLOAT32BE;
+ else
+ return FALSE;
+
+ ss->channels = spec->channels;
+ ss->rate = spec->rate;
+
+ if (!pa_sample_spec_valid(ss))
+ return FALSE;
+
+ return TRUE;
+}
+
+gchar *gst_polyp_client_name(void) {
+ gchar buf[64];
+
+ /* Dirty import form polyplib */
+ char *pa_get_binary_name(char *s, size_t l);
+ char *pa_path_get_filename(const char *p);
+
+ if (pa_get_binary_name(buf, sizeof(buf)))
+ return g_strdup_printf("gstreamer[%s]", pa_path_get_filename(buf));
+
+ else
+ return g_strdup("gstreamer");
+}
diff --git a/src/polyputil.h b/src/polyputil.h
new file mode 100644
index 0000000..b800bb2
--- /dev/null
+++ b/src/polyputil.h
@@ -0,0 +1,33 @@
+#ifndef __GST_POLYPUTIL_H__
+#define __GST_POLYPUTIL_H__
+
+/* $Id$ */
+
+/***
+ This file is part of gst-polyp.
+
+ gst-polyp 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
+ 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
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ USA.
+***/
+
+#include <gst/gst.h>
+#include <polyp/polypaudio.h>
+#include <gst/audio/gstaudiosink.h>
+
+gboolean gst_polyp_fill_sample_spec(GstRingBufferSpec *spec, pa_sample_spec *ss);
+
+gchar *gst_polyp_client_name(void);
+
+#endif