mirror of
				https://gitlab.freedesktop.org/pipewire/pipewire.git
				synced 2025-11-03 09:01:54 -05:00 
			
		
		
		
	adapter: pass spa_node to adapter
Make it possible to pass a spa_node as the follower of the adapter. This avoids us having to wrap it in a pw_impl_node in order to unwrap it again for the adapter spa_node.
This commit is contained in:
		
							parent
							
								
									9d186cf622
								
							
						
					
					
						commit
						daf53b94ed
					
				
					 4 changed files with 108 additions and 45 deletions
				
			
		| 
						 | 
				
			
			@ -67,7 +67,7 @@ struct node {
 | 
			
		|||
	struct pw_impl_node *node;
 | 
			
		||||
	struct spa_hook node_listener;
 | 
			
		||||
 | 
			
		||||
	struct pw_impl_node *follower;
 | 
			
		||||
	struct spa_node *follower;
 | 
			
		||||
 | 
			
		||||
	void *user_data;
 | 
			
		||||
	enum pw_direction direction;
 | 
			
		||||
| 
						 | 
				
			
			@ -199,7 +199,7 @@ static int handle_node_param(struct pw_impl_node *node, const char *key, const c
 | 
			
		|||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int find_format(struct pw_impl_node *node, enum pw_direction direction,
 | 
			
		||||
static int find_format(struct spa_node *node, enum pw_direction direction,
 | 
			
		||||
		uint32_t *media_type, uint32_t *media_subtype)
 | 
			
		||||
{
 | 
			
		||||
	uint32_t state = 0;
 | 
			
		||||
| 
						 | 
				
			
			@ -209,7 +209,7 @@ static int find_format(struct pw_impl_node *node, enum pw_direction direction,
 | 
			
		|||
	struct spa_pod *format;
 | 
			
		||||
 | 
			
		||||
	spa_pod_builder_init(&b, buffer, sizeof(buffer));
 | 
			
		||||
	if ((res = spa_node_port_enum_params_sync(pw_impl_node_get_implementation(node),
 | 
			
		||||
	if ((res = spa_node_port_enum_params_sync(node,
 | 
			
		||||
				direction == PW_DIRECTION_INPUT ?
 | 
			
		||||
					SPA_DIRECTION_INPUT :
 | 
			
		||||
					SPA_DIRECTION_OUTPUT, 0,
 | 
			
		||||
| 
						 | 
				
			
			@ -276,7 +276,7 @@ static int do_auto_port_config(struct node *n, const char *str)
 | 
			
		|||
		uint32_t n_position = 0;
 | 
			
		||||
 | 
			
		||||
		spa_pod_builder_init(&b, buffer, sizeof(buffer));
 | 
			
		||||
		if ((res = spa_node_port_enum_params_sync(pw_impl_node_get_implementation(n->follower),
 | 
			
		||||
		if ((res = spa_node_port_enum_params_sync(n->follower,
 | 
			
		||||
					n->direction == PW_DIRECTION_INPUT ?
 | 
			
		||||
						SPA_DIRECTION_INPUT :
 | 
			
		||||
						SPA_DIRECTION_OUTPUT, 0,
 | 
			
		||||
| 
						 | 
				
			
			@ -337,36 +337,75 @@ static int do_auto_port_config(struct node *n, const char *str)
 | 
			
		|||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
struct info_data {
 | 
			
		||||
	struct spa_hook listener;
 | 
			
		||||
	struct spa_node *node;
 | 
			
		||||
	struct pw_properties *props;
 | 
			
		||||
	uint32_t n_input_ports;
 | 
			
		||||
	uint32_t max_input_ports;
 | 
			
		||||
	uint32_t n_output_ports;
 | 
			
		||||
	uint32_t max_output_ports;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static void info_event(void *data, const struct spa_node_info *info)
 | 
			
		||||
{
 | 
			
		||||
	struct info_data *d = data;
 | 
			
		||||
 | 
			
		||||
	pw_properties_update(d->props, info->props);
 | 
			
		||||
 | 
			
		||||
	d->max_input_ports = info->max_input_ports;
 | 
			
		||||
	d->max_output_ports = info->max_output_ports;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void port_info_event(void *data, enum spa_direction direction, uint32_t port,
 | 
			
		||||
		const struct spa_port_info *info)
 | 
			
		||||
{
 | 
			
		||||
	struct info_data *d = data;
 | 
			
		||||
 | 
			
		||||
	if (direction == SPA_DIRECTION_OUTPUT)
 | 
			
		||||
		d->n_output_ports++;
 | 
			
		||||
	else if (direction == SPA_DIRECTION_INPUT)
 | 
			
		||||
		d->n_input_ports++;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static const struct spa_node_events node_info_events = {
 | 
			
		||||
	.version = SPA_VERSION_NODE_EVENTS,
 | 
			
		||||
	.info = info_event,
 | 
			
		||||
	.port_info = port_info_event,
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
struct pw_impl_node *pw_adapter_new(struct pw_context *context,
 | 
			
		||||
		struct pw_impl_node *follower,
 | 
			
		||||
		struct spa_node *follower,
 | 
			
		||||
		struct pw_properties *props,
 | 
			
		||||
		size_t user_data_size)
 | 
			
		||||
{
 | 
			
		||||
	struct pw_impl_node *node;
 | 
			
		||||
	struct node *n;
 | 
			
		||||
	const char *str, *factory_name;
 | 
			
		||||
	const struct pw_node_info *info;
 | 
			
		||||
	enum pw_direction direction;
 | 
			
		||||
	int res;
 | 
			
		||||
	uint32_t media_type, media_subtype;
 | 
			
		||||
	const struct spa_dict_item *it;
 | 
			
		||||
	struct pw_properties *copy;
 | 
			
		||||
	struct info_data info;
 | 
			
		||||
 | 
			
		||||
	info = pw_impl_node_get_info(follower);
 | 
			
		||||
	if (info == NULL) {
 | 
			
		||||
		res = -EINVAL;
 | 
			
		||||
	spa_zero(info);
 | 
			
		||||
	info.node = follower;
 | 
			
		||||
	info.props = props;
 | 
			
		||||
 | 
			
		||||
	res = spa_node_add_listener(info.node, &info.listener, &node_info_events, &info);
 | 
			
		||||
	if (res < 0)
 | 
			
		||||
		goto error;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	pw_log_debug("%p: in %d/%d out %d/%d", follower,
 | 
			
		||||
			info->n_input_ports, info->max_input_ports,
 | 
			
		||||
			info->n_output_ports, info->max_output_ports);
 | 
			
		||||
	spa_hook_remove(&info.listener);
 | 
			
		||||
 | 
			
		||||
	pw_properties_update(props, info->props);
 | 
			
		||||
	pw_log_debug("%p: in %d/%d out %d/%d", info.node,
 | 
			
		||||
			info.n_input_ports, info.max_input_ports,
 | 
			
		||||
			info.n_output_ports, info.max_output_ports);
 | 
			
		||||
 | 
			
		||||
	if (info->n_output_ports > 0) {
 | 
			
		||||
	if (info.n_output_ports > 0) {
 | 
			
		||||
		direction = PW_DIRECTION_OUTPUT;
 | 
			
		||||
	} else if (info->n_input_ports > 0) {
 | 
			
		||||
	} else if (info.n_input_ports > 0) {
 | 
			
		||||
		direction = PW_DIRECTION_INPUT;
 | 
			
		||||
	} else {
 | 
			
		||||
		res = -EINVAL;
 | 
			
		||||
| 
						 | 
				
			
			@ -388,8 +427,7 @@ struct pw_impl_node *pw_adapter_new(struct pw_context *context,
 | 
			
		|||
		goto error;
 | 
			
		||||
 | 
			
		||||
	if (media_type == SPA_MEDIA_TYPE_audio) {
 | 
			
		||||
		pw_properties_setf(props, "audio.adapt.follower", "pointer:%p",
 | 
			
		||||
				pw_impl_node_get_implementation(follower));
 | 
			
		||||
		pw_properties_setf(props, "audio.adapt.follower", "pointer:%p", follower);
 | 
			
		||||
		pw_properties_set(props, SPA_KEY_LIBRARY_NAME, "audioconvert/libspa-audioconvert");
 | 
			
		||||
		if (pw_properties_get(props, PW_KEY_MEDIA_CLASS) == NULL)
 | 
			
		||||
			pw_properties_setf(props, PW_KEY_MEDIA_CLASS, "Audio/%s",
 | 
			
		||||
| 
						 | 
				
			
			@ -397,8 +435,7 @@ struct pw_impl_node *pw_adapter_new(struct pw_context *context,
 | 
			
		|||
		factory_name = SPA_NAME_AUDIO_ADAPT;
 | 
			
		||||
	}
 | 
			
		||||
	else if (media_type == SPA_MEDIA_TYPE_video) {
 | 
			
		||||
		pw_properties_setf(props, "video.adapt.follower", "pointer:%p",
 | 
			
		||||
				pw_impl_node_get_implementation(follower));
 | 
			
		||||
		pw_properties_setf(props, "video.adapt.follower", "pointer:%p", follower);
 | 
			
		||||
		pw_properties_set(props, SPA_KEY_LIBRARY_NAME, "videoconvert/libspa-videoconvert");
 | 
			
		||||
		if (pw_properties_get(props, PW_KEY_MEDIA_CLASS) == NULL)
 | 
			
		||||
			pw_properties_setf(props, PW_KEY_MEDIA_CLASS, "Video/%s",
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue