summaryrefslogtreecommitdiffstats
path: root/4a-hal
diff options
context:
space:
mode:
authorJonathan Aillet <jonathan.aillet@iot.bzh>2018-06-18 15:51:33 +0200
committerJonathan Aillet <jonathan.aillet@iot.bzh>2018-10-08 15:53:53 +0200
commit2a283187230646b2537c1fee1f6dbe1239174d7c (patch)
tree45ae35f3dc3fd8c740c6e40e2737fd26ef6c30aa /4a-hal
parentab16006968af9c01139eea48374708c5a7148503 (diff)
Optimize alsacore event handler
Optimize alsacore event handler by avoiding generating a string to detect an alsacore event. Change-Id: I7498e99741b2b7095076016143ec8be6520ee122 Signed-off-by: Jonathan Aillet <jonathan.aillet@iot.bzh>
Diffstat (limited to '4a-hal')
-rw-r--r--4a-hal/4a-hal-controllers/4a-hal-controllers-cb.c32
1 files changed, 14 insertions, 18 deletions
diff --git a/4a-hal/4a-hal-controllers/4a-hal-controllers-cb.c b/4a-hal/4a-hal-controllers/4a-hal-controllers-cb.c
index cc7b7ff..acf3ce0 100644
--- a/4a-hal/4a-hal-controllers/4a-hal-controllers-cb.c
+++ b/4a-hal/4a-hal-controllers/4a-hal-controllers-cb.c
@@ -37,11 +37,7 @@
void HalCtlsDispatchApiEvent(afb_dynapi *apiHandle, const char *evtLabel, json_object *eventJ)
{
- int numid, idx;
-
- char cardIdString[6];
-
- char *alsaCoreLabel;
+ int numid, idx = 0, cardidx;
CtlConfigT *ctrlConfig;
CtlSourceT source;
@@ -65,17 +61,19 @@ void HalCtlsDispatchApiEvent(afb_dynapi *apiHandle, const char *evtLabel, json_o
return;
}
- snprintf(cardIdString, 6, "hw:%i", currentHalData->sndCardId);
- currentHalAlsaCtlsT = currentHalData->ctlHalSpecificData->ctlHalAlsaMapT;
+ // Extract sound card index from event
+ while(evtLabel[idx] != '\0' && evtLabel[idx] != ':')
+ idx++;
- if(asprintf(&alsaCoreLabel, "%s/%s", ALSACORE_API, cardIdString) < 0) {
- AFB_ApiError(apiHandle, "%s: Didn't succeed to generate string for alascore events catching", __func__);
- return;
- }
+ if(evtLabel[idx] != '\0' &&
+ sscanf(&evtLabel[idx + 1], "%d", &cardidx) == 1 &&
+ currentHalData->sndCardId == cardidx) {
+ if(wrap_json_unpack(eventJ, "{s:i s:o !}", "id", &numid, "val", &valuesJ)) {
+ AFB_ApiError(apiHandle, "%s: Invalid Alsa Event label=%s value=%s", __func__, evtLabel, json_object_get_string(eventJ));
+ return;
+ }
- if(strcmp(evtLabel, alsaCoreLabel) == 0 &&
- ! wrap_json_unpack(eventJ, "{s:i s:o !}", "id", &numid, "val", &valuesJ)) {
- free(alsaCoreLabel);
+ currentHalAlsaCtlsT = currentHalData->ctlHalSpecificData->ctlHalAlsaMapT;
// Search for corresponding numid in halCtls, if found, launch callback (if available)
for(idx = 0; idx < currentHalAlsaCtlsT->ctlsCount; idx++) {
@@ -107,8 +105,6 @@ void HalCtlsDispatchApiEvent(afb_dynapi *apiHandle, const char *evtLabel, json_o
return;
}
- free(alsaCoreLabel);
-
AFB_ApiNotice(apiHandle,
"%s: not an alsacore event '%s' [msg=%s]",
__func__,
@@ -231,8 +227,8 @@ int HalCtlsHandleOneHalMapObject(AFB_ApiT apiHandle, char *cardId, struct CtlHal
if(alsaMap->ctl.alsaCtlCreation) {
if(HalCtlsCreateAlsaCtl(apiHandle, cardId, &alsaMap->ctl)) {
AFB_ApiError(apiHandle,
- "%s: An error happened when trying to create a new alsa control",
- __func__);
+ "%s: An error happened when trying to create a new alsa control",
+ __func__);
return -1;
}
}