From 36721c55b616bdce8b8f79ff3c7042ef54d18478 Mon Sep 17 00:00:00 2001 From: Pierre MARZIN Date: Mon, 1 Apr 2019 10:35:57 +0200 Subject: pre-init: Add a config detection Scan the loaded modules during pre-init to know which config file to load. If Avirt core module is loaded then load the avirt config file. Otherwise, load the default config file. Change the config file name in order to use the prefix to select them. Change-Id: I8f9d5ed568fa20b06ac3bef443a2392de26c8235 Signed-off-by: Pierre MARZIN --- conf.d/project/etc/smixer-4a-avirt.json | 44 ------------------------- conf.d/project/etc/smixer-4a-default.json | 55 ------------------------------- conf.d/project/etc/smixer-avirt-4a.json | 44 +++++++++++++++++++++++++ conf.d/project/etc/smixer-default-4a.json | 55 +++++++++++++++++++++++++++++++ mixer-binding/mixer-binding.c | 39 ++++++++++++++++++++-- 5 files changed, 136 insertions(+), 101 deletions(-) delete mode 100644 conf.d/project/etc/smixer-4a-avirt.json delete mode 100644 conf.d/project/etc/smixer-4a-default.json create mode 100644 conf.d/project/etc/smixer-avirt-4a.json create mode 100644 conf.d/project/etc/smixer-default-4a.json diff --git a/conf.d/project/etc/smixer-4a-avirt.json b/conf.d/project/etc/smixer-4a-avirt.json deleted file mode 100644 index 18d6193..0000000 --- a/conf.d/project/etc/smixer-4a-avirt.json +++ /dev/null @@ -1,44 +0,0 @@ -{ - "$schema": "http://iot.bzh/download/public/schema/json/ctl-schema.json", - "metadata": { - "uid": "Soft Mixer", - "version": "1.0", - "api": "smixer", - "info": "Soft Mixer emulating hardware mixer" - }, - "resources": [ - { - "uid": "softmixer-avirt", - "info": "Map avirt-loop to 4A HAL streams", - "spath": "./package/lib/plugins:./package/var:./lib/plugins:./var:/usr/libexec/agl/smixer", - "libs": ["alsa-softmixer.ctlso"] - } - ], - "onload": [ - { - "uid": "mixer-create-api", - "info": "Create Audio Router", - "action": "plugin://softmixer-avirt#MixerCreate", - "args": { - "uid":"Alsa-Mixer", - "max_loop": 1, - "max_sink": 16, - "max_source": 16, - "max_zone": 16, - "max_stream": 16, - "max_ramp": 6 - } - }, - { - "uid": "mixer-attach-loop", - "info": "Create Audio Router", - "action": "plugin://softmixer-avirt#MixerAttach", - "args": { - "loops" : { - "uid":"AVIRT-Loopback", - "path": "/dev/snd/by-path/platform-snd_avirt.0" - } - } - } - ] -} diff --git a/conf.d/project/etc/smixer-4a-default.json b/conf.d/project/etc/smixer-4a-default.json deleted file mode 100644 index d03a7a9..0000000 --- a/conf.d/project/etc/smixer-4a-default.json +++ /dev/null @@ -1,55 +0,0 @@ -{ - "$schema": "http://iot.bzh/download/public/schema/json/ctl-schema.json", - "metadata": { - "uid": "Soft Mixer", - "version": "1.0", - "api": "smixer", - "info": "Soft Mixer emulating hardware mixer" - }, - "resources": [ - { - "uid": "softmixer", - "info": "Map alsa-loop subdevices to 4A HAL streams", - "spath": "./package/lib/plugins:./package/var:./lib/plugins:./var:/usr/libexec/agl/smixer", - "libs": ["alsa-softmixer.ctlso"] - } - ], - "onload": [ - { - "uid": "mixer-create-api", - "info": "Create Audio Router", - "action": "plugin://softmixer#MixerCreate", - "args": { - "uid":"Alsa-Mixer", - "max_loop": 1, - "max_sink": 8, - "max_source": 8, - "max_zone": 8, - "max_stream": 8, - "max_ramp": 6 - } - }, - { - "uid": "mixer-attach-loop", - "info": "Create Audio Router", - "action": "plugin://softmixer#MixerAttach", - "args": { - "loops" : { - "uid":"Alsa-Loopback", - "path": "/dev/snd/by-path/platform-snd_aloop.0", - "devices" : {"playback":0, "capture":1}, - "subdevs" : [ - {"subdev": 0, "numid": 51, "uid": "loop-legacy"}, - {"subdev": 1, "numid": 57, "uid": "loop-multimedia"}, - {"subdev": 2, "numid": 63}, - {"subdev": 3, "numid": 69}, - {"subdev": 4, "numid": 75}, - {"subdev": 5, "numid": 81}, - {"subdev": 6, "numid": 87}, - {"subdev": 7, "numid": 93} - ] - } - } - } - ] -} diff --git a/conf.d/project/etc/smixer-avirt-4a.json b/conf.d/project/etc/smixer-avirt-4a.json new file mode 100644 index 0000000..18d6193 --- /dev/null +++ b/conf.d/project/etc/smixer-avirt-4a.json @@ -0,0 +1,44 @@ +{ + "$schema": "http://iot.bzh/download/public/schema/json/ctl-schema.json", + "metadata": { + "uid": "Soft Mixer", + "version": "1.0", + "api": "smixer", + "info": "Soft Mixer emulating hardware mixer" + }, + "resources": [ + { + "uid": "softmixer-avirt", + "info": "Map avirt-loop to 4A HAL streams", + "spath": "./package/lib/plugins:./package/var:./lib/plugins:./var:/usr/libexec/agl/smixer", + "libs": ["alsa-softmixer.ctlso"] + } + ], + "onload": [ + { + "uid": "mixer-create-api", + "info": "Create Audio Router", + "action": "plugin://softmixer-avirt#MixerCreate", + "args": { + "uid":"Alsa-Mixer", + "max_loop": 1, + "max_sink": 16, + "max_source": 16, + "max_zone": 16, + "max_stream": 16, + "max_ramp": 6 + } + }, + { + "uid": "mixer-attach-loop", + "info": "Create Audio Router", + "action": "plugin://softmixer-avirt#MixerAttach", + "args": { + "loops" : { + "uid":"AVIRT-Loopback", + "path": "/dev/snd/by-path/platform-snd_avirt.0" + } + } + } + ] +} diff --git a/conf.d/project/etc/smixer-default-4a.json b/conf.d/project/etc/smixer-default-4a.json new file mode 100644 index 0000000..d03a7a9 --- /dev/null +++ b/conf.d/project/etc/smixer-default-4a.json @@ -0,0 +1,55 @@ +{ + "$schema": "http://iot.bzh/download/public/schema/json/ctl-schema.json", + "metadata": { + "uid": "Soft Mixer", + "version": "1.0", + "api": "smixer", + "info": "Soft Mixer emulating hardware mixer" + }, + "resources": [ + { + "uid": "softmixer", + "info": "Map alsa-loop subdevices to 4A HAL streams", + "spath": "./package/lib/plugins:./package/var:./lib/plugins:./var:/usr/libexec/agl/smixer", + "libs": ["alsa-softmixer.ctlso"] + } + ], + "onload": [ + { + "uid": "mixer-create-api", + "info": "Create Audio Router", + "action": "plugin://softmixer#MixerCreate", + "args": { + "uid":"Alsa-Mixer", + "max_loop": 1, + "max_sink": 8, + "max_source": 8, + "max_zone": 8, + "max_stream": 8, + "max_ramp": 6 + } + }, + { + "uid": "mixer-attach-loop", + "info": "Create Audio Router", + "action": "plugin://softmixer#MixerAttach", + "args": { + "loops" : { + "uid":"Alsa-Loopback", + "path": "/dev/snd/by-path/platform-snd_aloop.0", + "devices" : {"playback":0, "capture":1}, + "subdevs" : [ + {"subdev": 0, "numid": 51, "uid": "loop-legacy"}, + {"subdev": 1, "numid": 57, "uid": "loop-multimedia"}, + {"subdev": 2, "numid": 63}, + {"subdev": 3, "numid": 69}, + {"subdev": 4, "numid": 75}, + {"subdev": 5, "numid": 81}, + {"subdev": 6, "numid": 87}, + {"subdev": 7, "numid": 93} + ] + } + } + } + ] +} diff --git a/mixer-binding/mixer-binding.c b/mixer-binding/mixer-binding.c index 64a7f05..f2b6b05 100644 --- a/mixer-binding/mixer-binding.c +++ b/mixer-binding/mixer-binding.c @@ -22,6 +22,9 @@ #include "mixer-binding.h" +#define size_temp 512 + +enum smixer_audio_mode_t { DEFAULT, AVIRT }; // default api to print log when apihandle not avalaible PUBLIC afb_api_t AFB_default; @@ -102,12 +105,44 @@ PUBLIC int afbBindingEntry(afb_api_t apiHandle) { AFB_default = apiHandle; + FILE *fp; + char temp[size_temp]; + char *prefix; + enum smixer_audio_mode_t smixer_audio_mode = DEFAULT; + AFB_API_NOTICE (apiHandle, "Controller in afbBindingEntry"); - const char *dirList= getenv("CONTROL_CONFIG_PATH"); + const char *dirList = getenv("CONTROL_CONFIG_PATH"); if (!dirList) dirList=CONTROL_CONFIG_PATH; - const char *configPath = CtlConfigSearch(apiHandle, dirList, "smixer"); + // Select correct config file + char *configPath = getenv("SMIXER_CONFIG_FILE_PATH"); + if (!configPath) { + // Do a module detection to know which audio config we need (avirt or aloop=default) + if((fp = fopen("/proc/modules", "r")) == NULL) { + goto OnErrorExit; + } + + while(fgets(temp, size_temp, fp) != NULL) { + if((strstr(temp, "snd_avirt_core")) != NULL) { + AFB_API_NOTICE (apiHandle, "CTL-INIT: AVIRT module is loaded, assume that mixer needs avirt config."); + smixer_audio_mode = AVIRT; + break; + } + } + + if(fp) fclose(fp); + + if(smixer_audio_mode == AVIRT) { + prefix = "smixer-avirt"; + } else { + prefix = "smixer-default"; + } + + configPath = CtlConfigSearch(apiHandle, dirList, prefix); + AFB_API_NOTICE (apiHandle, "CTL-INIT: configPath=%s", configPath); + } + if (!configPath) { AFB_API_ERROR(apiHandle, "CtlPreInit: No smixer-%s-* config found in %s ", GetBinderName(), dirList); goto OnErrorExit; -- cgit 1.2.3-korg