Commit c5cf58d4 authored by Michael Niedermayer's avatar Michael Niedermayer

oggdec: resync from the last page.

Previously we re synced from where we where which cam lead
to loosing pages.
Signed-off-by: 's avatarMichael Niedermayer <michaelni@gmx.at>
parent 778069c8
...@@ -101,6 +101,7 @@ static int ogg_restore(AVFormatContext *s, int discard) ...@@ -101,6 +101,7 @@ static int ogg_restore(AVFormatContext *s, int discard)
av_free(ogg->streams[i].buf); av_free(ogg->streams[i].buf);
avio_seek(bc, ost->pos, SEEK_SET); avio_seek(bc, ost->pos, SEEK_SET);
ogg->page_pos = -1;
ogg->curidx = ost->curidx; ogg->curidx = ost->curidx;
ogg->nstreams = ost->nstreams; ogg->nstreams = ost->nstreams;
ogg->streams = av_realloc(ogg->streams, ogg->streams = av_realloc(ogg->streams,
...@@ -145,6 +146,7 @@ static int ogg_reset(AVFormatContext *s) ...@@ -145,6 +146,7 @@ static int ogg_reset(AVFormatContext *s)
} }
} }
ogg->page_pos = -1;
ogg->curidx = -1; ogg->curidx = -1;
return 0; return 0;
...@@ -296,6 +298,12 @@ static int ogg_read_page(AVFormatContext *s, int *sid) ...@@ -296,6 +298,12 @@ static int ogg_read_page(AVFormatContext *s, int *sid)
sync[(sp + 2) & 3] == 'g' && sync[(sp + 3) & 3] == 'S') sync[(sp + 2) & 3] == 'g' && sync[(sp + 3) & 3] == 'S')
break; break;
if(!i && bc->seekable && ogg->page_pos > 0) {
memset(sync, 0, 4);
avio_seek(bc, ogg->page_pos+4, SEEK_SET);
ogg->page_pos = -1;
}
c = avio_r8(bc); c = avio_r8(bc);
if (url_feof(bc)) if (url_feof(bc))
...@@ -334,6 +342,7 @@ static int ogg_read_page(AVFormatContext *s, int *sid) ...@@ -334,6 +342,7 @@ static int ogg_read_page(AVFormatContext *s, int *sid)
} }
os = ogg->streams + idx; os = ogg->streams + idx;
ogg->page_pos =
os->page_pos = avio_tell(bc) - 27; os->page_pos = avio_tell(bc) - 27;
if (os->psize > 0) if (os->psize > 0)
...@@ -558,6 +567,7 @@ static int ogg_get_length(AVFormatContext *s) ...@@ -558,6 +567,7 @@ static int ogg_get_length(AVFormatContext *s)
ogg_save(s); ogg_save(s);
avio_seek(s->pb, end, SEEK_SET); avio_seek(s->pb, end, SEEK_SET);
ogg->page_pos = -1;
while (!ogg_read_page(s, &i)) { while (!ogg_read_page(s, &i)) {
if (ogg->streams[i].granule != -1 && ogg->streams[i].granule != 0 && if (ogg->streams[i].granule != -1 && ogg->streams[i].granule != 0 &&
......
...@@ -100,6 +100,7 @@ struct ogg { ...@@ -100,6 +100,7 @@ struct ogg {
int nstreams; int nstreams;
int headers; int headers;
int curidx; int curidx;
int64_t page_pos; ///< file offset of the current page
struct ogg_state *state; struct ogg_state *state;
}; };
......
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