libcamera: Remove transform from V4L2SubdeviceFormat

Commit 6f6e1bf704 ("libcamera: camera_sensor: Apply flips at
setFormat()") extended the CameraSensor::setFormat() function
to apply vertical/horizontal flips on the sensor based on the
supplied Transform. To pass the Transform to the function the
V4L2SubdeviceFormat structure has been augmented with a Transform
member.

However as the newly added Transform is not used at all in the
V4L2Subdevice class, it should not be part of V4L2SubdeviceFormat.

Fix that by removing the transform field from V4L2SubdeviceFormat
and pass it as an explicit parameter to CameraSensor::setFormat().

Fixes: 6f6e1bf704 ("libcamera: camera_sensor: Apply flips at setFormat())
Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
This commit is contained in:
Jacopo Mondi 2023-02-06 19:21:32 +01:00
parent 3aa42f36c0
commit 85befa816e
7 changed files with 19 additions and 28 deletions

View file

@ -17,6 +17,7 @@
#include <libcamera/control_ids.h> #include <libcamera/control_ids.h>
#include <libcamera/controls.h> #include <libcamera/controls.h>
#include <libcamera/geometry.h> #include <libcamera/geometry.h>
#include <libcamera/transform.h>
#include <libcamera/ipa/core_ipa_interface.h> #include <libcamera/ipa/core_ipa_interface.h>
@ -29,8 +30,6 @@ class BayerFormat;
class CameraLens; class CameraLens;
class MediaEntity; class MediaEntity;
enum class Transform;
struct CameraSensorProperties; struct CameraSensorProperties;
class CameraSensor : protected Loggable class CameraSensor : protected Loggable
@ -55,7 +54,8 @@ public:
V4L2SubdeviceFormat getFormat(const std::vector<unsigned int> &mbusCodes, V4L2SubdeviceFormat getFormat(const std::vector<unsigned int> &mbusCodes,
const Size &size) const; const Size &size) const;
int setFormat(V4L2SubdeviceFormat *format); int setFormat(V4L2SubdeviceFormat *format,
Transform transform = Transform::Identity);
const ControlInfoMap &controls() const; const ControlInfoMap &controls() const;
ControlList getControls(const std::vector<uint32_t> &ids); ControlList getControls(const std::vector<uint32_t> &ids);

View file

@ -20,7 +20,6 @@
#include <libcamera/color_space.h> #include <libcamera/color_space.h>
#include <libcamera/geometry.h> #include <libcamera/geometry.h>
#include <libcamera/transform.h>
#include "libcamera/internal/formats.h" #include "libcamera/internal/formats.h"
#include "libcamera/internal/media_object.h" #include "libcamera/internal/media_object.h"
@ -45,7 +44,6 @@ struct V4L2SubdeviceFormat {
uint32_t mbus_code; uint32_t mbus_code;
Size size; Size size;
std::optional<ColorSpace> colorSpace; std::optional<ColorSpace> colorSpace;
Transform transform = Transform::Identity;
const std::string toString() const; const std::string toString() const;
uint8_t bitsPerPixel() const; uint8_t bitsPerPixel() const;

View file

@ -16,7 +16,6 @@
#include <string.h> #include <string.h>
#include <libcamera/property_ids.h> #include <libcamera/property_ids.h>
#include <libcamera/transform.h>
#include <libcamera/base/utils.h> #include <libcamera/base/utils.h>
@ -751,7 +750,6 @@ V4L2SubdeviceFormat CameraSensor::getFormat(const std::vector<unsigned int> &mbu
.mbus_code = bestCode, .mbus_code = bestCode,
.size = *bestSize, .size = *bestSize,
.colorSpace = ColorSpace::Raw, .colorSpace = ColorSpace::Raw,
.transform = Transform::Identity,
}; };
return format; return format;
@ -760,6 +758,8 @@ V4L2SubdeviceFormat CameraSensor::getFormat(const std::vector<unsigned int> &mbu
/** /**
* \brief Set the sensor output format * \brief Set the sensor output format
* \param[in] format The desired sensor output format * \param[in] format The desired sensor output format
* \param[in] transform The transform to be applied on the sensor.
* Defaults to Identity.
* *
* If flips are writable they are configured according to the desired Transform. * If flips are writable they are configured according to the desired Transform.
* Transform::Identity always corresponds to H/V flip being disabled if the * Transform::Identity always corresponds to H/V flip being disabled if the
@ -770,18 +770,16 @@ V4L2SubdeviceFormat CameraSensor::getFormat(const std::vector<unsigned int> &mbu
* *
* \return 0 on success or a negative error code otherwise * \return 0 on success or a negative error code otherwise
*/ */
int CameraSensor::setFormat(V4L2SubdeviceFormat *format) int CameraSensor::setFormat(V4L2SubdeviceFormat *format, Transform transform)
{ {
/* Configure flips if the sensor supports that. */ /* Configure flips if the sensor supports that. */
if (supportFlips_) { if (supportFlips_) {
ControlList flipCtrls(subdev_->controls()); ControlList flipCtrls(subdev_->controls());
flipCtrls.set(V4L2_CID_HFLIP, flipCtrls.set(V4L2_CID_HFLIP,
static_cast<int32_t>(!!(format->transform & static_cast<int32_t>(!!(transform & Transform::HFlip)));
Transform::HFlip)));
flipCtrls.set(V4L2_CID_VFLIP, flipCtrls.set(V4L2_CID_VFLIP,
static_cast<int32_t>(!!(format->transform & static_cast<int32_t>(!!(transform & Transform::VFlip)));
Transform::VFlip)));
int ret = subdev_->setControls(&flipCtrls); int ret = subdev_->setControls(&flipCtrls);
if (ret) if (ret)

View file

@ -194,8 +194,7 @@ int CIO2Device::configure(const Size &size, const Transform &transform,
*/ */
std::vector<unsigned int> mbusCodes = utils::map_keys(mbusCodesToPixelFormat); std::vector<unsigned int> mbusCodes = utils::map_keys(mbusCodesToPixelFormat);
sensorFormat = getSensorFormat(mbusCodes, size); sensorFormat = getSensorFormat(mbusCodes, size);
sensorFormat.transform = transform; ret = sensor_->setFormat(&sensorFormat, transform);
ret = sensor_->setFormat(&sensorFormat);
if (ret) if (ret)
return ret; return ret;

View file

@ -832,13 +832,14 @@ int PipelineHandlerRPi::configure(Camera *camera, CameraConfiguration *config)
} }
} }
/* First calculate the best sensor mode we can use based on the user request. */ /*
* Calculate the best sensor mode we can use based on the user's
* request, and apply it to the sensor with the cached transform, if
* any.
*/
V4L2SubdeviceFormat sensorFormat = findBestFormat(data->sensorFormats_, rawStream ? sensorSize : maxSize, bitDepth); V4L2SubdeviceFormat sensorFormat = findBestFormat(data->sensorFormats_, rawStream ? sensorSize : maxSize, bitDepth);
/* Apply any cached transform. */
const RPiCameraConfiguration *rpiConfig = static_cast<const RPiCameraConfiguration *>(config); const RPiCameraConfiguration *rpiConfig = static_cast<const RPiCameraConfiguration *>(config);
sensorFormat.transform = rpiConfig->combinedTransform_; ret = data->sensor_->setFormat(&sensorFormat, rpiConfig->combinedTransform_);
/* Finally apply the format on the sensor. */
ret = data->sensor_->setFormat(&sensorFormat);
if (ret) if (ret)
return ret; return ret;

View file

@ -125,6 +125,7 @@ public:
Status validate() override; Status validate() override;
const V4L2SubdeviceFormat &sensorFormat() { return sensorFormat_; } const V4L2SubdeviceFormat &sensorFormat() { return sensorFormat_; }
const Transform &combinedTransform() { return combinedTransform_; }
private: private:
bool fitsAllPaths(const StreamConfiguration &cfg); bool fitsAllPaths(const StreamConfiguration &cfg);
@ -138,6 +139,7 @@ private:
const RkISP1CameraData *data_; const RkISP1CameraData *data_;
V4L2SubdeviceFormat sensorFormat_; V4L2SubdeviceFormat sensorFormat_;
Transform combinedTransform_;
}; };
class PipelineHandlerRkISP1 : public PipelineHandler class PipelineHandlerRkISP1 : public PipelineHandler
@ -591,7 +593,7 @@ CameraConfiguration::Status RkISP1CameraConfiguration::validate()
if (sensorFormat_.size.isNull()) if (sensorFormat_.size.isNull())
sensorFormat_.size = sensor->resolution(); sensorFormat_.size = sensor->resolution();
sensorFormat_.transform = combined; combinedTransform_ = combined;
return status; return status;
} }
@ -720,7 +722,7 @@ int PipelineHandlerRkISP1::configure(Camera *camera, CameraConfiguration *c)
V4L2SubdeviceFormat format = config->sensorFormat(); V4L2SubdeviceFormat format = config->sensorFormat();
LOG(RkISP1, Debug) << "Configuring sensor with " << format; LOG(RkISP1, Debug) << "Configuring sensor with " << format;
ret = sensor->setFormat(&format); ret = sensor->setFormat(&format, config->combinedTransform());
if (ret < 0) if (ret < 0)
return ret; return ret;

View file

@ -216,13 +216,6 @@ const std::map<uint32_t, V4L2SubdeviceFormatInfo> formatInfoMap = {
* resulting color space is acceptable. * resulting color space is acceptable.
*/ */
/**
* \var V4L2SubdeviceFormat::transform
* \brief The transform (vertical/horizontal flips) to be applied on the subdev
*
* Default initialized to Identity (no transform).
*/
/** /**
* \brief Assemble and return a string describing the format * \brief Assemble and return a string describing the format
* \return A string describing the V4L2SubdeviceFormat * \return A string describing the V4L2SubdeviceFormat