[vlc-commits] DirectSound: use a new strategy for erasing the ring buffer

Ludovic Fauvet git at videolan.org
Sat Sep 7 21:57:49 CEST 2013


vlc | branch: master | Ludovic Fauvet <etix at videolan.org> | Sat Sep  7 21:53:07 2013 +0200| [26651679f6c67440cb3d942491e170ba383f970c] | committer: Jean-Baptiste Kempf

DirectSound: use a new strategy for erasing the ring buffer

Close #9275 #9328

Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=26651679f6c67440cb3d942491e170ba383f970c
---

 modules/audio_output/directx.c |   15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/modules/audio_output/directx.c b/modules/audio_output/directx.c
index 1bb719b..8367535 100644
--- a/modules/audio_output/directx.c
+++ b/modules/audio_output/directx.c
@@ -666,7 +666,7 @@ static int FillBuffer( audio_output_t *p_aout, block_t *p_buffer )
 {
     aout_sys_t *p_sys = p_aout->sys;
 
-    size_t towrite = (p_buffer)?p_buffer->i_buffer:DS_BUF_SIZE;
+    size_t towrite = (p_buffer)? p_buffer->i_buffer : DS_BUF_SIZE;
     void *p_write_position, *p_wrap_around;
     unsigned long l_bytes1, l_bytes2;
     uint32_t i_read;
@@ -674,13 +674,18 @@ static int FillBuffer( audio_output_t *p_aout, block_t *p_buffer )
     mtime_t i_buf;
     HRESULT dsresult;
 
+    size_t toerase = p_sys->i_bytes_per_sample * p_sys->i_rate / 4;
+    mtime_t max = towrite;
+
     if( IDirectSoundBuffer_GetCurrentPosition( p_aout->sys->p_dsbuffer, (LPDWORD) &i_read, NULL) ==  DS_OK )
     {
-        /* Compute the outer interval between the write and read pointers within the ring buffer */
-        i_buf = (mtime_t)i_read - (mtime_t)p_aout->sys->i_write;
-        if( i_buf <= 0 )
-            i_buf += DS_BUF_SIZE;
+        max = (mtime_t)i_read - (mtime_t)p_aout->sys->i_write;
+        if( max <= 0 )
+            max += DS_BUF_SIZE;
     }
+
+    if( towrite + toerase <= max )
+        i_buf = towrite + toerase;
     else
         i_buf = towrite;
 



More information about the vlc-commits mailing list