/* SPDX-License-Identifier: GPL-2.0-or-later */ /* * Copyright (C) 2022, Ideas on Board Oy * * Capture session configuration script */ #pragma once #include #include #include #include #include #include class CaptureScript { public: CaptureScript(std::shared_ptr camera, const std::string &fileName); bool valid() const { return valid_; } const libcamera::ControlList &frameControls(unsigned int frame); void populateConfiguration(libcamera::CameraConfiguration *configuration) const; private: struct EventDeleter { void operator()(yaml_event_t *event) const { yaml_event_delete(event); delete event; } }; using EventPtr = std::unique_ptr; std::map controls_; std::map frameControls_; std::shared_ptr camera_; yaml_parser_t parser_; unsigned int loop_; bool valid_; libcamera::Orientation orientation_; std::vector streamConfigs_; 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 parseProperties(); int parseProperty(); int parseFrames(); int parseFrame(EventPtr event); int parseControl(EventPtr event, libcamera::ControlList &controls); int parseConfiguration(); int parseOrientation(EventPtr event); int parseStreams(EventPtr event); int parseStream(EventPtr event, unsigned int index); libcamera::ControlValue parseScalarControl(const libcamera::ControlId *id, const std::string repr); libcamera::ControlValue parseArrayControl(const libcamera::ControlId *id, const std::vector &repr); std::string parseScalar(); libcamera::ControlValue parseRectangles(); std::vector> parseArrays(); std::vector parseSingleArray(); void unpackFailure(const libcamera::ControlId *id, const std::string &repr); libcamera::ControlValue unpackControl(const libcamera::ControlId *id); libcamera::Rectangle unpackRectangle(const std::vector &strVec); };