[vlc-commits] aout: fix flawed resampling logic

Rémi Denis-Courmont git at videolan.org
Tue Nov 13 20:36:04 CET 2012


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Tue Nov 13 21:35:50 2012 +0200| [62a75145b729b80b5f44931739338ef8a1812947] | committer: Rémi Denis-Courmont

aout: fix flawed resampling logic

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

 src/audio_output/dec.c     |   63 ++++++++++++++++++--------------------------
 src/audio_output/filters.c |    2 +-
 2 files changed, 27 insertions(+), 38 deletions(-)

diff --git a/src/audio_output/dec.c b/src/audio_output/dec.c
index 87310e6..8d72e27 100644
--- a/src/audio_output/dec.c
+++ b/src/audio_output/dec.c
@@ -333,61 +333,50 @@ static void aout_DecSynchronize (audio_output_t *aout, mtime_t dec_pts,
     }
 
     /* Resampling */
-
-    if (drift > +AOUT_MAX_PTS_DELAY)
+    if (drift > +AOUT_MAX_PTS_DELAY
+     && owner->sync.resamp_type != AOUT_RESAMPLING_UP)
     {
-        if (owner->sync.resamp_type == AOUT_RESAMPLING_NONE)
-        {
-            msg_Warn (aout, "playback too late (%"PRId64"): up-sampling",
-                      drift);
-            owner->sync.resamp_start_drift = +drift;
-        }
+        msg_Warn (aout, "playback too late (%"PRId64"): up-sampling",
+                  drift);
         owner->sync.resamp_type = AOUT_RESAMPLING_UP;
+        owner->sync.resamp_start_drift = +drift;
     }
-
-    if (drift < -AOUT_MAX_PTS_ADVANCE)
+    if (drift < -AOUT_MAX_PTS_ADVANCE
+     && owner->sync.resamp_type != AOUT_RESAMPLING_DOWN)
     {
-        if (owner->sync.resamp_type == AOUT_RESAMPLING_NONE)
-        {
-            msg_Warn (aout, "playback too early (%"PRId64"): down-sampling",
-                      drift);
-            owner->sync.resamp_start_drift = -drift;
-        }
+        msg_Warn (aout, "playback too early (%"PRId64"): down-sampling",
+                  drift);
         owner->sync.resamp_type = AOUT_RESAMPLING_DOWN;
+        owner->sync.resamp_start_drift = -drift;
     }
 
     if (owner->sync.resamp_type == AOUT_RESAMPLING_NONE)
         return; /* Everything is fine. Nothing to do. */
 
+    if (llabs (drift) > 2 * owner->sync.resamp_start_drift)
+    {   /* If the drift is ever increasing, then something is seriously wrong.
+         * Cease resampling and hope for the best. */
+        msg_Warn (aout, "timing screwed (drift: %"PRId64" us): "
+                  "stopping resampling", drift);
+        aout_StopResampling (aout);
+        return;
+    }
+
     /* Resampling has been triggered earlier. This checks if it needs to be
      * increased or decreased. Resampling rate changes must be kept slow for
      * the comfort of listeners. */
-    const int adj = (owner->sync.resamp_type == AOUT_RESAMPLING_UP) ? +2 : -2;
+    int adj = (owner->sync.resamp_type == AOUT_RESAMPLING_UP) ? +2 : -2;
+
+    if (2 * llabs (drift) <= owner->sync.resamp_start_drift)
+        /* If the drift has been reduced from more than half its initial
+         * value, then it is time to switch back the resampling direction. */
+        adj *= -1;
 
-    /* Check if everything is back to normal, then stop resampling. */
     if (!aout_FiltersAdjustResampling (aout, adj))
-    {
+    {   /* Everything is back to normal: stop resampling. */
         owner->sync.resamp_type = AOUT_RESAMPLING_NONE;
         msg_Dbg (aout, "resampling stopped (drift: %"PRId64" us)", drift);
     }
-    else
-    if (2 * llabs (drift) <= owner->sync.resamp_start_drift)
-    {   /* If the drift has been reduced from more than half its initial
-         * value, then it is time to switch back the resampling direction. */
-        if (owner->sync.resamp_type == AOUT_RESAMPLING_UP)
-            owner->sync.resamp_type = AOUT_RESAMPLING_DOWN;
-        else
-            owner->sync.resamp_type = AOUT_RESAMPLING_UP;
-        owner->sync.resamp_start_drift = 0;
-    }
-    else
-    if (llabs (drift) > 2 * owner->sync.resamp_start_drift)
-    {   /* If the drift is ever increasing, then something is seriously wrong.
-         * Cease resampling and hope for the best. */
-        msg_Warn (aout, "timing screwed (drift: %"PRId64" us): "
-                  "stopping resampling", drift);
-        aout_StopResampling (aout);
-    }
 }
 
 /*****************************************************************************
diff --git a/src/audio_output/filters.c b/src/audio_output/filters.c
index 056b9d0..14f9e66 100644
--- a/src/audio_output/filters.c
+++ b/src/audio_output/filters.c
@@ -550,7 +550,7 @@ bool aout_FiltersAdjustResampling (audio_output_t *aout, int adjust)
         owner->resampling += adjust;
     else
         owner->resampling = 0;
-    return !owner->resampling;
+    return owner->resampling != 0;
 }
 
 block_t *aout_FiltersPlay (audio_output_t *aout, block_t *block, int rate)



More information about the vlc-commits mailing list