summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorFulup Ar Foll <fulup@iot.bzh>2018-04-30 23:30:10 +0200
committerFulup Ar Foll <fulup@iot.bzh>2018-04-30 23:30:10 +0200
commit17edfc4c20cfd855d68e5b0ef044da2e7509f3f3 (patch)
treefe33046462ede30e6faaabbac82e1b75d49f28af /plugins
parent8372b87f2be8fe5b8655001e92572af4d96ddbf6 (diff)
On going effort, now load and support LUA+C plugin
Diffstat (limited to 'plugins')
-rw-r--r--plugins/CMakeLists.txt28
-rw-r--r--plugins/alsa/CMakeLists.txt42
-rw-r--r--plugins/alsa/alsa-dmix.c67
-rw-r--r--plugins/alsa/alsa-lua.c45
-rw-r--r--plugins/alsa/alsa-softmixer.c55
-rw-r--r--plugins/alsa/alsa-softmixer.h (renamed from plugins/alsa-router.c)33
-rw-r--r--plugins/alsa/alsa-tools-high.c66
-rw-r--r--plugins/alsa/alsa-tools-low.c55
8 files changed, 353 insertions, 38 deletions
diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt
index 644e359..28a0609 100644
--- a/plugins/CMakeLists.txt
+++ b/plugins/CMakeLists.txt
@@ -1,13 +1,13 @@
###########################################################################
# Copyright 2015, 2016, 2017 IoT.bzh
#
-# author: Romain Forlot <romain.forlot@iot.bzh>
+# author: Fulup Ar Foll <fulup@iot.bzh>
#
# 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
+# 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,
@@ -17,24 +17,6 @@
###########################################################################
-PROJECT_TARGET_ADD(alsa-router)
-
- # Define targets
- ADD_LIBRARY(${TARGET_NAME} MODULE ${TARGET_NAME}.c)
-
- # Alsa Plugin properties
- SET_TARGET_PROPERTIES(${TARGET_NAME} PROPERTIES
- LABELS "PLUGIN"
- PREFIX ""
- SUFFIX ".ctlso"
- OUTPUT_NAME ${TARGET_NAME}
- )
-
- # Library dependencies (include updates automatically)
- TARGET_LINK_LIBRARIES(${TARGET_NAME}
- ${link_libraries}
- )
-
- target_include_directories(${TARGET_NAME}
- PRIVATE "../app-controller-submodule/ctl-lib"
- PRIVATE "../mixer-binding")
+# Include any directory not starting with _
+# -----------------------------------------------------
+PROJECT_SUBDIRS_ADD(${PROJECT_SRC_DIR_PATTERN})
diff --git a/plugins/alsa/CMakeLists.txt b/plugins/alsa/CMakeLists.txt
new file mode 100644
index 0000000..51f4639
--- /dev/null
+++ b/plugins/alsa/CMakeLists.txt
@@ -0,0 +1,42 @@
+###########################################################################
+# Copyright 2015, 2016, 2017 IoT.bzh
+#
+# author: Romain Forlot <romain.forlot@iot.bzh>
+#
+# 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.
+###########################################################################
+
+
+PROJECT_TARGET_ADD(alsa-router)
+
+ file(GLOB SOURCE_FILES "alsa-*.c")
+
+ # Define targets
+ ADD_LIBRARY(${TARGET_NAME} MODULE ${SOURCE_FILES})
+
+ # Alsa Plugin properties
+ SET_TARGET_PROPERTIES(${TARGET_NAME} PROPERTIES
+ LABELS "PLUGIN"
+ PREFIX ""
+ SUFFIX ".ctlso"
+ OUTPUT_NAME ${TARGET_NAME}
+ )
+
+ # Library dependencies (include updates automatically)
+ TARGET_LINK_LIBRARIES(${TARGET_NAME}
+ ${link_libraries}
+ )
+
+ target_include_directories(${TARGET_NAME}
+ PRIVATE "${CMAKE_SOURCE_DIR}/app-controller-submodule/ctl-lib"
+ PRIVATE "${CMAKE_SOURCE_DIR}/mixer-binding")
diff --git a/plugins/alsa/alsa-dmix.c b/plugins/alsa/alsa-dmix.c
new file mode 100644
index 0000000..b162d04
--- /dev/null
+++ b/plugins/alsa/alsa-dmix.c
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2018 "IoT.bzh"
+ * Author Fulup Ar Foll <fulup@iot.bzh>
+ *
+ * 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.
+ *
+ */
+
+#define _GNU_SOURCE // needed for vasprintf
+
+#include "alsa-softmixer.h"
+
+static int uniqueIpcIndex = 1024;
+
+
+PUBLIC int AlsaCreateDmix(CtlSourceT *source) {
+
+ AFB_ApiNotice(source->api, "AlsaCreateDmix: start ");
+
+ int cardid= AlsaCardInfoByPath ("/dev/snd/by-id/usb-Focusrite_Scarlett_18i8_USB_10004EE6-00");
+ AFB_ApiNotice(source->api, "AlsaCreateDmix: cardid=%d ", cardid);
+
+ snd_pcm_t *dmixPcm;
+ snd_config_t *dmixConfig, *slaveConfig, *elemConfig;
+ snd_pcm_stream_t streamPcm = SND_PCM_STREAM_PLAYBACK;
+ int error = 0, streamMode = SND_PCM_NONBLOCK;
+
+
+ error += snd_config_top(&dmixConfig);
+ error += snd_config_imake_integer(&elemConfig, "ipc_key", uniqueIpcIndex++);
+ error += snd_config_add(dmixConfig, elemConfig);
+ if (error) goto OnErrorExit;
+
+ error += snd_config_make_compound(&slaveConfig, "slave", 0);
+ error += snd_config_imake_string(&elemConfig, "pcm", "hw:6");
+ error += snd_config_add(slaveConfig, elemConfig);
+ if (error) goto OnErrorExit;
+
+ // add leaf into config
+ error += snd_config_add(dmixConfig, slaveConfig);
+ if (error) goto OnErrorExit;
+
+ snd_config_update();
+ AlsaDumpConfig (source, snd_config, 1);
+ AlsaDumpConfig (source, dmixConfig, 1);
+
+
+ int status = _snd_pcm_dmix_open(&dmixPcm, "MyDMix", snd_config, dmixConfig, streamPcm , streamMode);
+
+ AFB_ApiNotice(source->api, "AlsaCreateDmix: done");
+
+ return status;
+
+OnErrorExit:
+ AFB_ApiNotice(source->api, "AlsaCreateDmix: OnErrorExit");
+ return 1;
+} \ No newline at end of file
diff --git a/plugins/alsa/alsa-lua.c b/plugins/alsa/alsa-lua.c
new file mode 100644
index 0000000..8f1329f
--- /dev/null
+++ b/plugins/alsa/alsa-lua.c
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2017 "IoT.bzh"
+ * Author Fulup Ar Foll <fulup@iot.bzh>
+ *
+ * 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.
+ *
+*/
+
+#define _GNU_SOURCE // needed for vasprintf
+
+#include "alsa-softmixer.h"
+
+
+// Force Lua2cWrapper inclusion within already existing plugin
+Lua2cWrapperT Lua2cWrap;
+
+CTLP_LUA2C (AlsaDmix, source, argsJ, responseJ) {
+ json_object* subscribeArgsJ = NULL;
+
+ int err = 0;
+ wrap_json_pack(&subscribeArgsJ, "{ss}", "value", "location");
+ AFB_ApiNotice(source->api, "--lua2c-- AlsaDmix");
+
+ return err;
+}
+
+CTLP_LUA2C (AlsaRouter, source, argsJ, responseJ) {
+ json_object* subscribeArgsJ = NULL;
+
+ int err = 0;
+ wrap_json_pack(&subscribeArgsJ, "{ss}", "value", "location");
+ AFB_ApiNotice(source->api, "lua2c router with %s", json_object_to_json_string_ext(subscribeArgsJ, JSON_C_TO_STRING_PRETTY));
+
+ return err;
+}
diff --git a/plugins/alsa/alsa-softmixer.c b/plugins/alsa/alsa-softmixer.c
new file mode 100644
index 0000000..bf195fb
--- /dev/null
+++ b/plugins/alsa/alsa-softmixer.c
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2017 "IoT.bzh"
+ * Author Fulup Ar Foll <fulup@iot.bzh>
+ *
+ * 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.
+ *
+*/
+
+#define _GNU_SOURCE // needed for vasprintf
+
+#include "alsa-softmixer.h"
+
+CTLP_CAPI_REGISTER("alsa-mixer");
+
+// Call at initialisation time
+CTLP_ONLOAD(plugin, callbacks) {
+ AFB_ApiDebug (plugin->api, "SoftMixer plugin: uid='%s' 'info='%s'", plugin->uid, plugin->info);
+
+ // fake action call during init for debug
+ CtlSourceT source;
+ source.api = plugin->api;
+ AlsaCreateDmix (&source);
+
+ return 0;
+}
+
+CTLP_CAPI (zone_ctl, source, argsJ, eventJ) {
+ json_object* subscribeArgsJ = NULL;
+
+ int err = 0;
+ wrap_json_pack(&subscribeArgsJ, "{ss}", "value", "location");
+ AFB_ApiDebug(source->api, "Calling zone_ctl with %s", json_object_to_json_string_ext(subscribeArgsJ, JSON_C_TO_STRING_PRETTY));
+
+ return err;
+}
+
+CTLP_CAPI (stream_ctl, source, argsJ, eventJ) {
+ json_object* subscribeArgsJ = NULL;
+
+ int err = 0;
+ wrap_json_pack(&subscribeArgsJ, "{ss}", "value", "location");
+ AFB_ApiDebug(source->api, "Calling stream_ctl with %s", json_object_to_json_string_ext(subscribeArgsJ, JSON_C_TO_STRING_PRETTY));
+
+ return err;
+}
diff --git a/plugins/alsa-router.c b/plugins/alsa/alsa-softmixer.h
index e0e7eb2..d413929 100644
--- a/plugins/alsa-router.c
+++ b/plugins/alsa/alsa-softmixer.h
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2016 "IoT.bzh"
- * Author Romain Forlot <romain.forlot@iot.bzh>
+ * Copyright (C) 2018 "IoT.bzh"
+ * Author Fulup Ar Foll <fulup@iot.bzh>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,6 +18,9 @@
#define _GNU_SOURCE // needed for vasprintf
+#ifndef _ALSA_SOFTMIXER_
+#define _ALSA_SOFTMIXER_
+
#include <afb/afb-binding.h>
#include <systemd/sd-event.h>
#include <json-c/json_object.h>
@@ -27,20 +30,20 @@
#include "ctl-plugin.h"
#include "wrap-json.h"
-CTLP_CAPI_REGISTER("alsa-mixer");
+#include <alsa/asoundlib.h>
+
+// Provide proto for LibASound low level API
+int _snd_pcm_dmix_open(snd_pcm_t **pcmp, const char *name,
+ snd_config_t *root, snd_config_t *conf,
+ snd_pcm_stream_t stream, int mode);
+
+// alsa-tools-high.c
+PUBLIC void AlsaDumpConfig (CtlSourceT *source, snd_config_t *config, int indent);
-// Call at initialisation time
-/*CTLP_ONLOAD(plugin, callbacks) {
- AFB_NOTICE ("GPS plugin: uid='%s' 'info='%s'", plugin->uid, plugin->info);
- return api;
-}*/
+// alsa-tools-low.c
+PUBLIC int AlsaCardInfoByPath (const char *control);
-CTLP_CAPI (zone_action, source, argsJ, eventJ) {
- json_object* subscribeArgsJ = NULL, *responseJ = NULL;
- int err = 0;
- wrap_json_pack(&subscribeArgsJ, "{ss}", "value", "location");
- AFB_ApiDebug(source->api, "Calling zone_action with %s", json_object_to_json_string_ext(subscribeArgsJ, JSON_C_TO_STRING_PRETTY));
+PUBLIC int AlsaCreateDmix (CtlSourceT *source);
- return err;
-}
+#endif \ No newline at end of file
diff --git a/plugins/alsa/alsa-tools-high.c b/plugins/alsa/alsa-tools-high.c
new file mode 100644
index 0000000..a86ba2e
--- /dev/null
+++ b/plugins/alsa/alsa-tools-high.c
@@ -0,0 +1,66 @@
+/*
+ * Copyright (C) 2018 "IoT.bzh"
+ * Author Fulup Ar Foll <fulup@iot.bzh>
+ *
+ * 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.
+ *
+ */
+
+#define _GNU_SOURCE // needed for vasprintf
+
+
+#include "alsa-softmixer.h"
+
+
+PUBLIC void AlsaDumpConfig(CtlSourceT *source, snd_config_t *config, int indent) {
+ snd_config_iterator_t it, next;
+
+ // hugly hack to get minimalist indentation
+ char *pretty = alloca(indent + 1);
+ for (int idx = 0; idx < indent; idx++) pretty[idx] = '-';
+ pretty[indent] = '\0';
+
+ snd_config_for_each(it, next, config) {
+ snd_config_t *node = snd_config_iterator_entry(it);
+ const char *key;
+
+ // ignore comment en empty lines
+ if (snd_config_get_id(node, &key) < 0) continue;
+
+ switch (snd_config_get_type(node)) {
+ long valueI;
+ const char *valueS;
+
+ case SND_CONFIG_TYPE_INTEGER:
+ snd_config_get_integer(node, &valueI);
+ AFB_ApiNotice(source->api, "DumpAlsaConfig: %s %s: %d (int)", pretty, key, (int) valueI);
+ break;
+
+ case SND_CONFIG_TYPE_STRING:
+ snd_config_get_string(node, &valueS);
+ AFB_ApiNotice(source->api, "DumpAlsaConfig: %s %s: %s (str)", pretty, key, valueS);
+ break;
+
+ case SND_CONFIG_TYPE_COMPOUND:
+ AFB_ApiNotice(source->api, "DumpAlsaConfig: %s %s { ", pretty, key);
+ AlsaDumpConfig(source, node, indent + 2);
+ AFB_ApiNotice(source->api, "DumpAlsaConfig: %s } ", pretty);
+ break;
+
+ default:
+ snd_config_get_string(node, &valueS);
+ AFB_ApiNotice(source->api, "DumpAlsaConfig: %s: key=%s unknown=%s", pretty, key, valueS);
+ break;
+ }
+ }
+}
diff --git a/plugins/alsa/alsa-tools-low.c b/plugins/alsa/alsa-tools-low.c
new file mode 100644
index 0000000..57b5e5c
--- /dev/null
+++ b/plugins/alsa/alsa-tools-low.c
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2018 "IoT.bzh"
+ * Author Fulup Ar Foll <fulup@iot.bzh>
+ *
+ * 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.
+ *
+ */
+
+#define _GNU_SOURCE // needed for vasprintf
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <ctype.h>
+#include <fcntl.h>
+#include <sys/ioctl.h>
+
+#include "alsa-softmixer.h"
+
+// extracted IOCTLs from <alsa/asoundlib.h>
+#define _IOR_HACKED(type,nr,size) _IOC(_IOC_READ,(type),(nr),size)
+#define SNDRV_CTL_IOCTL_CARD_INFO(size) _IOR_HACKED('U', 0x01, size)
+
+// Clone of AlsaLib snd_card_load2 static function
+int AlsaCardInfoByPath (const char *devpath) {
+ int open_dev;
+ snd_ctl_card_info_t *cardinfo = alloca(snd_ctl_card_info_sizeof());
+
+ open_dev = open(devpath, O_RDONLY);
+ if (open_dev >= 0) {
+ int rc = ioctl(open_dev, SNDRV_CTL_IOCTL_CARD_INFO(snd_ctl_card_info_sizeof()), cardinfo);
+ if (rc < 0) {
+ int err = -errno;
+ close(open_dev);
+ return err;
+ }
+ close(open_dev);
+ int cardId = snd_ctl_card_info_get_card(cardinfo);
+ return cardId;
+ } else {
+ return -errno;
+ }
+}
+