summaryrefslogtreecommitdiff
path: root/backends
diff options
context:
space:
mode:
Diffstat (limited to 'backends')
-rw-r--r--backends/alsa/Makefile.am1
-rw-r--r--backends/alsa/alsa-compat.h26
-rw-r--r--backends/alsa/alsa-constants.c13
-rw-r--r--backends/alsa/alsa-device.c3
-rw-r--r--backends/alsa/alsa-stream-input-control.c22
-rw-r--r--backends/alsa/alsa-stream-output-control.c22
6 files changed, 81 insertions, 6 deletions
diff --git a/backends/alsa/Makefile.am b/backends/alsa/Makefile.am
index c192cfb..7561290 100644
--- a/backends/alsa/Makefile.am
+++ b/backends/alsa/Makefile.am
@@ -14,6 +14,7 @@ libmatemixer_alsa_la_CFLAGS = \
libmatemixer_alsa_la_SOURCES = \
alsa-backend.c \
alsa-backend.h \
+ alsa-compat.h \
alsa-constants.c \
alsa-constants.h \
alsa-device.c \
diff --git a/backends/alsa/alsa-compat.h b/backends/alsa/alsa-compat.h
new file mode 100644
index 0000000..8b6b134
--- /dev/null
+++ b/backends/alsa/alsa-compat.h
@@ -0,0 +1,26 @@
+/*
+ * Copyright (C) 2015 Michal Ratajsky <[email protected]>
+ *
+ * This library 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 of the licence, or (at your option) any later version.
+ *
+ * This library 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 this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef ALSA_COMPAT_H
+#define ALSA_COMPAT_H
+
+#define ALSA_PACK_VERSION(major, minor, subminor) \
+ (((major) << 16) | \
+ ((minor) << 8) | \
+ (subminor))
+
+#endif /* ALSA_COMPAT_H */
diff --git a/backends/alsa/alsa-constants.c b/backends/alsa/alsa-constants.c
index 853db95..c55fc6e 100644
--- a/backends/alsa/alsa-constants.c
+++ b/backends/alsa/alsa-constants.c
@@ -20,6 +20,7 @@
#include <alsa/asoundlib.h>
#include <libmatemixer/matemixer.h>
+#include "alsa-compat.h"
#include "alsa-constants.h"
/*
@@ -228,9 +229,11 @@ const MateMixerChannelPosition alsa_channel_map_from[SND_MIXER_SCHN_LAST] =
[SND_MIXER_SCHN_REAR_RIGHT] = MATE_MIXER_CHANNEL_BACK_RIGHT,
[SND_MIXER_SCHN_FRONT_CENTER] = MATE_MIXER_CHANNEL_FRONT_CENTER,
[SND_MIXER_SCHN_WOOFER] = MATE_MIXER_CHANNEL_LFE,
+#if SND_LIB_VERSION >= ALSA_PACK_VERSION (1, 0, 10)
[SND_MIXER_SCHN_SIDE_LEFT] = MATE_MIXER_CHANNEL_SIDE_LEFT,
[SND_MIXER_SCHN_SIDE_RIGHT] = MATE_MIXER_CHANNEL_SIDE_RIGHT,
[SND_MIXER_SCHN_REAR_CENTER] = MATE_MIXER_CHANNEL_BACK_CENTER
+#endif
};
const snd_mixer_selem_channel_id_t alsa_channel_map_to[MATE_MIXER_CHANNEL_MAX] =
@@ -243,11 +246,17 @@ const snd_mixer_selem_channel_id_t alsa_channel_map_to[MATE_MIXER_CHANNEL_MAX] =
[MATE_MIXER_CHANNEL_LFE] = SND_MIXER_SCHN_WOOFER,
[MATE_MIXER_CHANNEL_BACK_LEFT] = SND_MIXER_SCHN_REAR_LEFT,
[MATE_MIXER_CHANNEL_BACK_RIGHT] = SND_MIXER_SCHN_REAR_RIGHT,
+#if SND_LIB_VERSION >= ALSA_PACK_VERSION (1, 0, 10)
[MATE_MIXER_CHANNEL_BACK_CENTER] = SND_MIXER_SCHN_REAR_CENTER,
- [MATE_MIXER_CHANNEL_FRONT_LEFT_CENTER] = SND_MIXER_SCHN_UNKNOWN,
- [MATE_MIXER_CHANNEL_FRONT_RIGHT_CENTER] = SND_MIXER_SCHN_UNKNOWN,
[MATE_MIXER_CHANNEL_SIDE_LEFT] = SND_MIXER_SCHN_SIDE_LEFT,
[MATE_MIXER_CHANNEL_SIDE_RIGHT] = SND_MIXER_SCHN_SIDE_RIGHT,
+#else
+ [MATE_MIXER_CHANNEL_BACK_CENTER] = SND_MIXER_SCHN_UNKNOWN,
+ [MATE_MIXER_CHANNEL_SIDE_LEFT] = SND_MIXER_SCHN_UNKNOWN,
+ [MATE_MIXER_CHANNEL_SIDE_RIGHT] = SND_MIXER_SCHN_UNKNOWN,
+#endif
+ [MATE_MIXER_CHANNEL_FRONT_LEFT_CENTER] = SND_MIXER_SCHN_UNKNOWN,
+ [MATE_MIXER_CHANNEL_FRONT_RIGHT_CENTER] = SND_MIXER_SCHN_UNKNOWN,
[MATE_MIXER_CHANNEL_TOP_FRONT_LEFT] = SND_MIXER_SCHN_UNKNOWN,
[MATE_MIXER_CHANNEL_TOP_FRONT_RIGHT] = SND_MIXER_SCHN_UNKNOWN,
[MATE_MIXER_CHANNEL_TOP_FRONT_CENTER] = SND_MIXER_SCHN_UNKNOWN,
diff --git a/backends/alsa/alsa-device.c b/backends/alsa/alsa-device.c
index f76478f..fb12447 100644
--- a/backends/alsa/alsa-device.c
+++ b/backends/alsa/alsa-device.c
@@ -24,6 +24,7 @@
#include <alsa/asoundlib.h>
#include <libmatemixer/matemixer.h>
+#include "alsa-compat.h"
#include "alsa-constants.h"
#include "alsa-device.h"
#include "alsa-element.h"
@@ -707,11 +708,13 @@ load_element (AlsaDevice *device, snd_mixer_elem_t *el)
gboolean cenum = FALSE;
gboolean penum = FALSE;
+#if SND_LIB_VERSION >= ALSA_PACK_VERSION (1, 0, 10)
/* The enumeration may have a capture or a playback capability.
* If it has either both or none, try to guess the more appropriate
* direction. */
cenum = snd_mixer_selem_is_enum_capture (el);
penum = snd_mixer_selem_is_enum_playback (el);
+#endif
if (cenum ^ penum) {
if (cenum == TRUE)
direction = MATE_MIXER_DIRECTION_INPUT;
diff --git a/backends/alsa/alsa-stream-input-control.c b/backends/alsa/alsa-stream-input-control.c
index 2e3f46d..1954008 100644
--- a/backends/alsa/alsa-stream-input-control.c
+++ b/backends/alsa/alsa-stream-input-control.c
@@ -22,6 +22,7 @@
#include <libmatemixer/matemixer.h>
#include <libmatemixer/matemixer-private.h>
+#include "alsa-compat.h"
#include "alsa-constants.h"
#include "alsa-element.h"
#include "alsa-stream-control.h"
@@ -52,7 +53,8 @@ static gboolean alsa_stream_input_control_get_decibel_from_volume (AlsaStreamCon
guint volume,
gdouble *decibel);
-static void read_volume_data (snd_mixer_elem_t *el, AlsaControlData *data);
+static void read_volume_data (snd_mixer_elem_t *el,
+ AlsaControlData *data);
static void
alsa_stream_input_control_class_init (AlsaStreamInputControlClass *klass)
@@ -195,6 +197,7 @@ alsa_stream_input_control_get_volume_from_decibel (AlsaStreamControl *control,
gdouble decibel,
guint *volume)
{
+#if SND_LIB_VERSION >= ALSA_PACK_VERSION (1, 0, 17)
snd_mixer_elem_t *el;
glong value;
gint ret;
@@ -213,6 +216,9 @@ alsa_stream_input_control_get_volume_from_decibel (AlsaStreamControl *control,
*volume = value;
return TRUE;
+#else
+ return FALSE;
+#endif
}
static gboolean
@@ -220,6 +226,7 @@ alsa_stream_input_control_get_decibel_from_volume (AlsaStreamControl *control,
guint volume,
gdouble *decibel)
{
+#if SND_LIB_VERSION >= ALSA_PACK_VERSION (1, 0, 17)
snd_mixer_elem_t *el;
glong value;
gint ret;
@@ -238,6 +245,9 @@ alsa_stream_input_control_get_decibel_from_volume (AlsaStreamControl *control,
*decibel = value / 100.0;
return TRUE;
+#else
+ return FALSE;
+#endif
}
static void
@@ -249,14 +259,19 @@ read_volume_data (snd_mixer_elem_t *el, AlsaControlData *data)
gint i;
/* Read volume ranges, this call should never fail on valid input */
+#if SND_LIB_VERSION >= ALSA_PACK_VERSION (1, 0, 10)
ret = snd_mixer_selem_get_capture_volume_range (el, &min, &max);
if G_UNLIKELY (ret < 0) {
g_warning ("Failed to read capture volume range: %s", snd_strerror (ret));
return;
}
+#else
+ snd_mixer_selem_get_capture_volume_range (el, &min, &max);
+#endif
data->min = (guint) min;
data->max = (guint) max;
+#if SND_LIB_VERSION >= ALSA_PACK_VERSION (1, 0, 10)
/* This fails when decibels are not supported */
ret = snd_mixer_selem_get_capture_dB_range (el, &min, &max);
if (ret == 0) {
@@ -264,6 +279,9 @@ read_volume_data (snd_mixer_elem_t *el, AlsaControlData *data)
data->max_decibel = max / 100.0;
} else
data->min_decibel = data->max_decibel = -MATE_MIXER_INFINITY;
+#else
+ data->min_decibel = data->max_decibel = -MATE_MIXER_INFINITY;
+#endif
for (i = 0; i < MATE_MIXER_CHANNEL_MAX; i++)
data->v[i] = data->min;
@@ -299,7 +317,7 @@ read_volume_data (snd_mixer_elem_t *el, AlsaControlData *data)
/* We use numeric channel indices, but ALSA only works with channel
* positions, go over all the positions supported by ALSA and create
* a list of channels */
- for (channel = 0; channel < SND_MIXER_SCHN_LAST; channel++) {
+ for (channel = 0; channel < SND_MIXER_SCHN_LAST; channel++) {
if (snd_mixer_selem_has_capture_channel (el, channel) == 0)
continue;
diff --git a/backends/alsa/alsa-stream-output-control.c b/backends/alsa/alsa-stream-output-control.c
index 1f4faf8..5b6a1eb 100644
--- a/backends/alsa/alsa-stream-output-control.c
+++ b/backends/alsa/alsa-stream-output-control.c
@@ -22,6 +22,7 @@
#include <libmatemixer/matemixer.h>
#include <libmatemixer/matemixer-private.h>
+#include "alsa-compat.h"
#include "alsa-constants.h"
#include "alsa-element.h"
#include "alsa-stream-control.h"
@@ -52,7 +53,8 @@ static gboolean alsa_stream_output_control_get_decibel_from_volume (AlsaStreamCo
guint volume,
gdouble *decibel);
-static void read_volume_data (snd_mixer_elem_t *el, AlsaControlData *data);
+static void read_volume_data (snd_mixer_elem_t *el,
+ AlsaControlData *data);
static void
alsa_stream_output_control_class_init (AlsaStreamOutputControlClass *klass)
@@ -195,6 +197,7 @@ alsa_stream_output_control_get_volume_from_decibel (AlsaStreamControl *control,
gdouble decibel,
guint *volume)
{
+#if SND_LIB_VERSION >= ALSA_PACK_VERSION (1, 0, 17)
snd_mixer_elem_t *el;
glong value;
gint ret;
@@ -213,6 +216,9 @@ alsa_stream_output_control_get_volume_from_decibel (AlsaStreamControl *control,
*volume = value;
return TRUE;
+#else
+ return FALSE;
+#endif
}
static gboolean
@@ -220,6 +226,7 @@ alsa_stream_output_control_get_decibel_from_volume (AlsaStreamControl *control,
guint volume,
gdouble *decibel)
{
+#if SND_LIB_VERSION >= ALSA_PACK_VERSION (1, 0, 17)
snd_mixer_elem_t *el;
glong value;
gint ret;
@@ -238,6 +245,9 @@ alsa_stream_output_control_get_decibel_from_volume (AlsaStreamControl *control,
*decibel = value / 100.0;
return TRUE;
+#else
+ return FALSE;
+#endif
}
static void
@@ -249,14 +259,19 @@ read_volume_data (snd_mixer_elem_t *el, AlsaControlData *data)
gint i;
/* Read volume ranges, this call should never fail on valid input */
+#if SND_LIB_VERSION >= ALSA_PACK_VERSION (1, 0, 10)
ret = snd_mixer_selem_get_playback_volume_range (el, &min, &max);
if G_UNLIKELY (ret < 0) {
g_warning ("Failed to read playback volume range: %s", snd_strerror (ret));
return;
}
+#else
+ snd_mixer_selem_get_playback_volume_range (el, &min, &max);
+#endif
data->min = (guint) min;
data->max = (guint) max;
+#if SND_LIB_VERSION >= ALSA_PACK_VERSION (1, 0, 10)
/* This fails when decibels are not supported */
ret = snd_mixer_selem_get_playback_dB_range (el, &min, &max);
if (ret == 0) {
@@ -264,6 +279,9 @@ read_volume_data (snd_mixer_elem_t *el, AlsaControlData *data)
data->max_decibel = max / 100.0;
} else
data->min_decibel = data->max_decibel = -MATE_MIXER_INFINITY;
+#else
+ data->min_decibel = data->max_decibel = -MATE_MIXER_INFINITY;
+#endif
for (i = 0; i < MATE_MIXER_CHANNEL_MAX; i++)
data->v[i] = data->min;
@@ -299,7 +317,7 @@ read_volume_data (snd_mixer_elem_t *el, AlsaControlData *data)
/* We use numeric channel indices, but ALSA only works with channel
* positions, go over all the positions supported by ALSA and create
* a list of channels */
- for (channel = 0; channel < SND_MIXER_SCHN_LAST; channel++) {
+ for (channel = 0; channel < SND_MIXER_SCHN_LAST; channel++) {
if (snd_mixer_selem_has_playback_channel (el, channel) == 0)
continue;