summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2007-10-21 20:51:26 +0000
committerLennart Poettering <lennart@poettering.net>2007-10-21 20:51:26 +0000
commit149a0d67a230fb5f4188f64c5e57b1917268f19f (patch)
treee42f4f7af8e00e4cc35cc4403029ada82a038bf9
parent45e26ca4d8afa5ecb1ed698fa05eb0223aac008e (diff)
multi channel support, contributed by Rob Taylor
git-svn-id: file:///home/lennart/svn/public/gst-pulse/trunk@68 bb39ca4e-bce3-0310-b5d4-eea78a553289
-rw-r--r--src/pulsesink.c3
-rw-r--r--src/pulseutil.c64
-rw-r--r--src/pulseutil.h2
3 files changed, 64 insertions, 5 deletions
diff --git a/src/pulsesink.c b/src/pulsesink.c
index cc4e788..04b10be 100644
--- a/src/pulsesink.c
+++ b/src/pulsesink.c
@@ -358,6 +358,7 @@ static gboolean gst_pulsesink_close(GstAudioSink *asink) {
static gboolean gst_pulsesink_prepare(GstAudioSink *asink, GstRingBufferSpec *spec) {
pa_buffer_attr buf_attr;
+ pa_channel_map channel_map;
GstPulseSink *pulsesink = GST_PULSESINK(asink);
@@ -373,7 +374,7 @@ static gboolean gst_pulsesink_prepare(GstAudioSink *asink, GstRingBufferSpec *sp
goto unlock_and_fail;
}
- if (!(pulsesink->stream = pa_stream_new(pulsesink->context, pulsesink->stream_name ? pulsesink->stream_name : "Playback Stream", &pulsesink->sample_spec, NULL))) {
+ if (!(pulsesink->stream = pa_stream_new(pulsesink->context, pulsesink->stream_name ? pulsesink->stream_name : "Playback Stream", &pulsesink->sample_spec, gst_pulse_gst_to_channel_map(&channel_map,spec)))) {
GST_ELEMENT_ERROR(pulsesink, RESOURCE, FAILED, ("Failed to create stream: %s", pa_strerror(pa_context_errno(pulsesink->context))), (NULL));
goto unlock_and_fail;
}
diff --git a/src/pulseutil.c b/src/pulseutil.c
index e25a238..c872236 100644
--- a/src/pulseutil.c
+++ b/src/pulseutil.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
@@ -24,6 +24,24 @@
#endif
#include "pulseutil.h"
+#include <gst/audio/multichannel.h>
+
+
+static pa_channel_position_t gst_pos_to_pa[GST_AUDIO_CHANNEL_POSITION_NUM] = {
+ [GST_AUDIO_CHANNEL_POSITION_FRONT_MONO] = PA_CHANNEL_POSITION_MONO,
+ [GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT] = PA_CHANNEL_POSITION_FRONT_LEFT,
+ [GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT] = PA_CHANNEL_POSITION_FRONT_RIGHT,
+ [GST_AUDIO_CHANNEL_POSITION_REAR_CENTER] = PA_CHANNEL_POSITION_REAR_CENTER,
+ [GST_AUDIO_CHANNEL_POSITION_REAR_LEFT] = PA_CHANNEL_POSITION_REAR_LEFT,
+ [GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT] = PA_CHANNEL_POSITION_REAR_RIGHT,
+ [GST_AUDIO_CHANNEL_POSITION_LFE] = PA_CHANNEL_POSITION_LFE,
+ [GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER] = PA_CHANNEL_POSITION_FRONT_CENTER,
+ [GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT_OF_CENTER] = PA_CHANNEL_POSITION_FRONT_LEFT_OF_CENTER,
+ [GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT_OF_CENTER] = PA_CHANNEL_POSITION_FRONT_RIGHT_OF_CENTER,
+ [GST_AUDIO_CHANNEL_POSITION_SIDE_LEFT] = PA_CHANNEL_POSITION_SIDE_LEFT,
+ [GST_AUDIO_CHANNEL_POSITION_SIDE_RIGHT] = PA_CHANNEL_POSITION_SIDE_RIGHT,
+ [GST_AUDIO_CHANNEL_POSITION_NONE] = PA_CHANNEL_POSITION_INVALID
+};
gboolean gst_pulse_fill_sample_spec(GstRingBufferSpec *spec, pa_sample_spec *ss) {
@@ -56,7 +74,7 @@ gboolean gst_pulse_fill_sample_spec(GstRingBufferSpec *spec, pa_sample_spec *ss)
gchar *gst_pulse_client_name(void) {
gchar buf[PATH_MAX];
const char *c;
-
+
if ((c = g_get_application_name()))
return g_strdup_printf("%s", c);
else if (pa_get_binary_name(buf, sizeof(buf)))
@@ -64,3 +82,41 @@ gchar *gst_pulse_client_name(void) {
else
return g_strdup("GStreamer");
}
+
+pa_channel_map* gst_pulse_gst_to_channel_map(pa_channel_map* map, GstRingBufferSpec *spec) {
+ int i;
+ GstAudioChannelPosition* pos;
+
+ pa_channel_map_init(map);
+
+ if (!(pos = gst_audio_get_channel_positions(gst_caps_get_structure(spec->caps, 0)))) {
+/* g_debug("%s: No channel positions!\n", G_STRFUNC); */
+ return NULL;
+ }
+
+/* g_debug("%s: Got channel positions:\n", G_STRFUNC); */
+
+ for (i = 0; i < spec->channels; i++) {
+
+ if (pos[i] == GST_AUDIO_CHANNEL_POSITION_NONE) {
+ /* no valid mappings for these channels */
+ g_free(pos);
+ return NULL;
+ } else if (pos[i] < GST_AUDIO_CHANNEL_POSITION_NUM)
+ map->map[i] = gst_pos_to_pa[pos[i]];
+ else
+ map->map[i] = PA_CHANNEL_POSITION_INVALID;
+
+/* g_debug(" channel %d: gst: %d pulse: %d\n", i, pos[i], papos); */
+ }
+
+ g_free(pos);
+ map->channels = spec->channels;
+
+ if (!pa_channel_map_valid(map)) {
+/* g_debug("generated invalid map!\n"); */
+ return NULL;
+ }
+
+ return map;
+}
diff --git a/src/pulseutil.h b/src/pulseutil.h
index 8cd6a5c..2df29bb 100644
--- a/src/pulseutil.h
+++ b/src/pulseutil.h
@@ -30,4 +30,6 @@ gboolean gst_pulse_fill_sample_spec(GstRingBufferSpec *spec, pa_sample_spec *ss)
gchar *gst_pulse_client_name(void);
+pa_channel_map* gst_pulse_gst_to_channel_map (pa_channel_map* map, GstRingBufferSpec *spec);
+
#endif