From 76659453efecc6a4807fc270af8216f05cfa3dfe Mon Sep 17 00:00:00 2001 From: Jaroslav Kysela Date: Wed, 6 Apr 2022 20:17:58 +0200 Subject: [PATCH] pcm: direct - add support for channel bindings in snd_pcm_direct_query_chmaps() Signed-off-by: Jaroslav Kysela --- src/pcm/pcm_direct.c | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/pcm/pcm_direct.c b/src/pcm/pcm_direct.c index 060bcd5a..9096315d 100644 --- a/src/pcm/pcm_direct.c +++ b/src/pcm/pcm_direct.c @@ -1066,7 +1066,34 @@ int snd_pcm_direct_munmap(snd_pcm_t *pcm ATTRIBUTE_UNUSED) snd_pcm_chmap_query_t **snd_pcm_direct_query_chmaps(snd_pcm_t *pcm) { snd_pcm_direct_t *dmix = pcm->private_data; - return snd_pcm_query_chmaps(dmix->spcm); + snd_pcm_chmap_query_t **smaps, **maps; + unsigned int i, j; + + if (dmix->bindings == NULL) + return snd_pcm_query_chmaps(dmix->spcm); + + maps = calloc(2, sizeof(*maps)); + if (!maps) + return NULL; + maps[0] = calloc(dmix->channels + 2, sizeof(int *)); + if (!maps[0]) { + free(maps); + return NULL; + } + smaps = snd_pcm_query_chmaps(dmix->spcm); + if (smaps == NULL) { + snd_pcm_free_chmaps(maps); + return NULL; + } + maps[0]->type = SND_CHMAP_TYPE_FIXED; + maps[0]->map.channels = dmix->channels; + for (i = 0; i < dmix->channels; i++) { + j = dmix->bindings[i]; + if (j == UINT_MAX || smaps[0]->map.channels < j) + continue; + maps[0]->map.pos[i] = smaps[0]->map.pos[j]; + } + return maps; } snd_pcm_chmap_t *snd_pcm_direct_get_chmap(snd_pcm_t *pcm) -- 2.47.1