From afa992189d20e71633a0bddd5593a44f0a6f5e99 Mon Sep 17 00:00:00 2001 From: Christopher Snowhill Date: Tue, 19 Jul 2022 07:31:04 -0700 Subject: [PATCH] Add a lock around access to output PTS variable This locking should help, but I don't know why visualization jumps around now. Signed-off-by: Christopher Snowhill --- Audio/Output/OutputAVFoundation.m | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Audio/Output/OutputAVFoundation.m b/Audio/Output/OutputAVFoundation.m index eb9587639..25e7e22eb 100644 --- a/Audio/Output/OutputAVFoundation.m +++ b/Audio/Output/OutputAVFoundation.m @@ -373,7 +373,9 @@ current_device_listener(AudioObjectID inObjectID, UInt32 inNumberAddresses, cons if(bufferRef) { CMTime chunkDuration = CMSampleBufferGetDuration(bufferRef); + [currentPtsLock lock]; outputPts = CMTimeAdd(outputPts, chunkDuration); + [currentPtsLock unlock]; trackPts = CMTimeAdd(trackPts, chunkDuration); [audioRenderer enqueueSampleBuffer:bufferRef]; @@ -1092,8 +1094,9 @@ current_device_listener(AudioObjectID inObjectID, UInt32 inNumberAddresses, cons if(timeAdded > 0) { [outputController incrementAmountPlayed:timeAdded]; } - + [lock lock]; CMTime latencyTime = CMTimeSubtract(*outputPts, time); + [lock unlock]; double latencySeconds = CMTimeGetSeconds(latencyTime); double latencyVis = 0.0; [lock lock];