android: camera_stream: Use PlatformFrameBufferAllocator
CameraStream originally creates FrameBuffers by FrameBufferAllocator and thus buffers are allocated in V4L2 API. This replaces the allocator in CameraStream with PlatformFrameBufferAllocator. It allocates a buffer in a platform dependent graphic buffer allocation API. Signed-off-by: Hirokazu Honda <hiroh@chromium.org> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
This commit is contained in:
parent
c58662c577
commit
b53f6efb99
2 changed files with 28 additions and 15 deletions
|
@ -22,6 +22,7 @@
|
|||
#include "camera_capabilities.h"
|
||||
#include "camera_device.h"
|
||||
#include "camera_metadata.h"
|
||||
#include "frame_buffer_allocator.h"
|
||||
#include "post_processor.h"
|
||||
|
||||
using namespace libcamera;
|
||||
|
@ -59,7 +60,15 @@ CameraStream::CameraStream(CameraDevice *const cameraDevice,
|
|||
|
||||
CameraStream::CameraStream(CameraStream &&other) = default;
|
||||
|
||||
CameraStream::~CameraStream() = default;
|
||||
CameraStream::~CameraStream()
|
||||
{
|
||||
/*
|
||||
* Manually delete buffers and then the allocator to make sure buffers
|
||||
* are released while the allocator is still valid.
|
||||
*/
|
||||
allocatedBuffers_.clear();
|
||||
allocator_.reset();
|
||||
}
|
||||
|
||||
const StreamConfiguration &CameraStream::configuration() const
|
||||
{
|
||||
|
@ -118,17 +127,8 @@ int CameraStream::configure()
|
|||
}
|
||||
|
||||
if (type_ == Type::Internal) {
|
||||
allocator_ = std::make_unique<FrameBufferAllocator>(cameraDevice_->camera());
|
||||
allocator_ = std::make_unique<PlatformFrameBufferAllocator>(cameraDevice_);
|
||||
mutex_ = std::make_unique<Mutex>();
|
||||
|
||||
int ret = allocator_->allocate(stream());
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
MutexLocker lock(*mutex_);
|
||||
/* 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;
|
||||
|
@ -212,8 +212,20 @@ FrameBuffer *CameraStream::getBuffer()
|
|||
MutexLocker locker(*mutex_);
|
||||
|
||||
if (buffers_.empty()) {
|
||||
LOG(HAL, Error) << "Buffer underrun";
|
||||
return nullptr;
|
||||
/*
|
||||
* Use HAL_PIXEL_FORMAT_YCBCR_420_888 unconditionally.
|
||||
*
|
||||
* YCBCR_420 is the source format for both the JPEG and the YUV
|
||||
* post-processors.
|
||||
*
|
||||
* \todo Store a reference to the format of the source stream
|
||||
* instead of hardcoding.
|
||||
*/
|
||||
auto frameBuffer = allocator_->allocate(HAL_PIXEL_FORMAT_YCBCR_420_888,
|
||||
configuration().size,
|
||||
camera3Stream_->usage);
|
||||
allocatedBuffers_.push_back(std::move(frameBuffer));
|
||||
buffers_.emplace_back(allocatedBuffers_.back().get());
|
||||
}
|
||||
|
||||
FrameBuffer *buffer = buffers_.back();
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
|
||||
#include <libcamera/camera.h>
|
||||
#include <libcamera/framebuffer.h>
|
||||
#include <libcamera/framebuffer_allocator.h>
|
||||
#include <libcamera/geometry.h>
|
||||
#include <libcamera/pixel_format.h>
|
||||
|
||||
|
@ -26,6 +25,7 @@
|
|||
#include "post_processor.h"
|
||||
|
||||
class CameraDevice;
|
||||
class PlatformFrameBufferAllocator;
|
||||
|
||||
class CameraStream
|
||||
{
|
||||
|
@ -169,7 +169,8 @@ private:
|
|||
camera3_stream_t *camera3Stream_;
|
||||
const unsigned int index_;
|
||||
|
||||
std::unique_ptr<libcamera::FrameBufferAllocator> allocator_;
|
||||
std::unique_ptr<PlatformFrameBufferAllocator> allocator_;
|
||||
std::vector<std::unique_ptr<libcamera::FrameBuffer>> allocatedBuffers_;
|
||||
std::vector<libcamera::FrameBuffer *> buffers_ LIBCAMERA_TSA_GUARDED_BY(mutex_);
|
||||
/*
|
||||
* The class has to be MoveConstructible as instances are stored in
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue