mirror of
https://git.libcamera.org/libcamera/libcamera.git
synced 2025-07-25 09:35:06 +03:00
Add to the Buffer class methods to set and retrieve a reference to the Request instance the buffer is part of. As buffers outlive the Request they are associated with, the reference is only temporary valid during the buffer completion interval (from when the buffer gets queued to Camera for processing, until it gets marked as completed). Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
95 lines
1.7 KiB
C++
95 lines
1.7 KiB
C++
/* 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>
|
|
|
|
namespace libcamera {
|
|
|
|
class BufferPool;
|
|
class Request;
|
|
|
|
class Plane final
|
|
{
|
|
public:
|
|
Plane();
|
|
~Plane();
|
|
|
|
int dmabuf() const { return fd_; }
|
|
int setDmabuf(int fd, unsigned int length);
|
|
|
|
void *mem();
|
|
unsigned int length() const { return length_; }
|
|
|
|
private:
|
|
int mmap();
|
|
int munmap();
|
|
|
|
int fd_;
|
|
unsigned int length_;
|
|
void *mem_;
|
|
};
|
|
|
|
class Buffer final
|
|
{
|
|
public:
|
|
enum Status {
|
|
BufferSuccess,
|
|
BufferError,
|
|
BufferCancelled,
|
|
};
|
|
|
|
Buffer();
|
|
|
|
unsigned int index() const { return index_; }
|
|
unsigned int bytesused() const { return bytesused_; }
|
|
uint64_t timestamp() const { return timestamp_; }
|
|
unsigned int sequence() const { return sequence_; }
|
|
Status status() const { return status_; }
|
|
std::vector<Plane> &planes() { return planes_; }
|
|
Request *request() const { return request_; }
|
|
|
|
private:
|
|
friend class BufferPool;
|
|
friend class PipelineHandler;
|
|
friend class Request;
|
|
friend class V4L2Device;
|
|
|
|
void cancel();
|
|
|
|
void setRequest(Request *request) { request_ = request; }
|
|
|
|
unsigned int index_;
|
|
unsigned int bytesused_;
|
|
uint64_t timestamp_;
|
|
unsigned int sequence_;
|
|
Status status_;
|
|
|
|
std::vector<Plane> planes_;
|
|
Request *request_;
|
|
};
|
|
|
|
class BufferPool final
|
|
{
|
|
public:
|
|
~BufferPool();
|
|
|
|
void createBuffers(unsigned int count);
|
|
void destroyBuffers();
|
|
|
|
unsigned int count() const { return buffers_.size(); }
|
|
std::vector<Buffer> &buffers() { return buffers_; }
|
|
|
|
private:
|
|
std::vector<Buffer> buffers_;
|
|
};
|
|
|
|
} /* namespace libcamera */
|
|
|
|
#endif /* __LIBCAMERA_BUFFER_H__ */
|