[vlc-commits] Fixed BDA support (close #5627).

Laurent Aimar git at videolan.org
Wed Jan 4 23:14:36 CET 2012


vlc | branch: master | Laurent Aimar <fenrir at videolan.org> | Tue Jan  3 21:01:49 2012 +0100| [435f1d55e7745df14c4e3a725d18dc2f32b6c7f1] | committer: Laurent Aimar

Fixed BDA support (close #5627).

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

 modules/access/dtv/bdagraph.cpp |   46 ++++++++++++++++++++++++--------------
 1 files changed, 29 insertions(+), 17 deletions(-)

diff --git a/modules/access/dtv/bdagraph.cpp b/modules/access/dtv/bdagraph.cpp
index 7303033..23f6818 100644
--- a/modules/access/dtv/bdagraph.cpp
+++ b/modules/access/dtv/bdagraph.cpp
@@ -305,28 +305,40 @@ void BDAOutput::Push( block_t *p_block )
 
 ssize_t BDAOutput::Pop(void *buf, size_t len)
 {
-    block_t *block;
+    vlc_mutex_locker l( &lock );
+
+    mtime_t i_deadline = mdate() + 250 * 1000;
+    while( !p_first )
     {
-        vlc_mutex_locker l( &lock );
+        if( vlc_cond_timedwait( &wait, &lock, i_deadline ) )
+            return -1;
+    }
 
-        if( !p_first )
-            vlc_cond_timedwait( &wait, &lock, mdate() + 250*1000 );
+    size_t i_index = 0;
+    while( i_index < len )
+    {
+        size_t i_copy = __MIN( len - i_index, p_first->i_buffer );
+        memcpy( (uint8_t *)buf + i_index, p_first->p_buffer, i_copy );
 
-        block = p_first;
-        p_first = NULL;
-        pp_next = &p_first;
-    }
+        i_index           += i_copy;
 
-    if(block == NULL)
-        return -1;
+        p_first->p_buffer += i_copy;
+        p_first->i_buffer -= i_copy;
 
-    if(len < block->i_buffer)
-        msg_Err(p_access, "buffer overflow!");
-    else
-        len = block->i_buffer;
-    vlc_memcpy(buf, block->p_buffer, len);
-    block_Release(block);
-    return len;
+        if( p_first->i_buffer <= 0 )
+        {
+            block_t *p_next = p_first->p_next;
+            block_Release( p_first );
+
+            p_first = p_next;
+            if( !p_first )
+            {
+                pp_next = &p_first;
+                break;
+            }
+        }
+    }
+    return i_index;
 }
 
 void BDAOutput::Empty()



More information about the vlc-commits mailing list