[vlc-commits] [Git][videolan/vlc][master] 4 commits: aout: assert that pts from filters are valid

Steve Lhomme (@robUx4) gitlab at videolan.org
Sat Jul 20 17:42:52 UTC 2024



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
f0c3760f by Thomas Guillem at 2024-07-20T17:19:25+00:00
aout: assert that pts from filters are valid

- - - - -
1ed24f11 by Thomas Guillem at 2024-07-20T17:19:25+00:00
aout: don't trigger a discontinuity if not played

This was already done for the BLOCK_FLAG_DISCONTINUITY case but I forgot
to add it for the clock_id case.

- - - - -
67eef6d2 by Thomas Guillem at 2024-07-20T17:19:25+00:00
aout: add intermediate stream_ClockConvert()

Lock the clock and convert a PTS and return an INVALID ts if the
clock_id changed (discontinuity from the clock)

- - - - -
7dc7847c by Thomas Guillem at 2024-07-20T17:19:25+00:00
aout: convert pts before filtering the input block

This allow to detect a discontinuity via the returned clock_id. Audio
filters won't have to detect discontinuities (None were doing it for
now).

The filtered PTS will be likely the same than the input one, in that
case, don't convert the PTS a second time.

- - - - -


1 changed file:

- src/audio_output/dec.c


Changes:

=====================================
src/audio_output/dec.c
=====================================
@@ -825,6 +825,25 @@ void vlc_aout_stream_NotifyTiming(vlc_aout_stream *stream, vlc_tick_t system_ts,
     vlc_mutex_unlock(&stream->timing.lock);
 }
 
+static vlc_tick_t stream_ClockConvert(vlc_aout_stream *stream,
+                                      vlc_tick_t system_now, vlc_tick_t pts)
+{
+    uint32_t clock_id;
+
+    vlc_clock_Lock(stream->sync.clock);
+    vlc_tick_t play_date =
+        vlc_clock_ConvertToSystem(stream->sync.clock, system_now, pts,
+                                  stream->sync.rate, &clock_id);
+    vlc_clock_Unlock(stream->sync.clock);
+
+    if (clock_id != stream->sync.clock_id && stream->sync.played)
+    {
+        stream->sync.clock_id = clock_id;
+        return VLC_TICK_INVALID;
+    }
+    return play_date;
+}
+
 /*****************************************************************************
  * vlc_aout_stream_Play : filter & mix the decoded buffer
  *****************************************************************************/
@@ -848,8 +867,18 @@ int vlc_aout_stream_Play(vlc_aout_stream *stream, block_t *block)
     if (unlikely(ret == AOUT_DEC_FAILED))
         goto drop; /* Pipeline is unrecoverably broken :-( */
 
+    vlc_tick_t play_date = VLC_TICK_INVALID;
+    vlc_tick_t system_now;
+
     if (stream->filters && (block->i_flags & BLOCK_FLAG_CORE_PRIVATE_FILTERED) == 0)
     {
+        system_now = vlc_tick_now();
+        vlc_tick_t prefilter_pts = block->i_pts;
+
+        play_date = stream_ClockConvert(stream, system_now, block->i_pts);
+        if (play_date == VLC_TICK_INVALID)
+            return stream_StartDiscontinuity(stream, block);
+
         if (atomic_load_explicit(&owner->vp.update, memory_order_relaxed))
         {
             vlc_mutex_lock (&owner->vp.lock);
@@ -861,6 +890,11 @@ int vlc_aout_stream_Play(vlc_aout_stream *stream, block_t *block)
         block = aout_FiltersPlay(stream->filters, block, stream->sync.rate);
         if (block == NULL)
             return ret;
+        assert (block->i_pts != VLC_TICK_INVALID);
+
+        /* Re-trigger a clock convert if the filtered ts is different */
+        if (prefilter_pts != block->i_pts)
+            play_date = VLC_TICK_INVALID;
     }
 
     /* Software volume */
@@ -880,23 +914,19 @@ int vlc_aout_stream_Play(vlc_aout_stream *stream, block_t *block)
             stream_Silence(stream, delta, block->i_pts);
     }
 
-    /* Drift correction */
-    vlc_tick_t system_now = vlc_tick_now();
-
-    uint32_t clock_id;
-    vlc_clock_Lock(stream->sync.clock);
-    vlc_tick_t play_date =
-        vlc_clock_ConvertToSystem(stream->sync.clock, system_now, block->i_pts,
-                                  stream->sync.rate, &clock_id);
-    vlc_clock_Unlock(stream->sync.clock);
-
-    if (clock_id != stream->sync.clock_id)
+    /* Convert the pts if not previously done by filters */
+    if (play_date == VLC_TICK_INVALID)
     {
-        stream->sync.clock_id = clock_id;
-        block->i_flags |= BLOCK_FLAG_CORE_PRIVATE_FILTERED;
-        return stream_StartDiscontinuity(stream, block);
+        system_now = vlc_tick_now();
+        play_date = stream_ClockConvert(stream, system_now, block->i_pts);
+        if (play_date == VLC_TICK_INVALID)
+        {
+            block->i_flags |= BLOCK_FLAG_CORE_PRIVATE_FILTERED;
+            return stream_StartDiscontinuity(stream, block);
+        }
     }
 
+    /* Drift correction */
     stream_Synchronize(stream, system_now, play_date, block->i_pts);
 
     vlc_audio_meter_Process(&owner->meter, block, play_date);
@@ -1046,7 +1076,10 @@ void vlc_aout_stream_Drain(vlc_aout_stream *stream)
     {
         block_t *block = aout_FiltersDrain (stream->filters);
         if (block)
+        {
+            assert (block->i_pts != VLC_TICK_INVALID);
             aout->play(aout, block, vlc_tick_now());
+        }
     }
 
     if (aout->drain)



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/18a0893793706047dfac75935336fd2c2f16b3e1...7dc7847c343a7fe27e78a5b100cf773ca8eddbcc

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/18a0893793706047dfac75935336fd2c2f16b3e1...7dc7847c343a7fe27e78a5b100cf773ca8eddbcc
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