// Constructor from external pixel buffer public Bgra32VideoFrame(int width, int height, _BMDFrameFlags flags, IntPtr byteArray) { m_width = width; m_height = height; m_flags = flags; // Make reference to buffer m_pixelBuffer = byteArray; }
// Constructor generates empty pixel buffer public Bgra32VideoFrame(int width, int height, _BMDFrameFlags flags) { m_width = width; m_height = height; m_flags = flags; m_pixelBufferBytes = m_width * m_height * 4; // Allocate pixel buffer from unmanaged memory m_unmanagedBuffer = System.Runtime.InteropServices.Marshal.AllocCoTaskMem(m_pixelBufferBytes); m_pixelBuffer = m_unmanagedBuffer; // Inform runtime of large unmanaged memory allocation for scheduling garbage collection System.GC.AddMemoryPressure(m_pixelBufferBytes); }