alsa: use the pcm status to compute the delay. fix #894 (spdif passthrough)
authorRafaël Carré <funman@videolan.org>
Sun, 11 Nov 2007 18:48:07 +0000 (18:48 +0000)
committerRafaël Carré <funman@videolan.org>
Sun, 11 Nov 2007 18:48:07 +0000 (18:48 +0000)
Please report loudly any regression, using spdif or not.

modules/audio_output/alsa.c

index a90e2fd..28bc6f2 100644 (file)
@@ -826,28 +826,12 @@ static void ALSAFill( aout_instance_t * p_aout )
     {
         /* Here the device should be in RUNNING state.
          * p_status is valid. */
-
-#if 0
-        /* This apparently does not work correctly in Alsa 1.0.11 */
-        snd_pcm_status_get_tstamp( p_status, &ts_next );
-        next_date = (mtime_t)ts_next.tv_sec * 1000000 + ts_next.tv_usec;
-        if( next_date )
-        {
-            next_date += (mtime_t)snd_pcm_status_get_delay(p_status)
-                    * 1000000 / p_aout->output.output.i_rate;
-        }
-        else
-#endif
-        {
-            /* With screwed ALSA drivers the timestamp is always zero;
-             * use another method then */
-            snd_pcm_sframes_t delay = 0;
-
-            snd_pcm_delay( p_sys->p_snd_pcm, &delay );
-            next_date = mdate() + (mtime_t)(delay) * 1000000
-                        / p_aout->output.output.i_rate
-                        * p_aout->output.output.i_frame_length;
-        }
+        snd_pcm_sframes_t delay = snd_pcm_status_get_delay( p_status );
+        int i_bytes = snd_pcm_frames_to_bytes( p_sys->p_snd_pcm, delay );
+        next_date = mdate() + ( (mtime_t)i_bytes * 1000000
+                / p_aout->output.output.i_bytes_per_frame
+                / p_aout->output.output.i_rate
+                * p_aout->output.output.i_frame_length );
     }
 
     p_buffer = aout_OutputNextBuffer( p_aout, next_date,