diff options
Diffstat (limited to 'Alsa-Plugin')
-rw-r--r-- | Alsa-Plugin/Alsa-Policy-Hook/CMakeLists.txt | 37 | ||||
-rw-r--r-- | Alsa-Plugin/Alsa-Policy-Hook/PolicyHookCb.c | 554 | ||||
-rw-r--r-- | Alsa-Plugin/Alsa-Policy-Hook/README.md | 76 | ||||
-rw-r--r-- | Alsa-Plugin/CMakeLists.txt | 23 | ||||
-rw-r--r-- | Alsa-Plugin/_Alsa-Hal-plugin/AlsaHalPlug.h | 91 | ||||
-rw-r--r-- | Alsa-Plugin/_Alsa-Hal-plugin/AlsaHalPlugCb.c | 66 | ||||
-rw-r--r-- | Alsa-Plugin/_Alsa-Hal-plugin/AlsaHalPlugCtl.c | 423 | ||||
-rw-r--r-- | Alsa-Plugin/_Alsa-Hal-plugin/CMakeLists.txt | 55 | ||||
-rw-r--r-- | Alsa-Plugin/_Alsa-Hal-plugin/README.md | 44 |
9 files changed, 0 insertions, 1369 deletions
diff --git a/Alsa-Plugin/Alsa-Policy-Hook/CMakeLists.txt b/Alsa-Plugin/Alsa-Policy-Hook/CMakeLists.txt deleted file mode 100644 index 329b2ef..0000000 --- a/Alsa-Plugin/Alsa-Policy-Hook/CMakeLists.txt +++ /dev/null @@ -1,37 +0,0 @@ -########################################################################### -# Copyright 2015, 2016, 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. -########################################################################### - -# Activate ALSA dynamic build build mode get resolve "snd_dlsym_start" -add_compile_options(-DPIC) - -PROJECT_TARGET_ADD(policy_hook_cb) - - # Define targets - ADD_LIBRARY(${TARGET_NAME} MODULE PolicyHookCb.c) - - # Alsa Plugin properties - SET_TARGET_PROPERTIES(${TARGET_NAME} PROPERTIES - PREFIX "" - OUTPUT_NAME ${TARGET_NAME} - ) - - # Library dependencies (include updates automatically) - TARGET_LINK_LIBRARIES(${TARGET_NAME} - ${link_libraries} - ) - install(TARGETS ${TARGET_NAME} LIBRARY DESTINATION lib) diff --git a/Alsa-Plugin/Alsa-Policy-Hook/PolicyHookCb.c b/Alsa-Plugin/Alsa-Policy-Hook/PolicyHookCb.c deleted file mode 100644 index 54fbe88..0000000 --- a/Alsa-Plugin/Alsa-Policy-Hook/PolicyHookCb.c +++ /dev/null @@ -1,554 +0,0 @@ -/* - * Copyright (C) 2016 "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. - * - * AfbCallBack (snd_ctl_hal_t *handle, int numid, void **response); - * AlsaHookInit is mandatory and called with numid=0 - * - * Syntax in .asoundrc file - * CrlLabel { cb MyFunctionName name "My_Second_Control" } - * - * Testing: - * aplay -DAlsaHook /usr/share/sounds/alsa/test.wav - * - * References: - * https://www.spinics.net/lists/alsa-devel/msg54235.html - * https://github.com/shivdasgujare/utilities/blob/master/nexuss/alsa-scenario-hook/src/alsa-wrapper.c - */ - -#define _GNU_SOURCE -#include <stdio.h> -#include <alsa/asoundlib.h> -#include <alsa/conf.h> -#include <alsa/pcm.h> - -#include <systemd/sd-event.h> -#include <json-c/json.h> - -#include "afb/afb-wsj1.h" -#include "afb/afb-ws-client.h" -#include <pthread.h> -#include <semaphore.h> - - -#define PLUGIN_ENTRY_POINT AlsaInstallHook - // Fulup Note: What ever you may find on Internet you should use - // SND_CONFIG_DLSYM_VERSION_HOOK and not SND_CONFIG_DLSYM_VERSION_HOOK - SND_DLSYM_BUILD_VERSION(PLUGIN_ENTRY_POINT, SND_PCM_DLSYM_VERSION) - -// this should be more than enough -#define MAX_API_CALL 10 -#define MAX_EVT_CALL 10 - -// timeout in ms -#define REQUEST_DEFAULT_TIMEOUT 500 -#ifndef MAINLOOP_WATCHDOG -#define MAINLOOP_WATCHDOG 100000 -#endif - -// closing message is added to query when PCM is closed -#define CLOSING_MSG ",\"source\":-1}" - -// Currently not implemented -#define UNUSED_ARG(x) UNUSED_ ## x __attribute__((__unused__)) -void OnRequestCB(void* UNUSED_ARG(handle) , const char* UNUSED_ARG(api), const char* UNUSED_ARG(verb), struct afb_wsj1_msg*UNUSED_ARG(msg)) {} - -typedef struct { - const char *api; - const char *verb; - long timeout; - char *query; - size_t length; - - sd_event_source *evtSource; - char *callIdTag; - void *afbClient; -} afbRequestT; - -typedef struct { - const char *name; - int signal; -} afbEventT; - -typedef struct { - snd_pcm_t *pcm; - const char *uri; - struct afb_wsj1 *wsj1; - sd_event *sdLoop; - int verbose; - sem_t semaphore; - int count; - int error; - afbRequestT **request; - afbEventT **event; -} afbClientT; - - - -static void *LoopInThread(void *handle) { - afbClientT *afbClient = (afbClientT*) handle; - int count=0; - int watchdog= MAINLOOP_WATCHDOG *1000; - - /* loop until end */ - for (;;) { - - if (afbClient->verbose) printf("ON-MAINLOOP ping=%d\n", count++); - sd_event_run(afbClient->sdLoop, watchdog); - } - - return NULL; -} - -// lost connect with the AudioDaemon -static void OnHangupCB(void *handle, struct afb_wsj1 *wsj1) { - - afbClientT *afbClient = (afbClientT*) handle; - SNDERR("(Hoops) Lost Connection to %s", afbClient->uri); - - // try to close PCM when impossible terminate client - int err = snd_pcm_close (afbClient->pcm); - if (err) exit(1); -} - -typedef enum { - HOOK_INSTALL, - HOOK_CLOSE, -} hookActionT; - - -void OnEventCB(void *handle, const char *event, struct afb_wsj1_msg *msg) { - afbClientT *afbClient = (afbClientT*) handle; - afbEventT **afbEvent = afbClient->event; - json_object *eventJ, *tmpJ, *dataJ; - const char *label; - int value, done, index; - - eventJ = afb_wsj1_msg_object_j(msg); - done= json_object_object_get_ex(eventJ,"data", &dataJ); - if (!done) { - SNDERR ("PCM_HOOK: uri=%s empty event label", afbClient->uri); - goto OnErrorExit; - } - - json_object_object_get_ex(dataJ,"signal", &tmpJ); - label=json_object_get_string(tmpJ); - - json_object_object_get_ex(dataJ,"value", &tmpJ); - value=json_object_get_int(tmpJ); - - for (index=0; afbEvent[index]!= NULL; index++) { - if (!strcmp(afbEvent[index]->name, label)) break; - } - - if (!afbEvent[index] || !afbEvent[index]->signal) { - SNDERR ("PCM_HOOK: Unsupported uri=%s label=%s", afbClient->uri, label); - return; - } - - // send signal to self process - kill (getpid(), afbEvent[index]->signal); - - if (afbClient->verbose) printf("ON-EVENT label=%s signal=%d\n", label, value); - return; - -OnErrorExit: - SNDERR("ON-EVENT %s(%s)\n", event, afb_wsj1_msg_object_s(msg)); - return; -} - -// callback interface for wsj1 -static struct afb_wsj1_itf itf = { - .on_hangup = OnHangupCB, - .on_call = OnRequestCB, - .on_event = OnEventCB -}; - -void OnResponseCB(void *handle, struct afb_wsj1_msg *msg) { - afbRequestT *afbRequest= (afbRequestT*)handle; - afbClientT *afbClient=(afbClientT*)afbRequest->afbClient; - - if (afbClient->verbose) printf("ON-RESPONSE call=%s response=%s\n", afbRequest->callIdTag, afb_wsj1_msg_object_s(msg)); - - // Cancel timeout for this request - sd_event_source_unref(afbRequest->evtSource); - - if (! afb_wsj1_msg_is_reply_ok(msg)) goto OnErrorExit; - - // When not more waiting call release semaphore - afbClient->count--; - if (afbClient->count == 0) { - if (afbClient->verbose) printf("ON-RESPONSE No More Waiting Request\n"); - afbClient->error=0; - sem_post (&afbClient->semaphore); - } - return; - -OnErrorExit: - fprintf(stderr, "ON-RESPONSE ERROR call=%s response=%s\n", afbRequest->callIdTag, afb_wsj1_msg_object_s(msg)); - afbClient->error=1; - sem_post (&afbClient->semaphore); -} - -int OnTimeoutCB (sd_event_source* source, uint64_t timer, void* handle) { - afbClientT *afbClient= (afbClientT*)handle; - - SNDERR("\nON-TIMEOUT Call Request Fail URI=%s\n", afbClient->uri); - - // Close PCM and release waiting client - afbClient->error=1; - sem_post (&afbClient->semaphore); - - return 0; -} - -// Call AGL binder asynchronously by with a timeout -static int CallWithTimeout(afbClientT *afbClient, afbRequestT *afbRequest, int count, hookActionT action) { - uint64_t usec; - int err; - - // create a unique tag for request - (void) asprintf(&afbRequest->callIdTag, "%d:%s/%s", count, afbRequest->api, afbRequest->verb); - - // create a timer with ~250us accuracy - sd_event_now(afbClient->sdLoop, CLOCK_MONOTONIC, &usec); - sd_event_add_time(afbClient->sdLoop, &afbRequest->evtSource, CLOCK_MONOTONIC, usec+afbRequest->timeout*1000, 250, OnTimeoutCB, afbClient); - - if (afbClient->verbose) printf("CALL-REQUEST api=%s/%s tag=%s\n", afbRequest->api, afbRequest->verb, afbRequest->callIdTag); - - // on PCM close replace last '}' by CLOSING_MSG - if (action == HOOK_CLOSE) { - for (size_t index=afbRequest->length; index >0; index--) { - if (afbRequest->query[index] == '}') { - strcpy (&afbRequest->query[index], CLOSING_MSG); - break; - } - } - } - - err = afb_wsj1_call_s(afbClient->wsj1, afbRequest->api, afbRequest->verb, afbRequest->query, OnResponseCB, afbRequest); - if (err) goto OnErrorExit; - - // save client handle in request - afbRequest->afbClient = afbClient; - afbClient->count ++; - - return 0; - -OnErrorExit: - return -1; -} - -static int LaunchCallRequest(afbClientT *afbClient, hookActionT action) { - - pthread_t tid; - int err, idx; - afbRequestT **afbRequest= afbClient->request; - - if (action == HOOK_INSTALL) { - // init waiting counting semaphore - if (sem_init(&afbClient->semaphore, 1, 0) == -1) { - fprintf(stderr, "LaunchCallRequest: Fail Semaphore Init: %s\n", afbClient->uri); - } - - // Create a main loop - err = sd_event_default(&afbClient->sdLoop); - if (err < 0) { - fprintf(stderr, "LaunchCallRequest: Connection to default event loop failed: %s\n", strerror(-err)); - goto OnErrorExit; - } - - // start a thread with a mainloop to monitor Audio-Agent - err = pthread_create(&tid, NULL, &LoopInThread, afbClient); - if (err) goto OnErrorExit; - - // connect the websocket wsj1 to the uri given by the first argument - afbClient->wsj1 = afb_ws_client_connect_wsj1(afbClient->sdLoop, afbClient->uri, &itf, afbClient); - if (afbClient->wsj1 == NULL) { - fprintf(stderr, "LaunchCallRequest: Connection to %s failed\n", afbClient->uri); - goto OnErrorExit; - } - } - - // send call request to audio-agent asynchronously (respond with thread mainloop context) - for (idx = 0; afbRequest[idx] != NULL; idx++) { - err = CallWithTimeout(afbClient, afbRequest[idx], idx, action); - if (err) { - fprintf(stderr, "LaunchCallRequest: Fail call %s//%s/%s&%s", afbClient->uri, afbRequest[idx]->api, afbRequest[idx]->verb, afbRequest[idx]->query); - goto OnErrorExit; - } - } - - // launch counter to keep track of waiting request call - afbClient->count=idx; - - return 0; - -OnErrorExit: - return -1; -} - -static int AlsaCloseHook(snd_pcm_hook_t *hook) { - - afbClientT *afbClient = (afbClientT*) snd_pcm_hook_get_private (hook); - - // launch call request and create a waiting mainloop thread - int err = LaunchCallRequest(afbClient, HOOK_CLOSE); - if (err < 0) { - fprintf (stderr, "PCM Fail to Enter Mainloop\n"); - goto OnErrorExit; - } - - // wait for all call request to return - sem_wait(&afbClient->semaphore); - if (afbClient->error) { - fprintf (stderr, "AlsaCloseHook: Audio Agent Fail to respond\n"); - goto OnErrorExit; - } - - if (afbClient->verbose) fprintf(stdout, "\nAlsaHook Close Success PCM=%s URI=%s\n", snd_pcm_name(afbClient->pcm), afbClient->uri); - return 0; - -OnErrorExit: - fprintf(stderr, "\nAlsaPcmHook Plugin Close Fail PCM=%s\n", snd_pcm_name(afbClient->pcm)); - return 0; -} - -// Function call when Plugin PCM is OPEN -int PLUGIN_ENTRY_POINT (snd_pcm_t *pcm, snd_config_t *conf) { - snd_pcm_hook_t *h_close = NULL; - snd_config_iterator_t it, next; - afbClientT *afbClient = malloc(sizeof (afbClientT)); - afbRequestT **afbRequest = malloc(MAX_API_CALL * sizeof(afbRequestT*)); - afbEventT **afbEvent= malloc(MAX_EVT_CALL * sizeof(afbEventT*)); - int err; - - // start populating client handle - afbClient->pcm = pcm; - afbClient->verbose = 0; - afbClient->request = afbRequest; - - // Get PCM arguments from asoundrc - snd_config_for_each(it, next, conf) { - snd_config_t *node = snd_config_iterator_entry(it); - const char *id; - - // ignore comment en empty lines - if (snd_config_get_id(node, &id) < 0) continue; - if (strcmp(id, "comment") == 0 || strcmp(id, "hint") == 0) continue; - - if (strcmp(id, "uri") == 0) { - const char *uri; - if (snd_config_get_string(node, &uri) < 0) { - SNDERR("Invalid String for %s", id); - goto OnErrorExit; - } - afbClient->uri=strdup(uri); - continue; - } - - if (strcmp(id, "verbose") == 0) { - afbClient->verbose= snd_config_get_bool(node); - if (afbClient->verbose < 0) { - SNDERR("Invalid Boolean for %s", id); - goto OnErrorExit; - } - continue; - } - - if (strcmp(id, "request") == 0) { - const char *callConf, *callLabel; - snd_config_type_t ctype; - snd_config_iterator_t currentCall, follow; - snd_config_t *itemConf; - int callCount=0; - - ctype = snd_config_get_type(node); - if (ctype != SND_CONFIG_TYPE_COMPOUND) { - snd_config_get_string(node, &callConf); - SNDERR("Invalid compound type for %s", callConf); - goto OnErrorExit; - } - - - // loop on each call - snd_config_for_each(currentCall, follow, node) { - snd_config_t *ctlconfig = snd_config_iterator_entry(currentCall); - - // ignore empty line - if (snd_config_get_id(ctlconfig, &callLabel) < 0) continue; - - // each clt should be a valid config compound - ctype = snd_config_get_type(ctlconfig); - if (ctype != SND_CONFIG_TYPE_COMPOUND) { - snd_config_get_string(node, &callConf); - SNDERR("Invalid call element for %s value=%s", callLabel, callConf); - goto OnErrorExit; - } - - // allocate an empty call request - afbRequest[callCount] = calloc(1, sizeof (afbRequestT)); - - - err = snd_config_search(ctlconfig, "api", &itemConf); - if (!err) { - const char *api; - if (snd_config_get_string(itemConf, &api) < 0) { - SNDERR("Invalid api string for %s", callLabel); - goto OnErrorExit; - } - afbRequest[callCount]->api=strdup(api); - } - - err = snd_config_search(ctlconfig, "verb", &itemConf); - if (!err) { - const char *verb; - if (snd_config_get_string(itemConf, &verb) < 0) { - SNDERR("Invalid verb string %s", id); - goto OnErrorExit; - } - afbRequest[callCount]->verb=strdup(verb); - } - - err = snd_config_search(ctlconfig, "timeout", &itemConf); - if (!err) { - if (snd_config_get_integer(itemConf, &afbRequest[callCount]->timeout) < 0) { - SNDERR("Invalid timeout Integer %s", id); - goto OnErrorExit; - } - } - - err = snd_config_search(ctlconfig, "query", &itemConf); - if (!err) { - const char *query; - if (snd_config_get_string(itemConf, &query) < 0) { - SNDERR("Invalid args string %s", id); - goto OnErrorExit; - } - // reserve enough space to ad closing message - afbRequest[callCount]->length= strlen(query); - afbRequest[callCount]->query = malloc (afbRequest[callCount]->length+strlen(CLOSING_MSG)+1); - strcpy (afbRequest[callCount]->query, query); - - // cleanup string for json_tokener - for (int idx = 0; query[idx] != '\0'; idx++) { - if (query[idx] == '\'') afbRequest[callCount]->query[idx] = '"'; - else afbRequest[callCount]->query[idx] = query[idx]; - } - json_object *queryJ = json_tokener_parse(afbRequest[callCount]->query); - if (!queryJ) { - SNDERR("Invalid Json %s args=%s should be args=\"{'tok1':'val1', 'tok2':'val2'}\" ", id, afbRequest[callCount]->query); - goto OnErrorExit; - } - } - - // Simple check on call request validity - if (!afbRequest[callCount]->query) afbRequest[callCount]->query= ""; - if (!afbRequest[callCount]->timeout) afbRequest[callCount]->timeout=REQUEST_DEFAULT_TIMEOUT ; - if (!afbRequest[callCount]->verb || !afbRequest[callCount]->api) { - SNDERR("Missing api/verb %s in asoundrc", callLabel); - goto OnErrorExit; - } - - // move to next call if any - callCount ++; - if (callCount == MAX_API_CALL) { - SNDERR("Too Many call MAX_API_CALL=%d", MAX_API_CALL); - goto OnErrorExit; - } - afbRequest[callCount]=NULL; // afbRequest array is NULL terminated - - } - continue; - } - if (strcmp(id, "event") == 0) { - const char *callConf, *callLabel; - snd_config_type_t ctype; - snd_config_iterator_t currentCall, follow; - int callCount=0; - - ctype = snd_config_get_type(node); - if (ctype != SND_CONFIG_TYPE_COMPOUND) { - snd_config_get_string(node, &callConf); - SNDERR("Invalid compound type for %s", callConf); - goto OnErrorExit; - } - - - // loop on each call - snd_config_for_each(currentCall, follow, node) { - snd_config_t *ctlconfig = snd_config_iterator_entry(currentCall); - long sigval; - - // ignore empty line - if (snd_config_get_id(ctlconfig, &callLabel) < 0) continue; - - // each clt should be a valid config compound - ctype = snd_config_get_type(ctlconfig); - if (ctype != SND_CONFIG_TYPE_INTEGER) { - snd_config_get_string(ctlconfig, &callConf); - SNDERR("Invalid signal number for %s value=%s", callLabel, callConf); - goto OnErrorExit; - } - - // allocate an empty call request - snd_config_get_integer(ctlconfig, &sigval); - afbEvent[callCount] = calloc(1, sizeof (afbEventT)); - afbEvent[callCount]->name=strdup(callLabel); - afbEvent[callCount]->signal= (int)sigval; - - // move to next call if any - callCount ++; - if (callCount == MAX_EVT_CALL) { - SNDERR("Too Many call MAX_EVT_CALL=%d", MAX_EVT_CALL); - goto OnErrorExit; - } - afbEvent[callCount]=NULL; // afbEvent array is NULL terminated - - } - continue; - } - } - - if (afbClient->verbose) fprintf(stdout, "\nAlsaHook Install Start PCM=%s URI=%s\n", snd_pcm_name(afbClient->pcm), afbClient->uri); - - err = snd_pcm_hook_add(&h_close, afbClient->pcm, SND_PCM_HOOK_TYPE_CLOSE, AlsaCloseHook, afbClient); - if (err < 0) goto OnErrorExit; - - // launch call request and create a waiting mainloop thread - err = LaunchCallRequest(afbClient, HOOK_INSTALL); - if (err < 0) { - fprintf (stderr, "PCM Fail to Enter Mainloop\n"); - goto OnErrorExit; - } - - // wait for all call request to return - sem_wait(&afbClient->semaphore); - if (afbClient->error) { - fprintf (stderr, "PCM Authorisation Deny from AAAA Controller (AGL Advanced Audio Agent)\n"); - goto OnErrorExit; - } - - if (afbClient->verbose) fprintf(stdout, "\nAlsaHook Install Success PCM=%s URI=%s\n", snd_pcm_name(afbClient->pcm), afbClient->uri); - return 0; - -OnErrorExit: - fprintf(stderr, "\nAlsaPcmHook Plugin Install Fail PCM=%s\n", snd_pcm_name(pcm)); - if (h_close) - snd_pcm_hook_remove(h_close); - - return -EINVAL; -} - diff --git a/Alsa-Plugin/Alsa-Policy-Hook/README.md b/Alsa-Plugin/Alsa-Policy-Hook/README.md deleted file mode 100644 index 20186db..0000000 --- a/Alsa-Plugin/Alsa-Policy-Hook/README.md +++ /dev/null @@ -1,76 +0,0 @@ -Alsa-Hook-Plugin - -Object: Provide a Hook on Alsa PCM to check permission again AGL Advance Audio Agent -Status: Release Candidate -Author: Fulup Ar Foll fulup@iot.bzh -Date : August-2017 - -Functionalities: - - Execute a set of websocket RPC request again AGL binders to allow/deny access - - Keep websocket open in an idepandant thread on order to monitor event receive from AGL audio agent - -Installation - - Alsaplugins are typically search in /usr/share/alsa-lib. Nevertheless a full path might be given - - This plugin implement a hook on a slave PCM. Typically this slave PCM is a dedicated virtual channel (eg: navigation, emergency,...) - - Config should be place in ~/.asoundrc (see config sample in PROJECT_ROOT/conf.d/alsa) - -Test - - Install a full .asoundrc from conf.d/project/alsa.d - - speaker-test -DMyNavigationHook -c2 -twav - -Config -``` -# Define sharelib location and entry point -# ----------------------------------------- -pcm_hook_type.MyHookPlugin { - install "AlsaInstallHook" - lib "/home/fulup/Workspace/AGL-AppFW/audio-bindings-dev/build/Alsa-Plugin/Alsa-Hook-Callback/alsa_hook_cb.so" -} - -# Create PCM HOOK with corresponding request calls to AGL Audio Agent -# -------------------------------------------------------------------- -pcm.MyNavigationHook { - type hooks - slave.pcm "MyMixerPCM" - - # Defined used hook sharelib and provide arguments/config to install func - hooks.0 { - type "MyHookPlugin" - hook_args { - verbose true # print few log messages (default false); - - # Every Call should return OK in order PCM to open (default timeout 100ms) - uri "ws://localhost:1234/api?token='audio-agent-token'" - request { - # Request autorisation to write on navigation - navigation-ctl { - api "control" - verb "dispatch" - args "{'target':'navigation', 'args':{'device':'Jabra SOLEMATE v1.34.0'}}" - } - # subscribe to Audio Agent Event map them to signal - subscribe-evt { - api "control" - verb "monitor" - } - } - # map event reception to self generated signal - event { - pause 30 - resume 31 - stop 3 - } - } - } -} - -``` - -NOTE: - -* Hook plugin is loaded by Alsa libasound within player context. It inherits client process attributes, as UID/GID or -the SMACK label on AGL. This smack label is tested by AGL security framework when requested a call on the audio-agent binder. -As a result the call will only succeed it the permission attached the application in Cynara matches. - -* Hook plugin keep a connection with the Audio-Agent until PCM is closed by the application. This connection allow the -Audio-Agent to send events. eg: pause, quit, mute, ...
\ No newline at end of file diff --git a/Alsa-Plugin/CMakeLists.txt b/Alsa-Plugin/CMakeLists.txt deleted file mode 100644 index b0c2e6a..0000000 --- a/Alsa-Plugin/CMakeLists.txt +++ /dev/null @@ -1,23 +0,0 @@ -########################################################################### -# Copyright 2015, 2016, 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. -########################################################################### - - -# Include any directory starting with a Capital letter -# ----------------------------------------------------- -PROJECT_SUBDIRS_ADD(${PROJECT_SRC_DIR_PATTERN}) - diff --git a/Alsa-Plugin/_Alsa-Hal-plugin/AlsaHalPlug.h b/Alsa-Plugin/_Alsa-Hal-plugin/AlsaHalPlug.h deleted file mode 100644 index 98850bf..0000000 --- a/Alsa-Plugin/_Alsa-Hal-plugin/AlsaHalPlug.h +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright (C) 2016 "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. - * - * AfbCallBack (snd_ctl_hal_t *handle, int numid, void **response); - * AfbHalInit is mandatory and called with numid=0 - * - * Syntaxe in .asoundrc file - * CrlLabel { cb MyFunctionName name "My_Second_Control" } - */ - - -#include <alsa/asoundlib.h> -#include <alsa/control_external.h> -#include <linux/soundcard.h> - -#ifndef SOUND_HAL_MAX_CTLS -#define SOUND_HAL_MAX_CTLS 255 -#endif - -typedef enum { - CTLCB_INIT, - CTLCB_CLOSE, - CTLCB_ELEM_COUNT, - CTLCB_ELEM_LIST, - CTLCB_FIND_ELEM, - CTLCB_FREE_KEY, - CTLCB_GET_ATTRIBUTE, - CTLCB_GET_INTEGER_INFO, - CTLCB_GET_INTEGER64_INFO, - CTLCB_GET_ENUMERATED_INFO, - CTLCB_GET_ENUMERATED_NAME, - CTLCB_READ_INTEGER, - CTLCB_READ_INTEGER64, - CTLCB_READ_ENUMERATED, - CTLCB_READ_BYTES, - CTLCB_READ_IEC958, - CTLCB_WRITE_INTEGER, - CTLCB_WRITE_INTEGER64, - CTLCB_WRITE_ENUMERATED, - CTLCB_WRITE_BYTES, - CTLCB_WRITE_IEC958, - CTLCB_SUBSCRIBE_EVENTS, - CTLCB_READ_EVENT, - CTLCB_POLL_DESCRIPTORS_COUNT, - CTLCB_POLL_DESCRIPTORS -} snd_ctl_action_t; - -typedef struct { - int ctlNumid; - const char *ctlName; -} snd_ctl_conf_t; - -typedef struct { - int type; - int acc; - unsigned count; -} snd_ctl_get_attrib_t; - -typedef struct { - int imin; - int imax; - int istep; -} snd_ctl_get_int_info_t; - -typedef int(*snd_ctl_cb_t)(void *handle, snd_ctl_action_t action, snd_ctl_ext_key_t key, void *response); - -typedef struct snd_ctl_hal { - snd_ctl_ext_t ext; - char *devid; - snd_ctl_t *ctlDev; - unsigned int ctlsCount; - void *dlHandle; - snd_ctl_conf_t ctls[SOUND_HAL_MAX_CTLS]; - snd_ctl_elem_info_t *infos[SOUND_HAL_MAX_CTLS]; - snd_ctl_cb_t cbs[SOUND_HAL_MAX_CTLS]; -} snd_ctl_hal_t; - - diff --git a/Alsa-Plugin/_Alsa-Hal-plugin/AlsaHalPlugCb.c b/Alsa-Plugin/_Alsa-Hal-plugin/AlsaHalPlugCb.c deleted file mode 100644 index 9e55f0c..0000000 --- a/Alsa-Plugin/_Alsa-Hal-plugin/AlsaHalPlugCb.c +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (C) 2016 "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. - * - * AfbCallBack (snd_ctl_hal_t *handle, int numid, void **response); - * AfbHalInit is mandatory and called with numid=0 - * - * Syntax in .asoundrc file - * CrlLabel { cb MyFunctionName name "My_Second_Control" } - * - * Testing: - * amixer -Dagl_hal controls - * amixer -Dagl_hal cget name=My_Sample_Callback - */ - - -#include "AlsaHalPlug.h" -#include <stdio.h> - -int AfbHalInitCB(void *handle, snd_ctl_action_t action, int numid, void*response) { - snd_ctl_hal_t *plughandle = (snd_ctl_hal_t*) handle; - - fprintf(stdout, "\n - CB AfbHalInit devid=%s\n", plughandle->devid); - return 0; -} - -int AfbHalSampleCB(void *handle, snd_ctl_action_t action, snd_ctl_ext_key_t key, void*response) { - - switch (action) { - case CTLCB_GET_ATTRIBUTE: - { - fprintf(stdout, " - AfbHalSampleCB CTLCB_GET_ATTRIBUTE numid=%d\n", (int) key + 1); - snd_ctl_get_attrib_t *item = (snd_ctl_get_attrib_t*) response; - item->type = 1; - item->count = 2; - item->acc = SND_CTL_EXT_ACCESS_READWRITE; - break; - } - - case CTLCB_GET_INTEGER_INFO: - { - fprintf(stdout, " - AfbHalSampleCB CTLCB_GET_INTEGER_INFO numid=%d\n", (int) key + 1); - snd_ctl_get_int_info_t *item = (snd_ctl_get_attrib_t*) response; - item->istep = 10; - item->imin = 20; - item->imax = 200; - break; - } - - default: - fprintf(stdout, "CB AfbHalSampleCB unsupported action=%d numid=%d\n", action, (int) key + 1); - } - return 0; -} diff --git a/Alsa-Plugin/_Alsa-Hal-plugin/AlsaHalPlugCtl.c b/Alsa-Plugin/_Alsa-Hal-plugin/AlsaHalPlugCtl.c deleted file mode 100644 index 22c217b..0000000 --- a/Alsa-Plugin/_Alsa-Hal-plugin/AlsaHalPlugCtl.c +++ /dev/null @@ -1,423 +0,0 @@ -/* - * Copyright (C) 2016 "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. - * - * Testing: - * 1) Copy generated plugin [libasound_module_pcm_afbhal.so] in alsa-lib/ dir visible from LD_LIBRARY_PATH (eg: /usr/lib64/alsa-lib) - * 2) Create a ~/.asounrc file base on following template - * ctl.agl_hal { - * type afbhal - * devid "hw:4" - * cblib "afbhal_cb_sample.so" - * ctls { - * # ctlLabel {numid integer name "Alsa Ctl Name"} - * MasterSwitch { numid 4 name "My_First_Control" } - * MasterVol { numid 5 name "My_Second_Control" } - * CB_sample { ctlcb @AfbHalSampleCB name "My_Sample_Callback"} - * } - * pcm.agl_hal { - * type copy # Copy PCM - * slave "hw:4" # Slave name - * } - * - * } - * 3) Test with - * - amixer -Dagl_hal controls # should list all your controls - * - amixer -Dagl_hal cget numid=1 - * - amixer -Dagl_hal cset numid=1 '10,20' - */ - - -#include <stdio.h> -#include <sys/ioctl.h> -#include "AlsaHalPlug.h" -#include <dlfcn.h> - -static snd_ctl_ext_key_t AfbHalElemFind(snd_ctl_ext_t *ext, const snd_ctl_elem_id_t *id) { - snd_ctl_hal_t *plughandle = (snd_ctl_hal_t*) ext->private_data; - snd_ctl_ext_key_t key = NULL; - - int numid = snd_ctl_elem_id_get_numid(id); - if (numid > 0) { - if (numid > plughandle->ctlsCount) goto OnErrorExit; - key = (snd_ctl_ext_key_t) numid - 1; - goto SucessExit; - } - - const char *ctlName = snd_ctl_elem_id_get_name(id); - if (ctlName == NULL) goto OnErrorExit; - - for (int idx = 0; idx < plughandle->ctlsCount; idx++) { - if (!strcmp(ctlName, plughandle->ctls[idx].ctlName)) { - key = idx; - goto SucessExit; - } - } - -SucessExit: - return key; - -OnErrorExit: - return -1; -} - -static int AfbHalGetAttrib(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key, int *type, unsigned int *acc, unsigned int *count) { - snd_ctl_hal_t *plughandle = (snd_ctl_hal_t*) ext->private_data; - snd_ctl_elem_info_t *elemInfo = plughandle->infos[key]; - snd_ctl_cb_t callback = plughandle->cbs[key]; - - - // search for equivalent NUMID in effective sound card - if (elemInfo) { - *type = snd_ctl_elem_info_get_type(elemInfo); - *count = snd_ctl_elem_info_get_count(elemInfo); - *acc = SND_CTL_EXT_ACCESS_READWRITE; // Future ToBeDone - return 0; - } - - if (callback) { - snd_ctl_get_attrib_t item; - - int err = callback(plughandle, CTLCB_GET_ATTRIBUTE, key, &item); - if (!err) { - *type = item.type; - *acc = item.acc; - *count = item.count; - } - return err; - } - - return -1; -} - -static int AfbHalGetIntInfo(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key, long *imin, long *imax, long *istep) { - snd_ctl_hal_t *plughandle = (snd_ctl_hal_t*) ext->private_data; - snd_ctl_elem_info_t *elemInfo = plughandle->infos[key]; - snd_ctl_cb_t callback = plughandle->cbs[key]; - - if (elemInfo) { - - // Should be normalised to make everything 0-100% - *imin = (long) snd_ctl_elem_info_get_min(elemInfo); - *imax = (long) snd_ctl_elem_info_get_min(elemInfo); - *istep = (long) snd_ctl_elem_info_get_min(elemInfo); - return 0; - } - - if (callback) { - snd_ctl_get_int_info_t item; - - int err = callback(plughandle, CTLCB_GET_INTEGER_INFO, key, &item); - if (!err) { - *imin = item.imin; - *imax = item.imax; - *istep = item.istep; - } - return err; - } - - return -1; -} - -static int AfbHalGetEnumInfo(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key, unsigned int *items) { - snd_ctl_hal_t *plughandle = (snd_ctl_hal_t*) ext->private_data; - snd_ctl_elem_info_t *elemInfo = plughandle->infos[key]; - snd_ctl_cb_t callback = plughandle->cbs[key]; - - if (elemInfo) *items = snd_ctl_elem_info_get_items(elemInfo); - if (callback) callback(plughandle, CTLCB_GET_ENUMERATED_INFO, key, items); - - return 0; -} - -static int AfbHalGetEnumName(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key, unsigned int item, char *name, size_t name_max_len) { - snd_ctl_hal_t *plughandle = (snd_ctl_hal_t*) ext->private_data; - snd_ctl_elem_info_t *elemInfo = plughandle->infos[key]; - - //name= snd_ctl_elem_info_get_item_name(elemInfo); - return 0; -} - -static int AfbHalReadInt(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key, long *value) { - snd_ctl_hal_t *plughandle = (snd_ctl_hal_t*) ext->private_data; - snd_ctl_elem_info_t *elemInfo = plughandle->infos[key]; - - return 0; -} - -static int AfbHalReadEnumerate(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key, unsigned int *items) { - snd_ctl_hal_t *plughandle = (snd_ctl_hal_t*) ext->private_data; - - return 0; -} - -static int AfbHalWriteInt(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key, long *value) { - snd_ctl_hal_t *plughandle = (snd_ctl_hal_t*) ext->private_data; - - return 0; -} - -static int AfbHalWriteEnum(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key, unsigned int *items) { - snd_ctl_hal_t *plughandle = (snd_ctl_hal_t*) ext->private_data; - - return 0; -} - -static int AfbHalEventRead(snd_ctl_ext_t *ext, snd_ctl_elem_id_t *id, unsigned int *event_mask) { - snd_ctl_hal_t *plughandle = (snd_ctl_hal_t*) ext->private_data; - - return -EAGAIN; -} - -static int AfbHalElemList(snd_ctl_ext_t *ext, unsigned int offset, snd_ctl_elem_id_t *id) { - snd_ctl_hal_t *plughandle = (snd_ctl_hal_t*) ext->private_data; - - snd_ctl_elem_id_set_interface(id, SND_CTL_ELEM_IFACE_MIXER); - snd_ctl_elem_id_set_name(id, plughandle->ctls[offset].ctlName); - - return 0; -} - -static int AfbHalElemCount(snd_ctl_ext_t *ext) { - snd_ctl_hal_t *plughandle = (snd_ctl_hal_t*) ext->private_data; - int count = plughandle->ctlsCount; - return count; -} - -static void AfbHalClose(snd_ctl_ext_t *ext) { - snd_ctl_hal_t *plughandle = (snd_ctl_hal_t*) ext->private_data; - int err; - - for (int idx = 0; idx < plughandle->ctlsCount; idx++) { - if (plughandle->ctls[idx].ctlName) free((void*) plughandle->ctls[idx].ctlName); - } - - err = snd_ctl_close(plughandle->ctlDev); - if (err) SNDERR("Fail Close sndctl: devid=%s err=%s", plughandle->devid, snd_strerror(err)); - - if (plughandle->devid) free(plughandle->devid); - free(plughandle); -} - -static snd_ctl_ext_callback_t afbHalCBs = { - .close = AfbHalClose, - .elem_count = AfbHalElemCount, - .elem_list = AfbHalElemList, - .find_elem = AfbHalElemFind, - .get_attribute = AfbHalGetAttrib, - .get_integer_info = AfbHalGetIntInfo, - .get_enumerated_info = AfbHalGetEnumInfo, - .get_enumerated_name = AfbHalGetEnumName, - .read_integer = AfbHalReadInt, - .read_enumerated = AfbHalReadEnumerate, - .write_integer = AfbHalWriteInt, - .write_enumerated = AfbHalWriteEnum, - .read_event = AfbHalEventRead, -}; - -SND_CTL_PLUGIN_DEFINE_FUNC(afbhal) { - - snd_config_iterator_t it, next; - snd_ctl_hal_t *plughandle; - int err; - snd_ctl_cb_t AfbHalInitCB; - const char *libname; - - plughandle = calloc(1, sizeof (snd_ctl_hal_t)); - - snd_config_for_each(it, next, conf) { - snd_config_t *node = snd_config_iterator_entry(it); - const char *id; - - // ignore comment en empty lines - if (snd_config_get_id(node, &id) < 0) continue; - if (strcmp(id, "comment") == 0 || strcmp(id, "type") == 0 || strcmp(id, "hint") == 0) continue; - - // devid should point onto a valid sound card - if (strcmp(id, "devid") == 0) { - const char *devid; - if (snd_config_get_string(node, &devid) < 0) { - SNDERR("Invalid string type for %s", id); - return -EINVAL; - } - plughandle->devid = strdup(devid); - - // open control interface for devid - err = snd_ctl_open(&plughandle->ctlDev, plughandle->devid, 0); - if (err < 0) { - SNDERR("Fail to open control device for devid=%s", plughandle->devid); - return -EINVAL; - } - continue; - } - - if (strcmp(id, "cblib") == 0) { - if (snd_config_get_string(node, &libname) < 0) { - SNDERR("Invalid libname string for %s", id); - return -EINVAL; - } - - plughandle->dlHandle = dlopen(libname, RTLD_NOW); - if (!plughandle->dlHandle) { - SNDERR("Fail to open callback sharelib=%s error=%s", libname, dlerror()); - return -EINVAL; - } - - AfbHalInitCB = dlsym(plughandle->dlHandle, "AfbHalInitCB"); - if (!AfbHalInitCB) { - SNDERR("Fail find 'AfbHalInitCB' symbol into callbacks sharelib=%s", libname); - return -EINVAL; - } - - err = (*AfbHalInitCB)(plughandle, CTLCB_INIT, 0, 0); - if (err) { - SNDERR("Fail AfbHalInitCB err=%d", err); - return -EINVAL; - } - - continue; - } - - if (strcmp(id, "ctl") == 0) { - const char *ctlConf; - snd_config_type_t ctype; - snd_config_iterator_t currentCtl, follow; - snd_config_t *itemConf; - - ctype = snd_config_get_type(node); - if (ctype != SND_CONFIG_TYPE_COMPOUND) { - snd_config_get_string(node, &ctlConf); - SNDERR("Invalid compound type for %s", node); - return -EINVAL; - } - - // loop on each ctl within ctls - - snd_config_for_each(currentCtl, follow, node) { - snd_config_t *ctlconfig = snd_config_iterator_entry(currentCtl); - snd_ctl_elem_info_t *elemInfo; - const char *ctlLabel, *ctlName; - - // ignore empty line - if (snd_config_get_id(ctlconfig, &ctlLabel) < 0) continue; - - // each clt should be a valid config compound - ctype = snd_config_get_type(ctlconfig); - if (ctype != SND_CONFIG_TYPE_COMPOUND) { - snd_config_get_string(node, &ctlConf); - SNDERR("Invalid ctl config for %s", ctlLabel); - return -EINVAL; - } - - err = snd_config_search(ctlconfig, "ctl", &itemConf); - if (!err) { - if (snd_config_get_integer(itemConf, (long*) &plughandle->ctls[plughandle->ctlsCount].ctlNumid) < 0) { - SNDERR("Not Integer: ctl:%s numid should be a valid integer", ctlLabel); - return -EINVAL; - } - - // Make sure than numid is valid on slave snd card - snd_ctl_elem_info_malloc(&elemInfo); - snd_ctl_elem_info_set_numid(elemInfo, (int) plughandle->ctls[plughandle->ctlsCount].ctlNumid); - plughandle->infos[plughandle->ctlsCount] = elemInfo; - - err = snd_ctl_elem_info(plughandle->ctlDev, elemInfo); - if (err) { - SNDERR("Not Found: 'numid=%d' for 'devid=%s'", plughandle->ctls[plughandle->ctlsCount].ctlNumid, plughandle->devid); - return -EINVAL; - } - } - - err = snd_config_search(ctlconfig, "ctlcb", &itemConf); - if (!err) { - const char *funcname; - void *funcaddr; - - if (snd_config_get_string(itemConf, &funcname) < 0) { - SNDERR("Not string: ctl:%s cbname should be a valid string", ctlLabel); - return -EINVAL; - } - - if (funcname[0] != '@') { - SNDERR("Not string: ctl:%s cbname=%s should be prefixed with '@' ", ctlLabel, funcname); - return -EINVAL; - } - - if (!plughandle->dlHandle) { - SNDERR("No CB: ctl:%s cblib:/my/libcallback missing from asoundrc", ctlLabel); - return -EINVAL; - } - - funcaddr = dlsym(plughandle->dlHandle, &funcname[1]); - if (!funcaddr) { - SNDERR("NotFound CB: ctl:%s cbname='%s' no symbol into %s", ctlLabel, &funcname[1], libname); - return -EINVAL; - } - plughandle->cbs[plughandle->ctlsCount] = funcaddr; - } - - err = snd_config_search(ctlconfig, "name", &itemConf); - if (err) { - SNDERR("Not Found: 'name' mandatory in ctl config"); - return -EINVAL; - } - - if (snd_config_get_string(itemConf, &ctlName) < 0) { - SNDERR("Not String: ctl:%s 'name' should be a valie string", ctlLabel); - return -EINVAL; - } - plughandle->ctls[plughandle->ctlsCount].ctlName = strdup(ctlName); - - // move to next ctl if any - plughandle->ctlsCount++; - } // end for each ctl - continue; - } - SNDERR("Unknown field %s", id); - return -EINVAL; - } - - - - // Create ALSA control plugin structure - plughandle->ext.version = SND_CTL_EXT_VERSION; - plughandle->ext.card_idx = 0; /* FIXME */ - strcpy(plughandle->ext.id, "AFB-HAL-CTL"); - strcpy(plughandle->ext.driver, "AFB-HAL"); - strcpy(plughandle->ext.name, "AFB-HAL Control Plugin"); - strcpy(plughandle->ext.mixername, "AFB-HAL Mixer Plugin"); - strcpy(plughandle->ext.longname, "Automotive-Linux Sound Abstraction Control Plugin"); - plughandle->ext.poll_fd = -1; - plughandle->ext.callback = &afbHalCBs; - plughandle->ext.private_data = (void*) plughandle; - - - - err = snd_ctl_ext_create(&plughandle->ext, name, mode); - if (err < 0) { - SNDERR("Fail Register sndctl for devid=%s", plughandle->devid); - goto OnErrorExit; - } - - // Plugin register controls update handlep before exiting - *handlep = plughandle->ext.handle; - return 0; - -OnErrorExit: - free(plughandle); - return -1; -} - -SND_CTL_PLUGIN_SYMBOL(afbhal); diff --git a/Alsa-Plugin/_Alsa-Hal-plugin/CMakeLists.txt b/Alsa-Plugin/_Alsa-Hal-plugin/CMakeLists.txt deleted file mode 100644 index 90ee5a3..0000000 --- a/Alsa-Plugin/_Alsa-Hal-plugin/CMakeLists.txt +++ /dev/null @@ -1,55 +0,0 @@ -########################################################################### -# Copyright 2015, 2016, 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. -########################################################################### - -# Activate ALSA dynamic build build mode get resolve "snd_dlsym_start" -add_compile_options(-DPIC) - -# Add target to project dependency list -PROJECT_TARGET_ADD(ctl_afbhal) - - # Define targets - ADD_LIBRARY(${TARGET_NAME} MODULE HalPlugCtl.c) - - # Alsa Plugin properties - SET_TARGET_PROPERTIES(${TARGET_NAME} PROPERTIES - PREFIX "libasound_module_" - OUTPUT_NAME ${TARGET_NAME} - ) - - # Library dependencies (include updates automatically) - TARGET_LINK_LIBRARIES(${TARGET_NAME} - ${link_libraries} - ) - install(TARGETS ${TARGET_NAME} LIBRARY DESTINATION lib/alsa-lib) - -PROJECT_TARGET_ADD(cb_sample) - - # Define targets - ADD_LIBRARY(${TARGET_NAME} MODULE HalPlugCb.c) - - # Alsa Plugin properties - SET_TARGET_PROPERTIES(${TARGET_NAME} PROPERTIES - PREFIX "afbhal_" - OUTPUT_NAME ${TARGET_NAME} - ) - - # Library dependencies (include updates automatically) - TARGET_LINK_LIBRARIES(${TARGET_NAME} - ${link_libraries} - ) - install(TARGETS ${TARGET_NAME} LIBRARY DESTINATION lib) diff --git a/Alsa-Plugin/_Alsa-Hal-plugin/README.md b/Alsa-Plugin/_Alsa-Hal-plugin/README.md deleted file mode 100644 index a6fc90d..0000000 --- a/Alsa-Plugin/_Alsa-Hal-plugin/README.md +++ /dev/null @@ -1,44 +0,0 @@ -Hal-Plugin - -Object: Add virtual soft control to sound card -Status: Proof of concept and not a usable product -Author: Fulup Ar Foll -Date : June-2017 - -HAL-plugin allows: - - to expose any existing NUMID under a customized label name, this is order to abstract sound card config. - - to add non alsa NUMID supported through a callback mechanism (eg: volume rampdown, power off, ...) - -installation - - Plugin should be placed where ever alsaplugins are located (typically: /usr/share/alsa-lib) - - Callback sharelib directory should be declare in $LD_LIBRARY_PATH - -Config -``` -cat ~/.asoundrc - ctl.agl_hal { - type afbhal - devid "hw:4" - cblib "afbhal_cb_sample.so" - ctls { - # ctlLabel {numid integer name "Alsa Ctl Name"} - MasterSwitch { numid 4 name "My_First_Control" } - MasterVol { numid 5 name "My_Second_Control" } - CB_sample { ctlcb @AfbHalSampleCB name "My_Sample_Callback"} - } - pcm.agl_hal { - type copy # Copy PCM - slave "hw:4" # Slave name - } -``` - -With such a config file - - numid=4 from sndcard=hw:4 is renamed "My_First_Control" - - numid=4 from sndcard=hw:4 is renamed "My_Second_Control" - - numid=4 will call AfbHalSampleCB from afbhal_cb_sample.so - -Note: to really implement a usable HAL at minimum every ALSA call should be implemented and read/write of values should be normalised from 0 to 100% with a step of 1. - -Conclusion: This demonstrate that implementing a HAL that both abstract ALSA get/set and enable non ALSA support is possible at an acceptable cost -without having to hack ALSA source code. The beauty of the model is than it is fully transparent to any ALSA application. The limit is that the plugin is loaded -within every application context, thus interaction with an external event loop remains complete as well as conflict management in case of share resources. |