libcamera  v0.0.0+100-debian/0_git20200629+e7aa92a-8-9-g77f5237c-dirty (2021-05-05T16:20:29+01:00)
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 #include <libcamera/class.h>
16 
17 namespace libcamera {
18 
19 class MediaDevice;
20 class MediaEntity;
21 class MediaPad;
22 
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 
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:
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:
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  const std::string &name() const { return name_; }
92  unsigned int function() const { return function_; }
93  unsigned int flags() const { return flags_; }
94  const std::string &deviceNode() const { return deviceNode_; }
95  unsigned int deviceMajor() const { return major_; }
96  unsigned int deviceMinor() const { return minor_; }
97 
98  const std::vector<MediaPad *> &pads() const { return pads_; }
99 
100  const MediaPad *getPadByIndex(unsigned int index) const;
101  const MediaPad *getPadById(unsigned int id) const;
102 
103  int setDeviceNode(const std::string &deviceNode);
104 
105 private:
107 
108  friend class MediaDevice;
109 
110  MediaEntity(MediaDevice *dev, const struct media_v2_entity *entity,
111  unsigned int major = 0, unsigned int minor = 0);
112 
113  void addPad(MediaPad *pad);
114 
115  std::string name_;
116  unsigned int function_;
117  unsigned int flags_;
118  std::string deviceNode_;
119  unsigned int major_;
120  unsigned int minor_;
121 
122  std::vector<MediaPad *> pads_;
123 };
124 
125 } /* namespace libcamera */
126 
127 #endif /* __LIBCAMERA_INTERNAL_MEDIA_OBJECT_H__ */
Utilities to help constructing class interfaces.
unsigned int id_
The media object id.
Definition: media_object.h:40
The MediaDevice represents a Media Controller device with its full graph of connected objects...
Definition: media_device.h:24
const std::vector< MediaPad * > & pads() const
Retrieve all pads of the entity.
Definition: media_object.h:98
const std::vector< MediaLink * > & links() const
Retrieve all links in the pad.
Definition: media_object.h:70
Top-level libcamera namespace.
Definition: bound_method.h:15
unsigned int flags() const
Retrieve the pad flags.
Definition: media_object.h:69
unsigned int deviceMinor() const
Retrieve the minor number of the interface associated with the entity.
Definition: media_object.h:96
const std::string & deviceNode() const
Retrieve the entity&#39;s device node path, if any.
Definition: media_object.h:94
MediaEntity * entity() const
Retrieve the entity the pad belongs to.
Definition: media_object.h:68
Base class for all media objects.
Definition: media_object.h:23
The MediaEntity represents an entity in the media graph.
Definition: media_object.h:88
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
#define LIBCAMERA_DISABLE_COPY_AND_MOVE(klass)
Disable copy and move construction and assignment of the klass.
const MediaDevice * device() const
Retrieve the media device the media object belongs to.
Definition: media_object.h:27
MediaDevice * device()
Retrieve the media device the media object belongs to.
Definition: media_object.h:26
unsigned int flags() const
Retrieve the entity&#39;s flags.
Definition: media_object.h:93
unsigned int deviceMajor() const
Retrieve the major number of the interface associated with the entity.
Definition: media_object.h:95
MediaDevice * dev_
The media device the media object belongs to.
Definition: media_object.h:39
const std::string & name() const
Retrieve the entity name.
Definition: media_object.h:91
unsigned int index() const
Retrieve the pad index.
Definition: media_object.h:67
unsigned int id() const
Retrieve the media object id.
Definition: media_object.h:28
The MediaPad represents a pad of an entity in the media graph.
Definition: media_object.h:64