diff options
Diffstat (limited to '4a-hal/4a-hal-controllers')
4 files changed, 135 insertions, 114 deletions
diff --git a/4a-hal/4a-hal-controllers/4a-hal-controllers-api-loader.c b/4a-hal/4a-hal-controllers/4a-hal-controllers-api-loader.c index 72515e7..0f63be7 100644 --- a/4a-hal/4a-hal-controllers/4a-hal-controllers-api-loader.c +++ b/4a-hal/4a-hal-controllers/4a-hal-controllers-api-loader.c @@ -104,8 +104,6 @@ static int HalCtlsInitOneApi(AFB_ApiT apiHandle) currentCtlHalData->ctlHalSpecificData->apiHandle = apiHandle; currentCtlHalData->ctlHalSpecificData->ctrlConfig = ctrlConfig; - currentCtlHalData->ctlHalSpecificData->ctlHalStreamsData.count = 0; - currentCtlHalData->sndCardId = HalCtlsGetCardIdByCardPath(apiHandle, currentCtlHalData->sndCardPath); if(currentCtlHalData->sndCardId < 0) 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 ba2454a..e501e53 100644 --- a/4a-hal/4a-hal-controllers/4a-hal-controllers-cb.c +++ b/4a-hal/4a-hal-controllers/4a-hal-controllers-cb.c @@ -419,7 +419,6 @@ void HalCtlsActionOnMixer(AFB_ReqT request, enum ActionOnMixerType actionType) struct SpecificHalData *currentCtlHalData; struct CtlHalMixerData *currentMixerData = NULL; - struct CtlHalMixerDataT *currentMixerDataT = NULL; json_object *requestJson, *returnJ = NULL, *responseJ, *toReturnJ = NULL; @@ -461,25 +460,20 @@ void HalCtlsActionOnMixer(AFB_ReqT request, enum ActionOnMixerType actionType) return; } + if(! (currentMixerData = (struct CtlHalMixerData *) AFB_ReqVCBData(request))) { + AFB_ReqFail(request, "hal_call_data", "Can't get current call data"); + return; + } + switch(actionType) { case ACTION_ON_MIXER_STREAM: - currentMixerData = (struct CtlHalMixerData *) AFB_ReqVCBData(request); - if(! currentMixerData) { - AFB_ReqFail(request, "hal_call_data", "Can't get current call data"); - return; - } count = 1; break; case ACTION_ON_MIXER_PLAYBACK: case ACTION_ON_MIXER_CAPTURE: case ACTION_ON_MIXER_ALL_STREAM: - currentMixerDataT = (struct CtlHalMixerDataT *) AFB_ReqVCBData(request); - if(! currentMixerDataT) { - AFB_ReqFail(request, "hal_call_data", "Can't get current call data"); - return; - } - count = currentMixerDataT->count; + count = (int) HalUtlGetNumberOfMixerDataInList(¤tMixerData); toReturnJ = json_object_new_object(); break; @@ -489,17 +483,6 @@ void HalCtlsActionOnMixer(AFB_ReqT request, enum ActionOnMixerType actionType) } for(idx = 0; idx < count; idx++) { - switch(actionType) { - case ACTION_ON_MIXER_PLAYBACK: - case ACTION_ON_MIXER_CAPTURE: - case ACTION_ON_MIXER_ALL_STREAM: - currentMixerData = ¤tMixerDataT->data[idx]; - break; - - default: - break; - } - if(AFB_ServiceSync(apiHandle, apiToCall, currentMixerData->verbToCall, @@ -551,6 +534,17 @@ void HalCtlsActionOnMixer(AFB_ReqT request, enum ActionOnMixerType actionType) } json_object_put(returnJ); + + switch(actionType) { + case ACTION_ON_MIXER_PLAYBACK: + case ACTION_ON_MIXER_CAPTURE: + case ACTION_ON_MIXER_ALL_STREAM: + currentMixerData = currentMixerData->next; + break; + + default: + break; + } } switch(actionType) { @@ -605,54 +599,53 @@ void HalCtlsActionOnAllStream(AFB_ReqT request) HalCtlsActionOnMixer(request, ACTION_ON_MIXER_ALL_STREAM); } -json_object *HalCtlsGetJsonArrayForMixerDataTable(AFB_ApiT apiHandle, struct CtlHalMixerDataT *currentMixerDataT, enum MixerDataType dataType) +json_object *HalCtlsGetJsonArrayForMixerDataTable(AFB_ApiT apiHandle, struct CtlHalMixerData **firstMixerData, enum MixerDataType dataType) { - unsigned int idx; + json_object *mixerDataArrayJ, *currentMixerDataJ; - json_object *mixerDataArray, *currentMixerData; + struct CtlHalMixerData *currentMixerData; if(! apiHandle) { AFB_ApiError(apiHandle, "Can't get current hal controller api handle"); return NULL; } - if(! currentMixerDataT) { - AFB_ApiError(apiHandle, "Can't get mixer data table to handle"); - return NULL; - } - - mixerDataArray = json_object_new_array(); - if(! mixerDataArray) { + mixerDataArrayJ = json_object_new_array(); + if(! mixerDataArrayJ) { AFB_ApiError(apiHandle, "Can't generate json mixer data array"); return NULL; } - for(idx = 0; idx < currentMixerDataT->count; idx++) { + currentMixerData = *firstMixerData; + + while(currentMixerData) { switch(dataType) { case MIXER_DATA_STREAMS: - wrap_json_pack(¤tMixerData, + wrap_json_pack(¤tMixerDataJ, "{s:s s:s}", - "name", currentMixerDataT->data[idx].verb, - "cardId", currentMixerDataT->data[idx].streamCardId); + "name", currentMixerData->verb, + "cardId", currentMixerData->streamCardId); break; case MIXER_DATA_PLAYBACKS: case MIXER_DATA_CAPTURES : - wrap_json_pack(¤tMixerData, + wrap_json_pack(¤tMixerDataJ, "{s:s s:s}", - "name", currentMixerDataT->data[idx].verb, - "mixer-name", currentMixerDataT->data[idx].verbToCall, - "uid", currentMixerDataT->data[idx].streamCardId ? currentMixerDataT->data[idx].streamCardId : "none"); + "name", currentMixerData->verb, + "mixer-name", currentMixerData->verbToCall, + "uid", currentMixerData->streamCardId ? currentMixerData->streamCardId : "none"); break; default: - json_object_put(mixerDataArray); + json_object_put(mixerDataArrayJ); return NULL; } - json_object_array_add(mixerDataArray, currentMixerData); + json_object_array_add(mixerDataArrayJ, currentMixerDataJ); + + currentMixerData = currentMixerData->next; } - return mixerDataArray; + return mixerDataArrayJ; } json_object *HalCtlsGetJsonArrayForControls(AFB_ApiT apiHandle, struct CtlHalAlsaMapT *currentAlsaMapDataT) @@ -794,7 +787,7 @@ void HalCtlsSubscribeUnsubscribe(AFB_ReqT request, enum SubscribeUnsubscribeType CtlConfigT *ctrlConfig; struct SpecificHalData *currentCtlHalData; - struct CtlHalMixerDataT *halStreamsData; + struct CtlHalMixerData *currentStreamData; struct CtlHalAlsaMapT *halAlsaMapT; json_object *requestJson, *requestedSubscriptionsJ, *requestedSubscriptionJ = NULL; @@ -823,7 +816,6 @@ void HalCtlsSubscribeUnsubscribe(AFB_ReqT request, enum SubscribeUnsubscribeType return; } - halStreamsData = ¤tCtlHalData->ctlHalSpecificData->ctlHalStreamsData; halAlsaMapT = currentCtlHalData->ctlHalSpecificData->ctlHalAlsaMapT; requestJson = AFB_ReqJson(request); @@ -864,26 +856,26 @@ void HalCtlsSubscribeUnsubscribe(AFB_ReqT request, enum SubscribeUnsubscribeType subscriptionFound = 0; currentSubscriptionString = (char *) json_object_get_string(requestedSubscriptionJ); - searchIdx = 0; - while((searchIdx < halStreamsData->count) && + currentStreamData = currentCtlHalData->ctlHalSpecificData->ctlHalStreamsData; + while(currentStreamData && (! subscriptionFound)) { - if(! strcasecmp(currentSubscriptionString, halStreamsData->data[searchIdx].verb)) { - if(halStreamsData->data[searchIdx].event && + if(! strcasecmp(currentSubscriptionString, currentStreamData->verb)) { + if(currentStreamData->event && subscribeUnsubscribeType == SUBSCRIPTION && - afb_req_subscribe(request, halStreamsData->data[searchIdx].event)) { + afb_req_subscribe(request, currentStreamData->event)) { AFB_ReqFailF(request, "request_stream_event", "Error while trying to subscribe to %s stream events", - halStreamsData->data[searchIdx].verb); + currentStreamData->verb); return; } - else if(halStreamsData->data[searchIdx].event && + else if(currentStreamData->event && subscribeUnsubscribeType == UNSUBSCRIPTION && - afb_req_unsubscribe(request, halStreamsData->data[searchIdx].event)) { + afb_req_unsubscribe(request, currentStreamData->event)) { AFB_ReqFailF(request, "request_stream_event", "Error while trying to unsubscribe to %s stream events", - halStreamsData->data[searchIdx].verb); + currentStreamData->verb); return; } @@ -893,7 +885,7 @@ void HalCtlsSubscribeUnsubscribe(AFB_ReqT request, enum SubscribeUnsubscribeType break; } - searchIdx++; + currentStreamData = currentStreamData->next; } searchIdx = 0; 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(¤tDataVerbName[verbStart]); - - if(AFB_ApiAddVerb(apiHandle, - currentMixerDataT->data[idx].verb, - "Stream action transferred to mixer", - HalCtlsActionOnStream, - (void *) ¤tMixerDataT->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(¤tDataVerbName[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, ¤tHalSpecificData->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 *) ¤tHalSpecificData->ctlHalStreamsData, + (void *) currentHalSpecificData->ctlHalStreamsData, NULL, 0, 0)) { diff --git a/4a-hal/4a-hal-controllers/4a-hal-controllers-mixer-link.h b/4a-hal/4a-hal-controllers/4a-hal-controllers-mixer-link.h index 9189664..7856bb7 100644 --- a/4a-hal/4a-hal-controllers/4a-hal-controllers-mixer-link.h +++ b/4a-hal/4a-hal-controllers/4a-hal-controllers-mixer-link.h @@ -51,9 +51,11 @@ enum MixerStatus { MIXER_ERROR_CAPTURE_VERB_NOT_CREATED =-5, MIXER_ERROR_ALL_STREAMS_VERB_NOT_CREATED =-6, MIXER_ERROR_DATA_NAME_UNAVAILABLE=-10, - MIXER_ERROR_DATA_CARDID_UNAVAILABLE=-1000, - MIXER_ERROR_STREAM_VERB_NOT_CREATED =-100000, - MIXER_ERROR_STREAM_EVENT_NOT_CREATED =-10000000 + MIXER_ERROR_DATA_CARDID_UNAVAILABLE=-100, + MIXER_ERROR_STREAM_NOT_ADDED_TO_STREAM_LIST =-1000, + MIXER_ERROR_STREAM_ALLOCATION_FAILED =-10000, + MIXER_ERROR_STREAM_EVENT_NOT_CREATED =-100000, + MIXER_ERROR_STREAM_VERB_NOT_CREATED =-1000000 }; // HAL controllers handle mixer calls functions |