@@ -211,30 +211,30 @@ static int ogg_replace_stream(AVFormatContext *s, uint32_t serial, int size)
struct ogg *ogg = s->priv_data;
struct ogg_stream *os;
const struct ogg_codec *codec;
+ uint8_t magic[8];
int i = 0;
- if (s->pb->seekable & AVIO_SEEKABLE_NORMAL) {
- uint8_t magic[8];
- avio_seek(s->pb, -size, SEEK_CUR);
- if (avio_read(s->pb, magic, sizeof(magic)) != sizeof(magic))
- return AVERROR_INVALIDDATA;
- avio_seek(s->pb, size - sizeof(magic), SEEK_CUR);
- codec = ogg_find_codec(magic, sizeof(magic));
- if (!codec) {
- av_log(s, AV_LOG_ERROR, "Cannot identify new stream\n");
- return AVERROR_INVALIDDATA;
- }
- for (i = 0; i < ogg->nstreams; i++) {
- if (ogg->streams[i].codec == codec)
- break;
- }
- if (i >= ogg->nstreams)
- return ogg_new_stream(s, serial);
- } else if (ogg->nstreams != 1) {
+ if (ogg->nstreams != 1) {
avpriv_report_missing_feature(s, "Changing stream parameters in multistream ogg");
return AVERROR_PATCHWELCOME;
}
+ avio_seek(s->pb, -size, SEEK_CUR);
+ if (avio_read(s->pb, magic, sizeof(magic)) != sizeof(magic))
+ return AVERROR_INVALIDDATA;
+ avio_seek(s->pb, size - sizeof(magic), SEEK_CUR);
+ codec = ogg_find_codec(magic, sizeof(magic));
+ if (!codec) {
+ av_log(s, AV_LOG_ERROR, "Cannot identify new stream\n");
+ return AVERROR_INVALIDDATA;
+ }
+ for (i = 0; i < ogg->nstreams; i++) {
+ if (ogg->streams[i].codec == codec)
+ break;
+ }
+ if (i >= ogg->nstreams)
+ return ogg_new_stream(s, serial);
+
os = &ogg->streams[i];
os->serial = serial;
@@ -410,6 +410,9 @@ static int ogg_read_page(AVFormatContext *s, int *sid)
readout_buf = av_malloc(size);
}
+ /* To rewind if checksum is bad/check magic on switches */
+ ffio_ensure_seekback(bc, size);
+
ret = avio_read(bc, readout_buf, size);
if (ret < size) {
if (idx < 0)
--
2.26.2