From 168e9288f1ff147d9aaa6064c3cc0308fd214a6a Mon Sep 17 00:00:00 2001 From: Thierry Bultel Date: Fri, 7 Sep 2018 15:52:28 +0200 Subject: dmix: used device when in name of slave When a sound card has multiple devices, it is invalid to set the slave name of the dmix as "hw:cardname" because alsa does not know which device to use. The fix consists in using the device number, when it is given. Signed-off-by: Thierry Bultel --- plugins/alsa/alsa-plug-dmix.c | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) (limited to 'plugins') diff --git a/plugins/alsa/alsa-plug-dmix.c b/plugins/alsa/alsa-plug-dmix.c index df525cb..3c6d62e 100644 --- a/plugins/alsa/alsa-plug-dmix.c +++ b/plugins/alsa/alsa-plug-dmix.c @@ -27,19 +27,37 @@ ALSA_PLUG_PROTO(dmix); PUBLIC AlsaPcmCtlT* AlsaCreateDmix(SoftMixerT *mixer, const char* pcmName, AlsaSndPcmT *pcmSlave, int open) { - snd_config_t *dmixConfig, *slaveConfig, *elemConfig, *pcmConfig; + snd_config_t *dmixConfig = NULL, *slaveConfig = NULL, *elemConfig = NULL, *pcmConfig=NULL; AlsaPcmCtlT *pcmPlug= calloc(1,sizeof(AlsaPcmCtlT)); AlsaSndCtlT *sndSlave=pcmSlave->sndcard; pcmPlug->cid.cardid=pcmName; + char * fullPcmName = NULL; int error=0; - AFB_ApiInfo(mixer->api, "%s: %s, slave %s, cardid %s\n", __func__, pcmName, pcmSlave->uid, pcmSlave->sndcard->cid.cardid); + AFB_ApiInfo(mixer->api, "%s: %s, slave %s, cardid %s (dev %d, subdev %d)\n", + __func__, + pcmName, + pcmSlave->uid, + sndSlave->cid.cardid, + sndSlave->cid.device, + sndSlave->cid.subdev + ); + + error = asprintf(&fullPcmName,"%s,%d,%d", sndSlave->cid.cardid, sndSlave->cid.device, sndSlave->cid.subdev); + if (error == -1) { + AFB_ApiError(mixer->api, + "%s: Insufficient memory", + __func__); + goto OnErrorExit; + } - error += snd_config_top(&dmixConfig); + error = snd_config_top(&dmixConfig); if (error) goto OnErrorExit; - error += snd_config_set_id (dmixConfig, pcmPlug->cid.cardid); + + error += snd_config_set_id (dmixConfig, pcmName); if (error) goto OnErrorExit; + error += snd_config_imake_string(&elemConfig, "type", "dmix"); if (error) goto OnErrorExit; error += snd_config_add(dmixConfig, elemConfig); @@ -51,7 +69,7 @@ PUBLIC AlsaPcmCtlT* AlsaCreateDmix(SoftMixerT *mixer, const char* pcmName, AlsaS error += snd_config_make_compound(&slaveConfig, "slave", 0); if (error) goto OnErrorExit; - error += snd_config_imake_string(&elemConfig, "pcm", sndSlave->cid.cardid); + error += snd_config_imake_string(&elemConfig, "pcm", fullPcmName); if (error) goto OnErrorExit; error += snd_config_add(slaveConfig, elemConfig); if (error) goto OnErrorExit; @@ -105,8 +123,12 @@ PUBLIC AlsaPcmCtlT* AlsaCreateDmix(SoftMixerT *mixer, const char* pcmName, AlsaS return pcmPlug; OnErrorExit: + + free(fullPcmName); + AlsaDumpCtlConfig(mixer, "plug-pcm", pcmConfig, 1); AlsaDumpCtlConfig(mixer, "plug-dmix", dmixConfig, 1); + AFB_ApiNotice(mixer->api, "%s: FAIL", __func__); return NULL; } -- cgit 1.2.3-korg