28#include "config_components.h"
39 .class_name =
"Vorbis parser",
45 const uint8_t *buf,
int buf_size)
60 if (memcmp(&buf[1],
"vorbis", 6)) {
65 if (!(buf[29] & 0x1)) {
70 s->blocksize[0] = 1 << (buf[28] & 0xF);
71 s->blocksize[1] = 1 << (buf[28] >> 4);
77 const uint8_t *buf,
int buf_size)
82 int got_framing_bit, mode_count, got_mode_header, last_mode_count = 0;
97 if (memcmp(&buf[1],
"vorbis", 6)) {
107 for (
i = 0;
i < buf_size;
i++)
108 rev_buf[
i] = buf[buf_size - 1 -
i];
118 if (!got_framing_bit) {
140 if (
get_bits(&gb0, 6) + 1 == mode_count) {
142 last_mode_count = mode_count;
145 if (!got_mode_header) {
154 if (last_mode_count > 2) {
156 "%d modes (either a false positive or a "
157 "sample from an unknown encoder)",
162 if (last_mode_count > 63) {
168 s->mode_count = mode_count = last_mode_count;
171 s->mode_mask = ((1 << (
av_log2(mode_count - 1) + 1)) - 1) << 1;
173 s->prev_mask = (
s->mode_mask | 0x1) + 1;
177 for (
i = mode_count - 1;
i >= 0;
i--) {
188 const uint8_t *extradata,
int extradata_size)
190 const uint8_t *header_start[3];
195 s->extradata_parsed = 1;
199 header_start, header_len)) < 0) {
210 s->valid_extradata = 1;
211 s->previous_blocksize =
s->blocksize[
s->mode_blocksize[0]];
217 int buf_size,
int *
flags)
221 if (
s->valid_extradata && buf_size > 0) {
222 int mode, current_blocksize;
223 int previous_blocksize =
s->previous_blocksize;
233 else if (buf[0] == 3)
235 else if (buf[0] == 5)
248 if (
s->mode_count == 1)
251 mode = (buf[0] &
s->mode_mask) >> 1;
252 if (
mode >=
s->mode_count) {
256 if(
s->mode_blocksize[
mode]){
257 int flag = !!(buf[0] &
s->prev_mask);
258 previous_blocksize =
s->blocksize[
flag];
260 current_blocksize =
s->blocksize[
s->mode_blocksize[
mode]];
261 duration = (previous_blocksize + current_blocksize) >> 2;
262 s->previous_blocksize = current_blocksize;
276 if (
s->valid_extradata)
277 s->previous_blocksize =
s->blocksize[0];
303#if CONFIG_VORBIS_PARSER
306 const uint8_t **poutbuf,
int *poutbuf_size,
307 const uint8_t *buf,
int buf_size)
315 if (!
s->valid_extradata)
325 *poutbuf_size = buf_size;
332 .
parse = vorbis_parse,
static int parse(AVCodecParserContext *s, AVCodecContext *avctx, const uint8_t **poutbuf, int *poutbuf_size, const uint8_t *buf, int buf_size)
#define flags(name, subs,...)
#define i(width, name, range_min, range_max)
bitstream reader API header.
static int get_bits_left(GetBitContext *gb)
static void skip_bits_long(GetBitContext *s, int n)
Skips the specified number of bits.
static unsigned int get_bits1(GetBitContext *s)
static void skip_bits(GetBitContext *s, int n)
static int get_bits_count(const GetBitContext *s)
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AV_LOG_VERBOSE
Detailed information.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
const char * av_default_item_name(void *ptr)
Return the context name.
#define LIBAVUTIL_VERSION_INT
Memory handling functions.
#define PARSER_CODEC_LIST(...)
const FFCodecParser ff_vorbis_parser
Describe the class of an AVClass context structure.
main external API structure.
uint8_t * extradata
Out-of-band global headers that may be used by some codecs.
int duration
Duration of the current frame.
#define avpriv_request_sample(...)
void av_vorbis_parse_free(AVVorbisParseContext **s)
Free the parser and everything associated with it.
int av_vorbis_parse_frame_flags(AVVorbisParseContext *s, const uint8_t *buf, int buf_size, int *flags)
Get the duration for a Vorbis packet.
static const AVClass vorbis_parser_class
int av_vorbis_parse_frame(AVVorbisParseContext *s, const uint8_t *buf, int buf_size)
Get the duration for a Vorbis packet.
int ff_vorbis_parse_init(AVVorbisParseContext *s, const uint8_t *extradata, int extradata_size)
static int parse_id_header(AVVorbisParseContext *s, const uint8_t *buf, int buf_size)
AVVorbisParseContext * av_vorbis_parse_init(const uint8_t *extradata, int extradata_size)
Allocate and initialize the Vorbis parser using headers in the extradata.
void av_vorbis_parse_reset(AVVorbisParseContext *s)
static int parse_setup_header(AVVorbisParseContext *s, const uint8_t *buf, int buf_size)
#define VORBIS_FLAG_SETUP
#define VORBIS_FLAG_COMMENT
#define VORBIS_FLAG_HEADER
int avpriv_split_xiph_headers(const uint8_t *extradata, int extradata_size, int first_header_size, const uint8_t *header_start[3], int header_len[3])
Split a single extradata buffer into the three headers that most Xiph codecs use.