Mercurial > libavcodec.hg
comparison flacdec.c @ 9146:b980183eb831 libavcodec
flacdec: Add a shared function for parsing a FLAC metadata block header.
author | jbr |
---|---|
date | Fri, 06 Mar 2009 01:25:11 +0000 |
parents | 4564ec1f21b0 |
children | f534d0cca450 |
comparison
equal
deleted
inserted
replaced
9145:de31b10455cc | 9146:b980183eb831 |
---|---|
218 skip_bits_long(&gb, 64); /* md5 sum */ | 218 skip_bits_long(&gb, 64); /* md5 sum */ |
219 | 219 |
220 dump_headers(avctx, s); | 220 dump_headers(avctx, s); |
221 } | 221 } |
222 | 222 |
223 void ff_flac_parse_block_header(const uint8_t *block_header, | |
224 int *last, int *type, int *size) | |
225 { | |
226 int tmp = bytestream_get_byte(&block_header); | |
227 if (last) | |
228 *last = tmp & 0x80; | |
229 if (type) | |
230 *type = tmp & 0x7F; | |
231 if (size) | |
232 *size = bytestream_get_be24(&block_header); | |
233 } | |
234 | |
223 /** | 235 /** |
224 * Parse the STREAMINFO from an inline header. | 236 * Parse the STREAMINFO from an inline header. |
225 * @param s the flac decoding context | 237 * @param s the flac decoding context |
226 * @param buf input buffer, starting with the "fLaC" marker | 238 * @param buf input buffer, starting with the "fLaC" marker |
227 * @param buf_size buffer size | 239 * @param buf_size buffer size |
233 | 245 |
234 if (buf_size < FLAC_STREAMINFO_SIZE+8) { | 246 if (buf_size < FLAC_STREAMINFO_SIZE+8) { |
235 /* need more data */ | 247 /* need more data */ |
236 return 0; | 248 return 0; |
237 } | 249 } |
238 buf += 4; | 250 ff_flac_parse_block_header(&buf[4], NULL, &metadata_type, &metadata_size); |
239 metadata_type = bytestream_get_byte(&buf) & 0x7F; | |
240 metadata_size = bytestream_get_be24(&buf); | |
241 if (metadata_type != FLAC_METADATA_TYPE_STREAMINFO || | 251 if (metadata_type != FLAC_METADATA_TYPE_STREAMINFO || |
242 metadata_size != FLAC_STREAMINFO_SIZE) { | 252 metadata_size != FLAC_STREAMINFO_SIZE) { |
243 return AVERROR_INVALIDDATA; | 253 return AVERROR_INVALIDDATA; |
244 } | 254 } |
245 ff_flac_parse_streaminfo(s->avctx, (FLACStreaminfo *)s, buf); | 255 ff_flac_parse_streaminfo(s->avctx, (FLACStreaminfo *)s, &buf[8]); |
246 allocate_buffers(s); | 256 allocate_buffers(s); |
247 s->got_streaminfo = 1; | 257 s->got_streaminfo = 1; |
248 | 258 |
249 return 0; | 259 return 0; |
250 } | 260 } |
260 int metadata_last, metadata_size; | 270 int metadata_last, metadata_size; |
261 const uint8_t *buf_end = buf + buf_size; | 271 const uint8_t *buf_end = buf + buf_size; |
262 | 272 |
263 buf += 4; | 273 buf += 4; |
264 do { | 274 do { |
265 metadata_last = bytestream_get_byte(&buf) & 0x80; | 275 ff_flac_parse_block_header(buf, &metadata_last, NULL, &metadata_size); |
266 metadata_size = bytestream_get_be24(&buf); | 276 buf += 4; |
267 if (buf + metadata_size > buf_end) { | 277 if (buf + metadata_size > buf_end) { |
268 /* need more data in order to read the complete header */ | 278 /* need more data in order to read the complete header */ |
269 return 0; | 279 return 0; |
270 } | 280 } |
271 buf += metadata_size; | 281 buf += metadata_size; |