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. diff --git a/audio/chmap_sel.h b/audio/chmap_sel.h index c9d75196a5..7758ca5d74 100644 --- a/audio/chmap_sel.h +++ b/audio/chmap_sel.h @@ -26,8 +26,12 @@ struct mp_chmap_sel { // should be considered opaque bool allow_any, allow_waveext; bool speakers[MP_SPEAKER_ID_COUNT]; - struct mp_chmap chmaps[20]; + struct mp_chmap *chmaps; int num_chmaps; + + struct mp_chmap chmaps_storage[20]; + + void *tmp; // set to any talloc context to allow more chmaps entries }; void mp_chmap_sel_add_any(struct mp_chmap_sel *s); diff --git a/audio/out/ao_alsa.c b/audio/out/ao_alsa.c index 86745c6e80..4e54f161fe 100644 --- a/audio/out/ao_alsa.c +++ b/audio/out/ao_alsa.c @@ -279,7 +279,7 @@ static int find_alsa_channel(int mp_channel) static bool query_chmaps(struct ao *ao, struct mp_chmap *chmap) { struct priv *p = ao->priv; - struct mp_chmap_sel chmap_sel = {0}; + struct mp_chmap_sel chmap_sel = {.tmp = p}; snd_pcm_chmap_query_t **maps = snd_pcm_query_chmaps(p->alsa); if (!maps) diff --git a/audio/out/ao_coreaudio.c b/audio/out/ao_coreaudio.c index 1e1ad8cb10..6498f3ecad 100644 --- a/audio/out/ao_coreaudio.c +++ b/audio/out/ao_coreaudio.c @@ -185,7 +185,7 @@ static bool init_chmap(struct ao *ao) &layouts, &n_layouts); CHECK_CA_ERROR("could not get audio device prefered layouts"); - struct mp_chmap_sel chmap_sel = {0}; + struct mp_chmap_sel chmap_sel = {.tmp = p}; for (int i = 0; i < n_layouts; i++) { struct mp_chmap chmap = {0}; if (ca_layout_to_mp_chmap(ao, &layouts[i], &chmap))