fix tabs
[gst-pulse.git] / src / pulseutil.c
blob36a21687ce1386251af40e8634588a1ece53581f
1 /* $Id$ */
3 /***
4 This file is part of gst-pulse.
6 gst-pulse is free software; you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as
8 published by the Free Software Foundation; either version 2.1 of the
9 License, or (at your option) any later version.
11 gst-pulse is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with gst-pulse; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19 USA.
20 ***/
22 #ifdef HAVE_CONFIG_H
23 #include "config.h"
24 #endif
26 #include "pulseutil.h"
27 #include <gst/audio/multichannel.h>
29 static pa_channel_position_t gst_pos_to_pa[GST_AUDIO_CHANNEL_POSITION_NUM] = {
30 [GST_AUDIO_CHANNEL_POSITION_FRONT_MONO] = PA_CHANNEL_POSITION_MONO,
31 [GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT] = PA_CHANNEL_POSITION_FRONT_LEFT,
32 [GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT] = PA_CHANNEL_POSITION_FRONT_RIGHT,
33 [GST_AUDIO_CHANNEL_POSITION_REAR_CENTER] = PA_CHANNEL_POSITION_REAR_CENTER,
34 [GST_AUDIO_CHANNEL_POSITION_REAR_LEFT] = PA_CHANNEL_POSITION_REAR_LEFT,
35 [GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT] = PA_CHANNEL_POSITION_REAR_RIGHT,
36 [GST_AUDIO_CHANNEL_POSITION_LFE] = PA_CHANNEL_POSITION_LFE,
37 [GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER] = PA_CHANNEL_POSITION_FRONT_CENTER,
38 [GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT_OF_CENTER] = PA_CHANNEL_POSITION_FRONT_LEFT_OF_CENTER,
39 [GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT_OF_CENTER] = PA_CHANNEL_POSITION_FRONT_RIGHT_OF_CENTER,
40 [GST_AUDIO_CHANNEL_POSITION_SIDE_LEFT] = PA_CHANNEL_POSITION_SIDE_LEFT,
41 [GST_AUDIO_CHANNEL_POSITION_SIDE_RIGHT] = PA_CHANNEL_POSITION_SIDE_RIGHT,
42 [GST_AUDIO_CHANNEL_POSITION_NONE] = PA_CHANNEL_POSITION_INVALID
45 gboolean gst_pulse_fill_sample_spec(GstRingBufferSpec *spec, pa_sample_spec *ss) {
47 if (spec->format == GST_MU_LAW && spec->width == 8)
48 ss->format = PA_SAMPLE_ULAW;
49 else if (spec->format == GST_A_LAW && spec->width == 8)
50 ss->format = PA_SAMPLE_ALAW;
51 else if (spec->format == GST_U8 && spec->width == 8)
52 ss->format = PA_SAMPLE_U8;
53 else if (spec->format == GST_S16_LE && spec->width == 16)
54 ss->format = PA_SAMPLE_S16LE;
55 else if (spec->format == GST_S16_BE && spec->width == 16)
56 ss->format = PA_SAMPLE_S16BE;
57 else if (spec->format == GST_FLOAT32_LE && spec->width == 32)
58 ss->format = PA_SAMPLE_FLOAT32LE;
59 else if (spec->format == GST_FLOAT32_BE && spec->width == 32)
60 ss->format = PA_SAMPLE_FLOAT32BE;
61 else
62 return FALSE;
64 ss->channels = spec->channels;
65 ss->rate = spec->rate;
67 if (!pa_sample_spec_valid(ss))
68 return FALSE;
70 return TRUE;
73 gchar *gst_pulse_client_name(void) {
74 gchar buf[PATH_MAX];
75 const char *c;
77 if ((c = g_get_application_name()))
78 return g_strdup_printf("%s", c);
79 else if (pa_get_binary_name(buf, sizeof(buf)))
80 return g_strdup_printf("%s", buf);
81 else
82 return g_strdup("GStreamer");
85 pa_channel_map* gst_pulse_gst_to_channel_map(pa_channel_map* map, GstRingBufferSpec *spec) {
86 int i;
87 GstAudioChannelPosition* pos;
89 pa_channel_map_init(map);
91 if (!(pos = gst_audio_get_channel_positions(gst_caps_get_structure(spec->caps, 0)))) {
92 /* g_debug("%s: No channel positions!\n", G_STRFUNC); */
93 return NULL;
96 /* g_debug("%s: Got channel positions:\n", G_STRFUNC); */
98 for (i = 0; i < spec->channels; i++) {
100 if (pos[i] == GST_AUDIO_CHANNEL_POSITION_NONE) {
101 /* no valid mappings for these channels */
102 g_free(pos);
103 return NULL;
104 } else if (pos[i] < GST_AUDIO_CHANNEL_POSITION_NUM)
105 map->map[i] = gst_pos_to_pa[pos[i]];
106 else
107 map->map[i] = PA_CHANNEL_POSITION_INVALID;
109 /*g_debug(" channel %d: gst: %d pulse: %d\n", i, pos[i], map->map[i]);*/
112 g_free(pos);
113 map->channels = spec->channels;
115 if (!pa_channel_map_valid(map)) {
116 /* g_debug("generated invalid map!\n"); */
117 return NULL;
120 return map;