Skip to content

Commit 7615454

Browse files
author
Umang Jain
committed
pipeline: rkisp1: Filter out sensor sizes not supported by the pipeline
It is possible that the maximum sensor size (returned by CameraSensor::resolution()) is not supported by the pipeline. In such cases, a filter function is required to filter out resolutions of the camera sensor, which cannot be supported by the pipeline. Introduce the filter function filterSensorResolution() in RkISP1Path class and use it for validate() and generateConfiguration(). The maximum sensor resolution is picked from that filtered set of resolutions instead of CameraSensor::resolution(). Signed-off-by: Umang Jain <umang.jain@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Tested-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
1 parent e85c7dd commit 7615454

File tree

2 files changed

+48
-2
lines changed

2 files changed

+48
-2
lines changed

src/libcamera/pipeline/rkisp1/rkisp1_path.cpp

+40-2
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,50 @@ void RkISP1Path::populateFormats()
123123
}
124124
}
125125

126+
/**
127+
* \brief Filter the sensor resolutions that can be supported
128+
* \param[in] sensor The camera sensor
129+
*
130+
* This function retrieves all the sizes supported by the sensor and
131+
* filters all the resolutions that can be supported on the pipeline.
132+
* It is possible that the sensor's maximum output resolution is higher
133+
* than the ISP maximum input. In that case, this function filters out all
134+
* the resolution incapable of being supported and returns the maximum
135+
* sensor resolution that can be supported by the pipeline.
136+
*
137+
* \return Maximum sensor size supported on the pipeline
138+
*/
139+
Size RkISP1Path::filterSensorResolution(const CameraSensor *sensor)
140+
{
141+
auto iter = sensorSizesMap_.find(sensor);
142+
if (iter != sensorSizesMap_.end())
143+
return iter->second.back();
144+
145+
std::vector<Size> &sizes = sensorSizesMap_[sensor];
146+
for (unsigned int code : sensor->mbusCodes()) {
147+
for (const Size &size : sensor->sizes(code)) {
148+
if (size.width > maxResolution_.width ||
149+
size.height > maxResolution_.height)
150+
continue;
151+
152+
sizes.push_back(size);
153+
}
154+
}
155+
156+
/* Sort in increasing order and remove duplicates. */
157+
std::sort(sizes.begin(), sizes.end());
158+
auto last = std::unique(sizes.begin(), sizes.end());
159+
sizes.erase(last, sizes.end());
160+
161+
return sizes.back();
162+
}
163+
126164
StreamConfiguration
127165
RkISP1Path::generateConfiguration(const CameraSensor *sensor, const Size &size,
128166
StreamRole role)
129167
{
130168
const std::vector<unsigned int> &mbusCodes = sensor->mbusCodes();
131-
const Size &resolution = sensor->resolution();
169+
Size resolution = filterSensorResolution(sensor);
132170

133171
/* Min and max resolutions to populate the available stream formats. */
134172
Size maxResolution = maxResolution_.boundedToAspectRatio(resolution)
@@ -217,7 +255,7 @@ CameraConfiguration::Status RkISP1Path::validate(const CameraSensor *sensor,
217255
StreamConfiguration *cfg)
218256
{
219257
const std::vector<unsigned int> &mbusCodes = sensor->mbusCodes();
220-
const Size &resolution = sensor->resolution();
258+
Size resolution = filterSensorResolution(sensor);
221259

222260
const StreamConfiguration reqCfg = *cfg;
223261
CameraConfiguration::Status status = CameraConfiguration::Valid;

src/libcamera/pipeline/rkisp1/rkisp1_path.h

+8
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#pragma once
99

10+
#include <map>
1011
#include <memory>
1112
#include <set>
1213
#include <vector>
@@ -62,6 +63,7 @@ class RkISP1Path
6263

6364
private:
6465
void populateFormats();
66+
Size filterSensorResolution(const CameraSensor *sensor);
6567

6668
static constexpr unsigned int RKISP1_BUFFER_COUNT = 4;
6769

@@ -76,6 +78,12 @@ class RkISP1Path
7678
std::unique_ptr<V4L2Subdevice> resizer_;
7779
std::unique_ptr<V4L2VideoDevice> video_;
7880
MediaLink *link_;
81+
82+
/*
83+
* Map from camera sensors to the sizes (in increasing order),
84+
* which are guaranteed to be supported by the pipeline.
85+
*/
86+
std::map<const CameraSensor *, std::vector<Size>> sensorSizesMap_;
7987
};
8088

8189
class RkISP1MainPath : public RkISP1Path

0 commit comments

Comments
 (0)