http://bugs.winehq.org/show_bug.cgi?id=30118
Bug #: 30118 Summary: Sound occasionally stalls past underrun, bypassing our lead-in writer Product: Wine Version: 1.4-rc5 Platform: x86 OS/Version: Linux Status: NEW Severity: normal Priority: P2 Component: winealsa.drv AssignedTo: wine-bugs@winehq.org ReportedBy: hoehle@users.sourceforge.net Classification: Unclassified
Attachment #39217 to bug #29294 contains a log where Civilization 5 audio stalls after an underrun.
99% of the time, an underrun happens while the mmdevapi render callback sleeps. snd_pcm_avail is then the first to detect it, recovers, writes the lead-in and audio is running again. This happened 266 times in the log: 62.063:alsa_write_data XRun state avail 12689, recovering
In rare cases, the underrun did not yet occur when snd_pcm_avail was called rather than a few µs later in snd_pcm_write. 62.190:alsa_write_data pad: 4245 62.190:alsa_write_best_effort writei failed, recovering: -32 (Broken pipe) ALSA lib pcm.c:7316:(snd_pcm_recover) underrun occurred
Following that, ALSA has a little data 62.201:alsa_write_data pad: 512 62.211:alsa:alsa_write_data pad: 5120 but somehow DSound stops feeding it.
Now bug #29294 involves Jack whose precise behaviour I don't know, but here's what would happen when using plain plug:dmix or hw:0: Our lead-in writer does not trigger because it sits before snd_pcm_write. The key issue is that ALSA has less than one period of data, so it doesn't start! That is known behaviour from both dmix and hw:x,y devices.
23.054:AudioClient_Initialize ALSA period: 5512 frames 23.055:AudioClient_Initialize ALSA buffer: 16537 frames 23.055:AudioClient_Initialize MMDevice period: 441 frames 23.055:AudioClient_Initialize MMDevice buffer: 5120 frames
As a result, position does not increase. The little data prevents writing the lead-in upon subsequent callback invocations. Unfortunately, DSound is presumably waiting for a particular position to be reached to continue feeding data.
Position would increase and bump to max = release_frames - held_frames if it would hit another underun -- if ALSA had managed to start.
So this is partly a bug in DSound which I've already blamed for using GetPosition instead of GetCurrentPadding when feeding data, witness comment #21, bug #29472, comment #17 or bug #29497, comment #1. However the subject of this bug report shall be winealsa's incomplete underrun recovery.
Also note another issue here: mmdevapi's buffer of 5120 frames is smaller than ALSA's period! Thanks to the lead-in, that nevertheless works at start. Perhaps DSound would not have stalled had that buffer been larger; it might have written more frames.
Months ago I conducted many tests with different buffer and period sizes in exclusive mode but have not finalized that work about the minimum and maximum buffer sizes and when to return E_INVALID_DEVICE_PERIOD or AUDCLNT_E_BUFFER_SIZE_ERROR etc. That's still a TODO on my list. That work has been very revealing about the relationship between mmdevapi and alsa buffer and period sizes. Presumably, mmdevapi must create a buffer at least as large as ALSA's period.
http://bugs.winehq.org/show_bug.cgi?id=30118
Jörg Höhle hoehle@users.sourceforge.net changed:
What |Removed |Added ---------------------------------------------------------------------------- CC| |aeikum@codeweavers.com Summary|Sound occasionally stalls |Sound occasionally stalls |past underrun, bypassing |past underrun, bypassing |our lead-in writer |the ALSA lead-in writer
http://bugs.winehq.org/show_bug.cgi?id=30118
--- Comment #1 from Andrew Eikum aeikum@codeweavers.com 2012-03-09 08:56:00 CST --- Created attachment 39267 --> http://bugs.winehq.org/attachment.cgi?id=39267 DSound cleanup patchset
(In reply to comment #0)
So this is partly a bug in DSound which I've already blamed for using GetPosition instead of GetCurrentPadding when feeding data, witness comment #21, bug #29472, comment #17 or bug #29497, comment #1. However the subject of this bug report shall be winealsa's incomplete underrun recovery.
I haven't yet thought about fixing ALSA's behavior, but here's the patchset to fix dsound. The first few patches up to the resampler are for Bug 14717. The patches after that are cleanup patches, with the last one changing it to use GCP instead of GetPosition.
http://bugs.winehq.org/show_bug.cgi?id=30118
Jörg Höhle hoehle@users.sourceforge.net changed:
What |Removed |Added ---------------------------------------------------------------------------- CC| |xtroce@gmail.com
--- Comment #2 from Jörg Höhle hoehle@users.sourceforge.net 2012-03-11 11:50:45 CDT --- There's something I don't understand. James' Civ5 log at bug #29294, comment #23 look like ALSA stalled after the broken pipe, despite 5120 frames in buffer. However no stalling is seen in the render test in bug #29294, comment #35, where another underrun soon follows the broken pipe. How to explain the difference?
Civ5: 23.054:dump_fmt nSamplesPerSec: 44100 16bit stereo 23.054:AudioClient_Initialize ALSA period: 5512 frames 23.055:AudioClient_Initialize ALSA buffer: 16537 frames 23.055:AudioClient_Initialize MMDevice period: 441 frames 23.055:AudioClient_Initialize MMDevice buffer: 5120 frames mmdevapi render: 1838.608:dump_fmt nSamplesPerSec: 48000 float stereo 1838.609:AudioClient_Initialize ALSA period: 6000 frames 1838.609:AudioClient_Initialize ALSA buffer: 18000 frames 1838.609:AudioClient_Initialize MMDevice period: 480 frames 1838.609:AudioClient_Initialize MMDevice buffer: 2400 frames
James, please use the Civ5 parameters with the render test. After GetMixFormat in mmdevapi/tests/render.c:test_worse_case, add: fmt->wFormatTag = WAVE_FORMAT_PCM; fmt->cbSize = 0; fmt->nSamplesPerSec = 44100; fmt->nAvgBytesPerSec= fmt.nBlockAlign * fmt.nSamplesPerSec;
http://bugs.winehq.org/show_bug.cgi?id=30118
Jerome Leclanche adys.wh@gmail.com changed:
What |Removed |Added ---------------------------------------------------------------------------- CC| |adys.wh@gmail.com
--- Comment #3 from Jerome Leclanche adys.wh@gmail.com 2012-04-05 17:36:13 CDT --- Is this fixed now? A lot of the patches made it in.
https://bugs.winehq.org/show_bug.cgi?id=30118
Austin English austinenglish@gmail.com changed:
What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution|--- |ABANDONED
--- Comment #4 from Austin English austinenglish@gmail.com --- No reply in 2 years, marking abandoned.
If this is still an issue in current (1.7.16 or newer) wine and you can provide the needed information, feel free to reopen.
https://bugs.winehq.org/show_bug.cgi?id=30118
austinenglish@gmail.com changed:
What |Removed |Added ---------------------------------------------------------------------------- Status|RESOLVED |CLOSED
--- Comment #5 from austinenglish@gmail.com --- Closing.