Changeset 196 for libmpc/branches/r2d/libmpcdec
- Timestamp:
- 12/30/06 17:49:40 (18 years ago)
- Location:
- libmpc/branches/r2d/libmpcdec
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
libmpc/branches/r2d/libmpcdec/internal.h
r195 r196 83 83 }; 84 84 85 /// Searches for a ID3v2-tag and reads the length (in bytes) of it.86 ///87 /// \param p_reader supplying raw stream data88 /// \return size of tag, in bytes89 /// \return MPC_STATUS_FILE on errors of any kind90 mpc_int32_t mpc_skip_id3v2(mpc_reader* p_reader);91 92 85 /// helper functions used by multiple files 93 86 mpc_uint32_t mpc_random_int(mpc_decoder *d); // in synth_filter.c -
libmpc/branches/r2d/libmpcdec/mpc_demux.c
r195 r196 131 131 mpc_demux_clear_buff(d); 132 132 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); 134 134 else 135 135 mpc_demux_fill(d, min_bytes + ((bit_offset + 7) >> 3), 0); … … 146 146 { 147 147 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 */ 157 mpc_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; 148 201 } 149 202 … … 219 272 { 220 273 char magic[4]; 221 int err;222 274 223 275 memset(&d->si, 0, sizeof d->si); 224 276 225 277 // 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; 232 280 233 281 d->si.tag_offset = d->si.total_file_length = d->r->get_size(d->r); … … 418 466 return MPC_STATUS_OK; 419 467 } 468 -
libmpc/branches/r2d/libmpcdec/mpc_reader.c
r195 r196 136 136 } 137 137 138 mpc_int32_t139 mpc_skip_id3v2(mpc_reader* p_reader)140 {141 mpc_uint8_t tmp [10];142 mpc_uint32_t unsynchronisation; // ID3v2.4-flag143 mpc_uint32_t extHeaderPresent; // ID3v2.4-flag144 mpc_uint32_t experimentalFlag; // ID3v2.4-flag145 mpc_uint32_t footerPresent; // ID3v2.4-flag146 mpc_int32_t ret;147 148 // seek to first byte of mpc data149 ret = p_reader->seek(p_reader, 0);150 if(!ret) return 0;151 152 p_reader->read(p_reader, tmp, sizeof tmp);153 154 // check id3-tag155 if ( 0 != memcmp( tmp, "ID3", 3 ) )156 return 0;157 158 // read flags159 unsynchronisation = tmp[5] & 0x80;160 extHeaderPresent = tmp[5] & 0x40;161 experimentalFlag = tmp[5] & 0x20;162 footerPresent = tmp[5] & 0x10;163 164 if ( tmp[5] & 0x0F )165 return MPC_STATUS_FILE; // not (yet???) allowed166 if ( (tmp[6] | tmp[7] | tmp[8] | tmp[9]) & 0x80 )167 return MPC_STATUS_FILE; // not allowed168 169 // read headerSize (syncsave: 4 * $0xxxxxxx = 28 significant bits)170 ret = tmp[6] << 21;171 ret += tmp[7] << 14;172 ret += tmp[8] << 7;173 ret += tmp[9];174 ret += 10;175 if ( footerPresent )176 ret += 10;177 178 return ret;179 }180 181 182
Note: See TracChangeset
for help on using the changeset viewer.