mixer: Add get_card_name() API
[android-sdk/platform-external-tinyalsa.git] / mixer.c
diff --git a/mixer.c b/mixer.c
index 4568cca2bfed71746b551b397f2a12e09207b894..8a0add01c2823b856751c2f9c8016382f776eefa 100644 (file)
--- a/mixer.c
+++ b/mixer.c
@@ -495,3 +495,35 @@ int mixer_ctl_set_enum_by_string(struct mixer_ctl *ctl, const char *string)
     return -EINVAL;
 }
 
+#ifdef OMAP_ENHANCEMENT
+int mixer_get_card_name(int card, char *str, size_t strlen)
+{
+    struct snd_ctl_card_info info;
+    char fn[256];
+    int fd;
+    int ret;
+
+    if (card > MAX_CARD_COUNT)
+        return -EINVAL;
+
+    if (!str)
+        return -EINVAL;
+
+    snprintf(fn, sizeof(fn), "/dev/snd/controlC%u", card);
+    fd = open(fn, O_RDWR);
+    if (fd < 0)
+        return -ENODEV;
+
+    ret = ioctl(fd, SNDRV_CTL_IOCTL_CARD_INFO, &info);
+    if (ret < 0) {
+        close(fd);
+        return ret;
+    }
+
+    strncpy(str, (char *)info.id, strlen);
+
+    close(fd);
+
+    return 0;
+}
+#endif