aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--4a-hal/4a-hal-controllers/4a-hal-controllers-alsacore-link.c79
-rw-r--r--4a-hal/4a-hal-controllers/4a-hal-controllers-alsacore-link.h (renamed from 4a-hal/4a-hal-utilities/4a-hal-utilities-alsa-link.c)15
-rw-r--r--4a-hal/4a-hal-controllers/4a-hal-controllers-api-loader.c9
-rw-r--r--4a-hal/4a-hal-controllers/4a-hal-controllers-cb.c21
-rw-r--r--4a-hal/4a-hal-utilities/4a-hal-utilities-alsa-link.h25
-rw-r--r--4a-hal/4a-hal-utilities/4a-hal-utilities-data.h2
-rw-r--r--4a-hal/CMakeLists.txt2
7 files changed, 116 insertions, 37 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-utilities/4a-hal-utilities-alsa-link.c b/4a-hal/4a-hal-controllers/4a-hal-controllers-alsacore-link.h
index 8ff6c06..19ff9e5 100644
--- a/4a-hal/4a-hal-utilities/4a-hal-utilities-alsa-link.c
+++ b/4a-hal/4a-hal-controllers/4a-hal-controllers-alsacore-link.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2016 "IoT.bzh"
+ * Copyright (C) 2018 "IoT.bzh"
* Author Jonathan Aillet <jonathan.aillet@iot.bzh>
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -15,13 +15,16 @@
* limitations under the License.
*/
-#define _GNU_SOURCE
+#ifndef HAL_CTLS_ALSACORE_LINK_INCLUDE_
+#define HAL_CTLS_ALSACORE_LINK_INCLUDE_
#include <stdio.h>
-#include <string.h>
#include <stdbool.h>
-#include "4a-hal-utilities-data.h"
-#include "4a-hal-utilities-alsa-link.h"
+#define ALSACORE_API "alsacore"
+#define ALSACORE_GETINFO_VERB "infoget"
-// TODO JAI: implement alsa link functions \ No newline at end of file
+// 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,
diff --git a/4a-hal/4a-hal-utilities/4a-hal-utilities-alsa-link.h b/4a-hal/4a-hal-utilities/4a-hal-utilities-alsa-link.h
deleted file mode 100644
index 5c15109..0000000
--- a/4a-hal/4a-hal-utilities/4a-hal-utilities-alsa-link.h
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * 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_UTILITIES_ALSA_LINK_INCLUDE_
-#define _HAL_UTILITIES_ALSA_LINK_INCLUDE_
-
-#include <stdio.h>
-
-// TODO JAI: implement alsa link functions
-
-#endif /* _HAL_UTILITIES_DATA_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 e357256..34ca3e8 100644
--- a/4a-hal/4a-hal-utilities/4a-hal-utilities-data.h
+++ b/4a-hal/4a-hal-utilities/4a-hal-utilities-data.h
@@ -33,6 +33,7 @@
enum HalStatus {
HAL_STATUS_UNAVAILABLE=0,
HAL_STATUS_AVAILABLE=1,
+ HAL_STATUS_READY=2,
};
struct CtlHalStreamData {
@@ -62,6 +63,7 @@ struct SpecificHalData {
char *apiName;
enum HalStatus status;
char *sndCard;
+ int sndCardId;
char *info;
unsigned int internal;
diff --git a/4a-hal/CMakeLists.txt b/4a-hal/CMakeLists.txt
index e205ec4..cf485fd 100644
--- a/4a-hal/CMakeLists.txt
+++ b/4a-hal/CMakeLists.txt
@@ -24,12 +24,12 @@ PROJECT_TARGET_ADD(4a-hal)
# Define project Targets
add_library(${TARGET_NAME} MODULE
${TARGET_NAME}-utilities/${TARGET_NAME}-utilities-appfw-responses-handler.c
- ${TARGET_NAME}-utilities/${TARGET_NAME}-utilities-alsa-link.c
${TARGET_NAME}-utilities/${TARGET_NAME}-utilities-data.c
${TARGET_NAME}-utilities/${TARGET_NAME}-utilities-verbs-loader.c
${TARGET_NAME}-manager/${TARGET_NAME}-manager.c
${TARGET_NAME}-manager/${TARGET_NAME}-manager-cb.c
${TARGET_NAME}-manager/${TARGET_NAME}-manager-events.c
+ ${TARGET_NAME}-controllers/${TARGET_NAME}-controllers-alsacore-link.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