Skip to content

Commit

Permalink
Pass ID when connecting streams
Browse files Browse the repository at this point in the history
WirePlumber <= 0.4.8 does not support PW_KEY_TARGET_OBJECT. And latest Ubuntu LTS (22.04) is on 0.4.8. This caused the streams to always connect to the default system sink.
  • Loading branch information
dimtpap committed Jan 21, 2024
1 parent a79fab7 commit 0805939
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/pipewire-audio-capture-app.c
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ static bool make_capture_sink(struct obs_pw_audio_capture_app *pwac, uint32_t ch

pwac->sink.autoconnect_targets = true;

if (obs_pw_audio_stream_connect(&pwac->pw.audio, pwac->sink.serial, channels) < 0) {
if (obs_pw_audio_stream_connect(&pwac->pw.audio, pwac->sink.id, pwac->sink.serial, channels) < 0) {
blog(LOG_WARNING, "[pipewire] Error connecting stream %p to app capture sink %u", pwac->pw.audio.stream,
pwac->sink.id);
}
Expand Down
4 changes: 3 additions & 1 deletion src/pipewire-audio-capture-device.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ struct target_node {
const char *friendly_name;
const char *name;
uint32_t serial;
uint32_t id;
uint32_t channels;

struct spa_hook node_listener;
Expand Down Expand Up @@ -78,7 +79,7 @@ static void start_streaming(struct obs_pw_audio_capture_device *pwac, struct tar
return;
}

if (obs_pw_audio_stream_connect(&pwac->pw.audio, node->serial, node->channels) == 0) {
if (obs_pw_audio_stream_connect(&pwac->pw.audio, node->id, node->serial, node->channels) == 0) {
pwac->connected_serial = node->serial;
blog(LOG_INFO, "[pipewire] %p streaming from %u", pwac->pw.audio.stream, node->serial);
} else {
Expand Down Expand Up @@ -186,6 +187,7 @@ static void register_target_node(struct obs_pw_audio_capture_device *pwac, const
struct target_node *n = pw_proxy_get_user_data(node_proxy);
n->friendly_name = bstrdup(friendly_name);
n->name = bstrdup(name);
n->id = global_id;
n->serial = object_serial;
n->channels = 0;
n->pwac = pwac;
Expand Down
5 changes: 3 additions & 2 deletions src/pipewire-audio.c
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,8 @@ static const struct pw_stream_events stream_events = {
.io_changed = on_io_changed_cb,
};

int obs_pw_audio_stream_connect(struct obs_pw_audio_stream *s, uint32_t target_serial, uint32_t audio_channels)
int obs_pw_audio_stream_connect(struct obs_pw_audio_stream *s, uint32_t target_id, uint32_t target_serial,
uint32_t audio_channels)
{
enum spa_audio_channel pos[8];
obs_channels_to_spa_audio_position(pos, audio_channels);
Expand All @@ -287,7 +288,7 @@ int obs_pw_audio_stream_connect(struct obs_pw_audio_stream *s, uint32_t target_s
pw_stream_update_properties(s->stream, &stream_props->dict);
pw_properties_free(stream_props);

return pw_stream_connect(s->stream, PW_DIRECTION_INPUT, PW_ID_ANY,
return pw_stream_connect(s->stream, PW_DIRECTION_INPUT, target_id,
PW_STREAM_FLAG_AUTOCONNECT | PW_STREAM_FLAG_MAP_BUFFERS | PW_STREAM_FLAG_DONT_RECONNECT,
params, 1);
}
Expand Down
3 changes: 2 additions & 1 deletion src/pipewire-audio.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ struct obs_pw_audio_stream {
* Connect a stream with the default params
* @return 0 on success, < 0 on error
*/
int obs_pw_audio_stream_connect(struct obs_pw_audio_stream *s, uint32_t target_serial, uint32_t channels);
int obs_pw_audio_stream_connect(struct obs_pw_audio_stream *s, uint32_t target_id, uint32_t target_serial,
uint32_t channels);
/* ------------------------------------------------- */

/**
Expand Down

0 comments on commit 0805939

Please sign in to comment.