fix:调整低水位判断逻辑增加渲染缓冲区
This commit is contained in:
parent
1370536da9
commit
bedb692484
@ -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)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user