Ejemplo n.º 1
0
        public void AddVideoFrame <T>(T[] pixels, int stride, int bpp, double timestamp, TimestampDomain domain, int frameNumber, VideoStreamProfile profile)
        {
            // TODO: avoid copy by adding void* user_data to native methods, so we can pass GCHandle.ToIntPtr() and free in deleter
            IntPtr hglobal = Marshal.AllocHGlobal(profile.Height * stride);

            var handle = GCHandle.Alloc(pixels, GCHandleType.Pinned);

            try
            {
                NativeMethods.Memcpy(hglobal, handle.AddrOfPinnedObject(), profile.Height * stride);
            }
            finally
            {
                handle.Free();
            }

            AddVideoFrame(new SoftwareVideoFrame
            {
                pixels       = hglobal,
                deleter      = (p) => { Marshal.FreeHGlobal(p); },
                stride       = stride,
                bpp          = bpp,
                timestamp    = timestamp,
                domain       = domain,
                frame_number = frameNumber,
                profile      = profile.Handle
            });
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Copy data from pointer
        /// </summary>
        /// <param name="ptr">source pointer</param>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="ptr"/> is null</exception>
        public void CopyFrom(IntPtr ptr)
        {
            if (ptr == IntPtr.Zero)
            {
                throw new ArgumentNullException(nameof(ptr));
            }

            NativeMethods.Memcpy(Data, ptr, Stride * Height);
        }
Ejemplo n.º 3
0
 private void Copy <T>(IntPtr src, IntPtr dst)
 {
     Debug.Assert(src != IntPtr.Zero);
     Debug.Assert(dst != IntPtr.Zero);
     NativeMethods.Memcpy(dst, src, Count * Marshal.SizeOf(typeof(T)));
 }
Ejemplo n.º 4
0
 private void Copy <T>(IntPtr src, IntPtr dst, int size)
 {
     Debug.Assert(src != IntPtr.Zero);
     Debug.Assert(dst != IntPtr.Zero);
     NativeMethods.Memcpy(dst, src, size);
 }