#ifndef MPG123_H_INDEX1#define MPG123_H_INDEX23/*4index: frame index data structure and functions56This is for keeping track of frame positions for accurate seeking.7Now in it's own file, with initial code from frame.c and parse.c .89The idea of the index with a certain amount of entries is to cover10all yet-encountered frame positions with minimal coarseness.11Meaning: At first every frame position is recorded, then, when12the index is full, every second position is trown away to make13space. Next time it is full, the same happens. And so on.14In this manner we maintain a good resolution with the given15maximum index size while covering the whole stream.1617copyright 2007-2023 by the mpg123 project - free software under the terms of the LGPL 2.118see COPYING and AUTHORS files in distribution or http://mpg123.org19initially written by Thomas Orgis20*/2122#include "config.h"23#include "../compat/compat.h"2425struct frame_index26{27int64_t *data; /* actual data, the frame positions */28int64_t step; /* advancement in frame number per index point */29int64_t next; /* frame offset supposed to come next into the index */30size_t size; /* total number of possible entries */31size_t fill; /* number of used entries */32size_t grow_size; /* if > 0: index allowed to grow on need with these steps, instead of lowering resolution */33};3435/* The condition for a framenum to be appended to the index.36if(FI_NEXT(fr->index, fr->num)) INT123_fi_add(offset); */37#define FI_NEXT(fi, framenum) ((fi).size && framenum == (fi).next)3839/* Initialize stuff, set things to zero and NULL... */40void INT123_fi_init(struct frame_index *fi);41/* Deallocate/zero things. */42void INT123_fi_exit(struct frame_index *fi);4344/* Prepare a given size, preserving current fill, if possible.45If the new size is smaller than fill, the entry density is reduced.46Return 0 on success. */47int INT123_fi_resize(struct frame_index *fi, size_t newsize);4849/* Append a frame position, reducing index density if needed. */50void INT123_fi_add(struct frame_index *fi, int64_t pos);5152/* Replace the frame index */53int INT123_fi_set(struct frame_index *fi, int64_t *offsets, int64_t step, size_t fill);5455/* Empty the index (setting fill=0 and step=1), but keep current size. */56void INT123_fi_reset(struct frame_index *fi);5758#endif596061