Commit 4bfba26a authored by Pierre d'Herbemont's avatar Pierre d'Herbemont

vlc_bits: Differentiate between writable bits stream and read only.

This fixes some const qualifier violation in modules.
parent 7ca02b97
...@@ -30,15 +30,25 @@ ...@@ -30,15 +30,25 @@
*/ */
typedef struct bs_s typedef struct bs_s
{
const uint8_t *p_start;
const uint8_t *p;
const uint8_t *p_end;
unsigned i_left; /* i_count number of available bits */
} bs_t;
typedef struct bs_writable_s
{ {
uint8_t *p_start; uint8_t *p_start;
uint8_t *p; uint8_t *p;
uint8_t *p_end; uint8_t *p_end;
unsigned i_left; /* i_count number of available bits */
} bsw_t;
int i_left; /* i_count number of available bits */
} bs_t;
static inline void bs_init( bs_t *s, void *p_data, int i_data ) static inline void bs_init( bs_t *s, const void *p_data, unsigned i_data )
{ {
s->p_start = p_data; s->p_start = p_data;
s->p = p_data; s->p = p_data;
...@@ -141,25 +151,67 @@ static inline void bs_skip( bs_t *s, int i_count ) ...@@ -141,25 +151,67 @@ static inline void bs_skip( bs_t *s, int i_count )
} }
} }
static inline void bs_write( bs_t *s, int i_count, uint32_t i_bits ) /*
* Writable bits stream
*/
static inline void bsw_init_writable( bsw_t *s, void *p_data, unsigned i_data )
{
s->p_start = p_data;
s->p = p_data;
s->p_end = s->p + i_data;
s->i_left = 8;
}
static inline bs_t * bs_from_writable( bsw_t *s )
{
return (bs_t *)s;
}
static inline void bsw_skip( bsw_t *s, int count )
{
return bs_skip(bs_from_writable(s), count);
}
static inline uint32_t bsw_show( bsw_t *s, int count )
{
return bs_show(bs_from_writable(s), count);
}
static inline uint32_t bsw_read1( bsw_t *s )
{
return bs_read1(bs_from_writable(s));
}
static inline uint32_t bsw_read( bsw_t *s, int count )
{
return bs_read(bs_from_writable(s), count);
}
static inline int bsw_pos( bsw_t *s )
{
return bs_pos(bs_from_writable(s));
}
static inline int bsw_eof( bsw_t *s )
{
return bs_eof(bs_from_writable(s));
}
static inline void bsw_write( bsw_t *s, int i_count, uint32_t i_bits )
{ {
while( i_count > 0 ) while( i_count > 0 )
{ {
if( s->p >= s->p_end ) if( s->p >= s->p_end )
{
break; break;
}
i_count--; i_count--;
if( ( i_bits >> i_count )&0x01 ) if( ( i_bits >> i_count )&0x01 )
{
*s->p |= 1 << ( s->i_left - 1 ); *s->p |= 1 << ( s->i_left - 1 );
}
else else
{
*s->p &= ~( 1 << ( s->i_left - 1 ) ); *s->p &= ~( 1 << ( s->i_left - 1 ) );
}
s->i_left--; s->i_left--;
if( s->i_left == 0 ) if( s->i_left == 0 )
{ {
...@@ -169,7 +221,7 @@ static inline void bs_write( bs_t *s, int i_count, uint32_t i_bits ) ...@@ -169,7 +221,7 @@ static inline void bs_write( bs_t *s, int i_count, uint32_t i_bits )
} }
} }
static inline void bs_align( bs_t *s ) static inline void bsw_align( bsw_t *s )
{ {
if( s->i_left != 8 ) if( s->i_left != 8 )
{ {
...@@ -178,20 +230,16 @@ static inline void bs_align( bs_t *s ) ...@@ -178,20 +230,16 @@ static inline void bs_align( bs_t *s )
} }
} }
static inline void bs_align_0( bs_t *s ) static inline void bsw_align_0( bsw_t *s )
{ {
if( s->i_left != 8 ) if( s->i_left != 8 )
{ bsw_write( s, s->i_left, 0 );
bs_write( s, s->i_left, 0 );
}
} }
static inline void bs_align_1( bs_t *s ) static inline void bsw_align_1( bsw_t *s )
{ {
while( s->i_left != 8 ) while( s->i_left != 8 )
{ bsw_write( s, 1, 1 );
bs_write( s, 1, 1 );
}
} }
#endif #endif
...@@ -573,9 +573,9 @@ static void RenderImage( decoder_t *p_dec, block_t *p_data, ...@@ -573,9 +573,9 @@ static void RenderImage( decoder_t *p_dec, block_t *p_data,
int i_field; /* The subtitles are interlaced */ int i_field; /* The subtitles are interlaced */
int i_row, i_column; /* scanline row/column number */ int i_row, i_column; /* scanline row/column number */
uint8_t i_color, i_count; uint8_t i_color, i_count;
bs_t bs; bsw_t bsw;
bs_init( &bs, p_data->p_buffer + p_sys->i_image_offset, bsw_init_writable( &bsw, p_data->p_buffer + p_sys->i_image_offset,
p_data->i_buffer - p_sys->i_image_offset ); p_data->i_buffer - p_sys->i_image_offset );
for( i_field = 0; i_field < 2; i_field++ ) for( i_field = 0; i_field < 2; i_field++ )
...@@ -584,12 +584,12 @@ static void RenderImage( decoder_t *p_dec, block_t *p_data, ...@@ -584,12 +584,12 @@ static void RenderImage( decoder_t *p_dec, block_t *p_data,
{ {
for( i_column = 0; i_column < p_sys->i_width; i_column++ ) for( i_column = 0; i_column < p_sys->i_width; i_column++ )
{ {
uint8_t i_val = bs_read( &bs, 4 ); uint8_t i_val = bsw_read( &bsw, 4 );
if( i_val == 0 ) if( i_val == 0 )
{ {
/* Fill the rest of the line with next color */ /* Fill the rest of the line with next color */
i_color = bs_read( &bs, 4 ); i_color = bsw_read( &bsw, 4 );
memset( &p_dest[i_row * p_region->p_picture->Y_PITCH + memset( &p_dest[i_row * p_region->p_picture->Y_PITCH +
i_column], i_color, i_column], i_color,
...@@ -612,7 +612,7 @@ static void RenderImage( decoder_t *p_dec, block_t *p_data, ...@@ -612,7 +612,7 @@ static void RenderImage( decoder_t *p_dec, block_t *p_data,
} }
} }
bs_align( &bs ); bsw_align( &bsw );
} }
} }
} }
This diff is collapsed.
...@@ -546,9 +546,9 @@ static void SVCDSubRenderImage( decoder_t *p_dec, block_t *p_data, ...@@ -546,9 +546,9 @@ static void SVCDSubRenderImage( decoder_t *p_dec, block_t *p_data,
int i_field; /* The subtitles are interlaced */ int i_field; /* The subtitles are interlaced */
int i_row, i_column; /* scanline row/column number */ int i_row, i_column; /* scanline row/column number */
uint8_t i_color, i_count; uint8_t i_color, i_count;
bs_t bs; bsw_t bs;
bs_init( &bs, p_data->p_buffer + p_sys->i_image_offset, bsw_init_writable( &bs, p_data->p_buffer + p_sys->i_image_offset,
p_data->i_buffer - p_sys->i_image_offset ); p_data->i_buffer - p_sys->i_image_offset );
for( i_field = 0; i_field < 2; i_field++ ) for( i_field = 0; i_field < 2; i_field++ )
...@@ -557,8 +557,8 @@ static void SVCDSubRenderImage( decoder_t *p_dec, block_t *p_data, ...@@ -557,8 +557,8 @@ static void SVCDSubRenderImage( decoder_t *p_dec, block_t *p_data,
{ {
for( i_column = 0; i_column < p_sys->i_width; i_column++ ) for( i_column = 0; i_column < p_sys->i_width; i_column++ )
{ {
i_color = bs_read( &bs, 2 ); i_color = bsw_read( &bs, 2 );
if( i_color == 0 && (i_count = bs_read( &bs, 2 )) ) if( i_color == 0 && (i_count = bsw_read( &bs, 2 )) )
{ {
i_count = __MIN( i_count, p_sys->i_width - i_column ); i_count = __MIN( i_count, p_sys->i_width - i_column );
memset( &p_dest[i_row * p_region->p_picture->Y_PITCH + memset( &p_dest[i_row * p_region->p_picture->Y_PITCH +
...@@ -570,11 +570,11 @@ static void SVCDSubRenderImage( decoder_t *p_dec, block_t *p_data, ...@@ -570,11 +570,11 @@ static void SVCDSubRenderImage( decoder_t *p_dec, block_t *p_data,
p_dest[i_row * p_region->p_picture->Y_PITCH + i_column] = i_color; p_dest[i_row * p_region->p_picture->Y_PITCH + i_column] = i_color;
} }
bs_align( &bs ); bsw_align( &bs );
} }
/* odd field */ /* odd field */
bs_init( &bs, p_data->p_buffer + p_sys->i_image_offset + bsw_init_writable( &bs, p_data->p_buffer + p_sys->i_image_offset +
p_sys->second_field_offset, p_sys->second_field_offset,
p_data->i_buffer - p_sys->i_image_offset - p_data->i_buffer - p_sys->i_image_offset -
p_sys->second_field_offset ); p_sys->second_field_offset );
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment