2
enum v4l2_memory {
    V4L2_MEMORY_MMAP             = 1,
    V4L2_MEMORY_USERPTR          = 2,
    V4L2_MEMORY_OVERLAY          = 3,
    V4L2_MEMORY_DMABUF           = 4,

};

Which is one of the fastest and efficient methods for video streaming without any frame drops.

  • Depends on the hardware, I suppose, followed by the driver implementation and user space tools. – 0andriy Apr 06 '21 at 13:57
  • 2
    They are used for different purposes.`'mmap` - the driver allocates the buffers and userspace should map them. `userptr` - userspace allocates the buffers, `dmabuf` used to share buffer already created by a different device. – dafnahaktana Apr 07 '21 at 09:32

1 Answers1

1

Userptr, mmap and DMABUF are all methods in order to avoid wasted CPU cycles caused by copying memory (zero-copy), but each have different usecases in which they are useful. An attempt at a simplistic comparison:

  • Userpointer

    • Here userspace allocates the memory, and passes a pointer to kernelspace (to use upon output, or even fill in for input).
    • In theory, even in a pipeline where video is captured, and sent out again on another device, this could avoid any copies.
    • In practice, this user-allocated-memory is typically not always easily accessible by the hardware. Hardware prefers DMA-memory regions, which userspace cannot allocate.
  • MMAP

    • Method by which the memory is allocated by the driver/in kernel space, and is mapped to the user memory space without any copies. This means the memory can point to DMA-memory (which was allocated in kernel space)

    • This works well for receiving frames, or sending frames, but in a pipeline where the same frames should be passed through multiple hardware devices (e.g. capture + encoder + output), only one driver can allocate the buffers. Letting all the drivers allocate their own memory requires userspace to still copy between them. Combining MMAP with a userpointer works for a single receive-send pipeline, but this breaks down further if multiple elements in a chain are needed.

  • DMABUF

    • Kernelspace allocates (explicit) DMA memory, but in contrast to MMAP, this information regarding the dma memory space is explicitly kept. This allows userspace to set up a processing chain, allowing multiple drivers to share DMA-buffers efficiently.

The guys at pengutronix have a nice presentation about this, where these concepts are visualized: https://elinux.org/images/b/b0/OSELAS.Presentation-DMABUF-migration.pdf

Arnout
  • 341
  • 2
  • 8