Jean-Baptiste Kempf pushed to branch master at VideoLAN / VLC


Commits:
46c5c750 by Thomas Guillem at 2026-01-03T15:38:23+01:00
aaudio: fix possible negative timestamp after an underrun

GetFrameTimestampLocked() might not return the last ts/date couple, so
the new underrun is unlikely to be taken into account.

- - - - -


1 changed file:

- modules/audio_output/android/aaudio.c


Changes:

=====================================
modules/audio_output/android/aaudio.c
=====================================
@@ -453,22 +453,27 @@ DataCallback(AAudioStream *as, void *user, void *data_, 
int32_t num_frames)
          && sys->timing_report_last_written_bytes >= 
sys->timing_report_delay_bytes
          && GetFrameTimestampLocked(stream, &pos_frames, &system_ts) == 
VLC_SUCCESS)
         {
-            sys->timing_report_last_written_bytes = 0;
-
-            /* From now on, fetch the timestamp every 1 seconds */
-            sys->timing_report_delay_bytes =
-                TicksToBytes(sys, TIMING_REPORT_DELAY_TICKS);
 
             vlc_tick_t pos_ticks = FramesToTicks(sys, pos_frames);
             /* underrun 0s don't count in timing reports */
             vlc_tick_t underrun_ticks = BytesToTicks(sys, 
sys->underrun_total_bytes);
-            pos_ticks -= underrun_ticks;
 
-            /* Add the start silence to the system time and don't subtract
-             * it from pos_ticks to avoid (unlikely) negatives ts */
-            system_ts += BytesToTicks(sys, sys->start_silence_bytes);
-            aout_stream_TimingReport(stream, system_ts,
-                                     pos_ticks + sys->first_pts);
+            /* pos_frame might not have taken the last underrun update */
+            if (likely(pos_ticks > underrun_ticks))
+            {
+                pos_ticks -= underrun_ticks;
+
+                /* From now on, fetch the timestamp every 1 seconds */
+                sys->timing_report_last_written_bytes = 0;
+                sys->timing_report_delay_bytes =
+                    TicksToBytes(sys, TIMING_REPORT_DELAY_TICKS);
+
+                /* Add the start silence to the system time and don't subtract
+                 * it from pos_ticks to avoid (unlikely) negatives ts */
+                system_ts += BytesToTicks(sys, sys->start_silence_bytes);
+                aout_stream_TimingReport(stream, system_ts,
+                                         pos_ticks + sys->first_pts);
+            }
         }
 
         memcpy(data, f->p_buffer, tocopy);



View it on GitLab: 
https://code.videolan.org/videolan/vlc/-/commit/46c5c75034e8aa16ccdc7e4d255add7db1bb711f

-- 
View it on GitLab: 
https://code.videolan.org/videolan/vlc/-/commit/46c5c75034e8aa16ccdc7e4d255add7db1bb711f
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance
_______________________________________________
vlc-commits mailing list
[email protected]
https://mailman.videolan.org/listinfo/vlc-commits

Reply via email to