[vlc-commits] coreaudio: move tinfo into p_sys

Thomas Guillem git at videolan.org
Wed Nov 20 14:13:17 CET 2019


vlc/vlc-3.0 | branch: master | Thomas Guillem <thomas at gllm.fr> | Wed Nov 20 13:50:45 2019 +0100| [03d4f115e0dc1b27af4711ff2d3766f7ef9fafb0] | committer: Thomas Guillem

coreaudio: move tinfo into p_sys

It doesn't need to be static since it is initialized from ca_Open().

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

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

 modules/audio_output/coreaudio_common.c | 33 ++++++++++++++-------------------
 modules/audio_output/coreaudio_common.h |  7 +++++--
 2 files changed, 19 insertions(+), 21 deletions(-)

diff --git a/modules/audio_output/coreaudio_common.c b/modules/audio_output/coreaudio_common.c
index 2c52553320..df06a36091 100644
--- a/modules/audio_output/coreaudio_common.c
+++ b/modules/audio_output/coreaudio_common.c
@@ -25,11 +25,6 @@
 #import "coreaudio_common.h"
 #import <CoreAudio/CoreAudioTypes.h>
 
-#import <dlfcn.h>
-#import <mach/mach_time.h>
-
-static mach_timebase_info_data_t tinfo;
-
 static inline uint64_t
 BytesToFrames(struct aout_sys_common *p_sys, size_t i_bytes)
 {
@@ -55,17 +50,15 @@ UsToFrames(struct aout_sys_common *p_sys, mtime_t i_us)
 }
 
 static inline mtime_t
-HostTimeToTick(uint64_t i_host_time)
+HostTimeToTick(struct aout_sys_common *p_sys, uint64_t i_host_time)
 {
-    assert(tinfo.denom != 0);
-    return i_host_time * tinfo.numer / tinfo.denom / 1000;
+    return i_host_time * p_sys->tinfo.numer / p_sys->tinfo.denom / 1000;
 }
 
 static inline uint64_t
-TickToHostTime(mtime_t i_us)
+TickToHostTime(struct aout_sys_common *p_sys, mtime_t i_us)
 {
-    assert(tinfo.denom != 0);
-    return i_us * 1000 * tinfo.denom / tinfo.numer;
+    return i_us * 1000 * p_sys->tinfo.denom / p_sys->tinfo.numer;
 }
 
 static void
@@ -119,11 +112,10 @@ ca_Open(audio_output_t *p_aout)
 {
     struct aout_sys_common *p_sys = (struct aout_sys_common *) p_aout->sys;
 
-    if (mach_timebase_info(&tinfo) != KERN_SUCCESS)
-    {
-        tinfo.numer = tinfo.denom = 0;
+    if (mach_timebase_info(&p_sys->tinfo) != KERN_SUCCESS)
         return VLC_EGENERIC;
-    }
+
+    assert(p_sys->tinfo.denom != 0 && p_sys->tinfo.numer != 0);
 
     vlc_sem_init(&p_sys->flush_sem, 0);
     lock_init(p_sys);
@@ -175,7 +167,8 @@ ca_Render(audio_output_t *p_aout, uint32_t i_frames, uint64_t i_host_time,
          * */
         const size_t i_requested_us =
             FramesToUs(p_sys, BytesToFrames(p_sys, i_requested));
-        const uint64_t i_requested_host_time = TickToHostTime(i_requested_us);
+        const uint64_t i_requested_host_time =
+            TickToHostTime(p_sys, i_requested_us);
         if (p_sys->i_first_render_host_time >= i_host_time + i_requested_host_time)
         {
             /* Fill the buffer with silence */
@@ -184,7 +177,7 @@ ca_Render(audio_output_t *p_aout, uint32_t i_frames, uint64_t i_host_time,
 
         /* Write silence to reach the first_render host time */
         const mtime_t i_silence_us =
-            HostTimeToTick(p_sys->i_first_render_host_time - i_host_time);
+            HostTimeToTick(p_sys, p_sys->i_first_render_host_time - i_host_time);
 
         const uint64_t i_silence_bytes =
             FramesToBytes(p_sys, UsToFrames(p_sys, i_silence_us));
@@ -266,7 +259,8 @@ ca_TimeGet(audio_output_t *p_aout, mtime_t *delay)
         return -1;
     }
 
-    const mtime_t i_render_time_us = HostTimeToTick(p_sys->i_render_host_time);
+    const mtime_t i_render_time_us =
+        HostTimeToTick(p_sys, p_sys->i_render_host_time);
     const mtime_t i_render_delay = i_render_time_us - mdate();
 
     *delay = ca_GetLatencyLocked(p_aout) + i_render_delay;
@@ -351,7 +345,8 @@ ca_Play(audio_output_t * p_aout, block_t * p_block)
          * Once the rendering is truly started, the date can be ignored. */
 
         const mtime_t first_render_time = p_block->i_pts - ca_GetLatencyLocked(p_aout);
-        p_sys->i_first_render_host_time = TickToHostTime(first_render_time);
+        p_sys->i_first_render_host_time =
+            TickToHostTime(p_sys, first_render_time);
     }
 
     do
diff --git a/modules/audio_output/coreaudio_common.h b/modules/audio_output/coreaudio_common.h
index 08ac4c1916..34cc1bdc7d 100644
--- a/modules/audio_output/coreaudio_common.h
+++ b/modules/audio_output/coreaudio_common.h
@@ -33,6 +33,7 @@
 #import <AudioUnit/AudioUnit.h>
 #import <AudioToolbox/AudioToolbox.h>
 #import <os/lock.h>
+#import <mach/mach_time.h>
 
 #define STREAM_FORMAT_MSG(pre, sfm) \
     pre "[%f][%4.4s][%u][%u][%u][%u][%u][%u]", \
@@ -46,8 +47,10 @@
 
 struct aout_sys_common
 {
-    /* The following is owned by common.c (initialized from ca_Init, cleaned
-     * from ca_Clean) */
+    /* The following is owned by common.c (initialized from ca_Open, cleaned
+     * from ca_Close) */
+
+    mach_timebase_info_data_t tinfo;
 
     size_t              i_underrun_size;
     bool                b_paused;



More information about the vlc-commits mailing list