alac: support a read sample size of up to 32

Use get_bits_long() in decode_scalar().
Use unsigned int for decoded value.
pull/59/head
Justin Ruggles 13 years ago
parent 73dc0db486
commit cd632619d9
  1. 21
      libavcodec/alac.c

@ -78,13 +78,14 @@ typedef struct {
int nb_samples; /**< number of samples in the current frame */ int nb_samples; /**< number of samples in the current frame */
} ALACContext; } ALACContext;
static inline int decode_scalar(GetBitContext *gb, int k, int readsamplesize) static inline unsigned int decode_scalar(GetBitContext *gb, int k,
int readsamplesize)
{ {
int x = get_unary_0_9(gb); unsigned int x = get_unary_0_9(gb);
if (x > 8) { /* RICE THRESHOLD */ if (x > 8) { /* RICE THRESHOLD */
/* use alternative encoding */ /* use alternative encoding */
x = get_bits(gb, readsamplesize); x = get_bits_long(gb, readsamplesize);
} else if (k != 1) { } else if (k != 1) {
int extrabits = show_bits(gb, k); int extrabits = show_bits(gb, k);
@ -111,7 +112,8 @@ static void bastardized_rice_decompress(ALACContext *alac,
int sign_modifier = 0; int sign_modifier = 0;
for (output_count = 0; output_count < output_size; output_count++) { for (output_count = 0; output_count < output_size; output_count++) {
int x, k; int k;
unsigned int x;
/* read k, that is bits as is */ /* read k, that is bits as is */
k = av_log2((history >> 9) + 3); k = av_log2((history >> 9) + 3);
@ -294,6 +296,11 @@ static int alac_decode_frame(AVCodecContext *avctx, void *data,
hassize = get_bits1(&alac->gb); hassize = get_bits1(&alac->gb);
alac->extra_bits = get_bits(&alac->gb, 2) << 3; alac->extra_bits = get_bits(&alac->gb, 2) << 3;
readsamplesize = alac->sample_size - alac->extra_bits + channels - 1;
if (readsamplesize > 32) {
av_log(avctx, AV_LOG_ERROR, "bps is unsupported: %d\n", readsamplesize);
return AVERROR_PATCHWELCOME;
}
/* whether the frame is compressed */ /* whether the frame is compressed */
is_compressed = !get_bits1(&alac->gb); is_compressed = !get_bits1(&alac->gb);
@ -321,12 +328,6 @@ static int alac_decode_frame(AVCodecContext *avctx, void *data,
alac->output_samples_buffer[ch] = (int32_t *)alac->frame.data[ch]; alac->output_samples_buffer[ch] = (int32_t *)alac->frame.data[ch];
} }
readsamplesize = alac->sample_size - alac->extra_bits + channels - 1;
if (readsamplesize > MIN_CACHE_BITS) {
av_log(avctx, AV_LOG_ERROR, "readsamplesize too big (%d)\n", readsamplesize);
return -1;
}
if (is_compressed) { if (is_compressed) {
int16_t predictor_coef_table[MAX_CHANNELS][32]; int16_t predictor_coef_table[MAX_CHANNELS][32];
int predictor_coef_num[MAX_CHANNELS]; int predictor_coef_num[MAX_CHANNELS];

Loading…
Cancel
Save