Skip to content

Instantly share code, notes, and snippets.

@EgorBo
Last active July 25, 2017 22:08
Show Gist options
  • Save EgorBo/619acd9ce44caff01eb8c2c9c3970f2e to your computer and use it in GitHub Desktop.
Save EgorBo/619acd9ce44caff01eb8c2c9c3970f2e to your computer and use it in GitHub Desktop.
CVPixelBuffer issue.cs
// called 60 times per second (60fps)
unsafe void DisplayBackground(CVPixelBuffer capturedImage)
{
capturedImage.Lock(CVPixelBufferLock.None);
var baseAddress = capturedImage.BaseAddress;
var format = capturedImage.PixelFormatType; //CV420YpCbCr8BiPlanarFullRange
var width = (int)capturedImage.Width; //1280
var height = (int)capturedImage.Height; //720
cameraTexture.SetData(0, 0, 0, width, height, (void*)baseAddress);
capturedImage.Unlock(CVPixelBufferLock.None);
//Workaround #1:
//CVPixelBufferRelease(capturedImage.Handle);
//GC.SuppressFinalize(capturedImage);
//Workaround #2:
GC.Collect();
}
[DllImport("/System/Library/Frameworks/CoreVideo.framework/CoreVideo")]
private static extern void CVPixelBufferRelease(IntPtr handle);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment