/* SPDX-License-Identifier: LGPL-2.1-or-later */ /* * Copyright (C) 2019, Google Inc. * * v4l2_device.h - Common base for V4L2 video devices and subdevices */ #pragma once #include #include #include #include #include #include #include #include #include #include #include #include "libcamera/internal/formats.h" namespace libcamera { class EventNotifier; class V4L2Device : protected Loggable { public: void close(); bool isOpen() const { return fd_.isValid(); } const ControlInfoMap &controls() const { return controls_; } ControlList getControls(const std::vector &ids); int setControls(ControlList *ctrls); const struct v4l2_query_ext_ctrl *controlInfo(uint32_t id) const; const std::string &deviceNode() const { return deviceNode_; } std::string devicePath() const; int setFrameStartEnabled(bool enable); Signal frameStart; void updateControlInfo(); protected: V4L2Device(const std::string &deviceNode); ~V4L2Device(); int open(unsigned int flags); int setFd(UniqueFD fd); int ioctl(unsigned long request, void *argp); int fd() const { return fd_.get(); } template static std::optional toColorSpace(const T &v4l2Format, PixelFormatInfo::ColourEncoding colourEncoding); template static int fromColorSpace(const std::optional &colorSpace, T &v4l2Format); private: static ControlType v4l2CtrlType(uint32_t ctrlType); static std::unique_ptr v4l2ControlId(const v4l2_query_ext_ctrl &ctrl); std::optional v4l2ControlInfo(const v4l2_query_ext_ctrl &ctrl); std::optional v4l2MenuControlInfo(const v4l2_query_ext_ctrl &ctrl); void listControls(); void updateControls(ControlList *ctrls, Span v4l2Ctrls); void eventAvailable(); std::map controlInfo_; std::vector> controlIds_; ControlIdMap controlIdMap_; ControlInfoMap controls_; std::string deviceNode_; UniqueFD fd_; EventNotifier *fdEventNotifier_; bool frameStartEnabled_; }; } /* namespace libcamera */