summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--backends/pulse/pulse-ext-stream.c15
-rw-r--r--backends/pulse/pulse-helpers.c91
-rw-r--r--backends/pulse/pulse-helpers.h6
-rw-r--r--backends/pulse/pulse-stream-control.c15
4 files changed, 61 insertions, 66 deletions
diff --git a/backends/pulse/pulse-ext-stream.c b/backends/pulse/pulse-ext-stream.c
index 8e503b2..5922ef5 100644
--- a/backends/pulse/pulse-ext-stream.c
+++ b/backends/pulse/pulse-ext-stream.c
@@ -524,15 +524,17 @@ pulse_ext_stream_get_channel_position (MateMixerStreamControl *mmsc, guint chann
if (channel >= ext->priv->channel_map.channels)
return MATE_MIXER_CHANNEL_UNKNOWN;
- return pulse_convert_position_from_pulse (ext->priv->channel_map.map[channel]);
+ if (ext->priv->channel_map.map[channel] == PA_CHANNEL_POSITION_INVALID)
+ return MATE_MIXER_CHANNEL_UNKNOWN;
+
+ return pulse_channel_map_from[ext->priv->channel_map.map[channel]];
}
static gboolean
pulse_ext_stream_has_channel_position (MateMixerStreamControl *mmsc,
MateMixerChannelPosition position)
{
- PulseExtStream *ext;
- pa_channel_position_t p;
+ PulseExtStream *ext;
g_return_val_if_fail (PULSE_IS_EXT_STREAM (mmsc), FALSE);
@@ -540,12 +542,11 @@ pulse_ext_stream_has_channel_position (MateMixerStreamControl *mmsc,
/* Handle invalid position as a special case, otherwise this function would
* return TRUE for e.g. unknown index in a default channel map */
- p = pulse_convert_position_to_pulse (position);
-
- if (p == PA_CHANNEL_POSITION_INVALID)
+ if (pulse_channel_map_to[position] == PA_CHANNEL_POSITION_INVALID)
return FALSE;
- if (pa_channel_map_has_position (&ext->priv->channel_map, p) != 0)
+ if (pa_channel_map_has_position (&ext->priv->channel_map,
+ pulse_channel_map_to[position]) != 0)
return TRUE;
else
return FALSE;
diff --git a/backends/pulse/pulse-helpers.c b/backends/pulse/pulse-helpers.c
index 73f8cdb..671c3e2 100644
--- a/backends/pulse/pulse-helpers.c
+++ b/backends/pulse/pulse-helpers.c
@@ -24,58 +24,51 @@
#include "pulse-helpers.h"
-typedef struct {
- MateMixerChannelPosition mm_position;
- pa_channel_position_t pa_position;
-} PositionMap;
-
-// XXX optimize
-static PositionMap const position_map[] = {
- { MATE_MIXER_CHANNEL_UNKNOWN, PA_CHANNEL_POSITION_INVALID },
- { MATE_MIXER_CHANNEL_MONO, PA_CHANNEL_POSITION_MONO },
- { MATE_MIXER_CHANNEL_FRONT_LEFT, PA_CHANNEL_POSITION_FRONT_LEFT },
- { MATE_MIXER_CHANNEL_FRONT_RIGHT, PA_CHANNEL_POSITION_FRONT_RIGHT },
- { MATE_MIXER_CHANNEL_FRONT_CENTER, PA_CHANNEL_POSITION_FRONT_CENTER },
- { MATE_MIXER_CHANNEL_LFE, PA_CHANNEL_POSITION_LFE },
- { MATE_MIXER_CHANNEL_BACK_LEFT, PA_CHANNEL_POSITION_REAR_LEFT },
- { MATE_MIXER_CHANNEL_BACK_RIGHT, PA_CHANNEL_POSITION_REAR_RIGHT },
- { MATE_MIXER_CHANNEL_BACK_CENTER, PA_CHANNEL_POSITION_REAR_CENTER },
- { MATE_MIXER_CHANNEL_FRONT_LEFT_CENTER, PA_CHANNEL_POSITION_FRONT_LEFT_OF_CENTER },
- { MATE_MIXER_CHANNEL_FRONT_RIGHT_CENTER, PA_CHANNEL_POSITION_FRONT_RIGHT_OF_CENTER },
- { MATE_MIXER_CHANNEL_SIDE_LEFT, PA_CHANNEL_POSITION_SIDE_LEFT },
- { MATE_MIXER_CHANNEL_SIDE_RIGHT, PA_CHANNEL_POSITION_SIDE_RIGHT },
- { MATE_MIXER_CHANNEL_TOP_FRONT_LEFT, PA_CHANNEL_POSITION_TOP_FRONT_LEFT },
- { MATE_MIXER_CHANNEL_TOP_FRONT_RIGHT, PA_CHANNEL_POSITION_TOP_FRONT_RIGHT },
- { MATE_MIXER_CHANNEL_TOP_FRONT_CENTER, PA_CHANNEL_POSITION_TOP_FRONT_CENTER },
- { MATE_MIXER_CHANNEL_TOP_CENTER, PA_CHANNEL_POSITION_TOP_CENTER },
- { MATE_MIXER_CHANNEL_TOP_BACK_LEFT, PA_CHANNEL_POSITION_TOP_REAR_LEFT },
- { MATE_MIXER_CHANNEL_TOP_BACK_RIGHT, PA_CHANNEL_POSITION_TOP_REAR_RIGHT },
- { MATE_MIXER_CHANNEL_TOP_BACK_CENTER, PA_CHANNEL_POSITION_TOP_REAR_CENTER },
-};
-
-MateMixerChannelPosition
-pulse_convert_position_from_pulse (pa_channel_position_t position)
+const MateMixerChannelPosition pulse_channel_map_from[PA_CHANNEL_POSITION_MAX] =
{
- guint i;
-
- for (i = 0; i < G_N_ELEMENTS (position_map); i++) {
- if (position == position_map[i].pa_position)
- return position_map[i].mm_position;
- }
- return MATE_MIXER_CHANNEL_UNKNOWN;
-}
+ [PA_CHANNEL_POSITION_MONO] = MATE_MIXER_CHANNEL_MONO,
+ [PA_CHANNEL_POSITION_FRONT_LEFT] = MATE_MIXER_CHANNEL_FRONT_LEFT,
+ [PA_CHANNEL_POSITION_FRONT_RIGHT] = MATE_MIXER_CHANNEL_FRONT_RIGHT,
+ [PA_CHANNEL_POSITION_FRONT_CENTER] = MATE_MIXER_CHANNEL_FRONT_CENTER,
+ [PA_CHANNEL_POSITION_LFE] = MATE_MIXER_CHANNEL_LFE,
+ [PA_CHANNEL_POSITION_REAR_LEFT] = MATE_MIXER_CHANNEL_BACK_LEFT,
+ [PA_CHANNEL_POSITION_REAR_RIGHT] = MATE_MIXER_CHANNEL_BACK_RIGHT,
+ [PA_CHANNEL_POSITION_FRONT_LEFT_OF_CENTER] = MATE_MIXER_CHANNEL_FRONT_LEFT_CENTER,
+ [PA_CHANNEL_POSITION_FRONT_RIGHT_OF_CENTER] = MATE_MIXER_CHANNEL_FRONT_RIGHT_CENTER,
+ [PA_CHANNEL_POSITION_SIDE_LEFT] = MATE_MIXER_CHANNEL_SIDE_LEFT,
+ [PA_CHANNEL_POSITION_SIDE_RIGHT] = MATE_MIXER_CHANNEL_SIDE_RIGHT,
+ [PA_CHANNEL_POSITION_TOP_FRONT_LEFT] = MATE_MIXER_CHANNEL_TOP_FRONT_LEFT,
+ [PA_CHANNEL_POSITION_TOP_FRONT_RIGHT] = MATE_MIXER_CHANNEL_TOP_FRONT_RIGHT,
+ [PA_CHANNEL_POSITION_TOP_FRONT_CENTER] = MATE_MIXER_CHANNEL_TOP_FRONT_CENTER,
+ [PA_CHANNEL_POSITION_TOP_CENTER] = MATE_MIXER_CHANNEL_TOP_CENTER,
+ [PA_CHANNEL_POSITION_TOP_REAR_LEFT] = MATE_MIXER_CHANNEL_TOP_BACK_LEFT,
+ [PA_CHANNEL_POSITION_TOP_REAR_RIGHT] = MATE_MIXER_CHANNEL_TOP_BACK_RIGHT,
+ [PA_CHANNEL_POSITION_TOP_REAR_CENTER] = MATE_MIXER_CHANNEL_TOP_BACK_CENTER
+};
-pa_channel_position_t
-pulse_convert_position_to_pulse (MateMixerChannelPosition position)
+const pa_channel_position_t pulse_channel_map_to[MATE_MIXER_CHANNEL_MAX] =
{
- guint i;
-
- for (i = 0; i < G_N_ELEMENTS (position_map); i++) {
- if (position == position_map[i].mm_position)
- return position_map[i].pa_position;
- }
- return PA_CHANNEL_POSITION_INVALID;
-}
+ [MATE_MIXER_CHANNEL_UNKNOWN] = PA_CHANNEL_POSITION_INVALID,
+ [MATE_MIXER_CHANNEL_MONO] = PA_CHANNEL_POSITION_MONO,
+ [MATE_MIXER_CHANNEL_FRONT_LEFT] = PA_CHANNEL_POSITION_FRONT_LEFT,
+ [MATE_MIXER_CHANNEL_FRONT_RIGHT] = PA_CHANNEL_POSITION_FRONT_RIGHT,
+ [MATE_MIXER_CHANNEL_FRONT_CENTER] = PA_CHANNEL_POSITION_FRONT_CENTER,
+ [MATE_MIXER_CHANNEL_LFE] = PA_CHANNEL_POSITION_LFE,
+ [MATE_MIXER_CHANNEL_BACK_LEFT] = PA_CHANNEL_POSITION_REAR_LEFT,
+ [MATE_MIXER_CHANNEL_BACK_RIGHT] = PA_CHANNEL_POSITION_REAR_RIGHT,
+ [MATE_MIXER_CHANNEL_BACK_CENTER] = PA_CHANNEL_POSITION_REAR_CENTER,
+ [MATE_MIXER_CHANNEL_FRONT_LEFT_CENTER] = PA_CHANNEL_POSITION_FRONT_LEFT_OF_CENTER,
+ [MATE_MIXER_CHANNEL_FRONT_RIGHT_CENTER] = PA_CHANNEL_POSITION_FRONT_RIGHT_OF_CENTER,
+ [MATE_MIXER_CHANNEL_SIDE_LEFT] = PA_CHANNEL_POSITION_SIDE_LEFT,
+ [MATE_MIXER_CHANNEL_SIDE_RIGHT] = PA_CHANNEL_POSITION_SIDE_RIGHT,
+ [MATE_MIXER_CHANNEL_TOP_FRONT_LEFT] = PA_CHANNEL_POSITION_TOP_FRONT_LEFT,
+ [MATE_MIXER_CHANNEL_TOP_FRONT_RIGHT] = PA_CHANNEL_POSITION_TOP_FRONT_RIGHT,
+ [MATE_MIXER_CHANNEL_TOP_FRONT_CENTER] = PA_CHANNEL_POSITION_TOP_FRONT_CENTER,
+ [MATE_MIXER_CHANNEL_TOP_CENTER] = PA_CHANNEL_POSITION_TOP_CENTER,
+ [MATE_MIXER_CHANNEL_TOP_BACK_LEFT] = PA_CHANNEL_POSITION_TOP_REAR_LEFT,
+ [MATE_MIXER_CHANNEL_TOP_BACK_RIGHT] = PA_CHANNEL_POSITION_TOP_REAR_RIGHT,
+ [MATE_MIXER_CHANNEL_TOP_BACK_CENTER] = PA_CHANNEL_POSITION_TOP_REAR_CENTER
+};
MateMixerStreamControlMediaRole
pulse_convert_media_role_name (const gchar *name)
diff --git a/backends/pulse/pulse-helpers.h b/backends/pulse/pulse-helpers.h
index 667fc3c..6d69e61 100644
--- a/backends/pulse/pulse-helpers.h
+++ b/backends/pulse/pulse-helpers.h
@@ -25,10 +25,10 @@
G_BEGIN_DECLS
-MateMixerChannelPosition pulse_convert_position_from_pulse (pa_channel_position_t position);
-pa_channel_position_t pulse_convert_position_to_pulse (MateMixerChannelPosition position);
+extern const MateMixerChannelPosition pulse_channel_map_from[PA_CHANNEL_POSITION_MAX];
+extern const pa_channel_position_t pulse_channel_map_to[MATE_MIXER_CHANNEL_MAX];
-MateMixerStreamControlMediaRole pulse_convert_media_role_name (const gchar *name);
+MateMixerStreamControlMediaRole pulse_convert_media_role_name (const gchar *name);
G_END_DECLS
diff --git a/backends/pulse/pulse-stream-control.c b/backends/pulse/pulse-stream-control.c
index f61a616..3da3221 100644
--- a/backends/pulse/pulse-stream-control.c
+++ b/backends/pulse/pulse-stream-control.c
@@ -550,15 +550,17 @@ pulse_stream_control_get_channel_position (MateMixerStreamControl *mmsc, guint c
if (channel >= control->priv->channel_map.channels)
return MATE_MIXER_CHANNEL_UNKNOWN;
- return pulse_convert_position_from_pulse (control->priv->channel_map.map[channel]);
+ if (control->priv->channel_map.map[channel] == PA_CHANNEL_POSITION_INVALID)
+ return MATE_MIXER_CHANNEL_UNKNOWN;
+
+ return pulse_channel_map_from[control->priv->channel_map.map[channel]];
}
static gboolean
pulse_stream_control_has_channel_position (MateMixerStreamControl *mmsc,
MateMixerChannelPosition position)
{
- PulseStreamControl *control;
- pa_channel_position_t p;
+ PulseStreamControl *control;
g_return_val_if_fail (PULSE_IS_STREAM_CONTROL (mmsc), FALSE);
@@ -566,12 +568,11 @@ pulse_stream_control_has_channel_position (MateMixerStreamControl *mmsc,
/* Handle invalid position as a special case, otherwise this function would
* return TRUE for e.g. unknown index in a default channel map */
- p = pulse_convert_position_to_pulse (position);
-
- if (p == PA_CHANNEL_POSITION_INVALID)
+ if (pulse_channel_map_to[position] == PA_CHANNEL_POSITION_INVALID)
return FALSE;
- if (pa_channel_map_has_position (&control->priv->channel_map, p) != 0)
+ if (pa_channel_map_has_position (&control->priv->channel_map,
+ pulse_channel_map_to[position]) != 0)
return TRUE;
else
return FALSE;