]> git.sesse.net Git - vlc/blobdiff - modules/audio_output/alsa.c
fixed some insanities which coused this module to fail on a52 sound
[vlc] / modules / audio_output / alsa.c
index 7e5ca61eace876a73727422e68fe82f77bc915c1..22a73d07ff2d979a215d5413d3c9245d36231940 100644 (file)
@@ -2,7 +2,7 @@
  * alsa.c : alsa plugin for vlc
  *****************************************************************************
  * Copyright (C) 2000-2001 VideoLAN
- * $Id: alsa.c,v 1.8 2002/08/25 09:39:59 sam Exp $
+ * $Id: alsa.c,v 1.12 2002/09/30 21:32:32 massiot Exp $
  *
  * Authors: Henri Fallon <henri@videolan.org> - Original Author
  *          Jeffrey Baker <jwbaker@acm.org> - Port to ALSA 1.0 API
@@ -52,8 +52,6 @@ struct aout_sys_t
     snd_pcm_sframes_t   i_buffer_size;
     int                 i_period_time;
 
-    volatile vlc_bool_t b_initialized;
-
     volatile vlc_bool_t b_can_sleek;
 
 #ifdef DEBUG
@@ -77,10 +75,7 @@ struct aout_sys_t
  *****************************************************************************/
 static int  Open         ( vlc_object_t * );
 static void Close        ( vlc_object_t * );
-
-static int  SetFormat    ( aout_instance_t * );
 static void Play         ( aout_instance_t * );
-
 static int  ALSAThread   ( aout_instance_t * );
 static void ALSAFill     ( aout_instance_t * );
 
@@ -105,6 +100,18 @@ static int Open( vlc_object_t *p_this )
     aout_instance_t * p_aout = (aout_instance_t *)p_this;
     struct aout_sys_t * p_sys;
 
+    int i_snd_rc;
+
+    char * psz_device;
+    char psz_alsadev[128];
+    char * psz_userdev;
+
+    int i_format;
+    int i_channels;
+
+    snd_pcm_hw_params_t *p_hw;
+    snd_pcm_sw_params_t *p_sw;
+
     /* Allocate structures */
     p_aout->output.p_sys = p_sys = malloc( sizeof( aout_sys_t ) );
     if( p_sys == NULL )
@@ -113,47 +120,12 @@ static int Open( vlc_object_t *p_this )
         return -1;
     }
 
-    /* Create ALSA thread and wait for its readiness. */
-    p_sys->b_initialized = VLC_FALSE;
-    if( vlc_thread_create( p_aout, "aout", ALSAThread, VLC_FALSE ) )
-    {
-        msg_Err( p_aout, "cannot create ALSA thread (%s)", strerror(errno) );
-        free( p_sys );
-        return -1;
-    }
-
-    p_aout->output.pf_setformat = SetFormat;
     p_aout->output.pf_play = Play;
 
 #ifdef DEBUG
     snd_output_stdio_attach( &p_sys->p_snd_stderr, stderr, 0 );
 #endif
 
-    return 0;
-}
-
-/*****************************************************************************
- * SetFormat : sets the alsa output format
- *****************************************************************************
- * This function prepares the device, sets the rate, format, the mode
- * ( "play as soon as you have data" ), and buffer information.
- *****************************************************************************/
-static int SetFormat( aout_instance_t * p_aout )
-{
-    struct aout_sys_t * p_sys = p_aout->output.p_sys;
-
-    int i_snd_rc;
-
-    char * psz_device;
-    char psz_alsadev[128];
-    char * psz_userdev;
-
-    int i_format;
-    int i_channels;
-
-    snd_pcm_hw_params_t *p_hw;
-    snd_pcm_sw_params_t *p_sw;
-
     /* Read in ALSA device preferences from configuration */
     psz_userdev = config_GetPsz( p_aout, "alsa-device" );
 
@@ -164,7 +136,7 @@ static int SetFormat( aout_instance_t * p_aout )
     else
     {
         /* Use the internal logic to decide on the device name */
-        if ( p_aout->output.output.i_format == AOUT_FMT_SPDIF )
+        if ( p_aout->output.output.i_format == VLC_FOURCC('s','p','d','i') )
         {
             /* Will probably need some little modification in the case
                we want to send some data at a different rate
@@ -178,10 +150,14 @@ static int SetFormat( aout_instance_t * p_aout )
                      "iec958:AES0=0x%x,AES1=0x%x,AES2=0x%x,AES3=0x%x",
                      s[0], s[1], s[2], s[3] );
             psz_device = psz_alsadev;
+
+            aout_VolumeNoneInit( p_aout );
         }
         else
         {
             psz_device = "default";
+
+            aout_VolumeSoftInit( p_aout );
         }
     }
 
@@ -204,7 +180,7 @@ static int SetFormat( aout_instance_t * p_aout )
     /* Default settings */
     p_sys->b_can_sleek = VLC_FALSE;
     i_channels = p_aout->output.output.i_channels;
-    if ( p_aout->output.output.i_format == AOUT_FMT_SPDIF )
+    if ( p_aout->output.output.i_format == VLC_FOURCC('s','p','d','i') )
     {
         p_sys->i_buffer_size = ALSA_SPDIF_BUFFER_SIZE;
         p_aout->output.i_nb_samples = ALSA_SPDIF_PERIOD_SIZE;
@@ -219,17 +195,11 @@ static int SetFormat( aout_instance_t * p_aout )
     /* Compute the settings */
     switch (p_aout->output.output.i_format)
     {
-        case AOUT_FMT_MU_LAW:    i_format = SND_PCM_FORMAT_MU_LAW; break;
-        case AOUT_FMT_A_LAW:     i_format = SND_PCM_FORMAT_A_LAW; break;
-        case AOUT_FMT_IMA_ADPCM: i_format = SND_PCM_FORMAT_IMA_ADPCM; break;
-        case AOUT_FMT_U8:        i_format = SND_PCM_FORMAT_U8; break;
-        case AOUT_FMT_S16_LE:    i_format = SND_PCM_FORMAT_S16_LE; break;
-        case AOUT_FMT_S16_BE:    i_format = SND_PCM_FORMAT_S16_BE; break;
-        case AOUT_FMT_S8:        i_format = SND_PCM_FORMAT_S8; break;
-        case AOUT_FMT_U16_LE:    i_format = SND_PCM_FORMAT_U16_LE; break;
-        case AOUT_FMT_U16_BE:    i_format = SND_PCM_FORMAT_U16_BE; break;
-        case AOUT_FMT_FLOAT32:   i_format = SND_PCM_FORMAT_FLOAT; break;
-        case AOUT_FMT_SPDIF:
+        case VLC_FOURCC('f','l','3','2'):
+            i_format = SND_PCM_FORMAT_FLOAT;
+            break;
+
+        case VLC_FOURCC('s','p','d','i'):
             /* Override some settings to make S/PDIF work */
             p_sys->b_can_sleek = VLC_TRUE;
             i_format = SND_PCM_FORMAT_S16_LE;
@@ -237,7 +207,6 @@ static int SetFormat( aout_instance_t * p_aout )
             p_aout->output.output.i_bytes_per_frame = AOUT_SPDIF_SIZE;
             p_aout->output.output.i_frame_length = ALSA_SPDIF_PERIOD_SIZE;
             break;
-        case AOUT_FMT_FIXED32:
         default:
             msg_Err( p_aout, "audio output format 0x%x not supported",
                      p_aout->output.output.i_format );
@@ -333,13 +302,20 @@ static int SetFormat( aout_instance_t * p_aout )
     snd_output_printf( p_sys->p_snd_stderr, "\n" );
 #endif
 
-    p_sys->b_initialized = VLC_TRUE;
+    /* Create ALSA thread and wait for its readiness. */
+    if( vlc_thread_create( p_aout, "aout", ALSAThread,
+                           VLC_THREAD_PRIORITY_OUTPUT, VLC_FALSE ) )
+    {
+        msg_Err( p_aout, "cannot create ALSA thread (%s)", strerror(errno) );
+        free( p_sys );
+        return -1;
+    }
 
     return 0;
 }
 
 /*****************************************************************************
- * Play: queue a buffer for playing by ALSAThread
+ * Play: nothing to do
  *****************************************************************************/
 static void Play( aout_instance_t *p_aout )
 {
@@ -382,9 +358,6 @@ static int ALSAThread( aout_instance_t * p_aout )
 {
     struct aout_sys_t * p_sys = p_aout->output.p_sys;
 
-    while ( !p_aout->b_die && !p_sys->b_initialized )
-        msleep( THREAD_SLEEP );
-
     while ( !p_aout->b_die )
     {
         ALSAFill( p_aout );