#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",
.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 */
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;
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];
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;
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;
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)
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:
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 */