Skip to content

Commit 947b862

Browse files
committed
ipa: rkisp1: Support raw capture in IPA operations
The RkISP1 can capture raw frames by bypassing the ISP. In that mode, the ISP will not produce statistics nor consume parameters. Most algorithms will thus be unable to run, with one exception: the AGC will still be able to configure the sensor exposure time and analog gain in manual mode. To prepare for this, add the ability to disable algorithms for the duration of the capture session based on the camera configuration. Individual algorithms report whether they support raw formats at construction time, and the IPA module disables algorithms in configure() based on the stream configurations. Disabled algorithms are skipped during the capture session in the processStatsBuffer() operation. As the ISP doesn't produce statistics, don't try to access the stats buffer. There is no need for similar logic in fillParamsBuffer() as that operation won't be called for raw capture. All algorithms report not supporting raw capture by default. Raw support in AGC will be added separately. The feature is implemented in the RkISP1 module without any support from libipa at this point to avoid designing a generic API based on a single user. This may be changed in the future. Signed-off-by: Laurent Pinchart <[email protected]> Reviewed-by: Paul Elder <[email protected]> Reviewed-by: Jacopo Mondi <[email protected]>
1 parent 81e7689 commit 947b862

File tree

4 files changed

+52
-7
lines changed

4 files changed

+52
-7
lines changed

src/ipa/rkisp1/algorithms/algorithm.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,17 @@ namespace libcamera {
1515

1616
namespace ipa::rkisp1 {
1717

18-
using Algorithm = libcamera::ipa::Algorithm<Module>;
18+
class Algorithm : public libcamera::ipa::Algorithm<Module>
19+
{
20+
public:
21+
Algorithm()
22+
: disabled_(false), supportsRaw_(false)
23+
{
24+
}
25+
26+
bool disabled_;
27+
bool supportsRaw_;
28+
};
1929

2030
} /* namespace ipa::rkisp1 */
2131

src/ipa/rkisp1/ipa_context.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ namespace libcamera::ipa::rkisp1 {
8989
* \brief Sensor output resolution
9090
*/
9191

92+
/**
93+
* \var IPASessionConfiguration::raw
94+
* \brief Indicates if the camera is configured to capture raw frames
95+
*/
96+
9297
/**
9398
* \struct IPAActiveState
9499
* \brief Active state for algorithms

src/ipa/rkisp1/ipa_context.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ struct IPASessionConfiguration {
4848
struct {
4949
rkisp1_cif_isp_version revision;
5050
} hw;
51+
52+
bool raw;
5153
};
5254

5355
struct IPAActiveState {

src/ipa/rkisp1/rkisp1.cpp

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <libcamera/ipa/rkisp1_ipa_interface.h>
2525
#include <libcamera/request.h>
2626

27+
#include "libcamera/internal/formats.h"
2728
#include "libcamera/internal/mapped_framebuffer.h"
2829
#include "libcamera/internal/yaml_parser.h"
2930

@@ -206,7 +207,7 @@ void IPARkISP1::stop()
206207
}
207208

208209
int IPARkISP1::configure(const IPAConfigInfo &ipaConfig,
209-
[[maybe_unused]] const std::map<uint32_t, IPAStream> &streamConfig,
210+
const std::map<uint32_t, IPAStream> &streamConfig,
210211
ControlInfoMap *ipaControls)
211212
{
212213
sensorControls_ = ipaConfig.sensorControls;
@@ -254,7 +255,21 @@ int IPARkISP1::configure(const IPAConfigInfo &ipaConfig,
254255
context_.configuration.sensor.minAnalogueGain = camHelper_->gain(minGain);
255256
context_.configuration.sensor.maxAnalogueGain = camHelper_->gain(maxGain);
256257

257-
for (auto const &algo : algorithms()) {
258+
context_.configuration.raw = std::any_of(streamConfig.begin(), streamConfig.end(),
259+
[](auto &cfg) -> bool {
260+
PixelFormat pixelFormat{ cfg.second.pixelFormat };
261+
const PixelFormatInfo &format = PixelFormatInfo::info(pixelFormat);
262+
return format.colourEncoding == PixelFormatInfo::ColourEncodingRAW;
263+
});
264+
265+
for (auto const &a : algorithms()) {
266+
Algorithm *algo = static_cast<Algorithm *>(a.get());
267+
268+
/* Disable algorithms that don't support raw formats. */
269+
algo->disabled_ = context_.configuration.raw && !algo->supportsRaw_;
270+
if (algo->disabled_)
271+
continue;
272+
258273
int ret = algo->configure(context_, info);
259274
if (ret)
260275
return ret;
@@ -297,8 +312,12 @@ void IPARkISP1::queueRequest(const uint32_t frame, const ControlList &controls)
297312
{
298313
IPAFrameContext &frameContext = context_.frameContexts.alloc(frame);
299314

300-
for (auto const &algo : algorithms())
315+
for (auto const &a : algorithms()) {
316+
Algorithm *algo = static_cast<Algorithm *>(a.get());
317+
if (algo->disabled_)
318+
continue;
301319
algo->queueRequest(context_, frame, frameContext, controls);
320+
}
302321
}
303322

304323
void IPARkISP1::fillParamsBuffer(const uint32_t frame, const uint32_t bufferId)
@@ -323,8 +342,13 @@ void IPARkISP1::processStatsBuffer(const uint32_t frame, const uint32_t bufferId
323342
{
324343
IPAFrameContext &frameContext = context_.frameContexts.get(frame);
325344

326-
const rkisp1_stat_buffer *stats =
327-
reinterpret_cast<rkisp1_stat_buffer *>(
345+
/*
346+
* In raw capture mode, the ISP is bypassed and no statistics buffer is
347+
* provided.
348+
*/
349+
const rkisp1_stat_buffer *stats = nullptr;
350+
if (!context_.configuration.raw)
351+
stats = reinterpret_cast<rkisp1_stat_buffer *>(
328352
mappedBuffers_.at(bufferId).planes()[0].data());
329353

330354
frameContext.sensor.exposure =
@@ -334,8 +358,12 @@ void IPARkISP1::processStatsBuffer(const uint32_t frame, const uint32_t bufferId
334358

335359
ControlList metadata(controls::controls);
336360

337-
for (auto const &algo : algorithms())
361+
for (auto const &a : algorithms()) {
362+
Algorithm *algo = static_cast<Algorithm *>(a.get());
363+
if (algo->disabled_)
364+
continue;
338365
algo->process(context_, frame, frameContext, stats, metadata);
366+
}
339367

340368
setControls(frame);
341369

0 commit comments

Comments
 (0)