From e355716f6bac57615195333559a746e283e22060 Mon Sep 17 00:00:00 2001 From: Thierry Bultel Date: Wed, 13 Feb 2019 11:59:45 +0100 Subject: pcm plugs: rework the alsa config cleanup The alsa config (for softvol, routes, rate conversion ...) was cleaned up by the owner stream or zone, at their deletion time. This was a mistake, because when the stream or zone creation was not complete, the cleanup of the configuration was not done. Instead of doing that, the config is attached to the plug objects as private data (in the AlsaPcmCtlT structure). Since the AlsaPcmCtlT are always recorded in the creation transaction, it is easy to call the cleaning callback (when it exists) when the transaction is deleted. Change-Id: I952871518a20bfe0be6398887bc747338cf574fb Signed-off-by: Thierry Bultel --- plugins/alsa/alsa-api-streams.c | 13 ------------- plugins/alsa/alsa-api-zones.c | 7 ------- plugins/alsa/alsa-plug-dmix.c | 12 +++++++++++- plugins/alsa/alsa-plug-rate.c | 12 ++++++++++-- plugins/alsa/alsa-plug-route.c | 13 +++++++++++-- plugins/alsa/alsa-plug-vol.c | 10 ++++++++-- plugins/alsa/alsa-softmixer.h | 10 +++++++--- plugins/alsa/alsa-utils-bypath.c | 3 +++ 8 files changed, 50 insertions(+), 30 deletions(-) diff --git a/plugins/alsa/alsa-api-streams.c b/plugins/alsa/alsa-api-streams.c index 43c14da..bc5ea6b 100644 --- a/plugins/alsa/alsa-api-streams.c +++ b/plugins/alsa/alsa-api-streams.c @@ -687,19 +687,6 @@ static void streamDestroy(SoftMixerT * mixer, void * arg) { AlsaPcmCopyStop(mixer, stream->copy); freemem: - if (stream->softvolConfig) { - AFB_ApiDebug(mixer->api, "%s... %s delete softvol config", __func__, stream->uid); - snd_config_delete(stream->softvolConfig); - snd_config_update(); - stream->softvolConfig = NULL; - } - - if (stream->rateConfig) { - AFB_ApiDebug(mixer->api, "%s... %s delete rate config", __func__, stream->uid); - snd_config_delete(stream->rateConfig); - snd_config_update(); - stream->rateConfig = NULL; - } free((char*)stream->uid); free((char*)stream->playback); diff --git a/plugins/alsa/alsa-api-zones.c b/plugins/alsa/alsa-api-zones.c index 03a2264..83f6e3a 100644 --- a/plugins/alsa/alsa-api-zones.c +++ b/plugins/alsa/alsa-api-zones.c @@ -200,13 +200,6 @@ static void zoneDestroy(SoftMixerT* mixer, void * arg) { AFB_ApiDebug(mixer->api, "%s... %s (%d sinks, %d sources)", __func__, zone->uid, zone->nbSinks, zone->nbSources); - if (zone->routeConfig) { - AFB_ApiDebug(mixer->api, "%s... %s delete route config", __func__, zone->uid); - snd_config_delete(zone->routeConfig); - snd_config_update(); - zone->routeConfig = NULL; - } - AlsaPcmChannelT * channel, *tmp; cds_list_for_each_entry_safe(channel, tmp, &zone->sinks.list, list) { diff --git a/plugins/alsa/alsa-plug-dmix.c b/plugins/alsa/alsa-plug-dmix.c index 9aaf866..bb58a29 100644 --- a/plugins/alsa/alsa-plug-dmix.c +++ b/plugins/alsa/alsa-plug-dmix.c @@ -24,6 +24,13 @@ static int uniqueIpcIndex = 1024; ALSA_PLUG_PROTO(dmix); +static void dmixConfigClean(SoftMixerT *mixer, void * arg) { + snd_config_t * dmixConfig = arg; + AFB_API_DEBUG(mixer->api, "%s... ", __func__); + snd_config_delete(dmixConfig); + snd_config_update(); +} + PUBLIC AlsaPcmCtlT* AlsaCreateDmix(SoftMixerT *mixer, const char* pcmName, AlsaSndPcmT *pcmSlave, int open) { @@ -92,7 +99,7 @@ PUBLIC AlsaPcmCtlT* AlsaCreateDmix(SoftMixerT *mixer, const char* pcmName, AlsaS if (error) goto OnErrorExit; } - /* It is critical to set the right number of channels ... know. + /* It is critical to set the right number of channels ... now. * Trying to set another value later leads to silent failure * */ @@ -121,6 +128,9 @@ PUBLIC AlsaPcmCtlT* AlsaCreateDmix(SoftMixerT *mixer, const char* pcmName, AlsaS goto OnErrorExit; } + pcmPlug->private_data = dmixConfig; + pcmPlug->private_data_clean = dmixConfigClean; + // Debug config & pcm AlsaDumpCtlConfig(mixer, "plug-dmix", dmixConfig, 1); AFB_ApiNotice(mixer->api, "%s: %s done", __func__, pcmPlug->cid.cardid); diff --git a/plugins/alsa/alsa-plug-rate.c b/plugins/alsa/alsa-plug-rate.c index d4a3068..ea96da2 100644 --- a/plugins/alsa/alsa-plug-rate.c +++ b/plugins/alsa/alsa-plug-rate.c @@ -23,6 +23,13 @@ ALSA_PLUG_PROTO(rate); +static void rateConfigClean(SoftMixerT *mixer, void * arg) { + snd_config_t * rateConfig = arg; + AFB_API_DEBUG(mixer->api, "%s... rate config", __func__); + snd_config_delete(rateConfig); + snd_config_update(); +} + PUBLIC AlsaPcmCtlT* AlsaCreateRate(SoftMixerT *mixer, AlsaStreamAudioT * stream, const char* pcmName, AlsaPcmCtlT *pcmSlave, AlsaPcmHwInfoT *params, int open) { snd_config_t *rateConfig, *slaveConfig, *elemConfig, *pcmConfig; @@ -71,8 +78,6 @@ PUBLIC AlsaPcmCtlT* AlsaCreateRate(SoftMixerT *mixer, AlsaStreamAudioT * stream, goto OnErrorExit; } - stream->rateConfig = rateConfig; - if (open) error = _snd_pcm_rate_open(&pcmPlug->handle, pcmPlug->cid.cardid, snd_config, rateConfig, SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK); if (error) { AFB_ApiError(mixer->api, @@ -81,6 +86,9 @@ PUBLIC AlsaPcmCtlT* AlsaCreateRate(SoftMixerT *mixer, AlsaStreamAudioT * stream, goto OnErrorExit; } + pcmPlug->private_data = rateConfig; + pcmPlug->private_data_clean = rateConfigClean; + // Debug config & pcm //AlsaDumpCtlConfig(mixer, "plug-rate", pcmConfig, 1); AlsaDumpCtlConfig (mixer, "plug-rate", rateConfig, 1); diff --git a/plugins/alsa/alsa-plug-route.c b/plugins/alsa/alsa-plug-route.c index d3f22a7..df39698 100644 --- a/plugins/alsa/alsa-plug-route.c +++ b/plugins/alsa/alsa-plug-route.c @@ -23,6 +23,14 @@ ALSA_PLUG_PROTO(route); +static void routeConfigClean(SoftMixerT *mixer, void * arg) { + snd_config_t * routeConfig = arg; + AFB_API_DEBUG(mixer->api, "%s... route config", __func__); + snd_config_delete(routeConfig); + snd_config_update(); +} + + typedef struct { const char *uid; const char *cardid; @@ -81,7 +89,7 @@ OnErrorExit: } PUBLIC AlsaPcmCtlT* AlsaCreateRoute(SoftMixerT *mixer, AlsaSndZoneT *zone, int open) { - snd_config_t *routeConfig, *elemConfig, *slaveConfig, *tableConfig, *pcmConfig; + snd_config_t *routeConfig = NULL, *elemConfig, *slaveConfig, *tableConfig, *pcmConfig; int error = 0; ChannelCardPortT slave, channelCardPort; AlsaPcmCtlT *pcmRoute = NULL; @@ -279,7 +287,8 @@ PUBLIC AlsaPcmCtlT* AlsaCreateRoute(SoftMixerT *mixer, AlsaSndZoneT *zone, int o goto fail; } - zone->routeConfig = routeConfig; + pcmRoute->private_data = routeConfig; + pcmRoute->private_data_clean = routeConfigClean; // Debug config & pcm AFB_ApiNotice(mixer->api, "%s: zone(%s) DONE", __func__, zone->uid); diff --git a/plugins/alsa/alsa-plug-vol.c b/plugins/alsa/alsa-plug-vol.c index 09025c4..ade29ac 100644 --- a/plugins/alsa/alsa-plug-vol.c +++ b/plugins/alsa/alsa-plug-vol.c @@ -22,8 +22,13 @@ ALSA_PLUG_PROTO(softvol); // stream uses softvol plugin -PUBLIC void AlsaDeleteSoftvol(SoftMixerT *mixer, AlsaPcmCtlT * ctl) { + +static void softVolConfigClean(SoftMixerT *mixer, void * arg) { + snd_config_t * softvolConfig = arg; + AFB_API_DEBUG(mixer->api, "%s... softvol config", __func__); + snd_config_delete(softvolConfig); + snd_config_update(); } PUBLIC AlsaPcmCtlT *AlsaCreateSoftvol(SoftMixerT *mixer, AlsaStreamAudioT *stream, char* slaveid, AlsaSndCtlT *sndcard, char* ctlName, int max, int open) { @@ -95,7 +100,8 @@ PUBLIC AlsaPcmCtlT *AlsaCreateSoftvol(SoftMixerT *mixer, AlsaStreamAudioT *strea goto OnErrorExit; } - stream->softvolConfig = streamConfig; + pcmVol->private_data = streamConfig; + pcmVol->private_data_clean = softVolConfigClean; // Debug config & pcm //AlsaDumpCtlConfig (mixer, "plug-config", pcmConfig, 1); diff --git a/plugins/alsa/alsa-softmixer.h b/plugins/alsa/alsa-softmixer.h index d895cef..781411d 100644 --- a/plugins/alsa/alsa-softmixer.h +++ b/plugins/alsa/alsa-softmixer.h @@ -128,6 +128,9 @@ typedef struct { bool closeAtDeletion; // intermediate pcms in the pcm chain must not be closed, else it make libasound abort() bool isPcmPlug; + + void * private_data; + void (*private_data_clean) (struct SoftMixerT_ *, void *); unsigned int quirks; } AlsaPcmCtlT; @@ -224,14 +227,17 @@ typedef struct { int ccount; AlsaPcmHwInfoT *params; struct cds_list_head list; - snd_config_t * routeConfig; + bool isPcmPlug; unsigned int quirks; } AlsaSndZoneT; + /* This is a list of known sound card (hardware or driver) specific bugs */ + /* - do not trust the result of snd_pcm_poll_descriptors_revents */ #define QUIRK_BOGUS_POLL_REVENTS_DEMANGLING (1<<0) + typedef struct { const char *uid; const char *verb; @@ -286,8 +292,6 @@ typedef struct AlsaStreamAudioT_ { struct cds_list_head list; /* link to the global list*/ AlsaPcmCtlT * softvol; - snd_config_t * softvolConfig; - snd_config_t * rateConfig; void * verbApiHandle; bool optional; bool noHwDetected; diff --git a/plugins/alsa/alsa-utils-bypath.c b/plugins/alsa/alsa-utils-bypath.c index 3a8afb7..674b4d6 100644 --- a/plugins/alsa/alsa-utils-bypath.c +++ b/plugins/alsa/alsa-utils-bypath.c @@ -93,6 +93,9 @@ PUBLIC void AlsaPcmCtlDelete(SoftMixerT* mixer, void * arg) { AFB_ApiDebug(mixer->api, "%s of %s (plug: %d)", __func__, pcmCtl->name, pcmCtl->isPcmPlug); + if (pcmCtl->private_data_clean) + pcmCtl->private_data_clean(mixer, pcmCtl->private_data); + if (!pcmCtl->closeAtDeletion) goto done; -- cgit 1.2.3-korg