blob: 5348e6cf583dbd1525f708ad80daf6a6fd624c2f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
/* SPDX-License-Identifier: LGPL-2.1-or-later */
/*
* Copyright (C) 2018, Google Inc.
*
* device_enumerator.h - API to enumerate and find media devices
*/
#ifndef __LIBCAMERA_DEVICE_ENUMERATOR_H__
#define __LIBCAMERA_DEVICE_ENUMERATOR_H__
#include <map>
#include <string>
#include <vector>
#include <linux/media.h>
namespace libcamera {
class DeviceInfo
{
public:
DeviceInfo(const std::string &devnode, const struct media_device_info &info,
const std::map<std::string, std::string> &entities);
int acquire();
void release();
bool busy() const;
const std::string &devnode() const;
const struct media_device_info &info() const;
std::vector<std::string> entities() const;
int lookup(const std::string &name, std::string &devnode) const;
private:
bool acquired_;
std::string devnode_;
struct media_device_info info_;
std::map<std::string, std::string> entities_;
};
class DeviceMatch
{
public:
DeviceMatch(const std::string &driver);
void add(const std::string &entity);
bool match(const DeviceInfo *info) const;
private:
std::string driver_;
std::vector<std::string> entities_;
};
class DeviceEnumerator
{
public:
virtual ~DeviceEnumerator();
virtual int init() = 0;
virtual int enumerate() = 0;
DeviceInfo *search(DeviceMatch &dm) const;
protected:
int addDevice(const std::string &devnode);
private:
std::vector<DeviceInfo *> devices_;
int readInfo(int fd, struct media_device_info &info);
int readTopology(int fd, std::map<std::string, std::string> &entities);
virtual std::string lookupDevnode(int major, int minor) = 0;
};
class DeviceEnumeratorUdev: public DeviceEnumerator
{
public:
DeviceEnumeratorUdev();
~DeviceEnumeratorUdev();
int init() final;
int enumerate() final;
private:
struct udev *udev_;
std::string lookupDevnode(int major, int minor) final;
};
} /* namespace libcamera */
#endif /* __LIBCAMERA_DEVICE_ENUMERATOR_H__ */
|