[vlc-commits] [Git][videolan/vlc][master] 3 commits: coreaudio: use clock_gettime_nsec_np()

Felix Paul Kühne (@fkuehne) gitlab at videolan.org
Mon Jan 2 10:40:19 UTC 2023



Felix Paul Kühne pushed to branch master at VideoLAN / VLC


Commits:
7eaa685e by Thomas Guillem at 2023-01-02T11:08:49+01:00
coreaudio: use clock_gettime_nsec_np()

Instead of mach_absolute_time().

As recommended by the documentation.

- - - - -
31ac778f by Thomas Guillem at 2023-01-02T11:08:49+01:00
coreaudio: fix timing instability

Only report the timing when all the data has been processed. Indeed, the
timing includes the length of the buffer to write. Reporting the timing
in the middle could cause a difference of [0; IOBufferDuration] (between
0 and 23ms generally).

- - - - -
242eeb56 by Thomas Guillem at 2023-01-02T11:08:49+01:00
audiounit_ios: don't include IOBufferDuration in latency

But continue to log it.

- - - - -


2 changed files:

- modules/audio_output/audiounit_ios.m
- modules/audio_output/coreaudio_common.c


Changes:

=====================================
modules/audio_output/audiounit_ios.m
=====================================
@@ -183,7 +183,8 @@ GetLatency(audio_output_t *p_aout)
         p_sys->io_buffer_duration_ticks = us;
         changed = true;
     }
-    latency_us += us;
+    /* Don't add 'us' to 'latency_us', IOBufferDuration is already handled by
+     * the render callback (end_ticks include the current buffer length). */
 
     if (changed)
         msg_Dbg(p_aout, "Current device has a new total latency of %" PRId64 "us",


=====================================
modules/audio_output/coreaudio_common.c
=====================================
@@ -156,8 +156,13 @@ ca_Render(audio_output_t *p_aout, uint64_t host_time,
 {
     struct aout_sys_common *p_sys = (struct aout_sys_common *) p_aout->sys;
 
-    const vlc_tick_t host_delay_ticks = host_time == 0 ? 0
-                                      : HostTimeToTick(p_sys, host_time - mach_absolute_time());
+    vlc_tick_t host_delay_ticks = 0;
+    if (host_time != 0)
+    {
+        uint64_t now_nsec = clock_gettime_nsec_np(CLOCK_UPTIME_RAW);
+        host_delay_ticks = HostTimeToTick(p_sys, host_time)
+                         - VLC_TICK_FROM_NS(now_nsec);
+    }
     const vlc_tick_t bytes_ticks = BytesToTicks(p_sys, bytes);
 
     const vlc_tick_t now_ticks = vlc_tick_now();
@@ -207,6 +212,7 @@ ca_Render(audio_output_t *p_aout, uint64_t host_time,
         }
     }
 
+    size_t bytes_copied = 0;
     while (bytes > 0)
     {
         vlc_frame_t *f = p_sys->p_out_chain;
@@ -223,17 +229,6 @@ ca_Render(audio_output_t *p_aout, uint64_t host_time,
         p_sys->i_out_size -= tocopy;
         p_sys->i_total_bytes += tocopy;
 
-        if (!p_sys->started
-          || (p_sys->timing_report_last_written_bytes >=
-             p_sys->timing_report_delay_bytes))
-        {
-            p_sys->timing_report_last_written_bytes = 0;
-            vlc_tick_t pos_ticks = BytesToTicks(p_sys, p_sys->i_total_bytes);
-            aout_TimingReport(p_aout, end_ticks + GetLatency(p_aout), pos_ticks);
-        }
-        else
-            p_sys->timing_report_last_written_bytes += tocopy;
-
         p_sys->started = true;
 
         memcpy(data, f->p_buffer, tocopy);
@@ -242,6 +237,7 @@ ca_Render(audio_output_t *p_aout, uint64_t host_time,
         bytes -= tocopy;
         f->i_buffer -= tocopy;
         f->p_buffer += tocopy;
+        bytes_copied += tocopy;
 
         if (f->i_buffer == 0)
         {
@@ -253,6 +249,16 @@ ca_Render(audio_output_t *p_aout, uint64_t host_time,
         }
     }
 
+    if (p_sys->timing_report_last_written_bytes >=
+        p_sys->timing_report_delay_bytes)
+    {
+        p_sys->timing_report_last_written_bytes = 0;
+        vlc_tick_t pos_ticks = BytesToTicks(p_sys, p_sys->i_total_bytes);
+        aout_TimingReport(p_aout, end_ticks + GetLatency(p_aout), pos_ticks);
+    }
+    else
+        p_sys->timing_report_last_written_bytes += bytes_copied;
+
     lock_unlock(p_sys);
 }
 



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/81c7e3c85d32e33ecba6892d6ae81726e44ffd93...242eeb5651f44dfc890fe34f258fb889e01e3a4a

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/81c7e3c85d32e33ecba6892d6ae81726e44ffd93...242eeb5651f44dfc890fe34f258fb889e01e3a4a
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