fix:调整低水位判断逻辑增加渲染缓冲区

This commit is contained in:
liyi 2025-06-26 09:36:51 +08:00
parent 1370536da9
commit bedb692484

View File

@ -67,7 +67,8 @@ class VideoDecoder {
///
private var lastRenderTimeMs: Int64 = 0
///
private var renderStarted = false
///
private let renderLowWaterMark = 15
// ====== ======
///
@ -147,10 +148,10 @@ class VideoDecoder {
let firstRel = firstFrameRelativeTimestamp ?? 0
let absTimestamp = base + (timestamp - firstRel)
if absTimestamp < now - maxAllowedDelayMs {
print("[VideoDecoder][警告] 丢弃延迟帧: type=\(frameType), seq=\(frameSeq), delay=\(now - absTimestamp)ms")
return false
}
// if absTimestamp < now - maxAllowedDelayMs {
// print("[VideoDecoder][] : type=\(frameType), seq=\(frameSeq), delay=\(now - absTimestamp)ms")
// return false
// }
// 2.
if frameType == 0 { // I
@ -225,17 +226,12 @@ class VideoDecoder {
return
}
//
if !self.renderStarted {
var outputCount = 0
self.outputQueue.sync { outputCount = self.outputBuffer.count }
if outputCount >= Int(Double(self.outputBufferMaxCount) * 0.15) {
self.renderStarted = true
print("[VideoDecoder] 渲染启动outputBuffer已达低水位: \(outputCount)")
} else {
//
return
}
//
var outputCount = 0
self.outputQueue.sync { outputCount = self.outputBuffer.count }
if outputCount < self.renderLowWaterMark {
//
return
}
if let (pixelBuffer, timestamp) = self.dequeueOutput() {
@ -245,10 +241,10 @@ class VideoDecoder {
let firstRel = firstFrameRelativeTimestamp ?? 0
let absTimestamp = base + (timestamp - firstRel)
if absTimestamp < now - self.maxAllowedDelayMs {
print("[VideoDecoder][警告] 丢弃延迟渲染帧: delay=\(now - absTimestamp)ms")
return
}
// if absTimestamp < now - self.maxAllowedDelayMs {
// print("[VideoDecoder][] : delay=\(now - absTimestamp)ms")
// return
// }
DispatchQueue.main.async {
self.onFrameDecoded?(pixelBuffer, timestamp)