diff options
author | Jonathan Aillet <jonathan.aillet@iot.bzh> | 2019-01-15 11:26:54 +0100 |
---|---|---|
committer | Jonathan Aillet <jonathan.aillet@iot.bzh> | 2019-01-28 15:38:43 +0100 |
commit | 5f5c1a6460b3bf342d1c3a01ae296ecb14560fb5 (patch) | |
tree | 8c91df06973df3e94f89cbb80eaca73f0ce14a53 /4a-hal/4a-hal-controllers | |
parent | e3f74a9f59c05df601aa26554612fc68901c1646 (diff) |
Improve stream creation/deletion functions
Add functions to add/remove stream verb while
adding/deleting stream data.
Use them to create streams when mixer response is received.
Change-Id: I158b04cef7f6ce4f58a9c7481b6ebad00de989e3
Signed-off-by: Jonathan Aillet <jonathan.aillet@iot.bzh>
Diffstat (limited to '4a-hal/4a-hal-controllers')
4 files changed, 15 insertions, 251 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 e501e53..ec00056 100644 --- a/4a-hal/4a-hal-controllers/4a-hal-controllers-cb.c +++ b/4a-hal/4a-hal-controllers/4a-hal-controllers-cb.c @@ -408,197 +408,6 @@ int HalCtlsHalMapConfig(AFB_ApiT apiHandle, CtlSectionT *section, json_object *A * HAL controllers verbs functions * ******************************************************************************/ -void HalCtlsActionOnMixer(AFB_ReqT request, enum ActionOnMixerType actionType) -{ - int idx, count; - - char *apiToCall; - - AFB_ApiT apiHandle; - CtlConfigT *ctrlConfig; - - struct SpecificHalData *currentCtlHalData; - struct CtlHalMixerData *currentMixerData = NULL; - - json_object *requestJson, *returnJ = NULL, *responseJ, *toReturnJ = NULL; - - apiHandle = (AFB_ApiT) AFB_ReqGetApi(request); - if(! apiHandle) { - AFB_ReqFail(request, "api_handle", "Can't get current hal controller api handle"); - return; - } - - ctrlConfig = (CtlConfigT *) AFB_ApiGetUserData(apiHandle); - if(! ctrlConfig) { - AFB_ReqFail(request, "hal_controller_config", "Can't get current hal controller config"); - return; - } - - currentCtlHalData = (struct SpecificHalData *) getExternalData(ctrlConfig); - if(! currentCtlHalData) { - AFB_ReqFail(request, "hal_controller_data", "Can't get current hal controller data"); - return; - } - - requestJson = AFB_ReqJson(request); - if(! requestJson) { - AFB_ReqFail(request, "request_json", "Can't get request json"); - return; - } - - if(json_object_is_type(requestJson, json_type_object) && json_object_get_object(requestJson)->count > 0) - json_object_object_add(requestJson, "verbose", json_object_new_boolean(1)); - - apiToCall = currentCtlHalData->ctlHalSpecificData->mixerApiName; - if(! apiToCall) { - AFB_ReqFail(request, "mixer_api", "Can't get mixer api"); - return; - } - - if(currentCtlHalData->status != HAL_STATUS_READY) { - AFB_ReqFail(request, "hal_not_ready", "Seems that hal is not ready"); - 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: - count = 1; - break; - - case ACTION_ON_MIXER_PLAYBACK: - case ACTION_ON_MIXER_CAPTURE: - case ACTION_ON_MIXER_ALL_STREAM: - count = (int) HalUtlGetNumberOfMixerDataInList(¤tMixerData); - toReturnJ = json_object_new_object(); - break; - - default: - AFB_ReqFail(request, "hal_call_data", "Can't get current call data"); - return; - } - - for(idx = 0; idx < count; idx++) { - if(AFB_ServiceSync(apiHandle, - apiToCall, - currentMixerData->verbToCall, - json_object_get(requestJson), - &returnJ)) { - HalUtlHandleAppFwCallErrorInRequest(request, apiToCall, currentMixerData->verbToCall, returnJ, "call_action"); - json_object_put(returnJ); - if(toReturnJ) - json_object_put(toReturnJ); - return; - } - - if(wrap_json_unpack(returnJ, "{s:o}", "response", &responseJ)) { - AFB_ReqFailF(request, - "Seems that %s call to api %s succeed, but no response was found in : '%s'", - currentMixerData->verbToCall, - apiToCall, - json_object_get_string(returnJ)); - json_object_put(returnJ); - if(toReturnJ) - json_object_put(toReturnJ); - return; - } - - // TBD JAI : When mixer events will be available, use them instead of generating events at calls - if((actionType == ACTION_ON_MIXER_STREAM || - actionType == ACTION_ON_MIXER_ALL_STREAM) && - ((! currentMixerData->event) || - (AFB_EventPush(currentMixerData->event, json_object_get(responseJ)) < 0))) { - AFB_ApiError(apiHandle, "Couldn't generate an event for stream %s", currentMixerData->verb); - } - - switch(actionType) { - case ACTION_ON_MIXER_STREAM: - toReturnJ = json_object_get(responseJ); - break; - - case ACTION_ON_MIXER_PLAYBACK: - case ACTION_ON_MIXER_CAPTURE: - json_object_object_add(toReturnJ, currentMixerData->verbToCall, json_object_get(responseJ)); - break; - - case ACTION_ON_MIXER_ALL_STREAM: - json_object_object_add(toReturnJ, currentMixerData->verb, json_object_get(responseJ)); - break; - - default: - break; - } - - 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) { - case ACTION_ON_MIXER_STREAM: - AFB_ReqSuccessF(request, - toReturnJ, - "Action %s correctly transferred to %s without any error raised", - currentMixerData->verbToCall, - apiToCall); - break; - - case ACTION_ON_MIXER_PLAYBACK: - AFB_ReqSuccess(request, - toReturnJ, - "Actions correctly transferred to all playbacks without any error raised"); - break; - - case ACTION_ON_MIXER_CAPTURE: - AFB_ReqSuccess(request, - toReturnJ, - "Actions correctly transferred to all captures without any error raised"); - break; - - case ACTION_ON_MIXER_ALL_STREAM: - AFB_ReqSuccess(request, - toReturnJ, - "Actions correctly transferred to all streams without any error raised"); - break; - - default: - break; - } -} - -void HalCtlsActionOnStream(AFB_ReqT request) -{ - HalCtlsActionOnMixer(request, ACTION_ON_MIXER_STREAM); -} - -void HalCtlsActionOnPlayback(AFB_ReqT request) -{ - HalCtlsActionOnMixer(request, ACTION_ON_MIXER_PLAYBACK); -} - -void HalCtlsActionOnCapture(AFB_ReqT request) -{ - HalCtlsActionOnMixer(request, ACTION_ON_MIXER_CAPTURE); -} - -void HalCtlsActionOnAllStream(AFB_ReqT request) -{ - HalCtlsActionOnMixer(request, ACTION_ON_MIXER_ALL_STREAM); -} - json_object *HalCtlsGetJsonArrayForMixerDataTable(AFB_ApiT apiHandle, struct CtlHalMixerData **firstMixerData, enum MixerDataType dataType) { json_object *mixerDataArrayJ, *currentMixerDataJ; diff --git a/4a-hal/4a-hal-controllers/4a-hal-controllers-cb.h b/4a-hal/4a-hal-controllers/4a-hal-controllers-cb.h index d9b4411..a90c19a 100644 --- a/4a-hal/4a-hal-controllers/4a-hal-controllers-cb.h +++ b/4a-hal/4a-hal-controllers/4a-hal-controllers-cb.h @@ -24,14 +24,6 @@ #include <ctl-config.h> -// Enum for the type of action on mixer -enum ActionOnMixerType { - ACTION_ON_MIXER_STREAM = 1, - ACTION_ON_MIXER_PLAYBACK = 2, - ACTION_ON_MIXER_CAPTURE = 3, - ACTION_ON_MIXER_ALL_STREAM = 4 -}; - // Enum for the type of subscription/subscription enum SubscribeUnsubscribeType { SUBSCRIPTION = 1, @@ -46,10 +38,6 @@ int HalCtlsHalMixerConfig(AFB_ApiT apiHandle, CtlSectionT *section, json_object int HalCtlsHalMapConfig(AFB_ApiT apiHandle, CtlSectionT *section, json_object *StreamControlsJ); // HAL controllers verbs functions -void HalCtlsActionOnStream(AFB_ReqT request); -void HalCtlsActionOnPlayback(AFB_ReqT request); -void HalCtlsActionOnCapture(AFB_ReqT request); -void HalCtlsActionOnAllStream(AFB_ReqT request); void HalCtlsInfo(AFB_ReqT request); void HalCtlsSubscribe(AFB_ReqT request); void HalCtlsUnsubscribe(AFB_ReqT request); 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 72f62dd..da05498 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 @@ -26,6 +26,8 @@ #include "4a-hal-utilities-appfw-responses-handler.h" #include "4a-hal-utilities-data.h" + +#include "4a-hal-utilities-hal-streams-handler.h" #include "4a-hal-utilities-verbs-loader.h" #include "../4a-hal-manager/4a-hal-manager.h" @@ -91,47 +93,14 @@ int HalCtlsHandleMixerData(AFB_ApiT apiHandle, struct CtlHalMixerData **firstMix if(verbStart == size) verbStart = 0; - 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; - } - - 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)) { + if(! HalUtlAddStreamDataAndCreateStreamVerb(apiHandle, + ¤tDataVerbName[verbStart], + currentDataVerbName, + currentStreamCardId)) { 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; + "Error while adding stream '%s'", + currentDataVerbName); + err += (int) MIXER_ERROR_STREAM_NOT_ADDED; } break; @@ -160,7 +129,7 @@ int HalCtlsHandleMixerData(AFB_ApiT apiHandle, struct CtlHalMixerData **firstMix if(AFB_ApiAddVerb(apiHandle, HAL_PLAYBACK_ID, "Playback action transferred to mixer", - HalCtlsActionOnPlayback, + HalUtlActionOnPlayback, (void *) *firstMixerData, NULL, 0, @@ -174,7 +143,7 @@ int HalCtlsHandleMixerData(AFB_ApiT apiHandle, struct CtlHalMixerData **firstMix if(AFB_ApiAddVerb(apiHandle, HAL_CAPTURE_ID, "Capture action transferred to mixer", - HalCtlsActionOnCapture, + HalUtlActionOnCapture, (void *) *firstMixerData, NULL, 0, @@ -218,7 +187,7 @@ int HalCtlsHandleMixerAttachResponse(AFB_ApiT apiHandle, struct CtlHalSpecificDa else if(AFB_ApiAddVerb(apiHandle, HAL_ALL_STREAMS_VERB, "Send a stream action on all streams", - HalCtlsActionOnAllStream, + HalUtlActionOnAllStream, (void *) currentHalSpecificData->ctlHalStreamsData, NULL, 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 7856bb7..db42001 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 @@ -22,7 +22,7 @@ #include <wrap-json.h> -#include "afb-helpers-utils.h" +#include <afb-helpers-utils.h> #include "4a-hal-utilities-data.h" @@ -52,10 +52,8 @@ enum MixerStatus { MIXER_ERROR_ALL_STREAMS_VERB_NOT_CREATED =-6, MIXER_ERROR_DATA_NAME_UNAVAILABLE=-10, 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 + MIXER_ERROR_STREAM_NOT_ADDED =-1000, + MIXER_ERROR_STREAM_ALLOCATION_FAILED =-10000 }; // HAL controllers handle mixer calls functions |