public void SetSourcePictureParameters(SourcePicture sourcePicture) { int width = sourcePicture.PicWidth; int height = sourcePicture.PicHeight; byte[] buffer = new byte[width * height * 3 / 2]; if (ImageBufferHandle != IntPtr.Zero) { Marshal.FreeHGlobal(ImageBufferHandle); } ImageBufferHandle = Marshal.AllocHGlobal(Marshal.SizeOf(buffer[0]) * width * height * 3 / 2); SourcePicture = sourcePicture; SourcePicture.Stride = Marshal.AllocHGlobal(Marshal.SizeOf((int)0) * 4); var imageStrides = new int[4]; imageStrides[0] = sourcePicture.PicWidth; imageStrides[1] = imageStrides[2] = sourcePicture.PicWidth >> 1; Marshal.Copy(imageStrides, 0, SourcePicture.Stride, 4); SourcePicture.Data = Marshal.AllocHGlobal(Marshal.SizeOf(IntPtr.Zero) * 4); var imageData = new IntPtr[4]; imageData[0] = ImageBufferHandle; imageData[1] = imageData[0] + width * height; imageData[2] = imageData[1] + (width * height >> 2); Marshal.Copy(imageData, 0, SourcePicture.Data, 4); return; }
private void FreeSourcePicture(SourcePicture picture) { try { if (picture.Stride != IntPtr.Zero) { Marshal.FreeHGlobal(SourcePicture.Stride); } if (picture.Stride != IntPtr.Zero) { Marshal.FreeHGlobal(SourcePicture.Data); } } catch (Exception) { } }
private static extern int EncodeFrame(IntPtr encoder, ref SourcePicture SourcePicture, ref FrameBitstreamInfo FrameInfo);