Ignore:
Timestamp:
12/30/06 17:49:40 (18 years ago)
Author:
r2d
Message:
  • moved skip_id3v2 to demuxer and changed so it doesn't need seek (not tested with id3v2 tags)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • libmpc/branches/r2d/libmpcdec/mpc_demux.c

    r195 r196  
    131131        mpc_demux_clear_buff(d);
    132132        if (d->si.stream_version == 7)
    133                 mpc_demux_fill(d, (min_bytes + ((bit_offset + 7) >> 3) + 3) & (-1 << 2), MPC_BUFFER_SWAP);
     133                mpc_demux_fill(d, (min_bytes + ((bit_offset + 7) >> 3) + 3) & (~3), MPC_BUFFER_SWAP);
    134134        else
    135135                mpc_demux_fill(d, min_bytes + ((bit_offset + 7) >> 3), 0);
     
    146146{
    147147        return ((d->r->tell(d->r) - d->bytes_total + d->bits_reader.buff - d->buffer) << 3) + 8 - d->bits_reader.count;
     148}
     149
     150/**
     151 * Searches for a ID3v2-tag and reads the length (in bytes) of it.
     152 *
     153 * @param d demuxer context
     154 * @return size of tag, in bytes
     155 * @return MPC_STATUS_FILE on errors of any kind
     156 */
     157mpc_int32_t mpc_demux_skip_id3v2(mpc_demux * d)
     158{
     159        mpc_uint8_t  tmp [4];
     160        mpc_bool_t footerPresent;     // ID3v2.4-flag
     161        mpc_int32_t size;
     162
     163    // we must be at the beginning of the stream
     164        mpc_demux_fill(d, 3, 0);
     165
     166    // check id3-tag
     167        if ( 0 != memcmp( d->bits_reader.buff, "ID3", 3 ) )
     168                return 0;
     169
     170        mpc_demux_fill(d, 10, 0);
     171
     172        mpc_bits_read(&d->bits_reader, 24); // read ID3
     173        mpc_bits_read(&d->bits_reader, 16); // read tag version
     174
     175        tmp[0] = mpc_bits_read(&d->bits_reader, 8); // read flags
     176        footerPresent = tmp[0] & 0x10;
     177        if ( tmp[0] & 0x0F )
     178                return MPC_STATUS_FILE; // not (yet???) allowed
     179
     180        tmp[0] = mpc_bits_read(&d->bits_reader, 8); // read size
     181        tmp[1] = mpc_bits_read(&d->bits_reader, 8); // read size
     182        tmp[2] = mpc_bits_read(&d->bits_reader, 8); // read size
     183        tmp[3] = mpc_bits_read(&d->bits_reader, 8); // read size
     184
     185        if ( (tmp[0] | tmp[1] | tmp[2] | tmp[3]) & 0x80 )
     186                return MPC_STATUS_FILE; // not allowed
     187
     188    // read headerSize (syncsave: 4 * $0xxxxxxx = 28 significant bits)
     189        size = tmp[0] << 21;
     190        size |= tmp[1] << 14;
     191        size |= tmp[2] << 7;
     192        size |= tmp[3];
     193
     194        if ( footerPresent )
     195                size += 10;
     196
     197        mpc_demux_fill(d, size, 0);
     198        d->bits_reader.buff += size;
     199
     200        return size + 10;
    148201}
    149202
     
    219272{
    220273        char magic[4];
    221         int err;
    222274
    223275        memset(&d->si, 0, sizeof d->si);
    224276
    225277    // get header position
    226         err = d->si.header_position = mpc_skip_id3v2(d->r);
    227         if(err < 0) return MPC_STATUS_FILE;
    228 
    229         // seek to first byte of mpc data
    230         err = d->r->seek(d->r, d->si.header_position);
    231         if(!err) return MPC_STATUS_FILE;
     278        d->si.header_position = mpc_demux_skip_id3v2(d);
     279        if(d->si.header_position < 0) return MPC_STATUS_FILE;
    232280
    233281        d->si.tag_offset = d->si.total_file_length = d->r->get_size(d->r);
     
    418466        return MPC_STATUS_OK;
    419467}
     468
Note: See TracChangeset for help on using the changeset viewer.