Changeset 407


Ignore:
Timestamp:
06/02/08 16:23:00 (16 years ago)
Author:
r2d
Message:

added a bound to the seek table size, varying the step between seek points if necessary

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libmpc/trunk/libmpcdec/mpc_demux.c

    r405 r407  
    4242#include "mpc_bits_reader.h"
    4343
     44/// maximum number of seek points in the table. The distance between points will
     45/// be adapted so this value is never exceeded.
     46#define MAX_SEEK_TABLE_SIZE     65536
     47
    4448// streaminfo.c
    4549mpc_status streaminfo_read_header_sv8(mpc_streaminfo* si,
     
    205209static mpc_status mpc_demux_seek_init(mpc_demux * d)
    206210{
     211        size_t seek_table_size;
    207212        if (d->seek_table != 0)
    208213                return MPC_STATUS_OK;
     
    211216        if (d->si.block_pwr > d->seek_pwr)
    212217                d->seek_pwr = d->si.block_pwr;
    213         d->seek_table = malloc((size_t)(2 + d->si.samples / (MPC_FRAME_LENGTH << d->seek_pwr)) * sizeof(mpc_seek_t));
     218        seek_table_size = (2 + d->si.samples / (MPC_FRAME_LENGTH << d->seek_pwr));
     219        while (seek_table_size > MAX_SEEK_TABLE_SIZE) {
     220                d->seek_pwr++;
     221                seek_table_size = (2 + d->si.samples / (MPC_FRAME_LENGTH << d->seek_pwr));
     222        }
     223        d->seek_table = malloc((size_t)(seek_table_size * sizeof(mpc_seek_t)));
    214224        if (d->seek_table == 0)
    215225                return MPC_STATUS_FILE;
     
    223233{
    224234        mpc_uint64_t tmp;
    225         mpc_seek_t * table;
     235        mpc_seek_t * table, last[2];
    226236        mpc_bits_reader r = d->bits_reader;
    227         mpc_uint_t i;
     237        mpc_uint_t i, diff_pwr = 0, mask;
     238        mpc_uint32_t file_table_size;
    228239
    229240        if (d->seek_table != 0)
     
    231242
    232243        mpc_bits_get_size(&r, &tmp);
    233         d->seek_table_size = (mpc_seek_t) tmp;
     244        file_table_size = (mpc_seek_t) tmp;
    234245        d->seek_pwr = d->si.block_pwr + mpc_bits_read(&r, 4);
     246
    235247        tmp = 2 + d->si.samples / (MPC_FRAME_LENGTH << d->seek_pwr);
    236         if (tmp < d->seek_table_size) tmp = d->seek_table_size;
    237         d->seek_table = malloc((size_t)(tmp * sizeof(mpc_seek_t)));
     248        while (tmp > MAX_SEEK_TABLE_SIZE) {
     249                d->seek_pwr++;
     250                diff_pwr++;
     251                tmp = 2 + d->si.samples / (MPC_FRAME_LENGTH << d->seek_pwr);
     252        }
     253        if ((file_table_size >> diff_pwr) > tmp)
     254                file_table_size = tmp << diff_pwr;
     255        d->seek_table = malloc((size_t) (tmp * sizeof(mpc_seek_t)));
     256        d->seek_table_size = (file_table_size + ((1 << diff_pwr) - 1)) >> diff_pwr;
    238257
    239258        table = d->seek_table;
    240259        mpc_bits_get_size(&r, &tmp);
    241         table[0] = (mpc_seek_t) (tmp + d->si.header_position) * 8;
     260        table[0] = last[0] = (mpc_seek_t) (tmp + d->si.header_position) * 8;
    242261
    243262        if (d->seek_table_size == 1)
     
    245264
    246265        mpc_bits_get_size(&r, &tmp);
    247         table[1] = (mpc_seek_t) (tmp + d->si.header_position) * 8;
    248 
    249         for (i = 2; i < d->seek_table_size; i++) {
     266        last[1] = (mpc_seek_t) (tmp + d->si.header_position) * 8;
     267        if (diff_pwr == 0) table[1] = last[1];
     268
     269        mask = (1 << diff_pwr) - 1;
     270        for (i = 2; i < file_table_size; i++) {
    250271                int code = mpc_bits_golomb_dec(&r, 12);
    251272                if (code & 1)
    252273                        code = -(code & (-1 << 1));
    253274                code <<= 2;
    254                 table[i] = code + 2 * table[i-1] - table[i-2];
     275                last[i & 1] = code + 2 * last[(i-1) & 1] - last[i & 1];
     276                if ((i & mask) == 0)
     277                        table[i >> diff_pwr] = last[i & 1];
    255278        }
    256279}
Note: See TracChangeset for help on using the changeset viewer.