summaryrefslogtreecommitdiffstats
path: root/plugins/alsa/alsa-api-mixer.c
diff options
context:
space:
mode:
authorThierry Bultel <thierry.bultel@iot.bzh>2019-02-13 11:30:53 +0100
committerThierry Bultel <thierry.bultel@iot.bzh>2019-02-18 15:51:30 +0100
commitedeccfc0d062117bdb74c86044e197372ca25885 (patch)
tree188927e042902e0907d128aed5902a4b84ec0b39 /plugins/alsa/alsa-api-mixer.c
parent0e9718e4158355093b281c1376ba9b0ed049d447 (diff)
alsa-transaction: simplify the cleanup
This simplifies the invocation of cleanup, by only using AlsaMixerTransactionDelete that performs the 3 actions of cleanup, removal from list, and memory freeing. Fixes a bug at MixerExit, because the first transaction was not removed from the list and led to a double free error. Also added a boolean parameter to AlsaMixerTransactionObjectDelete (was AlsaMixerTransactionObjectForget before), that decides wether or not the found object must be destroyed with its destructor (for most of the cases) or simply freed in memory (which is needed for loop device). Change-Id: I2eacbf80a22e3d556dc432d393a1807fcd7c47fb Signed-off-by: Thierry Bultel <thierry.bultel@iot.bzh>
Diffstat (limited to 'plugins/alsa/alsa-api-mixer.c')
-rw-r--r--plugins/alsa/alsa-api-mixer.c42
1 files changed, 18 insertions, 24 deletions
diff --git a/plugins/alsa/alsa-api-mixer.c b/plugins/alsa/alsa-api-mixer.c
index ebb8c25..bc27e24 100644
--- a/plugins/alsa/alsa-api-mixer.c
+++ b/plugins/alsa/alsa-api-mixer.c
@@ -32,7 +32,7 @@ static json_object *LoopsJ = NULL;
static void MixerExit() {
SoftMixerT *mixer, *tmp;
- printf("%s !\n", __func__);
+ printf("-------------------------- %s ------------------------!\n", __func__);
cds_list_for_each_entry_safe(mixer, tmp, &mixerList, list) {
// remove this mixer from the global mixer list
@@ -41,13 +41,12 @@ static void MixerExit() {
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);
}
+ AFB_API_INFO(mixer->api, "Mixer %s terminated", mixer->uid);
MixerDelete(mixer);
}
- printf("%s DONE ! Bye !\n", __func__);
+ printf("------------------------- %s DONE ! Bye ! --------------\n", __func__);
}
CTLP_ONLOAD(plugin, callbacks){
@@ -582,7 +581,7 @@ STATIC void MixerAttachVerb(afb_req_t request) {
if (playbacksJ) {
error = ApiSinkAttach(mixer, request, uid, playbacksJ);
- if (error) goto fail_loop;
+ if (error) goto fail;
json_object *resultJ = MixerInfoPcms(mixer, playbacksJ, SND_PCM_STREAM_PLAYBACK, 0);
json_object_object_add(responseJ, "playbacks", resultJ);
@@ -594,7 +593,7 @@ STATIC void MixerAttachVerb(afb_req_t request) {
error = ApiSourceAttach(mixer, request, uid, capturesJ);
if (error) {
AFB_API_ERROR(mixer->api,"%s: source attach failed", __func__);
- goto fail_sink;
+ goto fail;
}
json_object *resultJ = MixerInfoPcms(mixer, capturesJ, SND_PCM_STREAM_CAPTURE, 0);
@@ -606,7 +605,7 @@ STATIC void MixerAttachVerb(afb_req_t request) {
if (zonesJ) {
error = ApiZoneAttach(mixer, request, uid, zonesJ);
if (error)
- goto fail_source;
+ goto fail;
json_object *resultJ = MixerInfoZones(mixer, zonesJ, 0);
json_object_object_add(responseJ, "zone", resultJ);
@@ -619,7 +618,8 @@ STATIC void MixerAttachVerb(afb_req_t request) {
AFB_API_INFO(mixer->api, "%s set LOOPS/AVIRT", __func__);
error = ApiLoopAttach(mixer, request, uid,
((loopsJ) ? loopsJ : LoopsJ), streamsJ);
- if (error) goto fail_loop;
+ if (error)
+ goto fail;
}
AFB_API_INFO(mixer->api, "%s set RAMPS", __func__);
@@ -627,7 +627,7 @@ STATIC void MixerAttachVerb(afb_req_t request) {
if (rampsJ) {
error = ApiRampAttach(mixer, request, uid, rampsJ);
if (error)
- goto fail_zone;
+ goto fail;
json_object *resultJ = MixerInfoRamps(mixer, rampsJ, 0);
json_object_object_add(responseJ, "ramps", resultJ);
@@ -638,7 +638,7 @@ STATIC void MixerAttachVerb(afb_req_t request) {
if (streamsJ) {
error = ApiStreamAttach(mixer, request, uid, prefix, streamsJ);
if (error)
- goto fail_ramp;
+ goto fail;
json_object *resultJ = MixerInfoStreams(mixer, streamsJ, 0);
json_object_object_add(responseJ, "streams", resultJ);
@@ -648,7 +648,7 @@ STATIC void MixerAttachVerb(afb_req_t request) {
if (error) {
AFB_API_ERROR(mixer->api, "%s mixer=%s verb=%s fail to register post attach Verb ",
__func__, mixer->uid, uid);
- goto fail_stream;
+ goto fail;
}
AFB_API_NOTICE(mixer->api, "%s responseJ=%s", __func__, json_object_get_string(responseJ));
@@ -657,22 +657,12 @@ STATIC void MixerAttachVerb(afb_req_t request) {
AFB_API_INFO(mixer->api,"%s DONE", __func__);
return;
-fail_stream:
- // TODO remove created streams
-fail_ramp:
- // TODO remove created ramps
-fail_zone:
- // TODO remove created zone
-fail_loop:
- // TODO remove created loops
-fail_source:
- // TODO remove created sources
-fail_sink:
- // TODO remove created sinks
fail:
if (mixer->transaction)
- free(mixer->transaction);
+ AlsaMixerTransactionDelete(mixer->transaction);
+
+ mixer->transaction = NULL;
AFB_API_ERROR(mixer->api,"%s FAILED", __func__);
return;
@@ -771,6 +761,10 @@ CTLP_CAPI(MixerAttach, source, argsJ, responseJ) {
return 0;
OnErrorExit:
+ if (mixer->transaction)
+ AlsaMixerTransactionDelete(mixer->transaction);
+
+ mixer->transaction = NULL;
return -1;
}