public void AddVideoFrame(byte[] pixels, int stride, int bpp, double timestamp, TimestampDomain domain, int frameNumber, VideoStreamProfile profile) { object error; IntPtr hglobal = Marshal.AllocHGlobal(profile.Height * stride); var del = new frame_deleter(p => { Marshal.FreeHGlobal(p); }); Marshal.Copy(pixels, 0, hglobal, profile.Height * stride); var s = new NativeMethods.SoftwareVideoFrame { pixels = hglobal, deleter = del, stride = stride, bpp = bpp, timestamp = timestamp, domain = domain, frame_number = frameNumber, profile = profile.m_instance.Handle }; NativeMethods.rs2_software_sensor_on_video_frame(m_instance, s, out error); }
public void AddVideoFrame(byte[] pixels, int stride, int bpp, double timestamp, TimestampDomain domain, int frameNumber, VideoStreamProfile profile) { IntPtr hglobal = Marshal.AllocHGlobal(profile.Height * stride); Marshal.Copy(pixels, 0, hglobal, profile.Height * stride); 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 }); }
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 }); }