summaryrefslogtreecommitdiffstats
path: root/ALSA-afb
diff options
context:
space:
mode:
Diffstat (limited to 'ALSA-afb')
-rw-r--r--ALSA-afb/Alsa-AddCtl.c252
-rw-r--r--ALSA-afb/Alsa-ApiHat.c3
-rw-r--r--ALSA-afb/Alsa-ApiHat.h1
-rw-r--r--ALSA-afb/Alsa-RegEvt.c55
-rw-r--r--ALSA-afb/Alsa-SetGet.c16
-rw-r--r--ALSA-afb/Alsa-Ucm.c14
6 files changed, 169 insertions, 172 deletions
diff --git a/ALSA-afb/Alsa-AddCtl.c b/ALSA-afb/Alsa-AddCtl.c
index 5754c15..25e2a31 100644
--- a/ALSA-afb/Alsa-AddCtl.c
+++ b/ALSA-afb/Alsa-AddCtl.c
@@ -22,154 +22,92 @@
#define _GNU_SOURCE // needed for vasprintf
#include <alsa/asoundlib.h>
+#include <alsa/sound/tlv.h>
#include <systemd/sd-event.h>
-#include "Alsa-ApiHat.h"
-
#include <sys/ioctl.h>
-typedef struct _snd_ctl_ops {
- int (*close)(snd_ctl_t *handle);
- int (*nonblock)(snd_ctl_t *handle, int nonblock);
- int (*async)(snd_ctl_t *handle, int sig, pid_t pid);
- int (*subscribe_events)(snd_ctl_t *handle, int subscribe);
- int (*card_info)(snd_ctl_t *handle, snd_ctl_card_info_t *info);
- int (*element_list)(snd_ctl_t *handle, snd_ctl_elem_list_t *list);
- int (*element_info)(snd_ctl_t *handle, snd_ctl_elem_info_t *info);
- int (*element_add)(snd_ctl_t *handle, snd_ctl_elem_info_t *info);
- int (*element_replace)(snd_ctl_t *handle, snd_ctl_elem_info_t *info);
- int (*element_remove)(snd_ctl_t *handle, snd_ctl_elem_id_t *id);
- int (*element_read)(snd_ctl_t *handle, snd_ctl_elem_value_t *control);
- int (*element_write)(snd_ctl_t *handle, snd_ctl_elem_value_t *control);
- int (*element_lock)(snd_ctl_t *handle, snd_ctl_elem_id_t *lock);
- int (*element_unlock)(snd_ctl_t *handle, snd_ctl_elem_id_t *unlock);
- int (*element_tlv)(snd_ctl_t *handle, int op_flag, unsigned int numid,
- unsigned int *tlv, unsigned int tlv_size);
- int (*hwdep_next_device)(snd_ctl_t *handle, int *device);
- int (*hwdep_info)(snd_ctl_t *handle, snd_hwdep_info_t * info);
- int (*pcm_next_device)(snd_ctl_t *handle, int *device);
- int (*pcm_info)(snd_ctl_t *handle, snd_pcm_info_t * info);
- int (*pcm_prefer_subdevice)(snd_ctl_t *handle, int subdev);
- int (*rawmidi_next_device)(snd_ctl_t *handle, int *device);
- int (*rawmidi_info)(snd_ctl_t *handle, snd_rawmidi_info_t * info);
- int (*rawmidi_prefer_subdevice)(snd_ctl_t *handle, int subdev);
- int (*set_power_state)(snd_ctl_t *handle, unsigned int state);
- int (*get_power_state)(snd_ctl_t *handle, unsigned int *state);
- int (*read)(snd_ctl_t *handle, snd_ctl_event_t *event);
- int (*poll_descriptors_count)(snd_ctl_t *handle);
- int (*poll_descriptors)(snd_ctl_t *handle, struct pollfd *pfds, unsigned int space);
- int (*poll_revents)(snd_ctl_t *handle, struct pollfd *pfds, unsigned int nfds, unsigned short *revents);
-} snd_ctl_ops_t;
-
-typedef struct private_snd_ctl {
- void *open_func;
- char *name;
- snd_ctl_type_t type;
- const snd_ctl_ops_t *ops;
- void *private_data;
- int nonblock;
- int poll_fd;
- void *async_handlers;
-} private_snd_ctl_t;
-
-typedef struct {
- int card;
- int fd;
- unsigned int protocol;
-} snd_ctl_hw_t;
+#include "Alsa-ApiHat.h"
-static int snd_ctl_hw_elem_replace(snd_ctl_t *ctlDev, snd_ctl_elem_info_t *info, snd_ctl_elem_id_t *elemId) {
- size_t len=snd_ctl_elem_info_sizeof();
- private_snd_ctl_t *handle= (private_snd_ctl_t*) ctlDev;
- snd_ctl_hw_t *hw = handle->private_data;
-
- NOTICE ("count=%d ITEMNAME=%s writable=%d owner=%d", snd_ctl_elem_info_get_count(info), snd_ctl_elem_info_get_name(info)
- , snd_ctl_elem_info_is_writable(info), snd_ctl_elem_info_get_owner(info));
- snd_ctl_elem_lock(ctlDev, elemId);
-
- int err= handle->ops->element_replace (ctlDev, info);
- NOTICE ("count=%d ITEMNAME=%s writable=%d isowner=%d islocked=%d innactiv=%d", snd_ctl_elem_info_get_count(info), snd_ctl_elem_info_get_name(info)
- , snd_ctl_elem_info_is_writable(info), snd_ctl_elem_info_is_owner(info), snd_ctl_elem_info_is_locked(info), snd_ctl_elem_info_is_inactive(info));
- return err;
+// Performs like a toggle switch for attenuation, because they're bool (ref:user-ctl-element-set.c)
+static const unsigned int *allocate_bool_elem_set_tlv (void) {
+ static const SNDRV_CTL_TLVD_DECLARE_DB_MINMAX(range, -10000, 0);
+ unsigned int *tlv= malloc(sizeof(range));
+ if (tlv == NULL) return NULL;
+ memcpy(tlv, range, sizeof(range));
+ return tlv;
}
-
-STATIC int addOneSndCtl(afb_req request, snd_ctl_t *ctlDev, json_object *ctlJ) {
- int err, ctlExist;
- json_object *jTmp;
+STATIC json_object * addOneSndCtl(afb_req request, snd_ctl_t *ctlDev, json_object *ctlJ) {
+ int err, ctlNumid;
+ json_object *tmpJ;
+ ctlRequestT ctlRequest;
const char *ctlName;
- int ctlNumid, ctlMax, ctlMin, ctlStep, ctlCount, ctlSubDev, ctlSndDev;
+ int ctlMax, ctlMin, ctlStep, ctlCount, ctlSubDev, ctlSndDev;
snd_ctl_elem_type_t ctlType;
- snd_ctl_elem_id_t *elemId;
snd_ctl_elem_info_t *elemInfo;
+ snd_ctl_elem_id_t *elemId;
snd_ctl_elem_value_t *elemValue;
+ const unsigned int *elemTlv=NULL;
// parse json ctl object
- json_object_object_get_ex (ctlJ, "name" , &jTmp);
- if (!jTmp) {
- afb_req_fail_f (request, "ctl-invalid", "crl=%s name missing", json_object_get_string(ctlJ));
+ json_object_object_get_ex (ctlJ, "name" , &tmpJ);
+ ctlName = json_object_get_string(tmpJ);
+
+ json_object_object_get_ex (ctlJ, "numid" , &tmpJ);
+ ctlNumid = json_object_get_int(tmpJ);
+
+ if (!ctlNumid && !ctlName) {
+ afb_req_fail_f (request, "ctl-invalid", "crl=%s name or numid missing", json_object_get_string(ctlJ));
goto OnErrorExit;
- }
- ctlName = json_object_get_string(jTmp);
+ }
+
+ // Assert that this ctls is not used
+ snd_ctl_elem_info_alloca(&elemInfo);
+ if (ctlName) snd_ctl_elem_info_set_name (elemInfo, ctlName);
+ if (ctlNumid)snd_ctl_elem_info_set_numid(elemInfo, ctlNumid);
+ snd_ctl_elem_info_set_interface (elemInfo, SND_CTL_ELEM_IFACE_MIXER);
+ err = snd_ctl_elem_info(ctlDev, elemInfo);
+ if (!err) {
+ AFB_NOTICE ("ctlName=%s numid=%d already exit", snd_ctl_elem_info_get_name(elemInfo), snd_ctl_elem_info_get_numid(elemInfo));
+ snd_ctl_elem_id_alloca(&elemId);
+ snd_ctl_elem_info_get_id(elemInfo, elemId);
+ goto OnSucessExit;
+ }
- // default value when not present => 0
- json_object_object_get_ex (ctlJ, "numid" , &jTmp);
- ctlNumid = json_object_get_int(jTmp);
-
// default for json_object_get_int is zero
- json_object_object_get_ex (ctlJ, "min" , &jTmp);
- ctlMin = json_object_get_int(jTmp);
+ json_object_object_get_ex (ctlJ, "min" , &tmpJ);
+ ctlMin = json_object_get_int(tmpJ);
- json_object_object_get_ex (ctlJ, "max" , &jTmp);
- if (!jTmp) ctlMax=1;
- else ctlMax = json_object_get_int(jTmp);
+ json_object_object_get_ex (ctlJ, "max" , &tmpJ);
+ if (!tmpJ) ctlMax=1;
+ else ctlMax = json_object_get_int(tmpJ);
- json_object_object_get_ex (ctlJ, "step" , &jTmp);
- if (!jTmp) ctlStep=1;
- else ctlStep = json_object_get_int(jTmp);
+ json_object_object_get_ex (ctlJ, "step" , &tmpJ);
+ if (!tmpJ) ctlStep=1;
+ else ctlStep = json_object_get_int(tmpJ);
- json_object_object_get_ex (ctlJ, "count" , &jTmp);
- if (!jTmp) ctlCount=2;
- else ctlCount = json_object_get_int(jTmp);
+ json_object_object_get_ex (ctlJ, "count" , &tmpJ);
+ if (!tmpJ) ctlCount=2;
+ else ctlCount = json_object_get_int(tmpJ);
- json_object_object_get_ex (ctlJ, "snddev" , &jTmp);
- ctlSndDev = json_object_get_int(jTmp);
+ json_object_object_get_ex (ctlJ, "snddev" , &tmpJ);
+ ctlSndDev = json_object_get_int(tmpJ);
- json_object_object_get_ex (ctlJ, "subdev" , &jTmp);
- ctlSubDev = json_object_get_int(jTmp);
+ json_object_object_get_ex (ctlJ, "subdev" , &tmpJ);
+ ctlSubDev = json_object_get_int(tmpJ);
- json_object_object_get_ex (ctlJ, "type" , &jTmp);
- if (!jTmp) ctlType=SND_CTL_ELEM_TYPE_BOOLEAN;
- else ctlType = json_object_get_int(jTmp);
+ json_object_object_get_ex (ctlJ, "type" , &tmpJ);
+ if (!tmpJ) ctlType=SND_CTL_ELEM_TYPE_BOOLEAN;
+ else ctlType = json_object_get_int(tmpJ);
// Add requested ID into elemInfo
- snd_ctl_elem_info_alloca(&elemInfo);
- snd_ctl_elem_id_alloca(&elemId);
- snd_ctl_elem_id_set_numid (elemId, ctlNumid);
- snd_ctl_elem_id_set_name (elemId, ctlName);
- snd_ctl_elem_id_set_interface(elemId, SND_CTL_ELEM_IFACE_HWDEP);
- snd_ctl_elem_id_set_device(elemId, ctlSndDev);
- snd_ctl_elem_id_set_subdevice(elemId, ctlSubDev);
-
- // Assert that this ctls is not used
- snd_ctl_elem_info_set_id (elemInfo, elemId);
- ctlExist= !snd_ctl_elem_info(ctlDev, elemInfo);
- if (ctlExist) {
- NOTICE ("1:ctl exist ctlName=%s NUMID=%d NAME=%s", ctlName, snd_ctl_elem_info_get_numid(elemInfo), snd_ctl_elem_info_get_name(elemInfo));
- snd_ctl_elem_id_set_name (elemId, ctlName);
- snd_ctl_elem_info_set_name (elemInfo, ctlName);
- err= snd_ctl_hw_elem_replace (ctlDev, elemInfo, elemId);
- if (err) {
- NOTICE ("Fail changing ctlname error=%s", snd_strerror(err));
- }
- NOTICE ("2:ctl exist ctlName=%s NUMID=%d NAME=%s", ctlName, snd_ctl_elem_info_get_numid(elemInfo), snd_ctl_elem_info_get_name(elemInfo));
- }
+ snd_ctl_elem_info_set_device(elemInfo, ctlSndDev);
+ snd_ctl_elem_info_set_subdevice(elemInfo, ctlSubDev);
- // try to normalise ctl name
+ // prepare value set
snd_ctl_elem_value_alloca(&elemValue);
- snd_ctl_elem_id_set_name (elemId, ctlName);
- snd_ctl_elem_value_set_id(elemValue, elemId);
-
- if (!ctlExist) switch (ctlType) {
+
+ switch (ctlType) {
case SND_CTL_ELEM_TYPE_BOOLEAN:
err = snd_ctl_add_boolean_elem_set(ctlDev, elemInfo, 1, ctlCount);
if (err) {
@@ -177,45 +115,79 @@ STATIC int addOneSndCtl(afb_req request, snd_ctl_t *ctlDev, json_object *ctlJ)
goto OnErrorExit;
}
+ elemTlv = allocate_bool_elem_set_tlv();
+
// Provide FALSE as default value
for (int idx=0; idx < ctlCount; idx ++) {
- snd_ctl_elem_value_set_boolean (elemValue, idx, 0);
- }
+ snd_ctl_elem_value_set_boolean (elemValue, idx, 1);
+ }
break;
case SND_CTL_ELEM_TYPE_INTEGER:
+ err = snd_ctl_add_integer_elem_set (ctlDev, elemInfo, 1, ctlCount, ctlMin, ctlMax, ctlStep);
+ if (err) {
+ afb_req_fail_f (request, "ctl-invalid-bool", "devid=%s crl=%s invalid boolean data", snd_ctl_name(ctlDev), json_object_get_string(ctlJ));
+ goto OnErrorExit;
+ }
+
+ // Provide 0 as default value
+ for (int idx=0; idx < ctlCount; idx ++) {
+ snd_ctl_elem_value_set_integer (elemValue, idx, 0);
+ }
break;
case SND_CTL_ELEM_TYPE_INTEGER64:
+ err = snd_ctl_add_integer64_elem_set (ctlDev, elemInfo, 1, ctlCount, ctlMin, ctlMax, ctlStep);
+ if (err) {
+ afb_req_fail_f (request, "ctl-invalid-bool", "devid=%s crl=%s invalid boolean data", snd_ctl_name(ctlDev), json_object_get_string(ctlJ));
+ goto OnErrorExit;
+ }
+
+ // Provide 0 as default value
+ for (int idx=0; idx < ctlCount; idx ++) {
+ snd_ctl_elem_value_set_integer64 (elemValue, idx, 0);
+ }
break;
- case SND_CTL_ELEM_TYPE_ENUMERATED:
- break;
-
+ case SND_CTL_ELEM_TYPE_ENUMERATED:
case SND_CTL_ELEM_TYPE_BYTES:
- break;
-
default:
afb_req_fail_f (request, "ctl-invalid-type", "crl=%s invalid/unknown type", json_object_get_string(ctlJ));
goto OnErrorExit;
}
+ // write default values in newly created control
+ snd_ctl_elem_id_alloca(&elemId);
+ snd_ctl_elem_info_get_id(elemInfo, elemId);
+ snd_ctl_elem_value_set_id(elemValue, elemId);
err = snd_ctl_elem_write (ctlDev, elemValue);
if (err < 0) {
- afb_req_fail_f (request, "ctl-write-fail", "crl=%s fail to write data data", json_object_get_string(ctlJ));
+ afb_req_fail_f (request, "ctl-write-fail", "crl=%s numid=%d fail to write data error=%s", json_object_get_string(ctlJ), snd_ctl_elem_info_get_numid(elemInfo), snd_strerror(err));
goto OnErrorExit;
}
-
- return 0;
+ // write a default null TLV (if usefull should be implemented for every ctl type)
+ if (elemTlv) {
+ err=snd_ctl_elem_tlv_write (ctlDev, elemId, elemTlv);
+ if (err < 0) {
+ afb_req_fail_f (request, "TLV-write-fail", "crl=%s numid=%d fail to write data error=%s", json_object_get_string(ctlJ), snd_ctl_elem_info_get_numid(elemInfo), snd_strerror(err));
+ goto OnErrorExit;
+ }
+ }
+
+ // return newly created as a JSON object
+ OnSucessExit:
+ alsaGetSingleCtl (ctlDev, elemId, &ctlRequest, 0);
+ if (ctlRequest.used < 0) goto OnErrorExit;
+ return ctlRequest.jValues;
OnErrorExit:
- return -1;
+ return NULL;
}
PUBLIC void alsaAddCustomCtls(afb_req request) {
int err;
- json_object *ctlsJ;
+ json_object *ctlsJ, *ctlsValues, *ctlValues;
enum json_type;
snd_ctl_t *ctlDev=NULL;
const char *devid;
@@ -242,13 +214,16 @@ PUBLIC void alsaAddCustomCtls(afb_req request) {
switch (json_object_get_type(ctlsJ)) {
case json_type_object:
- addOneSndCtl(request, ctlDev, ctlsJ);
+ ctlsValues= addOneSndCtl(request, ctlDev, ctlsJ);
+
break;
case json_type_array:
+ ctlsValues= json_object_new_array();
for (int idx= 0; idx < json_object_array_length (ctlsJ); idx++) {
json_object *ctlJ = json_object_array_get_idx (ctlsJ, idx);
- addOneSndCtl(request, ctlDev, ctlJ) ;
+ ctlValues= addOneSndCtl(request, ctlDev, ctlJ) ;
+ if (ctlValues) json_object_array_add (ctlsValues, ctlValues);
}
break;
@@ -256,6 +231,9 @@ PUBLIC void alsaAddCustomCtls(afb_req request) {
afb_req_fail_f (request, "ctls-invalid","ctls=%s not valid JSON array", json_object_get_string(ctlsJ));
goto OnErrorExit;
}
+
+ // get ctl as a json response
+ afb_req_success(request, ctlsValues, NULL);
OnErrorExit:
if (ctlDev) snd_ctl_close(ctlDev);
diff --git a/ALSA-afb/Alsa-ApiHat.c b/ALSA-afb/Alsa-ApiHat.c
index 588e91b..5256fb4 100644
--- a/ALSA-afb/Alsa-ApiHat.c
+++ b/ALSA-afb/Alsa-ApiHat.c
@@ -39,7 +39,8 @@ static const struct afb_verb_v2 api_verbs[] = {
{ .verb= "setctls", .callback= alsaSetCtls},
{ .verb= "subscribe", .callback= alsaEvtSubcribe},
{ .verb= "getcardid", .callback= alsaGetCardId},
- { .verb= "registerHal", .callback= alsaRegisterHal},
+ { .verb= "halregister", .callback= alsaRegisterHal},
+ { .verb= "hallist", .callback= alsaActiveHal},
{ .verb= "ucmquery", .callback= alsaUseCaseQuery},
{ .verb= "ucmset", .callback= alsaUseCaseSet},
{ .verb= "ucmget", .callback= alsaUseCaseGet},
diff --git a/ALSA-afb/Alsa-ApiHat.h b/ALSA-afb/Alsa-ApiHat.h
index bd8518f..46f18de 100644
--- a/ALSA-afb/Alsa-ApiHat.h
+++ b/ALSA-afb/Alsa-ApiHat.h
@@ -68,6 +68,7 @@ PUBLIC void alsaAddCustomCtls(struct afb_req request);
PUBLIC void alsaEvtSubcribe (struct afb_req request);
PUBLIC void alsaGetCardId (struct afb_req request);
PUBLIC void alsaRegisterHal (struct afb_req request);
+PUBLIC void alsaActiveHal (struct afb_req request);
#endif /* ALSALIBMAPPING_H */
diff --git a/ALSA-afb/Alsa-RegEvt.c b/ALSA-afb/Alsa-RegEvt.c
index e06cf87..61885f7 100644
--- a/ALSA-afb/Alsa-RegEvt.c
+++ b/ALSA-afb/Alsa-RegEvt.c
@@ -104,7 +104,7 @@ STATIC int sndCtlEventCB (sd_event_source* src, int fd, uint32_t revents, void*
return 0;
OnErrorExit:
- WARNING ("sndCtlEventCB: ignored unsupported event type");
+ AFB_WARNING ("sndCtlEventCB: ignored unsupported event type");
return (0);
}
@@ -112,7 +112,7 @@ STATIC int sndCtlEventCB (sd_event_source* src, int fd, uint32_t revents, void*
PUBLIC void alsaEvtSubcribe (afb_req request) {
static sndHandleT sndHandles[MAX_SND_CARD];
evtHandleT *evtHandle;
- snd_ctl_t *ctlDev;
+ snd_ctl_t *ctlDev=NULL;
int err, idx, cardId, idxFree=-1;
snd_ctl_card_info_t *cardinfo;
queryValuesT queryValues;
@@ -125,7 +125,6 @@ PUBLIC void alsaEvtSubcribe (afb_req request) {
// open control interface for devid
err = snd_ctl_open(&ctlDev, queryValues.devid, SND_CTL_READONLY);
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;
}
@@ -212,7 +211,7 @@ PUBLIC void alsaGetCardId (afb_req request) {
char devid [10];
const char *devname, *shortname, *longname;
int card, err, index, idx;
- json_object *respJson;
+ json_object *responseJ;
snd_ctl_t *ctlDev;
snd_ctl_card_info_t *cardinfo;
@@ -252,26 +251,44 @@ PUBLIC void alsaGetCardId (afb_req request) {
}
// proxy ctlevent as a binder event
- respJson = json_object_new_object();
- json_object_object_add(respJson, "index" ,json_object_new_int (index));
- json_object_object_add(respJson, "devid" ,json_object_new_string (devid));
- json_object_object_add(respJson, "shortname" ,json_object_new_string (shortname));
- json_object_object_add(respJson, "longname" ,json_object_new_string (longname));
+ responseJ = json_object_new_object();
+ json_object_object_add(responseJ, "index" ,json_object_new_int (index));
+ json_object_object_add(responseJ, "devid" ,json_object_new_string (devid));
+ json_object_object_add(responseJ, "shortname" ,json_object_new_string (shortname));
+ json_object_object_add(responseJ, "longname" ,json_object_new_string (longname));
// search for a HAL binder card mapping name to api prefix
- for (idx=0; idx < MAX_SND_CARD; idx++) {
- if (!strcmp (cardRegistry[idx]->shortname, shortname)) break;
+ for (idx=0; (idx < MAX_SND_CARD && cardRegistry[idx]); idx++) {
+ if (!strcmp (cardRegistry[idx]->shortname, shortname)) {
+ json_object_object_add(responseJ, "halapi",json_object_new_string (cardRegistry[idx]->apiprefix));
+ break;
+ }
}
- // if a match if found, then we have an HAL for this board let's return its value
- if (idx < MAX_SND_CARD) json_object_object_add(respJson, "halapi",json_object_new_string (cardRegistry[idx]->apiprefix));
-
- afb_req_success(request, respJson, NULL);
+
+ afb_req_success(request, responseJ, NULL);
return;
OnErrorExit:
return;
}
+// Return list of active resgistrated HAL with corresponding sndcard
+PUBLIC void alsaActiveHal (afb_req request) {
+ json_object *responseJ = json_object_new_array();
+
+ for (int idx=0; idx < MAX_SND_CARD; idx++) {
+ if (!cardRegistry[idx]) break;
+
+ 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));
+ json_object_array_add (responseJ, haldevJ);
+ }
+
+ afb_req_success(request, responseJ, NULL);
+}
+
+
// Register loaded HAL with board Name and API prefix
PUBLIC void alsaRegisterHal (afb_req request) {
static int index=0;
@@ -293,14 +310,16 @@ 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;
-
- // If OK return sound card Alsa ID+Info
+
alsaGetCardId(request);
+
+ // If OK return sound card Alsa ID+Info
return;
OnErrorExit:
diff --git a/ALSA-afb/Alsa-SetGet.c b/ALSA-afb/Alsa-SetGet.c
index 9d0ec43..56dc32f 100644
--- a/ALSA-afb/Alsa-SetGet.c
+++ b/ALSA-afb/Alsa-SetGet.c
@@ -350,14 +350,14 @@ STATIC json_object* alsaCardProbe (const char *rqtSndId) {
int err;
if ((err = snd_ctl_open(&handle, rqtSndId, 0)) < 0) {
- INFO ("SndCard [%s] Not Found", rqtSndId);
+ AFB_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 ("SndCard [%s] info error: %s", rqtSndId, snd_strerror(err));
+ AFB_WARNING ("SndCard [%s] info error: %s", rqtSndId, snd_strerror(err));
return NULL;
}
@@ -375,7 +375,7 @@ STATIC json_object* alsaCardProbe (const char *rqtSndId) {
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 ("AJG: Soundcard Devid=%-5s devid=%-7s Name=%s\n", rqtSndId, devid, info);
+ AFB_INFO ("AJG: Soundcard Devid=%-5s devid=%-7s Name=%s\n", rqtSndId, devid, info);
}
// free card handle and return info
@@ -461,7 +461,6 @@ PUBLIC int alsaSetSingleCtl (snd_ctl_t *ctlDev, snd_ctl_elem_id_t *elemId, ctlRe
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)) {
AFB_NOTICE( "Not Writable ALSA NUMID=%d Values=[%s]", ctlRequest->numId, json_object_get_string(ctlRequest->jValues));
goto OnErrorExit;
@@ -533,23 +532,22 @@ PUBLIC int alsaGetSingleCtl (snd_ctl_t *ctlDev, snd_ctl_elem_id_t *elemId, ctlRe
// set info event ID and get value
snd_ctl_elem_info_alloca(&elemInfo);
- snd_ctl_elem_info_set_id(elemInfo, elemId); // map ctlInfo to ctlId elemInfo is updated !!!
+ snd_ctl_elem_info_set_id(elemInfo, elemId);
if (snd_ctl_elem_info(ctlDev, elemInfo) < 0) goto OnErrorExit;
count = snd_ctl_elem_info_get_count (elemInfo);
if (count == 0) goto OnErrorExit;
- snd_ctl_elem_info_get_id(elemInfo, elemId); // map ctlInfo to ctlId elemInfo is updated !!!
if (!snd_ctl_elem_info_is_readable(elemInfo)) goto OnErrorExit;
elemType = snd_ctl_elem_info_get_type(elemInfo);
snd_ctl_elem_value_alloca(&elemData);
- snd_ctl_elem_value_set_id(elemData, elemId); // map ctlInfo to ctlId elemInfo is updated !!!
+ snd_ctl_elem_value_set_id(elemData, elemId);
if (snd_ctl_elem_read(ctlDev, elemData) < 0) goto OnErrorExit;
int numid= snd_ctl_elem_info_get_numid(elemInfo);
ctlRequest->jValues= json_object_new_object();
- json_object_object_add (ctlRequest->jValues,"id" , json_object_new_int(numid));
+ json_object_object_add (ctlRequest->jValues,"numid" , json_object_new_int(numid));
if (quiet < 2) json_object_object_add (ctlRequest->jValues,"name" , json_object_new_string(snd_ctl_elem_id_get_name (elemId)));
if (quiet < 1) json_object_object_add (ctlRequest->jValues,"iface" , json_object_new_string(snd_ctl_elem_iface_name(snd_ctl_elem_id_get_interface(elemId))));
if (quiet < 3) json_object_object_add (ctlRequest->jValues,"actif", json_object_new_boolean(!snd_ctl_elem_info_is_inactive(elemInfo)));
@@ -594,7 +592,7 @@ PUBLIC int alsaGetSingleCtl (snd_ctl_t *ctlDev, snd_ctl_elem_id_t *elemId, ctlRe
if (!quiet) { // in simple mode do not print usable values
json_object *jsonClassCtl = json_object_new_object();
- json_object_object_add (jsonClassCtl,"type" , json_object_new_string(snd_ctl_elem_type_name(elemType)));
+ json_object_object_add (jsonClassCtl,"type" , json_object_new_int(elemType));
json_object_object_add (jsonClassCtl,"count", json_object_new_int(count));
switch (elemType) {
diff --git a/ALSA-afb/Alsa-Ucm.c b/ALSA-afb/Alsa-Ucm.c
index bc492b3..b2039be 100644
--- a/ALSA-afb/Alsa-Ucm.c
+++ b/ALSA-afb/Alsa-Ucm.c
@@ -275,17 +275,17 @@ PUBLIC void alsaUseCaseGet (struct afb_req request) {
enum json_type jtype= json_object_get_type(jLabels);
switch (jtype) {
- json_object *jTmp;
+ json_object *tmpJ;
case json_type_array:
labelCount = json_object_array_length (jLabels);
break;
case json_type_string:
- jTmp = json_object_new_array ();
+ tmpJ = json_object_new_array ();
labelCount = 1;
- json_object_array_add (jTmp, jLabels);
- jLabels=jTmp;
+ json_object_array_add (tmpJ, jLabels);
+ jLabels=tmpJ;
break;
default:
@@ -308,9 +308,9 @@ PUBLIC void alsaUseCaseGet (struct afb_req request) {
// use info section to notified not found values label
if (json_object_array_length (jWarnings) > 0) {
- json_object *jTmp = json_object_new_object ();
- json_object_object_add (jTmp, "no-context", jWarnings);
- warnings= json_object_get_string (jTmp);
+ json_object *tmpJ = json_object_new_object ();
+ json_object_object_add (tmpJ, "no-context", jWarnings);
+ warnings= json_object_get_string (tmpJ);
}
afb_req_success (request, jResponse, warnings);