[2/3] libcamera: device_enumerator_udev: Add initMediaDevice()
diff mbox series

Message ID 20250820132316.1033443-3-dan.scally@ideasonboard.com
State New
Headers show
Series
  • Fix fast-booting device enumeration problems
Related show

Commit Message

Dan Scally Aug. 20, 2025, 1:23 p.m. UTC
We will shortly be processing MediaDevices created by the device
enumerator in two places if they're initially deferreed. Move the
steps to a dedicated function so it can be called from multiple
places.

Signed-off-by: Daniel Scally <dan.scally@ideasonboard.com>
---
 .../internal/device_enumerator_udev.h         |  1 +
 src/libcamera/device_enumerator_udev.cpp      | 58 ++++++++++---------
 2 files changed, 33 insertions(+), 26 deletions(-)

Patch
diff mbox series

diff --git a/include/libcamera/internal/device_enumerator_udev.h b/include/libcamera/internal/device_enumerator_udev.h
index 1378c1906..a5e5e6efe 100644
--- a/include/libcamera/internal/device_enumerator_udev.h
+++ b/include/libcamera/internal/device_enumerator_udev.h
@@ -56,6 +56,7 @@  private:
 
 	int addUdevDevice(struct udev_device *dev);
 	int populateMediaDevice(MediaDevice *media, DependencyMap *deps);
+	int initMediaDevice(std::unique_ptr<MediaDevice> media);
 	std::string lookupDeviceNode(dev_t devnum);
 
 	int addV4L2Device(dev_t devnum);
diff --git a/src/libcamera/device_enumerator_udev.cpp b/src/libcamera/device_enumerator_udev.cpp
index 4e20a3cc0..53b4fac80 100644
--- a/src/libcamera/device_enumerator_udev.cpp
+++ b/src/libcamera/device_enumerator_udev.cpp
@@ -82,32 +82,7 @@  int DeviceEnumeratorUdev::addUdevDevice(struct udev_device *dev)
 		if (!media)
 			return -ENODEV;
 
-		DependencyMap deps;
-		int ret = populateMediaDevice(media.get(), &deps);
-		if (ret < 0) {
-			LOG(DeviceEnumerator, Warning)
-				<< "Failed to populate media device "
-				<< media->deviceNode()
-				<< " (" << media->driver() << "), skipping";
-			return ret;
-		}
-
-		if (!deps.empty()) {
-			LOG(DeviceEnumerator, Debug)
-				<< "Defer media device " << media->deviceNode()
-				<< " due to " << deps.size()
-				<< " missing dependencies";
-
-			pending_.emplace_back(std::move(media), std::move(deps));
-			MediaDeviceDeps *mediaDeps = &pending_.back();
-			for (const auto &dep : mediaDeps->deps_)
-				devMap_[dep.first] = mediaDeps;
-
-			return 0;
-		}
-
-		addDevice(std::move(media));
-		return 0;
+		return initMediaDevice(std::move(media));
 	}
 
 	if (!strcmp(subsystem, "video4linux")) {
@@ -194,6 +169,37 @@  done:
 	return 0;
 }
 
+int DeviceEnumeratorUdev::initMediaDevice(std::unique_ptr<MediaDevice> media)
+{
+	DependencyMap deps;
+
+	int ret = populateMediaDevice(media.get(), &deps);
+	if (ret < 0) {
+		LOG(DeviceEnumerator, Warning)
+			<< "Failed to populate media device "
+			<< media->deviceNode()
+			<< " (" << media->driver() << "), skipping";
+		return ret;
+	}
+
+	if (!deps.empty()) {
+		LOG(DeviceEnumerator, Debug)
+			<< "Defer media device " << media->deviceNode()
+			<< " due to " << deps.size()
+			<< " missing dependencies";
+
+		pending_.emplace_back(std::move(media), std::move(deps));
+		MediaDeviceDeps *mediaDeps = &pending_.back();
+		for (const auto &dep : mediaDeps->deps_)
+			devMap_[dep.first] = mediaDeps;
+
+		return 0;
+	}
+
+	addDevice(std::move(media));
+	return 0;
+}
+
 int DeviceEnumeratorUdev::populateMediaDevice(MediaDevice *media, DependencyMap *deps)
 {
 	std::set<dev_t> children;