summaryrefslogtreecommitdiff
path: root/test/v4l2_videodevice/controls.cpp
AgeCommit message (Expand)Author
2021-05-26test: v4l2_videodevice: controls: Test 64-bit controlsLaurent Pinchart
2020-10-20test: Omit extra semicolonsHirokazu Honda
2020-05-16libcamera: Move internal headers to include/libcamera/internal/Laurent Pinchart
2020-04-28libcamera: v4l2_device: Simplify usage of getControls()Laurent Pinchart
2020-03-23test: v4l2_videodevice: Test U8 array controlsJacopo Mondi
2020-03-20libcamera: controls: Rename ControlRange to ControlInfoLaurent Pinchart
2020-03-20libcamera: controls: Name all ControlInfoMap instance variables infoMapLaurent Pinchart
2019-10-23libcamera: Standardise on C compatibility headersLaurent Pinchart
2019-10-15libcamera: v4l2_controls: Remove V4L2ControlList classLaurent Pinchart
2019-10-15libcamera: controls: Merge ControlInfoMap and V4L2ControlInfoMapLaurent Pinchart
2019-10-15libcamera: v4l2_controls: Store a ControlRange in V4L2ControlInfoMapLaurent Pinchart
2019-10-15libcamera: v4l2_controls: Replace V4L2ControlInfo with V4L2ControlRangeLaurent Pinchart
2019-10-15test: v4l2_videodevice: controls: Use correct control range in checkLaurent Pinchart
2019-10-13libcamera: v4l2_device: Replace V4L2ControlList with ControlListLaurent Pinchart
2019-10-13test: v4l2_videodevice: Add V4L2 control testLaurent Pinchart
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
/* SPDX-License-Identifier: LGPL-2.1-or-later */
/*
 * Copyright (C) 2018, Google Inc.
 *
 * media_object.h - Media Device objects: entities, pads and links.
 */
#ifndef __LIBCAMERA_INTERNAL_MEDIA_OBJECT_H__
#define __LIBCAMERA_INTERNAL_MEDIA_OBJECT_H__

#include <string>
#include <vector>

#include <linux/media.h>

#include <libcamera/base/class.h>

namespace libcamera {

class MediaDevice;
class MediaEntity;
class MediaPad;

class MediaObject
{
public:
	MediaDevice *device() { return dev_; }
	const MediaDevice *device() const { return dev_; }
	unsigned int id() const { return id_; }

protected:
	friend class MediaDevice;

	MediaObject(MediaDevice *dev, unsigned int id)
		: dev_(dev), id_(id)
	{
	}
	virtual ~MediaObject() = default;

	MediaDevice *dev_;
	unsigned int id_;
};

class MediaLink : public MediaObject
{
public:
	MediaPad *source() const { return source_; }
	MediaPad *sink() const { return sink_; }
	unsigned int flags() const { return flags_; }
	int setEnabled(bool enable);

private:
	LIBCAMERA_DISABLE_COPY_AND_MOVE(MediaLink)

	friend class MediaDevice;

	MediaLink(const struct media_v2_link *link,
		  MediaPad *source, MediaPad *sink);

	MediaPad *source_;
	MediaPad *sink_;
	unsigned int flags_;
};

class MediaPad : public MediaObject
{
public:
	unsigned int index() const { return index_; }
	MediaEntity *entity() const { return entity_; }
	unsigned int flags() const { return flags_; }
	const std::vector<MediaLink *> &links() const { return links_; }

	void addLink(MediaLink *link);

private:
	LIBCAMERA_DISABLE_COPY_AND_MOVE(MediaPad)

	friend class MediaDevice;

	MediaPad(const struct media_v2_pad *pad, MediaEntity *entity);

	unsigned int index_;
	MediaEntity *entity_;
	unsigned int flags_;

	std::vector<MediaLink *> links_;
};

class MediaEntity : public MediaObject
{
public:
	enum class Type {
		Invalid,
		MediaEntity,
		V4L2Subdevice,
		V4L2VideoDevice,
	};

	const std::string &name() const { return name_; }
	unsigned int function() const { return function_; }
	unsigned int flags() const { return flags_; }
	Type type() const { return type_; }
	const std::string &deviceNode() const { return deviceNode_; }
	unsigned int deviceMajor() const { return major_; }
	unsigned int deviceMinor() const { return minor_; }

	const std::vector<MediaPad *> &pads() const { return pads_; }

	const MediaPad *getPadByIndex(unsigned int index) const;
	const MediaPad *getPadById(unsigned int id) const;

	int setDeviceNode(const std::string &deviceNode);

private:
	LIBCAMERA_DISABLE_COPY_AND_MOVE(MediaEntity)

	friend class MediaDevice;

	MediaEntity(MediaDevice *dev, const struct media_v2_entity *entity,
		    const struct media_v2_interface *iface);

	void addPad(MediaPad *pad);

	std::string name_;
	unsigned int function_;
	unsigned int flags_;
	Type type_;
	std::string deviceNode_;
	unsigned int major_;
	unsigned int minor_;

	std::vector<MediaPad *> pads_;
};

} /* namespace libcamera */

#endif /* __LIBCAMERA_INTERNAL_MEDIA_OBJECT_H__ */