libcamera  v0.3.1+12-19bbca3c
Supporting cameras in Linux since 2019
Public Types | Public Member Functions | List of all members
libcamera::DmaBufAllocator Class Reference

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

Public Types

enum  DmaBufAllocatorFlag { DmaBufAllocatorFlag::CmaHeap = 1 << 0, DmaBufAllocatorFlag::SystemHeap = 1 << 1, DmaBufAllocatorFlag::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. More...
 
 ~DmaBufAllocator ()
 Destroy the DmaBufAllocator instance.
 
bool isValid () const
 Check if the DmaBufAllocator instance is valid. More...
 
UniqueFD alloc (const char *name, std::size_t size)
 Allocate a dma-buf from the DmaBufAllocator. More...
 

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

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]typeThe 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]nameThe name to set for the allocated buffer
[in]sizeThe 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

◆ isValid()

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: