summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/libcamera/pipeline/simple/converter.cpp58
-rw-r--r--src/libcamera/pipeline/simple/converter.h5
-rw-r--r--src/libcamera/pipeline/simple/simple.cpp3
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";