1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2001, 2002 VLC authors and VideoLAN
7 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
8 * Eric Petit <titer@videolan.org>
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU Lesser General Public License as published by
12 * the Free Software Foundation; either version 2.1 of the License, or
13 * (at your option) any later version.
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 Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with this program; if not, write to the Free Software Foundation,
22 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
25 typedef struct bits_buffer_s
35 static inline int bits_initwrite( bits_buffer_t
*p_buffer
,
36 int i_size
, void *p_data
)
38 p_buffer
->i_size
= i_size
;
40 p_buffer
->i_mask
= 0x80;
41 p_buffer
->p_data
= p_data
;
42 if( !p_buffer
->p_data
)
44 if( !( p_buffer
->p_data
= malloc( i_size
) ) )
47 p_buffer
->p_data
[0] = 0;
51 static inline void bits_align( bits_buffer_t
*p_buffer
)
53 if( p_buffer
->i_mask
!= 0x80 && p_buffer
->i_data
< p_buffer
->i_size
)
55 p_buffer
->i_mask
= 0x80;
57 p_buffer
->p_data
[p_buffer
->i_data
] = 0x00;
61 static inline void bits_write( bits_buffer_t
*p_buffer
,
62 int i_count
, uint64_t i_bits
)
68 if( ( i_bits
>> i_count
)&0x01 )
70 p_buffer
->p_data
[p_buffer
->i_data
] |= p_buffer
->i_mask
;
74 p_buffer
->p_data
[p_buffer
->i_data
] &= ~p_buffer
->i_mask
;
76 p_buffer
->i_mask
>>= 1;
77 if( p_buffer
->i_mask
== 0 )
80 p_buffer
->i_mask
= 0x80;