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   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2007-11-11 16:57:17 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Jonathan Kamens 2007-10-07 06:18:33 UTC
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
/home/jik/.freevo/recordings/10-04_21_00_Grey_s_Anatomy_-_Love_Addiction.avi
Thu Oct 4 21:00:02 EDT 2007: Starting /usr/bin/mencoder tv:// -tv
driver=v4l2:adevice=hw.0,0:alsa:forceaudio:audiorate=32000:amode=1:norm=NTSC-M:input=0:chanlist=us-bcast:channel=5:width=768:height=576:outfmt=yuy2:device=/dev/video1:brightness=54:contrast=26:saturation=50:hue=50:buffersize=64
-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.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 =
SECAM-L;
 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 15:02:46 UTC
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 16:57:17 UTC
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-12 03:47:39 UTC
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.