summaryrefslogtreecommitdiffstats
path: root/plugins/alsa/alsa-api-pcm.c
diff options
context:
space:
mode:
authorStephane Desneux <stephane.desneux@iot.bzh>2018-12-22 11:51:54 +0100
committerStephane Desneux <stephane.desneux@iot.bzh>2018-12-22 11:51:54 +0100
commitc85fd2f131c73e8c21e05e1ea80b55d6a787dda6 (patch)
tree248aca4a75556e3546a3c89cac43bcffe3ccf634 /plugins/alsa/alsa-api-pcm.c
parente0f57e523112e1bc73a04e8615d7a21355f0ce0e (diff)
Implemented the bug cleanup at application exit
Fixes most memory leaks in softmixer. The concept of 'transaction' for dynamic streams has been generalized to the objects created at startup. The cleanup is done via a handle set through a atexit() call. Also added a missing strdup in alsa-api-loop, that fixes a double free. Warning, the bluez-alsa PCM are not closed in this version. This is intentional due to a BUG in the bluealsa ioplug PCM, that crashes upon close (pthread_cancel is used to terminate the io_thread and things get very bad. I have a pending fix for that, relying on a cancellation pipe, but deeper testing must be done). As an effect, only one phone call can be made, else 4a needs to be restarted Change-Id: Idb84cafe15f17c0ef02fcc70296d541dc55a2dcf Signed-off-by: Thierry Bultel <thierry.bultel@iot.bzh> Signed-off-by: Stephane Desneux <stephane.desneux@iot.bzh>
Diffstat (limited to 'plugins/alsa/alsa-api-pcm.c')
-rw-r--r--plugins/alsa/alsa-api-pcm.c45
1 files changed, 26 insertions, 19 deletions
diff --git a/plugins/alsa/alsa-api-pcm.c b/plugins/alsa/alsa-api-pcm.c
index 85e3c3a..036f158 100644
--- a/plugins/alsa/alsa-api-pcm.c
+++ b/plugins/alsa/alsa-api-pcm.c
@@ -372,11 +372,23 @@ OnErrorExit:
return;
}
+PUBLIC AlsaPcmHwInfoT* ApiPcmParamsDup(SoftMixerT* mixer, AlsaPcmHwInfoT* params) {
+ AlsaPcmHwInfoT* _params = (AlsaPcmHwInfoT*) malloc(sizeof(AlsaPcmHwInfoT));
+ if (params)
+ memcpy(_params, params, sizeof(AlsaPcmHwInfoT));
+ return _params;
+}
+
PUBLIC void ApiPcmDelParams(SoftMixerT* mixer, AlsaPcmHwInfoT* params) {
- free((char*)params->formatS);
free(params);
}
+PUBLIC void ApiPcmParamsShow(SoftMixerT * mixer, const char *msg, const AlsaPcmHwInfoT * params) {
+ AFB_ApiInfo(mixer->api, "%s PARAMS: rate=%d, format=%d, formatString=%s",
+ msg, params->rate, params->format, params->formatString);
+
+}
+
PUBLIC AlsaPcmHwInfoT * ApiPcmSetParams(SoftMixerT *mixer, const char *uid, json_object * paramsJ) {
const char *format = NULL, *access = NULL;
@@ -404,20 +416,14 @@ PUBLIC AlsaPcmHwInfoT * ApiPcmSetParams(SoftMixerT *mixer, const char *uid, json
}
}
+ // default format
if (!format) {
params->format = SND_PCM_FORMAT_S16_LE;
- params->formatS = strdup("S16_LE");
- if (params->formatS == NULL) {
- SOFTMIXER_NOMEM(mixer->api);
- goto fail_params;
- }
+ strcpy(params->formatString, SND_FORMAT_DEFAULT);
goto check_access;
}
- params->formatS = strdup(format);
- if (params->formatS == NULL) {
- SOFTMIXER_NOMEM(mixer->api);
- goto fail_params;
- }
+ strncpy(params->formatString, format, SND_FORMAT_STRING_LEN);
+
#define FORMAT_CHECK(arg) if (!strcmp(format,#arg)) { params->format = SND_PCM_FORMAT_##arg; goto check_access; }
FORMAT_CHECK(S16_LE);
@@ -441,7 +447,7 @@ PUBLIC AlsaPcmHwInfoT * ApiPcmSetParams(SoftMixerT *mixer, const char *uid, json
goto fail_params;
check_access:
- AFB_ApiNotice(mixer->api, "%s: %s format set to SND_PCM_FORMAT_%s", __func__, uid, params->formatS);
+ AFB_ApiNotice(mixer->api, "%s: %s format set to SND_PCM_FORMAT_%s", __func__, uid, params->formatString);
#define ACCESS_CHECK(arg) if (!strcmp(access,#arg)) { params->access = SND_PCM_ACCESS_##arg; goto success;}
@@ -466,33 +472,33 @@ success:
return params;
fail_params:
- free(params);
+ ApiPcmDelParams(mixer, params);
fail:
return NULL;
}
static void pcmChannelsDestroy(SoftMixerT * mixer, AlsaSndPcmT * pcm) {
- AFB_ApiDebug(mixer->api, "%s: pcm %s (%d channels)", __func__, pcm->uid, pcm->nbChannels);
+ AFB_ApiDebug(mixer->api, "\t%s: pcm %s (%d channels)", __func__, pcm->uid, pcm->nbChannels);
AlsaPcmChannelT * channel, *tmp;
cds_list_for_each_entry_safe(channel, tmp, &pcm->channels.list, list) {
cds_list_del(&channel->list);
- AFB_ApiDebug(mixer->api, "%s: del channel %s", __func__, channel->uid);
free((char *)channel->uid);
free(channel);
}
- AFB_ApiDebug(mixer->api, "%s: pcm %s DONE", __func__, pcm->uid);
+ AFB_ApiDebug(mixer->api, "\t%s: pcm %s DONE", __func__, pcm->uid);
}
PUBLIC void ApiPcmDelete(SoftMixerT * mixer, AlsaSndPcmT * pcm) {
- AFB_ApiDebug(mixer->api, "%s: pcm %s", __func__, pcm->uid);
+ AFB_ApiDebug(mixer->api, "%s: pcm %s\n", __func__, pcm->uid);
free(pcm->apiVerbHandle);
AlsaSndCtlT * card = pcm->sndcard;
- if (card->cid.pcmplug_params)
+ if (card->cid.pcmplug_params) {
free((char*)card->cid.pcmplug_params);
+ }
pcmChannelsDestroy(mixer, pcm);
@@ -503,10 +509,11 @@ PUBLIC void ApiPcmDelete(SoftMixerT * mixer, AlsaSndPcmT * pcm) {
if (pcm->verb &&
(strcmp(pcm->verb, SOFTMIXER_VERB_NONE)!=0)) {
- int error = afb_api_del_verb(mixer->api, pcm->verb, (void**)&pcm->apiVerbHandle);
+ int error = afb_api_del_verb(mixer->api, pcm->verb, (void**)NULL);
if (error) {
AFB_ApiError(mixer->api, "Failed to remove verb %s", pcm->verb);
}
+ free((char*)pcm->verb);
}
free((char*)pcm->uid);