This just cleans up the code and simplifies it.

Patch attached.

>From 401b0d86f38905c647cc591b0bd34662b0953e5c Mon Sep 17 00:00:00 2001
From: Lynne <d...@lynne.ee>
Date: Tue, 28 Apr 2020 12:55:17 +0100
Subject: [PATCH 3/3] oggdec: use ffio_ensure_seekback() to not require seeking
 to read the magic

This just cleans up the code and simplifies it.
---
 libavformat/oggdec.c | 39 +++++++++++++++++++++------------------
 1 file changed, 21 insertions(+), 18 deletions(-)

diff --git a/libavformat/oggdec.c b/libavformat/oggdec.c
index 05cea2528b..88d54dfe12 100644
--- a/libavformat/oggdec.c
+++ b/libavformat/oggdec.c
@@ -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

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Reply via email to