From eb4030f6c07174a520be1ebd73628e9ae4789569 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niklas=20S=C3=B6derlund?= Date: Sun, 27 Oct 2019 22:10:25 +0100 Subject: libcamera: allocator: Add FrameBufferAllocator to help applications allocate buffers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Laurent Pinchart --- include/libcamera/camera.h | 5 ++++ include/libcamera/framebuffer_allocator.h | 45 +++++++++++++++++++++++++++++++ include/libcamera/meson.build | 1 + 3 files changed, 51 insertions(+) create mode 100644 include/libcamera/framebuffer_allocator.h (limited to 'include') diff --git a/include/libcamera/camera.h b/include/libcamera/camera.h index ef6a37bb..2fd5870b 100644 --- a/include/libcamera/camera.h +++ b/include/libcamera/camera.h @@ -20,6 +20,7 @@ namespace libcamera { class Buffer; +class FrameBufferAllocator; class PipelineHandler; class Request; @@ -126,6 +127,10 @@ private: bool disconnected_; State state_; + + /* Needed to update allocator_ and to read state_ and activeStreams_. */ + friend class FrameBufferAllocator; + FrameBufferAllocator *allocator_; }; } /* namespace libcamera */ diff --git a/include/libcamera/framebuffer_allocator.h b/include/libcamera/framebuffer_allocator.h new file mode 100644 index 00000000..42812253 --- /dev/null +++ b/include/libcamera/framebuffer_allocator.h @@ -0,0 +1,45 @@ +/* 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 +#include +#include + +namespace libcamera { + +class Camera; +class FrameBuffer; +class Stream; + +class FrameBufferAllocator +{ +public: + static FrameBufferAllocator *create(std::shared_ptr 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> &buffers(Stream *stream) const; + +private: + FrameBufferAllocator(std::shared_ptr camera); + + std::shared_ptr camera_; + std::map>> buffers_; +}; + +} /* namespace libcamera */ + +#endif /* __LIBCAMERA_FRAMEBUFFER_ALLOCATOR_H__ */ diff --git a/include/libcamera/meson.build b/include/libcamera/meson.build index 543e6773..8db217bb 100644 --- a/include/libcamera/meson.build +++ b/include/libcamera/meson.build @@ -7,6 +7,7 @@ libcamera_api = files([ 'event_dispatcher.h', 'event_notifier.h', 'file_descriptor.h', + 'framebuffer_allocator.h', 'geometry.h', 'logging.h', 'object.h', -- cgit v1.2.1