/* SPDX-License-Identifier: LGPL-2.1-or-later */ /* * Copyright (C) 2019, Google Inc. * * camera3_hal.cpp - Android Camera HALv3 module */ #include #include #include "camera_device.h" #include "camera_hal_manager.h" using namespace libcamera; LOG_DEFINE_CATEGORY(HAL) /*------------------------------------------------------------------------------ * Android Camera HAL callbacks */ static int hal_get_number_of_cameras() { return CameraHalManager::instance()->numCameras(); } static int hal_get_camera_info(int id, struct camera_info *info) { return CameraHalManager::instance()->getCameraInfo(id, info); } static int hal_set_callbacks(const camera_module_callbacks_t *callbacks) { CameraHalManager::instance()->setCallbacks(callbacks); return 0; } static int hal_open_legacy([[maybe_unused]] const struct hw_module_t *module, [[maybe_unused]] const char *id, [[maybe_unused]] uint32_t halVersion, [[maybe_unused]] struct hw_device_t **device) { return -ENOSYS; } static int hal_set_torch_mode([[maybe_unused]] const char *camera_id, [[maybe_unused]] bool enabled) { return -ENOSYS; } /* * First entry point of the camera HAL module. * * Initialize the HAL but does not open any camera device yet (see hal_dev_open) */ static int hal_init() { LOG(HAL, Info) << "Initialising Android camera HAL"; CameraHalManager::instance()->init(); return 0; } /*------------------------------------------------------------------------------ * Android Camera Device */ static int hal_dev_open(const hw_module_t *module, const char *name, hw_device_t **device) { LOG(HAL, Debug) << "Open camera " << name; int id = atoi(name); auto [camera, ret] = CameraHalManager::instance()->open(id, module); if (!camera) { LOG(HAL, Error) << "Failed to open camera module '" << id << "'"; return ret == -EBUSY ? -EUSERS : ret; } *device = &camera->camera3Device()->common; return 0; } static struct hw_module_methods_t hal_module_methods = { .open = hal_dev_open, }; camera_module_t HAL_MODULE_INFO_SYM = { .common = { .tag = HARDWARE_MODULE_TAG, .module_api_version = CAMERA_MODULE_API_VERSION_2_4, .hal_api_version = HARDWARE_HAL_API_VERSION, .id = CAMERA_HARDWARE_MODULE_ID, .name = "libcamera camera HALv3 module", .author = "libcamera", .methods = &hal_module_methods, .dso = nullptr, .reserved = {}, }, .get_number_of_cameras = hal_get_number_of_cameras, .get_camera_info = hal_get_camera_info, .set_callbacks = hal_set_callbacks, .get_vendor_tag_ops = nullptr, .open_legacy = hal_open_legacy, .set_torch_mode = hal_set_torch_mode, .init = hal_init, .reserved = {}, }; est/event-dispatcher.cpp?id=f57e9fa6dde5999bab71fc9a756bc5e1e6e68739'>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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/* SPDX-License-Identifier: GPL-2.0-or-later */
/*
 * Copyright (C) 2019, Google Inc.
 *
 * Event dispatcher test
 */

#include <chrono>
#include <iostream>
#include <signal.h>
#include <sys/time.h>

#include <libcamera/base/event_dispatcher.h>
#include <libcamera/base/thread.h>
#include <libcamera/base/timer.h>

#include "test.h"

using namespace libcamera;
using namespace std;
using namespace std::chrono_literals;

static EventDispatcher *dispatcher;
static bool interrupt;

class EventDispatcherTest : public Test
{
protected:
	static void sigAlarmHandler(int)
	{
		cout << "SIGALARM received" << endl;
		if (interrupt)
			dispatcher->interrupt();
	}

	int init()
	{
		dispatcher = Thread::current()->eventDispatcher();

		struct sigaction sa = {};
		sa.sa_handler = &sigAlarmHandler;
		sigaction(SIGALRM, &sa, nullptr);

		return 0;
	}

	int run()
	{
		Timer timer;

		/* Event processing interruption by signal. */
		std::chrono::steady_clock::time_point start = std::chrono::steady_clock::now();

		timer.start(1000ms);

		struct itimerval itimer = {};
		itimer.it_value.tv_usec = 500000;
		interrupt = false;
		setitimer(ITIMER_REAL, &itimer, nullptr);

		dispatcher->processEvents();

		std::chrono::steady_clock::time_point stop = std::chrono::steady_clock::now();
		std::chrono::steady_clock::duration duration = stop - start;
		int msecs = std::chrono::duration_cast<std::chrono::milliseconds>(duration).count();

		if (abs(msecs - 1000) > 50) {
			cout << "Event processing restart test failed" << endl;
			return TestFail;
		}

		/* Event processing interruption. */
		timer.start(1000ms);
		dispatcher->interrupt();

		dispatcher->processEvents();

		if (!timer.isRunning()) {
			cout << "Event processing immediate interruption failed" << endl;
			return TestFail;
		}

		timer.start(1000ms);