From 76313161866db1a48a798da1ff8e196de747d238 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Fri, 4 Nov 2022 15:22:01 +0100 Subject: [PATCH] buffer: add option to reverse filter priority By default, buffer negotiation favours the default property values of the output node. Make this configurable and reverse this logic when the output is a driver. This makes it so that a stream connecting to a source will negotiate with the preferences of the stream and not the source. An example is a stream that wants 4 buffers from v4l2-source, because v4l2-source has a default of 4 buffers, this will always result in 4 buffers, ignoring the preference of the stream. --- src/pipewire/buffers.c | 6 ++++++ src/pipewire/buffers.h | 1 + src/pipewire/impl-link.c | 3 +++ 3 files changed, 10 insertions(+) diff --git a/src/pipewire/buffers.c b/src/pipewire/buffers.c index d27b9ee24..3499805ee 100644 --- a/src/pipewire/buffers.c +++ b/src/pipewire/buffers.c @@ -255,6 +255,12 @@ int pw_buffers_negotiate(struct pw_context *context, uint32_t flags, struct port input = { innode, SPA_DIRECTION_INPUT, in_port_id }; int res; + if (flags & PW_BUFFERS_FLAG_IN_PRIORITY) { + struct port tmp = output; + output = input; + input = tmp; + } + res = param_filter(result, &input, &output, SPA_PARAM_Buffers, &b); if (res < 0) { pw_context_debug_port_params(context, input.node, input.direction, diff --git a/src/pipewire/buffers.h b/src/pipewire/buffers.h index df72bf3f8..abef3925f 100644 --- a/src/pipewire/buffers.h +++ b/src/pipewire/buffers.h @@ -48,6 +48,7 @@ extern "C" { #define PW_BUFFERS_FLAG_SHARED (1<<1) /**< buffers can be shared */ #define PW_BUFFERS_FLAG_DYNAMIC (1<<2) /**< buffers have dynamic data */ #define PW_BUFFERS_FLAG_SHARED_MEM (1<<3) /**< buffers need shared memory */ +#define PW_BUFFERS_FLAG_IN_PRIORITY (1<<4) /**< input parameters have priority */ struct pw_buffers { struct pw_memblock *mem; /**< allocated buffer memory */ diff --git a/src/pipewire/impl-link.c b/src/pipewire/impl-link.c index 012bced6c..5eeff5b01 100644 --- a/src/pipewire/impl-link.c +++ b/src/pipewire/impl-link.c @@ -517,6 +517,9 @@ static int do_allocation(struct pw_impl_link *this) if (output->node->remote || input->node->remote) alloc_flags |= PW_BUFFERS_FLAG_SHARED_MEM; + if (output->node->driver) + alloc_flags |= PW_BUFFERS_FLAG_IN_PRIORITY; + /* if output port can alloc buffers, alloc skeleton buffers */ if (SPA_FLAG_IS_SET(out_flags, SPA_PORT_FLAG_CAN_ALLOC_BUFFERS)) { SPA_FLAG_SET(alloc_flags, PW_BUFFERS_FLAG_NO_MEM);