Change the gmp download URL to https://gmplib.org/download
[vlc/gmpfix.git] / modules / mux / mpeg / bits.h
blob4f0e6002c57e0e34eada5bb0e40bf9810652a171
1 /*****************************************************************************
2 * bits.h
3 *****************************************************************************
4 * Copyright (C) 2001, 2002 VLC authors and VideoLAN
5 * $Id$
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
27 int i_size;
29 int i_data;
30 uint8_t i_mask;
31 uint8_t *p_data;
33 } bits_buffer_t;
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;
39 p_buffer->i_data = 0;
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 ) ) )
45 return -1;
47 p_buffer->p_data[0] = 0;
48 return 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;
56 p_buffer->i_data++;
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 )
64 while( i_count > 0 )
66 i_count--;
68 if( ( i_bits >> i_count )&0x01 )
70 p_buffer->p_data[p_buffer->i_data] |= p_buffer->i_mask;
72 else
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 )
79 p_buffer->i_data++;
80 p_buffer->i_mask = 0x80;