diff options
Diffstat (limited to '4a-hal/4a-hal-controllers')
4 files changed, 134 insertions, 5 deletions
diff --git a/4a-hal/4a-hal-controllers/4a-hal-controllers-alsacore-link.c b/4a-hal/4a-hal-controllers/4a-hal-controllers-alsacore-link.c new file mode 100644 index 0000000..37d6447 --- /dev/null +++ b/4a-hal/4a-hal-controllers/4a-hal-controllers-alsacore-link.c @@ -0,0 +1,79 @@ +/* + * Copyright (C) 2018 "IoT.bzh" + * Author Jonathan Aillet <jonathan.aillet@iot.bzh> + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define _GNU_SOURCE + +#include <stdio.h> +#include <string.h> +#include <stdbool.h> + +#include "../4a-hal-utilities/4a-hal-utilities-data.h" +#include "../4a-hal-utilities/4a-hal-utilities-appfw-responses-handler.h" + +#include "4a-hal-controllers-alsacore-link.h" + +/******************************************************************************* + * HAL controllers alsacore calls funtions * + ******************************************************************************/ + +bool HalCtlsGetCardIdByCardPath(afb_dynapi *apiHandle, struct SpecificHalData *currentCtlHalData) +{ + int *cardId; + + char *cardIdString = NULL; + char **returnedStatus, **returnedInfo; + + enum CallError returnedError; + + json_object *toSendJ, *returnJ, *responsJ, *devidJ; + + cardId = alloca(sizeof(int)); + *cardId = -1; + + wrap_json_pack(&toSendJ, "{s:s}", "devpath", currentCtlHalData->sndCard); + + if(afb_dynapi_call_sync(apiHandle, ALSACORE_API, ALSACORE_GETINFO_VERB, toSendJ, &returnJ)) { + returnedStatus = alloca(sizeof(char *)); + returnedInfo = alloca(sizeof(char *)); + + returnedError = HalUtlHandleAppFwCallError(apiHandle, ALSACORE_API, ALSACORE_GETINFO_VERB, returnJ, returnedStatus, returnedInfo); + AFB_DYNAPI_WARNING(apiHandle, + "Error %i during call to verb %s of %s api", + (int) returnedError, + ALSACORE_GETINFO_VERB, + ALSACORE_API); + } + else if(json_object_object_get_ex(returnJ, "response", &responsJ)) { + if(json_object_object_get_ex(responsJ, "devid", &devidJ) && json_object_is_type(devidJ, json_type_string)) { + cardIdString = (char *) json_object_get_string(devidJ); + if(sscanf(cardIdString, "hw:%i", cardId) <= 0) + AFB_DYNAPI_WARNING(apiHandle, "Couldn't get valid devid from string: '%s'", cardIdString); + } + else { + AFB_DYNAPI_WARNING(apiHandle, "Response devid is not present/valid"); + } + + currentCtlHalData->sndCardId = *cardId; + + return true; + } + + currentCtlHalData->sndCardId = *cardId; + + return false; +} + diff --git a/4a-hal/4a-hal-controllers/4a-hal-controllers-alsacore-link.h b/4a-hal/4a-hal-controllers/4a-hal-controllers-alsacore-link.h new file mode 100644 index 0000000..19ff9e5 --- /dev/null +++ b/4a-hal/4a-hal-controllers/4a-hal-controllers-alsacore-link.h @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2018 "IoT.bzh" + * Author Jonathan Aillet <jonathan.aillet@iot.bzh> + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef HAL_CTLS_ALSACORE_LINK_INCLUDE_ +#define HAL_CTLS_ALSACORE_LINK_INCLUDE_ + +#include <stdio.h> +#include <stdbool.h> + +#define ALSACORE_API "alsacore" +#define ALSACORE_GETINFO_VERB "infoget" + +// HAL controllers alsacore calls funtions +bool HalCtlsGetCardIdByCardPath(afb_dynapi *apiHandle, struct SpecificHalData *currentCtlHalData); + +#endif /* HAL_CTLS_ALSACORE_LINK_INCLUDE_ */
\ No newline at end of file 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 972cc53..6656ddc 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 @@ -29,6 +29,7 @@ #include "../4a-hal-utilities/4a-hal-utilities-verbs-loader.h" #include "4a-hal-controllers-api-loader.h" +#include "4a-hal-controllers-alsacore-link.h" #include "4a-hal-controllers-cb.h" // Default api to print log when apihandle not available @@ -90,7 +91,6 @@ static int HalCtlsInitOneApi(afb_dynapi *apiHandle) // Fill SpecificHalDatadata structure currentCtlHalData->internal = (unsigned int) true; - currentCtlHalData->status = HAL_STATUS_UNAVAILABLE; currentCtlHalData->apiName = (char *) ctrlConfig->api; currentCtlHalData->sndCard = (char *) ctrlConfig->uid; @@ -105,8 +105,11 @@ static int HalCtlsInitOneApi(afb_dynapi *apiHandle) currentCtlHalData->ctlHalSpecificData->ctlHalStreamsData.count = 0; - // TODO JAI: Search for hw sndCard - // TODO JAI: Update alsa command of HalCtl to use alsa-softmixer/alsa-core data + if(HalCtlsGetCardIdByCardPath(apiHandle, currentCtlHalData)) + currentCtlHalData->status = HAL_STATUS_AVAILABLE; + else + currentCtlHalData->status = HAL_STATUS_UNAVAILABLE; + // TODO JAI: handle refresh of hal status using /dev/snd/byId (or /dev/snd/byId) return CtlConfigExec(apiHandle, ctrlConfig); 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 b37000d..2d0f400 100644 --- a/4a-hal/4a-hal-controllers/4a-hal-controllers-cb.c +++ b/4a-hal/4a-hal-controllers/4a-hal-controllers-cb.c @@ -28,6 +28,7 @@ #include "4a-hal-controllers-cb.h" #include "4a-hal-controllers-mixer-handler.h" +#include "4a-hal-controllers-alsacore-link.h" /******************************************************************************* * HAL controllers sections parsing functions * @@ -126,7 +127,10 @@ void HalCtlsActionOnStream(afb_request *request) return; } - // TODO JAI: check status of hal before doing anything + if(currentCtlHalData->status != HAL_STATUS_AVAILABLE) { + afb_request_fail(request, "hal_unavailable", "Seems that hal is not available"); + return; + } // TODO JAI : remove verb to call prefix, each hal should have its own api in softmixer, and each streams should be created as verb by mixer verbToCallSize = (int) strlen(mixerVerbName) + (int) strlen(request->verb) + 2; @@ -251,7 +255,18 @@ void HalCtlsInitMixer(afb_request *request) return; } - // TODO JAI: test hal status (card is detected) + switch(currentCtlHalData->status) { + case HAL_STATUS_UNAVAILABLE: + afb_request_fail(request, "hal_unavailable", "Seems that the hal corresponding card was not found by alsacore at startup"); + return; + + case HAL_STATUS_READY: + afb_request_success(request, NULL, "Seems that the hal mixer is already initialized"); + return; + + case HAL_STATUS_AVAILABLE: + break; + } if(afb_dynapi_call_sync(apiHandle, apiToCall, "create", json_object_get(currentCtlHalData->ctlHalSpecificData->halMixerJ), &returnJ)) { HalUtlHandleAppFwCallErrorInRequest(request, apiToCall, "create", returnJ, "mixer_create"); @@ -271,6 +286,8 @@ void HalCtlsInitMixer(afb_request *request) toReturnJ, "Seems that create call to api %s succeed with no warning raised", apiToCall); + + currentCtlHalData->status = HAL_STATUS_READY; } else { afb_request_fail_f(request, |