diff --git a/libavcodec/atrac3plus.c b/libavcodec/atrac3plus.c index 076fb844a7..2731a80725 100644 --- a/libavcodec/atrac3plus.c +++ b/libavcodec/atrac3plus.c @@ -26,8 +26,9 @@ */ #include "libavutil/avassert.h" + #include "avcodec.h" -#include "get_bits.h" +#include "bitstream.h" #include "atrac3plus.h" #include "atrac3plus_data.h" @@ -212,20 +213,20 @@ av_cold void ff_atrac3p_init_vlcs(AVCodec *codec) /** * Decode number of coded quantization units. * - * @param[in] gb the GetBit context + * @param[in] bc the Bitstream context * @param[in,out] chan ptr to the channel parameters * @param[in,out] ctx ptr to the channel unit context * @param[in] avctx ptr to the AVCodecContext * @return result code: 0 = OK, otherwise - error code */ -static int num_coded_units(GetBitContext *gb, Atrac3pChanParams *chan, +static int num_coded_units(BitstreamContext *bc, Atrac3pChanParams *chan, Atrac3pChanUnitCtx *ctx, AVCodecContext *avctx) { - chan->fill_mode = get_bits(gb, 2); + chan->fill_mode = bitstream_read(bc, 2); if (!chan->fill_mode) { chan->num_coded_vals = ctx->num_quant_units; } else { - chan->num_coded_vals = get_bits(gb, 5); + chan->num_coded_vals = bitstream_read(bc, 5); if (chan->num_coded_vals > ctx->num_quant_units) { av_log(avctx, AV_LOG_ERROR, "Invalid number of transmitted units!\n"); @@ -233,7 +234,7 @@ static int num_coded_units(GetBitContext *gb, Atrac3pChanParams *chan, } if (chan->fill_mode == 3) - chan->split_point = get_bits(gb, 2) + (chan->ch_num << 1) + 1; + chan->split_point = bitstream_read(bc, 2) + (chan->ch_num << 1) + 1; } return 0; @@ -318,21 +319,21 @@ static inline void unpack_vq_shape(int start_val, const int8_t *shape_vec, } } -#define UNPACK_SF_VQ_SHAPE(gb, dst, num_vals) \ - start_val = get_bits((gb), 6); \ - unpack_vq_shape(start_val, &atrac3p_sf_shapes[get_bits((gb), 6)][0], \ +#define UNPACK_SF_VQ_SHAPE(bc, dst, num_vals) \ + start_val = bitstream_read((bc), 6); \ + unpack_vq_shape(start_val, &atrac3p_sf_shapes[bitstream_read((bc), 6)][0], \ (dst), (num_vals)) /** * Decode word length for each quantization unit of a channel. * - * @param[in] gb the GetBit context + * @param[in] bc the Bitstream context * @param[in,out] ctx ptr to the channel unit context * @param[in] ch_num channel to process * @param[in] avctx ptr to the AVCodecContext * @return result code: 0 = OK, otherwise - error code */ -static int decode_channel_wordlen(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, +static int decode_channel_wordlen(BitstreamContext *bc, Atrac3pChanUnitCtx *ctx, int ch_num, AVCodecContext *avctx) { int i, weight_idx = 0, delta, diff, pos, delta_bits, min_val, flag, @@ -343,107 +344,107 @@ static int decode_channel_wordlen(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, chan->fill_mode = 0; - switch (get_bits(gb, 2)) { /* switch according to coding mode */ + switch (bitstream_read(bc, 2)) { /* switch according to coding mode */ case 0: /* coded using constant number of bits */ for (i = 0; i < ctx->num_quant_units; i++) - chan->qu_wordlen[i] = get_bits(gb, 3); + chan->qu_wordlen[i] = bitstream_read(bc, 3); break; case 1: if (ch_num) { - if ((ret = num_coded_units(gb, chan, ctx, avctx)) < 0) + if ((ret = num_coded_units(bc, chan, ctx, avctx)) < 0) return ret; if (chan->num_coded_vals) { - vlc_tab = &wl_vlc_tabs[get_bits(gb, 2)]; + vlc_tab = &wl_vlc_tabs[bitstream_read(bc, 2)]; for (i = 0; i < chan->num_coded_vals; i++) { - delta = get_vlc2(gb, vlc_tab->table, vlc_tab->bits, 1); + delta = bitstream_read_vlc(bc, vlc_tab->table, vlc_tab->bits, 1); chan->qu_wordlen[i] = (ref_chan->qu_wordlen[i] + delta) & 7; } } } else { - weight_idx = get_bits(gb, 2); - if ((ret = num_coded_units(gb, chan, ctx, avctx)) < 0) + weight_idx = bitstream_read(bc, 2); + if ((ret = num_coded_units(bc, chan, ctx, avctx)) < 0) return ret; if (chan->num_coded_vals) { - pos = get_bits(gb, 5); + pos = bitstream_read(bc, 5); if (pos > chan->num_coded_vals) { av_log(avctx, AV_LOG_ERROR, "WL mode 1: invalid position!\n"); return AVERROR_INVALIDDATA; } - delta_bits = get_bits(gb, 2); - min_val = get_bits(gb, 3); + delta_bits = bitstream_read(bc, 2); + min_val = bitstream_read(bc, 3); for (i = 0; i < pos; i++) - chan->qu_wordlen[i] = get_bits(gb, 3); + chan->qu_wordlen[i] = bitstream_read(bc, 3); for (i = pos; i < chan->num_coded_vals; i++) - chan->qu_wordlen[i] = (min_val + get_bitsz(gb, delta_bits)) & 7; + chan->qu_wordlen[i] = (min_val + bitstream_read(bc, delta_bits)) & 7; } } break; case 2: - if ((ret = num_coded_units(gb, chan, ctx, avctx)) < 0) + if ((ret = num_coded_units(bc, chan, ctx, avctx)) < 0) return ret; if (ch_num && chan->num_coded_vals) { - vlc_tab = &wl_vlc_tabs[get_bits(gb, 2)]; - delta = get_vlc2(gb, vlc_tab->table, vlc_tab->bits, 1); + vlc_tab = &wl_vlc_tabs[bitstream_read(bc, 2)]; + delta = bitstream_read_vlc(bc, vlc_tab->table, vlc_tab->bits, 1); chan->qu_wordlen[0] = (ref_chan->qu_wordlen[0] + delta) & 7; for (i = 1; i < chan->num_coded_vals; i++) { diff = ref_chan->qu_wordlen[i] - ref_chan->qu_wordlen[i - 1]; - delta = get_vlc2(gb, vlc_tab->table, vlc_tab->bits, 1); + delta = bitstream_read_vlc(bc, vlc_tab->table, vlc_tab->bits, 1); chan->qu_wordlen[i] = (chan->qu_wordlen[i - 1] + diff + delta) & 7; } } else if (chan->num_coded_vals) { - flag = get_bits(gb, 1); - vlc_tab = &wl_vlc_tabs[get_bits(gb, 1)]; + flag = bitstream_read(bc, 1); + vlc_tab = &wl_vlc_tabs[bitstream_read(bc, 1)]; - start_val = get_bits(gb, 3); + start_val = bitstream_read(bc, 3); unpack_vq_shape(start_val, - &atrac3p_wl_shapes[start_val][get_bits(gb, 4)][0], + &atrac3p_wl_shapes[start_val][bitstream_read(bc, 4)][0], chan->qu_wordlen, chan->num_coded_vals); if (!flag) { for (i = 0; i < chan->num_coded_vals; i++) { - delta = get_vlc2(gb, vlc_tab->table, vlc_tab->bits, 1); + delta = bitstream_read_vlc(bc, vlc_tab->table, vlc_tab->bits, 1); chan->qu_wordlen[i] = (chan->qu_wordlen[i] + delta) & 7; } } else { for (i = 0; i < (chan->num_coded_vals & - 2); i += 2) - if (!get_bits1(gb)) { + if (!bitstream_read_bit(bc)) { chan->qu_wordlen[i] = (chan->qu_wordlen[i] + - get_vlc2(gb, vlc_tab->table, - vlc_tab->bits, 1)) & 7; + bitstream_read_vlc(bc, vlc_tab->table, + vlc_tab->bits, 1)) & 7; chan->qu_wordlen[i + 1] = (chan->qu_wordlen[i + 1] + - get_vlc2(gb, vlc_tab->table, - vlc_tab->bits, 1)) & 7; + bitstream_read_vlc(bc, vlc_tab->table, + vlc_tab->bits, 1)) & 7; } if (chan->num_coded_vals & 1) chan->qu_wordlen[i] = (chan->qu_wordlen[i] + - get_vlc2(gb, vlc_tab->table, - vlc_tab->bits, 1)) & 7; + bitstream_read_vlc(bc, vlc_tab->table, + vlc_tab->bits, 1)) & 7; } } break; case 3: - weight_idx = get_bits(gb, 2); - if ((ret = num_coded_units(gb, chan, ctx, avctx)) < 0) + weight_idx = bitstream_read(bc, 2); + if ((ret = num_coded_units(bc, chan, ctx, avctx)) < 0) return ret; if (chan->num_coded_vals) { - vlc_tab = &wl_vlc_tabs[get_bits(gb, 2)]; + vlc_tab = &wl_vlc_tabs[bitstream_read(bc, 2)]; /* first coefficient is coded directly */ - chan->qu_wordlen[0] = get_bits(gb, 3); + chan->qu_wordlen[0] = bitstream_read(bc, 3); for (i = 1; i < chan->num_coded_vals; i++) { - delta = get_vlc2(gb, vlc_tab->table, vlc_tab->bits, 1); + delta = bitstream_read_vlc(bc, vlc_tab->table, vlc_tab->bits, 1); chan->qu_wordlen[i] = (chan->qu_wordlen[i - 1] + delta) & 7; } } @@ -452,7 +453,7 @@ static int decode_channel_wordlen(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, if (chan->fill_mode == 2) { for (i = chan->num_coded_vals; i < ctx->num_quant_units; i++) - chan->qu_wordlen[i] = ch_num ? get_bits1(gb) : 1; + chan->qu_wordlen[i] = ch_num ? bitstream_read_bit(bc) : 1; } else if (chan->fill_mode == 3) { pos = ch_num ? chan->num_coded_vals + chan->split_point : ctx->num_quant_units - chan->split_point; @@ -469,13 +470,13 @@ static int decode_channel_wordlen(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, /** * Decode scale factor indexes for each quant unit of a channel. * - * @param[in] gb the GetBit context + * @param[in] bc the Bitstream context * @param[in,out] ctx ptr to the channel unit context * @param[in] ch_num channel to process * @param[in] avctx ptr to the AVCodecContext * @return result code: 0 = OK, otherwise - error code */ -static int decode_channel_sf_idx(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, +static int decode_channel_sf_idx(BitstreamContext *bc, Atrac3pChanUnitCtx *ctx, int ch_num, AVCodecContext *avctx) { int i, weight_idx = 0, delta, diff, num_long_vals, @@ -484,40 +485,40 @@ static int decode_channel_sf_idx(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, Atrac3pChanParams *chan = &ctx->channels[ch_num]; Atrac3pChanParams *ref_chan = &ctx->channels[0]; - switch (get_bits(gb, 2)) { /* switch according to coding mode */ + switch (bitstream_read(bc, 2)) { /* switch according to coding mode */ case 0: /* coded using constant number of bits */ for (i = 0; i < ctx->used_quant_units; i++) - chan->qu_sf_idx[i] = get_bits(gb, 6); + chan->qu_sf_idx[i] = bitstream_read(bc, 6); break; case 1: if (ch_num) { - vlc_tab = &sf_vlc_tabs[get_bits(gb, 2)]; + vlc_tab = &sf_vlc_tabs[bitstream_read(bc, 2)]; for (i = 0; i < ctx->used_quant_units; i++) { - delta = get_vlc2(gb, vlc_tab->table, vlc_tab->bits, 1); + delta = bitstream_read_vlc(bc, vlc_tab->table, vlc_tab->bits, 1); chan->qu_sf_idx[i] = (ref_chan->qu_sf_idx[i] + delta) & 0x3F; } } else { - weight_idx = get_bits(gb, 2); + weight_idx = bitstream_read(bc, 2); if (weight_idx == 3) { - UNPACK_SF_VQ_SHAPE(gb, chan->qu_sf_idx, ctx->used_quant_units); + UNPACK_SF_VQ_SHAPE(bc, chan->qu_sf_idx, ctx->used_quant_units); - num_long_vals = get_bits(gb, 5); - delta_bits = get_bits(gb, 2); - min_val = get_bits(gb, 4) - 7; + num_long_vals = bitstream_read(bc, 5); + delta_bits = bitstream_read(bc, 2); + min_val = bitstream_read(bc, 4) - 7; for (i = 0; i < num_long_vals; i++) chan->qu_sf_idx[i] = (chan->qu_sf_idx[i] + - get_bits(gb, 4) - 7) & 0x3F; + bitstream_read(bc, 4) - 7) & 0x3F; /* all others are: min_val + delta */ for (i = num_long_vals; i < ctx->used_quant_units; i++) chan->qu_sf_idx[i] = (chan->qu_sf_idx[i] + min_val + - get_bitsz(gb, delta_bits)) & 0x3F; + bitstream_read(bc, delta_bits)) & 0x3F; } else { - num_long_vals = get_bits(gb, 5); - delta_bits = get_bits(gb, 3); - min_val = get_bits(gb, 6); + num_long_vals = bitstream_read(bc, 5); + delta_bits = bitstream_read(bc, 3); + min_val = bitstream_read(bc, 6); if (num_long_vals > ctx->used_quant_units || delta_bits == 7) { av_log(avctx, AV_LOG_ERROR, "SF mode 1: invalid parameters!\n"); @@ -526,34 +527,34 @@ static int decode_channel_sf_idx(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, /* read full-precision SF indexes */ for (i = 0; i < num_long_vals; i++) - chan->qu_sf_idx[i] = get_bits(gb, 6); + chan->qu_sf_idx[i] = bitstream_read(bc, 6); /* all others are: min_val + delta */ for (i = num_long_vals; i < ctx->used_quant_units; i++) chan->qu_sf_idx[i] = (min_val + - get_bitsz(gb, delta_bits)) & 0x3F; + bitstream_read(bc, delta_bits)) & 0x3F; } } break; case 2: if (ch_num) { - vlc_tab = &sf_vlc_tabs[get_bits(gb, 2)]; + vlc_tab = &sf_vlc_tabs[bitstream_read(bc, 2)]; - delta = get_vlc2(gb, vlc_tab->table, vlc_tab->bits, 1); + delta = bitstream_read_vlc(bc, vlc_tab->table, vlc_tab->bits, 1); chan->qu_sf_idx[0] = (ref_chan->qu_sf_idx[0] + delta) & 0x3F; for (i = 1; i < ctx->used_quant_units; i++) { diff = ref_chan->qu_sf_idx[i] - ref_chan->qu_sf_idx[i - 1]; - delta = get_vlc2(gb, vlc_tab->table, vlc_tab->bits, 1); + delta = bitstream_read_vlc(bc, vlc_tab->table, vlc_tab->bits, 1); chan->qu_sf_idx[i] = (chan->qu_sf_idx[i - 1] + diff + delta) & 0x3F; } } else { - vlc_tab = &sf_vlc_tabs[get_bits(gb, 2) + 4]; + vlc_tab = &sf_vlc_tabs[bitstream_read(bc, 2) + 4]; - UNPACK_SF_VQ_SHAPE(gb, chan->qu_sf_idx, ctx->used_quant_units); + UNPACK_SF_VQ_SHAPE(bc, chan->qu_sf_idx, ctx->used_quant_units); for (i = 0; i < ctx->used_quant_units; i++) { - delta = get_vlc2(gb, vlc_tab->table, vlc_tab->bits, 1); + delta = bitstream_read_vlc(bc, vlc_tab->table, vlc_tab->bits, 1); chan->qu_sf_idx[i] = (chan->qu_sf_idx[i] + sign_extend(delta, 4)) & 0x3F; } @@ -565,29 +566,29 @@ static int decode_channel_sf_idx(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, for (i = 0; i < ctx->used_quant_units; i++) chan->qu_sf_idx[i] = ref_chan->qu_sf_idx[i]; } else { - weight_idx = get_bits(gb, 2); - vlc_sel = get_bits(gb, 2); + weight_idx = bitstream_read(bc, 2); + vlc_sel = bitstream_read(bc, 2); vlc_tab = &sf_vlc_tabs[vlc_sel]; if (weight_idx == 3) { vlc_tab = &sf_vlc_tabs[vlc_sel + 4]; - UNPACK_SF_VQ_SHAPE(gb, chan->qu_sf_idx, ctx->used_quant_units); + UNPACK_SF_VQ_SHAPE(bc, chan->qu_sf_idx, ctx->used_quant_units); - diff = (get_bits(gb, 4) + 56) & 0x3F; - chan->qu_sf_idx[0] = (chan->qu_sf_idx[0] + diff) & 0x3F; + diff = (bitstream_read(bc, 4) + 56) & 0x3F; + chan->qu_sf_idx[0] = (chan->qu_sf_idx[0] + diff) & 0x3F; for (i = 1; i < ctx->used_quant_units; i++) { - delta = get_vlc2(gb, vlc_tab->table, vlc_tab->bits, 1); + delta = bitstream_read_vlc(bc, vlc_tab->table, vlc_tab->bits, 1); diff = (diff + sign_extend(delta, 4)) & 0x3F; chan->qu_sf_idx[i] = (diff + chan->qu_sf_idx[i]) & 0x3F; } } else { /* 1st coefficient is coded directly */ - chan->qu_sf_idx[0] = get_bits(gb, 6); + chan->qu_sf_idx[0] = bitstream_read(bc, 6); for (i = 1; i < ctx->used_quant_units; i++) { - delta = get_vlc2(gb, vlc_tab->table, vlc_tab->bits, 1); + delta = bitstream_read_vlc(bc, vlc_tab->table, vlc_tab->bits, 1); chan->qu_sf_idx[i] = (chan->qu_sf_idx[i - 1] + delta) & 0x3F; } } @@ -604,13 +605,13 @@ static int decode_channel_sf_idx(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, /** * Decode word length information for each channel. * - * @param[in] gb the GetBit context + * @param[in] bc the Bitstream context * @param[in,out] ctx ptr to the channel unit context * @param[in] num_channels number of channels to process * @param[in] avctx ptr to the AVCodecContext * @return result code: 0 = OK, otherwise - error code */ -static int decode_quant_wordlen(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, +static int decode_quant_wordlen(BitstreamContext *bc, Atrac3pChanUnitCtx *ctx, int num_channels, AVCodecContext *avctx) { int ch_num, i, ret; @@ -619,7 +620,7 @@ static int decode_quant_wordlen(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, memset(ctx->channels[ch_num].qu_wordlen, 0, sizeof(ctx->channels[ch_num].qu_wordlen)); - if ((ret = decode_channel_wordlen(gb, ctx, ch_num, avctx)) < 0) + if ((ret = decode_channel_wordlen(bc, ctx, ch_num, avctx)) < 0) return ret; } @@ -637,13 +638,13 @@ static int decode_quant_wordlen(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, /** * Decode scale factor indexes for each channel. * - * @param[in] gb the GetBit context + * @param[in] bc the Bitstream context * @param[in,out] ctx ptr to the channel unit context * @param[in] num_channels number of channels to process * @param[in] avctx ptr to the AVCodecContext * @return result code: 0 = OK, otherwise - error code */ -static int decode_scale_factors(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, +static int decode_scale_factors(BitstreamContext *bc, Atrac3pChanUnitCtx *ctx, int num_channels, AVCodecContext *avctx) { int ch_num, ret; @@ -655,7 +656,7 @@ static int decode_scale_factors(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, memset(ctx->channels[ch_num].qu_sf_idx, 0, sizeof(ctx->channels[ch_num].qu_sf_idx)); - if ((ret = decode_channel_sf_idx(gb, ctx, ch_num, avctx)) < 0) + if ((ret = decode_channel_sf_idx(bc, ctx, ch_num, avctx)) < 0) return ret; } @@ -665,18 +666,18 @@ static int decode_scale_factors(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, /** * Decode number of code table values. * - * @param[in] gb the GetBit context + * @param[in] bc the Bitstream context * @param[in,out] ctx ptr to the channel unit context * @param[in] avctx ptr to the AVCodecContext * @return result code: 0 = OK, otherwise - error code */ -static int get_num_ct_values(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, +static int get_num_ct_values(BitstreamContext *bc, Atrac3pChanUnitCtx *ctx, AVCodecContext *avctx) { int num_coded_vals; - if (get_bits1(gb)) { - num_coded_vals = get_bits(gb, 5); + if (bitstream_read_bit(bc)) { + num_coded_vals = bitstream_read(bc, 5); if (num_coded_vals > ctx->used_quant_units) { av_log(avctx, AV_LOG_ERROR, "Invalid number of code table indexes: %d!\n", num_coded_vals); @@ -688,7 +689,7 @@ static int get_num_ct_values(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, } #define DEC_CT_IDX_COMMON(OP) \ - num_vals = get_num_ct_values(gb, ctx, avctx); \ + num_vals = get_num_ct_values(bc, ctx, avctx); \ if (num_vals < 0) \ return num_vals; \ \ @@ -697,33 +698,33 @@ static int get_num_ct_values(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, chan->qu_tab_idx[i] = OP; \ } else if (ch_num && ref_chan->qu_wordlen[i]) \ /* get clone master flag */ \ - chan->qu_tab_idx[i] = get_bits1(gb); \ + chan->qu_tab_idx[i] = bitstream_read_bit(bc); \ } -#define CODING_DIRECT get_bits(gb, num_bits) +#define CODING_DIRECT bitstream_read(bc, num_bits) -#define CODING_VLC get_vlc2(gb, vlc_tab->table, vlc_tab->bits, 1) +#define CODING_VLC bitstream_read_vlc(bc, vlc_tab->table, vlc_tab->bits, 1) #define CODING_VLC_DELTA \ (!i) ? CODING_VLC \ - : (pred + get_vlc2(gb, delta_vlc->table, \ - delta_vlc->bits, 1)) & mask; \ + : (pred + bitstream_read_vlc(bc, delta_vlc->table, \ + delta_vlc->bits, 1)) & mask; \ pred = chan->qu_tab_idx[i] #define CODING_VLC_DIFF \ (ref_chan->qu_tab_idx[i] + \ - get_vlc2(gb, vlc_tab->table, vlc_tab->bits, 1)) & mask + bitstream_read_vlc(bc, vlc_tab->table, vlc_tab->bits, 1)) & mask /** * Decode code table indexes for each quant unit of a channel. * - * @param[in] gb the GetBit context + * @param[in] bc the Bitstream context * @param[in,out] ctx ptr to the channel unit context * @param[in] ch_num channel to process * @param[in] avctx ptr to the AVCodecContext * @return result code: 0 = OK, otherwise - error code */ -static int decode_channel_code_tab(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, +static int decode_channel_code_tab(BitstreamContext *bc, Atrac3pChanUnitCtx *ctx, int ch_num, AVCodecContext *avctx) { int i, num_vals, num_bits, pred; @@ -732,9 +733,9 @@ static int decode_channel_code_tab(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, Atrac3pChanParams *chan = &ctx->channels[ch_num]; Atrac3pChanParams *ref_chan = &ctx->channels[0]; - chan->table_type = get_bits1(gb); + chan->table_type = bitstream_read_bit(bc); - switch (get_bits(gb, 2)) { /* switch according to coding mode */ + switch (bitstream_read(bc, 2)) { /* switch according to coding mode */ case 0: /* directly coded */ num_bits = ctx->use_full_table + 2; DEC_CT_IDX_COMMON(CODING_DIRECT); @@ -770,13 +771,13 @@ static int decode_channel_code_tab(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, /** * Decode code table indexes for each channel. * - * @param[in] gb the GetBit context + * @param[in] bc the Bitstream context * @param[in,out] ctx ptr to the channel unit context * @param[in] num_channels number of channels to process * @param[in] avctx ptr to the AVCodecContext * @return result code: 0 = OK, otherwise - error code */ -static int decode_code_table_indexes(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, +static int decode_code_table_indexes(BitstreamContext *bc, Atrac3pChanUnitCtx *ctx, int num_channels, AVCodecContext *avctx) { int ch_num, ret; @@ -784,13 +785,13 @@ static int decode_code_table_indexes(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, if (!ctx->used_quant_units) return 0; - ctx->use_full_table = get_bits1(gb); + ctx->use_full_table = bitstream_read_bit(bc); for (ch_num = 0; ch_num < num_channels; ch_num++) { memset(ctx->channels[ch_num].qu_tab_idx, 0, sizeof(ctx->channels[ch_num].qu_tab_idx)); - if ((ret = decode_channel_code_tab(gb, ctx, ch_num, avctx)) < 0) + if ((ret = decode_channel_code_tab(bc, ctx, ch_num, avctx)) < 0) return ret; } @@ -803,13 +804,13 @@ static int decode_code_table_indexes(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, * This is a generalized version for all known coding modes. * Its speed can be improved by creating separate functions for each mode. * - * @param[in] gb the GetBit context + * @param[in] bc the Bitstream context * @param[in] tab code table telling how to decode spectral lines * @param[in] vlc_tab ptr to the huffman table associated with the code table * @param[out] out pointer to buffer where decoded data should be stored * @param[in] num_specs number of spectral lines to decode */ -static void decode_qu_spectra(GetBitContext *gb, const Atrac3pSpecCodeTab *tab, +static void decode_qu_spectra(BitstreamContext *bc, const Atrac3pSpecCodeTab *tab, VLC *vlc_tab, int16_t *out, const int num_specs) { int i, j, pos, cf; @@ -820,15 +821,15 @@ static void decode_qu_spectra(GetBitContext *gb, const Atrac3pSpecCodeTab *tab, unsigned val, mask = (1 << bits) - 1; for (pos = 0; pos < num_specs;) { - if (group_size == 1 || get_bits1(gb)) { + if (group_size == 1 || bitstream_read_bit(bc)) { for (j = 0; j < group_size; j++) { - val = get_vlc2(gb, vlc_tab->table, vlc_tab->bits, 1); + val = bitstream_read_vlc(bc, vlc_tab->table, vlc_tab->bits, 1); for (i = 0; i < num_coeffs; i++) { cf = val & mask; if (is_signed) cf = sign_extend(cf, bits); - else if (cf && get_bits1(gb)) + else if (cf && bitstream_read_bit(bc)) cf = -cf; out[pos++] = cf; @@ -843,12 +844,12 @@ static void decode_qu_spectra(GetBitContext *gb, const Atrac3pSpecCodeTab *tab, /** * Decode huffman-coded IMDCT spectrum for all channels. * - * @param[in] gb the GetBit context + * @param[in] bc the Bitstream context * @param[in,out] ctx ptr to the channel unit context * @param[in] num_channels number of channels to process * @param[in] avctx ptr to the AVCodecContext */ -static void decode_spectrum(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, +static void decode_spectrum(BitstreamContext *bc, Atrac3pChanUnitCtx *ctx, int num_channels, AVCodecContext *avctx) { int i, ch_num, qu, wordlen, codetab, tab_index, num_specs; @@ -880,7 +881,7 @@ static void decode_spectrum(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, if (tab->redirect >= 0) tab_index = tab->redirect; - decode_qu_spectra(gb, tab, &spec_vlc_tabs[tab_index], + decode_qu_spectra(bc, tab, &spec_vlc_tabs[tab_index], &chan->spectrum[ff_atrac3p_qu_to_spec_pos[qu]], num_specs); } else if (ch_num && ctx->channels[0].qu_wordlen[qu] && !codetab) { @@ -900,7 +901,7 @@ static void decode_spectrum(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, if (ctx->used_quant_units > 2) { num_specs = atrac3p_subband_to_num_powgrps[ctx->num_coded_subbands - 1]; for (i = 0; i < num_specs; i++) - chan->power_levs[i] = get_bits(gb, 4); + chan->power_levs[i] = bitstream_read(bc, 4); } } } @@ -913,22 +914,22 @@ static void decode_spectrum(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, * Otherwise, all necessary bits will be directly stored * prefixed by two signal bits = 1,1. * - * @param[in] gb ptr to the GetBitContext + * @param[in] bc ptr to the BitstreamContext * @param[out] out where to place decoded flags * @param[in] num_flags number of flags to process * @return: 0 = all flag bits are zero, 1 = there is at least one non-zero flag bit */ -static int get_subband_flags(GetBitContext *gb, uint8_t *out, int num_flags) +static int get_subband_flags(BitstreamContext *bc, uint8_t *out, int num_flags) { int i, result; memset(out, 0, num_flags); - result = get_bits1(gb); + result = bitstream_read_bit(bc); if (result) { - if (get_bits1(gb)) + if (bitstream_read_bit(bc)) for (i = 0; i < num_flags; i++) - out[i] = get_bits1(gb); + out[i] = bitstream_read_bit(bc); else memset(out, 1, num_flags); } @@ -939,63 +940,63 @@ static int get_subband_flags(GetBitContext *gb, uint8_t *out, int num_flags) /** * Decode mdct window shape flags for all channels. * - * @param[in] gb the GetBit context + * @param[in] bc the Bitstream context * @param[in,out] ctx ptr to the channel unit context * @param[in] num_channels number of channels to process */ -static void decode_window_shape(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, +static void decode_window_shape(BitstreamContext *bc, Atrac3pChanUnitCtx *ctx, int num_channels) { int ch_num; for (ch_num = 0; ch_num < num_channels; ch_num++) - get_subband_flags(gb, ctx->channels[ch_num].wnd_shape, + get_subband_flags(bc, ctx->channels[ch_num].wnd_shape, ctx->num_subbands); } /** * Decode number of gain control points. * - * @param[in] gb the GetBit context + * @param[in] bc the Bitstream context * @param[in,out] ctx ptr to the channel unit context * @param[in] ch_num channel to process * @param[in] coded_subbands number of subbands to process * @return result code: 0 = OK, otherwise - error code */ -static int decode_gainc_npoints(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, +static int decode_gainc_npoints(BitstreamContext *bc, Atrac3pChanUnitCtx *ctx, int ch_num, int coded_subbands) { int i, delta, delta_bits, min_val; Atrac3pChanParams *chan = &ctx->channels[ch_num]; Atrac3pChanParams *ref_chan = &ctx->channels[0]; - switch (get_bits(gb, 2)) { /* switch according to coding mode */ + switch (bitstream_read(bc, 2)) { /* switch according to coding mode */ case 0: /* fixed-length coding */ for (i = 0; i < coded_subbands; i++) - chan->gain_data[i].num_points = get_bits(gb, 3); + chan->gain_data[i].num_points = bitstream_read(bc, 3); break; case 1: /* variable-length coding */ for (i = 0; i < coded_subbands; i++) chan->gain_data[i].num_points = - get_vlc2(gb, gain_vlc_tabs[0].table, - gain_vlc_tabs[0].bits, 1); + bitstream_read_vlc(bc, gain_vlc_tabs[0].table, + gain_vlc_tabs[0].bits, 1); break; case 2: if (ch_num) { /* VLC modulo delta to master channel */ for (i = 0; i < coded_subbands; i++) { - delta = get_vlc2(gb, gain_vlc_tabs[1].table, - gain_vlc_tabs[1].bits, 1); + delta = bitstream_read_vlc(bc, gain_vlc_tabs[1].table, + gain_vlc_tabs[1].bits, 1); chan->gain_data[i].num_points = (ref_chan->gain_data[i].num_points + delta) & 7; } } else { /* VLC modulo delta to previous */ chan->gain_data[0].num_points = - get_vlc2(gb, gain_vlc_tabs[0].table, - gain_vlc_tabs[0].bits, 1); + bitstream_read_vlc(bc, gain_vlc_tabs[0].table, + gain_vlc_tabs[0].bits, 1); for (i = 1; i < coded_subbands; i++) { - delta = get_vlc2(gb, gain_vlc_tabs[1].table, - gain_vlc_tabs[1].bits, 1); + delta = bitstream_read_vlc(bc, gain_vlc_tabs[1].table, + gain_vlc_tabs[1].bits, 1); chan->gain_data[i].num_points = (chan->gain_data[i - 1].num_points + delta) & 7; } @@ -1007,11 +1008,11 @@ static int decode_gainc_npoints(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, chan->gain_data[i].num_points = ref_chan->gain_data[i].num_points; } else { /* shorter delta to min */ - delta_bits = get_bits(gb, 2); - min_val = get_bits(gb, 3); + delta_bits = bitstream_read(bc, 2); + min_val = bitstream_read(bc, 3); for (i = 0; i < coded_subbands; i++) { - chan->gain_data[i].num_points = min_val + get_bitsz(gb, delta_bits); + chan->gain_data[i].num_points = min_val + bitstream_read(bc, delta_bits); if (chan->gain_data[i].num_points > 7) return AVERROR_INVALIDDATA; } @@ -1038,23 +1039,23 @@ static inline void gainc_level_mode3s(AtracGainInfo *dst, AtracGainInfo *ref) /** * Implements coding mode 1 (master) for gain compensation levels. * - * @param[in] gb the GetBit context + * @param[in] bc the Bitstream context * @param[in] ctx ptr to the channel unit context * @param[out] dst ptr to the output array */ -static inline void gainc_level_mode1m(GetBitContext *gb, +static inline void gainc_level_mode1m(BitstreamContext *bc, Atrac3pChanUnitCtx *ctx, AtracGainInfo *dst) { int i, delta; if (dst->num_points > 0) - dst->lev_code[0] = get_vlc2(gb, gain_vlc_tabs[2].table, - gain_vlc_tabs[2].bits, 1); + dst->lev_code[0] = bitstream_read_vlc(bc, gain_vlc_tabs[2].table, + gain_vlc_tabs[2].bits, 1); for (i = 1; i < dst->num_points; i++) { - delta = get_vlc2(gb, gain_vlc_tabs[3].table, - gain_vlc_tabs[3].bits, 1); + delta = bitstream_read_vlc(bc, gain_vlc_tabs[3].table, + gain_vlc_tabs[3].bits, 1); dst->lev_code[i] = (dst->lev_code[i - 1] + delta) & 0xF; } } @@ -1062,58 +1063,58 @@ static inline void gainc_level_mode1m(GetBitContext *gb, /** * Decode level code for each gain control point. * - * @param[in] gb the GetBit context + * @param[in] bc the Bitstream context * @param[in,out] ctx ptr to the channel unit context * @param[in] ch_num channel to process * @param[in] coded_subbands number of subbands to process * @return result code: 0 = OK, otherwise - error code */ -static int decode_gainc_levels(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, +static int decode_gainc_levels(BitstreamContext *bc, Atrac3pChanUnitCtx *ctx, int ch_num, int coded_subbands) { int sb, i, delta, delta_bits, min_val, pred; Atrac3pChanParams *chan = &ctx->channels[ch_num]; Atrac3pChanParams *ref_chan = &ctx->channels[0]; - switch (get_bits(gb, 2)) { /* switch according to coding mode */ + switch (bitstream_read(bc, 2)) { /* switch according to coding mode */ case 0: /* fixed-length coding */ for (sb = 0; sb < coded_subbands; sb++) for (i = 0; i < chan->gain_data[sb].num_points; i++) - chan->gain_data[sb].lev_code[i] = get_bits(gb, 4); + chan->gain_data[sb].lev_code[i] = bitstream_read(bc, 4); break; case 1: if (ch_num) { /* VLC modulo delta to master channel */ for (sb = 0; sb < coded_subbands; sb++) for (i = 0; i < chan->gain_data[sb].num_points; i++) { - delta = get_vlc2(gb, gain_vlc_tabs[5].table, - gain_vlc_tabs[5].bits, 1); + delta = bitstream_read_vlc(bc, gain_vlc_tabs[5].table, + gain_vlc_tabs[5].bits, 1); pred = (i >= ref_chan->gain_data[sb].num_points) ? 7 : ref_chan->gain_data[sb].lev_code[i]; chan->gain_data[sb].lev_code[i] = (pred + delta) & 0xF; } } else { /* VLC modulo delta to previous */ for (sb = 0; sb < coded_subbands; sb++) - gainc_level_mode1m(gb, ctx, &chan->gain_data[sb]); + gainc_level_mode1m(bc, ctx, &chan->gain_data[sb]); } break; case 2: if (ch_num) { /* VLC modulo delta to previous or clone master */ for (sb = 0; sb < coded_subbands; sb++) if (chan->gain_data[sb].num_points > 0) { - if (get_bits1(gb)) - gainc_level_mode1m(gb, ctx, &chan->gain_data[sb]); + if (bitstream_read_bit(bc)) + gainc_level_mode1m(bc, ctx, &chan->gain_data[sb]); else gainc_level_mode3s(&chan->gain_data[sb], &ref_chan->gain_data[sb]); } } else { /* VLC modulo delta to lev_codes of previous subband */ if (chan->gain_data[0].num_points > 0) - gainc_level_mode1m(gb, ctx, &chan->gain_data[0]); + gainc_level_mode1m(bc, ctx, &chan->gain_data[0]); for (sb = 1; sb < coded_subbands; sb++) for (i = 0; i < chan->gain_data[sb].num_points; i++) { - delta = get_vlc2(gb, gain_vlc_tabs[4].table, - gain_vlc_tabs[4].bits, 1); + delta = bitstream_read_vlc(bc, gain_vlc_tabs[4].table, + gain_vlc_tabs[4].bits, 1); pred = (i >= chan->gain_data[sb - 1].num_points) ? 7 : chan->gain_data[sb - 1].lev_code[i]; chan->gain_data[sb].lev_code[i] = (pred + delta) & 0xF; @@ -1126,12 +1127,12 @@ static int decode_gainc_levels(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, gainc_level_mode3s(&chan->gain_data[sb], &ref_chan->gain_data[sb]); } else { /* shorter delta to min */ - delta_bits = get_bits(gb, 2); - min_val = get_bits(gb, 4); + delta_bits = bitstream_read(bc, 2); + min_val = bitstream_read(bc, 4); for (sb = 0; sb < coded_subbands; sb++) for (i = 0; i < chan->gain_data[sb].num_points; i++) { - chan->gain_data[sb].lev_code[i] = min_val + get_bitsz(gb, delta_bits); + chan->gain_data[sb].lev_code[i] = min_val + bitstream_read(bc, delta_bits); if (chan->gain_data[sb].lev_code[i] > 15) return AVERROR_INVALIDDATA; } @@ -1145,35 +1146,35 @@ static int decode_gainc_levels(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, /** * Implements coding mode 0 for gain compensation locations. * - * @param[in] gb the GetBit context + * @param[in] bc the Bitstream context * @param[in] ctx ptr to the channel unit context * @param[out] dst ptr to the output array * @param[in] pos position of the value to be processed */ -static inline void gainc_loc_mode0(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, +static inline void gainc_loc_mode0(BitstreamContext *bc, Atrac3pChanUnitCtx *ctx, AtracGainInfo *dst, int pos) { int delta_bits; if (!pos || dst->loc_code[pos - 1] < 15) - dst->loc_code[pos] = get_bits(gb, 5); + dst->loc_code[pos] = bitstream_read(bc, 5); else if (dst->loc_code[pos - 1] >= 30) dst->loc_code[pos] = 31; else { delta_bits = av_log2(30 - dst->loc_code[pos - 1]) + 1; dst->loc_code[pos] = dst->loc_code[pos - 1] + - get_bits(gb, delta_bits) + 1; + bitstream_read(bc, delta_bits) + 1; } } /** * Implements coding mode 1 for gain compensation locations. * - * @param[in] gb the GetBit context + * @param[in] bc the Bitstream context * @param[in] ctx ptr to the channel unit context * @param[out] dst ptr to the output array */ -static inline void gainc_loc_mode1(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, +static inline void gainc_loc_mode1(BitstreamContext *bc, Atrac3pChanUnitCtx *ctx, AtracGainInfo *dst) { int i; @@ -1181,7 +1182,7 @@ static inline void gainc_loc_mode1(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, if (dst->num_points > 0) { /* 1st coefficient is stored directly */ - dst->loc_code[0] = get_bits(gb, 5); + dst->loc_code[0] = bitstream_read(bc, 5); for (i = 1; i < dst->num_points; i++) { /* switch VLC according to the curve direction @@ -1190,7 +1191,7 @@ static inline void gainc_loc_mode1(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, ? &gain_vlc_tabs[7] : &gain_vlc_tabs[9]; dst->loc_code[i] = dst->loc_code[i - 1] + - get_vlc2(gb, tab->table, tab->bits, 1); + bitstream_read_vlc(bc, tab->table, tab->bits, 1); } } } @@ -1198,14 +1199,14 @@ static inline void gainc_loc_mode1(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, /** * Decode location code for each gain control point. * - * @param[in] gb the GetBit context + * @param[in] bc the Bitstream context * @param[in,out] ctx ptr to the channel unit context * @param[in] ch_num channel to process * @param[in] coded_subbands number of subbands to process * @param[in] avctx ptr to the AVCodecContext * @return result code: 0 = OK, otherwise - error code */ -static int decode_gainc_loc_codes(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, +static int decode_gainc_loc_codes(BitstreamContext *bc, Atrac3pChanUnitCtx *ctx, int ch_num, int coded_subbands, AVCodecContext *avctx) { @@ -1215,11 +1216,11 @@ static int decode_gainc_loc_codes(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, Atrac3pChanParams *chan = &ctx->channels[ch_num]; Atrac3pChanParams *ref_chan = &ctx->channels[0]; - switch (get_bits(gb, 2)) { /* switch according to coding mode */ + switch (bitstream_read(bc, 2)) { /* switch according to coding mode */ case 0: /* sequence of numbers in ascending order */ for (sb = 0; sb < coded_subbands; sb++) for (i = 0; i < chan->gain_data[sb].num_points; i++) - gainc_loc_mode0(gb, ctx, &chan->gain_data[sb], i); + gainc_loc_mode0(bc, ctx, &chan->gain_data[sb], i); break; case 1: if (ch_num) { @@ -1230,8 +1231,8 @@ static int decode_gainc_loc_codes(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, ref = &ref_chan->gain_data[sb]; /* 1st value is vlc-coded modulo delta to master */ - delta = get_vlc2(gb, gain_vlc_tabs[10].table, - gain_vlc_tabs[10].bits, 1); + delta = bitstream_read_vlc(bc, gain_vlc_tabs[10].table, + gain_vlc_tabs[10].bits, 1); pred = ref->num_points > 0 ? ref->loc_code[0] : 0; dst->loc_code[0] = (pred + delta) & 0x1F; @@ -1241,19 +1242,19 @@ static int decode_gainc_loc_codes(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, /* ascending curve */ if (more_than_ref) { delta = - get_vlc2(gb, gain_vlc_tabs[9].table, - gain_vlc_tabs[9].bits, 1); + bitstream_read_vlc(bc, gain_vlc_tabs[9].table, + gain_vlc_tabs[9].bits, 1); dst->loc_code[i] = dst->loc_code[i - 1] + delta; } else { - if (get_bits1(gb)) - gainc_loc_mode0(gb, ctx, dst, i); // direct coding + if (bitstream_read_bit(bc)) + gainc_loc_mode0(bc, ctx, dst, i); // direct coding else dst->loc_code[i] = ref->loc_code[i]; // clone master } } else { /* descending curve */ tab = more_than_ref ? &gain_vlc_tabs[7] : &gain_vlc_tabs[10]; - delta = get_vlc2(gb, tab->table, tab->bits, 1); + delta = bitstream_read_vlc(bc, tab->table, tab->bits, 1); if (more_than_ref) dst->loc_code[i] = dst->loc_code[i - 1] + delta; else @@ -1263,7 +1264,7 @@ static int decode_gainc_loc_codes(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, } } else /* VLC delta to previous */ for (sb = 0; sb < coded_subbands; sb++) - gainc_loc_mode1(gb, ctx, &chan->gain_data[sb]); + gainc_loc_mode1(bc, ctx, &chan->gain_data[sb]); break; case 2: if (ch_num) { @@ -1272,8 +1273,8 @@ static int decode_gainc_loc_codes(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, continue; dst = &chan->gain_data[sb]; ref = &ref_chan->gain_data[sb]; - if (dst->num_points > ref->num_points || get_bits1(gb)) - gainc_loc_mode1(gb, ctx, dst); + if (dst->num_points > ref->num_points || bitstream_read_bit(bc)) + gainc_loc_mode1(bc, ctx, dst); else /* clone master for the whole subband */ for (i = 0; i < chan->gain_data[sb].num_points; i++) dst->loc_code[i] = ref->loc_code[i]; @@ -1281,7 +1282,7 @@ static int decode_gainc_loc_codes(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, } else { /* data for the first subband is coded directly */ for (i = 0; i < chan->gain_data[0].num_points; i++) - gainc_loc_mode0(gb, ctx, &chan->gain_data[0], i); + gainc_loc_mode0(bc, ctx, &chan->gain_data[0], i); for (sb = 1; sb < coded_subbands; sb++) { if (chan->gain_data[sb].num_points <= 0) @@ -1290,8 +1291,8 @@ static int decode_gainc_loc_codes(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, /* 1st value is vlc-coded modulo delta to the corresponding * value of the previous subband if any or zero */ - delta = get_vlc2(gb, gain_vlc_tabs[6].table, - gain_vlc_tabs[6].bits, 1); + delta = bitstream_read_vlc(bc, gain_vlc_tabs[6].table, + gain_vlc_tabs[6].bits, 1); pred = dst[-1].num_points > 0 ? dst[-1].loc_code[0] : 0; dst->loc_code[0] = (pred + delta) & 0x1F; @@ -1302,7 +1303,7 @@ static int decode_gainc_loc_codes(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, * presence of prediction. */ tab = &gain_vlc_tabs[(dst->lev_code[i] > dst->lev_code[i - 1]) * 2 + more_than_ref + 6]; - delta = get_vlc2(gb, tab->table, tab->bits, 1); + delta = bitstream_read_vlc(bc, tab->table, tab->bits, 1); if (more_than_ref) dst->loc_code[i] = dst->loc_code[i - 1] + delta; else @@ -1316,19 +1317,19 @@ static int decode_gainc_loc_codes(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, for (sb = 0; sb < coded_subbands; sb++) for (i = 0; i < chan->gain_data[sb].num_points; i++) { if (i >= ref_chan->gain_data[sb].num_points) - gainc_loc_mode0(gb, ctx, &chan->gain_data[sb], i); + gainc_loc_mode0(bc, ctx, &chan->gain_data[sb], i); else chan->gain_data[sb].loc_code[i] = ref_chan->gain_data[sb].loc_code[i]; } } else { /* shorter delta to min */ - delta_bits = get_bits(gb, 2) + 1; - min_val = get_bits(gb, 5); + delta_bits = bitstream_read(bc, 2) + 1; + min_val = bitstream_read(bc, 5); for (sb = 0; sb < coded_subbands; sb++) for (i = 0; i < chan->gain_data[sb].num_points; i++) chan->gain_data[sb].loc_code[i] = min_val + i + - get_bits(gb, delta_bits); + bitstream_read(bc, delta_bits); } break; } @@ -1353,13 +1354,13 @@ static int decode_gainc_loc_codes(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, /** * Decode gain control data for all channels. * - * @param[in] gb the GetBit context + * @param[in] bc the Bitstream context * @param[in,out] ctx ptr to the channel unit context * @param[in] num_channels number of channels to process * @param[in] avctx ptr to the AVCodecContext * @return result code: 0 = OK, otherwise - error code */ -static int decode_gainc_data(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, +static int decode_gainc_data(BitstreamContext *bc, Atrac3pChanUnitCtx *ctx, int num_channels, AVCodecContext *avctx) { int ch_num, coded_subbands, sb, ret; @@ -1368,16 +1369,16 @@ static int decode_gainc_data(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, memset(ctx->channels[ch_num].gain_data, 0, sizeof(*ctx->channels[ch_num].gain_data) * ATRAC3P_SUBBANDS); - if (get_bits1(gb)) { /* gain control data present? */ - coded_subbands = get_bits(gb, 4) + 1; - if (get_bits1(gb)) /* is high band gain data replication on? */ - ctx->channels[ch_num].num_gain_subbands = get_bits(gb, 4) + 1; + if (bitstream_read_bit(bc)) { /* gain control data present? */ + coded_subbands = bitstream_read(bc, 4) + 1; + if (bitstream_read_bit(bc)) /* is high band gain data replication on? */ + ctx->channels[ch_num].num_gain_subbands = bitstream_read(bc, 4) + 1; else ctx->channels[ch_num].num_gain_subbands = coded_subbands; - if ((ret = decode_gainc_npoints(gb, ctx, ch_num, coded_subbands)) < 0 || - (ret = decode_gainc_levels(gb, ctx, ch_num, coded_subbands)) < 0 || - (ret = decode_gainc_loc_codes(gb, ctx, ch_num, coded_subbands, avctx)) < 0) + if ((ret = decode_gainc_npoints(bc, ctx, ch_num, coded_subbands)) < 0 || + (ret = decode_gainc_levels(bc, ctx, ch_num, coded_subbands)) < 0 || + (ret = decode_gainc_loc_codes(bc, ctx, ch_num, coded_subbands, avctx)) < 0) return ret; if (coded_subbands > 0) { /* propagate gain data if requested */ @@ -1396,29 +1397,29 @@ static int decode_gainc_data(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, /** * Decode envelope for all tones of a channel. * - * @param[in] gb the GetBit context + * @param[in] bc the Bitstream context * @param[in,out] ctx ptr to the channel unit context * @param[in] ch_num channel to process * @param[in] band_has_tones ptr to an array of per-band-flags: * 1 - tone data present */ -static void decode_tones_envelope(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, +static void decode_tones_envelope(BitstreamContext *bc, Atrac3pChanUnitCtx *ctx, int ch_num, int band_has_tones[]) { int sb; Atrac3pWavesData *dst = ctx->channels[ch_num].tones_info; Atrac3pWavesData *ref = ctx->channels[0].tones_info; - if (!ch_num || !get_bits1(gb)) { /* mode 0: fixed-length coding */ + if (!ch_num || !bitstream_read_bit(bc)) { /* mode 0: fixed-length coding */ for (sb = 0; sb < ctx->waves_info->num_tone_bands; sb++) { if (!band_has_tones[sb]) continue; - dst[sb].pend_env.has_start_point = get_bits1(gb); + dst[sb].pend_env.has_start_point = bitstream_read_bit(bc); dst[sb].pend_env.start_pos = dst[sb].pend_env.has_start_point - ? get_bits(gb, 5) : -1; - dst[sb].pend_env.has_stop_point = get_bits1(gb); + ? bitstream_read(bc, 5) : -1; + dst[sb].pend_env.has_stop_point = bitstream_read_bit(bc); dst[sb].pend_env.stop_pos = dst[sb].pend_env.has_stop_point - ? get_bits(gb, 5) : 32; + ? bitstream_read(bc, 5) : 32; } } else { /* mode 1(slave only): copy master */ for (sb = 0; sb < ctx->waves_info->num_tone_bands; sb++) { @@ -1435,7 +1436,7 @@ static void decode_tones_envelope(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, /** * Decode number of tones for each subband of a channel. * - * @param[in] gb the GetBit context + * @param[in] bc the Bitstream context * @param[in,out] ctx ptr to the channel unit context * @param[in] ch_num channel to process * @param[in] band_has_tones ptr to an array of per-band-flags: @@ -1443,7 +1444,7 @@ static void decode_tones_envelope(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, * @param[in] avctx ptr to the AVCodecContext * @return result code: 0 = OK, otherwise - error code */ -static int decode_band_numwavs(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, +static int decode_band_numwavs(BitstreamContext *bc, Atrac3pChanUnitCtx *ctx, int ch_num, int band_has_tones[], AVCodecContext *avctx) { @@ -1451,25 +1452,25 @@ static int decode_band_numwavs(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, Atrac3pWavesData *dst = ctx->channels[ch_num].tones_info; Atrac3pWavesData *ref = ctx->channels[0].tones_info; - mode = get_bits(gb, ch_num + 1); + mode = bitstream_read(bc, ch_num + 1); switch (mode) { case 0: /** fixed-length coding */ for (sb = 0; sb < ctx->waves_info->num_tone_bands; sb++) if (band_has_tones[sb]) - dst[sb].num_wavs = get_bits(gb, 4); + dst[sb].num_wavs = bitstream_read(bc, 4); break; case 1: /** variable-length coding */ for (sb = 0; sb < ctx->waves_info->num_tone_bands; sb++) if (band_has_tones[sb]) dst[sb].num_wavs = - get_vlc2(gb, tone_vlc_tabs[1].table, - tone_vlc_tabs[1].bits, 1); + bitstream_read_vlc(bc, tone_vlc_tabs[1].table, + tone_vlc_tabs[1].bits, 1); break; case 2: /** VLC modulo delta to master (slave only) */ for (sb = 0; sb < ctx->waves_info->num_tone_bands; sb++) if (band_has_tones[sb]) { - delta = get_vlc2(gb, tone_vlc_tabs[2].table, - tone_vlc_tabs[2].bits, 1); + delta = bitstream_read_vlc(bc, tone_vlc_tabs[2].table, + tone_vlc_tabs[2].bits, 1); delta = sign_extend(delta, 3); dst[sb].num_wavs = (ref[sb].num_wavs + delta) & 0xF; } @@ -1501,13 +1502,13 @@ static int decode_band_numwavs(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, /** * Decode frequency information for each subband of a channel. * - * @param[in] gb the GetBit context + * @param[in] bc the Bitstream context * @param[in,out] ctx ptr to the channel unit context * @param[in] ch_num channel to process * @param[in] band_has_tones ptr to an array of per-band-flags: * 1 - tone data present */ -static void decode_tones_frequency(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, +static void decode_tones_frequency(BitstreamContext *bc, Atrac3pChanUnitCtx *ctx, int ch_num, int band_has_tones[]) { int sb, i, direction, nbits, pred, delta; @@ -1515,26 +1516,26 @@ static void decode_tones_frequency(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, Atrac3pWavesData *dst = ctx->channels[ch_num].tones_info; Atrac3pWavesData *ref = ctx->channels[0].tones_info; - if (!ch_num || !get_bits1(gb)) { /* mode 0: fixed-length coding */ + if (!ch_num || !bitstream_read_bit(bc)) { /* mode 0: fixed-length coding */ for (sb = 0; sb < ctx->waves_info->num_tone_bands; sb++) { if (!band_has_tones[sb] || !dst[sb].num_wavs) continue; iwav = &ctx->waves_info->waves[dst[sb].start_index]; - direction = (dst[sb].num_wavs > 1) ? get_bits1(gb) : 0; + direction = (dst[sb].num_wavs > 1) ? bitstream_read_bit(bc) : 0; if (direction) { /** packed numbers in descending order */ if (dst[sb].num_wavs) - iwav[dst[sb].num_wavs - 1].freq_index = get_bits(gb, 10); + iwav[dst[sb].num_wavs - 1].freq_index = bitstream_read(bc, 10); for (i = dst[sb].num_wavs - 2; i >= 0 ; i--) { nbits = av_log2(iwav[i+1].freq_index) + 1; - iwav[i].freq_index = get_bits(gb, nbits); + iwav[i].freq_index = bitstream_read(bc, nbits); } } else { /** packed numbers in ascending order */ for (i = 0; i < dst[sb].num_wavs; i++) { if (!i || iwav[i - 1].freq_index < 512) - iwav[i].freq_index = get_bits(gb, 10); + iwav[i].freq_index = bitstream_read(bc, 10); else { nbits = av_log2(1023 - iwav[i - 1].freq_index) + 1; - iwav[i].freq_index = get_bits(gb, nbits) + + iwav[i].freq_index = bitstream_read(bc, nbits) + 1024 - (1 << nbits); } } @@ -1547,8 +1548,8 @@ static void decode_tones_frequency(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, iwav = &ctx->waves_info->waves[ref[sb].start_index]; owav = &ctx->waves_info->waves[dst[sb].start_index]; for (i = 0; i < dst[sb].num_wavs; i++) { - delta = get_vlc2(gb, tone_vlc_tabs[6].table, - tone_vlc_tabs[6].bits, 1); + delta = bitstream_read_vlc(bc, tone_vlc_tabs[6].table, + tone_vlc_tabs[6].bits, 1); delta = sign_extend(delta, 8); pred = (i < ref[sb].num_wavs) ? iwav[i].freq_index : (ref[sb].num_wavs ? iwav[ref[sb].num_wavs - 1].freq_index : 0); @@ -1561,13 +1562,13 @@ static void decode_tones_frequency(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, /** * Decode amplitude information for each subband of a channel. * - * @param[in] gb the GetBit context + * @param[in] bc the Bitstream context * @param[in,out] ctx ptr to the channel unit context * @param[in] ch_num channel to process * @param[in] band_has_tones ptr to an array of per-band-flags: * 1 - tone data present */ -static void decode_tones_amplitude(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, +static void decode_tones_amplitude(BitstreamContext *bc, Atrac3pChanUnitCtx *ctx, int ch_num, int band_has_tones[]) { int mode, sb, j, i, diff, maxdiff, fi, delta, pred; @@ -1601,7 +1602,7 @@ static void decode_tones_amplitude(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, } } - mode = get_bits(gb, ch_num + 1); + mode = bitstream_read(bc, ch_num + 1); switch (mode) { case 0: /** fixed-length coding */ @@ -1610,9 +1611,9 @@ static void decode_tones_amplitude(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, continue; if (ctx->waves_info->amplitude_mode) for (i = 0; i < dst[sb].num_wavs; i++) - ctx->waves_info->waves[dst[sb].start_index + i].amp_sf = get_bits(gb, 6); + ctx->waves_info->waves[dst[sb].start_index + i].amp_sf = bitstream_read(bc, 6); else - ctx->waves_info->waves[dst[sb].start_index].amp_sf = get_bits(gb, 6); + ctx->waves_info->waves[dst[sb].start_index].amp_sf = bitstream_read(bc, 6); } break; case 1: /** min + VLC delta */ @@ -1622,12 +1623,12 @@ static void decode_tones_amplitude(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, if (ctx->waves_info->amplitude_mode) for (i = 0; i < dst[sb].num_wavs; i++) ctx->waves_info->waves[dst[sb].start_index + i].amp_sf = - get_vlc2(gb, tone_vlc_tabs[3].table, - tone_vlc_tabs[3].bits, 1) + 20; + bitstream_read_vlc(bc, tone_vlc_tabs[3].table, + tone_vlc_tabs[3].bits, 1) + 20; else ctx->waves_info->waves[dst[sb].start_index].amp_sf = - get_vlc2(gb, tone_vlc_tabs[4].table, - tone_vlc_tabs[4].bits, 1) + 24; + bitstream_read_vlc(bc, tone_vlc_tabs[4].table, + tone_vlc_tabs[4].bits, 1) + 24; } break; case 2: /** VLC modulo delta to master (slave only) */ @@ -1635,8 +1636,8 @@ static void decode_tones_amplitude(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, if (!band_has_tones[sb] || !dst[sb].num_wavs) continue; for (i = 0; i < dst[sb].num_wavs; i++) { - delta = get_vlc2(gb, tone_vlc_tabs[5].table, - tone_vlc_tabs[5].bits, 1); + delta = bitstream_read_vlc(bc, tone_vlc_tabs[5].table, + tone_vlc_tabs[5].bits, 1); delta = sign_extend(delta, 5); pred = refwaves[dst[sb].start_index + i] >= 0 ? ctx->waves_info->waves[refwaves[dst[sb].start_index + i]].amp_sf : 34; @@ -1661,13 +1662,13 @@ static void decode_tones_amplitude(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, /** * Decode phase information for each subband of a channel. * - * @param[in] gb the GetBit context + * @param[in] bc the Bitstream context * @param[in,out] ctx ptr to the channel unit context * @param[in] ch_num channel to process * @param[in] band_has_tones ptr to an array of per-band-flags: * 1 - tone data present */ -static void decode_tones_phase(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, +static void decode_tones_phase(BitstreamContext *bc, Atrac3pChanUnitCtx *ctx, int ch_num, int band_has_tones[]) { int sb, i; @@ -1679,20 +1680,20 @@ static void decode_tones_phase(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, continue; wparam = &ctx->waves_info->waves[dst[sb].start_index]; for (i = 0; i < dst[sb].num_wavs; i++) - wparam[i].phase_index = get_bits(gb, 5); + wparam[i].phase_index = bitstream_read(bc, 5); } } /** * Decode tones info for all channels. * - * @param[in] gb the GetBit context + * @param[in] bc the Bitstream context * @param[in,out] ctx ptr to the channel unit context * @param[in] num_channels number of channels to process * @param[in] avctx ptr to the AVCodecContext * @return result code: 0 = OK, otherwise - error code */ -static int decode_tones_info(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, +static int decode_tones_info(BitstreamContext *bc, Atrac3pChanUnitCtx *ctx, int num_channels, AVCodecContext *avctx) { int ch_num, i, ret; @@ -1702,26 +1703,26 @@ static int decode_tones_info(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, memset(ctx->channels[ch_num].tones_info, 0, sizeof(*ctx->channels[ch_num].tones_info) * ATRAC3P_SUBBANDS); - ctx->waves_info->tones_present = get_bits1(gb); + ctx->waves_info->tones_present = bitstream_read_bit(bc); if (!ctx->waves_info->tones_present) return 0; memset(ctx->waves_info->waves, 0, sizeof(ctx->waves_info->waves)); - ctx->waves_info->amplitude_mode = get_bits1(gb); + ctx->waves_info->amplitude_mode = bitstream_read_bit(bc); if (!ctx->waves_info->amplitude_mode) { avpriv_report_missing_feature(avctx, "GHA amplitude mode 0"); return AVERROR_PATCHWELCOME; } ctx->waves_info->num_tone_bands = - get_vlc2(gb, tone_vlc_tabs[0].table, - tone_vlc_tabs[0].bits, 1) + 1; + bitstream_read_vlc(bc, tone_vlc_tabs[0].table, + tone_vlc_tabs[0].bits, 1) + 1; if (num_channels == 2) { - get_subband_flags(gb, ctx->waves_info->tone_sharing, ctx->waves_info->num_tone_bands); - get_subband_flags(gb, ctx->waves_info->tone_master, ctx->waves_info->num_tone_bands); - if (get_subband_flags(gb, ctx->waves_info->phase_shift, + get_subband_flags(bc, ctx->waves_info->tone_sharing, ctx->waves_info->num_tone_bands); + get_subband_flags(bc, ctx->waves_info->tone_master, ctx->waves_info->num_tone_bands); + if (get_subband_flags(bc, ctx->waves_info->phase_shift, ctx->waves_info->num_tone_bands)) { avpriv_report_missing_feature(avctx, "GHA Phase shifting"); return AVERROR_PATCHWELCOME; @@ -1734,14 +1735,14 @@ static int decode_tones_info(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, for (i = 0; i < ctx->waves_info->num_tone_bands; i++) band_has_tones[i] = !ch_num ? 1 : !ctx->waves_info->tone_sharing[i]; - decode_tones_envelope(gb, ctx, ch_num, band_has_tones); - if ((ret = decode_band_numwavs(gb, ctx, ch_num, band_has_tones, + decode_tones_envelope(bc, ctx, ch_num, band_has_tones); + if ((ret = decode_band_numwavs(bc, ctx, ch_num, band_has_tones, avctx)) < 0) return ret; - decode_tones_frequency(gb, ctx, ch_num, band_has_tones); - decode_tones_amplitude(gb, ctx, ch_num, band_has_tones); - decode_tones_phase(gb, ctx, ch_num, band_has_tones); + decode_tones_frequency(bc, ctx, ch_num, band_has_tones); + decode_tones_amplitude(bc, ctx, ch_num, band_has_tones); + decode_tones_phase(bc, ctx, ch_num, band_has_tones); } if (num_channels == 2) { @@ -1758,13 +1759,13 @@ static int decode_tones_info(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, return 0; } -int ff_atrac3p_decode_channel_unit(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, +int ff_atrac3p_decode_channel_unit(BitstreamContext *bc, Atrac3pChanUnitCtx *ctx, int num_channels, AVCodecContext *avctx) { int ret; /* parse sound header */ - ctx->num_quant_units = get_bits(gb, 5) + 1; + ctx->num_quant_units = bitstream_read(bc, 5) + 1; if (ctx->num_quant_units > 28 && ctx->num_quant_units < 32) { av_log(avctx, AV_LOG_ERROR, "Invalid number of quantization units: %d!\n", @@ -1772,10 +1773,10 @@ int ff_atrac3p_decode_channel_unit(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, return AVERROR_INVALIDDATA; } - ctx->mute_flag = get_bits1(gb); + ctx->mute_flag = bitstream_read_bit(bc); /* decode various sound parameters */ - if ((ret = decode_quant_wordlen(gb, ctx, num_channels, avctx)) < 0) + if ((ret = decode_quant_wordlen(bc, ctx, num_channels, avctx)) < 0) return ret; ctx->num_subbands = atrac3p_qu_to_subband[ctx->num_quant_units - 1] + 1; @@ -1783,32 +1784,32 @@ int ff_atrac3p_decode_channel_unit(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, ? atrac3p_qu_to_subband[ctx->used_quant_units - 1] + 1 : 0; - if ((ret = decode_scale_factors(gb, ctx, num_channels, avctx)) < 0) + if ((ret = decode_scale_factors(bc, ctx, num_channels, avctx)) < 0) return ret; - if ((ret = decode_code_table_indexes(gb, ctx, num_channels, avctx)) < 0) + if ((ret = decode_code_table_indexes(bc, ctx, num_channels, avctx)) < 0) return ret; - decode_spectrum(gb, ctx, num_channels, avctx); + decode_spectrum(bc, ctx, num_channels, avctx); if (num_channels == 2) { - get_subband_flags(gb, ctx->swap_channels, ctx->num_coded_subbands); - get_subband_flags(gb, ctx->negate_coeffs, ctx->num_coded_subbands); + get_subband_flags(bc, ctx->swap_channels, ctx->num_coded_subbands); + get_subband_flags(bc, ctx->negate_coeffs, ctx->num_coded_subbands); } - decode_window_shape(gb, ctx, num_channels); + decode_window_shape(bc, ctx, num_channels); - if ((ret = decode_gainc_data(gb, ctx, num_channels, avctx)) < 0) + if ((ret = decode_gainc_data(bc, ctx, num_channels, avctx)) < 0) return ret; - if ((ret = decode_tones_info(gb, ctx, num_channels, avctx)) < 0) + if ((ret = decode_tones_info(bc, ctx, num_channels, avctx)) < 0) return ret; /* decode global noise info */ - ctx->noise_present = get_bits1(gb); + ctx->noise_present = bitstream_read_bit(bc); if (ctx->noise_present) { - ctx->noise_level_index = get_bits(gb, 4); - ctx->noise_table_index = get_bits(gb, 4); + ctx->noise_level_index = bitstream_read(bc, 4); + ctx->noise_table_index = bitstream_read(bc, 4); } return 0; diff --git a/libavcodec/atrac3plus.h b/libavcodec/atrac3plus.h index e56c4441b6..cca399adab 100644 --- a/libavcodec/atrac3plus.h +++ b/libavcodec/atrac3plus.h @@ -31,10 +31,11 @@ #include #include "libavutil/float_dsp.h" + #include "atrac.h" +#include "bitstream.h" #include "avcodec.h" #include "fft.h" -#include "get_bits.h" /** Global unit sizes */ #define ATRAC3P_SUBBANDS 16 ///< number of PQF subbands @@ -163,13 +164,13 @@ void ff_atrac3p_init_vlcs(AVCodec *codec); /** * Decode bitstream data of a channel unit. * - * @param[in] gb the GetBit context + * @param[in] bc the Bitstream context * @param[in,out] ctx ptr to the channel unit context * @param[in] num_channels number of channels to process * @param[in] avctx ptr to the AVCodecContext * @return result code: 0 = OK, otherwise - error code */ -int ff_atrac3p_decode_channel_unit(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, +int ff_atrac3p_decode_channel_unit(BitstreamContext *bc, Atrac3pChanUnitCtx *ctx, int num_channels, AVCodecContext *avctx); /** diff --git a/libavcodec/atrac3plusdec.c b/libavcodec/atrac3plusdec.c index 4a742c159e..17774d5657 100644 --- a/libavcodec/atrac3plusdec.c +++ b/libavcodec/atrac3plusdec.c @@ -39,14 +39,15 @@ #include "libavutil/channel_layout.h" #include "libavutil/float_dsp.h" + #include "avcodec.h" -#include "get_bits.h" +#include "bitstream.h" #include "internal.h" #include "atrac.h" #include "atrac3plus.h" typedef struct ATRAC3PContext { - GetBitContext gb; + BitstreamContext bc; AVFloatDSPContext fdsp; DECLARE_ALIGNED(32, float, samples)[2][ATRAC3P_FRAME_SAMPLES]; ///< quantized MDCT spectrum @@ -334,16 +335,16 @@ static int atrac3p_decode_frame(AVCodecContext *avctx, void *data, return ret; } - if ((ret = init_get_bits8(&ctx->gb, avpkt->data, avpkt->size)) < 0) + if ((ret = bitstream_init8(&ctx->bc, avpkt->data, avpkt->size)) < 0) return ret; - if (get_bits1(&ctx->gb)) { + if (bitstream_read_bit(&ctx->bc)) { av_log(avctx, AV_LOG_ERROR, "Invalid start bit!\n"); return AVERROR_INVALIDDATA; } - while (get_bits_left(&ctx->gb) >= 2 && - (ch_unit_id = get_bits(&ctx->gb, 2)) != CH_UNIT_TERMINATOR) { + while (bitstream_bits_left(&ctx->bc) >= 2 && + (ch_unit_id = bitstream_read(&ctx->bc, 2)) != CH_UNIT_TERMINATOR) { if (ch_unit_id == CH_UNIT_EXTENSION) { avpriv_report_missing_feature(avctx, "Channel unit extension"); return AVERROR_PATCHWELCOME; @@ -358,7 +359,7 @@ static int atrac3p_decode_frame(AVCodecContext *avctx, void *data, ctx->ch_units[ch_block].unit_type = ch_unit_id; channels_to_process = ch_unit_id + 1; - if ((ret = ff_atrac3p_decode_channel_unit(&ctx->gb, + if ((ret = ff_atrac3p_decode_channel_unit(&ctx->bc, &ctx->ch_units[ch_block], channels_to_process, avctx)) < 0)