Skip to content

Commit 047d647

Browse files
author
Umang Jain
committed
libcamera: rkisp1: Integrate SensorConfiguration support
Integrate the RkISP1 pipeline handler to support sensor configuration provided by applications through CameraConfiguration::sensorConfig. The SensorConfiguration must be validated on both RkISP1Path (mainPath and selfPath), so the parameters of RkISP1Path::validate() have been updated to include sensorConfig. The camera configuration will be marked as invalid when the sensor configuration is supplied, if: - Invalid sensor configuration (SensorConfiguration::isValid()) - Bit depth not supported by RkISP1 pipeline - Sensor configuration output size is larger than maximum supported sensor's size on RkISP1 pipeline - No matching sensor configuration output size supplied by the sensor Signed-off-by: Umang Jain <umang.jain@ideasonboard.com> Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com> Reviewed-by: Stefan Klug <stefan.klug@ideasonboard.com> Tested-by: Stefan Klug <stefan.klug@ideasonboard.com>
1 parent fc761ff commit 047d647

File tree

3 files changed

+80
-12
lines changed

3 files changed

+80
-12
lines changed

src/libcamera/pipeline/rkisp1/rkisp1.cpp

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -447,11 +447,12 @@ bool RkISP1CameraConfiguration::fitsAllPaths(const StreamConfiguration &cfg)
447447
StreamConfiguration config;
448448

449449
config = cfg;
450-
if (data_->mainPath_->validate(sensor, &config) != Valid)
450+
if (data_->mainPath_->validate(sensor, sensorConfig, &config) != Valid)
451451
return false;
452452

453453
config = cfg;
454-
if (data_->selfPath_ && data_->selfPath_->validate(sensor, &config) != Valid)
454+
if (data_->selfPath_ &&
455+
data_->selfPath_->validate(sensor, sensorConfig, &config) != Valid)
455456
return false;
456457

457458
return true;
@@ -468,6 +469,27 @@ CameraConfiguration::Status RkISP1CameraConfiguration::validate()
468469

469470
status = validateColorSpaces(ColorSpaceFlag::StreamsShareColorSpace);
470471

472+
/*
473+
* Make sure that if a sensor configuration has been requested it
474+
* is valid.
475+
*/
476+
if (sensorConfig) {
477+
if (!sensorConfig->isValid()) {
478+
LOG(RkISP1, Error)
479+
<< "Invalid sensor configuration request";
480+
481+
return Invalid;
482+
}
483+
484+
unsigned int bitDepth = sensorConfig->bitDepth;
485+
if (bitDepth != 8 && bitDepth != 10 && bitDepth != 12) {
486+
LOG(RkISP1, Error)
487+
<< "Invalid sensor configuration bit depth";
488+
489+
return Invalid;
490+
}
491+
}
492+
471493
/* Cap the number of entries to the available streams. */
472494
if (config_.size() > pathCount) {
473495
config_.resize(pathCount);
@@ -514,7 +536,7 @@ CameraConfiguration::Status RkISP1CameraConfiguration::validate()
514536
/* Try to match stream without adjusting configuration. */
515537
if (mainPathAvailable) {
516538
StreamConfiguration tryCfg = cfg;
517-
if (data_->mainPath_->validate(sensor, &tryCfg) == Valid) {
539+
if (data_->mainPath_->validate(sensor, sensorConfig, &tryCfg) == Valid) {
518540
mainPathAvailable = false;
519541
cfg = tryCfg;
520542
cfg.setStream(const_cast<Stream *>(&data_->mainPathStream_));
@@ -524,7 +546,7 @@ CameraConfiguration::Status RkISP1CameraConfiguration::validate()
524546

525547
if (selfPathAvailable) {
526548
StreamConfiguration tryCfg = cfg;
527-
if (data_->selfPath_->validate(sensor, &tryCfg) == Valid) {
549+
if (data_->selfPath_->validate(sensor, sensorConfig, &tryCfg) == Valid) {
528550
selfPathAvailable = false;
529551
cfg = tryCfg;
530552
cfg.setStream(const_cast<Stream *>(&data_->selfPathStream_));
@@ -535,7 +557,7 @@ CameraConfiguration::Status RkISP1CameraConfiguration::validate()
535557
/* Try to match stream allowing adjusting configuration. */
536558
if (mainPathAvailable) {
537559
StreamConfiguration tryCfg = cfg;
538-
if (data_->mainPath_->validate(sensor, &tryCfg) == Adjusted) {
560+
if (data_->mainPath_->validate(sensor, sensorConfig, &tryCfg) == Adjusted) {
539561
mainPathAvailable = false;
540562
cfg = tryCfg;
541563
cfg.setStream(const_cast<Stream *>(&data_->mainPathStream_));
@@ -546,7 +568,7 @@ CameraConfiguration::Status RkISP1CameraConfiguration::validate()
546568

547569
if (selfPathAvailable) {
548570
StreamConfiguration tryCfg = cfg;
549-
if (data_->selfPath_->validate(sensor, &tryCfg) == Adjusted) {
571+
if (data_->selfPath_->validate(sensor, sensorConfig, &tryCfg) == Adjusted) {
550572
selfPathAvailable = false;
551573
cfg = tryCfg;
552574
cfg.setStream(const_cast<Stream *>(&data_->selfPathStream_));
@@ -723,7 +745,13 @@ int PipelineHandlerRkISP1::configure(Camera *camera, CameraConfiguration *c)
723745
V4L2SubdeviceFormat format = config->sensorFormat();
724746
LOG(RkISP1, Debug) << "Configuring sensor with " << format;
725747

726-
ret = sensor->setFormat(&format, config->combinedTransform());
748+
if (config->sensorConfig)
749+
ret = sensor->applyConfiguration(*config->sensorConfig,
750+
config->combinedTransform(),
751+
&format);
752+
else
753+
ret = sensor->setFormat(&format, config->combinedTransform());
754+
727755
if (ret < 0)
728756
return ret;
729757

src/libcamera/pipeline/rkisp1/rkisp1_path.cpp

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,10 @@ RkISP1Path::generateConfiguration(const CameraSensor *sensor, const Size &size,
251251
return cfg;
252252
}
253253

254-
CameraConfiguration::Status RkISP1Path::validate(const CameraSensor *sensor,
255-
StreamConfiguration *cfg)
254+
CameraConfiguration::Status
255+
RkISP1Path::validate(const CameraSensor *sensor,
256+
std::optional<SensorConfiguration> &sensorConfig,
257+
StreamConfiguration *cfg)
256258
{
257259
const std::vector<unsigned int> &mbusCodes = sensor->mbusCodes();
258260
Size resolution = filterSensorResolution(sensor);
@@ -282,9 +284,14 @@ CameraConfiguration::Status RkISP1Path::validate(const CameraSensor *sensor,
282284
continue;
283285

284286
/*
285-
* Store the raw format with the highest bits per pixel
286-
* for later usage.
287+
* If the bits per pixel is supplied from the sensor
288+
* configuration, choose a raw format that complies with
289+
* it. Otherwise, store the raw format with the highest
290+
* bits per pixel for later usage.
287291
*/
292+
if (sensorConfig && info.bitsPerPixel != sensorConfig->bitDepth)
293+
continue;
294+
288295
if (info.bitsPerPixel > rawBitsPerPixel) {
289296
rawBitsPerPixel = info.bitsPerPixel;
290297
rawFormat = format;
@@ -297,6 +304,9 @@ CameraConfiguration::Status RkISP1Path::validate(const CameraSensor *sensor,
297304
}
298305
}
299306

307+
if (sensorConfig && !found)
308+
return CameraConfiguration::Invalid;
309+
300310
bool isRaw = PixelFormatInfo::info(cfg->pixelFormat).colourEncoding ==
301311
PixelFormatInfo::ColourEncodingRAW;
302312

@@ -319,11 +329,39 @@ CameraConfiguration::Status RkISP1Path::validate(const CameraSensor *sensor,
319329
* size.
320330
*/
321331
uint32_t mbusCode = formatToMediaBus.at(cfg->pixelFormat);
332+
Size rawSize = sensorConfig ? sensorConfig->outputSize
333+
: cfg->size;
334+
322335
V4L2SubdeviceFormat sensorFormat =
323-
sensor->getFormat({ mbusCode }, cfg->size);
336+
sensor->getFormat({ mbusCode }, rawSize);
337+
338+
if (sensorConfig &&
339+
sensorConfig->outputSize != sensorFormat.size)
340+
return CameraConfiguration::Invalid;
324341

325342
minResolution = sensorFormat.size;
326343
maxResolution = sensorFormat.size;
344+
} else if (sensorConfig) {
345+
/*
346+
* We have already ensured 'rawFormat' has the matching bit
347+
* depth with sensorConfig.bitDepth hence, only validate the
348+
* sensorConfig's output size here.
349+
*/
350+
Size sensorSize = sensorConfig->outputSize;
351+
352+
if (sensorSize > resolution)
353+
return CameraConfiguration::Invalid;
354+
355+
uint32_t mbusCode = formatToMediaBus.at(rawFormat);
356+
V4L2SubdeviceFormat sensorFormat =
357+
sensor->getFormat({ mbusCode }, sensorSize);
358+
359+
if (sensorFormat.size != sensorSize)
360+
return CameraConfiguration::Invalid;
361+
362+
minResolution = minResolution_.expandedToAspectRatio(sensorSize);
363+
maxResolution = maxResolution_.boundedTo(sensorSize)
364+
.boundedToAspectRatio(sensorSize);
327365
} else {
328366
/*
329367
* Adjust the size based on the sensor resolution and absolute

src/libcamera/pipeline/rkisp1/rkisp1_path.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ namespace libcamera {
2727
class CameraSensor;
2828
class MediaDevice;
2929
class V4L2Subdevice;
30+
class SensorConfiguration;
3031
struct StreamConfiguration;
3132
struct V4L2SubdeviceFormat;
3233

@@ -44,6 +45,7 @@ class RkISP1Path
4445
const Size &resolution,
4546
StreamRole role);
4647
CameraConfiguration::Status validate(const CameraSensor *sensor,
48+
std::optional<SensorConfiguration> &sensorConfig,
4749
StreamConfiguration *cfg);
4850

4951
int configure(const StreamConfiguration &config,

0 commit comments

Comments
 (0)