]> git.sesse.net Git - vlc/blobdiff - modules/audio_output/esd.c
* ALL: More hooks for audio volume management.
[vlc] / modules / audio_output / esd.c
index 33e91c45ffdac1e1a1ad867c658c75969f79f431..496f1c9f6b5209f774ff27fa34811b2f04cf9c0d 100644 (file)
@@ -2,7 +2,7 @@
  * esd.c : EsounD module
  *****************************************************************************
  * Copyright (C) 2000, 2001 VideoLAN
- * $Id: esd.c,v 1.7 2002/08/19 21:31:11 massiot Exp $
+ * $Id: esd.c,v 1.13 2002/09/18 21:21:23 massiot Exp $
  *
  * Authors: Samuel Hocevar <sam@zoy.org>
  *
@@ -46,7 +46,6 @@ struct aout_sys_t
 {
     esd_format_t esd_format;
     int          i_fd;
-    vlc_bool_t   b_initialized;
 
     mtime_t      latency;
 };
@@ -56,8 +55,6 @@ 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  ESDThread    ( aout_instance_t * );
 
@@ -89,29 +86,8 @@ static int Open( vlc_object_t *p_this )
 
     p_aout->output.p_sys = p_sys;
 
-    /* Create ESD thread and wait for its readiness. */
-    p_sys->b_initialized = VLC_FALSE;
-    if( vlc_thread_create( p_aout, "aout", ESDThread, VLC_FALSE ) )
-    {
-        msg_Err( p_aout, "cannot create ESD thread (%s)", strerror(errno) );
-        free( p_sys );
-        return -1;
-    }
-
-    p_aout->output.pf_setformat = SetFormat;
     p_aout->output.pf_play = Play;
-
-    return( 0 );
-}
-
-/*****************************************************************************
- * SetFormat: set the output format
- *****************************************************************************/
-static int SetFormat( aout_instance_t *p_aout )
-{
-    struct aout_sys_t * p_sys = p_aout->output.p_sys;
-
-    p_sys->b_initialized = VLC_FALSE;
+    aout_VolumeSoftInit( p_aout );
 
     /* Initialize some variables */
     p_sys->esd_format = ESD_BITS16 | ESD_STREAM | ESD_PLAY;
@@ -147,18 +123,27 @@ static int SetFormat( aout_instance_t *p_aout )
      * number of buffered samples, so I assume ESD_BUF_SIZE/2 */
     p_sys->latency =
         (mtime_t)( esd_get_latency( esd_open_sound(NULL) ) + ESD_BUF_SIZE/2
-                    * aout_FormatToByterate( &p_aout->output.output )
+                    * p_aout->output.output.i_bytes_per_frame
+                    * p_aout->output.output.i_rate
                     / ESD_DEFAULT_RATE )
       * (mtime_t)1000000
-      / (mtime_t)aout_FormatToByterate( &p_aout->output.output );
+      / p_aout->output.output.i_bytes_per_frame
+      / p_aout->output.output.i_rate;
 
-    p_sys->b_initialized = VLC_TRUE;
+    /* Create ESD thread and wait for its readiness. */
+    if( vlc_thread_create( p_aout, "aout", ESDThread,
+                           VLC_THREAD_PRIORITY_OUTPUT, VLC_FALSE ) )
+    {
+        msg_Err( p_aout, "cannot create ESD thread (%s)", strerror(errno) );
+        free( p_sys );
+        return -1;
+    }
 
     return 0;
 }
 
 /*****************************************************************************
- * Play: queue a buffer for playing by ESDThread
+ * Play: nothing to do
  *****************************************************************************/
 static void Play( aout_instance_t *p_aout )
 {
@@ -192,15 +177,10 @@ static int ESDThread( aout_instance_t * p_aout )
         int i_tmp, i_size;
         byte_t * p_bytes;
 
-        if( !p_sys->b_initialized )
-        {
-            msleep( THREAD_SLEEP );
-            continue;
-        }
-
         /* Get the presentation date of the next write() operation. It
          * is equal to the current date + buffered samples + esd latency */
-        p_buffer = aout_OutputNextBuffer( p_aout, mdate() + p_sys->latency, 0 );
+        p_buffer = aout_OutputNextBuffer( p_aout, mdate() + p_sys->latency,
+                                                  VLC_FALSE );
 
         if ( p_buffer != NULL )
         {
@@ -209,9 +189,9 @@ static int ESDThread( aout_instance_t * p_aout )
         }
         else
         {
-            i_size = aout_FormatToByterate( &p_aout->output.output )
-                      * ESD_BUF_SIZE * 2
-                      / p_aout->output.output.i_rate;
+            i_size = ESD_BUF_SIZE * 2
+                      / p_aout->output.output.i_frame_length
+                      * p_aout->output.output.i_bytes_per_frame;
             p_bytes = alloca( i_size );
             memset( p_bytes, 0, i_size );
         }