summaryrefslogtreecommitdiffstats
path: root/plugins/alsa/alsa-api-mixer.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-mixer.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-mixer.c')
-rw-r--r--plugins/alsa/alsa-api-mixer.c50
1 files changed, 49 insertions, 1 deletions
diff --git a/plugins/alsa/alsa-api-mixer.c b/plugins/alsa/alsa-api-mixer.c
index ae08461..6d80b55 100644
--- a/plugins/alsa/alsa-api-mixer.c
+++ b/plugins/alsa/alsa-api-mixer.c
@@ -23,6 +23,38 @@
#include <string.h>
#include <pthread.h>
+static struct cds_list_head mixerList;
+
+static void MixerDelete(SoftMixerT * mixer);
+
+static void MixerExit() {
+ SoftMixerT *mixer, *tmp;
+ printf("%s !\n", __func__);
+
+ cds_list_for_each_entry_safe(mixer, tmp, &mixerList, list) {
+ // remove this mixer from the global mixer list
+ cds_list_del(&mixer->list);
+ AFB_ApiInfo(mixer->api, "Terminating mixer %s", mixer->uid);
+
+ AlsaMixerTransaction * transaction, * tmp_trans;
+ cds_list_for_each_entry_safe(transaction, tmp_trans, &mixer->transactionList, transaction_node) {
+ cds_list_del(&transaction->transaction_node);
+ AlsaMixerTransactionDoCleanup(transaction);
+ AlsaMixerTransactionDelete(transaction);
+ }
+ MixerDelete(mixer);
+ }
+ printf("%s DONE ! Bye !\n", __func__);
+}
+
+CTLP_ONLOAD(plugin, callbacks){
+
+ AFB_ApiInfo(plugin->api, "MIXER INIT");
+ CDS_INIT_LIST_HEAD(&mixerList);
+
+ atexit(MixerExit);
+ return 0;
+}
static void MixerRemoveVerb(AFB_ReqT request) {
@@ -249,7 +281,7 @@ STATIC json_object *MixerInfoOneZone(AlsaSndZoneT *zone, int verbose) {
json_object *paramsJ;
wrap_json_pack(&paramsJ, "{si,ss,si}"
, "rate", zone->params->rate
- , "format", zone->params->formatS
+ , "format", zone->params->formatString
, "channels", zone->params->channels
);
json_object_object_add(responseJ, "params", paramsJ);
@@ -514,6 +546,8 @@ STATIC void MixerAttachVerb(AFB_ReqT request) {
int error;
AlsaMixerTransaction * transaction = NULL;
+ AFB_ApiInfo(mixer->api, "%s: %s", __func__, json_object_get_string(argsJ));
+
error = wrap_json_unpack(argsJ, "{ss,s?s,s?s,s?o,s?o,s?o,s?o,s?o,s?o !}"
, "uid", &uid
, "prefix", &prefix
@@ -688,6 +722,8 @@ CTLP_CAPI(MixerAttach, source, argsJ, responseJ) {
goto OnErrorExit;
}
+ mixer->transaction = transaction;
+
if (playbackJ) {
error = ApiSinkAttach(mixer, NULL, uid, playbackJ);
if (error) goto OnErrorExit;
@@ -718,6 +754,8 @@ CTLP_CAPI(MixerAttach, source, argsJ, responseJ) {
if (error) goto OnErrorExit;
}
+ mixer->transaction = NULL;
+
// return mixer info data after attach
return 0;
@@ -725,7 +763,14 @@ OnErrorExit:
return -1;
}
+static void MixerDelete(SoftMixerT * mixer) {
+ free((char*)mixer->info);
+ free((char*)mixer->uid);
+ free(mixer);
+}
+
CTLP_CAPI(MixerCreate, source, argsJ, responseJ) {
+
SoftMixerT *mixer = calloc(1, sizeof (SoftMixerT));
if (mixer == NULL) {
SOFTMIXER_NOMEM(source->api);
@@ -790,6 +835,7 @@ CTLP_CAPI(MixerCreate, source, argsJ, responseJ) {
CDS_INIT_LIST_HEAD(&mixer->zones.list);
CDS_INIT_LIST_HEAD(&mixer->streams.list);
CDS_INIT_LIST_HEAD(&mixer->ramps.list);
+ CDS_INIT_LIST_HEAD(&mixer->transactionList);
mixer->sdLoop = AFB_GetEventLoop(source->api);
mixer->api = source->api;
@@ -799,6 +845,8 @@ CTLP_CAPI(MixerCreate, source, argsJ, responseJ) {
if (error)
goto fail_info;
+ cds_list_add_tail(&mixer->list, &mixerList);
+
return 0;
fail_info: