summaryrefslogtreecommitdiff
path: root/libavformat/mp3dec.c
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2012-05-08 03:47:58 +0200
committerMichael Niedermayer <michaelni@gmx.at>2012-05-08 03:47:58 +0200
commit7da0a07283e8546c7cf4cde9eca7ad4fe9f57fb4 (patch)
tree82451c6f5607728244a95e88fda28ce4f448dc00 /libavformat/mp3dec.c
parentf46185c289baf8bf98e8970fb0cbb5f6f56c7837 (diff)
downloadffmpeg-7da0a07283e8546c7cf4cde9eca7ad4fe9f57fb4.tar.gz
mp3demux: fix id3 discard code
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavformat/mp3dec.c')
-rw-r--r--libavformat/mp3dec.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/libavformat/mp3dec.c b/libavformat/mp3dec.c
index 8d92aec96e..61405f71b7 100644
--- a/libavformat/mp3dec.c
+++ b/libavformat/mp3dec.c
@@ -29,6 +29,10 @@
#include "id3v1.h"
#include "libavcodec/mpegaudiodecheader.h"
+typedef struct {
+ int64_t filesize;
+} MP3Context;
+
/* mp3 read */
static int mp3_read_probe(AVProbeData *p)
@@ -136,6 +140,7 @@ static int mp3_parse_vbr_tags(AVFormatContext *s, AVStream *st, int64_t base)
static int mp3_read_header(AVFormatContext *s)
{
+ MP3Context *mp3 = s->priv_data;
AVStream *st;
int64_t off;
@@ -157,6 +162,9 @@ static int mp3_read_header(AVFormatContext *s)
if (!av_dict_get(s->metadata, "", NULL, AV_DICT_IGNORE_SUFFIX))
ff_id3v1_read(s);
+ if(s->pb->seekable)
+ mp3->filesize = avio_size(s->pb);
+
if (mp3_parse_vbr_tags(s, st, off) < 0)
avio_seek(s->pb, off, SEEK_SET);
@@ -168,10 +176,15 @@ static int mp3_read_header(AVFormatContext *s)
static int mp3_read_packet(AVFormatContext *s, AVPacket *pkt)
{
+ MP3Context *mp3 = s->priv_data;
int ret, size;
+ int64_t pos;
// AVStream *st = s->streams[0];
size= MP3_PACKET_SIZE;
+ pos = avio_tell(s->pb);
+ if(mp3->filesize > ID3v1_TAG_SIZE && pos < mp3->filesize)
+ size= FFMIN(size, mp3->filesize - pos);
ret= av_get_packet(s->pb, pkt, size);
@@ -196,6 +209,7 @@ static int mp3_read_packet(AVFormatContext *s, AVPacket *pkt)
AVInputFormat ff_mp3_demuxer = {
.name = "mp3",
.long_name = NULL_IF_CONFIG_SMALL("MPEG audio layer 2/3"),
+ .priv_data_size = sizeof(MP3Context),
.read_probe = mp3_read_probe,
.read_header = mp3_read_header,
.read_packet = mp3_read_packet,