]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/vorbis_parser.c
avcodec: rename the AV1 profiles
[ffmpeg] / libavcodec / vorbis_parser.c
index cdca9531713575ab1d3ec085cc46468e132bc9bf..054635d10030c02889bbb906e3ce0f3c5af8da9d 100644 (file)
@@ -30,7 +30,7 @@
 #include "get_bits.h"
 #include "parser.h"
 #include "xiph.h"
-#include "vorbis_parser.h"
+#include "vorbis_parser_internal.h"
 
 static const AVClass vorbis_parser_class = {
     .class_name = "Vorbis parser",
@@ -38,7 +38,7 @@ static const AVClass vorbis_parser_class = {
     .version    = LIBAVUTIL_VERSION_INT,
 };
 
-static int parse_id_header(VorbisParseContext *s,
+static int parse_id_header(AVVorbisParseContext *s,
                            const uint8_t *buf, int buf_size)
 {
     /* Id header should be 30 bytes */
@@ -70,7 +70,7 @@ static int parse_id_header(VorbisParseContext *s,
     return 0;
 }
 
-static int parse_setup_header(VorbisParseContext *s,
+static int parse_setup_header(AVVorbisParseContext *s,
                               const uint8_t *buf, int buf_size)
 {
     GetBitContext gb, gb0;
@@ -181,7 +181,8 @@ bad_header:
     return ret;
 }
 
-int avpriv_vorbis_parse_extradata(AVCodecContext *avctx, VorbisParseContext *s)
+static int vorbis_parse_init(AVVorbisParseContext *s,
+                             const uint8_t *extradata, int extradata_size)
 {
     uint8_t *header_start[3];
     int header_len[3];
@@ -190,8 +191,8 @@ int avpriv_vorbis_parse_extradata(AVCodecContext *avctx, VorbisParseContext *s)
     s->class = &vorbis_parser_class;
     s->extradata_parsed = 1;
 
-    if ((ret = avpriv_split_xiph_headers(avctx->extradata,
-                                         avctx->extradata_size, 30,
+    if ((ret = avpriv_split_xiph_headers(extradata,
+                                         extradata_size, 30,
                                          header_start, header_len)) < 0) {
         av_log(s, AV_LOG_ERROR, "Extradata corrupt.\n");
         return ret;
@@ -209,8 +210,8 @@ int avpriv_vorbis_parse_extradata(AVCodecContext *avctx, VorbisParseContext *s)
     return 0;
 }
 
-int avpriv_vorbis_parse_frame(VorbisParseContext *s, const uint8_t *buf,
-                              int buf_size)
+int av_vorbis_parse_frame(AVVorbisParseContext *s, const uint8_t *buf,
+                          int buf_size)
 {
     int duration = 0;
 
@@ -242,13 +243,57 @@ int avpriv_vorbis_parse_frame(VorbisParseContext *s, const uint8_t *buf,
     return duration;
 }
 
-void avpriv_vorbis_parse_reset(VorbisParseContext *s)
+void av_vorbis_parse_reset(AVVorbisParseContext *s)
 {
     if (s->valid_extradata)
         s->previous_blocksize = s->mode_blocksize[0];
 }
 
+void av_vorbis_parse_free(AVVorbisParseContext **s)
+{
+    av_freep(s);
+}
+
+AVVorbisParseContext *av_vorbis_parse_init(const uint8_t *extradata,
+                                           int extradata_size)
+{
+    AVVorbisParseContext *s = av_mallocz(sizeof(*s));
+    int ret;
+
+    if (!s)
+        return NULL;
+
+    ret = vorbis_parse_init(s, extradata, extradata_size);
+    if (ret < 0) {
+        av_vorbis_parse_free(&s);
+        return NULL;
+    }
+
+    return s;
+}
+
+#if LIBAVCODEC_VERSION_MAJOR < 57
+int avpriv_vorbis_parse_extradata(AVCodecContext *avctx, AVVorbisParseContext *s)
+{
+    return vorbis_parse_init(s, avctx->extradata, avctx->extradata_size);
+}
+void avpriv_vorbis_parse_reset(AVVorbisParseContext *s)
+{
+    av_vorbis_parse_reset(s);
+}
+int avpriv_vorbis_parse_frame(AVVorbisParseContext *s, const uint8_t *buf,
+                              int buf_size)
+{
+    return av_vorbis_parse_frame(s, buf, buf_size);
+}
+#endif
+
 #if CONFIG_VORBIS_PARSER
+
+typedef struct VorbisParseContext {
+    AVVorbisParseContext *vp;
+} VorbisParseContext;
+
 static int vorbis_parse(AVCodecParserContext *s1, AVCodecContext *avctx,
                         const uint8_t **poutbuf, int *poutbuf_size,
                         const uint8_t *buf, int buf_size)
@@ -256,11 +301,13 @@ static int vorbis_parse(AVCodecParserContext *s1, AVCodecContext *avctx,
     VorbisParseContext *s = s1->priv_data;
     int duration;
 
-    if (!s->extradata_parsed && avctx->extradata && avctx->extradata_size)
-        if (avpriv_vorbis_parse_extradata(avctx, s))
-            goto end;
+    if (!s->vp && avctx->extradata && avctx->extradata_size) {
+        s->vp = av_vorbis_parse_init(avctx->extradata, avctx->extradata_size);
+    }
+    if (!s->vp)
+        goto end;
 
-    if ((duration = avpriv_vorbis_parse_frame(s, buf, buf_size)) >= 0)
+    if ((duration = av_vorbis_parse_frame(s->vp, buf, buf_size)) >= 0)
         s1->duration = duration;
 
 end:
@@ -271,9 +318,16 @@ end:
     return buf_size;
 }
 
+static void vorbis_parser_close(AVCodecParserContext *ctx)
+{
+    VorbisParseContext *s = ctx->priv_data;
+    av_vorbis_parse_free(&s->vp);
+}
+
 AVCodecParser ff_vorbis_parser = {
     .codec_ids      = { AV_CODEC_ID_VORBIS },
     .priv_data_size = sizeof(VorbisParseContext),
     .parser_parse   = vorbis_parse,
+    .parser_close   = vorbis_parser_close,
 };
 #endif /* CONFIG_VORBIS_PARSER */