public CVReturn SetOutputCallback(DisplayLinkOutputCallback callback) { callbackHandle = GCHandle.Alloc(callback); CVReturn ret = CVDisplayLinkSetOutputCallback(this.Handle, static_OutputCallback, GCHandle.ToIntPtr(callbackHandle)); return(ret); }
public CVPixelBuffer(int width, int height, CVPixelFormatType pixelFormatType, NSDictionary pixelBufferAttributes) { if (width <= 0) { throw new ArgumentOutOfRangeException("width"); } if (height <= 0) { throw new ArgumentOutOfRangeException("height"); } IntPtr pixelBufferOut = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(IntPtr))); CVReturn ret = CVPixelBufferCreate(IntPtr.Zero, (IntPtr)width, (IntPtr)height, pixelFormatType, pixelBufferAttributes == null ? IntPtr.Zero : pixelBufferAttributes.Handle, pixelBufferOut); if (ret != CVReturn.Success) { Marshal.FreeHGlobal(pixelBufferOut); throw new ArgumentException(ret.ToString()); } this.handle = Marshal.ReadIntPtr(pixelBufferOut); Marshal.FreeHGlobal(pixelBufferOut); }
public static CVDisplayLink?CreateFromOpenGLMask(uint mask, out CVReturn error) { error = CVDisplayLinkCreateWithOpenGLDisplayMask(mask, out IntPtr handle); if (error != 0) { return(null); } return(new CVDisplayLink(handle, true)); }
public CVPixelBufferPool(NSDictionary poolAttributes, NSDictionary pixelBufferAttributes) { CVReturn ret = CVPixelBufferPoolCreate(IntPtr.Zero, poolAttributes.GetHandle(), pixelBufferAttributes.GetHandle(), out handle); if (ret != CVReturn.Success) { throw new Exception("CVPixelBufferPoolCreate returned " + ret.ToString()); } }
public static CVDisplayLink?CreateFromDisplayId(uint displayId, out CVReturn error) { error = CVDisplayLinkCreateWithCGDisplay(displayId, out IntPtr handle); if (error != 0) { return(null); } return(new CVDisplayLink(handle, true)); }
public CVPixelBuffer CreatePixelBuffer() { IntPtr pixelBufferOut; CVReturn ret = CVPixelBufferPoolCreatePixelBuffer(IntPtr.Zero, handle, out pixelBufferOut); if (ret != CVReturn.Success) { throw new Exception("CVPixelBufferPoolCreatePixelBuffer returned " + ret.ToString()); } return(new CVPixelBuffer(pixelBufferOut, true)); }
public CVDisplayLink() { IntPtr displayLinkOut; CVReturn ret = CVDisplayLinkCreateWithActiveCGDisplays(out displayLinkOut); if (ret != CVReturn.Success) { throw new Exception("CVDisplayLink returned: " + ret); } this.handle = displayLinkOut; }
CVPixelBuffer(nint width, nint height, CVPixelFormatType pixelFormatType, NSDictionary pixelBufferAttributes) { if (width <= 0) throw new ArgumentOutOfRangeException ("width"); if (height <= 0) throw new ArgumentOutOfRangeException ("height"); CVReturn ret = CVPixelBufferCreate (IntPtr.Zero, width, height, pixelFormatType, pixelBufferAttributes == null ? IntPtr.Zero : pixelBufferAttributes.Handle, out handle); if (ret != CVReturn.Success) throw new ArgumentException (ret.ToString ()); }
public CVPixelBufferPool(NSDictionary poolAttributes, NSDictionary pixelBufferAttributes) { IntPtr poolOut = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(IntPtr))); CVReturn ret = CVPixelBufferPoolCreate(IntPtr.Zero, poolAttributes.Handle, pixelBufferAttributes.Handle, poolOut); if (ret != CVReturn.Success) { Marshal.FreeHGlobal(poolOut); throw new Exception("CVPixelBufferPoolCreate returned " + ret.ToString()); } this.handle = Marshal.ReadIntPtr(poolOut); Marshal.FreeHGlobal(poolOut); }
public CVPixelBuffer(int width, int height, CVPixelFormatType pixelFormatType, NSDictionary pixelBufferAttributes) { IntPtr pixelBufferOut = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(IntPtr))); CVReturn ret = CVPixelBufferCreate(IntPtr.Zero, (IntPtr)width, (IntPtr)height, pixelFormatType, pixelBufferAttributes.Handle, pixelBufferOut); if (ret != CVReturn.Success) { Marshal.FreeHGlobal(pixelBufferOut); throw new Exception("CVPixelBufferCreate returned: " + ret); } this.handle = Marshal.ReadIntPtr(pixelBufferOut); Marshal.FreeHGlobal(pixelBufferOut); }
// Private Callback function for CVDisplayLink private CVReturn MyDisplayLinkOutputCallback(CVDisplayLink displayLink, ref CVTimeStamp inNow, ref CVTimeStamp inOutputTime, CVOptionFlags flagsIn, ref CVOptionFlags flagsOut) { //CVReturn result = GetFrameForTime (inOutputTime); CVReturn result = CVReturn.Error; // There is no autorelease pool when this method is called because it will be called from a background thread // It's important to create one or you will leak objects using (NSAutoreleasePool pool = new NSAutoreleasePool()) { // Update the animation RenderScene(); result = CVReturn.Success; } return(result); }
public CVPixelBuffer CreatePixelBuffer() { IntPtr pixelBufferOut = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(IntPtr))); CVReturn ret = CVPixelBufferPoolCreatePixelBuffer(IntPtr.Zero, handle, pixelBufferOut); if (ret != CVReturn.Success) { Marshal.FreeHGlobal(pixelBufferOut); throw new Exception("CVPixelBufferPoolCreatePixelBuffer returned " + ret.ToString()); } CVPixelBuffer pixelBuffer = new CVPixelBuffer(Marshal.ReadIntPtr(pixelBufferOut)); Marshal.FreeHGlobal(pixelBufferOut); return(pixelBuffer); }
public CVDisplayLink() { IntPtr displayLinkOut = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(IntPtr))); try { CVReturn ret = CVDisplayLinkCreateWithActiveCGDisplays(displayLinkOut); if (ret != CVReturn.Success) { throw new Exception("CVDisplayLink returned: " + ret); } this.handle = Marshal.ReadIntPtr(displayLinkOut); } finally { Marshal.FreeHGlobal(displayLinkOut); } }
public NSDictionary GetAttributes(NSDictionary [] attributes) { IntPtr resolvedDictionaryOut = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(IntPtr))); NSArray attributeArray = NSArray.FromNSObjects(attributes); CVReturn ret = CVPixelBufferCreateResolvedAttributesDictionary(IntPtr.Zero, attributeArray.Handle, resolvedDictionaryOut); if (ret != CVReturn.Success) { Marshal.FreeHGlobal(resolvedDictionaryOut); throw new Exception("CVPixelBufferCreate returned: " + ret); } NSDictionary dictionary = (NSDictionary)Runtime.GetNSObject(Marshal.ReadIntPtr(resolvedDictionaryOut)); Marshal.FreeHGlobal(resolvedDictionaryOut); return(dictionary); }
public static CVDisplayLink?CreateFromDisplayIds(uint[] displayIds, out CVReturn error) { if (displayIds == null) { throw new ArgumentNullException(nameof(displayIds)); } error = 0; IntPtr handle = IntPtr.Zero; error = CVDisplayLinkCreateWithCGDisplays(displayIds, displayIds.Length, out handle); if (error != 0) { return(null); } return(new CVDisplayLink(handle, true)); }
public CVMetalTextureCache(IMTLDevice metalDevice, CVMetalTextureAttributes textureAttributes) { if (metalDevice == null) { throw new ArgumentNullException(nameof(metalDevice)); } CVReturn err = (CVReturn)CVMetalTextureCacheCreate(IntPtr.Zero, IntPtr.Zero, /* change one day to support cache attributes */ metalDevice.Handle, textureAttributes?.Dictionary.Handle ?? IntPtr.Zero, out handle); if (err == CVReturn.Success) { return; } throw new Exception($"Could not create the texture cache, Reason: {err}."); }
static IntPtr Create(IMTLDevice metalDevice, CVMetalTextureAttributes?textureAttributes) { if (metalDevice is null) { throw new ArgumentNullException(nameof(metalDevice)); } CVReturn err = (CVReturn)CVMetalTextureCacheCreate(IntPtr.Zero, IntPtr.Zero, /* change one day to support cache attributes */ metalDevice.Handle, textureAttributes.GetHandle(), out var handle); if (err == CVReturn.Success) { return(handle); } throw new Exception($"Could not create the texture cache, Reason: {err}."); }
// Private Callback function for CVDisplayLink static CVReturn DisplayLinkOutputCallback(IntPtr displayLink, ref CVTimeStamp inNow, ref CVTimeStamp inOutputTime, CVOptionFlags flagsIn, ref CVOptionFlags flagsOut, IntPtr displayLinkContext) { //CVReturn result = GetFrameForTime (inOutputTime); CVReturn result = CVReturn.Success; using (new NSAutoreleasePool()) { try { foreach (var view in _views) { view.Value.Draw(); } } catch (Exception e) { Console.Error.WriteLine(e); result = CVReturn.Error; } } return(result); }
public static CVPixelBuffer?Create(IOSurface.IOSurface surface, out CVReturn result, CVPixelBufferAttributes?pixelBufferAttributes = null) { if (surface == null) { throw new ArgumentNullException(nameof(surface)); } IntPtr pixelBufferPtr; result = CVPixelBufferCreateWithIOSurface( allocator: IntPtr.Zero, surface: surface.Handle, pixelBufferAttributes: pixelBufferAttributes?.Dictionary.Handle ?? IntPtr.Zero, pixelBufferOut: out pixelBufferPtr ); if (result != CVReturn.Success) { return(null); } return(new CVPixelBuffer(pixelBufferPtr, true)); }
public static CVPixelBuffer Create (nint width, nint height, CVPixelFormatType pixelFormatType, byte[] data, nint bytesPerRow, CVPixelBufferAttributes pixelBufferAttributes, out CVReturn status) { IntPtr handle; GCHandle gchandle; if (data == null) throw new ArgumentNullException (nameof (data)); if (data.Length < height * bytesPerRow) throw new ArgumentOutOfRangeException (nameof (data), "The length of data is smaller than height * bytesPerRow"); gchandle = GCHandle.Alloc (data, GCHandleType.Pinned); status = CVPixelBufferCreateWithBytes (IntPtr.Zero, width, height, pixelFormatType, gchandle.AddrOfPinnedObject (), bytesPerRow, releaseBytesCallback, GCHandle.ToIntPtr (gchandle), DictionaryContainerHelper.GetHandle (pixelBufferAttributes), out handle); if (status != CVReturn.Success) { gchandle.Free (); return null; } return new CVPixelBuffer (handle, true); }
public static CVPixelBuffer Create (nint width, nint height, CVPixelFormatType pixelFormatType, byte[][] planes, nint[] planeWidths, nint[] planeHeights, nint[] planeBytesPerRow, CVPixelBufferAttributes pixelBufferAttributes, out CVReturn status) { IntPtr handle; IntPtr[] addresses; PlaneData data; GCHandle data_handle; if (planes == null) throw new ArgumentNullException (nameof (planes)); if (planeWidths == null) throw new ArgumentNullException (nameof (planeWidths)); if (planeHeights == null) throw new ArgumentNullException (nameof (planeHeights)); if (planeBytesPerRow == null) throw new ArgumentNullException (nameof (planeBytesPerRow)); var planeCount = planes.Length; if (planeWidths.Length != planeCount) throw new ArgumentOutOfRangeException (nameof (planeWidths), "The length of planeWidths does not match the number of planes"); if (planeHeights.Length != planeCount) throw new ArgumentOutOfRangeException (nameof (planeWidths), "The length of planeHeights does not match the number of planes"); if (planeBytesPerRow.Length != planeCount) throw new ArgumentOutOfRangeException (nameof (planeWidths), "The length of planeBytesPerRow does not match the number of planes"); addresses = new IntPtr [planeCount]; data = new PlaneData (); data.dataHandles = new GCHandle [planeCount]; for (int i = 0; i < planeCount; i++) { data.dataHandles[i] = GCHandle.Alloc (planes [i], GCHandleType.Pinned); addresses[i] = data.dataHandles[i].AddrOfPinnedObject (); } data_handle = GCHandle.Alloc (data); status = CVPixelBufferCreateWithPlanarBytes (IntPtr.Zero, width, height, pixelFormatType, IntPtr.Zero, 0, planeCount, addresses, planeWidths, planeHeights, planeBytesPerRow, releasePlanarBytesCallback, GCHandle.ToIntPtr (data_handle), DictionaryContainerHelper.GetHandle (pixelBufferAttributes), out handle); if (status != CVReturn.Success) { data_handle.Free (); return null; } return new CVPixelBuffer (handle, true); }
public CVReturn GetCurrentTime(out CVTimeStamp outTime) { CVReturn ret = CVDisplayLinkGetCurrentTime(this.Handle, out outTime); return(ret); }
public CVOperationFailedException(CVReturn reason) : base("Core Video operation failed. (" + reason + ").") { this.reason = reason; }
public static CVMetalTextureCache FromDevice(IMTLDevice metalDevice, CVMetalTextureAttributes textureAttributes, out CVReturn creationErr) { if (metalDevice == null) { throw new ArgumentNullException(nameof(metalDevice)); } IntPtr handle; creationErr = (CVReturn)CVMetalTextureCacheCreate(IntPtr.Zero, IntPtr.Zero, /* change one day to support cache attributes */ metalDevice.Handle, textureAttributes?.Dictionary.Handle ?? IntPtr.Zero, out handle); if (creationErr == CVReturn.Success) { return(new CVMetalTextureCache(handle)); } return(null); }
public CVPixelBuffer?CreatePixelBuffer(CVPixelBufferPoolAllocationSettings allocationSettings, out CVReturn error) { IntPtr pb; error = CVPixelBufferPoolCreatePixelBufferWithAuxAttributes(IntPtr.Zero, handle, allocationSettings.GetHandle(), out pb); if (error != CVReturn.Success) { return(null); } return(new CVPixelBuffer(pb, true)); }
public static CVPixelBuffer? Create (nint width, nint height, CVPixelFormatType pixelFormatType, byte[][] planes, nint[] planeWidths, nint[] planeHeights, nint[] planeBytesPerRow, CVPixelBufferAttributes pixelBufferAttributes, out CVReturn status) { IntPtr handle; IntPtr[] addresses; PlaneData data; GCHandle data_handle; if (planes == null) throw new ArgumentNullException (nameof (planes)); if (planeWidths == null) throw new ArgumentNullException (nameof (planeWidths)); if (planeHeights == null) throw new ArgumentNullException (nameof (planeHeights)); if (planeBytesPerRow == null) throw new ArgumentNullException (nameof (planeBytesPerRow)); var planeCount = planes.Length; if (planeWidths.Length != planeCount) throw new ArgumentOutOfRangeException (nameof (planeWidths), "The length of planeWidths does not match the number of planes"); if (planeHeights.Length != planeCount) throw new ArgumentOutOfRangeException (nameof (planeWidths), "The length of planeHeights does not match the number of planes"); if (planeBytesPerRow.Length != planeCount) throw new ArgumentOutOfRangeException (nameof (planeWidths), "The length of planeBytesPerRow does not match the number of planes"); addresses = new IntPtr [planeCount]; data = new PlaneData (); data.dataHandles = new GCHandle [planeCount]; for (int i = 0; i < planeCount; i++) { data.dataHandles[i] = GCHandle.Alloc (planes [i], GCHandleType.Pinned); // This can't use unsafe code because we need to get the pointer for an unbound number of objects. addresses[i] = data.dataHandles[i].AddrOfPinnedObject (); } data_handle = GCHandle.Alloc (data); IntPtr data_handle_ptr = GCHandle.ToIntPtr (data_handle); status = CVPixelBufferCreateWithPlanarBytes (IntPtr.Zero, width, height, pixelFormatType, IntPtr.Zero, 0, planeCount, addresses, planeWidths, planeHeights, planeBytesPerRow, releasePlanarBytesCallback, data_handle_ptr, DictionaryContainerHelper.GetHandle (pixelBufferAttributes), out handle); if (status != CVReturn.Success) { ReleasePlanarBytesCallback (data_handle_ptr, IntPtr.Zero, 0, 0, IntPtr.Zero); return null; } return new CVPixelBuffer (handle, true); }
public static CVPixelBuffer? Create (nint width, nint height, CVPixelFormatType pixelFormatType, byte[] data, nint bytesPerRow, CVPixelBufferAttributes pixelBufferAttributes, out CVReturn status) { IntPtr handle; GCHandle gchandle; if (data == null) throw new ArgumentNullException (nameof (data)); if (data.Length < height * bytesPerRow) throw new ArgumentOutOfRangeException (nameof (data), "The length of data is smaller than height * bytesPerRow"); gchandle = GCHandle.Alloc (data, GCHandleType.Pinned); // This requires a pinned GCHandle, because unsafe code is scoped to the current block, and the address of the byte array will be used after this function returns. status = CVPixelBufferCreateWithBytes (IntPtr.Zero, width, height, pixelFormatType, gchandle.AddrOfPinnedObject (), bytesPerRow, releaseBytesCallback, GCHandle.ToIntPtr (gchandle), DictionaryContainerHelper.GetHandle (pixelBufferAttributes), out handle); if (status != CVReturn.Success) { gchandle.Free (); return null; } return new CVPixelBuffer (handle, true); }
public CVOpenGLESTexture TextureFromImage (CVImageBuffer imageBuffer, bool isTexture2d, OpenTK.Graphics.ES30.All internalFormat, int width, int height, OpenTK.Graphics.ES30.All pixelFormat, OpenTK.Graphics.ES30.DataType pixelType, int planeIndex, out CVReturn errorCode) { return TextureFromImage (imageBuffer, isTexture2d, (OpenTK.Graphics.ES20.All) internalFormat, width, height, (OpenTK.Graphics.ES20.All) pixelFormat, (OpenTK.Graphics.ES20.DataType) pixelType, planeIndex, out errorCode); }
public CVPixelBuffer CreatePixelBuffer(CVPixelBufferPoolAllocationSettings allocationSettings, out CVReturn error) { IntPtr pb; error = CVPixelBufferPoolCreatePixelBufferWithAuxAttributes(IntPtr.Zero, handle, allocationSettings == null ? IntPtr.Zero : allocationSettings.Dictionary.Handle, out pb); if (error != CVReturn.Success) { return(null); } return(new CVPixelBuffer(pb)); }
public CVMetalTexture TextureFromImage(CVImageBuffer imageBuffer, MTLPixelFormat format, nint width, nint height, nint planeIndex, out CVReturn errorCode) { if (imageBuffer == null) { throw new ArgumentNullException("imageBuffer"); } IntPtr texture; errorCode = CVMetalTextureCacheCreateTextureFromImage( allocator: IntPtr.Zero, textureCache: handle, /* textureCache dict, one day we might add it */ sourceImage: imageBuffer.Handle, textureAttr: IntPtr.Zero, format: (nuint)(ulong)format, width: width, height: height, planeIndex: planeIndex, textureOut: out texture); if (errorCode != 0) { return(null); } return(new CVMetalTexture(texture)); }
public CVPixelBuffer CreatePixelBuffer (CVPixelBufferPoolAllocationSettings allocationSettings, out CVReturn error) { IntPtr pb; error = CVPixelBufferPoolCreatePixelBufferWithAuxAttributes (IntPtr.Zero, handle, allocationSettings.GetHandle (), out pb); if (error != CVReturn.Success) return null; return new CVPixelBuffer (pb, true); }
public CVMetalTexture TextureFromImage(CVImageBuffer imageBuffer, MTLPixelFormat format, nint width, nint height, nint planeIndex, out CVReturn errorCode) { if (imageBuffer == null) throw new ArgumentNullException ("imageBuffer"); IntPtr texture; errorCode = CVMetalTextureCacheCreateTextureFromImage ( allocator: IntPtr.Zero, textureCache: handle, /* textureCache dict, one day we might add it */ sourceImage: imageBuffer.Handle, textureAttr: IntPtr.Zero, format: (nuint) (ulong) format, width: width, height: height, planeIndex: planeIndex, textureOut: out texture); if (errorCode != 0) return null; return new CVMetalTexture (texture); }
public CVOpenGLESTexture TextureFromImage(CVImageBuffer imageBuffer, bool isTexture2d, OpenTK.Graphics.ES20.All internalFormat, int width, int height, OpenTK.Graphics.ES20.All pixelFormat, OpenTK.Graphics.ES20.DataType pixelType, int planeIndex, out CVReturn errorCode) { if (imageBuffer == null) { throw new ArgumentNullException("imageBuffer"); } int target = isTexture2d ? 0x0DE1 /* GL_TEXTURE_2D */ : 0x8D41 /* GL_RENDERBUFFER */; IntPtr texture; errorCode = CVOpenGLESTextureCacheCreateTextureFromImage( IntPtr.Zero, handle, /* textureCache dict, one day we might add it */ imageBuffer.Handle, IntPtr.Zero, target, internalFormat, width, height, pixelFormat, pixelType, (IntPtr)planeIndex, out texture); if (errorCode != 0) { return(null); } return(new CVOpenGLESTexture(texture)); }
public CVOpenGLESTexture TextureFromImage(CVImageBuffer imageBuffer, bool isTexture2d, OpenTK.Graphics.ES30.All internalFormat, int width, int height, OpenTK.Graphics.ES30.All pixelFormat, OpenTK.Graphics.ES30.DataType pixelType, int planeIndex, out CVReturn errorCode) { return(TextureFromImage(imageBuffer, isTexture2d, (OpenTK.Graphics.ES20.All)internalFormat, width, height, (OpenTK.Graphics.ES20.All)pixelFormat, (OpenTK.Graphics.ES20.DataType)pixelType, planeIndex, out errorCode)); }
public CVReturn MyDisplayLinkOutputCallback(CVDisplayLink displayLink, ref CVTimeStamp inNow, ref CVTimeStamp inOutputTime, CVOptionFlags flagsIn, ref CVOptionFlags flagsOut) { CVReturn result = GetFrameForTime(inOutputTime); return(result); }
public CVOpenGLESTexture TextureFromImage (CVImageBuffer imageBuffer, bool isTexture2d, OpenTK.Graphics.ES20.All internalFormat, int width, int height, OpenTK.Graphics.ES20.All pixelFormat, OpenTK.Graphics.ES20.DataType pixelType, int planeIndex, out CVReturn errorCode) { if (imageBuffer == null) throw new ArgumentNullException ("imageBuffer"); int target = isTexture2d ? 0x0DE1 /* GL_TEXTURE_2D */ : 0x8D41 /* GL_RENDERBUFFER */; IntPtr texture; errorCode = CVOpenGLESTextureCacheCreateTextureFromImage ( IntPtr.Zero, handle, /* textureCache dict, one day we might add it */ imageBuffer.Handle, IntPtr.Zero, target, internalFormat, width, height, pixelFormat, pixelType, (IntPtr) planeIndex, out texture); if (errorCode != 0) return null; return new CVOpenGLESTexture (texture); }