21 #include <vorbis/vorbisenc.h>
40 int i, hsizes[3], ret;
41 unsigned char *headers[3], *extradata = avccontext->
extradata;
48 vorbis_info_init(&context->
vi) ;
49 vorbis_comment_init(&context->
vc) ;
51 if(p[0] == 0 && p[1] == 30) {
53 for(
i = 0;
i < 3;
i++){
54 hsizes[
i] = bytestream_get_be16((
const uint8_t **)&p);
55 sizesum += 2 + hsizes[
i];
67 unsigned int sizesum = 1;
71 while((*p == 0xFF) && (sizesum < avccontext->extradata_size)) {
82 "vorbis header sizes damaged\n");
91 "vorbis header sizes: %d, %d, %d, / extradata_len is %d \n",
94 headers[0] = extradata +
offset;
95 headers[1] = extradata +
offset + hsizes[0];
96 headers[2] = extradata +
offset + hsizes[0] + hsizes[1];
99 "vorbis initial header len is wrong: %d\n", *p);
105 context->
op.b_o_s=
i==0;
106 context->
op.bytes = hsizes[
i];
107 context->
op.packet = headers[
i];
108 if(vorbis_synthesis_headerin(&context->
vi, &context->
vc, &context->
op)<0){
120 vorbis_synthesis_init(&context->
vd, &context->
vi);
121 vorbis_block_init(&context->
vd, &context->
vb);
131 static inline int conv(
int samples,
float **pcm,
char *buf,
int channels) {
133 ogg_int16_t *ptr, *
data = (ogg_int16_t*)buf ;
140 for(j = 0 ; j < samples ; j++) {
150 int *got_frame_ptr,
AVPacket *avpkt)
156 int samples, total_samples, total_bytes;
180 if(vorbis_synthesis(&context->
vb,
op) == 0)
181 vorbis_synthesis_blockin(&context->
vd, &context->
vb) ;
186 while((samples = vorbis_synthesis_pcmout(&context->
vd, &pcm)) > 0) {
187 conv(samples, pcm, (
char*)output + total_bytes, context->
vi.channels) ;
188 total_bytes += samples * 2 * context->
vi.channels ;
189 total_samples += samples ;
190 vorbis_synthesis_read(&context->
vd, samples) ;
194 *got_frame_ptr = total_samples > 0;
202 vorbis_block_clear(&context->
vb);
203 vorbis_dsp_clear(&context->
vd);
204 vorbis_info_clear(&context->
vi) ;
205 vorbis_comment_clear(&context->
vc) ;
Libavcodec external API header.
static av_cold int init(AVCodecContext *avctx)
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
#define AV_CODEC_CAP_CHANNEL_CONF
Codec should fill in channel configuration and samplerate instead of container.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
@ AV_SAMPLE_FMT_S16
signed 16 bits
static int op(uint8_t **dst, const uint8_t *dst_end, GetByteContext *gb, int pixel, int count, int *x, int width, int linesize)
Perform decode operation.
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
AVCodec ff_libvorbis_decoder
static int oggvorbis_decode_close(AVCodecContext *avccontext)
static int oggvorbis_decode_frame(AVCodecContext *avccontext, void *data, int *got_frame_ptr, AVPacket *avpkt)
static int conv(int samples, float **pcm, char *buf, int channels)
static int oggvorbis_decode_init(AVCodecContext *avccontext)
static int ogg_packet(AVFormatContext *s, int *sid, int *dstart, int *dsize, int64_t *fpos)
find the next Ogg packet
main external API structure.
enum AVSampleFormat sample_fmt
audio sample format
int sample_rate
samples per second
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
int channels
number of audio channels
const char * name
Name of the codec implementation.
This structure describes decoded (raw) audio or video data.
int nb_samples
number of audio samples (per channel) described by this frame
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
This structure stores compressed data.
Rational number (pair of numerator and denominator).
vorbis_block vb
vorbis_block used for analysis
vorbis_comment vc
VorbisComment info
vorbis_info vi
vorbis_info used during init
vorbis_dsp_state vd
DSP state used for analysis
static void error(const char *err)
static const uint8_t offset[127][2]