Rare deadlock when closing on audiounit_ios
It seems that the call to
if (AudioUnitGetProperty(p_sys->au_unit, kAudioUnitProperty_Latency,
kAudioUnitScope_Global, 0, &unit_s,
&(UInt32) { sizeof(unit_s) }) != noErr)
From the trace
AURemoteIO::IOThread (25496)#0 0x0000000198ab24d4 in __psynch_mutexwait ()
#1 0x0000000198b471a4 in _pthread_mutex_firstfit_lock_wait ()
#2 0x0000000198b470f8 in _pthread_mutex_firstfit_lock_slow ()
#3 0x00000001987e692c in std::__1::recursive_mutex::lock() ()
#4 0x00000001c37d0554 in ausdk::AUMethodGetProperty(void*, unsigned int, unsigned int, unsigned int, void*, unsigned int*) ()
#5 0x000000010ab68434 in GetLatency at /Users/unidan/Workspace/test_skbuild/framework/vlc/modules/audio_output/audiounit_ios.m:189
#6 0x000000010ab69768 in GetLatency at /Users/unidan/Workspace/test_skbuild/framework/vlc/modules/audio_output/coreaudio_common.c:143
#7 0x000000010ab694d8 in ca_Render at /Users/unidan/Workspace/test_skbuild/framework/vlc/modules/audio_output/coreaudio_common.c:217
#8 0x000000010ab6abd0 in RenderCallback at /Users/unidan/Workspace/test_skbuild/framework/vlc/modules/audio_output/coreaudio_common.c:451
#9 0x00000001c37cecd8 in ausdk::AUInputElement::PullInput(unsigned int&, AudioTimeStamp const&, unsigned int, unsigned int) ()
#10 0x00000001c3717b50 in AUInputFormatConverter2::InputProc(OpaqueAudioConverter*, unsigned int*, AudioBufferList*, AudioStreamPacketDescription**, void*) ()
#11 0x00000001ca06dbc0 in acv1::AudioConverterChain::CallInputProc(unsigned int) ()
#12 0x00000001ca06eb78 in acv1::AudioConverterChain::FillBufferFromInputProc(unsigned int*, CADeprecated::CABufferList*) ()
#13 0x00000001ca173454 in acv1::BufferedAudioConverter::GetInputBytes(unsigned int, unsigned int&, CADeprecated::CABufferList const*&) ()
#14 0x00000001ca0541c0 in acv1::CBRConverter::RenderOutput(CADeprecated::CABufferList*, unsigned int, unsigned int&, AudioStreamPacketDescription*) ()
#15 0x00000001ca1731fc in acv1::BufferedAudioConverter::FillBuffer(unsigned int&, AudioBufferList&, AudioStreamPacketDescription*) ()
#16 0x00000001ca06d9ac in acv1::AudioConverterChain::RenderOutput(CADeprecated::CABufferList*, unsigned int, unsigned int&, AudioStreamPacketDescription*) ()
#17 0x00000001ca1731fc in acv1::BufferedAudioConverter::FillBuffer(unsigned int&, AudioBufferList&, AudioStreamPacketDescription*) ()
#18 0x00000001ca1a76f4 in acv1::_AudioConverterFillComplexBuffer(OpaqueAudioConverter*, int (*)(OpaqueAudioConverter*, unsigned int*, AudioBufferList*, AudioStreamPacketDescription**, void*), void*, unsigned int*, AudioBufferList*, AudioStreamPacketDescription*, AudioStreamPacketDependencyInfo*) ()
#19 0x00000001c37162dc in AUConverterBase::RenderBus(unsigned int&, AudioTimeStamp const&, unsigned int, unsigned int) ()
#20 0x00000001c378759c in AURemoteIO::RenderBus(unsigned int&, AudioTimeStamp const&, unsigned int, unsigned int) ()
#21 0x00000001c37ce134 in ausdk::AUBase::DoRender(unsigned int&, AudioTimeStamp const&, unsigned int, unsigned int, AudioBufferList&) ()
#22 0x00000001c37926ec in AURemoteIO::PerformIO(unsigned int, unsigned int, unsigned int, AudioTimeStamp const&, AudioTimeStamp const&, AudioBufferList const*, AudioBufferList*, int&) ()
#23 0x00000001c37c7554 in _XPerformIO ()
#24 0x00000001dbc85db0 in mshMIGPerform ()
#25 0x00000001dbc861ac in MSHMIGDispatchMessage ()
#26 0x00000001c378ad54 in void* caulk::thread_proxy<std::__1::tuple<caulk::thread::attributes, AURemoteIO::IOThread::IOThread(AURemoteIO&, caulk::thread::attributes const&, caulk::mach::os_workgroup const&)::'lambda'(), std::__1::tuple<> > >(void*) ()
#27 0x0000000198b4185c in _pthread_start ()
is racing against the call to
if (!p_sys->b_stopped)
{
err = AudioOutputUnitStop(p_sys->au_unit);
from the trace
vlc-input tid_np=76291 (25492)#0 0x0000000198ab30f8 in __ulock_wait ()
#1 0x0000000198b446dc in _pthread_join ()
#2 0x00000001db790cdc in caulk::thread::join() ()
#3 0x00000001c378afa0 in std::__1::__shared_ptr_emplace<AURemoteIO::IOThread, std::__1::allocator<AURemoteIO::IOThread> >::__on_zero_shared() ()
#4 0x00000001c37891a8 in AURemoteIO::Stop() ()
#5 0x00000001c37d100c in ausdk::AUMethodStop(void*) ()
#6 0x000000010ab67788 in Stop at /Users/unidan/Workspace/test_skbuild/framework/vlc/modules/audio_output/audiounit_ios.m:534
#7 0x0000000103eefa84 in aout_OutputDelete at /Users/unidan/Workspace/test_skbuild/framework/vlc/src/audio_output/output.c:822
#8 0x0000000103ee74c4 in vlc_aout_stream_Delete at /Users/unidan/Workspace/test_skbuild/framework/vlc/src/audio_output/dec.c:341
#9 0x0000000103e9ae44 in DeleteDecoder at /Users/unidan/Workspace/test_skbuild/framework/vlc/src/input/decoder.c:2154
#10 0x0000000103e9a978 in vlc_input_decoder_Delete at /Users/unidan/Workspace/test_skbuild/framework/vlc/src/input/decoder.c:2380
#11 0x0000000103eaa9e4 in EsOutDestroyDecoder at /Users/unidan/Workspace/test_skbuild/framework/vlc/src/input/es_out.c:2612
#12 0x0000000103eaa4ac in EsOutUnselectEs at /Users/unidan/Workspace/test_skbuild/framework/vlc/src/input/es_out.c:2781
#13 0x0000000103eb1e8c in EsOutVaPrivControlLocked at /Users/unidan/Workspace/test_skbuild/framework/vlc/src/input/es_out.c:3977
#14 0x0000000103ea6a9c in EsOutPrivControl at /Users/unidan/Workspace/test_skbuild/framework/vlc/src/input/es_out.c:4272
#15 0x0000000103eb9b70 in es_out_vaPrivControl at /Users/unidan/Workspace/test_skbuild/framework/vlc/src/input/es_out.h:105
#16 0x0000000103eb9bc4 in es_out_PrivControl at /Users/unidan/Workspace/test_skbuild/framework/vlc/src/input/es_out.h:112
#17 0x0000000103eb9588 in CmdExecutePrivControl at /Users/unidan/Workspace/test_skbuild/framework/vlc/src/input/es_out_timeshift.c:1811
#18 0x0000000103eb9024 in PrivControlLocked at /Users/unidan/Workspace/test_skbuild/framework/vlc/src/input/es_out_timeshift.c:801
#19 0x0000000103eb6514 in PrivControl at /Users/unidan/Workspace/test_skbuild/framework/vlc/src/input/es_out_timeshift.c:860
#20 0x0000000103ec2188 in es_out_vaPrivControl at /Users/unidan/Workspace/test_skbuild/framework/vlc/src/input/es_out.h:105
#21 0x0000000103ec20d0 in es_out_PrivControl at /Users/unidan/Workspace/test_skbuild/framework/vlc/src/input/es_out.h:112
#22 0x0000000103ebfbfc in es_out_SetMode at /Users/unidan/Workspace/test_skbuild/framework/vlc/src/input/es_out.h:119
#23 0x0000000103ebd650 in End at /Users/unidan/Workspace/test_skbuild/framework/vlc/src/input/input.c:1412
#24 0x0000000103ebaa8c in Run at /Users/unidan/Workspace/test_skbuild/framework/vlc/src/input/input.c:442
#25 0x0000000198b4185c in _pthread_start ()
leading to random deadlock when switching media (with a non-precise odd of 2000 media switch for one crash).