From 218ba9bee9f7a1cee34e1963f6d0b2d75499e58e Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 9 May 2006 15:29:27 +0000 Subject: * 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 --- src/Makefile.am | 3 ++- src/polypsink.c | 36 +++++------------------------- src/polypsink.h | 2 +- src/polypsrc.c | 39 +++++++-------------------------- src/polypsrc.h | 2 +- src/polyputil.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/polyputil.h | 33 ++++++++++++++++++++++++++++ 7 files changed, 119 insertions(+), 64 deletions(-) create mode 100644 src/polyputil.c create mode 100644 src/polyputil.h 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 #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 -#include +#include #include #include 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 #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 -#include +#include #include #include 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 +#include +#include + +gboolean gst_polyp_fill_sample_spec(GstRingBufferSpec *spec, pa_sample_spec *ss); + +gchar *gst_polyp_client_name(void); + +#endif -- cgit