libcamera v0.5.1
Supporting cameras in Linux since 2019
Loading...
Searching...
No Matches
media_object.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: LGPL-2.1-or-later */
2/*
3 * Copyright (C) 2018, Google Inc.
4 *
5 * Media Device objects: entities, pads and links.
6 */
7
8#pragma once
9
10#include <string>
11#include <vector>
12
13#include <linux/media.h>
14
16
17namespace libcamera {
18
19class MediaDevice;
20class MediaEntity;
21class MediaPad;
22
24{
25public:
26 MediaDevice *device() { return dev_; }
27 const MediaDevice *device() const { return dev_; }
28 unsigned int id() const { return id_; }
29
30protected:
31 friend class MediaDevice;
32
33 MediaObject(MediaDevice *dev, unsigned int id)
34 : dev_(dev), id_(id)
35 {
36 }
37 virtual ~MediaObject() = default;
38
39 MediaDevice *dev_;
40 unsigned int id_;
41};
42
43class MediaLink : public MediaObject
44{
45public:
46 MediaPad *source() const { return source_; }
47 MediaPad *sink() const { return sink_; }
48 unsigned int flags() const { return flags_; }
49 int setEnabled(bool enable);
50
51 std::string toString() const;
52
53private:
55
56 friend class MediaDevice;
57
58 MediaLink(const struct media_v2_link *link,
60
61 MediaPad *source_;
62 MediaPad *sink_;
63 unsigned int flags_;
64};
65
66std::ostream &operator<<(std::ostream &out, const MediaLink &link);
67
68class MediaPad : public MediaObject
69{
70public:
71 unsigned int index() const { return index_; }
72 MediaEntity *entity() const { return entity_; }
73 unsigned int flags() const { return flags_; }
74 const std::vector<MediaLink *> &links() const { return links_; }
75
76 void addLink(MediaLink *link);
77
78 std::string toString() const;
79
80private:
82
83 friend class MediaDevice;
84
85 MediaPad(const struct media_v2_pad *pad, MediaEntity *entity);
86
87 unsigned int index_;
88 MediaEntity *entity_;
89 unsigned int flags_;
90
91 std::vector<MediaLink *> links_;
92};
93
94std::ostream &operator<<(std::ostream &out, const MediaPad &pad);
95
96class MediaEntity : public MediaObject
97{
98public:
99 enum class Type {
101 MediaEntity,
104 };
105
106 const std::string &name() const { return name_; }
107 unsigned int function() const { return function_; }
108 unsigned int flags() const { return flags_; }
109 Type type() const { return type_; }
110 const std::string &deviceNode() const { return deviceNode_; }
111 unsigned int deviceMajor() const { return major_; }
112 unsigned int deviceMinor() const { return minor_; }
113
114 const std::vector<MediaPad *> &pads() const { return pads_; }
115 const std::vector<MediaEntity *> &ancillaryEntities() const { return ancillaryEntities_; }
116
117 const MediaPad *getPadByIndex(unsigned int index) const;
118 const MediaPad *getPadById(unsigned int id) const;
119
120 int setDeviceNode(const std::string &deviceNode);
121
122private:
124
125 friend class MediaDevice;
126
127 MediaEntity(MediaDevice *dev, const struct media_v2_entity *entity,
128 const struct media_v2_interface *iface);
129
130 void addPad(MediaPad *pad);
131
132 void addAncillaryEntity(MediaEntity *ancillaryEntity);
133
134 std::string name_;
135 unsigned int function_;
136 unsigned int flags_;
137 Type type_;
138 std::string deviceNode_;
139 unsigned int major_;
140 unsigned int minor_;
141
142 std::vector<MediaPad *> pads_;
143 std::vector<MediaEntity *> ancillaryEntities_;
144};
145
146} /* namespace libcamera */
Utilities to help constructing class interfaces.
#define LIBCAMERA_DISABLE_COPY_AND_MOVE(klass)
Disable copy and move construction and assignment of the klass.
Definition class.h:29
The MediaDevice represents a Media Controller device with its full graph of connected objects.
Definition media_device.h:25
The MediaEntity represents an entity in the media graph.
Definition media_object.h:97
const std::vector< MediaEntity * > & ancillaryEntities() const
Retrieve all ancillary entities of the entity.
Definition media_object.h:115
Type type() const
Retrieve the entity's type.
Definition media_object.h:109
const std::string & deviceNode() const
Retrieve the entity's device node path, if any.
Definition media_object.h:110
unsigned int flags() const
Retrieve the entity's flags.
Definition media_object.h:108
const std::vector< MediaPad * > & pads() const
Retrieve all pads of the entity.
Definition media_object.h:114
const MediaPad * getPadById(unsigned int id) const
Get a pad in this entity by its object id.
Definition media_object.cpp:399
Type
The type of the interface exposed by the entity to userspace.
Definition media_object.h:99
@ MediaEntity
Plain media entity with no userspace interface.
Definition media_object.h:101
@ Invalid
Invalid or unsupported entity type.
Definition media_object.h:100
@ V4L2Subdevice
V4L2 subdevice with a V4L2 subdev device node.
Definition media_object.h:102
@ V4L2VideoDevice
V4L2 video device with a V4L2 video device node.
Definition media_object.h:103
unsigned int function() const
Retrieve the entity's main function.
Definition media_object.h:107
const MediaPad * getPadByIndex(unsigned int index) const
Get a pad in this entity by its index.
Definition media_object.cpp:384
unsigned int deviceMajor() const
Retrieve the major number of the interface associated with the entity.
Definition media_object.h:111
const std::string & name() const
Retrieve the entity name.
Definition media_object.h:106
unsigned int deviceMinor() const
Retrieve the minor number of the interface associated with the entity.
Definition media_object.h:112
int setDeviceNode(const std::string &deviceNode)
Set the path to the device node for the associated interface.
Definition media_object.cpp:414
Base class for all media objects.
Definition media_object.h:24
MediaObject(MediaDevice *dev, unsigned int id)
Construct a MediaObject part of the MediaDevice dev, identified by the id unique within the device.
Definition media_object.h:33
MediaDevice * dev_
The media device the media object belongs to.
Definition media_object.h:39
unsigned int id() const
Retrieve the media object id.
Definition media_object.h:28
MediaDevice * device()
Retrieve the media device the media object belongs to.
Definition media_object.h:26
const MediaDevice * device() const
Retrieve the media device the media object belongs to.
Definition media_object.h:27
unsigned int id_
The media object id.
Definition media_object.h:40
The MediaPad represents a pad of an entity in the media graph.
Definition media_object.h:69
unsigned int flags() const
Retrieve the pad flags.
Definition media_object.h:73
void addLink(MediaLink *link)
Add a new link to this pad.
Definition media_object.cpp:258
MediaEntity * entity() const
Retrieve the entity the pad belongs to.
Definition media_object.h:72
const std::vector< MediaLink * > & links() const
Retrieve all links in the pad.
Definition media_object.h:74
unsigned int index() const
Retrieve the pad index.
Definition media_object.h:71
std::string toString() const
Generate a string representation of the MediaPad.
Definition media_object.cpp:267
Top-level libcamera namespace.
Definition backtrace.h:17
std::ostream & operator<<(std::ostream &out, const Point &p)
Insert a text representation of a Point into an output stream.
Definition geometry.cpp:91