@@ -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);
@@ -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;
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(-)