libcamera v0.7.1+1-5701eb5f-nvm
Supporting cameras in Linux since 2019
Loading...
Searching...
No Matches
v4l2_params.h
1/* SPDX-License-Identifier: LGPL-2.1-or-later */
2/*
3 * Copyright (C) 2025, Ideas On Board
4 *
5 * V4L2 ISP Parameters
6 */
7
8#pragma once
9
10#include <map>
11#include <stdint.h>
12#include <string.h>
13
14#include <linux/media/v4l2-isp.h>
15
16#include <libcamera/base/log.h>
17#include <libcamera/base/span.h>
19
20namespace libcamera {
21
22namespace ipa {
23
24LOG_DECLARE_CATEGORY(V4L2Params)
25
26template<typename T>
28{
29public:
30 V4L2ParamsBlock(const Span<uint8_t> data)
31 : data_(data)
32 {
33 }
34
35 virtual ~V4L2ParamsBlock() {}
36
37 virtual void setEnabled(bool enabled)
38 {
39 struct v4l2_isp_params_block_header *header =
40 reinterpret_cast<struct v4l2_isp_params_block_header *>(data_.data());
41
42 header->flags &= ~(V4L2_ISP_PARAMS_FL_BLOCK_ENABLE |
43 V4L2_ISP_PARAMS_FL_BLOCK_DISABLE);
44 header->flags |= enabled ? V4L2_ISP_PARAMS_FL_BLOCK_ENABLE
45 : V4L2_ISP_PARAMS_FL_BLOCK_DISABLE;
46 }
47
48 virtual const T *operator->() const
49 {
50 return reinterpret_cast<const T *>(data_.data());
51 }
52
53 virtual T *operator->()
54 {
55 return reinterpret_cast<T *>(data_.data());
56 }
57
58 virtual const T &operator*() const
59 {
60 return *reinterpret_cast<const T *>(data_.data());
61 }
62
63 virtual T &operator*()
64 {
65 return *reinterpret_cast<T *>(data_.data());
66 }
67
68protected:
69 Span<uint8_t> data_;
70};
71
73{
74protected:
75 V4L2ParamsBase(Span<uint8_t> data, unsigned int version);
76
77public:
78 size_t bytesused() const { return used_; }
79
80protected:
81 Span<uint8_t> block(uint16_t type, unsigned int blockType,
82 size_t blockSize);
83
84 Span<uint8_t> data_;
85 size_t used_;
86
87 std::map<uint16_t, Span<uint8_t>> blocks_;
88};
89
90template<typename Traits>
92{
93public:
94 static_assert(std::is_same_v<std::underlying_type_t<typename Traits::id_type>, uint16_t>);
95
96 V4L2Params(Span<uint8_t> data, unsigned int version)
97 : V4L2ParamsBase(data, version)
98 {
99 }
100
101 template<typename Traits::id_type Id>
102 auto block()
103 {
104 using Details = typename Traits::template id_to_details<Id>;
105
106 using Type = typename Details::type;
107 constexpr auto kernelId = Details::blockType;
108
109 auto data = V4L2ParamsBase::block(utils::to_underlying(Id),
110 kernelId, sizeof(Type));
111 return V4L2ParamsBlock<Type>(data);
112 }
113};
114
115} /* namespace ipa */
116
117} /* namespace libcamera */
Base class for V4L2Params.
Definition v4l2_params.h:73
size_t used_
The number of bytes used in the parameters buffer.
Definition v4l2_params.h:85
Span< uint8_t > block(uint16_t type, unsigned int blockType, size_t blockSize)
Populate an ISP configuration block a returns a reference to its memory.
Definition v4l2_params.cpp:170
size_t bytesused() const
Retrieve the used size of the parameters buffer (in bytes)
Definition v4l2_params.h:78
Span< uint8_t > data_
The ISP parameters buffer memory.
Definition v4l2_params.h:84
std::map< uint16_t, Span< uint8_t > > blocks_
Cache of ISP configuration blocks.
Definition v4l2_params.h:87
Helper class that represents an ISP configuration block.
Definition v4l2_params.h:28
virtual T * operator->()
Access the ISP configuration block casting it to the kernel-defined ISP configuration type.
Definition v4l2_params.h:53
virtual const T & operator*() const
Access the ISP configuration block casting it to the kernel-defined ISP configuration type.
Definition v4l2_params.h:58
virtual const T * operator->() const
Access the ISP configuration block casting it to the kernel-defined ISP configuration type.
Definition v4l2_params.h:48
virtual T & operator*()
Access the ISP configuration block casting it to the kernel-defined ISP configuration type.
Definition v4l2_params.h:63
V4L2ParamsBlock(const Span< uint8_t > data)
Construct a V4L2ParamsBlock with memory represented by data.
Definition v4l2_params.h:30
virtual void setEnabled(bool enabled)
Enable/disable an ISP configuration block.
Definition v4l2_params.h:37
Span< uint8_t > data_
Memory area reserved for the ISP configuration block.
Definition v4l2_params.h:69
Helper class that represent an ISP configuration buffer.
Definition v4l2_params.h:92
auto block()
Retrieve the location of an ISP configuration block a return it.
Definition v4l2_params.h:102
V4L2Params(Span< uint8_t > data, unsigned int version)
Construct an instance of V4L2Params.
Definition v4l2_params.h:96
Logging infrastructure.
#define LOG_DECLARE_CATEGORY(name)
Declare a category of log messages.
Definition log.h:51
Top-level libcamera namespace.
Definition backtrace.h:17
Miscellaneous utility functions.