After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 559111 - ALSA sink hangs on USB audio device unplug while playing
ALSA sink hangs on USB audio device unplug while playing
Status: RESOLVED FIXED
Product: GStreamer
Classification: Platform
Component: gst-plugins-base
0.10.21
Other Linux
: Normal normal
: 0.10.22
Assigned To: GStreamer Maintainers
GStreamer Maintainers
Depends on:
Blocks:
 
 
Reported: 2008-11-03 14:12 UTC by Matthias Kretz
Modified: 2008-11-03 17:09 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Patch to make writes non-blocking (1.24 KB, patch)
2008-11-03 14:13 UTC, Matthias Kretz
reviewed Details | Review

Description Matthias Kretz 2008-11-03 14:12:48 UTC
The ALSA sink uses blocking writes to write to the soundcard. If the audio device is unplugged this write will block forever. It should use non-blocking writes instead and handle the case of an unplugged device.
Comment 1 Matthias Kretz 2008-11-03 14:13:33 UTC
Created attachment 121868 [details] [review]
Patch to make writes non-blocking
Comment 2 Wim Taymans 2008-11-03 15:31:28 UTC
I changed the patch a little so that it leaves the device open in non-blocking mode. I rearranged the code so that it starts with a wait operation before attempting the write. Please test it this also solves your problems.

        Based on patch by: Matthias Kretz <kretz at kde dot org>

        * ext/alsa/gstalsasink.c: (gst_alsasink_open),
        (gst_alsasink_prepare), (gst_alsasink_unprepare),
        (gst_alsasink_write):
        Make all access non-blocking so that we can better handle unplugging 
        of usb devices. Fixes #559111
Comment 3 Jan Schmidt 2008-11-03 16:01:44 UTC
It's pretty lame that userspace has to care about this - ALSA should be failing the read if it can't complete it afaics. 
Comment 4 Matthias Kretz 2008-11-03 17:09:53 UTC
Careful with fully switching to non-blocking unconditionally. I've seen libxine failing to play the last audio frames because of a non-blocking snd_pcm_drain and snd_pcm_close.

AFAICS you're not using snd_pcm_drain, so gstreamer might not need blocking mode at all, but as I don't know how the end of a stream and closing of the output is handled I thought I point this out so that you can check it doesn't introduce regressions...

I also just tested your patch and so far it seems to work alright.