media_object.h
Go to the documentation of this file.
/* 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>
namespace libcamera {
class MediaDevice;
class MediaEntity;
class MediaPad;
class MediaObject
{
public:
MediaDevice *device() { return dev_; }
unsigned int id() const { return id_; }
protected:
friend class MediaDevice;
MediaObject(MediaDevice *dev, unsigned int id)
: dev_(dev), id_(id)
{
}
virtual ~MediaObject() {}
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:
friend class MediaDevice;
MediaLink(const struct media_v2_link *link,
MediaPad *source, MediaPad *sink);
MediaLink(const MediaLink &) = delete;
~MediaLink() {}
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:
friend class MediaDevice;
MediaPad(const struct media_v2_pad *pad, MediaEntity *entity);
MediaPad(const MediaPad &) = delete;
~MediaPad();
unsigned int index_;
MediaEntity *entity_;
unsigned int flags_;
std::vector<MediaLink *> links_;
};
class MediaEntity : public MediaObject
{
public:
const std::string &name() const { return name_; }
unsigned int function() const { return function_; }
unsigned int flags() const { return flags_; }
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:
friend class MediaDevice;
MediaEntity(MediaDevice *dev, const struct media_v2_entity *entity,
unsigned int major = 0, unsigned int minor = 0);
MediaEntity(const MediaEntity &) = delete;
~MediaEntity();
void addPad(MediaPad *pad);
std::string name_;
unsigned int function_;
unsigned int flags_;
std::string deviceNode_;
unsigned int major_;
unsigned int minor_;
std::vector<MediaPad *> pads_;
};
} /* namespace libcamera */
#endif /* __LIBCAMERA_INTERNAL_MEDIA_OBJECT_H__ */
libcamera::MediaDevice
The MediaDevice represents a Media Controller device with its full graph of connected objects.
Definition: media_device.h:25
libcamera::MediaEntity
The MediaEntity represents an entity in the media graph.
Definition: media_object.h:86
libcamera::MediaEntity::flags
unsigned int flags() const
Retrieve the entity's flags.
Definition: media_object.h:90
libcamera::MediaEntity::deviceMinor
unsigned int deviceMinor() const
Retrieve the minor number of the interface associated with the entity.
Definition: media_object.h:93
libcamera::MediaEntity::deviceNode
const std::string & deviceNode() const
Retrieve the entity's device node path, if any.
Definition: media_object.h:91
libcamera::MediaEntity::deviceMajor
unsigned int deviceMajor() const
Retrieve the major number of the interface associated with the entity.
Definition: media_object.h:92
libcamera::MediaEntity::name
const std::string & name() const
Retrieve the entity name.
Definition: media_object.h:88
libcamera::MediaEntity::getPadById
const MediaPad * getPadById(unsigned int id) const
Get a pad in this entity by its object id.
Definition: media_object.cpp:325
libcamera::MediaEntity::getPadByIndex
const MediaPad * getPadByIndex(unsigned int index) const
Get a pad in this entity by its index.
Definition: media_object.cpp:310
libcamera::MediaEntity::pads
const std::vector< MediaPad * > & pads() const
Retrieve all pads of the entity.
Definition: media_object.h:95
libcamera::MediaEntity::setDeviceNode
int setDeviceNode(const std::string &deviceNode)
Set the path to the device node for the associated interface.
Definition: media_object.cpp:340
libcamera::MediaLink
The MediaLink represents a link between two pads in the media graph.
Definition: media_object.h:41
libcamera::MediaLink::setEnabled
int setEnabled(bool enable)
Enable or disable a link.
Definition: media_object.cpp:116
libcamera::MediaLink::sink
MediaPad * sink() const
Retrieve the link's sink pad.
Definition: media_object.h:44
libcamera::MediaLink::source
MediaPad * source() const
Retrieve the link's source pad.
Definition: media_object.h:43
libcamera::MediaLink::flags
unsigned int flags() const
Retrieve the link's flags.
Definition: media_object.h:45
libcamera::MediaObject
Base class for all media objects.
Definition: media_object.h:22
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:30
libcamera::MediaObject::id_
unsigned int id_
The media object id.
Definition: media_object.h:37
libcamera::MediaObject::id
unsigned int id() const
Retrieve the media object id.
Definition: media_object.h:25
libcamera::MediaObject::dev_
MediaDevice * dev_
The media device the media object belongs to.
Definition: media_object.h:36
libcamera::MediaObject::device
MediaDevice * device()
Retrieve the media device the media object belongs to.
Definition: media_object.h:24
libcamera::MediaPad
The MediaPad represents a pad of an entity in the media graph.
Definition: media_object.h:62
libcamera::MediaPad::index
unsigned int index() const
Retrieve the pad index.
Definition: media_object.h:64
libcamera::MediaPad::addLink
void addLink(MediaLink *link)
Add a new link to this pad.
Definition: media_object.cpp:235
libcamera::MediaPad::links
const std::vector< MediaLink * > & links() const
Retrieve all links in the pad.
Definition: media_object.h:67
libcamera::MediaPad::entity
MediaEntity * entity() const
Retrieve the entity the pad belongs to.
Definition: media_object.h:65
libcamera::MediaPad::flags
unsigned int flags() const
Retrieve the pad flags.
Definition: media_object.h:66