PipeWire camera: check for node existence before adding it to the list

This avoids having duplicate camera entries presented to the user when
PipeWire camera is being used.

Bug: webrtc:346350844
Change-Id: I423db7fe0654cc1b1c91ee5264c6ba5dc4e24100
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/354320
Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org>
Reviewed-by: Andreas Pehrson <apehrson@mozilla.com>
Commit-Queue: Jan Grulich <grulja@gmail.com>
Cr-Commit-Position: refs/heads/main@{#42462}
This commit is contained in:
Jan Grulich 2024-06-11 14:27:33 +02:00 committed by WebRTC LUCI CQ
parent 3f91288883
commit 633a41ff8e

View File

@ -354,6 +354,13 @@ void PipeWireSession::OnRegistryGlobal(void* data,
const spa_dict* props) {
PipeWireSession* that = static_cast<PipeWireSession*>(data);
// Skip already added nodes to avoid duplicate camera entries
if (std::find_if(that->nodes_.begin(), that->nodes_.end(),
[id](const PipeWireNode& node) {
return node.id() == id;
}) != that->nodes_.end())
return;
if (type != absl::string_view(PW_TYPE_INTERFACE_Node))
return;
@ -372,12 +379,10 @@ void PipeWireSession::OnRegistryGlobal(void* data,
void PipeWireSession::OnRegistryGlobalRemove(void* data, uint32_t id) {
PipeWireSession* that = static_cast<PipeWireSession*>(data);
for (auto it = that->nodes_.begin(); it != that->nodes().end(); ++it) {
if ((*it).id() == id) {
that->nodes_.erase(it);
break;
}
}
auto it = std::remove_if(
that->nodes_.begin(), that->nodes_.end(),
[id](const PipeWireNode& node) { return node.id() == id; });
that->nodes_.erase(it, that->nodes_.end());
}
void PipeWireSession::Finish(VideoCaptureOptions::Status status) {