
Hugh world !

Here is a patch to have spdif output with ALSA but I don't want to
commit it since it's really ugly and the audio_output is being
rewritten.


--- 1/
As I say it is ugly.

--- 2/
in plugins/alsa/aout_alsa.c:233

The ugliness is that:

  - when I keep AOUT_BUFFER_DURATION set to 100000
      * pcm-alsa works fine
      * spdif-alsa (SBLive! 5.1 platinum) crashes the whole computer
        (I don't know if it's an alsa-driver bug)

  - when I put the hardcoded 500000 value (as I do in the attached
    patch)
      * spdif-alsa works quite fine except sometimes I have some
        sound loops (I suppose it's the soft side of the above crash)
      * pcm-alsa has permanent buffer underruns

  - when I keep AOUT_BUFFER_DURATION set to 500000
      * pcm-alsa works but the resampler has some kind of ugly
        variations
      * spdif-alsa works fine (as described in the previous point)

Note: I'm using the CVS version of ALSA with my "SBLive! 5.1 platinum".

--- 3/
I had to know the kind of audio stream before the call to pf_open so
I have swapped some lines in the file src/audio_output/audio_output.c

--- 4/
I had an ugly call to pf_getbufinfo in the spdif audio output to handle
buffer underruns (src/audio_output/aout_spdif.c).


So I'm looking for an audio-output compliant brain to patch my patch
;-) and then commit it into the CVS.


Enjoy.

-- 
Arnaud de Bossoreille de Ribou - http://www.via.ecp.fr/~bozo/


-- Attached file included as plaintext by Listar --

Index: plugins/alsa/aout_alsa.c
===================================================================
RCS file: /var/cvs/videolan/vlc/plugins/alsa/aout_alsa.c,v
retrieving revision 1.24
diff -u -r1.24 aout_alsa.c
--- plugins/alsa/aout_alsa.c	2001/12/30 07:09:54	1.24
+++ plugins/alsa/aout_alsa.c	2002/01/19 14:54:51
@@ -74,9 +74,9 @@
     aout_sys_t local_sys;
 
     /* Open device */
-    i_open_return = snd_pcm_open( &(local_sys.p_alsa_handle), "default",
+    i_open_return = snd_pcm_open( &(local_sys.p_alsa_handle), "iec958:AES0=0x2,AES1=0x82,AES2=0x0,AES3=0x2",
                                   SND_PCM_STREAM_PLAYBACK, 0 );
-    if( i_open_return )
+    if( i_open_return < 0)
     {
         intf_WarnMsg( 2, "aout info: could not probe ALSA device (%s)",
                       snd_strerror( i_open_return ) );
@@ -106,6 +106,7 @@
 {
 
     int i_open_returns;
+    char str_alsadev[128];
 
     /* Allocate structures */
     p_aout->p_sys = malloc( sizeof( aout_sys_t ) );
@@ -116,16 +117,25 @@
         return( 1 );
     }
 
-    p_aout->i_format   = AOUT_FORMAT_DEFAULT;
-    p_aout->i_channels = 1 + main_GetIntVariable( AOUT_STEREO_VAR,
-                                                  AOUT_STEREO_DEFAULT );
-    p_aout->l_rate     = main_GetIntVariable( AOUT_RATE_VAR,
-                                              AOUT_RATE_DEFAULT );
+    if( p_aout->i_format != AOUT_FMT_AC3 )
+    {
+        strcpy(str_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(str_alsadev, "iec958:AES0=0x%x,AES1=0x%x,AES2=0x%x,AES3=0x%x",
+                s[0], s[1], s[2], s[3]);
+    }
 
     /* Open device */
     if( ( i_open_returns = snd_pcm_open(&(p_aout->p_sys->p_alsa_handle),
-                                        "default",
-                                        SND_PCM_STREAM_PLAYBACK, 0) ) )
+                                        str_alsadev,
+                                        SND_PCM_STREAM_PLAYBACK, 0) ) < 0 )
     {
         intf_ErrMsg( "aout error: could not open ALSA device (%s)",
                      snd_strerror(i_open_returns) );
@@ -162,6 +172,12 @@
             p_aout->p_sys->bytes_per_sample = 2;
             break;
 
+        case AOUT_FMT_AC3:
+            p_aout->i_channels = 2;
+            i_format = SND_PCM_FORMAT_S16_LE;
+            p_aout->p_sys->bytes_per_sample = 2;
+            break;
+
         default:
             i_format = SND_PCM_FORMAT_S16_BE;
             p_aout->p_sys->bytes_per_sample = 2;
@@ -214,7 +230,7 @@
     p_aout->p_sys->rate = i_rv;
 
     i_rv = snd_pcm_hw_params_set_buffer_time_near( p_aout->p_sys->p_alsa_handle,
-                                                   p_hw, AOUT_BUFFER_DURATION,
+                                                   p_hw, 500000,
                                                    0 );
     if( i_rv < 0 )
     {
@@ -280,7 +296,6 @@
 
     intf_ErrMsg( "aout error: resetting output after buffer underrun" );
 
-    i_rv = snd_pcm_reset( p_aout->p_sys->p_alsa_handle );
     i_rv = snd_pcm_prepare( p_aout->p_sys->p_alsa_handle );
     if( i_rv < 0 )
     {
Index: src/audio_output/aout_spdif.c
===================================================================
RCS file: /var/cvs/videolan/vlc/src/audio_output/aout_spdif.c,v
retrieving revision 1.21
diff -u -r1.21 aout_spdif.c
--- src/audio_output/aout_spdif.c	2001/12/30 07:09:56	1.21
+++ src/audio_output/aout_spdif.c	2002/01/19 14:54:51
@@ -113,6 +113,9 @@
             }
             m_old = m_play;
 
+            p_aout->pf_getbufinfo( p_aout,
+                                   p_aout->l_units << p_aout->b_stereo );
+
             p_aout->pf_play( p_aout,
                              (byte_t *)p_aout->buffer,
                              SPDIF_FRAME_SIZE );
Index: src/audio_output/audio_output.c
===================================================================
RCS file: /var/cvs/videolan/vlc/src/audio_output/audio_output.c,v
retrieving revision 1.73
diff -u -r1.73 audio_output.c
--- src/audio_output/audio_output.c	2002/01/15 11:51:11	1.73
+++ src/audio_output/audio_output.c	2002/01/19 14:54:51
@@ -112,16 +112,6 @@
     p_aout->pf_close      = aout_functions.pf_close;
 #undef aout_functions
 
-    /*
-     * Initialize audio device
-     */
-    if ( p_aout->pf_open( p_aout ) )
-    {
-        module_Unneed( p_aout->p_module );
-        free( p_aout );
-        return( NULL );
-    }
-
     p_aout->l_rate = l_rate;
     p_aout->i_channels = i_channels;
 
@@ -133,11 +123,29 @@
         p_aout->i_format = AOUT_FMT_AC3;
         p_aout->l_rate = 48000;
     }
+    else
+    {
+        p_aout->i_format   = AOUT_FORMAT_DEFAULT;
+        p_aout->i_channels = 1 + main_GetIntVariable( AOUT_STEREO_VAR,
+                                                      AOUT_STEREO_DEFAULT );
+        p_aout->l_rate     = main_GetIntVariable( AOUT_RATE_VAR,
+                                                  AOUT_RATE_DEFAULT );
+    }
 
     if( p_aout->l_rate == 0 )
     {
         intf_ErrMsg( "aout error: null sample rate" );
         p_aout->pf_close( p_aout );
+        module_Unneed( p_aout->p_module );
+        free( p_aout );
+        return( NULL );
+    }
+
+    /*
+     * Initialize audio device
+     */
+    if ( p_aout->pf_open( p_aout ) )
+    {
         module_Unneed( p_aout->p_module );
         free( p_aout );
         return( NULL );


-- 
This is the vlc-devel mailing-list, see http://www.videolan.org/vlc/
To unsubscribe, please read http://www.videolan.org/lists.html

