libcamera v0.3.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
15#include <libcamera/base/class.h>
16
17 namespace libcamera {
18
19 class MediaDevice;
20 class MediaEntity;
21 class MediaPad;
22
23 class MediaObject
24{
25 public:
26 MediaDevice *device() { return dev_; }
27 const MediaDevice *device() const { return dev_; }
28 unsigned int id() const { return id_; }
29
30 protected:
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
43 class MediaLink : public MediaObject
44{
45 public:
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 private:
52 LIBCAMERA_DISABLE_COPY_AND_MOVE(MediaLink)
53
54 friend class MediaDevice;
55
56 MediaLink(const struct media_v2_link *link,
57 MediaPad *source, MediaPad *sink);
58
59 MediaPad *source_;
60 MediaPad *sink_;
61 unsigned int flags_;
62};
63
64 class MediaPad : public MediaObject
65{
66 public:
67 unsigned int index() const { return index_; }
68 MediaEntity *entity() const { return entity_; }
69 unsigned int flags() const { return flags_; }
70 const std::vector<MediaLink *> &links() const { return links_; }
71
72 void addLink(MediaLink *link);
73
74 private:
75 LIBCAMERA_DISABLE_COPY_AND_MOVE(MediaPad)
76
77 friend class MediaDevice;
78
79 MediaPad(const struct media_v2_pad *pad, MediaEntity *entity);
80
81 unsigned int index_;
82 MediaEntity *entity_;
83 unsigned int flags_;
84
85 std::vector<MediaLink *> links_;
86};
87
88 class MediaEntity : public MediaObject
89{
90 public:
91 enum class Type {
92 Invalid,
93 MediaEntity,
94 V4L2Subdevice,
95 V4L2VideoDevice,
96 };
97
98 const std::string &name() const { return name_; }
99 unsigned int function() const { return function_; }
100 unsigned int flags() const { return flags_; }
101 Type type() const { return type_; }
102 const std::string &deviceNode() const { return deviceNode_; }
103 unsigned int deviceMajor() const { return major_; }
104 unsigned int deviceMinor() const { return minor_; }
105
106 const std::vector<MediaPad *> &pads() const { return pads_; }
107 const std::vector<MediaEntity *> ancillaryEntities() const { return ancillaryEntities_; }
108
109 const MediaPad *getPadByIndex(unsigned int index) const;
110 const MediaPad *getPadById(unsigned int id) const;
111
112 int setDeviceNode(const std::string &deviceNode);
113
114 private:
115 LIBCAMERA_DISABLE_COPY_AND_MOVE(MediaEntity)
116
117 friend class MediaDevice;
118
119 MediaEntity(MediaDevice *dev, const struct media_v2_entity *entity,
120 const struct media_v2_interface *iface);
121
122 void addPad(MediaPad *pad);
123
124 void addAncillaryEntity(MediaEntity *ancillaryEntity);
125
126 std::string name_;
127 unsigned int function_;
128 unsigned int flags_;
129 Type type_;
130 std::string deviceNode_;
131 unsigned int major_;
132 unsigned int minor_;
133
134 std::vector<MediaPad *> pads_;
135 std::vector<MediaEntity *> ancillaryEntities_;
136};
137
138} /* namespace libcamera */
class.h
Utilities to help constructing class interfaces.
LIBCAMERA_DISABLE_COPY_AND_MOVE
#define LIBCAMERA_DISABLE_COPY_AND_MOVE(klass)
Disable copy and move construction and assignment of the klass.
Definition class.h:29
libcamera::MediaDevice
The MediaDevice represents a Media Controller device with its full graph of connected objects.
Definition media_device.h:26
libcamera::MediaEntity
The MediaEntity represents an entity in the media graph.
Definition media_object.h:89
libcamera::MediaEntity::type
Type type() const
Retrieve the entity's type.
Definition media_object.h:101
libcamera::MediaEntity::deviceNode
const std::string & deviceNode() const
Retrieve the entity's device node path, if any.
Definition media_object.h:102
libcamera::MediaEntity::flags
unsigned int flags() const
Retrieve the entity's flags.
Definition media_object.h:100
libcamera::MediaEntity::pads
const std::vector< MediaPad * > & pads() const
Retrieve all pads of the entity.
Definition media_object.h:106
libcamera::MediaEntity::getPadById
const MediaPad * getPadById(unsigned int id) const
Get a pad in this entity by its object id.
Definition media_object.cpp:349
libcamera::MediaEntity::Type
Type
The type of the interface exposed by the entity to userspace.
Definition media_object.h:91
libcamera::MediaEntity::Type::MediaEntity
@ MediaEntity
Plain media entity with no userspace interface.
libcamera::MediaEntity::Type::Invalid
@ Invalid
Invalid or unsupported entity type.
libcamera::MediaEntity::Type::V4L2Subdevice
@ V4L2Subdevice
V4L2 subdevice with a V4L2 subdev device node.
libcamera::MediaEntity::Type::V4L2VideoDevice
@ V4L2VideoDevice
V4L2 video device with a V4L2 video device node.
libcamera::MediaEntity::function
unsigned int function() const
Retrieve the entity's main function.
Definition media_object.h:99
libcamera::MediaEntity::getPadByIndex
const MediaPad * getPadByIndex(unsigned int index) const
Get a pad in this entity by its index.
Definition media_object.cpp:334
libcamera::MediaEntity::deviceMajor
unsigned int deviceMajor() const
Retrieve the major number of the interface associated with the entity.
Definition media_object.h:103
libcamera::MediaEntity::name
const std::string & name() const
Retrieve the entity name.
Definition media_object.h:98
libcamera::MediaEntity::deviceMinor
unsigned int deviceMinor() const
Retrieve the minor number of the interface associated with the entity.
Definition media_object.h:104
libcamera::MediaEntity::ancillaryEntities
const std::vector< MediaEntity * > ancillaryEntities() const
Retrieve all ancillary entities of the entity.
Definition media_object.h:107
libcamera::MediaEntity::setDeviceNode
int setDeviceNode(const std::string &deviceNode)
Set the path to the device node for the associated interface.
Definition media_object.cpp:364
libcamera::MediaLink
The MediaLink represents a link between two pads in the media graph.
Definition media_object.h:44
libcamera::MediaLink::source
MediaPad * source() const
Retrieve the link's source pad.
Definition media_object.h:46
libcamera::MediaLink::sink
MediaPad * sink() const
Retrieve the link's sink pad.
Definition media_object.h:47
libcamera::MediaLink::setEnabled
int setEnabled(bool enable)
Enable or disable a link.
Definition media_object.cpp:122
libcamera::MediaLink::flags
unsigned int flags() const
Retrieve the link's flags.
Definition media_object.h:48
libcamera::MediaObject
Base class for all media objects.
Definition media_object.h:24
libcamera::MediaObject::MediaObject
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
libcamera::MediaObject::dev_
MediaDevice * dev_
The media device the media object belongs to.
Definition media_object.h:39
libcamera::MediaObject::id
unsigned int id() const
Retrieve the media object id.
Definition media_object.h:28
libcamera::MediaObject::device
MediaDevice * device()
Retrieve the media device the media object belongs to.
Definition media_object.h:26
libcamera::MediaObject::device
const MediaDevice * device() const
Retrieve the media device the media object belongs to.
Definition media_object.h:27
libcamera::MediaObject::id_
unsigned int id_
The media object id.
Definition media_object.h:40
libcamera::MediaPad
The MediaPad represents a pad of an entity in the media graph.
Definition media_object.h:65
libcamera::MediaPad::flags
unsigned int flags() const
Retrieve the pad flags.
Definition media_object.h:69
libcamera::MediaPad::addLink
void addLink(MediaLink *link)
Add a new link to this pad.
Definition media_object.cpp:233
libcamera::MediaPad::entity
MediaEntity * entity() const
Retrieve the entity the pad belongs to.
Definition media_object.h:68
libcamera::MediaPad::links
const std::vector< MediaLink * > & links() const
Retrieve all links in the pad.
Definition media_object.h:70
libcamera::MediaPad::index
unsigned int index() const
Retrieve the pad index.
Definition media_object.h:67
libcamera
Top-level libcamera namespace.
Definition backtrace.h:17