diff options
author | Justin Ruggles <justin.ruggles@gmail.com> | 2009-03-06 01:25:11 +0000 |
---|---|---|
committer | Justin Ruggles <justin.ruggles@gmail.com> | 2009-03-06 01:25:11 +0000 |
commit | 5b63d33d7d178cdf4581b946a4f758695f2123f9 (patch) | |
tree | 98ddd86f9636ebc1ebd433ed5c793d592e0b0ffc /libavcodec/flacdec.c | |
parent | e0c98063e7cd4d140c05f150d72e7f76374a2a58 (diff) | |
download | ffmpeg-5b63d33d7d178cdf4581b946a4f758695f2123f9.tar.gz |
flacdec: Add a shared function for parsing a FLAC metadata block header.
Originally committed as revision 17851 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavcodec/flacdec.c')
-rw-r--r-- | libavcodec/flacdec.c | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/libavcodec/flacdec.c b/libavcodec/flacdec.c index 2c5f22ce2c..cd746f224d 100644 --- a/libavcodec/flacdec.c +++ b/libavcodec/flacdec.c @@ -220,6 +220,18 @@ void ff_flac_parse_streaminfo(AVCodecContext *avctx, struct FLACStreaminfo *s, dump_headers(avctx, s); } +void ff_flac_parse_block_header(const uint8_t *block_header, + int *last, int *type, int *size) +{ + int tmp = bytestream_get_byte(&block_header); + if (last) + *last = tmp & 0x80; + if (type) + *type = tmp & 0x7F; + if (size) + *size = bytestream_get_be24(&block_header); +} + /** * Parse the STREAMINFO from an inline header. * @param s the flac decoding context @@ -235,14 +247,12 @@ static int parse_streaminfo(FLACContext *s, const uint8_t *buf, int buf_size) /* need more data */ return 0; } - buf += 4; - metadata_type = bytestream_get_byte(&buf) & 0x7F; - metadata_size = bytestream_get_be24(&buf); + ff_flac_parse_block_header(&buf[4], NULL, &metadata_type, &metadata_size); if (metadata_type != FLAC_METADATA_TYPE_STREAMINFO || metadata_size != FLAC_STREAMINFO_SIZE) { return AVERROR_INVALIDDATA; } - ff_flac_parse_streaminfo(s->avctx, (FLACStreaminfo *)s, buf); + ff_flac_parse_streaminfo(s->avctx, (FLACStreaminfo *)s, &buf[8]); allocate_buffers(s); s->got_streaminfo = 1; @@ -262,8 +272,8 @@ static int get_metadata_size(const uint8_t *buf, int buf_size) buf += 4; do { - metadata_last = bytestream_get_byte(&buf) & 0x80; - metadata_size = bytestream_get_be24(&buf); + ff_flac_parse_block_header(buf, &metadata_last, NULL, &metadata_size); + buf += 4; if (buf + metadata_size > buf_end) { /* need more data in order to read the complete header */ return 0; |