PipeWire camera: use better unique device name for camera devices

Originally we used node id from PipeWire as an unique device name and
while this works, it will change everytime PipeWire is restarted. This
has an impact on default camera selection, where for example Firefox can
automatically request a camera device that was used before, but this can
break with the next PipeWire restart.

Bug: webrtc:42225999
Change-Id: I9440ee065ffeaa1ffb911a4dc7c405d57c9416dc
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/367880
Commit-Queue: Jan Grulich <grulja@gmail.com>
Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#43387}
This commit is contained in:
Jan Grulich 2024-11-07 15:39:25 +01:00 committed by WebRTC LUCI CQ
parent 9fb71e3b01
commit a5d71009ac
2 changed files with 8 additions and 5 deletions

View File

@ -75,7 +75,7 @@ PipeWireNode::PipeWireNode(PipeWireSession* session,
: session_(session), : session_(session),
id_(id), id_(id),
display_name_(spa_dict_lookup(props, PW_KEY_NODE_DESCRIPTION)), display_name_(spa_dict_lookup(props, PW_KEY_NODE_DESCRIPTION)),
unique_id_(rtc::ToString(id)) { unique_id_(spa_dict_lookup(props, PW_KEY_NODE_NAME)) {
RTC_LOG(LS_VERBOSE) << "Found Camera: " << display_name_; RTC_LOG(LS_VERBOSE) << "Found Camera: " << display_name_;
proxy_ = static_cast<pw_proxy*>(pw_registry_bind( proxy_ = static_cast<pw_proxy*>(pw_registry_bind(

View File

@ -83,12 +83,15 @@ int32_t VideoCaptureModulePipeWire::Init(const char* deviceUniqueId) {
RTC_CHECK_RUNS_SERIALIZED(&capture_checker_); RTC_CHECK_RUNS_SERIALIZED(&capture_checker_);
RTC_DCHECK_RUN_ON(&api_checker_); RTC_DCHECK_RUN_ON(&api_checker_);
std::optional<int> id; auto node =
id = rtc::StringToNumber<int>(deviceUniqueId); std::find_if(session_->nodes_.begin(), session_->nodes_.end(),
if (id == std::nullopt) [deviceUniqueId](const PipeWireNode::PipeWireNodePtr& node) {
return node->unique_id() == deviceUniqueId;
});
if (node == session_->nodes_.end())
return -1; return -1;
node_id_ = id.value(); node_id_ = (*node)->id();
const int len = strlen(deviceUniqueId); const int len = strlen(deviceUniqueId);
_deviceUniqueId = new (std::nothrow) char[len + 1]; _deviceUniqueId = new (std::nothrow) char[len + 1];