[vlc-commits] [Git][videolan/vlc][master] coreaudio: don't call AudioUnit API from the render callback

Felix Paul Kühne (@fkuehne) gitlab at videolan.org
Wed Dec 7 09:36:56 UTC 2022



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


Commits:
c8cd58f9 by Thomas Guillem at 2022-12-07T09:01:16+00:00
coreaudio: don't call AudioUnit API from the render callback

It is very unlikely that AudioUnitGetProperty(kAudioUnitProperty_Latency) can
change midstream (contrary to [AVInstance outputLatency]), so only fetch
this latency when starting the AudioUnit.

This fixes a deadlock between the render callback and AudioUnitStop().

Fixes #27591

- - - - -


2 changed files:

- modules/audio_output/coreaudio_common.c
- modules/audio_output/coreaudio_common.h


Changes:

=====================================
modules/audio_output/coreaudio_common.c
=====================================
@@ -146,24 +146,7 @@ GetLatency(audio_output_t *p_aout)
                                    : p_sys->i_dev_latency_ticks;
 
     /* Add the AudioUnit latency to the auhal/audiounit_ios latency */
-    if (p_sys->au != NULL)
-    {
-        Float64 unit_s;
-        if (AudioUnitGetProperty(p_sys->au, kAudioUnitProperty_Latency,
-                                 kAudioUnitScope_Global, 0, &unit_s,
-                                 &(UInt32) { sizeof(unit_s) }) != noErr)
-            unit_s = 0;
-        vlc_tick_t us = vlc_tick_from_sec(unit_s);
-        if (us != p_sys->au_latency_ticks)
-        {
-            msg_Dbg(p_aout, "Adding AudioUnit latency: %" PRId64 "us", us);
-            p_sys->au_latency_ticks = us;
-        }
-
-        dev_latency_ticks += us;
-    }
-
-    return dev_latency_ticks;
+    return dev_latency_ticks + p_sys->au_latency_ticks;
 }
 
 /* Called from render callbacks. No lock, wait, and IO here */
@@ -361,7 +344,6 @@ ca_Initialize(audio_output_t *p_aout, const audio_sample_format_t *fmt,
 {
     struct aout_sys_common *p_sys = (struct aout_sys_common *) p_aout->sys;
 
-    p_sys->au = NULL;
     p_sys->au_latency_ticks = 0;
     p_sys->i_underrun_size = 0;
     p_sys->b_paused = false;
@@ -874,7 +856,15 @@ au_Initialize(audio_output_t *p_aout, AudioUnit au, audio_sample_format_t *fmt,
         AudioUnitUninitialize(au);
         return VLC_EGENERIC;
     }
-    p_sys->au = au;
+
+    Float64 unit_s;
+    if (AudioUnitGetProperty(au, kAudioUnitProperty_Latency,
+                             kAudioUnitScope_Global, 0, &unit_s,
+                             &(UInt32) { sizeof(unit_s) }) == noErr)
+    {
+        p_sys->au_latency_ticks = vlc_tick_from_sec(unit_s);
+        msg_Dbg(p_aout, "AudioUnit latency: %" PRId64 "us", p_sys->au_latency_ticks);
+    }
 
     return VLC_SUCCESS;
 }


=====================================
modules/audio_output/coreaudio_common.h
=====================================
@@ -51,8 +51,6 @@ struct aout_sys_common
 {
     /* The following is owned by common.c (initialized from ca_Open) */
 
-    AudioUnit au; /* Can be NULL (pass-through) */
-
     mach_timebase_info_data_t tinfo;
 
     size_t              i_underrun_size;
@@ -73,7 +71,7 @@ struct aout_sys_common
     size_t timing_report_last_written_bytes;
     /* Number of bytes to write before sending a timing report */
     size_t timing_report_delay_bytes;
-    /* Last AudioUnit Latency, for debug/log purpose */
+    /* AudioUnit Latency */
     vlc_tick_t au_latency_ticks;
 
     union lock



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

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/c8cd58f922afd512245ff812a3aa13093d0bee75
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