| 
									
										
										
										
											2018-04-06 18:39:07 +02:00
										 |  |  | /* Spa
 | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2018-11-05 17:48:52 +01:00
										 |  |  |  * Copyright © 2018 Wim Taymans | 
					
						
							| 
									
										
										
										
											2018-04-06 18:39:07 +02:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2018-11-05 17:48:52 +01:00
										 |  |  |  * Permission is hereby granted, free of charge, to any person obtaining a | 
					
						
							|  |  |  |  * copy of this software and associated documentation files (the "Software"), | 
					
						
							|  |  |  |  * to deal in the Software without restriction, including without limitation | 
					
						
							|  |  |  |  * the rights to use, copy, modify, merge, publish, distribute, sublicense, | 
					
						
							|  |  |  |  * and/or sell copies of the Software, and to permit persons to whom the | 
					
						
							|  |  |  |  * Software is furnished to do so, subject to the following conditions: | 
					
						
							| 
									
										
										
										
											2018-04-06 18:39:07 +02:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2018-11-05 17:48:52 +01:00
										 |  |  |  * The above copyright notice and this permission notice (including the next | 
					
						
							|  |  |  |  * paragraph) shall be included in all copies or substantial portions of the | 
					
						
							|  |  |  |  * Software. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | 
					
						
							|  |  |  |  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | 
					
						
							|  |  |  |  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL | 
					
						
							|  |  |  |  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | 
					
						
							|  |  |  |  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | 
					
						
							|  |  |  |  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | 
					
						
							|  |  |  |  * DEALINGS IN THE SOFTWARE. | 
					
						
							| 
									
										
										
										
											2018-04-06 18:39:07 +02:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <errno.h>
 | 
					
						
							|  |  |  | #include <string.h>
 | 
					
						
							|  |  |  | #include <stdio.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <spa/support/log.h>
 | 
					
						
							|  |  |  | #include <spa/utils/list.h>
 | 
					
						
							|  |  |  | #include <spa/node/node.h>
 | 
					
						
							| 
									
										
										
										
											2018-04-10 15:54:29 +02:00
										 |  |  | #include <spa/buffer/alloc.h>
 | 
					
						
							| 
									
										
										
										
											2018-04-06 18:39:07 +02:00
										 |  |  | #include <spa/node/io.h>
 | 
					
						
							|  |  |  | #include <spa/param/audio/format-utils.h>
 | 
					
						
							| 
									
										
										
										
											2018-08-25 12:08:29 +02:00
										 |  |  | #include <spa/param/param.h>
 | 
					
						
							| 
									
										
										
										
											2018-08-13 17:17:23 +02:00
										 |  |  | #include <spa/pod/filter.h>
 | 
					
						
							| 
									
										
										
										
											2018-08-14 12:33:53 +02:00
										 |  |  | #include <spa/debug/pod.h>
 | 
					
						
							| 
									
										
										
										
											2018-08-23 17:47:57 +02:00
										 |  |  | #include <spa/debug/types.h>
 | 
					
						
							| 
									
										
										
										
											2018-04-06 18:39:07 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | #define NAME "audioconvert"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-10 15:54:29 +02:00
										 |  |  | struct buffer { | 
					
						
							|  |  |  | 	struct spa_list link; | 
					
						
							|  |  |  | #define BUFFER_FLAG_OUT		(1 << 0)
 | 
					
						
							|  |  |  | 	uint32_t flags; | 
					
						
							|  |  |  | 	struct spa_buffer *outbuf; | 
					
						
							|  |  |  | 	struct spa_meta_header *h; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | struct link { | 
					
						
							|  |  |  | 	struct spa_node *out_node; | 
					
						
							|  |  |  | 	uint32_t out_port; | 
					
						
							|  |  |  | 	const struct spa_port_info *out_info; | 
					
						
							|  |  |  | 	struct spa_node *in_node; | 
					
						
							|  |  |  | 	uint32_t in_port; | 
					
						
							|  |  |  | 	const struct spa_port_info *in_info; | 
					
						
							|  |  |  | 	struct spa_io_buffers io; | 
					
						
							|  |  |  | 	bool negotiated; | 
					
						
							|  |  |  | 	uint32_t n_buffers; | 
					
						
							|  |  |  | 	struct spa_buffer **buffers; | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2018-04-06 18:39:07 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | struct impl { | 
					
						
							|  |  |  | 	struct spa_handle handle; | 
					
						
							|  |  |  | 	struct spa_node node; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	struct spa_log *log; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	const struct spa_node_callbacks *callbacks; | 
					
						
							|  |  |  | 	void *user_data; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-10 15:54:29 +02:00
										 |  |  | 	int n_links; | 
					
						
							| 
									
										
										
										
											2018-05-24 18:09:54 +02:00
										 |  |  | 	struct link links[8]; | 
					
						
							| 
									
										
										
										
											2018-06-15 11:31:42 +02:00
										 |  |  | 	int n_nodes; | 
					
						
							|  |  |  | 	struct spa_node *nodes[8]; | 
					
						
							| 
									
										
										
										
											2018-04-06 18:39:07 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-19 09:46:36 +01:00
										 |  |  | #define MODE_SPLIT	0
 | 
					
						
							|  |  |  | #define MODE_MERGE	1
 | 
					
						
							|  |  |  | #define MODE_CONVERT	2
 | 
					
						
							|  |  |  | 	int mode; | 
					
						
							| 
									
										
										
										
											2018-04-10 15:54:29 +02:00
										 |  |  | 	bool started; | 
					
						
							| 
									
										
										
										
											2018-04-06 18:39:07 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-15 11:31:42 +02:00
										 |  |  | 	struct spa_handle *hnd_fmt[2]; | 
					
						
							| 
									
										
										
										
											2018-04-10 15:54:29 +02:00
										 |  |  | 	struct spa_handle *hnd_channelmix; | 
					
						
							|  |  |  | 	struct spa_handle *hnd_resample; | 
					
						
							| 
									
										
										
										
											2018-04-06 18:39:07 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-15 11:31:42 +02:00
										 |  |  | 	struct spa_node *fmt[2]; | 
					
						
							| 
									
										
										
										
											2018-04-10 15:54:29 +02:00
										 |  |  | 	struct spa_node *channelmix; | 
					
						
							|  |  |  | 	struct spa_node *resample; | 
					
						
							| 
									
										
										
										
											2018-04-06 18:39:07 +02:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-10 15:54:29 +02:00
										 |  |  | static int make_link(struct impl *this, | 
					
						
							|  |  |  | 		struct spa_node *out_node, uint32_t out_port, | 
					
						
							|  |  |  | 		struct spa_node *in_node, uint32_t in_port, | 
					
						
							|  |  |  | 		struct spa_audio_info *info) | 
					
						
							| 
									
										
										
										
											2018-04-06 18:39:07 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-04-10 15:54:29 +02:00
										 |  |  | 	struct link *l = &this->links[this->n_links++]; | 
					
						
							| 
									
										
										
										
											2018-04-06 18:39:07 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-10 15:54:29 +02:00
										 |  |  | 	l->out_node = out_node; | 
					
						
							|  |  |  | 	l->out_port = out_port; | 
					
						
							|  |  |  | 	l->in_node = in_node; | 
					
						
							|  |  |  | 	l->in_port = in_port; | 
					
						
							|  |  |  | 	l->negotiated = false; | 
					
						
							|  |  |  | 	l->io.status = SPA_STATUS_NEED_BUFFER; | 
					
						
							|  |  |  | 	l->io.buffer_id = SPA_ID_INVALID; | 
					
						
							|  |  |  | 	l->n_buffers = 0; | 
					
						
							| 
									
										
										
										
											2018-06-25 14:34:36 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	spa_node_port_get_info(out_node, | 
					
						
							|  |  |  | 			       SPA_DIRECTION_OUTPUT, out_port, | 
					
						
							|  |  |  | 			       &l->out_info); | 
					
						
							|  |  |  | 	spa_node_port_set_io(out_node, | 
					
						
							|  |  |  | 			     SPA_DIRECTION_OUTPUT, out_port, | 
					
						
							| 
									
										
										
										
											2018-08-25 12:08:29 +02:00
										 |  |  | 			     SPA_IO_Buffers, | 
					
						
							| 
									
										
										
										
											2018-06-25 14:34:36 +02:00
										 |  |  | 			     &l->io, sizeof(l->io)); | 
					
						
							|  |  |  | 	spa_node_port_get_info(in_node, | 
					
						
							|  |  |  | 			       SPA_DIRECTION_INPUT, in_port, | 
					
						
							|  |  |  | 			       &l->in_info); | 
					
						
							|  |  |  | 	spa_node_port_set_io(in_node, | 
					
						
							|  |  |  | 			     SPA_DIRECTION_INPUT, in_port, | 
					
						
							| 
									
										
										
										
											2018-08-25 12:08:29 +02:00
										 |  |  | 			     SPA_IO_Buffers, | 
					
						
							| 
									
										
										
										
											2018-06-25 14:34:36 +02:00
										 |  |  | 			     &l->io, sizeof(l->io)); | 
					
						
							| 
									
										
										
										
											2018-04-10 15:54:29 +02:00
										 |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2018-04-06 18:39:07 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-20 16:27:19 +02:00
										 |  |  | static void clean_link(struct impl *this, struct link *link) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-06-25 14:34:36 +02:00
										 |  |  | 	spa_node_port_set_param(link->in_node, | 
					
						
							|  |  |  | 				SPA_DIRECTION_INPUT, link->in_port, | 
					
						
							| 
									
										
										
										
											2018-08-25 12:08:29 +02:00
										 |  |  | 				SPA_PARAM_Format, 0, NULL); | 
					
						
							| 
									
										
										
										
											2018-06-25 14:34:36 +02:00
										 |  |  | 	spa_node_port_set_param(link->out_node, | 
					
						
							|  |  |  | 				SPA_DIRECTION_OUTPUT, link->out_port, | 
					
						
							| 
									
										
										
										
											2018-08-25 12:08:29 +02:00
										 |  |  | 				SPA_PARAM_Format, 0, NULL); | 
					
						
							| 
									
										
										
										
											2018-04-20 16:27:19 +02:00
										 |  |  | 	if (link->buffers) | 
					
						
							|  |  |  | 		free(link->buffers); | 
					
						
							|  |  |  | 	link->buffers = NULL; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-15 11:31:42 +02:00
										 |  |  | static int debug_params(struct impl *this, struct spa_node *node, | 
					
						
							|  |  |  | 		enum spa_direction direction, uint32_t port_id, uint32_t id, struct spa_pod *filter) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct spa_pod_builder b = { 0 }; | 
					
						
							|  |  |  | 	uint8_t buffer[4096]; | 
					
						
							| 
									
										
										
										
											2018-08-14 12:33:53 +02:00
										 |  |  | 	uint32_t state; | 
					
						
							|  |  |  | 	struct spa_pod *param; | 
					
						
							| 
									
										
										
										
											2018-06-15 11:31:42 +02:00
										 |  |  | 	int res; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-14 12:33:53 +02:00
										 |  |  | 	spa_log_error(this->log, "params:"); | 
					
						
							| 
									
										
										
										
											2018-06-15 11:31:42 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	state = 0; | 
					
						
							|  |  |  | 	while (true) { | 
					
						
							|  |  |  | 		spa_pod_builder_init(&b, buffer, sizeof(buffer)); | 
					
						
							|  |  |  | 		res = spa_node_port_enum_params(node, | 
					
						
							|  |  |  | 				       direction, port_id, | 
					
						
							|  |  |  | 				       id, &state, | 
					
						
							| 
									
										
										
										
											2018-08-14 12:33:53 +02:00
										 |  |  | 				       NULL, ¶m, &b); | 
					
						
							| 
									
										
										
										
											2018-06-15 11:31:42 +02:00
										 |  |  | 		if (res <= 0) | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-30 12:01:52 +02:00
										 |  |  | 		spa_debug_pod(2, NULL, param); | 
					
						
							| 
									
										
										
										
											2018-06-15 11:31:42 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	spa_log_error(this->log, "failed filter:"); | 
					
						
							|  |  |  | 	if (filter) | 
					
						
							| 
									
										
										
										
											2018-08-30 12:01:52 +02:00
										 |  |  | 		spa_debug_pod(2, NULL, filter); | 
					
						
							| 
									
										
										
										
											2018-06-15 11:31:42 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-10 15:54:29 +02:00
										 |  |  | static int negotiate_link_format(struct impl *this, struct link *link) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct spa_pod_builder b = { 0 }; | 
					
						
							|  |  |  | 	uint8_t buffer[4096]; | 
					
						
							|  |  |  | 	uint32_t state; | 
					
						
							|  |  |  | 	struct spa_pod *format, *filter; | 
					
						
							|  |  |  | 	int res; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (link->negotiated) | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	spa_pod_builder_init(&b, buffer, sizeof(buffer)); | 
					
						
							| 
									
										
										
										
											2018-06-25 14:34:36 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	state = 0; | 
					
						
							|  |  |  | 	filter = NULL; | 
					
						
							|  |  |  | 	if ((res = spa_node_port_enum_params(link->out_node, | 
					
						
							|  |  |  | 			       SPA_DIRECTION_OUTPUT, link->out_port, | 
					
						
							| 
									
										
										
										
											2018-08-25 12:08:29 +02:00
										 |  |  | 			       SPA_PARAM_EnumFormat, &state, | 
					
						
							| 
									
										
										
										
											2018-06-25 14:34:36 +02:00
										 |  |  | 			       filter, &format, &b)) <= 0) { | 
					
						
							|  |  |  | 		debug_params(this, link->out_node, SPA_DIRECTION_OUTPUT, link->out_port, | 
					
						
							| 
									
										
										
										
											2018-08-25 12:08:29 +02:00
										 |  |  | 				SPA_PARAM_EnumFormat, filter); | 
					
						
							| 
									
										
										
										
											2018-06-25 14:34:36 +02:00
										 |  |  | 		return -ENOTSUP; | 
					
						
							| 
									
										
										
										
											2018-04-10 15:54:29 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-06-25 14:34:36 +02:00
										 |  |  | 	filter = format; | 
					
						
							|  |  |  | 	state = 0; | 
					
						
							|  |  |  | 	if ((res = spa_node_port_enum_params(link->in_node, | 
					
						
							|  |  |  | 			       SPA_DIRECTION_INPUT, link->in_port, | 
					
						
							| 
									
										
										
										
											2018-08-25 12:08:29 +02:00
										 |  |  | 			       SPA_PARAM_EnumFormat, &state, | 
					
						
							| 
									
										
										
										
											2018-06-25 14:34:36 +02:00
										 |  |  | 			       filter, &format, &b)) <= 0) { | 
					
						
							|  |  |  | 		debug_params(this, link->in_node, SPA_DIRECTION_INPUT, link->in_port, | 
					
						
							| 
									
										
										
										
											2018-08-25 12:08:29 +02:00
										 |  |  | 				SPA_PARAM_EnumFormat, filter); | 
					
						
							| 
									
										
										
										
											2018-06-25 14:34:36 +02:00
										 |  |  | 		return -ENOTSUP; | 
					
						
							| 
									
										
										
										
											2018-04-10 15:54:29 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-06-25 14:34:36 +02:00
										 |  |  | 	filter = format; | 
					
						
							| 
									
										
										
										
											2018-04-10 15:54:29 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	spa_pod_fixate(filter); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-25 14:34:36 +02:00
										 |  |  | 	if ((res = spa_node_port_set_param(link->out_node, | 
					
						
							|  |  |  | 				   SPA_DIRECTION_OUTPUT, link->out_port, | 
					
						
							| 
									
										
										
										
											2018-08-25 12:08:29 +02:00
										 |  |  | 				   SPA_PARAM_Format, 0, | 
					
						
							| 
									
										
										
										
											2018-06-25 14:34:36 +02:00
										 |  |  | 				   filter)) < 0) | 
					
						
							|  |  |  | 		return res; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if ((res = spa_node_port_set_param(link->in_node, | 
					
						
							|  |  |  | 				   SPA_DIRECTION_INPUT, link->in_port, | 
					
						
							| 
									
										
										
										
											2018-08-25 12:08:29 +02:00
										 |  |  | 				   SPA_PARAM_Format, 0, | 
					
						
							| 
									
										
										
										
											2018-06-25 14:34:36 +02:00
										 |  |  | 				   filter)) < 0) | 
					
						
							|  |  |  | 		return res; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-10 15:54:29 +02:00
										 |  |  | 	link->negotiated = true; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							| 
									
										
										
										
											2018-04-06 18:39:07 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int setup_convert(struct impl *this) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-05-24 16:09:31 +02:00
										 |  |  | 	int i, j, res; | 
					
						
							| 
									
										
										
										
											2018-04-06 18:39:07 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-12 09:42:19 +02:00
										 |  |  | 	if (this->n_links > 0) | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-19 09:46:36 +01:00
										 |  |  | 	spa_log_debug(this->log, "setup convert"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-15 11:31:42 +02:00
										 |  |  | 	this->n_nodes = 0; | 
					
						
							| 
									
										
										
										
											2018-04-06 18:39:07 +02:00
										 |  |  | 	/* unpack */ | 
					
						
							| 
									
										
										
										
											2018-06-15 11:31:42 +02:00
										 |  |  | 	this->nodes[this->n_nodes++] = this->fmt[SPA_DIRECTION_INPUT]; | 
					
						
							| 
									
										
										
										
											2018-04-06 18:39:07 +02:00
										 |  |  | 	/* down mix */ | 
					
						
							| 
									
										
										
										
											2018-06-15 11:31:42 +02:00
										 |  |  | 	this->nodes[this->n_nodes++] = this->channelmix; | 
					
						
							| 
									
										
										
										
											2018-04-06 18:39:07 +02:00
										 |  |  | 	/* resample */ | 
					
						
							| 
									
										
										
										
											2018-06-15 11:31:42 +02:00
										 |  |  | 	this->nodes[this->n_nodes++] = this->resample; | 
					
						
							| 
									
										
										
										
											2018-04-06 18:39:07 +02:00
										 |  |  | 	/* pack */ | 
					
						
							| 
									
										
										
										
											2018-06-15 11:31:42 +02:00
										 |  |  | 	this->nodes[this->n_nodes++] = this->fmt[SPA_DIRECTION_OUTPUT]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (i = 0; i < this->n_nodes - 1; i++) | 
					
						
							|  |  |  | 		make_link(this, this->nodes[i], 0, this->nodes[i+1], 0, NULL); | 
					
						
							| 
									
										
										
										
											2018-04-10 15:54:29 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-24 16:09:31 +02:00
										 |  |  | 	for (i = 0, j = this->n_links - 1; j >= i; i++, j--) { | 
					
						
							| 
									
										
										
										
											2018-04-10 15:54:29 +02:00
										 |  |  | 		if ((res = negotiate_link_format(this, &this->links[i])) < 0) | 
					
						
							|  |  |  | 			return res; | 
					
						
							| 
									
										
										
										
											2018-05-24 16:09:31 +02:00
										 |  |  | 		if ((res = negotiate_link_format(this, &this->links[j])) < 0) | 
					
						
							|  |  |  | 			return res; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-04-10 15:54:29 +02:00
										 |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2018-04-06 18:39:07 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-10 15:54:29 +02:00
										 |  |  | static int negotiate_link_buffers(struct impl *this, struct link *link) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	uint8_t buffer[4096]; | 
					
						
							|  |  |  | 	struct spa_pod_builder b = SPA_POD_BUILDER_INIT(buffer, sizeof(buffer)); | 
					
						
							|  |  |  | 	uint32_t state; | 
					
						
							|  |  |  | 	struct spa_pod *param = NULL; | 
					
						
							|  |  |  | 	int res, i; | 
					
						
							|  |  |  | 	bool in_alloc, out_alloc; | 
					
						
							|  |  |  | 	int32_t size, buffers, blocks, align, flags; | 
					
						
							|  |  |  | 	uint32_t *aligns; | 
					
						
							|  |  |  | 	struct spa_data *datas; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (link->n_buffers > 0) | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-25 14:34:36 +02:00
										 |  |  | 	state = 0; | 
					
						
							|  |  |  | 	if ((res = spa_node_port_enum_params(link->in_node, | 
					
						
							|  |  |  | 			       SPA_DIRECTION_INPUT, link->in_port, | 
					
						
							| 
									
										
										
										
											2018-08-25 12:08:29 +02:00
										 |  |  | 			       SPA_PARAM_Buffers, &state, | 
					
						
							| 
									
										
										
										
											2018-06-25 14:34:36 +02:00
										 |  |  | 			       param, ¶m, &b)) <= 0) { | 
					
						
							|  |  |  | 		debug_params(this, link->out_node, SPA_DIRECTION_OUTPUT, link->out_port, | 
					
						
							| 
									
										
										
										
											2018-08-25 12:08:29 +02:00
										 |  |  | 				SPA_PARAM_Buffers, param); | 
					
						
							| 
									
										
										
										
											2018-06-25 14:34:36 +02:00
										 |  |  | 		return -ENOTSUP; | 
					
						
							| 
									
										
										
										
											2018-04-10 15:54:29 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-06-25 14:34:36 +02:00
										 |  |  | 	state = 0; | 
					
						
							|  |  |  | 	if ((res = spa_node_port_enum_params(link->out_node, | 
					
						
							|  |  |  | 			       SPA_DIRECTION_OUTPUT, link->out_port, | 
					
						
							| 
									
										
										
										
											2018-08-25 12:08:29 +02:00
										 |  |  | 			       SPA_PARAM_Buffers, &state, | 
					
						
							| 
									
										
										
										
											2018-06-25 14:34:36 +02:00
										 |  |  | 			       param, ¶m, &b)) <= 0) { | 
					
						
							|  |  |  | 		debug_params(this, link->in_node, SPA_DIRECTION_INPUT, link->in_port, | 
					
						
							| 
									
										
										
										
											2018-08-25 12:08:29 +02:00
										 |  |  | 				SPA_PARAM_Buffers, param); | 
					
						
							| 
									
										
										
										
											2018-06-25 14:34:36 +02:00
										 |  |  | 		return -ENOTSUP; | 
					
						
							| 
									
										
										
										
											2018-04-10 15:54:29 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	spa_pod_fixate(param); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (link->in_info) | 
					
						
							| 
									
										
										
										
											2018-05-17 17:26:09 +02:00
										 |  |  | 		in_alloc = SPA_FLAG_CHECK(link->in_info->flags, | 
					
						
							|  |  |  | 				SPA_PORT_INFO_FLAG_CAN_ALLOC_BUFFERS); | 
					
						
							| 
									
										
										
										
											2018-04-10 15:54:29 +02:00
										 |  |  | 	else | 
					
						
							|  |  |  | 		in_alloc = false; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (link->out_info) | 
					
						
							| 
									
										
										
										
											2018-05-17 17:26:09 +02:00
										 |  |  | 		out_alloc = SPA_FLAG_CHECK(link->out_info->flags, | 
					
						
							|  |  |  | 				SPA_PORT_INFO_FLAG_CAN_ALLOC_BUFFERS); | 
					
						
							| 
									
										
										
										
											2018-04-10 15:54:29 +02:00
										 |  |  | 	else | 
					
						
							|  |  |  | 		out_alloc = false; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	flags = 0; | 
					
						
							|  |  |  | 	if (out_alloc || in_alloc) { | 
					
						
							|  |  |  | 		flags |= SPA_BUFFER_ALLOC_FLAG_NO_DATA; | 
					
						
							|  |  |  | 		if (out_alloc) | 
					
						
							|  |  |  | 			in_alloc = false; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (spa_pod_object_parse(param, | 
					
						
							| 
									
										
										
										
											2018-08-23 17:47:57 +02:00
										 |  |  | 		":", SPA_PARAM_BUFFERS_buffers, "i", &buffers, | 
					
						
							|  |  |  | 		":", SPA_PARAM_BUFFERS_blocks, "i", &blocks, | 
					
						
							|  |  |  | 		":", SPA_PARAM_BUFFERS_size, "i", &size, | 
					
						
							|  |  |  | 		":", SPA_PARAM_BUFFERS_align, "i", &align, | 
					
						
							| 
									
										
										
										
											2018-04-10 15:54:29 +02:00
										 |  |  | 		NULL) < 0) | 
					
						
							|  |  |  | 		return -EINVAL; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-15 11:31:42 +02:00
										 |  |  | 	spa_log_debug(this->log, "%p: buffers %d, blocks %d, size %d, align %d", | 
					
						
							|  |  |  | 			this, buffers, blocks, size, align); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-10 15:54:29 +02:00
										 |  |  | 	datas = alloca(sizeof(struct spa_data) * blocks); | 
					
						
							|  |  |  | 	memset(datas, 0, sizeof(struct spa_data) * blocks); | 
					
						
							|  |  |  | 	aligns = alloca(sizeof(uint32_t) * blocks); | 
					
						
							|  |  |  | 	for (i = 0; i < blocks; i++) { | 
					
						
							| 
									
										
										
										
											2018-08-23 17:47:57 +02:00
										 |  |  | 		datas[i].type = SPA_DATA_MemPtr; | 
					
						
							| 
									
										
										
										
											2018-04-10 15:54:29 +02:00
										 |  |  | 		datas[i].maxsize = size; | 
					
						
							|  |  |  | 		aligns[i] = align; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-20 16:27:19 +02:00
										 |  |  | 	if (link->buffers) | 
					
						
							|  |  |  | 		free(link->buffers); | 
					
						
							| 
									
										
										
										
											2018-04-10 15:54:29 +02:00
										 |  |  | 	link->buffers = spa_buffer_alloc_array(buffers, flags, 0, NULL, blocks, datas, aligns); | 
					
						
							|  |  |  | 	if (link->buffers == NULL) | 
					
						
							|  |  |  | 		return -ENOMEM; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	link->n_buffers = buffers; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-25 14:34:36 +02:00
										 |  |  | 	if (out_alloc) { | 
					
						
							|  |  |  | 		if ((res = spa_node_port_alloc_buffers(link->out_node, | 
					
						
							|  |  |  | 			       SPA_DIRECTION_OUTPUT, link->out_port, | 
					
						
							|  |  |  | 			       NULL, 0, | 
					
						
							|  |  |  | 			       link->buffers, &link->n_buffers)) < 0) | 
					
						
							|  |  |  | 			return res; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							|  |  |  | 		if ((res = spa_node_port_use_buffers(link->out_node, | 
					
						
							|  |  |  | 			       SPA_DIRECTION_OUTPUT, link->out_port, | 
					
						
							|  |  |  | 			       link->buffers, link->n_buffers)) < 0) | 
					
						
							|  |  |  | 			return res; | 
					
						
							| 
									
										
										
										
											2018-04-10 15:54:29 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-06-25 14:34:36 +02:00
										 |  |  | 	if (in_alloc) { | 
					
						
							|  |  |  | 		if ((res = spa_node_port_alloc_buffers(link->in_node, | 
					
						
							|  |  |  | 			       SPA_DIRECTION_INPUT, link->in_port, | 
					
						
							|  |  |  | 			       NULL, 0, | 
					
						
							|  |  |  | 			       link->buffers, &link->n_buffers)) < 0) | 
					
						
							|  |  |  | 			return res; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							|  |  |  | 		if ((res = spa_node_port_use_buffers(link->in_node, | 
					
						
							|  |  |  | 			       SPA_DIRECTION_INPUT, link->in_port, | 
					
						
							|  |  |  | 			       link->buffers, link->n_buffers)) < 0) | 
					
						
							|  |  |  | 			return res; | 
					
						
							| 
									
										
										
										
											2018-04-10 15:54:29 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-17 17:27:14 +02:00
										 |  |  | static void clean_convert(struct impl *this) | 
					
						
							| 
									
										
										
										
											2018-04-20 16:27:19 +02:00
										 |  |  | { | 
					
						
							|  |  |  | 	int i; | 
					
						
							|  |  |  | 	for (i = 0; i < this->n_links; i++) | 
					
						
							|  |  |  | 		clean_link(this, &this->links[i]); | 
					
						
							| 
									
										
										
										
											2018-05-17 17:27:14 +02:00
										 |  |  | 	this->n_links = 0; | 
					
						
							| 
									
										
										
										
											2018-04-20 16:27:19 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-10 15:54:29 +02:00
										 |  |  | static int setup_buffers(struct impl *this, enum spa_direction direction) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int i, res; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-19 09:46:36 +01:00
										 |  |  | 	spa_log_debug(this->log, NAME " %p: %d %d", this, direction, this->n_links); | 
					
						
							| 
									
										
										
										
											2018-04-10 15:54:29 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (direction == SPA_DIRECTION_INPUT) { | 
					
						
							| 
									
										
										
										
											2018-06-15 11:31:42 +02:00
										 |  |  | 		for (i = 0; i < this->n_links; i++) { | 
					
						
							| 
									
										
										
										
											2018-04-10 15:54:29 +02:00
										 |  |  | 			if ((res = negotiate_link_buffers(this, &this->links[i])) < 0) | 
					
						
							|  |  |  | 				spa_log_error(this->log, NAME " %p: buffers %d failed %s", | 
					
						
							|  |  |  | 						this, i, spa_strerror(res)); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2018-06-15 11:31:42 +02:00
										 |  |  | 		for (i = this->n_links-1; i >= 0 ; i--) { | 
					
						
							| 
									
										
										
										
											2018-04-10 15:54:29 +02:00
										 |  |  | 			if ((res = negotiate_link_buffers(this, &this->links[i])) < 0) | 
					
						
							|  |  |  | 				spa_log_error(this->log, NAME " %p: buffers %d failed %s", | 
					
						
							|  |  |  | 						this, i, spa_strerror(res)); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-04-06 18:39:07 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int impl_node_enum_params(struct spa_node *node, | 
					
						
							|  |  |  | 				 uint32_t id, uint32_t *index, | 
					
						
							|  |  |  | 				 const struct spa_pod *filter, | 
					
						
							| 
									
										
										
										
											2018-10-18 15:04:40 +02:00
										 |  |  | 				 struct spa_pod **result, | 
					
						
							| 
									
										
										
										
											2018-04-06 18:39:07 +02:00
										 |  |  | 				 struct spa_pod_builder *builder) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-10-18 15:04:40 +02:00
										 |  |  | 	struct impl *this; | 
					
						
							|  |  |  | 	struct spa_pod *param; | 
					
						
							|  |  |  | 	struct spa_pod_builder b = { 0 }; | 
					
						
							|  |  |  | 	uint8_t buffer[1024]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	spa_return_val_if_fail(node != NULL, -EINVAL); | 
					
						
							|  |  |  | 	spa_return_val_if_fail(index != NULL, -EINVAL); | 
					
						
							|  |  |  | 	spa_return_val_if_fail(builder != NULL, -EINVAL); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	this = SPA_CONTAINER_OF(node, struct impl, node); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       next: | 
					
						
							|  |  |  | 	spa_pod_builder_init(&b, buffer, sizeof(buffer)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	switch (id) { | 
					
						
							| 
									
										
										
										
											2018-11-29 15:24:13 +01:00
										 |  |  | 	case SPA_PARAM_EnumProfile: | 
					
						
							| 
									
										
										
										
											2018-10-18 15:04:40 +02:00
										 |  |  | 		switch (*index) { | 
					
						
							|  |  |  | 		case 0: | 
					
						
							|  |  |  | 			param = spa_pod_builder_object(&b, | 
					
						
							|  |  |  | 				SPA_TYPE_OBJECT_ParamProfile, id, | 
					
						
							|  |  |  | 				SPA_PARAM_PROFILE_direction, &SPA_POD_Id(SPA_DIRECTION_INPUT), | 
					
						
							|  |  |  | 				0); | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case 1: | 
					
						
							|  |  |  | 			param = spa_pod_builder_object(&b, | 
					
						
							|  |  |  | 				SPA_TYPE_OBJECT_ParamProfile, id, | 
					
						
							|  |  |  | 				SPA_PARAM_PROFILE_direction, &SPA_POD_Id(SPA_DIRECTION_OUTPUT), | 
					
						
							|  |  |  | 				0); | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		default: | 
					
						
							|  |  |  | 			return 0; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case SPA_PARAM_Props: | 
					
						
							|  |  |  | 		switch (*index) { | 
					
						
							|  |  |  | 		case 0: | 
					
						
							|  |  |  | 			return spa_node_enum_params(this->channelmix, id, index, filter, result, builder); | 
					
						
							|  |  |  | 		default: | 
					
						
							|  |  |  | 			return 0; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	default: | 
					
						
							|  |  |  | 		return -ENOENT; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	(*index)++; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (spa_pod_filter(builder, result, param, filter) < 0) | 
					
						
							|  |  |  | 		goto next; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 1; | 
					
						
							| 
									
										
										
										
											2018-04-06 18:39:07 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-23 12:31:41 +02:00
										 |  |  | static int impl_node_set_io(struct spa_node *node, uint32_t id, void *data, size_t size) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return -ENOTSUP; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-06 18:39:07 +02:00
										 |  |  | static int impl_node_set_param(struct spa_node *node, uint32_t id, uint32_t flags, | 
					
						
							|  |  |  | 			       const struct spa_pod *param) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-10-08 11:45:52 +02:00
										 |  |  | 	int res = 0; | 
					
						
							|  |  |  | 	struct impl *this; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	spa_return_val_if_fail(node != NULL, -EINVAL); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	this = SPA_CONTAINER_OF(node, struct impl, node); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	switch (id) { | 
					
						
							|  |  |  | 	case SPA_PARAM_Profile: | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		enum spa_direction direction; | 
					
						
							| 
									
										
										
										
											2018-11-19 09:46:36 +01:00
										 |  |  | 		struct spa_pod *format; | 
					
						
							|  |  |  | 		struct spa_audio_info info = { 0, }; | 
					
						
							|  |  |  | 		struct spa_pod_builder b = { 0 }; | 
					
						
							|  |  |  | 		uint8_t buffer[1024]; | 
					
						
							| 
									
										
										
										
											2018-10-08 11:45:52 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if (spa_pod_object_parse(param, | 
					
						
							|  |  |  | 				":", SPA_PARAM_PROFILE_direction, "I", &direction, | 
					
						
							| 
									
										
										
										
											2018-11-19 09:46:36 +01:00
										 |  |  | 				":", SPA_PARAM_PROFILE_format, "P", &format, | 
					
						
							| 
									
										
										
										
											2018-10-08 11:45:52 +02:00
										 |  |  | 				NULL) < 0) | 
					
						
							|  |  |  | 			return -EINVAL; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-19 09:46:36 +01:00
										 |  |  | 		if (!SPA_POD_IS_OBJECT_TYPE(format, SPA_TYPE_OBJECT_Format)) | 
					
						
							|  |  |  | 			return -EINVAL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if ((res = spa_format_parse(format, &info.media_type, &info.media_subtype)) < 0) | 
					
						
							|  |  |  | 			return res; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (info.media_type != SPA_MEDIA_TYPE_audio || | 
					
						
							|  |  |  | 		    info.media_subtype != SPA_MEDIA_SUBTYPE_raw) | 
					
						
							|  |  |  | 			return -EINVAL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (spa_format_audio_raw_parse(format, &info.info.raw) < 0) | 
					
						
							|  |  |  | 			return -EINVAL; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-08 11:45:52 +02:00
										 |  |  | 		switch (direction) { | 
					
						
							|  |  |  | 		case SPA_DIRECTION_INPUT: | 
					
						
							|  |  |  | 		case SPA_DIRECTION_OUTPUT: | 
					
						
							| 
									
										
										
										
											2018-11-19 09:46:36 +01:00
										 |  |  | 			spa_log_debug(this->log, NAME " %p: profile %d", this, info.info.raw.channels); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			info.info.raw.format = SPA_AUDIO_FORMAT_F32P; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			spa_pod_builder_init(&b, buffer, sizeof(buffer)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			param = spa_format_audio_raw_build(&b, SPA_PARAM_Format, &info.info.raw); | 
					
						
							|  |  |  | 			param = spa_pod_builder_object(&b, | 
					
						
							| 
									
										
										
										
											2018-11-29 15:24:13 +01:00
										 |  |  | 				SPA_TYPE_OBJECT_ParamProfile, id, | 
					
						
							|  |  |  | 				SPA_PARAM_PROFILE_direction,  &SPA_POD_Id(direction), | 
					
						
							|  |  |  | 				SPA_PARAM_PROFILE_format,     param, | 
					
						
							| 
									
										
										
										
											2018-11-19 09:46:36 +01:00
										 |  |  |                         0); | 
					
						
							| 
									
										
										
										
											2018-10-18 15:04:40 +02:00
										 |  |  | 			res = spa_node_set_param(this->fmt[direction], id, flags, param); | 
					
						
							| 
									
										
										
										
											2018-10-08 11:45:52 +02:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 		default: | 
					
						
							|  |  |  | 			res = -EINVAL; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-11-19 09:46:36 +01:00
										 |  |  | 		if (this->callbacks && this->callbacks->event) | 
					
						
							|  |  |  | 			this->callbacks->event(this->user_data, | 
					
						
							|  |  |  | 				&SPA_NODE_EVENT_INIT(SPA_NODE_EVENT_PortsChanged)); | 
					
						
							| 
									
										
										
										
											2018-10-08 11:45:52 +02:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-10-18 15:04:40 +02:00
										 |  |  | 	case SPA_PARAM_Props: | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		res = spa_node_set_param(this->channelmix, id, flags, param); | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-10-08 11:45:52 +02:00
										 |  |  | 	default: | 
					
						
							|  |  |  | 		res = -ENOTSUP; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return res; | 
					
						
							| 
									
										
										
										
											2018-04-06 18:39:07 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int impl_node_send_command(struct spa_node *node, const struct spa_command *command) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct impl *this; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	spa_return_val_if_fail(node != NULL, -EINVAL); | 
					
						
							|  |  |  | 	spa_return_val_if_fail(command != NULL, -EINVAL); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	this = SPA_CONTAINER_OF(node, struct impl, node); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-24 10:53:09 +02:00
										 |  |  | 	switch (SPA_NODE_COMMAND_ID(command)) { | 
					
						
							|  |  |  | 	case SPA_NODE_COMMAND_Start: | 
					
						
							| 
									
										
										
										
											2018-04-06 18:39:07 +02:00
										 |  |  | 		this->started = true; | 
					
						
							| 
									
										
										
										
											2018-08-23 17:47:57 +02:00
										 |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2018-10-18 15:04:40 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-24 10:53:09 +02:00
										 |  |  | 	case SPA_NODE_COMMAND_Pause: | 
					
						
							| 
									
										
										
										
											2018-04-06 18:39:07 +02:00
										 |  |  | 		this->started = false; | 
					
						
							| 
									
										
										
										
											2018-08-23 17:47:57 +02:00
										 |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2018-10-18 15:04:40 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-23 17:47:57 +02:00
										 |  |  | 	default: | 
					
						
							| 
									
										
										
										
											2018-04-06 18:39:07 +02:00
										 |  |  | 		return -ENOTSUP; | 
					
						
							| 
									
										
										
										
											2018-08-23 17:47:57 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-04-06 18:39:07 +02:00
										 |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int | 
					
						
							|  |  |  | impl_node_set_callbacks(struct spa_node *node, | 
					
						
							|  |  |  | 			const struct spa_node_callbacks *callbacks, | 
					
						
							|  |  |  | 			void *user_data) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct impl *this; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	spa_return_val_if_fail(node != NULL, -EINVAL); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	this = SPA_CONTAINER_OF(node, struct impl, node); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	this->callbacks = callbacks; | 
					
						
							|  |  |  | 	this->user_data = user_data; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int | 
					
						
							|  |  |  | impl_node_get_n_ports(struct spa_node *node, | 
					
						
							|  |  |  | 		      uint32_t *n_input_ports, | 
					
						
							|  |  |  | 		      uint32_t *max_input_ports, | 
					
						
							|  |  |  | 		      uint32_t *n_output_ports, | 
					
						
							|  |  |  | 		      uint32_t *max_output_ports) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-06-15 11:31:42 +02:00
										 |  |  | 	struct impl *this; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-06 18:39:07 +02:00
										 |  |  | 	spa_return_val_if_fail(node != NULL, -EINVAL); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-15 11:31:42 +02:00
										 |  |  | 	this = SPA_CONTAINER_OF(node, struct impl, node); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	spa_node_get_n_ports(this->fmt[SPA_DIRECTION_INPUT], n_input_ports, max_input_ports, NULL, NULL); | 
					
						
							|  |  |  | 	spa_node_get_n_ports(this->fmt[SPA_DIRECTION_OUTPUT], NULL, NULL, n_output_ports, max_output_ports); | 
					
						
							| 
									
										
										
										
											2018-04-06 18:39:07 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int | 
					
						
							|  |  |  | impl_node_get_port_ids(struct spa_node *node, | 
					
						
							|  |  |  | 		       uint32_t *input_ids, | 
					
						
							|  |  |  | 		       uint32_t n_input_ids, | 
					
						
							|  |  |  | 		       uint32_t *output_ids, | 
					
						
							|  |  |  | 		       uint32_t n_output_ids) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-06-15 11:31:42 +02:00
										 |  |  | 	struct impl *this; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-06 18:39:07 +02:00
										 |  |  | 	spa_return_val_if_fail(node != NULL, -EINVAL); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-15 11:31:42 +02:00
										 |  |  | 	this = SPA_CONTAINER_OF(node, struct impl, node); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	spa_node_get_port_ids(this->fmt[SPA_DIRECTION_INPUT], input_ids, n_input_ids, NULL, 0); | 
					
						
							|  |  |  | 	spa_node_get_port_ids(this->fmt[SPA_DIRECTION_OUTPUT], NULL, 0, output_ids, n_output_ids); | 
					
						
							| 
									
										
										
										
											2018-04-06 18:39:07 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int impl_node_add_port(struct spa_node *node, enum spa_direction direction, uint32_t port_id) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-06-15 11:31:42 +02:00
										 |  |  | 	struct impl *this; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	spa_return_val_if_fail(node != NULL, -EINVAL); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	this = SPA_CONTAINER_OF(node, struct impl, node); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return spa_node_add_port(this->fmt[direction], direction, port_id); | 
					
						
							| 
									
										
										
										
											2018-04-06 18:39:07 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int | 
					
						
							|  |  |  | impl_node_remove_port(struct spa_node *node, enum spa_direction direction, uint32_t port_id) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-06-15 11:31:42 +02:00
										 |  |  | 	struct impl *this; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	spa_return_val_if_fail(node != NULL, -EINVAL); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	this = SPA_CONTAINER_OF(node, struct impl, node); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return spa_node_remove_port(this->fmt[direction], direction, port_id); | 
					
						
							| 
									
										
										
										
											2018-04-06 18:39:07 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int | 
					
						
							|  |  |  | impl_node_port_get_info(struct spa_node *node, | 
					
						
							|  |  |  | 			enum spa_direction direction, | 
					
						
							|  |  |  | 			uint32_t port_id, | 
					
						
							|  |  |  | 			const struct spa_port_info **info) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct impl *this; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	spa_return_val_if_fail(node != NULL, -EINVAL); | 
					
						
							|  |  |  | 	spa_return_val_if_fail(info != NULL, -EINVAL); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	this = SPA_CONTAINER_OF(node, struct impl, node); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-15 11:31:42 +02:00
										 |  |  | 	return spa_node_port_get_info(this->fmt[direction], direction, port_id, info); | 
					
						
							| 
									
										
										
										
											2018-04-06 18:39:07 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int | 
					
						
							|  |  |  | impl_node_port_enum_params(struct spa_node *node, | 
					
						
							|  |  |  | 			   enum spa_direction direction, uint32_t port_id, | 
					
						
							|  |  |  | 			   uint32_t id, uint32_t *index, | 
					
						
							|  |  |  | 			   const struct spa_pod *filter, | 
					
						
							|  |  |  | 			   struct spa_pod **result, | 
					
						
							|  |  |  | 			   struct spa_pod_builder *builder) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct impl *this; | 
					
						
							| 
									
										
										
										
											2018-07-03 21:34:22 +02:00
										 |  |  | 	struct spa_pod *param; | 
					
						
							|  |  |  | 	struct spa_pod_builder b = { 0 }; | 
					
						
							|  |  |  | 	uint8_t buffer[1024]; | 
					
						
							| 
									
										
										
										
											2018-04-06 18:39:07 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	spa_return_val_if_fail(node != NULL, -EINVAL); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	this = SPA_CONTAINER_OF(node, struct impl, node); | 
					
						
							| 
									
										
										
										
											2018-07-03 21:34:22 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |       next: | 
					
						
							| 
									
										
										
										
											2018-08-30 12:02:39 +02:00
										 |  |  | 	spa_pod_builder_init(&b, buffer, sizeof(buffer)); | 
					
						
							| 
									
										
										
										
											2018-04-06 18:39:07 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-30 12:02:39 +02:00
										 |  |  | 	switch (id) { | 
					
						
							|  |  |  | 	case SPA_PARAM_PropInfo: | 
					
						
							| 
									
										
										
										
											2018-07-03 21:34:22 +02:00
										 |  |  | 		switch (*index) { | 
					
						
							|  |  |  | 		case 0: | 
					
						
							|  |  |  | 			param = spa_pod_builder_object(builder, | 
					
						
							| 
									
										
										
										
											2018-08-27 15:03:11 +02:00
										 |  |  | 				SPA_TYPE_OBJECT_PropInfo, id, | 
					
						
							| 
									
										
										
										
											2018-09-05 16:41:07 +02:00
										 |  |  | 				SPA_PROP_INFO_id,   &SPA_POD_Id(SPA_PROP_volume), | 
					
						
							|  |  |  | 				SPA_PROP_INFO_type, &SPA_POD_CHOICE_RANGE_Float(1.0, 0.0, 10.0), | 
					
						
							|  |  |  | 				0); | 
					
						
							| 
									
										
										
										
											2018-07-03 21:34:22 +02:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 		default: | 
					
						
							|  |  |  | 			return 0; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-08-30 12:02:39 +02:00
										 |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2018-07-03 21:34:22 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-30 12:02:39 +02:00
										 |  |  | 	case SPA_PARAM_IO: | 
					
						
							|  |  |  | 		switch (*index) { | 
					
						
							|  |  |  | 		case 0: | 
					
						
							|  |  |  | 			param = spa_pod_builder_object(builder, | 
					
						
							|  |  |  | 				SPA_TYPE_OBJECT_ParamIO, id, | 
					
						
							| 
									
										
										
										
											2018-09-05 16:41:07 +02:00
										 |  |  | 				SPA_PARAM_IO_id, &SPA_POD_Id(SPA_IO_Buffers), | 
					
						
							|  |  |  | 				SPA_PARAM_IO_size, &SPA_POD_Int(sizeof(struct spa_io_buffers)), | 
					
						
							|  |  |  | 				0); | 
					
						
							| 
									
										
										
										
											2018-08-30 12:02:39 +02:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 		case 1: | 
					
						
							|  |  |  | 			param = spa_pod_builder_object(builder, | 
					
						
							|  |  |  | 				SPA_TYPE_OBJECT_ParamIO, id, | 
					
						
							| 
									
										
										
										
											2018-09-05 16:41:07 +02:00
										 |  |  | 				SPA_PARAM_IO_id, &SPA_POD_Id(SPA_IO_Range), | 
					
						
							|  |  |  | 				SPA_PARAM_IO_size, &SPA_POD_Int(sizeof(struct spa_io_range)), | 
					
						
							|  |  |  | 				0); | 
					
						
							| 
									
										
										
										
											2018-08-30 12:02:39 +02:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 		case 2: | 
					
						
							|  |  |  | 			param = spa_pod_builder_object(builder, | 
					
						
							|  |  |  | 				SPA_TYPE_OBJECT_ParamIO, id, | 
					
						
							| 
									
										
										
										
											2018-09-05 16:41:07 +02:00
										 |  |  | 				SPA_PARAM_IO_id, &SPA_POD_Id(SPA_IO_Control), | 
					
						
							|  |  |  | 				SPA_PARAM_IO_size, &SPA_POD_Int(sizeof(struct spa_io_sequence)), | 
					
						
							|  |  |  | 				0); | 
					
						
							| 
									
										
										
										
											2018-08-30 12:02:39 +02:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 		default: | 
					
						
							|  |  |  | 			return 0; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2018-08-23 17:47:57 +02:00
										 |  |  | 	default: | 
					
						
							| 
									
										
										
										
											2018-07-03 21:34:22 +02:00
										 |  |  | 		return spa_node_port_enum_params(this->fmt[direction], direction, port_id, | 
					
						
							| 
									
										
										
										
											2018-06-15 11:31:42 +02:00
										 |  |  | 			id, index, filter, result, builder); | 
					
						
							| 
									
										
										
										
											2018-08-23 17:47:57 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-08-30 12:02:39 +02:00
										 |  |  | 	(*index)++; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (spa_pod_filter(builder, result, param, filter) < 0) | 
					
						
							|  |  |  | 		goto next; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 1; | 
					
						
							| 
									
										
										
										
											2018-04-06 18:39:07 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int | 
					
						
							|  |  |  | impl_node_port_set_param(struct spa_node *node, | 
					
						
							|  |  |  | 			 enum spa_direction direction, uint32_t port_id, | 
					
						
							|  |  |  | 			 uint32_t id, uint32_t flags, | 
					
						
							|  |  |  | 			 const struct spa_pod *param) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct impl *this; | 
					
						
							| 
									
										
										
										
											2018-11-19 09:46:36 +01:00
										 |  |  | 	int res; | 
					
						
							| 
									
										
										
										
											2018-04-06 18:39:07 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	spa_return_val_if_fail(node != NULL, -EINVAL); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	this = SPA_CONTAINER_OF(node, struct impl, node); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-19 09:46:36 +01:00
										 |  |  | 	if ((res = spa_node_port_set_param(this->fmt[direction], | 
					
						
							|  |  |  | 					direction, port_id, id, flags, param)) < 0) | 
					
						
							|  |  |  | 		return res; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (id == SPA_PARAM_Format) { | 
					
						
							|  |  |  | 		if (param == NULL) | 
					
						
							|  |  |  | 			clean_convert(this); | 
					
						
							|  |  |  | 		else if ((direction == SPA_DIRECTION_OUTPUT && this->mode == MODE_MERGE) || | 
					
						
							|  |  |  | 		    (direction == SPA_DIRECTION_INPUT && this->mode == MODE_SPLIT)) { | 
					
						
							|  |  |  | 			if ((res = setup_convert(this)) < 0) | 
					
						
							|  |  |  | 				return res; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return res; | 
					
						
							| 
									
										
										
										
											2018-04-06 18:39:07 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int | 
					
						
							|  |  |  | impl_node_port_use_buffers(struct spa_node *node, | 
					
						
							|  |  |  | 			   enum spa_direction direction, | 
					
						
							|  |  |  | 			   uint32_t port_id, | 
					
						
							|  |  |  | 			   struct spa_buffer **buffers, | 
					
						
							|  |  |  | 			   uint32_t n_buffers) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct impl *this; | 
					
						
							| 
									
										
										
										
											2018-11-19 09:46:36 +01:00
										 |  |  | 	int res; | 
					
						
							| 
									
										
										
										
											2018-04-06 18:39:07 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	spa_return_val_if_fail(node != NULL, -EINVAL); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	this = SPA_CONTAINER_OF(node, struct impl, node); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-19 09:46:36 +01:00
										 |  |  | 	if ((res = spa_node_port_use_buffers(this->fmt[direction], | 
					
						
							|  |  |  | 					direction, port_id, buffers, n_buffers)) < 0) | 
					
						
							|  |  |  | 		return res; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if ((direction == SPA_DIRECTION_OUTPUT && this->mode == MODE_MERGE) || | 
					
						
							|  |  |  | 	    (direction == SPA_DIRECTION_INPUT && this->mode == MODE_SPLIT)) { | 
					
						
							|  |  |  | 		if ((res = setup_buffers(this, SPA_DIRECTION_INPUT)) < 0) | 
					
						
							|  |  |  | 			return res; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return res; | 
					
						
							| 
									
										
										
										
											2018-04-06 18:39:07 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int | 
					
						
							|  |  |  | impl_node_port_alloc_buffers(struct spa_node *node, | 
					
						
							|  |  |  | 			     enum spa_direction direction, | 
					
						
							|  |  |  | 			     uint32_t port_id, | 
					
						
							|  |  |  | 			     struct spa_pod **params, | 
					
						
							|  |  |  | 			     uint32_t n_params, | 
					
						
							|  |  |  | 			     struct spa_buffer **buffers, | 
					
						
							|  |  |  | 			     uint32_t *n_buffers) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-04-10 15:54:29 +02:00
										 |  |  | 	struct impl *this; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	spa_return_val_if_fail(node != NULL, -EINVAL); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	this = SPA_CONTAINER_OF(node, struct impl, node); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-15 11:31:42 +02:00
										 |  |  | 	return spa_node_port_alloc_buffers(this->fmt[direction], direction, port_id, | 
					
						
							| 
									
										
										
										
											2018-04-10 15:54:29 +02:00
										 |  |  | 			params, n_params, buffers, n_buffers); | 
					
						
							| 
									
										
										
										
											2018-04-06 18:39:07 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int | 
					
						
							|  |  |  | impl_node_port_set_io(struct spa_node *node, | 
					
						
							|  |  |  | 		      enum spa_direction direction, uint32_t port_id, | 
					
						
							|  |  |  | 		      uint32_t id, void *data, size_t size) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct impl *this; | 
					
						
							| 
									
										
										
										
											2018-07-03 21:34:22 +02:00
										 |  |  | 	int res; | 
					
						
							| 
									
										
										
										
											2018-04-06 18:39:07 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	spa_return_val_if_fail(node != NULL, -EINVAL); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	this = SPA_CONTAINER_OF(node, struct impl, node); | 
					
						
							| 
									
										
										
										
											2018-06-15 12:45:04 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-03 21:34:22 +02:00
										 |  |  | 	spa_log_debug(this->log, "set io %d %d %d", id, direction, port_id); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-28 18:16:41 +02:00
										 |  |  | 	switch (id) { | 
					
						
							|  |  |  | 	case SPA_IO_Range: | 
					
						
							| 
									
										
										
										
											2018-07-03 21:34:22 +02:00
										 |  |  | 		res = spa_node_port_set_io(this->resample, direction, 0, id, data, size); | 
					
						
							| 
									
										
										
										
											2018-08-28 18:16:41 +02:00
										 |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2018-08-30 12:02:39 +02:00
										 |  |  | 	case SPA_IO_Control: | 
					
						
							|  |  |  | 		res = spa_node_port_set_io(this->channelmix, direction, 0, id, data, size); | 
					
						
							|  |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2018-08-28 18:16:41 +02:00
										 |  |  | 	default: | 
					
						
							| 
									
										
										
										
											2018-07-03 21:34:22 +02:00
										 |  |  | 		res = spa_node_port_set_io(this->fmt[direction], direction, port_id, id, data, size); | 
					
						
							| 
									
										
										
										
											2018-08-28 18:16:41 +02:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-07-03 21:34:22 +02:00
										 |  |  | 	return res; | 
					
						
							| 
									
										
										
										
											2018-04-06 18:39:07 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int impl_node_port_reuse_buffer(struct spa_node *node, uint32_t port_id, uint32_t buffer_id) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct impl *this; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	spa_return_val_if_fail(node != NULL, -EINVAL); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	this = SPA_CONTAINER_OF(node, struct impl, node); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-15 11:31:42 +02:00
										 |  |  | 	return spa_node_port_reuse_buffer(this->fmt[SPA_DIRECTION_OUTPUT], port_id, buffer_id); | 
					
						
							| 
									
										
										
										
											2018-04-06 18:39:07 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int | 
					
						
							|  |  |  | impl_node_port_send_command(struct spa_node *node, | 
					
						
							|  |  |  | 			    enum spa_direction direction, | 
					
						
							|  |  |  | 			    uint32_t port_id, | 
					
						
							|  |  |  | 			    const struct spa_command *command) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct impl *this; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	spa_return_val_if_fail(node != NULL, -EINVAL); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	this = SPA_CONTAINER_OF(node, struct impl, node); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-15 11:31:42 +02:00
										 |  |  | 	return spa_node_port_send_command(this->fmt[direction], direction, port_id, command); | 
					
						
							| 
									
										
										
										
											2018-04-10 15:54:29 +02:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2018-04-06 18:39:07 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-10 15:54:29 +02:00
										 |  |  | static int impl_node_process(struct spa_node *node) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct impl *this; | 
					
						
							| 
									
										
										
										
											2018-06-15 11:31:42 +02:00
										 |  |  | 	int r, i, res = SPA_STATUS_OK; | 
					
						
							| 
									
										
										
										
											2018-06-22 17:27:57 +02:00
										 |  |  | 	int ready; | 
					
						
							| 
									
										
										
										
											2018-04-06 18:39:07 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-10 15:54:29 +02:00
										 |  |  | 	spa_return_val_if_fail(node != NULL, -EINVAL); | 
					
						
							| 
									
										
										
										
											2018-04-06 18:39:07 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-10 15:54:29 +02:00
										 |  |  | 	this = SPA_CONTAINER_OF(node, struct impl, node); | 
					
						
							| 
									
										
										
										
											2018-04-06 18:39:07 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-10 15:54:29 +02:00
										 |  |  | 	spa_log_trace(this->log, NAME " %p: process %d", this, this->n_links); | 
					
						
							| 
									
										
										
										
											2018-04-06 18:39:07 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-22 17:27:57 +02:00
										 |  |  | 	while (1) { | 
					
						
							|  |  |  | 		res = SPA_STATUS_OK; | 
					
						
							|  |  |  | 		ready = 0; | 
					
						
							|  |  |  | 		for (i = 0; i < this->n_nodes; i++) { | 
					
						
							|  |  |  | 			r = spa_node_process(this->nodes[i]); | 
					
						
							|  |  |  | 			spa_log_trace(this->log, NAME " %p: process %d %d", this, i, r); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-31 12:23:35 +02:00
										 |  |  | 			if (r < 0) | 
					
						
							|  |  |  | 				return r; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-22 17:27:57 +02:00
										 |  |  | 			if (r & SPA_STATUS_HAVE_BUFFER) | 
					
						
							|  |  |  | 				ready++; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			if (i == 0) | 
					
						
							|  |  |  | 				res |= r & SPA_STATUS_NEED_BUFFER; | 
					
						
							|  |  |  | 			if (i == this->n_nodes-1) | 
					
						
							|  |  |  | 				res |= r & SPA_STATUS_HAVE_BUFFER; | 
					
						
							| 
									
										
										
										
											2018-04-19 20:12:24 +02:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-06-22 17:27:57 +02:00
										 |  |  | 		if (res & SPA_STATUS_HAVE_BUFFER) | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		if (ready == 0) | 
					
						
							|  |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2018-04-19 20:12:24 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-04-06 18:39:07 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-19 20:12:24 +02:00
										 |  |  | 	spa_log_trace(this->log, NAME " %p: process result: %d", this, res); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return res; | 
					
						
							| 
									
										
										
										
											2018-04-06 18:39:07 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static const struct spa_node impl_node = { | 
					
						
							|  |  |  | 	SPA_VERSION_NODE, | 
					
						
							|  |  |  | 	impl_node_enum_params, | 
					
						
							|  |  |  | 	impl_node_set_param, | 
					
						
							| 
									
										
										
										
											2018-10-23 12:31:41 +02:00
										 |  |  | 	impl_node_set_io, | 
					
						
							| 
									
										
										
										
											2018-04-06 18:39:07 +02:00
										 |  |  | 	impl_node_send_command, | 
					
						
							|  |  |  | 	impl_node_set_callbacks, | 
					
						
							|  |  |  | 	impl_node_get_n_ports, | 
					
						
							|  |  |  | 	impl_node_get_port_ids, | 
					
						
							|  |  |  | 	impl_node_add_port, | 
					
						
							|  |  |  | 	impl_node_remove_port, | 
					
						
							|  |  |  | 	impl_node_port_get_info, | 
					
						
							|  |  |  | 	impl_node_port_enum_params, | 
					
						
							|  |  |  | 	impl_node_port_set_param, | 
					
						
							|  |  |  | 	impl_node_port_use_buffers, | 
					
						
							|  |  |  | 	impl_node_port_alloc_buffers, | 
					
						
							|  |  |  | 	impl_node_port_set_io, | 
					
						
							|  |  |  | 	impl_node_port_reuse_buffer, | 
					
						
							|  |  |  | 	impl_node_port_send_command, | 
					
						
							|  |  |  | 	impl_node_process, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-27 15:03:11 +02:00
										 |  |  | static int impl_get_interface(struct spa_handle *handle, uint32_t type, void **interface) | 
					
						
							| 
									
										
										
										
											2018-04-06 18:39:07 +02:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct impl *this; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	spa_return_val_if_fail(handle != NULL, -EINVAL); | 
					
						
							|  |  |  | 	spa_return_val_if_fail(interface != NULL, -EINVAL); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	this = (struct impl *) handle; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-27 15:03:11 +02:00
										 |  |  | 	if (type == SPA_TYPE_INTERFACE_Node) | 
					
						
							| 
									
										
										
										
											2018-04-06 18:39:07 +02:00
										 |  |  | 		*interface = &this->node; | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		return -ENOENT; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int impl_clear(struct spa_handle *handle) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-04-20 16:27:19 +02:00
										 |  |  | 	struct impl *this; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	spa_return_val_if_fail(handle != NULL, -EINVAL); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	this = (struct impl *) handle; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-17 17:27:14 +02:00
										 |  |  | 	clean_convert(this); | 
					
						
							| 
									
										
										
										
											2018-04-06 18:39:07 +02:00
										 |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-10 15:54:29 +02:00
										 |  |  | extern const struct spa_handle_factory spa_fmtconvert_factory; | 
					
						
							|  |  |  | extern const struct spa_handle_factory spa_channelmix_factory; | 
					
						
							|  |  |  | extern const struct spa_handle_factory spa_resample_factory; | 
					
						
							| 
									
										
										
										
											2018-10-04 15:56:54 +02:00
										 |  |  | extern const struct spa_handle_factory spa_splitter_factory; | 
					
						
							|  |  |  | extern const struct spa_handle_factory spa_merger_factory; | 
					
						
							| 
									
										
										
										
											2018-04-10 15:54:29 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-09 10:06:17 +02:00
										 |  |  | static size_t | 
					
						
							|  |  |  | impl_get_size(const struct spa_handle_factory *factory, | 
					
						
							|  |  |  | 	      const struct spa_dict *params) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-10-04 15:56:54 +02:00
										 |  |  | 	size_t size, max; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	max = spa_handle_factory_get_size(&spa_fmtconvert_factory, params); | 
					
						
							|  |  |  | 	max = SPA_MAX(max, spa_handle_factory_get_size(&spa_splitter_factory, params)); | 
					
						
							|  |  |  | 	max = SPA_MAX(max, spa_handle_factory_get_size(&spa_merger_factory, params)); | 
					
						
							| 
									
										
										
										
											2018-04-10 15:54:29 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	size = sizeof(struct impl); | 
					
						
							| 
									
										
										
										
											2018-10-04 15:56:54 +02:00
										 |  |  | 	size += max * 2; | 
					
						
							| 
									
										
										
										
											2018-04-10 15:54:29 +02:00
										 |  |  | 	size += spa_handle_factory_get_size(&spa_channelmix_factory, params); | 
					
						
							|  |  |  | 	size += spa_handle_factory_get_size(&spa_resample_factory, params); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return size; | 
					
						
							| 
									
										
										
										
											2018-04-09 10:06:17 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-06 18:39:07 +02:00
										 |  |  | static int | 
					
						
							|  |  |  | impl_init(const struct spa_handle_factory *factory, | 
					
						
							|  |  |  | 	  struct spa_handle *handle, | 
					
						
							|  |  |  | 	  const struct spa_dict *info, | 
					
						
							|  |  |  | 	  const struct spa_support *support, | 
					
						
							|  |  |  | 	  uint32_t n_support) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct impl *this; | 
					
						
							|  |  |  | 	uint32_t i; | 
					
						
							| 
									
										
										
										
											2018-04-10 15:54:29 +02:00
										 |  |  | 	size_t size; | 
					
						
							|  |  |  | 	void *iface; | 
					
						
							| 
									
										
										
										
											2018-10-04 15:56:54 +02:00
										 |  |  | 	const char *str; | 
					
						
							|  |  |  | 	const struct spa_handle_factory *in_factory, *out_factory; | 
					
						
							| 
									
										
										
										
											2018-04-06 18:39:07 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	spa_return_val_if_fail(factory != NULL, -EINVAL); | 
					
						
							|  |  |  | 	spa_return_val_if_fail(handle != NULL, -EINVAL); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	handle->get_interface = impl_get_interface; | 
					
						
							|  |  |  | 	handle->clear = impl_clear; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	this = (struct impl *) handle; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (i = 0; i < n_support; i++) { | 
					
						
							| 
									
										
										
										
											2018-08-27 15:03:11 +02:00
										 |  |  | 		if (support[i].type == SPA_TYPE_INTERFACE_Log) | 
					
						
							| 
									
										
										
										
											2018-04-06 18:39:07 +02:00
										 |  |  | 			this->log = support[i].data; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	this->node = impl_node; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-04 15:56:54 +02:00
										 |  |  | 	if (info == NULL || (str = spa_dict_lookup(info, "factory.mode")) == NULL) | 
					
						
							|  |  |  | 		str = "convert"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (strcmp(str, "split") == 0) { | 
					
						
							| 
									
										
										
										
											2018-11-19 09:46:36 +01:00
										 |  |  | 		this->mode = MODE_SPLIT; | 
					
						
							| 
									
										
										
										
											2018-10-04 15:56:54 +02:00
										 |  |  | 		in_factory = &spa_fmtconvert_factory; | 
					
						
							|  |  |  | 		out_factory = &spa_splitter_factory; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else if (strcmp(str, "merge") == 0) { | 
					
						
							| 
									
										
										
										
											2018-11-19 09:46:36 +01:00
										 |  |  | 		this->mode = MODE_MERGE; | 
					
						
							| 
									
										
										
										
											2018-10-04 15:56:54 +02:00
										 |  |  | 		in_factory = &spa_merger_factory; | 
					
						
							|  |  |  | 		out_factory = &spa_fmtconvert_factory; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							| 
									
										
										
										
											2018-11-19 09:46:36 +01:00
										 |  |  | 		this->mode = MODE_CONVERT; | 
					
						
							| 
									
										
										
										
											2018-10-04 15:56:54 +02:00
										 |  |  | 		in_factory = &spa_fmtconvert_factory; | 
					
						
							|  |  |  | 		out_factory = &spa_fmtconvert_factory; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-15 11:31:42 +02:00
										 |  |  | 	this->hnd_fmt[SPA_DIRECTION_INPUT] = SPA_MEMBER(this, sizeof(struct impl), struct spa_handle); | 
					
						
							| 
									
										
										
										
											2018-10-04 15:56:54 +02:00
										 |  |  | 	spa_handle_factory_init(in_factory, | 
					
						
							| 
									
										
										
										
											2018-06-15 11:31:42 +02:00
										 |  |  | 				this->hnd_fmt[SPA_DIRECTION_INPUT], | 
					
						
							| 
									
										
										
										
											2018-04-10 15:54:29 +02:00
										 |  |  | 				info, support, n_support); | 
					
						
							| 
									
										
										
										
											2018-10-04 15:56:54 +02:00
										 |  |  | 	size = spa_handle_factory_get_size(in_factory, info); | 
					
						
							| 
									
										
										
										
											2018-04-10 15:54:29 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-15 11:31:42 +02:00
										 |  |  | 	this->hnd_channelmix = SPA_MEMBER(this->hnd_fmt[SPA_DIRECTION_INPUT], size, struct spa_handle); | 
					
						
							| 
									
										
										
										
											2018-04-10 15:54:29 +02:00
										 |  |  | 	spa_handle_factory_init(&spa_channelmix_factory, | 
					
						
							|  |  |  | 				this->hnd_channelmix, | 
					
						
							|  |  |  | 				info, support, n_support); | 
					
						
							|  |  |  | 	size = spa_handle_factory_get_size(&spa_channelmix_factory, info); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-04 15:56:54 +02:00
										 |  |  | 	this->hnd_resample = SPA_MEMBER(this->hnd_channelmix, size, struct spa_handle); | 
					
						
							| 
									
										
										
										
											2018-04-10 15:54:29 +02:00
										 |  |  | 	spa_handle_factory_init(&spa_resample_factory, | 
					
						
							|  |  |  | 				this->hnd_resample, | 
					
						
							|  |  |  | 				info, support, n_support); | 
					
						
							|  |  |  | 	size = spa_handle_factory_get_size(&spa_resample_factory, info); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-04 15:56:54 +02:00
										 |  |  | 	this->hnd_fmt[SPA_DIRECTION_OUTPUT] = SPA_MEMBER(this->hnd_resample, size, struct spa_handle); | 
					
						
							|  |  |  | 	spa_handle_factory_init(out_factory, | 
					
						
							|  |  |  | 				this->hnd_fmt[SPA_DIRECTION_OUTPUT], | 
					
						
							|  |  |  | 				info, support, n_support); | 
					
						
							|  |  |  | 	size = spa_handle_factory_get_size(out_factory, info); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-27 15:03:11 +02:00
										 |  |  | 	spa_handle_get_interface(this->hnd_fmt[SPA_DIRECTION_INPUT], SPA_TYPE_INTERFACE_Node, &iface); | 
					
						
							| 
									
										
										
										
											2018-06-15 11:31:42 +02:00
										 |  |  | 	this->fmt[SPA_DIRECTION_INPUT] = iface; | 
					
						
							| 
									
										
										
										
											2018-08-27 15:03:11 +02:00
										 |  |  | 	spa_handle_get_interface(this->hnd_channelmix, SPA_TYPE_INTERFACE_Node, &iface); | 
					
						
							| 
									
										
										
										
											2018-04-10 15:54:29 +02:00
										 |  |  | 	this->channelmix = iface; | 
					
						
							| 
									
										
										
										
											2018-08-27 15:03:11 +02:00
										 |  |  | 	spa_handle_get_interface(this->hnd_resample, SPA_TYPE_INTERFACE_Node, &iface); | 
					
						
							| 
									
										
										
										
											2018-04-10 15:54:29 +02:00
										 |  |  | 	this->resample = iface; | 
					
						
							| 
									
										
										
										
											2018-10-04 15:56:54 +02:00
										 |  |  | 	spa_handle_get_interface(this->hnd_fmt[SPA_DIRECTION_OUTPUT], SPA_TYPE_INTERFACE_Node, &iface); | 
					
						
							|  |  |  | 	this->fmt[SPA_DIRECTION_OUTPUT] = iface; | 
					
						
							| 
									
										
										
										
											2018-04-10 15:54:29 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-06 18:39:07 +02:00
										 |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static const struct spa_interface_info impl_interfaces[] = { | 
					
						
							| 
									
										
										
										
											2018-08-27 15:03:11 +02:00
										 |  |  | 	{ SPA_TYPE_INTERFACE_Node, }, | 
					
						
							| 
									
										
										
										
											2018-04-06 18:39:07 +02:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int | 
					
						
							|  |  |  | impl_enum_interface_info(const struct spa_handle_factory *factory, | 
					
						
							|  |  |  | 			 const struct spa_interface_info **info, | 
					
						
							|  |  |  | 			 uint32_t *index) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	spa_return_val_if_fail(factory != NULL, -EINVAL); | 
					
						
							|  |  |  | 	spa_return_val_if_fail(info != NULL, -EINVAL); | 
					
						
							|  |  |  | 	spa_return_val_if_fail(index != NULL, -EINVAL); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	switch (*index) { | 
					
						
							|  |  |  | 	case 0: | 
					
						
							|  |  |  | 		*info = &impl_interfaces[*index]; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	default: | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	(*index)++; | 
					
						
							|  |  |  | 	return 1; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const struct spa_handle_factory spa_audioconvert_factory = { | 
					
						
							|  |  |  | 	SPA_VERSION_HANDLE_FACTORY, | 
					
						
							|  |  |  | 	NAME, | 
					
						
							|  |  |  | 	NULL, | 
					
						
							| 
									
										
										
										
											2018-04-09 10:06:17 +02:00
										 |  |  | 	impl_get_size, | 
					
						
							| 
									
										
										
										
											2018-04-06 18:39:07 +02:00
										 |  |  | 	impl_init, | 
					
						
							|  |  |  | 	impl_enum_interface_info, | 
					
						
							|  |  |  | }; |