From 253df14bd84f535a54f4d12c95399899e1343c20 Mon Sep 17 00:00:00 2001 From: Fulup Ar Foll Date: Thu, 17 May 2018 21:43:24 +0200 Subject: Initial version with dynamic APIs --- conf.d/cmake/config.cmake | 4 +- conf.d/project/etc/4a-softmixer-config.json | 42 ------ conf.d/project/etc/4a-softmixer-test.json | 75 ++++++++++ conf.d/project/lua.d/softmixer-simple-test.lua | 142 +++++++++++++++++++ conf.d/project/lua.d/softmixer-simple.lua | 181 ------------------------- 5 files changed, 219 insertions(+), 225 deletions(-) delete mode 100644 conf.d/project/etc/4a-softmixer-config.json create mode 100644 conf.d/project/etc/4a-softmixer-test.json create mode 100644 conf.d/project/lua.d/softmixer-simple-test.lua delete mode 100644 conf.d/project/lua.d/softmixer-simple.lua (limited to 'conf.d') diff --git a/conf.d/cmake/config.cmake b/conf.d/cmake/config.cmake index afba6b7..5f5bc23 100644 --- a/conf.d/cmake/config.cmake +++ b/conf.d/cmake/config.cmake @@ -131,8 +131,8 @@ list(APPEND link_libraries afb-helpers) set(CONTROL_SUPPORT_LUA 1) add_definitions(-DCONTROL_PLUGIN_PATH="${CMAKE_BINARY_DIR}/package/lib/plugins:${CMAKE_INSTALL_PREFIX}/${PROJECT_NAME}/lib/plugins") -add_definitions(-DCONTROL_CONFIG_PATH="${CMAKE_BINARY_DIR}/package/etc:${CMAKE_INSTALL_PREFIX}/${PROJECT_NAME}/etc") -add_definitions(-DCONTROL_LUA_PATH="${CMAKE_SOURCE_DIR}/conf.d/project/lua.d:${CMAKE_INSTALL_PREFIX}/${PROJECT_NAME}/data") +add_definitions(-DCONTROL_CONFIG_PATH="${CMAKE_SOURCE_DIR}/conf.d/project/etc:${CMAKE_BINARY_DIR}/package/etc:${CMAKE_INSTALL_PREFIX}/${PROJECT_NAME}/etc") +add_definitions(-DCONTROL_LUA_PATH="${CMAKE_SOURCE_DIR}/conf.d/project/lua.d:${CMAKE_INSTALL_PREFIX}/${PROJECT_NAME}/var") add_definitions(-DCTL_PLUGIN_MAGIC=987456123) add_definitions(-DUSE_API_DYN=1 -DAFB_BINDING_VERSION=dyn) diff --git a/conf.d/project/etc/4a-softmixer-config.json b/conf.d/project/etc/4a-softmixer-config.json deleted file mode 100644 index e67709f..0000000 --- a/conf.d/project/etc/4a-softmixer-config.json +++ /dev/null @@ -1,42 +0,0 @@ -{ - "$schema": "http://iot.bzh/download/public/schema/json/ctl-schema.json", - "metadata": { - "uid": "Soft Mixer", - "version": "1.0", - "api": "softmixer", - "info": "Soft Mixer emulating hardware mixer" - }, - "resources": [ - { - "uid": "alsa-softmixer", - "info": "Map alsa-loop subdevices to 4A HAL streams", - "spath":"./plugins/alsa:../conf.d/project/lua.d", - "libs": ["alsa-router.ctlso", "softmixer-simple.lua"], - "lua": {"prefix":"smix","functions": ["snd_cards", "snd_zones", "snd_loops", "snd_streams"]} - } - ], - - "onload": [ - { - "uid": "init-soft-mixer", - "info": "Initialise Audio Router", - "action": "lua://alsa-softmixer#_init_softmixer_" - } - ], - - "controls": [ - { - "uid": "mixer-config", - "action": "lua://alsa-softmixer#_mixer_config_" - }, - { - "uid": "snd-cards", - "action": "plugin://alsa-softmixer#snd_cards" - }, - { - "uid": "snd-zone", - "action": "plugin://alsa-softmixer#snd_zones" - } - ] - -} diff --git a/conf.d/project/etc/4a-softmixer-test.json b/conf.d/project/etc/4a-softmixer-test.json new file mode 100644 index 0000000..f363a55 --- /dev/null +++ b/conf.d/project/etc/4a-softmixer-test.json @@ -0,0 +1,75 @@ +{ + "$schema": "http://iot.bzh/download/public/schema/json/ctl-schema.json", + "metadata": { + "uid": "Soft Mixer", + "version": "1.0", + "api": "softmixer", + "info": "Soft Mixer emulating hardware mixer" + }, + "resources": [ + { + "uid": "softmixer", + "info": "Map alsa-loop subdevices to 4A HAL streams", + "spath": "./plugins/alsa:../conf.d/project/lua.d", + "libs": ["alsa-softmixer.ctlso", "softmixer-simple-test.lua"], + "lua": { + "prefix": "smix", + "functions": ["_mixer_new_"] + } + } + ], + + "onload": [ + { + "uid": "init-soft-mixer", + "info": "Initialise Audio Router", + "action": "lua://softmixer#_mixer_simple_test_" + } + ], + "controls": [ + { + "uid": "new", + "action": "plugin://softmixer#_mixer_new_", + "args": { + "devices": { + "playback": 0, + "capture": 1 + }, + "subdevs": [ + { + "subdev": 0, + "numid": 51 + }, + { + "subdev": 1, + "numid": 57 + }, + { + "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/lua.d/softmixer-simple-test.lua b/conf.d/project/lua.d/softmixer-simple-test.lua new file mode 100644 index 0000000..6d6dffc --- /dev/null +++ b/conf.d/project/lua.d/softmixer-simple-test.lua @@ -0,0 +1,142 @@ +--[[ + Copyright (C) 2016 "IoT.bzh" + Author Fulup Ar Foll + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + NOTE: strict mode: every global variables should be prefixed by '_' +--]] + +-- Static variables should be prefixed with _ +_EventHandle={} + +-- Call when AlsaCore return HAL active list +function _AlsaPingCB_ (source, result, context) + + AFB:notice (source, "--InLua-- PingCB: result='%s'", Dump_Table(result)) + +end + + +-- Display receive arguments and echo them to caller +function _mixer_simple_test_ (source, args) + do + local error + local response + + -- ================== Default Alsa snd-aloop numid and subdev config + local aloop = { + ["devices"] = {["playback"]=0,["capture"]=1}, + ["subdevs"] = { + {["subdev"]= 0, ["numid"]= 51}, + {["subdev"]= 1, ["numid"]= 57}, + {["subdev"]= 2, ["numid"]= 63}, + {["subdev"]= 3, ["numid"]= 69}, + {["subdev"]= 4, ["numid"]= 75}, + {["subdev"]= 5, ["numid"]= 81}, + {["subdev"]= 6, ["numid"]= 87}, + {["subdev"]= 7, ["numid"]= 93}, + } + } + + -- ==================== Default rate =========================== + + local audio_defaults = { + ["rate"] = 48000, + } + + -- ======================= Loop PCM =========================== + local snd_aloop = { + ["uid"] = "Alsa-Loop", + ["devpath"] = "/dev/snd/by-path/platform-snd_aloop.0", + ["params"] = audio_defaults, + ["devices"] = aloop.devices, + ["subdevs"] = aloop.subdevs, + } + + + -- ============================= Sound Cards =================== + local snd_yamaha = { + ["uid"]= "YAMAHA-APU70", + ["devpath"]= "/dev/snd/by-id/usb-YAMAHA_Corporation_YAMAHA_AP-U70_USB_Audio_00-00", + ["params"] = snd_params, + ["sink"] = { + [0]= {["uid"]= "front-right", ["port"]= 0}, + [1]= {["uid"]= "front-left", ["port"]= 1}, + } + } + + local snd_jabra= { + ["uid"]= "Jabra-Solemate", + ["devpath"]= "/dev/snd/by-id/usb-0b0e_Jabra_SOLEMATE_v1.34.0-00", + ["params"] = snd_params, + ["sink"] = { + [0]= {["uid"]= "front-right", ["port"]= 0}, + [1]= {["uid"]= "front-left", ["port"]= 1}, + } + } + + + -- ============================= Zones =================== + local zone_front= { + ["uid"] = "front-seats", + ["type"] = "playback", + ["mapping"] = { + {["target"]="front-right",["channel"]=0}, + {["target"]="front-left" ,["channel"]=1}, + } + } + + -- =================== Audio Stream ============================ + local stream_music= { + ["uid"] = "multimedia", + ["zone"] = "front-seats", + ["volume"]= 70, + ["mute"] = false, + } + + local stream_navigation= { + ["uid"] = "navigation", + ["zone"] = "front-seats", + ["volume"]= 80, + ["mute"] = false, + } + + --- ================ Create Mixer ========================= + local MyMixer= { + ["uid"]="Simple_Mixer", + ["backend"] = {snd_yamaha}, + ["frontend"]= {snd_aloop}, + ["zones"] = {zone_front}, + ["streams"] = {stream_music,stream_navigation}, + } + + local error,response= smix:_mixer_new_ (source, MyMixer) + if (error ~= 0) then + AFB:error (source, "--InLua-- smix:_mixer_new_ fail config=%s", Dump_Table(aloop)) + goto OnErrorExit + else + AFB:notice (source, "--InLua-- smix:_mixer_new_ done response=%s\n", Dump_Table(response)) + end + + + -- ================== Happy End ============================= + AFB:notice (source, "--InLua-- _mixer_config_ done") + return 0 end + + -- ================= Unhappy End ============================ + ::OnErrorExit:: + AFB:error (source, "--InLua-- snd_attach fail") + return 1 -- unhappy end -- +end diff --git a/conf.d/project/lua.d/softmixer-simple.lua b/conf.d/project/lua.d/softmixer-simple.lua deleted file mode 100644 index e78eacd..0000000 --- a/conf.d/project/lua.d/softmixer-simple.lua +++ /dev/null @@ -1,181 +0,0 @@ ---[[ - Copyright (C) 2016 "IoT.bzh" - Author Fulup Ar Foll - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - - - NOTE: strict mode: every global variables should be prefixed by '_' ---]] - --- Static variables should be prefixed with _ -_EventHandle={} - --- Call when AlsaCore return HAL active list -function _AlsaPingCB_ (source, result, context) - - AFB:notice (source, "--InLua-- PingCB: result='%s'", Dump_Table(result)) - -end - - --- Display receive arguments and echo them to caller -function _mixer_config_ (source, args) - do - local error - local response - - -- ==================== Default rate =========================== - - local audio_defaults = { - ["rate"] = 48000, - } - - -- ======================= Loop PCM =========================== - - local snd_aloop = { - ["uid"] = "Alsa-Loop", - ["devpath"] = "/dev/snd/by-path/platform-snd_aloop.0", - ["devices"] = {["playback"]=0,["capture"]=1}, - ["params"] = audio_defaults, - ["subdevs"] = { - {["subdev"]= 0, ["numid"]= 51}, - {["subdev"]= 1, ["numid"]= 57}, - {["subdev"]= 2, ["numid"]= 63}, - {["subdev"]= 3, ["numid"]= 69}, - {["subdev"]= 4, ["numid"]= 75}, - {["subdev"]= 5, ["numid"]= 81}, - {["subdev"]= 6, ["numid"]= 87}, - {["subdev"]= 7, ["numid"]= 93}, - } - } - - error,response= smix:snd_loops (source, snd_aloop) - if (error ~= 0) then - AFB:error (source, "--InLua-- smix:snd_loops fail to attach sndcards=%s", Dump_Table(aloop)) - goto OnErrorExit - else - AFB:notice (source, "--InLua-- smix:snd_loops done response=%s\n", Dump_Table(response)) - end - - - -- ============================= Sound Cards =================== - - local snd_yamaha = { - ["uid"]= "YAMAHA-APU70", - ["devpath"]= "/dev/snd/by-id/usb-YAMAHA_Corporation_YAMAHA_AP-U70_USB_Audio_00-00", - ["params"] = snd_params, - ["sink"] = { - [0]= {["uid"]= "front-right", ["port"]= 0}, - [1]= {["uid"]= "front-left", ["port"]= 1}, - } - } - - local snd_jabra= { - ["uid"]= "Jabra-Solemate", - ["devpath"]= "/dev/snd/by-id/usb-0b0e_Jabra_SOLEMATE_v1.34.0-00", - ["params"] = snd_params, - ["sink"] = { - [0]= {["uid"]= "front-right", ["port"]= 0}, - [1]= {["uid"]= "front-left", ["port"]= 1}, - } - } - - -- group sound card as one multi channels card - local sndcards= { - snd_yamaha, - } - - error,response= smix:snd_cards (source, sndcards) - if (error ~= 0) then - AFB:error (source, "--InLua-- smix:snd_cards fail to attach sndcards=%s", Dump_Table(sndcards)) - goto OnErrorExit - else - AFB:notice (source, "--InLua-- smix:snd_cards done response=%s\n", Dump_Table(response)) - end - - -- ============================= Zones =================== - - local zone_front= { - ["uid"] = "front-seats", - ["type"] = "playback", - ["mapping"] = { - {["target"]="front-right",["channel"]=0}, - {["target"]="front-left" ,["channel"]=1}, - } - } - - local multi_zones = { - zone_front, - } - - error,response= smix:snd_zones (source, multi_zones) - if (error ~= 0) then - AFB:error (source, "--InLua-- smix:snd_zones fail to attach sndcards=%s", Dump_Table(multi_zones)) - goto OnErrorExit - else - AFB:notice (source, "--InLua-- smix:snd_zones done response=%s\n", Dump_Table(response)) - end - - -- =================== Audio Stream ============================ - - local stream_music= { - ["uid"] = "multimedia", - ["zone"] = "front-seats", - ["volume"]= 70, - ["mute"] = false, - } - - local stream_navigation= { - ["uid"] = "navigation", - ["zone"] = "front-seats", - ["volume"]= 80, - ["mute"] = false, - } - - local snd_streams = { - stream_music, - stream_navigation, - } - - error,response= smix:snd_streams (source, snd_streams) - if (error ~= 0) then - AFB:error (source, "--InLua-- smix:snd_streams fail to attach sndcards=%s", Dump_Table(aloop)) - goto OnErrorExit - else - AFB:notice (source, "--InLua-- smix:streams_loops done response=%s\n", Dump_Table(response)) - end - - - -- ================== Happy End ============================= - AFB:notice (source, "--InLua-- _mixer_config_ done") - return 0 end - - -- ================= Unhappy End ============================ - ::OnErrorExit:: - AFB:error (source, "--InLua-- snd_attach fail") - return 1 -- unhappy end -- -end - --- Display receive arguments and echo them to caller -function _init_softmixer_ (source, args) - - printf ("*********** in print ") - -- create event to push change audio roles to potential listeners - _EventHandle=AFB:evtmake(source, "control") - - _mixer_config_ (source, args) - -end - -printf ("*********** load done ") -- cgit 1.2.3-korg