aboutsummaryrefslogtreecommitdiffstats
path: root/lib/4a-hal-utilities
diff options
context:
space:
mode:
Diffstat (limited to 'lib/4a-hal-utilities')
-rw-r--r--lib/4a-hal-utilities/4a-hal-utilities-data.c195
-rw-r--r--lib/4a-hal-utilities/4a-hal-utilities-data.h47
2 files changed, 242 insertions, 0 deletions
diff --git a/lib/4a-hal-utilities/4a-hal-utilities-data.c b/lib/4a-hal-utilities/4a-hal-utilities-data.c
index 10fdf27..5bd6b27 100644
--- a/lib/4a-hal-utilities/4a-hal-utilities-data.c
+++ b/lib/4a-hal-utilities/4a-hal-utilities-data.c
@@ -28,6 +28,199 @@
#include "4a-hal-utilities-alsa-data.h"
/*******************************************************************************
+ * Internal Hal - Probed devices structure handling functions *
+ ******************************************************************************/
+
+enum ProbedDeviceClasses HalUtlGetProbedDeviceClassFromString(char *probedDeviceString)
+{
+ if(! probedDeviceString)
+ return INVALID_PROBED_DEVICE;
+
+ if(! strcasecmp("static", probedDeviceString))
+ return STATIC_PROBED_DEVICE;
+
+ if(! strcasecmp("dynamic", probedDeviceString))
+ return DYNAMIC_PROBED_DEVICE;
+
+ if(! strcasecmp("mandatory", probedDeviceString))
+ return MANDATORY_PROBED_DEVICE;
+
+ return INVALID_PROBED_DEVICE;
+}
+
+struct InternalHalProbedDevice *HalUtlAddProbedDeviceToProbedDeviceList(struct InternalHalProbedDevice **probedDevicesList)
+{
+ struct InternalHalProbedDevice *currentProbedDevice;
+
+ if(! probedDevicesList)
+ return NULL;
+
+ currentProbedDevice = *probedDevicesList;
+ if(! currentProbedDevice) {
+ currentProbedDevice = (struct InternalHalProbedDevice *) calloc(1, sizeof(struct InternalHalProbedDevice));
+ if(! currentProbedDevice)
+ return NULL;
+
+ *probedDevicesList = currentProbedDevice;
+ }
+ else {
+ while(currentProbedDevice->next)
+ currentProbedDevice = currentProbedDevice->next;
+
+ currentProbedDevice->next = calloc(1, sizeof(struct InternalHalProbedDevice));
+ if(! currentProbedDevice->next)
+ return NULL;
+
+ currentProbedDevice = currentProbedDevice->next;
+ }
+
+ return currentProbedDevice;
+}
+
+int HalUtlRemoveSelectedProbedDeviceFromList(struct InternalHalProbedDevice **probedDevicesList, struct InternalHalProbedDevice *probedDeviceToRemove)
+{
+ struct InternalHalProbedDevice *currentProbedDevice, *matchingProbedDevice;
+
+ if(! probedDevicesList || ! *probedDevicesList || ! probedDeviceToRemove)
+ return -1;
+
+ currentProbedDevice = *probedDevicesList;
+ if(currentProbedDevice == probedDeviceToRemove) {
+ *probedDevicesList = currentProbedDevice->next;
+ matchingProbedDevice = currentProbedDevice;
+ }
+ else {
+ while(currentProbedDevice && currentProbedDevice->next != probedDeviceToRemove)
+ currentProbedDevice = currentProbedDevice->next;
+
+ if(currentProbedDevice) {
+ matchingProbedDevice = currentProbedDevice->next;
+ currentProbedDevice->next = currentProbedDevice->next->next;
+ }
+ else {
+ return -2;
+ }
+ }
+
+ free(matchingProbedDevice->uid);
+
+ if(matchingProbedDevice->deviceData) {
+ free(matchingProbedDevice->deviceData->extendedCardNb);
+ free(matchingProbedDevice->deviceData->cardId);
+ free(matchingProbedDevice->deviceData->cardShortName);
+ free(matchingProbedDevice->deviceData->cardLongName);
+ free(matchingProbedDevice->deviceData->cardDriver);
+ free(matchingProbedDevice->deviceData->cardMixerName);
+ free(matchingProbedDevice->deviceData->cardComponents);
+ free(matchingProbedDevice->deviceData->playbackDeviceId);
+ free(matchingProbedDevice->deviceData->playbackDeviceName);
+
+ free(matchingProbedDevice->deviceData);
+ }
+
+ if(matchingProbedDevice->requestedDeviceJ)
+ json_object_put(matchingProbedDevice->requestedDeviceJ);
+
+ free(matchingProbedDevice);
+
+ return 0;
+}
+
+int HalUtlRemoveAllProbedDevicesFromList(struct InternalHalProbedDevice **probedDevicesList)
+{
+ int probedDevicesRemoved = 0;
+
+ if(! probedDevicesList)
+ return -1;
+
+ if(! *probedDevicesList)
+ return 0;
+
+ while(*probedDevicesList) {
+ if(HalUtlRemoveSelectedProbedDeviceFromList(probedDevicesList, *probedDevicesList))
+ return -2;
+
+ probedDevicesRemoved++;
+ }
+
+ return probedDevicesRemoved;
+}
+
+int HalUtlGetNumberOfProbedDevicesInList(struct InternalHalProbedDevice **probedDevicesList)
+{
+ int numberOfProbedDevices = 0;
+ struct InternalHalProbedDevice *currentProbedDevice;
+
+ if(! probedDevicesList)
+ return -1;
+
+ currentProbedDevice = *probedDevicesList;
+ while(currentProbedDevice) {
+ currentProbedDevice = currentProbedDevice->next;
+ numberOfProbedDevices++;
+ }
+
+ return numberOfProbedDevices;
+}
+
+struct InternalHalProbedDevice *HalUtlSearchProbedDeviceDataById(struct InternalHalProbedDevice **probedDevicesList, char *uid)
+{
+ struct InternalHalProbedDevice *currentProbedDevice;
+
+ if(! probedDevicesList || ! *probedDevicesList || ! uid)
+ return NULL;
+
+ currentProbedDevice = *probedDevicesList;
+ while(currentProbedDevice) {
+ if(! strcmp(uid, currentProbedDevice->uid))
+ return currentProbedDevice;
+
+ currentProbedDevice = currentProbedDevice->next;
+ }
+
+ return NULL;
+}
+
+struct InternalHalDeviceData *HalUtlAllocateAndFillProbedDeviceDataUsingInfoGetResponse(json_object *responseJ)
+{
+ struct InternalHalDeviceData *currentProbedDeviceData;
+
+ if(! responseJ)
+ return NULL;
+
+ currentProbedDeviceData = calloc(1, sizeof(struct InternalHalDeviceData));
+ if(! currentProbedDeviceData)
+ return NULL;
+
+ currentProbedDeviceData->cardNb = HAL_UNKNOWN_DEVICE;
+ currentProbedDeviceData->playbackDeviceNb = HAL_UNKNOWN_DEVICE;
+
+ if(wrap_json_unpack(responseJ, "{s:i, s:s, s:s, s:s, s:s, s:s, s:s, s?:i, s?:s, s?:s !}",
+ "cardNb", &currentProbedDeviceData->cardNb,
+ "cardId", &currentProbedDeviceData->cardId,
+ "cardShortName", &currentProbedDeviceData->cardShortName,
+ "cardLongName", &currentProbedDeviceData->cardLongName,
+ "cardDriver", &currentProbedDeviceData->cardDriver,
+ "cardMixerName", &currentProbedDeviceData->cardMixerName,
+ "cardComponents", &currentProbedDeviceData->cardComponents,
+ "playbackDeviceNb", &currentProbedDeviceData->playbackDeviceNb,
+ "playbackDeviceId", &currentProbedDeviceData->playbackDeviceId,
+ "playbackDeviceName", &currentProbedDeviceData->playbackDeviceName) ||
+ currentProbedDeviceData->cardNb == HAL_UNKNOWN_DEVICE ||
+ (currentProbedDeviceData->playbackDeviceNb == HAL_UNKNOWN_DEVICE &&
+ asprintf(&currentProbedDeviceData->extendedCardNb, "hw:%i", currentProbedDeviceData->cardNb) < 0) ||
+ (currentProbedDeviceData->playbackDeviceNb != HAL_UNKNOWN_DEVICE &&
+ asprintf(&currentProbedDeviceData->extendedCardNb, "hw:%i,%i",
+ currentProbedDeviceData->cardNb,
+ currentProbedDeviceData->playbackDeviceNb) < 0)) {
+ free(currentProbedDeviceData);
+ return NULL;
+ }
+
+ return currentProbedDeviceData;
+}
+
+/*******************************************************************************
* Internal Hal - Streams data handling functions *
******************************************************************************/
@@ -217,6 +410,8 @@ int HalUtlRemoveSelectedHalFromList(struct HalData **halDataList, struct HalData
if(matchingHal->internal) {
free(matchingHal->internalHalData->mixerApiName);
free(matchingHal->internalHalData->prefix);
+
+ HalUtlRemoveAllProbedDevicesFromList(&matchingHal->internalHalData->probedDevicesList);
HalUtlRemoveAllMixerData(&matchingHal->internalHalData->streamsData);
diff --git a/lib/4a-hal-utilities/4a-hal-utilities-data.h b/lib/4a-hal-utilities/4a-hal-utilities-data.h
index dd89078..c072650 100644
--- a/lib/4a-hal-utilities/4a-hal-utilities-data.h
+++ b/lib/4a-hal-utilities/4a-hal-utilities-data.h
@@ -28,6 +28,8 @@
#include "4a-hal-utilities-alsa-data.h"
+#define HAL_UNKNOWN_DEVICE -1
+
#define HAL_STREAM_UPDATES_EVENT_NAME "stream-updates"
// Enum for hal status
@@ -37,6 +39,40 @@ enum HalStatus {
HAL_STATUS_READY=2
};
+// Enum for probed devices (dependencies) class
+enum ProbedDeviceClasses {
+ INVALID_PROBED_DEVICE=0,
+ STATIC_PROBED_DEVICE=1,
+ DYNAMIC_PROBED_DEVICE=2,
+ MANDATORY_PROBED_DEVICE=3
+};
+
+// Structure to store data for audio devices validated by dependencies
+struct InternalHalDeviceData {
+ int cardNb;
+ char *cardId;
+ char *cardShortName;
+ char *cardLongName;
+ char *cardDriver;
+ char *cardMixerName;
+ char *cardComponents;
+ int playbackDeviceNb;
+ char *playbackDeviceId;
+ char *playbackDeviceName;
+ char *extendedCardNb;
+};
+
+// Structure to store one provided dependency
+struct InternalHalProbedDevice {
+ char *uid;
+ enum ProbedDeviceClasses deviceClass;
+ json_object *requestedDeviceJ;
+
+ struct InternalHalDeviceData *deviceData;
+
+ struct InternalHalProbedDevice *next;
+};
+
// Structure to store stream data
struct InternalHalMixerData {
char *verb;
@@ -53,6 +89,8 @@ struct InternalHalData {
char *prefix;
json_object *halMixerJ;
+ struct InternalHalProbedDevice *probedDevicesList;
+
struct InternalHalMixerData *streamsData;
afb_event_t streamUpdates;
@@ -92,6 +130,15 @@ struct HalMgrData {
struct HalData *halDataList;
};
+// Internal Hal - Probed devices structure handling functions
+enum ProbedDeviceClasses HalUtlGetProbedDeviceClassFromString(char *probedDeviceString);
+struct InternalHalProbedDevice *HalUtlAddProbedDeviceToProbedDeviceList(struct InternalHalProbedDevice **probedDevicesList);
+int HalUtlRemoveSelectedProbedDeviceFromList(struct InternalHalProbedDevice **probedDevicesList, struct InternalHalProbedDevice *probedDeviceToRemove);
+int HalUtlRemoveAllProbedDevicesFromList(struct InternalHalProbedDevice **probedDevicesList);
+int HalUtlGetNumberOfProbedDevicesInList(struct InternalHalProbedDevice **probedDevicesList);
+struct InternalHalProbedDevice *HalUtlSearchProbedDeviceDataById(struct InternalHalProbedDevice **probedDevicesList, char *uid);
+struct InternalHalDeviceData *HalUtlAllocateAndFillProbedDeviceDataUsingInfoGetResponse(json_object *responseJ);
+
// Internal Hal - Streams data handling functions
struct InternalHalMixerData *HalUtlAddMixerDataToMixerDataList(struct InternalHalMixerData **mixerDataList);
int HalUtlRemoveSelectedMixerData(struct InternalHalMixerData **mixerDataList, struct InternalHalMixerData *mixerDataToRemove);