@@ -2082,7 +2082,20 @@ bool SimplePipelineHandler::matchDevice(std::shared_ptr<MediaDevice> media,
registered = true;
}
- return registered;
+ if (!registered)
+ return false;
+
+ /*
+ * Enable hot-unplug notifications. Platform media devices go away
+ * when their driver is unbound, and the cameras have to be
+ * unregistered then, or they would clash with the cameras created
+ * when the driver is bound again.
+ */
+ hotplugMediaDevice(media);
+ if (converter_)
+ hotplugMediaDevice(converter_);
+
+ return true;
}
bool SimplePipelineHandler::match(DeviceEnumerator *enumerator)
The simple pipeline handler does not call hotplugMediaDevice(), so its cameras stay registered when their media device goes away, for instance when the driver is unbound. If the media device comes back, the new instance yields a camera with the same ID. Before commit 50858dc3 ("libcamera: camera_manager: Non-fatal duplicate id detection") this aborted the process, as seen in WirePlumber on a Dell XPS 9315 (Intel IPU6) when the media device and its V4L2 nodes were removed and added again with synthetic udev events: FATAL Camera camera_manager.cpp:213 Trying to register a camera with a duplicated ID '\_SB_.PC00.LNK1' Now the new camera is dropped instead, and the stale one stays. With a real driver unbind on the same laptop (intel_ipu6_isys) and libcamera 0.7.2, the enumerator removes /dev/media0, DEBUG DeviceEnumerator device_enumerator.cpp:331 Media device for node /dev/media0 removed. but PipeWire keeps listing the camera, and the stale camera keeps its V4L2 device nodes open. After binding the driver again, only four of the six V4L2 subdevices came back (CSI2 0-3, numbered 0, 1, 3 and 6), the IVSC CSI and sensor subdevices were missing, and no camera was added. When WirePlumber closed the stale handles at shutdown, the kernel crashed in v4l2_release() (a separate kernel bug, the IPU6 driver frees its video devices on unbind while they are open [1]). Enable hot-unplug notifications for the media device, and for the converter if one is used, once a camera has been registered, like the UVC pipeline handler does. With this change, on the same laptop and in the same test (2 of 2 runs), the camera is removed when intel_ipu6_isys is unbound, and after binding it again all six subdevices are back and the camera is added again in the same WirePlumber process: DEBUG DeviceEnumerator device_enumerator.cpp:333 Media device for node /dev/media0 removed. INFO Camera camera_manager.cpp:223 Adding camera '\_SB_.PC00.LNK1' for pipeline handler simple [1]: https://lore.kernel.org/all/abcc474a-bd58-45da-8551-d7925ca18d52@molgen.mpg.de/ Signed-off-by: Paul Menzel <pmenzel@molgen.mpg.de> --- Notes: This patch was written with the help of an LLM (Claude Code, claude-opus-5.5). It was built and tested on the Dell XPS 9315 as described above (on top of libcamera 0.7.2, where the touched files are identical), and compile-tested on master with the unit tests. The test only checked that the camera is listed again, not that it streams. src/libcamera/pipeline/simple/simple.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-)