[vlc-commits] ALSA: correct S/PDIF start timing (fixes #6565)

Rémi Denis-Courmont git at videolan.org
Mon Jul 23 15:34:35 CEST 2012


vlc/vlc-2.0 | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Mon Apr  2 23:10:30 2012 +0300| [b98a2ef126e06de8fa19d05835847861b8ba2a26] | committer: Rémi Denis-Courmont

ALSA: correct S/PDIF start timing (fixes #6565)

This is completely untested, but it seems logical.
(cherry picked from commit 89d23df7d82a27c42cfa3a52d4008e34130bc99f)

> http://git.videolan.org/gitweb.cgi/vlc/vlc-2.0.git/?a=commit;h=b98a2ef126e06de8fa19d05835847861b8ba2a26
---

 modules/audio_output/alsa.c |   32 ++++++++++++++++++++------------
 1 file changed, 20 insertions(+), 12 deletions(-)

diff --git a/modules/audio_output/alsa.c b/modules/audio_output/alsa.c
index b1b7b0e..dbac149 100644
--- a/modules/audio_output/alsa.c
+++ b/modules/audio_output/alsa.c
@@ -562,22 +562,30 @@ static void Play (audio_output_t *aout, block_t *block)
         if (state != SND_PCM_STATE_RUNNING)
         {
             delay = block->i_pts - (mdate () + delay);
-            if (delay > 0 && aout->format.i_format != VLC_CODEC_SPDIFL)
+            if (delay > 0)
             {
-                frames = (delay * aout->format.i_rate) / CLOCK_FREQ;
-                msg_Dbg (aout, "prepending %ld zeroes", frames);
-
-                void *pad = calloc (frames, aout->format.i_bytes_per_frame);
-                if (likely(pad != NULL))
+                if (aout->format.i_format != VLC_CODEC_SPDIFL)
+                {
+                    frames = (delay * aout->format.i_rate) / CLOCK_FREQ;
+                    msg_Dbg (aout, "prepending %ld zeroes", frames);
+
+                    void *z = calloc (frames, aout->format.i_bytes_per_frame);
+                    if (likely(z != NULL))
+                    {
+                        snd_pcm_writei (pcm, z, frames);
+                        free (z);
+                        delay = 0;
+                    }
+                }
+                /* Lame fallback if zero padding does not work */
+                if (delay > 0)
                 {
-                    snd_pcm_writei (pcm, pad, frames);
-                    free (pad);
-                    delay = 0;
+                    msg_Dbg (aout, "deferring start (%"PRId64" us)", delay);
+                    msleep (delay);
                 }
             }
-            /* Lame fallback if zero padding does not work */
-            if (delay > 0)
-                mwait (block->i_pts - delay);
+            else
+                msg_Dbg (aout, "starting late (%"PRId64" us)", delay);
         }
         else
             aout_TimeReport (aout, block->i_pts - delay);



More information about the vlc-commits mailing list