libcamera: libcamera::Request Class Reference

libcamera v0.0.1 Supporting cameras in Linux since 2019

Classes | Public Types | Public Member Functions | List of all members
libcamera::Request Class Reference

A frame capture request. More...

Inheritance diagram for libcamera::Request:
[legend]
Collaboration diagram for libcamera::Request:
[legend]

## Classes
class | Private
| Request private data. More...

## Public Types
enum | Status { RequestPending , RequestComplete , RequestCancelled }
enum | ReuseFlag { Default = 0 , ReuseBuffers = (1 << 0) }
using | BufferMap = std::map< const Stream *, FrameBuffer * >
| A map of Stream to FrameBuffer pointers.

## Public Member Functions
| Request (Camera *camera, uint64_t cookie=0)
| Create a capture request for a camera. More...
void | reuse (ReuseFlag flags=Default)
| Reset the request for reuse. More...
ControlList & | controls ()
| Retrieve the request's ControlList. More...
ControlList & | metadata ()
| Retrieve the request's metadata. More...
const BufferMap & | buffers () const
| Retrieve the request's streams to buffers map. More...
int | addBuffer (const Stream *stream, FrameBuffer *buffer, std::unique_ptr< Fence > fence=nullptr)
| Add a FrameBuffer with its associated Stream to the Request. More...
FrameBuffer * | findBuffer (const Stream *stream) const
| Return the buffer associated with a stream. More...
uint32_t | sequence () const
| Retrieve the sequence number for the request. More...
uint64_t | cookie () const
| Retrieve the cookie set when the request was created. More...
Status | status () const
| Retrieve the request completion status. More...
bool | hasPendingBuffers () const
| Check if a request has buffers yet to be completed. More...
std::string | toString () const
| Generate a string representation of the Request internals. More...
Public Member Functions inherited from libcamera::Extensible
| Extensible (std::unique_ptr< Private > d)
| Construct an instance of an Extensible class. More...

## Additional Inherited Members
Protected Member Functions inherited from libcamera::Extensible
template<typename T >
const T * | _d () const
| Retrieve the private data instance. More...
template<typename T >
T * | _d ()

## Detailed Description

A frame capture request.

A Request allows an application to associate buffers and controls on a per-frame basis to be queued to the camera device for processing.

## Member Enumeration Documentation

## ◆ ReuseFlag

enum libcamera::Request::ReuseFlag

Flags to control the behavior of Request::reuse()

Enumerator
Default | Don't reuse buffers
ReuseBuffers | Reuse the buffers that were previously added by addBuffer()

## ◆ Status

enum libcamera::Request::Status

Request completion status

Enumerator
RequestPending | The request hasn't completed yet
RequestComplete | The request has completed
RequestCancelled | The request has been cancelled due to capture stop

## Constructor & Destructor Documentation

## ◆ Request()

libcamera::Request::Request | ( | Camera * | camera,
|  | uint64_t | cookie = `0`
| ) |  |

Create a capture request for a camera.

Parameters

  [in] | camera | The camera that creates the request
  [in] | cookie | Opaque cookie for application use

The cookie is stored in the request and is accessible through the cookie() function at any time. It is typically used by applications to map the request to an external resource in the request completion handler, and is completely opaque to libcamera.

Todo:
  Add a validator for metadata controls.

## Member Function Documentation

## ◆ addBuffer()

int libcamera::Request::addBuffer | ( | const Stream * | stream,
|  | FrameBuffer * | buffer,
|  | std::unique_ptr< Fence > | fence = `nullptr`
| ) |  |

Add a FrameBuffer with its associated Stream to the Request.

Parameters

  [in] | stream | The stream the buffer belongs to
  [in] | buffer | The FrameBuffer to add to the request
  [in] | fence | The optional fence

A reference to the buffer is stored in the request. The caller is responsible for ensuring that the buffer will remain valid until the request complete callback is called.

A request can only contain one buffer per stream. If a buffer has already been added to the request for the same stream, this function returns -EEXIST.

A Fence can be optionally associated with the buffer.

When a valid Fence is provided to this function, fence is moved to buffer and this Request will only be queued to the device once the fences of all its buffers have been correctly signalled.

If the fence associated with buffer isn't signalled, the request will fail after a timeout. The buffer will still contain the fence, which applications must retrieve with FrameBuffer::releaseFence() before the buffer can be reused in another request. Attempting to add a buffer that still contains a fence to a request will result in this function returning -EEXIST.

See also
  FrameBuffer::releaseFence()

Returns
  0 on success or a negative error code otherwise

Return values

  -EEXIST | The request already contains a buffer for the stream or the buffer still references a fence
  -EINVAL | The buffer does not reference a valid Stream

## ◆ buffers()

libcamera::Request::buffers | ( |  | ) | const
| inline

Retrieve the request's streams to buffers map.

Return a reference to the map that associates each Stream part of the request to the FrameBuffer the Stream output should be directed to.

Returns
  The map of Stream to FrameBuffer

## ◆ controls()

libcamera::Request::controls | ( |  | ) |
| inline

Retrieve the request's ControlList.

Requests store a list of controls to be applied to all frames captured for the request. They are created with an empty list of controls that can be accessed through this function. Control values can be retrieved using ControlList::get() and updated using ControlList::set().

Only controls supported by the camera to which this request will be submitted shall be included in the controls list. Attempting to add an unsupported control causes undefined behaviour.

Returns
  A reference to the ControlList in this request

## ◆ cookie()

libcamera::Request::cookie | ( |  | ) | const
| inline

Retrieve the cookie set when the request was created.

Returns
  The request cookie

## ◆ findBuffer()

FrameBuffer * libcamera::Request::findBuffer | ( | const Stream * | stream | ) | const

Return the buffer associated with a stream.

Parameters

  [in] | stream | The stream the buffer is associated to

Returns
  The buffer associated with the stream, or nullptr if the stream is not part of this request

## ◆ hasPendingBuffers()

bool libcamera::Request::hasPendingBuffers | ( |  | ) | const

Check if a request has buffers yet to be completed.

Returns
  True if the request has buffers pending for completion, false otherwise

## ◆ metadata()

libcamera::Request::metadata | ( |  | ) |
| inline

Retrieve the request's metadata.

Todo:
  Offer a read-only API towards applications while keeping a read/write API internally.

Returns
  The metadata associated with the request

## ◆ reuse()

void libcamera::Request::reuse | ( | ReuseFlag | flags = `Default` | ) |

Reset the request for reuse.

Parameters

  [in] | flags | Indicate whether or not to reuse the buffers

Reset the status and controls associated with the request, to allow it to be reused and requeued without destruction. This function shall be called prior to queueing the request to the camera, in lieu of constructing a new request. The application can reuse the buffers that were previously added to the request via addBuffer() by setting flags to ReuseBuffers.

## ◆ sequence()

uint32_t libcamera::Request::sequence | ( |  | ) | const

Retrieve the sequence number for the request.

When requests are queued, they are given a sequential number to track the order in which requests are queued to a camera. This number counts all requests given to a camera and is reset to zero between camera stop/start sequences.

It can be used to support debugging and identifying the flow of requests through a pipeline, but does not guarantee to represent the sequence number of any images in the stream. The sequence number is stored as an unsigned integer and will wrap when overflowed.

Returns
  The request sequence number

## ◆ status()

libcamera::Request::status | ( |  | ) | const
| inline

Retrieve the request completion status.

The request status indicates whether the request has completed successfully or with an error. When requests are created and before they complete the request status is set to RequestPending, and is updated at completion time to RequestComplete. If a request is cancelled at capture stop before it has completed, its status is set to RequestCancelled.

Returns
  The request completion status

## ◆ toString()

std::string libcamera::Request::toString | ( |  | ) | const

Generate a string representation of the Request internals.

This function facilitates debugging of Request state while it is used internally within libcamera.

Returns
  A string representing the current state of the request

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

- include/libcamera/request.h
- src/libcamera/request.cpp