aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfulup <fulup.arfoll@iot.bzh>2017-03-30 10:12:31 +0200
committerfulup <fulup.arfoll@iot.bzh>2017-03-30 10:12:31 +0200
commit36bea37e9781276e7162292ea6933a7f6404c5ee (patch)
treef3feef5053f227a394a8c459faa70270bb33588e
parent0cf14446989c8e58a2ce681246507c0803b1e370 (diff)
Initial working implementation for Alsa UCM.
Cleanup format for Alsa control GET. Status: working in progress
-rw-r--r--AlsaSound/CoreBinding/AlsaCoreBinding.c (renamed from AlsaSound/CoreBinding/AlsaAfbBinding.c)19
-rw-r--r--AlsaSound/CoreBinding/AlsaCoreBinding.h (renamed from AlsaSound/CoreBinding/AlsaLibMapping.h)25
-rw-r--r--AlsaSound/CoreBinding/AlsaCtlSetGet.c (renamed from AlsaSound/CoreBinding/AlsaLibMapping.c)232
-rw-r--r--AlsaSound/CoreBinding/AlsaUseCase.c430
-rw-r--r--AlsaSound/CoreBinding/CMakeLists.txt2
-rw-r--r--README.md34
-rw-r--r--cd0
-rw-r--r--htdocs/AFB-websock.js2
-rw-r--r--htdocs/AudioBinding.js7
-rw-r--r--htdocs/README.md2
-rw-r--r--htdocs/alsa-core.html32
-rw-r--r--nbproject/configurations.xml18
12 files changed, 649 insertions, 154 deletions
diff --git a/AlsaSound/CoreBinding/AlsaAfbBinding.c b/AlsaSound/CoreBinding/AlsaCoreBinding.c
index c9bdf30..19a7f3b 100644
--- a/AlsaSound/CoreBinding/AlsaAfbBinding.c
+++ b/AlsaSound/CoreBinding/AlsaCoreBinding.c
@@ -26,7 +26,7 @@
#include <sys/time.h>
#include <sys/types.h>
-#include "AlsaLibMapping.h"
+#include "AlsaCoreBinding.h"
PUBLIC const struct afb_binding_interface *afbIface;
@@ -35,12 +35,17 @@ PUBLIC const struct afb_binding_interface *afbIface;
*/
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= "List All/One 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= "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= "List All/One 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= NULL } /* marker for end of the array */
};
diff --git a/AlsaSound/CoreBinding/AlsaLibMapping.h b/AlsaSound/CoreBinding/AlsaCoreBinding.h
index a6edd1d..0e5f84a 100644
--- a/AlsaSound/CoreBinding/AlsaLibMapping.h
+++ b/AlsaSound/CoreBinding/AlsaCoreBinding.h
@@ -21,10 +21,25 @@
#include "AudioCommonLib.h"
+
+typedef enum {
+ ACTION_SET,
+ ACTION_GET
+} ActionSetGetT;
+
+// generic structure to pass parsed query values
+typedef struct {
+ const char *devid;
+ json_object *jNumIds;
+ int quiet;
+ int count;
+} queryValuesT;
+
// import from AlsaAfbBinding
extern const struct afb_binding_interface *afbIface;
+PUBLIC int alsaCheckQuery (struct afb_req request, queryValuesT *queryValues);
-// import from AlsaAfbMapping
+// AlseCoreSetGet exports
PUBLIC void alsaGetInfo (struct afb_req request);
PUBLIC void alsaGetCtls(struct afb_req request);
PUBLIC void alsaSetCtrl(struct afb_req request);
@@ -32,6 +47,14 @@ PUBLIC void alsaSubcribe (struct afb_req request);
PUBLIC void alsaGetCardId (struct afb_req request);
PUBLIC void alsaRegisterHal (struct afb_req request);
+// AlsaUseCase exports
+PUBLIC void alsaUseCaseQuery(struct afb_req request);
+PUBLIC void alsaUseCaseSet(struct afb_req request);
+PUBLIC void alsaUseCaseGet(struct afb_req request);
+PUBLIC void alsaUseCaseClose(struct afb_req request);
+PUBLIC void alsaUseCaseReset(struct afb_req request);
+
+
#endif /* ALSALIBMAPPING_H */
diff --git a/AlsaSound/CoreBinding/AlsaLibMapping.c b/AlsaSound/CoreBinding/AlsaCtlSetGet.c
index 375d501..a6cd45b 100644
--- a/AlsaSound/CoreBinding/AlsaLibMapping.c
+++ b/AlsaSound/CoreBinding/AlsaCtlSetGet.c
@@ -27,34 +27,31 @@
#define _GNU_SOURCE // needed for vasprintf
#include <alsa/asoundlib.h>
-#include "AlsaLibMapping.h"
+#include "AlsaCoreBinding.h"
#include <systemd/sd-event.h>
-typedef enum {
- ACTION_SET,
- ACTION_GET
-} ActionSetGetT;
-// generic structure to pass parsed query values
+// use to store crl numid user request
typedef struct {
- const char *devid;
- json_object *jNumIds;
- int quiet;
- int count;
-} queryValuesT;
+ unsigned int numId;
+ json_object *jToken;
+ json_object *jValues;
+ int used;
+} ctlRequestT;
// generic sndctrl event handle hook to event callback when pooling
typedef struct {
struct pollfd pfds;
sd_event_source *src;
- snd_ctl_t *ctl;
+ snd_ctl_t *ctlDev;
+ int quiet;
struct afb_event afbevt;
} evtHandleT;
typedef struct {
- int cardid;
int ucount;
+ int cardId;
evtHandleT *evtHandle;
} sndHandleT;
@@ -63,23 +60,17 @@ typedef struct {
char *shortname;
}cardRegistryT;
-// use to store crl numid user request
-typedef struct {
- unsigned int numId;
- json_object *jToken;
- json_object *jValues;
- int used;
-} ctlRequestT;
-
-
cardRegistryT *cardRegistry[MAX_SND_CARD+1];
-STATIC void NumidsListParse (queryValuesT *queryValues, ctlRequestT *ctlRequest) {
+PUBLIC void NumidsListParse (queryValuesT *queryValues, ctlRequestT *ctlRequest) {
json_object *jValues;
int length;
- for (int idx=0; queryValues->count; idx ++) {
+ 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;
+
switch (json_object_get_type(ctlRequest[idx].jToken)) {
@@ -97,7 +88,6 @@ STATIC void NumidsListParse (queryValuesT *queryValues, ctlRequestT *ctlRequest)
}
ctlRequest[idx].numId =json_object_get_int(json_object_array_get_idx (ctlRequest[idx].jToken, 0));
- ctlRequest[idx].used=0;
if (length == 2) {
jValues = json_object_array_get_idx (ctlRequest[idx].jToken, 1);
@@ -114,33 +104,51 @@ STATIC void NumidsListParse (queryValuesT *queryValues, ctlRequestT *ctlRequest)
}
}
-STATIC int alsaCheckQuery (struct afb_req request, queryValuesT *queryValues) {
+PUBLIC int alsaCheckQuery (struct 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 *rqtQuiet = afb_req_value(request, "quiet");
if (!rqtQuiet) queryValues->quiet=99; // default super quiet
else if (rqtQuiet && ! sscanf (rqtQuiet, "%d", &queryValues->quiet)) {
json_object *query = afb_req_json(request);
- afb_req_fail_f (request, "quiet-notinteger","Query=%s NumID not integer &numid=%s&", json_object_to_json_string(query), rqtQuiet);
+ afb_req_fail_f (request, "quiet-notinteger","Query=%s Quiet not integer &quiet=%s&", json_object_to_json_string(query), rqtQuiet);
goto OnErrorExit;
};
// no NumId is interpreted as ALL for get and error for set
numids = afb_req_value(request, "numids");
- if (numids != NULL) {
+ if (numids == NULL) {
queryValues->count=0;
goto OnExit;
}
- queryValues->jNumIds = json_tokener_parse(numids);
- queryValues->count = json_object_array_length (queryValues->jNumIds);
- if (queryValues->count <= 0) {
- afb_req_fail_f (request, "numid-notarray","NumId=%s NumId not valid JSON array", numids);
+ 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:
@@ -362,14 +370,12 @@ STATIC json_object* alsaCardProbe (const char *rqtSndId) {
snd_ctl_card_info_t *cardinfo;
int err;
-
- snd_ctl_card_info_alloca(&cardinfo);
-
if ((err = snd_ctl_open(&handle, rqtSndId, 0)) < 0) {
INFO (afbIface, "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));
@@ -390,7 +396,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 (afbIface, "AJG: Soundcard Devid=%-5s Cardid=%-7s Name=%s\n", rqtSndId, devid, info);
+ INFO (afbIface, "AJG: Soundcard Devid=%-5s devid=%-7s Name=%s\n", rqtSndId, devid, info);
}
// free card handle and return info
@@ -532,8 +538,6 @@ STATIC int alsaGetSingleCtl (snd_ctl_t *ctlDev, snd_ctl_elem_id_t *elemId, ctlRe
snd_ctl_elem_info_t *elemInfo;
int count, idx, err;
- // let's make sure we are processing the right control
- if (ctlRequest->numId != snd_ctl_elem_id_get_numid (elemId)) goto OnErrorExit;
// set info event ID and get value
@@ -552,6 +556,7 @@ STATIC int alsaGetSingleCtl (snd_ctl_t *ctlDev, snd_ctl_elem_id_t *elemId, ctlRe
if (snd_ctl_elem_read(ctlDev, elemData) < 0) goto OnErrorExit;
ctlRequest->jValues= json_object_new_object();
+ json_object_object_add (ctlRequest->jValues,"numid" , ctlRequest->jToken);
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)));
@@ -658,8 +663,7 @@ PUBLIC void alsaSetGetCtls (struct afb_req request, ActionSetGetT action) {
unsigned int ctlCount;
snd_ctl_t *ctlDev;
snd_ctl_elem_list_t *ctlList;
-
- json_object *sndctrls=json_object_new_object();;
+ json_object *sndctls=json_object_new_array();;
queryValuesT queryValues;
err = alsaCheckQuery (request, &queryValues);
@@ -737,29 +741,38 @@ PUBLIC void alsaSetGetCtls (struct afb_req request, ActionSetGetT action) {
err = 1;
}
if (err) status++;
- else json_object_object_add (sndctrls, json_object_to_json_string(ctlRequest[jdx].jToken), ctlRequest[jdx].jValues);
+ else {
+ json_object_array_add (sndctls, ctlRequest[jdx].jValues);
+ }
}
}
// if we had error let's add them into response message info
- json_object *warnings = json_object_new_object();
+ json_object *warnings = json_object_new_array();
for (int jdx=0; jdx < queryValues.count; jdx++) {
if (ctlRequest[jdx].used <= 0) {
- if (ctlRequest[jdx].used == 0) json_object_object_add (warnings, json_object_to_json_string(ctlRequest[jdx].jToken), json_object_new_string ("Does Not Exist"));
- else json_object_object_add (warnings, json_object_to_json_string(ctlRequest[jdx].jToken), json_object_new_string ("Invalid Value"));
- }
- if (ctlRequest[jdx].numId == -1) {
- json_object_object_add (warnings, json_object_to_json_string(ctlRequest[jdx].jToken), json_object_new_string ("Invalid NumID"));
+ 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].numId == -1) json_object_object_add (failctl, "info", json_object_new_string ("Invalid NumID"));
+ 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"));
+ }
+ json_object_array_add (warnings, failctl);
}
- // free intermediary object
+ /* WARNING!!!! Check with Jose why following put free jValues
if (ctlRequest[jdx].jToken) json_object_put(ctlRequest[jdx].jToken);
if (ctlRequest[jdx].jValues) json_object_put(ctlRequest[jdx].jValues);
+ */
}
- if (json_object_object_length(warnings)) warmsg=json_object_to_json_string(warnings);
- else json_object_put(warnings);
+
+ if (json_object_array_length(warnings)) warmsg=json_object_to_json_string_ext(warnings, JSON_C_TO_STRING_PLAIN);
- // send response warning if any are passed into info element
- afb_req_success (request, sndctrls, warmsg);
+ // send response+warning if any
+ afb_req_success (request, sndctls, warmsg);
snd_ctl_elem_list_clear(ctlList);
OnErrorExit:
@@ -779,15 +792,15 @@ PUBLIC void alsaSetCtls (struct afb_req request) {
STATIC int sndCtlEventCB (sd_event_source* src, int fd, uint32_t revents, void* userData) {
int err;
evtHandleT *evtHandle = (evtHandleT*)userData;
- snd_ctl_event_t *ctlEvent;
- json_object *ctlEventJson;
+ snd_ctl_event_t *eventId;
+ json_object *ctlEventJ;
unsigned int mask;
- int numid;
int iface;
int device;
int subdev;
const char*devname;
- int index;
+ ctlRequestT ctlRequest;
+ snd_ctl_elem_id_t *elemId;
if ((revents & EPOLLHUP) != 0) {
NOTICE (afbIface, "SndCtl hanghup [car disconnected]");
@@ -795,37 +808,43 @@ STATIC int sndCtlEventCB (sd_event_source* src, int fd, uint32_t revents, void*
}
if ((revents & EPOLLIN) != 0) {
-
- snd_ctl_event_alloca(&ctlEvent); // initialise event structure on stack
- err = snd_ctl_read(evtHandle->ctl, ctlEvent);
+ // initialise event structure on stack
+ snd_ctl_event_alloca(&eventId);
+ snd_ctl_elem_id_alloca(&elemId);
+
+ err = snd_ctl_read(evtHandle->ctlDev, eventId);
if (err < 0) goto OnErrorExit;
// we only process sndctrl element
- if (snd_ctl_event_get_type(ctlEvent) != SND_CTL_EVENT_ELEM) goto ExitOnSucess;
+ if (snd_ctl_event_get_type(eventId) != SND_CTL_EVENT_ELEM) goto ExitOnSucess;
// we only process value changed events
- mask = snd_ctl_event_elem_get_mask(ctlEvent);
+ mask = snd_ctl_event_elem_get_mask(eventId);
if (!(mask & SND_CTL_EVENT_MASK_VALUE)) goto ExitOnSucess;
-
- numid = snd_ctl_event_elem_get_numid(ctlEvent);
- iface = snd_ctl_event_elem_get_interface(ctlEvent);
- device = snd_ctl_event_elem_get_device(ctlEvent);
- subdev = snd_ctl_event_elem_get_subdevice(ctlEvent);
- devname= snd_ctl_event_elem_get_name(ctlEvent);
- index = snd_ctl_event_elem_get_index(ctlEvent);
- DEBUG(afbIface, "sndCtlEventCB: (%i,%i,%i,%i,%s,%i)", numid, iface, device, subdev, devname, index);
+ snd_ctl_event_elem_get_id (eventId, elemId);
+
+ err = alsaGetSingleCtl (evtHandle->ctlDev, elemId, &ctlRequest, evtHandle->quiet);
+ if (err) goto OnErrorExit;
+ iface = snd_ctl_event_elem_get_interface(eventId);
+ device = snd_ctl_event_elem_get_device(eventId);
+ subdev = snd_ctl_event_elem_get_subdevice(eventId);
+ devname= snd_ctl_event_elem_get_name(eventId);
+
// proxy ctlevent as a binder event
- ctlEventJson = json_object_new_object();
- json_object_object_add(ctlEventJson, "numid" ,json_object_new_int (numid));
- json_object_object_add(ctlEventJson, "iface" ,json_object_new_int (iface));
- json_object_object_add(ctlEventJson, "device" ,json_object_new_int (device));
- json_object_object_add(ctlEventJson, "subdev" ,json_object_new_int (subdev));
- json_object_object_add(ctlEventJson, "devname",json_object_new_string (devname));
- json_object_object_add(ctlEventJson, "index" ,json_object_new_int (index));
- afb_event_push(evtHandle->afbevt, ctlEventJson);
+ ctlEventJ = json_object_new_object();
+ json_object_object_add(ctlEventJ, "device" ,json_object_new_int (device));
+ json_object_object_add(ctlEventJ, "subdev" ,json_object_new_int (subdev));
+ if (evtHandle->quiet < 2) {
+ 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));
+ DEBUG(afbIface, "sndCtlEventCB=%s", json_object_get_string(ctlEventJ));
+ afb_event_push(evtHandle->afbevt, ctlEventJ);
+
}
ExitOnSucess:
@@ -841,31 +860,34 @@ PUBLIC void alsaSubcribe (struct afb_req request) {
static sndHandleT sndHandles[MAX_SND_CARD];
evtHandleT *evtHandle;
snd_ctl_t *ctlDev;
- snd_ctl_card_info_t *card_info;
- int err, idx, cardid;
- int idxFree=-1;
+ int err, idx, cardId, idxFree=-1;
+ snd_ctl_card_info_t *cardinfo;
+ queryValuesT queryValues;
+
- const char *devid = afb_req_value(request, "devid");
- if (devid == NULL) {
- afb_req_fail_f (request, "devid-missing", "devid=hw:xxx missing");
+ err = alsaCheckQuery (request, &queryValues);
+ if (err) goto OnErrorExit;
+
+
+ // 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;
}
- // open control interface for devid
- err = snd_ctl_open(&ctlDev, devid, SND_CTL_READONLY);
- if (err < 0) {
- afb_req_fail_f (request, "devid-unknown", "SndCard devid=%s Not Found err=%d", devid, err);
- goto OnErrorExit;
+ snd_ctl_card_info_alloca(&cardinfo);
+ if ((err = snd_ctl_card_info(ctlDev, cardinfo)) < 0) {
+ afb_req_fail_f (request, "devid-invalid", "SndCard devid=%s Not Found err=%s", queryValues.devid, snd_strerror(err));
+ goto OnErrorExit;
}
- // get sound card index use to search existing subscription
- snd_ctl_card_info_alloca(&card_info);
- snd_ctl_card_info(ctlDev, card_info);
- cardid = snd_ctl_card_info_get_card(card_info);
+ cardId=snd_ctl_card_info_get_card(cardinfo);
// search for an existing subscription and mark 1st free slot
for (idx= 0; idx < MAX_SND_CARD; idx ++) {
- if (sndHandles[idx].ucount > 0 && sndHandles[idx].cardid == cardid) {
+ if (sndHandles[idx].ucount > 0 && cardId == sndHandles[idx].cardId) {
evtHandle= sndHandles[idx].evtHandle;
break;
} else if (idxFree == -1) idxFree= idx;
@@ -877,40 +899,37 @@ PUBLIC void alsaSubcribe (struct afb_req request) {
// reach MAX_SND_CARD event registration
if (idxFree == -1) {
afb_req_fail_f (request, "register-toomany", "Cannot register new event Maxcard==%devent name=%s", idx);
- snd_ctl_close(ctlDev);
goto OnErrorExit;
}
evtHandle = malloc (sizeof(evtHandleT));
- evtHandle->ctl = ctlDev;
+ evtHandle->ctlDev = ctlDev;
+ evtHandle->quiet = queryValues.quiet;
sndHandles[idxFree].ucount = 0;
- sndHandles[idxFree].cardid = cardid;
+ sndHandles[idxFree].cardId = cardId;
sndHandles[idxFree].evtHandle = evtHandle;
// subscribe for sndctl events attached to devid
- err = snd_ctl_subscribe_events(evtHandle->ctl, 1);
+ err = snd_ctl_subscribe_events(evtHandle->ctlDev, 1);
if (err < 0) {
- afb_req_fail_f (request, "subscribe-fail", "Cannot subscribe events from devid=%s err=%d", devid, err);
- snd_ctl_close(ctlDev);
+ afb_req_fail_f (request, "subscribe-fail", "Cannot subscribe events from devid=%s err=%d", queryValues.devid, err);
goto OnErrorExit;
}
// get pollfd attach to this sound board
- snd_ctl_poll_descriptors(evtHandle->ctl, &evtHandle->pfds, 1);
+ 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);
if (err < 0) {
- afb_req_fail_f (request, "register-mainloop", "Cannot hook events to mainloop devid=%s err=%d", devid, err);
- snd_ctl_close(ctlDev);
+ 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, devid);
+ evtHandle->afbevt = afb_daemon_make_event (afbIface->daemon, queryValues.devid);
if (!afb_event_is_valid (evtHandle->afbevt)) {
- afb_req_fail_f (request, "register-event", "Cannot register new binder event name=%s", devid);
- snd_ctl_close(ctlDev);
+ afb_req_fail_f (request, "register-event", "Cannot register new binder event name=%s", queryValues.devid);
goto OnErrorExit;
}
@@ -921,7 +940,7 @@ PUBLIC void alsaSubcribe (struct afb_req request) {
// subscribe to binder event
err = afb_req_subscribe(request, evtHandle->afbevt);
if (err != 0) {
- afb_req_fail_f (request, "register-eventname", "Cannot subscribe binder event name=%s [invalid channel]", devid, err);
+ afb_req_fail_f (request, "register-eventname", "Cannot subscribe binder event name=%s [invalid channel]", queryValues.devid, err);
goto OnErrorExit;
}
@@ -931,6 +950,7 @@ PUBLIC void alsaSubcribe (struct afb_req request) {
return;
OnErrorExit:
+ if (ctlDev) snd_ctl_close(ctlDev);
return;
}
diff --git a/AlsaSound/CoreBinding/AlsaUseCase.c b/AlsaSound/CoreBinding/AlsaUseCase.c
new file mode 100644
index 0000000..ccea4fa
--- /dev/null
+++ b/AlsaSound/CoreBinding/AlsaUseCase.c
@@ -0,0 +1,430 @@
+/*
+ * AlsaUseCase -- provide low level interface with ALSA lib (extracted from alsa-json-gateway code)
+ * Copyright (C) 2015,2016,2017, Fulup Ar Foll fulup@iot.bzh
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+
+ References:
+ http://www.alsa-project.org/alsa-doc/alsa-lib/group__ucm.html
+ https://www.alsa-project.org/main/index.php/DAPM
+ http://alsa-lib.sourcearchive.com/documentation/1.0.24.1-2/group__Use_ga4332c6bb50481bbdaf21be11551fb930.html
+ https://android.googlesource.com/platform/hardware/qcom/audio/+/jb-mr1-dev/libalsa-intf/alsa_ucm.h
+
+ Sample alsaucm commands using /usr/share/alsa/ucm/PandaBoard
+ - alsaucm -c PandaBoard list _verbs
+ - alsaucm -c PandaBoard list _devices/HiFi
+ - alsaucm -c PandaBoard list _modifiers/HiFi #need to uncomment modifiers section
+ - alsaucm -c PandaBoard list TQ/HiFi
+ - alsaucm -c PandaBoard get TQ/HiFi/Voice
+ - alsaucm -c PandaBoard get PlaybackPCM//HiFi
+ - alsaucm -c PandaBoard set _verb HiFi
+ - alsaucm -c PandaBoard set _verb HiFi _enadev Headset
+ - alsaucm -c 'HDA Intel PCH' set _verb HiFi set _enadev Headphone set _enamod RecordMedia
+ - alsaucm -c 'HDA Intel PCH' set _verb HiFi get OutputDspName//
+
+*/
+#define _GNU_SOURCE // needed for vasprintf
+
+#include <alsa/asoundlib.h>
+#include "AlsaCoreBinding.h"
+#include <alsa/asoundlib.h>
+#include <alsa/use-case.h>
+
+typedef struct {
+ snd_use_case_mgr_t *ucm;
+ int cardId;
+ char *cardName;
+} ucmHandleT;
+
+static ucmHandleT ucmHandles[MAX_SND_CARD];
+
+// Cache opened UCM handles
+STATIC int alsaUseCaseOpen (struct afb_req request, queryValuesT *queryValues, int allowNewMgr) {
+ snd_ctl_t *ctlDev;
+ snd_ctl_card_info_t *cardinfo;
+ snd_use_case_mgr_t *ucmHandle;
+ const char *cardName;
+ int cardId, idx, idxFree=-1, err;
+
+ // 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=%d", queryValues->devid, err);
+ goto OnErrorExit;
+ }
+
+ snd_ctl_card_info_alloca(&cardinfo);
+ if ((err = snd_ctl_card_info(ctlDev, cardinfo)) < 0) {
+ afb_req_fail_f (request, "devid-invalid", "SndCard devid=[%s] Not Found err=%s", queryValues->devid, snd_strerror(err));
+ goto OnErrorExit;
+ }
+
+ // search for an existing subscription and mark 1st free slot
+ cardId = snd_ctl_card_info_get_card(cardinfo);
+ for (idx= 0; idx < MAX_SND_CARD; idx ++) {
+ if (ucmHandles[idx].ucm != NULL) {
+ if (ucmHandles[idx].cardId == cardId) goto OnSuccessExit;
+ } else if (idxFree == -1) idxFree= idx;
+ };
+
+ if (!allowNewMgr) {
+ afb_req_fail_f (request, "ucm-nomgr", "SndCard devid=[%s] no exiting UCM manager session", queryValues->devid);
+ goto OnErrorExit;
+ }
+
+ if (idxFree < 0 && idx == MAX_SND_CARD) {
+ afb_req_fail_f (request, "ucm-toomany", "SndCard devid=[%s] too many open UCM Max=%d", queryValues->devid, MAX_SND_CARD);
+ goto OnErrorExit;
+ }
+
+ idx = idxFree;
+ cardName = snd_ctl_card_info_get_name(cardinfo);
+ err = snd_use_case_mgr_open(&ucmHandle, cardName);
+ if (err) {
+ afb_req_fail_f (request, "ucm-open", "SndCard devid=[%s] name=[%s] No UCM Profile err=%s", queryValues->devid, cardName, snd_strerror(err));
+ goto OnErrorExit;
+ }
+ ucmHandles[idx].ucm = ucmHandle;
+ ucmHandles[idx].cardId = cardId;
+ ucmHandles[idx].cardName = strdup(cardName);
+
+ OnSuccessExit:
+ if (ctlDev) snd_ctl_close(ctlDev);
+ return idx;
+
+ OnErrorExit:
+ if (ctlDev) snd_ctl_close(ctlDev);
+ return -1;
+}
+
+
+PUBLIC void alsaUseCaseQuery(struct afb_req request) {
+ int err, 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;
+
+ ucmIdx = alsaUseCaseOpen (request, &queryValues, TRUE);
+ if (ucmIdx < 0) goto OnErrorExit;
+ ucmHandle = ucmHandles [ucmIdx].ucm;
+ cardName = ucmHandles [ucmIdx].cardName;
+
+ verbCount = snd_use_case_get_list (ucmHandle, "_verbs", &verbList);
+ if (verbCount < 0) {
+ afb_req_fail_f (request, "ucm-list", "SndCard devid=[%s] name=[%s] No UCM Verbs", queryValues.devid, cardName);
+ goto OnErrorExit;
+ }
+
+ ucmJs = json_object_new_array();
+ for (int idx=0; idx < verbCount; idx +=2) {
+ int devCount, modCount, tqCount;
+ const char **devList, **modList, **tqList;
+ json_object *ucmJ = json_object_new_object();
+ char identifier[32];
+
+ json_object_object_add (ucmJ, "verb", json_object_new_string(verbList[idx]));
+ if (verbList[idx+1]) json_object_object_add (ucmJ, "info", json_object_new_string(verbList[idx+1]));
+
+ DEBUG (afbIface, "Verb[%d] Action=%s Info=%s", idx, verbList[idx], verbList[idx+1]);
+
+ snprintf (identifier, sizeof(identifier), "_devices/%s", verbList[idx]);
+ devCount = snd_use_case_get_list (ucmHandle, identifier, &devList);
+ if (devCount > 0) {
+ json_object *devsJ = json_object_new_array();
+
+ for (int jdx=0; jdx < devCount; jdx+=2) {
+ json_object *devJ = json_object_new_object();
+ DEBUG (afbIface, "device[%d] Action=%s Info=%s", jdx, devList[jdx], devList[jdx+1]);
+ json_object_object_add (devJ, "dev", json_object_new_string(devList[jdx]));
+ if (devList[jdx+1]) json_object_object_add (devJ, "info", json_object_new_string(devList[jdx+1]));
+ json_object_array_add (devsJ, devJ);
+ }
+ json_object_object_add(ucmJ,"devices", devsJ);
+ snd_use_case_free_list(devList, err);
+ }
+
+ snprintf (identifier, sizeof(identifier), "_modifiers/%s", verbList[idx]);
+ modCount = snd_use_case_get_list (ucmHandle, identifier, &modList);
+ if (modCount > 0) {
+ json_object *modsJ = json_object_new_array();
+
+ for (int jdx=0; jdx < modCount; jdx+=2) {
+ json_object *modJ = json_object_new_object();
+ DEBUG (afbIface, "modifier[%d] Action=%s Info=%s", jdx, modList[jdx], modList[jdx+1]);
+ json_object_object_add (modJ, "mod", json_object_new_string(modList[jdx]));
+ if (modList[jdx+1]) json_object_object_add (modJ, "info", json_object_new_string(modList[jdx+1]));
+ json_object_array_add (modsJ, modJ);
+ }
+ json_object_object_add(ucmJ,"modifiers", modsJ);
+ snd_use_case_free_list(modList, err);
+ }
+
+ snprintf (identifier, sizeof(identifier), "TQ/%s", verbList[idx]);
+ tqCount = snd_use_case_get_list (ucmHandle, identifier, &tqList);
+ if (tqCount > 0) {
+ json_object *tqsJ = json_object_new_array();
+
+ for (int jdx=0; jdx < tqCount; jdx+=2) {
+ json_object *tqJ = json_object_new_object();
+ DEBUG (afbIface, "toneqa[%d] Action=%s Info=%s", jdx, tqList[jdx], tqList[jdx+1]);
+ json_object_object_add (tqJ, "tq", json_object_new_string(tqList[jdx]));
+ if (tqList[jdx+1]) json_object_object_add (tqJ, "info", json_object_new_string(tqList[jdx+1]));
+ json_object_array_add (tqsJ, tqJ);
+ }
+ json_object_object_add(ucmJ,"tqs", tqsJ);
+ snd_use_case_free_list(tqList, err);
+ }
+
+ json_object_array_add (ucmJs, ucmJ);
+ }
+
+ afb_req_success (request, ucmJs, NULL);
+ snd_use_case_free_list(verbList, err);
+
+ OnErrorExit:
+ return;
+}
+
+STATIC json_object *ucmGetValue (ucmHandleT *ucmHandle, const char *verb, const char *mod, const char *label) {
+ char identifier[80];
+ char *value;
+ int err;
+ json_object *jValue;
+
+ // handle optional parameters
+ if (!mod) mod="";
+ if (!verb) verb="";
+
+ if (!label) {
+ NOTICE (afbIface, "ucmGetValue cardname=[%s] value label missing", ucmHandle->cardName);
+ goto OnErrorExit;
+ }
+
+ snprintf (identifier, sizeof(identifier), "%s/%s/%s", label, mod, verb);
+ err = snd_use_case_get (ucmHandle->ucm, identifier, (const char**)&value); // Note: value casting is a known "FEATURE" of AlsaUCM API
+ if (err) {
+ DEBUG (afbIface, "ucmGetValue cardname=[%s] identifier=[%s] error=%s", ucmHandle->cardName, identifier, snd_strerror (err));
+ goto OnErrorExit;
+ }
+
+ // copy value into json object and free string
+ jValue = json_object_new_string (value);
+ free (value);
+ return (jValue);
+
+ OnErrorExit:
+ return (NULL);
+}
+
+PUBLIC void alsaUseCaseSet(struct afb_req request) {
+ int err, ucmIdx;
+ queryValuesT queryValues;
+ json_object *jResponse = json_object_new_object();
+
+ err = alsaCheckQuery (request, &queryValues);
+ if (err) goto OnErrorExit;
+
+ ucmIdx = alsaUseCaseOpen (request, &queryValues, TRUE);
+ if (ucmIdx < 0) goto OnErrorExit;
+
+ snd_use_case_mgr_t *ucmMgr= ucmHandles[ucmIdx].ucm;
+ const char *cardName= ucmHandles[ucmIdx].cardName;
+
+ const char *verb = afb_req_value(request, "verb");
+ const char *mod = afb_req_value(request, "mod");
+ const char *dev = afb_req_value(request, "dev");
+ // Known identifiers: _verb - set current verb = value _enadev - enable given device = value _disdev - disable given device = value _swdev/{old_device} - new_device = value
+
+ if (verb) {
+ err = snd_use_case_set (ucmMgr, "_verb", verb);
+ if (err) {
+ afb_req_fail_f (request, "ucmset-verb", "SndCard devid=[%s] name=[%s] Invalid UCM verb=[%s] err=%s", queryValues.devid, cardName, verb, snd_strerror(err));
+ goto OnErrorExit;
+ }
+ }
+
+ if (dev) {
+ err = snd_use_case_set (ucmMgr, "_enadev", dev);
+ if (err) {
+ afb_req_fail_f (request, "ucmset-dev", "SndCard devid=[%s] name=[%s] Invalid UCMverb=[%s] dev=%s err=%s", queryValues.devid, cardName, verb, dev, snd_strerror(err));
+ goto OnErrorExit;
+ }
+ }
+
+ if (mod) {
+ err = snd_use_case_set (ucmMgr, "_enamod", mod);
+ if (err) {
+ afb_req_fail_f (request, "ucmset-mod", "SndCard devid=[%s] name=[%s] Invalid UCM verb=[%s] mod=[%s] err=%s", queryValues.devid, cardName, verb, mod, snd_strerror(err));
+ goto OnErrorExit;
+ }
+ }
+
+ if (queryValues.quiet <= 3) {
+ json_object *jValue;
+
+ jValue = ucmGetValue (&ucmHandles[ucmIdx], verb, dev, "OutputDspName");
+ if (jValue) json_object_object_add (jResponse, "OutputDspName", jValue);
+
+ jValue = ucmGetValue (&ucmHandles[ucmIdx], verb, dev, "PlaybackPCM");
+ if (jValue) json_object_object_add (jResponse, "PlaybackPCM", jValue);
+
+ jValue = ucmGetValue (&ucmHandles[ucmIdx], verb, mod, "CapturePCM");
+ if (jValue) json_object_object_add (jResponse, "CapturePCM", jValue);
+ }
+ afb_req_success (request, jResponse, NULL);
+
+ OnErrorExit:
+ return;
+}
+
+
+PUBLIC void alsaUseCaseGet (struct afb_req request) {
+ int err, 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;
+
+ ucmIdx = alsaUseCaseOpen (request, &queryValues, TRUE);
+ if (ucmIdx < 0) goto OnErrorExit;
+
+ const char *cardName= ucmHandles[ucmIdx].cardName;
+
+ const char *verb = afb_req_value(request, "verb");
+ const char *mod = afb_req_value(request, "mod");
+ const char *dev = afb_req_value(request, "dev");
+
+ if (dev && mod) {
+ afb_req_fail_f (request, "ucmget-labels", "SndCard devid=[%s] name=[%s] UCM mod+dev incompatible", queryValues.devid, cardName);
+ goto OnErrorExit;
+ }
+
+ // device selection is handle as a modifier
+ if (dev) mod=dev;
+
+ const char *labels = afb_req_value(request, "values");
+ if (!labels) {
+ afb_req_fail_f (request, "ucmget-labels", "SndCard devid=[%s] name=[%s] UCM values name missing", queryValues.devid, cardName);
+ goto OnErrorExit;
+ }
+
+ json_object *jLabels = json_tokener_parse(labels);
+ if (!jLabels) {
+ afb_req_fail_f (request, "ucmget-notjson","labels=%s not a valid json entry", labels);
+ goto OnErrorExit;
+ };
+
+ enum json_type jtype= json_object_get_type(jLabels);
+ switch (jtype) {
+ json_object *jTmp;
+
+ case json_type_array:
+ labelCount = json_object_array_length (jLabels);
+ break;
+
+ case json_type_string:
+ jTmp = json_object_new_array ();
+ labelCount = 1;
+ json_object_array_add (jTmp, jLabels);
+ jLabels=jTmp;
+ break;
+
+ default:
+ afb_req_fail_f (request, "ucmget-notarray","labels=%s not valid JSON array", labels);
+ goto OnErrorExit;
+ }
+
+ for (int idx=0; idx < labelCount; idx++) {
+ json_object *jValue, *jLabel;
+ const char *label ;
+
+ jLabel= json_object_array_get_idx (jLabels, idx);
+ label= json_object_get_string (jLabel);
+ jValue = ucmGetValue (&ucmHandles[ucmIdx], verb, mod, label);
+ if (jValue) json_object_object_add (jResponse, label, jValue);
+ else {
+ json_object_array_add (jWarnings, jLabel);
+ }
+ }
+
+ // 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_to_json_string (jTmp);
+ }
+ afb_req_success (request, jResponse, warnings);
+
+ OnErrorExit:
+ return;
+}
+
+
+PUBLIC void alsaUseCaseReset (struct afb_req request) {
+ int err, ucmIdx;
+ queryValuesT queryValues;
+
+ err = alsaCheckQuery (request, &queryValues);
+ if (err) goto OnErrorExit;
+
+ ucmIdx = alsaUseCaseOpen (request, &queryValues, FALSE);
+ if (ucmIdx < 0) goto OnErrorExit;
+
+ err= snd_use_case_mgr_reset (ucmHandles[ucmIdx].ucm);
+ if (err) {
+ afb_req_fail_f (request, "ucmreset-fail","devid=%s Card Name=%s", queryValues.devid, ucmHandles[ucmIdx].cardName);
+ goto OnErrorExit;
+ }
+
+ afb_req_success (request, NULL, NULL);
+
+ OnErrorExit:
+ return;
+}
+
+PUBLIC void alsaUseCaseClose (struct afb_req request) {
+ int err, ucmIdx;
+ queryValuesT queryValues;
+
+ err = alsaCheckQuery (request, &queryValues);
+ if (err) goto OnErrorExit;
+
+ ucmIdx = alsaUseCaseOpen (request, &queryValues, FALSE);
+ if (ucmIdx < 0) goto OnErrorExit;
+
+ err= snd_use_case_mgr_close (ucmHandles[ucmIdx].ucm);
+ if (err) {
+ afb_req_fail_f (request, "ucmreset-close","devid=%s Card Name=%s", queryValues.devid, ucmHandles[ucmIdx].cardName);
+ goto OnErrorExit;
+ }
+
+ // do not forget to release sound card name string
+ free (ucmHandles[ucmIdx].cardName);
+
+ afb_req_success (request, NULL, NULL);
+
+ OnErrorExit:
+ return;
+}
+
+
diff --git a/AlsaSound/CoreBinding/CMakeLists.txt b/AlsaSound/CoreBinding/CMakeLists.txt
index 0475e72..e14432e 100644
--- a/AlsaSound/CoreBinding/CMakeLists.txt
+++ b/AlsaSound/CoreBinding/CMakeLists.txt
@@ -22,7 +22,7 @@ INCLUDE_DIRECTORIES(${include_dirs})
##################################################
# AlsaBinding
##################################################
-ADD_LIBRARY(alsacore-afb MODULE AlsaAfbBinding.c AlsaLibMapping.c)
+ADD_LIBRARY(alsacore-afb MODULE AlsaCoreBinding.c AlsaCtlSetGet.c AlsaUseCase.c)
SET_TARGET_PROPERTIES(alsacore-afb PROPERTIES
PREFIX ""
diff --git a/README.md b/README.md
index f340955..7de6f53 100644
--- a/README.md
+++ b/README.md
@@ -7,9 +7,17 @@ AFB_daemon dependency on Standard Linux Distributions
-------------------------------------------------------
# handle dependencies > (OpenSuse-42.2, Fedora-25, Ubuntu 16.04.2LTS)
gcc > 4.8
- libsystemd-dev>=222
- openssl-dev
- uuid-dev
+ systemd-devel (libsystemd-dev>=222)
+ libopenssl-devel
+ uuid-devel
+ file-devel (libmagic-dev)
+ libjson-c-devel
+ alsa-devel
+ ElectricFence (BUG should not be mandatory)
+
+ OpenSuse >=42.2
+ zypper in gcc5 gdb gcc5-c++ cmake ElectricFence systemd-devel libopenssl-devel uuid-devel file-devel alsa-devel
+
libmicrohttpd with AGL patches http://iot.bzh/download/public/2016/appfw/libmicrohttpd-0.9.49-agl.tgz
afb-daemon from AGL Gerrit git clone https://gerrit.automotivelinux.org/gerrit/src/app-framework-binder
@@ -17,11 +25,11 @@ AFB_daemon dependency on Standard Linux Distributions
```
# Might want to add following variables into ~/.bashrc
# export CC=gcc-5; export CXX=g++-5 # if using gcc5
- echo "export DEST=\$HOME/opt" >>~/.bashrc
- echo "export LD_LIBRARY_PATH=\$DEST/lib64" >>~/.bashrc
- echo "export LIBRARY_PATH=\$DEST/lib64" >>~/.bashrc
- echo "export PKG_CONFIG_PATH=\$DEST/lib64/pkgconfig" >>~/.bashrc
- echo "export PATH=\$DEST/bin:\$PATH" >>~/.bashrc
+ echo "export DEST=$HOME/opt" >>~/.bashrc
+ echo "export LD_LIBRARY_PATH=$DEST/lib64" >>~/.bashrc
+ echo "export LIBRARY_PATH=$DEST/lib64" >>~/.bashrc
+ echo "export PKG_CONFIG_PATH=$DEST/lib64/pkgconfig" >>~/.bashrc
+ echo "export PATH=$DEST/bin:$PATH" >>~/.bashrc
source ~/.bashrc
# install AGL pached version of LibMicroHttpd
@@ -61,9 +69,15 @@ make install
ls
# Start the binder
-afb-daemon --token=x --ldpaths=$INSTALL_DIR/lib/audio --port=1234 --roothttp=$INSTALL_DIR/htdocs/audio-bindings --verbose
+
+# From Development Tree
+ afb-daemon --verbose --token="" --ldpaths=./build --port=1234 --roothttp=./htdoc
+
+# From $INSTALL_DIR
+ afb-daemon --verbose --token="" --ldpaths=$INSTALL_DIR/lib/audio --port=1234 --roothttp=$INSTALL_DIR/htdocs/audio-bindings
```
-Start a browser on http://localhost:1234?devid=hw:0
+# replace hd:XX with your own sound card ID ex: "hw:0", "hw:PCH", ...
+Start a browser on http://localhost:1234?devid=hw:XX
Start AlsaMixer and change volume you should see event in your browser
```
diff --git a/cd b/cd
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/cd
diff --git a/htdocs/AFB-websock.js b/htdocs/AFB-websock.js
index f904a58..e77ec89 100644
--- a/htdocs/AFB-websock.js
+++ b/htdocs/AFB-websock.js
@@ -58,6 +58,7 @@ var AFB_websocket;
this.ws.onmessage = onmessage.bind(this);
this.onopen = onopen;
this.onabort = onabort;
+ this.onclose = onabort;
}
function onerror(event) {
@@ -132,6 +133,7 @@ var AFB_websocket;
function close() {
this.ws.close();
+ this.onabort();
}
function call(method, request) {
diff --git a/htdocs/AudioBinding.js b/htdocs/AudioBinding.js
index a1267b1..e830861 100644
--- a/htdocs/AudioBinding.js
+++ b/htdocs/AudioBinding.js
@@ -14,13 +14,16 @@
return decodeURIComponent(results[2].replace(/\+/g, " "));
}
- // default soundcard is hw:0
+ // default soundcard is "PCH"
var devid=getParameterByName("devid");
if (!devid) devid="hw:0";
var sndname=getParameterByName("sndname");
if (!sndname) sndname="PCH";
+ var quiet=getParameterByName("quiet");
+ if (!quiet) quiet="99";
+
function init() {
ws = new afb.ws(onopen, onabort);
}
@@ -57,11 +60,13 @@
function send(message) {
var api = document.getElementById("api").value;
var verb = document.getElementById("verb").value;
+ document.getElementById("question").innerHTML = "subscribe: "+api+"/"+verb + " (" + JSON.stringify(message) +")";
ws.call(api+"/"+verb, {data:message}).then(replyok, replyerr);
}
function callbinder(api, verb, query) {
console.log ("subscribe api="+api+" verb="+verb+" query=" +query);
+ document.getElementById("question").innerHTML = "apicall: " + api+"/"+verb +" ("+ JSON.stringify(query)+")";
ws.call(api+"/"+verb, query).then(replyok, replyerr);
} \ No newline at end of file
diff --git a/htdocs/README.md b/htdocs/README.md
index 79b57d8..bb14b7e 100644
--- a/htdocs/README.md
+++ b/htdocs/README.md
@@ -3,5 +3,5 @@
------------------------------------------------------------------------
# Load bindings directly from development tree for debug
- afb-daemon --token=x --ldpaths=build/Alsa/core-binding --port=1234 --roothttp=htdocs --verbose
+ afb-daemon --verbose --verbose --token="" --ldpaths=build --port=1234 --roothttp=htdocs
diff --git a/htdocs/alsa-core.html b/htdocs/alsa-core.html
index 2987832..9df5d06 100644
--- a/htdocs/alsa-core.html
+++ b/htdocs/alsa-core.html
@@ -4,22 +4,36 @@
<script type="text/javascript" src="AFB-websock.js"></script>
<script type="text/javascript" src="AudioBinding.js"></script>
+
+<b>http://localhost:1234/alsa-core.html?devid=hw:xx</b>
<body onload="init();">
<h1>Hello world test</h1>
- <button id="connected">Binder WS Fail</button></li>
+ <button id="connected" onclick="init()">Binder WS Fail</button></li>
<br>
<ol>
<li><a href="api/alsacore/getinfo">getinfo: List Sound Cards</a>
- <li><a href="api/alsacore/getinfo?devid=hw:0">Card info about hw:0</a>
- <li><a href="api/alsacore/getctls?devid=hw:0">List All Controls for hw:0 (quiet)</a>
- <li><a href="api/alsacore/getctls?devid=hw:0&quiet=0">List controls for hw:0 (verbose)</a>
- <li><a href="api/alsacore/getctls?devid=hw:0&numids=[1,2]&quiet=0">List Controls 1+2 for hw:0 (verbose)</a>
- <li><a href="api/alsacore/getctls?devid=hw:0&numids=1&quiet=0">return control numid=1 for hw:0</a>
+ <li><button onclick="callbinder('alsacore','getinfo', {quiet:quiet})">Get All Sound Card info</button></li>
+ <li><button onclick="callbinder('alsacore','getinfo', {devid:devid, quiet:quiet})">Get Sound Card info devid=xx</button></li>
+ <li><button onclick="callbinder('alsacore','getctls', {devid:devid, quiet:quiet})">Get all Alsa Ctls for devid=xx</button></li>
+ <li><button onclick="callbinder('alsacore','getctls', {devid:devid, quiet:quiet, numids:[1,2]})">Get Alsa Ctls numid=1+2</button></li>
+ <li><button onclick="callbinder('alsacore','getctls', {devid:devid, quiet:quiet, numids:1})">Get Alsa Ctl numid=1</button></li>
+ <br>
+ <li><button onclick="callbinder('alsacore','ucmquery', {devid:devid, quiet:quiet})">List UCM verbs</button></li>
+ <li><button onclick="callbinder('alsacore','ucmset' , {devid:devid, quiet:quiet, verb:'HiFi'})">Set UCM HiFi</button></li>
+ <li><button onclick="callbinder('alsacore','ucmset' , {devid:devid, quiet:quiet, verb:'HiFi', dev:'Headphone'})">Set UCM HiFi+Headphone</button></li>
+ <li><button onclick="callbinder('alsacore','ucmset' , {devid:devid, quiet:quiet, verb:'HiFi', dev:'Headphone', mod:'RecordMedia'})">Set UCM HiFi+Headphone+RecordMedia</button></li>
<br>
- <li><button onclick="callbinder('alsacore','subscribe', {devid:devid})">Subscribe AlsaCtl Events</button></li>
+ <li><button onclick="callbinder('alsacore','ucmget' , {devid:devid, quiet:quiet, values:['OutputDspName','PlaybackPCM','CapturePCM']})">Get UCM OutputDspName+PlaybackPCM+CapturePCM (after SET UCM)</button></li>
<br>
+ <li><button onclick="callbinder('alsacore','subscribe', {devid:devid})">Subscribe AlsaCtl Events</button></li>
+ <br>
+ </ol>
+
<div id="main" style="visibility:hidden">
- Server says... <div id="output"></div>
- Events: <div id="outevt"></div>
+ <ol>
+ <li>Question <div id="question"></div>
+ <li>Response <div id="output"></div>
+ <li>Events: <div id="outevt"></div>
+ </ol>
</div>
diff --git a/nbproject/configurations.xml b/nbproject/configurations.xml
index 6db5cb9..dbdc7fc 100644
--- a/nbproject/configurations.xml
+++ b/nbproject/configurations.xml
@@ -65,16 +65,6 @@
<preBuildFirst>true</preBuildFirst>
</preBuild>
</makefileType>
- <item path="AlsaSound/HALayer/Shared/ShareHalLib.h"
- ex="false"
- tool="3"
- flavor2="0">
- </item>
- <item path="AlsaSound/HALayer/Shared/SharedHalLib.h"
- ex="false"
- tool="3"
- flavor2="0">
- </item>
<item path="AlsaSound/HALayer/include/AlsaHalIface.h"
ex="false"
tool="3"
@@ -85,14 +75,6 @@
tool="3"
flavor2="0">
</item>
- <item path="Common/AudioCommonLib.h" ex="false" tool="3" flavor2="0">
- </item>
- <item path="Common/include/AudioCommonLib.h" ex="false" tool="3" flavor2="0">
- </item>
- <item path="Common/include/ShareHalLib.h" ex="false" tool="3" flavor2="0">
- </item>
- <item path="Common/include/SharedHalLib.h" ex="false" tool="3" flavor2="0">
- </item>
<item path="MostVolume/DeviceContainer.cpp" ex="false" tool="1" flavor2="0">
</item>
<item path="MostVolume/DeviceValue.cpp" ex="false" tool="1" flavor2="0">