/* SPDX-License-Identifier: LGPL-2.1-or-later */ /* * Copyright (C) 2021, Google Inc. * * Helper class that performs sensor-specific parameter computations */ #pragma once #include #include #include #include #include #include namespace libcamera { namespace ipa { class CameraSensorHelper { public: CameraSensorHelper() = default; virtual ~CameraSensorHelper() = default; std::optional blackLevel() const { return blackLevel_; } virtual uint32_t gainCode(double gain) const; virtual double gain(uint32_t gainCode) const; protected: enum AnalogueGainType { AnalogueGainLinear, AnalogueGainExponential, }; struct AnalogueGainLinearConstants { int16_t m0; int16_t c0; int16_t m1; int16_t c1; }; struct AnalogueGainExpConstants { double a; double m; }; union AnalogueGainConstants { AnalogueGainLinearConstants linear; AnalogueGainExpConstants exp; }; std::optional blackLevel_; AnalogueGainType gainType_; AnalogueGainConstants gainConstants_; private: LIBCAMERA_DISABLE_COPY_AND_MOVE(CameraSensorHelper) }; class CameraSensorHelperFactoryBase { public: CameraSensorHelperFactoryBase(const std::string name); virtual ~CameraSensorHelperFactoryBase() = default; static std::unique_ptr create(const std::string &name); static std::vector &factories(); private: LIBCAMERA_DISABLE_COPY_AND_MOVE(CameraSensorHelperFactoryBase) static void registerType(CameraSensorHelperFactoryBase *factory); virtual std::unique_ptr createInstance() const = 0; std::string name_; }; template class CameraSensorHelperFactory final : public CameraSensorHelperFactoryBase { public: CameraSensorHelperFactory(const char *name) : CameraSensorHelperFactoryBase(name) { } private: std::unique_ptr createInstance() const override { return std::make_unique<_Helper>(); } }; #define REGISTER_CAMERA_SENSOR_HELPER(name, helper) \ static CameraSensorHelperFactory global_##helper##Factory(name); } /* namespace ipa */ } /* namespace libcamera */ ption value='grep'>log msg
blob: c349c9e31c406f322852137f3d265e6f177ec3d5 (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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/* SPDX-License-Identifier: GPL-2.0-or-later */
/*
 * Copyright (C) 2019, Google Inc.
 *
 * VIMC-based V4L2 subdevice test
 */

#include <iostream>
#include <string.h>
#include <sys/stat.h>

#include "libcamera/internal/device_enumerator.h"
#include "libcamera/internal/media_device.h"
#include "libcamera/internal/v4l2_subdevice.h"

#include "v4l2_subdevice_test.h"

using namespace std;
using namespace libcamera;

/*
 * This test runs on vimc media device. For a description of vimc, in the
 * context of libcamera testing, please refer to
 * 'test/media_device/media_device_link_test.cpp' file.
 *
 * If the vimc module is not loaded, the test gets skipped.
 */

int V4L2SubdeviceTest::init()
{
	enumerator_ = DeviceEnumerator::create();
	if (!enumerator_) {
		cerr << "Failed to create device enumerator" << endl;
		return TestFail;
	}

	if (enumerator_->enumerate()) {
		cerr << "Failed to enumerate media devices" << endl;
		return TestFail;
	}

	DeviceMatch dm("vimc");
	media_ = enumerator_->search(dm);
	if (!media_) {
		cerr << "Unable to find \'vimc\' media device node" << endl;
		return TestSkip;
	}

	MediaEntity *videoEntity = media_->getEntityByName("Scaler");
	if (!videoEntity) {
		cerr << "Unable to find media entity 'Scaler'" << endl;
		return TestFail;
	}

	scaler_ = new V4L2Subdevice(videoEntity);
	if (scaler_->open()) {
		cerr << "Unable to open video subdevice "
		     << scaler_->entity()->deviceNode() << endl;
		return TestSkip;
	}

	return 0;
}

void V4L2SubdeviceTest::cleanup()
{
	delete scaler_;
}