mirror of
				https://gitlab.freedesktop.org/pipewire/pipewire.git
				synced 2025-11-03 09:01:54 -05:00 
			
		
		
		
	filter-graph: separate data and size for filter graph
Remove the chunk and add separate arrays with data and n_samples. This aligns better with other methods and makes it possible to more easily reuse arrays of pointers as input and output.
This commit is contained in:
		
							parent
							
								
									d6030adada
								
							
						
					
					
						commit
						49f48a5fda
					
				
					 3 changed files with 22 additions and 40 deletions
				
			
		| 
						 | 
				
			
			@ -63,11 +63,6 @@ struct spa_filter_graph_events {
 | 
			
		|||
	void (*props_changed) (void *object, enum spa_direction direction);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
struct spa_filter_graph_chunk {
 | 
			
		||||
	void *data;
 | 
			
		||||
	size_t size;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
struct spa_filter_graph_methods {
 | 
			
		||||
#define SPA_VERSION_FILTER_GRAPH_METHODS	0
 | 
			
		||||
	uint32_t version;
 | 
			
		||||
| 
						 | 
				
			
			@ -87,9 +82,7 @@ struct spa_filter_graph_methods {
 | 
			
		|||
 | 
			
		||||
	int (*reset) (void *object);
 | 
			
		||||
 | 
			
		||||
	int (*process) (void *object,
 | 
			
		||||
			const struct spa_filter_graph_chunk in[], uint32_t n_in,
 | 
			
		||||
			struct spa_filter_graph_chunk out[], uint32_t n_out);
 | 
			
		||||
	int (*process) (void *object, const void *in[], void *out[], uint32_t n_samples);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
SPA_API_FILTER_GRAPH int spa_filter_graph_add_listener(struct spa_filter_graph *object,
 | 
			
		||||
| 
						 | 
				
			
			@ -139,11 +132,10 @@ SPA_API_FILTER_GRAPH int spa_filter_graph_reset(struct spa_filter_graph *object)
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
SPA_API_FILTER_GRAPH int spa_filter_graph_process(struct spa_filter_graph *object,
 | 
			
		||||
			const struct spa_filter_graph_chunk in[], uint32_t n_in,
 | 
			
		||||
			struct spa_filter_graph_chunk out[], uint32_t n_out)
 | 
			
		||||
			const void *in[], void *out[], uint32_t n_samples)
 | 
			
		||||
{
 | 
			
		||||
	return spa_api_method_r(int, -ENOTSUP,
 | 
			
		||||
			spa_filter_graph, &object->iface, process, 0, in, n_in, out, n_out);
 | 
			
		||||
			spa_filter_graph, &object->iface, process, 0, in, out, n_samples);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -236,39 +236,33 @@ impl_add_listener(void *object,
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
static int impl_process(void *object,
 | 
			
		||||
		const struct spa_filter_graph_chunk in[], uint32_t n_in,
 | 
			
		||||
		struct spa_filter_graph_chunk out[], uint32_t n_out)
 | 
			
		||||
		const void *in[], void *out[], uint32_t n_samples)
 | 
			
		||||
{
 | 
			
		||||
	struct impl *impl = object;
 | 
			
		||||
	struct graph *graph = &impl->graph;
 | 
			
		||||
	uint32_t i, j, insize = 0, outsize = 0, n_hndl = graph->n_hndl;
 | 
			
		||||
	uint32_t i, j, n_hndl = graph->n_hndl;
 | 
			
		||||
	struct graph_port *port;
 | 
			
		||||
 | 
			
		||||
	for (i = 0, j = 0; i < n_in; i++) {
 | 
			
		||||
	for (i = 0, j = 0; i < impl->info.n_inputs; i++) {
 | 
			
		||||
		while (j < graph->n_input) {
 | 
			
		||||
			port = &graph->input[j++];
 | 
			
		||||
			if (port->desc)
 | 
			
		||||
				port->desc->connect_port(*port->hndl, port->port, in[i].data);
 | 
			
		||||
				port->desc->connect_port(*port->hndl, port->port, (float*)in[i]);
 | 
			
		||||
			if (!port->next)
 | 
			
		||||
				break;
 | 
			
		||||
		}
 | 
			
		||||
		insize = i == 0 ? in[i].size : SPA_MIN(insize, in[i].size);
 | 
			
		||||
	}
 | 
			
		||||
	outsize = insize;
 | 
			
		||||
 | 
			
		||||
	for (i = 0; i < n_out; i++) {
 | 
			
		||||
		outsize = SPA_MIN(outsize, out[i].size);
 | 
			
		||||
 | 
			
		||||
	for (i = 0; i < impl->info.n_outputs; i++) {
 | 
			
		||||
		port = i < graph->n_output ? &graph->output[i] : NULL;
 | 
			
		||||
 | 
			
		||||
		if (port && port->desc)
 | 
			
		||||
			port->desc->connect_port(*port->hndl, port->port, out[i].data);
 | 
			
		||||
			port->desc->connect_port(*port->hndl, port->port, (float*)out[i]);
 | 
			
		||||
		else
 | 
			
		||||
			memset(out[i].data, 0, outsize);
 | 
			
		||||
			memset(out[i], 0, n_samples * sizeof(float));
 | 
			
		||||
	}
 | 
			
		||||
	for (i = 0; i < n_hndl; i++) {
 | 
			
		||||
		struct graph_hndl *hndl = &graph->hndl[i];
 | 
			
		||||
		hndl->desc->run(*hndl->hndl, outsize / sizeof(float));
 | 
			
		||||
		hndl->desc->run(*hndl->hndl, n_samples);
 | 
			
		||||
	}
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -870,10 +870,11 @@ static void playback_process(void *d)
 | 
			
		|||
{
 | 
			
		||||
	struct impl *impl = d;
 | 
			
		||||
	struct pw_buffer *in, *out;
 | 
			
		||||
	uint32_t i, insize = 0, outsize = 0;
 | 
			
		||||
	uint32_t i, data_size = 0;
 | 
			
		||||
	int32_t stride = 0;
 | 
			
		||||
	struct spa_data *bd;
 | 
			
		||||
	struct spa_filter_graph_chunk cin[128], cout[128];
 | 
			
		||||
	const void *cin[128];
 | 
			
		||||
	void *cout[128];
 | 
			
		||||
 | 
			
		||||
	in = NULL;
 | 
			
		||||
	while (true) {
 | 
			
		||||
| 
						 | 
				
			
			@ -901,33 +902,28 @@ static void playback_process(void *d)
 | 
			
		|||
		offs = SPA_MIN(bd->chunk->offset, bd->maxsize);
 | 
			
		||||
		size = SPA_MIN(bd->chunk->size, bd->maxsize - offs);
 | 
			
		||||
 | 
			
		||||
		cin[i].data = SPA_PTROFF(bd->data, offs, void);
 | 
			
		||||
		cin[i].size = size;
 | 
			
		||||
		cin[i] = SPA_PTROFF(bd->data, offs, void);
 | 
			
		||||
 | 
			
		||||
		insize = i == 0 ? size : SPA_MIN(insize, size);
 | 
			
		||||
		data_size = i == 0 ? size : SPA_MIN(data_size, size);
 | 
			
		||||
		stride = SPA_MAX(stride, bd->chunk->stride);
 | 
			
		||||
	}
 | 
			
		||||
	outsize = insize;
 | 
			
		||||
 | 
			
		||||
	for (i = 0; i < out->buffer->n_datas; i++) {
 | 
			
		||||
		bd = &out->buffer->datas[i];
 | 
			
		||||
 | 
			
		||||
		outsize = SPA_MIN(outsize, bd->maxsize);
 | 
			
		||||
		data_size = SPA_MIN(data_size, bd->maxsize);
 | 
			
		||||
 | 
			
		||||
		cout[i].data = bd->data;
 | 
			
		||||
		cout[i].size = outsize;
 | 
			
		||||
		cout[i] = bd->data;
 | 
			
		||||
 | 
			
		||||
		bd->chunk->offset = 0;
 | 
			
		||||
		bd->chunk->size = outsize;
 | 
			
		||||
		bd->chunk->size = data_size;
 | 
			
		||||
		bd->chunk->stride = stride;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	pw_log_trace_fp("%p: stride:%d in:%d out:%d requested:%"PRIu64" (%"PRIu64")", impl,
 | 
			
		||||
			stride, insize, outsize, out->requested, out->requested * stride);
 | 
			
		||||
	pw_log_trace_fp("%p: stride:%d size:%d requested:%"PRIu64" (%"PRIu64")", impl,
 | 
			
		||||
			stride, data_size, out->requested, out->requested * stride);
 | 
			
		||||
 | 
			
		||||
	spa_filter_graph_process(impl->graph,
 | 
			
		||||
			cin, in->buffer->n_datas,
 | 
			
		||||
			cout, out->buffer->n_datas);
 | 
			
		||||
	spa_filter_graph_process(impl->graph, cin, cout, data_size / sizeof(float));
 | 
			
		||||
 | 
			
		||||
done:
 | 
			
		||||
	if (in != NULL)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue