From 6e7a72dbd4bbab64b21e65f4f0abfd9cf5350ebd Mon Sep 17 00:00:00 2001 From: shogo4405 Date: Sat, 7 Oct 2023 17:28:06 +0900 Subject: [PATCH] . --- Sources/Media/IOAudioRingBuffer.swift | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/Sources/Media/IOAudioRingBuffer.swift b/Sources/Media/IOAudioRingBuffer.swift index f600c4e48..14929fb69 100644 --- a/Sources/Media/IOAudioRingBuffer.swift +++ b/Sources/Media/IOAudioRingBuffer.swift @@ -72,16 +72,8 @@ final class IOAudioRingBuffer { let distance = distance(sampleBuffer) if 0 <= distance { skip = distance - } else { - // #1289. Considering cases where PTS may be rolled back. - let newHead = head + distance - if 0 <= newHead { - head = newHead - } else { - head = Int(buffer.frameLength) + newHead - } } - appendAudioPCMBuffer(workingBuffer) + appendAudioPCMBuffer(workingBuffer, offset: offsetCount(sampleBuffer) / 8) } func appendAudioPCMBuffer(_ audioPCMBuffer: AVAudioPCMBuffer, offset: Int = 0) { @@ -200,6 +192,17 @@ final class IOAudioRingBuffer { } return noErr } + + private func offsetCount(_ sampleBuffer: CMSampleBuffer) -> Int { + let data = sampleBuffer.dataBuffer?.data?.bytes ?? [] + let count = 0 + for i in 0.. Int { // Device audioMic or ReplayKit audioMic.