Skip to content

Draft: Add wrappers for node commands

Dimitris Papaioannou requested to merge dimtpap/pipewire-rs:node-commands into main

To implement pw_node_send_command, wrappers were needed for spa/pod/command.h and spa/node/command.h since these files contain macros that act on struct spa_command and enum spa_node_command. The macros were wrapped manually in C functions so that they can be called from Rust code.

The Rust-friendly wrappers for node commands are a bit rough. In spa/node/command.h there is the macro SPA_NODE_COMMAND_INIT which takes an enum spa_node_command value and returns a spa_command that represents the node command. For now I have mirrored this exactly in the Rust wrappers, but this makes the usage like so:

node.send_command(&spa::node::command::Command::init(spa::node::command::Command::START))

the equivalent C code would be

pw_node_send_command(node, &SPA_NODE_COMMAND_INIT(SPA_NODE_COMMAND_Start)

Node::send_command has the signature fn(spa::pod::command::Command) which results in

  1. being able to send arbitrary commands to nodes, which is probably invalid
  2. making non-obvious the fact that the argument should be made with spa::node::command::Command and not spa::pod::command::Command

Which is why I've made this a draft. A better wrapper design, probably a newtype around spa::pod::command::Command, could address both of these issues.

Edited by Dimitris Papaioannou

Merge request reports

Loading