21 #include <vorbis/vorbisenc.h>
39 unsigned char *headers[3], *extradata = avccontext->
extradata;
41 vorbis_info_init(&context->
vi) ;
42 vorbis_comment_init(&context->
vc) ;
49 if(p[0] == 0 && p[1] == 30) {
50 for(i = 0; i < 3; i++){
51 hsizes[i] = bytestream_get_be16((
const uint8_t **)&p);
60 while((*p == 0xFF) && (offset < avccontext->extradata_size)) {
67 "vorbis header sizes damaged\n");
77 "vorbis header sizes: %d, %d, %d, / extradata_len is %d \n",
80 headers[0] = extradata +
offset;
81 headers[1] = extradata + offset + hsizes[0];
82 headers[2] = extradata + offset + hsizes[0] + hsizes[1];
85 "vorbis initial header len is wrong: %d\n", *p);
90 context->
op.b_o_s= i==0;
91 context->
op.bytes = hsizes[i];
92 context->
op.packet = headers[i];
93 if(vorbis_synthesis_headerin(&context->
vi, &context->
vc, &context->
op)<0){
104 vorbis_synthesis_init(&context->
vd, &context->
vi);
105 vorbis_block_init(&context->
vd, &context->
vb);
111 static inline int conv(
int samples,
float **pcm,
char *
buf,
int channels) {
113 ogg_int16_t *ptr, *
data = (ogg_int16_t*)buf ;
116 for(i = 0 ; i < channels ; i++){
120 for(j = 0 ; j < samples ; j++) {
121 *ptr = av_clip_int16(mono[j] * 32767.f);
130 int *got_frame_ptr,
AVPacket *avpkt)
136 int samples, total_samples, total_bytes;
148 output = (int16_t *)frame->
data[0];
151 op->packet = avpkt->
data;
152 op->bytes = avpkt->
size;
160 if(vorbis_synthesis(&context->
vb, op) == 0)
161 vorbis_synthesis_blockin(&context->
vd, &context->
vb) ;
166 while((samples = vorbis_synthesis_pcmout(&context->
vd, &pcm)) > 0) {
167 conv(samples, pcm, (
char*)output + total_bytes, context->
vi.channels) ;
168 total_bytes += samples * 2 * context->
vi.channels ;
169 total_samples += samples ;
170 vorbis_synthesis_read(&context->
vd, samples) ;
174 *got_frame_ptr = total_samples > 0;
182 vorbis_info_clear(&context->
vi) ;
183 vorbis_comment_clear(&context->
vc) ;
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.
void av_log(void *avcl, int level, const char *fmt,...) av_printf_format(3
Send the specified message to the log if the level is less than or equal to the current av_log_level...
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
vorbis_block vb
vorbis_block used for analysis
enum AVSampleFormat sample_fmt
audio sample format
static const uint8_t offset[511][2]
static int oggvorbis_decode_init(AVCodecContext *avccontext)
const char * name
Name of the codec implementation.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
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.
Libavcodec external API header.
vorbis_info vi
vorbis_info used during init
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.
static void close(AVCodecParserContext *s)
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 numerator/denominator
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.
AVCodec ff_libvorbis_decoder
int channels
number of audio channels
static int decode(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
This structure stores compressed 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.