pipewire/spa/plugins/libcamera
Barnabás Pőcze 2c2808fab1 spa: libcamera: manager: fix id allocation
There is an issue in the id allocation mechanism which can result
in the different devices having the same id. Specifically, consider
the scenario where there are only two cameras, which have just been
added. In this case `impl::devices` looks like this:

   (0, camA) | (1, camB) | (?, nullptr) | ...

Now assume that `camA` is removed, after which the array appears
as follows:

  (1, camB) | (1, nullptr) | (?, nullptr) | ...

Then assume that a new camera appears. When `get_free_id()` runs,
when `i == 1`, it will observe that `devices[i].camera == nullptr`,
so it selects `1` as the id. Leading to the following:

  (1, camB) | (1, camC) | (?, nullptr) | ...

This is of course incorrect. The set of ids must be unique. When
wireplumber is faced with this situation it destroys the device
object for `camB` when `camC` is emitted.

Fix this by simply not moving elements in the `devices` array,
leaving everything where it is. In which case the array looks
like this:

  (nullptr) | (camB) | (nullptr) | ... // after `camA` removal
  (camC) | (camB) | (nullptr) | ... // after `camC` appearance

Note that `device::id` is removed, and the id is now derived from
the position in `impl::devices`.
2025-07-15 08:12:54 +00:00
..
libcamera-device.cpp spa: libcamera: use nullptr instead of NULL 2025-07-15 08:12:54 +00:00
libcamera-manager.cpp spa: libcamera: manager: fix id allocation 2025-07-15 08:12:54 +00:00
libcamera-manager.hpp treewide: use SPDX tags to specify copyright information 2023-02-16 10:54:48 +00:00
libcamera-source.cpp spa: libcamera: use nullptr instead of NULL 2025-07-15 08:12:54 +00:00
libcamera.c spa: export log topic enumerations 2024-01-04 10:02:55 +00:00
libcamera.h spa: remove unnecessary indirection for some spa_log_topics 2023-10-06 13:08:24 +00:00
meson.build meson: fix build with missing libudev-devel 2024-02-06 11:49:40 +01:00