libcamera  v0.0.0
Supporting cameras in Linux since 2019
v4l2_device.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 /*
3  * Copyright (C) 2019, Google Inc.
4  *
5  * v4l2_device.h - Common base for V4L2 video devices and subdevices
6  */
7 #ifndef __LIBCAMERA_INTERNAL_V4L2_DEVICE_H__
8 #define __LIBCAMERA_INTERNAL_V4L2_DEVICE_H__
9 
10 #include <map>
11 #include <memory>
12 #include <vector>
13 
14 #include <linux/videodev2.h>
15 
16 #include "libcamera/internal/log.h"
18 
19 namespace libcamera {
20 
21 class V4L2Device : protected Loggable
22 {
23 public:
24  void close();
25  bool isOpen() const { return fd_ != -1; }
26 
27  const ControlInfoMap &controls() const { return controls_; }
28 
29  ControlList getControls(const std::vector<uint32_t> &ids);
30  int setControls(ControlList *ctrls);
31 
32  const std::string &deviceNode() const { return deviceNode_; }
33 
34 protected:
35  V4L2Device(const std::string &deviceNode);
36  ~V4L2Device();
37 
38  int open(unsigned int flags);
39  int setFd(int fd);
40 
41  int ioctl(unsigned long request, void *argp);
42 
43  int fd() { return fd_; }
44 
45 private:
46  void listControls();
47  void updateControls(ControlList *ctrls,
48  const struct v4l2_ext_control *v4l2Ctrls,
49  unsigned int count);
50 
51  std::map<unsigned int, struct v4l2_query_ext_ctrl> controlInfo_;
52  std::vector<std::unique_ptr<V4L2ControlId>> controlIds_;
53  ControlInfoMap controls_;
54  std::string deviceNode_;
55  int fd_;
56 };
57 
58 } /* namespace libcamera */
59 
60 #endif /* __LIBCAMERA_INTERNAL_V4L2_DEVICE_H__ */
A map of ControlId to ControlInfo.
Definition: controls.h:297
Associate a list of ControlId with their values for an object.
Definition: controls.h:342
Base class to support log message extensions.
Definition: log.h:83
Base class for V4L2VideoDevice and V4L2Subdevice.
Definition: v4l2_device.h:22
~V4L2Device()
Destroy a V4L2Device.
Definition: v4l2_device.cpp:59
bool isOpen() const
Check if the V4L2 device node is open.
Definition: v4l2_device.h:25
int ioctl(unsigned long request, void *argp)
Perform an IOCTL system call on the device node.
Definition: v4l2_device.cpp:359
const ControlInfoMap & controls() const
Retrieve the supported V4L2 controls and their information.
Definition: v4l2_device.h:27
void close()
Close the device node.
Definition: v4l2_device.cpp:125
int open(unsigned int flags)
Open a V4L2 device node.
Definition: v4l2_device.cpp:72
int setFd(int fd)
Set the file descriptor of a V4L2 device.
Definition: v4l2_device.cpp:110
int fd()
Retrieve the V4L2 device file descriptor.
Definition: v4l2_device.h:43
ControlList getControls(const std::vector< uint32_t > &ids)
Read controls from the device.
Definition: v4l2_device.cpp:163
int setControls(ControlList *ctrls)
Write controls to the device.
Definition: v4l2_device.cpp:273
V4L2Device(const std::string &deviceNode)
Construct a V4L2Device.
Definition: v4l2_device.cpp:51
const std::string & deviceNode() const
Retrieve the device node path.
Definition: v4l2_device.h:32
Logging infrastructure.
Support for V4L2 Controls using the V4L2 Extended Controls APIs.