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];
70 while((*p == 0xFF) && (offset < avccontext->extradata_size)) {
77 "vorbis header sizes damaged\n");
88 "vorbis header sizes: %d, %d, %d, / extradata_len is %d \n",
91 headers[0] = extradata +
offset;
92 headers[1] = extradata + offset + hsizes[0];
93 headers[2] = extradata + offset + hsizes[0] + hsizes[1];
96 "vorbis initial header len is wrong: %d\n", *p);
102 context->
op.b_o_s= i==0;
103 context->
op.bytes = hsizes[
i];
104 context->
op.packet = headers[
i];
105 if(vorbis_synthesis_headerin(&context->
vi, &context->
vc, &context->
op)<0){
117 vorbis_synthesis_init(&context->
vd, &context->
vi);
118 vorbis_block_init(&context->
vd, &context->
vb);
130 ogg_int16_t *ptr, *
data = (ogg_int16_t*)buf ;
137 for(j = 0 ; j < samples ; j++) {
138 *ptr = av_clip_int16(mono[j] * 32767.
f);
147 int *got_frame_ptr,
AVPacket *avpkt)
153 int samples, total_samples, total_bytes;
165 output = (int16_t *)frame->
data[0];
168 op->packet = avpkt->
data;
169 op->bytes = avpkt->
size;
177 if(vorbis_synthesis(&context->
vb, op) == 0)
178 vorbis_synthesis_blockin(&context->
vd, &context->
vb) ;
183 while((samples = vorbis_synthesis_pcmout(&context->
vd, &pcm)) > 0) {
184 conv(samples, pcm, (
char*)output + total_bytes, context->
vi.channels) ;
185 total_bytes += samples * 2 * context->
vi.channels ;
186 total_samples += samples ;
187 vorbis_synthesis_read(&context->
vd, samples) ;
191 *got_frame_ptr = total_samples > 0;
199 vorbis_block_clear(&context->
vb);
200 vorbis_dsp_clear(&context->
vd);
201 vorbis_info_clear(&context->
vi) ;
202 vorbis_comment_clear(&context->
vc) ;
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
This structure describes decoded (raw) audio or video data.
static int conv(int samples, float **pcm, char *buf, int channels)
static av_cold int init(AVCodecContext *avctx)
vorbis_dsp_state vd
DSP state used for analysis.
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
vorbis_block vb
vorbis_block used for analysis
enum AVSampleFormat sample_fmt
audio sample format
static int oggvorbis_decode_init(AVCodecContext *avccontext)
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
#define i(width, name, range_min, range_max)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
vorbis_comment vc
VorbisComment info.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
const char * name
Name of the codec implementation.
static const uint8_t offset[127][2]
vorbis_info vi
vorbis_info used during init
static void error(const char *err)
Libavcodec external API header.
static int oggvorbis_decode_frame(AVCodecContext *avccontext, void *data, int *got_frame_ptr, AVPacket *avpkt)
int sample_rate
samples per second
static int ogg_packet(AVFormatContext *s, int *sid, int *dstart, int *dsize, int64_t *fpos)
find the next Ogg packet
main external API structure.
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
static int oggvorbis_decode_close(AVCodecContext *avccontext)
Rational number (pair of numerator and denominator).
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
common internal api header.
AVCodec ff_libvorbis_decoder
int channels
number of audio channels
This structure stores compressed data.
int nb_samples
number of audio samples (per channel) described by this frame