/// <summary> /// Begin streaming buffers. /// </summary> public unsafe void StreamBuffers() { if (LinuxVideoInterop.ReqBufs(this.handle, NumberOfDriverBuffers, LinuxVideoInterop.Memory.MemoryMapping) != NumberOfDriverBuffers) { throw new IOException("Could not allocate buffers."); } try { // enque and memory map all the buffers for (var i = 0u; i < NumberOfDriverBuffers; i++) { var buf = LinuxVideoInterop.QueryBuf(this.handle, i); LinuxVideoInterop.EnqueBuffer(this.handle, buf); this.buffers[i] = new BufferInfo() { Initialized = true, Start = LinuxVideoInterop.MemoryMap(this.handle, buf), Buffer = buf, }; } LinuxVideoInterop.StreamOn(this.handle); this.background = new Thread(new ThreadStart(this.ProcessFrames)) { IsBackground = true }; this.isStopping = false; this.background.Start(); } catch { for (var i = 0u; i < NumberOfDriverBuffers; i++) { var buf = this.buffers[i]; if (buf.Initialized) { LinuxVideoInterop.MemoryUnmap(buf.Buffer); } } throw; } }
/// <summary> /// Dispose image frame (re-enqueuing underlying driver buffer). /// </summary> public void Dispose() { LinuxVideoInterop.EnqueBuffer(this.handle, this.buffer); }