libcamera v0.7.0+1-4ceceb68
Supporting cameras in Linux since 2019
Loading...
Searching...
No Matches
swstats_cpu.h
1/* SPDX-License-Identifier: LGPL-2.1-or-later */
2/*
3 * Copyright (C) 2023, Linaro Ltd
4 * Copyright (C) 2023, Red Hat Inc.
5 *
6 * Authors:
7 * Hans de Goede <hdegoede@redhat.com>
8 *
9 * CPU based software statistics implementation
10 */
11
12#pragma once
13
14#include <stdint.h>
15
17
18#include <libcamera/geometry.h>
19
22#include "libcamera/internal/global_configuration.h"
23#include "libcamera/internal/shared_mem_object.h"
24#include "libcamera/internal/software_isp/swisp_stats.h"
25
26#include "benchmark.h"
27
28namespace libcamera {
29
30class PixelFormat;
31class MappedFrameBuffer;
32struct StreamConfiguration;
33
35{
36public:
37 SwStatsCpu(const GlobalConfiguration &configuration);
38 ~SwStatsCpu() = default;
39
40 /*
41 * The combination of pipeline + sensor delays means that
42 * exposure changes can take up to 3 frames to get applied,
43 * Run stats once every 4 frames to ensure any previous
44 * exposure changes have been applied.
45 */
46 static constexpr uint32_t kStatPerNumFrames = 4;
47
48 bool isValid() const { return sharedStats_.fd().isValid(); }
49
50 const SharedFD &getStatsFD() { return sharedStats_.fd(); }
51
52 const Size &patternSize() { return patternSize_; }
53
54 int configure(const StreamConfiguration &inputCfg);
55 void setWindow(const Rectangle &window);
56 void startFrame(uint32_t frame);
57 void finishFrame(uint32_t frame, uint32_t bufferId);
58 void processFrame(uint32_t frame, uint32_t bufferId, FrameBuffer *input);
59
60 void processLine0(uint32_t frame, unsigned int y, const uint8_t *src[])
61 {
62 if (frame % kStatPerNumFrames)
63 return;
64
65 if ((y & ySkipMask_) || y < static_cast<unsigned int>(window_.y) ||
66 y >= (window_.y + window_.height))
67 return;
68
69 (this->*stats0_)(src);
70 }
71
72 void processLine2(uint32_t frame, unsigned int y, const uint8_t *src[])
73 {
74 if (frame % kStatPerNumFrames)
75 return;
76
77 if ((y & ySkipMask_) || y < static_cast<unsigned int>(window_.y) ||
78 y >= (window_.y + window_.height))
79 return;
80
81 (this->*stats2_)(src);
82 }
83
85
86private:
87 using statsProcessFn = void (SwStatsCpu::*)(const uint8_t *src[]);
88 using processFrameFn = void (SwStatsCpu::*)(MappedFrameBuffer &in);
89
90 int setupStandardBayerOrder(BayerFormat::Order order);
91 /* Bayer 8 bpp unpacked */
92 void statsBGGR8Line0(const uint8_t *src[]);
93 /* Bayer 10 bpp unpacked */
94 void statsBGGR10Line0(const uint8_t *src[]);
95 /* Bayer 12 bpp unpacked */
96 void statsBGGR12Line0(const uint8_t *src[]);
97 /* Bayer 10 bpp packed */
98 void statsBGGR10PLine0(const uint8_t *src[]);
99 void statsGBRG10PLine0(const uint8_t *src[]);
100
101 void processBayerFrame2(MappedFrameBuffer &in);
102
103 processFrameFn processFrame_;
104
105 /* Variables set by configure(), used every line */
106 statsProcessFn stats0_;
107 statsProcessFn stats2_;
108 bool swapLines_;
109
110 unsigned int ySkipMask_;
111
112 Rectangle window_;
113
114 Size patternSize_;
115
116 unsigned int xShift_;
117 unsigned int stride_;
118
119 SharedMemObject<SwIspStats> sharedStats_;
120 SwIspStats stats_;
121 Benchmark bench_;
122};
123
124} /* namespace libcamera */
Class to represent Bayer formats and manipulate them.
Order
The order of the colour channels in the Bayer pattern.
Definition bayer_format.h:25
Simple builtin benchmark.
Definition benchmark.h:21
Frame buffer data and its associated dynamic metadata.
Definition framebuffer.h:50
Support for global libcamera configuration.
Definition global_configuration.h:22
Map a FrameBuffer using the MappedBuffer interface.
Definition mapped_framebuffer.h:47
Describe a rectangle's position and dimensions.
Definition geometry.h:247
int y
The vertical coordinate of the rectangle's top-left corner.
Definition geometry.h:279
unsigned int height
The distance between the top and bottom sides.
Definition geometry.h:281
RAII-style wrapper for file descriptors.
Definition shared_fd.h:17
Helper class to allocate an object in shareable memory.
Definition shared_mem_object.h:60
Generic signal and slot communication mechanism.
Definition signal.h:39
Describe a two-dimensional size.
Definition geometry.h:51
Class for gathering statistics on the CPU.
Definition swstats_cpu.h:35
const SharedFD & getStatsFD()
Get the file descriptor for the statistics.
Definition swstats_cpu.h:50
void processLine0(uint32_t frame, unsigned int y, const uint8_t *src[])
Process line 0.
Definition swstats_cpu.h:60
void processLine2(uint32_t frame, unsigned int y, const uint8_t *src[])
Process line 2 and 3.
Definition swstats_cpu.h:72
int configure(const StreamConfiguration &inputCfg)
Configure the statistics object for the passed in input format.
Definition swstats_cpu.cpp:395
void finishFrame(uint32_t frame, uint32_t bufferId)
Finish statistics calculation for the current frame.
Definition swstats_cpu.cpp:346
void setWindow(const Rectangle &window)
Specify window coordinates over which to gather statistics.
Definition swstats_cpu.cpp:474
Signal< uint32_t, uint32_t > statsReady
Signals that the statistics are ready.
Definition swstats_cpu.h:84
bool isValid() const
Gets whether the statistics object is valid.
Definition swstats_cpu.h:48
void processFrame(uint32_t frame, uint32_t bufferId, FrameBuffer *input)
Calculate statistics for a frame in one go.
Definition swstats_cpu.cpp:520
static constexpr uint32_t kStatPerNumFrames
Run stats once every kStatPerNumFrames frames.
Definition swstats_cpu.h:46
const Size & patternSize()
Get the pattern size.
Definition swstats_cpu.h:52
void startFrame(uint32_t frame)
Reset state to start statistics gathering for a new frame.
Definition swstats_cpu.cpp:327
Data structures related to geometric objects.
Internal frame buffer handling support.
Top-level libcamera namespace.
Definition backtrace.h:17
Signal & slot implementation.
Configuration parameters for a stream.
Definition stream.h:40
Struct that holds the statistics for the Software ISP.
Definition swisp_stats.h:24