23#ifndef VLC_BLOCK_HELPER_H
24#define VLC_BLOCK_HELPER_H 1
71 while( block != p_bytestream->
p_block )
92 if( p_bytestream->
p_chain == NULL )
101 for( ; p_block; p_block = p_block->
p_next )
118 p_block = p_bytestream->
p_block;
123 else if( !p_block->
p_next )
135 p_block = p_block->
p_next;
137 block_t *p_block_old = p_block;
138 p_block = p_block->
p_next;
139 p_block_old->
p_next = NULL;
156 uint8_t *p_data,
size_t i_data )
163 size_t i_size = i_data;
165 p_block != NULL; p_block = p_block->
p_next )
167 size_t i_copy = __MIN( i_size, p_block->i_buffer - i_offset );
172 memcpy( p_data, p_block->p_buffer + i_offset, i_copy );
185 uint8_t *p_data,
size_t i_data )
192 size_t i_size = i_data;
195 for( p_block = p_bytestream->
p_block;
196 p_block != NULL; p_block = p_block->
p_next )
198 i_copy = __MIN( i_size, p_block->
i_buffer - i_offset );
201 if( i_copy && p_data != NULL )
203 memcpy( p_data, p_block->
p_buffer + i_offset, i_copy );
214 p_bytestream->
p_block = p_block;
232 size_t i_peek_offset, uint8_t *p_data,
size_t i_data )
235 if( i_remain < i_data + i_peek_offset )
240 size_t i_size = i_peek_offset;
243 for( p_block = p_bytestream->
p_block;
244 p_block != NULL; p_block = p_block->
p_next )
246 i_copy = __MIN( i_size, p_block->
i_buffer - i_offset );
257 for( ; p_block != NULL; p_block = p_block->
p_next )
259 i_copy = __MIN( i_size, p_block->
i_buffer - i_offset );
264 memcpy( p_data, p_block->
p_buffer + i_offset, i_copy );
276typedef const uint8_t * (*block_startcode_helper_t)(
const uint8_t *,
const uint8_t * );
281 const uint8_t *p_startcode,
int i_startcode_length,
285 block_t *p_block, *p_block_backup = 0;
287 size_t i_offset, i_offset_backup = 0;
288 int i_caller_offset_backup = 0, i_match;
292 for( p_block = p_bytestream->
p_block;
293 p_block != NULL; p_block = p_block->
p_next )
296 if( i_size < 0 )
break;
309 *pi_offset -= i_size;
311 for( ; p_block != NULL; p_block = p_block->
p_next )
313 for( i_offset = i_size; i_offset < p_block->
i_buffer; i_offset++ )
316 if( p_startcode_helper && !i_match &&
317 (p_block->
i_buffer - i_offset) > ((
size_t)i_startcode_length - 1) )
319 const uint8_t *p_res = p_startcode_helper( &p_block->
p_buffer[i_offset],
323 *pi_offset += i_offset + (p_res - &p_block->
p_buffer[i_offset]);
327 i_offset = p_block->
i_buffer - (i_startcode_length - 1);
330 bool b_matched = ( p_startcode_matcher )
331 ? p_startcode_matcher( p_block->
p_buffer[i_offset], i_match, p_startcode )
332 : p_block->
p_buffer[i_offset] == p_startcode[i_match];
337 p_block_backup = p_block;
338 i_offset_backup = i_offset;
339 i_caller_offset_backup = *pi_offset;
342 if( i_match + 1 == i_startcode_length )
345 *pi_offset += i_offset - i_match;
351 else if ( i_match > 0 )
354 p_block = p_block_backup;
355 i_offset = i_offset_backup;
356 *pi_offset = i_caller_offset_backup;
362 *pi_offset += i_offset;
365 *pi_offset -= i_match;
#define VLC_USED
Definition: fourcc_gen.c:32
#define unlikely(p)
Predicted false condition.
Definition: vlc_common.h:257
#define VLC_EGENERIC
Unspecified error.
Definition: vlc_common.h:505
#define VLC_SUCCESS
No error.
Definition: vlc_common.h:503
Definition: vlc_block_helper.h:30
block_t ** pp_last
tail ppointer for appends
Definition: vlc_block_helper.h:32
block_t * p_block
byte stream read pointer block
Definition: vlc_block_helper.h:33
size_t i_base_offset
block base offset (previous blocks total size)
Definition: vlc_block_helper.h:35
block_t * p_chain
byte stream head block
Definition: vlc_block_helper.h:31
size_t i_total
total bytes over all linked blocks
Definition: vlc_block_helper.h:36
size_t i_block_offset
byte stream read pointer offset within block
Definition: vlc_block_helper.h:34
Definition: vlc_frame.h:123
vlc_frame_t * p_next
Definition: vlc_frame.h:124
uint8_t * p_buffer
Payload start.
Definition: vlc_frame.h:126
size_t i_buffer
Payload length.
Definition: vlc_frame.h:127
#define block_ChainRelease
Definition: vlc_block.h:99
#define block_ChainLastAppend
Definition: vlc_block.h:98
#define block_Release
Definition: vlc_block.h:87
static void block_BytestreamFlush(block_bytestream_t *p_bytestream)
It flushes all already read data from a block_bytestream_t.
Definition: vlc_block_helper.h:68
struct block_bytestream_t block_bytestream_t
static int block_PeekOffsetBytes(block_bytestream_t *p_bytestream, size_t i_peek_offset, uint8_t *p_data, size_t i_data)
Definition: vlc_block_helper.h:232
static int block_GetBytes(block_bytestream_t *p_bytestream, uint8_t *p_data, size_t i_data)
Definition: vlc_block_helper.h:185
static int block_WaitBytes(block_bytestream_t *p_bytestream, size_t i_data)
Definition: vlc_block_helper.h:148
const uint8_t *(* block_startcode_helper_t)(const uint8_t *, const uint8_t *)
Definition: vlc_block_helper.h:277
static block_t * block_BytestreamPop(block_bytestream_t *p_bytestream)
Definition: vlc_block_helper.h:113
static int block_FindStartcodeFromOffset(block_bytestream_t *p_bytestream, size_t *pi_offset, const uint8_t *p_startcode, int i_startcode_length, block_startcode_helper_t p_startcode_helper, block_startcode_matcher_t p_startcode_matcher)
Definition: vlc_block_helper.h:280
static void block_BytestreamEmpty(block_bytestream_t *p_bytestream)
It flush all data (read and unread) from a block_bytestream_t.
Definition: vlc_block_helper.h:59
static int block_PeekBytes(block_bytestream_t *p_bytestream, uint8_t *p_data, size_t i_data)
Definition: vlc_block_helper.h:156
static int block_SkipBytes(block_bytestream_t *p_bytestream, size_t i_data)
Definition: vlc_block_helper.h:221
static int block_SkipByte(block_bytestream_t *p_bytestream)
Definition: vlc_block_helper.h:227
static void block_BytestreamInit(block_bytestream_t *p_bytestream)
Definition: vlc_block_helper.h:42
static void block_BytestreamRelease(block_bytestream_t *p_bytestream)
Definition: vlc_block_helper.h:51
static size_t block_BytestreamRemaining(const block_bytestream_t *p_bytestream)
Definition: vlc_block_helper.h:106
static void block_BytestreamPush(block_bytestream_t *p_bytestream, block_t *p_block)
Definition: vlc_block_helper.h:97
bool(* block_startcode_matcher_t)(uint8_t, size_t, const uint8_t *)
Definition: vlc_block_helper.h:278
This file is a collection of common definitions and types.