From 2fe719793012e33578a8131a3c9a28fcffd22499 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Tue, 20 Feb 2018 12:28:19 +0100 Subject: [PATCH] node: add option to pause-on-idle v4l2 is slower to start when we pause in idle. Disable this behaviour with an option on the node. --- spa/plugins/v4l2/v4l2-source.c | 1 + src/pipewire/node.c | 26 +++++++++++++++++++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/spa/plugins/v4l2/v4l2-source.c b/spa/plugins/v4l2/v4l2-source.c index 8133865d4..5835e3e03 100644 --- a/spa/plugins/v4l2/v4l2-source.c +++ b/spa/plugins/v4l2/v4l2-source.c @@ -861,6 +861,7 @@ static int impl_node_process_output(struct spa_node *node) static const struct spa_dict_item info_items[] = { { "media.class", "Video/Source" }, + { "node.pause-on-idle", "false" }, }; static const struct spa_dict info = { diff --git a/src/pipewire/node.c b/src/pipewire/node.c index f7403a95b..4132666db 100644 --- a/src/pipewire/node.c +++ b/src/pipewire/node.c @@ -40,6 +40,7 @@ struct impl { struct pw_node this; struct pw_work_queue *work; + bool pause_on_idle; }; struct resource_data { @@ -372,6 +373,17 @@ int pw_node_register(struct pw_node *this, return 0; } +static void check_properties(struct pw_node *node) +{ + struct impl *impl = SPA_CONTAINER_OF(node, struct impl, this); + const char *str; + + if ((str = pw_properties_get(node->properties, "node.pause-on-idle"))) + impl->pause_on_idle = pw_properties_parse_bool(str); + else + impl->pause_on_idle = true; +} + struct pw_node *pw_node_new(struct pw_core *core, const char *name, struct pw_properties *properties, @@ -399,6 +411,8 @@ struct pw_node *pw_node_new(struct pw_core *core, this->enabled = true; this->properties = properties; + check_properties(this); + impl->work = pw_work_queue_new(this->core->main_loop); this->info.name = strdup(name); @@ -460,6 +474,8 @@ int pw_node_update_properties(struct pw_node *node, const struct spa_dict *dict) for (i = 0; i < dict->n_items; i++) pw_properties_set(node->properties, dict->items[i].key, dict->items[i].value); + check_properties(node); + node->info.props = &node->properties->dict; node->info.change_mask |= PW_NODE_CHANGE_MASK_PROPS; @@ -885,6 +901,7 @@ int pw_node_set_state(struct pw_node *node, enum pw_node_state state) */ void pw_node_update_state(struct pw_node *node, enum pw_node_state state, char *error) { + struct impl *impl = SPA_CONTAINER_OF(node, struct impl, this); enum pw_node_state old; old = node->info.state; @@ -894,14 +911,17 @@ void pw_node_update_state(struct pw_node *node, enum pw_node_state state, char * pw_log_debug("node %p: update state from %s -> %s", node, pw_node_state_as_string(old), pw_node_state_as_string(state)); + if (state == PW_NODE_STATE_IDLE) { + if (impl->pause_on_idle) + pause_node(node); + node_deactivate(node); + } + if (node->info.error) free((char*)node->info.error); node->info.error = error; node->info.state = state; - if (state == PW_NODE_STATE_IDLE) - node_deactivate(node); - spa_hook_list_call(&node->listener_list, struct pw_node_events, state_changed, old, state, error);