Bug 321781

Summary: pulseaudio refuses to let device be opened immediately after it's closed
Product: [Fedora] Fedora Reporter: Jonathan Kamens <jik>
Component: pulseaudioAssignee: Lennart Poettering <lpoetter>
Status: CLOSED NOTABUG QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: low Docs Contact:
Priority: low    
Version: rawhideCC: pierre-bugzilla
Target Milestone: ---   
Target Release: ---   
Hardware: All   
OS: Linux   
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2007-11-11 11:57:17 EST Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Description Jonathan Kamens 2007-10-07 02:18:33 EDT
I have a script for recording TV programs from my TV card which mucks around
with the ALSA devices and then launches mencoder to record the program.  I
terminate a recording by killing the script, which causes it to clean up. 
Sometimes, when I have cron jobs set up to record two programs one right after
the other, the second recording task starts up immediately after the previous
has finished.  When this happens, mencoder fails to open the audio device:

Thu Oct 4 21:00:02 EDT 2007: Executed as /home/jik/scripts/record 5
Thu Oct 4 21:00:02 EDT 2007: Starting /usr/bin/mencoder tv:// -tv
-ovc lavc -lavcopts vcodec=mpeg4:vbitrate=4000:keyint=30 -idx -oac mp3lame
-lameopts br=128:cbr:mode=3 -ffourcc divx -vf pp=md/de,phase=U -o
/home/jik/.freevo/recordings/10-04_21_00_Grey_s_Anatomy_-_Love_Addiction.avi -quiet
Thu Oct 4 21:00:02 EDT 2007: child PID is 20114
Thu Oct 4 21:00:03 EDT 2007: Waiting for /usr/bin/mencoder (20114)
MEncoder SVN-r23784 (C) 2000-2007 MPlayer Team
CPU: Intel(R) Pentium(R) 4 CPU 3.00GHz (Family: 15, Model: 4, Stepping: 1)
CPUflags: Type: 15 MMX: 1 MMX2: 1 3DNow: 0 3DNow2: 0 SSE: 1 SSE2: 1
Compiled with runtime CPU detection.
success: format: 9  data: 0x0 - 0x0
TV file format detected.
Selected driver: v4l2
 name: Video 4 Linux 2 input
 author: Martin Olschewski <olschewski@zpr.uni-koeln.de>
 comment: first try, more to come ;-)
Selected device: Hauppauge WinTV 34xxx models
 Tuner cap:
 Tuner rxs:
 Capabilites:  video capture  VBI capture device  tuner  read/write  streaming
 supported norms: 0 = PAL-BG; 1 = PAL-DK; 2 = PAL-I; 3 = PAL-M; 4 = PAL-N; 5 =
PAL-Nc; 6 = PAL-60; 7 = NTSC-M; 8 = NTSC-M-JP; 9 = NTSC-443; 10 = SECAM-DK; 11 =
 inputs: 0 = Television; 1 = for debug only; 2 = Composite1; 3 = S-Video;
 Current input: 0
 Current format: BGR24
v4l2: current audio mode is : STEREO
Selected channel: 5 (freq: 77.250)
Error opening audio: Device or resource busy
Error opening audio: Device or resource busy
Error opening audio: Device or resource busy
v4l2: 0 frames successfully processed, 0 frames dropped.
Thu Oct 4 21:00:03 EDT 2007: Finished with /usr/bin/mencoder (20114)

If I pause for just a second before launching the recording script, this doesn't
happen.  This also didn't happen before I replaced esound with pulseaudio.

It appears that there's some sort of race condition right after the device is
closed where pulseaudio isn't prepared to accept new connections.  This needs to
be fixed, i think.
Comment 1 Lennart Poettering 2007-10-15 11:02:46 EDT
I am sorry, I don't get what this has to do with PA? The mencoder line you are
using suggests that you are using ALSA natively, without going through PA
(adevice=hw.0,0). And the first mencoder invocation works, but the second
doesn't? But where does PA come into play here?

Please elaborate!
Comment 2 Lennart Poettering 2007-11-11 11:57:17 EST
Since I fail to see what this has to do with PA and I didn't get feedback for a
month now, I will close the bug.

Feel free to reopen, if the bug persists and you still believe it's PA's fault.
Comment 3 Jonathan Kamens 2007-11-11 22:47:39 EST
I did some more research, and you're right, this is not a pulseaudio bug.  I
don't know why it seemed to start happening when I switched from esound to
pulseaudio, but in any case, the root cause was actually an issue with my driver
script which I've addressed.  Sorry to have bothered you.