media_device.h
Go to the documentation of this file.
/* SPDX-License-Identifier: LGPL-2.1-or-later */
/*
* Copyright (C) 2018, Google Inc.
*
* media_device.h - Media device handler
*/
#ifndef __LIBCAMERA_INTERNAL_MEDIA_DEVICE_H__
#define __LIBCAMERA_INTERNAL_MEDIA_DEVICE_H__
#include <map>
#include <sstream>
#include <string>
#include <vector>
#include <linux/media.h>
#include <libcamera/signal.h>
#include "libcamera/internal/log.h"
#include "libcamera/internal/media_object.h"
namespace libcamera {
class MediaDevice : protected Loggable
{
public:
MediaDevice(const std::string &deviceNode);
~MediaDevice();
bool acquire();
void release();
bool busy() const { return acquired_; }
bool lock();
void unlock();
int populate();
bool valid() const { return valid_; }
const std::string driver() const { return driver_; }
const std::string deviceNode() const { return deviceNode_; }
const std::string model() const { return model_; }
unsigned int version() const { return version_; }
const std::vector<MediaEntity *> &entities() const { return entities_; }
MediaEntity *getEntityByName(const std::string &name) const;
MediaLink *link(const std::string &sourceName, unsigned int sourceIdx,
const std::string &sinkName, unsigned int sinkIdx);
MediaLink *link(const MediaEntity *source, unsigned int sourceIdx,
const MediaEntity *sink, unsigned int sinkIdx);
MediaLink *link(const MediaPad *source, const MediaPad *sink);
int disableLinks();
Signal<MediaDevice *> disconnected;
protected:
std::string logPrefix() const override;
private:
int open();
void close();
MediaObject *object(unsigned int id);
bool addObject(MediaObject *object);
void clear();
struct media_v2_interface *findInterface(const struct media_v2_topology &topology,
unsigned int entityId);
bool populateEntities(const struct media_v2_topology &topology);
bool populatePads(const struct media_v2_topology &topology);
bool populateLinks(const struct media_v2_topology &topology);
void fixupEntityFlags(struct media_v2_entity *entity);
friend int MediaLink::setEnabled(bool enable);
int setupLink(const MediaLink *link, unsigned int flags);
std::string driver_;
std::string deviceNode_;
std::string model_;
unsigned int version_;
int fd_;
bool valid_;
bool acquired_;
bool lockOwner_;
std::map<unsigned int, MediaObject *> objects_;
std::vector<MediaEntity *> entities_;
};
} /* namespace libcamera */
#endif /* __LIBCAMERA_INTERNAL_MEDIA_DEVICE_H__ */
libcamera::Loggable
Base class to support log message extensions.
Definition: log.h:83
libcamera::MediaDevice
The MediaDevice represents a Media Controller device with its full graph of connected objects.
Definition: media_device.h:25
libcamera::MediaDevice::acquire
bool acquire()
Claim a device for exclusive use.
Definition: media_device.cpp:105
libcamera::MediaDevice::logPrefix
std::string logPrefix() const override
Retrieve a string to be prefixed to the log message.
Definition: media_device.cpp:78
libcamera::MediaDevice::disableLinks
int disableLinks()
Disable all links in the media device.
Definition: media_device.cpp:434
libcamera::MediaDevice::release
void release()
Release a device previously claimed for exclusive use.
Definition: media_device.cpp:121
libcamera::MediaDevice::disconnected
Signal< MediaDevice * > disconnected
Signal emitted when the media device is disconnected from the system.
Definition: media_device.h:55
libcamera::MediaDevice::driver
const std::string driver() const
Retrieve the media device driver name.
Definition: media_device.h:40
libcamera::MediaDevice::model
const std::string model() const
Retrieve the media device model name.
Definition: media_device.h:42
libcamera::MediaDevice::populate
int populate()
Populate the MediaDevice with device information and media objects.
Definition: media_device.cpp:206
libcamera::MediaDevice::deviceNode
const std::string deviceNode() const
Retrieve the media device node path.
Definition: media_device.h:41
libcamera::MediaDevice::lock
bool lock()
Lock the device to prevent it from being used by other instances of libcamera.
Definition: media_device.cpp:144
libcamera::MediaDevice::link
MediaLink * link(const std::string &sourceName, unsigned int sourceIdx, const std::string &sinkName, unsigned int sinkIdx)
Retrieve the MediaLink connecting two pads, identified by entity names and pad indexes.
Definition: media_device.cpp:364
libcamera::MediaDevice::MediaDevice
MediaDevice(const std::string &deviceNode)
Construct a MediaDevice.
Definition: media_device.cpp:65
libcamera::MediaDevice::entities
const std::vector< MediaEntity * > & entities() const
Retrieve the list of entities in the media graph.
Definition: media_device.h:45
libcamera::MediaDevice::getEntityByName
MediaEntity * getEntityByName(const std::string &name) const
Return the MediaEntity with name name.
Definition: media_device.cpp:337
libcamera::MediaDevice::busy
bool busy() const
Check if a device is in use.
Definition: media_device.h:32
libcamera::MediaDevice::valid
bool valid() const
Query whether the media graph has been populated and is valid.
Definition: media_device.h:38
libcamera::MediaDevice::unlock
void unlock()
Unlock the device and free it for use for libcamera instances.
Definition: media_device.cpp:170
libcamera::MediaDevice::version
unsigned int version() const
Retrieve the media device API version.
Definition: media_device.h:43
libcamera::MediaEntity
The MediaEntity represents an entity in the media graph.
Definition: media_object.h:86
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::MediaObject
Base class for all media objects.
Definition: media_object.h:22
libcamera::MediaPad
The MediaPad represents a pad of an entity in the media graph.
Definition: media_object.h:62
libcamera::Signal
Generic signal and slot communication mechanism.
Definition: signal.h:39
log.h
Logging infrastructure.
media_object.h
Provides a class hierarchy that represents the media objects exposed by the Linux kernel Media Contro...
signal.h
Signal & slot implementation.