diff options
Diffstat (limited to 'ALSA-afb')
-rw-r--r-- | ALSA-afb/Alsa-RegEvt.c | 60 | ||||
-rw-r--r-- | ALSA-afb/Alsa-SetGet.c | 2 | ||||
-rw-r--r-- | ALSA-afb/CMakeLists.txt | 8 |
3 files changed, 49 insertions, 21 deletions
diff --git a/ALSA-afb/Alsa-RegEvt.c b/ALSA-afb/Alsa-RegEvt.c index 61885f7..6344e2d 100644 --- a/ALSA-afb/Alsa-RegEvt.c +++ b/ALSA-afb/Alsa-RegEvt.c @@ -36,8 +36,10 @@ typedef struct { } sndHandleT; typedef struct { + char *devid; char *apiprefix; - char *shortname; + char *shortname; + char *longname; }cardRegistryT; cardRegistryT *cardRegistry[MAX_SND_CARD+1]; @@ -111,7 +113,7 @@ STATIC int sndCtlEventCB (sd_event_source* src, int fd, uint32_t revents, void* // Subscribe to every Alsa CtlEvent send by a given board PUBLIC void alsaEvtSubcribe (afb_req request) { static sndHandleT sndHandles[MAX_SND_CARD]; - evtHandleT *evtHandle; + evtHandleT *evtHandle=NULL; snd_ctl_t *ctlDev=NULL; int err, idx, cardId, idxFree=-1; snd_ctl_card_info_t *cardinfo; @@ -207,7 +209,7 @@ PUBLIC void alsaEvtSubcribe (afb_req request) { } // Subscribe to every Alsa CtlEvent send by a given board -PUBLIC void alsaGetCardId (afb_req request) { +STATIC json_object *alsaProbeCardId (afb_req request) { char devid [10]; const char *devname, *shortname, *longname; int card, err, index, idx; @@ -265,11 +267,17 @@ PUBLIC void alsaGetCardId (afb_req request) { } } - afb_req_success(request, responseJ, NULL); - return; + return responseJ; - OnErrorExit: - return; + OnErrorExit: + return NULL; +} + +// Make alsaProbeCardId compatible with AFB request +PUBLIC void alsaGetCardId (afb_req request) { + + json_object *responseJ = alsaProbeCardId (request); + if (responseJ) afb_req_success(request, responseJ, NULL); } // Return list of active resgistrated HAL with corresponding sndcard @@ -281,7 +289,9 @@ PUBLIC void alsaActiveHal (afb_req request) { json_object *haldevJ = json_object_new_object(); json_object_object_add(haldevJ, "api", json_object_new_string(cardRegistry[idx]->apiprefix)); - json_object_object_add(haldevJ, "devid", json_object_new_string(cardRegistry[idx]->shortname)); + if (cardRegistry[idx]->devid) json_object_object_add(haldevJ, "devid", json_object_new_string(cardRegistry[idx]->devid)); + if (cardRegistry[idx]->shortname)json_object_object_add(haldevJ, "shortname", json_object_new_string(cardRegistry[idx]->shortname)); + if (cardRegistry[idx]->longname) json_object_object_add(haldevJ, "longname", json_object_new_string(cardRegistry[idx]->longname)); json_object_array_add (responseJ, haldevJ); } @@ -292,6 +302,7 @@ PUBLIC void alsaActiveHal (afb_req request) { // Register loaded HAL with board Name and API prefix PUBLIC void alsaRegisterHal (afb_req request) { static int index=0; + json_object *responseJ; const char *shortname, *apiPrefix; apiPrefix = afb_req_value(request, "prefix"); @@ -310,15 +321,32 @@ PUBLIC void alsaRegisterHal (afb_req request) { afb_req_fail_f (request, "alsahal-toomany", "Fail to register sndname=[%s]", shortname); goto OnErrorExit; } - + // alsaGetCardId should be check to register only valid card - cardRegistry[index]= malloc (sizeof(cardRegistry)); - cardRegistry[index]->apiprefix=strdup(apiPrefix); - cardRegistry[index]->shortname=strdup(shortname); - index++;cardRegistry[index]=NULL; - - alsaGetCardId(request); - + responseJ= alsaProbeCardId(request); + if (responseJ) { + json_object *tmpJ; + int done; + + cardRegistry[index]= malloc (sizeof(cardRegistry)); + cardRegistry[index]->apiprefix=strdup(apiPrefix); + cardRegistry[index]->shortname=strdup(shortname); + + done= json_object_object_get_ex (responseJ, "devid" , &tmpJ); + if (done) cardRegistry[index]->devid = strdup (json_object_get_string(tmpJ)); + else cardRegistry[index]->devid=NULL; + + done = json_object_object_get_ex (responseJ, "longname" , &tmpJ); + if (done) cardRegistry[index]->longname = strdup (json_object_get_string(tmpJ)); + else cardRegistry[index]->longname=NULL; + + // make sure register close with a null value + index++; + cardRegistry[index]=NULL; + + afb_req_success(request, responseJ, NULL); + } + // If OK return sound card Alsa ID+Info return; diff --git a/ALSA-afb/Alsa-SetGet.c b/ALSA-afb/Alsa-SetGet.c index 56dc32f..31406f3 100644 --- a/ALSA-afb/Alsa-SetGet.c +++ b/ALSA-afb/Alsa-SetGet.c @@ -448,7 +448,7 @@ STATIC json_object *getControlAcl (snd_ctl_elem_info_t *info) { PUBLIC int alsaSetSingleCtl (snd_ctl_t *ctlDev, snd_ctl_elem_id_t *elemId, ctlRequestT *ctlRequest) { snd_ctl_elem_value_t *elemData; snd_ctl_elem_info_t *elemInfo; - int count, length, err, valueIsArray; + int count, length, err, valueIsArray=0; // let's make sure we are processing the right control if (ctlRequest->numId != snd_ctl_elem_id_get_numid (elemId)) goto OnErrorExit; diff --git a/ALSA-afb/CMakeLists.txt b/ALSA-afb/CMakeLists.txt index 4ca7158..443acbd 100644 --- a/ALSA-afb/CMakeLists.txt +++ b/ALSA-afb/CMakeLists.txt @@ -20,10 +20,10 @@ PROJECT_TARGET_ADD(alsa-lowlevel) # Define project Targets - ADD_LIBRARY(alsa-lowlevel MODULE Alsa-ApiHat.c Alsa-SetGet.c Alsa-Ucm.c Alsa-AddCtl.c Alsa-RegEvt.c) + ADD_LIBRARY(${TARGET_NAME} MODULE Alsa-ApiHat.c Alsa-SetGet.c Alsa-Ucm.c Alsa-AddCtl.c Alsa-RegEvt.c) # Binder exposes a unique public entry point - SET_TARGET_PROPERTIES(alsa-lowlevel PROPERTIES + SET_TARGET_PROPERTIES(${TARGET_NAME} PROPERTIES PREFIX "afb-" LABELS "BINDING" LINK_FLAGS ${BINDINGS_LINK_FLAG} @@ -31,11 +31,11 @@ PROJECT_TARGET_ADD(alsa-lowlevel) ) # Library dependencies (include updates automatically) - TARGET_LINK_LIBRARIES(alsa-lowlevel + TARGET_LINK_LIBRARIES(${TARGET_NAME} audio-interface ${link_libraries} ) # installation directory - INSTALL(TARGETS alsa-lowlevel + INSTALL(TARGETS ${TARGET_NAME} LIBRARY DESTINATION ${BINDINGS_INSTALL_DIR}) |