aboutsummaryrefslogtreecommitdiffstats
path: root/libavformat
diff options
context:
space:
mode:
authorMichael Karcher <ffmpeg@mkarcher.dialup.fu-berlin.de>2010-06-11 13:44:57 +0000
committerCarl Eugen Hoyos <cehoyos@rainbow.studorg.tuwien.ac.at>2010-06-11 13:44:57 +0000
commit3a1350e8d9955a5eb9ec90f9b3e27ae63c3fb0bb (patch)
tree0c5f4ce531628c132328144c7d0e1ed76b642393 /libavformat
parent1c1697117dbd2923d5876c10a1ebaeec233338b5 (diff)
downloadffmpeg-3a1350e8d9955a5eb9ec90f9b3e27ae63c3fb0bb.tar.gz
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 Originally committed as revision 23583 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavformat')
-rw-r--r--libavformat/flacdec.c4
-rw-r--r--libavformat/id3v2.c13
-rw-r--r--libavformat/id3v2.h13
-rw-r--r--libavformat/mp3.c4
-rw-r--r--libavformat/mpc.c6
-rw-r--r--libavformat/raw.c4
-rw-r--r--libavformat/tta.c4
7 files changed, 28 insertions, 20 deletions
diff --git a/libavformat/flacdec.c b/libavformat/flacdec.c
index 2ceef964e8..3cdd53c6af 100644
--- a/libavformat/flacdec.c
+++ b/libavformat/flacdec.c
@@ -43,7 +43,7 @@ static int flac_read_header(AVFormatContext *s,
/* 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 @@ static int flac_probe(AVProbeData *p)
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;
diff --git a/libavformat/id3v2.c b/libavformat/id3v2.c
index 6fa11db6c0..7e4a16fae8 100644
--- a/libavformat/id3v2.c
+++ b/libavformat/id3v2.c
@@ -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 @@ int ff_id3v2_tag_len(const uint8_t * buf)
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 @@ void ff_id3v2_read(AVFormatContext *s)
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) |
diff --git a/libavformat/id3v2.h b/libavformat/id3v2.h
index 70030d297f..1f1530467e 100644
--- a/libavformat/id3v2.h
+++ b/libavformat/id3v2.h
@@ -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 @@ void ff_id3v2_parse(AVFormatContext *s, int len, uint8_t version, uint8_t flags)
/**
* 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[];
diff --git a/libavformat/mp3.c b/libavformat/mp3.c
index dcb59e8417..bdb2e4ec0a 100644
--- a/libavformat/mp3.c
+++ b/libavformat/mp3.c
@@ -42,7 +42,7 @@ static int mp3_read_probe(AVProbeData *p)
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 @@ static int mp3_read_header(AVFormatContext *s,
// 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))
diff --git a/libavformat/mpc.c b/libavformat/mpc.c
index 4dda65dbca..681e37f772 100644
--- a/libavformat/mpc.c
+++ b/libavformat/mpc.c
@@ -45,7 +45,7 @@ typedef struct {
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 @@ static int mpc_read_header(AVFormatContext *s, AVFormatParameters *ap)
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 @@ static int mpc_read_header(AVFormatContext *s, AVFormatParameters *ap)
/* 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);
diff --git a/libavformat/raw.c b/libavformat/raw.c
index 85d204d7e3..0a188cf25c 100644
--- a/libavformat/raw.c
+++ b/libavformat/raw.c
@@ -664,7 +664,7 @@ static int adts_aac_probe(AVProbeData *p)
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 @@ static int adts_aac_read_header(AVFormatContext *s,
st->need_parsing = AVSTREAM_PARSE_FULL;
ff_id3v1_read(s);
- ff_id3v2_read(s);
+ ff_id3v2_read(s, ID3v2_DEFAULT_MAGIC);
return 0;
}
diff --git a/libavformat/tta.c b/libavformat/tta.c
index 66d3bad904..628932da0c 100644
--- a/libavformat/tta.c
+++ b/libavformat/tta.c
@@ -32,7 +32,7 @@ static int tta_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 - p->buf >= p->buf_size)
@@ -50,7 +50,7 @@ static int tta_read_header(AVFormatContext *s, AVFormatParameters *ap)
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);