]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/oggparsevorbis.c
asm: Consistently uppercase SECTION markers
[ffmpeg] / libavformat / oggparsevorbis.c
index 27f04bf2618f59cbe3b85acce3b13ed9ce468b13..95fe082949c71b78df69c2987e4dc1298752af69 100644 (file)
 #include "libavutil/base64.h"
 #include "libavutil/bswap.h"
 #include "libavutil/dict.h"
+
 #include "libavcodec/bytestream.h"
-#include "libavcodec/get_bits.h"
 #include "libavcodec/vorbis_parser.h"
+
 #include "avformat.h"
 #include "flac_picture.h"
 #include "internal.h"
@@ -208,7 +209,7 @@ int ff_vorbis_comment(AVFormatContext *as, AVDictionary **m,
 struct oggvorbis_private {
     unsigned int len[3];
     unsigned char *packet[3];
-    AVVorbisParseContext vp;
+    AVVorbisParseContext *vp;
     int64_t final_pts;
     int final_duration;
 };
@@ -234,7 +235,7 @@ static int fixup_vorbis_headers(AVFormatContext *as,
         offset += priv->len[i];
         av_freep(&priv->packet[i]);
     }
-    if ((err = av_reallocp(buf, offset + FF_INPUT_BUFFER_PADDING_SIZE)) < 0)
+    if ((err = av_reallocp(buf, offset + AV_INPUT_BUFFER_PADDING_SIZE)) < 0)
         return err;
     return offset;
 }
@@ -245,9 +246,11 @@ static void vorbis_cleanup(AVFormatContext *s, int idx)
     struct ogg_stream *os = ogg->streams + idx;
     struct oggvorbis_private *priv = os->private;
     int i;
-    if (os->private)
+    if (os->private) {
+        av_vorbis_parse_free(&priv->vp);
         for (i = 0; i < 3; i++)
             av_freep(&priv->packet[i]);
+    }
 }
 
 static int vorbis_header(AVFormatContext *s, int idx)
@@ -293,10 +296,10 @@ static int vorbis_header(AVFormatContext *s, int idx)
         if (bytestream_get_le32(&p) != 0) /* vorbis_version */
             return AVERROR_INVALIDDATA;
 
-        st->codec->channels = bytestream_get_byte(&p);
+        st->codecpar->channels = bytestream_get_byte(&p);
         srate               = bytestream_get_le32(&p);
         p += 4; // skip maximum bitrate
-        st->codec->bit_rate = bytestream_get_le32(&p); // nominal bitrate
+        st->codecpar->bit_rate = bytestream_get_le32(&p); // nominal bitrate
         p += 4; // skip minimum bitrate
 
         blocksize = bytestream_get_byte(&p);
@@ -311,11 +314,11 @@ static int vorbis_header(AVFormatContext *s, int idx)
         if (bytestream_get_byte(&p) != 1) /* framing_flag */
             return AVERROR_INVALIDDATA;
 
-        st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
-        st->codec->codec_id   = AV_CODEC_ID_VORBIS;
+        st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
+        st->codecpar->codec_id   = AV_CODEC_ID_VORBIS;
 
         if (srate > 0) {
-            st->codec->sample_rate = srate;
+            st->codecpar->sample_rate = srate;
             avpriv_set_pts_info(st, 64, 1, srate);
         }
     } else if (os->buf[os->pstart] == 3) {
@@ -337,15 +340,17 @@ static int vorbis_header(AVFormatContext *s, int idx)
             }
         }
     } else {
-        int ret = fixup_vorbis_headers(s, priv, &st->codec->extradata);
+        int ret = fixup_vorbis_headers(s, priv, &st->codecpar->extradata);
         if (ret < 0) {
-            st->codec->extradata_size = 0;
+            st->codecpar->extradata_size = 0;
             return ret;
         }
-        st->codec->extradata_size = ret;
-        if ((ret = avpriv_vorbis_parse_extradata(st->codec, &priv->vp))) {
-            av_freep(&st->codec->extradata);
-            st->codec->extradata_size = 0;
+        st->codecpar->extradata_size = ret;
+
+        priv->vp = av_vorbis_parse_init(st->codecpar->extradata, st->codecpar->extradata_size);
+        if (!priv->vp) {
+            av_freep(&st->codecpar->extradata);
+            st->codecpar->extradata_size = 0;
             return ret;
         }
     }
@@ -360,6 +365,9 @@ static int vorbis_packet(AVFormatContext *s, int idx)
     struct oggvorbis_private *priv = os->private;
     int duration;
 
+    if (!priv->vp)
+        return AVERROR_INVALIDDATA;
+
     /* first packet handling
      * here we parse the duration of each packet in the first page and compare
      * the total duration to the page granule to find the encoder delay and
@@ -370,11 +378,11 @@ static int vorbis_packet(AVFormatContext *s, int idx)
         uint8_t *next_pkt  = last_pkt;
         int first_duration = 0;
 
-        avpriv_vorbis_parse_reset(&priv->vp);
+        av_vorbis_parse_reset(priv->vp);
         duration = 0;
         for (seg = 0; seg < os->nsegs; seg++) {
             if (os->segments[seg] < 255) {
-                int d = avpriv_vorbis_parse_frame(&priv->vp, last_pkt, 1);
+                int d = av_vorbis_parse_frame(priv->vp, last_pkt, 1);
                 if (d < 0) {
                     duration = os->granule;
                     break;
@@ -393,12 +401,12 @@ static int vorbis_packet(AVFormatContext *s, int idx)
             s->streams[idx]->duration -= s->streams[idx]->start_time;
         s->streams[idx]->cur_dts = AV_NOPTS_VALUE;
         priv->final_pts          = AV_NOPTS_VALUE;
-        avpriv_vorbis_parse_reset(&priv->vp);
+        av_vorbis_parse_reset(priv->vp);
     }
 
     /* parse packet duration */
     if (os->psize > 0) {
-        duration = avpriv_vorbis_parse_frame(&priv->vp, os->buf + os->pstart, 1);
+        duration = av_vorbis_parse_frame(priv->vp, os->buf + os->pstart, 1);
         if (duration <= 0) {
             os->pflags |= AV_PKT_FLAG_CORRUPT;
             return 0;