Это мой код, преобразованный рендеринг yuv иногда нормальный, иногда ненормальный, есть ли проблемы? [code] func convertRTCVideoFrameToYUV(frame: RTCVideoFrame) -> (yData: Data, uData: Data, vData: Data) {
let i420Buffer = frame.buffer.toI420()
let width = Int(i420Buffer.width) let height = Int(i420Buffer.height)
let ySize = Int(width * height)
// let uvWidth = (width + 1) / 2 // let uvHeight = (height + 1) / 2
// let uSize = Int(uvWidth * uvHeight) // let vSize = Int(uvWidth * uvHeight) let uSize = Int((width / 2) * (height / 2)) let vSize = Int((width / 2) * (height / 2))
var yData = Data(count: ySize) var uData = Data(count: uSize) var vData = Data(count: vSize)
yData.withUnsafeMutableBytes { yBuffer in guard let yPtr = yBuffer.baseAddress?.assumingMemoryBound(to: UInt8.self) else { return } let yPlane = i420Buffer.dataY memcpy(yPtr, yPlane, ySize) }
uData.withUnsafeMutableBytes { uBuffer in guard let uPtr = uBuffer.baseAddress?.assumingMemoryBound(to: UInt8.self) else { return } let uPlane = i420Buffer.dataU memcpy(uPtr, uPlane, uSize) }
vData.withUnsafeMutableBytes { vBuffer in guard let vPtr = vBuffer.baseAddress?.assumingMemoryBound(to: UInt8.self) else { return } let vPlane = i420Buffer.dataV memcpy(vPtr, vPlane, vSize) }