[patch] user selection for ALSA device

John Paul Lorenti jpl31 at columbia.edu
Sat Jul 6 11:59:11 CEST 2002


The existing code for ALSA sound output uses the device 'default' for 
non-surround sound output and another fixed string for surround sound. 
The patch to vlc/plugins/alsa/alsa.c below creates a text box in the 
alsa plugin configuration to specify which device to use and a checkbox 
to switch between using the user-specified device and using the device 
choosing logic already in the code. By default, my code is set to use 
the device choosing logic that's already in the cvs tree so it shouldn't 
cause any problems.
This patch is useful because people may have multiple sound cards or a 
single card with multiple subdevices. For example, I have a card with 
Creative's ensoniq 1371 chipset. It has two devices, one which is 
intended for software synthesized midi and the other for general audio. 
Since ALSA's 'default' is translating to the same device my software 
midi setup uses, I can't use the midi at the same time as vlc. With my 
patch, I can set vlc to use the other subdevice and avoid the conflict. 
Feel free to put my name and email address in the file if you commit 
this patch. In any case, it would be satisfying for me if you decided to 
commit my patch.

John Paul


--- alsa.c    Sat Jul  6 05:02:37 2002
+++ alsa_userselect.c    Sat Jul  6 05:23:56 2002
@@ -49,7 +49,9 @@
  * Build configuration tree.
  
*****************************************************************************/
 MODULE_CONFIG_START
-
+    ADD_CATEGORY_HINT( N_("Device"), NULL )
+    ADD_STRING  ( "alsa-device","hw:0,0", NULL,  N_("Name") , NULL )
+    ADD_BOOL ( "alsa-userset", 0, NULL, N_("Use Device Specified 
Here"), N_("Use the User Specified Device Here Rather Than the Internal 
Device Choosing Logic"))
 MODULE_CONFIG_STOP
 
 MODULE_INIT_START
@@ -90,6 +92,9 @@
     unsigned int  bytes_per_sample;
     unsigned int  samples_per_frame;
     unsigned int  bytes_per_frame;
+    /* Allows user to choose which ALSA device to use */
+    vlc_bool_t    b_useusersetting;
+    char *        psz_device;
 };
 
 /*****************************************************************************
@@ -123,19 +128,42 @@
         return -1;
     }
 
-    if( p_aout->i_format != AOUT_FMT_AC3 )
+    /* Read in ALSA device preferences from configuration */
+
+    if( !(p_aout->p_sys->b_useusersetting = config_GetInt( p_aout, 
"alsa-userset" )))
+    {
+       /* Use the internal logic instead */
+       p_aout->p_sys->b_useusersetting = VLC_FALSE;
+    }
+
+    if( !(p_aout->p_sys->psz_device = config_GetPsz( p_aout, 
"alsa-device")))
+    {
+       /* Use the internal logic instead */
+       p_aout->p_sys->b_useusersetting = VLC_FALSE;
+    }
+
+    if (p_aout->p_sys->b_useusersetting)
     {
-        strcpy( psz_alsadev, "default" );
+       /* Use the device name specified by the user */
+       strncpy( psz_alsadev, p_aout->p_sys->psz_device , 128 );
     }
     else
     {
-        unsigned char s[4];
-        s[0] = IEC958_AES0_CON_EMPHASIS_NONE | IEC958_AES0_NONAUDIO;
-        s[1] = IEC958_AES1_CON_ORIGINAL | IEC958_AES1_CON_PCM_CODER;
-        s[2] = 0;
-        s[3] = IEC958_AES3_CON_FS_48000;
-        sprintf( psz_alsadev, 
"iec958:AES0=0x%x,AES1=0x%x,AES2=0x%x,AES3=0x%x",
+       /* Use the internal logic to decide on the device name */ 
+       if( p_aout->i_format != AOUT_FMT_AC3 )
+       {
+          strcpy( psz_alsadev, "default" );
+       }
+       else
+       {
+          unsigned char s[4];
+          s[0] = IEC958_AES0_CON_EMPHASIS_NONE | IEC958_AES0_NONAUDIO;
+          s[1] = IEC958_AES1_CON_ORIGINAL | IEC958_AES1_CON_PCM_CODER;
+          s[2] = 0;
+          s[3] = IEC958_AES3_CON_FS_48000;
+          sprintf( psz_alsadev, 
"iec958:AES0=0x%x,AES1=0x%x,AES2=0x%x,AES3=0x%x",
                  s[0], s[1], s[2], s[3] );
+       }
     }
 
     /* Open device */



-- 
This is the vlc-devel mailing-list, see http://www.videolan.org/vlc/
To unsubscribe, please read http://www.videolan.org/lists.html
If you are in trouble, please contact <postmaster at videolan.org>



More information about the vlc-devel mailing list