#include <inttypes.h>
#include <math.h>
-#define ALT_BITSTREAM_READER_LE
+#define BITSTREAM_READER_LE
#include "avcodec.h"
#include "get_bits.h"
#include "dsputil.h"
typedef struct vorbis_context_s {
AVCodecContext *avccontext;
+ AVFrame frame;
GetBitContext gb;
DSPContext dsp;
FmtConvertContext fmt_conv;
av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis id header packet corrupt (illegal blocksize). \n");
return AVERROR_INVALIDDATA;
}
- // output format int16
- if (vc->blocksize[1] / 2 * vc->audio_channels * 2 > AVCODEC_MAX_AUDIO_FRAME_SIZE) {
- av_log(vc->avccontext, AV_LOG_ERROR, "Vorbis channel count makes "
- "output packets too large.\n");
- return AVERROR_PATCHWELCOME;
- }
vc->win[0] = ff_vorbis_vwin[bl0 - 6];
vc->win[1] = ff_vorbis_vwin[bl1 - 6];
avccontext->sample_rate = vc->audio_samplerate;
avccontext->frame_size = FFMIN(vc->blocksize[0], vc->blocksize[1]) >> 2;
+ avcodec_get_frame_defaults(&vc->frame);
+ avccontext->coded_frame = &vc->frame;
+
return 0;
}
// Return the decoded audio packet through the standard api
-static int vorbis_decode_frame(AVCodecContext *avccontext,
- void *data, int *data_size,
- AVPacket *avpkt)
+static int vorbis_decode_frame(AVCodecContext *avccontext, void *data,
+ int *got_frame_ptr, AVPacket *avpkt)
{
const uint8_t *buf = avpkt->data;
int buf_size = avpkt->size;
vorbis_context *vc = avccontext->priv_data;
GetBitContext *gb = &(vc->gb);
const float *channel_ptrs[255];
- int i, len, out_size;
+ int i, len, ret;
av_dlog(NULL, "packet length %d \n", buf_size);
if (!vc->first_frame) {
vc->first_frame = 1;
- *data_size = 0;
+ *got_frame_ptr = 0;
return buf_size;
}
av_dlog(NULL, "parsed %d bytes %d bits, returned %d samples (*ch*bits) \n",
get_bits_count(gb) / 8, get_bits_count(gb) % 8, len);
- out_size = len * vc->audio_channels *
- av_get_bytes_per_sample(avccontext->sample_fmt);
- if (*data_size < out_size) {
- av_log(avccontext, AV_LOG_ERROR, "output buffer is too small\n");
- return AVERROR(EINVAL);
+ /* get output buffer */
+ vc->frame.nb_samples = len;
+ if ((ret = avccontext->get_buffer(avccontext, &vc->frame)) < 0) {
+ av_log(avccontext, AV_LOG_ERROR, "get_buffer() failed\n");
+ return ret;
}
if (vc->audio_channels > 8) {
}
if (avccontext->sample_fmt == AV_SAMPLE_FMT_FLT)
- vc->fmt_conv.float_interleave(data, channel_ptrs, len, vc->audio_channels);
+ vc->fmt_conv.float_interleave((float *)vc->frame.data[0], channel_ptrs,
+ len, vc->audio_channels);
else
- vc->fmt_conv.float_to_int16_interleave(data, channel_ptrs, len,
+ vc->fmt_conv.float_to_int16_interleave((int16_t *)vc->frame.data[0],
+ channel_ptrs, len,
vc->audio_channels);
- *data_size = out_size;
+ *got_frame_ptr = 1;
+ *(AVFrame *)data = vc->frame;
return buf_size;
}
.init = vorbis_decode_init,
.close = vorbis_decode_close,
.decode = vorbis_decode_frame,
+ .capabilities = CODEC_CAP_DR1,
.long_name = NULL_IF_CONFIG_SMALL("Vorbis"),
.channel_layouts = ff_vorbis_channel_layouts,
.sample_fmts = (const enum AVSampleFormat[]) {