View Full Version : Possible bug in soundout()?
spotter
20th December 2007, 04:35
I think I've encountered what I consider a bug in soundout(), that causes a race condition in AutoMKV on my quad core box.
Namely, soundout() doesn't close stdout to a "cmd" output type until it actually closes (i.e. if one has a std 5sec timeout, it doesn't close it until the timeout expires or one hits "close").
Now, virtualdub exits right away, but the cmd process doesn't seem to have to exit right away. In AutoMKV, it sees that the virtualdub it spawned is closed and then looks at the file size to see if encoded correctly (has to be over a minimum size).
Now, if the output program is NeroAAC, it seems to do a lot of housekeeping on the output file when it reaches the end of the input (i.e. its stdin reaches end of file due to soundout() closing stdout). Part of this housekeeping seems to be rewriting the file from scratch (or at least refreshing file size quickly shows the file size drop to 0 and then be recreated).
On a quadcore box, automkv is able to get the size of the file when its 0.
From my perspective, either soundout() should close stdout earlier, or more correctly, avisynth/virtualdub shouldn't exit until the programs they executed (in this case neroaac) exit.
sh0dan
20th December 2007, 08:46
@spotter: Thanks, I'll investigate. I'm currently experimenting with various additions/rewrites, so I hope you have a little patience. Hopefully in the beginning of the new year.
spotter
20th December 2007, 15:44
does my analysis make sense to you?
sh0dan
6th January 2008, 13:47
The output pipe is closed immediately after the last samples have been delivered.
The process is however forcefully terminated, when the windows is closed. Nero might not be finished updating the file when it is terminated.
Is the output correct, if you do not use autoclose or close the window early?
sh0dan
6th January 2008, 15:19
Please try: http://klauspost.googlepages.com/SoundOut-test.zip
I have added a process exit check. It will wait 5 seconds. If more than 5 seconds elapses it will ask if you forcefully wants to terminate the thread.
spotter
6th January 2008, 16:12
ok, have a friend's wedding today and a research paper due tomorrow, so it might be a couple of days.
thanks.
spotter
8th January 2008, 18:19
it took longer than 5s to exit, but it did exit before I said ok to killing it. Any chance soundout can just wait till it exits by default, ala in unix
if (pid = fork()) {
wait(pid);
} else {
exec();
}
not a win32 programmer (even after spending a summer at microsoft), so unsure about the semantics for windows.
sh0dan
8th January 2008, 19:50
Basicly I deliver all the audio samples, close the pipes and wait for the process to exit by itself.
Could you provide some additional info so I can reproduce the bug, since NeroAAC works fine here.
spotter
8th January 2008, 20:10
this is the script automkv creates
LoadPlugin("D:\Copy of AutoMKV\exe\filter\NicAudio.dll")
LoadPlugin("D:\Copy of AutoMKV\exe\filter\SoundOut.dll")
LoadPlugin("D:\Copy of AutoMKV\exe\filter\FFmpegSource.dll")
NicAC3Source("D:\Movie\temp\movie t80 3_2ch 448kbps delay 0ms.ac3")
DelayAudio(0.0000)
#Applying STEREO downmixing routines
function stereo(clip a)
{
flr = GetChannel(a, 1, 2)
fcc = GetChannel(a, 3)
lfe = GetChannel(a, 4)
lfc = MixAudio(fcc, lfe, 0.2071, 0.2071)
mix = MergeChannels(lfc, lfc)
lrc = MixAudio(flr, mix, 0.2929, 1.0)
blr = GetChannel(a, 5, 6)
Return MixAudio(lrc, blr, 1.0, 0.2929)
}
#
6==Audiochannels() ? stereo() : last
function addvideo(clip c) {
blankclip(length = Int(100 * AudioLengthF(c) / float(audiorate(c))), fps=100)
Return audiodub(last,c)
}
Normalize()
Soundout(output="cmd",type=1,format=3,autoclose=true,executable="D:\Copy of AutoMKV\exe\besweet\neroaacenc.exe",prefilename=" -ignorelength -q 0.35 -if - -of audio.mp4",postfilename="",nofilename=true,showoutput=false)
basically what I observe is that when neroaac does a lot of work after the the pipe closes. If the disk is slow on IO (for instance because a lot of other IO is going on). It can take a while to complete. soundout() closes b4 that happens. For instance, with the modified version you posted, it asks to kill the process, but as I only see it 20-30s after it pops up, the neroaac process already quit (checking task manager) so killing it does nothing. (hence I'm not sure what you mean by waiting for process to exit, as there would be nothing to forceably kill if you did that).
What I'm asking, instead of the modified version that asks to forcably kill the child process, you just wait on that process to exit.
spotter
11th January 2008, 04:19
wondering if you need any more info from me?
sh0dan
11th January 2008, 10:22
@spotter: No - actually the prompt just proves that the fix is working. I've increased the timeout, and added a parameter to control it. I've tested with a 2 hour stream, and it works nicely.
The prompt must come up, if the app doesn't terminate by itself, otherwise users can be stuck there.
The prompt actually does the opposite of what it's advertising.
spotter
16th January 2008, 18:40
@sh0dan: do you have the a copy that I can use? :)
spotter
16th January 2008, 19:26
another thing to think about, is it possible to have the even when the "terminate" window is up, to continue checking to see if the process quit by itself, and if it did, close the window automatically and continue?
sh0dan
16th January 2008, 21:10
http://klauspost.googlepages.com/SoundOut-test2.zip
Rather untested though. Exit timeout is 60 seconds - if you don't want the box, increase "exittimeout" parameter until it doesn't appear - parameter is in seconds.
spotter
17th January 2008, 23:51
btw, done a bunch of encodes w/ the new one, seems to work great for me.
vBulletin® v3.8.4, Copyright ©2000-2010, Jelsoft Enterprises Ltd.