mirror of
https://git.libcamera.org/libcamera/libcamera.git
synced 2025-07-13 15:29:45 +03:00
The FrameBuffer interface is based on the idea that all buffers are allocated externally to libcamera and are only used by it. This is meant to create a simpler API centered around usage of buffers, regardless of where they come from. Linux however lacks a centralized allocator at the moment, and not all users of libcamera are expected to use another device that could provide suitable buffers for the camera. This patch thus adds a helper class to allocate buffers internally in libcamera, in a way that matches the needs of the FrameBuffer-based API. Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
45 lines
1 KiB
C++
45 lines
1 KiB
C++
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
|
/*
|
|
* Copyright (C) 2019, Google Inc.
|
|
*
|
|
* framebuffer_allocator.h - FrameBuffer allocator
|
|
*/
|
|
#ifndef __LIBCAMERA_FRAMEBUFFER_ALLOCATOR_H__
|
|
#define __LIBCAMERA_FRAMEBUFFER_ALLOCATOR_H__
|
|
|
|
#include <map>
|
|
#include <memory>
|
|
#include <vector>
|
|
|
|
namespace libcamera {
|
|
|
|
class Camera;
|
|
class FrameBuffer;
|
|
class Stream;
|
|
|
|
class FrameBufferAllocator
|
|
{
|
|
public:
|
|
static FrameBufferAllocator *create(std::shared_ptr<Camera> camera);
|
|
|
|
FrameBufferAllocator(const Camera &) = delete;
|
|
FrameBufferAllocator &operator=(const Camera &) = delete;
|
|
|
|
~FrameBufferAllocator();
|
|
|
|
int allocate(Stream *stream);
|
|
int free(Stream *stream);
|
|
|
|
bool allocated() const { return !buffers_.empty(); }
|
|
const std::vector<std::unique_ptr<FrameBuffer>> &buffers(Stream *stream) const;
|
|
|
|
private:
|
|
FrameBufferAllocator(std::shared_ptr<Camera> camera);
|
|
|
|
std::shared_ptr<Camera> camera_;
|
|
std::map<Stream *, std::vector<std::unique_ptr<FrameBuffer>>> buffers_;
|
|
};
|
|
|
|
} /* namespace libcamera */
|
|
|
|
#endif /* __LIBCAMERA_FRAMEBUFFER_ALLOCATOR_H__ */
|