*/
/**
- * @file shorten.c
+ * @file
* Shorten decoder
* @author Jeff Muizelaar
*
#define DEBUG
#include <limits.h>
#include "avcodec.h"
-#include "bitstream.h"
+#include "get_bits.h"
#include "golomb.h"
#define MAX_CHANNELS 8
int32_t *decoded[MAX_CHANNELS];
int32_t *offset[MAX_CHANNELS];
+ int *coeffs;
uint8_t *bitstream;
int bitstream_size;
int bitstream_index;
static int allocate_buffers(ShortenContext *s)
{
int i, chan;
+ int *coeffs;
+
for (chan=0; chan<s->channels; chan++) {
if(FFMAX(1, s->nmean) >= UINT_MAX/sizeof(int32_t)){
av_log(s->avctx, AV_LOG_ERROR, "nmean too large\n");
s->decoded[chan][i] = 0;
s->decoded[chan] += s->nwrap;
}
+
+ coeffs = av_realloc(s->coeffs, s->nwrap * sizeof(*s->coeffs));
+ if (!coeffs)
+ return AVERROR(ENOMEM);
+ s->coeffs = coeffs;
+
return 0;
}
static inline int get_le32(GetBitContext *gb)
{
- return bswap_32(get_bits_long(gb, 32));
+ return av_bswap32(get_bits_long(gb, 32));
}
static inline short get_le16(GetBitContext *gb)
{
- return bswap_16(get_bits_long(gb, 16));
+ return av_bswap16(get_bits_long(gb, 16));
}
static int decode_wave_header(AVCodecContext *avctx, uint8_t *header, int header_size)
static void decode_subframe_lpc(ShortenContext *s, int channel, int residual_size, int pred_order)
{
int sum, i, j;
- int coeffs[pred_order];
+ int *coeffs = s->coeffs;
for (i=0; i<pred_order; i++)
coeffs[i] = get_sr_golomb_shorten(&s->gb, LPCQUANT);
static int shorten_decode_frame(AVCodecContext *avctx,
void *data, int *data_size,
- const uint8_t *buf, int buf_size)
+ AVPacket *avpkt)
{
+ const uint8_t *buf = avpkt->data;
+ int buf_size = avpkt->size;
ShortenContext *s = avctx->priv_data;
int i, input_buf_size = 0;
int16_t *samples = data;
case FN_QLPC:
{
int pred_order = get_ur_golomb_shorten(&s->gb, LPCQSIZE);
+ if (pred_order > s->nwrap) {
+ av_log(avctx, AV_LOG_ERROR,
+ "invalid pred_order %d\n",
+ pred_order);
+ return -1;
+ }
for (i=0; i<pred_order; i++)
s->decoded[channel][i - pred_order] -= coffset;
decode_subframe_lpc(s, channel, residual_size, pred_order);
av_freep(&s->offset[i]);
}
av_freep(&s->bitstream);
+ av_freep(&s->coeffs);
return 0;
}
AVCodec shorten_decoder = {
"shorten",
- CODEC_TYPE_AUDIO,
+ AVMEDIA_TYPE_AUDIO,
CODEC_ID_SHORTEN,
sizeof(ShortenContext),
shorten_decode_init,