diff options
author | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2020-05-19 19:48:02 +0300 |
---|---|---|
committer | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2020-05-22 04:54:03 +0300 |
commit | fd76304e005903d6fe7ad28fa537f356b1048454 (patch) | |
tree | 831a4a133d1dc5015babc927547ac20a544a2675 /src | |
parent | 5331051c35fe5412901435d81b4153d307c04a49 (diff) |
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>
Diffstat (limited to 'src')
-rw-r--r-- | src/libcamera/pipeline/simple/converter.cpp | 58 | ||||
-rw-r--r-- | src/libcamera/pipeline/simple/converter.h | 5 | ||||
-rw-r--r-- | src/libcamera/pipeline/simple/simple.cpp | 3 |
3 files changed, 57 insertions, 9 deletions
diff --git a/src/libcamera/pipeline/simple/converter.cpp b/src/libcamera/pipeline/simple/converter.cpp index 7a9d67b3..e5e2f0fd 100644 --- a/src/libcamera/pipeline/simple/converter.cpp +++ b/src/libcamera/pipeline/simple/converter.cpp @@ -8,6 +8,7 @@ #include "converter.h" #include <algorithm> +#include <limits.h> #include <libcamera/buffer.h> #include <libcamera/geometry.h> @@ -93,7 +94,52 @@ std::vector<PixelFormat> SimpleConverter::formats(PixelFormat input) 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) { V4L2DeviceFormat format; @@ -101,7 +147,7 @@ int SimpleConverter::configure(PixelFormat inputFormat, V4L2PixelFormat videoFormat = m2m_->output()->toV4L2PixelFormat(inputFormat); format.fourcc = videoFormat; - format.size = cfg->size; + format.size = inputSize; ret = m2m_->output()->setFormat(&format); if (ret < 0) { @@ -110,18 +156,16 @@ int SimpleConverter::configure(PixelFormat inputFormat, return ret; } - if (format.fourcc != videoFormat || format.size != cfg->size) { + if (format.fourcc != videoFormat || format.size != inputSize) { LOG(SimplePipeline, Error) << "Input format not supported"; return -EINVAL; } - /* - * Set the pixel format on the output, the size is identical to the - * input as we don't support scaling. - */ + /* Set the pixel format and size on the output. */ videoFormat = m2m_->capture()->toV4L2PixelFormat(cfg->pixelFormat); format.fourcc = videoFormat; + format.size = cfg->size; ret = m2m_->capture()->setFormat(&format); if (ret < 0) { diff --git a/src/libcamera/pipeline/simple/converter.h b/src/libcamera/pipeline/simple/converter.h index 0beb96a5..1f770eb8 100644 --- a/src/libcamera/pipeline/simple/converter.h +++ b/src/libcamera/pipeline/simple/converter.h @@ -20,6 +20,7 @@ namespace libcamera { class FrameBuffer; class MediaDevice; struct Size; +class SizeRange; struct StreamConfiguration; class V4L2M2MDevice; @@ -33,8 +34,10 @@ public: void close(); 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, std::vector<std::unique_ptr<FrameBuffer>> *buffers); diff --git a/src/libcamera/pipeline/simple/simple.cpp b/src/libcamera/pipeline/simple/simple.cpp index 68595bc2..686639c3 100644 --- a/src/libcamera/pipeline/simple/simple.cpp +++ b/src/libcamera/pipeline/simple/simple.cpp @@ -555,7 +555,8 @@ int SimplePipelineHandler::configure(Camera *camera, CameraConfiguration *c) useConverter_ = config->needConversion(); if (useConverter_) { - int ret = converter_->configure(pipeConfig.pixelFormat, &cfg); + int ret = converter_->configure(pipeConfig.pixelFormat, + cfg.size, &cfg); if (ret < 0) { LOG(SimplePipeline, Error) << "Unable to configure converter"; |