mirror of
				https://gitlab.freedesktop.org/pipewire/pipewire.git
				synced 2025-11-03 09:01:54 -05:00 
			
		
		
		
	alsa-seq: keep track of last port
Keep track of the last port and only iterate until that port.
This commit is contained in:
		
							parent
							
								
									b3bddb853f
								
							
						
					
					
						commit
						74665de68e
					
				
					 3 changed files with 19 additions and 9 deletions
				
			
		| 
						 | 
					@ -350,7 +350,7 @@ static struct seq_port *find_port(struct seq_state *state,
 | 
				
			||||||
		struct seq_stream *stream, const snd_seq_addr_t *addr)
 | 
							struct seq_stream *stream, const snd_seq_addr_t *addr)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	uint32_t i;
 | 
						uint32_t i;
 | 
				
			||||||
	for (i = 0; i < MAX_PORTS; i++) {
 | 
						for (i = 0; i < stream->last_port; i++) {
 | 
				
			||||||
		struct seq_port *port = &stream->ports[i];
 | 
							struct seq_port *port = &stream->ports[i];
 | 
				
			||||||
		if (port->valid &&
 | 
							if (port->valid &&
 | 
				
			||||||
		    port->addr.client == addr->client &&
 | 
							    port->addr.client == addr->client &&
 | 
				
			||||||
| 
						 | 
					@ -369,14 +369,23 @@ static struct seq_port *alloc_port(struct seq_state *state, struct seq_stream *s
 | 
				
			||||||
			port->id = i;
 | 
								port->id = i;
 | 
				
			||||||
			port->direction = stream->direction;
 | 
								port->direction = stream->direction;
 | 
				
			||||||
			port->valid = true;
 | 
								port->valid = true;
 | 
				
			||||||
 | 
								if (stream->last_port < i + 1)
 | 
				
			||||||
 | 
									stream->last_port = i + 1;
 | 
				
			||||||
			return port;
 | 
								return port;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return NULL;
 | 
						return NULL;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void free_port(struct seq_state *state, struct seq_port *port)
 | 
					static void free_port(struct seq_state *state, struct seq_stream *stream, struct seq_port *port)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
						if (port->id + 1 == stream->last_port) {
 | 
				
			||||||
 | 
							int i;
 | 
				
			||||||
 | 
							for (i = stream->last_port - 1; i >= 0; i--)
 | 
				
			||||||
 | 
								if (!stream->ports[i].valid)
 | 
				
			||||||
 | 
									break;
 | 
				
			||||||
 | 
							stream->last_port = i + 1;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	spa_node_emit_port_info(&state->hooks,
 | 
						spa_node_emit_port_info(&state->hooks,
 | 
				
			||||||
			port->direction, port->id, NULL);
 | 
								port->direction, port->id, NULL);
 | 
				
			||||||
	spa_zero(*port);
 | 
						spa_zero(*port);
 | 
				
			||||||
| 
						 | 
					@ -417,7 +426,7 @@ static void update_stream_port(struct seq_state *state, struct seq_stream *strea
 | 
				
			||||||
	if (info == NULL) {
 | 
						if (info == NULL) {
 | 
				
			||||||
		spa_log_debug(state->log, "free port %d.%d", addr->client, addr->port);
 | 
							spa_log_debug(state->log, "free port %d.%d", addr->client, addr->port);
 | 
				
			||||||
		if (port)
 | 
							if (port)
 | 
				
			||||||
			free_port(state, port);
 | 
								free_port(state, stream, port);
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		if (port == NULL && (caps & stream->caps) == stream->caps) {
 | 
							if (port == NULL && (caps & stream->caps) == stream->caps) {
 | 
				
			||||||
			spa_log_debug(state->log, "new port %d.%d", addr->client, addr->port);
 | 
								spa_log_debug(state->log, "new port %d.%d", addr->client, addr->port);
 | 
				
			||||||
| 
						 | 
					@ -428,7 +437,7 @@ static void update_stream_port(struct seq_state *state, struct seq_stream *strea
 | 
				
			||||||
		} else if (port != NULL) {
 | 
							} else if (port != NULL) {
 | 
				
			||||||
			if ((caps & stream->caps) != stream->caps) {
 | 
								if ((caps & stream->caps) != stream->caps) {
 | 
				
			||||||
				spa_log_debug(state->log, "free port %d.%d", addr->client, addr->port);
 | 
									spa_log_debug(state->log, "free port %d.%d", addr->client, addr->port);
 | 
				
			||||||
				free_port(state, port);
 | 
									free_port(state, stream, port);
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			else {
 | 
								else {
 | 
				
			||||||
				spa_log_debug(state->log, "update port %d.%d", addr->client, addr->port);
 | 
									spa_log_debug(state->log, "update port %d.%d", addr->client, addr->port);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -366,7 +366,7 @@ static struct seq_port *find_port(struct seq_state *state,
 | 
				
			||||||
		struct seq_stream *stream, const snd_seq_addr_t *addr)
 | 
							struct seq_stream *stream, const snd_seq_addr_t *addr)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	uint32_t i;
 | 
						uint32_t i;
 | 
				
			||||||
	for (i = 0; i < MAX_PORTS; i++) {
 | 
						for (i = 0; i < stream->last_port; i++) {
 | 
				
			||||||
		struct seq_port *port = &stream->ports[i];
 | 
							struct seq_port *port = &stream->ports[i];
 | 
				
			||||||
		if (port->valid &&
 | 
							if (port->valid &&
 | 
				
			||||||
		    port->addr.client == addr->client &&
 | 
							    port->addr.client == addr->client &&
 | 
				
			||||||
| 
						 | 
					@ -460,7 +460,7 @@ static int process_recycle(struct seq_state *state)
 | 
				
			||||||
	struct seq_stream *stream = &state->streams[SPA_DIRECTION_OUTPUT];
 | 
						struct seq_stream *stream = &state->streams[SPA_DIRECTION_OUTPUT];
 | 
				
			||||||
	uint32_t i;
 | 
						uint32_t i;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for (i = 0; i < MAX_PORTS; i++) {
 | 
						for (i = 0; i < stream->last_port; i++) {
 | 
				
			||||||
		struct seq_port *port = &stream->ports[i];
 | 
							struct seq_port *port = &stream->ports[i];
 | 
				
			||||||
		struct spa_io_buffers *io = port->io;
 | 
							struct spa_io_buffers *io = port->io;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -547,7 +547,7 @@ static int process_read(struct seq_state *state)
 | 
				
			||||||
	/* prepare a buffer on each port, some ports might have their
 | 
						/* prepare a buffer on each port, some ports might have their
 | 
				
			||||||
	 * buffer filled above */
 | 
						 * buffer filled above */
 | 
				
			||||||
	res = 0;
 | 
						res = 0;
 | 
				
			||||||
	for (i = 0; i < MAX_PORTS; i++) {
 | 
						for (i = 0; i < stream->last_port; i++) {
 | 
				
			||||||
		struct seq_port *port = &stream->ports[i];
 | 
							struct seq_port *port = &stream->ports[i];
 | 
				
			||||||
		struct spa_io_buffers *io = port->io;
 | 
							struct spa_io_buffers *io = port->io;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -599,7 +599,7 @@ static int process_write(struct seq_state *state)
 | 
				
			||||||
	uint32_t i;
 | 
						uint32_t i;
 | 
				
			||||||
	int res = 0;
 | 
						int res = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for (i = 0; i < MAX_PORTS; i++) {
 | 
						for (i = 0; i < stream->last_port; i++) {
 | 
				
			||||||
		struct seq_port *port = &stream->ports[i];
 | 
							struct seq_port *port = &stream->ports[i];
 | 
				
			||||||
		struct spa_io_buffers *io = port->io;
 | 
							struct spa_io_buffers *io = port->io;
 | 
				
			||||||
		struct buffer *buffer;
 | 
							struct buffer *buffer;
 | 
				
			||||||
| 
						 | 
					@ -819,7 +819,7 @@ static void reset_buffers(struct seq_state *this, struct seq_port *port)
 | 
				
			||||||
static void reset_stream(struct seq_state *this, struct seq_stream *stream, bool active)
 | 
					static void reset_stream(struct seq_state *this, struct seq_stream *stream, bool active)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	uint32_t i;
 | 
						uint32_t i;
 | 
				
			||||||
	for (i = 0; i < MAX_PORTS; i++) {
 | 
						for (i = 0; i < stream->last_port; i++) {
 | 
				
			||||||
		struct seq_port *port = &stream->ports[i];
 | 
							struct seq_port *port = &stream->ports[i];
 | 
				
			||||||
		if (port->valid) {
 | 
							if (port->valid) {
 | 
				
			||||||
			reset_buffers(this, port);
 | 
								reset_buffers(this, port);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -94,6 +94,7 @@ struct seq_stream {
 | 
				
			||||||
	unsigned int caps;
 | 
						unsigned int caps;
 | 
				
			||||||
	snd_midi_event_t *codec;
 | 
						snd_midi_event_t *codec;
 | 
				
			||||||
	struct seq_port ports[MAX_PORTS];
 | 
						struct seq_port ports[MAX_PORTS];
 | 
				
			||||||
 | 
						uint32_t last_port;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct seq_conn {
 | 
					struct seq_conn {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue