From b10068cd44f7362ae1877f6010c63c74c196dc9c Mon Sep 17 00:00:00 2001 From: AkazaAkalin <478080766@qq.com> Date: Sat, 10 Oct 2026 19:43:19 +0800 Subject: [PATCH] fix(linux): select PipeWire node IDs with the path property --- native/capture/linux/main.c | 19 +++++++++++++++---- native/capture/linux/main.test.c | 13 +++++++++++++ native/capture/linux/portal.c | 3 --- 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/native/capture/linux/main.c b/native/capture/linux/main.c index 855140635..3a340f205 100644 --- a/native/capture/linux/main.c +++ b/native/capture/linux/main.c @@ -1098,6 +1098,13 @@ static int run_pipeline(CaptureRun *run, const char *starting_status) { return 0; } +static char *pipewire_target(const PiikPortalCapture *portal) { + // target-object accepts a name or object serial; path accepts a node ID. + return portal->target_object != NULL + ? g_strdup_printf("target-object=%s", portal->target_object) + : g_strdup_printf("path=%u", portal->node_id); +} + static int capture_video(int count, char **values) { CaptureRun run = {.last_input_timestamp = GST_CLOCK_TIME_NONE}; gboolean encoded = count > 1 && strcmp(values[1], "--encoded-video") == 0; @@ -1130,10 +1137,14 @@ static int capture_video(int count, char **values) { "max-buffers=1 max-bytes=1048576 max-time=0 " "caps=video/x-h264,stream-format=byte-stream,alignment=au ! " "h264parse ! decodebin ! video/x-raw ! tee name=frames "); - } else g_string_append_printf(pipeline_text, - "pipewiresrc name=source fd=%d target-object=%s do-timestamp=true ! " - "videorate drop-only=true ! video/x-raw,framerate=%u/1 ! tee name=frames ", - portal.pipewire_fd, portal.target_object, run.profile.frame_rate); + } else { + char *target = pipewire_target(&portal); + g_string_append_printf(pipeline_text, + "pipewiresrc name=source fd=%d %s do-timestamp=true ! " + "videorate drop-only=true ! video/x-raw,framerate=%u/1 ! tee name=frames ", + portal.pipewire_fd, target, run.profile.frame_rate); + g_free(target); + } for (guint index = 0; index < run.output_count; ++index) { const VideoProfile *profile = &run.outputs[index].profile; g_string_append_printf(pipeline_text, diff --git a/native/capture/linux/main.test.c b/native/capture/linux/main.test.c index 591b59e84..639ac19ca 100644 --- a/native/capture/linux/main.test.c +++ b/native/capture/linux/main.test.c @@ -430,8 +430,21 @@ static void check_output_failure_isolation(gboolean post_error) { g_mutex_clear(&run->lock); } +static void check_pipewire_target_identity(void) { + PiikPortalCapture portal = {.node_id = 42}; + char *target = pipewire_target(&portal); + g_assert_cmpstr(target, ==, "path=42"); + g_free(target); + + portal.target_object = "9001"; + target = pipewire_target(&portal); + g_assert_cmpstr(target, ==, "target-object=9001"); + g_free(target); +} + int main(int argc, char **argv) { gst_init(&argc, &argv); + check_pipewire_target_identity(); check_encoder_admission_and_control(); check_bus_error_retains_primary_cause(); check_slot_profiles(); diff --git a/native/capture/linux/portal.c b/native/capture/linux/portal.c index 586e8cd8f..4defa3bf4 100644 --- a/native/capture/linux/portal.c +++ b/native/capture/linux/portal.c @@ -125,9 +125,6 @@ gboolean piik_portal_capture_open(const char *restore_token, piik_portal_capture_close(capture); return FALSE; } - if (capture->target_object == NULL) { - capture->target_object = g_strdup_printf("%u", capture->node_id); - } capture->restore_token = xdp_session_get_restore_token(capture->session); return TRUE; }