Andrew Eikum : dsound: Don't overrun capture buffer.

Alexandre Julliard julliard at winehq.org
Thu May 16 13:55:06 CDT 2013


Module: wine
Branch: master
Commit: 508b0c9c44349a5d980e0f1ee0ba4fca871bd2cb
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=508b0c9c44349a5d980e0f1ee0ba4fca871bd2cb

Author: Andrew Eikum <aeikum at codeweavers.com>
Date:   Thu May 16 09:24:31 2013 -0500

dsound: Don't overrun capture buffer.

---

 dlls/dsound/capture.c |   11 ++++++++---
 1 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/dlls/dsound/capture.c b/dlls/dsound/capture.c
index 1b004e6..01cf775 100644
--- a/dlls/dsound/capture.c
+++ b/dlls/dsound/capture.c
@@ -855,7 +855,7 @@ static void CALLBACK DSOUND_capture_timer(UINT timerID, UINT msg, DWORD_PTR user
                                           DWORD_PTR dw1, DWORD_PTR dw2)
 {
     DirectSoundCaptureDevice *device = (DirectSoundCaptureDevice*)user;
-    UINT32 packet_frames, packet_bytes, avail_bytes;
+    UINT32 packet_frames, packet_bytes, avail_bytes, skip_bytes = 0;
     DWORD flags;
     BYTE *buf;
     HRESULT hr;
@@ -888,18 +888,23 @@ static void CALLBACK DSOUND_capture_timer(UINT timerID, UINT msg, DWORD_PTR user
     }
 
     packet_bytes = packet_frames * device->pwfx->nBlockAlign;
+    if(packet_bytes > device->buflen){
+        TRACE("audio glitch: dsound buffer too small for data\n");
+        skip_bytes = packet_bytes - device->buflen;
+        packet_bytes = device->buflen;
+    }
 
     avail_bytes = device->buflen - device->write_pos_bytes;
     if(avail_bytes > packet_bytes)
         avail_bytes = packet_bytes;
 
-    memcpy(device->buffer + device->write_pos_bytes, buf, avail_bytes);
+    memcpy(device->buffer + device->write_pos_bytes, buf + skip_bytes, avail_bytes);
     capture_CheckNotify(device->capture_buffer, device->write_pos_bytes, avail_bytes);
 
     packet_bytes -= avail_bytes;
     if(packet_bytes > 0){
         if(device->capture_buffer->flags & DSCBSTART_LOOPING){
-            memcpy(device->buffer, buf + avail_bytes, packet_bytes);
+            memcpy(device->buffer, buf + skip_bytes + avail_bytes, packet_bytes);
             capture_CheckNotify(device->capture_buffer, 0, packet_bytes);
         }else{
             device->state = STATE_STOPPED;




More information about the wine-cvs mailing list