summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorReimar Döffinger <Reimar.Doeffinger@gmx.de>2010-10-06 20:21:07 +0000
committerReimar Döffinger <Reimar.Doeffinger@gmx.de>2010-10-06 20:21:07 +0000
commit6612d8cf3170a5bf1b3460c22f8c725c02542533 (patch)
tree887a00c4d753247b8cdc7639d6a0d21fe8468767
parent1136850dd59f52d92d8ba3a70a42fafcdf37c05d (diff)
Move handling of ID3v2 to common utils.c code, reducing code duplication
and supporting it for more formats, fixing issue 2258. Originally committed as revision 25378 to svn://svn.ffmpeg.org/ffmpeg/trunk
-rw-r--r--libavformat/aacdec.c5
-rw-r--r--libavformat/flacdec.c14
-rw-r--r--libavformat/mp3.c4
-rw-r--r--libavformat/mpc.c33
-rw-r--r--libavformat/tta.c8
-rw-r--r--libavformat/utils.c18
6 files changed, 19 insertions, 63 deletions
diff --git a/libavformat/aacdec.c b/libavformat/aacdec.c
index bc6c5a8b1f..64ac3d13c6 100644
--- a/libavformat/aacdec.c
+++ b/libavformat/aacdec.c
@@ -23,7 +23,6 @@
#include "libavutil/intreadwrite.h"
#include "avformat.h"
#include "rawdec.h"
-#include "id3v2.h"
#include "id3v1.h"
@@ -36,9 +35,6 @@ static int adts_aac_probe(AVProbeData *p)
uint8_t *buf;
uint8_t *end = buf0 + p->buf_size - 7;
- if (ff_id3v2_match(buf0, ID3v2_DEFAULT_MAGIC)) {
- buf0 += ff_id3v2_tag_len(buf0);
- }
buf = buf0;
for(; buf < end; buf= buf2+1) {
@@ -78,7 +74,6 @@ static int adts_aac_read_header(AVFormatContext *s,
st->need_parsing = AVSTREAM_PARSE_FULL;
ff_id3v1_read(s);
- ff_id3v2_read(s, ID3v2_DEFAULT_MAGIC);
//LCM of all possible ADTS sample rates
av_set_pts_info(st, 64, 1, 28224000);
diff --git a/libavformat/flacdec.c b/libavformat/flacdec.c
index e54fb395ff..6922b6ce3f 100644
--- a/libavformat/flacdec.c
+++ b/libavformat/flacdec.c
@@ -22,14 +22,12 @@
#include "libavcodec/flac.h"
#include "avformat.h"
#include "rawdec.h"
-#include "id3v2.h"
#include "oggdec.h"
#include "vorbiscomment.h"
static int flac_read_header(AVFormatContext *s,
AVFormatParameters *ap)
{
- uint8_t buf[ID3v2_HEADER_SIZE];
int ret, metadata_last=0, metadata_type, metadata_size, found_streaminfo=0;
uint8_t header[4];
uint8_t *buffer=NULL;
@@ -41,15 +39,6 @@ static int flac_read_header(AVFormatContext *s,
st->need_parsing = AVSTREAM_PARSE_FULL;
/* the parameters will be extracted from the compressed bitstream */
- /* skip ID3v2 header if found */
- ret = get_buffer(s->pb, buf, ID3v2_HEADER_SIZE);
- 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 {
- url_fseek(s->pb, 0, SEEK_SET);
- }
-
/* if fLaC marker is not found, assume there is no header */
if (get_le32(s->pb) != MKTAG('f','L','a','C')) {
url_fseek(s->pb, -4, SEEK_CUR);
@@ -130,9 +119,6 @@ static int flac_probe(AVProbeData *p)
uint8_t *bufptr = p->buf;
uint8_t *end = p->buf + p->buf_size;
- if(ff_id3v2_match(bufptr, ID3v2_DEFAULT_MAGIC))
- bufptr += ff_id3v2_tag_len(bufptr);
-
if(bufptr > end-4 || memcmp(bufptr, "fLaC", 4)) return 0;
else return AVPROBE_SCORE_MAX/2;
}
diff --git a/libavformat/mp3.c b/libavformat/mp3.c
index c1622a3567..4dfffec6de 100644
--- a/libavformat/mp3.c
+++ b/libavformat/mp3.c
@@ -42,9 +42,6 @@ static int mp3_read_probe(AVProbeData *p)
AVCodecContext avctx;
buf0 = p->buf;
- if(ff_id3v2_match(buf0, ID3v2_DEFAULT_MAGIC)) {
- buf0 += ff_id3v2_tag_len(buf0);
- }
end = p->buf + p->buf_size - sizeof(uint32_t);
while(buf0 < end && !*buf0)
buf0++;
@@ -156,7 +153,6 @@ 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, 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 681e37f772..084f79752e 100644
--- a/libavformat/mpc.c
+++ b/libavformat/mpc.c
@@ -21,7 +21,6 @@
#include "libavcodec/get_bits.h"
#include "avformat.h"
-#include "id3v2.h"
#include "apetag.h"
#define MPC_FRAMESIZE 1152
@@ -45,10 +44,6 @@ typedef struct {
static int mpc_probe(AVProbeData *p)
{
const uint8_t *d = p->buf;
- if (ff_id3v2_match(d, ID3v2_DEFAULT_MAGIC)) {
- d += ff_id3v2_tag_len(d);
- }
- if (d+3 < p->buf+p->buf_size)
if (d[0] == 'M' && d[1] == 'P' && d[2] == '+' && (d[3] == 0x17 || d[3] == 0x7))
return AVPROBE_SCORE_MAX;
return 0;
@@ -58,32 +53,10 @@ static int mpc_read_header(AVFormatContext *s, AVFormatParameters *ap)
{
MPCContext *c = s->priv_data;
AVStream *st;
- int t, ret;
- int64_t pos = url_ftell(s->pb);
- t = get_le24(s->pb);
- if(t != MKTAG('M', 'P', '+', 0)){
- uint8_t buf[ID3v2_HEADER_SIZE];
- 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, ID3v2_DEFAULT_MAGIC)) {
- av_log(s, AV_LOG_ERROR, "Not a Musepack file\n");
- return -1;
- }
- /* skip ID3 tags and try again */
- t = ff_id3v2_tag_len(buf) - ID3v2_HEADER_SIZE;
- av_log(s, AV_LOG_DEBUG, "Skipping %d(%X) bytes of ID3 data\n", t, t);
- url_fskip(s->pb, t);
- if(get_le24(s->pb) != MKTAG('M', 'P', '+', 0)){
- av_log(s, AV_LOG_ERROR, "Not a Musepack file\n");
- return -1;
- }
- /* read ID3 tags */
- if (url_fseek(s->pb, pos, SEEK_SET) < 0)
- return -1;
- ff_id3v2_read(s, ID3v2_DEFAULT_MAGIC);
- get_le24(s->pb);
+ if(get_le24(s->pb) != MKTAG('M', 'P', '+', 0)){
+ av_log(s, AV_LOG_ERROR, "Not a Musepack file\n");
+ return -1;
}
c->ver = get_byte(s->pb);
if(c->ver != 0x07 && c->ver != 0x17){
diff --git a/libavformat/tta.c b/libavformat/tta.c
index 628932da0c..64ed4d819a 100644
--- a/libavformat/tta.c
+++ b/libavformat/tta.c
@@ -21,7 +21,6 @@
#include "libavcodec/get_bits.h"
#include "avformat.h"
-#include "id3v2.h"
#include "id3v1.h"
typedef struct {
@@ -32,12 +31,6 @@ static int tta_probe(AVProbeData *p)
{
const uint8_t *d = p->buf;
- if (ff_id3v2_match(d, ID3v2_DEFAULT_MAGIC))
- d += ff_id3v2_tag_len(d);
-
- if (d - p->buf >= p->buf_size)
- return 0;
-
if (d[0] == 'T' && d[1] == 'T' && d[2] == 'A' && d[3] == '1')
return 80;
return 0;
@@ -50,7 +43,6 @@ 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, ID3v2_DEFAULT_MAGIC);
if (!av_metadata_get(s->metadata, "", NULL, AV_METADATA_IGNORE_SUFFIX))
ff_id3v1_read(s);
diff --git a/libavformat/utils.c b/libavformat/utils.c
index a545a5d9f4..a51a5faf59 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -23,6 +23,7 @@
#include "libavcodec/internal.h"
#include "libavutil/opt.h"
#include "metadata.h"
+#include "id3v2.h"
#include "libavutil/avstring.h"
#include "riff.h"
#include "audiointerleave.h"
@@ -343,18 +344,27 @@ int av_filename_number_test(const char *filename)
AVInputFormat *av_probe_input_format2(AVProbeData *pd, int is_opened, int *score_max)
{
+ AVProbeData lpd = *pd;
AVInputFormat *fmt1, *fmt;
int score;
+ if (lpd.buf_size > 10 && ff_id3v2_match(lpd.buf, ID3v2_DEFAULT_MAGIC)) {
+ int id3len = ff_id3v2_tag_len(lpd.buf);
+ if (lpd.buf_size > id3len + 16) {
+ lpd.buf += id3len;
+ lpd.buf_size -= id3len;
+ }
+ }
+
fmt = NULL;
for(fmt1 = first_iformat; fmt1 != NULL; fmt1 = fmt1->next) {
if (!is_opened == !(fmt1->flags & AVFMT_NOFILE))
continue;
score = 0;
if (fmt1->read_probe) {
- score = fmt1->read_probe(pd);
+ score = fmt1->read_probe(&lpd);
} else if (fmt1->extensions) {
- if (av_match_ext(pd->filename, fmt1->extensions)) {
+ if (av_match_ext(lpd.filename, fmt1->extensions)) {
score = 50;
}
}
@@ -448,6 +458,10 @@ int av_open_input_stream(AVFormatContext **ic_ptr,
ic->priv_data = NULL;
}
+ // e.g. AVFMT_NOFILE formats will not have a ByteIOContext
+ if (ic->pb)
+ ff_id3v2_read(ic, ID3v2_DEFAULT_MAGIC);
+
if (ic->iformat->read_header) {
err = ic->iformat->read_header(ic, ap);
if (err < 0)