android: camera_stream: Create post processor in configure()

CameraStream creates PostProcessor and FrameBufferAllocator in
the constructor. CameraStream assumes that a used post processor
is JPEG post processor. Since we need to support various post
processors, we would rather move the creation to configure() so
as to return an error code if no proper post processor is found.
This also moves FrameBufferAllocator and Mutex creation for
consistency.

Signed-off-by: Hirokazu Honda <hiroh@chromium.org>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
This commit is contained in:
Hirokazu Honda 2021-09-01 17:03:00 +09:00 committed by Laurent Pinchart
parent 3e335b69b6
commit 76819971b9
2 changed files with 21 additions and 17 deletions

View file

@ -48,6 +48,7 @@ public:
unsigned int id() const { return id_; } unsigned int id() const { return id_; }
camera3_device_t *camera3Device() { return &camera3Device_; } camera3_device_t *camera3Device() { return &camera3Device_; }
const CameraCapabilities *capabilities() const { return &capabilities_; }
const std::shared_ptr<libcamera::Camera> &camera() const { return camera_; } const std::shared_ptr<libcamera::Camera> &camera() const { return camera_; }
const std::string &maker() const { return maker_; } const std::string &maker() const { return maker_; }

View file

@ -10,6 +10,7 @@
#include <sys/mman.h> #include <sys/mman.h>
#include "camera_buffer.h" #include "camera_buffer.h"
#include "camera_capabilities.h"
#include "camera_device.h" #include "camera_device.h"
#include "camera_metadata.h" #include "camera_metadata.h"
#include "jpeg/post_processor_jpeg.h" #include "jpeg/post_processor_jpeg.h"
@ -47,20 +48,6 @@ CameraStream::CameraStream(CameraDevice *const cameraDevice,
: cameraDevice_(cameraDevice), config_(config), type_(type), : cameraDevice_(cameraDevice), config_(config), type_(type),
camera3Stream_(camera3Stream), index_(index) camera3Stream_(camera3Stream), index_(index)
{ {
if (type_ == Type::Internal || type_ == Type::Mapped) {
/*
* \todo There might be multiple post-processors. The logic
* which should be instantiated here, is deferred for the
* future. For now, we only have PostProcessorJpeg and that
* is what we instantiate here.
*/
postProcessor_ = std::make_unique<PostProcessorJpeg>(cameraDevice_);
}
if (type == Type::Internal) {
allocator_ = std::make_unique<FrameBufferAllocator>(cameraDevice_->camera());
mutex_ = std::make_unique<std::mutex>();
}
} }
const StreamConfiguration &CameraStream::configuration() const const StreamConfiguration &CameraStream::configuration() const
@ -75,15 +62,31 @@ Stream *CameraStream::stream() const
int CameraStream::configure() int CameraStream::configure()
{ {
if (postProcessor_) { if (type_ == Type::Internal || type_ == Type::Mapped) {
const PixelFormat outFormat =
cameraDevice_->capabilities()->toPixelFormat(camera3Stream_->format);
StreamConfiguration output = configuration(); StreamConfiguration output = configuration();
output.pixelFormat = formats::MJPEG; output.pixelFormat = outFormat;
switch (outFormat) {
case formats::MJPEG:
postProcessor_ = std::make_unique<PostProcessorJpeg>(cameraDevice_);
break;
default:
LOG(HAL, Error) << "Unsupported format: " << outFormat;
return -EINVAL;
}
int ret = postProcessor_->configure(configuration(), output); int ret = postProcessor_->configure(configuration(), output);
if (ret) if (ret)
return ret; return ret;
} }
if (allocator_) { if (type_ == Type::Internal) {
allocator_ = std::make_unique<FrameBufferAllocator>(cameraDevice_->camera());
mutex_ = std::make_unique<std::mutex>();
int ret = allocator_->allocate(stream()); int ret = allocator_->allocate(stream());
if (ret < 0) if (ret < 0)
return ret; return ret;