summaryrefslogtreecommitdiff
path: root/src/cam/capture_script.h
blob: 8b4f8f62a634cb8bfed6c6aa46aed045951b5924 (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
/* 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);
};