libcamera: include/libcamera/internal/media_device.h Source File

libcamera v0.2.0 Supporting cameras in Linux since 2019

Loading...
Searching...
No Matches
media_device.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.h - Media device handler
6 */
7
8#pragma once
9
10#include <map>
11#include <sstream>
12#include <string>
13#include <vector>
14
15#include <linux/media.h>
16
17#include <libcamera/base/log.h>
18#include <libcamera/base/signal.h>
19#include <libcamera/base/unique_fd.h>
20
21#include "libcamera/internal/media_object.h"
22
23namespace libcamera {
24
25 class MediaDevice : protected Loggable
26{
27public:
28 MediaDevice(const std::string &deviceNode);
29 ~MediaDevice();
30
31 bool acquire();
32 void release();
33 bool busy() const { return acquired_; }
34
35 bool lock();
36 void unlock();
37
38 int populate();
39 bool isValid() const { return valid_; }
40
41 const std::string &driver() const { return driver_; }
42 const std::string &deviceNode() const { return deviceNode_; }
43 const std::string &model() const { return model_; }
44 unsigned int version() const { return version_; }
45 unsigned int hwRevision() const { return hwRevision_; }
46
47 const std::vector<MediaEntity *> &entities() const { return entities_; }
48 MediaEntity *getEntityByName(const std::string &name) const;
49
50 MediaLink *link(const std::string &sourceName, unsigned int sourceIdx,
51 const std::string &sinkName, unsigned int sinkIdx);
52 MediaLink *link(const MediaEntity *source, unsigned int sourceIdx,
53 const MediaEntity *sink, unsigned int sinkIdx);
54 MediaLink *link(const MediaPad *source, const MediaPad *sink);
55 int disableLinks();
56
57 Signal<> disconnected;
58
59protected:
60 std::string logPrefix() const override;
61
62private:
63 int open();
64 void close();
65
66 MediaObject *object(unsigned int id);
67 bool addObject(MediaObject *object);
68 void clear();
69
70 struct media_v2_interface *findInterface(const struct media_v2_topology &topology,
71 unsigned int entityId);
72 bool populateEntities(const struct media_v2_topology &topology);
73 bool populatePads(const struct media_v2_topology &topology);
74 bool populateLinks(const struct media_v2_topology &topology);
75 void fixupEntityFlags(struct media_v2_entity *entity);
76
77 friend int MediaLink::setEnabled(bool enable);
78 int setupLink(const MediaLink *link, unsigned int flags);
79
80 std::string driver_;
81 std::string deviceNode_;
82 std::string model_;
83 unsigned int version_;
84 unsigned int hwRevision_;
85
86 UniqueFD fd_;
87 bool valid_;
88 bool acquired_;
89
90 std::map<unsigned int, MediaObject *> objects_;
91 std::vector<MediaEntity *> entities_;
92};
93
94} /* namespace libcamera */
libcamera::Loggable
Base class to support log message extensions.
Definition log.h:91
libcamera::MediaDevice
The MediaDevice represents a Media Controller device with its full graph of connected objects.
Definition media_device.h:26
libcamera::MediaDevice::acquire
bool acquire()
Claim a device for exclusive use.
Definition media_device.cpp:103
libcamera::MediaDevice::logPrefix
std::string logPrefix() const override
Retrieve a string to be prefixed to the log message.
Definition media_device.cpp:76
libcamera::MediaDevice::disableLinks
int disableLinks()
Disable all links in the media device.
Definition media_device.cpp:435
libcamera::MediaDevice::release
void release()
Release a device previously claimed for exclusive use.
Definition media_device.cpp:119
libcamera::MediaDevice::disconnected
Signal disconnected
Signal emitted when the media device is disconnected from the system.
Definition media_device.h:57
libcamera::MediaDevice::driver
const std::string & driver() const
Retrieve the media device driver name.
Definition media_device.h:41
libcamera::MediaDevice::isValid
bool isValid() const
Query whether the media graph has been populated and is valid.
Definition media_device.h:39
libcamera::MediaDevice::model
const std::string & model() const
Retrieve the media device model name.
Definition media_device.h:43
libcamera::MediaDevice::populate
int populate()
Populate the MediaDevice with device information and media objects.
Definition media_device.cpp:193
libcamera::MediaDevice::deviceNode
const std::string & deviceNode() const
Retrieve the media device node path.
Definition media_device.h:42
libcamera::MediaDevice::lock
bool lock()
Lock the device to prevent it from being used by other instances of libcamera.
Definition media_device.cpp:142
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:362
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:47
libcamera::MediaDevice::getEntityByName
MediaEntity * getEntityByName(const std::string &name) const
Return the MediaEntity with name name.
Definition media_device.cpp:334
libcamera::MediaDevice::busy
bool busy() const
Check if a device is in use.
Definition media_device.h:33
libcamera::MediaDevice::hwRevision
unsigned int hwRevision() const
Retrieve the media device hardware revision.
Definition media_device.h:45
libcamera::MediaDevice::unlock
void unlock()
Unlock the device and free it for use for libcamera instances.
Definition media_device.cpp:162
libcamera::MediaDevice::version
unsigned int version() const
Retrieve the media device API version.
Definition media_device.h:44
libcamera::MediaEntity
The MediaEntity represents an entity in the media graph.
Definition media_object.h:89
libcamera::MediaLink
The MediaLink represents a link between two pads in the media graph.
Definition media_object.h:44
libcamera::MediaLink::setEnabled
int setEnabled(bool enable)
Enable or disable a link.
Definition media_object.cpp:122
libcamera::MediaObject
Base class for all media objects.
Definition media_object.h:24
libcamera::MediaPad
The MediaPad represents a pad of an entity in the media graph.
Definition media_object.h:65
libcamera::Signal
Generic signal and slot communication mechanism.
Definition signal.h:39
libcamera::UniqueFD
unique_ptr-like wrapper for a file descriptor
Definition unique_fd.h:18
log.h
Logging infrastructure.
media_object.h
Provides a class hierarchy that represents the media objects exposed by the Linux kernel Media Contro...
libcamera
Top-level libcamera namespace.
Definition backtrace.h:17
signal.h
Signal & slot implementation.
unique_fd.h
File descriptor wrapper that owns a file descriptor.