ControlInfoMap does not have a ControlId map associated, but rather creates one with the generateIdMap() function at creation time. As a consequence, when in the need to de-serialize a ControlInfoMap all the ControlId it contains are created by the deserializer instance, not being able to discern if the controls the ControlIdMap refers to are the global libcamera controls (and properties) or instances local to the V4L2 device that has first initialized the controls. As a consequence the ControlId stored in a de-serialized map will always be newly created entities, preventing lookup by ControlId reference on a de-serialized ControlInfoMap. In order to make it possible to use globally available ControlId instances whenever possible, create ControlInfoMap with a reference to an externally allocated ControlIdMap instead of generating one internally. As a consequence the class constructors take and additional argument, which might be not pleasant to type in, but enforces the concepts that ControlInfoMap should be created with controls part of the same id map. As the ControlIdMap the ControlInfoMap refers to needs to be allocated externally: - Use the globally available controls::controls (or properties::properties) id map when referring to libcamera controls - The V4L2 device that creates ControlInfoMap by parsing the device's controls has to allocate a ControlIdMap - The ControlSerializer that de-serializes a ControlInfoMap has to create and store the ControlIdMap the de-serialized info map refers to Signed-off-by: Jacopo Mondi <jacopo@jmondi.org> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
84 lines
2.0 KiB
C++
84 lines
2.0 KiB
C++
/* 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/base/log.h>
|
|
#include <libcamera/base/signal.h>
|
|
#include <libcamera/base/span.h>
|
|
|
|
#include <libcamera/controls.h>
|
|
|
|
namespace libcamera {
|
|
|
|
class EventNotifier;
|
|
|
|
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 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<uint32_t> frameStart;
|
|
|
|
void updateControlInfo();
|
|
|
|
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() const { return fd_; }
|
|
|
|
private:
|
|
static ControlType v4l2CtrlType(uint32_t ctrlType);
|
|
static std::unique_ptr<ControlId> v4l2ControlId(const v4l2_query_ext_ctrl &ctrl);
|
|
ControlInfo v4l2ControlInfo(const v4l2_query_ext_ctrl &ctrl);
|
|
ControlInfo v4l2MenuControlInfo(const v4l2_query_ext_ctrl &ctrl);
|
|
|
|
void listControls();
|
|
void updateControls(ControlList *ctrls,
|
|
Span<const v4l2_ext_control> v4l2Ctrls);
|
|
|
|
void eventAvailable(EventNotifier *notifier);
|
|
|
|
std::map<unsigned int, struct v4l2_query_ext_ctrl> controlInfo_;
|
|
std::vector<std::unique_ptr<ControlId>> controlIds_;
|
|
ControlIdMap controlIdMap_;
|
|
ControlInfoMap controls_;
|
|
std::string deviceNode_;
|
|
int fd_;
|
|
|
|
EventNotifier *fdEventNotifier_;
|
|
bool frameStartEnabled_;
|
|
};
|
|
|
|
} /* namespace libcamera */
|
|
|
|
#endif /* __LIBCAMERA_INTERNAL_V4L2_DEVICE_H__ */
|