aboutsummaryrefslogtreecommitdiffstats
path: root/4a-hal/4a-hal-controllers/4a-hal-controllers-mixer-link.c
diff options
context:
space:
mode:
authorJonathan Aillet <jonathan.aillet@iot.bzh>2019-01-10 09:49:24 +0100
committerJonathan Aillet <jonathan.aillet@iot.bzh>2019-01-28 15:38:43 +0100
commite3f74a9f59c05df601aa26554612fc68901c1646 (patch)
treede604ee593e46f57595a068dc261e048defd7668 /4a-hal/4a-hal-controllers/4a-hal-controllers-mixer-link.c
parent4f44ee8f17789ac27cd1e29a451ac450c7dbeb06 (diff)
Use linked-list to handle hal stream list
Use linked-list instead of an array to handle hal stream list. Usefull to add/remove dynamic stream (e.g. bluetooth). Change-Id: I39bbf0f16941f1c4642c916fdc5143a683c6460c Signed-off-by: Jonathan Aillet <jonathan.aillet@iot.bzh>
Diffstat (limited to '4a-hal/4a-hal-controllers/4a-hal-controllers-mixer-link.c')
-rw-r--r--4a-hal/4a-hal-controllers/4a-hal-controllers-mixer-link.c135
1 files changed, 82 insertions, 53 deletions
diff --git a/4a-hal/4a-hal-controllers/4a-hal-controllers-mixer-link.c b/4a-hal/4a-hal-controllers/4a-hal-controllers-mixer-link.c
index fd42899..72f62dd 100644
--- a/4a-hal/4a-hal-controllers/4a-hal-controllers-mixer-link.c
+++ b/4a-hal/4a-hal-controllers/4a-hal-controllers-mixer-link.c
@@ -37,9 +37,9 @@
* HAL controllers handle mixer calls functions *
******************************************************************************/
-int HalCtlsHandleMixerData(AFB_ApiT apiHandle, struct CtlHalMixerDataT *currentMixerDataT, json_object *currentDataJ, enum MixerDataType dataType)
+int HalCtlsHandleMixerData(AFB_ApiT apiHandle, struct CtlHalMixerData **firstMixerData, json_object *currentDataJ, enum MixerDataType dataType)
{
- int idx, verbStart, size;
+ int idx, mixerDataNb, verbStart, size;
int err = (int) MIXER_NO_ERROR;
char *currentDataVerbName, *currentStreamCardId;
@@ -47,23 +47,23 @@ int HalCtlsHandleMixerData(AFB_ApiT apiHandle, struct CtlHalMixerDataT *currentM
json_type currentDataType;
json_object *currentJ;
+ struct CtlHalMixerData *currentMixerData;
+
currentDataType = json_object_get_type(currentDataJ);
switch(currentDataType) {
case json_type_object:
- currentMixerDataT->count = 1;
+ mixerDataNb = 1;
break;
case json_type_array:
- currentMixerDataT->count = (unsigned int) json_object_array_length(currentDataJ);
+ mixerDataNb = (unsigned int) json_object_array_length(currentDataJ);
break;
default:
- currentMixerDataT->count = 0;
+ mixerDataNb = 0;
AFB_ApiError(apiHandle, "No data returned");
return (int) MIXER_ERROR_DATA_EMPTY;
}
- currentMixerDataT->data = (struct CtlHalMixerData *) calloc(currentMixerDataT->count, sizeof(struct CtlHalMixerData));
-
- for(idx = 0; idx < currentMixerDataT->count; idx++) {
+ for(idx = 0; idx < mixerDataNb; idx++) {
if(currentDataType == json_type_array)
currentJ = json_object_array_get_idx(currentDataJ, (int) idx);
else
@@ -78,51 +78,80 @@ int HalCtlsHandleMixerData(AFB_ApiT apiHandle, struct CtlHalMixerDataT *currentM
err += (int) MIXER_ERROR_DATA_CARDID_UNAVAILABLE;
}
else {
- currentMixerDataT->data[idx].verbToCall = strdup(currentDataVerbName);
+ switch(dataType) {
+ case MIXER_DATA_STREAMS:
+ size = (int) strlen(currentDataVerbName);
+ for(verbStart = 0; verbStart < size; verbStart++) {
+ if(currentDataVerbName[verbStart] == '#') {
+ verbStart++;
+ break;
+ }
+ }
- if(dataType == MIXER_DATA_STREAMS) {
- currentMixerDataT->data[idx].streamCardId = strdup(currentStreamCardId);
+ if(verbStart == size)
+ verbStart = 0;
- size = (int) strlen(currentDataVerbName);
- for(verbStart = 0; verbStart < size; verbStart++) {
- if(currentDataVerbName[verbStart] == '#') {
- verbStart++;
+ if(! (currentMixerData = HalUtlAddMixerDataToMixerDataList(firstMixerData))) {
+ AFB_ApiError(apiHandle, "Error while adding a stream to stream list");
+ err += (int) MIXER_ERROR_STREAM_NOT_ADDED_TO_STREAM_LIST;
break;
}
- }
-
- if(verbStart == size)
- verbStart = 0;
-
- currentMixerDataT->data[idx].verb = strdup(&currentDataVerbName[verbStart]);
-
- if(AFB_ApiAddVerb(apiHandle,
- currentMixerDataT->data[idx].verb,
- "Stream action transferred to mixer",
- HalCtlsActionOnStream,
- (void *) &currentMixerDataT->data[idx],
- NULL,
- 0,
- 0)) {
- AFB_ApiError(apiHandle,
- "Error while creating verbs for stream : '%s'",
- currentMixerDataT->data[idx].verb);
- err += (int) MIXER_ERROR_STREAM_VERB_NOT_CREATED;
- }
-
- currentMixerDataT->data[idx].event = AFB_EventMake(apiHandle, currentMixerDataT->data[idx].verb);
- if(! AFB_EventIsValid(currentMixerDataT->data[idx].event)) {
- AFB_ApiError(apiHandle,
- "Error while creating event for stream : '%s'",
- currentMixerDataT->data[idx].verb);
- err += (int) MIXER_ERROR_STREAM_EVENT_NOT_CREATED;
- }
- }
- else if(dataType == MIXER_DATA_PLAYBACKS) {
- currentMixerDataT->data[idx].verb = strdup(HAL_PLAYBACK_ID);
- }
- else if(dataType == MIXER_DATA_CAPTURES) {
- currentMixerDataT->data[idx].verb = strdup(HAL_CAPTURE_ID);
+
+ currentMixerData->verb = strdup(&currentDataVerbName[verbStart]);
+ currentMixerData->verbToCall = strdup(currentDataVerbName);
+ currentMixerData->streamCardId = strdup(currentStreamCardId);
+
+ if((! currentMixerData->verb) ||
+ (! currentMixerData->verbToCall) ||
+ (! currentMixerData->streamCardId)) {
+ HalUtlRemoveSelectedMixerData(firstMixerData, currentMixerData);
+ err += (int) MIXER_ERROR_STREAM_ALLOCATION_FAILED;
+ break;
+ }
+
+ if(AFB_ApiAddVerb(apiHandle,
+ currentMixerData->verb,
+ "Stream action transferred to mixer",
+ HalCtlsActionOnStream,
+ (void *) currentMixerData,
+ NULL,
+ 0,
+ 0)) {
+ AFB_ApiError(apiHandle,
+ "Error while creating verbs for stream : '%s'",
+ currentMixerData->verb);
+ HalUtlRemoveSelectedMixerData(firstMixerData, currentMixerData);
+ err += (int) MIXER_ERROR_STREAM_VERB_NOT_CREATED;
+ break;
+ }
+
+ currentMixerData->event = AFB_EventMake(apiHandle, currentMixerData->verb);
+ if(! AFB_EventIsValid(currentMixerData->event)) {
+ AFB_ApiError(apiHandle,
+ "Error while creating event for stream %s",
+ currentMixerData->verb);
+ HalUtlRemoveSelectedMixerData(firstMixerData, currentMixerData);
+ err += (int) MIXER_ERROR_STREAM_EVENT_NOT_CREATED;
+ }
+
+ break;
+
+ case MIXER_DATA_PLAYBACKS:
+ case MIXER_DATA_CAPTURES:
+ currentMixerData = HalUtlAddMixerDataToMixerDataList(firstMixerData);
+
+ currentMixerData->verb = strdup((dataType == MIXER_DATA_PLAYBACKS) ? HAL_PLAYBACK_ID : HAL_CAPTURE_ID);
+ currentMixerData->verbToCall = strdup(currentDataVerbName);
+
+ if((! currentMixerData->verb) ||
+ (! currentMixerData->verbToCall)) {
+ HalUtlRemoveSelectedMixerData(firstMixerData, currentMixerData);
+ err += (int) MIXER_ERROR_STREAM_ALLOCATION_FAILED;
+ }
+ break;
+
+ default:
+ break;
}
}
}
@@ -132,7 +161,7 @@ int HalCtlsHandleMixerData(AFB_ApiT apiHandle, struct CtlHalMixerDataT *currentM
HAL_PLAYBACK_ID,
"Playback action transferred to mixer",
HalCtlsActionOnPlayback,
- (void *) currentMixerDataT,
+ (void *) *firstMixerData,
NULL,
0,
0)) {
@@ -146,7 +175,7 @@ int HalCtlsHandleMixerData(AFB_ApiT apiHandle, struct CtlHalMixerDataT *currentM
HAL_CAPTURE_ID,
"Capture action transferred to mixer",
HalCtlsActionOnCapture,
- (void *) currentMixerDataT,
+ (void *) *firstMixerData,
NULL,
0,
0)) {
@@ -183,14 +212,14 @@ int HalCtlsHandleMixerAttachResponse(AFB_ApiT apiHandle, struct CtlHalSpecificDa
if(mixerCapturesJ && (err += HalCtlsHandleMixerData(apiHandle, &currentHalSpecificData->ctlHalCapturesData, mixerCapturesJ, MIXER_DATA_CAPTURES)))
AFB_ApiError(apiHandle, "Error during handling response mixer captures data '%s'", json_object_get_string(mixerCapturesJ));
- if(! currentHalSpecificData->ctlHalStreamsData.count) {
+ if(! currentHalSpecificData->ctlHalStreamsData) {
AFB_ApiWarning(apiHandle, "No stream detected in mixer response, %s verb won't be created", HAL_ALL_STREAMS_VERB);
}
else if(AFB_ApiAddVerb(apiHandle,
HAL_ALL_STREAMS_VERB,
"Send a stream action on all streams",
HalCtlsActionOnAllStream,
- (void *) &currentHalSpecificData->ctlHalStreamsData,
+ (void *) currentHalSpecificData->ctlHalStreamsData,
NULL,
0,
0)) {