libcamera  v0.0.0
Supporting cameras in Linux since 2019
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_object.h - Media Device objects: entities, pads and links.
6  */
7 #ifndef __LIBCAMERA_INTERNAL_MEDIA_OBJECT_H__
8 #define __LIBCAMERA_INTERNAL_MEDIA_OBJECT_H__
9 
10 #include <string>
11 #include <vector>
12 
13 #include <linux/media.h>
14 
15 namespace libcamera {
16 
17 class MediaDevice;
18 class MediaEntity;
19 class MediaPad;
20 
22 {
23 public:
24  MediaDevice *device() { return dev_; }
25  unsigned int id() const { return id_; }
26 
27 protected:
28  friend class MediaDevice;
29 
30  MediaObject(MediaDevice *dev, unsigned int id)
31  : dev_(dev), id_(id)
32  {
33  }
34  virtual ~MediaObject() {}
35 
37  unsigned int id_;
38 };
39 
40 class MediaLink : public MediaObject
41 {
42 public:
43  MediaPad *source() const { return source_; }
44  MediaPad *sink() const { return sink_; }
45  unsigned int flags() const { return flags_; }
46  int setEnabled(bool enable);
47 
48 private:
49  friend class MediaDevice;
50 
51  MediaLink(const struct media_v2_link *link,
53  MediaLink(const MediaLink &) = delete;
54  ~MediaLink() {}
55 
56  MediaPad *source_;
57  MediaPad *sink_;
58  unsigned int flags_;
59 };
60 
61 class MediaPad : public MediaObject
62 {
63 public:
64  unsigned int index() const { return index_; }
65  MediaEntity *entity() const { return entity_; }
66  unsigned int flags() const { return flags_; }
67  const std::vector<MediaLink *> &links() const { return links_; }
68 
69  void addLink(MediaLink *link);
70 
71 private:
72  friend class MediaDevice;
73 
74  MediaPad(const struct media_v2_pad *pad, MediaEntity *entity);
75  MediaPad(const MediaPad &) = delete;
76  ~MediaPad();
77 
78  unsigned int index_;
79  MediaEntity *entity_;
80  unsigned int flags_;
81 
82  std::vector<MediaLink *> links_;
83 };
84 
85 class MediaEntity : public MediaObject
86 {
87 public:
88  const std::string &name() const { return name_; }
89  unsigned int function() const { return function_; }
90  unsigned int flags() const { return flags_; }
91  const std::string &deviceNode() const { return deviceNode_; }
92  unsigned int deviceMajor() const { return major_; }
93  unsigned int deviceMinor() const { return minor_; }
94 
95  const std::vector<MediaPad *> &pads() const { return pads_; }
96 
97  const MediaPad *getPadByIndex(unsigned int index) const;
98  const MediaPad *getPadById(unsigned int id) const;
99 
100  int setDeviceNode(const std::string &deviceNode);
101 
102 private:
103  friend class MediaDevice;
104 
105  MediaEntity(MediaDevice *dev, const struct media_v2_entity *entity,
106  unsigned int major = 0, unsigned int minor = 0);
107  MediaEntity(const MediaEntity &) = delete;
108  ~MediaEntity();
109 
110  void addPad(MediaPad *pad);
111 
112  std::string name_;
113  unsigned int function_;
114  unsigned int flags_;
115  std::string deviceNode_;
116  unsigned int major_;
117  unsigned int minor_;
118 
119  std::vector<MediaPad *> pads_;
120 };
121 
122 } /* namespace libcamera */
123 
124 #endif /* __LIBCAMERA_INTERNAL_MEDIA_OBJECT_H__ */
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:86
unsigned int flags() const
Retrieve the entity's flags.
Definition: media_object.h:90
unsigned int deviceMinor() const
Retrieve the minor number of the interface associated with the entity.
Definition: media_object.h:93
const std::string & deviceNode() const
Retrieve the entity's device node path, if any.
Definition: media_object.h:91
unsigned int deviceMajor() const
Retrieve the major number of the interface associated with the entity.
Definition: media_object.h:92
const std::string & name() const
Retrieve the entity name.
Definition: media_object.h:88
const MediaPad * getPadById(unsigned int id) const
Get a pad in this entity by its object id.
Definition: media_object.cpp:325
const MediaPad * getPadByIndex(unsigned int index) const
Get a pad in this entity by its index.
Definition: media_object.cpp:310
const std::vector< MediaPad * > & pads() const
Retrieve all pads of the entity.
Definition: media_object.h:95
int setDeviceNode(const std::string &deviceNode)
Set the path to the device node for the associated interface.
Definition: media_object.cpp:340
Base class for all media objects.
Definition: media_object.h:22
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:30
unsigned int id_
The media object id.
Definition: media_object.h:37
unsigned int id() const
Retrieve the media object id.
Definition: media_object.h:25
MediaDevice * dev_
The media device the media object belongs to.
Definition: media_object.h:36
MediaDevice * device()
Retrieve the media device the media object belongs to.
Definition: media_object.h:24
The MediaPad represents a pad of an entity in the media graph.
Definition: media_object.h:62
unsigned int index() const
Retrieve the pad index.
Definition: media_object.h:64
void addLink(MediaLink *link)
Add a new link to this pad.
Definition: media_object.cpp:235
const std::vector< MediaLink * > & links() const
Retrieve all links in the pad.
Definition: media_object.h:67
MediaEntity * entity() const
Retrieve the entity the pad belongs to.
Definition: media_object.h:65
unsigned int flags() const
Retrieve the pad flags.
Definition: media_object.h:66