buffers: add new ASYNC flag

Make sure we allocate at least 2 buffers when we are dealing with an
ASYNC node. This ensures that an adapter without a converter will at
least negotiate to 2 buffers when the follower stream is async (such as
is the case with pw-cat).
This commit is contained in:
Wim Taymans 2023-03-30 14:53:44 +02:00
parent b3940627dd
commit d3bd687bc2
3 changed files with 10 additions and 2 deletions

View file

@ -292,6 +292,9 @@ int pw_buffers_negotiate(struct pw_context *context, uint32_t flags,
align = SPA_MAX(align, qalign);
types = qtypes;
if (SPA_FLAG_IS_SET(flags, PW_BUFFERS_FLAG_ASYNC))
max_buffers = SPA_MAX(2u, max_buffers);
pw_log_debug("%p: %d %d %d %d %d %d -> %d %zd %zd %d %zd %d", result,
qblocks, qminsize, qstride, qmax_buffers, qalign, qtypes,
blocks, minsize, stride, max_buffers, align, types);
@ -300,6 +303,7 @@ int pw_buffers_negotiate(struct pw_context *context, uint32_t flags,
minsize = 8192;
max_buffers = 2;
}
if (SPA_FLAG_IS_SET(flags, PW_BUFFERS_FLAG_SHARED_MEM)) {
if (types != SPA_ID_INVALID)
SPA_FLAG_CLEAR(types, 1<<SPA_DATA_MemPtr);

View file

@ -29,6 +29,7 @@ extern "C" {
#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 */
#define PW_BUFFERS_FLAG_ASYNC (1<<5) /**< one of the nodes is async */
struct pw_buffers {
struct pw_memblock *mem; /**< allocated buffer memory */

View file

@ -1574,9 +1574,12 @@ static int negotiate_mixer_buffers(struct pw_impl_port *port, uint32_t flags,
/* try dynamic data */
alloc_flags = PW_BUFFERS_FLAG_DYNAMIC;
if (SPA_FLAG_IS_SET(node->spa_flags, SPA_NODE_FLAG_ASYNC))
alloc_flags |= PW_BUFFERS_FLAG_ASYNC;
pw_log_debug("%p: %d.%d negotiate %d buffers on node: %p",
port, port->direction, port->port_id, n_buffers, node->node);
pw_log_debug("%p: %d.%d negotiate %d buffers on node: %p flags:%08x",
port, port->direction, port->port_id, n_buffers, node->node,
alloc_flags);
if (port->added) {
pw_loop_invoke(node->data_loop, do_remove_port, SPA_ID_INVALID, NULL, 0, true, port);