summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonathan Aillet <jonathan.aillet@iot.bzh>2019-06-19 14:26:58 +0200
committerJonathan Aillet <jonathan.aillet@iot.bzh>2019-06-25 11:18:00 +0200
commit675c85ec8246780cd18a68151bcdb3e596794ee7 (patch)
tree1ecf1be685655ace80a5e4c5bc48592049c83f1a
parentf29775f7da003bbadb44dd82d8b3974aa1e59274 (diff)
Use a dynamic allocation for halmap data storage
Use a dynamically allocated structure to store properties about ALSA controls (halmap). BUG-AGL: SPEC-2329 Change-Id: I691648452d6c950d201bc25977a493608fede197 Signed-off-by: Jonathan Aillet <jonathan.aillet@iot.bzh>
-rw-r--r--lib/4a-hal-utilities/4a-hal-utilities-alsa-data.h2
-rw-r--r--lib/4a-hal-utilities/4a-hal-utilities-data.c11
-rw-r--r--src/4a-internals-hal/4a-internals-hal-alsacore-link.c29
-rw-r--r--src/4a-internals-hal/4a-internals-hal-cb.c71
4 files changed, 82 insertions, 31 deletions
diff --git a/lib/4a-hal-utilities/4a-hal-utilities-alsa-data.h b/lib/4a-hal-utilities/4a-hal-utilities-alsa-data.h
index 88b3e44..d548c73 100644
--- a/lib/4a-hal-utilities/4a-hal-utilities-alsa-data.h
+++ b/lib/4a-hal-utilities/4a-hal-utilities-alsa-data.h
@@ -53,7 +53,7 @@ struct InternalHalAlsaCtl {
int numid;
int value;
- struct InternalHalAlsaCtlProperties alsaCtlProperties;
+ struct InternalHalAlsaCtlProperties *alsaCtlProperties;
struct InternalHalAlsaCtlProperties *alsaCtlCreation;
};
diff --git a/lib/4a-hal-utilities/4a-hal-utilities-data.c b/lib/4a-hal-utilities/4a-hal-utilities-data.c
index d7ae1f6..cebc223 100644
--- a/lib/4a-hal-utilities/4a-hal-utilities-data.c
+++ b/lib/4a-hal-utilities/4a-hal-utilities-data.c
@@ -878,6 +878,17 @@ void HalUtlFreeSelectedHalMapDataAllocation(struct InternalHalAlsaMap *halMapDat
free(halMapDataToFree->ctl.name);
+ if(halMapDataToFree->ctl.alsaCtlCreation) {
+ free(halMapDataToFree->ctl.alsaCtlCreation->enums);
+ free(halMapDataToFree->ctl.alsaCtlCreation->dbscale);
+ free(halMapDataToFree->ctl.alsaCtlCreation);
+ }
+ else if(halMapDataToFree->ctl.alsaCtlProperties) {
+ free(halMapDataToFree->ctl.alsaCtlProperties->enums);
+ free(halMapDataToFree->ctl.alsaCtlProperties->dbscale);
+ free(halMapDataToFree->ctl.alsaCtlProperties);
+ }
+
free(halMapDataToFree);
}
diff --git a/src/4a-internals-hal/4a-internals-hal-alsacore-link.c b/src/4a-internals-hal/4a-internals-hal-alsacore-link.c
index e1ad6dd..81e60f9 100644
--- a/src/4a-internals-hal/4a-internals-hal-alsacore-link.c
+++ b/src/4a-internals-hal/4a-internals-hal-alsacore-link.c
@@ -295,24 +295,28 @@ int InternalHalUpdateAlsaCtlProperties(afb_api_t apiHandle, char *cardId, struct
if(err) {
return err;
}
+ else if(! currentAlsaCtl->alsaCtlProperties) {
+ AFB_API_ERROR(apiHandle, "Data structure to store alsa control properties is not allocated");
+ err = -9;
+ }
// TBD JAI : get dblinear/dbminmax/... values
else if(wrap_json_unpack(returnedDataJ,
"{s:i s:s s:{s?:i s?:i s?:i s?:i s?:i}}",
"id", &currentAlsaCtl->numid,
"name", &name,
"ctl",
- "type", (int *) &currentAlsaCtl->alsaCtlProperties.type,
- "count", &currentAlsaCtl->alsaCtlProperties.count,
- "min", &currentAlsaCtl->alsaCtlProperties.minval,
- "max", &currentAlsaCtl->alsaCtlProperties.maxval,
- "step", &currentAlsaCtl->alsaCtlProperties.step)) {
+ "type", (int *) &currentAlsaCtl->alsaCtlProperties->type,
+ "count", &currentAlsaCtl->alsaCtlProperties->count,
+ "min", &currentAlsaCtl->alsaCtlProperties->minval,
+ "max", &currentAlsaCtl->alsaCtlProperties->maxval,
+ "step", &currentAlsaCtl->alsaCtlProperties->step)) {
AFB_API_ERROR(apiHandle,
"Didn't succeed to get control %i properties on device '%s' : '%s'",
currentAlsaCtl->numid,
cardId,
json_object_get_string(returnedDataJ));
- err = -9;
+ err = -10;
}
else {
currentAlsaCtl->name = strdup(name);
@@ -578,6 +582,11 @@ void InternalHalActionOnAlsaCtl(afb_req_t request)
return;
}
+ if(! currentAlsaCtl->ctl.alsaCtlProperties) {
+ afb_req_fail(request, "alsa_control_not_available", "Alsa control is not available");
+ return;
+ }
+
snprintf(cardIdString, 6, "hw:%i", currentHalData->sndCardId);
if(InternalHalGetAlsaCtlValues(apiHandle, cardIdString, &currentAlsaCtl->ctl, &previousControlValuesJ)) {
@@ -585,7 +594,7 @@ void InternalHalActionOnAlsaCtl(afb_req_t request)
return;
}
else if(InternalHalConvertJsonValues(apiHandle,
- &currentAlsaCtl->ctl.alsaCtlProperties,
+ currentAlsaCtl->ctl.alsaCtlProperties,
previousControlValuesJ,
&normalizedPreviousControlValuesJ,
CONVERSION_ALSACORE_TO_NORMALIZED)) {
@@ -632,7 +641,7 @@ void InternalHalActionOnAlsaCtl(afb_req_t request)
if((! json_object_is_type(valueJ, json_type_string)) &&
InternalHalConvertJsonValues(apiHandle,
- &currentAlsaCtl->ctl.alsaCtlProperties,
+ currentAlsaCtl->ctl.alsaCtlProperties,
valueJ,
&convertedJ,
CONVERSION_NORMALIZED_TO_ALSACORE)) {
@@ -646,7 +655,7 @@ void InternalHalActionOnAlsaCtl(afb_req_t request)
}
else if(json_object_is_type(valueJ, json_type_string) &&
InternalHalChangePreviousValuesUsingJson(apiHandle,
- &currentAlsaCtl->ctl.alsaCtlProperties,
+ currentAlsaCtl->ctl.alsaCtlProperties,
valueJ,
previousControlValuesJ,
&convertedJ)) {
@@ -682,7 +691,7 @@ void InternalHalActionOnAlsaCtl(afb_req_t request)
return;
}
else if(InternalHalConvertJsonValues(apiHandle,
- &currentAlsaCtl->ctl.alsaCtlProperties,
+ currentAlsaCtl->ctl.alsaCtlProperties,
appliedControlValuesJ,
&normalizedAppliedControlValuesJ,
CONVERSION_ALSACORE_TO_NORMALIZED)) {
diff --git a/src/4a-internals-hal/4a-internals-hal-cb.c b/src/4a-internals-hal/4a-internals-hal-cb.c
index 0050f11..19a1d4a 100644
--- a/src/4a-internals-hal/4a-internals-hal-cb.c
+++ b/src/4a-internals-hal/4a-internals-hal-cb.c
@@ -91,7 +91,8 @@ void InternalHalDispatchApiEvent(afb_api_t apiHandle, const char *evtLabel, json
// Search for corresponding numid in ALSA controls list, if found, launch callback (if available)
cds_list_for_each_entry(currentHalMapControl, &currentHalData->internalHalData->halMapListHead, node) {
- if(currentHalMapControl->ctl.numid == numid) {
+ if(currentHalMapControl->ctl.alsaCtlProperties &&
+ currentHalMapControl->ctl.numid == numid) {
if(currentHalMapControl->action) {
memset(&source, 0, sizeof(CtlSourceT));
source.uid = currentHalMapControl->action->uid;
@@ -115,7 +116,7 @@ void InternalHalDispatchApiEvent(afb_api_t apiHandle, const char *evtLabel, json
if(! currentHalMapControl->alsaControlEvent ||
InternalHalConvertJsonValues(apiHandle,
- &currentHalMapControl->ctl.alsaCtlProperties,
+ currentHalMapControl->ctl.alsaCtlProperties,
valuesJ,
&normalizedValuesJ,
CONVERSION_ALSACORE_TO_NORMALIZED) ||
@@ -219,7 +220,10 @@ int InternalHalProcessOneHalMapObject(afb_api_t apiHandle, struct InternalHalAls
"info", &info,
"alsa", &alsaJ,
"action", &action)) {
- AFB_API_ERROR(apiHandle, "Parsing error, map should only contains [label]|[uid]|[tag]|[info]|[alsa]|[action] in : '%s'", json_object_get_string(halMapJ));
+ AFB_API_ERROR(apiHandle,
+ "Parsing error, map should only contains "
+ "[label]|[uid]|[tag]|[info]|[alsa]|[action] in : '%s'",
+ json_object_get_string(halMapJ));
return -1;
}
@@ -242,7 +246,10 @@ int InternalHalProcessOneHalMapObject(afb_api_t apiHandle, struct InternalHalAls
"numid", &halMapData->ctl.numid,
"value", &halMapData->ctl.value,
"create", &createAlsaCtlJ)) {
- AFB_API_ERROR(apiHandle, "Parsing error, alsa json should only contains [name]|[numid]||[value]|[create] in : '%s'", json_object_get_string(alsaJ));
+ AFB_API_ERROR(apiHandle,
+ "Parsing error, alsa json should only contains "
+ "[name]|[numid]||[value]|[create] in : '%s'",
+ json_object_get_string(alsaJ));
return -4;
}
@@ -255,7 +262,12 @@ int InternalHalProcessOneHalMapObject(afb_api_t apiHandle, struct InternalHalAls
}
if(createAlsaCtlJ) {
- halMapData->ctl.alsaCtlCreation = &halMapData->ctl.alsaCtlProperties;
+ halMapData->ctl.alsaCtlCreation = calloc(1, sizeof(struct InternalHalAlsaCtlProperties));
+ if(! halMapData->ctl.alsaCtlCreation) {
+ AFB_API_ERROR(apiHandle,
+ "Didn't succeed to allocate alsa properties data structure for control to create");
+ return -6;
+ }
if(wrap_json_unpack(createAlsaCtlJ,
"{s:s s:i s:i s:i s:i !}",
@@ -264,8 +276,11 @@ int InternalHalProcessOneHalMapObject(afb_api_t apiHandle, struct InternalHalAls
"minval", &halMapData->ctl.alsaCtlCreation->minval,
"maxval", &halMapData->ctl.alsaCtlCreation->maxval,
"step", &halMapData->ctl.alsaCtlCreation->step)) {
- AFB_API_ERROR(apiHandle, "Parsing error, alsa creation json should only contains [type]|[count]|[minval]|[maxval]|[step] in : '%s'", json_object_get_string(alsaJ));
- return -6;
+ AFB_API_ERROR(apiHandle,
+ "Parsing error, alsa creation json should only contains "
+ "[type]|[count]|[minval]|[maxval]|[step] in : '%s'",
+ json_object_get_string(alsaJ));
+ return -7;
}
if(typename) {
@@ -275,7 +290,7 @@ int InternalHalProcessOneHalMapObject(afb_api_t apiHandle, struct InternalHalAls
"Couldn't get alsa type from string %s in : '%s'",
typename,
json_object_get_string(alsaJ));
- return -7;
+ return -8;
}
}
@@ -288,13 +303,13 @@ int InternalHalProcessOneHalMapObject(afb_api_t apiHandle, struct InternalHalAls
halMapData->ctl.name,
halMapData->ctl.numid,
json_object_get_string(alsaJ));
- return -8;
+ return -9;
}
else if(! halMapData->ctl.name && halMapData->ctl.numid <= 0) {
AFB_API_ERROR(apiHandle,
"Need at least a control name or a control uid in alsa object : '%s'",
json_object_get_string(alsaJ));
- return -9;
+ return -10;
}
if(action)
@@ -369,10 +384,22 @@ int InternalHalHandleOneHalMapObject(afb_api_t apiHandle, char *cardId, struct I
AFB_API_ERROR(apiHandle, "An error happened when trying to create a new alsa control");
return -2;
}
+ halMapData->ctl.alsaCtlProperties = halMapData->ctl.alsaCtlCreation;
}
- else if(InternalHalUpdateAlsaCtlProperties(apiHandle, cardId, &halMapData->ctl)) {
- AFB_API_ERROR(apiHandle, "An error happened when trying to get existing alsa control info");
- return -3;
+ else {
+ halMapData->ctl.alsaCtlProperties = calloc(1, sizeof(struct InternalHalAlsaCtlProperties));
+ if(! halMapData->ctl.alsaCtlProperties) {
+ AFB_API_ERROR(apiHandle,
+ "Didn't succeed to allocate alsa properties data structure for control");
+ return -3;
+ }
+
+ if(InternalHalUpdateAlsaCtlProperties(apiHandle, cardId, &halMapData->ctl)) {
+ AFB_API_ERROR(apiHandle, "An error happened when trying to get existing alsa control info");
+ free(halMapData->ctl.alsaCtlProperties);
+ halMapData->ctl.alsaCtlProperties = NULL;
+ return -4;
+ }
}
if(halMapData->actionJ) {
@@ -381,7 +408,7 @@ int InternalHalHandleOneHalMapObject(afb_api_t apiHandle, char *cardId, struct I
AFB_API_ERROR(apiHandle,
"Didn't succeed to allocate structure used to store action to perform "
"when the corresponding ALSA control is detected");
- return -4;
+ return -5;
}
if(ActionLoadOne(apiHandle, toLoadAction, halMapData->actionJ, 0)) {
@@ -389,7 +416,7 @@ int InternalHalHandleOneHalMapObject(afb_api_t apiHandle, char *cardId, struct I
"Didn't succeed to load action using alsa object : '%s'",
json_object_get_string(halMapData->actionJ));
free(toLoadAction);
- return -5;
+ return -6;
}
halMapData->action = toLoadAction;
@@ -397,7 +424,7 @@ int InternalHalHandleOneHalMapObject(afb_api_t apiHandle, char *cardId, struct I
if(InternalHalSubscribeToAlsaCardEvent(apiHandle, cardId)) {
AFB_API_ERROR(apiHandle, "Error when trying to subscribe to alsacore event for audio card '%s'", cardId);
- return -6;
+ return -7;
}
if(halMapData->ctl.value) {
@@ -405,14 +432,18 @@ int InternalHalHandleOneHalMapObject(afb_api_t apiHandle, char *cardId, struct I
valueJ = json_object_new_int(halMapData->ctl.value);
if(! valueJ) {
AFB_API_ERROR(apiHandle, "Didn't succeed to allocate ALSA control value json string");
- return -7;
+ return -8;
}
err = 0;
- if(InternalHalConvertJsonValues(apiHandle, &halMapData->ctl.alsaCtlProperties, valueJ, &convertedValueJ, CONVERSION_NORMALIZED_TO_ALSACORE)) {
+ if(InternalHalConvertJsonValues(apiHandle,
+ halMapData->ctl.alsaCtlProperties,
+ valueJ,
+ &convertedValueJ,
+ CONVERSION_NORMALIZED_TO_ALSACORE)) {
AFB_API_ERROR(apiHandle, "Error when trying to convert initiate value json '%s'", json_object_get_string(valueJ));
- err = -8;
+ err = -9;
}
else if(InternalHalSetAlsaCtlValue(apiHandle, cardId, halMapData->ctl.numid, convertedValueJ)) {
AFB_API_ERROR(apiHandle,
@@ -420,7 +451,7 @@ int InternalHalHandleOneHalMapObject(afb_api_t apiHandle, char *cardId, struct I
halMapData->ctl.numid,
cardId,
json_object_get_string(valueJ));
- err = -9;
+ err = -10;
}
json_object_put(valueJ);