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