diff 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
line wrap: on
line diff
--- a/flacdec.c	Fri Mar 06 00:54:49 2009 +0000
+++ b/flacdec.c	Fri Mar 06 01:25:11 2009 +0000
@@ -220,6 +220,18 @@
     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 @@
         /* 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 @@
 
     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;