Gladson Andrade
Gladson Andrade

Reputation: 55

What is the use of mmap , userptr and dmabuf in video streaming using v4l2 drivers in linux?

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.

Upvotes: 3

Views: 3625

Answers (1)

Arnout
Arnout

Reputation: 371

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

Upvotes: 3

Related Questions