fixed possible crash in micHandler

This commit is contained in:
TrueZhuanjia
2025-09-15 11:37:50 +08:00
parent b950882846
commit 464492529e
+3 -2
View File
@@ -195,8 +195,9 @@ public class MicHandler: NSObject {
guard let enc = self.opusEncoder else {return}
let outBytes = opus_encode(enc, chunk, 960, &packet, Int32(packet.count))
sendMicrophoneData(packet, outBytes)
if pcm16Buffer.count >= 960 {
pcm16Buffer.removeFirst(960)
let removeCount = min(960, pcm16Buffer.count)
if removeCount > 0 {
pcm16Buffer.removeFirst(removeCount)
}
}
}