[libcamera-devel,v2,3/8] libcamera: frame_buffer_allocator: Add clear()

Message ID 20200918135041.91492-4-jacopo@jmondi.org
State Superseded
Headers show
Series
  • android: camera_device: Add support for internal buffers
Related show

Commit Message

Jacopo Mondi Sept. 18, 2020, 1:50 p.m. UTC
Add a clear() method to the FrameBufferAllocator class that
frees all the buffers previously reserved by the allocator.

Reviewed-by: Hirokazu Honda <hiroh@chromium.org>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
---
 include/libcamera/framebuffer_allocator.h | 1 +
 src/libcamera/framebuffer_allocator.cpp   | 8 ++++++++
 2 files changed, 9 insertions(+)

Patch

diff --git a/include/libcamera/framebuffer_allocator.h b/include/libcamera/framebuffer_allocator.h
index 78f1353964eb..2a4d538a0cb2 100644
--- a/include/libcamera/framebuffer_allocator.h
+++ b/include/libcamera/framebuffer_allocator.h
@@ -28,6 +28,7 @@  public:
 
 	int allocate(Stream *stream);
 	int free(Stream *stream);
+	void clear();
 
 	bool allocated() const { return !buffers_.empty(); }
 	const std::vector<std::unique_ptr<FrameBuffer>> &buffers(Stream *stream) const;
diff --git a/src/libcamera/framebuffer_allocator.cpp b/src/libcamera/framebuffer_allocator.cpp
index 2fbba37a1b0b..7ed80011c845 100644
--- a/src/libcamera/framebuffer_allocator.cpp
+++ b/src/libcamera/framebuffer_allocator.cpp
@@ -125,6 +125,14 @@  int FrameBufferAllocator::free(Stream *stream)
 	return 0;
 }
 
+/**
+ * \brief Free all the buffers previously allocated
+ */
+void FrameBufferAllocator::clear()
+{
+	buffers_.clear();
+}
+
 /**
  * \fn FrameBufferAllocator::allocated()
  * \brief Check if the allocator has allocated buffers for any stream