Hi,
I'm seeing some apps hang after playing an audio sample (even after the latest fix from Eric Pouech/Dan Kegel). I've tracked it down to the following.
dwBufferSize is calculated from info->fragstotal * info->fragsize:
wwo->dwBufferSize = info.fragstotal * info.fragsize;
whereas dwPlayedTotal is calculated using info->bytes:
wwo->dwPlayedTotal = wwo->dwWrittenTotal - (wwo->dwBufferSize - info->bytes);
Thus the assumption is that, at beginning and end of playback, info->fragstotal * info->fragsize == info->bytes, so that wwo->dwPlayedTotal == wwo->dwWrittenTotal.
But, for my soundcard (ymfpci driver), after asking for 15 frags * 1024 bytes the situation is:
fragments = 15, fragstotal = 18, fragsize = 1024, bytes = 15612
i.e. info->fragstotal * info->fragsize = 18432, info->bytes = 15612
Thus dwPlayedTotal never reaches dwWrittenTotal and the last buffer never gets marked as done.
Using info->bytes for wwo->dwBufferSize does fix my problem, not sure if there's a better solution.
Matt
[Looking at the driver, it looks like the difference is a safety margin to stop the DSP when it reaches the end. Arguably the driver should just report 15 in fragstotal and not bother applications with the detail that its buffer is actually 18 frags in size...]
Index: dlls/winmm/wineoss/audio.c =================================================================== RCS file: /home/wine/wine/dlls/winmm/wineoss/audio.c,v retrieving revision 1.68 diff -u -r1.68 audio.c --- dlls/winmm/wineoss/audio.c 15 Dec 2002 02:59:13 -0000 1.68 +++ dlls/winmm/wineoss/audio.c 28 Dec 2002 09:56:46 -0000 @@ -1357,7 +1357,7 @@
/* Remember fragsize and total buffer size for future use */ wwo->dwFragmentSize = info.fragsize; - wwo->dwBufferSize = info.fragstotal * info.fragsize; + wwo->dwBufferSize = info.bytes; wwo->dwPlayedTotal = 0; wwo->dwWrittenTotal = 0; wwo->bNeedPost = TRUE;
Matt Chapman wrote:
Thus the assumption is that, at beginning and end of playback, info->fragstotal * info->fragsize == info->bytes, so that wwo->dwPlayedTotal == wwo->dwWrittenTotal.
But, for my soundcard (ymfpci driver), after asking for 15 frags * 1024 bytes the situation is:
fragments = 15, fragstotal = 18, fragsize = 1024, bytes = 15612
i.e. info->fragstotal * info->fragsize = 18432, info->bytes = 15612
this sounds a bit crazy from the API point of view but if the driver is really implemented like this your patch would be fine. IMO, we should anyway add a comment for this behavior in the code so that we don't loose track of this interesting "feature"