summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2015-05-06 21:33:54 +0200
committerwm4 <wm4@nowhere>2015-05-06 21:48:40 +0200
commitd577872a28c9729e987566530905bde238af8109 (patch)
treef6760219c59a009d481032caa96a1dbc54aff4d0
parent9434aa75b2613b1d00ad713f5db7a6e4f639792c (diff)
downloadmpv-d577872a28c9729e987566530905bde238af8109.tar.bz2
mpv-d577872a28c9729e987566530905bde238af8109.tar.xz
ao_alsa: move ALSA -> mp channel map to a function
One side effect is that the warning about too many channels goes away, and is replaced with printing the ALSA channel map as "unknown".
-rw-r--r--audio/out/ao_alsa.c29
1 files changed, 18 insertions, 11 deletions
diff --git a/audio/out/ao_alsa.c b/audio/out/ao_alsa.c
index f4565da0dc..82494717cf 100644
--- a/audio/out/ao_alsa.c
+++ b/audio/out/ao_alsa.c
@@ -275,6 +275,20 @@ static int find_alsa_channel(int mp_channel)
return SND_CHMAP_UNKNOWN;
}
+static int mp_chmap_from_alsa(struct mp_chmap *dst, snd_pcm_chmap_t *src)
+{
+ *dst = (struct mp_chmap) {0};
+
+ if (src->channels > MP_NUM_CHANNELS)
+ return -1;
+
+ dst->num = src->channels;
+ for (int c = 0; c < dst->num; c++)
+ dst->speaker[c] = find_mp_channel(src->pos[c]);
+
+ return 0;
+}
+
static bool query_chmaps(struct ao *ao, struct mp_chmap *chmap)
{
struct priv *p = ao->priv;
@@ -285,14 +299,8 @@ static bool query_chmaps(struct ao *ao, struct mp_chmap *chmap)
return false;
for (int i = 0; maps[i] != NULL; i++) {
- if (maps[i]->map.channels > MP_NUM_CHANNELS) {
- MP_VERBOSE(ao, "skipping ALSA channel map with too many channels.\n");
- continue;
- }
-
- struct mp_chmap entry = {.num = maps[i]->map.channels};
- for (int c = 0; c < entry.num; c++)
- entry.speaker[c] = find_mp_channel(maps[i]->map.pos[c]);
+ struct mp_chmap entry;
+ mp_chmap_from_alsa(&entry, &maps[i]->map);
if (mp_chmap_is_valid(&entry)) {
MP_VERBOSE(ao, "Got supported channel map: %s (type %s)\n",
@@ -564,9 +572,8 @@ static int init_device(struct ao *ao)
if (snd_pcm_chmap_print(alsa_chmap, sizeof(tmp), tmp) > 0)
MP_VERBOSE(ao, "channel map reported by ALSA: %s\n", tmp);
- struct mp_chmap chmap = {.num = alsa_chmap->channels};
- for (int c = 0; c < chmap.num; c++)
- chmap.speaker[c] = find_mp_channel(alsa_chmap->pos[c]);
+ struct mp_chmap chmap;
+ mp_chmap_from_alsa(&chmap, alsa_chmap);
MP_VERBOSE(ao, "which we understand as: %s\n", mp_chmap_to_str(&chmap));