alsa-project / alsa-utils

The Advanced Linux Sound Architecture (ALSA) - utilities
GNU General Public License v2.0
197 stars 136 forks source link

aplaymidi causes pa_stream_writeable_size() failed - connection terminated #232

Closed symdeb closed 1 year ago

symdeb commented 1 year ago

How to reproduce:

  1. Plain Ubuntu 23.04 desktop but with kernel 6.5rc1... rc7 and ALSA UMP & sequencer enabled.
  2. play a video with the "video" application.
  3. Insert a MIDI 2.0 UMP capable device
    Note: A Focusrite 18i20 Gen 1 audio interface is used for audio playback and set in Pavucontrol as "pro Audio"
  4. run aplaymidi -l or aplaymidi --version within about 30 seconds of plugging in the device. (if longer, the issue is not reproduceable)
  5. Audio stops and soon after the error appears stopping the video.
    pavuctl screen goes blank and reinitializes itself. Unplug the device
    Wait for about 30 seconds (this is important, sooner the error will appear) Repeat steps 2 and 4 . The error won't occur.

image

This is not unique to aplaymidi, other ALSA clients (aseqdump) may also cause this error. in almost all other applications there is no error, such a web browsers as playing videos in Youtube, the audio playback just stops. some applications , like browsers, can recover by readadjusting the timeline and restarting playback. Some can only recover after closing the application i.e mpv media player.

tiwai commented 1 year ago

Is it with PulseAudio or pipewire? And, is this reproducible on VM with the gadget driver, too?

The second question is basically to check whether the problem is device-specific or not. It might be that the device firmware is buggy and causes some issue when MIDI 2.0 is in use. I guess it's a generic problem, but still need to verify.

BTW, each open of a github issue and the edit of the content is notified / forwarded to alsa-devel mailing list, too. The ML is archived on lore.kernel.org, and it'll remain forever :) So, please be careful about editing. Your previous 26 times edits spewed 26 posts there.

symdeb commented 1 year ago

Host uses Pipewire as provided with the Ubuntu 23.04 distro as default. no changes. This uses the pw-pulse (and pw-jack AFAIK) drop in replacements

It is re-produceable without actual MIDI 2 hardware or a VM It can be reproduced with a MIDI2 gadget as well.

  1. Start Youtube video (for example, or anything that play audio)
  2. Start the midi2 gadget
  3. run aplaymidi (no options) Audio stops, video continues
  4. Restart the video (audio plays again)
  5. run aplaymidi (no options) Audio stops, video continues
  6. Also occurs when unloading the mid2 gadget.

Note snd_usb_audio is not removed because the external usb audio interface is used Does not occur with a MIDI1 gadget. This should exclude the hardware from the equation.

pactl info: Server String: /run/user/1000/pulse/native Library Protocol Version: 35 Server Protocol Version: 35 Is Local: yes Client Index: 124 Tile Size: 65472 User Name: user Host Name: H3 Server Name: PulseAudio (on PipeWire 0.3.65) Server Version: 15.0.0 Default Sample Specification: float32le 2ch 48000Hz Default Channel Map: front-left,front-right Default Sink: alsa_output.usb-Focusrite_Scarlett_18i20_USB-00.pro-output-0 Default Source: alsa_input.usb-Focusrite_Scarlett_18i20_USB-00.pro-input-0 Cookie: f33b:c78f

tiwai commented 1 year ago

Thanks, it's clearer now.

The bug is in alsa-lib sequencer code, and it caused pipewire segfaulting. The seq->midi_version was incorrectly updated upon get_client_info for another client.

symdeb commented 1 year ago

Glad the cause was found and fix implemented. https://github.com/alsa-project/alsa-lib/commit/dc1e683cc2d2aaed938f9459605d51d4a2cb7ba0