]> git.sesse.net Git - vlc/blobdiff - modules/audio_output/alsa.c
mux/mpeg/ts.c: support for libdvbpsi >= 1.0.0
[vlc] / modules / audio_output / alsa.c
index cd0a59391efbb72ada3cac5dddb5ddd9ccedd056..fa7d70fa7b4021beb0d849a4f9607c72210da4c0 100644 (file)
@@ -44,9 +44,9 @@ struct aout_sys_t
 {
     snd_pcm_t *pcm;
     unsigned rate; /**< Sample rate */
+    vlc_fourcc_t format; /**< Sample format */
     uint8_t chans_table[AOUT_CHAN_MAX]; /**< Channels order table */
     uint8_t chans_to_reorder; /**< Number of channels to reorder */
-    uint8_t bits; /**< Bits per sample per channel */
 
     bool soft_mute;
     float soft_gain;
@@ -460,7 +460,10 @@ static int Start (audio_output_t *aout, audio_sample_format_t *restrict fmt)
         channels = popcount (fmt->i_physical_channels);
     }
     else
+    {
+        sys->chans_to_reorder = 0;
         channels = 2;
+    }
     fmt->i_original_channels = fmt->i_physical_channels;
 
     /* By default, ALSA plug will pad missing channels with zeroes, which is
@@ -563,11 +566,7 @@ static int Start (audio_output_t *aout, audio_sample_format_t *restrict fmt)
         fmt->i_bytes_per_frame = AOUT_SPDIF_SIZE;
         fmt->i_frame_length = A52_FRAME_NB;
     }
-    else
-    {
-        aout_FormatPrepare (fmt);
-        sys->bits = fmt->i_bitspersample;
-    }
+    sys->format = fmt->i_format;
 
     aout->time_get = TimeGet;
     aout->play = Play;
@@ -611,7 +610,7 @@ static void Play (audio_output_t *aout, block_t *block)
 
     if (sys->chans_to_reorder != 0)
         aout_ChannelReorder(block->p_buffer, block->i_buffer,
-                           sys->chans_to_reorder, sys->chans_table, sys->bits);
+                           sys->chans_to_reorder, sys->chans_table, sys->format);
 
     snd_pcm_t *pcm = sys->pcm;
 
@@ -741,11 +740,6 @@ static int EnumDevices(vlc_object_t *obj, char const *varname,
     return n;
 }
 
-static int DevicesEnum (audio_output_t *aout, char ***idp, char ***namep)
-{
-    return EnumDevices (VLC_OBJECT(aout), NULL, idp, namep);
-}
-
 static int DeviceSelect (audio_output_t *aout, const char *id)
 {
     aout_sys_t *sys = aout->sys;
@@ -776,9 +770,24 @@ static int Open(vlc_object_t *obj)
     aout->start = Start;
     aout->stop = Stop;
     aout_SoftVolumeInit (aout);
-    aout->device_enum = DevicesEnum;
     aout->device_select = DeviceSelect;
     aout_DeviceReport (aout, sys->device);
+
+    /* ALSA does not support hot-plug events so list devices at startup */
+    char **ids, **names;
+    int count = EnumDevices (VLC_OBJECT(aout), NULL, &ids, &names);
+    if (count >= 0)
+    {
+        for (int i = 0; i < count; i++)
+        {
+            aout_HotplugReport (aout, ids[i], names[i]);
+            free (names[i]);
+            free (ids[i]);
+        }
+        free (names);
+        free (ids);
+    }
+
     return VLC_SUCCESS;
 error:
     free (sys);