[FFmpeg-cvslog] r25378 - in trunk/libavformat: aacdec.c flacdec.c mp3.c mpc.c tta.c utils.c

reimar subversion
Wed Oct 6 22:21:07 CEST 2010


Author: reimar
Date: Wed Oct  6 22:21:07 2010
New Revision: 25378

Log:
Move handling of ID3v2 to common utils.c code, reducing code duplication
and supporting it for more formats, fixing issue 2258.

Modified:
   trunk/libavformat/aacdec.c
   trunk/libavformat/flacdec.c
   trunk/libavformat/mp3.c
   trunk/libavformat/mpc.c
   trunk/libavformat/tta.c
   trunk/libavformat/utils.c

Modified: trunk/libavformat/aacdec.c
==============================================================================
--- trunk/libavformat/aacdec.c	Wed Oct  6 20:54:10 2010	(r25377)
+++ trunk/libavformat/aacdec.c	Wed Oct  6 22:21:07 2010	(r25378)
@@ -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(AVFormat
     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);

Modified: trunk/libavformat/flacdec.c
==============================================================================
--- trunk/libavformat/flacdec.c	Wed Oct  6 20:54:10 2010	(r25377)
+++ trunk/libavformat/flacdec.c	Wed Oct  6 22:21:07 2010	(r25378)
@@ -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(AVFormatCont
     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;
 }

Modified: trunk/libavformat/mp3.c
==============================================================================
--- trunk/libavformat/mp3.c	Wed Oct  6 20:54:10 2010	(r25377)
+++ trunk/libavformat/mp3.c	Wed Oct  6 22:21:07 2010	(r25378)
@@ -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(AVFormatConte
     // 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))

Modified: trunk/libavformat/mpc.c
==============================================================================
--- trunk/libavformat/mpc.c	Wed Oct  6 20:54:10 2010	(r25377)
+++ trunk/libavformat/mpc.c	Wed Oct  6 22:21:07 2010	(r25378)
@@ -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(AVFormatConte
 {
     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){

Modified: trunk/libavformat/tta.c
==============================================================================
--- trunk/libavformat/tta.c	Wed Oct  6 20:54:10 2010	(r25377)
+++ trunk/libavformat/tta.c	Wed Oct  6 22:21:07 2010	(r25378)
@@ -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(AVFormatConte
     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);
 

Modified: trunk/libavformat/utils.c
==============================================================================
--- trunk/libavformat/utils.c	Wed Oct  6 20:54:10 2010	(r25377)
+++ trunk/libavformat/utils.c	Wed Oct  6 22:21:07 2010	(r25378)
@@ -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 *
 
 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->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)



More information about the ffmpeg-cvslog mailing list