Commit 505642f1 authored by Michael Niedermayer's avatar Michael Niedermayer Committed by Anton Khirnov

mp3dec: fallback to generic seeking when a TOC is not present

Fixes seeking without a Xing/Info header.

CC: libav-stable@libav.org
Signed-off-by: 's avatarAnton Khirnov <anton@khirnov.net>
parent a0a872d0
...@@ -35,6 +35,10 @@ ...@@ -35,6 +35,10 @@
#define XING_TOC_COUNT 100 #define XING_TOC_COUNT 100
typedef struct MP3DecContext {
int xing_toc;
} MP3DecContext;
/* mp3 read */ /* mp3 read */
static int mp3_read_probe(AVProbeData *p) static int mp3_read_probe(AVProbeData *p)
...@@ -100,6 +104,7 @@ static int mp3_read_probe(AVProbeData *p) ...@@ -100,6 +104,7 @@ static int mp3_read_probe(AVProbeData *p)
static void read_xing_toc(AVFormatContext *s, int64_t filesize, int64_t duration) static void read_xing_toc(AVFormatContext *s, int64_t filesize, int64_t duration)
{ {
int i; int i;
MP3DecContext *mp3 = s->priv_data;
if (!filesize && if (!filesize &&
!(filesize = avio_size(s->pb))) { !(filesize = avio_size(s->pb))) {
...@@ -115,6 +120,7 @@ static void read_xing_toc(AVFormatContext *s, int64_t filesize, int64_t duration ...@@ -115,6 +120,7 @@ static void read_xing_toc(AVFormatContext *s, int64_t filesize, int64_t duration
av_rescale(i, duration, XING_TOC_COUNT), av_rescale(i, duration, XING_TOC_COUNT),
0, 0, AVINDEX_KEYFRAME); 0, 0, AVINDEX_KEYFRAME);
} }
mp3->xing_toc = 1;
} }
/** /**
...@@ -238,11 +244,15 @@ static int mp3_read_packet(AVFormatContext *s, AVPacket *pkt) ...@@ -238,11 +244,15 @@ static int mp3_read_packet(AVFormatContext *s, AVPacket *pkt)
static int mp3_seek(AVFormatContext *s, int stream_index, int64_t timestamp, static int mp3_seek(AVFormatContext *s, int stream_index, int64_t timestamp,
int flags) int flags)
{ {
MP3DecContext *mp3 = s->priv_data;
AVIndexEntry *ie; AVIndexEntry *ie;
AVStream *st = s->streams[0]; AVStream *st = s->streams[0];
int64_t ret = av_index_search_timestamp(st, timestamp, flags); int64_t ret = av_index_search_timestamp(st, timestamp, flags);
uint32_t header = 0; uint32_t header = 0;
if (!mp3->xing_toc)
return AVERROR(ENOSYS);
if (ret < 0) if (ret < 0)
return ret; return ret;
...@@ -270,6 +280,7 @@ AVInputFormat ff_mp3_demuxer = { ...@@ -270,6 +280,7 @@ AVInputFormat ff_mp3_demuxer = {
.read_header = mp3_read_header, .read_header = mp3_read_header,
.read_packet = mp3_read_packet, .read_packet = mp3_read_packet,
.read_seek = mp3_seek, .read_seek = mp3_seek,
.priv_data_size = sizeof(MP3DecContext),
.flags = AVFMT_GENERIC_INDEX, .flags = AVFMT_GENERIC_INDEX,
.extensions = "mp2,mp3,m2a", /* XXX: use probe */ .extensions = "mp2,mp3,m2a", /* XXX: use probe */
}; };
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment