[vlc-devel] commit: Alsa access: list available capture devices (Antoine Cellerier )

git version control git at videolan.org
Sat Mar 28 21:56:48 CET 2009


vlc | branch: master | Antoine Cellerier <dionoea at videolan.org> | Sat Mar 28 21:57:11 2009 +0100| [1e8e2c1cdb0df2e569c94c04a3aff15cec1e0423] | committer: Antoine Cellerier 

Alsa access: list available capture devices

Available capture devices will be listed in the debug output when no device is forces (alsa://).

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=1e8e2c1cdb0df2e569c94c04a3aff15cec1e0423
---

 modules/access/alsa.c |   43 +++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 43 insertions(+), 0 deletions(-)

diff --git a/modules/access/alsa.c b/modules/access/alsa.c
index ec3ef0c..43bd16f 100644
--- a/modules/access/alsa.c
+++ b/modules/access/alsa.c
@@ -151,6 +151,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
  *****************************************************************************
@@ -186,7 +226,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 )
     {




More information about the vlc-devel mailing list