|
| 1 | +/* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 2 | +/* |
| 3 | + * Copyright (C) 2025, Ideas on Board Oy |
| 4 | + * |
| 5 | + * DW100 Dewarp Engine integration |
| 6 | + */ |
| 7 | + |
| 8 | +#pragma once |
| 9 | + |
| 10 | +#include <memory> |
| 11 | +#include <queue> |
| 12 | + |
| 13 | +#include <libcamera/control_ids.h> |
| 14 | +#include <libcamera/controls.h> |
| 15 | +#include <libcamera/framebuffer.h> |
| 16 | + |
| 17 | +#include "libcamera/internal/converter/converter_dw100_vertexmap.h" |
| 18 | +#include "libcamera/internal/converter/converter_v4l2_m2m.h" |
| 19 | +#include "libcamera/internal/device_enumerator.h" |
| 20 | + |
| 21 | +namespace libcamera { |
| 22 | + |
| 23 | +class MediaDevice; |
| 24 | +class Rectangle; |
| 25 | +class Stream; |
| 26 | + |
| 27 | +class ConverterDW100Module |
| 28 | +{ |
| 29 | +public: |
| 30 | + virtual ~ConverterDW100Module() = default; |
| 31 | + |
| 32 | + static std::unique_ptr<ConverterDW100Module> createModule(DeviceEnumerator *enumerator); |
| 33 | + |
| 34 | + int init(const YamlObject ¶ms); |
| 35 | + |
| 36 | + int configure(const StreamConfiguration &inputCfg, |
| 37 | + const std::vector<std::reference_wrapper<StreamConfiguration>> |
| 38 | + &outputCfg); |
| 39 | + bool isConfigured(const Stream *stream) const; |
| 40 | + |
| 41 | + Size adjustInputSize(const PixelFormat &pixFmt, const Size &size, |
| 42 | + Converter::Alignment align = Converter::Alignment::Down); |
| 43 | + Size adjustOutputSize(const PixelFormat &pixFmt, const Size &size, |
| 44 | + Converter::Alignment align = Converter::Alignment::Down); |
| 45 | + |
| 46 | + int exportBuffers(const Stream *stream, unsigned int count, |
| 47 | + std::vector<std::unique_ptr<FrameBuffer>> *buffers); |
| 48 | + int validateOutput(StreamConfiguration *cfg, bool *adjusted, |
| 49 | + Converter::Alignment align = Converter::Alignment::Down); |
| 50 | + int queueBuffers(FrameBuffer *input, |
| 51 | + const std::map<const Stream *, FrameBuffer *> &outputs); |
| 52 | + |
| 53 | + int start(); |
| 54 | + void stop(); |
| 55 | + |
| 56 | + void updateControlInfos(const Stream *stream, ControlInfoMap::Map &infos); |
| 57 | + void setControls(const Stream *stream, const ControlList &controls); |
| 58 | + void populateMetadata(const Stream *stream, ControlList &meta); |
| 59 | + |
| 60 | + void setSensorCrop(const Rectangle &rect); |
| 61 | + void setTransform(const Stream *stream, const Transform &transform); |
| 62 | + |
| 63 | + Signal<FrameBuffer *> inputBufferReady; |
| 64 | + Signal<FrameBuffer *> outputBufferReady; |
| 65 | + |
| 66 | +private: |
| 67 | + ConverterDW100Module(std::shared_ptr<MediaDevice> media); |
| 68 | + |
| 69 | + int applyControls(const Stream *stream, const V4L2Request *request); |
| 70 | + void reinitRequest(V4L2Request *request); |
| 71 | + |
| 72 | + struct DewarpParms { |
| 73 | + Matrix<double, 3, 3> cm; |
| 74 | + std::vector<double> coeffs; |
| 75 | + }; |
| 76 | + |
| 77 | + struct VertexMapInfo { |
| 78 | + Dw100VertexMap map; |
| 79 | + bool update; |
| 80 | + }; |
| 81 | + |
| 82 | + std::map<const Stream *, VertexMapInfo> vertexMaps_; |
| 83 | + std::optional<DewarpParms> dewarpParams_; |
| 84 | + unsigned int inputBufferCount_; |
| 85 | + V4L2M2MConverter converter_; |
| 86 | + Rectangle sensorCrop_; |
| 87 | + bool running_; |
| 88 | + |
| 89 | + std::vector<std::unique_ptr<V4L2Request>> requests_; |
| 90 | + std::queue<V4L2Request *> availableRequests_; |
| 91 | +}; |
| 92 | + |
| 93 | +} /* namespace libcamera */ |
0 commit comments