summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--AlsaSound/CoreBinding/AlsaCoreBinding.c5
-rw-r--r--AlsaSound/CoreBinding/AlsaCoreBinding.h2
-rw-r--r--AlsaSound/CoreBinding/AlsaCtlSetGet.c57
-rw-r--r--htdocs/alsa-core.html20
4 files changed, 60 insertions, 24 deletions
diff --git a/AlsaSound/CoreBinding/AlsaCoreBinding.c b/AlsaSound/CoreBinding/AlsaCoreBinding.c
index 19a7f3b..d866daf 100644
--- a/AlsaSound/CoreBinding/AlsaCoreBinding.c
+++ b/AlsaSound/CoreBinding/AlsaCoreBinding.c
@@ -37,10 +37,11 @@ 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= "getctls", .session= AFB_SESSION_NONE, .callback= alsaGetCtls, .info= "Get Controls from selected sndcard" },
+ { .name= "setctls", .session= AFB_SESSION_NONE, .callback= alsaSetCtls, .info= "Set Controls from selected sndcard" },
{ .name= "subscribe", .session= AFB_SESSION_NONE, .callback= alsaSubcribe, .info= "Subscribe to events from selected sndcard" },
{ .name= "getcardid", .session= AFB_SESSION_NONE, .callback= alsaGetCardId, .info= "Get CardId from its short/long name" },
- { .name= "registerHal",.session= AFB_SESSION_NONE,.callback= alsaRegisterHal, .info= "Register Hal CardName/ApiPrefix" },
+ { .name= "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" },
diff --git a/AlsaSound/CoreBinding/AlsaCoreBinding.h b/AlsaSound/CoreBinding/AlsaCoreBinding.h
index 0e5f84a..2852384 100644
--- a/AlsaSound/CoreBinding/AlsaCoreBinding.h
+++ b/AlsaSound/CoreBinding/AlsaCoreBinding.h
@@ -42,7 +42,7 @@ PUBLIC int alsaCheckQuery (struct afb_req request, queryValuesT *queryValues);
// AlseCoreSetGet exports
PUBLIC void alsaGetInfo (struct afb_req request);
PUBLIC void alsaGetCtls(struct afb_req request);
-PUBLIC void alsaSetCtrl(struct afb_req request);
+PUBLIC void alsaSetCtls(struct afb_req request);
PUBLIC void alsaSubcribe (struct afb_req request);
PUBLIC void alsaGetCardId (struct afb_req request);
PUBLIC void alsaRegisterHal (struct afb_req request);
diff --git a/AlsaSound/CoreBinding/AlsaCtlSetGet.c b/AlsaSound/CoreBinding/AlsaCtlSetGet.c
index a6cd45b..cd21724 100644
--- a/AlsaSound/CoreBinding/AlsaCtlSetGet.c
+++ b/AlsaSound/CoreBinding/AlsaCtlSetGet.c
@@ -71,8 +71,9 @@ PUBLIC void NumidsListParse (queryValuesT *queryValues, ctlRequestT *ctlRequest)
ctlRequest[idx].jValues = NULL;
ctlRequest[idx].used=0;
-
- switch (json_object_get_type(ctlRequest[idx].jToken)) {
+ 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
@@ -98,7 +99,20 @@ PUBLIC void NumidsListParse (queryValuesT *queryValues, ctlRequestT *ctlRequest)
// Value is an int or an array with potentially multiple subvalues
ctlRequest[idx].jValues = jValues;
}
- default:
+ 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)) {
+ NOTICE (afbIface,"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;
+ }
+
+
+ default:
ctlRequest[idx].used=-1;
}
}
@@ -488,17 +502,27 @@ STATIC int alsaSetSingleCtl (snd_ctl_t *ctlDev, snd_ctl_elem_id_t *elemId, ctlRe
goto OnErrorExit;
}
- count = snd_ctl_elem_info_get_count (elemInfo);
- if (!json_object_is_type (ctlRequest->jValues, json_type_array)) {
- length=1;
- valueIsArray=0;
- } else {
- length = json_object_array_length (ctlRequest->jValues);
- valueIsArray=1;
+ count = snd_ctl_elem_info_get_count (elemInfo);
+ if (count == 0) goto OnErrorExit;
+
+ enum json_type jtype= json_object_get_type(ctlRequest->jValues);
+ switch (jtype) {
+ case json_type_array:
+ length = json_object_array_length (ctlRequest->jValues);
+ valueIsArray=1;
+ break;
+ case json_type_int:
+ length=1;
+ valueIsArray=0;
+ break;
+ default:
+ count =0;
+ break;
}
+
if (count == 0 || count < length) {
- NOTICE (afbIface, "Invalid Values ALSA NUMID=%d Values=[%s] wanted count=%d", ctlRequest->numId, json_object_to_json_string(ctlRequest->jValues), count);
+ NOTICE (afbIface, "Invalid values NUMID='%d' Values='%s' count='%d' wanted='%d'", ctlRequest->numId, json_object_to_json_string(ctlRequest->jValues), length, count);
goto OnErrorExit;
}
@@ -517,9 +541,10 @@ STATIC int alsaSetSingleCtl (snd_ctl_t *ctlDev, snd_ctl_elem_id_t *elemId, ctlRe
value= json_object_get_int (element);
snd_ctl_elem_value_set_integer(elemData, index, value);
}
-
- if ((err = snd_ctl_elem_write(ctlDev, elemData)) < 0) {
- NOTICE (afbIface, "Fail to write ALSA NUMID=%d Values=[%s]", ctlRequest->numId, json_object_to_json_string(ctlRequest->jValues));
+
+ err = snd_ctl_elem_write(ctlDev, elemData);
+ if (err < 0) {
+ NOTICE (afbIface, "Fail to write ALSA NUMID=%d Values=[%s] Error=%s", ctlRequest->numId, json_object_to_json_string(ctlRequest->jValues), snd_strerror(err));
goto OnErrorExit;
}
@@ -556,7 +581,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);
+ json_object_object_add (ctlRequest->jValues,"id" , 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)));
@@ -597,7 +622,7 @@ STATIC int alsaGetSingleCtl (snd_ctl_t *ctlDev, snd_ctl_elem_id_t *elemId, ctlRe
break;
}
}
- json_object_object_add (ctlRequest->jValues,"value",jsonValuesCtl);
+ json_object_object_add (ctlRequest->jValues,"val",jsonValuesCtl);
if (!quiet) { // in simple mode do not print usable values
json_object *jsonClassCtl = json_object_new_object();
diff --git a/htdocs/alsa-core.html b/htdocs/alsa-core.html
index 9df5d06..6483180 100644
--- a/htdocs/alsa-core.html
+++ b/htdocs/alsa-core.html
@@ -5,7 +5,11 @@
<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>
+<b> references</b>
+ <ol>
+ <li>http://localhost:1234/alsa-core.html?devid=hw:xx</li>
+ <li>amixer -D hw:PCH controls</li>
+ </ol>
<body onload="init();">
<h1>Hello world test</h1>
@@ -16,15 +20,21 @@
<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','getctls', {devid:devid, quiet:quiet, numids:[1,2]})">Get Alsa Ctls numids:[1,2]</button></li>
+ <li><button onclick="callbinder('alsacore','getctls', {devid:devid, quiet:quiet, numids:17})">Get Alsa Ctl numids:17</button></li>
+ <br>
+ <li><button onclick="callbinder('alsacore','setctls', {devid:devid, quiet:quiet, numids:[[17,20]]})">Set Alsa Ctl numid:[[17,20]]</button></li>
+ <li><button onclick="callbinder('alsacore','setctls', {devid:devid, quiet:quiet, numids:[{id:17,val:50}]})">Set Alsa Ctl numid:[{id:17,val:50}]}</button></li>
+ <li><button onclick="callbinder('alsacore','setctls', {devid:devid, quiet:quiet, numids:[[1,[20,20]]]})">Set Alsa Ctl numids:[[1,[20,20]]]</button></li>
+ <li><button onclick="callbinder('alsacore','setctls', {devid:devid, quiet:quiet, numids:[{id:1,val:[50,50]}]})">Set Alsa Ctl numids:[{id:1,val:[50,50]}]</button></li>
+ <li><button onclick="callbinder('alsacore','setctls', {devid:devid, quiet:quiet, numids:[{id:1,val:[50,50]}, {id:17,val:50,50}]})">Set Alsa Ctl numids:[{id:1,val:[50,50]}, {id:17,val:50,50}]</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','ucmget' , {devid:devid, quiet:quiet, values:['OutputDspName','PlaybackPCM','CapturePCM']})">Get UCM OutputDspName+PlaybackPCM+CapturePCM (after SET UCM)</button></li>
+ <li><button onclick="callbinder('alsacore','ucmget' , {devid:devid, quiet:quiet, values:['OutputDspName','PlaybackPCM','CapturePCM']})">Get UCM OutputDspName+PlaybackPCM+CapturePCM (SET UCM)</button></li>
<br>
<li><button onclick="callbinder('alsacore','subscribe', {devid:devid})">Subscribe AlsaCtl Events</button></li>
<br>