[vlc-commits] coreaudio: always return a valid delay

Thomas Guillem git at videolan.org
Thu Jun 21 16:56:55 CEST 2018


vlc/vlc-3.0 | branch: master | Thomas Guillem <thomas at gllm.fr> | Thu Jun 21 09:41:27 2018 +0200| [531fb72410c06a78f65d231db393443093e719e0] | committer: Thomas Guillem

coreaudio: always return a valid delay

Even if the render callbacks is not yet called.

(cherry picked from commit 7a098bbaac82471b11a9c63490f9d6a7462bc817)
Signed-off-by: Thomas Guillem <thomas at gllm.fr>

> http://git.videolan.org/gitweb.cgi/vlc/vlc-3.0.git/?a=commit;h=531fb72410c06a78f65d231db393443093e719e0
---

 modules/audio_output/coreaudio_common.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/modules/audio_output/coreaudio_common.c b/modules/audio_output/coreaudio_common.c
index da1ba1a8c9..6e2b5ed14d 100644
--- a/modules/audio_output/coreaudio_common.c
+++ b/modules/audio_output/coreaudio_common.c
@@ -206,20 +206,24 @@ ca_TimeGet(audio_output_t *p_aout, mtime_t *delay)
 {
     struct aout_sys_common *p_sys = (struct aout_sys_common *) p_aout->sys;
 
+    if (unlikely(tinfo.denom == 0))
+        return -1;
+
     lock_lock(p_sys);
 
-    if (tinfo.denom == 0 || p_sys->i_render_host_time == 0)
+    mtime_t i_render_delay;
+    if (likely(p_sys->i_render_host_time != 0))
     {
-        lock_unlock(p_sys);
-        return -1;
+        const uint64_t i_render_time_us = p_sys->i_render_host_time
+                                        * tinfo.numer / tinfo.denom / 1000;
+        i_render_delay = i_render_time_us - mdate();
     }
-
-    const uint64_t i_render_time_us = p_sys->i_render_host_time
-                                    * tinfo.numer / tinfo.denom / 1000;
+    else
+        i_render_delay = 0;
 
     const int64_t i_out_frames = BytesToFrames(p_sys, p_sys->i_out_size);
     *delay = FramesToUs(p_sys, i_out_frames + p_sys->i_render_frames)
-           + p_sys->i_dev_latency_us + i_render_time_us - mdate();
+           + p_sys->i_dev_latency_us + i_render_delay;
 
     lock_unlock(p_sys);
     return 0;



More information about the vlc-commits mailing list