diff options
Diffstat (limited to '4a-hal/4a-hal-controllers')
4 files changed, 185 insertions, 48 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 ca3ba6b..9e25c61 100644 --- a/4a-hal/4a-hal-controllers/4a-hal-controllers-cb.c +++ b/4a-hal/4a-hal-controllers/4a-hal-controllers-cb.c @@ -385,17 +385,20 @@ int HalCtlsHalMapConfig(AFB_ApiT apiHandle, CtlSectionT *section, json_object *A * HAL controllers verbs functions * ******************************************************************************/ -void HalCtlsActionOnCall(AFB_ReqT request) +void HalCtlsActionOnMixer(AFB_ReqT request, enum ActionOnMixerType actionType) { + int idx, count; + char *apiToCall; AFB_ApiT apiHandle; CtlConfigT *ctrlConfig; struct SpecificHalData *currentCtlHalData; - struct CtlHalMixerData *currentMixerData; + struct CtlHalMixerData *currentMixerData = NULL; + struct CtlHalMixerDataT *currentMixerDataT = NULL; - json_object *requestJson, *returnJ = NULL, *toReturnJ; + json_object *requestJson, *returnJ = NULL, *responseJ, *toReturnJ = NULL; apiHandle = (AFB_ApiT) AFB_ReqGetApi(request); if(! apiHandle) { @@ -409,12 +412,6 @@ void HalCtlsActionOnCall(AFB_ReqT request) return; } - currentMixerData = (struct CtlHalMixerData *) AFB_ReqVCBData(request); - if(! currentMixerData) { - AFB_ReqFail(request, "hal_call_data", "Can't get current call data"); - return; - } - currentCtlHalData = (struct SpecificHalData *) getExternalData(ctrlConfig); if(! currentCtlHalData) { AFB_ReqFail(request, "hal_controller_data", "Can't get current hal controller data"); @@ -427,6 +424,9 @@ void HalCtlsActionOnCall(AFB_ReqT request) 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"); @@ -438,32 +438,140 @@ void HalCtlsActionOnCall(AFB_ReqT request) 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)); + 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; - // TBD JAI : handle the case of there is multiple 'playbacks' or 'captures' entries (call them all) + 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; + toReturnJ = json_object_new_object(); + break; - if(AFB_ServiceSync(apiHandle, apiToCall, currentMixerData->verbToCall, json_object_get(requestJson), &returnJ)) { - HalUtlHandleAppFwCallErrorInRequest(request, apiToCall, currentMixerData->verbToCall, returnJ, "call_action"); + default: + AFB_ReqFail(request, "hal_call_data", "Can't get current call data"); + return; } - else if(wrap_json_unpack(returnJ, "{s:o}", "response", &toReturnJ)) { - AFB_ReqSuccessF(request, - json_object_get(returnJ), - "Seems that %s call to api %s succeed, but no response was found : '%s'", - currentMixerData->verbToCall, - apiToCall, - json_object_get_string(returnJ)); + + 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, + 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; + } + + 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); } - else { - AFB_ReqSuccessF(request, - json_object_get(toReturnJ), - "Action %s correctly transferred to %s without any error raised", - currentMixerData->verbToCall, - apiToCall); + + 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; } +} - if(returnJ) - json_object_put(returnJ); +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 CtlHalMixerDataT *currentMixerDataT, enum MixerDataType dataType) 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 488b6f1..f1766ae 100644 --- a/4a-hal/4a-hal-controllers/4a-hal-controllers-cb.h +++ b/4a-hal/4a-hal-controllers/4a-hal-controllers-cb.h @@ -24,6 +24,14 @@ #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 +}; + // HAL controller event handler function void HalCtlsDispatchApiEvent(AFB_ApiT apiHandle, const char *evtLabel, json_object *eventJ); @@ -32,7 +40,10 @@ int HalCtlsHalMixerConfig(AFB_ApiT apiHandle, CtlSectionT *section, json_object int HalCtlsHalMapConfig(AFB_ApiT apiHandle, CtlSectionT *section, json_object *StreamControlsJ); // HAL controllers verbs functions -void HalCtlsActionOnCall(AFB_ReqT request); +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); #endif /* _HALMGR_CB_INCLUDE_ */
\ No newline at end of file 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 6f160d7..165bb42 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 @@ -83,21 +83,21 @@ int HalCtlsHandleMixerData(AFB_ApiT apiHandle, struct CtlHalMixerDataT *currentM size = (int) strlen(currentDataVerbName); for(verbStart = 0; verbStart < size; verbStart++) { - if(currentDataVerbName[verbStart] == '#') + if(currentDataVerbName[verbStart] == '#') { + verbStart++; break; + } } if(verbStart == size) verbStart = 0; - else - verbStart++; currentMixerDataT->data[idx].verb = strdup(¤tDataVerbName[verbStart]); if(AFB_ApiAddVerb(apiHandle, currentMixerDataT->data[idx].verb, "Stream action transferred to mixer", - HalCtlsActionOnCall, + HalCtlsActionOnStream, (void *) ¤tMixerDataT->data[idx], NULL, 0, @@ -109,38 +109,38 @@ int HalCtlsHandleMixerData(AFB_ApiT apiHandle, struct CtlHalMixerDataT *currentM } } else if(dataType == MIXER_DATA_PLAYBACKS) { - currentMixerDataT->data[idx].verb = strdup(HAL_PLAYBACK_VERB); + currentMixerDataT->data[idx].verb = strdup(HAL_PLAYBACK_ID); } else if(dataType == MIXER_DATA_CAPTURES) { - currentMixerDataT->data[idx].verb = strdup(HAL_CAPTURE_VERB); + currentMixerDataT->data[idx].verb = strdup(HAL_CAPTURE_ID); } } } if(dataType == MIXER_DATA_PLAYBACKS) { if(AFB_ApiAddVerb(apiHandle, - HAL_PLAYBACK_VERB, + HAL_PLAYBACK_ID, "Playback action transferred to mixer", - HalCtlsActionOnCall, - (void *) currentMixerDataT->data, + HalCtlsActionOnPlayback, + (void *) currentMixerDataT, NULL, 0, 0)) { - AFB_ApiError(apiHandle, "Error while creating verb for playbacks : '%s'", HAL_PLAYBACK_VERB); + AFB_ApiError(apiHandle, "Error while creating verb for playbacks : '%s'", HAL_PLAYBACK_ID); err += (int) MIXER_ERROR_PLAYBACK_VERB_NOT_CREATED; } } if(dataType == MIXER_DATA_CAPTURES) { if(AFB_ApiAddVerb(apiHandle, - HAL_CAPTURE_VERB, + HAL_CAPTURE_ID, "Capture action transferred to mixer", - HalCtlsActionOnCall, - (void *) currentMixerDataT->data, + HalCtlsActionOnCapture, + (void *) currentMixerDataT, NULL, 0, 0)) { - AFB_ApiError(apiHandle, "Error while creating verb for captures : '%s'", HAL_CAPTURE_VERB); + AFB_ApiError(apiHandle, "Error while creating verb for captures : '%s'", HAL_CAPTURE_ID); err += (int) MIXER_ERROR_CAPTURE_VERB_NOT_CREATED; } } @@ -173,6 +173,21 @@ 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) { + 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, + NULL, + 0, + 0)) { + AFB_ApiError(apiHandle, "Error while creating verb for all streams : '%s'", HAL_ALL_STREAMS_VERB); + return (int) MIXER_ERROR_ALL_STREAMS_VERB_NOT_CREATED; + } + return err; } 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 4ba5e8d..7deef1b 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 @@ -29,8 +29,10 @@ #define MIXER_ATTACH_VERB "attach" #define MIXER_INFO_VERB "info" -#define HAL_PLAYBACK_VERB "playback" -#define HAL_CAPTURE_VERB "capture" +#define HAL_PLAYBACK_ID "playback" +#define HAL_CAPTURE_ID "capture" + +#define HAL_ALL_STREAMS_VERB "all-streams" // Enum for the type of object sent back by the mixer enum MixerDataType { @@ -45,11 +47,12 @@ enum MixerStatus { MIXER_ERROR_API_UNAVAILABLE=-1, MIXER_ERROR_DATA_UNAVAILABLE=-2, MIXER_ERROR_DATA_EMPTY =-3, + MIXER_ERROR_PLAYBACK_VERB_NOT_CREATED =-4, + 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_PLAYBACK_VERB_NOT_CREATED =-4, - MIXER_ERROR_CAPTURE_VERB_NOT_CREATED =-5 }; // HAL controllers handle mixer calls functions |