It is required by (at least) the ogg demuxer. Mark the current semi-public apriv API for removal. --- doc/APIchanges | 3 +++ libavcodec/Makefile | 12 ++++++---- libavcodec/version.h | 4 ++-- libavcodec/vorbis_parse.h | 58 ++++++++++++++++++++++++++++++++++++++++++++++ libavcodec/vorbis_parser.c | 52 ++++++++++++++++++++++++++++++++++++----- libavcodec/vorbis_parser.h | 7 ++++-- 6 files changed, 121 insertions(+), 15 deletions(-) create mode 100644 libavcodec/vorbis_parse.h
diff --git a/doc/APIchanges b/doc/APIchanges index ad444e1..c129dd7 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -13,6 +13,9 @@ libavutil: 2014-08-09 API changes, most recent first: +2014-11-xx - xxxxxxx - lavc 56.6.0 - vorbis_parse.h + Add a public API for parsing vorbis packets. + 2014-10-xx - xxxxxxx - lavu 54.5.0 - time.h Add av_gettime_relative(). diff --git a/libavcodec/Makefile b/libavcodec/Makefile index 62e41b8..9c5f123 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -8,6 +8,7 @@ HEADERS = avcodec.h \ vda.h \ vdpau.h \ version.h \ + vorbis_parse.h \ xvmc.h \ OBJS = allcodecs.o \ @@ -25,6 +26,7 @@ OBJS = allcodecs.o \ parser.o \ raw.o \ utils.o \ + vorbis_parser.o \ # subsystems OBJS-$(CONFIG_AANDCTTABLES) += aandcttab.o @@ -566,7 +568,7 @@ OBJS-$(CONFIG_ADTS_MUXER) += mpeg4audio.o OBJS-$(CONFIG_CAF_DEMUXER) += mpeg4audio.o mpegaudiodata.o \ ac3tab.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_FLV_DEMUXER) += mpeg4audio.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 \ flac.o flacdata.o OBJS-$(CONFIG_MATROSKA_DEMUXER) += mpeg4audio.o mpegaudiodata.o \ - vorbis_parser.o xiph.o + xiph.o OBJS-$(CONFIG_MATROSKA_MUXER) += mpeg4audio.o mpegaudiodata.o \ flac.o flacdata.o xiph.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_NUT_MUXER) += mpegaudiodata.o OBJS-$(CONFIG_OGG_DEMUXER) += xiph.o flac.o flacdata.o \ - mpeg12data.o vorbis_parser.o \ + mpeg12data.o \ dirac.o OBJS-$(CONFIG_OGG_MUXER) += xiph.o flac.o flacdata.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_AMRWBENC_ENCODER) += libvo-amrwbenc.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_ENCODER) += libvpxenc.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 \ msmpeg4.o msmpeg4data.o mpeg4video.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_VP8_PARSER) += vp8_parser.o diff --git a/libavcodec/version.h b/libavcodec/version.h index 20c7135..fd774a7 100644 --- a/libavcodec/version.h +++ b/libavcodec/version.h @@ -29,8 +29,8 @@ #include "libavutil/version.h" #define LIBAVCODEC_VERSION_MAJOR 56 -#define LIBAVCODEC_VERSION_MINOR 5 -#define LIBAVCODEC_VERSION_MICRO 2 +#define LIBAVCODEC_VERSION_MINOR 6 +#define LIBAVCODEC_VERSION_MICRO 0 #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ LIBAVCODEC_VERSION_MINOR, \ diff --git a/libavcodec/vorbis_parse.h b/libavcodec/vorbis_parse.h new file mode 100644 index 0000000..7b12900 --- /dev/null +++ b/libavcodec/vorbis_parse.h @@ -0,0 +1,58 @@ +/* + * + * 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 + * A public API for Vorbis parsing + * + * Determines the duration for each packet. + */ + +#ifndef AVCODEC_VORBIS_PARSE_H +#define AVCODEC_VORBIS_PARSE_H + +typedef struct AVVorbisParseContext AVVorbisParseContext; + +/** + * Allocate and initialize the Vorbis parser using headers in the extradata. + * + * @param avctx codec context + * @param s Vorbis parser context + */ +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. + * + * @param s Vorbis parser context + * @param buf buffer containing a Vorbis frame + * @param buf_size size of the buffer + */ +int av_vorbis_parse_frame(AVVorbisParseContext *s, const uint8_t *buf, + int buf_size); + +void av_vorbis_parse_reset(AVVorbisParseContext *s); + +#endif /* AVCODEC_VORBIS_PARSE_H */ diff --git a/libavcodec/vorbis_parser.c b/libavcodec/vorbis_parser.c index b088465..0231e63 100644 --- a/libavcodec/vorbis_parser.c +++ b/libavcodec/vorbis_parser.c @@ -181,7 +181,8 @@ bad_header: 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]; int header_len[3]; @@ -190,8 +191,8 @@ int avpriv_vorbis_parse_extradata(AVCodecContext *avctx, AVVorbisParseContext *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, AVVorbisParseContext *s return 0; } -int avpriv_vorbis_parse_frame(AVVorbisParseContext *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,12 +243,51 @@ int avpriv_vorbis_parse_frame(AVVorbisParseContext *s, const uint8_t *buf, return duration; } -void avpriv_vorbis_parse_reset(AVVorbisParseContext *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 static int vorbis_parse(AVCodecParserContext *s1, AVCodecContext *avctx, const uint8_t **poutbuf, int *poutbuf_size, diff --git a/libavcodec/vorbis_parser.h b/libavcodec/vorbis_parser.h index 414a04b..f9efc71 100644 --- a/libavcodec/vorbis_parser.h +++ b/libavcodec/vorbis_parser.h @@ -29,8 +29,9 @@ #define AVCODEC_VORBIS_PARSER_H #include "avcodec.h" +#include "vorbis_parse.h" -typedef struct AVVorbisParseContext { +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 @@ -40,8 +41,9 @@ typedef struct AVVorbisParseContext { 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; +}; +#if LIBAVCODEC_VERSION_MAJOR < 57 /** * Initialize the Vorbis parser using headers in the extradata. * @@ -64,5 +66,6 @@ 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 */ -- 2.0.0 _______________________________________________ libav-devel mailing list libav-devel@libav.org https://lists.libav.org/mailman/listinfo/libav-devel