From 14995410fe8546350d35108398e8b853c9ced002 Mon Sep 17 00:00:00 2001 From: Jacopo Mondi Date: Sun, 29 Jan 2023 11:21:57 +0100 Subject: libcamera: imx8-isi: Automatically select media bus code The ISICameraConfiguration::validate() function selects which media bus format to configure the sensor with based on the pixel format of the first configured stream using the media bus code associated to it in the formatsMap_ map. In order to remove the PixelFormamt-to-mbus-code association in formatsMap_ provide a wrapper function for the newly introduced getRawMediaBusFormat() and getYuvMediaBusFormat() that automatically selects what media bus format to use based on the first stream pixel format. Signed-off-by: Jacopo Mondi Reviewed-by: Paul Elder Reviewed-by: Daniel Scally Tested-by: Daniel Scally Reviewed-by: Laurent Pinchart --- src/libcamera/pipeline/imx8-isi/imx8-isi.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/libcamera/pipeline/imx8-isi/imx8-isi.cpp b/src/libcamera/pipeline/imx8-isi/imx8-isi.cpp index 148f108d..ee3dc4ad 100644 --- a/src/libcamera/pipeline/imx8-isi/imx8-isi.cpp +++ b/src/libcamera/pipeline/imx8-isi/imx8-isi.cpp @@ -61,6 +61,7 @@ public: unsigned int getRawMediaBusFormat(PixelFormat *pixelFormat) const; unsigned int getYuvMediaBusFormat(const PixelFormat &pixelFormat) const; + unsigned int getMediaBusFormat(PixelFormat *pixelFormat) const; std::unique_ptr sensor_; std::unique_ptr csis_; @@ -318,6 +319,15 @@ unsigned int ISICameraData::getYuvMediaBusFormat(const PixelFormat &pixelFormat) return supportedCodes[0]; } +unsigned int ISICameraData::getMediaBusFormat(PixelFormat *pixelFormat) const +{ + if (PixelFormatInfo::info(*pixelFormat).colourEncoding == + PixelFormatInfo::ColourEncodingRAW) + return getRawMediaBusFormat(pixelFormat); + + return getYuvMediaBusFormat(*pixelFormat); +} + /* ----------------------------------------------------------------------------- * Camera Configuration */ @@ -631,16 +641,16 @@ CameraConfiguration::Status ISICameraConfiguration::validate() * image quality in exchange of a usually slower frame rate. * Usage of the STILL_CAPTURE role could be consider for this. */ - const PipeFormat &pipeFmt = formatsMap_.at(config_[0].pixelFormat); - Size maxSize; for (const auto &cfg : config_) { if (cfg.size > maxSize) maxSize = cfg.size; } + PixelFormat pixelFormat = config_[0].pixelFormat; + V4L2SubdeviceFormat sensorFormat{}; - sensorFormat.mbus_code = pipeFmt.sensorCode; + sensorFormat.mbus_code = data_->getMediaBusFormat(&pixelFormat); sensorFormat.size = maxSize; LOG(ISI, Debug) << "Computed sensor configuration: " << sensorFormat; -- cgit v1.2.1