From d7fe11634c1ad3433d5ea5a08604692d583fea2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandra=20H=C3=A1jkov=C3=A1?= Date: Sun, 10 Apr 2016 21:41:02 +0200 Subject: [PATCH 1/4] motionpixels: Convert to the new bitstream reader --- libavcodec/motionpixels.c | 77 ++++++++++++++++++++------------------- 1 file changed, 40 insertions(+), 37 deletions(-) diff --git a/libavcodec/motionpixels.c b/libavcodec/motionpixels.c index a18541b852..333f18fdb2 100644 --- a/libavcodec/motionpixels.c +++ b/libavcodec/motionpixels.c @@ -20,7 +20,7 @@ */ #include "avcodec.h" -#include "get_bits.h" +#include "bitstream.h" #include "bswapdsp.h" #include "internal.h" @@ -87,17 +87,18 @@ static av_cold int mp_decode_init(AVCodecContext *avctx) return 0; } -static void mp_read_changes_map(MotionPixelsContext *mp, GetBitContext *gb, int count, int bits_len, int read_color) +static void mp_read_changes_map(MotionPixelsContext *mp, BitstreamContext *bc, + int count, int bits_len, int read_color) { uint16_t *pixels; int offset, w, h, color = 0, x, y, i; while (count--) { - offset = get_bits_long(gb, mp->offset_bits_len); - w = get_bits(gb, bits_len) + 1; - h = get_bits(gb, bits_len) + 1; + offset = bitstream_read(bc, mp->offset_bits_len); + w = bitstream_read(bc, bits_len) + 1; + h = bitstream_read(bc, bits_len) + 1; if (read_color) - color = get_bits(gb, 15); + color = bitstream_read(bc, 15); x = offset % mp->avctx->width; y = offset / mp->avctx->width; if (y >= mp->avctx->height) @@ -116,16 +117,17 @@ static void mp_read_changes_map(MotionPixelsContext *mp, GetBitContext *gb, int } } -static void mp_get_code(MotionPixelsContext *mp, GetBitContext *gb, int size, int code) +static void mp_get_code(MotionPixelsContext *mp, BitstreamContext *bc, + int size, int code) { - while (get_bits1(gb)) { + while (bitstream_read_bit(bc)) { ++size; if (size > mp->max_codes_bits) { av_log(mp->avctx, AV_LOG_ERROR, "invalid code size %d/%d\n", size, mp->max_codes_bits); return; } code <<= 1; - mp_get_code(mp, gb, size, code + 1); + mp_get_code(mp, bc, size, code + 1); } if (mp->current_codes_count >= MAX_HUFF_CODES) { av_log(mp->avctx, AV_LOG_ERROR, "too many codes\n"); @@ -135,18 +137,18 @@ static void mp_get_code(MotionPixelsContext *mp, GetBitContext *gb, int size, in mp->codes[mp->current_codes_count++].size = size; } -static void mp_read_codes_table(MotionPixelsContext *mp, GetBitContext *gb) +static void mp_read_codes_table(MotionPixelsContext *mp, BitstreamContext *bc) { if (mp->codes_count == 1) { - mp->codes[0].delta = get_bits(gb, 4); + mp->codes[0].delta = bitstream_read(bc, 4); } else { int i; - mp->max_codes_bits = get_bits(gb, 4); + mp->max_codes_bits = bitstream_read(bc, 4); for (i = 0; i < mp->codes_count; ++i) - mp->codes[i].delta = get_bits(gb, 4); + mp->codes[i].delta = bitstream_read(bc, 4); mp->current_codes_count = 0; - mp_get_code(mp, gb, 0, 0); + mp_get_code(mp, bc, 0, 0); } } @@ -175,16 +177,16 @@ static void mp_set_rgb_from_yuv(MotionPixelsContext *mp, int x, int y, const Yuv *(uint16_t *)&mp->frame->data[0][y * mp->frame->linesize[0] + x * 2] = color; } -static int mp_get_vlc(MotionPixelsContext *mp, GetBitContext *gb) +static int mp_get_vlc(MotionPixelsContext *mp, BitstreamContext *bc) { int i; - i = (mp->codes_count == 1) ? 0 : get_vlc2(gb, mp->vlc.table, mp->max_codes_bits, 1); + i = (mp->codes_count == 1) ? 0 : bitstream_read_vlc(bc, mp->vlc.table, mp->max_codes_bits, 1); i = FFMIN(i, FF_ARRAY_ELEMS(mp->codes) - 1); return mp->codes[i].delta; } -static void mp_decode_line(MotionPixelsContext *mp, GetBitContext *gb, int y) +static void mp_decode_line(MotionPixelsContext *mp, BitstreamContext *bc, int y) { YuvPixel p; const int y0 = y * mp->avctx->width; @@ -211,13 +213,13 @@ static void mp_decode_line(MotionPixelsContext *mp, GetBitContext *gb, int y) memset(mp->gradient_scale, 1, sizeof(mp->gradient_scale)); p = mp_get_yuv_from_rgb(mp, x - 1, y); } else { - p.y += mp_gradient(mp, 0, mp_get_vlc(mp, gb)); + p.y += mp_gradient(mp, 0, mp_get_vlc(mp, bc)); p.y = av_clip_uintp2(p.y, 5); if ((x & 3) == 0) { if ((y & 3) == 0) { - p.v += mp_gradient(mp, 1, mp_get_vlc(mp, gb)); + p.v += mp_gradient(mp, 1, mp_get_vlc(mp, bc)); p.v = av_clip_intp2(p.v, 5); - p.u += mp_gradient(mp, 2, mp_get_vlc(mp, gb)); + p.u += mp_gradient(mp, 2, mp_get_vlc(mp, bc)); p.u = av_clip_intp2(p.u, 5); mp->hpt[((y / 4) * mp->avctx->width + x) / 4] = p; } else { @@ -231,7 +233,8 @@ static void mp_decode_line(MotionPixelsContext *mp, GetBitContext *gb, int y) } } -static void mp_decode_frame_helper(MotionPixelsContext *mp, GetBitContext *gb) +static void mp_decode_frame_helper(MotionPixelsContext *mp, + BitstreamContext *bc) { YuvPixel p; int y, y0; @@ -241,12 +244,12 @@ static void mp_decode_frame_helper(MotionPixelsContext *mp, GetBitContext *gb) memset(mp->gradient_scale, 1, sizeof(mp->gradient_scale)); p = mp_get_yuv_from_rgb(mp, 0, y); } else { - p.y += mp_gradient(mp, 0, mp_get_vlc(mp, gb)); + p.y += mp_gradient(mp, 0, mp_get_vlc(mp, bc)); p.y = av_clip_uintp2(p.y, 5); if ((y & 3) == 0) { - p.v += mp_gradient(mp, 1, mp_get_vlc(mp, gb)); + p.v += mp_gradient(mp, 1, mp_get_vlc(mp, bc)); p.v = av_clip_intp2(p.v, 5); - p.u += mp_gradient(mp, 2, mp_get_vlc(mp, gb)); + p.u += mp_gradient(mp, 2, mp_get_vlc(mp, bc)); p.u = av_clip_intp2(p.u, 5); } mp->vpt[y] = p; @@ -255,7 +258,7 @@ static void mp_decode_frame_helper(MotionPixelsContext *mp, GetBitContext *gb) } for (y0 = 0; y0 < 2; ++y0) for (y = y0; y < mp->avctx->height; y += 2) - mp_decode_line(mp, gb, y); + mp_decode_line(mp, bc, y); } static int mp_decode_frame(AVCodecContext *avctx, @@ -265,7 +268,7 @@ static int mp_decode_frame(AVCodecContext *avctx, const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; MotionPixelsContext *mp = avctx->priv_data; - GetBitContext gb; + BitstreamContext bc; int i, count1, count2, sz, ret; if ((ret = ff_reget_buffer(avctx, mp->frame)) < 0) { @@ -282,29 +285,29 @@ static int mp_decode_frame(AVCodecContext *avctx, if (buf_size & 3) memcpy(mp->bswapbuf + (buf_size & ~3), buf + (buf_size & ~3), buf_size & 3); memset(mp->bswapbuf + buf_size, 0, AV_INPUT_BUFFER_PADDING_SIZE); - init_get_bits(&gb, mp->bswapbuf, buf_size * 8); + bitstream_init(&bc, mp->bswapbuf, buf_size * 8); memset(mp->changes_map, 0, avctx->width * avctx->height); for (i = !(avctx->extradata[1] & 2); i < 2; ++i) { - count1 = get_bits(&gb, 12); - count2 = get_bits(&gb, 12); - mp_read_changes_map(mp, &gb, count1, 8, i); - mp_read_changes_map(mp, &gb, count2, 4, i); + count1 = bitstream_read(&bc, 12); + count2 = bitstream_read(&bc, 12); + mp_read_changes_map(mp, &bc, count1, 8, i); + mp_read_changes_map(mp, &bc, count2, 4, i); } - mp->codes_count = get_bits(&gb, 4); + mp->codes_count = bitstream_read(&bc, 4); if (mp->codes_count == 0) goto end; if (mp->changes_map[0] == 0) { - *(uint16_t *)mp->frame->data[0] = get_bits(&gb, 15); + *(uint16_t *)mp->frame->data[0] = bitstream_read(&bc, 15); mp->changes_map[0] = 1; } - mp_read_codes_table(mp, &gb); + mp_read_codes_table(mp, &bc); - sz = get_bits(&gb, 18); + sz = bitstream_read(&bc, 18); if (avctx->extradata[0] != 5) - sz += get_bits(&gb, 18); + sz += bitstream_read(&bc, 18); if (sz == 0) goto end; @@ -312,7 +315,7 @@ static int mp_decode_frame(AVCodecContext *avctx, goto end; if (init_vlc(&mp->vlc, mp->max_codes_bits, mp->codes_count, &mp->codes[0].size, sizeof(HuffCode), 1, &mp->codes[0].code, sizeof(HuffCode), 4, 0)) goto end; - mp_decode_frame_helper(mp, &gb); + mp_decode_frame_helper(mp, &bc); ff_free_vlc(&mp->vlc); end: From 9aec009f65f737c7566b2329b5cbd975665d1e02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandra=20H=C3=A1jkov=C3=A1?= Date: Tue, 12 Apr 2016 12:29:20 +0200 Subject: [PATCH 2/4] dvbsubdec: Convert to the new bitstream reader --- libavcodec/dvbsubdec.c | 68 +++++++++++++++++++++--------------------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/libavcodec/dvbsubdec.c b/libavcodec/dvbsubdec.c index c3248c9919..2b9760fb35 100644 --- a/libavcodec/dvbsubdec.c +++ b/libavcodec/dvbsubdec.c @@ -20,7 +20,7 @@ */ #include "avcodec.h" -#include "get_bits.h" +#include "bitstream.h" #include "bytestream.h" #include "internal.h" #include "libavutil/colorspace.h" @@ -330,16 +330,16 @@ static int dvbsub_read_2bit_string(uint8_t *destbuf, int dbuf_len, const uint8_t **srcbuf, int buf_size, int non_mod, uint8_t *map_table) { - GetBitContext gb; + BitstreamContext bc; int bits; int run_length; int pixels_read = 0; - init_get_bits(&gb, *srcbuf, buf_size << 3); + bitstream_init(&bc, *srcbuf, buf_size << 3); - while (get_bits_count(&gb) < buf_size << 3 && pixels_read < dbuf_len) { - bits = get_bits(&gb, 2); + while (bitstream_tell(&bc) < buf_size << 3 && pixels_read < dbuf_len) { + bits = bitstream_read(&bc, 2); if (bits) { if (non_mod != 1 || bits != 1) { @@ -350,10 +350,10 @@ static int dvbsub_read_2bit_string(uint8_t *destbuf, int dbuf_len, } pixels_read++; } else { - bits = get_bits1(&gb); + bits = bitstream_read_bit(&bc); if (bits == 1) { - run_length = get_bits(&gb, 3) + 3; - bits = get_bits(&gb, 2); + run_length = bitstream_read(&bc, 3) + 3; + bits = bitstream_read(&bc, 2); if (non_mod == 1 && bits == 1) pixels_read += run_length; @@ -366,12 +366,12 @@ static int dvbsub_read_2bit_string(uint8_t *destbuf, int dbuf_len, } } } else { - bits = get_bits1(&gb); + bits = bitstream_read_bit(&bc); if (bits == 0) { - bits = get_bits(&gb, 2); + bits = bitstream_read(&bc, 2); if (bits == 2) { - run_length = get_bits(&gb, 4) + 12; - bits = get_bits(&gb, 2); + run_length = bitstream_read(&bc, 4) + 12; + bits = bitstream_read(&bc, 2); if (non_mod == 1 && bits == 1) pixels_read += run_length; @@ -384,8 +384,8 @@ static int dvbsub_read_2bit_string(uint8_t *destbuf, int dbuf_len, } } } else if (bits == 3) { - run_length = get_bits(&gb, 8) + 29; - bits = get_bits(&gb, 2); + run_length = bitstream_read(&bc, 8) + 29; + bits = bitstream_read(&bc, 2); if (non_mod == 1 && bits == 1) pixels_read += run_length; @@ -408,7 +408,7 @@ static int dvbsub_read_2bit_string(uint8_t *destbuf, int dbuf_len, *destbuf++ = bits; } } else { - (*srcbuf) += (get_bits_count(&gb) + 7) >> 3; + *srcbuf += (bitstream_tell(&bc) + 7) >> 3; return pixels_read; } } else { @@ -423,10 +423,10 @@ static int dvbsub_read_2bit_string(uint8_t *destbuf, int dbuf_len, } } - if (get_bits(&gb, 6)) + if (bitstream_read(&bc, 6)) av_log(NULL, AV_LOG_ERROR, "DVBSub error: line overflow\n"); - (*srcbuf) += (get_bits_count(&gb) + 7) >> 3; + *srcbuf += (bitstream_tell(&bc) + 7) >> 3; return pixels_read; } @@ -435,16 +435,16 @@ static int dvbsub_read_4bit_string(uint8_t *destbuf, int dbuf_len, const uint8_t **srcbuf, int buf_size, int non_mod, uint8_t *map_table) { - GetBitContext gb; + BitstreamContext bc; int bits; int run_length; int pixels_read = 0; - init_get_bits(&gb, *srcbuf, buf_size << 3); + bitstream_init(&bc, *srcbuf, buf_size << 3); - while (get_bits_count(&gb) < buf_size << 3 && pixels_read < dbuf_len) { - bits = get_bits(&gb, 4); + while (bitstream_tell(&bc) < buf_size << 3 && pixels_read < dbuf_len) { + bits = bitstream_read(&bc, 4); if (bits) { if (non_mod != 1 || bits != 1) { @@ -455,12 +455,12 @@ static int dvbsub_read_4bit_string(uint8_t *destbuf, int dbuf_len, } pixels_read++; } else { - bits = get_bits1(&gb); + bits = bitstream_read_bit(&bc); if (bits == 0) { - run_length = get_bits(&gb, 3); + run_length = bitstream_read(&bc, 3); if (run_length == 0) { - (*srcbuf) += (get_bits_count(&gb) + 7) >> 3; + *srcbuf += (bitstream_tell(&bc) + 7) >> 3; return pixels_read; } @@ -476,10 +476,10 @@ static int dvbsub_read_4bit_string(uint8_t *destbuf, int dbuf_len, pixels_read++; } } else { - bits = get_bits1(&gb); + bits = bitstream_read_bit(&bc); if (bits == 0) { - run_length = get_bits(&gb, 2) + 4; - bits = get_bits(&gb, 4); + run_length = bitstream_read(&bc, 2) + 4; + bits = bitstream_read(&bc, 4); if (non_mod == 1 && bits == 1) pixels_read += run_length; @@ -492,10 +492,10 @@ static int dvbsub_read_4bit_string(uint8_t *destbuf, int dbuf_len, } } } else { - bits = get_bits(&gb, 2); + bits = bitstream_read(&bc, 2); if (bits == 2) { - run_length = get_bits(&gb, 4) + 9; - bits = get_bits(&gb, 4); + run_length = bitstream_read(&bc, 4) + 9; + bits = bitstream_read(&bc, 4); if (non_mod == 1 && bits == 1) pixels_read += run_length; @@ -508,8 +508,8 @@ static int dvbsub_read_4bit_string(uint8_t *destbuf, int dbuf_len, } } } else if (bits == 3) { - run_length = get_bits(&gb, 8) + 25; - bits = get_bits(&gb, 4); + run_length = bitstream_read(&bc, 8) + 25; + bits = bitstream_read(&bc, 4); if (non_mod == 1 && bits == 1) pixels_read += run_length; @@ -544,10 +544,10 @@ static int dvbsub_read_4bit_string(uint8_t *destbuf, int dbuf_len, } } - if (get_bits(&gb, 8)) + if (bitstream_read(&bc, 8)) av_log(NULL, AV_LOG_ERROR, "DVBSub error: line overflow\n"); - (*srcbuf) += (get_bits_count(&gb) + 7) >> 3; + *srcbuf += (bitstream_tell(&bc) + 7) >> 3; return pixels_read; } From 4e2505103146c539c6277b8d9d7e6840f6f1db07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandra=20H=C3=A1jkov=C3=A1?= Date: Tue, 12 Apr 2016 12:32:06 +0200 Subject: [PATCH 3/4] adx: Convert to the new bitstream reader --- libavcodec/adxdec.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/libavcodec/adxdec.c b/libavcodec/adxdec.c index dc587b2733..a3344ae695 100644 --- a/libavcodec/adxdec.c +++ b/libavcodec/adxdec.c @@ -20,9 +20,10 @@ */ #include "libavutil/intreadwrite.h" + #include "avcodec.h" #include "adx.h" -#include "get_bits.h" +#include "bitstream.h" #include "internal.h" /** @@ -66,7 +67,7 @@ static int adx_decode(ADXContext *c, int16_t *out, int offset, const uint8_t *in, int ch) { ADXChannelState *prev = &c->prev[ch]; - GetBitContext gb; + BitstreamContext bc; int scale = AV_RB16(in); int i; int s0, s1, s2, d; @@ -75,12 +76,12 @@ static int adx_decode(ADXContext *c, int16_t *out, int offset, if (scale & 0x8000) return -1; - init_get_bits(&gb, in + 2, (BLOCK_SIZE - 2) * 8); + bitstream_init(&bc, in + 2, (BLOCK_SIZE - 2) * 8); out += offset; s1 = prev->s1; s2 = prev->s2; for (i = 0; i < BLOCK_SAMPLES; i++) { - d = get_sbits(&gb, 4); + d = bitstream_read_signed(&bc, 4); s0 = ((d << COEFF_BITS) * scale + c->coeff[0] * s1 + c->coeff[1] * s2) >> COEFF_BITS; s2 = s1; s1 = av_clip_int16(s0); From bd6496fa07e32fd09ceb79404f9af43df959bcb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandra=20H=C3=A1jkov=C3=A1?= Date: Tue, 12 Apr 2016 17:18:09 +0200 Subject: [PATCH 4/4] interplayvideo: Convert to the new bitstream reader --- libavcodec/interplayvideo.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libavcodec/interplayvideo.c b/libavcodec/interplayvideo.c index e0d1e91992..fab9f2724c 100644 --- a/libavcodec/interplayvideo.c +++ b/libavcodec/interplayvideo.c @@ -40,8 +40,8 @@ #define BITSTREAM_READER_LE #include "avcodec.h" +#include "bitstream.h" #include "bytestream.h" -#include "get_bits.h" #include "hpeldsp.h" #include "internal.h" @@ -881,7 +881,7 @@ static void ipvideo_decode_opcodes(IpvideoContext *s, AVFrame *frame) int x, y; unsigned char opcode; int ret; - GetBitContext gb; + BitstreamContext bc; bytestream2_skip(&s->stream_ptr, 14); /* data starts 14 bytes in */ if (!s->is_16bpp) { @@ -898,10 +898,10 @@ static void ipvideo_decode_opcodes(IpvideoContext *s, AVFrame *frame) s->upper_motion_limit_offset = (s->avctx->height - 8) * frame->linesize[0] + (s->avctx->width - 8) * (1 + s->is_16bpp); - init_get_bits(&gb, s->decoding_map, s->decoding_map_size * 8); + bitstream_init(&bc, s->decoding_map, s->decoding_map_size * 8); for (y = 0; y < s->avctx->height; y += 8) { for (x = 0; x < s->avctx->width; x += 8) { - opcode = get_bits(&gb, 4); + opcode = bitstream_read(&bc, 4); ff_dlog(s->avctx, " block @ (%3d, %3d): encoding 0x%X, data ptr offset %d\n",