]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/oggdec.c
avformat: Constify all muxer/demuxers
[ffmpeg] / libavformat / oggdec.c
index b4ba00df61bf17d93e4e51041285151fee9ff193..e5ca3272cd67fe623b9533fc8574e5a434facca9 100644 (file)
@@ -206,7 +206,7 @@ static const struct ogg_codec *ogg_find_codec(uint8_t *buf, int size)
  * situation where a new audio stream spawn (identified with a new serial) and
  * must replace the previous one (track switch).
  */
-static int ogg_replace_stream(AVFormatContext *s, uint32_t serial, char *magic,
+static int ogg_replace_stream(AVFormatContext *s, uint32_t serial, char *magic, int page_size,
                               int probing)
 {
     struct ogg *ogg = s->priv_data;
@@ -220,15 +220,16 @@ static int ogg_replace_stream(AVFormatContext *s, uint32_t serial, char *magic,
     }
 
     /* Check for codecs */
-    codec = ogg_find_codec(magic, 8);
+    codec = ogg_find_codec(magic, page_size);
     if (!codec && !probing) {
         av_log(s, AV_LOG_ERROR, "Cannot identify new stream\n");
         return AVERROR_INVALIDDATA;
     }
 
-    /* We only have a single stream anyway, so if there's a new stream with
-     * a different codec just replace it */
     os = &ogg->streams[0];
+    if (os->codec != codec)
+        return AVERROR(EINVAL);
+
     os->serial  = serial;
     os->codec   = codec;
     os->serial  = serial;
@@ -412,6 +413,7 @@ static int ogg_read_page(AVFormatContext *s, int *sid, int probing)
         if (idx < 0)
             av_free(readout_buf);
         avio_seek(bc, start_pos, SEEK_SET);
+        *sid = -1;
         return 0;
     }
 
@@ -422,13 +424,14 @@ static int ogg_read_page(AVFormatContext *s, int *sid, int probing)
         if (idx < 0)
             av_free(readout_buf);
         avio_seek(bc, start_pos, SEEK_SET);
+        *sid = -1;
         return 0;
     }
 
     /* CRC is correct so we can be 99% sure there's an actual change here */
     if (idx < 0) {
         if (data_packets_seen(ogg))
-            idx = ogg_replace_stream(s, serial, readout_buf, probing);
+            idx = ogg_replace_stream(s, serial, readout_buf, size, probing);
         else
             idx = ogg_new_stream(s, serial);
 
@@ -661,7 +664,7 @@ static int ogg_get_length(AVFormatContext *s)
     ogg->page_pos = -1;
 
     while (!ogg_read_page(s, &i, 1)) {
-        if (ogg->streams[i].granule != -1 && ogg->streams[i].granule != 0 &&
+        if (i >= 0 && ogg->streams[i].granule != -1 && ogg->streams[i].granule != 0 &&
             ogg->streams[i].codec) {
             s->streams[i]->duration =
                 ogg_gptopts(s, i, ogg->streams[i].granule, NULL);
@@ -963,7 +966,7 @@ static int ogg_probe(const AVProbeData *p)
     return 0;
 }
 
-AVInputFormat ff_ogg_demuxer = {
+const AVInputFormat ff_ogg_demuxer = {
     .name           = "ogg",
     .long_name      = NULL_IF_CONFIG_SMALL("Ogg"),
     .priv_data_size = sizeof(struct ogg),