summaryrefslogtreecommitdiffstats
path: root/ext/pulse/pulseutil.c
diff options
context:
space:
mode:
authorSebastian Dröge <slomo@circular-chaos.org>2008-06-10 06:45:33 +0000
committerSebastian Dröge <slomo@circular-chaos.org>2008-06-10 06:45:33 +0000
commitf3b03cd77318bccf2fd0d724a3f3f6d457b4277f (patch)
tree70b67fcb0e3bea880994ff6d44e853495e3ea0fa /ext/pulse/pulseutil.c
parent660d958685e84e0334c038c03824de7ebee14ca7 (diff)
Add pulseaudio GStreamer element from gst-pulse. Development will continue here instead of pulseaudio SVN. Fixes bug ...
Original commit message from CVS: * configure.ac: * ext/pulse/Makefile.am: * ext/pulse/plugin.c: (plugin_init): * ext/pulse/pulsemixer.c: (gst_pulsemixer_interface_supported), (gst_pulsemixer_implements_interface_init), (gst_pulsemixer_init_interfaces), (gst_pulsemixer_base_init), (gst_pulsemixer_class_init), (gst_pulsemixer_init), (gst_pulsemixer_finalize), (gst_pulsemixer_set_property), (gst_pulsemixer_get_property), (gst_pulsemixer_change_state): * ext/pulse/pulsemixer.h: * ext/pulse/pulsemixerctrl.c: (gst_pulsemixer_ctrl_context_state_cb), (gst_pulsemixer_ctrl_sink_info_cb), (gst_pulsemixer_ctrl_source_info_cb), (gst_pulsemixer_ctrl_subscribe_cb), (gst_pulsemixer_ctrl_success_cb), (gst_pulsemixer_ctrl_open), (gst_pulsemixer_ctrl_close), (gst_pulsemixer_ctrl_new), (gst_pulsemixer_ctrl_free), (gst_pulsemixer_ctrl_list_tracks), (gst_pulsemixer_ctrl_timeout_event), (restart_time_event), (gst_pulsemixer_ctrl_set_volume), (gst_pulsemixer_ctrl_get_volume), (gst_pulsemixer_ctrl_set_record), (gst_pulsemixer_ctrl_set_mute): * ext/pulse/pulsemixerctrl.h: * ext/pulse/pulsemixertrack.c: (gst_pulsemixer_track_class_init), (gst_pulsemixer_track_init), (gst_pulsemixer_track_new): * ext/pulse/pulsemixertrack.h: * ext/pulse/pulseprobe.c: (gst_pulseprobe_context_state_cb), (gst_pulseprobe_sink_info_cb), (gst_pulseprobe_source_info_cb), (gst_pulseprobe_invalidate), (gst_pulseprobe_open), (gst_pulseprobe_enumerate), (gst_pulseprobe_close), (gst_pulseprobe_new), (gst_pulseprobe_free), (gst_pulseprobe_get_properties), (gst_pulseprobe_needs_probe), (gst_pulseprobe_probe_property), (gst_pulseprobe_get_values), (gst_pulseprobe_set_server): * ext/pulse/pulseprobe.h: * ext/pulse/pulsesink.c: (gst_pulsesink_base_init), (gst_pulsesink_class_init), (gst_pulsesink_init), (gst_pulsesink_destroy_stream), (gst_pulsesink_destroy_context), (gst_pulsesink_finalize), (gst_pulsesink_dispose), (gst_pulsesink_set_property), (gst_pulsesink_get_property), (gst_pulsesink_context_state_cb), (gst_pulsesink_stream_state_cb), (gst_pulsesink_stream_request_cb), (gst_pulsesink_stream_latency_update_cb), (gst_pulsesink_open), (gst_pulsesink_close), (gst_pulsesink_prepare), (gst_pulsesink_unprepare), (gst_pulsesink_write), (gst_pulsesink_delay), (gst_pulsesink_success_cb), (gst_pulsesink_reset), (gst_pulsesink_change_title), (gst_pulsesink_event), (gst_pulsesink_get_type): * ext/pulse/pulsesink.h: * ext/pulse/pulsesrc.c: (gst_pulsesrc_interface_supported), (gst_pulsesrc_implements_interface_init), (gst_pulsesrc_init_interfaces), (gst_pulsesrc_base_init), (gst_pulsesrc_class_init), (gst_pulsesrc_init), (gst_pulsesrc_destroy_stream), (gst_pulsesrc_destroy_context), (gst_pulsesrc_finalize), (gst_pulsesrc_dispose), (gst_pulsesrc_set_property), (gst_pulsesrc_get_property), (gst_pulsesrc_context_state_cb), (gst_pulsesrc_stream_state_cb), (gst_pulsesrc_stream_request_cb), (gst_pulsesrc_open), (gst_pulsesrc_close), (gst_pulsesrc_prepare), (gst_pulsesrc_unprepare), (gst_pulsesrc_read), (gst_pulsesrc_delay), (gst_pulsesrc_change_state), (gst_pulsesrc_get_type): * ext/pulse/pulsesrc.h: * ext/pulse/pulseutil.c: (gst_pulse_fill_sample_spec), (gst_pulse_client_name), (gst_pulse_gst_to_channel_map): * ext/pulse/pulseutil.h: Add pulseaudio GStreamer element from gst-pulse. Development will continue here instead of pulseaudio SVN. Fixes bug #400679. Only changes over gst-pulse SVN are added copyright to the top of files and coding style changes.
Diffstat (limited to 'ext/pulse/pulseutil.c')
-rw-r--r--ext/pulse/pulseutil.c138
1 files changed, 138 insertions, 0 deletions
diff --git a/ext/pulse/pulseutil.c b/ext/pulse/pulseutil.c
new file mode 100644
index 00000000..518bce2f
--- /dev/null
+++ b/ext/pulse/pulseutil.c
@@ -0,0 +1,138 @@
+/*
+ * GStreamer pulseaudio plugin
+ *
+ * Copyright (c) 2004-2008 Lennart Poettering
+ *
+ * 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
+ * USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "pulseutil.h"
+#include <gst/audio/multichannel.h>
+
+static const 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)
+{
+
+ 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 if (spec->format == GST_S32_LE && spec->width == 32)
+ ss->format = PA_SAMPLE_S32LE;
+ else if (spec->format == GST_S32_BE && spec->width == 32)
+ ss->format = PA_SAMPLE_S32BE;
+ else
+ return FALSE;
+
+ ss->channels = spec->channels;
+ ss->rate = spec->rate;
+
+ if (!pa_sample_spec_valid (ss))
+ return FALSE;
+
+ return TRUE;
+}
+
+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)))
+ return g_strdup_printf ("%s", buf);
+ 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], map->map[i]); */
+ }
+
+ g_free (pos);
+ map->channels = spec->channels;
+
+ if (!pa_channel_map_valid (map)) {
+/* g_debug("generated invalid map!\n"); */
+ return NULL;
+ }
+
+ return map;
+}