v4l2_device.h
Go to the documentation of this file.
/* SPDX-License-Identifier: LGPL-2.1-or-later */
/*
* Copyright (C) 2019, Google Inc.
*
* v4l2_device.h - Common base for V4L2 video devices and subdevices
*/
#ifndef __LIBCAMERA_INTERNAL_V4L2_DEVICE_H__
#define __LIBCAMERA_INTERNAL_V4L2_DEVICE_H__
#include <map>
#include <memory>
#include <vector>
#include <linux/videodev2.h>
#include "libcamera/internal/log.h"
#include "libcamera/internal/v4l2_controls.h"
namespace libcamera {
class V4L2Device : protected Loggable
{
public:
void close();
bool isOpen() const { return fd_ != -1; }
const ControlInfoMap &controls() const { return controls_; }
ControlList getControls(const std::vector<uint32_t> &ids);
int setControls(ControlList *ctrls);
const std::string &deviceNode() const { return deviceNode_; }
protected:
V4L2Device(const std::string &deviceNode);
~V4L2Device();
int open(unsigned int flags);
int setFd(int fd);
int ioctl(unsigned long request, void *argp);
int fd() { return fd_; }
private:
void listControls();
void updateControls(ControlList *ctrls,
const struct v4l2_ext_control *v4l2Ctrls,
unsigned int count);
std::map<unsigned int, struct v4l2_query_ext_ctrl> controlInfo_;
std::vector<std::unique_ptr<V4L2ControlId>> controlIds_;
ControlInfoMap controls_;
std::string deviceNode_;
int fd_;
};
} /* namespace libcamera */
#endif /* __LIBCAMERA_INTERNAL_V4L2_DEVICE_H__ */
libcamera::ControlInfoMap
A map of ControlId to ControlInfo.
Definition: controls.h:297
libcamera::ControlList
Associate a list of ControlId with their values for an object.
Definition: controls.h:342
libcamera::Loggable
Base class to support log message extensions.
Definition: log.h:83
libcamera::V4L2Device
Base class for V4L2VideoDevice and V4L2Subdevice.
Definition: v4l2_device.h:22
libcamera::V4L2Device::~V4L2Device
~V4L2Device()
Destroy a V4L2Device.
Definition: v4l2_device.cpp:59
libcamera::V4L2Device::isOpen
bool isOpen() const
Check if the V4L2 device node is open.
Definition: v4l2_device.h:25
libcamera::V4L2Device::ioctl
int ioctl(unsigned long request, void *argp)
Perform an IOCTL system call on the device node.
Definition: v4l2_device.cpp:359
libcamera::V4L2Device::controls
const ControlInfoMap & controls() const
Retrieve the supported V4L2 controls and their information.
Definition: v4l2_device.h:27
libcamera::V4L2Device::close
void close()
Close the device node.
Definition: v4l2_device.cpp:125
libcamera::V4L2Device::open
int open(unsigned int flags)
Open a V4L2 device node.
Definition: v4l2_device.cpp:72
libcamera::V4L2Device::setFd
int setFd(int fd)
Set the file descriptor of a V4L2 device.
Definition: v4l2_device.cpp:110
libcamera::V4L2Device::fd
int fd()
Retrieve the V4L2 device file descriptor.
Definition: v4l2_device.h:43
libcamera::V4L2Device::getControls
ControlList getControls(const std::vector< uint32_t > &ids)
Read controls from the device.
Definition: v4l2_device.cpp:163
libcamera::V4L2Device::setControls
int setControls(ControlList *ctrls)
Write controls to the device.
Definition: v4l2_device.cpp:273
libcamera::V4L2Device::V4L2Device
V4L2Device(const std::string &deviceNode)
Construct a V4L2Device.
Definition: v4l2_device.cpp:51
libcamera::V4L2Device::deviceNode
const std::string & deviceNode() const
Retrieve the device node path.
Definition: v4l2_device.h:32
log.h
Logging infrastructure.
v4l2_controls.h
Support for V4L2 Controls using the V4L2 Extended Controls APIs.