Example #1
0
		public static VTCompressionSession Create (int width, int height, CMVideoCodecType codecType,
			VTCompressionOutputCallback compressionOutputCallback,
			VTVideoEncoderSpecification encoderSpecification, // hardware acceleration is default behavior on iOS. no opt-in required.
			CVPixelBufferAttributes sourceImageBufferAttributes)
		{
			return Create (width, height, codecType, compressionOutputCallback, encoderSpecification, sourceImageBufferAttributes == null ? null : sourceImageBufferAttributes.Dictionary, static_CompressionOutputCallback);
		}
            /* CV_RETURNS_RETAINED_PARAMETER CVPixelBufferRef CV_NULLABLE * CV_NONNULL */ out IntPtr pixelBufferOut);             // __OSX_AVAILABLE_STARTING(__MAC_10_4,__IPHONE_4_0);

        public static CVPixelBuffer Create(nint width, nint height, CVPixelFormatType pixelFormatType, byte[][] planes, nint[] planeWidths, nint[] planeHeights, nint[] planeBytesPerRow, CVPixelBufferAttributes pixelBufferAttributes)
        {
            CVReturn status;

            return(Create(width, height, pixelFormatType, planes, planeWidths, planeHeights, planeBytesPerRow, pixelBufferAttributes, out status));
        }
        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));
        }
            /* CV_RETURNS_RETAINED_PARAMETER CVPixelBufferRef CV_NULLABLE * CV_NONNULL */ out IntPtr pixelBufferOut);            // __OSX_AVAILABLE_STARTING(__MAC_10_4,__IPHONE_4_0);

        public static CVPixelBuffer Create(nint width, nint height, CVPixelFormatType pixelFormatType, byte[] data, nint bytesPerRow, CVPixelBufferAttributes pixelBufferAttributes)
        {
            CVReturn status;

            return(Create(width, height, pixelFormatType, data, bytesPerRow, pixelBufferAttributes, out status));
        }
        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));
        }
Example #6
0
			/* CV_RETURNS_RETAINED_PARAMETER CVPixelBufferRef CV_NULLABLE * CV_NONNULL */ out IntPtr pixelBufferOut);// __OSX_AVAILABLE_STARTING(__MAC_10_4,__IPHONE_4_0);

		public static CVPixelBuffer Create (nint width, nint height, CVPixelFormatType pixelFormatType, byte[] data, nint bytesPerRow, CVPixelBufferAttributes pixelBufferAttributes)
		{
			CVReturn status;
			return Create (width, height, pixelFormatType, data, bytesPerRow, pixelBufferAttributes, out status);
		}
 public CVPixelBuffer(System.Drawing.Size size, CVPixelFormatType pixelFormatType, CVPixelBufferAttributes attributes)
     : this(size.Width, size.Height, pixelFormatType, attributes == null ? null : attributes.Dictionary)
 {
 }
Example #8
0
        public static CVPixelBuffer Create(XamCore.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));
        }
Example #9
0
        public static CVPixelBuffer Create(XamCore.IOSurface.IOSurface surface, CVPixelBufferAttributes pixelBufferAttributes = null)
        {
            CVReturn result;

            return(Create(surface, out result, pixelBufferAttributes));
        }
Example #10
0
		public CVPixelBuffer (nint width, nint height, CVPixelFormatType pixelFormatType, CVPixelBufferAttributes attributes)
			: this (width, height, pixelFormatType, attributes == null ? null : attributes.Dictionary)
		{
		}
Example #11
0
 public CVPixelBufferPool(CVPixelBufferPoolSettings settings, CVPixelBufferAttributes pixelBufferAttributes)
     : this(settings.GetDictionary(), pixelBufferAttributes.GetDictionary())
 {
 }
Example #12
0
		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);
		}
Example #13
0
			/* CV_RETURNS_RETAINED_PARAMETER CVPixelBufferRef CV_NULLABLE * CV_NONNULL */ out IntPtr pixelBufferOut); // __OSX_AVAILABLE_STARTING(__MAC_10_4,__IPHONE_4_0);

		public static CVPixelBuffer Create (nint width, nint height, CVPixelFormatType pixelFormatType, byte[][] planes, nint[] planeWidths, nint[] planeHeights, nint[] planeBytesPerRow, CVPixelBufferAttributes pixelBufferAttributes)
		{
			CVReturn status;
			return Create (width, height, pixelFormatType, planes, planeWidths, planeHeights, planeBytesPerRow, pixelBufferAttributes, out status);
		}
Example #14
0
		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);
		}
Example #15
0
		public static VTDecompressionSession Create (VTDecompressionOutputCallback outputCallback,
							     CMVideoFormatDescription formatDescription,
							     VTVideoDecoderSpecification decoderSpecification, // hardware acceleration is default behavior on iOS. no opt-in required.
							     CVPixelBufferAttributes destinationImageBufferAttributes)
		{
			return Create (outputCallback, formatDescription, decoderSpecification, destinationImageBufferAttributes == null ? null : destinationImageBufferAttributes.Dictionary, static_newDecompressionOutputCallback);
		}
 public CVPixelBuffer(nint width, nint height, CVPixelFormatType pixelFormatType, CVPixelBufferAttributes attributes)
     : this(width, height, pixelFormatType, attributes == null ? null : attributes.Dictionary)
 {
 }
Example #17
0
		public CVPixelBufferPool (CVPixelBufferPoolSettings settings, CVPixelBufferAttributes pixelBufferAttributes)
			: this (settings.GetDictionary (), pixelBufferAttributes.GetDictionary ())
		{
		}
Example #18
0
		public CVPixelBuffer (System.Drawing.Size size, CVPixelFormatType pixelFormatType, CVPixelBufferAttributes attributes)
			: this (size.Width, size.Height, pixelFormatType, attributes == null ? null : attributes.Dictionary)
		{
		}