diff options
author | Jonathan Aillet <jonathan.aillet@iot.bzh> | 2018-06-01 22:44:21 +0200 |
---|---|---|
committer | Jonathan Aillet <jonathan.aillet@iot.bzh> | 2018-10-08 15:51:00 +0200 |
commit | 8943be0ab8f315d935c9bfe7b46523c4e94b0025 (patch) | |
tree | f6043225194b93380a6e253822186fe088c3a3cd | |
parent | 67c4b9bb390192fa1cb4004da0ca3ec4ad8d54a6 (diff) |
Handle mixer response after its init
Handle mixer response to get created streams and them corresponding
card ids after mixer initialization. Store these informations into the
controller hal data strucure.
Creation of a verb for each stream is now handle at response handling.
Remove unnecessary function because we don't need to search for a
stream by his name.
Change-Id: Id9e598668b071ca18d152b57e71109314025f698
Signed-off-by: Jonathan Aillet <jonathan.aillet@iot.bzh>
-rw-r--r-- | 4a-hal/4a-hal-controllers/4a-hal-controllers-api-loader.c | 2 | ||||
-rw-r--r-- | 4a-hal/4a-hal-controllers/4a-hal-controllers-cb.c | 72 | ||||
-rw-r--r-- | 4a-hal/4a-hal-controllers/4a-hal-controllers-mixer-handler.c | 101 | ||||
-rw-r--r-- | 4a-hal/4a-hal-controllers/4a-hal-controllers-mixer-handler.h | 29 | ||||
-rw-r--r-- | 4a-hal/4a-hal-utilities/4a-hal-utilities-data.h | 2 | ||||
-rw-r--r-- | 4a-hal/CMakeLists.txt | 1 |
6 files changed, 150 insertions, 57 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 bc6b9c1..39be303 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 @@ -103,6 +103,8 @@ static int HalCtlsInitOneApi(afb_dynapi *apiHandle) currentCtlHalData->ctlHalSpecificData->apiHandle = apiHandle; currentCtlHalData->ctlHalSpecificData->ctrlConfig = ctrlConfig; + 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 // TODO JAI: handle refresh of hal status using /dev/snd/byId (or /dev/snd/byId) 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 30f89ba..f80063d 100644 --- a/4a-hal/4a-hal-controllers/4a-hal-controllers-cb.c +++ b/4a-hal/4a-hal-controllers/4a-hal-controllers-cb.c @@ -27,6 +27,7 @@ #include "../4a-hal-utilities/4a-hal-utilities-verbs-loader.h" #include "4a-hal-controllers-cb.h" +#include "4a-hal-controllers-mixer-handler.h" /******************************************************************************* * HAL controllers sections parsing functions * @@ -34,16 +35,9 @@ int HalCtlsHalMixerConfig(afb_dynapi *apiHandle, CtlSectionT *section, json_object *MixerJ) { - unsigned int streamCount, idx; - char *currentStreamName; - CtlConfigT *ctrlConfig; struct SpecificHalData *currentHalData; - json_object *streamsArray, *currentStream; - - struct HalUtlApiVerb *CtlHalDynApiStreamVerbs; - if(! apiHandle || ! section) return -1; @@ -64,50 +58,8 @@ int HalCtlsHalMixerConfig(afb_dynapi *apiHandle, CtlSectionT *section, json_obje if(wrap_json_unpack(MixerJ, "{s:s}", "mixerapi", ¤tHalData->ctlHalSpecificData->mixerApiName)) return -5; - if(wrap_json_unpack(MixerJ, "{s:s}", "uid", ¤tHalData->ctlHalSpecificData->halSoftMixerVerb)) + if(wrap_json_unpack(MixerJ, "{s:s}", "uid", ¤tHalData->ctlHalSpecificData->mixerVerbName)) return -6; - - if(! json_object_object_get_ex(MixerJ, "streams", &streamsArray)) - return -7; - - switch(json_object_get_type(streamsArray)) { - case json_type_object: - streamCount = 1; - break; - case json_type_array: - streamCount = json_object_array_length(streamsArray); - break; - default: - return -8; - } - - currentHalData->ctlHalSpecificData->ctlHalStreamsData.count = streamCount; - currentHalData->ctlHalSpecificData->ctlHalStreamsData.data = - (struct CtlHalStreamData *) calloc(streamCount, sizeof (struct CtlHalStreamData *)); - - CtlHalDynApiStreamVerbs = alloca((streamCount + 1) * sizeof(struct HalUtlApiVerb)); - memset(CtlHalDynApiStreamVerbs, '\0', (streamCount + 1) * sizeof(struct HalUtlApiVerb)); - CtlHalDynApiStreamVerbs[streamCount + 1].verb = NULL; - - for(idx = 0; idx < streamCount; idx++) { - if(streamCount > 1) - currentStream = json_object_array_get_idx(streamsArray, (int) idx); - else - currentStream = streamsArray; - - if(wrap_json_unpack(currentStream, "{s:s}", "uid", ¤tStreamName)) - return -10-idx; - - currentHalData->ctlHalSpecificData->ctlHalStreamsData.data[idx].name = strdup(currentStreamName); - currentHalData->ctlHalSpecificData->ctlHalStreamsData.data[idx].cardId = NULL; - - CtlHalDynApiStreamVerbs[idx].verb = currentStreamName; - CtlHalDynApiStreamVerbs[idx].callback = HalCtlsActionOnStream; - CtlHalDynApiStreamVerbs[idx].info = "Peform action on this stream"; - } - - if(HalUtlLoadVerbs(apiHandle, CtlHalDynApiStreamVerbs)) - return -9; } return 0; @@ -168,7 +120,7 @@ void HalCtlsActionOnStream(afb_request *request) return; } - halSoftMixerVerb = currentCtlHalData->ctlHalSpecificData->halSoftMixerVerb; + halSoftMixerVerb = currentCtlHalData->ctlHalSpecificData->mixerVerbName; if(! halSoftMixerVerb) { afb_request_fail(request, "hal_softmixer_verb", "Can't get hal mixer verb prefix"); return; @@ -254,9 +206,7 @@ void HalCtlsListVerbs(afb_request *request) wrap_json_pack(¤tStream, "{s:s s:s}", "name", currentCtlHalData->ctlHalSpecificData->ctlHalStreamsData.data[idx].name, - "cardId", currentCtlHalData->ctlHalSpecificData->ctlHalStreamsData.data[idx].cardId ? - currentCtlHalData->ctlHalSpecificData->ctlHalStreamsData.data[idx].cardId : - ""); + "cardId", currentCtlHalData->ctlHalSpecificData->ctlHalStreamsData.data[idx].cardId); json_object_array_add(streamsArray, currentStream); } @@ -269,6 +219,8 @@ void HalCtlsListVerbs(afb_request *request) void HalCtlsInitMixer(afb_request *request) { + unsigned int err; + char *apiToCall; afb_dynapi *apiHandle; @@ -311,11 +263,19 @@ void HalCtlsInitMixer(afb_request *request) apiToCall); } else if(json_object_object_get_ex(returnJ, "response", &toReturnJ)) { - // TODO JAI : get streams cardId from mixer response + err = HalCtlsHandleMixerAttachResponse(request, ¤tCtlHalData->ctlHalSpecificData->ctlHalStreamsData, toReturnJ); + if(err) { + afb_request_success_f(request, + toReturnJ, + "Seems that create call to api %s succeed but this warning was rised by response decoder : %i", + apiToCall, + err); + return; + } afb_request_success_f(request, toReturnJ, - "Seems that mix_new call to api %s succeed", + "Seems that create call to api %s succeed with no warning raised", apiToCall); } else { diff --git a/4a-hal/4a-hal-controllers/4a-hal-controllers-mixer-handler.c b/4a-hal/4a-hal-controllers/4a-hal-controllers-mixer-handler.c new file mode 100644 index 0000000..21c99af --- /dev/null +++ b/4a-hal/4a-hal-controllers/4a-hal-controllers-mixer-handler.c @@ -0,0 +1,101 @@ +/* + * Copyright (C) 2016 "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-verbs-loader.h" + +#include "4a-hal-controllers-mixer-handler.h" +#include "4a-hal-controllers-cb.h" + +/******************************************************************************* + * HAL controllers hanlde mixer responses functions * + ******************************************************************************/ + +int HalCtlsHandleMixerAttachResponse(AFB_ReqT request, struct CtlHalStreamsDataT *currentHalStreamsData, json_object *mixerResponseJ) +{ + int err = 0; + unsigned int idx; + + char *currentStreamName, *currentStreamCardId; + + AFB_ApiT apiHandle; + + struct HalUtlApiVerb *CtlHalDynApiStreamVerbs; + + json_object *currentStreamJ; + + apiHandle = (AFB_ApiT) afb_request_get_dynapi(request); + if(! apiHandle) { + AFB_ReqWarning(request, "%s: Can't get current hal api handle", __func__); + return -1; + } + + switch(json_object_get_type(mixerResponseJ)) { + case json_type_object: + currentHalStreamsData->count = 1; + break; + case json_type_array: + currentHalStreamsData->count = json_object_array_length(mixerResponseJ); + break; + default: + currentHalStreamsData->count = 0; + AFB_ReqWarning(request, "%s: no streams returned", __func__); + return -2; + } + + currentHalStreamsData->data = (struct CtlHalStreamData *) calloc(currentHalStreamsData->count, sizeof(struct CtlHalStreamData)); + + CtlHalDynApiStreamVerbs = alloca((currentHalStreamsData->count + 1) * sizeof(struct HalUtlApiVerb)); + memset(CtlHalDynApiStreamVerbs, '\0', (currentHalStreamsData->count + 1) * sizeof(struct HalUtlApiVerb)); + CtlHalDynApiStreamVerbs[currentHalStreamsData->count].verb = NULL; + + for(idx = 0; idx < currentHalStreamsData->count; idx++) { + if(currentHalStreamsData->count > 1) + currentStreamJ = json_object_array_get_idx(mixerResponseJ, (int) idx); + else + currentStreamJ = mixerResponseJ; + + if(wrap_json_unpack(currentStreamJ, "{s:s}", "uid", ¤tStreamName)) { + AFB_ReqWarning(request, "%s: can't find name in current stream object", __func__); + err -= 10; + } + else if(wrap_json_unpack(currentStreamJ, "{s:s}", "alsa", ¤tStreamCardId)) { + AFB_ReqWarning(request, "%s: can't find card id in current stream object", __func__); + err -= 1000; + } + else { + currentHalStreamsData->data[idx].name = strdup(currentStreamName); + currentHalStreamsData->data[idx].cardId = strdup(currentStreamCardId); + + CtlHalDynApiStreamVerbs[idx].verb = currentStreamName; + CtlHalDynApiStreamVerbs[idx].callback = HalCtlsActionOnStream; + CtlHalDynApiStreamVerbs[idx].info = "Peform action on this stream"; + } + } + + if(HalUtlLoadVerbs(apiHandle, CtlHalDynApiStreamVerbs)) { + AFB_ReqWarning(request, "%s: error while creating verbs for streams", __func__); + err -= 100000; + } + + return err; +}
\ No newline at end of file diff --git a/4a-hal/4a-hal-controllers/4a-hal-controllers-mixer-handler.h b/4a-hal/4a-hal-controllers/4a-hal-controllers-mixer-handler.h new file mode 100644 index 0000000..4512996 --- /dev/null +++ b/4a-hal/4a-hal-controllers/4a-hal-controllers-mixer-handler.h @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2016 "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_SOFTMIXER_LINK_INCLUDE_ +#define _HAL_CTLS_SOFTMIXER_LINK_INCLUDE_ + +#include <stdio.h> + +#include <wrap-json.h> + +#include "../4a-hal-utilities/4a-hal-utilities-data.h" + +int HalCtlsHandleMixerAttachResponse(AFB_ReqT request, struct CtlHalStreamsDataT *currentHalStreamsData, json_object *MixerResponseJ); + +#endif /* _HAL_CTLS_SOFTMIXER_LINK_INCLUDE_ */
\ No newline at end of file diff --git a/4a-hal/4a-hal-utilities/4a-hal-utilities-data.h b/4a-hal/4a-hal-utilities/4a-hal-utilities-data.h index 1d15785..2e66b87 100644 --- a/4a-hal/4a-hal-utilities/4a-hal-utilities-data.h +++ b/4a-hal/4a-hal-utilities/4a-hal-utilities-data.h @@ -45,7 +45,7 @@ struct CtlHalStreamsDataT { struct CtlHalSpecificData { char *mixerApiName; - char *halSoftMixerVerb; + char *mixerVerbName; json_object *halMixerJ; struct CtlHalStreamsDataT ctlHalStreamsData; diff --git a/4a-hal/CMakeLists.txt b/4a-hal/CMakeLists.txt index b963bc0..323c490 100644 --- a/4a-hal/CMakeLists.txt +++ b/4a-hal/CMakeLists.txt @@ -31,6 +31,7 @@ PROJECT_TARGET_ADD(4a-hal) ${TARGET_NAME}-manager/${TARGET_NAME}-manager-events.c ${TARGET_NAME}-controllers/${TARGET_NAME}-controllers-api-loader.c ${TARGET_NAME}-controllers/${TARGET_NAME}-controllers-cb.c + ${TARGET_NAME}-controllers/${TARGET_NAME}-controllers-mixer-handler.c ) # Binder exposes a unique public entry point |