[4/5] libcamera: Add flash helpers for pipeline handlers
diff mbox series

Message ID 20250828-flash-support-v1-4-4c5dc674a05b@emfend.at
State New
Headers show
Series
  • Support for v4l2 flash devices
Related show

Commit Message

Matthias Fend Aug. 28, 2025, 1:09 p.m. UTC
Add a set of helpers that pipeline handlers can use to deal with camera
flash devices. This mainly involves mapping controls to the flash device
and vice versa.

Signed-off-by: Matthias Fend <matthias.fend@emfend.at>
---
 include/libcamera/internal/flash_control.h |  23 +++++++
 src/libcamera/flash_control.cpp            | 103 +++++++++++++++++++++++++++++
 src/libcamera/meson.build                  |   1 +
 3 files changed, 127 insertions(+)

Patch
diff mbox series

diff --git a/include/libcamera/internal/flash_control.h b/include/libcamera/internal/flash_control.h
new file mode 100644
index 0000000000000000000000000000000000000000..d530dc24fd8ea2d5676d95ab5943a7dacee07617
--- /dev/null
+++ b/include/libcamera/internal/flash_control.h
@@ -0,0 +1,23 @@ 
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+/*
+ * Copyright (C) 2025, matthias.fend@emfend.at
+ *
+ * Flash controls helpers for pipeline handlers
+ */
+
+#pragma once
+
+#include <libcamera/controls.h>
+
+#include "libcamera/internal/camera_flash.h"
+
+namespace libcamera {
+
+class FlashControl
+{
+public:
+	static void updateFlashControls(CameraFlash *flash, ControlInfoMap::Map &controls);
+	static void handleFlashControls(CameraFlash *flash, ControlList &controls, ControlList &metadata);
+};
+
+} /* namespace libcamera */
diff --git a/src/libcamera/flash_control.cpp b/src/libcamera/flash_control.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..0350bfb7c6600d0cba767726be17678ce792e5e5
--- /dev/null
+++ b/src/libcamera/flash_control.cpp
@@ -0,0 +1,103 @@ 
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+/*
+ * Copyright (C) 2025, matthias.fend@emfend.at
+ *
+ * Flash controls helpers for pipeline handlers
+ */
+
+#include "libcamera/internal/flash_control.h"
+
+#include <libcamera/control_ids.h>
+#include <libcamera/controls.h>
+
+namespace libcamera {
+
+void FlashControl::updateFlashControls(CameraFlash *flash, ControlInfoMap::Map &controls)
+{
+	if (!flash)
+		return;
+
+	controls[&controls::draft::FlashMode] = ControlInfo(controls::draft::FlashModeValues, controls::draft::FlashModeNone);
+	controls[&controls::draft::FlashIntensity] = flash->getFlashIntensityInfo();
+	controls[&controls::draft::FlashTimeout] = flash->getFlashTimeoutInfo();
+	controls[&controls::draft::FlashStrobeSource] = ControlInfo(controls::draft::FlashStrobeSourceValues, controls::draft::FlashStrobeSourceSoftware);
+	controls[&controls::draft::FlashStrobe] = ControlInfo(controls::draft::FlashStrobeValues);
+	controls[&controls::draft::FlashTorchIntensity] = flash->getTorchIntensityInfo();
+}
+
+void FlashControl::handleFlashControls(CameraFlash *flash, ControlList &controls, ControlList &metadata)
+{
+	if (!flash)
+		return;
+
+	const auto &flashMode = controls.get(controls::draft::FlashMode);
+	if (flashMode) {
+		CameraFlash::Mode mode;
+
+		switch (*flashMode) {
+		case controls::draft::FlashModeFlash:
+			mode = CameraFlash::Mode::Flash;
+			break;
+		case controls::draft::FlashModeTorch:
+			mode = CameraFlash::Mode::Torch;
+			break;
+		case controls::draft::FlashModeNone:
+		default:
+			mode = CameraFlash::Mode::None;
+			break;
+		}
+
+		flash->setMode(mode);
+	}
+
+	const auto &flashIntensity = controls.get<int32_t>(controls::draft::FlashIntensity);
+	if (flashIntensity)
+		flash->setFlashIntensity(*flashIntensity);
+
+	const auto &flashTimeout = controls.get<int32_t>(controls::draft::FlashTimeout);
+	if (flashTimeout)
+		flash->setFlashTimeout(*flashTimeout);
+
+	const auto &flashStrobeSource = controls.get(controls::draft::FlashStrobeSource);
+	if (flashStrobeSource) {
+		CameraFlash::StrobeSource source;
+
+		switch (*flashStrobeSource) {
+		case controls::draft::FlashStrobeSourceExternal:
+			source = CameraFlash::StrobeSource::External;
+			break;
+		case controls::draft::FlashStrobeSourceSoftware:
+		default:
+			source = CameraFlash::StrobeSource::Software;
+			break;
+		}
+
+		flash->setStrobeSource(source);
+	}
+
+	const auto &flashStrobe = controls.get(controls::draft::FlashStrobe);
+	if (flashStrobe) {
+		switch (*flashStrobe) {
+		case controls::draft::FlashStrobeEnum::FlashStrobeStart:
+			flash->startStrobe();
+			break;
+		case controls::draft::FlashStrobeEnum::FlashStrobeStop:
+			flash->stopStrobe();
+			break;
+		default:
+			break;
+		}
+	}
+
+	const auto &flashTorchIntensity = controls.get<int32_t>(controls::draft::FlashTorchIntensity);
+	if (flashTorchIntensity)
+		flash->setTorchIntensity(*flashTorchIntensity);
+
+	metadata.set(controls::draft::FlashMode, flash->getMode());
+	metadata.set(controls::draft::FlashIntensity, flash->getFlashIntensity());
+	metadata.set(controls::draft::FlashTimeout, flash->getFlashTimeout());
+	metadata.set(controls::draft::FlashStrobeSource, flash->getStrobeSource());
+	metadata.set(controls::draft::FlashTorchIntensity, flash->getTorchIntensity());
+}
+
+} /* namespace libcamera */
diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build
index 0f125661a51e2431c1febc353cef30a1219f9ce7..a68a49637db12f9e66b5bb38ee859aaac8c2fd1a 100644
--- a/src/libcamera/meson.build
+++ b/src/libcamera/meson.build
@@ -31,6 +31,7 @@  libcamera_internal_sources = files([
     'device_enumerator.cpp',
     'device_enumerator_sysfs.cpp',
     'dma_buf_allocator.cpp',
+    'flash_control.cpp',
     'formats.cpp',
     'ipa_controls.cpp',
     'ipa_data_serializer.cpp',