From 94a5ddff9d5d85104755ee17b301c289a060cebf Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Mon, 6 Nov 2023 16:33:59 +0100 Subject: [PATCH] seq: Simplify snd_seq_extract_output() Now that we never put UMP events on the output buffer in the legacy mode, the check and skip of UMP events are no longer necessary. It means that ump_allowed argument is meaningless in extract_output(), too. Let's drop the unnecessary check and move the code extract_output() into snd_seq_extract_output() again, and call this directly from snd_seq_ump_extract_output() for simplification. Signed-off-by: Takashi Iwai --- src/seq/seq.c | 52 ++++++++++++++++++++------------------------------- 1 file changed, 20 insertions(+), 32 deletions(-) diff --git a/src/seq/seq.c b/src/seq/seq.c index 643cf159f3ef..5eac4848b9c7 100644 --- a/src/seq/seq.c +++ b/src/seq/seq.c @@ -4308,36 +4308,6 @@ int snd_seq_drain_output(snd_seq_t *seq) return 0; } -static int extract_output(snd_seq_t *seq, snd_seq_event_t **ev_res, int ump_allowed) -{ - size_t len, olen; - assert(seq); - if (ev_res) - *ev_res = NULL; - repeat: - if ((olen = seq->obufused) < sizeof(snd_seq_event_t)) - return -ENOENT; - len = snd_seq_event_length((snd_seq_event_t *)seq->obuf); - if (olen < len) - return -ENOENT; - /* skip invalid UMP events */ - if (snd_seq_ev_is_ump((snd_seq_event_t *)seq->obuf) && !ump_allowed) { - seq->obufused -= len; - memmove(seq->obuf, seq->obuf + len, seq->obufused); - goto repeat; - } - if (ev_res) { - /* extract the event */ - if (alloc_tmpbuf(seq, len) < 0) - return -ENOMEM; - memcpy(seq->tmpbuf, seq->obuf, len); - *ev_res = (snd_seq_event_t *)seq->tmpbuf; - } - seq->obufused = olen - len; - memmove(seq->obuf, seq->obuf + len, seq->obufused); - return 0; -} - /** * \brief extract the first event in output buffer * \param seq sequencer handle @@ -4351,7 +4321,25 @@ static int extract_output(snd_seq_t *seq, snd_seq_event_t **ev_res, int ump_allo */ int snd_seq_extract_output(snd_seq_t *seq, snd_seq_event_t **ev_res) { - return extract_output(seq, ev_res, 0); + size_t len, olen; + assert(seq); + if (ev_res) + *ev_res = NULL; + if ((olen = seq->obufused) < sizeof(snd_seq_event_t)) + return -ENOENT; + len = snd_seq_event_length((snd_seq_event_t *)seq->obuf); + if (olen < len) + return -ENOENT; + if (ev_res) { + /* extract the event */ + if (alloc_tmpbuf(seq, len) < 0) + return -ENOMEM; + memcpy(seq->tmpbuf, seq->obuf, len); + *ev_res = (snd_seq_event_t *)seq->tmpbuf; + } + seq->obufused = olen - len; + memmove(seq->obuf, seq->obuf + len, seq->obufused); + return 0; } /*----------------------------------------------------------------*/ @@ -4547,7 +4535,7 @@ int snd_seq_ump_extract_output(snd_seq_t *seq, snd_seq_ump_event_t **ev_res) { if (!seq->midi_version) return -EBADFD; - return extract_output(seq, (snd_seq_event_t **)ev_res, 1); + return snd_seq_extract_output(seq, (snd_seq_event_t **)ev_res); } /** -- 2.35.3