[PATCH 1/3] ALSA USB MIDI: Fix port starvation

Clemens Ladisch clemens at ladisch.de
Mon Mar 16 13:03:46 CET 2020


Andreas Steinmetz wrote:
> the snd_usbmidi_transmit_byte helper had to be converted to
> return output notification to allow for the 'repeat' shortcut.

Why not simply handle one MIDI byte per port in each iteration?  It
could be argued that single-byte MIDI commands are likely to be real-
time messages and deserve to go first.

> Current multi port MIDI interfaces do
> typically have 2^n output ports and 2^x as wMaxPacketSize where x>n.

The USB specification requires bulk endpoints to have a wMaxPacketSize
value of 8/16/32/64 for full speed, or exactly 512 for high speed.

> For the patch to properly work the wMaxPacketSize of the device must be
> large enough to allow for at least one MIDI event per port in a URB.

There are devices that handle only the first four bytes of a received
packet (because Windows used to send only small packets), and one of
them, the ESI M4U, actually has more than one port.

My original idea for that FIXME was to use round robin until the packet
is filled (or all ports are empty), and to store the next port index
(where to start for the next packet) in the endpoint.  This would be
able to distribute the balancing over multiple packets.


Regards,
Clemens


More information about the Alsa-devel mailing list