libcamera  v0.4.0
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...
 
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. 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

◆ 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]countThe number of requested FrameBuffers
[in]planeSizesThe sizes of planes in each FrameBuffer
[out]buffersArray 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()

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: