aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--alsa-binding/Alsa-ApiHat.h1
-rw-r--r--alsa-binding/Alsa-SetGet.c60
2 files changed, 39 insertions, 22 deletions
diff --git a/alsa-binding/Alsa-ApiHat.h b/alsa-binding/Alsa-ApiHat.h
index 0300f3d..59a9b0c 100644
--- a/alsa-binding/Alsa-ApiHat.h
+++ b/alsa-binding/Alsa-ApiHat.h
@@ -90,6 +90,7 @@ extern const struct afb_binding_interface *afbIface;
PUBLIC json_object *alsaCheckQuery (afb_req_t request, queryValuesT *queryValues);
// AlseCoreSetGet exports
+PUBLIC int getCardNbFromCardPath(char *cardPath);
PUBLIC json_object *getCardInfo(int card);
PUBLIC int alsaGetSingleCtl (snd_ctl_t *ctlDev, snd_ctl_elem_id_t *elemId, ctlRequestT *ctlRequest, queryModeE queryMode);
PUBLIC void alsaGetInfo (afb_req_t request);
diff --git a/alsa-binding/Alsa-SetGet.c b/alsa-binding/Alsa-SetGet.c
index e8c6563..8c189de 100644
--- a/alsa-binding/Alsa-SetGet.c
+++ b/alsa-binding/Alsa-SetGet.c
@@ -345,14 +345,43 @@ STATIC json_object *decodeTlv(unsigned int *tlv, unsigned int tlv_size, int mode
return (decodeTlvJson);
}
-STATIC int searchInQueryForAlsaCardToProbe(queryCardInfo *queryInfo, int *cardToProbe)
-{
- int err, cardPathFileId;
+PUBLIC int getCardNbFromCardPath(char *cardPath) {
+ int err, cardPathFileFd, fileCardId;
snd_ctl_card_info_t *currentCardInfo;
+ if (! cardPath)
+ return -1;
+
+ cardPathFileFd = open(cardPath, O_RDONLY);
+ if (cardPathFileFd < 0) {
+ AFB_ERROR("CardPath '%s' error %i during open", cardPath, cardPathFileFd);
+ return -2;
+ }
+
snd_ctl_card_info_alloca(&currentCardInfo);
+ err = ioctl(cardPathFileFd, SNDRV_CTL_IOCTL_CARD_INFO(snd_ctl_card_info_sizeof()), currentCardInfo);
+ close(cardPathFileFd);
+ if (err < 0) {
+ AFB_ERROR("CardPath '%s' error %i during ioctl", cardPath, err);
+ return -3;
+ }
+
+ fileCardId = snd_ctl_card_info_get_card(currentCardInfo);
+
+ if (fileCardId < 0 || fileCardId >= MAX_SND_CARD) {
+ AFB_ERROR("CardPath '%s' returned an incorrect card number %i", cardPath, fileCardId);
+ return -4;
+ }
+
+ return fileCardId;
+}
+
+STATIC int searchInQueryForAlsaCardToProbe(queryCardInfo *queryInfo, int *cardToProbe)
+{
+ int err;
+
if(! queryInfo) {
AFB_ERROR("Structure to look for an ALSA card is NULL");
return -1;
@@ -381,31 +410,18 @@ STATIC int searchInQueryForAlsaCardToProbe(queryCardInfo *queryInfo, int *cardTo
}
if(queryInfo->cardPath) {
- cardPathFileId = open(queryInfo->cardPath, O_RDONLY);
- if(cardPathFileId < 0) {
- AFB_ERROR("CardPath '%s' error %i during open", queryInfo->cardPath, cardPathFileId);
- return -4;
- }
+ *cardToProbe = getCardNbFromCardPath(queryInfo->cardPath);
- err = ioctl(cardPathFileId, SNDRV_CTL_IOCTL_CARD_INFO(snd_ctl_card_info_sizeof()), currentCardInfo);
- close(cardPathFileId);
-
- *cardToProbe = snd_ctl_card_info_get_card(currentCardInfo);
-
- if(err < 0) {
- AFB_ERROR("CardPath '%s' error %i during ioctl", queryInfo->cardPath, err);
- return -5;
- }
- else if(*cardToProbe < 0 || *cardToProbe >= MAX_SND_CARD) {
+ if(*cardToProbe < 0 || *cardToProbe >= MAX_SND_CARD) {
AFB_ERROR("CardPath '%s' returned an incorrect card number %i", queryInfo->cardPath, *cardToProbe);
- return -6;
+ return -4;
}
else if(queryInfo->cardNb != NO_CARD_SELECTED && *cardToProbe != queryInfo->cardNb) {
AFB_WARNING("CardPath '%s' (id %i) is not corresponding to the requested card number %i",
queryInfo->cardPath,
*cardToProbe,
queryInfo->cardNb);
- return -7;
+ return -5;
}
queryInfo->cardNb = *cardToProbe;
@@ -417,12 +433,12 @@ STATIC int searchInQueryForAlsaCardToProbe(queryCardInfo *queryInfo, int *cardTo
err = snd_card_next(cardToProbe);
if(err < 0) {
AFB_ERROR("Error %i happened when tried to get next ALSA card number", err);
- return -8;
+ return -6;
}
if(*cardToProbe < 0) {
AFB_NOTICE("No ALSA card connected");
- return -9;
+ return -7;
}
return 1;