]> git.alsa-project.org Git - alsa-lib.git/commitdiff
ucm: add _alibpref to get the private device prefix
authorJaroslav Kysela <perex@perex.cz>
Wed, 2 Jun 2021 09:09:43 +0000 (11:09 +0200)
committerJaroslav Kysela <perex@perex.cz>
Wed, 2 Jun 2021 09:09:46 +0000 (11:09 +0200)
It may be useful to get the device prefix for the local configuration.

Link: https://gitlab.freedesktop.org/pipewire/pipewire/-/issues/1251
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
include/use-case.h
src/ucm/main.c

index ec1a97b01e71d88b74e7cabf92cfdbed24489c24..7890358b8d8f4e8d3806aeff243a6e4c5441ef60 100644 (file)
@@ -258,6 +258,7 @@ int snd_use_case_get_list(snd_use_case_mgr_t *uc_mgr,
  *   - _verb           - return current verb
  *   - _file           - return configuration file loaded for current card
  *   - _alibcfg                - return private alsa-lib's configuration for current card
+ *   - _alibpref       - return private alsa-lib's configuration device prefix for current card
  *
  *   - [=]{NAME}[/[{modifier}|{/device}][/{verb}]]
  *                      - value identifier {NAME}
index 361952f6283042ebf2c93313e0d9fb0f214747e0..3c9ea15d564253f981acd0a98b39a8052b43cefe 100644 (file)
@@ -2138,6 +2138,25 @@ static int get_alibcfg(snd_use_case_mgr_t *uc_mgr, char **str)
        return 0;
 }
 
+/**
+ * \brief Get device prefix for private alsa-lib configuration
+ * \param uc_mgr Use case manager
+ * \param str Returned value string
+ * \return Zero on success (value is filled), otherwise a negative error code
+ */
+static int get_alibpref(snd_use_case_mgr_t *uc_mgr, char **str)
+{
+       const size_t l = 9;
+       char *s;
+
+       s = malloc(l);
+       if (s == NULL)
+               return -ENOMEM;
+       snprintf(s, l, "_ucm%04X", uc_mgr->ucm_card_number);
+       *str = s;
+       return 0;
+}
+
 /**
  * \brief Get current - string
  * \param uc_mgr Use case manager
@@ -2193,6 +2212,8 @@ int snd_use_case_get(snd_use_case_mgr_t *uc_mgr,
 
        } else if (strcmp(identifier, "_alibcfg") == 0) {
                err = get_alibcfg(uc_mgr, (char **)value);
+       } else if (strcmp(identifier, "_alibpref") == 0) {
+               err = get_alibpref(uc_mgr, (char **)value);
        } else if (identifier[0] == '_') {
                err = -ENOENT;
        } else {