Blame src/libmpg123/index.h

Packit c32a2d
#ifndef MPG123_H_INDEX
Packit c32a2d
#define MPG123_H_INDEX
Packit c32a2d
Packit c32a2d
/*
Packit c32a2d
	index: frame index data structure and functions
Packit c32a2d
Packit c32a2d
	This is for keeping track of frame positions for accurate seeking.
Packit c32a2d
	Now in it's own file, with initial code from frame.c and parse.c .
Packit c32a2d
Packit c32a2d
	The idea of the index with a certain amount of entries is to cover
Packit c32a2d
	all yet-encountered frame positions with minimal coarseness.
Packit c32a2d
	Meaning: At first every frame position is recorded, then, when
Packit c32a2d
	the index is full, every second position is trown away to make
Packit c32a2d
	space. Next time it is full, the same happens. And so on.
Packit c32a2d
	In this manner we maintain a good resolution with the given
Packit c32a2d
	maximum index size while covering the whole stream.
Packit c32a2d
Packit c32a2d
	copyright 2007-8 by the mpg123 project - free software under the terms of the LGPL 2.1
Packit c32a2d
	see COPYING and AUTHORS files in distribution or http://mpg123.org
Packit c32a2d
	initially written by Thomas Orgis
Packit c32a2d
*/
Packit c32a2d
Packit c32a2d
#include "config.h"
Packit c32a2d
#include "compat.h"
Packit c32a2d
Packit c32a2d
struct frame_index
Packit c32a2d
{
Packit c32a2d
	off_t *data; /* actual data, the frame positions */
Packit c32a2d
	off_t  step; /* advancement in frame number per index point */
Packit c32a2d
	off_t  next; /* frame offset supposed to come next into the index */
Packit c32a2d
	size_t size; /* total number of possible entries */
Packit c32a2d
	size_t fill; /* number of used entries */
Packit c32a2d
	size_t grow_size; /* if > 0: index allowed to grow on need with these steps, instead of lowering resolution */
Packit c32a2d
};
Packit c32a2d
Packit c32a2d
/* The condition for a framenum to be appended to the index. 
Packit c32a2d
  if(FI_NEXT(fr->index, fr->num)) fi_add(offset); */
Packit c32a2d
#define FI_NEXT(fi, framenum) ((fi).size && framenum == (fi).next)
Packit c32a2d
Packit c32a2d
/* Initialize stuff, set things to zero and NULL... */
Packit c32a2d
void fi_init(struct frame_index *fi);
Packit c32a2d
/* Deallocate/zero things. */
Packit c32a2d
void fi_exit(struct frame_index *fi);
Packit c32a2d
Packit c32a2d
/* Prepare a given size, preserving current fill, if possible.
Packit c32a2d
   If the new size is smaller than fill, the entry density is reduced.
Packit c32a2d
   Return 0 on success. */
Packit c32a2d
int fi_resize(struct frame_index *fi, size_t newsize);
Packit c32a2d
Packit c32a2d
/* Append a frame position, reducing index density if needed. */
Packit c32a2d
void fi_add(struct frame_index *fi, off_t pos);
Packit c32a2d
Packit c32a2d
/* Replace the frame index */
Packit c32a2d
int fi_set(struct frame_index *fi, off_t *offsets, off_t step, size_t fill);
Packit c32a2d
Packit c32a2d
/* Empty the index (setting fill=0 and step=1), but keep current size. */
Packit c32a2d
void fi_reset(struct frame_index *fi);
Packit c32a2d
Packit c32a2d
#endif