]> git.sesse.net Git - vlc/blobdiff - modules/audio_output/oss.c
Fixed a bug in the OSS output I introduced yesterday.
[vlc] / modules / audio_output / oss.c
index 9633e24af1276d82f09b37a5017a13e4ed489ecc..22e980e146cac62896a3a53de3167e3335584484 100644 (file)
@@ -2,7 +2,7 @@
  * oss.c : OSS /dev/dsp module for vlc
  *****************************************************************************
  * Copyright (C) 2000-2002 VideoLAN
- * $Id: oss.c,v 1.22 2002/08/31 22:10:25 stef Exp $
+ * $Id: oss.c,v 1.28 2002/10/01 22:34:43 massiot Exp $
  *
  * Authors: Michel Kaempf <maxx@via.ecp.fr>
  *          Samuel Hocevar <sam@zoy.org>
@@ -158,27 +158,50 @@ static int Open( vlc_object_t *p_this )
     }
 
     /* Set the output format */
-    if ( p_aout->output.output.i_format == AOUT_FMT_SPDIF )
+    if ( p_aout->output.output.i_format == VLC_FOURCC('s','p','d','i') )
     {
-        i_format = AOUT_FMT_SPDIF;
+        i_format = AFMT_AC3;
         p_aout->output.i_nb_samples = A52_FRAME_NB;
         p_aout->output.output.i_bytes_per_frame = AOUT_SPDIF_SIZE;
         p_aout->output.output.i_frame_length = A52_FRAME_NB;
+
+        aout_VolumeNoneInit( p_aout );
     }
     else
     {
-        p_aout->output.output.i_format = i_format = AOUT_FMT_S16_NE;
+        p_aout->output.output.i_format = AOUT_FMT_S16_NE;
+        i_format = AFMT_S16_NE;
         p_aout->output.i_nb_samples = FRAME_SIZE;
+
+        aout_VolumeSoftInit( p_aout );
     }
 
     if( ioctl( p_sys->i_fd, SNDCTL_DSP_SETFMT, &i_format ) < 0
          || i_format != p_aout->output.output.i_format )
     {
-        msg_Err( p_aout, "cannot set audio output format (%i)", i_format );
-        return VLC_EGENERIC;
+        if ( i_format == AFMT_AC3 )
+        {
+            /* Retry with S16 */
+            msg_Warn( p_aout, "cannot set audio output format (%i)", i_format );
+            p_aout->output.output.i_format = AOUT_FMT_S16_NE;
+            i_format = AFMT_S16_NE;
+            p_aout->output.i_nb_samples = FRAME_SIZE;
+            if( ioctl( p_sys->i_fd, SNDCTL_DSP_SETFMT, &i_format ) < 0
+                 || i_format != p_aout->output.output.i_format )
+            {
+                msg_Err( p_aout, "cannot set audio output format (%i)",
+                         i_format );
+                return VLC_EGENERIC;
+            }
+        }
+        else
+        {
+            msg_Err( p_aout, "cannot set audio output format (%i)", i_format );
+            return VLC_EGENERIC;
+        }
     }
 
-    if ( p_aout->output.output.i_format != AOUT_FMT_SPDIF )
+    if ( p_aout->output.output.i_format != VLC_FOURCC('s','p','d','i') )
     {
         /* FIXME */
         if ( p_aout->output.output.i_channels > 2 )
@@ -301,11 +324,11 @@ static int OSSThread( aout_instance_t * p_aout )
 
     while ( !p_aout->b_die )
     {
-        aout_buffer_t * p_buffer;
+        aout_buffer_t * p_buffer = NULL;
         int i_tmp, i_size;
         byte_t * p_bytes;
 
-        if ( p_aout->output.output.i_format != AOUT_FMT_SPDIF )
+        if ( p_aout->output.output.i_format != VLC_FOURCC('s','p','d','i') )
         {
             mtime_t buffered = BufferDuration( p_aout );
 
@@ -334,7 +357,27 @@ static int OSSThread( aout_instance_t * p_aout )
         }
         else
         {
-            p_buffer = aout_OutputNextBuffer( p_aout, 0, VLC_TRUE );
+            /* emu10k1 driver does not report Buffer Duration correctly in
+             * passthrough mode so we have to cheat */
+            if( !next_date )
+            {
+                next_date = mdate();
+            }
+            else
+            {
+                mtime_t delay = next_date - mdate();
+                if( delay > AOUT_PTS_TOLERANCE )
+                {
+                    msleep( delay / 2 );
+                }
+            }
+            
+            while( !p_aout->b_die && ! ( p_buffer =
+                aout_OutputNextBuffer( p_aout, next_date, VLC_TRUE ) ) )
+            {
+                msleep( 1000 );
+                next_date = mdate();
+            }
         }
 
         if ( p_buffer != NULL )