[vlc-commits] coreaudio: a valid timebase is now mandatory

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


vlc/vlc-3.0 | branch: master | Thomas Guillem <thomas at gllm.fr> | Fri Aug 16 09:01:20 2019 +0200| [868b358b1125abf554a516c37d93e3544f196287] | committer: Thomas Guillem

coreaudio: a valid timebase is now mandatory

For some unknown reason, ca_init_once() was not executed on iOS 9. Instead of
debugging this issue, backport this patch from 4.0 since the usage of
pthread_once() was useless in that precise case. Indeed, ca_Open() is called
only one time per media player instance, we don't really need to cache the
mach_timebase_info in that case.

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

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

 modules/audio_output/audiounit_ios.m    | 11 ++++++++---
 modules/audio_output/auhal.c            | 11 ++++++++---
 modules/audio_output/coreaudio_common.c | 21 ++++++++-------------
 modules/audio_output/coreaudio_common.h |  2 +-
 4 files changed, 25 insertions(+), 20 deletions(-)

diff --git a/modules/audio_output/audiounit_ios.m b/modules/audio_output/audiounit_ios.m
index f97c83ceea..4a4edc06db 100644
--- a/modules/audio_output/audiounit_ios.m
+++ b/modules/audio_output/audiounit_ios.m
@@ -642,17 +642,24 @@ static int
 Open(vlc_object_t *obj)
 {
     audio_output_t *aout = (audio_output_t *)obj;
-    aout_sys_t *sys = calloc(1, sizeof (*sys));
 
+    aout_sys_t *sys = aout->sys = calloc(1, sizeof (*sys));
     if (unlikely(sys == NULL))
         return VLC_ENOMEM;
 
+    if (ca_Open(aout) != VLC_SUCCESS)
+    {
+        free(sys);
+        return VLC_EGENERIC;
+    }
+
     sys->avInstance = [AVAudioSession sharedInstance];
     assert(sys->avInstance != NULL);
 
     sys->aoutWrapper = [[AoutWrapper alloc] initWithAout:aout];
     if (sys->aoutWrapper == NULL)
     {
+        ca_Close(aout);
         free(sys);
         return VLC_ENOMEM;
     }
@@ -660,7 +667,6 @@ Open(vlc_object_t *obj)
     sys->b_muted = false;
     sys->b_preferred_channels_set = false;
     sys->au_dev = var_InheritBool(aout, "spdif") ? AU_DEV_ENCODED : AU_DEV_PCM;
-    aout->sys = sys;
     aout->start = Start;
     aout->stop = Stop;
     aout->device_select = DeviceSelect;
@@ -670,6 +676,5 @@ Open(vlc_object_t *obj)
     for (unsigned int i = 0; i< sizeof(au_devs) / sizeof(au_devs[0]); ++i)
         aout_HotplugReport(aout, au_devs[i].psz_id, au_devs[i].psz_name);
 
-    ca_Open(aout);
     return VLC_SUCCESS;
 }
diff --git a/modules/audio_output/auhal.c b/modules/audio_output/auhal.c
index 4c8886a8c4..6c507b2bcf 100644
--- a/modules/audio_output/auhal.c
+++ b/modules/audio_output/auhal.c
@@ -1702,10 +1702,17 @@ static void Close(vlc_object_t *obj)
 static int Open(vlc_object_t *obj)
 {
     audio_output_t *p_aout = (audio_output_t *)obj;
-    aout_sys_t *p_sys = calloc(1, sizeof (*p_sys));
+
+    aout_sys_t *p_sys = p_aout->sys = calloc(1, sizeof (*p_sys));
     if (unlikely(p_sys == NULL))
         return VLC_ENOMEM;
 
+    if (ca_Open(p_aout) != VLC_SUCCESS)
+    {
+        free(p_sys);
+        return VLC_EGENERIC;
+    }
+
     vlc_mutex_init(&p_sys->device_list_lock);
     vlc_mutex_init(&p_sys->selected_device_lock);
     p_sys->b_digital = false;
@@ -1714,7 +1721,6 @@ static int Open(vlc_object_t *obj)
     memset(&p_sys->sfmt_revert, 0, sizeof(p_sys->sfmt_revert));
     p_sys->i_stream_id = 0;
 
-    p_aout->sys = p_sys;
     p_aout->start = Start;
     p_aout->stop = Stop;
     p_aout->volume_set = VolumeSet;
@@ -1772,6 +1778,5 @@ static int Open(vlc_object_t *obj)
     p_sys->b_mute = var_InheritBool(p_aout, "mute");
     aout_MuteReport(p_aout, p_sys->b_mute);
 
-    ca_Open(p_aout);
     return VLC_SUCCESS;
 }
diff --git a/modules/audio_output/coreaudio_common.c b/modules/audio_output/coreaudio_common.c
index 41917b6458..2c52553320 100644
--- a/modules/audio_output/coreaudio_common.c
+++ b/modules/audio_output/coreaudio_common.c
@@ -81,13 +81,6 @@ ca_ClearOutBuffers(audio_output_t *p_aout)
 }
 
 static void
-ca_init_once(void)
-{
-    if (mach_timebase_info(&tinfo) != KERN_SUCCESS)
-        tinfo.numer = tinfo.denom = 0;
-}
-
-static inline void
 lock_init(struct aout_sys_common *p_sys)
 {
     if (likely(os_unfair_lock_lock))
@@ -121,13 +114,16 @@ lock_unlock(struct aout_sys_common *p_sys)
         vlc_mutex_unlock(&p_sys->lock.mutex);
 }
 
-void
+int
 ca_Open(audio_output_t *p_aout)
 {
     struct aout_sys_common *p_sys = (struct aout_sys_common *) p_aout->sys;
 
-    static pthread_once_t once = PTHREAD_ONCE_INIT;
-    pthread_once(&once, ca_init_once);
+    if (mach_timebase_info(&tinfo) != KERN_SUCCESS)
+    {
+        tinfo.numer = tinfo.denom = 0;
+        return VLC_EGENERIC;
+    }
 
     vlc_sem_init(&p_sys->flush_sem, 0);
     lock_init(p_sys);
@@ -137,6 +133,8 @@ ca_Open(audio_output_t *p_aout)
     p_aout->pause = ca_Pause;
     p_aout->flush = ca_Flush;
     p_aout->time_get = ca_TimeGet;
+
+    return VLC_SUCCESS;
 }
 
 void
@@ -259,9 +257,6 @@ 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 (p_sys->i_render_host_time == 0 || p_sys->i_first_render_host_time == 0)
diff --git a/modules/audio_output/coreaudio_common.h b/modules/audio_output/coreaudio_common.h
index e47a1c28e2..08ac4c1916 100644
--- a/modules/audio_output/coreaudio_common.h
+++ b/modules/audio_output/coreaudio_common.h
@@ -82,7 +82,7 @@ struct aout_sys_common
     mtime_t             i_dev_latency_us;
 };
 
-void ca_Open(audio_output_t *p_aout);
+int ca_Open(audio_output_t *p_aout);
 
 void ca_Close(audio_output_t *p_aout);
 



More information about the vlc-commits mailing list