[vlc-commits] [Git][videolan/vlc][master] audiounit_ios: add @autoreleasepool to GetLatency

Felix Paul Kühne (@fkuehne) gitlab at videolan.org
Mon Aug 26 17:38:08 UTC 2024



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


Commits:
2e77112d by Alexandre Janniaux at 2024-08-26T17:23:38+00:00
audiounit_ios: add @autoreleasepool to GetLatency

GetLatency calls [AVAudioSession outputLatency] in the following
callstack:

 - _malloc_zone_malloc_instrumented_or_legacy
 - _Block_copy
 - -[_NSXPCDistantObject _initWithConnection:proxyNumber:generationCount:interface:options:error:]
 - -[NSXPCConnection synchronousRemoteObjectProxyWithErrorHandler:]
 - caulk::xpc::message<id<SessionManagerXPCProtocol> __strong, objc_object* __strong, unsigned int>::sync_proxy()
 - GetPropertyXPC(std::__1::shared_ptr<as::client::XPCConnection>, unsigned int, NSString*, bool)
 - GetProperty(AVAudioSessionImpl*, NSString*, bool)
 - float GetProperty_DefaultToZeroXPC<float>(AVAudioSessionImpl*, NSString*, bool)
 - -[AVAudioSession outputLatency]
 - GetLatency
 - GetLatency
 - ca_Render
 - RenderCallback
 - ausdk::AUInputElement::PullInput(unsigned int&, AudioTimeStamp const&, unsigned int, unsigned int)
 - AUInputFormatConverter2::InputProc(OpaqueAudioConverter*, unsigned int*, AudioBufferList*, AudioStreamPacketDescription**, void*)
 - caulk::expected<unsigned int, int> caulk::function_ref<caulk::expected<unsigned int, int> (ACAudioSpan&)>::functor_invoker<acv2::AudioConverterV2::fillComplexBuffer(int (*)(OpaqueAudioConverter*, unsigned int*, AudioBufferList*, AudioStreamPacketDescription**, void*), void*, unsigned int*, AudioBufferList*, AudioStreamPacketDescription*, AudioStreamPacketDependencyInfo*)::$_2>(caulk::details::erased_callable<caulk::expected<unsigned int, int> (ACAudioSpan&)> const&, ACAudioSpan&)
 - acv2::AudioConverterChain::ObtainInput(acv2::AudioConverterBase&, unsigned int)
 - acv2::CBRConverter::ProduceOutput(ACAudioSpan&)
 - acv2::AudioConverterChain::ProduceOutput(caulk::function_ref<caulk::expected<unsigned int, int> (ACAudioSpan&)>, ACBaseAudioSpan&)
 - acv2::AudioConverterV2::fillComplexBuffer(int (*)(OpaqueAudioConverter*, unsigned int*, AudioBufferList*, AudioStreamPacketDescription**, void*), void*, unsigned int*, AudioBufferList*, AudioStreamPacketDescription*, AudioStreamPacketDependencyInfo*)
 - with_resolved(OpaqueAudioConverter*, caulk::function_ref<int (AudioConverterAPI*)>)
 - AudioConverterFillComplexBuffer
 - AUConverterBase::RenderBus(unsigned int&, AudioTimeStamp const&, unsigned int, unsigned int)
 - AURemoteIO::RenderBus(unsigned int&, AudioTimeStamp const&, unsigned int, unsigned int)
 - ausdk::AUBase::DoRender(unsigned int&, AudioTimeStamp const&, unsigned int, unsigned int, AudioBufferList&)
 - AURemoteIO::PerformIO(unsigned int, unsigned int, unsigned int, AudioTimeStamp const&, AudioTimeStamp const&, AudioBufferList const*, AudioBufferList*, int&)
 - _XPerformIO
 - mshMIGPerform
 - MSHMIGDispatchMessage
 - void* caulk::thread_proxy<std::__1::tuple<caulk::thread::attributes, AURemoteIO::IOThread::IOThread(AURemoteIO&, caulk::thread::attributes const&, caulk::mach::os_workgroup_managed const&)::'lambda'(), std::__1::tuple<>>>(void*)
 - _pthread_start
 - thread_start

The call to Objective-C function might generate objects released from
autoreleasepool, which seems to be the case with the call to
[NSXPConnection synchronousRemoteObjectProxyWithErrorHandler][^1].

I've not found where exactly `[[block copy] autorelease]` was called but
setting up the autoreleasepool before unwinding back to the C code
removes the accumulatoin of memory on this specify callstack.

[^1]: https://developer.apple.com/documentation/foundation/nsxpcconnection/2879410-synchronousremoteobjectproxywith?language=objc

- - - - -


1 changed file:

- modules/audio_output/apple/audiounit_ios.m


Changes:

=====================================
modules/audio_output/apple/audiounit_ios.m
=====================================
@@ -90,35 +90,37 @@ typedef struct
 static vlc_tick_t
 GetLatency(audio_output_t *p_aout)
 {
-    aout_sys_t *p_sys = p_aout->sys;
+    @autoreleasepool {
+        aout_sys_t *p_sys = p_aout->sys;
 
-    Float64 unit_s;
-    vlc_tick_t latency_us = 0, us;
-    bool changed = false;
+        Float64 unit_s;
+        vlc_tick_t latency_us = 0, us;
+        bool changed = false;
 
-    us = vlc_tick_from_sec([p_sys->avInstance outputLatency]);
-    if (us != p_sys->output_latency_ticks)
-    {
-        msg_Dbg(p_aout, "Current device has a new outputLatency of %" PRId64 "us", us);
-        p_sys->output_latency_ticks = us;
-        changed = true;
-    }
-    latency_us += us;
+        us = vlc_tick_from_sec([p_sys->avInstance outputLatency]);
+        if (us != p_sys->output_latency_ticks)
+        {
+            msg_Dbg(p_aout, "Current device has a new outputLatency of %" PRId64 "us", us);
+            p_sys->output_latency_ticks = us;
+            changed = true;
+        }
+        latency_us += us;
 
-    us = vlc_tick_from_sec([p_sys->avInstance IOBufferDuration]);
-    if (us != p_sys->io_buffer_duration_ticks)
-    {
-        msg_Dbg(p_aout, "Current device has a new IOBufferDuration of %" PRId64 "us", us);
-        p_sys->io_buffer_duration_ticks = us;
-        changed = true;
-    }
-    /* Don't add 'us' to 'latency_us', IOBufferDuration is already handled by
-     * the render callback (end_ticks include the current buffer length). */
+        us = vlc_tick_from_sec([p_sys->avInstance IOBufferDuration]);
+        if (us != p_sys->io_buffer_duration_ticks)
+        {
+            msg_Dbg(p_aout, "Current device has a new IOBufferDuration of %" PRId64 "us", us);
+            p_sys->io_buffer_duration_ticks = us;
+            changed = true;
+        }
+        /* 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",
-                latency_us);
-    return latency_us;
+        if (changed)
+            msg_Dbg(p_aout, "Current device has a new total latency of %" PRId64 "us",
+                    latency_us);
+        return latency_us;
+    }
 }
 
 #pragma mark -



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

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