From 593ed6dc72274f86046aae3dc6b264c568241917 Mon Sep 17 00:00:00 2001 From: fulup Date: Tue, 25 Jul 2017 11:37:10 +0200 Subject: Initial version of HAL with Set/Get operation --- ALSA-afb/Alsa-AddCtl.c | 2 +- ALSA-afb/Alsa-ApiHat.h | 6 +- ALSA-afb/Alsa-RegEvt.c | 33 +++- ALSA-afb/Alsa-SetGet.c | 236 +++++++++++++--------------- ALSA-afb/Alsa-Ucm.c | 39 ++--- HAL-afb/HAL-interface/hal-interface.c | 150 +++++++----------- HAL-afb/HAL-interface/hal-interface.h | 7 +- HAL-afb/HAL-interface/hal-volmap.c | 97 +++++++++--- HAL-afb/Scarlett-Focusrite/ScarlettUsbHAL.c | 1 + Shared-Interface/audio-interface.c | 28 ---- Shared-Interface/audio-interface.h | 15 +- conf.d/cmake/config.cmake | 1 + htdocs/AudioBinding.js | 102 ++++++++---- htdocs/alsa-core.html | 38 +++-- htdocs/alsa-hal.html | 10 +- nbproject/configurations.xml | 54 +++---- 16 files changed, 437 insertions(+), 382 deletions(-) diff --git a/ALSA-afb/Alsa-AddCtl.c b/ALSA-afb/Alsa-AddCtl.c index 4635503..b7e3d90 100644 --- a/ALSA-afb/Alsa-AddCtl.c +++ b/ALSA-afb/Alsa-AddCtl.c @@ -183,7 +183,7 @@ STATIC json_object * addOneSndCtl(afb_req request, snd_ctl_t *ctlDev, json_obje OnSucessExit: alsaGetSingleCtl (ctlDev, elemId, &ctlRequest, queryMode); if (ctlRequest.used < 0) goto OnErrorExit; - return ctlRequest.jValues; + return ctlRequest.valuesJ; OnErrorExit: return NULL; diff --git a/ALSA-afb/Alsa-ApiHat.h b/ALSA-afb/Alsa-ApiHat.h index 6c9f4c3..6e50e11 100644 --- a/ALSA-afb/Alsa-ApiHat.h +++ b/ALSA-afb/Alsa-ApiHat.h @@ -32,7 +32,7 @@ typedef enum { // generic structure to pass parsed query values typedef struct { const char *devid; - json_object *jNumIds; + json_object *numidsJ; halQueryMode mode; int count; } queryValuesT; @@ -41,13 +41,13 @@ typedef struct { typedef struct { unsigned int numId; json_object *jToken; - json_object *jValues; + json_object *valuesJ; int used; } ctlRequestT; // import from AlsaAfbBinding extern const struct afb_binding_interface *afbIface; -PUBLIC int alsaCheckQuery (struct afb_req request, queryValuesT *queryValues); +PUBLIC json_object *alsaCheckQuery (struct afb_req request, queryValuesT *queryValues); // AlseCoreSetGet exports PUBLIC int alsaGetSingleCtl (snd_ctl_t *ctlDev, snd_ctl_elem_id_t *elemId, ctlRequestT *ctlRequest, halQueryMode queryMode); diff --git a/ALSA-afb/Alsa-RegEvt.c b/ALSA-afb/Alsa-RegEvt.c index 7b0a722..df6570a 100644 --- a/ALSA-afb/Alsa-RegEvt.c +++ b/ALSA-afb/Alsa-RegEvt.c @@ -44,6 +44,31 @@ typedef struct { cardRegistryT *cardRegistry[MAX_SND_CARD+1]; +PUBLIC json_object *alsaCheckQuery (afb_req request, queryValuesT *queryValues) { + + json_object *tmpJ; + int done; + + // get query from request + json_object *queryInJ = afb_req_json(request); + + done= json_object_object_get_ex (queryInJ, "devid" , &tmpJ); + if (!done) { + afb_req_fail_f(request, "devid-missing", "Invalid query='%s'", json_object_get_string(queryInJ)); + goto OnErrorExit; + } + queryValues->devid = json_object_get_string(tmpJ); + + done= json_object_object_get_ex (queryInJ, "mode" , &tmpJ); + if (!done) queryValues->mode=QUERY_QUIET; // default quiet + else queryValues->mode = json_object_get_int (tmpJ); + + return queryInJ; + +OnErrorExit: + return NULL; +} + // This routine is called when ALSA event are fired STATIC int sndCtlEventCB (sd_event_source* src, int fd, uint32_t revents, void* userData) { int err; @@ -97,7 +122,7 @@ STATIC int sndCtlEventCB (sd_event_source* src, int fd, uint32_t revents, void* json_object_object_add(ctlEventJ, "iface" ,json_object_new_int (iface)); json_object_object_add(ctlEventJ, "devname",json_object_new_string (devname)); } - if (ctlRequest.jValues) (json_object_object_add(ctlEventJ, "values" ,ctlRequest.jValues)); + if (ctlRequest.valuesJ) (json_object_object_add(ctlEventJ, "value" ,ctlRequest.valuesJ)); AFB_DEBUG( "sndCtlEventCB=%s", json_object_get_string(ctlEventJ)); afb_event_push(evtHandle->afbevt, ctlEventJ); } @@ -119,10 +144,8 @@ PUBLIC void alsaEvtSubcribe (afb_req request) { snd_ctl_card_info_t *cardinfo; queryValuesT queryValues; - - err = alsaCheckQuery (request, &queryValues); - if (err) goto OnErrorExit; - + json_object *queryJ = alsaCheckQuery (request, &queryValues); + if (!queryJ) goto OnErrorExit; // open control interface for devid err = snd_ctl_open(&ctlDev, queryValues.devid, SND_CTL_READONLY); diff --git a/ALSA-afb/Alsa-SetGet.c b/ALSA-afb/Alsa-SetGet.c index 0815f35..50b62ce 100644 --- a/ALSA-afb/Alsa-SetGet.c +++ b/ALSA-afb/Alsa-SetGet.c @@ -21,62 +21,69 @@ http://alsa.opensrc.org/HowTo_access_a_mixer_control https://github.com/gch1p/alsa-volume-monitor/blob/master/main.c https://github.com/DongheonKim/android_hardware_alsa-sound/blob/master/ALSAControl.cpp (ALSA low level API) + https://www.kernel.org/doc/html/v4.11/sound/index.html */ #define _GNU_SOURCE // needed for vasprintf - #include "Alsa-ApiHat.h" -PUBLIC void NumidsListParse (queryValuesT *queryValues, ctlRequestT *ctlRequest) { - json_object *jValues; +PUBLIC void NumidsListParse (ActionSetGetT action, queryValuesT *queryValues, ctlRequestT *ctlRequest) { int length; - - for (int idx=0; idx < queryValues->count; idx ++) { - ctlRequest[idx].jToken = json_object_array_get_idx (queryValues->jNumIds, idx); - ctlRequest[idx].jValues = NULL; - ctlRequest[idx].used=0; + for (int idx=0; idx < queryValues->count; idx ++) { + json_object *jId, *valuesJ; + ctlRequest[idx].used=0; + ctlRequest[idx].valuesJ = NULL; + + // when only one NUMID is provided it might not be encapsulated in a JSON array + if (json_type_array == json_object_get_type(queryValues->numidsJ)) ctlRequest[idx].jToken = json_object_array_get_idx (queryValues->numidsJ, idx); + else ctlRequest[idx].jToken=queryValues->numidsJ; + enum json_type jtype=json_object_get_type(ctlRequest[idx].jToken); switch (jtype) { - json_object *jId, *jVal; case json_type_int: // if NUMID is not an array then it should be an integer numid with no value ctlRequest[idx].numId = json_object_get_int (ctlRequest[idx].jToken); + + // Special SET simple short numid form [numid, [VAL1...VALX]] + if (action == ACTION_SET && queryValues->count == 2) { + ctlRequest[idx].valuesJ = json_object_array_get_idx (queryValues->numidsJ, 1); + queryValues->count =1; //In this form count==2 , when only one numid is to set + idx ++; + continue; + } else break; case json_type_array: // NUMID is an array 1st slot should be numid, optionally values may come after length=json_object_array_length (ctlRequest[idx].jToken); - if (length < 1 || length >2) { - ctlRequest[idx].used=-1; - continue; - } + // numid must be in 1st slot of numid json array ctlRequest[idx].numId =json_object_get_int(json_object_array_get_idx (ctlRequest[idx].jToken, 0)); + if (action == ACTION_GET) continue; - if (length == 2) { - jValues = json_object_array_get_idx (ctlRequest[idx].jToken, 1); - if (jValues == NULL) { - ctlRequest[idx].used=-1; - continue; - } - // Value is an int or an array with potentially multiple subvalues - ctlRequest[idx].jValues = jValues; + // In Write mode second value should be the value + if (action == ACTION_SET && length == 2) { + ctlRequest[idx].valuesJ = json_object_array_get_idx (ctlRequest[idx].jToken, 1); + continue; } + + // no numid value + ctlRequest[idx].used=-1; break; 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)) { + if (!json_object_object_get_ex (ctlRequest[idx].jToken,"id", &jId) || !json_object_object_get_ex (ctlRequest[idx].jToken,"val",&valuesJ)) { AFB_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); - ctlRequest[idx].jValues =jVal; + if (action == ACTION_SET) ctlRequest[idx].valuesJ=valuesJ; } - + break; default: ctlRequest[idx].used=-1; @@ -84,59 +91,6 @@ PUBLIC void NumidsListParse (queryValuesT *queryValues, ctlRequestT *ctlRequest) } } -PUBLIC int alsaCheckQuery (afb_req request, queryValuesT *queryValues) { - queryValues->devid = afb_req_value(request, "devid"); - if (queryValues->devid == NULL) goto OnErrorExit; - const char *numids; - json_object *jNumIds; - - const char *rqtmode = afb_req_value(request, "mode"); - if (!rqtmode) queryValues->mode=QUERY_QUIET; // default quiet - else if (rqtmode && ! sscanf (rqtmode, "%d", (int)&queryValues->mode)) { - json_object *query = afb_req_json(request); - - afb_req_fail_f (request, "mode-notinteger","Query=%s mode not integer &mode=%s&", json_object_get_string(query), rqtmode); - goto OnErrorExit; - }; - - // no NumId is interpreted as ALL for get and error for set - numids = afb_req_value(request, "numid"); - if (numids == NULL) { - queryValues->count=0; - goto OnExit; - } - - jNumIds = json_tokener_parse(numids); - if (!jNumIds) { - afb_req_fail_f (request, "numids-notjson","numids=%s not a valid json entry", numids); - goto OnErrorExit; - }; - - enum json_type jtype= json_object_get_type(jNumIds); - switch (jtype) { - case json_type_array: - queryValues->jNumIds = jNumIds; - queryValues->count = json_object_array_length (jNumIds); - break; - - case json_type_int: - queryValues->count = 1; - queryValues->jNumIds = json_object_new_array (); - json_object_array_add (queryValues->jNumIds, jNumIds); - break; - - default: - afb_req_fail_f (request, "numid-notarray","NumId=%s NumId not valid JSON array", numids); - goto OnErrorExit; - } - -OnExit: - return 0; - -OnErrorExit: - return 1; -} - STATIC json_object *DB2StringJsonOject (long dB) { char label [20]; if (dB < 0) { @@ -380,14 +334,14 @@ STATIC json_object* alsaCardProbe (const char *rqtSndId) { int err; if ((err = snd_ctl_open(&handle, rqtSndId, 0)) < 0) { - AFB_INFO ("alsaCardProbe [%s] Not Found", rqtSndId); + AFB_INFO ("alsaCardProbe '%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); - AFB_WARNING ("SndCard [%s] info error: %s", rqtSndId, snd_strerror(err)); + AFB_WARNING ("SndCard '%s' info error: %s", rqtSndId, snd_strerror(err)); return NULL; } @@ -427,7 +381,7 @@ PUBLIC void alsaGetInfo (afb_req request) { // only one card was requested let's probe it ctlDev = alsaCardProbe (rqtSndId); if (ctlDev != NULL) afb_req_success(request, ctlDev, NULL); - else afb_req_fail_f (request, "sndscard-notfound", "SndCard [%s] Not Found", rqtSndId); + else afb_req_fail_f (request, "sndscard-notfound", "SndCard '%s' Not Found", rqtSndId); } else { // return an array of ctlDev @@ -487,22 +441,22 @@ PUBLIC 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) { - AFB_NOTICE( "Fail to load ALSA NUMID=%d Values=[%s]", ctlRequest->numId, json_object_get_string(ctlRequest->jValues)); + AFB_NOTICE( "Fail to load ALSA NUMID=%d Values='%s'", ctlRequest->numId, json_object_get_string(ctlRequest->valuesJ)); goto OnErrorExit; } if (!snd_ctl_elem_info_is_writable(elemInfo)) { - AFB_NOTICE( "Not Writable ALSA NUMID=%d Values=[%s]", ctlRequest->numId, json_object_get_string(ctlRequest->jValues)); + AFB_NOTICE( "Not Writable ALSA NUMID=%d Values='%s'", ctlRequest->numId, json_object_get_string(ctlRequest->valuesJ)); goto OnErrorExit; } count = snd_ctl_elem_info_get_count (elemInfo); if (count == 0) goto OnErrorExit; - - enum json_type jtype= json_object_get_type(ctlRequest->jValues); + + enum json_type jtype= json_object_get_type(ctlRequest->valuesJ); switch (jtype) { case json_type_array: - length = json_object_array_length (ctlRequest->jValues); + length = json_object_array_length (ctlRequest->valuesJ); valueIsArray=1; break; case json_type_int: @@ -510,14 +464,13 @@ PUBLIC int alsaSetSingleCtl (snd_ctl_t *ctlDev, snd_ctl_elem_id_t *elemId, ctlRe valueIsArray=0; break; default: - count =0; length = 0; break; } - if (count == 0 || count < length) { - AFB_NOTICE( "Invalid values NUMID='%d' Values='%s' count='%d' wanted='%d'", ctlRequest->numId, json_object_get_string(ctlRequest->jValues), length, count); + if (length == 0) { + AFB_NOTICE( "Invalid values NUMID='%d' Values='%s' count='%d' wanted='%d'", ctlRequest->numId, json_object_get_string(ctlRequest->valuesJ), length, count); goto OnErrorExit; } @@ -526,12 +479,16 @@ PUBLIC int alsaSetSingleCtl (snd_ctl_t *ctlDev, snd_ctl_elem_id_t *elemId, ctlRe if (snd_ctl_elem_read(ctlDev, elemData) < 0) goto OnErrorExit; // Loop on every control value and push to sndcard - for (int index=0; index < count && index < length; index++) { + for (int index=0; index < count; index++) { json_object *element; int value; - - if (valueIsArray) element= json_object_array_get_idx(ctlRequest->jValues, index); - else element= ctlRequest->jValues; + + // when not enough value duplicate last provided one + if (!valueIsArray) element= ctlRequest->valuesJ; + else { + if (index < length) element= json_object_array_get_idx(ctlRequest->valuesJ, index); + else element= json_object_array_get_idx(ctlRequest->valuesJ, length-1); + } value= json_object_get_int (element); snd_ctl_elem_value_set_integer(elemData, index, value); @@ -539,7 +496,7 @@ PUBLIC int alsaSetSingleCtl (snd_ctl_t *ctlDev, snd_ctl_elem_id_t *elemId, ctlRe err = snd_ctl_elem_write(ctlDev, elemData); if (err < 0) { - AFB_NOTICE( "Fail to write ALSA NUMID=%d Values=[%s] Error=%s", ctlRequest->numId, json_object_get_string(ctlRequest->jValues), snd_strerror(err)); + AFB_NOTICE( "Fail to write ALSA NUMID=%d Values='%s' Error=%s", ctlRequest->numId, json_object_get_string(ctlRequest->valuesJ), snd_strerror(err)); goto OnErrorExit; } @@ -576,11 +533,11 @@ PUBLIC int alsaGetSingleCtl (snd_ctl_t *ctlDev, snd_ctl_elem_id_t *elemId, ctlRe int numid= snd_ctl_elem_info_get_numid(elemInfo); - ctlRequest->jValues= json_object_new_object(); - json_object_object_add (ctlRequest->jValues,"numid" , json_object_new_int(numid)); - if (queryMode >= 1) json_object_object_add (ctlRequest->jValues,"name" , json_object_new_string(snd_ctl_elem_id_get_name (elemId))); - if (queryMode >= 2) json_object_object_add (ctlRequest->jValues,"iface" , json_object_new_string(snd_ctl_elem_iface_name(snd_ctl_elem_id_get_interface(elemId)))); - if (queryMode >= 3) json_object_object_add (ctlRequest->jValues,"actif", json_object_new_boolean(!snd_ctl_elem_info_is_inactive(elemInfo))); + ctlRequest->valuesJ= json_object_new_object(); + json_object_object_add (ctlRequest->valuesJ,"id" , json_object_new_int(numid)); + if (queryMode >= 1) json_object_object_add (ctlRequest->valuesJ,"name" , json_object_new_string(snd_ctl_elem_id_get_name (elemId))); + if (queryMode >= 2) json_object_object_add (ctlRequest->valuesJ,"iface" , json_object_new_string(snd_ctl_elem_iface_name(snd_ctl_elem_id_get_interface(elemId)))); + if (queryMode >= 3) json_object_object_add (ctlRequest->valuesJ,"actif", json_object_new_boolean(!snd_ctl_elem_info_is_inactive(elemInfo))); json_object *jsonValuesCtl = json_object_new_array(); for (idx = 0; idx < count; idx++) { // start from one in amixer.c !!! @@ -618,7 +575,7 @@ PUBLIC int alsaGetSingleCtl (snd_ctl_t *ctlDev, snd_ctl_elem_id_t *elemId, ctlRe break; } } - json_object_object_add (ctlRequest->jValues,"val",jsonValuesCtl); + json_object_object_add (ctlRequest->valuesJ,"val",jsonValuesCtl); if (queryMode >= 1) { // in simple mode do not print usable values json_object *jsonClassCtl = json_object_new_object(); @@ -653,18 +610,18 @@ PUBLIC int alsaGetSingleCtl (snd_ctl_t *ctlDev, snd_ctl_elem_id_t *elemId, ctlRe } // add collected class info with associated ACLs - json_object_object_add (ctlRequest->jValues,"ctl", jsonClassCtl); + json_object_object_add (ctlRequest->valuesJ,"ctl", jsonClassCtl); - if (queryMode >= QUERY_FULL) json_object_object_add (ctlRequest->jValues,"acl" , getControlAcl (elemInfo)); + if (queryMode >= QUERY_FULL) json_object_object_add (ctlRequest->valuesJ,"acl" , getControlAcl (elemInfo)); // check for tlv [direct port from amixer.c] if (snd_ctl_elem_info_is_tlv_readable(elemInfo)) { - unsigned int *tlv = alloca(4096); + unsigned int *tlv = alloca(TLV_BYTE_SIZE); if ((err = snd_ctl_elem_tlv_read(ctlDev, elemId, tlv, 4096)) < 0) { fprintf (stderr, "Control %s element TLV read error\n", snd_strerror(err)); goto OnErrorExit; } else { - json_object_object_add (ctlRequest->jValues,"tlv", decodeTlv (tlv, 4096, queryMode)); + json_object_object_add (ctlRequest->valuesJ,"tlv", decodeTlv (tlv, TLV_BYTE_SIZE, queryMode)); } } } @@ -678,38 +635,61 @@ PUBLIC int alsaGetSingleCtl (snd_ctl_t *ctlDev, snd_ctl_elem_id_t *elemId, ctlRe } // assign multiple control to the same value -STATIC void alsaSetGetCtls (afb_req request, ActionSetGetT action) { +STATIC void alsaSetGetCtls (ActionSetGetT action, afb_req request) { ctlRequestT *ctlRequest; const char *warmsg=NULL; - int err=0, status=0; + int err=0, status=0, done; unsigned int ctlCount; snd_ctl_t *ctlDev; snd_ctl_elem_list_t *ctlList; json_object *sndctls=json_object_new_array();; queryValuesT queryValues; + json_object *queryJ, *numidsJ; - err = alsaCheckQuery (request, &queryValues); - if (err) goto OnErrorExit; + queryJ = alsaCheckQuery (request, &queryValues); + if (!queryJ) goto OnErrorExit; + // Prase Numids + optional values + done= json_object_object_get_ex (queryJ, "numid" , &numidsJ); + if (!done) queryValues.count=0; + else { + enum json_type jtype= json_object_get_type(numidsJ); + switch (jtype) { + case json_type_array: + queryValues.numidsJ = numidsJ; + queryValues.count = json_object_array_length (numidsJ); + break; + case json_type_int: + case json_type_object: + queryValues.count = 1; + queryValues.numidsJ = numidsJ; + break; + + default: + afb_req_fail_f (request, "numid-notarray","NumId=%s NumId not valid JSON array", json_object_get_string(numidsJ)); + goto OnErrorExit; + } + } + if ((err = snd_ctl_open(&ctlDev, queryValues.devid, 0)) < 0) { - afb_req_fail_f (request, "sndcrl-notfound","devid=[%s] load fail error=%s\n", queryValues.devid, snd_strerror(err)); + afb_req_fail_f (request, "sndcrl-notfound","devid='%s' load fail error=%s\n", queryValues.devid, snd_strerror(err)); goto OnErrorExit; } snd_ctl_elem_list_alloca(&ctlList); if ((err = snd_ctl_elem_list (ctlDev, ctlList)) < 0) { - afb_req_fail_f (request, "listInit-failed","devid=[%s] load fail error=%s\n", queryValues.devid, snd_strerror(err)); + afb_req_fail_f (request, "listInit-failed","devid='%s' load fail error=%s\n", queryValues.devid, snd_strerror(err)); goto OnErrorExit; } if ((err = snd_ctl_elem_list_alloc_space(ctlList, snd_ctl_elem_list_get_count(ctlList))) < 0) { - afb_req_fail_f (request, "listAlloc-failed","devid=[%s] load fail error=%s\n", queryValues.devid, snd_strerror(err)); + afb_req_fail_f (request, "listAlloc-failed","devid='%s' load fail error=%s\n", queryValues.devid, snd_strerror(err)); goto OnErrorExit; } if ((err = snd_ctl_elem_list (ctlDev, ctlList)) < 0) { - afb_req_fail_f (request, "listOpen-failed","devid=[%s] load fail error=%s\n", queryValues.devid, snd_strerror(err)); + afb_req_fail_f (request, "listOpen-failed","devid='%s' load fail error=%s\n", queryValues.devid, snd_strerror(err)); goto OnErrorExit; } @@ -719,7 +699,7 @@ STATIC void alsaSetGetCtls (afb_req request, ActionSetGetT action) { ctlRequest= alloca (sizeof(ctlRequestT)*(ctlCount)); } else { ctlRequest= alloca (sizeof(ctlRequestT)*(queryValues.count)); - NumidsListParse (&queryValues, ctlRequest); + NumidsListParse (action, &queryValues, ctlRequest); } // Loop on all ctlDev controls @@ -754,45 +734,47 @@ STATIC void alsaSetGetCtls (afb_req request, ActionSetGetT action) { switch (action) { case ACTION_GET: err = alsaGetSingleCtl (ctlDev, elemId, &ctlRequest[jdx], queryValues.mode); - break; + break; case ACTION_SET: err = alsaSetSingleCtl (ctlDev, elemId, &ctlRequest[jdx]); + break; default: err = 1; } if (err) status++; else { - json_object_array_add (sndctls, ctlRequest[jdx].jValues); + if (action == ACTION_GET) json_object_array_add (sndctls, ctlRequest[jdx].valuesJ); } } } // if we had error let's add them into response message info - json_object *warnings = json_object_new_array(); + json_object *warningsJ = json_object_new_array(); for (int jdx=0; jdx < queryValues.count; jdx++) { if (ctlRequest[jdx].used <= 0) { json_object *failctl = json_object_new_object(); json_object_object_add (failctl, "numid", ctlRequest[jdx].jToken); - if (ctlRequest[jdx].jValues) - json_object_object_add(failctl, "values", ctlRequest[jdx].jValues); + if (ctlRequest[jdx].valuesJ) json_object_object_add(failctl, "value", ctlRequest[jdx].valuesJ); + + AFB_NOTICE ("*** jToken=%s value=%s", json_object_get_string(ctlRequest[jdx].jToken), json_object_get_string(ctlRequest[jdx].valuesJ)); - if (ctlRequest[jdx].numId == -1) json_object_object_add (failctl, "info", json_object_new_string ("Invalid NumID")); + if (ctlRequest[jdx].numId == -1) json_object_object_add (failctl, "error", json_object_new_string ("Numid Invalid")); else { - if (ctlRequest[jdx].used == 0) json_object_object_add (failctl, "info", json_object_new_string ("Does Not Exist")); - if (ctlRequest[jdx].used == -1) json_object_object_add (failctl, "info", json_object_new_string ("Invalid Value")); + if (ctlRequest[jdx].used == 0) json_object_object_add (failctl, "error", json_object_new_string ("Numid Does Not Exist")); + if (ctlRequest[jdx].used == -1) json_object_object_add (failctl, "error", json_object_new_string ("Value invalid")); } - json_object_array_add (warnings, failctl); + json_object_array_add (warningsJ, failctl); } - /* WARNING!!!! Check with Jose why following put free jValues + /* WARNING!!!! Check with Jose why following put free valuesJ if (ctlRequest[jdx].jToken) json_object_put(ctlRequest[jdx].jToken); - if (ctlRequest[jdx].jValues) json_object_put(ctlRequest[jdx].jValues); + if (ctlRequest[jdx].valuesJ) json_object_put(ctlRequest[jdx].valuesJ); */ } - if (json_object_array_length(warnings)) warmsg=json_object_get_string (warnings); - else json_object_put(warnings); + if (json_object_array_length(warningsJ) > 0) warmsg=json_object_get_string (warningsJ); + else json_object_put(warningsJ); // send response+warning if any afb_req_success (request, sndctls, warmsg); @@ -803,11 +785,11 @@ STATIC void alsaSetGetCtls (afb_req request, ActionSetGetT action) { } PUBLIC void alsaGetCtls (afb_req request) { - alsaSetGetCtls (request, ACTION_GET); + alsaSetGetCtls (ACTION_GET, request); } PUBLIC void alsaSetCtls (afb_req request) { - alsaSetGetCtls (request, ACTION_SET); + alsaSetGetCtls (ACTION_SET, request); } diff --git a/ALSA-afb/Alsa-Ucm.c b/ALSA-afb/Alsa-Ucm.c index f512417..ee2b36d 100644 --- a/ALSA-afb/Alsa-Ucm.c +++ b/ALSA-afb/Alsa-Ucm.c @@ -111,16 +111,15 @@ STATIC int alsaUseCaseOpen (struct afb_req request, queryValuesT *queryValues, i PUBLIC void alsaUseCaseQuery(struct afb_req request) { - int err, verbCount, ucmIdx; + int verbCount, ucmIdx; const char **verbList; snd_use_case_mgr_t *ucmHandle; queryValuesT queryValues; json_object *ucmJs; const char *cardName; - - err = alsaCheckQuery (request, &queryValues); - if (err) goto OnErrorExit; + json_object *queryJ = alsaCheckQuery (request, &queryValues); + if (!queryJ) goto OnErrorExit; ucmIdx = alsaUseCaseOpen (request, &queryValues, TRUE); if (ucmIdx < 0) goto OnErrorExit; @@ -158,7 +157,7 @@ PUBLIC void alsaUseCaseQuery(struct afb_req request) { json_object_array_add (devsJ, devJ); } json_object_object_add(ucmJ,"devices", devsJ); - snd_use_case_free_list(devList, err); + snd_use_case_free_list(devList, devCount); } snprintf (identifier, sizeof(identifier), "_modifiers/%s", verbList[idx]); @@ -174,7 +173,7 @@ PUBLIC void alsaUseCaseQuery(struct afb_req request) { json_object_array_add (modsJ, modJ); } json_object_object_add(ucmJ,"modifiers", modsJ); - snd_use_case_free_list(modList, err); + snd_use_case_free_list(modList, modCount); } snprintf (identifier, sizeof(identifier), "TQ/%s", verbList[idx]); @@ -190,14 +189,14 @@ PUBLIC void alsaUseCaseQuery(struct afb_req request) { json_object_array_add (tqsJ, tqJ); } json_object_object_add(ucmJ,"tqs", tqsJ); - snd_use_case_free_list(tqList, err); + snd_use_case_free_list(tqList, tqCount); } json_object_array_add (ucmJs, ucmJ); } afb_req_success (request, ucmJs, NULL); - snd_use_case_free_list(verbList, err); + snd_use_case_free_list(verbList, verbCount); OnErrorExit: return; @@ -235,14 +234,15 @@ STATIC json_object *ucmGetValue (ucmHandleT *ucmHandle, const char *verb, const } PUBLIC void alsaUseCaseGet (struct afb_req request) { - int err, ucmIdx, labelCount; + int ucmIdx, labelCount; queryValuesT queryValues; json_object *jResponse = json_object_new_object(); json_object *jWarnings = json_object_new_array(); const char *warnings=NULL; - err = alsaCheckQuery (request, &queryValues); - if (err) goto OnErrorExit; + json_object *queryJ = alsaCheckQuery (request, &queryValues); + if (!queryJ) goto OnErrorExit; +; ucmIdx = alsaUseCaseOpen (request, &queryValues, TRUE); if (ucmIdx < 0) goto OnErrorExit; @@ -261,7 +261,7 @@ PUBLIC void alsaUseCaseGet (struct afb_req request) { // device selection is handle as a modifier if (dev) mod=dev; - const char *labels = afb_req_value(request, "values"); + const char *labels = afb_req_value(request, "value"); if (!labels) { afb_req_fail_f (request, "ucmget-labels", "SndCard devid=[%s] name=[%s] UCM values name missing", queryValues.devid, cardName); goto OnErrorExit; @@ -323,8 +323,9 @@ PUBLIC void alsaUseCaseSet(struct afb_req request) { queryValuesT queryValues; json_object *jResponse = json_object_new_object(); - err = alsaCheckQuery (request, &queryValues); - if (err) goto OnErrorExit; + json_object *queryJ = alsaCheckQuery (request, &queryValues); + if (!queryJ) goto OnErrorExit; + ucmIdx = alsaUseCaseOpen (request, &queryValues, TRUE); if (ucmIdx < 0) goto OnErrorExit; @@ -362,7 +363,7 @@ PUBLIC void alsaUseCaseSet(struct afb_req request) { } // label are requested transfert request to get - if (afb_req_value(request, "values")) return alsaUseCaseGet(request); + if (afb_req_value(request, "value")) return alsaUseCaseGet(request); if (queryValues.mode <= 3) { json_object *jValue; @@ -388,8 +389,8 @@ PUBLIC void alsaUseCaseReset (struct afb_req request) { int err, ucmIdx; queryValuesT queryValues; - err = alsaCheckQuery (request, &queryValues); - if (err) goto OnErrorExit; + json_object *queryJ = alsaCheckQuery (request, &queryValues); + if (!queryJ) goto OnErrorExit; ucmIdx = alsaUseCaseOpen (request, &queryValues, FALSE); if (ucmIdx < 0) goto OnErrorExit; @@ -410,8 +411,8 @@ PUBLIC void alsaUseCaseClose (struct afb_req request) { int err, ucmIdx; queryValuesT queryValues; - err = alsaCheckQuery (request, &queryValues); - if (err) goto OnErrorExit; + json_object *queryJ = alsaCheckQuery (request, &queryValues); + if (!queryJ) goto OnErrorExit; ucmIdx = alsaUseCaseOpen (request, &queryValues, FALSE); if (ucmIdx < 0) goto OnErrorExit; diff --git a/HAL-afb/HAL-interface/hal-interface.c b/HAL-afb/HAL-interface/hal-interface.c index 1f39a81..f4fc8df 100644 --- a/HAL-afb/HAL-interface/hal-interface.c +++ b/HAL-afb/HAL-interface/hal-interface.c @@ -52,12 +52,10 @@ STATIC void halSubscribe(afb_req request) { } } - - // Map HAL ctlName to ctlLabel STATIC int halCtlStringToIndex (const char* label) { - for (int idx = 0; halCtls[idx].ctl.numid; idx++) { + for (int idx = 0; halCtls[idx].tag != EndHalCrlTag; idx++) { if (!strcmp (halCtls[idx].label, label)) return idx; } @@ -67,7 +65,7 @@ STATIC int halCtlStringToIndex (const char* label) { STATIC int halCtlTagToIndex (halCtlsEnumT tag) { - for (int idx = 0; halCtls[idx].ctl.numid; idx++) { + for (int idx = 0; halCtls[idx].tag != EndHalCrlTag; idx++) { if (halCtls[idx].tag == tag) return idx; } @@ -93,122 +91,98 @@ PUBLIC void halListCtls(afb_req request) { afb_req_success (request, ctlsHalJ, NULL); } - STATIC int halGetCtlIndex (afb_req request, struct json_object*ctlInJ) { struct json_object *tmpJ; - int tag, index; + int tag, index, done; // check 1st short command mode [tag1, tag2, ...] - tag = json_object_get_type (ctlInJ); - - if (!tag) { - json_object_object_get_ex (ctlInJ, "tag" , &tmpJ); - tag = json_object_get_int(tmpJ); - } - - if (tag) { - index = halCtlTagToIndex((halCtlsEnumT) tag); - } else { - // tag was not provided let's try label - const char *label; + enum json_type jtype = json_object_get_type (ctlInJ); + switch (jtype) { + case json_type_array: + tmpJ = json_object_array_get_idx (ctlInJ, 0); + tag = json_object_get_int(tmpJ); + index = halCtlTagToIndex(tag); + break; + + case json_type_int: + tag = json_object_get_int(ctlInJ); + index = halCtlTagToIndex(tag); + break; - json_object_object_get_ex (ctlInJ, "label" , &tmpJ); - label = json_object_get_string(tmpJ); - index = halCtlStringToIndex(label); + case json_type_object: + done = json_object_object_get_ex (ctlInJ, "tag" , &tmpJ); + if (done) { + tag = json_object_get_int(tmpJ); + index = halCtlTagToIndex(tag); + } else { + const char *label; + done = json_object_object_get_ex (ctlInJ, "label" , &tmpJ); + if (!done) goto OnErrorExit; + label = json_object_get_string(tmpJ); + index = halCtlStringToIndex(label); + } + break; + + default: + goto OnErrorExit; } + - if (index < 0) { - afb_req_fail_f(request, "ctl-invalid", "No Label/Tag given ctl='%s'", json_object_get_string(ctlInJ)); - goto OnErrorExit; - } + if (index < 0) goto OnErrorExit; // return corresponding lowlevel numid to querylist return index; OnErrorExit: + afb_req_fail_f(request, "ctl-invalid", "No Label/Tag given ctl='%s'", json_object_get_string(ctlInJ)); return -1; } -// HAL normalise volume values to 0-100% -STATIC struct json_object *UnNormaliseValue(const alsaHalCtlMapT *halCtls, struct json_object *valuesJ) { - int length; - - // assert response as the right length - length = json_object_array_length(valuesJ); - if (length != halCtls->count) { - AFB_WARNING ("UnNormaliseValue invalid ctl='%s' values count=%d len=%d", halCtls->name, halCtls->count, length); - return NULL; - } - - json_object *normalisedJ= json_object_new_array(); - for (int idx=0; idx < halCtls->count; idx++) { - int value; - - // use last value in array when number of values does not match with actual ctl count - if (idx < length) { - json_object *valueJ = json_object_array_get_idx (valuesJ, idx); - value = json_object_get_int(valueJ); - - // cleanup and normalise value - if (value > halCtls->maxval) value= halCtls->maxval; - if (value < halCtls->minval) value= halCtls->minval; - - // If Integer move from 0-100% to effective value - if (halCtls->type == SND_CTL_ELEM_TYPE_INTEGER) { - value = (value * (halCtls->maxval-halCtls->minval))/100; - } - } - - // add unnormalised value into response - json_object_array_add(normalisedJ, json_object_new_int(value)); - } - - return (normalisedJ); -} - // Translate high level control to low level and call lower layer PUBLIC void halSetCtls(afb_req request) { - int err, index; + int err, done, index; struct json_object *ctlsInJ, *ctlsOutJ, *queryJ, *valuesJ, *responseJ; // get query from request ctlsInJ = afb_req_json(request); - ctlsOutJ = json_object_new_array(); switch (json_object_get_type(ctlsInJ)) { case json_type_object: { + ctlsOutJ = json_object_new_object(); + // control is in literal form {tag=xxx, label=xxx, value=xxxx} index = halGetCtlIndex (request, ctlsInJ); - if (index <=0) goto OnErrorExit; + if (index < 0) goto OnErrorExit; - err= json_object_object_get_ex (ctlsInJ, "value" , &valuesJ); - if (err) { + done= json_object_object_get_ex (ctlsInJ, "val" , &valuesJ); + if (!done) { afb_req_fail_f(request, "ctl-invalid", "No val=[val1, ...] ctl='%s'", json_object_get_string(ctlsInJ)); goto OnErrorExit; } - json_object_array_add (ctlsOutJ, json_object_new_int(halCtls[index].ctl.numid)); - json_object_array_add (ctlsOutJ, UnNormaliseValue (&halCtls[index].ctl, valuesJ)); + json_object_object_add (ctlsOutJ, "id", json_object_new_int(halCtls[index].ctl.numid)); + json_object_object_add (ctlsOutJ,"val", SetGetNormaliseVolumes (ACTION_SET, &halCtls[index].ctl, valuesJ)); break; } case json_type_array: { + ctlsOutJ = json_object_new_array(); for (int idx= 0; idx < json_object_array_length (ctlsInJ); idx++) { struct json_object *ctlInJ = json_object_array_get_idx (ctlsInJ, idx); index= halGetCtlIndex (request, ctlInJ); - if (index<=0) goto OnErrorExit; + if (index < 0) goto OnErrorExit; - err= json_object_object_get_ex (ctlInJ, "value" , &valuesJ); - if (err) { + done= json_object_object_get_ex (ctlInJ, "val" , &valuesJ); + if (!done) { afb_req_fail_f(request, "ctl-invalid", "No val=[val1, ...] ctl='%s'", json_object_get_string(ctlsInJ)); goto OnErrorExit; } // let's create alsa low level set control request - struct json_object *ctlOutJ = json_object_new_array(); - json_object_array_add (ctlOutJ, json_object_new_int(halCtls[index].ctl.numid)); - json_object_array_add (ctlOutJ, UnNormaliseValue (&halCtls[index].ctl, valuesJ)); + struct json_object *ctlOutJ = json_object_new_object(); + json_object_object_add (ctlOutJ, "id", json_object_new_int(halCtls[index].ctl.numid)); + json_object_object_add (ctlOutJ, "val", SetGetNormaliseVolumes (ACTION_SET, &halCtls[index].ctl, valuesJ)); json_object_array_add (ctlsOutJ, ctlOutJ); } @@ -225,19 +199,12 @@ PUBLIC void halSetCtls(afb_req request) { json_object_object_add(queryJ, "devid", json_object_new_string (halDevid)); json_object_object_add(queryJ, "numid", ctlsOutJ); - err= afb_service_call_sync("alsacore", "setctls", queryJ, &responseJ); + err= afb_service_call_sync("alsacore", "setctl", queryJ, &responseJ); if (err) { afb_req_fail_f(request, "subcall:alsacore/setctl", "%s", json_object_get_string(responseJ)); goto OnErrorExit; } - // Let ignore info data if any and keep on response - json_object_object_get_ex (responseJ, "response", &responseJ); - - // map back low level response to HAL ctl with normalised values - //struct json_object *halResponse = CtlSetPrepareResponse(request, responseJ); - //if (!halResponse) goto OnErrorExit; - afb_req_success (request, NULL, NULL); return; @@ -246,7 +213,7 @@ OnErrorExit: }; // Remap low level controls into HAL hight level ones -STATIC json_object *CtlGetPrepareResponse(afb_req request, struct json_object *ctlsJ) { +STATIC json_object *HalGetPrepareResponse(afb_req request, struct json_object *ctlsJ) { struct json_object *halResponseJ; // make sure return controls have a valid type @@ -264,7 +231,7 @@ STATIC json_object *CtlGetPrepareResponse(afb_req request, struct json_object *c int numid; sndCtlJ = json_object_array_get_idx(ctlsJ, idx); - if (!json_object_object_get_ex(sndCtlJ, "numid", &numidJ) || !json_object_object_get_ex(sndCtlJ, "val", &valJ)) { + if (!json_object_object_get_ex(sndCtlJ, "id", &numidJ) || !json_object_object_get_ex(sndCtlJ, "val", &valJ)) { afb_req_fail_f(request, "ctl-invalid", "Invalid Control return from alsa/getcontrol ctl=%s", json_object_get_string(sndCtlJ)); goto OnErrorExit; } @@ -279,7 +246,7 @@ STATIC json_object *CtlGetPrepareResponse(afb_req request, struct json_object *c struct json_object *halCtlJ = json_object_new_object(); json_object_object_add(halCtlJ, "label", json_object_new_string(halCtls[idx].label)); // idx+1 == HAL/NUMID json_object_object_add(halCtlJ, "tag" , json_object_new_int(halCtls[idx].tag)); // idx+1 == HAL/NUMID - json_object_object_add(halCtlJ, "val" , GetNormaliseVolume(&halCtls[idx].ctl, valJ)); + json_object_object_add(halCtlJ, "val" , SetGetNormaliseVolumes(ACTION_GET, &halCtls[idx].ctl, valJ)); json_object_array_add(halResponseJ, halCtlJ); break; } @@ -308,7 +275,7 @@ PUBLIC void halGetCtls(afb_req request) { case json_type_object: { index = halGetCtlIndex (request, ctlsInJ); - if (index <=0) goto OnErrorExit; + if (index < 0) goto OnErrorExit; json_object_array_add (ctlsOutJ, json_object_new_int(halCtls[index].ctl.numid)); break; } @@ -318,7 +285,7 @@ PUBLIC void halGetCtls(afb_req request) { for (int idx= 0; idx < json_object_array_length (ctlsInJ); idx++) { struct json_object *ctlInJ = json_object_array_get_idx (ctlsInJ, idx); index= halGetCtlIndex (request, ctlInJ); - if (index<=0) goto OnErrorExit; + if (index < 0) goto OnErrorExit; json_object_array_add (ctlsOutJ, json_object_new_int(halCtls[index].ctl.numid)); } break; @@ -344,7 +311,7 @@ PUBLIC void halGetCtls(afb_req request) { json_object_object_get_ex (responseJ, "response", &responseJ); // map back low level response to HAL ctl with normalised values - struct json_object *halResponse = CtlGetPrepareResponse(request, responseJ); + struct json_object *halResponse = HalGetPrepareResponse(request, responseJ); if (!halResponse) goto OnErrorExit; afb_req_success (request, halResponse, NULL); @@ -361,7 +328,7 @@ PUBLIC void halServiceEvent(const char *evtname, struct json_object *eventJ) { AFB_NOTICE("halServiceEvent evtname=%s [msg=%s]", evtname, json_object_get_string(eventJ)); - json_object_object_get_ex (eventJ, "values" , &valuesJ); + json_object_object_get_ex (eventJ, "val" , &valuesJ); if (!valuesJ) { AFB_ERROR("halServiceEvent novalues: evtname=%s [msg=%s]", evtname, json_object_get_string(eventJ)); return; @@ -387,7 +354,7 @@ STATIC int UpdateOneSndCtl (alsaHalCtlMapT *ctl, struct json_object *sndCtlJ) { json_object_object_get_ex (sndCtlJ, "name" , &tmpJ); ctl->name = (char*)json_object_get_string(tmpJ); - json_object_object_get_ex (sndCtlJ, "numid" , &tmpJ); + json_object_object_get_ex (sndCtlJ, "id" , &tmpJ); ctl->numid = json_object_get_int(tmpJ); // make sure we face a valid Alsa Low level ctl @@ -547,6 +514,7 @@ PUBLIC afb_verb_v2 halServiceApi[] = { { .verb = "ping", .callback = pingtest}, { .verb = "ctl-list", .callback = halListCtls}, { .verb = "ctl-get", .callback = halGetCtls}, + { .verb = "ctl-set", .callback = halSetCtls}, { .verb = "evt-sub", .callback = halSubscribe}, { .verb = NULL} /* marker for end of the array */ }; diff --git a/HAL-afb/HAL-interface/hal-interface.h b/HAL-afb/HAL-interface/hal-interface.h index afe480e..c31c145 100644 --- a/HAL-afb/HAL-interface/hal-interface.h +++ b/HAL-afb/HAL-interface/hal-interface.h @@ -23,6 +23,11 @@ #include "audio-interface.h" +typedef enum { + ACTION_SET, + ACTION_GET +} ActionSetGetT; + typedef struct { int min; int max; @@ -69,7 +74,7 @@ PUBLIC void halServiceEvent(const char *evtname, struct json_object *object); PUBLIC int halServiceInit (const char *apiPrefix, alsaHalSndCardT *alsaHalSndCard); // hal-volmap.c -PUBLIC struct json_object *GetNormaliseVolume(const alsaHalCtlMapT *halCtls, struct json_object *valuesJ); +PUBLIC struct json_object *SetGetNormaliseVolumes(ActionSetGetT action, const alsaHalCtlMapT *halCtls, struct json_object *valuesJ); #endif /* SHAREHALLIB_H */ diff --git a/HAL-afb/HAL-interface/hal-volmap.c b/HAL-afb/HAL-interface/hal-volmap.c index de99974..2b619fd 100644 --- a/HAL-afb/HAL-interface/hal-volmap.c +++ b/HAL-afb/HAL-interface/hal-volmap.c @@ -24,26 +24,30 @@ typedef enum { - DB_NORMALIZE_LINEAR, - DB_NORMALIZE_MATH, + NORMALIZE_NONE=0, + NORMALIZE_DB_LINEAR, + NORMALIZE_DB_MATH, + NORMALIZE_LINEAR, } enumRandeModeDB_T; + // Return Value express from 0-100% STATIC int dbNormalizeVal (enumRandeModeDB_T normaliseMode, const alsaHalDBscaleT *dbscale, int value) { double normalized, min_norm; - + // To get real DB from TLV DB values should be divided by 100 switch (normaliseMode) { - case DB_NORMALIZE_LINEAR: - normalized = ((double)(value-dbscale->min)/(double)(dbscale->max-dbscale->min))*100; + case NORMALIZE_DB_LINEAR: + normalized = ((double)(value-dbscale->min)/(double)(dbscale->max-dbscale->min)); break; - case DB_NORMALIZE_MATH: + case NORMALIZE_DB_MATH: normalized = exp10((double)(value - dbscale->max) / 6000.0); if (dbscale->min != SND_CTL_TLV_DB_GAIN_MUTE) { - min_norm = exp10((double)(dbscale->min - dbscale->max) / 6000.0); + min_norm = exp10((double)(dbscale->min - dbscale->max) / 20); normalized = (normalized - min_norm) / (1 - min_norm); } + break; default: @@ -54,35 +58,82 @@ STATIC int dbNormalizeVal (enumRandeModeDB_T normaliseMode, const alsaHalDBscale } // HAL normalise volume values to 0-100% -PUBLIC struct json_object *GetNormaliseVolume(const alsaHalCtlMapT *halCtls, struct json_object *valuesJ) { - int useNormalizeDB; +PUBLIC struct json_object *SetGetNormaliseVolumes(ActionSetGetT action, const alsaHalCtlMapT *halCtls, struct json_object *valuesJ) { + enumRandeModeDB_T useNormalizeDB; + int length; + + // If Integer look for DBscale + if (halCtls->type == SND_CTL_ELEM_TYPE_INTEGER) { - // If not valid db_scale let's use raw_scale - if (!halCtls->dbscale || (halCtls->dbscale->min >= halCtls->dbscale->max)) { + // If not valid db_scale let's use raw_scale + if (!halCtls->dbscale || (halCtls->dbscale->min >= halCtls->dbscale->max)) { // dbscale is invalid let's try raw range if (halCtls->minval >= halCtls->maxval) goto ExitOnError; // Use Raw Scale Model - useNormalizeDB= 0; + useNormalizeDB= NORMALIZE_LINEAR; - } else { // db_scale looks OK let's use it - if ((halCtls->dbscale->max - halCtls->dbscale->min) <= MAX_LINEAR_DB_SCALE * 100) useNormalizeDB= DB_NORMALIZE_LINEAR; - else useNormalizeDB = DB_NORMALIZE_MATH; - - } + } else { // db_scale looks OK let's use it + if ((halCtls->dbscale->max - halCtls->dbscale->min) <= MAX_LINEAR_DB_SCALE * 100) useNormalizeDB= NORMALIZE_DB_LINEAR; + else useNormalizeDB = NORMALIZE_LINEAR; // Fulup not sure how to handle this useNormalizeDB=NORMALIZE_DB_MATH; + } + } else useNormalizeDB= NORMALIZE_NONE; + // loop on values to normalise - int length = json_object_array_length(valuesJ); + enum json_type jtype=json_object_get_type(valuesJ); + if (jtype == json_type_array) length = json_object_array_length(valuesJ); + else length = 1; + json_object *normalisedJ= json_object_new_array(); - for (int idx=0; idx type == SND_CTL_ELEM_TYPE_INTEGER) { - if (useNormalizeDB) value = dbNormalizeVal (useNormalizeDB, halCtls->dbscale, value); - else value = 100* (value - halCtls->minval) / (halCtls->maxval - halCtls->minval); + + switch (action) { + + case ACTION_GET: + switch (useNormalizeDB) { + case NORMALIZE_LINEAR: + value = 100* (value - halCtls->minval) / (halCtls->maxval - halCtls->minval); + break; + case NORMALIZE_DB_MATH: //ToBeDone + value = dbNormalizeVal (useNormalizeDB, halCtls->dbscale, value); + break; + case NORMALIZE_NONE: + default: + value = value; + } + break; + + case ACTION_SET: + switch (useNormalizeDB) { + case NORMALIZE_LINEAR: + value = (value * (halCtls->maxval - halCtls->minval))/100; + break; + case NORMALIZE_DB_MATH: //ToBeDone + value = dbNormalizeVal (useNormalizeDB, halCtls->dbscale, value); + break; + case NORMALIZE_NONE: + default: + value = value; + } + break; + + default: + AFB_NOTICE ("SetGetNormaliseVolumes: invalid action value=%d", (int)action); + goto ExitOnError; + } } json_object_array_add(normalisedJ, json_object_new_int(value)); diff --git a/HAL-afb/Scarlett-Focusrite/ScarlettUsbHAL.c b/HAL-afb/Scarlett-Focusrite/ScarlettUsbHAL.c index cc62be1..10ef204 100644 --- a/HAL-afb/Scarlett-Focusrite/ScarlettUsbHAL.c +++ b/HAL-afb/Scarlett-Focusrite/ScarlettUsbHAL.c @@ -19,6 +19,7 @@ * aplay -l # Check sndcard name name in between [] * amixer -D hw:USB controls # get supported controls * amixer -Dhw:USB cget name=Power-Switch + * amixer -Dhw:USB cset name=Power-Switch true * */ #define _GNU_SOURCE diff --git a/Shared-Interface/audio-interface.c b/Shared-Interface/audio-interface.c index edaaf7f..b4750ae 100644 --- a/Shared-Interface/audio-interface.c +++ b/Shared-Interface/audio-interface.c @@ -23,34 +23,6 @@ #include "audio-interface.h" -typedef struct { - int index; - int numid; -} shareHallMap_T; - - -PUBLIC int cbCheckResponse(struct afb_req request, int iserror, struct json_object *result) { - struct json_object *response, *status, *info; - - if (iserror) { // on error proxy information we got from lower layer - if (result) { - if (json_object_object_get_ex(result, "request", &response)) { - json_object_object_get_ex(response, "info", &info); - json_object_object_get_ex(response, "status", &status); - afb_req_fail(request, json_object_get_string(status), json_object_get_string(info)); - goto OnErrorExit; - } - } else { - afb_req_fail(request, "cbCheckFail", "No Result inside API response"); - } - goto OnErrorExit; - } - return (0); - -OnErrorExit: - return (-1); -} - PUBLIC void pingtest(struct afb_req request) { json_object *query = afb_req_json(request); diff --git a/Shared-Interface/audio-interface.h b/Shared-Interface/audio-interface.h index 09cb6c2..01c71cd 100644 --- a/Shared-Interface/audio-interface.h +++ b/Shared-Interface/audio-interface.h @@ -62,19 +62,18 @@ typedef enum { typedef enum { StartHalCrlTag=0, - // HighLevel Audio Control List - Master_Playback_Volume, - Master_OnOff_Switch, - Master_Playback_Ramp, - PCM_Playback_Volume, - PCM_Playback_Switch, - Capture_Volume, + // HighLevel Audio Control List, + Master_Playback_Volume =1, + Master_Playback_Ramp =2, + PCM_Playback_Volume =3, + PCM_Playback_Switch =4, + Capture_Volume =5, + Master_OnOff_Switch =6, EndHalCrlTag // used to compute number of ctls } halCtlsEnumT; -PUBLIC int cbCheckResponse(struct afb_req request, int iserror, struct json_object *result) ; PUBLIC void pingtest(struct afb_req request); #endif /* AUDIO_INTERF_H */ diff --git a/conf.d/cmake/config.cmake b/conf.d/cmake/config.cmake index 97c4986..e7801c8 100644 --- a/conf.d/cmake/config.cmake +++ b/conf.d/cmake/config.cmake @@ -45,6 +45,7 @@ set(CMAKE_BUILD_TYPE "DEBUG") # ----------------------------- add_compile_options(-DMAX_SND_CARD=16) # should be more than enough even in luxury vehicule add_compile_options(-DMAX_LINEAR_DB_SCALE=24) # until 24db volume normalisation use a simple linear scale +add_compile_options(-DTLV_BYTE_SIZE=256) # Alsa use 4096 as default but 256 should fit most sndcards # Compiler selection if needed. Overload the detected compiler. # ----------------------------------------------- diff --git a/htdocs/AudioBinding.js b/htdocs/AudioBinding.js index e000a70..607d31c 100644 --- a/htdocs/AudioBinding.js +++ b/htdocs/AudioBinding.js @@ -2,6 +2,7 @@ var ws; var sndcard="HALNotSelected"; var evtidx=0; + var numid=0; function syntaxHighlight(json) { if (typeof json !== 'string') { @@ -48,31 +49,10 @@ if (!sndname) sndname="PCH"; var mode=getParameterByName("mode"); - if (!mode) mode="99"; + if (!mode) mode="0"; - function init(elemid, api, verb, query) { - - function onopen() { - // check for active HALs - probeActiveHal (elemid, api, verb, query); - - document.getElementById("main").style.visibility = "visible"; - document.getElementById("connected").innerHTML = "Binder WS Active"; - document.getElementById("connected").style.background = "lightgreen"; - ws.onevent("*", gotevent); - } - - function onabort() { - document.getElementById("main").style.visibility = "hidden"; - document.getElementById("connected").innerHTML = "Connected Closed"; - document.getElementById("connected").style.background = "red"; - - } - - ws = new afb.ws(onopen, onabort); - } function replyok(obj) { console.log("replyok:" + JSON.stringify(obj)); @@ -106,9 +86,17 @@ } - // Retrieve the list of active HAL - function probeActiveHal (elemid, api, verb, query) { + // Retreive Select value and Text from the binder + // Note: selection of value/text for a given context is huggly!!! + function querySelectList (elemid, api, verb, query) { + + console.log("querySelectList elemid=%s api=%s verb=%s query=%s", elemid, api, verb, query); + var selectobj = document.getElementById(elemid); + if (!selectobj) { + console.log ("****** elemid=%s does not exit in HTML page ****", elemid); + return; + } // onlick update selected HAL api selectobj.onclick=function(){ @@ -139,12 +127,72 @@ sndcard= selectobj.value; } - - console.log ("subscribe api="+api+" verb="+verb+" query=" +query); - + + var question = urlws +"/"+api +"/" +verb + "?query=" + JSON.stringify(query); + document.getElementById("question").innerHTML = syntaxHighlight(question); + + // request lowlevel ALSA to get API list + ws.call(api+"/"+verb, query).then(gotit, replyerr); + } + + function refresh_list (self, api, verb, query) { + console.log("refresh_list id=%s api=%s verb=%s query=%s", self.id, api, verb, query); + + if (self.value > 0) return; + + // onlick update selected HAL api + self.onclick=function(){ + numid = parseInt(self.value); + console.log ("Default numid=%d", numid); + }; + + function gotit (result) { + + // display response as for normal onclick action + replyok(result); + var response=result.response; + + + + // fulfill select with avaliable active HAL + for (idx=0; idx + - references - +

Selected SndCard + + Select NUMID + API Verbosity -
- + + +
  1. -
  2. -
  3. -
  4. -
    -
  5. -
  6. -
  7. -
  8. -
  9. +
  10. +
  11. +
    + + +
  12. +
  13. +
  14. +
  15. +

  16. diff --git a/htdocs/alsa-hal.html b/htdocs/alsa-hal.html index 7a8655c..7377bd4 100644 --- a/htdocs/alsa-hal.html +++ b/htdocs/alsa-hal.html @@ -27,15 +27,15 @@
      -
    1. +

    2. -
    3. -
    4. -
    5. -
    6. +
    7. +
    8. +
    9. +

    diff --git a/nbproject/configurations.xml b/nbproject/configurations.xml index 18d1e63..938c355 100644 --- a/nbproject/configurations.xml +++ b/nbproject/configurations.xml @@ -107,6 +107,8 @@ + ../../../opt/include/afb + ALSA-afb ../../../opt/include/alsa /usr/include/json-c Shared-Interface @@ -118,6 +120,8 @@ + ../../../opt/include/afb + ALSA-afb build/ALSA-afb @@ -125,6 +129,8 @@ + ../../../opt/include/afb + ALSA-afb ../../../opt/include/alsa /usr/include/json-c Shared-Interface @@ -134,19 +140,30 @@ - + + ../../../opt/include ../../../opt/include/alsa + /usr/include/p11-kit-1 /usr/include/json-c Shared-Interface - ../../../opt/include build/ALSA-afb + + CONTROL_CDEV_RX="/dev/inic-usb-crx" + CONTROL_CDEV_TX="/dev/inic-usb-ctx" + MAX_LINEAR_DB_SCALE=24 + MAX_SND_CARD=16 + TLV_BYTE_SIZE=256 + alsa_lowlevel_EXPORTS + + ../../../opt/include/afb + ALSA-afb ../../../opt/include/alsa /usr/include/json-c Shared-Interface @@ -163,28 +180,17 @@ ex="false" tool="0" flavor2="3"> - + - ../../../opt/include/afb - ../../../opt/include - ../../../opt/include/alsa - /usr/include/p11-kit-1 - /usr/include/json-c - HAL-afb/HAL-interface Shared-Interface + ../../../opt/include build/HAL-afb/HAL-interface - + - ../../../opt/include - ../../../opt/include/alsa - /usr/include/p11-kit-1 - /usr/include/json-c - HAL-afb/HAL-interface - Shared-Interface build/HAL-afb/HAL-interface @@ -298,14 +304,6 @@ - - - - ../../../opt/include/afb - ALSA-afb - - - @@ -335,9 +333,11 @@ - - MAX_LINEAR_DB_SCALE=24 - + + HAL-afb/HAL-interface + ../../../opt/include/alsa + /usr/include/json-c + -- cgit 1.2.3-korg