summaryrefslogtreecommitdiffstats
path: root/ALSA-afb
diff options
context:
space:
mode:
Diffstat (limited to 'ALSA-afb')
-rw-r--r--ALSA-afb/Alsa-AddCtl.c78
-rw-r--r--ALSA-afb/Alsa-ApiHat.c61
-rw-r--r--ALSA-afb/Alsa-ApiHat.h1
-rw-r--r--ALSA-afb/Alsa-SetGet.c47
4 files changed, 46 insertions, 141 deletions
diff --git a/ALSA-afb/Alsa-AddCtl.c b/ALSA-afb/Alsa-AddCtl.c
index e30ebea..7593f2d 100644
--- a/ALSA-afb/Alsa-AddCtl.c
+++ b/ALSA-afb/Alsa-AddCtl.c
@@ -21,16 +21,14 @@
#include <systemd/sd-event.h>
#include "Alsa-ApiHat.h"
-STATIC int addOneSndCtl(struct afb_req request, snd_ctl_t *ctlDev, json_object *ctlJ) {
- snd_ctl_elem_info_t *cinfo;
+STATIC int addOneSndCtl(afb_req request, snd_ctl_t *ctlDev, json_object *ctlJ) {
int err;
- int i;
- unsigned int def_val;
json_object *jName, *jNumid, *jTmp;
const char *ctlName;
int ctlNumid, ctlMax, ctlMin, ctlStep, ctlCount, ctlSubDev;
snd_ctl_elem_type_t ctlType;
snd_ctl_elem_info_t *elemInfo;
+
// parse json ctl object
json_object_object_get_ex (ctlJ, "name" , &jName);
@@ -42,7 +40,7 @@ STATIC int addOneSndCtl(struct afb_req request, snd_ctl_t *ctlDev, json_object
ctlName = json_object_to_json_string(jName);
ctlNumid = json_object_get_int(jNumid);
-
+
// default for json_object_get_int is zero
json_object_object_get_ex (ctlJ, "min" , &jTmp);
ctlMin = json_object_get_int(jTmp);
@@ -80,7 +78,7 @@ STATIC int addOneSndCtl(struct afb_req request, snd_ctl_t *ctlDev, json_object
switch (ctlType) {
case SND_CTL_ELEM_TYPE_BOOLEAN:
- err = snd_ctl_add_boolean_elem_set(ctlDev, cinfo, 1, ctlCount);
+ err = snd_ctl_add_boolean_elem_set(ctlDev, elemInfo, 1, ctlCount);
if (err) {
afb_req_fail_f (request, "ctl-invalid-bool", "crl=%s invalid boolean data", json_object_to_json_string(ctlJ));
goto OnErrorExit;
@@ -104,77 +102,9 @@ STATIC int addOneSndCtl(struct afb_req request, snd_ctl_t *ctlDev, json_object
goto OnErrorExit;
}
-
- snd_ctl_elem_write(ctlDev, &ctlElem);
return 0;
OnErrorExit:
return -1;
}
-
-// Subscribe to every Alsa CtlEvent send by a given board
-PUBLIC void alsaAddCustomCtl (struct afb_req request) {
- snd_ctl_t *ctlDev;
- int err;
- const char *devid, *ctls;
- json_object *ctlsJ;
-
- devid = afb_req_value(request, "devid");
- if (!devid) {
- afb_req_fail_f (request, "missing-devid", "devid=xxx missing");
- goto OnErrorExit;
- }
-
- // open control interface for devid
- err = snd_ctl_open(&ctlDev, devid, 0);
- if (err < 0) {
- ctlDev=NULL;
- afb_req_fail_f (request, "devid-unknown", "SndCard devid=%s Not Found err=%s", queryValues.devid, snd_strerror(err));
- goto OnErrorExit;
- }
-
- ctls = afb_req_value(request, "ctls");
- if (!ctls) {
- afb_req_fail_f (request, "missing-ctls", "ctls=[{name:xxx, numdid=xx, ...}] missing");
- goto OnErrorExit;
- }
-
- ctlsJ = json_tokener_parse(ctls);
- if (!ctlsJ) {
- afb_req_fail_f (request, "ctls-notjson","ctls=%s not a valid json entry", ctls);
- goto OnErrorExit;
- };
-
- enum json_type jtype= json_object_get_type(ctlsJ);
- switch (jtype) {
- int error;
- json_object *ctlJ;
-
- case json_type_array:
- int count = json_object_array_length (ctlsJ);
- for (int idx=0; idx < count; idx ++) {
- ctlJ = json_object_array_get_idx (ctlsJ, idx);
- error = alsaAddCtrl (request, ctlDev, ctlsJ);
- if (error) goto OnErrorExit;
- }
- break;
-
- case json_type_object:
- error = alsaAddCtrl (request, ctlDev, ctlsJ);
- if (error) goto OnErrorExit;
- break;
-
- default:
- afb_req_fail_f (request, "ctls-notarray","ctls=%s not valid JSON control object", ctls);
- goto OnErrorExit;
- }
-
- snd_ctl_close(ctlDev);
- return;
-
- OnErrorExit:
- if (ctlDev) snd_ctl_close(ctlDev);
- return;
-}
-
diff --git a/ALSA-afb/Alsa-ApiHat.c b/ALSA-afb/Alsa-ApiHat.c
index 9520ce7..ced5d50 100644
--- a/ALSA-afb/Alsa-ApiHat.c
+++ b/ALSA-afb/Alsa-ApiHat.c
@@ -28,54 +28,31 @@
#include "Alsa-ApiHat.h"
-PUBLIC const struct afb_binding_interface *afbIface;
-
/*
* array of the verbs exported to afb-daemon
*/
-static const struct afb_verb_desc_v1 binding_verbs[] = {
- /* VERB'S NAME SESSION MANAGEMENT FUNCTION TO CALL SHORT DESCRIPTION */
- { .name= "ping" , .session= AFB_SESSION_NONE, .callback= pingtest, .info= "Ping Binding" },
- { .name= "getinfo", .session= AFB_SESSION_NONE, .callback= alsaGetInfo, .info= "List All/One Sound Cards Info" },
- { .name= "getctls", .session= AFB_SESSION_NONE, .callback= alsaGetCtls, .info= "Get Controls from selected sndcard" },
- { .name= "setctls", .session= AFB_SESSION_NONE, .callback= alsaSetCtls, .info= "Set Controls from selected sndcard" },
- { .name= "subscribe", .session= AFB_SESSION_NONE, .callback= alsaSubcribe, .info= "Subscribe to events from selected sndcard" },
- { .name= "getcardid", .session= AFB_SESSION_NONE, .callback= alsaGetCardId, .info= "Get CardId from its short/long name" },
- { .name= "registerHal",.session= AFB_SESSION_NONE, .callback= alsaRegisterHal, .info= "Register Hal CardName/ApiPrefix" },
- { .name= "ucmquery", .session= AFB_SESSION_NONE, .callback= alsaUseCaseQuery,.info= "Use Case Query" },
- { .name= "ucmset", .session= AFB_SESSION_NONE, .callback= alsaUseCaseSet, .info= "Use Case Set" },
- { .name= "ucmget", .session= AFB_SESSION_NONE, .callback= alsaUseCaseGet, .info= "Use Case Get" },
- { .name= "ucmreset", .session= AFB_SESSION_NONE, .callback= alsaUseCaseReset,.info= "Use Case Reset to Default" },
- { .name= "ucmclose", .session= AFB_SESSION_NONE, .callback= alsaUseCaseClose,.info= "Use Case Close Manager" },
- { .name= "addctl", .session= AFB_SESSION_NONE, .callback= alsaAddCustomCtl ,.info= "Add User Custom Sound Control" },
- { .name= NULL } /* marker for end of the array */
+static const struct afb_verb_v2 binding_verbs[] = {
+ /* VERB'S NAME FUNCTION TO CALL */
+ { .verb= "ping" , .callback= pingtest },
+ { .verb= "getinfo", .callback= alsaGetInfo},
+ { .verb= "getctls", .callback= alsaGetCtls},
+ { .verb= "setctls", .callback= alsaSetCtls},
+ { .verb= "subscribe", .callback= alsaSubcribe},
+ { .verb= "getcardid", .callback= alsaGetCardId},
+ { .verb= "registerHal", .callback= alsaRegisterHal},
+ { .verb= "ucmquery", .callback= alsaUseCaseQuery},
+ { .verb= "ucmset", .callback= alsaUseCaseSet},
+ { .verb= "ucmget", .callback= alsaUseCaseGet},
+ { .verb= "ucmreset", .callback= alsaUseCaseReset},
+ { .verb= "ucmclose", .callback= alsaUseCaseClose},
+ { .verb= "addctl", .callback= alsaAddCustomCtl},
+ { .verb= NULL } /* marker for end of the array */
};
/*
* description of the binding for afb-daemon
*/
-static const struct afb_binding binding_description = {
- /* description conforms to VERSION 1 */
- .type= AFB_BINDING_VERSION_1,
- .v1= {
- .prefix= "alsacore",
- .info= "Low Level Interface to Alsa Sound Lib",
- .verbs = binding_verbs
- }
-};
-
-extern int afbBindingV1ServiceInit(struct afb_service service) {
- // this is call when after all bindings are loaded
- // alsaLibInit (service); // AlsaBinding check for sound card at installation time
- return (0);
+const struct afb_binding_v2 afbBindingV2 = {
+ .api = "alsacore",
+ .verbs = binding_verbs,
};
-
-/*
- * activation function for registering the binding called by afb-daemon
- */
-const struct afb_binding *afbBindingV1Register(const struct afb_binding_interface *itf) {
- afbIface= itf;
-
- return &binding_description; /* returns the description of the binding */
-}
-
diff --git a/ALSA-afb/Alsa-ApiHat.h b/ALSA-afb/Alsa-ApiHat.h
index 44ef26f..c33f92e 100644
--- a/ALSA-afb/Alsa-ApiHat.h
+++ b/ALSA-afb/Alsa-ApiHat.h
@@ -21,7 +21,6 @@
#include "audio-interface.h"
-
typedef enum {
ACTION_SET,
ACTION_GET
diff --git a/ALSA-afb/Alsa-SetGet.c b/ALSA-afb/Alsa-SetGet.c
index 025846f..d6cf50d 100644
--- a/ALSA-afb/Alsa-SetGet.c
+++ b/ALSA-afb/Alsa-SetGet.c
@@ -103,7 +103,7 @@ PUBLIC void NumidsListParse (queryValuesT *queryValues, ctlRequestT *ctlRequest)
case json_type_object:
// numid+values formated as {id:xxx, val:[aa,bb...,nn]}
if (!json_object_object_get_ex (ctlRequest[idx].jToken,"id", &jId) || !json_object_object_get_ex (ctlRequest[idx].jToken,"val",&jVal)) {
- NOTICE (afbIface,"Invalid Json=%s missing 'id'|'val'", json_object_get_string(ctlRequest[idx].jToken));
+ NOTICE("Invalid Json=%s missing 'id'|'val'", json_object_get_string(ctlRequest[idx].jToken));
ctlRequest[idx].used=-1;
} else {
ctlRequest[idx].numId =json_object_get_int(jId);
@@ -117,8 +117,7 @@ PUBLIC void NumidsListParse (queryValuesT *queryValues, ctlRequestT *ctlRequest)
}
}
-PUBLIC int alsaCheckQuery (struct afb_req request, queryValuesT *queryValues) {
-
+PUBLIC int alsaCheckQuery (afb_req request, queryValuesT *queryValues) {
queryValues->devid = afb_req_value(request, "devid");
if (queryValues->devid == NULL) goto OnErrorExit;
const char *numids;
@@ -384,14 +383,14 @@ STATIC json_object* alsaCardProbe (const char *rqtSndId) {
int err;
if ((err = snd_ctl_open(&handle, rqtSndId, 0)) < 0) {
- INFO (afbIface, "SndCard [%s] Not Found", rqtSndId);
+ INFO ("SndCard [%s] Not Found", rqtSndId);
return NULL;
}
snd_ctl_card_info_alloca(&cardinfo);
if ((err = snd_ctl_card_info(handle, cardinfo)) < 0) {
snd_ctl_close(handle);
- WARNING (afbIface, "SndCard [%s] info error: %s", rqtSndId, snd_strerror(err));
+ WARNING ("SndCard [%s] info error: %s", rqtSndId, snd_strerror(err));
return NULL;
}
@@ -403,13 +402,13 @@ STATIC json_object* alsaCardProbe (const char *rqtSndId) {
name = snd_ctl_card_info_get_name(cardinfo);
json_object_object_add (ctlDev, "name", json_object_new_string (name));
- if (afbIface->verbosity > 1) {
+ if (AFB_GET_VERBOSITY > 1) {
json_object_object_add (ctlDev, "devid", json_object_new_string(rqtSndId));
driver= snd_ctl_card_info_get_driver(cardinfo);
json_object_object_add (ctlDev, "driver" , json_object_new_string(driver));
info = strdup(snd_ctl_card_info_get_longname (cardinfo));
json_object_object_add (ctlDev, "info" , json_object_new_string (info));
- INFO (afbIface, "AJG: Soundcard Devid=%-5s devid=%-7s Name=%s\n", rqtSndId, devid, info);
+ INFO ("AJG: Soundcard Devid=%-5s devid=%-7s Name=%s\n", rqtSndId, devid, info);
}
// free card handle and return info
@@ -418,7 +417,7 @@ STATIC json_object* alsaCardProbe (const char *rqtSndId) {
}
// Loop on every potential Sound card and register active one
-PUBLIC void alsaGetInfo (struct afb_req request) {
+PUBLIC void alsaGetInfo (afb_req request) {
int card;
json_object *ctlDev, *ctlDevs;
char devid[32];
@@ -491,13 +490,13 @@ STATIC int alsaSetSingleCtl (snd_ctl_t *ctlDev, snd_ctl_elem_id_t *elemId, ctlRe
snd_ctl_elem_info_alloca(&elemInfo);
snd_ctl_elem_info_set_id(elemInfo, elemId); // map ctlInfo to ctlId elemInfo is updated !!!
if (snd_ctl_elem_info(ctlDev, elemInfo) < 0) {
- NOTICE (afbIface, "Fail to load ALSA NUMID=%d Values=[%s]", ctlRequest->numId, json_object_to_json_string(ctlRequest->jValues));
+ NOTICE( "Fail to load ALSA NUMID=%d Values=[%s]", ctlRequest->numId, json_object_to_json_string(ctlRequest->jValues));
goto OnErrorExit;
}
snd_ctl_elem_info_get_id(elemInfo, elemId); // map ctlInfo to ctlId elemInfo is updated !!!
if (!snd_ctl_elem_info_is_writable(elemInfo)) {
- NOTICE (afbIface, "Not Writable ALSA NUMID=%d Values=[%s]", ctlRequest->numId, json_object_to_json_string(ctlRequest->jValues));
+ NOTICE( "Not Writable ALSA NUMID=%d Values=[%s]", ctlRequest->numId, json_object_to_json_string(ctlRequest->jValues));
goto OnErrorExit;
}
@@ -521,7 +520,7 @@ STATIC int alsaSetSingleCtl (snd_ctl_t *ctlDev, snd_ctl_elem_id_t *elemId, ctlRe
if (count == 0 || count < length) {
- NOTICE (afbIface, "Invalid values NUMID='%d' Values='%s' count='%d' wanted='%d'", ctlRequest->numId, json_object_to_json_string(ctlRequest->jValues), length, count);
+ NOTICE( "Invalid values NUMID='%d' Values='%s' count='%d' wanted='%d'", ctlRequest->numId, json_object_to_json_string(ctlRequest->jValues), length, count);
goto OnErrorExit;
}
@@ -543,7 +542,7 @@ STATIC int alsaSetSingleCtl (snd_ctl_t *ctlDev, snd_ctl_elem_id_t *elemId, ctlRe
err = snd_ctl_elem_write(ctlDev, elemData);
if (err < 0) {
- NOTICE (afbIface, "Fail to write ALSA NUMID=%d Values=[%s] Error=%s", ctlRequest->numId, json_object_to_json_string(ctlRequest->jValues), snd_strerror(err));
+ NOTICE( "Fail to write ALSA NUMID=%d Values=[%s] Error=%s", ctlRequest->numId, json_object_to_json_string(ctlRequest->jValues), snd_strerror(err));
goto OnErrorExit;
}
@@ -682,7 +681,7 @@ STATIC int alsaGetSingleCtl (snd_ctl_t *ctlDev, snd_ctl_elem_id_t *elemId, ctlRe
}
// assign multiple control to the same value
-PUBLIC void alsaSetGetCtls (struct afb_req request, ActionSetGetT action) {
+PUBLIC void alsaSetGetCtls (afb_req request, ActionSetGetT action) {
ctlRequestT *ctlRequest;
const char *warmsg=NULL;
int err=0, status=0;
@@ -737,7 +736,7 @@ PUBLIC void alsaSetGetCtls (struct afb_req request, ActionSetGetT action) {
} else {
int numid = snd_ctl_elem_list_get_numid(ctlList, ctlIndex);
if (numid < 0) {
- NOTICE (afbIface,"snd_ctl_elem_list_get_numid index=%d fail", ctlIndex);
+ NOTICE("snd_ctl_elem_list_get_numid index=%d fail", ctlIndex);
continue;
}
// check if current control was requested in query numids list
@@ -806,11 +805,11 @@ PUBLIC void alsaSetGetCtls (struct afb_req request, ActionSetGetT action) {
return;
}
-PUBLIC void alsaGetCtls (struct afb_req request) {
+PUBLIC void alsaGetCtls (afb_req request) {
alsaSetGetCtls (request, ACTION_GET);
}
-PUBLIC void alsaSetCtls (struct afb_req request) {
+PUBLIC void alsaSetCtls (afb_req request) {
alsaSetGetCtls (request, ACTION_SET);
}
@@ -830,7 +829,7 @@ STATIC int sndCtlEventCB (sd_event_source* src, int fd, uint32_t revents, void*
snd_ctl_elem_id_t *elemId;
if ((revents & EPOLLHUP) != 0) {
- NOTICE (afbIface, "SndCtl hanghup [car disconnected]");
+ NOTICE( "SndCtl hanghup [car disconnected]");
goto ExitOnSucess;
}
@@ -869,7 +868,7 @@ STATIC int sndCtlEventCB (sd_event_source* src, int fd, uint32_t revents, void*
json_object_object_add(ctlEventJ, "devname",json_object_new_string (devname));
}
if (ctlRequest.jValues) (json_object_object_add(ctlEventJ, "values" ,ctlRequest.jValues));
- DEBUG(afbIface, "sndCtlEventCB=%s", json_object_get_string(ctlEventJ));
+ DEBUG( "sndCtlEventCB=%s", json_object_get_string(ctlEventJ));
afb_event_push(evtHandle->afbevt, ctlEventJ);
}
@@ -878,12 +877,12 @@ STATIC int sndCtlEventCB (sd_event_source* src, int fd, uint32_t revents, void*
return 0;
OnErrorExit:
- WARNING (afbIface, "sndCtlEventCB: ignored unsupported event type");
+ WARNING ("sndCtlEventCB: ignored unsupported event type");
return (0);
}
// Subscribe to every Alsa CtlEvent send by a given board
-PUBLIC void alsaSubcribe (struct afb_req request) {
+PUBLIC void alsaSubcribe (afb_req request) {
static sndHandleT sndHandles[MAX_SND_CARD];
evtHandleT *evtHandle;
snd_ctl_t *ctlDev;
@@ -947,14 +946,14 @@ PUBLIC void alsaSubcribe (struct afb_req request) {
snd_ctl_poll_descriptors(evtHandle->ctlDev, &evtHandle->pfds, 1);
// register sound event to binder main loop
- err = sd_event_add_io(afb_daemon_get_event_loop(afbIface->daemon), &evtHandle->src, evtHandle->pfds.fd, EPOLLIN, sndCtlEventCB, evtHandle);
+ err = sd_event_add_io(afb_daemon_get_event_loop(), &evtHandle->src, evtHandle->pfds.fd, EPOLLIN, sndCtlEventCB, evtHandle);
if (err < 0) {
afb_req_fail_f (request, "register-mainloop", "Cannot hook events to mainloop devid=%s err=%d", queryValues.devid, err);
goto OnErrorExit;
}
// create binder event attached to devid name
- evtHandle->afbevt = afb_daemon_make_event (afbIface->daemon, queryValues.devid);
+ evtHandle->afbevt = afb_daemon_make_event (queryValues.devid);
if (!afb_event_is_valid (evtHandle->afbevt)) {
afb_req_fail_f (request, "register-event", "Cannot register new binder event name=%s", queryValues.devid);
goto OnErrorExit;
@@ -982,7 +981,7 @@ PUBLIC void alsaSubcribe (struct afb_req request) {
}
// Subscribe to every Alsa CtlEvent send by a given board
-PUBLIC void alsaGetCardId (struct afb_req request) {
+PUBLIC void alsaGetCardId (afb_req request) {
char devid [10];
const char *devname, *shortname, *longname;
int card, err, index, idx;
@@ -1047,7 +1046,7 @@ PUBLIC void alsaGetCardId (struct afb_req request) {
}
// Register loaded HAL with board Name and API prefix
-PUBLIC void alsaRegisterHal (struct afb_req request) {
+PUBLIC void alsaRegisterHal (afb_req request) {
static int index=0;
const char *shortname, *apiPrefix;