From 8cadcd7f5656e7461dbe45d1ad2ee5386497f275 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Wed, 14 Mar 2018 11:17:51 +0100 Subject: [PATCH] hook: return number of hooks called Do finish_format ourselved when nobody was listening for the format change. --- spa/include/spa/utils/hook.h | 6 +++++- src/pipewire/stream.c | 11 ++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/spa/include/spa/utils/hook.h b/spa/include/spa/utils/hook.h index 69f995865..97bda8594 100644 --- a/spa/include/spa/utils/hook.h +++ b/spa/include/spa/utils/hook.h @@ -78,19 +78,23 @@ static inline void spa_hook_remove(struct spa_hook *hook) } /** Call all hooks in a list, starting from the given one and optionally stopping - * after calling the first non-NULL function */ + * after calling the first non-NULL function, returns the number of methods + * called */ #define spa_hook_list_do_call(l,start,type,method,once,...) ({ \ struct spa_hook_list *list = l; \ struct spa_list *s = start ? (struct spa_list *)start : &list->list; \ struct spa_hook *ci, *t; \ + int count = 0; \ spa_list_for_each_safe_next(ci, t, &list->list, s, link) { \ const type *cb = ci->funcs; \ if (cb->method) { \ cb->method(ci->data, ## __VA_ARGS__); \ + count++; \ if (once) \ break; \ } \ } \ + count; \ }) #define spa_hook_list_call(l,t,m,...) spa_hook_list_do_call(l,NULL,t,m,false,##__VA_ARGS__) diff --git a/src/pipewire/stream.c b/src/pipewire/stream.c index f807bc715..dfbef3df9 100644 --- a/src/pipewire/stream.c +++ b/src/pipewire/stream.c @@ -800,6 +800,8 @@ client_node_port_set_param(void *data, struct pw_type *t = &stream->remote->core->type; if (id == t->param.idFormat) { + int count; + pw_log_debug("stream %p: format changed %d", stream, seq); if (impl->format) @@ -814,9 +816,12 @@ client_node_port_set_param(void *data, impl->pending_seq = seq; - spa_hook_list_call(&stream->listener_list, - struct pw_stream_events, - format_changed, impl->format); + count = spa_hook_list_call(&stream->listener_list, + struct pw_stream_events, + format_changed, impl->format); + + if (count == 0) + pw_stream_finish_format(stream, 0, NULL, 0); if (impl->format) stream_set_state(stream, PW_STREAM_STATE_READY, NULL);