From 7d8075cf471459dee372595c74b7f28cb4e9a05d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandra=20H=C3=A1jkov=C3=A1?= Date: Wed, 13 Apr 2016 11:53:47 +0200 Subject: [PATCH 01/20] ra144: Convert to the new bitstream reader --- libavcodec/ra144dec.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/libavcodec/ra144dec.c b/libavcodec/ra144dec.c index 289535741f..35ee697731 100644 --- a/libavcodec/ra144dec.c +++ b/libavcodec/ra144dec.c @@ -23,8 +23,9 @@ */ #include "libavutil/channel_layout.h" + #include "avcodec.h" -#include "get_bits.h" +#include "bitstream.h" #include "internal.h" #include "ra144.h" @@ -46,12 +47,12 @@ static av_cold int ra144_decode_init(AVCodecContext * avctx) } static void do_output_subblock(RA144Context *ractx, const uint16_t *lpc_coefs, - int gval, GetBitContext *gb) + int gval, BitstreamContext *bc) { - int cba_idx = get_bits(gb, 7); // index of the adaptive CB, 0 if none - int gain = get_bits(gb, 8); - int cb1_idx = get_bits(gb, 7); - int cb2_idx = get_bits(gb, 7); + int cba_idx = bitstream_read(bc, 7); // index of the adaptive CB, 0 if none + int gain = bitstream_read(bc, 8); + int cb1_idx = bitstream_read(bc, 7); + int cb2_idx = bitstream_read(bc, 7); ff_subblock_synthesis(ractx, lpc_coefs, cba_idx, cb1_idx, cb2_idx, gval, gain); @@ -74,7 +75,7 @@ static int ra144_decode_frame(AVCodecContext * avctx, void *data, unsigned int energy; RA144Context *ractx = avctx->priv_data; - GetBitContext gb; + BitstreamContext bc; if (buf_size < FRAMESIZE) { av_log(avctx, AV_LOG_ERROR, @@ -91,15 +92,15 @@ static int ra144_decode_frame(AVCodecContext * avctx, void *data, } samples = (int16_t *)frame->data[0]; - init_get_bits(&gb, buf, FRAMESIZE * 8); + bitstream_init(&bc, buf, FRAMESIZE * 8); for (i = 0; i < LPC_ORDER; i++) - lpc_refl[i] = ff_lpc_refl_cb[i][get_bits(&gb, sizes[i])]; + lpc_refl[i] = ff_lpc_refl_cb[i][bitstream_read(&bc, sizes[i])]; ff_eval_coefs(ractx->lpc_coef[0], lpc_refl); ractx->lpc_refl_rms[0] = ff_rms(lpc_refl); - energy = ff_energy_tab[get_bits(&gb, 5)]; + energy = ff_energy_tab[bitstream_read(&bc, 5)]; refl_rms[0] = ff_interp(ractx, block_coefs[0], 1, 1, ractx->old_energy); refl_rms[1] = ff_interp(ractx, block_coefs[1], 2, @@ -111,7 +112,7 @@ static int ra144_decode_frame(AVCodecContext * avctx, void *data, ff_int_to_int16(block_coefs[3], ractx->lpc_coef[0]); for (i=0; i < NBLOCKS; i++) { - do_output_subblock(ractx, block_coefs[i], refl_rms[i], &gb); + do_output_subblock(ractx, block_coefs[i], refl_rms[i], &bc); for (j=0; j < BLOCKSIZE; j++) *samples++ = av_clip_int16(ractx->curr_sblock[j + 10] << 2); From c60cda7cb476315fd7f6d28715316b1aff2e080a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandra=20H=C3=A1jkov=C3=A1?= Date: Wed, 13 Apr 2016 19:34:49 +0200 Subject: [PATCH 02/20] ra288: Convert to the new bitstream reader --- libavcodec/ra288.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/libavcodec/ra288.c b/libavcodec/ra288.c index 96d8d1ece1..bc3fe29dc1 100644 --- a/libavcodec/ra288.c +++ b/libavcodec/ra288.c @@ -25,8 +25,8 @@ #define BITSTREAM_READER_LE #include "avcodec.h" +#include "bitstream.h" #include "celp_filters.h" -#include "get_bits.h" #include "internal.h" #include "lpc.h" #include "ra288.h" @@ -181,7 +181,7 @@ static int ra288_decode_frame(AVCodecContext * avctx, void *data, float *out; int i, ret; RA288Context *ractx = avctx->priv_data; - GetBitContext gb; + BitstreamContext bc; if (buf_size < avctx->block_align) { av_log(avctx, AV_LOG_ERROR, @@ -198,11 +198,11 @@ static int ra288_decode_frame(AVCodecContext * avctx, void *data, } out = (float *)frame->data[0]; - init_get_bits(&gb, buf, avctx->block_align * 8); + bitstream_init(&bc, buf, avctx->block_align * 8); for (i=0; i < RA288_BLOCKS_PER_FRAME; i++) { - float gain = amptable[get_bits(&gb, 3)]; - int cb_coef = get_bits(&gb, 6 + (i&1)); + float gain = amptable[bitstream_read(&bc, 3)]; + int cb_coef = bitstream_read(&bc, 6 + (i & 1)); decode(ractx, gain, cb_coef); From f26cbb555b9547b7a532c7a0d883579a52815b1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandra=20H=C3=A1jkov=C3=A1?= Date: Wed, 13 Apr 2016 19:41:09 +0200 Subject: [PATCH 03/20] rtjpeg: Convert to the new bitstream reader --- libavcodec/rtjpeg.c | 42 +++++++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/libavcodec/rtjpeg.c b/libavcodec/rtjpeg.c index 67eeff8f4a..baa1f7857d 100644 --- a/libavcodec/rtjpeg.c +++ b/libavcodec/rtjpeg.c @@ -18,8 +18,10 @@ * License along with Libav; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ + #include "libavutil/common.h" -#include "get_bits.h" + +#include "bitstream.h" #include "rtjpeg.h" #define PUT_COEFF(c) \ @@ -28,34 +30,36 @@ /// aligns the bitstream to the given power of two #define ALIGN(a) \ - n = (-get_bits_count(gb)) & (a - 1); \ - if (n) {skip_bits(gb, n);} + n = (-bitstream_tell(bc)) & (a - 1); \ + if (n) \ + bitstream_skip(bc, n); /** * @brief read one block from stream - * @param gb contains stream data + * @param bc contains stream data * @param block where data is written to * @param scan array containing the mapping stream address -> block position * @param quant quantization factors * @return 0 means the block is not coded, < 0 means an error occurred. * - * Note: GetBitContext is used to make the code simpler, since all data is + * Note: BitstreamContext is used to make the code simpler, since all data is * aligned this could be done faster in a different way, e.g. as it is done * in MPlayer libmpcodecs/native/rtjpegn.c. */ -static inline int get_block(GetBitContext *gb, int16_t *block, const uint8_t *scan, - const uint32_t *quant) { +static inline int get_block(BitstreamContext *bc, int16_t *block, + const uint8_t *scan, const uint32_t *quant) +{ int coeff, i, n; int8_t ac; - uint8_t dc = get_bits(gb, 8); + uint8_t dc = bitstream_read(bc, 8); // block not coded if (dc == 255) return 0; // number of non-zero coefficients - coeff = get_bits(gb, 6); - if (get_bits_left(gb) < (coeff << 1)) + coeff = bitstream_read(bc, 6); + if (bitstream_bits_left(bc) < (coeff << 1)) return AVERROR_INVALIDDATA; // normally we would only need to clear the (63 - coeff) last values, @@ -64,7 +68,7 @@ static inline int get_block(GetBitContext *gb, int16_t *block, const uint8_t *sc // 2 bits per coefficient while (coeff) { - ac = get_sbits(gb, 2); + ac = bitstream_read_signed(bc, 2); if (ac == -2) break; // continue with more bits PUT_COEFF(ac); @@ -72,10 +76,10 @@ static inline int get_block(GetBitContext *gb, int16_t *block, const uint8_t *sc // 4 bits per coefficient ALIGN(4); - if (get_bits_left(gb) < (coeff << 2)) + if (bitstream_bits_left(bc) < (coeff << 2)) return AVERROR_INVALIDDATA; while (coeff) { - ac = get_sbits(gb, 4); + ac = bitstream_read_signed(bc, 4); if (ac == -8) break; // continue with more bits PUT_COEFF(ac); @@ -83,10 +87,10 @@ static inline int get_block(GetBitContext *gb, int16_t *block, const uint8_t *sc // 8 bits per coefficient ALIGN(8); - if (get_bits_left(gb) < (coeff << 3)) + if (bitstream_bits_left(bc) < (coeff << 3)) return AVERROR_INVALIDDATA; while (coeff) { - ac = get_sbits(gb, 8); + ac = bitstream_read_signed(bc, 8); PUT_COEFF(ac); } @@ -105,19 +109,19 @@ static inline int get_block(GetBitContext *gb, int16_t *block, const uint8_t *sc */ int ff_rtjpeg_decode_frame_yuv420(RTJpegContext *c, AVFrame *f, const uint8_t *buf, int buf_size) { - GetBitContext gb; + BitstreamContext bc; int w = c->w / 16, h = c->h / 16; int x, y, ret; uint8_t *y1 = f->data[0], *y2 = f->data[0] + 8 * f->linesize[0]; uint8_t *u = f->data[1], *v = f->data[2]; - if ((ret = init_get_bits8(&gb, buf, buf_size)) < 0) + if ((ret = bitstream_init8(&bc, buf, buf_size)) < 0) return ret; for (y = 0; y < h; y++) { for (x = 0; x < w; x++) { #define BLOCK(quant, dst, stride) do { \ - int res = get_block(&gb, block, c->scan, quant); \ + int res = get_block(&bc, block, c->scan, quant); \ if (res < 0) \ return res; \ if (res > 0) \ @@ -142,7 +146,7 @@ int ff_rtjpeg_decode_frame_yuv420(RTJpegContext *c, AVFrame *f, u += 8 * (f->linesize[1] - w); v += 8 * (f->linesize[2] - w); } - return get_bits_count(&gb) / 8; + return bitstream_tell(&bc) / 8; } /** From 087bc8d70415b3b50db4dbf5adf49cf071281874 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandra=20H=C3=A1jkov=C3=A1?= Date: Wed, 13 Apr 2016 19:49:21 +0200 Subject: [PATCH 04/20] sipr: Convert to the new bitstream reader --- libavcodec/sipr.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/libavcodec/sipr.c b/libavcodec/sipr.c index 686b3e2154..cf29d3bba7 100644 --- a/libavcodec/sipr.c +++ b/libavcodec/sipr.c @@ -31,7 +31,7 @@ #define BITSTREAM_READER_LE #include "avcodec.h" -#include "get_bits.h" +#include "bitstream.h" #include "internal.h" #include "lsp.h" #include "acelp_vectors.h" @@ -188,28 +188,28 @@ static void pitch_sharpening(int pitch_lag_int, float beta, /** * Extract decoding parameters from the input bitstream. * @param parms parameters structure - * @param pgb pointer to initialized GetBitContext structure + * @param bc pointer to initialized BitstreamContext structure */ -static void decode_parameters(SiprParameters* parms, GetBitContext *pgb, +static void decode_parameters(SiprParameters* parms, BitstreamContext *bc, const SiprModeParam *p) { int i, j; if (p->ma_predictor_bits) - parms->ma_pred_switch = get_bits(pgb, p->ma_predictor_bits); + parms->ma_pred_switch = bitstream_read(bc, p->ma_predictor_bits); for (i = 0; i < 5; i++) - parms->vq_indexes[i] = get_bits(pgb, p->vq_indexes_bits[i]); + parms->vq_indexes[i] = bitstream_read(bc, p->vq_indexes_bits[i]); for (i = 0; i < p->subframe_count; i++) { - parms->pitch_delay[i] = get_bits(pgb, p->pitch_delay_bits[i]); + parms->pitch_delay[i] = bitstream_read(bc, p->pitch_delay_bits[i]); if (p->gp_index_bits) - parms->gp_index[i] = get_bits(pgb, p->gp_index_bits); + parms->gp_index[i] = bitstream_read(bc, p->gp_index_bits); for (j = 0; j < p->number_of_fc_indexes; j++) - parms->fc_indexes[i][j] = get_bits(pgb, p->fc_index_bits[j]); + parms->fc_indexes[i][j] = bitstream_read(bc, p->fc_index_bits[j]); - parms->gc_index[i] = get_bits(pgb, p->gc_index_bits); + parms->gc_index[i] = bitstream_read(bc, p->gc_index_bits); } } @@ -527,7 +527,7 @@ static int sipr_decode_frame(AVCodecContext *avctx, void *data, const uint8_t *buf=avpkt->data; SiprParameters parm; const SiprModeParam *mode_par = &modes[ctx->mode]; - GetBitContext gb; + BitstreamContext bc; float *samples; int subframe_size = ctx->mode == MODE_16k ? L_SUBFR_16k : SUBFR_SIZE; int i, ret; @@ -549,10 +549,10 @@ static int sipr_decode_frame(AVCodecContext *avctx, void *data, } samples = (float *)frame->data[0]; - init_get_bits(&gb, buf, mode_par->bits_per_frame); + bitstream_init(&bc, buf, mode_par->bits_per_frame); for (i = 0; i < mode_par->frames_per_packet; i++) { - decode_parameters(&parm, &gb, mode_par); + decode_parameters(&parm, &bc, mode_par); ctx->decode_frame(ctx, &parm, samples); From 6efbc88a5cf40c8e6f3c4f7897caf83165920d3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandra=20H=C3=A1jkov=C3=A1?= Date: Wed, 13 Apr 2016 19:56:53 +0200 Subject: [PATCH 05/20] smacker: Convert to the new bitstream reader --- libavcodec/smacker.c | 143 +++++++++++++++++++++++-------------------- 1 file changed, 75 insertions(+), 68 deletions(-) diff --git a/libavcodec/smacker.c b/libavcodec/smacker.c index e3e54752a7..027728e387 100644 --- a/libavcodec/smacker.c +++ b/libavcodec/smacker.c @@ -35,8 +35,8 @@ #define BITSTREAM_READER_LE #include "avcodec.h" +#include "bitstream.h" #include "bytestream.h" -#include "get_bits.h" #include "internal.h" #include "mathops.h" @@ -93,9 +93,10 @@ enum SmkBlockTypes { /** * Decode local frame tree */ -static int smacker_decode_tree(GetBitContext *gb, HuffContext *hc, uint32_t prefix, int length) +static int smacker_decode_tree(BitstreamContext *bc, HuffContext *hc, + uint32_t prefix, int length) { - if(!get_bits1(gb)){ //Leaf + if (!bitstream_read_bit(bc)) { // Leaf if(hc->current >= 256){ av_log(NULL, AV_LOG_ERROR, "Tree size exceeded!\n"); return -1; @@ -107,7 +108,7 @@ static int smacker_decode_tree(GetBitContext *gb, HuffContext *hc, uint32_t pref hc->bits[hc->current] = 0; hc->lengths[hc->current] = 0; } - hc->values[hc->current] = get_bits(gb, 8); + hc->values[hc->current] = bitstream_read(bc, 8); hc->current++; if(hc->maxlength < length) hc->maxlength = length; @@ -115,26 +116,27 @@ static int smacker_decode_tree(GetBitContext *gb, HuffContext *hc, uint32_t pref } else { //Node int r; length++; - r = smacker_decode_tree(gb, hc, prefix, length); + r = smacker_decode_tree(bc, hc, prefix, length); if(r) return r; - return smacker_decode_tree(gb, hc, prefix | (1 << (length - 1)), length); + return smacker_decode_tree(bc, hc, prefix | (1 << (length - 1)), length); } } /** * Decode header tree */ -static int smacker_decode_bigtree(GetBitContext *gb, HuffContext *hc, DBCtx *ctx) +static int smacker_decode_bigtree(BitstreamContext *bc, HuffContext *hc, + DBCtx *ctx) { if (hc->current + 1 >= hc->length) { av_log(NULL, AV_LOG_ERROR, "Tree size exceeded!\n"); return -1; } - if(!get_bits1(gb)){ //Leaf + if (!bitstream_read_bit(bc)) { // Leaf int val, i1, i2; - i1 = ctx->v1->table ? get_vlc2(gb, ctx->v1->table, SMKTREE_BITS, 3) : 0; - i2 = ctx->v2->table ? get_vlc2(gb, ctx->v2->table, SMKTREE_BITS, 3) : 0; + i1 = ctx->v1->table ? bitstream_read_vlc(bc, ctx->v1->table, SMKTREE_BITS, 3) : 0; + i2 = ctx->v2->table ? bitstream_read_vlc(bc, ctx->v2->table, SMKTREE_BITS, 3) : 0; if (i1 < 0 || i2 < 0) return -1; val = ctx->recode1[i1] | (ctx->recode2[i2] << 8); @@ -155,12 +157,12 @@ static int smacker_decode_bigtree(GetBitContext *gb, HuffContext *hc, DBCtx *ctx int r = 0, r_new, t; t = hc->current++; - r = smacker_decode_bigtree(gb, hc, ctx); + r = smacker_decode_bigtree(bc, hc, ctx); if(r < 0) return r; hc->values[t] = SMK_NODE | r; r++; - r_new = smacker_decode_bigtree(gb, hc, ctx); + r_new = smacker_decode_bigtree(bc, hc, ctx); if (r_new < 0) return r_new; return r + r_new; @@ -170,7 +172,8 @@ static int smacker_decode_bigtree(GetBitContext *gb, HuffContext *hc, DBCtx *ctx /** * Store large tree as Libav's vlc codes */ -static int smacker_decode_header_tree(SmackVContext *smk, GetBitContext *gb, int **recodes, int *last, int size) +static int smacker_decode_header_tree(SmackVContext *smk, BitstreamContext *bc, + int **recodes, int *last, int size) { int res; HuffContext huff; @@ -204,9 +207,9 @@ static int smacker_decode_header_tree(SmackVContext *smk, GetBitContext *gb, int goto error; } - if(get_bits1(gb)) { - smacker_decode_tree(gb, &tmp1, 0, 0); - skip_bits1(gb); + if (bitstream_read_bit(bc)) { + smacker_decode_tree(bc, &tmp1, 0, 0); + bitstream_skip(bc, 1); res = init_vlc(&vlc[0], SMKTREE_BITS, tmp1.length, tmp1.lengths, sizeof(int), sizeof(int), tmp1.bits, sizeof(uint32_t), sizeof(uint32_t), INIT_VLC_LE); @@ -218,9 +221,9 @@ static int smacker_decode_header_tree(SmackVContext *smk, GetBitContext *gb, int } else { av_log(smk->avctx, AV_LOG_ERROR, "Skipping low bytes tree\n"); } - if(get_bits1(gb)){ - smacker_decode_tree(gb, &tmp2, 0, 0); - skip_bits1(gb); + if (bitstream_read_bit(bc)) { + smacker_decode_tree(bc, &tmp2, 0, 0); + bitstream_skip(bc, 1); res = init_vlc(&vlc[1], SMKTREE_BITS, tmp2.length, tmp2.lengths, sizeof(int), sizeof(int), tmp2.bits, sizeof(uint32_t), sizeof(uint32_t), INIT_VLC_LE); @@ -233,12 +236,12 @@ static int smacker_decode_header_tree(SmackVContext *smk, GetBitContext *gb, int av_log(smk->avctx, AV_LOG_ERROR, "Skipping high bytes tree\n"); } - escapes[0] = get_bits(gb, 8); - escapes[0] |= get_bits(gb, 8) << 8; - escapes[1] = get_bits(gb, 8); - escapes[1] |= get_bits(gb, 8) << 8; - escapes[2] = get_bits(gb, 8); - escapes[2] |= get_bits(gb, 8) << 8; + escapes[0] = bitstream_read(bc, 8); + escapes[0] |= bitstream_read(bc, 8) << 8; + escapes[1] = bitstream_read(bc, 8); + escapes[1] |= bitstream_read(bc, 8) << 8; + escapes[2] = bitstream_read(bc, 8); + escapes[2] |= bitstream_read(bc, 8) << 8; last[0] = last[1] = last[2] = -1; @@ -260,9 +263,9 @@ static int smacker_decode_header_tree(SmackVContext *smk, GetBitContext *gb, int goto error; } - if (smacker_decode_bigtree(gb, &huff, &ctx) < 0) + if (smacker_decode_bigtree(bc, &huff, &ctx) < 0) err = -1; - skip_bits1(gb); + bitstream_skip(bc, 1); if(ctx.last[0] == -1) ctx.last[0] = huff.current++; if(ctx.last[1] == -1) ctx.last[1] = huff.current++; if(ctx.last[2] == -1) ctx.last[2] = huff.current++; @@ -291,7 +294,7 @@ error: } static int decode_header_trees(SmackVContext *smk) { - GetBitContext gb; + BitstreamContext bc; int mmap_size, mclr_size, full_size, type_size; mmap_size = AV_RL32(smk->avctx->extradata); @@ -299,9 +302,9 @@ static int decode_header_trees(SmackVContext *smk) { full_size = AV_RL32(smk->avctx->extradata + 8); type_size = AV_RL32(smk->avctx->extradata + 12); - init_get_bits(&gb, smk->avctx->extradata + 16, (smk->avctx->extradata_size - 16) * 8); + bitstream_init(&bc, smk->avctx->extradata + 16, (smk->avctx->extradata_size - 16) * 8); - if(!get_bits1(&gb)) { + if (!bitstream_read_bit(&bc)) { av_log(smk->avctx, AV_LOG_INFO, "Skipping MMAP tree\n"); smk->mmap_tbl = av_malloc(sizeof(int) * 2); if (!smk->mmap_tbl) @@ -309,10 +312,10 @@ static int decode_header_trees(SmackVContext *smk) { smk->mmap_tbl[0] = 0; smk->mmap_last[0] = smk->mmap_last[1] = smk->mmap_last[2] = 1; } else { - if (smacker_decode_header_tree(smk, &gb, &smk->mmap_tbl, smk->mmap_last, mmap_size)) + if (smacker_decode_header_tree(smk, &bc, &smk->mmap_tbl, smk->mmap_last, mmap_size)) return -1; } - if(!get_bits1(&gb)) { + if (!bitstream_read_bit(&bc)) { av_log(smk->avctx, AV_LOG_INFO, "Skipping MCLR tree\n"); smk->mclr_tbl = av_malloc(sizeof(int) * 2); if (!smk->mclr_tbl) @@ -320,10 +323,10 @@ static int decode_header_trees(SmackVContext *smk) { smk->mclr_tbl[0] = 0; smk->mclr_last[0] = smk->mclr_last[1] = smk->mclr_last[2] = 1; } else { - if (smacker_decode_header_tree(smk, &gb, &smk->mclr_tbl, smk->mclr_last, mclr_size)) + if (smacker_decode_header_tree(smk, &bc, &smk->mclr_tbl, smk->mclr_last, mclr_size)) return -1; } - if(!get_bits1(&gb)) { + if (!bitstream_read_bit(&bc)) { av_log(smk->avctx, AV_LOG_INFO, "Skipping FULL tree\n"); smk->full_tbl = av_malloc(sizeof(int) * 2); if (!smk->full_tbl) @@ -331,10 +334,10 @@ static int decode_header_trees(SmackVContext *smk) { smk->full_tbl[0] = 0; smk->full_last[0] = smk->full_last[1] = smk->full_last[2] = 1; } else { - if (smacker_decode_header_tree(smk, &gb, &smk->full_tbl, smk->full_last, full_size)) + if (smacker_decode_header_tree(smk, &bc, &smk->full_tbl, smk->full_last, full_size)) return -1; } - if(!get_bits1(&gb)) { + if (!bitstream_read_bit(&bc)) { av_log(smk->avctx, AV_LOG_INFO, "Skipping TYPE tree\n"); smk->type_tbl = av_malloc(sizeof(int) * 2); if (!smk->type_tbl) @@ -342,7 +345,7 @@ static int decode_header_trees(SmackVContext *smk) { smk->type_tbl[0] = 0; smk->type_last[0] = smk->type_last[1] = smk->type_last[2] = 1; } else { - if (smacker_decode_header_tree(smk, &gb, &smk->type_tbl, smk->type_last, type_size)) + if (smacker_decode_header_tree(smk, &bc, &smk->type_tbl, smk->type_last, type_size)) return -1; } @@ -354,12 +357,14 @@ static av_always_inline void last_reset(int *recode, int *last) { } /* get code and update history */ -static av_always_inline int smk_get_code(GetBitContext *gb, int *recode, int *last) { +static av_always_inline int smk_get_code(BitstreamContext *bc, int *recode, + int *last) +{ register int *table = recode; int v; while(*table & SMK_NODE) { - if(get_bits1(gb)) + if (bitstream_read_bit(bc)) table += (*table) & (~SMK_NODE); table++; } @@ -380,7 +385,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, uint8_t *out; uint32_t *pal; GetByteContext gb2; - GetBitContext gb; + BitstreamContext bc; int blocks, blk, bw, bh; int i, ret; int stride; @@ -412,7 +417,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, last_reset(smk->mclr_tbl, smk->mclr_last); last_reset(smk->full_tbl, smk->full_last); last_reset(smk->type_tbl, smk->type_last); - init_get_bits(&gb, avpkt->data + 769, (avpkt->size - 769) * 8); + bitstream_init(&bc, avpkt->data + 769, (avpkt->size - 769) * 8); blk = 0; bw = avctx->width >> 2; @@ -424,15 +429,15 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, int type, run, mode; uint16_t pix; - type = smk_get_code(&gb, smk->type_tbl, smk->type_last); + type = smk_get_code(&bc, smk->type_tbl, smk->type_last); run = block_runs[(type >> 2) & 0x3F]; switch(type & 3){ case SMK_BLK_MONO: while(run-- && blk < blocks){ int clr, map; int hi, lo; - clr = smk_get_code(&gb, smk->mclr_tbl, smk->mclr_last); - map = smk_get_code(&gb, smk->mmap_tbl, smk->mmap_last); + clr = smk_get_code(&bc, smk->mclr_tbl, smk->mclr_last); + map = smk_get_code(&bc, smk->mmap_tbl, smk->mmap_last); out = smk->pic->data[0] + (blk / bw) * (stride * 4) + (blk % bw) * 4; hi = clr >> 8; lo = clr & 0xFF; @@ -450,30 +455,32 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, case SMK_BLK_FULL: mode = 0; if(avctx->codec_tag == MKTAG('S', 'M', 'K', '4')) { // In case of Smacker v4 we have three modes - if(get_bits1(&gb)) mode = 1; - else if(get_bits1(&gb)) mode = 2; + if (bitstream_read_bit(&bc)) + mode = 1; + else if (bitstream_read_bit(&bc)) + mode = 2; } while(run-- && blk < blocks){ out = smk->pic->data[0] + (blk / bw) * (stride * 4) + (blk % bw) * 4; switch(mode){ case 0: for(i = 0; i < 4; i++) { - pix = smk_get_code(&gb, smk->full_tbl, smk->full_last); + pix = smk_get_code(&bc, smk->full_tbl, smk->full_last); AV_WL16(out+2,pix); - pix = smk_get_code(&gb, smk->full_tbl, smk->full_last); + pix = smk_get_code(&bc, smk->full_tbl, smk->full_last); AV_WL16(out,pix); out += stride; } break; case 1: - pix = smk_get_code(&gb, smk->full_tbl, smk->full_last); + pix = smk_get_code(&bc, smk->full_tbl, smk->full_last); out[0] = out[1] = pix & 0xFF; out[2] = out[3] = pix >> 8; out += stride; out[0] = out[1] = pix & 0xFF; out[2] = out[3] = pix >> 8; out += stride; - pix = smk_get_code(&gb, smk->full_tbl, smk->full_last); + pix = smk_get_code(&bc, smk->full_tbl, smk->full_last); out[0] = out[1] = pix & 0xFF; out[2] = out[3] = pix >> 8; out += stride; @@ -484,8 +491,8 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, case 2: for(i = 0; i < 2; i++) { uint16_t pix1, pix2; - pix2 = smk_get_code(&gb, smk->full_tbl, smk->full_last); - pix1 = smk_get_code(&gb, smk->full_tbl, smk->full_last); + pix2 = smk_get_code(&bc, smk->full_tbl, smk->full_last); + pix1 = smk_get_code(&bc, smk->full_tbl, smk->full_last); AV_WL16(out,pix1); AV_WL16(out+2,pix2); out += stride; @@ -593,7 +600,7 @@ static int smka_decode_frame(AVCodecContext *avctx, void *data, AVFrame *frame = data; const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; - GetBitContext gb; + BitstreamContext bc; HuffContext h[4] = { { 0 } }; VLC vlc[4] = { { 0 } }; int16_t *samples; @@ -611,15 +618,15 @@ static int smka_decode_frame(AVCodecContext *avctx, void *data, unp_size = AV_RL32(buf); - init_get_bits(&gb, buf + 4, (buf_size - 4) * 8); + bitstream_init(&bc, buf + 4, (buf_size - 4) * 8); - if(!get_bits1(&gb)){ + if (!bitstream_read_bit(&bc)) { av_log(avctx, AV_LOG_INFO, "Sound: no data\n"); *got_frame_ptr = 0; return 1; } - stereo = get_bits1(&gb); - bits = get_bits1(&gb); + stereo = bitstream_read_bit(&bc); + bits = bitstream_read_bit(&bc); if (stereo ^ (avctx->channels != 1)) { av_log(avctx, AV_LOG_ERROR, "channels mismatch\n"); return AVERROR(EINVAL); @@ -650,12 +657,12 @@ static int smka_decode_frame(AVCodecContext *avctx, void *data, ret = AVERROR(ENOMEM); goto error; } - skip_bits1(&gb); - if (smacker_decode_tree(&gb, &h[i], 0, 0) < 0) { + bitstream_skip(&bc, 1); + if (smacker_decode_tree(&bc, &h[i], 0, 0) < 0) { ret = AVERROR_INVALIDDATA; goto error; } - skip_bits1(&gb); + bitstream_skip(&bc, 1); if(h[i].current > 1) { res = init_vlc(&vlc[i], SMKTREE_BITS, h[i].length, h[i].lengths, sizeof(int), sizeof(int), @@ -670,18 +677,18 @@ static int smka_decode_frame(AVCodecContext *avctx, void *data, /* this codec relies on wraparound instead of clipping audio */ if(bits) { //decode 16-bit data for(i = stereo; i >= 0; i--) - pred[i] = sign_extend(av_bswap16(get_bits(&gb, 16)), 16); + pred[i] = sign_extend(av_bswap16(bitstream_read(&bc, 16)), 16); for(i = 0; i <= stereo; i++) *samples++ = pred[i]; for(; i < unp_size / 2; i++) { if(i & stereo) { if(vlc[2].table) - res = get_vlc2(&gb, vlc[2].table, SMKTREE_BITS, 3); + res = bitstream_read_vlc(&bc, vlc[2].table, SMKTREE_BITS, 3); else res = 0; val = h[2].values[res]; if(vlc[3].table) - res = get_vlc2(&gb, vlc[3].table, SMKTREE_BITS, 3); + res = bitstream_read_vlc(&bc, vlc[3].table, SMKTREE_BITS, 3); else res = 0; val |= h[3].values[res] << 8; @@ -689,12 +696,12 @@ static int smka_decode_frame(AVCodecContext *avctx, void *data, *samples++ = pred[1]; } else { if(vlc[0].table) - res = get_vlc2(&gb, vlc[0].table, SMKTREE_BITS, 3); + res = bitstream_read_vlc(&bc, vlc[0].table, SMKTREE_BITS, 3); else res = 0; val = h[0].values[res]; if(vlc[1].table) - res = get_vlc2(&gb, vlc[1].table, SMKTREE_BITS, 3); + res = bitstream_read_vlc(&bc, vlc[1].table, SMKTREE_BITS, 3); else res = 0; val |= h[1].values[res] << 8; @@ -704,20 +711,20 @@ static int smka_decode_frame(AVCodecContext *avctx, void *data, } } else { //8-bit data for(i = stereo; i >= 0; i--) - pred[i] = get_bits(&gb, 8); + pred[i] = bitstream_read(&bc, 8); for(i = 0; i <= stereo; i++) *samples8++ = pred[i]; for(; i < unp_size; i++) { if(i & stereo){ if(vlc[1].table) - res = get_vlc2(&gb, vlc[1].table, SMKTREE_BITS, 3); + res = bitstream_read_vlc(&bc, vlc[1].table, SMKTREE_BITS, 3); else res = 0; pred[1] += sign_extend(h[1].values[res], 8); *samples8++ = pred[1]; } else { if(vlc[0].table) - res = get_vlc2(&gb, vlc[0].table, SMKTREE_BITS, 3); + res = bitstream_read_vlc(&bc, vlc[0].table, SMKTREE_BITS, 3); else res = 0; pred[0] += sign_extend(h[0].values[res], 8); From 9f78e3a46d15abbdc900d755818ef235ae5e886c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandra=20H=C3=A1jkov=C3=A1?= Date: Wed, 13 Apr 2016 20:25:22 +0200 Subject: [PATCH 06/20] svq1dec: Convert to the new bitstream reader --- libavcodec/svq1dec.c | 120 +++++++++++++++++++++---------------------- 1 file changed, 60 insertions(+), 60 deletions(-) diff --git a/libavcodec/svq1dec.c b/libavcodec/svq1dec.c index cc43f1491c..2ab0f238bb 100644 --- a/libavcodec/svq1dec.c +++ b/libavcodec/svq1dec.c @@ -33,7 +33,7 @@ */ #include "avcodec.h" -#include "get_bits.h" +#include "bitstream.h" #include "h263.h" #include "hpeldsp.h" #include "internal.h" @@ -55,7 +55,7 @@ typedef struct svq1_pmv_s { typedef struct SVQ1Context { HpelDSPContext hdsp; - GetBitContext gb; + BitstreamContext bc; AVFrame *prev; uint8_t *pkt_swapped; @@ -111,7 +111,7 @@ static const uint8_t string_table[256] = { break; \ } \ /* divide block if next bit set */ \ - if (get_bits1(bitbuf) == 0) \ + if (bitstream_read_bit(bc) == 0) \ break; \ /* add child nodes */ \ list[n++] = list[i]; \ @@ -145,7 +145,7 @@ static const uint8_t string_table[256] = { #define SVQ1_CALC_CODEBOOK_ENTRIES(cbook) \ codebook = (const uint32_t *)cbook[level]; \ if (stages > 0) \ - bit_cache = get_bits(bitbuf, 4 * stages); \ + bit_cache = bitstream_read(bc, 4 * stages); \ /* calculate codebook entries for this vector */ \ for (j = 0; j < stages; j++) { \ entries[j] = (((bit_cache >> (4 * (stages - j - 1))) & 0xF) + \ @@ -154,7 +154,7 @@ static const uint8_t string_table[256] = { mean -= stages * 128; \ n4 = mean + (mean >> 31) << 16 | (mean & 0xFFFF); -static int svq1_decode_block_intra(GetBitContext *bitbuf, uint8_t *pixels, +static int svq1_decode_block_intra(BitstreamContext *bc, uint8_t *pixels, ptrdiff_t pitch) { uint32_t bit_cache; @@ -180,7 +180,7 @@ static int svq1_decode_block_intra(GetBitContext *bitbuf, uint8_t *pixels, height = 1 << ((3 + level) / 2); /* get number of stages (-1 skips vector, 0 for mean only) */ - stages = get_vlc2(bitbuf, svq1_intra_multistage[level].table, 3, 3) - 1; + stages = bitstream_read_vlc(bc, svq1_intra_multistage[level].table, 3, 3) - 1; if (stages == -1) { for (y = 0; y < height; y++) @@ -195,7 +195,7 @@ static int svq1_decode_block_intra(GetBitContext *bitbuf, uint8_t *pixels, return AVERROR_INVALIDDATA; /* invalid vector */ } - mean = get_vlc2(bitbuf, svq1_intra_mean.table, 8, 3); + mean = bitstream_read_vlc(bc, svq1_intra_mean.table, 8, 3); if (stages == 0) { for (y = 0; y < height; y++) @@ -219,7 +219,7 @@ static int svq1_decode_block_intra(GetBitContext *bitbuf, uint8_t *pixels, return 0; } -static int svq1_decode_block_non_intra(GetBitContext *bitbuf, uint8_t *pixels, +static int svq1_decode_block_non_intra(BitstreamContext *bc, uint8_t *pixels, ptrdiff_t pitch) { uint32_t bit_cache; @@ -245,7 +245,7 @@ static int svq1_decode_block_non_intra(GetBitContext *bitbuf, uint8_t *pixels, height = 1 << ((3 + level) / 2); /* get number of stages (-1 skips vector, 0 for mean only) */ - stages = get_vlc2(bitbuf, svq1_inter_multistage[level].table, 3, 2) - 1; + stages = bitstream_read_vlc(bc, svq1_inter_multistage[level].table, 3, 2) - 1; if (stages == -1) continue; /* skip vector */ @@ -257,7 +257,7 @@ static int svq1_decode_block_non_intra(GetBitContext *bitbuf, uint8_t *pixels, return AVERROR_INVALIDDATA; /* invalid vector */ } - mean = get_vlc2(bitbuf, svq1_inter_mean.table, 9, 3) - 256; + mean = bitstream_read_vlc(bc, svq1_inter_mean.table, 9, 3) - 256; SVQ1_CALC_CODEBOOK_ENTRIES(ff_svq1_inter_codebooks); @@ -277,7 +277,7 @@ static int svq1_decode_block_non_intra(GetBitContext *bitbuf, uint8_t *pixels, return 0; } -static int svq1_decode_motion_vector(GetBitContext *bitbuf, svq1_pmv *mv, +static int svq1_decode_motion_vector(BitstreamContext *bc, svq1_pmv *mv, svq1_pmv **pmv) { int diff; @@ -285,11 +285,11 @@ static int svq1_decode_motion_vector(GetBitContext *bitbuf, svq1_pmv *mv, for (i = 0; i < 2; i++) { /* get motion code */ - diff = get_vlc2(bitbuf, svq1_motion_component.table, 7, 2); + diff = bitstream_read_vlc(bc, svq1_motion_component.table, 7, 2); if (diff < 0) return AVERROR_INVALIDDATA; else if (diff) { - if (get_bits1(bitbuf)) + if (bitstream_read_bit(bc)) diff = -diff; } @@ -320,7 +320,7 @@ static void svq1_skip_block(uint8_t *current, uint8_t *previous, } } -static int svq1_motion_inter_block(HpelDSPContext *hdsp, GetBitContext *bitbuf, +static int svq1_motion_inter_block(HpelDSPContext *hdsp, BitstreamContext *bc, uint8_t *current, uint8_t *previous, ptrdiff_t pitch, svq1_pmv *motion, int x, int y, int width, int height) @@ -341,7 +341,7 @@ static int svq1_motion_inter_block(HpelDSPContext *hdsp, GetBitContext *bitbuf, pmv[2] = &motion[x / 8 + 4]; } - result = svq1_decode_motion_vector(bitbuf, &mv, pmv); + result = svq1_decode_motion_vector(bc, &mv, pmv); if (result != 0) return result; @@ -364,7 +364,7 @@ static int svq1_motion_inter_block(HpelDSPContext *hdsp, GetBitContext *bitbuf, return 0; } -static int svq1_motion_inter_4v_block(HpelDSPContext *hdsp, GetBitContext *bitbuf, +static int svq1_motion_inter_4v_block(HpelDSPContext *hdsp, BitstreamContext *bc, uint8_t *current, uint8_t *previous, ptrdiff_t pitch, svq1_pmv *motion, int x, int y, int width, int height) @@ -385,7 +385,7 @@ static int svq1_motion_inter_4v_block(HpelDSPContext *hdsp, GetBitContext *bitbu pmv[2] = &motion[(x / 8) + 4]; } - result = svq1_decode_motion_vector(bitbuf, &mv, pmv); + result = svq1_decode_motion_vector(bc, &mv, pmv); if (result != 0) return result; @@ -398,7 +398,7 @@ static int svq1_motion_inter_4v_block(HpelDSPContext *hdsp, GetBitContext *bitbu } else { pmv[1] = &motion[(x / 8) + 3]; } - result = svq1_decode_motion_vector(bitbuf, &motion[0], pmv); + result = svq1_decode_motion_vector(bc, &motion[0], pmv); if (result != 0) return result; @@ -407,7 +407,7 @@ static int svq1_motion_inter_4v_block(HpelDSPContext *hdsp, GetBitContext *bitbu pmv[1] = &motion[0]; pmv[2] = &motion[(x / 8) + 1]; - result = svq1_decode_motion_vector(bitbuf, &motion[(x / 8) + 2], pmv); + result = svq1_decode_motion_vector(bc, &motion[(x / 8) + 2], pmv); if (result != 0) return result; @@ -416,7 +416,7 @@ static int svq1_motion_inter_4v_block(HpelDSPContext *hdsp, GetBitContext *bitbu pmv[2] = &motion[(x / 8) + 2]; pmv[3] = &motion[(x / 8) + 3]; - result = svq1_decode_motion_vector(bitbuf, pmv[3], pmv); + result = svq1_decode_motion_vector(bc, pmv[3], pmv); if (result != 0) return result; @@ -446,7 +446,7 @@ static int svq1_motion_inter_4v_block(HpelDSPContext *hdsp, GetBitContext *bitbu } static int svq1_decode_delta_block(AVCodecContext *avctx, HpelDSPContext *hdsp, - GetBitContext *bitbuf, + BitstreamContext *bc, uint8_t *current, uint8_t *previous, ptrdiff_t pitch, svq1_pmv *motion, int x, int y, int width, int height) @@ -455,7 +455,7 @@ static int svq1_decode_delta_block(AVCodecContext *avctx, HpelDSPContext *hdsp, int result = 0; /* get block type */ - block_type = get_vlc2(bitbuf, svq1_block_type.table, 2, 2); + block_type = bitstream_read_vlc(bc, svq1_block_type.table, 2, 2); /* reset motion vectors */ if (block_type == SVQ1_BLOCK_SKIP || block_type == SVQ1_BLOCK_INTRA) { @@ -473,45 +473,45 @@ static int svq1_decode_delta_block(AVCodecContext *avctx, HpelDSPContext *hdsp, break; case SVQ1_BLOCK_INTER: - result = svq1_motion_inter_block(hdsp, bitbuf, current, previous, + result = svq1_motion_inter_block(hdsp, bc, current, previous, pitch, motion, x, y, width, height); if (result != 0) { ff_dlog(avctx, "Error in svq1_motion_inter_block %i\n", result); break; } - result = svq1_decode_block_non_intra(bitbuf, current, pitch); + result = svq1_decode_block_non_intra(bc, current, pitch); break; case SVQ1_BLOCK_INTER_4V: - result = svq1_motion_inter_4v_block(hdsp, bitbuf, current, previous, + result = svq1_motion_inter_4v_block(hdsp, bc, current, previous, pitch, motion, x, y, width, height); if (result != 0) { ff_dlog(avctx, "Error in svq1_motion_inter_4v_block %i\n", result); break; } - result = svq1_decode_block_non_intra(bitbuf, current, pitch); + result = svq1_decode_block_non_intra(bc, current, pitch); break; case SVQ1_BLOCK_INTRA: - result = svq1_decode_block_intra(bitbuf, current, pitch); + result = svq1_decode_block_intra(bc, current, pitch); break; } return result; } -static void svq1_parse_string(GetBitContext *bitbuf, uint8_t *out) +static void svq1_parse_string(BitstreamContext *bc, uint8_t *out) { uint8_t seed; int i; - out[0] = get_bits(bitbuf, 8); + out[0] = bitstream_read(bc, 8); seed = string_table[out[0]]; for (i = 1; i <= out[0]; i++) { - out[i] = get_bits(bitbuf, 8) ^ seed; + out[i] = bitstream_read(bc, 8) ^ seed; seed = string_table[out[i] ^ seed]; } } @@ -519,14 +519,14 @@ static void svq1_parse_string(GetBitContext *bitbuf, uint8_t *out) static int svq1_decode_frame_header(AVCodecContext *avctx, AVFrame *frame) { SVQ1Context *s = avctx->priv_data; - GetBitContext *bitbuf = &s->gb; + BitstreamContext *bc = &s->bc; int frame_size_code; - skip_bits(bitbuf, 8); /* temporal_reference */ + bitstream_skip(bc, 8); /* temporal_reference */ /* frame type */ s->nonref = 0; - switch (get_bits(bitbuf, 2)) { + switch (bitstream_read(bc, 2)) { case 0: frame->pict_type = AV_PICTURE_TYPE_I; break; @@ -543,10 +543,9 @@ static int svq1_decode_frame_header(AVCodecContext *avctx, AVFrame *frame) if (frame->pict_type == AV_PICTURE_TYPE_I) { /* unknown fields */ if (s->frame_code == 0x50 || s->frame_code == 0x60) { - int csum = get_bits(bitbuf, 16); + int csum = bitstream_read(bc, 16); - csum = ff_svq1_packet_checksum(bitbuf->buffer, - bitbuf->size_in_bits >> 3, + csum = ff_svq1_packet_checksum(bc->buffer, bc->size_in_bits >> 3, csum); ff_dlog(avctx, "%s checksum (%02x) for packet data\n", @@ -556,23 +555,23 @@ static int svq1_decode_frame_header(AVCodecContext *avctx, AVFrame *frame) if ((s->frame_code ^ 0x10) >= 0x50) { uint8_t msg[256]; - svq1_parse_string(bitbuf, msg); + svq1_parse_string(bc, msg); av_log(avctx, AV_LOG_INFO, "embedded message: \"%s\"\n", (char *)msg); } - skip_bits(bitbuf, 2); - skip_bits(bitbuf, 2); - skip_bits1(bitbuf); + bitstream_skip(bc, 2); + bitstream_skip(bc, 2); + bitstream_skip(bc, 1); /* load frame size */ - frame_size_code = get_bits(bitbuf, 3); + frame_size_code = bitstream_read(bc, 3); if (frame_size_code == 7) { /* load width, height (12 bits each) */ - s->width = get_bits(bitbuf, 12); - s->height = get_bits(bitbuf, 12); + s->width = bitstream_read(bc, 12); + s->height = bitstream_read(bc, 12); if (!s->width || !s->height) return AVERROR_INVALIDDATA; @@ -584,22 +583,22 @@ static int svq1_decode_frame_header(AVCodecContext *avctx, AVFrame *frame) } /* unknown fields */ - if (get_bits1(bitbuf) == 1) { - skip_bits1(bitbuf); /* use packet checksum if (1) */ - skip_bits1(bitbuf); /* component checksums after image data if (1) */ + if (bitstream_read_bit(bc) == 1) { + bitstream_skip(bc, 1); /* use packet checksum if (1) */ + bitstream_skip(bc, 1); /* component checksums after image data if (1) */ - if (get_bits(bitbuf, 2) != 0) + if (bitstream_read(bc, 2) != 0) return AVERROR_INVALIDDATA; } - if (get_bits1(bitbuf) == 1) { - skip_bits1(bitbuf); - skip_bits(bitbuf, 4); - skip_bits1(bitbuf); - skip_bits(bitbuf, 2); + if (bitstream_read_bit(bc) == 1) { + bitstream_skip(bc, 1); + bitstream_skip(bc, 4); + bitstream_skip(bc, 1); + bitstream_skip(bc, 2); - while (get_bits1(bitbuf) == 1) - skip_bits(bitbuf, 8); + while (bitstream_read_bit(bc) == 1) + bitstream_skip(bc, 8); } return 0; @@ -617,10 +616,10 @@ static int svq1_decode_frame(AVCodecContext *avctx, void *data, svq1_pmv *pmv; /* initialize bit buffer */ - init_get_bits(&s->gb, buf, buf_size * 8); + bitstream_init(&s->bc, buf, buf_size * 8); /* decode frame header */ - s->frame_code = get_bits(&s->gb, 22); + s->frame_code = bitstream_read(&s->bc, 22); if ((s->frame_code & ~0x70) || !(s->frame_code & 0x60)) return AVERROR_INVALIDDATA; @@ -642,13 +641,14 @@ static int svq1_decode_frame(AVCodecContext *avctx, void *data, memcpy(s->pkt_swapped, buf, buf_size); buf = s->pkt_swapped; - init_get_bits(&s->gb, buf, buf_size * 8); - skip_bits(&s->gb, 22); src = (uint32_t *)(s->pkt_swapped + 4); for (i = 0; i < 4; i++) src[i] = ((src[i] << 16) | (src[i] >> 16)) ^ src[7 - i]; + + bitstream_init(&s->bc, buf, buf_size * 8); + bitstream_skip(&s->bc, 22); } result = svq1_decode_frame_header(avctx, cur); @@ -695,7 +695,7 @@ static int svq1_decode_frame(AVCodecContext *avctx, void *data, /* keyframe */ for (y = 0; y < height; y += 16) { for (x = 0; x < width; x += 16) { - result = svq1_decode_block_intra(&s->gb, ¤t[x], + result = svq1_decode_block_intra(&s->bc, ¤t[x], linesize); if (result != 0) { av_log(avctx, AV_LOG_INFO, @@ -721,7 +721,7 @@ static int svq1_decode_frame(AVCodecContext *avctx, void *data, for (y = 0; y < height; y += 16) { for (x = 0; x < width; x += 16) { result = svq1_decode_delta_block(avctx, &s->hdsp, - &s->gb, ¤t[x], + &s->bc, ¤t[x], previous, linesize, pmv, x, y, width, height); if (result != 0) { From 9ab1a3e28371f599afe05aea9f7ca75fd8eb3c3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandra=20H=C3=A1jkov=C3=A1?= Date: Sat, 23 Apr 2016 15:11:27 +0200 Subject: [PATCH 07/20] truemotion2: Convert to the new bitstream reader --- libavcodec/truemotion2.c | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/libavcodec/truemotion2.c b/libavcodec/truemotion2.c index 172644007c..99884be4bb 100644 --- a/libavcodec/truemotion2.c +++ b/libavcodec/truemotion2.c @@ -27,9 +27,9 @@ #include #include "avcodec.h" +#include "bitstream.h" #include "bswapdsp.h" #include "bytestream.h" -#include "get_bits.h" #include "internal.h" #define TM2_ESCAPE 0x80000000 @@ -62,7 +62,7 @@ typedef struct TM2Context { AVCodecContext *avctx; AVFrame *pic; - GetBitContext gb; + BitstreamContext bc; BswapDSPContext bdsp; /* TM2 streams */ @@ -117,7 +117,7 @@ static int tm2_read_tree(TM2Context *ctx, uint32_t prefix, int length, TM2Huff * return AVERROR_INVALIDDATA; } - if (!get_bits1(&ctx->gb)) { /* literal */ + if (!bitstream_read_bit(&ctx->bc)) { /* literal */ if (length == 0) { length = 1; } @@ -125,7 +125,7 @@ static int tm2_read_tree(TM2Context *ctx, uint32_t prefix, int length, TM2Huff * av_log(ctx->avctx, AV_LOG_DEBUG, "Too many literals\n"); return AVERROR_INVALIDDATA; } - huff->nums[huff->num] = get_bits_long(&ctx->gb, huff->val_bits); + huff->nums[huff->num] = bitstream_read(&ctx->bc, huff->val_bits); huff->bits[huff->num] = prefix; huff->lens[huff->num] = length; huff->num++; @@ -144,10 +144,10 @@ static int tm2_build_huff_table(TM2Context *ctx, TM2Codes *code) TM2Huff huff; int res = 0; - huff.val_bits = get_bits(&ctx->gb, 5); - huff.max_bits = get_bits(&ctx->gb, 5); - huff.min_bits = get_bits(&ctx->gb, 5); - huff.nodes = get_bits_long(&ctx->gb, 17); + huff.val_bits = bitstream_read(&ctx->bc, 5); + huff.max_bits = bitstream_read(&ctx->bc, 5); + huff.min_bits = bitstream_read(&ctx->bc, 5); + huff.nodes = bitstream_read(&ctx->bc, 17); huff.num = 0; /* check for correct codes parameters */ @@ -222,10 +222,10 @@ static void tm2_free_codes(TM2Codes *code) ff_free_vlc(&code->vlc); } -static inline int tm2_get_token(GetBitContext *gb, TM2Codes *code) +static inline int tm2_get_token(BitstreamContext *bc, TM2Codes *code) { int val; - val = get_vlc2(gb, code->vlc.table, code->bits, 1); + val = bitstream_read_vlc(bc, code->vlc.table, code->bits, 1); return code->recode[val]; } @@ -254,8 +254,8 @@ static int tm2_read_deltas(TM2Context *ctx, int stream_id) int d, mb; int i, v; - d = get_bits(&ctx->gb, 9); - mb = get_bits(&ctx->gb, 5); + d = bitstream_read(&ctx->bc, 9); + mb = bitstream_read(&ctx->bc, 5); if ((d < 1) || (d > TM2_DELTAS) || (mb < 1) || (mb > 32)) { av_log(ctx->avctx, AV_LOG_ERROR, "Incorrect delta table: %i deltas x %i bits\n", d, mb); @@ -263,7 +263,7 @@ static int tm2_read_deltas(TM2Context *ctx, int stream_id) } for (i = 0; i < d; i++) { - v = get_bits_long(&ctx->gb, mb); + v = bitstream_read(&ctx->bc, mb); if (v & (1 << (mb - 1))) ctx->deltas[stream_id][i] = v - (1 << mb); else @@ -306,10 +306,10 @@ static int tm2_read_stream(TM2Context *ctx, const uint8_t *buf, int stream_id, i pos = bytestream2_tell(&gb); if (skip <= pos) return AVERROR_INVALIDDATA; - init_get_bits(&ctx->gb, buf + pos, (skip - pos) * 8); + bitstream_init(&ctx->bc, buf + pos, (skip - pos) * 8); if ((ret = tm2_read_deltas(ctx, stream_id)) < 0) return ret; - bytestream2_skip(&gb, ((get_bits_count(&ctx->gb) + 31) >> 5) << 2); + bytestream2_skip(&gb, ((bitstream_tell(&ctx->bc) + 31) >> 5) << 2); } } /* skip unused fields */ @@ -323,10 +323,10 @@ static int tm2_read_stream(TM2Context *ctx, const uint8_t *buf, int stream_id, i pos = bytestream2_tell(&gb); if (skip <= pos) return AVERROR_INVALIDDATA; - init_get_bits(&ctx->gb, buf + pos, (skip - pos) * 8); + bitstream_init(&ctx->bc, buf + pos, (skip - pos) * 8); if ((ret = tm2_build_huff_table(ctx, &codes)) < 0) return ret; - bytestream2_skip(&gb, ((get_bits_count(&ctx->gb) + 31) >> 5) << 2); + bytestream2_skip(&gb, ((bitstream_tell(&ctx->bc) + 31) >> 5) << 2); toks >>= 1; /* check if we have sane number of tokens */ @@ -342,13 +342,13 @@ static int tm2_read_stream(TM2Context *ctx, const uint8_t *buf, int stream_id, i pos = bytestream2_tell(&gb); if (skip <= pos) return AVERROR_INVALIDDATA; - init_get_bits(&ctx->gb, buf + pos, (skip - pos) * 8); + bitstream_init(&ctx->bc, buf + pos, (skip - pos) * 8); for (i = 0; i < toks; i++) { - if (get_bits_left(&ctx->gb) <= 0) { + if (bitstream_bits_left(&ctx->bc) <= 0) { av_log(ctx->avctx, AV_LOG_ERROR, "Incorrect number of tokens: %i\n", toks); return AVERROR_INVALIDDATA; } - ctx->tokens[stream_id][i] = tm2_get_token(&ctx->gb, &codes); + ctx->tokens[stream_id][i] = tm2_get_token(&ctx->bc, &codes); if (stream_id <= TM2_MOT && ctx->tokens[stream_id][i] >= TM2_DELTAS) { av_log(ctx->avctx, AV_LOG_ERROR, "Invalid delta token index %d for type %d, n=%d\n", ctx->tokens[stream_id][i], stream_id, i); From 0ac07d0b8d75cce10a139c868d415284a9d2ca48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandra=20H=C3=A1jkov=C3=A1?= Date: Sat, 23 Apr 2016 15:13:41 +0200 Subject: [PATCH 08/20] tiertex: Convert to the new bitstream reader --- libavcodec/tiertexseqv.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/libavcodec/tiertexseqv.c b/libavcodec/tiertexseqv.c index 8ca7edfeac..d95226678b 100644 --- a/libavcodec/tiertexseqv.c +++ b/libavcodec/tiertexseqv.c @@ -26,7 +26,7 @@ #define BITSTREAM_READER_LE #include "avcodec.h" -#include "get_bits.h" +#include "bitstream.h" #include "internal.h" @@ -41,18 +41,18 @@ static const unsigned char *seq_unpack_rle_block(const unsigned char *src, unsigned char *dst, int dst_size) { int i, len, sz; - GetBitContext gb; + BitstreamContext bc; int code_table[64]; /* get the rle codes */ - init_get_bits(&gb, src, (src_end - src) * 8); + bitstream_init(&bc, src, (src_end - src) * 8); for (i = 0, sz = 0; i < 64 && sz < dst_size; i++) { - if (get_bits_left(&gb) < 4) + if (bitstream_bits_left(&bc) < 4) return NULL; - code_table[i] = get_sbits(&gb, 4); + code_table[i] = bitstream_read_signed(&bc, 4); sz += FFABS(code_table[i]); } - src += (get_bits_count(&gb) + 7) / 8; + src += (bitstream_tell(&bc) + 7) / 8; /* do the rle unpacking */ for (i = 0; i < 64 && dst_size > 0; i++) { @@ -81,7 +81,7 @@ static const unsigned char *seq_decode_op1(SeqVideoContext *seq, { const unsigned char *color_table; int b, i, len, bits; - GetBitContext gb; + BitstreamContext bc; unsigned char block[8 * 8]; if (src_end - src < 1) @@ -113,10 +113,11 @@ static const unsigned char *seq_decode_op1(SeqVideoContext *seq, return NULL; color_table = src; src += len; - init_get_bits(&gb, src, bits * 8 * 8); src += bits * 8; + bitstream_init(&bc, src, bits * 8 * 8); + src += bits * 8; for (b = 0; b < 8; b++) { for (i = 0; i < 8; i++) - dst[i] = color_table[get_bits(&gb, bits)]; + dst[i] = color_table[bitstream_read(&bc, bits)]; dst += seq->frame->linesize[0]; } } @@ -164,7 +165,7 @@ static const unsigned char *seq_decode_op3(SeqVideoContext *seq, static int seqvideo_decode(SeqVideoContext *seq, const unsigned char *data, int data_size) { const unsigned char *data_end = data + data_size; - GetBitContext gb; + BitstreamContext bc; int flags, i, j, x, y, op; unsigned char c[3]; unsigned char *dst; @@ -187,11 +188,12 @@ static int seqvideo_decode(SeqVideoContext *seq, const unsigned char *data, int if (flags & 2) { if (data_end - data < 128) return AVERROR_INVALIDDATA; - init_get_bits(&gb, data, 128 * 8); data += 128; + bitstream_init(&bc, data, 128 * 8); + data += 128; for (y = 0; y < 128; y += 8) for (x = 0; x < 256; x += 8) { dst = &seq->frame->data[0][y * seq->frame->linesize[0] + x]; - op = get_bits(&gb, 2); + op = bitstream_read(&bc, 2); switch (op) { case 1: data = seq_decode_op1(seq, data, data_end, dst); From 8e4cadea5d20e463e9d6cf00fc58841f17c811e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandra=20H=C3=A1jkov=C3=A1?= Date: Thu, 14 Apr 2016 10:32:31 +0200 Subject: [PATCH 09/20] truespeech: Convert to the new bitstream reader --- libavcodec/truespeech.c | 72 +++++++++++++++++++++-------------------- 1 file changed, 37 insertions(+), 35 deletions(-) diff --git a/libavcodec/truespeech.c b/libavcodec/truespeech.c index b2195baef4..48e2126ba6 100644 --- a/libavcodec/truespeech.c +++ b/libavcodec/truespeech.c @@ -21,12 +21,14 @@ #include "libavutil/channel_layout.h" #include "libavutil/intreadwrite.h" + #include "avcodec.h" +#include "bitstream.h" #include "bswapdsp.h" -#include "get_bits.h" #include "internal.h" #include "truespeech_data.h" + /** * @file * TrueSpeech decoder. @@ -77,50 +79,50 @@ static av_cold int truespeech_decode_init(AVCodecContext * avctx) static void truespeech_read_frame(TSContext *dec, const uint8_t *input) { - GetBitContext gb; + BitstreamContext bc; dec->bdsp.bswap_buf((uint32_t *) dec->buffer, (const uint32_t *) input, 8); - init_get_bits(&gb, dec->buffer, 32 * 8); + bitstream_init(&bc, dec->buffer, 32 * 8); - dec->vector[7] = ts_codebook[7][get_bits(&gb, 3)]; - dec->vector[6] = ts_codebook[6][get_bits(&gb, 3)]; - dec->vector[5] = ts_codebook[5][get_bits(&gb, 3)]; - dec->vector[4] = ts_codebook[4][get_bits(&gb, 4)]; - dec->vector[3] = ts_codebook[3][get_bits(&gb, 4)]; - dec->vector[2] = ts_codebook[2][get_bits(&gb, 4)]; - dec->vector[1] = ts_codebook[1][get_bits(&gb, 5)]; - dec->vector[0] = ts_codebook[0][get_bits(&gb, 5)]; - dec->flag = get_bits1(&gb); + dec->vector[7] = ts_codebook[7][bitstream_read(&bc, 3)]; + dec->vector[6] = ts_codebook[6][bitstream_read(&bc, 3)]; + dec->vector[5] = ts_codebook[5][bitstream_read(&bc, 3)]; + dec->vector[4] = ts_codebook[4][bitstream_read(&bc, 4)]; + dec->vector[3] = ts_codebook[3][bitstream_read(&bc, 4)]; + dec->vector[2] = ts_codebook[2][bitstream_read(&bc, 4)]; + dec->vector[1] = ts_codebook[1][bitstream_read(&bc, 5)]; + dec->vector[0] = ts_codebook[0][bitstream_read(&bc, 5)]; + dec->flag = bitstream_read_bit(&bc); - dec->offset1[0] = get_bits(&gb, 4) << 4; - dec->offset2[3] = get_bits(&gb, 7); - dec->offset2[2] = get_bits(&gb, 7); - dec->offset2[1] = get_bits(&gb, 7); - dec->offset2[0] = get_bits(&gb, 7); + dec->offset1[0] = bitstream_read(&bc, 4) << 4; + dec->offset2[3] = bitstream_read(&bc, 7); + dec->offset2[2] = bitstream_read(&bc, 7); + dec->offset2[1] = bitstream_read(&bc, 7); + dec->offset2[0] = bitstream_read(&bc, 7); - dec->offset1[1] = get_bits(&gb, 4); - dec->pulseval[1] = get_bits(&gb, 14); - dec->pulseval[0] = get_bits(&gb, 14); + dec->offset1[1] = bitstream_read(&bc, 4); + dec->pulseval[1] = bitstream_read(&bc, 14); + dec->pulseval[0] = bitstream_read(&bc, 14); - dec->offset1[1] |= get_bits(&gb, 4) << 4; - dec->pulseval[3] = get_bits(&gb, 14); - dec->pulseval[2] = get_bits(&gb, 14); + dec->offset1[1] |= bitstream_read(&bc, 4) << 4; + dec->pulseval[3] = bitstream_read(&bc, 14); + dec->pulseval[2] = bitstream_read(&bc, 14); - dec->offset1[0] |= get_bits1(&gb); - dec->pulsepos[0] = get_bits_long(&gb, 27); - dec->pulseoff[0] = get_bits(&gb, 4); + dec->offset1[0] |= bitstream_read_bit(&bc); + dec->pulsepos[0] = bitstream_read(&bc, 27); + dec->pulseoff[0] = bitstream_read(&bc, 4); - dec->offset1[0] |= get_bits1(&gb) << 1; - dec->pulsepos[1] = get_bits_long(&gb, 27); - dec->pulseoff[1] = get_bits(&gb, 4); + dec->offset1[0] |= bitstream_read_bit(&bc) << 1; + dec->pulsepos[1] = bitstream_read(&bc, 27); + dec->pulseoff[1] = bitstream_read(&bc, 4); - dec->offset1[0] |= get_bits1(&gb) << 2; - dec->pulsepos[2] = get_bits_long(&gb, 27); - dec->pulseoff[2] = get_bits(&gb, 4); + dec->offset1[0] |= bitstream_read_bit(&bc) << 2; + dec->pulsepos[2] = bitstream_read(&bc, 27); + dec->pulseoff[2] = bitstream_read(&bc, 4); - dec->offset1[0] |= get_bits1(&gb) << 3; - dec->pulsepos[3] = get_bits_long(&gb, 27); - dec->pulseoff[3] = get_bits(&gb, 4); + dec->offset1[0] |= bitstream_read_bit(&bc) << 3; + dec->pulsepos[3] = bitstream_read(&bc, 27); + dec->pulseoff[3] = bitstream_read(&bc, 4); } static void truespeech_correlate_filter(TSContext *dec) From 0bea79afa6cc71e38d58350d05cdeb33e97f6234 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandra=20H=C3=A1jkov=C3=A1?= Date: Thu, 14 Apr 2016 10:42:27 +0200 Subject: [PATCH 10/20] tscc2: Convert to the new bitstream reader --- libavcodec/tscc2.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/libavcodec/tscc2.c b/libavcodec/tscc2.c index d3d45e4d22..d86428afc6 100644 --- a/libavcodec/tscc2.c +++ b/libavcodec/tscc2.c @@ -28,8 +28,8 @@ #define BITSTREAM_READER_LE #include "avcodec.h" +#include "bitstream.h" #include "bytestream.h" -#include "get_bits.h" #include "internal.h" #include "mathops.h" #include "tscc2data.h" @@ -41,7 +41,7 @@ typedef struct TSCC2Context { uint8_t *slice_quants; int quant[2]; int q[2][3]; - GetBitContext gb; + BitstreamContext bc; VLC dc_vlc, nc_vlc[NUM_VLC_SETS], ac_vlc[NUM_VLC_SETS]; int block[16]; @@ -127,21 +127,21 @@ static void tscc2_idct4_put(int *in, int q[3], uint8_t *dst, int stride) static int tscc2_decode_mb(TSCC2Context *c, int *q, int vlc_set, uint8_t *dst, int stride, int plane) { - GetBitContext *gb = &c->gb; + BitstreamContext *bc = &c->bc; int prev_dc, dc, nc, ac, bpos, val; int i, j, k, l; - if (get_bits1(gb)) { - if (get_bits1(gb)) { - val = get_bits(gb, 8); + if (bitstream_read_bit(bc)) { + if (bitstream_read_bit(bc)) { + val = bitstream_read(bc, 8); for (i = 0; i < 8; i++, dst += stride) memset(dst, val, 16); } else { - if (get_bits_left(gb) < 16 * 8 * 8) + if (bitstream_bits_left(bc) < 16 * 8 * 8) return AVERROR_INVALIDDATA; for (i = 0; i < 8; i++) { for (j = 0; j < 16; j++) - dst[j] = get_bits(gb, 8); + dst[j] = bitstream_read(bc, 8); dst += stride; } } @@ -152,30 +152,30 @@ static int tscc2_decode_mb(TSCC2Context *c, int *q, int vlc_set, for (j = 0; j < 2; j++) { for (k = 0; k < 4; k++) { if (!(j | k)) { - dc = get_bits(gb, 8); + dc = bitstream_read(bc, 8); } else { - dc = get_vlc2(gb, c->dc_vlc.table, 9, 2); + dc = bitstream_read_vlc(bc, c->dc_vlc.table, 9, 2); if (dc == -1) return AVERROR_INVALIDDATA; if (dc == 0x100) - dc = get_bits(gb, 8); + dc = bitstream_read(bc, 8); } dc = (dc + prev_dc) & 0xFF; prev_dc = dc; c->block[0] = dc; - nc = get_vlc2(gb, c->nc_vlc[vlc_set].table, 9, 1); + nc = bitstream_read_vlc(bc, c->nc_vlc[vlc_set].table, 9, 1); if (nc == -1) return AVERROR_INVALIDDATA; bpos = 1; memset(c->block + 1, 0, 15 * sizeof(*c->block)); for (l = 0; l < nc; l++) { - ac = get_vlc2(gb, c->ac_vlc[vlc_set].table, 9, 2); + ac = bitstream_read_vlc(bc, c->ac_vlc[vlc_set].table, 9, 2); if (ac == -1) return AVERROR_INVALIDDATA; if (ac == 0x1000) - ac = get_bits(gb, 12); + ac = bitstream_read(bc, 12); bpos += ac & 0xF; if (bpos >= 16) return AVERROR_INVALIDDATA; @@ -195,7 +195,7 @@ static int tscc2_decode_slice(TSCC2Context *c, int mb_y, int i, mb_x, q, ret; int off; - init_get_bits(&c->gb, buf, buf_size * 8); + bitstream_init(&c->bc, buf, buf_size * 8); for (mb_x = 0; mb_x < c->mb_width; mb_x++) { q = c->slice_quants[mb_x + c->mb_width * mb_y]; From 85f760fedd49816f3a197da22f4c8e33d1b3dda7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandra=20H=C3=A1jkov=C3=A1?= Date: Thu, 14 Apr 2016 10:59:22 +0200 Subject: [PATCH 11/20] twinvq: Convert to the new bitstream reader --- libavcodec/twinvq_data.h | 2 +- libavcodec/twinvqdec.c | 42 ++++++++++++++++++++-------------------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/libavcodec/twinvq_data.h b/libavcodec/twinvq_data.h index 01a54a5ea8..cc7ba59093 100644 --- a/libavcodec/twinvq_data.h +++ b/libavcodec/twinvq_data.h @@ -130,7 +130,7 @@ static const uint16_t bark_tab_s44_128[] = { /** * TwinVQ codebooks. They are coded in a struct so we can use code such as * - * float val = tab.fcb0808l[get_bits(gb, 12)]; + * float val = tab.fcb0808l[bitstream_read(bc, 12)]; * * without risking a segfault on malformed files. */ diff --git a/libavcodec/twinvqdec.c b/libavcodec/twinvqdec.c index 56df10557a..6355ad4ed2 100644 --- a/libavcodec/twinvqdec.c +++ b/libavcodec/twinvqdec.c @@ -23,8 +23,9 @@ #include #include "libavutil/channel_layout.h" + #include "avcodec.h" -#include "get_bits.h" +#include "bitstream.h" #include "internal.h" #include "twinvq.h" #include "twinvq_data.h" @@ -235,7 +236,7 @@ static void dec_bark_env(TwinVQContext *tctx, const uint8_t *in, int use_hist, } } -static void read_cb_data(TwinVQContext *tctx, GetBitContext *gb, +static void read_cb_data(TwinVQContext *tctx, BitstreamContext *bc, uint8_t *dst, enum TwinVQFrameType ftype) { int i; @@ -243,8 +244,8 @@ static void read_cb_data(TwinVQContext *tctx, GetBitContext *gb, for (i = 0; i < tctx->n_div[ftype]; i++) { int bs_second_part = (i >= tctx->bits_main_spec_change[ftype]); - *dst++ = get_bits(gb, tctx->bits_main_spec[0][ftype][bs_second_part]); - *dst++ = get_bits(gb, tctx->bits_main_spec[1][ftype][bs_second_part]); + *dst++ = bitstream_read(bc, tctx->bits_main_spec[0][ftype][bs_second_part]); + *dst++ = bitstream_read(bc, tctx->bits_main_spec[1][ftype][bs_second_part]); } } @@ -255,13 +256,13 @@ static int twinvq_read_bitstream(AVCodecContext *avctx, TwinVQContext *tctx, const TwinVQModeTab *mtab = tctx->mtab; int channels = tctx->avctx->channels; int sub; - GetBitContext gb; + BitstreamContext bc; int i, j, k; - init_get_bits(&gb, buf, buf_size * 8); - skip_bits(&gb, get_bits(&gb, 8)); + bitstream_init(&bc, buf, buf_size * 8); + bitstream_skip(&bc, bitstream_read(&bc, 8)); - bits->window_type = get_bits(&gb, TWINVQ_WINDOW_TYPE_BITS); + bits->window_type = bitstream_read(&bc, TWINVQ_WINDOW_TYPE_BITS); if (bits->window_type > 8) { av_log(avctx, AV_LOG_ERROR, "Invalid window type, broken sample?\n"); @@ -272,43 +273,42 @@ static int twinvq_read_bitstream(AVCodecContext *avctx, TwinVQContext *tctx, sub = mtab->fmode[bits->ftype].sub; - read_cb_data(tctx, &gb, bits->main_coeffs, bits->ftype); + read_cb_data(tctx, &bc, bits->main_coeffs, bits->ftype); for (i = 0; i < channels; i++) for (j = 0; j < sub; j++) for (k = 0; k < mtab->fmode[bits->ftype].bark_n_coef; k++) bits->bark1[i][j][k] = - get_bits(&gb, mtab->fmode[bits->ftype].bark_n_bit); + bitstream_read(&bc, mtab->fmode[bits->ftype].bark_n_bit); for (i = 0; i < channels; i++) for (j = 0; j < sub; j++) - bits->bark_use_hist[i][j] = get_bits1(&gb); + bits->bark_use_hist[i][j] = bitstream_read_bit(&bc); if (bits->ftype == TWINVQ_FT_LONG) { for (i = 0; i < channels; i++) - bits->gain_bits[i] = get_bits(&gb, TWINVQ_GAIN_BITS); + bits->gain_bits[i] = bitstream_read(&bc, TWINVQ_GAIN_BITS); } else { for (i = 0; i < channels; i++) { - bits->gain_bits[i] = get_bits(&gb, TWINVQ_GAIN_BITS); + bits->gain_bits[i] = bitstream_read(&bc, TWINVQ_GAIN_BITS); for (j = 0; j < sub; j++) - bits->sub_gain_bits[i * sub + j] = get_bits(&gb, - TWINVQ_SUB_GAIN_BITS); + bits->sub_gain_bits[i * sub + j] = bitstream_read(&bc, TWINVQ_SUB_GAIN_BITS); } } for (i = 0; i < channels; i++) { - bits->lpc_hist_idx[i] = get_bits(&gb, mtab->lsp_bit0); - bits->lpc_idx1[i] = get_bits(&gb, mtab->lsp_bit1); + bits->lpc_hist_idx[i] = bitstream_read(&bc, mtab->lsp_bit0); + bits->lpc_idx1[i] = bitstream_read(&bc, mtab->lsp_bit1); for (j = 0; j < mtab->lsp_split; j++) - bits->lpc_idx2[i][j] = get_bits(&gb, mtab->lsp_bit2); + bits->lpc_idx2[i][j] = bitstream_read(&bc, mtab->lsp_bit2); } if (bits->ftype == TWINVQ_FT_LONG) { - read_cb_data(tctx, &gb, bits->ppc_coeffs, 3); + read_cb_data(tctx, &bc, bits->ppc_coeffs, 3); for (i = 0; i < channels; i++) { - bits->p_coef[i] = get_bits(&gb, mtab->ppc_period_bit); - bits->g_coef[i] = get_bits(&gb, mtab->pgain_bit); + bits->p_coef[i] = bitstream_read(&bc, mtab->ppc_period_bit); + bits->g_coef[i] = bitstream_read(&bc, mtab->pgain_bit); } } From 104a4289f925c600c13035de6c282fe656510a27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandra=20H=C3=A1jkov=C3=A1?= Date: Thu, 14 Apr 2016 11:07:15 +0200 Subject: [PATCH 12/20] utvideodec: Convert to the new bitstream reader --- libavcodec/utvideodec.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/libavcodec/utvideodec.c b/libavcodec/utvideodec.c index 3a581568dd..29de815d4e 100644 --- a/libavcodec/utvideodec.c +++ b/libavcodec/utvideodec.c @@ -28,10 +28,11 @@ #include #include "libavutil/intreadwrite.h" + #include "avcodec.h" +#include "bitstream.h" #include "bswapdsp.h" #include "bytestream.h" -#include "get_bits.h" #include "thread.h" #include "utvideo.h" @@ -85,7 +86,7 @@ static int decode_plane(UtvideoContext *c, int plane_no, int i, j, slice, pix; int sstart, send; VLC vlc; - GetBitContext gb; + BitstreamContext bc; int prev, fsym; const int cmask = ~(!plane_no && c->avctx->pix_fmt == AV_PIX_FMT_YUV420P); @@ -146,17 +147,17 @@ static int decode_plane(UtvideoContext *c, int plane_no, c->bdsp.bswap_buf((uint32_t *) c->slice_bits, (uint32_t *) c->slice_bits, (slice_data_end - slice_data_start + 3) >> 2); - init_get_bits(&gb, c->slice_bits, slice_size * 8); + bitstream_init(&bc, c->slice_bits, slice_size * 8); prev = 0x80; for (j = sstart; j < send; j++) { for (i = 0; i < width * step; i += step) { - if (get_bits_left(&gb) <= 0) { + if (bitstream_bits_left(&bc) <= 0) { av_log(c->avctx, AV_LOG_ERROR, "Slice decoding ran out of bits\n"); goto fail; } - pix = get_vlc2(&gb, vlc.table, vlc.bits, 4); + pix = bitstream_read_vlc(&bc, vlc.table, vlc.bits, 4); if (pix < 0) { av_log(c->avctx, AV_LOG_ERROR, "Decoding error\n"); goto fail; @@ -169,9 +170,9 @@ static int decode_plane(UtvideoContext *c, int plane_no, } dest += stride; } - if (get_bits_left(&gb) > 32) + if (bitstream_bits_left(&bc) > 32) av_log(c->avctx, AV_LOG_WARNING, - "%d bits left after decoding slice\n", get_bits_left(&gb)); + "%d bits left after decoding slice\n", bitstream_bits_left(&bc)); } ff_free_vlc(&vlc); From e5bdfc679004199c4a1837e256046331e5e4e713 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandra=20H=C3=A1jkov=C3=A1?= Date: Thu, 14 Apr 2016 11:52:48 +0200 Subject: [PATCH 13/20] vble: Convert to the new bitstream reader --- libavcodec/vble.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/libavcodec/vble.c b/libavcodec/vble.c index 1a78036731..fef10903dd 100644 --- a/libavcodec/vble.c +++ b/libavcodec/vble.c @@ -28,7 +28,7 @@ #define BITSTREAM_READER_LE #include "avcodec.h" -#include "get_bits.h" +#include "bitstream.h" #include "huffyuvdsp.h" #include "internal.h" #include "mathops.h" @@ -41,18 +41,18 @@ typedef struct VBLEContext { uint8_t *val; /* First holds the lengths of vlc symbols and then their values */ } VBLEContext; -static uint8_t vble_read_reverse_unary(GetBitContext *gb) +static uint8_t vble_read_reverse_unary(BitstreamContext *bc) { /* At most we need to read 9 bits total to get indices up to 8 */ - uint8_t val = show_bits(gb, 8); + uint8_t val = bitstream_peek(bc, 8); if (val) { val = 7 - av_log2_16bit(ff_reverse[val]); - skip_bits(gb, val + 1); + bitstream_skip(bc, val + 1); return val; } else { - skip_bits(gb, 8); - if (get_bits1(gb)) + bitstream_skip(bc, 8); + if (bitstream_read_bit(bc)) return 8; } @@ -60,13 +60,13 @@ static uint8_t vble_read_reverse_unary(GetBitContext *gb) return UINT8_MAX; } -static int vble_unpack(VBLEContext *ctx, GetBitContext *gb) +static int vble_unpack(VBLEContext *ctx, BitstreamContext *bc) { int i; /* Read all the lengths in first */ for (i = 0; i < ctx->size; i++) { - ctx->val[i] = vble_read_reverse_unary(gb); + ctx->val[i] = vble_read_reverse_unary(bc); if (ctx->val[i] == UINT8_MAX) return -1; @@ -74,12 +74,12 @@ static int vble_unpack(VBLEContext *ctx, GetBitContext *gb) for (i = 0; i < ctx->size; i++) { /* Check we have enough bits left */ - if (get_bits_left(gb) < ctx->val[i]) + if (bitstream_bits_left(bc) < ctx->val[i]) return -1; /* get_bits can't take a length of 0 */ if (ctx->val[i]) - ctx->val[i] = (1 << ctx->val[i]) + get_bits(gb, ctx->val[i]) - 1; + ctx->val[i] = (1 << ctx->val[i]) + bitstream_read(bc, ctx->val[i]) - 1; } return 0; @@ -118,7 +118,7 @@ static int vble_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, { VBLEContext *ctx = avctx->priv_data; AVFrame *pic = data; - GetBitContext gb; + BitstreamContext bc; const uint8_t *src = avpkt->data; int version; int offset = 0; @@ -140,10 +140,10 @@ static int vble_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, if (version != 1) av_log(avctx, AV_LOG_WARNING, "Unsupported VBLE Version: %d\n", version); - init_get_bits(&gb, src + 4, (avpkt->size - 4) * 8); + bitstream_init(&bc, src + 4, (avpkt->size - 4) * 8); /* Unpack */ - if (vble_unpack(ctx, &gb) < 0) { + if (vble_unpack(ctx, &bc) < 0) { av_log(avctx, AV_LOG_ERROR, "Invalid Code\n"); return AVERROR_INVALIDDATA; } From 0536e7d78248d8c563f21271fa5ace0b4f38c727 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandra=20H=C3=A1jkov=C3=A1?= Date: Thu, 14 Apr 2016 11:59:21 +0200 Subject: [PATCH 14/20] vima: Convert to the new bitstream reader --- libavcodec/vima.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/libavcodec/vima.c b/libavcodec/vima.c index 6f539a86b6..0db18972a2 100644 --- a/libavcodec/vima.c +++ b/libavcodec/vima.c @@ -29,7 +29,7 @@ #include "adpcm_data.h" #include "avcodec.h" -#include "get_bits.h" +#include "bitstream.h" #include "internal.h" static int predict_table_init = 0; @@ -118,7 +118,7 @@ static av_cold int decode_init(AVCodecContext *avctx) static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *pkt) { - GetBitContext gb; + BitstreamContext bc; AVFrame *frame = data; int16_t pcm_data[2]; uint32_t samples; @@ -129,19 +129,19 @@ static int decode_frame(AVCodecContext *avctx, void *data, if (pkt->size < 13) return AVERROR_INVALIDDATA; - if ((ret = init_get_bits8(&gb, pkt->data, pkt->size)) < 0) + if ((ret = bitstream_init8(&bc, pkt->data, pkt->size)) < 0) return ret; - samples = get_bits_long(&gb, 32); + samples = bitstream_read(&bc, 32); if (samples == 0xffffffff) { - skip_bits_long(&gb, 32); - samples = get_bits_long(&gb, 32); + bitstream_skip(&bc, 32); + samples = bitstream_read(&bc, 32); } if (samples > pkt->size * 2) return AVERROR_INVALIDDATA; - channel_hint[0] = get_sbits(&gb, 8); + channel_hint[0] = bitstream_read_signed(&bc, 8); if (channel_hint[0] & 0x80) { channel_hint[0] = ~channel_hint[0]; channels = 2; @@ -149,10 +149,10 @@ static int decode_frame(AVCodecContext *avctx, void *data, avctx->channels = channels; avctx->channel_layout = (channels == 2) ? AV_CH_LAYOUT_STEREO : AV_CH_LAYOUT_MONO; - pcm_data[0] = get_sbits(&gb, 16); + pcm_data[0] = bitstream_read_signed(&bc, 16); if (channels > 1) { - channel_hint[1] = get_sbits(&gb, 8); - pcm_data[1] = get_sbits(&gb, 16); + channel_hint[1] = bitstream_read_signed(&bc, 8); + pcm_data[1] = bitstream_read_signed(&bc, 16); } frame->nb_samples = samples; @@ -170,7 +170,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, step_index = av_clip(step_index, 0, 88); lookup_size = size_table[step_index]; - lookup = get_bits(&gb, lookup_size); + lookup = bitstream_read(&bc, lookup_size); highbit = 1 << (lookup_size - 1); lowbits = highbit - 1; @@ -180,7 +180,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, highbit = 0; if (lookup == lowbits) { - output = get_sbits(&gb, 16); + output = bitstream_read_signed(&bc, 16); } else { int predict_index, diff; From f9c59f26c852cec4dd7e5c04d26ec284a796a919 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandra=20H=C3=A1jkov=C3=A1?= Date: Fri, 15 Apr 2016 10:50:38 +0200 Subject: [PATCH 15/20] wnv1: Convert to the new bitstream reader --- libavcodec/wnv1.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/libavcodec/wnv1.c b/libavcodec/wnv1.c index d0304c97ad..80d66ae96c 100644 --- a/libavcodec/wnv1.c +++ b/libavcodec/wnv1.c @@ -25,7 +25,7 @@ */ #include "avcodec.h" -#include "get_bits.h" +#include "bitstream.h" #include "internal.h" #include "mathops.h" @@ -34,7 +34,7 @@ typedef struct WNV1Context { AVCodecContext *avctx; int shift; - GetBitContext gb; + BitstreamContext bc; } WNV1Context; static const uint16_t code_tab[16][2] = { @@ -49,10 +49,10 @@ static VLC code_vlc; /* returns modified base_value */ static inline int wnv1_get_code(WNV1Context *w, int base_value) { - int v = get_vlc2(&w->gb, code_vlc.table, CODE_VLC_BITS, 1); + int v = bitstream_read_vlc(&w->bc, code_vlc.table, CODE_VLC_BITS, 1); if (v == 15) - return ff_reverse[get_bits(&w->gb, 8 - w->shift)]; + return ff_reverse[bitstream_read(&w->bc, 8 - w->shift)]; else return base_value + ((v - 7) << w->shift); } @@ -90,7 +90,7 @@ static int decode_frame(AVCodecContext *avctx, for (i = 8; i < buf_size; i++) rbuf[i] = ff_reverse[buf[i]]; - init_get_bits(&l->gb, rbuf + 8, (buf_size - 8) * 8); + bitstream_init(&l->bc, rbuf + 8, (buf_size - 8) * 8); if (buf[2] >> 4 == 6) l->shift = 2; From be35ef92a418916f0fceaf18af5f5b768c44117f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandra=20H=C3=A1jkov=C3=A1?= Date: Fri, 15 Apr 2016 10:57:22 +0200 Subject: [PATCH 16/20] xan: Convert to the new bitstream reader --- libavcodec/xan.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libavcodec/xan.c b/libavcodec/xan.c index c16c651d7b..33149e5ff7 100644 --- a/libavcodec/xan.c +++ b/libavcodec/xan.c @@ -37,8 +37,8 @@ #define BITSTREAM_READER_LE #include "avcodec.h" +#include "bitstream.h" #include "bytestream.h" -#include "get_bits.h" #include "internal.h" #define RUNTIME_GAMMA 0 @@ -124,15 +124,15 @@ static int xan_huffman_decode(unsigned char *dest, int dest_len, unsigned char val = ival; unsigned char *dest_end = dest + dest_len; unsigned char *dest_start = dest; - GetBitContext gb; + BitstreamContext bc; if (ptr_len < 0) return AVERROR_INVALIDDATA; - init_get_bits(&gb, ptr, ptr_len * 8); + bitstream_init(&bc, ptr, ptr_len * 8); while (val != 0x16) { - unsigned idx = val - 0x17 + get_bits1(&gb) * byte; + unsigned idx = val - 0x17 + bitstream_read_bit(&bc) * byte; if (idx >= 2 * byte) return AVERROR_INVALIDDATA; val = src[idx]; From 178b4ea5f9a43009781311af2737284fdca48a5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandra=20H=C3=A1jkov=C3=A1?= Date: Fri, 15 Apr 2016 11:03:55 +0200 Subject: [PATCH 17/20] xsubdec: Convert to the new bitstream reader --- libavcodec/xsubdec.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/libavcodec/xsubdec.c b/libavcodec/xsubdec.c index 3af300c22b..a07f94ce73 100644 --- a/libavcodec/xsubdec.c +++ b/libavcodec/xsubdec.c @@ -21,8 +21,9 @@ #include "libavutil/mathematics.h" #include "libavutil/imgutils.h" + #include "avcodec.h" -#include "get_bits.h" +#include "bitstream.h" #include "bytestream.h" static av_cold int decode_init(AVCodecContext *avctx) { @@ -55,7 +56,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, uint8_t *bitmap; int w, h, x, y, i; int64_t packet_time = 0; - GetBitContext gb; + BitstreamContext bc; int has_alpha = avctx->codec_tag == MKTAG('D','X','S','A'); memset(sub, 0, sizeof(*sub)); @@ -146,15 +147,15 @@ FF_ENABLE_DEPRECATION_WARNINGS #endif // process RLE-compressed data - init_get_bits(&gb, buf, (buf_end - buf) * 8); + bitstream_init(&bc, buf, (buf_end - buf) * 8); bitmap = sub->rects[0]->data[0]; for (y = 0; y < h; y++) { // interlaced: do odd lines if (y == (h + 1) / 2) bitmap = sub->rects[0]->data[0] + w; for (x = 0; x < w; ) { - int log2 = ff_log2_tab[show_bits(&gb, 8)]; - int run = get_bits(&gb, 14 - 4 * (log2 >> 1)); - int color = get_bits(&gb, 2); + int log2 = ff_log2_tab[bitstream_peek(&bc, 8)]; + int run = bitstream_read(&bc, 14 - 4 * (log2 >> 1)); + int color = bitstream_read(&bc, 2); run = FFMIN(run, w - x); // run length 0 means till end of row if (!run) run = w - x; @@ -164,7 +165,7 @@ FF_ENABLE_DEPRECATION_WARNINGS } // interlaced, skip every second line bitmap += w; - align_get_bits(&gb); + bitstream_align(&bc); } *data_size = 1; return buf_size; From 8d1997add6220b7d956dcfdcc9f711efb56ca30d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandra=20H=C3=A1jkov=C3=A1?= Date: Sat, 16 Apr 2016 17:46:29 +0200 Subject: [PATCH 18/20] mpegts: Convert to the new bitstream reader --- libavformat/mpegts.c | 48 +++++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c index 28b6d37bb3..5024404111 100644 --- a/libavformat/mpegts.c +++ b/libavformat/mpegts.c @@ -26,9 +26,11 @@ #include "libavutil/dict.h" #include "libavutil/mathematics.h" #include "libavutil/opt.h" + +#include "libavcodec/bitstream.h" #include "libavcodec/bytestream.h" -#include "libavcodec/get_bits.h" #include "libavcodec/opus.h" + #include "avformat.h" #include "mpegts.h" #include "internal.h" @@ -735,56 +737,56 @@ static void new_pes_packet(PESContext *pes, AVPacket *pkt) static int read_sl_header(PESContext *pes, SLConfigDescr *sl, const uint8_t *buf, int buf_size) { - GetBitContext gb; + BitstreamContext bc; int au_start_flag = 0, au_end_flag = 0, ocr_flag = 0, idle_flag = 0; int padding_flag = 0, padding_bits = 0, inst_bitrate_flag = 0; int dts_flag = -1, cts_flag = -1; int64_t dts = AV_NOPTS_VALUE, cts = AV_NOPTS_VALUE; - init_get_bits(&gb, buf, buf_size * 8); + bitstream_init(&bc, buf, buf_size * 8); if (sl->use_au_start) - au_start_flag = get_bits1(&gb); + au_start_flag = bitstream_read_bit(&bc); if (sl->use_au_end) - au_end_flag = get_bits1(&gb); + au_end_flag = bitstream_read_bit(&bc); if (!sl->use_au_start && !sl->use_au_end) au_start_flag = au_end_flag = 1; if (sl->ocr_len > 0) - ocr_flag = get_bits1(&gb); + ocr_flag = bitstream_read_bit(&bc); if (sl->use_idle) - idle_flag = get_bits1(&gb); + idle_flag = bitstream_read_bit(&bc); if (sl->use_padding) - padding_flag = get_bits1(&gb); + padding_flag = bitstream_read_bit(&bc); if (padding_flag) - padding_bits = get_bits(&gb, 3); + padding_bits = bitstream_read(&bc, 3); if (!idle_flag && (!padding_flag || padding_bits != 0)) { if (sl->packet_seq_num_len) - skip_bits_long(&gb, sl->packet_seq_num_len); + bitstream_skip(&bc, sl->packet_seq_num_len); if (sl->degr_prior_len) - if (get_bits1(&gb)) - skip_bits(&gb, sl->degr_prior_len); + if (bitstream_read_bit(&bc)) + bitstream_skip(&bc, sl->degr_prior_len); if (ocr_flag) - skip_bits_long(&gb, sl->ocr_len); + bitstream_skip(&bc, sl->ocr_len); if (au_start_flag) { if (sl->use_rand_acc_pt) - get_bits1(&gb); + bitstream_read_bit(&bc); if (sl->au_seq_num_len > 0) - skip_bits_long(&gb, sl->au_seq_num_len); + bitstream_skip(&bc, sl->au_seq_num_len); if (sl->use_timestamps) { - dts_flag = get_bits1(&gb); - cts_flag = get_bits1(&gb); + dts_flag = bitstream_read_bit(&bc); + cts_flag = bitstream_read_bit(&bc); } } if (sl->inst_bitrate_len) - inst_bitrate_flag = get_bits1(&gb); + inst_bitrate_flag = bitstream_read_bit(&bc); if (dts_flag == 1) - dts = get_bits64(&gb, sl->timestamp_len); + dts = bitstream_read_63(&bc, sl->timestamp_len); if (cts_flag == 1) - cts = get_bits64(&gb, sl->timestamp_len); + cts = bitstream_read_63(&bc, sl->timestamp_len); if (sl->au_len > 0) - skip_bits_long(&gb, sl->au_len); + bitstream_skip(&bc, sl->au_len); if (inst_bitrate_flag) - skip_bits_long(&gb, sl->inst_bitrate_len); + bitstream_skip(&bc, sl->inst_bitrate_len); } if (dts != AV_NOPTS_VALUE) @@ -795,7 +797,7 @@ static int read_sl_header(PESContext *pes, SLConfigDescr *sl, if (sl->timestamp_len && sl->timestamp_res) avpriv_set_pts_info(pes->st, sl->timestamp_len, 1, sl->timestamp_res); - return (get_bits_count(&gb) + 7) >> 3; + return (bitstream_tell(&bc) + 7) >> 3; } /* return non zero if a packet could be constructed */ From 2cef81a87cd88cf7904ef815ee109e3611fe3fa4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandra=20H=C3=A1jkov=C3=A1?= Date: Sat, 16 Apr 2016 17:51:16 +0200 Subject: [PATCH 19/20] ogg: Convert to the new bitstream reader --- libavformat/oggparseflac.c | 22 +++++++++++--------- libavformat/oggparsetheora.c | 39 +++++++++++++++++++----------------- 2 files changed, 33 insertions(+), 28 deletions(-) diff --git a/libavformat/oggparseflac.c b/libavformat/oggparseflac.c index dab1040cc4..90b1495c51 100644 --- a/libavformat/oggparseflac.c +++ b/libavformat/oggparseflac.c @@ -19,8 +19,10 @@ */ #include -#include "libavcodec/get_bits.h" + +#include "libavcodec/bitstream.h" #include "libavcodec/flac.h" + #include "avformat.h" #include "internal.h" #include "oggdec.h" @@ -33,28 +35,28 @@ flac_header (AVFormatContext * s, int idx) struct ogg *ogg = s->priv_data; struct ogg_stream *os = ogg->streams + idx; AVStream *st = s->streams[idx]; - GetBitContext gb; + BitstreamContext bc; int mdt; if (os->buf[os->pstart] == 0xff) return 0; - init_get_bits(&gb, os->buf + os->pstart, os->psize*8); - skip_bits1(&gb); /* metadata_last */ - mdt = get_bits(&gb, 7); + bitstream_init(&bc, os->buf + os->pstart, os->psize * 8); + bitstream_skip(&bc, 1); /* metadata_last */ + mdt = bitstream_read(&bc, 7); if (mdt == OGG_FLAC_METADATA_TYPE_STREAMINFO) { uint8_t *streaminfo_start = os->buf + os->pstart + 5 + 4 + 4 + 4; uint32_t samplerate; - skip_bits_long(&gb, 4*8); /* "FLAC" */ - if(get_bits(&gb, 8) != 1) /* unsupported major version */ + bitstream_skip(&bc, 4 * 8); /* "FLAC" */ + if (bitstream_read(&bc, 8) != 1) /* unsupported major version */ return -1; - skip_bits_long(&gb, 8 + 16); /* minor version + header count */ - skip_bits_long(&gb, 4*8); /* "fLaC" */ + bitstream_skip(&bc, 8 + 16); /* minor version + header count */ + bitstream_skip(&bc, 4 * 8); /* "fLaC" */ /* METADATA_BLOCK_HEADER */ - if (get_bits_long(&gb, 32) != FLAC_STREAMINFO_SIZE) + if (bitstream_read(&bc, 32) != FLAC_STREAMINFO_SIZE) return -1; st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; diff --git a/libavformat/oggparsetheora.c b/libavformat/oggparsetheora.c index 1e7a776c06..da47a0cd89 100644 --- a/libavformat/oggparsetheora.c +++ b/libavformat/oggparsetheora.c @@ -23,8 +23,11 @@ **/ #include + #include "libavutil/bswap.h" -#include "libavcodec/get_bits.h" + +#include "libavcodec/bitstream.h" + #include "avformat.h" #include "internal.h" #include "oggdec.h" @@ -57,41 +60,41 @@ static int theora_header(AVFormatContext *s, int idx) switch (os->buf[os->pstart]) { case 0x80: { - GetBitContext gb; + BitstreamContext bc; AVRational timebase; - init_get_bits(&gb, os->buf + os->pstart, os->psize * 8); + bitstream_init(&bc, os->buf + os->pstart, os->psize * 8); /* 0x80"theora" */ - skip_bits_long(&gb, 7 * 8); + bitstream_skip(&bc, 7 * 8); - thp->version = get_bits_long(&gb, 24); + thp->version = bitstream_read(&bc, 24); if (thp->version < 0x030100) { av_log(s, AV_LOG_ERROR, "Too old or unsupported Theora (%x)\n", thp->version); return AVERROR(ENOSYS); } - st->codecpar->width = get_bits(&gb, 16) << 4; - st->codecpar->height = get_bits(&gb, 16) << 4; + st->codecpar->width = bitstream_read(&bc, 16) << 4; + st->codecpar->height = bitstream_read(&bc, 16) << 4; if (thp->version >= 0x030400) - skip_bits(&gb, 100); + bitstream_skip(&bc, 100); if (thp->version >= 0x030200) { - int width = get_bits_long(&gb, 24); - int height = get_bits_long(&gb, 24); + int width = bitstream_read(&bc, 24); + int height = bitstream_read(&bc, 24); if (width <= st->codecpar->width && width > st->codecpar->width - 16 && height <= st->codecpar->height && height > st->codecpar->height - 16) { st->codecpar->width = width; st->codecpar->height = height; } - skip_bits(&gb, 16); + bitstream_skip(&bc, 16); } - timebase.den = get_bits_long(&gb, 32); - timebase.num = get_bits_long(&gb, 32); + timebase.den = bitstream_read(&bc, 32); + timebase.num = bitstream_read(&bc, 32); if (!(timebase.num > 0 && timebase.den > 0)) { av_log(s, AV_LOG_WARNING, "Invalid time base in theora stream, assuming 25 FPS\n"); timebase.num = 1; @@ -99,15 +102,15 @@ static int theora_header(AVFormatContext *s, int idx) } avpriv_set_pts_info(st, 64, timebase.num, timebase.den); - st->sample_aspect_ratio.num = get_bits_long(&gb, 24); - st->sample_aspect_ratio.den = get_bits_long(&gb, 24); + st->sample_aspect_ratio.num = bitstream_read(&bc, 24); + st->sample_aspect_ratio.den = bitstream_read(&bc, 24); if (thp->version >= 0x030200) - skip_bits_long(&gb, 38); + bitstream_skip(&bc, 38); if (thp->version >= 0x304000) - skip_bits(&gb, 2); + bitstream_skip(&bc, 2); - thp->gpshift = get_bits(&gb, 5); + thp->gpshift = bitstream_read(&bc, 5); thp->gpmask = (1 << thp->gpshift) - 1; st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; From 2dbe2aa2c2d4f02d2669feae45dee4fc45414813 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandra=20H=C3=A1jkov=C3=A1?= Date: Sat, 16 Apr 2016 17:58:30 +0200 Subject: [PATCH 20/20] rdt: Convert to the new bitstream reader --- libavformat/rdt.c | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/libavformat/rdt.c b/libavformat/rdt.c index eb718cfe81..da5ff59c22 100644 --- a/libavformat/rdt.c +++ b/libavformat/rdt.c @@ -25,6 +25,8 @@ * @author Ronald S. Bultje */ +#include "libavcodec/bitstream.h" + #include "avformat.h" #include "libavutil/avstring.h" #include "rtpdec.h" @@ -34,7 +36,6 @@ #include "rm.h" #include "internal.h" #include "avio_internal.h" -#include "libavcodec/get_bits.h" struct RDTDemuxContext { AVFormatContext *ic; /**< the containing (RTSP) demux context */ @@ -191,7 +192,7 @@ ff_rdt_parse_header(const uint8_t *buf, int len, int *pset_id, int *pseq_no, int *pstream_id, int *pis_keyframe, uint32_t *ptimestamp) { - GetBitContext gb; + BitstreamContext bc; int consumed = 0, set_id, seq_no, stream_id, is_keyframe, len_included, need_reliable; uint32_t timestamp; @@ -261,24 +262,24 @@ ff_rdt_parse_header(const uint8_t *buf, int len, * [2] http://www.wireshark.org/docs/dfref/r/rdt.html and * http://anonsvn.wireshark.org/viewvc/trunk/epan/dissectors/packet-rdt.c */ - init_get_bits(&gb, buf, len << 3); - len_included = get_bits1(&gb); - need_reliable = get_bits1(&gb); - set_id = get_bits(&gb, 5); - skip_bits(&gb, 1); - seq_no = get_bits(&gb, 16); + bitstream_init(&bc, buf, len << 3); + len_included = bitstream_read_bit(&bc); + need_reliable = bitstream_read_bit(&bc); + set_id = bitstream_read(&bc, 5); + bitstream_skip(&bc, 1); + seq_no = bitstream_read(&bc, 16); if (len_included) - skip_bits(&gb, 16); - skip_bits(&gb, 2); - stream_id = get_bits(&gb, 5); - is_keyframe = !get_bits1(&gb); - timestamp = get_bits_long(&gb, 32); + bitstream_skip(&bc, 16); + bitstream_skip(&bc, 2); + stream_id = bitstream_read(&bc, 5); + is_keyframe = !bitstream_read_bit(&bc); + timestamp = bitstream_read(&bc, 32); if (set_id == 0x1f) - set_id = get_bits(&gb, 16); + set_id = bitstream_read(&bc, 16); if (need_reliable) - skip_bits(&gb, 16); + bitstream_skip(&bc, 16); if (stream_id == 0x1f) - stream_id = get_bits(&gb, 16); + stream_id = bitstream_read(&bc, 16); if (pset_id) *pset_id = set_id; if (pseq_no) *pseq_no = seq_no; @@ -286,7 +287,7 @@ ff_rdt_parse_header(const uint8_t *buf, int len, if (pis_keyframe) *pis_keyframe = is_keyframe; if (ptimestamp) *ptimestamp = timestamp; - return consumed + (get_bits_count(&gb) >> 3); + return consumed + (bitstream_tell(&bc) >> 3); } /**< return 0 on packet, no more left, 1 on packet, 1 on partial packet... */