]> git.sesse.net Git - vlc/blobdiff - modules/access/alsa.c
Do not uselessly include vlc_vout.h in access.
[vlc] / modules / access / alsa.c
index db7ee7f6d1b700176bc19efd40f46cbb92b51deb..d8b4b45759533f9b1c5e077360212bca9964de59 100644 (file)
@@ -44,7 +44,6 @@
 #include <vlc_access.h>
 #include <vlc_demux.h>
 #include <vlc_input.h>
-#include <vlc_vout.h>
 
 #include <ctype.h>
 #include <fcntl.h>
@@ -83,23 +82,23 @@ static void DemuxClose( vlc_object_t * );
 #define ALSA_DEFAULT "hw"
 #define CFG_PREFIX "alsa-"
 
-vlc_module_begin();
-    set_shortname( N_("Alsa") );
-    set_description( N_("Alsa audio capture input") );
-    set_category( CAT_INPUT );
-    set_subcategory( SUBCAT_INPUT_ACCESS );
+vlc_module_begin()
+    set_shortname( N_("Alsa") )
+    set_description( N_("Alsa audio capture input") )
+    set_category( CAT_INPUT )
+    set_subcategory( SUBCAT_INPUT_ACCESS )
 
-    add_shortcut( "alsa" );
-    set_capability( "access_demux", 10 );
-    set_callbacks( DemuxOpen, DemuxClose );
+    add_shortcut( "alsa" )
+    set_capability( "access_demux", 10 )
+    set_callbacks( DemuxOpen, DemuxClose )
 
     add_bool( CFG_PREFIX "stereo", true, NULL, STEREO_TEXT, STEREO_LONGTEXT,
-                true );
+                true )
     add_integer( CFG_PREFIX "samplerate", 48000, NULL, SAMPLERATE_TEXT,
-                SAMPLERATE_LONGTEXT, true );
+                SAMPLERATE_LONGTEXT, true )
     add_integer( CFG_PREFIX "caching", DEFAULT_PTS_DELAY / 1000, NULL,
-                CACHING_TEXT, CACHING_LONGTEXT, true );
-vlc_module_end();
+                CACHING_TEXT, CACHING_LONGTEXT, true )
+vlc_module_end()
 
 /*****************************************************************************
  * Access: local prototypes
@@ -119,7 +118,7 @@ struct demux_sys_t
     const char *psz_device;  /* Alsa device from MRL */
 
     /* Audio */
-    int i_pts;
+    int i_cache;
     unsigned int i_sample_rate;
     bool b_stereo;
     size_t i_max_frame_size;
@@ -151,6 +150,46 @@ static int FindMainDevice( demux_t *p_demux )
     return VLC_SUCCESS;
 }
 
+static void ListAvailableDevices( demux_t *p_demux )
+{
+    snd_ctl_card_info_t *p_info = NULL;
+    snd_ctl_card_info_alloca( &p_info );
+
+    snd_pcm_info_t *p_pcminfo = NULL;
+    snd_pcm_info_alloca( &p_pcminfo );
+
+    msg_Dbg( p_demux, "Available alsa capture devices:" );
+    int i_card = -1;
+    while( !snd_card_next( &i_card ) && i_card >= 0 )
+    {
+        char psz_devname[10];
+        snprintf( psz_devname, 10, "hw:%d", i_card );
+
+        snd_ctl_t *p_ctl = NULL;
+        if( snd_ctl_open( &p_ctl, psz_devname, 0 ) < 0 ) continue;
+
+        snd_ctl_card_info( p_ctl, p_info );
+        msg_Dbg( p_demux, "  %s (%s)",
+                 snd_ctl_card_info_get_id( p_info ),
+                 snd_ctl_card_info_get_name( p_info ) );
+
+        int i_dev = -1;
+        while( !snd_ctl_pcm_next_device( p_ctl, &i_dev ) && i_dev >= 0 )
+        {
+            snd_pcm_info_set_device( p_pcminfo, i_dev );
+            snd_pcm_info_set_subdevice( p_pcminfo, 0 );
+            snd_pcm_info_set_stream( p_pcminfo, SND_PCM_STREAM_CAPTURE );
+            if( snd_ctl_pcm_info( p_ctl, p_pcminfo ) < 0 ) continue;
+
+            msg_Dbg( p_demux, "    hw:%d,%d : %s (%s)", i_card, i_dev,
+                     snd_pcm_info_get_id( p_pcminfo ),
+                     snd_pcm_info_get_name( p_pcminfo ) );
+        }
+
+        snd_ctl_close( p_ctl );
+    }
+}
+
 /*****************************************************************************
  * DemuxOpen: opens alsa device, access_demux callback
  *****************************************************************************
@@ -178,7 +217,7 @@ static int DemuxOpen( vlc_object_t *p_this )
 
     p_sys->i_sample_rate = var_CreateGetInteger( p_demux, CFG_PREFIX "samplerate" );
     p_sys->b_stereo = var_CreateGetBool( p_demux, CFG_PREFIX "stereo" );
-    p_sys->i_pts = var_CreateGetInteger( p_demux, CFG_PREFIX "caching" );
+    p_sys->i_cache = var_CreateGetInteger( p_demux, CFG_PREFIX "caching" );
     p_sys->p_es = NULL;
     p_sys->p_block = NULL;
     p_sys->i_next_demux_date = -1;
@@ -186,7 +225,10 @@ static int DemuxOpen( vlc_object_t *p_this )
     if( p_demux->psz_path && *p_demux->psz_path )
         p_sys->psz_device = p_demux->psz_path;
     else
+    {
         p_sys->psz_device = ALSA_DEFAULT;
+        ListAvailableDevices( p_demux );
+    }
 
     if( FindMainDevice( p_demux ) != VLC_SUCCESS )
     {
@@ -237,7 +279,7 @@ static int DemuxControl( demux_t *p_demux, int i_query, va_list args )
 
         case DEMUX_GET_PTS_DELAY:
             pi64 = (int64_t*)va_arg( args, int64_t * );
-            *pi64 = (int64_t)p_sys->i_pts * 1000;
+            *pi64 = (int64_t)p_sys->i_cache * 1000;
             return VLC_SUCCESS;
 
         case DEMUX_GET_TIME: