From 7dcfe81690fd84e965dac9aec006148844bd0fd3 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Thu, 9 May 2024 18:32:14 +0200 Subject: [PATCH] alsa-seq: improve midi encode some more snd_midi_event_encode() will reset the encoder when it returns an encoded event. It is possible that the function returns with an encoded event when the internal buffer is full, in that case we need to push the event and continue encoding without reseting the encoder. 0 is not a snd_midi_event_encode() error, so don't handle it like one. --- spa/plugins/alsa/alsa-seq.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/spa/plugins/alsa/alsa-seq.c b/spa/plugins/alsa/alsa-seq.c index 5410dd080..d3136ab57 100644 --- a/spa/plugins/alsa/alsa-seq.c +++ b/spa/plugins/alsa/alsa-seq.c @@ -649,16 +649,16 @@ static int process_write(struct seq_state *state) if (c->type != SPA_CONTROL_Midi) continue; - if (size == 0) { + if (size == 0) /* only reset when we start decoding a new message */ snd_seq_ev_clear(&ev); - snd_midi_event_reset_encode(stream->codec); - } + if ((s = snd_midi_event_encode(stream->codec, SPA_POD_BODY(&c->value), - SPA_POD_BODY_SIZE(&c->value), &ev)) <= 0) { + SPA_POD_BODY_SIZE(&c->value), &ev)) < 0) { spa_log_warn(state->log, "failed to encode event: %s", snd_strerror(s)); + snd_midi_event_reset_encode(stream->codec); size = 0; continue; }