libcamera: pipeline: simple: converter: Add scaling support
Extend the SimpleConverter to support scaling, with reporting of the minimum and maximum output sizes supported for a given input size. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
This commit is contained in:
parent
5331051c35
commit
fd76304e00
3 changed files with 57 additions and 9 deletions
|
@ -8,6 +8,7 @@
|
||||||
#include "converter.h"
|
#include "converter.h"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <limits.h>
|
||||||
|
|
||||||
#include <libcamera/buffer.h>
|
#include <libcamera/buffer.h>
|
||||||
#include <libcamera/geometry.h>
|
#include <libcamera/geometry.h>
|
||||||
|
@ -93,7 +94,52 @@ std::vector<PixelFormat> SimpleConverter::formats(PixelFormat input)
|
||||||
return pixelFormats;
|
return pixelFormats;
|
||||||
}
|
}
|
||||||
|
|
||||||
int SimpleConverter::configure(PixelFormat inputFormat,
|
SizeRange SimpleConverter::sizes(const Size &input)
|
||||||
|
{
|
||||||
|
if (!m2m_)
|
||||||
|
return {};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Set the size on the input side (V4L2 output) of the converter to
|
||||||
|
* enumerate the scaling capabilities on its output (V4L2 capture).
|
||||||
|
*/
|
||||||
|
V4L2DeviceFormat format;
|
||||||
|
format.fourcc = V4L2PixelFormat();
|
||||||
|
format.size = input;
|
||||||
|
|
||||||
|
int ret = m2m_->output()->setFormat(&format);
|
||||||
|
if (ret < 0) {
|
||||||
|
LOG(SimplePipeline, Error)
|
||||||
|
<< "Failed to set format: " << strerror(-ret);
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
SizeRange sizes;
|
||||||
|
|
||||||
|
format.size = { 1, 1 };
|
||||||
|
ret = m2m_->capture()->setFormat(&format);
|
||||||
|
if (ret < 0) {
|
||||||
|
LOG(SimplePipeline, Error)
|
||||||
|
<< "Failed to set format: " << strerror(-ret);
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
sizes.min = format.size;
|
||||||
|
|
||||||
|
format.size = { UINT_MAX, UINT_MAX };
|
||||||
|
ret = m2m_->capture()->setFormat(&format);
|
||||||
|
if (ret < 0) {
|
||||||
|
LOG(SimplePipeline, Error)
|
||||||
|
<< "Failed to set format: " << strerror(-ret);
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
sizes.max = format.size;
|
||||||
|
|
||||||
|
return sizes;
|
||||||
|
}
|
||||||
|
|
||||||
|
int SimpleConverter::configure(PixelFormat inputFormat, const Size &inputSize,
|
||||||
StreamConfiguration *cfg)
|
StreamConfiguration *cfg)
|
||||||
{
|
{
|
||||||
V4L2DeviceFormat format;
|
V4L2DeviceFormat format;
|
||||||
|
@ -101,7 +147,7 @@ int SimpleConverter::configure(PixelFormat inputFormat,
|
||||||
|
|
||||||
V4L2PixelFormat videoFormat = m2m_->output()->toV4L2PixelFormat(inputFormat);
|
V4L2PixelFormat videoFormat = m2m_->output()->toV4L2PixelFormat(inputFormat);
|
||||||
format.fourcc = videoFormat;
|
format.fourcc = videoFormat;
|
||||||
format.size = cfg->size;
|
format.size = inputSize;
|
||||||
|
|
||||||
ret = m2m_->output()->setFormat(&format);
|
ret = m2m_->output()->setFormat(&format);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
|
@ -110,18 +156,16 @@ int SimpleConverter::configure(PixelFormat inputFormat,
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (format.fourcc != videoFormat || format.size != cfg->size) {
|
if (format.fourcc != videoFormat || format.size != inputSize) {
|
||||||
LOG(SimplePipeline, Error)
|
LOG(SimplePipeline, Error)
|
||||||
<< "Input format not supported";
|
<< "Input format not supported";
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/* Set the pixel format and size on the output. */
|
||||||
* Set the pixel format on the output, the size is identical to the
|
|
||||||
* input as we don't support scaling.
|
|
||||||
*/
|
|
||||||
videoFormat = m2m_->capture()->toV4L2PixelFormat(cfg->pixelFormat);
|
videoFormat = m2m_->capture()->toV4L2PixelFormat(cfg->pixelFormat);
|
||||||
format.fourcc = videoFormat;
|
format.fourcc = videoFormat;
|
||||||
|
format.size = cfg->size;
|
||||||
|
|
||||||
ret = m2m_->capture()->setFormat(&format);
|
ret = m2m_->capture()->setFormat(&format);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
|
|
|
@ -20,6 +20,7 @@ namespace libcamera {
|
||||||
class FrameBuffer;
|
class FrameBuffer;
|
||||||
class MediaDevice;
|
class MediaDevice;
|
||||||
struct Size;
|
struct Size;
|
||||||
|
class SizeRange;
|
||||||
struct StreamConfiguration;
|
struct StreamConfiguration;
|
||||||
class V4L2M2MDevice;
|
class V4L2M2MDevice;
|
||||||
|
|
||||||
|
@ -33,8 +34,10 @@ public:
|
||||||
void close();
|
void close();
|
||||||
|
|
||||||
std::vector<PixelFormat> formats(PixelFormat input);
|
std::vector<PixelFormat> formats(PixelFormat input);
|
||||||
|
SizeRange sizes(const Size &input);
|
||||||
|
|
||||||
int configure(PixelFormat inputFormat, StreamConfiguration *cfg);
|
int configure(PixelFormat inputFormat, const Size &inputSize,
|
||||||
|
StreamConfiguration *cfg);
|
||||||
int exportBuffers(unsigned int count,
|
int exportBuffers(unsigned int count,
|
||||||
std::vector<std::unique_ptr<FrameBuffer>> *buffers);
|
std::vector<std::unique_ptr<FrameBuffer>> *buffers);
|
||||||
|
|
||||||
|
|
|
@ -555,7 +555,8 @@ int SimplePipelineHandler::configure(Camera *camera, CameraConfiguration *c)
|
||||||
useConverter_ = config->needConversion();
|
useConverter_ = config->needConversion();
|
||||||
|
|
||||||
if (useConverter_) {
|
if (useConverter_) {
|
||||||
int ret = converter_->configure(pipeConfig.pixelFormat, &cfg);
|
int ret = converter_->configure(pipeConfig.pixelFormat,
|
||||||
|
cfg.size, &cfg);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
LOG(SimplePipeline, Error)
|
LOG(SimplePipeline, Error)
|
||||||
<< "Unable to configure converter";
|
<< "Unable to configure converter";
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue