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 <kode54@gmail.com>
xcode15
Christopher Snowhill 2022-07-19 07:31:04 -07:00
parent b3d10bdd4d
commit 4c4f479fb6
1 changed files with 4 additions and 1 deletions

View File

@ -373,7 +373,9 @@ current_device_listener(AudioObjectID inObjectID, UInt32 inNumberAddresses, cons
if(bufferRef) { if(bufferRef) {
CMTime chunkDuration = CMSampleBufferGetDuration(bufferRef); CMTime chunkDuration = CMSampleBufferGetDuration(bufferRef);
[currentPtsLock lock];
outputPts = CMTimeAdd(outputPts, chunkDuration); outputPts = CMTimeAdd(outputPts, chunkDuration);
[currentPtsLock unlock];
trackPts = CMTimeAdd(trackPts, chunkDuration); trackPts = CMTimeAdd(trackPts, chunkDuration);
[audioRenderer enqueueSampleBuffer:bufferRef]; [audioRenderer enqueueSampleBuffer:bufferRef];
@ -1092,8 +1094,9 @@ current_device_listener(AudioObjectID inObjectID, UInt32 inNumberAddresses, cons
if(timeAdded > 0) { if(timeAdded > 0) {
[outputController incrementAmountPlayed:timeAdded]; [outputController incrementAmountPlayed:timeAdded];
} }
[lock lock];
CMTime latencyTime = CMTimeSubtract(*outputPts, time); CMTime latencyTime = CMTimeSubtract(*outputPts, time);
[lock unlock];
double latencySeconds = CMTimeGetSeconds(latencyTime); double latencySeconds = CMTimeGetSeconds(latencyTime);
double latencyVis = 0.0; double latencyVis = 0.0;
[lock lock]; [lock lock];