From 9aaabade8674f8e87621512dfb5389cc3cdbda6e Mon Sep 17 00:00:00 2001 From: Mark Farrugia Date: Tue, 9 Apr 2019 10:49:37 +1000 Subject: Updates for latest libavirt, adds avirt cleanup Cleanup for avirt is introduced. There are still some issues with this when invoked whilst a PCM is active, This now allows 4A to be restarted without a reboot. Loops must be deleted last to avoid any cleanup issues, so to enforce this a new transaction API is added: AlsaMixerTransactionObjectAddTail. Change-Id: Ide4bbb319e8c6a2f4209ab957d80a54690f76de4 Signed-off-by: Mark Farrugia --- plugins/alsa/alsa-api-loop.c | 11 ++++++++--- plugins/alsa/alsa-transaction.c | 21 +++++++++++++++++++++ plugins/alsa/alsa-transaction.h | 1 + 3 files changed, 30 insertions(+), 3 deletions(-) (limited to 'plugins/alsa') diff --git a/plugins/alsa/alsa-api-loop.c b/plugins/alsa/alsa-api-loop.c index e5e6af5..7e852a8 100644 --- a/plugins/alsa/alsa-api-loop.c +++ b/plugins/alsa/alsa-api-loop.c @@ -159,7 +159,7 @@ STATIC AlsaLoopSubdevT *ProcessOneAvirtSubdev(SoftMixerT *mixer, AlsaSndLoopT *l } error = snd_avirt_stream_new(uid, zone->ccount, - SND_PCM_STREAM_PLAYBACK, "ap_loopback"); + SND_PCM_STREAM_PLAYBACK, "ap_loopback", false); if (error < 0) { AFB_ApiError(mixer->api, "%s: mixer=%s stream=%s could not create AVIRT stream [errno=%d]", @@ -363,7 +363,7 @@ STATIC AlsaSndLoopT *AttachOneLoop(SoftMixerT *mixer, const char *uid, json_obje goto fail_snd_card; } - snd_avirt_card_seal(); + snd_avirt_card_configure(); // try to open sound card control interface loop->sndcard->ctl = AlsaByPathOpenCtl(mixer, loop->uid, loop->sndcard); @@ -413,6 +413,10 @@ static void loopDestroy(SoftMixerT * mixer, void* arg) { mixer->nbLoops--; cds_list_del(&loop->list); + + if (loop->avirt) + snd_avirt_card_unconfigure(); + free(loop); AFB_ApiDebug(mixer->api, "DONE !"); @@ -427,7 +431,8 @@ static AlsaSndLoopT * loopCreate(SoftMixerT *mixer, const char *uid, json_object mixer->nbLoops++; cds_list_add(&newLoop->list, &mixer->loops.list); - AlsaMixerTransactionObjectAdd(mixer->transaction, newLoop, loopDestroy); + /* We need the loops to be at the end of the list, so that they are destroyed last */ + AlsaMixerTransactionObjectAddTail(mixer->transaction, newLoop, loopDestroy); loopsDisplay(mixer); diff --git a/plugins/alsa/alsa-transaction.c b/plugins/alsa/alsa-transaction.c index 1958c87..dcfd028 100644 --- a/plugins/alsa/alsa-transaction.c +++ b/plugins/alsa/alsa-transaction.c @@ -67,6 +67,27 @@ fail: } +bool AlsaMixerTransactionObjectAddTail(AlsaMixerTransaction* list, void* object, AlsaTransactionDestructor destructor) { + bool ret = false; + AlsaMixerTransactionDataItem * newItem = NULL; + if (!list) + goto fail; + + newItem = (AlsaMixerTransactionDataItem *) malloc(sizeof(AlsaMixerTransactionDataItem)); + if (newItem == NULL) + goto fail; + + CDS_INIT_LIST_HEAD(&newItem->list_entry); + newItem->object = object; + newItem->destructor = destructor; + cds_list_add_tail(&newItem->list_entry, &list->item_list); + + ret = true; +fail: + return ret; + +} + void AlsaMixerTransactionDoCleanup(AlsaMixerTransaction* transaction) { AlsaMixerTransactionDataItem * item, *sav; diff --git a/plugins/alsa/alsa-transaction.h b/plugins/alsa/alsa-transaction.h index dd6e91b..ba45ae7 100644 --- a/plugins/alsa/alsa-transaction.h +++ b/plugins/alsa/alsa-transaction.h @@ -30,6 +30,7 @@ extern void AlsaMixerTransactionDelete(AlsaMixerTransaction * transaction); extern void AlsaMixerTransactionDataListDestroy(AlsaMixerTransaction*); extern bool AlsaMixerTransactionObjectAdd(AlsaMixerTransaction*, void * object, AlsaTransactionDestructor destructor); +extern bool AlsaMixerTransactionObjectAddTail(AlsaMixerTransaction* list, void* object, AlsaTransactionDestructor destructor); extern void AlsaMixerTransactionObjectForget(AlsaMixerTransaction* list, void * object); -- cgit 1.2.3-korg