Loading...
Searching...
No Matches
swstats_cpu.h
/* SPDX-License-Identifier: LGPL-2.1-or-later */
/*
* Copyright (C) 2023, Linaro Ltd
* Copyright (C) 2023, Red Hat Inc.
*
* Authors:
* Hans de Goede <hdegoede@redhat.com>
*
* CPU based software statistics implementation
*/
#pragma once
#include <stdint.h>
#include <libcamera/base/signal.h>
#include <libcamera/geometry.h>
#include "libcamera/internal/bayer_format.h"
#include "libcamera/internal/framebuffer.h"
#include "libcamera/internal/global_configuration.h"
#include "libcamera/internal/shared_mem_object.h"
#include "libcamera/internal/software_isp/swisp_stats.h"
#include "benchmark.h"
namespace libcamera {
class PixelFormat;
class MappedFrameBuffer;
struct StreamConfiguration;
class SwStatsCpu
{
public:
SwStatsCpu(const GlobalConfiguration &configuration);
~SwStatsCpu() = default;
/*
* The combination of pipeline + sensor delays means that
* exposure changes can take up to 3 frames to get applied,
* Run stats once every 4 frames to ensure any previous
* exposure changes have been applied.
*/
static constexpr uint32_t kStatPerNumFrames = 4;
bool isValid() const { return sharedStats_.fd().isValid(); }
const SharedFD &getStatsFD() { return sharedStats_.fd(); }
const Size &patternSize() { return patternSize_; }
int configure(const StreamConfiguration &inputCfg);
void setWindow(const Rectangle &window);
void startFrame(uint32_t frame);
void finishFrame(uint32_t frame, uint32_t bufferId);
void processFrame(uint32_t frame, uint32_t bufferId, FrameBuffer *input);
void processLine0(uint32_t frame, unsigned int y, const uint8_t *src[])
{
if (frame % kStatPerNumFrames)
return;
if ((y & ySkipMask_) || y < static_cast<unsigned int>(window_.y) ||
y >= (window_.y + window_.height))
return;
(this->*stats0_)(src);
}
void processLine2(uint32_t frame, unsigned int y, const uint8_t *src[])
{
if (frame % kStatPerNumFrames)
return;
if ((y & ySkipMask_) || y < static_cast<unsigned int>(window_.y) ||
y >= (window_.y + window_.height))
return;
(this->*stats2_)(src);
}
Signal<uint32_t, uint32_t> statsReady;
private:
using statsProcessFn = void (SwStatsCpu::*)(const uint8_t *src[]);
using processFrameFn = void (SwStatsCpu::*)(MappedFrameBuffer &in);
int setupStandardBayerOrder(BayerFormat::Order order);
/* Bayer 8 bpp unpacked */
void statsBGGR8Line0(const uint8_t *src[]);
/* Bayer 10 bpp unpacked */
void statsBGGR10Line0(const uint8_t *src[]);
/* Bayer 12 bpp unpacked */
void statsBGGR12Line0(const uint8_t *src[]);
/* Bayer 10 bpp packed */
void statsBGGR10PLine0(const uint8_t *src[]);
void statsGBRG10PLine0(const uint8_t *src[]);
void processBayerFrame2(MappedFrameBuffer &in);
processFrameFn processFrame_;
/* Variables set by configure(), used every line */
statsProcessFn stats0_;
statsProcessFn stats2_;
bool swapLines_;
unsigned int ySkipMask_;
Rectangle window_;
Size patternSize_;
unsigned int xShift_;
unsigned int stride_;
SharedMemObject<SwIspStats> sharedStats_;
SwIspStats stats_;
Benchmark bench_;
};
} /* namespace libcamera */
bayer_format.h
Class to represent Bayer formats and manipulate them.
libcamera::BayerFormat::Order
Order
The order of the colour channels in the Bayer pattern.
Definition bayer_format.h:25
libcamera::Benchmark
Simple builtin benchmark.
Definition benchmark.h:21
libcamera::FrameBuffer
Frame buffer data and its associated dynamic metadata.
Definition framebuffer.h:50
libcamera::GlobalConfiguration
Support for global libcamera configuration.
Definition global_configuration.h:22
libcamera::MappedFrameBuffer
Map a FrameBuffer using the MappedBuffer interface.
Definition mapped_framebuffer.h:47
libcamera::PixelFormat
libcamera image pixel format
Definition pixel_format.h:17
libcamera::Rectangle
Describe a rectangle's position and dimensions.
Definition geometry.h:247
libcamera::SharedFD
RAII-style wrapper for file descriptors.
Definition shared_fd.h:17
libcamera::SharedMemObject
Helper class to allocate an object in shareable memory.
Definition shared_mem_object.h:60
libcamera::Signal
Generic signal and slot communication mechanism.
Definition signal.h:39
libcamera::Size
Describe a two-dimensional size.
Definition geometry.h:51
libcamera::SwStatsCpu::kStatPerNumFrames
static constexpr uint32_t kStatPerNumFrames
Run stats once every kStatPerNumFrames frames.
Definition swstats_cpu.h:46
libcamera::SwStatsCpu::getStatsFD
const SharedFD & getStatsFD()
Get the file descriptor for the statistics.
Definition swstats_cpu.h:50
libcamera::SwStatsCpu::processLine0
void processLine0(uint32_t frame, unsigned int y, const uint8_t *src[])
Process line 0.
Definition swstats_cpu.h:60
libcamera::SwStatsCpu::processLine2
void processLine2(uint32_t frame, unsigned int y, const uint8_t *src[])
Process line 2 and 3.
Definition swstats_cpu.h:72
libcamera::SwStatsCpu::statsReady
Signal< uint32_t, uint32_t > statsReady
Signals that the statistics are ready.
Definition swstats_cpu.h:84
libcamera::SwStatsCpu::configure
int configure(const StreamConfiguration &inputCfg)
Configure the statistics object for the passed in input format.
Definition swstats_cpu.cpp:395
libcamera::SwStatsCpu::finishFrame
void finishFrame(uint32_t frame, uint32_t bufferId)
Finish statistics calculation for the current frame.
Definition swstats_cpu.cpp:346
libcamera::SwStatsCpu::setWindow
void setWindow(const Rectangle &window)
Specify window coordinates over which to gather statistics.
Definition swstats_cpu.cpp:474
libcamera::SwStatsCpu::SwStatsCpu
SwStatsCpu(const GlobalConfiguration &configuration)
Construct a SwStatsCpu object.
Definition swstats_cpu.cpp:157
libcamera::SwStatsCpu::isValid
bool isValid() const
Gets whether the statistics object is valid.
Definition swstats_cpu.h:48
libcamera::SwStatsCpu::processFrame
void processFrame(uint32_t frame, uint32_t bufferId, FrameBuffer *input)
Calculate statistics for a frame in one go.
Definition swstats_cpu.cpp:520
libcamera::SwStatsCpu::patternSize
const Size & patternSize()
Get the pattern size.
Definition swstats_cpu.h:52
libcamera::SwStatsCpu::startFrame
void startFrame(uint32_t frame)
Reset state to start statistics gathering for a new frame.
Definition swstats_cpu.cpp:327
geometry.h
Data structures related to geometric objects.
framebuffer.h
Internal frame buffer handling support.
libcamera
Top-level libcamera namespace.
Definition backtrace.h:17
signal.h
Signal & slot implementation.
libcamera::StreamConfiguration
Configuration parameters for a stream.
Definition stream.h:40
libcamera::SwIspStats
Struct that holds the statistics for the Software ISP.
Definition swisp_stats.h:24