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/libcamera/pipeline/simple/converter.cpp | |
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/libcamera/pipeline/simple/converter.cpp')
-rw-r--r-- | src/libcamera/pipeline/simple/converter.cpp | 58 |
1 files changed, 51 insertions, 7 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) { |