summaryrefslogtreecommitdiff
path: root/src/cam/capture_script.h
diff options
context:
space:
mode:
authorJacopo Mondi <jacopo@jmondi.org>2022-05-18 19:19:17 +0200
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2022-05-22 12:52:02 +0300
commit38bff0c82bf18e7bc7a35a5395ccdc8078797f30 (patch)
treeb132ebb007e8b76567a1710980ac17af10874a4a /src/cam/capture_script.h
parent0c1b3f5e4c5f36c19d702529d4b597415f813394 (diff)
cam: Add a parser for capture scripts
Add a parser class to the cam test application to control the capture operations through a yaml script. The capture script currently allow to specify a list of controls and their associated values to be applied per-frame. Also add a trivial capture script example to showcase the intended script structure. Signed-off-by: Jacopo Mondi <jacopo@jmondi.org> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Diffstat (limited to 'src/cam/capture_script.h')
-rw-r--r--src/cam/capture_script.h62
1 files changed, 62 insertions, 0 deletions
diff --git a/src/cam/capture_script.h b/src/cam/capture_script.h
new file mode 100644
index 00000000..8b4f8f62
--- /dev/null
+++ b/src/cam/capture_script.h
@@ -0,0 +1,62 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Copyright (C) 2022, Ideas on Board Oy
+ *
+ * capture_script.h - Capture session configuration script
+ */
+
+#pragma once
+
+#include <map>
+#include <memory>
+#include <string>
+
+#include <libcamera/camera.h>
+#include <libcamera/controls.h>
+
+#include <yaml.h>
+
+class CaptureScript
+{
+public:
+ CaptureScript(std::shared_ptr<libcamera::Camera> camera,
+ const std::string &fileName);
+
+ bool valid() const { return valid_; }
+
+ const libcamera::ControlList &frameControls(unsigned int frame);
+
+private:
+ struct EventDeleter {
+ void operator()(yaml_event_t *event) const
+ {
+ yaml_event_delete(event);
+ delete event;
+ }
+ };
+ using EventPtr = std::unique_ptr<yaml_event_t, EventDeleter>;
+
+ std::map<std::string, const libcamera::ControlId *> controls_;
+ std::map<unsigned int, libcamera::ControlList> frameControls_;
+ std::shared_ptr<libcamera::Camera> camera_;
+ yaml_parser_t parser_;
+ bool valid_;
+
+ EventPtr nextEvent(yaml_event_type_t expectedType = YAML_NO_EVENT);
+ bool checkEvent(const EventPtr &event, yaml_event_type_t expectedType) const;
+ static std::string eventScalarValue(const EventPtr &event);
+ static std::string eventTypeName(yaml_event_type_t type);
+
+ int parseScript(FILE *script);
+
+ int parseFrames();
+ int parseFrame(EventPtr event);
+ int parseControl(EventPtr event, libcamera::ControlList &controls);
+
+ std::string parseScalar();
+
+ void unpackFailure(const libcamera::ControlId *id,
+ const std::string &repr);
+ libcamera::ControlValue unpackControl(const libcamera::ControlId *id,
+ const std::string &repr);
+};