Merge commit '5e80fb7ff226f136dbcf3fed00a2966bf8e9bd70'

* commit '5e80fb7ff226f136dbcf3fed00a2966bf8e9bd70':
  lavc: add a public API for parsing vorbis packets.

Conflicts:
	doc/APIchanges
	libavcodec/Makefile
	libavcodec/version.h
	libavcodec/vorbis_parser.c

Merged-by: Michael Niedermayer <michaelni@gmx.at>
pull/94/head
Michael Niedermayer 10 years ago
commit 44fa2671e0
  1. 3
      doc/APIchanges
  2. 14
      libavcodec/Makefile
  3. 2
      libavcodec/libvorbisenc.c
  4. 4
      libavcodec/version.h
  5. 52
      libavcodec/vorbis_parser.c
  6. 40
      libavcodec/vorbis_parser.h
  7. 71
      libavcodec/vorbis_parser_internal.h
  8. 2
      libavformat/oggparsevorbis.c

@ -15,6 +15,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 - lavc 56.5.0 - avcodec.h 2014-10-xx - xxxxxxx - lavc 56.5.0 - avcodec.h
Replace AVCodecContext.time_base used for decoding Replace AVCodecContext.time_base used for decoding
with AVCodecContext.framerate. with AVCodecContext.framerate.

@ -11,6 +11,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 \
@ -31,6 +32,7 @@ OBJS = allcodecs.o \
resample.o \ resample.o \
resample2.o \ resample2.o \
utils.o \ utils.o \
vorbis_parser.o \
# subsystems # subsystems
OBJS-$(CONFIG_AANDCTTABLES) += aandcttab.o OBJS-$(CONFIG_AANDCTTABLES) += aandcttab.o
@ -677,7 +679,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 vorbis_data.o \ OBJS-$(CONFIG_FLAC_DEMUXER) += flac.o flacdata.o vorbis_data.o \
vorbis_parser.o xiph.o xiph.o
OBJS-$(CONFIG_FLAC_MUXER) += flac.o flacdata.o vorbis_data.o OBJS-$(CONFIG_FLAC_MUXER) += flac.o flacdata.o vorbis_data.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
@ -687,7 +689,7 @@ OBJS-$(CONFIG_LATM_MUXER) += mpeg4audio.o
OBJS-$(CONFIG_MATROSKA_AUDIO_MUXER) += xiph.o mpeg4audio.o vorbis_data.o \ OBJS-$(CONFIG_MATROSKA_AUDIO_MUXER) += xiph.o mpeg4audio.o vorbis_data.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 vorbis_data.o xiph.o flac.o flacdata.o vorbis_data.o xiph.o
OBJS-$(CONFIG_MP2_MUXER) += mpegaudiodata.o mpegaudiodecheader.o OBJS-$(CONFIG_MP2_MUXER) += mpegaudiodata.o mpegaudiodecheader.o
@ -700,7 +702,7 @@ OBJS-$(CONFIG_MXF_MUXER) += dnxhddata.o
OBJS-$(CONFIG_NUT_MUXER) += mpegaudiodata.o OBJS-$(CONFIG_NUT_MUXER) += mpegaudiodata.o
OBJS-$(CONFIG_OGA_MUXER) += xiph.o flac.o flacdata.o OBJS-$(CONFIG_OGA_MUXER) += xiph.o flac.o flacdata.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 vorbis_data.o dirac.o vorbis_data.o
OBJS-$(CONFIG_OGG_MUXER) += xiph.o flac.o flacdata.o \ OBJS-$(CONFIG_OGG_MUXER) += xiph.o flac.o flacdata.o \
vorbis_data.o vorbis_data.o
@ -712,7 +714,7 @@ OBJS-$(CONFIG_TAK_DEMUXER) += tak.o
OBJS-$(CONFIG_WEBM_MUXER) += mpeg4audio.o mpegaudiodata.o \ OBJS-$(CONFIG_WEBM_MUXER) += mpeg4audio.o mpegaudiodata.o \
xiph.o flac.o flacdata.o \ xiph.o flac.o flacdata.o \
vorbis_data.o vorbis_data.o
OBJS-$(CONFIG_WEBM_DASH_MANIFEST_DEMUXER) += vorbis_parser.o xiph.o OBJS-$(CONFIG_WEBM_DASH_MANIFEST_DEMUXER) += xiph.o
OBJS-$(CONFIG_WTV_DEMUXER) += mpeg4audio.o mpegaudiodata.o OBJS-$(CONFIG_WTV_DEMUXER) += mpeg4audio.o mpegaudiodata.o
# libavfilter dependencies # libavfilter dependencies
@ -756,7 +758,7 @@ 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_DECODER) += libvorbisdec.o OBJS-$(CONFIG_LIBVORBIS_DECODER) += libvorbisdec.o
OBJS-$(CONFIG_LIBVORBIS_ENCODER) += libvorbisenc.o \ OBJS-$(CONFIG_LIBVORBIS_ENCODER) += libvorbisenc.o \
vorbis_data.o vorbis_parser.o xiph.o vorbis_data.o xiph.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
@ -812,7 +814,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
OBJS-$(CONFIG_VP9_PARSER) += vp9_parser.o OBJS-$(CONFIG_VP9_PARSER) += vp9_parser.o

@ -27,7 +27,7 @@
#include "audio_frame_queue.h" #include "audio_frame_queue.h"
#include "internal.h" #include "internal.h"
#include "vorbis.h" #include "vorbis.h"
#include "vorbis_parser.h" #include "vorbis_parser_internal.h"
/* Number of samples the user should send in each call. /* Number of samples the user should send in each call.

@ -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 10 #define LIBAVCODEC_VERSION_MINOR 11
#define LIBAVCODEC_VERSION_MICRO 102 #define LIBAVCODEC_VERSION_MICRO 100
#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;
@ -258,18 +259,57 @@ bad_packet:
return duration; return duration;
} }
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)
{ {
return avpriv_vorbis_parse_frame_flags(s, buf, buf_size, NULL); return avpriv_vorbis_parse_frame_flags(s, buf, buf_size, NULL);
} }
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->blocksize[0]; s->previous_blocksize = s->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 FFmpeg. * This file is part of FFmpeg.
* *
@ -20,35 +19,29 @@
/** /**
* @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);
#define VORBIS_FLAG_HEADER 0x00000001 #define VORBIS_FLAG_HEADER 0x00000001
#define VORBIS_FLAG_COMMENT 0x00000002 #define VORBIS_FLAG_COMMENT 0x00000002
@ -71,16 +64,13 @@ int avpriv_vorbis_parse_frame_flags(AVVorbisParseContext *s, const uint8_t *buf,
/** /**
* 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 FFmpeg.
*
* FFmpeg 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.
*
* FFmpeg 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 FFmpeg; 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