libcamera v0.2.0
Supporting cameras in Linux since 2019
Public Types | Public Member Functions | List of all members
libcamera::DmaHeap Class Reference

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

Public Types

enum class  DmaHeapFlag { Cma = 1 << 0 , System = 1 << 1 }
 Type of the dma-heap. More...
 
using DmaHeapFlags = Flags< DmaHeapFlag >
 A bitwise combination of DmaHeap::DmaHeapFlag values.
 

Public Member Functions

 DmaHeap (DmaHeapFlags flags=DmaHeapFlag::Cma)
 Construct a DmaHeap that owns a CMA or system dma-heap file descriptor. More...
 
 ~DmaHeap ()
 Destroy the DmaHeap instance. More...
 
bool isValid () const
 Check if the DmaHeap instance is valid. More...
 
UniqueFD alloc (const char *name, std::size_t size)
 Allocate a dma-buf from the DmaHeap. More...
 

Detailed Description

Helper class for dma-heap allocations.

Member Enumeration Documentation

◆ DmaHeapFlag

Type of the dma-heap.

Enumerator
Cma 

Allocate from a CMA dma-heap.

System 

Allocate from the system dma-heap.

Constructor & Destructor Documentation

◆ DmaHeap()

libcamera::DmaHeap::DmaHeap ( DmaHeapFlags  flags = DmaHeapFlag::Cma)

Construct a DmaHeap that owns a CMA or system dma-heap file descriptor.

Parameters
[in]flagsThe type(s) of the dma-heap(s) to allocate from

By default flags are set to DmaHeap::DmaHeapFlag::Cma. The constructor goes through the internal list of possible names of the CMA and system dma-heap devices until the dma-heap device of the requested type is successfully opened. If more than one dma-heap type is specified in flags the CMA heap is tried first. If it fails to open any dma-heap device an invalid DmaHeap object is constructed. A valid DmaHeap object owns a wrapped dma-heap file descriptor.

Please check the new DmaHeap object with DmaHeap::isValid before using it.

◆ ~DmaHeap()

libcamera::DmaHeap::~DmaHeap ( )
default

Destroy the DmaHeap instance.

Destroying a DmaHeap instance which owns a wrapped dma-heap file descriptor closes the descriptor automatically.

Member Function Documentation

◆ alloc()

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

Allocate a dma-buf from the DmaHeap.

Parameters
[in]nameThe name to set for the allocated buffer
[in]sizeThe size of the buffer to allocate
Returns
The UniqueFD of the allocated buffer

Allocates a dma-buf with read/write access. If the allocation fails returns invalid UniqueFD.

◆ isValid()

libcamera::DmaHeap::isValid ( ) const
inline

Check if the DmaHeap instance is valid.

Returns
True if the DmaHeap is valid, false otherwise

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