From b0ed93d87ddf351a6983d3cb87063c75efa04281 Mon Sep 17 00:00:00 2001 From: wm4 Date: Mon, 1 Dec 2014 15:28:06 +0100 Subject: audio: allow more than 20 channel map entries This could trigger an assertion when using ao_alsa or ao_coreaudio. The code was simply assuming the number of channel maps was bounded statically (which was true at first in both AOs). Fix by using dynamic memory allocation. It needs to be explicitly enabled by the AOs by setting a temp context, because otherwise the memory couldn't be freed. (Or at least this seems to be the most elegant solution.) Fixes #1306. --- audio/chmap_sel.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'audio/chmap_sel.c') diff --git a/audio/chmap_sel.c b/audio/chmap_sel.c index 160f1ce5fa..8e591aea44 100644 --- a/audio/chmap_sel.c +++ b/audio/chmap_sel.c @@ -81,14 +81,21 @@ void mp_chmap_sel_add_alsa_def(struct mp_chmap_sel *s) } } -#define ARRAY_LEN(x) (sizeof(x) / sizeof((x)[0])) - // Add a channel map that should be allowed. void mp_chmap_sel_add_map(struct mp_chmap_sel *s, const struct mp_chmap *map) { - assert(s->num_chmaps < ARRAY_LEN(s->chmaps)); - if (mp_chmap_is_valid(map)) - s->chmaps[s->num_chmaps++] = *map; + if (!mp_chmap_is_valid(map)) + return; + if (!s->chmaps) + s->chmaps = s->chmaps_storage; + if (s->num_chmaps == MP_ARRAY_SIZE(s->chmaps)) { + if (!s->tmp) + return; + s->chmaps = talloc_memdup(s->tmp, s->chmaps, sizeof(s->chmaps_storage)); + } + if (s->chmaps != s->chmaps_storage) + MP_TARRAY_GROW(s->tmp, s->chmaps, s->num_chmaps); + s->chmaps[s->num_chmaps++] = *map; } // Allow all waveext formats in default order. -- cgit v1.2.3