]> git.sesse.net Git - vlc/commitdiff
GetChunk() : reads n bytes from the elementary stream and places them
authorChristophe Massiot <massiot@videolan.org>
Tue, 19 Dec 2000 19:55:35 +0000 (19:55 +0000)
committerChristophe Massiot <massiot@videolan.org>
Tue, 19 Dec 2000 19:55:35 +0000 (19:55 +0000)
in a big buffer (a gift for Sam).

include/input_ext-dec.h

index 40fecfde3d4a957b9900fe0f380e0a61f296f02f..edd5165d851bda78b322bae4feed14fcb4ec9a7e 100644 (file)
@@ -361,6 +361,51 @@ static __inline__ void RealignBits( bit_stream_t * p_bit_stream )
 }
 
 
+/*
+ * Philosophy of the third implementation : the decoder asks for n bytes,
+ * and we will copy them in its buffer.
+ */
+
+/*****************************************************************************
+ * GetChunk : reads a large chunk of data
+ *****************************************************************************
+ * The position in the stream must be byte-aligned, if unsure call
+ * RealignBits(). p_buffer must to a buffer at least as big as i_buf_len
+ * otherwise your code will crash.
+ *****************************************************************************/
+static __inline__ void GetChunk( bit_stream_t * p_bit_stream,
+                                 byte_t * p_buffer, size_t i_buf_len )
+{
+    int     i_available;
+
+    if( (i_available = p_bit_stream->p_end - p_bit_stream->p_byte)
+            >= i_buf_len )
+    {
+        memcpy( p_buffer, p_bit_stream->p_byte, i_buf_len );
+        p_bit_stream->p_byte += i_buf_len;
+    }
+    else
+    {
+        do
+        {
+            memcpy( p_buffer, p_bit_stream->p_byte, i_available );
+            p_bit_stream->p_byte = p_bit_stream->p_end;
+            p_buffer += i_available;
+            i_buf_len -= i_available;
+            p_bit_stream->pf_next_data_packet( p_bit_stream );
+        }
+        while( (i_available = p_bit_stream->p_end - p_bit_stream->p_byte)
+                <= i_buf_len );
+
+        if( i_buf_len )
+        {
+            memcpy( p_buffer, p_bit_stream->p_byte, i_buf_len );
+            p_bit_stream->p_byte += i_buf_len;
+        }
+    }
+}
+
+
 /*
  * Communication interface between input and decoders
  */