internal void CopyPlanes(NvGpuVmm vmm, SurfaceOutputConfig outputConfig) { switch (outputConfig.PixelFormat) { case SurfacePixelFormat.Rgba8: CopyPlanesRgba8(vmm, outputConfig); break; case SurfacePixelFormat.Yuv420P: CopyPlanesYuv420P(vmm, outputConfig); break; default: ThrowUnimplementedPixelFormat(outputConfig.PixelFormat); break; } }
private void CopyPlanesRgba8(GpuContext gpu, SurfaceOutputConfig outputConfig) { FFmpegFrame frame = FFmpegWrapper.GetFrameRgba(); if ((frame.Width | frame.Height) == 0) { return; } throw new NotImplementedException(); }
internal void CopyPlanes(NvGpuVmm Vmm, SurfaceOutputConfig OutputConfig) { switch (OutputConfig.PixelFormat) { case SurfacePixelFormat.RGBA8: CopyPlanesRgba8(Vmm, OutputConfig); break; case SurfacePixelFormat.YUV420P: CopyPlanesYuv420p(Vmm, OutputConfig); break; default: ThrowUnimplementedPixelFormat(OutputConfig.PixelFormat); break; } }
private void CopyPlanesRgba8(NvGpuVmm Vmm, SurfaceOutputConfig OutputConfig) { FFmpegFrame Frame = FFmpegWrapper.GetFrameRgba(); if ((Frame.Width | Frame.Height) == 0) { return; } GalImage Image = new GalImage( OutputConfig.SurfaceWidth, OutputConfig.SurfaceHeight, 1, OutputConfig.GobBlockHeight, GalMemoryLayout.BlockLinear, GalImageFormat.RGBA8 | GalImageFormat.Unorm); ImageUtils.WriteTexture(Vmm, Image, Vmm.GetPhysicalAddress(OutputConfig.SurfaceLumaAddress), Frame.Data); }
private void CopyPlanesRgba8(NvGpuVmm vmm, SurfaceOutputConfig outputConfig) { FFmpegFrame frame = FFmpegWrapper.GetFrameRgba(); if ((frame.Width | frame.Height) == 0) { return; } GalImage image = new GalImage( outputConfig.SurfaceWidth, outputConfig.SurfaceHeight, 1, 1, 1, outputConfig.GobBlockHeight, 1, GalMemoryLayout.BlockLinear, GalImageFormat.Rgba8 | GalImageFormat.Unorm, GalTextureTarget.TwoD); ImageUtils.WriteTexture(vmm, image, vmm.GetPhysicalAddress(outputConfig.SurfaceLumaAddress), frame.Data); }
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)); } } }