summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNiklas Söderlund <niklas.soderlund@ragnatech.se>2018-12-21 15:52:14 +0100
committerNiklas Söderlund <niklas.soderlund@ragnatech.se>2018-12-31 00:58:06 +0100
commit0eab433d057ba5ed0feffe89c9f5b67f3557fb41 (patch)
tree8b898a5ea3354162baaed6d254162b99984694f8 /src
parent723a6356c80fbcd6603ec38dfa6b32cab248822d (diff)
libcamera: device_enumerator: add DeviceInfo class
Provide a DeviceInfo class which holds all information from the initial enumeration of a media device. Not all information available at a media device is stored, only the information needed for a pipeline handler to find a specific device. Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Diffstat (limited to 'src')
-rw-r--r--src/libcamera/device_enumerator.cpp78
-rw-r--r--src/libcamera/include/device_enumerator.h44
-rw-r--r--src/libcamera/meson.build2
3 files changed, 124 insertions, 0 deletions
diff --git a/src/libcamera/device_enumerator.cpp b/src/libcamera/device_enumerator.cpp
new file mode 100644
index 00000000..83dcda94
--- /dev/null
+++ b/src/libcamera/device_enumerator.cpp
@@ -0,0 +1,78 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+/*
+ * Copyright (C) 2018, Google Inc.
+ *
+ * device_enumerator.cpp - Enumeration and matching
+ */
+
+#include "device_enumerator.h"
+#include "log.h"
+
+namespace libcamera {
+
+/* -----------------------------------------------------------------------------
+ * DeviceInfo
+ */
+
+DeviceInfo::DeviceInfo(const std::string &devnode, const struct media_device_info &info,
+ const std::map<std::string, std::string> &entities)
+ : acquired_(false), devnode_(devnode), info_(info), entities_(entities)
+{
+ for (const auto &entity : entities_)
+ LOG(Info) << "Device: " << devnode_ << " Entity: '" << entity.first << "' -> " << entity.second;
+}
+
+int DeviceInfo::acquire()
+{
+ if (acquired_)
+ return -EBUSY;
+
+ acquired_ = true;
+
+ return 0;
+}
+
+void DeviceInfo::release()
+{
+ acquired_ = false;
+}
+
+bool DeviceInfo::busy() const
+{
+ return acquired_;
+}
+
+const std::string &DeviceInfo::devnode() const
+{
+ return devnode_;
+}
+
+const struct media_device_info &DeviceInfo::info() const
+{
+ return info_;
+}
+
+std::vector<std::string> DeviceInfo::entities() const
+{
+ std::vector<std::string> entities;
+
+ for (const auto &entity : entities_)
+ entities.push_back(entity.first);
+
+ return entities;
+}
+
+int DeviceInfo::lookup(const std::string &name, std::string &devnode) const
+{
+ auto it = entities_.find(name);
+
+ if (it == entities_.end()) {
+ LOG(Error) << "Trying to lookup entity '" << name << "' which does not exist";
+ return -ENODEV;
+ }
+
+ devnode = it->second;
+ return 0;
+}
+
+} /* namespace libcamera */
diff --git a/src/libcamera/include/device_enumerator.h b/src/libcamera/include/device_enumerator.h
new file mode 100644
index 00000000..ac40bafc
--- /dev/null
+++ b/src/libcamera/include/device_enumerator.h
@@ -0,0 +1,44 @@
+/* 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_;
+};
+
+} /* namespace libcamera */
+
+#endif /* __LIBCAMERA_DEVICE_ENUMERATOR_H__ */
diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build
index 52b556a8..581da1aa 100644
--- a/src/libcamera/meson.build
+++ b/src/libcamera/meson.build
@@ -1,10 +1,12 @@
libcamera_sources = files([
'camera.cpp',
+ 'device_enumerator.cpp',
'log.cpp',
'main.cpp',
])
libcamera_headers = files([
+ 'include/device_enumerator.h',
'include/log.h',
'include/utils.h',
])