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
oldabi
Reimar Döffinger 14 years ago
parent 1136850dd5
commit 6612d8cf31
  1. 5
      libavformat/aacdec.c
  2. 14
      libavformat/flacdec.c
  3. 4
      libavformat/mp3.c
  4. 27
      libavformat/mpc.c
  5. 8
      libavformat/tta.c
  6. 18
      libavformat/utils.c

@ -23,7 +23,6 @@
#include "libavutil/intreadwrite.h" #include "libavutil/intreadwrite.h"
#include "avformat.h" #include "avformat.h"
#include "rawdec.h" #include "rawdec.h"
#include "id3v2.h"
#include "id3v1.h" #include "id3v1.h"
@ -36,9 +35,6 @@ static int adts_aac_probe(AVProbeData *p)
uint8_t *buf; uint8_t *buf;
uint8_t *end = buf0 + p->buf_size - 7; uint8_t *end = buf0 + p->buf_size - 7;
if (ff_id3v2_match(buf0, ID3v2_DEFAULT_MAGIC)) {
buf0 += ff_id3v2_tag_len(buf0);
}
buf = buf0; buf = buf0;
for(; buf < end; buf= buf2+1) { for(; buf < end; buf= buf2+1) {
@ -78,7 +74,6 @@ static int adts_aac_read_header(AVFormatContext *s,
st->need_parsing = AVSTREAM_PARSE_FULL; st->need_parsing = AVSTREAM_PARSE_FULL;
ff_id3v1_read(s); ff_id3v1_read(s);
ff_id3v2_read(s, ID3v2_DEFAULT_MAGIC);
//LCM of all possible ADTS sample rates //LCM of all possible ADTS sample rates
av_set_pts_info(st, 64, 1, 28224000); av_set_pts_info(st, 64, 1, 28224000);

@ -22,14 +22,12 @@
#include "libavcodec/flac.h" #include "libavcodec/flac.h"
#include "avformat.h" #include "avformat.h"
#include "rawdec.h" #include "rawdec.h"
#include "id3v2.h"
#include "oggdec.h" #include "oggdec.h"
#include "vorbiscomment.h" #include "vorbiscomment.h"
static int flac_read_header(AVFormatContext *s, static int flac_read_header(AVFormatContext *s,
AVFormatParameters *ap) AVFormatParameters *ap)
{ {
uint8_t buf[ID3v2_HEADER_SIZE];
int ret, metadata_last=0, metadata_type, metadata_size, found_streaminfo=0; int ret, metadata_last=0, metadata_type, metadata_size, found_streaminfo=0;
uint8_t header[4]; uint8_t header[4];
uint8_t *buffer=NULL; uint8_t *buffer=NULL;
@ -41,15 +39,6 @@ static int flac_read_header(AVFormatContext *s,
st->need_parsing = AVSTREAM_PARSE_FULL; st->need_parsing = AVSTREAM_PARSE_FULL;
/* the parameters will be extracted from the compressed bitstream */ /* 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 fLaC marker is not found, assume there is no header */
if (get_le32(s->pb) != MKTAG('f','L','a','C')) { if (get_le32(s->pb) != MKTAG('f','L','a','C')) {
url_fseek(s->pb, -4, SEEK_CUR); url_fseek(s->pb, -4, SEEK_CUR);
@ -130,9 +119,6 @@ static int flac_probe(AVProbeData *p)
uint8_t *bufptr = p->buf; uint8_t *bufptr = p->buf;
uint8_t *end = p->buf + p->buf_size; 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; if(bufptr > end-4 || memcmp(bufptr, "fLaC", 4)) return 0;
else return AVPROBE_SCORE_MAX/2; else return AVPROBE_SCORE_MAX/2;
} }

@ -42,9 +42,6 @@ static int mp3_read_probe(AVProbeData *p)
AVCodecContext avctx; AVCodecContext avctx;
buf0 = p->buf; 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); end = p->buf + p->buf_size - sizeof(uint32_t);
while(buf0 < end && !*buf0) while(buf0 < end && !*buf0)
buf0++; buf0++;
@ -156,7 +153,6 @@ static int mp3_read_header(AVFormatContext *s,
// lcm of all mp3 sample rates // lcm of all mp3 sample rates
av_set_pts_info(st, 64, 1, 14112000); av_set_pts_info(st, 64, 1, 14112000);
ff_id3v2_read(s, ID3v2_DEFAULT_MAGIC);
off = url_ftell(s->pb); off = url_ftell(s->pb);
if (!av_metadata_get(s->metadata, "", NULL, AV_METADATA_IGNORE_SUFFIX)) if (!av_metadata_get(s->metadata, "", NULL, AV_METADATA_IGNORE_SUFFIX))

@ -21,7 +21,6 @@
#include "libavcodec/get_bits.h" #include "libavcodec/get_bits.h"
#include "avformat.h" #include "avformat.h"
#include "id3v2.h"
#include "apetag.h" #include "apetag.h"
#define MPC_FRAMESIZE 1152 #define MPC_FRAMESIZE 1152
@ -45,10 +44,6 @@ typedef struct {
static int mpc_probe(AVProbeData *p) static int mpc_probe(AVProbeData *p)
{ {
const uint8_t *d = p->buf; 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)) if (d[0] == 'M' && d[1] == 'P' && d[2] == '+' && (d[3] == 0x17 || d[3] == 0x7))
return AVPROBE_SCORE_MAX; return AVPROBE_SCORE_MAX;
return 0; return 0;
@ -58,33 +53,11 @@ static int mpc_read_header(AVFormatContext *s, AVFormatParameters *ap)
{ {
MPCContext *c = s->priv_data; MPCContext *c = s->priv_data;
AVStream *st; 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)){ if(get_le24(s->pb) != MKTAG('M', 'P', '+', 0)){
av_log(s, AV_LOG_ERROR, "Not a Musepack file\n"); av_log(s, AV_LOG_ERROR, "Not a Musepack file\n");
return -1; 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);
}
c->ver = get_byte(s->pb); c->ver = get_byte(s->pb);
if(c->ver != 0x07 && c->ver != 0x17){ if(c->ver != 0x07 && c->ver != 0x17){
av_log(s, AV_LOG_ERROR, "Can demux Musepack SV7, got version %02X\n", c->ver); av_log(s, AV_LOG_ERROR, "Can demux Musepack SV7, got version %02X\n", c->ver);

@ -21,7 +21,6 @@
#include "libavcodec/get_bits.h" #include "libavcodec/get_bits.h"
#include "avformat.h" #include "avformat.h"
#include "id3v2.h"
#include "id3v1.h" #include "id3v1.h"
typedef struct { typedef struct {
@ -32,12 +31,6 @@ static int tta_probe(AVProbeData *p)
{ {
const uint8_t *d = p->buf; 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') if (d[0] == 'T' && d[1] == 'T' && d[2] == 'A' && d[3] == '1')
return 80; return 80;
return 0; return 0;
@ -50,7 +43,6 @@ static int tta_read_header(AVFormatContext *s, AVFormatParameters *ap)
int i, channels, bps, samplerate, datalen, framelen; int i, channels, bps, samplerate, datalen, framelen;
uint64_t framepos, start_offset; uint64_t framepos, start_offset;
ff_id3v2_read(s, ID3v2_DEFAULT_MAGIC);
if (!av_metadata_get(s->metadata, "", NULL, AV_METADATA_IGNORE_SUFFIX)) if (!av_metadata_get(s->metadata, "", NULL, AV_METADATA_IGNORE_SUFFIX))
ff_id3v1_read(s); ff_id3v1_read(s);

@ -23,6 +23,7 @@
#include "libavcodec/internal.h" #include "libavcodec/internal.h"
#include "libavutil/opt.h" #include "libavutil/opt.h"
#include "metadata.h" #include "metadata.h"
#include "id3v2.h"
#include "libavutil/avstring.h" #include "libavutil/avstring.h"
#include "riff.h" #include "riff.h"
#include "audiointerleave.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) AVInputFormat *av_probe_input_format2(AVProbeData *pd, int is_opened, int *score_max)
{ {
AVProbeData lpd = *pd;
AVInputFormat *fmt1, *fmt; AVInputFormat *fmt1, *fmt;
int score; 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; fmt = NULL;
for(fmt1 = first_iformat; fmt1 != NULL; fmt1 = fmt1->next) { for(fmt1 = first_iformat; fmt1 != NULL; fmt1 = fmt1->next) {
if (!is_opened == !(fmt1->flags & AVFMT_NOFILE)) if (!is_opened == !(fmt1->flags & AVFMT_NOFILE))
continue; continue;
score = 0; score = 0;
if (fmt1->read_probe) { if (fmt1->read_probe) {
score = fmt1->read_probe(pd); score = fmt1->read_probe(&lpd);
} else if (fmt1->extensions) { } else if (fmt1->extensions) {
if (av_match_ext(pd->filename, fmt1->extensions)) { if (av_match_ext(lpd.filename, fmt1->extensions)) {
score = 50; score = 50;
} }
} }
@ -448,6 +458,10 @@ int av_open_input_stream(AVFormatContext **ic_ptr,
ic->priv_data = NULL; 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) { if (ic->iformat->read_header) {
err = ic->iformat->read_header(ic, ap); err = ic->iformat->read_header(ic, ap);
if (err < 0) if (err < 0)

Loading…
Cancel
Save