Exemplo n.º 1
0
        private unsafe NewImageBufferReadyEventArgs GetFrameDataPooled(InteropVideodev2.V4l2FrameBuffer *buffers)
        {
            // Get one frame from the buffer
            InteropVideodev2.v4l2_buffer frame = new InteropVideodev2.v4l2_buffer
            {
                type   = InteropVideodev2.v4l2_buf_type.V4L2_BUF_TYPE_VIDEO_CAPTURE,
                memory = InteropVideodev2.v4l2_memory.V4L2_MEMORY_MMAP,
            };
            V4l2Struct(InteropVideodev2.V4l2Request.VIDIOC_DQBUF, ref frame);

            // Get data from pointer
            IntPtr intptr = buffers[frame.index].Start;
            var    length = (int)buffers[frame.index].Length;

            byte[] dataBuffer = Array.Empty <byte>();
            if (ImageBufferPoolingEnabled)
            {
                dataBuffer = ArrayPool <byte> .Shared.Rent(length);
            }
            else
            {
                dataBuffer = new byte[length];
            }

            Marshal.Copy(source: intptr, destination: dataBuffer, startIndex: 0, length: (int)buffers[frame.index].Length);

            // Requeue the buffer
            V4l2Struct(InteropVideodev2.V4l2Request.VIDIOC_QBUF, ref frame);

            return(new NewImageBufferReadyEventArgs(dataBuffer, length));
        }
Exemplo n.º 2
0
 private static unsafe void UnmappingFrameBuffers(InteropVideodev2.V4l2FrameBuffer *buffers)
 {
     // Unmapping the applied buffer to user space
     for (uint i = 0; i < BufferCount; i++)
     {
         Interop.munmap(buffers[i].Start, (int)buffers[i].Length);
     }
 }
Exemplo n.º 3
0
        private unsafe byte[] GetFrameData(InteropVideodev2.V4l2FrameBuffer *buffers)
        {
            // Get one frame from the buffer
            InteropVideodev2.v4l2_buffer frame = new InteropVideodev2.v4l2_buffer
            {
                type   = InteropVideodev2.v4l2_buf_type.V4L2_BUF_TYPE_VIDEO_CAPTURE,
                memory = InteropVideodev2.v4l2_memory.V4L2_MEMORY_MMAP,
            };
            V4l2Struct(InteropVideodev2.V4l2Request.VIDIOC_DQBUF, ref frame);

            // Get data from pointer
            IntPtr intptr = buffers[frame.index].Start;

            byte[] dataBuffer = new byte[buffers[frame.index].Length];
            Marshal.Copy(source: intptr, destination: dataBuffer, startIndex: 0, length: (int)buffers[frame.index].Length);

            // Requeue the buffer
            V4l2Struct(InteropVideodev2.V4l2Request.VIDIOC_QBUF, ref frame);

            return(dataBuffer);
        }