func:  nestegg_read_packet(nestegg * ctx, nestegg_packet ** pkt) uint64_t id , size ; r = ne_peek_element ( ctx , & id , & size ); static ne_peek_element(nestegg * ctx, uint64_t * id, uint64_t * size) int r ; if ( ctx -> last_valid )  return 1 ; r = ne_read_id ( ctx -> io , & ctx -> last_id , NULL ); static ne_read_id(nestegg_io * io, uint64_t * value, uint64_t * length) return ne_bare_read_vint ( io , value , length , MASK_NONE ) ; static ne_bare_read_vint(nestegg_io * io, uint64_t * value, uint64_t * length, enum vint_mask maskflag) int r ; unsigned char b ; size_t maxlen = 8 ; unsigned int count = 1 , mask = 1 << 7 ; r = ne_io_read ( io , & b , 1 ); static ne_io_read(nestegg_io * io, void * buffer, size_t length) return io -> read ( buffer , length , io -> userdata ) ; if ( r != 1 )  return r ; while ( count < maxlen )  if ( ( b & mask ) != 0 )  mask >>= 1; count += 1; while ( -- count )  r = ne_io_read ( io , & b , 1 ); static ne_io_read(nestegg_io * io, void * buffer, size_t length) return io -> read ( buffer , length , io -> userdata ) ; if ( r != 1 )  return r ; return 1 ; if ( r != 1 )  return r ; r = ne_read_vint ( ctx -> io , & ctx -> last_size , NULL ); static ne_read_vint(nestegg_io * io, uint64_t * value, uint64_t * length) return ne_bare_read_vint ( io , value , length , MASK_FIRST_BIT ) ; static ne_bare_read_vint(nestegg_io * io, uint64_t * value, uint64_t * length, enum vint_mask maskflag) int r ; unsigned char b ; size_t maxlen = 8 ; unsigned int count = 1 , mask = 1 << 7 ; r = ne_io_read ( io , & b , 1 ); if ( r != 1 )  return r ; while ( count < maxlen )  if ( ( b & mask ) != 0 )  mask >>= 1; count += 1; while ( -- count )  r = ne_io_read ( io , & b , 1 ); if ( r != 1 )  return r ; return 1 ; if ( r != 1 )  return r ; return 1 ; if ( r != 1 )  if ( ne_is_suspend_element ( id ) )  static ne_is_suspend_element(uint64_t id) if ( id == ID_SIMPLE_BLOCK || id == ID_BLOCK )  return 1 ; return 0 ; r = ne_parse ( ctx , NULL , - 1 ); if ( r != 1 )  static ne_parse(nestegg * ctx, struct ebml_element_desc * top_level, int64_t max_offset) int r ; int64_t * data_offset ; uint64_t id , size , peeked_id ; struct ebml_element_desc * element ; if ( ! ctx -> ancestor )  if ( max_offset > 0 && ne_io_tell ( ctx -> io ) >= max_offset )  static ne_io_tell(nestegg_io * io) return io -> tell ( io -> userdata ) ; r = ne_peek_element ( ctx , & id , & size ); static ne_peek_element(nestegg * ctx, uint64_t * id, uint64_t * size) int r ; if ( ctx -> last_valid )  return 1 ; r = ne_read_id ( ctx -> io , & ctx -> last_id , NULL ); if ( r != 1 )  return r ; r = ne_read_vint ( ctx -> io , & ctx -> last_size , NULL ); if ( r != 1 )  return r ; return 1 ; if ( r != 1 )  element = ne_find_element ( id , ctx -> ancestor -> node ); static struct ebml_element_desc ne_find_element(uint64_t id, struct ebml_element_desc * elements) struct ebml_element_desc * element ; for (element = elements; element->id; ++element) if ( element -> id == id )  return element ; return NULL ; if ( element )  if ( element -> flags & DESC_FLAG_SUSPEND )  r = ne_read_element ( ctx , & id , & size ); static ne_read_element(nestegg * ctx, uint64_t * id, uint64_t * size) int r ; r = ne_peek_element ( ctx , id , size ); static ne_peek_element(nestegg * ctx, uint64_t * id, uint64_t * size) int r ; if ( ctx -> last_valid )  return 1 ; r = ne_read_id ( ctx -> io , & ctx -> last_id , NULL ); if ( r != 1 )  return r ; r = ne_read_vint ( ctx -> io , & ctx -> last_size , NULL ); if ( r != 1 )  return r ; return 1 ; if ( r != 1 )  return r ; return 1 ; if ( r != 1 )  if ( element -> flags & DESC_FLAG_OFFSET )  data_offset = ( int64_t * ) ( ctx -> ancestor -> data + element -> data_offset ); * data_offset = ne_io_tell ( ctx -> io ); static ne_io_tell(nestegg_io * io) return io -> tell ( io -> userdata ) ; if ( * data_offset < 0 )  if ( element -> type == TYPE_MASTER )  if ( element -> flags & DESC_FLAG_MULTI )  if ( ne_read_master ( ctx , element ) < 0 )  if ( ne_read_single_master ( ctx , element ) < 0 )  static ne_read_single_master(nestegg * ctx, struct ebml_element_desc * desc) return ne_ctx_push ( ctx , desc -> children , ctx -> ancestor -> data + desc -> offset ) ; static ne_ctx_push(nestegg * ctx, struct ebml_element_desc * ancestor, void * data) struct list_node * item ; item = ne_alloc ( sizeof ( * item ) ); static void ne_alloc(size_t size) return calloc ( 1 , size ) ; if ( ! item )  return - 1 ; return 0 ; r = ne_read_simple ( ctx , element , size ); static ne_read_simple(nestegg * ctx, struct ebml_element_desc * desc, size_t length) struct ebml_type * storage ; int r ; storage = ( struct ebml_type * ) ( ctx -> ancestor -> data + desc -> offset ); if ( storage -> read )  return 0 ; storage -> type = desc -> type; switch ( desc -> type )  r = ne_read_uint ( ctx -> io , & storage -> v . u , length ); static ne_read_uint(nestegg_io * io, uint64_t * val, uint64_t length) int r ; if ( length == 0 || length > 8 )  return - 1 ; r = ne_io_read ( io , & b , 1 ); static ne_io_read(nestegg_io * io, void * buffer, size_t length) return io -> read ( buffer , length , io -> userdata ) ; if ( r != 1 )  return r ; while ( -- length )  r = ne_io_read ( io , & b , 1 ); static ne_io_read(nestegg_io * io, void * buffer, size_t length) return io -> read ( buffer , length , io -> userdata ) ; if ( r != 1 )  return r ; return 1 ; r = ne_read_float ( ctx -> io , & storage -> v . f , length ); static ne_read_float(nestegg_io * io, double * val, uint64_t length) union { uint64_t u ; float f ; double d ; } value ; int r ; if ( length != 4 && length != 8 )  return - 1 ; r = ne_read_uint ( io , & value . u , length ); static ne_read_uint(nestegg_io * io, uint64_t * val, uint64_t length) int r ; if ( length == 0 || length > 8 )  return - 1 ; r = ne_io_read ( io , & b , 1 ); if ( r != 1 )  return r ; while ( -- length )  r = ne_io_read ( io , & b , 1 ); if ( r != 1 )  return r ; return 1 ; if ( r != 1 )  return r ; return 1 ; r = ne_read_int ( ctx -> io , & storage -> v . i , length ); static ne_read_int(nestegg_io * io, int64_t * val, uint64_t length) int r ; r = ne_read_uint ( io , & uval , length ); static ne_read_uint(nestegg_io * io, uint64_t * val, uint64_t length) int r ; if ( length == 0 || length > 8 )  return - 1 ; r = ne_io_read ( io , & b , 1 ); if ( r != 1 )  return r ; while ( -- length )  r = ne_io_read ( io , & b , 1 ); if ( r != 1 )  return r ; return 1 ; if ( r != 1 )  return r ; return 1 ; r = ne_read_string ( ctx , & storage -> v . s , length ); static ne_read_string(nestegg * ctx, char ** val, uint64_t length) char * str ; int r ; if ( length > LIMIT_STRING )  return - 1 ; str = ne_pool_alloc ( length + 1 , ctx -> alloc_pool ); static void ne_pool_alloc(size_t size, struct pool_ctx * pool) void * p ; p = h_malloc ( size ); if ( ! p )  return NULL ; memset ( p , 0 , size ); return p ; if ( ! str )  return - 1 ; if ( length )  r = ne_io_read ( ctx -> io , ( unsigned char * ) str , length ); static ne_io_read(nestegg_io * io, void * buffer, size_t length) return io -> read ( buffer , length , io -> userdata ) ; if ( r != 1 )  return r ; return 1 ; r = ne_read_binary ( ctx , & storage -> v . b , length ); static ne_read_binary(nestegg * ctx, struct ebml_binary * val, uint64_t length) if ( length == 0 || length > LIMIT_BINARY )  return - 1 ; val -> data = ne_pool_alloc ( length , ctx -> alloc_pool ); static void ne_pool_alloc(size_t size, struct pool_ctx * pool) void * p ; p = h_malloc ( size ); if ( ! p )  return NULL ; memset ( p , 0 , size ); return p ; if ( ! val -> data )  return - 1 ; val -> length = length; return ne_io_read ( ctx -> io , val -> data , length ) ; static ne_io_read(nestegg_io * io, void * buffer, size_t length) return io -> read ( buffer , length , io -> userdata ) ; r = 0; return r ; if ( r < 0 )  if ( ne_is_ancestor_element ( id , ctx -> ancestor -> previous ) )  static ne_is_ancestor_element(uint64_t id, struct list_node * ancestor) struct ebml_element_desc * element ; for (; ancestor; ancestor = ancestor->previous) for (element = ancestor->node; element->id; ++element) if ( element -> id == id )  return 1 ; return 0 ; if ( top_level && ctx -> ancestor -> node == top_level )  r = ne_read_element ( ctx , & id , & size ); static ne_read_element(nestegg * ctx, uint64_t * id, uint64_t * size) int r ; r = ne_peek_element ( ctx , id , size ); if ( r != 1 )  return r ; return 1 ; if ( r != 1 )  r = ne_io_read_skip ( ctx -> io , size ); static ne_io_read_skip(nestegg_io * io, size_t length) size_t get ; unsigned char buf [ 8192 ] ; int r = 1 ; while ( length > 0 )  get = length < sizeof ( buf ) ? length : sizeof ( buf ); r = ne_io_read ( io , buf , get ); static ne_io_read(nestegg_io * io, void * buffer, size_t length) return io -> read ( buffer , length , io -> userdata ) ; if ( r != 1 )  length -= get; return r ; if ( r != 1 )  static ne_read_master(nestegg * ctx, struct ebml_element_desc * desc) assert ( desc -> type == TYPE_MASTER && desc -> flags & DESC_FLAG_MULTI ); 