示例#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.m_instance.Handle
            });
        }
示例#2
0
        /// <summary>
        /// Copy frame data to Vertex array
        /// </summary>
        /// <param name="array"></param>
        public void CopyTo(Vertex[] array)
        {
            if (array == null)
            {
                throw new ArgumentNullException("array");
            }
            var handle = GCHandle.Alloc(array, GCHandleType.Pinned);

            try
            {
                NativeMethods.memcpy(handle.AddrOfPinnedObject(), VertexData, Count * Marshal.SizeOf(typeof(Vertex)));
            }
            finally
            {
                handle.Free();
            }
        }
示例#3
0
        /// <summary>
        /// Copy frame data to managed typed array
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="array"></param>
        //public void CopyTo<T>(out T[] array)
        public void CopyTo <T>(T[] array)
        {
            if (array == null)
            {
                throw new ArgumentNullException("array");
            }
            var handle = GCHandle.Alloc(array, GCHandleType.Pinned);

            try
            {
                //System.Diagnostics.Debug.Assert((array.Length * Marshal.SizeOf(typeof(T))) == (Stride * Height));
                NativeMethods.memcpy(handle.AddrOfPinnedObject(), Data, Stride * Height);
            }
            finally
            {
                handle.Free();
            }
        }
示例#4
0
        /// <summary>
        /// Copy frame data to TextureCoordinate array
        /// </summary>
        /// <param name="textureArray"></param>
        public void CopyTo(TextureCoordinate[] textureArray)
        {
            if (textureArray == null)
            {
                throw new ArgumentNullException("textureArray");
            }

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

            try
            {
                var size = Count * Marshal.SizeOf(typeof(TextureCoordinate));
                NativeMethods.memcpy(handle.AddrOfPinnedObject(), TextureData, size);
            }
            finally
            {
                handle.Free();
            }
        }
示例#5
0
 public void CopyTo(IntPtr ptr)
 {
     //System.Diagnostics.Debug.Assert(ptr != IntPtr.Zero);
     NativeMethods.memcpy(ptr, Data, Stride * Height);
 }
示例#6
0
 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)));
 }