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