summaryrefslogtreecommitdiff
path: root/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp
diff options
context:
space:
mode:
authorNiklas Söderlund <niklas.soderlund@ragnatech.se>2020-09-24 23:16:25 +0200
committerNiklas Söderlund <niklas.soderlund@ragnatech.se>2020-09-30 14:24:42 +0200
commitdf64542035f7aab6f6d8eec801a9fcb9f19bed60 (patch)
treeea06addf17afe1cd6d8ad0bf040b65f8ddf4a599 /src/libcamera/pipeline/rkisp1/rkisp1_path.cpp
parentdf2af09050514c64c4af8cef0581423a705490af (diff)
libcamera: pipeline: rkisp1: Move path configuration generation and validation to RkISP1Path
Move the path configuration generation and validation to RkISP1Path. This is done to increase code reuse and to encapsulate the main and self path differences inside the RkISP1Path class. There is no functional change. Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Diffstat (limited to 'src/libcamera/pipeline/rkisp1/rkisp1_path.cpp')
-rw-r--r--src/libcamera/pipeline/rkisp1/rkisp1_path.cpp94
1 files changed, 90 insertions, 4 deletions
diff --git a/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp b/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp
index 66b5eebd..96c18b35 100644
--- a/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp
+++ b/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp
@@ -7,6 +7,7 @@
#include "rkisp1_path.h"
+#include <libcamera/formats.h>
#include <libcamera/stream.h>
#include "libcamera/internal/media_device.h"
@@ -17,8 +18,11 @@ namespace libcamera {
LOG_DECLARE_CATEGORY(RkISP1)
-RkISP1Path::RkISP1Path(const char *name)
- : video_(nullptr), name_(name), resizer_(nullptr)
+RkISP1Path::RkISP1Path(const char *name, const Span<const PixelFormat> &formats,
+ const Size &minResolution, const Size &maxResolution)
+ : video_(nullptr), name_(name), formats_(formats),
+ minResolution_(minResolution), maxResolution_(maxResolution),
+ resizer_(nullptr)
{
}
@@ -44,6 +48,58 @@ bool RkISP1Path::init(MediaDevice *media)
return true;
}
+StreamConfiguration RkISP1Path::generateConfiguration(const Size &resolution)
+{
+ Size maxResolution = resolution;
+ maxResolution.boundTo(maxResolution_);
+
+ std::map<PixelFormat, std::vector<SizeRange>> streamFormats;
+ for (const PixelFormat &format : formats_)
+ streamFormats[format] = { { minResolution_, maxResolution } };
+
+ StreamFormats formats(streamFormats);
+ StreamConfiguration cfg(formats);
+ cfg.pixelFormat = formats::NV12;
+ cfg.size = maxResolution;
+ cfg.bufferCount = RKISP1_BUFFER_COUNT;
+
+ return cfg;
+}
+
+CameraConfiguration::Status RkISP1Path::validate(StreamConfiguration *cfg)
+{
+ const StreamConfiguration reqCfg = *cfg;
+ CameraConfiguration::Status status = CameraConfiguration::Valid;
+
+ if (std::find(formats_.begin(), formats_.end(), cfg->pixelFormat) ==
+ formats_.end())
+ cfg->pixelFormat = formats::NV12;
+
+ cfg->size.boundTo(maxResolution_);
+ cfg->size.expandTo(minResolution_);
+ cfg->bufferCount = RKISP1_BUFFER_COUNT;
+
+ V4L2DeviceFormat format = {};
+ format.fourcc = video_->toV4L2PixelFormat(cfg->pixelFormat);
+ format.size = cfg->size;
+
+ int ret = video_->tryFormat(&format);
+ if (ret)
+ return CameraConfiguration::Invalid;
+
+ cfg->stride = format.planes[0].bpl;
+ cfg->frameSize = format.planes[0].size;
+
+ if (cfg->pixelFormat != reqCfg.pixelFormat || cfg->size != reqCfg.size) {
+ LOG(RkISP1, Debug)
+ << "Adjusting format from " << reqCfg.toString()
+ << " to " << cfg->toString();
+ status = CameraConfiguration::Adjusted;
+ }
+
+ return status;
+}
+
int RkISP1Path::configure(const StreamConfiguration &config,
const V4L2SubdeviceFormat &inputFormat)
{
@@ -93,13 +149,43 @@ int RkISP1Path::configure(const StreamConfiguration &config,
return 0;
}
+namespace {
+constexpr Size RKISP1_RSZ_MP_SRC_MIN{ 32, 16 };
+constexpr Size RKISP1_RSZ_MP_SRC_MAX{ 4416, 3312 };
+constexpr std::array<PixelFormat, 7> RKISP1_RSZ_MP_FORMATS{
+ formats::YUYV,
+ formats::YVYU,
+ formats::VYUY,
+ formats::NV16,
+ formats::NV61,
+ formats::NV21,
+ formats::NV12,
+ /* \todo Add support for 8-bit greyscale to DRM formats */
+};
+
+constexpr Size RKISP1_RSZ_SP_SRC_MIN{ 32, 16 };
+constexpr Size RKISP1_RSZ_SP_SRC_MAX{ 1920, 1920 };
+constexpr std::array<PixelFormat, 7> RKISP1_RSZ_SP_FORMATS{
+ formats::YUYV,
+ formats::YVYU,
+ formats::VYUY,
+ formats::NV16,
+ formats::NV61,
+ formats::NV21,
+ formats::NV12,
+ /* \todo Add support for BGR888 and RGB565 */
+};
+} /* namespace */
+
RkISP1MainPath::RkISP1MainPath()
- : RkISP1Path("main")
+ : RkISP1Path("main", RKISP1_RSZ_MP_FORMATS,
+ RKISP1_RSZ_MP_SRC_MIN, RKISP1_RSZ_MP_SRC_MAX)
{
}
RkISP1SelfPath::RkISP1SelfPath()
- : RkISP1Path("self")
+ : RkISP1Path("self", RKISP1_RSZ_SP_FORMATS,
+ RKISP1_RSZ_SP_SRC_MIN, RKISP1_RSZ_SP_SRC_MAX)
{
}