lavc: add a public API for parsing vorbis packets.

It is required by (at least) the ogg demuxer.

Mark the current semi-public apriv API for removal.
pull/94/head
Anton Khirnov 10 years ago
parent 6896f95b24
commit 5e80fb7ff2
  1. 3
      doc/APIchanges
  2. 12
      libavcodec/Makefile
  3. 2
      libavcodec/libvorbis.c
  4. 4
      libavcodec/version.h
  5. 54
      libavcodec/vorbis_parser.c
  6. 42
      libavcodec/vorbis_parser.h
  7. 71
      libavcodec/vorbis_parser_internal.h
  8. 2
      libavformat/oggparsevorbis.c

@ -13,6 +13,9 @@ libavutil: 2014-08-09
API changes, most recent first: API changes, most recent first:
2014-11-xx - xxxxxxx - lavc 56.6.0 - vorbis_parser.h
Add a public API for parsing vorbis packets.
2014-10-xx - xxxxxxx - lavu 54.5.0 - time.h 2014-10-xx - xxxxxxx - lavu 54.5.0 - time.h
Add av_gettime_relative(). Add av_gettime_relative().

@ -8,6 +8,7 @@ HEADERS = avcodec.h \
vda.h \ vda.h \
vdpau.h \ vdpau.h \
version.h \ version.h \
vorbis_parser.h \
xvmc.h \ xvmc.h \
OBJS = allcodecs.o \ OBJS = allcodecs.o \
@ -25,6 +26,7 @@ OBJS = allcodecs.o \
parser.o \ parser.o \
raw.o \ raw.o \
utils.o \ utils.o \
vorbis_parser.o \
# subsystems # subsystems
OBJS-$(CONFIG_AANDCTTABLES) += aandcttab.o OBJS-$(CONFIG_AANDCTTABLES) += aandcttab.o
@ -566,7 +568,7 @@ OBJS-$(CONFIG_ADTS_MUXER) += mpeg4audio.o
OBJS-$(CONFIG_CAF_DEMUXER) += mpeg4audio.o mpegaudiodata.o \ OBJS-$(CONFIG_CAF_DEMUXER) += mpeg4audio.o mpegaudiodata.o \
ac3tab.o ac3tab.o
OBJS-$(CONFIG_FLAC_DEMUXER) += flac.o flacdata.o \ OBJS-$(CONFIG_FLAC_DEMUXER) += flac.o flacdata.o \
vorbis_parser.o xiph.o xiph.o
OBJS-$(CONFIG_FLAC_MUXER) += flac.o flacdata.o OBJS-$(CONFIG_FLAC_MUXER) += flac.o flacdata.o
OBJS-$(CONFIG_FLV_DEMUXER) += mpeg4audio.o OBJS-$(CONFIG_FLV_DEMUXER) += mpeg4audio.o
OBJS-$(CONFIG_GXF_DEMUXER) += mpeg12data.o OBJS-$(CONFIG_GXF_DEMUXER) += mpeg12data.o
@ -576,7 +578,7 @@ OBJS-$(CONFIG_LATM_MUXER) += mpeg4audio.o
OBJS-$(CONFIG_MATROSKA_AUDIO_MUXER) += xiph.o mpeg4audio.o \ OBJS-$(CONFIG_MATROSKA_AUDIO_MUXER) += xiph.o mpeg4audio.o \
flac.o flacdata.o flac.o flacdata.o
OBJS-$(CONFIG_MATROSKA_DEMUXER) += mpeg4audio.o mpegaudiodata.o \ OBJS-$(CONFIG_MATROSKA_DEMUXER) += mpeg4audio.o mpegaudiodata.o \
vorbis_parser.o xiph.o xiph.o
OBJS-$(CONFIG_MATROSKA_MUXER) += mpeg4audio.o mpegaudiodata.o \ OBJS-$(CONFIG_MATROSKA_MUXER) += mpeg4audio.o mpegaudiodata.o \
flac.o flacdata.o xiph.o flac.o flacdata.o xiph.o
OBJS-$(CONFIG_MP2_MUXER) += mpegaudiodata.o mpegaudiodecheader.o OBJS-$(CONFIG_MP2_MUXER) += mpegaudiodata.o mpegaudiodecheader.o
@ -587,7 +589,7 @@ OBJS-$(CONFIG_MPEGTS_MUXER) += mpeg4audio.o
OBJS-$(CONFIG_MPEGTS_DEMUXER) += mpeg4audio.o mpegaudiodata.o OBJS-$(CONFIG_MPEGTS_DEMUXER) += mpeg4audio.o mpegaudiodata.o
OBJS-$(CONFIG_NUT_MUXER) += mpegaudiodata.o OBJS-$(CONFIG_NUT_MUXER) += mpegaudiodata.o
OBJS-$(CONFIG_OGG_DEMUXER) += xiph.o flac.o flacdata.o \ OBJS-$(CONFIG_OGG_DEMUXER) += xiph.o flac.o flacdata.o \
mpeg12data.o vorbis_parser.o \ mpeg12data.o \
dirac.o dirac.o
OBJS-$(CONFIG_OGG_MUXER) += xiph.o flac.o flacdata.o OBJS-$(CONFIG_OGG_MUXER) += xiph.o flac.o flacdata.o
OBJS-$(CONFIG_RTP_MUXER) += mpeg4audio.o xiph.o OBJS-$(CONFIG_RTP_MUXER) += mpeg4audio.o xiph.o
@ -630,7 +632,7 @@ OBJS-$(CONFIG_LIBTWOLAME_ENCODER) += libtwolame.o
OBJS-$(CONFIG_LIBVO_AACENC_ENCODER) += libvo-aacenc.o mpeg4audio.o OBJS-$(CONFIG_LIBVO_AACENC_ENCODER) += libvo-aacenc.o mpeg4audio.o
OBJS-$(CONFIG_LIBVO_AMRWBENC_ENCODER) += libvo-amrwbenc.o OBJS-$(CONFIG_LIBVO_AMRWBENC_ENCODER) += libvo-amrwbenc.o
OBJS-$(CONFIG_LIBVORBIS_ENCODER) += libvorbis.o \ OBJS-$(CONFIG_LIBVORBIS_ENCODER) += libvorbis.o \
vorbis_data.o vorbis_parser.o vorbis_data.o
OBJS-$(CONFIG_LIBVPX_VP8_DECODER) += libvpxdec.o OBJS-$(CONFIG_LIBVPX_VP8_DECODER) += libvpxdec.o
OBJS-$(CONFIG_LIBVPX_VP8_ENCODER) += libvpxenc.o OBJS-$(CONFIG_LIBVPX_VP8_ENCODER) += libvpxenc.o
OBJS-$(CONFIG_LIBVPX_VP9_DECODER) += libvpxdec.o libvpx.o OBJS-$(CONFIG_LIBVPX_VP9_DECODER) += libvpxdec.o libvpx.o
@ -681,7 +683,7 @@ OBJS-$(CONFIG_TAK_PARSER) += tak_parser.o tak.o
OBJS-$(CONFIG_VC1_PARSER) += vc1_parser.o vc1.o vc1data.o vc1dsp.o \ OBJS-$(CONFIG_VC1_PARSER) += vc1_parser.o vc1.o vc1data.o vc1dsp.o \
msmpeg4.o msmpeg4data.o mpeg4video.o \ msmpeg4.o msmpeg4data.o mpeg4video.o \
h263.o h263.o
OBJS-$(CONFIG_VORBIS_PARSER) += vorbis_parser.o xiph.o OBJS-$(CONFIG_VORBIS_PARSER) += xiph.o
OBJS-$(CONFIG_VP3_PARSER) += vp3_parser.o OBJS-$(CONFIG_VP3_PARSER) += vp3_parser.o
OBJS-$(CONFIG_VP8_PARSER) += vp8_parser.o OBJS-$(CONFIG_VP8_PARSER) += vp8_parser.o

@ -33,7 +33,7 @@
#include "bytestream.h" #include "bytestream.h"
#include "internal.h" #include "internal.h"
#include "vorbis.h" #include "vorbis.h"
#include "vorbis_parser.h" #include "vorbis_parser_internal.h"
#undef NDEBUG #undef NDEBUG
#include <assert.h> #include <assert.h>

@ -29,8 +29,8 @@
#include "libavutil/version.h" #include "libavutil/version.h"
#define LIBAVCODEC_VERSION_MAJOR 56 #define LIBAVCODEC_VERSION_MAJOR 56
#define LIBAVCODEC_VERSION_MINOR 5 #define LIBAVCODEC_VERSION_MINOR 6
#define LIBAVCODEC_VERSION_MICRO 2 #define LIBAVCODEC_VERSION_MICRO 0
#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
LIBAVCODEC_VERSION_MINOR, \ LIBAVCODEC_VERSION_MINOR, \

@ -30,7 +30,7 @@
#include "get_bits.h" #include "get_bits.h"
#include "parser.h" #include "parser.h"
#include "xiph.h" #include "xiph.h"
#include "vorbis_parser.h" #include "vorbis_parser_internal.h"
static const AVClass vorbis_parser_class = { static const AVClass vorbis_parser_class = {
.class_name = "Vorbis parser", .class_name = "Vorbis parser",
@ -181,7 +181,8 @@ bad_header:
return ret; return ret;
} }
int avpriv_vorbis_parse_extradata(AVCodecContext *avctx, AVVorbisParseContext *s) static int vorbis_parse_init(AVVorbisParseContext *s,
const uint8_t *extradata, int extradata_size)
{ {
uint8_t *header_start[3]; uint8_t *header_start[3];
int header_len[3]; int header_len[3];
@ -190,8 +191,8 @@ int avpriv_vorbis_parse_extradata(AVCodecContext *avctx, AVVorbisParseContext *s
s->class = &vorbis_parser_class; s->class = &vorbis_parser_class;
s->extradata_parsed = 1; s->extradata_parsed = 1;
if ((ret = avpriv_split_xiph_headers(avctx->extradata, if ((ret = avpriv_split_xiph_headers(extradata,
avctx->extradata_size, 30, extradata_size, 30,
header_start, header_len)) < 0) { header_start, header_len)) < 0) {
av_log(s, AV_LOG_ERROR, "Extradata corrupt.\n"); av_log(s, AV_LOG_ERROR, "Extradata corrupt.\n");
return ret; return ret;
@ -209,8 +210,8 @@ int avpriv_vorbis_parse_extradata(AVCodecContext *avctx, AVVorbisParseContext *s
return 0; return 0;
} }
int avpriv_vorbis_parse_frame(AVVorbisParseContext *s, const uint8_t *buf, int av_vorbis_parse_frame(AVVorbisParseContext *s, const uint8_t *buf,
int buf_size) int buf_size)
{ {
int duration = 0; int duration = 0;
@ -242,12 +243,51 @@ int avpriv_vorbis_parse_frame(AVVorbisParseContext *s, const uint8_t *buf,
return duration; return duration;
} }
void avpriv_vorbis_parse_reset(AVVorbisParseContext *s) void av_vorbis_parse_reset(AVVorbisParseContext *s)
{ {
if (s->valid_extradata) if (s->valid_extradata)
s->previous_blocksize = s->mode_blocksize[0]; 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 #if CONFIG_VORBIS_PARSER
static int vorbis_parse(AVCodecParserContext *s1, AVCodecContext *avctx, static int vorbis_parse(AVCodecParserContext *s1, AVCodecContext *avctx,
const uint8_t **poutbuf, int *poutbuf_size, const uint8_t **poutbuf, int *poutbuf_size,

@ -1,5 +1,4 @@
/* /*
* Copyright (c) 2012 Justin Ruggles
* *
* This file is part of Libav. * This file is part of Libav.
* *
@ -20,49 +19,40 @@
/** /**
* @file * @file
* Vorbis audio parser * A public API for Vorbis parsing
* *
* Determines the duration for each packet. * Determines the duration for each packet.
*/ */
#ifndef AVCODEC_VORBIS_PARSER_H #ifndef AVCODEC_VORBIS_PARSE_H
#define AVCODEC_VORBIS_PARSER_H #define AVCODEC_VORBIS_PARSE_H
#include "avcodec.h" typedef struct AVVorbisParseContext AVVorbisParseContext;
typedef struct AVVorbisParseContext {
const AVClass *class;
int extradata_parsed; ///< we have attempted to parse extradata
int valid_extradata; ///< extradata is valid, so we can calculate duration
int blocksize[2]; ///< short and long window sizes
int previous_blocksize; ///< previous window size
int mode_blocksize[64]; ///< window size mapping for each mode
int mode_count; ///< number of modes
int mode_mask; ///< bitmask used to get the mode in each packet
int prev_mask; ///< bitmask used to get the previous mode flag in each packet
} AVVorbisParseContext;
/** /**
* Initialize the Vorbis parser using headers in the extradata. * Allocate and initialize the Vorbis parser using headers in the extradata.
* *
* @param avctx codec context * @param avctx codec context
* @param s Vorbis parser context * @param s Vorbis parser context
*/ */
int avpriv_vorbis_parse_extradata(AVCodecContext *avctx, AVVorbisParseContext *s); AVVorbisParseContext *av_vorbis_parse_init(const uint8_t *extradata,
int extradata_size);
/**
* Free the parser and everything associated with it.
*/
void av_vorbis_parse_free(AVVorbisParseContext **s);
/** /**
* Get the duration for a Vorbis packet. * Get the duration for a Vorbis packet.
* *
* avpriv_vorbis_parse_extradata() must have been successfully called prior to
* this in order for a correct duration to be returned.
*
* @param s Vorbis parser context * @param s Vorbis parser context
* @param buf buffer containing a Vorbis frame * @param buf buffer containing a Vorbis frame
* @param buf_size size of the buffer * @param buf_size size of the buffer
*/ */
int avpriv_vorbis_parse_frame(AVVorbisParseContext *s, const uint8_t *buf, int av_vorbis_parse_frame(AVVorbisParseContext *s, const uint8_t *buf,
int buf_size); int buf_size);
void avpriv_vorbis_parse_reset(AVVorbisParseContext *s); void av_vorbis_parse_reset(AVVorbisParseContext *s);
#endif /* AVCODEC_VORBIS_PARSER_H */ #endif /* AVCODEC_VORBIS_PARSE_H */

@ -0,0 +1,71 @@
/*
* Copyright (c) 2012 Justin Ruggles
*
* This file is part of Libav.
*
* Libav is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* Libav is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with Libav; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @file
* Vorbis audio parser
*
* Determines the duration for each packet.
*/
#ifndef AVCODEC_VORBIS_PARSER_H
#define AVCODEC_VORBIS_PARSER_H
#include "avcodec.h"
#include "vorbis_parser.h"
struct AVVorbisParseContext {
const AVClass *class;
int extradata_parsed; ///< we have attempted to parse extradata
int valid_extradata; ///< extradata is valid, so we can calculate duration
int blocksize[2]; ///< short and long window sizes
int previous_blocksize; ///< previous window size
int mode_blocksize[64]; ///< window size mapping for each mode
int mode_count; ///< number of modes
int mode_mask; ///< bitmask used to get the mode in each packet
int prev_mask; ///< bitmask used to get the previous mode flag in each packet
};
#if LIBAVCODEC_VERSION_MAJOR < 57
/**
* Initialize the Vorbis parser using headers in the extradata.
*
* @param avctx codec context
* @param s Vorbis parser context
*/
int avpriv_vorbis_parse_extradata(AVCodecContext *avctx, AVVorbisParseContext *s);
/**
* Get the duration for a Vorbis packet.
*
* avpriv_vorbis_parse_extradata() must have been successfully called prior to
* this in order for a correct duration to be returned.
*
* @param s Vorbis parser context
* @param buf buffer containing a Vorbis frame
* @param buf_size size of the buffer
*/
int avpriv_vorbis_parse_frame(AVVorbisParseContext *s, const uint8_t *buf,
int buf_size);
void avpriv_vorbis_parse_reset(AVVorbisParseContext *s);
#endif
#endif /* AVCODEC_VORBIS_PARSER_H */

@ -30,7 +30,7 @@
#include "libavutil/dict.h" #include "libavutil/dict.h"
#include "libavcodec/bytestream.h" #include "libavcodec/bytestream.h"
#include "libavcodec/get_bits.h" #include "libavcodec/get_bits.h"
#include "libavcodec/vorbis_parser.h" #include "libavcodec/vorbis_parser_internal.h"
#include "avformat.h" #include "avformat.h"
#include "flac_picture.h" #include "flac_picture.h"
#include "internal.h" #include "internal.h"

Loading…
Cancel
Save