buffer.h
Go to the documentation of this file.
/* SPDX-License-Identifier: LGPL-2.1-or-later */
/*
* Copyright (C) 2019, Google Inc.
*
* buffer.h - Buffer handling
*/
#ifndef __LIBCAMERA_BUFFER_H__
#define __LIBCAMERA_BUFFER_H__
#include <stdint.h>
#include <vector>
#include <libcamera/file_descriptor.h>
namespace libcamera {
class Request;
struct FrameMetadata {
enum Status {
FrameSuccess,
FrameError,
FrameCancelled,
};
struct Plane {
unsigned int bytesused;
};
Status status;
unsigned int sequence;
uint64_t timestamp;
std::vector<Plane> planes;
};
class FrameBuffer final
{
public:
struct Plane {
FileDescriptor fd;
unsigned int length;
};
FrameBuffer(const std::vector<Plane> &planes, unsigned int cookie = 0);
FrameBuffer(const FrameBuffer &) = delete;
FrameBuffer(FrameBuffer &&) = delete;
FrameBuffer &operator=(const FrameBuffer &) = delete;
FrameBuffer &operator=(FrameBuffer &&) = delete;
const std::vector<Plane> &planes() const { return planes_; }
Request *request() const { return request_; }
void setRequest(Request *request) { request_ = request; }
const FrameMetadata &metadata() const { return metadata_; }
unsigned int cookie() const { return cookie_; }
void setCookie(unsigned int cookie) { cookie_ = cookie; }
int copyFrom(const FrameBuffer *src);
private:
friend class Request; /* Needed to update request_. */
friend class V4L2VideoDevice; /* Needed to update metadata_. */
std::vector<Plane> planes_;
Request *request_;
FrameMetadata metadata_;
unsigned int cookie_;
};
} /* namespace libcamera */
#endif /* __LIBCAMERA_BUFFER_H__ */
libcamera::FileDescriptor
RAII-style wrapper for file descriptors.
Definition: file_descriptor.h:15
libcamera::FrameBuffer
Frame buffer data and its associated dynamic metadata.
Definition: buffer.h:37
libcamera::FrameBuffer::planes
const std::vector< Plane > & planes() const
Retrieve the static plane descriptors.
Definition: buffer.h:52
libcamera::FrameBuffer::copyFrom
int copyFrom(const FrameBuffer *src)
Copy the contents from another buffer.
Definition: buffer.cpp:244
libcamera::FrameBuffer::setRequest
void setRequest(Request *request)
Set the request this buffer belongs to.
Definition: buffer.h:55
libcamera::FrameBuffer::cookie
unsigned int cookie() const
Retrieve the cookie.
Definition: buffer.h:58
libcamera::FrameBuffer::request
Request * request() const
Retrieve the request this buffer belongs to.
Definition: buffer.h:54
libcamera::FrameBuffer::FrameBuffer
FrameBuffer(const std::vector< Plane > &planes, unsigned int cookie=0)
Construct a FrameBuffer with an array of planes.
Definition: buffer.cpp:159
libcamera::FrameBuffer::setCookie
void setCookie(unsigned int cookie)
Set the cookie.
Definition: buffer.h:59
libcamera::FrameBuffer::metadata
const FrameMetadata & metadata() const
Retrieve the dynamic metadata.
Definition: buffer.h:56
libcamera::Request
A frame capture request.
Definition: request.h:26
libcamera::V4L2VideoDevice
V4L2VideoDevice object and API.
Definition: v4l2_videodevice.h:169
file_descriptor.h
File descriptor wrapper.
libcamera::FrameBuffer::Plane
A memory region to store a single plane of a frame.
Definition: buffer.h:39
libcamera::FrameBuffer::Plane::length
unsigned int length
The plane length in bytes.
Definition: buffer.h:41
libcamera::FrameBuffer::Plane::fd
FileDescriptor fd
The dmabuf file descriptor.
Definition: buffer.h:40
libcamera::FrameMetadata::Plane
Per-plane frame metadata.
Definition: buffer.h:26
libcamera::FrameMetadata::Plane::bytesused
unsigned int bytesused
Number of bytes occupied by the data in the plane, including line padding.
Definition: buffer.h:27
libcamera::FrameMetadata
Metadata related to a captured frame.
Definition: buffer.h:19
libcamera::FrameMetadata::timestamp
uint64_t timestamp
Time when the frame was captured.
Definition: buffer.h:32
libcamera::FrameMetadata::Status
Status
Define the frame completion status.
Definition: buffer.h:20
libcamera::FrameMetadata::FrameCancelled
@ FrameCancelled
Definition: buffer.h:23
libcamera::FrameMetadata::FrameError
@ FrameError
Definition: buffer.h:22
libcamera::FrameMetadata::FrameSuccess
@ FrameSuccess
Definition: buffer.h:21
libcamera::FrameMetadata::sequence
unsigned int sequence
Frame sequence number.
Definition: buffer.h:31
libcamera::FrameMetadata::planes
std::vector< Plane > planes
Array of per-plane metadata.
Definition: buffer.h:33
libcamera::FrameMetadata::status
Status status
Status of the frame.
Definition: buffer.h:30