>From 23214b8d506f8592aa4bc39ca9ce5ca66ac44162 Mon Sep 17 00:00:00 2001
From: Andrew Eikum <aeikum@codeweavers.com>
Date: Tue, 10 Jan 2012 10:32:54 -0600
Subject: wineoss.drv: Use GETODELAY instead of GETOSPACE to determine device
 position
To: wine-patches <wine-patches@winehq.org>
Reply-To: wine-devel <wine-devel@winehq.org>,Andrew Eikum <aeikum@codeweavers.com>
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="------------1.7.8.3"

This is a multi-part message in MIME format.
--------------1.7.8.3
Content-Type: text/plain; charset=UTF-8; format=fixed
Content-Transfer-Encoding: 8bit

---
 dlls/wineoss.drv/mmdevdrv.c |   36 +++++++++++++++++++++++++-----------
 1 files changed, 25 insertions(+), 11 deletions(-)


--------------1.7.8.3
Content-Type: text/x-patch; name="0003-wineoss.drv-Use-GETODELAY-instead-of-GETOSPACE-to-de.patch"
Content-Transfer-Encoding: 8bit
Content-Disposition: inline; filename="0003-wineoss.drv-Use-GETODELAY-instead-of-GETOSPACE-to-de.patch"

diff --git a/dlls/wineoss.drv/mmdevdrv.c b/dlls/wineoss.drv/mmdevdrv.c
index aaa94ee..88de2a3 100644
--- a/dlls/wineoss.drv/mmdevdrv.c
+++ b/dlls/wineoss.drv/mmdevdrv.c
@@ -2038,8 +2038,6 @@ static HRESULT WINAPI AudioClock_GetPosition(IAudioClock *iface, UINT64 *pos,
         UINT64 *qpctime)
 {
     ACImpl *This = impl_from_IAudioClock(iface);
-    UINT32 pad;
-    HRESULT hr;
 
     TRACE("(%p)->(%p, %p)\n", This, pos, qpctime);
 
@@ -2048,17 +2046,33 @@ static HRESULT WINAPI AudioClock_GetPosition(IAudioClock *iface, UINT64 *pos,
 
     EnterCriticalSection(&This->lock);
 
-    hr = IAudioClient_GetCurrentPadding(&This->IAudioClient_iface, &pad);
-    if(FAILED(hr)){
-        LeaveCriticalSection(&This->lock);
-        return hr;
+    if(This->dataflow == eRender){
+        int delay;
+        if(ioctl(This->fd, SNDCTL_DSP_GETODELAY, &delay) < 0)
+            delay = 0;
+        else
+            delay /= This->fmt->nBlockAlign;
+        if(This->held_frames + delay >= This->written_frames)
+            *pos = 0;
+        else
+            *pos = This->written_frames - This->held_frames - delay;
+    }else if(This->dataflow == eCapture){
+        audio_buf_info bi;
+        UINT32 held;
+
+        if(ioctl(This->fd, SNDCTL_DSP_GETISPACE, &bi) < 0){
+            TRACE("GETISPACE failed: %d (%s)\n", errno, strerror(errno));
+            held = 0;
+        }else{
+            if(bi.bytes <= bi.fragsize)
+                held = 0;
+            else
+                held = bi.bytes / This->fmt->nBlockAlign;
+        }
+
+        *pos = This->written_frames + held;
     }
 
-    if(This->dataflow == eRender)
-        *pos = This->written_frames - pad;
-    else if(This->dataflow == eCapture)
-        *pos = This->written_frames + pad;
-
     LeaveCriticalSection(&This->lock);
 
     if(qpctime){

--------------1.7.8.3--


