@@ -45,6 +45,7 @@ public:
virtual int enumerate() = 0;
std::shared_ptr<MediaDevice> search(const DeviceMatch &dm);
+ std::vector<std::shared_ptr<MediaDevice>> searchAll(const DeviceMatch &dm) const;
Signal<> devicesAdded;
@@ -362,4 +362,35 @@ std::shared_ptr<MediaDevice> DeviceEnumerator::search(const DeviceMatch &dm)
return nullptr;
}
+/**
+ * \brief Search available media devices for all pattern matches
+ * \param[in] dm Search pattern
+ *
+ * Search in the enumerated media devices that are not already in use for
+ * matches described in \a dm. Unlike search(), all matching media devices are
+ * returned instead of the first match only. The caller shall not use the
+ * returned devices for capture without acquiring them first.
+ *
+ * \return A vector of matching MediaDevice instances, empty if no match is
+ * found
+ */
+std::vector<std::shared_ptr<MediaDevice>> DeviceEnumerator::searchAll(const DeviceMatch &dm) const
+{
+ std::vector<std::shared_ptr<MediaDevice>> matches;
+
+ for (const std::shared_ptr<MediaDevice> &media : devices_) {
+ if (media->busy())
+ continue;
+
+ if (dm.match(media.get())) {
+ LOG(DeviceEnumerator, Debug)
+ << "Successful match for media device \""
+ << media->driver() << "\"";
+ matches.push_back(media);
+ }
+ }
+
+ return matches;
+}
+
} /* namespace libcamera */
Add a searchAll() function that returns all media devices matching a DeviceMatch instead of the first match only. Unlike the acquire and advance behaviour used with search() in pipeline handler match() implementations, searchAll() allows callers to inspect every matching media device without acquiring any of them. This will be used by future commits for device enumeration. Signed-off-by: Naushir Patuck <naush@raspberrypi.com> --- .../libcamera/internal/device_enumerator.h | 1 + src/libcamera/device_enumerator.cpp | 31 +++++++++++++++++++ 2 files changed, 32 insertions(+)