diff options
Diffstat (limited to 'plugins/alsa/alsa-api-mixer.c')
-rw-r--r-- | plugins/alsa/alsa-api-mixer.c | 50 |
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(¶msJ, "{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: |