alsa-seq: handle midi event decoder errors

This commit is contained in:
Wim Taymans 2022-06-20 16:12:49 +02:00
parent 40f50deae9
commit 25d9039f2e

View file

@ -131,13 +131,18 @@ static int seq_close(struct seq_state *state, struct seq_conn *conn)
static int init_stream(struct seq_state *state, enum spa_direction direction)
{
struct seq_stream *stream = &state->streams[direction];
int res;
stream->direction = direction;
if (direction == SPA_DIRECTION_INPUT) {
stream->caps = SND_SEQ_PORT_CAP_SUBS_WRITE;
} else {
stream->caps = SND_SEQ_PORT_CAP_SUBS_READ;
}
snd_midi_event_new(MAX_EVENT_SIZE, &stream->codec);
if ((res = snd_midi_event_new(MAX_EVENT_SIZE, &stream->codec)) < 0) {
spa_log_error(state->log, "can make event decoder: %s",
snd_strerror(res));
return res;
}
memset(stream->ports, 0, sizeof(stream->ports));
return 0;
}
@ -145,7 +150,9 @@ static int init_stream(struct seq_state *state, enum spa_direction direction)
static int uninit_stream(struct seq_state *state, enum spa_direction direction)
{
struct seq_stream *stream = &state->streams[direction];
snd_midi_event_free(stream->codec);
if (stream->codec)
snd_midi_event_free(stream->codec);
stream->codec = NULL;
return 0;
}