mirror of
				https://gitlab.freedesktop.org/pipewire/pipewire.git
				synced 2025-11-03 09:01:54 -05:00 
			
		
		
		
	convert: refactor node_set_param functions
Move them to their own function to make the main function shorter. Also make sure we emit the new ports first and then the node info.
This commit is contained in:
		
							parent
							
								
									8dfa086c3c
								
							
						
					
					
						commit
						2420c3a8c8
					
				
					 2 changed files with 130 additions and 102 deletions
				
			
		| 
						 | 
					@ -1828,6 +1828,8 @@ static int reconfigure_mode(struct impl *this, enum spa_param_port_config_mode m
 | 
				
			||||||
		i = dir->n_ports++;
 | 
							i = dir->n_ports++;
 | 
				
			||||||
		init_port(this, direction, i, 0, false, false, true);
 | 
							init_port(this, direction, i, 0, false, false, true);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						/* emit all port changes */
 | 
				
			||||||
 | 
						emit_info(this, false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	this->info.change_mask |= SPA_NODE_CHANGE_MASK_FLAGS | SPA_NODE_CHANGE_MASK_PARAMS;
 | 
						this->info.change_mask |= SPA_NODE_CHANGE_MASK_FLAGS | SPA_NODE_CHANGE_MASK_PARAMS;
 | 
				
			||||||
	this->info.flags &= ~SPA_NODE_FLAG_NEED_CONFIGURE;
 | 
						this->info.flags &= ~SPA_NODE_FLAG_NEED_CONFIGURE;
 | 
				
			||||||
| 
						 | 
					@ -1836,19 +1838,9 @@ static int reconfigure_mode(struct impl *this, enum spa_param_port_config_mode m
 | 
				
			||||||
	return 0;
 | 
						return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static int impl_node_set_param(void *object, uint32_t id, uint32_t flags,
 | 
					static int node_set_param_port_config(struct impl *this, uint32_t flags,
 | 
				
			||||||
				const struct spa_pod *param)
 | 
									const struct spa_pod *param)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	struct impl *this = object;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	spa_return_val_if_fail(this != NULL, -EINVAL);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if (param == NULL)
 | 
					 | 
				
			||||||
		return 0;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	switch (id) {
 | 
					 | 
				
			||||||
	case SPA_PARAM_PortConfig:
 | 
					 | 
				
			||||||
	{
 | 
					 | 
				
			||||||
	struct spa_audio_info info = { 0, }, *infop = NULL;
 | 
						struct spa_audio_info info = { 0, }, *infop = NULL;
 | 
				
			||||||
	struct spa_pod *format = NULL;
 | 
						struct spa_pod *format = NULL;
 | 
				
			||||||
	enum spa_direction direction;
 | 
						enum spa_direction direction;
 | 
				
			||||||
| 
						 | 
					@ -1856,6 +1848,9 @@ static int impl_node_set_param(void *object, uint32_t id, uint32_t flags,
 | 
				
			||||||
	bool monitor = false, control = false;
 | 
						bool monitor = false, control = false;
 | 
				
			||||||
	int res;
 | 
						int res;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (param == NULL)
 | 
				
			||||||
 | 
							return 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (spa_pod_parse_object(param,
 | 
						if (spa_pod_parse_object(param,
 | 
				
			||||||
			SPA_TYPE_OBJECT_ParamPortConfig, NULL,
 | 
								SPA_TYPE_OBJECT_ParamPortConfig, NULL,
 | 
				
			||||||
			SPA_PARAM_PORT_CONFIG_direction,	SPA_POD_Id(&direction),
 | 
								SPA_PARAM_PORT_CONFIG_direction,	SPA_POD_Id(&direction),
 | 
				
			||||||
| 
						 | 
					@ -1885,15 +1880,18 @@ static int impl_node_set_param(void *object, uint32_t id, uint32_t flags,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		infop = &info;
 | 
							infop = &info;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						return reconfigure_mode(this, mode, direction, monitor, control, infop);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if ((res = reconfigure_mode(this, mode, direction, monitor, control, infop)) < 0)
 | 
					static int node_set_param_props(struct impl *this, uint32_t flags,
 | 
				
			||||||
			return res;
 | 
									const struct spa_pod *param)
 | 
				
			||||||
		break;
 | 
					{
 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	case SPA_PARAM_Props:
 | 
					 | 
				
			||||||
	{
 | 
					 | 
				
			||||||
	bool have_graph = false;
 | 
						bool have_graph = false;
 | 
				
			||||||
	struct filter_graph *g, *t;
 | 
						struct filter_graph *g, *t;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (param == NULL)
 | 
				
			||||||
 | 
							return 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	this->filter_props_count = 0;
 | 
						this->filter_props_count = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	spa_list_for_each_safe(g, t, &this->active_graphs, link) {
 | 
						spa_list_for_each_safe(g, t, &this->active_graphs, link) {
 | 
				
			||||||
| 
						 | 
					@ -1902,8 +1900,7 @@ static int impl_node_set_param(void *object, uint32_t id, uint32_t flags,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		have_graph = true;
 | 
							have_graph = true;
 | 
				
			||||||
		this->in_filter_props++;
 | 
							this->in_filter_props++;
 | 
				
			||||||
			spa_filter_graph_set_props(g->graph,
 | 
							spa_filter_graph_set_props(g->graph, SPA_DIRECTION_INPUT, param);
 | 
				
			||||||
					SPA_DIRECTION_INPUT, param);
 | 
					 | 
				
			||||||
		this->filter_props_count++;
 | 
							this->filter_props_count++;
 | 
				
			||||||
		this->in_filter_props--;
 | 
							this->in_filter_props--;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					@ -1911,13 +1908,29 @@ static int impl_node_set_param(void *object, uint32_t id, uint32_t flags,
 | 
				
			||||||
		apply_props(this, param);
 | 
							apply_props(this, param);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	clean_filter_handles(this, false);
 | 
						clean_filter_handles(this, false);
 | 
				
			||||||
 | 
						return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static int impl_node_set_param(void *object, uint32_t id, uint32_t flags,
 | 
				
			||||||
 | 
								       const struct spa_pod *param)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct impl *this = object;
 | 
				
			||||||
 | 
						int res;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						spa_return_val_if_fail(this != NULL, -EINVAL);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						switch (id) {
 | 
				
			||||||
 | 
						case SPA_PARAM_PortConfig:
 | 
				
			||||||
 | 
							res = node_set_param_port_config(this, flags, param);
 | 
				
			||||||
 | 
							break;
 | 
				
			||||||
 | 
						case SPA_PARAM_Props:
 | 
				
			||||||
 | 
							res = node_set_param_props(this, flags, param);
 | 
				
			||||||
		break;
 | 
							break;
 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	default:
 | 
						default:
 | 
				
			||||||
		return -ENOENT;
 | 
							return -ENOENT;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	emit_info(this, false);
 | 
						emit_info(this, false);
 | 
				
			||||||
	return 0;
 | 
						return res;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static int int32_cmp(const void *v1, const void *v2)
 | 
					static int int32_cmp(const void *v1, const void *v2)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -472,10 +472,10 @@ static int init_port(struct impl *this, enum spa_direction direction, uint32_t p
 | 
				
			||||||
	port->latency[SPA_DIRECTION_INPUT] = SPA_LATENCY_INFO(SPA_DIRECTION_INPUT);
 | 
						port->latency[SPA_DIRECTION_INPUT] = SPA_LATENCY_INFO(SPA_DIRECTION_INPUT);
 | 
				
			||||||
	port->latency[SPA_DIRECTION_OUTPUT] = SPA_LATENCY_INFO(SPA_DIRECTION_OUTPUT);
 | 
						port->latency[SPA_DIRECTION_OUTPUT] = SPA_LATENCY_INFO(SPA_DIRECTION_OUTPUT);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						port->info = SPA_PORT_INFO_INIT();
 | 
				
			||||||
	port->info.change_mask = port->info_all = SPA_PORT_CHANGE_MASK_FLAGS |
 | 
						port->info.change_mask = port->info_all = SPA_PORT_CHANGE_MASK_FLAGS |
 | 
				
			||||||
			SPA_PORT_CHANGE_MASK_PROPS |
 | 
								SPA_PORT_CHANGE_MASK_PROPS |
 | 
				
			||||||
			SPA_PORT_CHANGE_MASK_PARAMS;
 | 
								SPA_PORT_CHANGE_MASK_PARAMS;
 | 
				
			||||||
	port->info = SPA_PORT_INFO_INIT();
 | 
					 | 
				
			||||||
	port->info.flags = SPA_PORT_FLAG_NO_REF |
 | 
						port->info.flags = SPA_PORT_FLAG_NO_REF |
 | 
				
			||||||
		SPA_PORT_FLAG_DYNAMIC_DATA;
 | 
							SPA_PORT_FLAG_DYNAMIC_DATA;
 | 
				
			||||||
	port->params[IDX_EnumFormat] = SPA_PARAM_INFO(SPA_PARAM_EnumFormat, SPA_PARAM_INFO_READ);
 | 
						port->params[IDX_EnumFormat] = SPA_PARAM_INFO(SPA_PARAM_EnumFormat, SPA_PARAM_INFO_READ);
 | 
				
			||||||
| 
						 | 
					@ -788,6 +788,9 @@ static int reconfigure_mode(struct impl *this, enum spa_param_port_config_mode m
 | 
				
			||||||
		init_port(this, direction, i, false, false, true);
 | 
							init_port(this, direction, i, false, false, true);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* emit all port info first, then the node props and flags */
 | 
				
			||||||
 | 
						emit_info(this, false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	this->info.change_mask |= SPA_NODE_CHANGE_MASK_FLAGS | SPA_NODE_CHANGE_MASK_PARAMS;
 | 
						this->info.change_mask |= SPA_NODE_CHANGE_MASK_FLAGS | SPA_NODE_CHANGE_MASK_PARAMS;
 | 
				
			||||||
	this->info.flags &= ~SPA_NODE_FLAG_NEED_CONFIGURE;
 | 
						this->info.flags &= ~SPA_NODE_FLAG_NEED_CONFIGURE;
 | 
				
			||||||
	this->params[IDX_PortConfig].user++;
 | 
						this->params[IDX_PortConfig].user++;
 | 
				
			||||||
| 
						 | 
					@ -795,19 +798,9 @@ static int reconfigure_mode(struct impl *this, enum spa_param_port_config_mode m
 | 
				
			||||||
	return 0;
 | 
						return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static int impl_node_set_param(void *object, uint32_t id, uint32_t flags,
 | 
					static int node_set_param_port_config(struct impl *this, uint32_t flags,
 | 
				
			||||||
				const struct spa_pod *param)
 | 
									const struct spa_pod *param)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	struct impl *this = object;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	spa_return_val_if_fail(this != NULL, -EINVAL);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if (param == NULL)
 | 
					 | 
				
			||||||
		return 0;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	switch (id) {
 | 
					 | 
				
			||||||
	case SPA_PARAM_PortConfig:
 | 
					 | 
				
			||||||
	{
 | 
					 | 
				
			||||||
	struct spa_video_info info = { 0, }, *infop = NULL;
 | 
						struct spa_video_info info = { 0, }, *infop = NULL;
 | 
				
			||||||
	struct spa_pod *format = NULL;
 | 
						struct spa_pod *format = NULL;
 | 
				
			||||||
	enum spa_direction direction;
 | 
						enum spa_direction direction;
 | 
				
			||||||
| 
						 | 
					@ -815,6 +808,9 @@ static int impl_node_set_param(void *object, uint32_t id, uint32_t flags,
 | 
				
			||||||
	bool monitor = false, control = false;
 | 
						bool monitor = false, control = false;
 | 
				
			||||||
	int res;
 | 
						int res;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (param == NULL)
 | 
				
			||||||
 | 
							return 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (spa_pod_parse_object(param,
 | 
						if (spa_pod_parse_object(param,
 | 
				
			||||||
			SPA_TYPE_OBJECT_ParamPortConfig, NULL,
 | 
								SPA_TYPE_OBJECT_ParamPortConfig, NULL,
 | 
				
			||||||
			SPA_PARAM_PORT_CONFIG_direction,	SPA_POD_Id(&direction),
 | 
								SPA_PARAM_PORT_CONFIG_direction,	SPA_POD_Id(&direction),
 | 
				
			||||||
| 
						 | 
					@ -833,19 +829,38 @@ static int impl_node_set_param(void *object, uint32_t id, uint32_t flags,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		infop = &info;
 | 
							infop = &info;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						return reconfigure_mode(this, mode, direction, monitor, control, infop);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static int node_set_param_props(struct impl *this, uint32_t flags,
 | 
				
			||||||
 | 
									const struct spa_pod *param)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						if (param == NULL)
 | 
				
			||||||
 | 
							return 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if ((res = reconfigure_mode(this, mode, direction, monitor, control, infop)) < 0)
 | 
					 | 
				
			||||||
			return res;
 | 
					 | 
				
			||||||
		break;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	case SPA_PARAM_Props:
 | 
					 | 
				
			||||||
	apply_props(this, param);
 | 
						apply_props(this, param);
 | 
				
			||||||
 | 
						return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					static int impl_node_set_param(void *object, uint32_t id, uint32_t flags,
 | 
				
			||||||
 | 
								       const struct spa_pod *param)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct impl *this = object;
 | 
				
			||||||
 | 
						int res;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						spa_return_val_if_fail(this != NULL, -EINVAL);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						switch (id) {
 | 
				
			||||||
 | 
						case SPA_PARAM_PortConfig:
 | 
				
			||||||
 | 
							res = node_set_param_port_config(this, flags, param);
 | 
				
			||||||
 | 
							break;
 | 
				
			||||||
 | 
						case SPA_PARAM_Props:
 | 
				
			||||||
 | 
							res = node_set_param_props(this, flags, param);
 | 
				
			||||||
		break;
 | 
							break;
 | 
				
			||||||
	default:
 | 
						default:
 | 
				
			||||||
		return -ENOENT;
 | 
							return -ENOENT;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	emit_info(this, false);
 | 
						emit_info(this, false);
 | 
				
			||||||
	return 0;
 | 
						return res;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static inline void free_decoder(struct impl *this)
 | 
					static inline void free_decoder(struct impl *this)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue