summaryrefslogtreecommitdiff
path: root/src/ipa/raspberrypi/controller/algorithm.cpp
blob: 6d91ee292bd198702a3d47807d43f8b3ccd6ee12 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/* SPDX-License-Identifier: BSD-2-Clause */
/*
 * Copyright (C) 2019, Raspberry Pi Ltd
 *
 * algorithm.cpp - ISP control algorithms
 */

#include "algorithm.h"

using namespace RPiController;

int Algorithm::read([[maybe_unused]] const libcamera::YamlObject &params)
{
	return 0;
}

void Algorithm::initialise()
{
}

void Algorithm::switchMode([[maybe_unused]] CameraMode const &cameraMode,
			   [[maybe_unused]] Metadata *metadata)
{
}

void Algorithm::prepare([[maybe_unused]] Metadata *imageMetadata)
{
}

void Algorithm::process([[maybe_unused]] StatisticsPtr &stats,
			[[maybe_unused]] Metadata *imageMetadata)
{
}

/* For registering algorithms with the system: */

static std::map<std::string, AlgoCreateFunc> algorithms;
std::map<std::string, AlgoCreateFunc> const &RPiController::getAlgorithms()
{
	return algorithms;
}

RegisterAlgorithm::RegisterAlgorithm(char const *name,
				     AlgoCreateFunc createFunc)
{
	algorithms[std::string(name)] = createFunc;
}
n class="hl kwd">entity_(entity) { } /** * \brief Destroy a CameraLens */ CameraLens::~CameraLens() = default; /** * \brief Initialize the camera lens instance * * This function performs the initialisation steps of the CameraLens that may * fail. It shall be called once and only once after constructing the instance. * * \return 0 on success or a negative error code otherwise */ int CameraLens::init() { if (entity_->function() != MEDIA_ENT_F_LENS) { LOG(CameraLens, Error) << "Invalid lens function " << utils::hex(entity_->function()); return -EINVAL; } /* Create and open the subdev. */ subdev_ = std::make_unique<V4L2Subdevice>(entity_); int ret = subdev_->open(); if (ret < 0) return ret; ret = validateLensDriver(); if (ret) return ret; model_ = subdev_->model(); return 0; } /** * \brief This function sets the focal point of the lens to a specific position. * \param[in] position The focal point of the lens * * This function sets the value of focal point of the lens as in \a position. * * \return 0 on success or -EINVAL otherwise */ int CameraLens::setFocusPosition(int32_t position) { ControlList lensCtrls(subdev_->controls()); lensCtrls.set(V4L2_CID_FOCUS_ABSOLUTE, static_cast<int32_t>(position)); if (subdev_->setControls(&lensCtrls)) return -EINVAL; return 0; } int CameraLens::validateLensDriver() { int ret = 0; static constexpr uint32_t mandatoryControls[] = { V4L2_CID_FOCUS_ABSOLUTE, }; const ControlInfoMap &controls = subdev_->controls(); for (uint32_t ctrl : mandatoryControls) { if (!controls.count(ctrl)) { LOG(CameraLens, Error) << "Mandatory V4L2 control " << utils::hex(ctrl) << " not available"; ret = -EINVAL; } } if (ret) { LOG(CameraLens, Error) << "The lens kernel driver needs to be fixed"; LOG(CameraLens, Error) << "See Documentation/lens_driver_requirements.rst in" << " the libcamera sources for more information"; return ret; } return ret; } /** * \fn CameraLens::model() * \brief Retrieve the lens model name * * The lens model name is a free-formed string that uniquely identifies the * lens model. * * \return The lens model name */ std::string CameraLens::logPrefix() const { return "'" + entity_->name() + "'"; } /** * \fn CameraLens::controls() * \brief Retrieve the V4L2 controls of the lens' subdev * * \return A map of the V4L2 controls supported by the lens' driver */ const ControlInfoMap &CameraLens::controls() const { return subdev_->controls(); } } /* namespace libcamera */