changeset 6121:81614e9b541b libavformat

Generalize ID3v2 functions to support ID3v2-like ID headers with a different magic in the header (mainly targeted to Sony's .oma/.aa3 format). Patch by Michael Karcher, ffmpeg A mkarcher dialup fu-berlin de
author cehoyos
date Fri, 11 Jun 2010 13:44:57 +0000
parents a2a55244ca6b
children ad7cfe404294
files flacdec.c id3v2.c id3v2.h mp3.c mpc.c raw.c tta.c
diffstat 7 files changed, 28 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/flacdec.c	Fri Jun 11 13:28:42 2010 +0000
+++ b/flacdec.c	Fri Jun 11 13:44:57 2010 +0000
@@ -43,7 +43,7 @@
 
     /* skip ID3v2 header if found */
     ret = get_buffer(s->pb, buf, ID3v2_HEADER_SIZE);
-    if (ret == ID3v2_HEADER_SIZE && ff_id3v2_match(buf)) {
+    if (ret == ID3v2_HEADER_SIZE && ff_id3v2_match(buf, ID3v2_DEFAULT_MAGIC)) {
         int len = ff_id3v2_tag_len(buf);
         url_fseek(s->pb, len - ID3v2_HEADER_SIZE, SEEK_CUR);
     } else {
@@ -130,7 +130,7 @@
     uint8_t *bufptr = p->buf;
     uint8_t *end    = p->buf + p->buf_size;
 
-    if(ff_id3v2_match(bufptr))
+    if(ff_id3v2_match(bufptr, ID3v2_DEFAULT_MAGIC))
         bufptr += ff_id3v2_tag_len(bufptr);
 
     if(bufptr > end-4 || memcmp(bufptr, "fLaC", 4)) return 0;
--- a/id3v2.c	Fri Jun 11 13:28:42 2010 +0000
+++ b/id3v2.c	Fri Jun 11 13:44:57 2010 +0000
@@ -22,12 +22,13 @@
 #include "id3v2.h"
 #include "id3v1.h"
 #include "libavutil/avstring.h"
+#include "libavutil/intreadwrite.h"
 
-int ff_id3v2_match(const uint8_t *buf)
+int ff_id3v2_match(const uint8_t *buf, const char * magic)
 {
-    return  buf[0]         ==  'I' &&
-            buf[1]         ==  'D' &&
-            buf[2]         ==  '3' &&
+    return  buf[0]         == magic[0] &&
+            buf[1]         == magic[1] &&
+            buf[2]         == magic[2] &&
             buf[3]         != 0xff &&
             buf[4]         != 0xff &&
            (buf[6] & 0x80) ==    0 &&
@@ -48,7 +49,7 @@
     return len;
 }
 
-void ff_id3v2_read(AVFormatContext *s)
+void ff_id3v2_read(AVFormatContext *s, const char *magic)
 {
     int len, ret;
     uint8_t buf[ID3v2_HEADER_SIZE];
@@ -56,7 +57,7 @@
     ret = get_buffer(s->pb, buf, ID3v2_HEADER_SIZE);
     if (ret != ID3v2_HEADER_SIZE)
         return;
-    if (ff_id3v2_match(buf)) {
+    if (ff_id3v2_match(buf, magic)) {
         /* parse ID3v2 header */
         len = ((buf[6] & 0x7f) << 21) |
             ((buf[7] & 0x7f) << 14) |
--- a/id3v2.h	Fri Jun 11 13:28:42 2010 +0000
+++ b/id3v2.h	Fri Jun 11 13:44:57 2010 +0000
@@ -29,10 +29,17 @@
 #define ID3v2_HEADER_SIZE 10
 
 /**
+ * Default magic bytes for ID3v2 header: "ID3"
+ */
+#define ID3v2_DEFAULT_MAGIC "ID3"
+
+/**
  * Detects ID3v2 Header.
- * @buf must be ID3v2_HEADER_SIZE byte long
+ * @buf   must be ID3v2_HEADER_SIZE byte long
+ * @magic magic bytes to identify the header, machine byte order.
+ * If in doubt, use ID3v2_DEFAULT_MAGIC.
  */
-int ff_id3v2_match(const uint8_t *buf);
+int ff_id3v2_match(const uint8_t *buf, const char *magic);
 
 /**
  * Gets the length of an ID3v2 tag.
@@ -50,7 +57,7 @@
 /**
  * Read an ID3v2 tag
  */
-void ff_id3v2_read(AVFormatContext *s);
+void ff_id3v2_read(AVFormatContext *s, const char *magic);
 
 extern const AVMetadataConv ff_id3v2_metadata_conv[];
 
--- a/mp3.c	Fri Jun 11 13:28:42 2010 +0000
+++ b/mp3.c	Fri Jun 11 13:44:57 2010 +0000
@@ -42,7 +42,7 @@
     AVCodecContext avctx;
 
     buf0 = p->buf;
-    if(ff_id3v2_match(buf0)) {
+    if(ff_id3v2_match(buf0, ID3v2_DEFAULT_MAGIC)) {
         buf0 += ff_id3v2_tag_len(buf0);
     }
     end = p->buf + p->buf_size - sizeof(uint32_t);
@@ -148,7 +148,7 @@
     // lcm of all mp3 sample rates
     av_set_pts_info(st, 64, 1, 14112000);
 
-    ff_id3v2_read(s);
+    ff_id3v2_read(s, ID3v2_DEFAULT_MAGIC);
     off = url_ftell(s->pb);
 
     if (!av_metadata_get(s->metadata, "", NULL, AV_METADATA_IGNORE_SUFFIX))
--- a/mpc.c	Fri Jun 11 13:28:42 2010 +0000
+++ b/mpc.c	Fri Jun 11 13:44:57 2010 +0000
@@ -45,7 +45,7 @@
 static int mpc_probe(AVProbeData *p)
 {
     const uint8_t *d = p->buf;
-    if (ff_id3v2_match(d)) {
+    if (ff_id3v2_match(d, ID3v2_DEFAULT_MAGIC)) {
         d += ff_id3v2_tag_len(d);
     }
     if (d+3 < p->buf+p->buf_size)
@@ -67,7 +67,7 @@
         if (url_fseek(s->pb, pos, SEEK_SET) < 0)
             return -1;
         ret = get_buffer(s->pb, buf, ID3v2_HEADER_SIZE);
-        if (ret != ID3v2_HEADER_SIZE || !ff_id3v2_match(buf)) {
+        if (ret != ID3v2_HEADER_SIZE || !ff_id3v2_match(buf, ID3v2_DEFAULT_MAGIC)) {
             av_log(s, AV_LOG_ERROR, "Not a Musepack file\n");
             return -1;
         }
@@ -82,7 +82,7 @@
         /* read ID3 tags */
         if (url_fseek(s->pb, pos, SEEK_SET) < 0)
             return -1;
-        ff_id3v2_read(s);
+        ff_id3v2_read(s, ID3v2_DEFAULT_MAGIC);
         get_le24(s->pb);
     }
     c->ver = get_byte(s->pb);
--- a/raw.c	Fri Jun 11 13:28:42 2010 +0000
+++ b/raw.c	Fri Jun 11 13:44:57 2010 +0000
@@ -664,7 +664,7 @@
     uint8_t *buf;
     uint8_t *end = buf0 + p->buf_size - 7;
 
-    if (ff_id3v2_match(buf0)) {
+    if (ff_id3v2_match(buf0, ID3v2_DEFAULT_MAGIC)) {
         buf0 += ff_id3v2_tag_len(buf0);
     }
     buf = buf0;
@@ -706,7 +706,7 @@
     st->need_parsing = AVSTREAM_PARSE_FULL;
 
     ff_id3v1_read(s);
-    ff_id3v2_read(s);
+    ff_id3v2_read(s, ID3v2_DEFAULT_MAGIC);
 
     return 0;
 }
--- a/tta.c	Fri Jun 11 13:28:42 2010 +0000
+++ b/tta.c	Fri Jun 11 13:44:57 2010 +0000
@@ -32,7 +32,7 @@
 {
     const uint8_t *d = p->buf;
 
-    if (ff_id3v2_match(d))
+    if (ff_id3v2_match(d, ID3v2_DEFAULT_MAGIC))
         d += ff_id3v2_tag_len(d);
 
     if (d - p->buf >= p->buf_size)
@@ -50,7 +50,7 @@
     int i, channels, bps, samplerate, datalen, framelen;
     uint64_t framepos, start_offset;
 
-    ff_id3v2_read(s);
+    ff_id3v2_read(s, ID3v2_DEFAULT_MAGIC);
     if (!av_metadata_get(s->metadata, "", NULL, AV_METADATA_IGNORE_SUFFIX))
         ff_id3v1_read(s);