android: camera_stream: Create buffer pool
Add a FrameBufferAllocator class member to the CameraStream class. The allocator is constructed for CameraStream instances that needs internal allocation and automatically deleted. Allocate FrameBuffers using the allocator_ class member in the CameraStream class at CameraStream::configure() time and add two methods to the CameraStream class to get and put FrameBuffer pointers from the pool of allocated buffers. As buffer allocation can take place only after the Camera has been configured, move the CameraStream configuration loop in the CameraDevice class after camera_->configure() call. The newly created pool will be used to provide buffers to CameraStream that need to provide memory to libcamera where to deliver frames. Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
This commit is contained in:
parent
6c8837da5e
commit
b84e35dc97
3 changed files with 67 additions and 11 deletions
|
@ -26,6 +26,11 @@ CameraStream::CameraStream(CameraDevice *cameraDevice, Type type,
|
|||
|
||||
if (type_ == Type::Internal || type_ == Type::Mapped)
|
||||
encoder_ = std::make_unique<EncoderLibJpeg>();
|
||||
|
||||
if (type == Type::Internal) {
|
||||
allocator_ = std::make_unique<FrameBufferAllocator>(cameraDevice_->camera());
|
||||
mutex_ = std::make_unique<std::mutex>();
|
||||
}
|
||||
}
|
||||
|
||||
const StreamConfiguration &CameraStream::configuration() const
|
||||
|
@ -46,6 +51,16 @@ int CameraStream::configure()
|
|||
return ret;
|
||||
}
|
||||
|
||||
if (allocator_) {
|
||||
int ret = allocator_->allocate(stream());
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
/* Save a pointer to the reserved frame buffers */
|
||||
for (const auto &frameBuffer : allocator_->buffers(stream()))
|
||||
buffers_.push_back(frameBuffer.get());
|
||||
}
|
||||
|
||||
camera3Stream_->max_buffers = configuration().bufferCount;
|
||||
|
||||
return 0;
|
||||
|
@ -109,3 +124,31 @@ int CameraStream::process(const libcamera::FrameBuffer &source,
|
|||
|
||||
return 0;
|
||||
}
|
||||
|
||||
FrameBuffer *CameraStream::getBuffer()
|
||||
{
|
||||
if (!allocator_)
|
||||
return nullptr;
|
||||
|
||||
std::lock_guard<std::mutex> locker(*mutex_);
|
||||
|
||||
if (buffers_.empty()) {
|
||||
LOG(HAL, Error) << "Buffer underrun";
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
FrameBuffer *buffer = buffers_.back();
|
||||
buffers_.pop_back();
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
void CameraStream::putBuffer(libcamera::FrameBuffer *buffer)
|
||||
{
|
||||
if (!allocator_)
|
||||
return;
|
||||
|
||||
std::lock_guard<std::mutex> locker(*mutex_);
|
||||
|
||||
buffers_.push_back(buffer);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue