Skip to content

Commit

Permalink
PipeWire: Use proper node ID and name
Browse files Browse the repository at this point in the history
Before:

ID:   70
Name: alsa_output.pci-0000_0e_00.4.analog-surround-51

After:

ID:   alsa_output.pci-0000_0e_00.4.analog-surround-51
Name: Starship/Matisse HD Audio Controller Analog Surround 5.1
  • Loading branch information
davidebeatrici committed Aug 5, 2024
1 parent 5c4fa1c commit fc0fe76
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 20 deletions.
27 changes: 8 additions & 19 deletions src/backends/PipeWire/PipeWire.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,13 +313,9 @@ Nodes *Engine::engineNodesGet() {
const auto &nodeIn = iter.second;
auto &nodeOut = nodes->items[i++];

nodeOut.id = strdup(nodeIn.id.data());
nodeOut.name = strdup(nodeIn.name.data());
nodeOut.direction = nodeIn.direction;

const auto size = snprintf(nullptr, 0, "%u", nodeIn.serial) + 1;
nodeOut.id = static_cast< char *>(malloc(size));
snprintf(nodeOut.id, size, "%u", nodeIn.serial);

nodeOut.name = strdup(nodeIn.name.data());
}

return nodes;
Expand All @@ -328,21 +324,14 @@ Nodes *Engine::engineNodesGet() {
void Engine::addNode(const pw_node_info *info) {
const spa_dict *props = info->props;

const char *serialStr = spa_dict_lookup(props, PW_KEY_OBJECT_SERIAL);
if (!serialStr) {
return;
}

errno = 0;
const uint32_t serial = std::strtoul(serialStr, nullptr, 10);
if (errno != 0) {
const char *id = spa_dict_lookup(props, PW_KEY_NODE_NAME);
if (!id) {
return;
}

const char *name;
if (!(name = spa_dict_lookup(props, PW_KEY_NODE_NAME)) && !(name = spa_dict_lookup(props, PW_KEY_NODE_DESCRIPTION))
&& !(name = spa_dict_lookup(props, PW_KEY_APP_NAME))) {
return;
const char *name = spa_dict_lookup(props, PW_KEY_NODE_DESCRIPTION);
if (!name) {
name = id;
}

uint8_t direction = CROSSAUDIO_DIR_NONE;
Expand All @@ -355,7 +344,7 @@ void Engine::addNode(const pw_node_info *info) {

const auto lock = locker();

m_nodes.emplace(info->id, Node(serial, name, static_cast< Direction >(direction)));
m_nodes.emplace(info->id, Node(id, name, static_cast< Direction >(direction)));

Check failure on line 347 in src/backends/PipeWire/PipeWire.cpp

View workflow job for this annotation

GitHub Actions / build (Ubuntu (Clang), ubuntu-latest, clang, clang++)

no matching constructor for initialization of 'pipewire::Engine::Node'
}

void Engine::removeNode(const uint32_t id) {
Expand Down
2 changes: 1 addition & 1 deletion src/backends/PipeWire/PipeWire.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class Engine {
};

struct Node {
uint32_t serial;
std::string id;
std::string name;
Direction direction;
};
Expand Down

0 comments on commit fc0fe76

Please sign in to comment.