private void CopyPlanesYuv420P(NvGpuVmm vmm, SurfaceOutputConfig outputConfig) { FFmpegFrame frame = FFmpegWrapper.GetFrame(); if ((frame.Width | frame.Height) == 0) { return; } int halfSrcWidth = frame.Width / 2; int halfWidth = frame.Width / 2; int halfHeight = frame.Height / 2; int alignedWidth = (outputConfig.SurfaceWidth + 0xff) & ~0xff; for (int y = 0; y < frame.Height; y++) { int src = y * frame.Width; int dst = y * alignedWidth; int size = frame.Width; for (int offset = 0; offset < size; offset++) { vmm.WriteByte(outputConfig.SurfaceLumaAddress + dst + offset, *(frame.LumaPtr + src + offset)); } } // Copy chroma data from both channels with interleaving. for (int y = 0; y < halfHeight; y++) { int src = y * halfSrcWidth; int dst = y * alignedWidth; for (int x = 0; x < halfWidth; x++) { vmm.WriteByte(outputConfig.SurfaceChromaUAddress + dst + x * 2 + 0, *(frame.ChromaBPtr + src + x)); vmm.WriteByte(outputConfig.SurfaceChromaUAddress + dst + x * 2 + 1, *(frame.ChromaRPtr + src + x)); } } }
private void CopyPlanesYuv420p(NvGpuVmm Vmm, SurfaceOutputConfig OutputConfig) { FFmpegFrame Frame = FFmpegWrapper.GetFrame(); if ((Frame.Width | Frame.Height) == 0) { return; } int HalfSrcWidth = Frame.Width / 2; int HalfWidth = Frame.Width / 2; int HalfHeight = Frame.Height / 2; int AlignedWidth = (OutputConfig.SurfaceWidth + 0xff) & ~0xff; for (int Y = 0; Y < Frame.Height; Y++) { int Src = Y * Frame.Width; int Dst = Y * AlignedWidth; int Size = Frame.Width; for (int Offset = 0; Offset < Size; Offset++) { Vmm.WriteByte(OutputConfig.SurfaceLumaAddress + Dst + Offset, *(Frame.LumaPtr + Src + Offset)); } } //Copy chroma data from both channels with interleaving. for (int Y = 0; Y < HalfHeight; Y++) { int Src = Y * HalfSrcWidth; int Dst = Y * AlignedWidth; for (int X = 0; X < HalfWidth; X++) { Vmm.WriteByte(OutputConfig.SurfaceChromaUAddress + Dst + X * 2 + 0, *(Frame.ChromaBPtr + Src + X)); Vmm.WriteByte(OutputConfig.SurfaceChromaUAddress + Dst + X * 2 + 1, *(Frame.ChromaRPtr + Src + X)); } } }