|
@@ -425,33 +425,38 @@ public final class LNMP4FrameHWDecoder: LNBaseDecoder {
|
|
|
)
|
|
)
|
|
|
guard status == noErr, let sampleBuffer, let decodeSession else { return }
|
|
guard status == noErr, let sampleBuffer, let decodeSession else { return }
|
|
|
|
|
|
|
|
- var flagOut: VTDecodeInfoFlags = []
|
|
|
|
|
- let decodeStatus = VTDecompressionSessionDecodeFrame(
|
|
|
|
|
- decodeSession,
|
|
|
|
|
- sampleBuffer: sampleBuffer,
|
|
|
|
|
- flags: [],
|
|
|
|
|
- infoFlagsOut: &flagOut
|
|
|
|
|
- ) { [weak self] status, _, imageBuffer, _, _ in
|
|
|
|
|
- guard let self else { return }
|
|
|
|
|
- self.handleDecodePixelBuffer(
|
|
|
|
|
- imageBuffer,
|
|
|
|
|
- frameIndex: frameIndex,
|
|
|
|
|
- currentPts: currentPts,
|
|
|
|
|
- startDate: startDate,
|
|
|
|
|
- status: status,
|
|
|
|
|
- needDrop: drop,
|
|
|
|
|
- buffers: buffers,
|
|
|
|
|
- fps: parser.fps
|
|
|
|
|
- )
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if decodeStatus == kVTInvalidSessionErr {
|
|
|
|
|
- invalidRetryCount += 1
|
|
|
|
|
- if invalidRetryCount >= 3 { return }
|
|
|
|
|
- resetDecoder()
|
|
|
|
|
- findKeyFrameAndDecodeToCurrent(frameIndex)
|
|
|
|
|
- } else {
|
|
|
|
|
- invalidRetryCount = 0
|
|
|
|
|
|
|
+ // 与 ObjC 版 CFRelease(sampleBuffer) 对齐:将 sampleBuffer 放在 autoreleasepool
|
|
|
|
|
+ // 内,确保解码提交后立即释放,避免高帧率场景下多帧 sampleBuffer 同时滞留内存。
|
|
|
|
|
+ autoreleasepool {
|
|
|
|
|
+ var flagOut: VTDecodeInfoFlags = []
|
|
|
|
|
+ let decodeStatus = VTDecompressionSessionDecodeFrame(
|
|
|
|
|
+ decodeSession,
|
|
|
|
|
+ sampleBuffer: sampleBuffer,
|
|
|
|
|
+ flags: [],
|
|
|
|
|
+ infoFlagsOut: &flagOut
|
|
|
|
|
+ ) { [weak self] status, _, imageBuffer, _, _ in
|
|
|
|
|
+ guard let self else { return }
|
|
|
|
|
+ self.handleDecodePixelBuffer(
|
|
|
|
|
+ imageBuffer,
|
|
|
|
|
+ frameIndex: frameIndex,
|
|
|
|
|
+ currentPts: currentPts,
|
|
|
|
|
+ startDate: startDate,
|
|
|
|
|
+ status: status,
|
|
|
|
|
+ needDrop: drop,
|
|
|
|
|
+ buffers: buffers,
|
|
|
|
|
+ fps: parser.fps
|
|
|
|
|
+ )
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if decodeStatus == kVTInvalidSessionErr {
|
|
|
|
|
+ invalidRetryCount += 1
|
|
|
|
|
+ if invalidRetryCount < 3 {
|
|
|
|
|
+ resetDecoder()
|
|
|
|
|
+ findKeyFrameAndDecodeToCurrent(frameIndex)
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ invalidRetryCount = 0
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|