]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
ALSA: aloop: Add control element for getting the access mode
authorIvan Orlov <ivan.orlov0322@gmail.com>
Wed, 27 Sep 2023 11:35:55 +0000 (12:35 +0100)
committerTakashi Iwai <tiwai@suse.de>
Fri, 6 Oct 2023 09:11:40 +0000 (11:11 +0200)
Add new control element 'PCM Slave Access Mode' which shows the access
mode (interleaved/non-interleaved) for the PCM playing device. Add
corresponding control change notification calls.

Signed-off-by: Ivan Orlov <ivan.orlov0322@gmail.com>
Reviewed-by: Jaroslav Kysela <perex@perex.cz>
Link: https://lore.kernel.org/r/20230927113555.14877-2-ivan.orlov0322@gmail.com
Signed-off-by: Takashi Iwai <tiwai@suse.de>
sound/drivers/aloop.c

index ab116b1fed96916b07096ea22b4db7ac2eac255b..e87dc67f33c692567da42cffc97d0cd072818b5a 100644 (file)
@@ -119,11 +119,13 @@ struct loopback_setup {
        unsigned int rate_shift;
        snd_pcm_format_t format;
        unsigned int rate;
+       snd_pcm_access_t access;
        unsigned int channels;
        struct snd_ctl_elem_id active_id;
        struct snd_ctl_elem_id format_id;
        struct snd_ctl_elem_id rate_id;
        struct snd_ctl_elem_id channels_id;
+       struct snd_ctl_elem_id access_id;
 };
 
 struct loopback {
@@ -367,6 +369,11 @@ static int loopback_check_format(struct loopback_cable *cable, int stream)
                                                        &setup->channels_id);
                        setup->channels = runtime->channels;
                }
+               if (setup->access != runtime->access) {
+                       snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE,
+                                                       &setup->access_id);
+                       setup->access = runtime->access;
+               }
        }
        return 0;
 }
@@ -1520,6 +1527,30 @@ static int loopback_channels_get(struct snd_kcontrol *kcontrol,
        return 0;
 }
 
+static int loopback_access_info(struct snd_kcontrol *kcontrol,
+                               struct snd_ctl_elem_info *uinfo)
+{
+       const char * const texts[] = {"Interleaved", "Non-interleaved"};
+
+       return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(texts), texts);
+}
+
+static int loopback_access_get(struct snd_kcontrol *kcontrol,
+                              struct snd_ctl_elem_value *ucontrol)
+{
+       struct loopback *loopback = snd_kcontrol_chip(kcontrol);
+       snd_pcm_access_t access;
+
+       mutex_lock(&loopback->cable_lock);
+       access = loopback->setup[kcontrol->id.subdevice][kcontrol->id.device].access;
+
+       ucontrol->value.enumerated.item[0] = access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED ||
+                                            access == SNDRV_PCM_ACCESS_MMAP_NONINTERLEAVED;
+
+       mutex_unlock(&loopback->cable_lock);
+       return 0;
+}
+
 static const struct snd_kcontrol_new loopback_controls[]  = {
 {
        .iface =        SNDRV_CTL_ELEM_IFACE_PCM,
@@ -1566,7 +1597,15 @@ static const struct snd_kcontrol_new loopback_controls[]  = {
        .name =         "PCM Slave Channels",
        .info =         loopback_channels_info,
        .get =          loopback_channels_get
-}
+},
+#define ACCESS_IDX 6
+{
+       .access =       SNDRV_CTL_ELEM_ACCESS_READ,
+       .iface =        SNDRV_CTL_ELEM_IFACE_PCM,
+       .name =         "PCM Slave Access Mode",
+       .info =         loopback_access_info,
+       .get =          loopback_access_get,
+},
 };
 
 static int loopback_mixer_new(struct loopback *loopback, int notify)
@@ -1587,6 +1626,7 @@ static int loopback_mixer_new(struct loopback *loopback, int notify)
                        setup->notify = notify;
                        setup->rate_shift = NO_PITCH;
                        setup->format = SNDRV_PCM_FORMAT_S16_LE;
+                       setup->access = SNDRV_PCM_ACCESS_RW_INTERLEAVED;
                        setup->rate = 48000;
                        setup->channels = 2;
                        for (idx = 0; idx < ARRAY_SIZE(loopback_controls);
@@ -1618,6 +1658,9 @@ static int loopback_mixer_new(struct loopback *loopback, int notify)
                                case CHANNELS_IDX:
                                        setup->channels_id = kctl->id;
                                        break;
+                               case ACCESS_IDX:
+                                       setup->access_id = kctl->id;
+                                       break;
                                default:
                                        break;
                                }