- av_dlog(avctx, "resolution = %i\n", sconf->resolution);
- av_dlog(avctx, "floating = %i\n", sconf->floating);
- av_dlog(avctx, "frame_length = %i\n", sconf->frame_length);
- av_dlog(avctx, "ra_distance = %i\n", sconf->ra_distance);
- av_dlog(avctx, "ra_flag = %i\n", sconf->ra_flag);
- av_dlog(avctx, "adapt_order = %i\n", sconf->adapt_order);
- av_dlog(avctx, "coef_table = %i\n", sconf->coef_table);
- av_dlog(avctx, "long_term_prediction = %i\n", sconf->long_term_prediction);
- av_dlog(avctx, "max_order = %i\n", sconf->max_order);
- av_dlog(avctx, "block_switching = %i\n", sconf->block_switching);
- av_dlog(avctx, "bgmc = %i\n", sconf->bgmc);
- av_dlog(avctx, "sb_part = %i\n", sconf->sb_part);
- av_dlog(avctx, "joint_stereo = %i\n", sconf->joint_stereo);
- av_dlog(avctx, "mc_coding = %i\n", sconf->mc_coding);
- av_dlog(avctx, "chan_config = %i\n", sconf->chan_config);
- av_dlog(avctx, "chan_sort = %i\n", sconf->chan_sort);
- av_dlog(avctx, "RLSLMS = %i\n", sconf->rlslms);
- av_dlog(avctx, "chan_config_info = %i\n", sconf->chan_config_info);
-#endif
+ ff_dlog(avctx, "resolution = %i\n", sconf->resolution);
+ ff_dlog(avctx, "floating = %i\n", sconf->floating);
+ ff_dlog(avctx, "frame_length = %i\n", sconf->frame_length);
+ ff_dlog(avctx, "ra_distance = %i\n", sconf->ra_distance);
+ ff_dlog(avctx, "ra_flag = %i\n", sconf->ra_flag);
+ ff_dlog(avctx, "adapt_order = %i\n", sconf->adapt_order);
+ ff_dlog(avctx, "coef_table = %i\n", sconf->coef_table);
+ ff_dlog(avctx, "long_term_prediction = %i\n", sconf->long_term_prediction);
+ ff_dlog(avctx, "max_order = %i\n", sconf->max_order);
+ ff_dlog(avctx, "block_switching = %i\n", sconf->block_switching);
+ ff_dlog(avctx, "bgmc = %i\n", sconf->bgmc);
+ ff_dlog(avctx, "sb_part = %i\n", sconf->sb_part);
+ ff_dlog(avctx, "joint_stereo = %i\n", sconf->joint_stereo);
+ ff_dlog(avctx, "mc_coding = %i\n", sconf->mc_coding);
+ ff_dlog(avctx, "chan_config = %i\n", sconf->chan_config);
+ ff_dlog(avctx, "chan_sort = %i\n", sconf->chan_sort);
+ ff_dlog(avctx, "RLSLMS = %i\n", sconf->rlslms);
+ ff_dlog(avctx, "chan_config_info = %i\n", sconf->chan_config_info);
- skip_bits(&gb, 16); // number of channels already knwon
- skip_bits(&gb, 3); // skip file_type
- sconf->resolution = get_bits(&gb, 3);
- sconf->floating = get_bits1(&gb);
- sconf->msb_first = get_bits1(&gb);
- sconf->frame_length = get_bits(&gb, 16) + 1;
- sconf->ra_distance = get_bits(&gb, 8);
- sconf->ra_flag = get_bits(&gb, 2);
- sconf->adapt_order = get_bits1(&gb);
- sconf->coef_table = get_bits(&gb, 2);
- sconf->long_term_prediction = get_bits1(&gb);
- sconf->max_order = get_bits(&gb, 10);
- sconf->block_switching = get_bits(&gb, 2);
- sconf->bgmc = get_bits1(&gb);
- sconf->sb_part = get_bits1(&gb);
- sconf->joint_stereo = get_bits1(&gb);
- sconf->mc_coding = get_bits1(&gb);
- sconf->chan_config = get_bits1(&gb);
- sconf->chan_sort = get_bits1(&gb);
- sconf->crc_enabled = get_bits1(&gb);
- sconf->rlslms = get_bits1(&gb);
- skip_bits(&gb, 5); // skip 5 reserved bits
- skip_bits1(&gb); // skip aux_data_enabled
+ bitstream_skip(&bc, 16); // number of channels already known
+ bitstream_skip(&bc, 3); // skip file_type
+ sconf->resolution = bitstream_read(&bc, 3);
+ sconf->floating = bitstream_read_bit(&bc);
+ sconf->msb_first = bitstream_read_bit(&bc);
+ sconf->frame_length = bitstream_read(&bc, 16) + 1;
+ sconf->ra_distance = bitstream_read(&bc, 8);
+ sconf->ra_flag = bitstream_read(&bc, 2);
+ sconf->adapt_order = bitstream_read_bit(&bc);
+ sconf->coef_table = bitstream_read(&bc, 2);
+ sconf->long_term_prediction = bitstream_read_bit(&bc);
+ sconf->max_order = bitstream_read(&bc, 10);
+ sconf->block_switching = bitstream_read(&bc, 2);
+ sconf->bgmc = bitstream_read_bit(&bc);
+ sconf->sb_part = bitstream_read_bit(&bc);
+ sconf->joint_stereo = bitstream_read_bit(&bc);
+ sconf->mc_coding = bitstream_read_bit(&bc);
+ sconf->chan_config = bitstream_read_bit(&bc);
+ sconf->chan_sort = bitstream_read_bit(&bc);
+ sconf->crc_enabled = bitstream_read_bit(&bc);
+ sconf->rlslms = bitstream_read_bit(&bc);
+ bitstream_skip(&bc, 5); // skip 5 reserved bits
+ bitstream_skip(&bc, 1); // skip aux_data_enabled
- MISSING_ERR(sconf->floating, "Floating point decoding", -1);
- MISSING_ERR(sconf->rlslms, "Adaptive RLS-LMS prediction", -1);
- MISSING_ERR(sconf->chan_sort, "Channel sorting", 0);
+ MISSING_ERR(sconf->floating, "Floating point decoding", AVERROR_PATCHWELCOME);
+ MISSING_ERR(sconf->rlslms, "Adaptive RLS-LMS prediction", AVERROR_PATCHWELCOME);
+ MISSING_ERR(sconf->chan_sort, "Channel sorting", 0);
- ff_bgmc_decode(gb, sb_length, current_res,
- delta[sb], sx[sb], &high, &low, &value, ctx->bgmc_lut, ctx->bgmc_lut_status);
+ ff_bgmc_decode(bc, sb_len, current_res, delta[sb], sx[sb], &high,
+ &low, &value, ctx->bgmc_lut, ctx->bgmc_lut_status);
- if(read_decode_block(ctx, &bd[0]) || read_decode_block(ctx, &bd[1])) {
- // damaged block, write zero for the rest of the frame
- zero_remaining(b, ctx->num_blocks, div_blocks, bd[0].raw_samples);
- zero_remaining(b, ctx->num_blocks, div_blocks, bd[1].raw_samples);
- return -1;
- }
+ if ((ret = read_decode_block(ctx, &bd[0])) < 0 ||
+ (ret = read_decode_block(ctx, &bd[1])) < 0)
+ goto fail;
- current->time_diff_flag = get_bits1(gb);
- current->weighting[0] = mcc_weightings[av_clip(decode_rice(gb, 1) + 16, 0, 32)];
- current->weighting[1] = mcc_weightings[av_clip(decode_rice(gb, 2) + 14, 0, 32)];
- current->weighting[2] = mcc_weightings[av_clip(decode_rice(gb, 1) + 16, 0, 32)];
+ current->time_diff_flag = bitstream_read_bit(bc);
+ current->weighting[0] = als_weighting(bc, 1, 16);
+ current->weighting[1] = als_weighting(bc, 2, 14);
+ current->weighting[2] = als_weighting(bc, 1, 16);
- current->weighting[3] = mcc_weightings[av_clip(decode_rice(gb, 1) + 16, 0, 32)];
- current->weighting[4] = mcc_weightings[av_clip(decode_rice(gb, 1) + 16, 0, 32)];
- current->weighting[5] = mcc_weightings[av_clip(decode_rice(gb, 1) + 16, 0, 32)];
+ current->weighting[3] = als_weighting(bc, 1, 16);
+ current->weighting[4] = als_weighting(bc, 1, 16);
+ current->weighting[5] = als_weighting(bc, 1, 16);
+ if (FFMIN(begin - 1, begin - 1 + t) < ctx->raw_buffer - master ||
+ FFMAX(end + 1, end + 1 + t) > ctx->raw_buffer + channels * channel_size - master) {
+ av_log(ctx->avctx, AV_LOG_ERROR,
+ "sample pointer range [%p, %p] not contained in raw_buffer [%p, %p].\n",
+ master + FFMIN(begin - 1, begin - 1 + t), master + FFMAX(end + 1, end + 1 + t),
+ ctx->raw_buffer, ctx->raw_buffer + channels * channel_size);
+ return AVERROR_INVALIDDATA;
+ }
+
+
+ if (begin - 1 < ctx->raw_buffer - master ||
+ end + 1 > ctx->raw_buffer + channels * channel_size - master) {
+ av_log(ctx->avctx, AV_LOG_ERROR,
+ "sample pointer range [%p, %p] not contained in raw_buffer [%p, %p].\n",
+ master + begin - 1, master + end + 1,
+ ctx->raw_buffer, ctx->raw_buffer + channels * channel_size);
+ return AVERROR_INVALIDDATA;
+ }
+
ALSSpecificConfig *sconf = &ctx->sconf;
const uint8_t *buffer = avpkt->data;
int buffer_size = avpkt->size;
int invalid_frame, ret;
unsigned int c, sample, ra_frame, bytes_read, shift;
ALSSpecificConfig *sconf = &ctx->sconf;
const uint8_t *buffer = avpkt->data;
int buffer_size = avpkt->size;
int invalid_frame, ret;
unsigned int c, sample, ra_frame, bytes_read, shift;