libcamera: libcamera::DmaBufAllocator Class Reference

libcamera v0.7.1 Supporting cameras in Linux since 2019

Loading...
Searching...
No Matches
libcamera::DmaBufAllocator Class Reference

Helper class for dma-buf allocations. More...

## Public Types
enum class | DmaBufAllocatorFlag { CmaHeap = 1 << 0 , SystemHeap = 1 << 1 , UDmaBuf = 1 << 2 }
| Type of the dma-buf provider. More...
using | DmaBufAllocatorFlags = Flags<DmaBufAllocatorFlag>
| A bitwise combination of DmaBufAllocator::DmaBufAllocatorFlag values.

## Public Member Functions
| DmaBufAllocator (DmaBufAllocatorFlags flags=DmaBufAllocatorFlag::CmaHeap)
| Construct a DmaBufAllocator of a given type.
| ~DmaBufAllocator ()
| Destroy the DmaBufAllocator instance.
bool | isValid () const
| Check if the DmaBufAllocator instance is valid.
UniqueFD | alloc (const char *name, std::size_t size)
| Allocate a dma-buf from the DmaBufAllocator.
int | exportBuffers (unsigned int count, const std::vector< unsigned int > &planeSizes, std::vector< std::unique_ptr< FrameBuffer > > *buffers)
| Allocate and export buffers from the DmaBufAllocator.

## Detailed Description

Helper class for dma-buf allocations.

This class wraps a userspace dma-buf provider selected at construction time, and exposes functions to allocate dma-buffers from this provider.

Different providers may provide dma-buffers with different properties for the underlying memory. Which providers are acceptable is specified through the type argument passed to the DmaBufAllocator() constructor.

## Member Enumeration Documentation

## ◆ DmaBufAllocatorFlag

enum class libcamera::DmaBufAllocator::DmaBufAllocatorFlag
| strong

Type of the dma-buf provider.

Enumerator
CmaHeap | Allocate from a CMA dma-heap, providing physically-contiguous memory.
SystemHeap | Allocate from the system dma-heap, using the page allocator.
UDmaBuf | Allocate using a memfd + /dev/udmabuf.

## Constructor & Destructor Documentation

## ◆ DmaBufAllocator()

libcamera::DmaBufAllocator::DmaBufAllocator | ( | DmaBufAllocatorFlags | type = DmaBufAllocatorFlag::CmaHeap | ) |

Construct a DmaBufAllocator of a given type.

Parameters

  [in] | type | The type(s) of the dma-buf providers to allocate from

The dma-buf provider type is selected with the type parameter, which defaults to the CMA heap. If no provider of the given type can be accessed, the constructed DmaBufAllocator instance is invalid as indicated by the isValid() function.

Multiple types can be selected by combining type flags, in which case the constructed DmaBufAllocator will match one of the types. If multiple requested types can work on the system, which provider is used is undefined.

## Member Function Documentation

## ◆ alloc()

UniqueFD libcamera::DmaBufAllocator::alloc | ( | const char * | name,
|  | std::size_t | size )

Allocate a dma-buf from the DmaBufAllocator.

Parameters

  [in] | name | The name to set for the allocated buffer
  [in] | size | The size of the buffer to allocate

Allocates a dma-buf with read/write access.

If the allocation fails, return an invalid UniqueFD.

Returns
  The UniqueFD of the allocated buffer

## ◆ exportBuffers()

int libcamera::DmaBufAllocator::exportBuffers | ( | unsigned int | count,
|  | const std::vector< unsigned int > & | planeSizes,
|  | std::vector< std::unique_ptr< FrameBuffer > > * | buffers )

Allocate and export buffers from the DmaBufAllocator.

Parameters

  [in] | count | The number of requested FrameBuffers
  [in] | planeSizes | The sizes of planes in each FrameBuffer
  [out] | buffers | Array of buffers successfully allocated

Planes in a FrameBuffer are allocated with a single dma buf.

Todo
  Add the option to allocate each plane with a dma buf respectively.

Returns
  The number of allocated buffers on success or a negative error code otherwise

## ◆ isValid()

bool libcamera::DmaBufAllocator::isValid | ( |  | ) | const
| inline

Check if the DmaBufAllocator instance is valid.

Returns
  True if the DmaBufAllocator is valid, false otherwise

The documentation for this class was generated from the following files:

- include/libcamera/internal/dma_buf_allocator.h
- src/libcamera/dma_buf_allocator.cpp