]> git.sesse.net Git - vlc/blob - src/ac3_decoder/ac3_bit_stream.h
7c96f32e8cd892aa7a4ef682373ab50b64178cad
[vlc] / src / ac3_decoder / ac3_bit_stream.h
1 /*****************************************************************************
2  * ac3_bit_stream.h: getbits functions for the ac3 decoder
3  *****************************************************************************
4  * Copyright (C) 2000, 2001 VideoLAN
5  *
6  * Authors: Michel Lespinasse <walken@zoy.org>
7  *          Renaud Dartus <reno@videolan.org>
8  *
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  * 
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
23  *****************************************************************************/
24
25 static __inline__ u32 bitstream_get (ac3_bit_stream_t * p_bit_stream, 
26                                      u32 num_bits)
27 {
28     u32 result=0;
29     while (p_bit_stream->i_available < num_bits)
30     {
31         if (p_bit_stream->byte_stream.p_byte >= p_bit_stream->byte_stream.p_end)
32         {
33             ac3dec_thread_t * p_ac3dec = p_bit_stream->byte_stream.info;
34             
35             /* no, switch to next buffer */
36             if(!p_ac3dec->p_fifo->b_die)
37                 ac3_byte_stream_next (&p_bit_stream->byte_stream);
38         }
39         p_bit_stream->buffer |=((u32) *(p_bit_stream->byte_stream.p_byte++)) 
40             << (24 - p_bit_stream->i_available);
41         p_bit_stream->i_available += 8;
42     }
43     result = p_bit_stream->buffer >> (32 - num_bits);
44     p_bit_stream->buffer <<= num_bits;
45     p_bit_stream->i_available -= num_bits;
46     p_bit_stream->total_bits_read += num_bits;
47     
48     return result;
49 }