alsa-seq: fix port delete

We need to first mark the removed port as invalid, and then look for the
last valid port in the port array otherwise last_port becomes 0 and
midi dataflow stops.

Fixes #1601
This commit is contained in:
Wim Taymans 2021-09-14 18:08:30 +02:00
parent bf29130f84
commit d793086174
2 changed files with 9 additions and 1 deletions

View file

@ -384,13 +384,16 @@ static struct seq_port *alloc_port(struct seq_state *state, struct seq_stream *s
static void free_port(struct seq_state *state, struct seq_stream *stream, struct seq_port *port)
{
port->valid = false;
if (port->id + 1 == stream->last_port) {
int i;
for (i = stream->last_port - 1; i >= 0; i--)
if (!stream->ports[i].valid)
if (stream->ports[i].valid)
break;
stream->last_port = i + 1;
}
spa_node_emit_port_info(&state->hooks,
port->direction, port->id, NULL);
spa_zero(*port);

View file

@ -247,6 +247,11 @@ static void alsa_seq_on_sys(struct spa_source *source)
addr->client, addr->port);
state->port_info(state->port_info_data, addr, NULL);
break;
default:
spa_log_info(state->log, "unhandled event %d: %d:%d",
ev->type, addr->client, addr->port);
break;
}
snd_seq_free_event(ev);
}