[vlc-commits] [Git][videolan/vlc][master] 4 commits: aout: don't handle drift when paused

Thomas Guillem (@tguillem) gitlab at videolan.org
Fri Nov 17 16:11:22 UTC 2023



Thomas Guillem pushed to branch master at VideoLAN / VLC


Commits:
d946275c by Thomas Guillem at 2023-11-17T15:44:31+00:00
aout: don't handle drift when paused

In case where the audio is not master and paused (unlikely since audio
is not master in case of live playback, that is generally not pauseable).

Fixes some potential enormous silence:
playback way too early (-9223371872593688789): playing silence

"luckily" the allocation was too big and silently failing, and not causing OOM.

- - - - -
e0f1805f by Thomas Guillem at 2023-11-17T15:44:31+00:00
aout: use the same system_time when converting

The system time is only used when there is no master in order to get the
reference point (wait_sync_ref). Therefore, it's better to always use
the same vlc_tick_now() to avoid gaps.

- - - - -
2a25f23a by Thomas Guillem at 2023-11-17T15:44:31+00:00
aout: call vlc_clock_ConvertToSystem() only one time when playing

- - - - -
a3ddf46f by Thomas Guillem at 2023-11-17T15:44:31+00:00
aout: fix wrong delay after a pause when not master

This fixes the following case when resuming from pause:

main audio output warning: playback way too early (-7040339): playing silence
main audio output debug: inserting 337936 zeroes / 7040ms
main audio output warning: playback way too late (7038677): flushing buffers

It was not happening with all aout modules. For example, PulseAudio was
likely updating its timing just after a uncork and just before the core
was playing the next audio sample.

- - - - -


1 changed file:

- src/audio_output/dec.c


Changes:

=====================================
src/audio_output/dec.c
=====================================
@@ -76,6 +76,8 @@ struct vlc_aout_stream
 
         vlc_tick_t system_ts;
         vlc_tick_t audio_ts;
+
+        vlc_tick_t pause_date;
         float rate;
     } timing;
 
@@ -165,6 +167,8 @@ static void stream_Discontinuity(vlc_aout_stream *stream)
     stream->timing.system_ts = VLC_TICK_INVALID;
     stream->timing.audio_ts = VLC_TICK_INVALID;
     vlc_mutex_unlock(&stream->timing.lock);
+
+    stream->timing.pause_date = VLC_TICK_INVALID;
     stream->timing.played_samples = 0;
 }
 
@@ -588,7 +592,7 @@ static void stream_HandleDrift(vlc_aout_stream *stream, vlc_tick_t drift,
 }
 
 static void stream_Synchronize(vlc_aout_stream *stream, vlc_tick_t system_now,
-                               vlc_tick_t dec_pts)
+                               vlc_tick_t play_date, vlc_tick_t dec_pts)
 {
     /**
      * Depending on the drift between the actual and intended playback times,
@@ -625,11 +629,6 @@ static void stream_Synchronize(vlc_aout_stream *stream, vlc_tick_t system_now,
         if (stream_GetDelay(stream, &delay) != 0)
             return; /* nothing can be done if timing is unknown */
 
-        /* Equivalent to vlc_clock_Update() but we don't want to update points
-         * (since there are already updated via aout_TimingReport()). */
-        vlc_tick_t play_date =
-            vlc_clock_ConvertToSystem(stream->sync.clock, system_now + delay, dec_pts,
-                                      stream->sync.rate);
         drift = play_date - system_now - delay;
     }
     else
@@ -648,9 +647,7 @@ static void stream_Synchronize(vlc_aout_stream *stream, vlc_tick_t system_now,
              * clock without taking the jitter into account. Therefore, we
              * manually insert silence that correspond to the clock jitter
              * value before updating the clock. */
-            vlc_tick_t play_date =
-                vlc_clock_ConvertToSystem(stream->sync.clock, system_now + delay,
-                                          dec_pts, stream->sync.rate);
+
             vlc_tick_t jitter = play_date - system_now;
             if (jitter > 0)
             {
@@ -772,7 +769,6 @@ int vlc_aout_stream_Play(vlc_aout_stream *stream, block_t *block)
 
     /* Drift correction */
     vlc_tick_t system_now = vlc_tick_now();
-    stream_Synchronize(stream, system_now, original_pts);
 
     vlc_tick_t play_date =
         vlc_clock_ConvertToSystem(stream->sync.clock, system_now, original_pts,
@@ -782,8 +778,9 @@ int vlc_aout_stream_Play(vlc_aout_stream *stream, block_t *block)
         /* The clock is paused but not the output, play the audio anyway since
          * we can't delay audio playback from here. */
         play_date = system_now;
-
     }
+    else
+        stream_Synchronize(stream, system_now, play_date, original_pts);
 
     vlc_audio_meter_Process(&owner->meter, block, play_date);
 
@@ -845,6 +842,24 @@ void vlc_aout_stream_ChangePause(vlc_aout_stream *stream, bool paused, vlc_tick_
             vlc_tracer_TraceEvent(tracer, "RENDER", stream->str_id,
                                   paused ? "paused" : "resumed");
 
+        if (paused)
+        {
+            assert(stream->timing.pause_date == VLC_TICK_INVALID);
+            stream->timing.pause_date = date;
+        }
+        else
+        {
+            assert(stream->timing.pause_date != VLC_TICK_INVALID);
+            /* Delay the last timing with the pause duration. This will be used
+             * by stream_GetDelay() until the module updates its next point
+             * after being resumed. */
+            vlc_mutex_lock(&stream->timing.lock);
+            if (stream->timing.system_ts != VLC_TICK_INVALID)
+                stream->timing.system_ts += date - stream->timing.pause_date;
+            vlc_mutex_unlock(&stream->timing.lock);
+            stream->timing.pause_date = VLC_TICK_INVALID;
+        }
+
         if (aout->pause != NULL)
             aout->pause(aout, paused, date);
         else if (paused)



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/ab853bd0a3b6197ed0d2201e6c558d2e25bc02ae...a3ddf46f334bd48deb34032f07c4cce4a7bea4d9

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/ab853bd0a3b6197ed0d2201e6c558d2e25bc02ae...a3ddf46f334bd48deb34032f07c4cce4a7bea4d9
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list