View Single Post
Old 13 May 2010, 03:53 pm   #2
Buschel
The Man
 
Join Date: Mar 2008
Posts: 9
Default

I am searching for a solution that looks similar to this:

// d->bits_reader.buff - d->buffer = position within buffer
// d->bytes_total = total position in file at buffer start
// fpos = file position in bit (not byte)
// min_bytes = minimum number of bytes to be available from fpos on
if ((fpos>>3) >= d->bytes_total &&
d->bits_reader.buff - d->buffer + d->bytes_total + (fpos>>3) + min_bytes <= DEMUX_BUFFER_SIZE)
{
int total_pos_bytes = d->bytes_total + d->bits_reader.buff - d->buffer;
int diff_pos_bytes = (fpos>>3) - total_pos_bytes;
d->bits_reader.buff += diff_pos_bytes;
d->bits_reader.count = 8 - (fpos & 7);
}
else
{
next_pos = fpos >> 3;
if (d->si.stream_version == 7)
next_pos = ((next_pos - d->si.header_position) & (-1 << 2)) + d->si.header_position;
bit_offset = (int) (fpos - (next_pos << 3));

d->r->seek(d->r, (mpc_int32_t) next_pos);
mpc_demux_clear_buff(d);
if (d->si.stream_version == 7)
mpc_demux_fill(d, DEMUX_BUFFER_SIZE, MPC_BUFFER_SWAP);
else
mpc_demux_fill(d, DEMUX_BUFFER_SIZE, 0);
d->bits_reader.buff += bit_offset >> 3;
d->bits_reader.count = 8 - (bit_offset & 7);
}

This code still performs a search. But it still does not enter the first if-path. This is because I am still not sure how to use and interprete the different variables. Help is very much appreciated.

Goal: Check whether the next needed bytes are within the current buffer. if not, refill the buffer completely.
Buschel is offline   Reply With Quote