mirror of
https://git.libcamera.org/libcamera/libcamera.git
synced 2025-07-26 01:55:51 +03:00
libcamera: buffer: Split memory information to BufferMemory
The Buffer class is a large beast the stores information about the buffer memory, dynamic metadata related to the frame stored in the buffer, and buffer reference data (in the index). In order to implement buffer import we will need to extend this with dmabuf file descriptors, making usage of the class even more complex. Refactor the Buffer class by splitting the buffer memory information to a BufferMemory class, and repurposing the Buffer class to reference a buffer and to store dynamic metadata. The BufferMemory class becomes a long term storage, valid and stable from the time buffer memory is allocated to the time it is freed. The Buffer class, on the other hand, becomes transient, is created on demand when an application requires a buffer, is given to a request, and is deleted when the request completes. Buffer and BufferMemory don't need to be copied, so their copy constructor and assignment operators are deleted. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
This commit is contained in:
parent
9bb36ec274
commit
a2bcf6feee
15 changed files with 311 additions and 158 deletions
|
@ -14,6 +14,7 @@ namespace libcamera {
|
|||
|
||||
class BufferPool;
|
||||
class Request;
|
||||
class Stream;
|
||||
|
||||
class Plane final
|
||||
{
|
||||
|
@ -36,43 +37,13 @@ private:
|
|||
void *mem_;
|
||||
};
|
||||
|
||||
class Buffer final
|
||||
class BufferMemory 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 V4L2VideoDevice;
|
||||
|
||||
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
|
||||
|
@ -84,10 +55,54 @@ public:
|
|||
void destroyBuffers();
|
||||
|
||||
unsigned int count() const { return buffers_.size(); }
|
||||
std::vector<Buffer> &buffers() { return buffers_; }
|
||||
std::vector<BufferMemory> &buffers() { return buffers_; }
|
||||
|
||||
private:
|
||||
std::vector<Buffer> buffers_;
|
||||
std::vector<BufferMemory> buffers_;
|
||||
};
|
||||
|
||||
class Buffer final
|
||||
{
|
||||
public:
|
||||
enum Status {
|
||||
BufferSuccess,
|
||||
BufferError,
|
||||
BufferCancelled,
|
||||
};
|
||||
|
||||
Buffer(unsigned int index = -1, const Buffer *metadata = nullptr);
|
||||
Buffer(const Buffer &) = delete;
|
||||
Buffer &operator=(const Buffer &) = delete;
|
||||
|
||||
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_; }
|
||||
Request *request() const { return request_; }
|
||||
Stream *stream() const { return stream_; }
|
||||
|
||||
private:
|
||||
friend class PipelineHandler;
|
||||
friend class Request;
|
||||
friend class Stream;
|
||||
friend class V4L2VideoDevice;
|
||||
|
||||
void cancel();
|
||||
|
||||
void setRequest(Request *request) { request_ = request; }
|
||||
|
||||
unsigned int index_;
|
||||
|
||||
unsigned int bytesused_;
|
||||
uint64_t timestamp_;
|
||||
unsigned int sequence_;
|
||||
|
||||
Status status_;
|
||||
Request *request_;
|
||||
Stream *stream_;
|
||||
};
|
||||
|
||||
} /* namespace libcamera */
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#define __LIBCAMERA_REQUEST_H__
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <stdint.h>
|
||||
#include <unordered_set>
|
||||
|
||||
|
@ -33,10 +34,11 @@ public:
|
|||
Request(Camera *camera, uint64_t cookie = 0);
|
||||
Request(const Request &) = delete;
|
||||
Request &operator=(const Request &) = delete;
|
||||
~Request();
|
||||
|
||||
ControlList &controls() { return controls_; }
|
||||
const std::map<Stream *, Buffer *> &buffers() const { return bufferMap_; }
|
||||
int setBuffers(const std::map<Stream *, Buffer *> &streamMap);
|
||||
int addBuffer(std::unique_ptr<Buffer> buffer);
|
||||
Buffer *findBuffer(Stream *stream) const;
|
||||
|
||||
uint64_t cookie() const { return cookie_; }
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#define __LIBCAMERA_STREAM_H__
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
|
@ -66,6 +67,9 @@ class Stream
|
|||
{
|
||||
public:
|
||||
Stream();
|
||||
|
||||
std::unique_ptr<Buffer> createBuffer(unsigned int index);
|
||||
|
||||
BufferPool &bufferPool() { return bufferPool_; }
|
||||
const StreamConfiguration &configuration() const { return configuration_; }
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue