]> git.alsa-project.org Git - alsa-lib.git/commitdiff
seq: Clear UMP event flag for legacy apps
authorTakashi Iwai <tiwai@suse.de>
Mon, 6 Nov 2023 15:27:11 +0000 (16:27 +0100)
committerTakashi Iwai <tiwai@suse.de>
Tue, 7 Nov 2023 11:16:47 +0000 (12:16 +0100)
It seems that some applications (at least Chrome WebMIDI) set random
bits to the flags of event packet, and this confuses as if they were
UMP-events, which are eventually filtered out.

Although it's a bug of applications, it's better to avoid the
regressions.  So this patch forcibly clears the UMP flag of the
incoming and outgoing events when the application is running in the
legacy mode (i.e. midi_version = 0).

Fixes: 2aefb5c41cc0 ("seq: Add UMP support")
Closes: https://github.com/alsa-project/alsa-lib/issues/360
Signed-off-by: Takashi Iwai <tiwai@suse.de>
src/seq/seq.c

index 5ec737a7004feb3e34e185ba186e1f5cd6315ef4..643cf159f3ef02013abe6a63bc3a638d26181adb 100644 (file)
@@ -4161,6 +4161,13 @@ int snd_seq_event_output(snd_seq_t *seq, snd_seq_event_t *ev)
        return result;
 }
 
+/* workaround for broken legacy apps that set UMP event bit unexpectedly */
+static void clear_ump_for_legacy_apps(snd_seq_t *seq, snd_seq_event_t *ev)
+{
+       if (!seq->midi_version && snd_seq_ev_is_ump(ev))
+               ev->flags &= ~SNDRV_SEQ_EVENT_UMP;
+}
+
 /**
  * \brief output an event onto the lib buffer without draining buffer
  * \param seq sequencer handle
@@ -4178,6 +4185,7 @@ int snd_seq_event_output_buffer(snd_seq_t *seq, snd_seq_event_t *ev)
 {
        int len;
        assert(seq && ev);
+       clear_ump_for_legacy_apps(seq, ev);
        len = snd_seq_event_length(ev);
        if (len < 0)
                return -EINVAL;
@@ -4238,6 +4246,7 @@ int snd_seq_event_output_direct(snd_seq_t *seq, snd_seq_event_t *ev)
        ssize_t len;
        void *buf;
 
+       clear_ump_for_legacy_apps(seq, ev);
        len = snd_seq_event_length(ev);
        if (len < 0)
                return len;
@@ -4374,6 +4383,7 @@ static int snd_seq_event_retrieve_buffer(snd_seq_t *seq, snd_seq_event_t **retp)
        snd_seq_event_t *ev;
 
        *retp = ev = (snd_seq_event_t *)(seq->ibuf + seq->ibufptr * packet_size);
+       clear_ump_for_legacy_apps(seq, ev);
        seq->ibufptr++;
        seq->ibuflen--;
        if (! snd_seq_ev_is_variable(ev))