Re: [libav-devel] [PATCH 00/38] Convert to the new bitstream reader, set 3

2016-05-20 Thread Ronald S. Bultje
Hi,

On Fri, May 20, 2016 at 4:11 PM, Alexandra Hájková <
alexandra.khirn...@gmail.com> wrote:

> This set is compilable together only.


I noticed proresdec (for example) is not converted to the new bitstream
reader. Is there a reason for that?

Also, since this patch basically converts the bitstream reader to 64bits,
do people think it would be useful to do some speed tests on 32bit as well?
I feel that on 32bits, the 64bit emulation might actually slow the thing
down considerably, even if it's faster on 64bits.

(That doesn't mean the patch doesn't have merit, but rather it might mean
that you might want a state size that depends on the bit width of the
architecture. While I agree 32bit x86 is on its way out and possibly
somewhat irrelevant, some - chromebook or x86-android are some examples -
still care about it, and on non-x86, 32bit may actually be a more
predominant target.)

Btw don't get my comments wrong, I'm not criticizing the direction you guys
take, work in this area is good and seems to have merit (as measured on
64bits), so thanks!

Ronald
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel

[libav-devel] [PATCH 34/38] loco: Convert to the new bitstream reader

2016-05-20 Thread Alexandra Hájková
---
 libavcodec/loco.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/libavcodec/loco.c b/libavcodec/loco.c
index f25ef61..fa4c5ed 100644
--- a/libavcodec/loco.c
+++ b/libavcodec/loco.c
@@ -25,7 +25,7 @@
  */
 
 #include "avcodec.h"
-#include "get_bits.h"
+#include "bitstream.h"
 #include "golomb.h"
 #include "internal.h"
 #include "mathops.h"
@@ -50,7 +50,7 @@ typedef struct LOCOContext {
 } LOCOContext;
 
 typedef struct RICEContext {
-GetBitContext gb;
+BitstreamContext bc;
 int save, run, run2; /* internal rice decoder state */
 int sum, count; /* sum and count for getting rice parameter */
 int lossy;
@@ -88,11 +88,11 @@ static inline int loco_get_rice(RICEContext *r)
 loco_update_rice_param(r, 0);
 return 0;
 }
-v = get_ur_golomb_jpegls(>gb, loco_get_rice_param(r), INT_MAX, 0);
+v = get_ur_golomb_jpegls(>bc, loco_get_rice_param(r), INT_MAX, 0);
 loco_update_rice_param(r, (v + 1) >> 1);
 if (!v) {
 if (r->save >= 0) {
-r->run = get_ur_golomb_jpegls(>gb, 2, INT_MAX, 0);
+r->run = get_ur_golomb_jpegls(>bc, 2, INT_MAX, 0);
 if (r->run > 1)
 r->save += r->run + 1;
 else
@@ -132,7 +132,7 @@ static int loco_decode_plane(LOCOContext *l, uint8_t *data, 
int width, int heigh
 int val;
 int i, j;
 
-init_get_bits(, buf, buf_size*8);
+bitstream_init8(, buf, buf_size);
 rc.save  = 0;
 rc.run   = 0;
 rc.run2  = 0;
@@ -162,7 +162,7 @@ static int loco_decode_plane(LOCOContext *l, uint8_t *data, 
int width, int heigh
 data += stride;
 }
 
-return (get_bits_count() + 7) >> 3;
+return (bitstream_tell() + 7) >> 3;
 }
 
 static int decode_frame(AVCodecContext *avctx,
-- 
2.1.4

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH 25/38] h264: Convert to the new bitstream reader

2016-05-20 Thread Alexandra Hájková
---
 libavcodec/h264.c |  15 +--
 libavcodec/h264.h |  13 ++-
 libavcodec/h2645_parse.c  |  21 ++--
 libavcodec/h2645_parse.h  |   4 +-
 libavcodec/h264_cabac.c   |   2 +
 libavcodec/h264_cavlc.c   | 167 ++-
 libavcodec/h264_mb_template.c |  16 +--
 libavcodec/h264_parse.c   |  32 +++---
 libavcodec/h264_parse.h   |   6 +-
 libavcodec/h264_parser.c  |  64 +--
 libavcodec/h264_ps.c  | 260 +-
 libavcodec/h264_refs.c|  23 ++--
 libavcodec/h264_sei.c | 192 +++
 libavcodec/h264_sei.h |   4 +-
 libavcodec/h264_slice.c   |  68 +--
 libavcodec/vaapi_h264.c   |   3 +-
 16 files changed, 453 insertions(+), 437 deletions(-)

diff --git a/libavcodec/h264.c b/libavcodec/h264.c
index 224ba2f..9001fb1 100644
--- a/libavcodec/h264.c
+++ b/libavcodec/h264.c
@@ -31,6 +31,7 @@
 #include "libavutil/stereo3d.h"
 #include "libavutil/timer.h"
 #include "internal.h"
+#include "bitstream.h"
 #include "bytestream.h"
 #include "cabac.h"
 #include "cabac_functions.h"
@@ -777,7 +778,7 @@ static int get_last_needed_nal(H264Context *h)
 
 for (i = 0; i < h->pkt.nb_nals; i++) {
 H2645NAL *nal = >pkt.nals[i];
-GetBitContext gb;
+BitstreamContext bc;
 
 /* packets can sometimes contain multiple PPS/SPS,
  * e.g. two PAFF field pictures in one packet, or a demuxer
@@ -791,8 +792,8 @@ static int get_last_needed_nal(H264Context *h)
 case NAL_DPA:
 case NAL_IDR_SLICE:
 case NAL_SLICE:
-init_get_bits(, nal->data + 1, (nal->size - 1) * 8);
-if (!get_ue_golomb())
+bitstream_init8(, nal->data + 1, (nal->size - 1));
+if (!get_ue_golomb())
 nals_needed = i;
 }
 }
@@ -849,7 +850,7 @@ static int decode_nal_units(H264Context *h, const uint8_t 
*buf, int buf_size)
 }
 idr(h); // FIXME ensure we don't lose some frames if there is 
reordering
 case NAL_SLICE:
-sl->gb = nal->gb;
+sl->bc = nal->bc;
 
 if ((err = ff_h264_decode_slice_header(h, sl)))
 break;
@@ -904,17 +905,17 @@ static int decode_nal_units(H264Context *h, const uint8_t 
*buf, int buf_size)
 goto end;
 break;
 case NAL_SEI:
-ret = ff_h264_sei_decode(>sei, >gb, >ps, avctx);
+ret = ff_h264_sei_decode(>sei, >bc, >ps, avctx);
 if (ret < 0 && (h->avctx->err_recognition & AV_EF_EXPLODE))
 goto end;
 break;
 case NAL_SPS:
-ret = ff_h264_decode_seq_parameter_set(>gb, avctx, >ps);
+ret = ff_h264_decode_seq_parameter_set(>bc, avctx, >ps);
 if (ret < 0 && (h->avctx->err_recognition & AV_EF_EXPLODE))
 goto end;
 break;
 case NAL_PPS:
-ret = ff_h264_decode_picture_parameter_set(>gb, avctx, >ps,
+ret = ff_h264_decode_picture_parameter_set(>bc, avctx, >ps,
nal->size_bits);
 if (ret < 0 && (h->avctx->err_recognition & AV_EF_EXPLODE))
 goto end;
diff --git a/libavcodec/h264.h b/libavcodec/h264.h
index bfbcc81..238f98d 100644
--- a/libavcodec/h264.h
+++ b/libavcodec/h264.h
@@ -31,9 +31,10 @@
 #include "libavutil/buffer.h"
 #include "libavutil/intreadwrite.h"
 #include "libavutil/thread.h"
+
+#include "bitstream.h"
 #include "cabac.h"
 #include "error_resilience.h"
-#include "get_bits.h"
 #include "h264_parse.h"
 #include "h264_sei.h"
 #include "h2645_parse.h"
@@ -300,7 +301,7 @@ typedef struct H264Ref {
 
 typedef struct H264SliceContext {
 struct H264Context *h264;
-GetBitContext gb;
+BitstreamContext bc;
 ERContext er;
 
 int slice_num;
@@ -445,7 +446,7 @@ typedef struct H264Context {
 H264DSPContext h264dsp;
 H264ChromaContext h264chroma;
 H264QpelContext h264qpel;
-GetBitContext gb;
+BitstreamContext bc;
 
 H264Picture DPB[H264_MAX_PICTURE_COUNT];
 H264Picture *cur_pic_ptr;
@@ -637,13 +638,13 @@ extern const uint16_t ff_h264_mb_sizes[4];
 /**
  * Decode SPS
  */
-int ff_h264_decode_seq_parameter_set(GetBitContext *gb, AVCodecContext *avctx,
+int ff_h264_decode_seq_parameter_set(BitstreamContext *bc, AVCodecContext 
*avctx,
  H264ParamSets *ps);
 
 /**
  * Decode PPS
  */
-int ff_h264_decode_picture_parameter_set(GetBitContext *gb, AVCodecContext 
*avctx,
+int ff_h264_decode_picture_parameter_set(BitstreamContext *bc, AVCodecContext 
*avctx,
  H264ParamSets *ps, int bit_length);
 
 /**
@@ -666,7 +667,7 @@ void ff_h264_remove_all_refs(H264Context *h);
  */
 int ff_h264_execute_ref_pic_marking(H264Context *h, MMCO *mmco, int 
mmco_count);
 
-int ff_h264_decode_ref_pic_marking(H264Context 

[libav-devel] [PATCH 26/38] on2avc: Convert to the new bitstream reader

2016-05-20 Thread Alexandra Hájková
---
 libavcodec/on2avc.c | 63 +++--
 1 file changed, 32 insertions(+), 31 deletions(-)

diff --git a/libavcodec/on2avc.c b/libavcodec/on2avc.c
index 3918365..2c256b0 100644
--- a/libavcodec/on2avc.c
+++ b/libavcodec/on2avc.c
@@ -23,12 +23,13 @@
 #include "libavutil/channel_layout.h"
 #include "libavutil/float_dsp.h"
 #include "avcodec.h"
+#include "bitstream.h"
 #include "bytestream.h"
 #include "fft.h"
-#include "get_bits.h"
 #include "golomb.h"
 #include "internal.h"
 #include "unary.h"
+#include "vlc.h"
 
 #include "on2avcdata.h"
 
@@ -86,11 +87,11 @@ typedef struct On2AVCContext {
 DECLARE_ALIGNED(32, float, short_win)[ON2AVC_SUBFRAME_SIZE / 8];
 } On2AVCContext;
 
-static void on2avc_read_ms_info(On2AVCContext *c, GetBitContext *gb)
+static void on2avc_read_ms_info(On2AVCContext *c, BitstreamContext *bc)
 {
 int w, b, band_off = 0;
 
-c->ms_present = get_bits1(gb);
+c->ms_present = bitstream_read_bit(bc);
 if (!c->ms_present)
 return;
 for (w = 0; w < c->num_windows; w++) {
@@ -102,12 +103,12 @@ static void on2avc_read_ms_info(On2AVCContext *c, 
GetBitContext *gb)
 continue;
 }
 for (b = 0; b < c->num_bands; b++)
-c->ms_info[band_off++] = get_bits1(gb);
+c->ms_info[band_off++] = bitstream_read_bit(bc);
 }
 }
 
 // do not see Table 17 in ISO/IEC 13818-7
-static int on2avc_decode_band_types(On2AVCContext *c, GetBitContext *gb)
+static int on2avc_decode_band_types(On2AVCContext *c, BitstreamContext *bc)
 {
 int bits_per_sect = c->is_long ? 5 : 3;
 int esc_val = (1 << bits_per_sect) - 1;
@@ -115,10 +116,10 @@ static int on2avc_decode_band_types(On2AVCContext *c, 
GetBitContext *gb)
 int band = 0, i, band_type, run_len, run;
 
 while (band < num_bands) {
-band_type = get_bits(gb, 4);
+band_type = bitstream_read(bc, 4);
 run_len   = 1;
 do {
-run = get_bits(gb, bits_per_sect);
+run = bitstream_read(bc, bits_per_sect);
 run_len += run;
 } while (run == esc_val);
 if (band + run_len > num_bands) {
@@ -137,7 +138,7 @@ static int on2avc_decode_band_types(On2AVCContext *c, 
GetBitContext *gb)
 
 // completely not like Table 18 in ISO/IEC 13818-7
 // (no intensity stereo, different coding for the first coefficient)
-static int on2avc_decode_band_scales(On2AVCContext *c, GetBitContext *gb)
+static int on2avc_decode_band_scales(On2AVCContext *c, BitstreamContext *bc)
 {
 int w, w2, b, scale, first = 1;
 int band_off = 0;
@@ -167,10 +168,10 @@ static int on2avc_decode_band_scales(On2AVCContext *c, 
GetBitContext *gb)
 }
 }
 if (first) {
-scale = get_bits(gb, 7);
+scale = bitstream_read(bc, 7);
 first = 0;
 } else {
-scale += get_vlc2(gb, c->scale_diff.table, 9, 3) - 60;
+scale += bitstream_read_vlc(bc, c->scale_diff.table, 9, 3) - 
60;
 }
 if (scale < 0 || scale > 127) {
 av_log(c->avctx, AV_LOG_ERROR, "Invalid scale value %d\n",
@@ -190,13 +191,13 @@ static inline float on2avc_scale(int v, float scale)
 }
 
 // spectral data is coded completely differently - there are no unsigned 
codebooks
-static int on2avc_decode_quads(On2AVCContext *c, GetBitContext *gb, float *dst,
+static int on2avc_decode_quads(On2AVCContext *c, BitstreamContext *bc, float 
*dst,
int dst_size, int type, float band_scale)
 {
 int i, j, val, val1;
 
 for (i = 0; i < dst_size; i += 4) {
-val = get_vlc2(gb, c->cb_vlc[type].table, 9, 3);
+val = bitstream_read_vlc(bc, c->cb_vlc[type].table, 9, 3);
 
 for (j = 0; j < 4; j++) {
 val1 = sign_extend((val >> (12 - j * 4)) & 0xF, 4);
@@ -207,11 +208,11 @@ static int on2avc_decode_quads(On2AVCContext *c, 
GetBitContext *gb, float *dst,
 return 0;
 }
 
-static inline int get_egolomb(GetBitContext *gb)
+static inline int get_egolomb(BitstreamContext *bc)
 {
 int v = 4;
 
-while (get_bits1(gb)) {
+while (bitstream_read_bit(bc)) {
 v++;
 if (v > 30) {
 av_log(NULL, AV_LOG_WARNING, "Too large golomb code in 
get_egolomb.\n");
@@ -220,27 +221,27 @@ static inline int get_egolomb(GetBitContext *gb)
 }
 }
 
-return (1 << v) + get_bits_long(gb, v);
+return (1 << v) + bitstream_read(bc, v);
 }
 
-static int on2avc_decode_pairs(On2AVCContext *c, GetBitContext *gb, float *dst,
+static int on2avc_decode_pairs(On2AVCContext *c, BitstreamContext *bc, float 
*dst,
int dst_size, int type, float band_scale)
 {
 int i, val, val1, val2, sign;
 
 for (i = 0; i < dst_size; i += 2) {
-val = get_vlc2(gb, c->cb_vlc[type].table, 9, 3);
+val = bitstream_read_vlc(bc, c->cb_vlc[type].table, 9, 3);
 
 val1 = sign_extend(val 

[libav-devel] [PATCH 22/38] golomb: Convert to the new bitstream reader

2016-05-20 Thread Alexandra Hájková
---
 libavcodec/golomb.h   | 199 ++
 libavcodec/tests/golomb.c |  22 ++---
 2 files changed, 87 insertions(+), 134 deletions(-)

diff --git a/libavcodec/golomb.h b/libavcodec/golomb.h
index 22a87c6..371db4e 100644
--- a/libavcodec/golomb.h
+++ b/libavcodec/golomb.h
@@ -32,7 +32,7 @@
 
 #include 
 
-#include "get_bits.h"
+#include "bitstream.h"
 #include "put_bits.h"
 
 #define INVALID_VLC   0x8000
@@ -50,26 +50,24 @@ extern const uint8_t 
ff_interleaved_dirac_golomb_vlc_code[256];
 /**
  * read unsigned exp golomb code.
  */
-static inline int get_ue_golomb(GetBitContext *gb)
+static inline int get_ue_golomb(BitstreamContext *bb)
 {
 unsigned int buf;
+int ret;
 
-OPEN_READER(re, gb);
-UPDATE_CACHE(re, gb);
-buf = GET_CACHE(re, gb);
+buf = bitstream_peek(bb, 32);
 
 if (buf >= (1 << 27)) {
 buf >>= 32 - 9;
-LAST_SKIP_BITS(re, gb, ff_golomb_vlc_len[buf]);
-CLOSE_READER(re, gb);
+bitstream_skip(bb, ff_golomb_vlc_len[buf]);
 
-return ff_ue_golomb_vlc_code[buf];
+ret = ff_ue_golomb_vlc_code[buf];
+return ret;
 } else {
 int log = 2 * av_log2(buf) - 31;
 buf >>= log;
 buf--;
-LAST_SKIP_BITS(re, gb, 32 - log);
-CLOSE_READER(re, gb);
+bitstream_skip(bb, 32 - log);
 
 return buf;
 }
@@ -78,48 +76,42 @@ static inline int get_ue_golomb(GetBitContext *gb)
 /**
  * Read an unsigned Exp-Golomb code in the range 0 to UINT32_MAX-1.
  */
-static inline unsigned get_ue_golomb_long(GetBitContext *gb)
+static inline unsigned get_ue_golomb_long(BitstreamContext *bb)
 {
 unsigned buf, log;
 
-buf = show_bits_long(gb, 32);
+buf = bitstream_peek(bb, 32);
 log = 31 - av_log2(buf);
-skip_bits_long(gb, log);
+bitstream_skip(bb, log);
 
-return get_bits_long(gb, log + 1) - 1;
+return bitstream_read(bb, log + 1) - 1;
 }
 
 /**
  * read unsigned exp golomb code, constraint to a max of 31.
  * the return value is undefined if the stored value exceeds 31.
  */
-static inline int get_ue_golomb_31(GetBitContext *gb)
+static inline int get_ue_golomb_31(BitstreamContext *bb)
 {
 unsigned int buf;
 
-OPEN_READER(re, gb);
-UPDATE_CACHE(re, gb);
-buf = GET_CACHE(re, gb);
+buf = bitstream_peek(bb, 32);
 
 buf >>= 32 - 9;
-LAST_SKIP_BITS(re, gb, ff_golomb_vlc_len[buf]);
-CLOSE_READER(re, gb);
+bitstream_skip(bb, ff_golomb_vlc_len[buf]);
 
 return ff_ue_golomb_vlc_code[buf];
 }
 
-static inline unsigned svq3_get_ue_golomb(GetBitContext *gb)
+static inline unsigned svq3_get_ue_golomb(BitstreamContext *bb)
 {
 uint32_t buf;
 
-OPEN_READER(re, gb);
-UPDATE_CACHE(re, gb);
-buf = GET_CACHE(re, gb);
+buf = bitstream_peek(bb, 32);
 
 if (buf & 0xAA80) {
 buf >>= 32 - 8;
-LAST_SKIP_BITS(re, gb, ff_interleaved_golomb_vlc_len[buf]);
-CLOSE_READER(re, gb);
+bitstream_skip(bb, ff_interleaved_golomb_vlc_len[buf]);
 
 return ff_interleaved_ue_golomb_vlc_code[buf];
 } else {
@@ -127,8 +119,7 @@ static inline unsigned svq3_get_ue_golomb(GetBitContext *gb)
 
 do {
 buf >>= 32 - 8;
-LAST_SKIP_BITS(re, gb,
-   FFMIN(ff_interleaved_golomb_vlc_len[buf], 8));
+bitstream_skip(bb, FFMIN(ff_interleaved_golomb_vlc_len[buf], 8));
 
 if (ff_interleaved_golomb_vlc_len[buf] != 9) {
 ret <<= (ff_interleaved_golomb_vlc_len[buf] - 1) >> 1;
@@ -136,11 +127,9 @@ static inline unsigned svq3_get_ue_golomb(GetBitContext 
*gb)
 break;
 }
 ret = (ret << 4) | ff_interleaved_dirac_golomb_vlc_code[buf];
-UPDATE_CACHE(re, gb);
-buf = GET_CACHE(re, gb);
-} while (BITS_AVAILABLE(re, gb));
+buf = bitstream_peek(bb, 32);
+} while (bitstream_bits_left(bb) > 0);
 
-CLOSE_READER(re, gb);
 return ret - 1;
 }
 }
@@ -148,54 +137,50 @@ static inline unsigned svq3_get_ue_golomb(GetBitContext 
*gb)
 /**
  * read unsigned truncated exp golomb code.
  */
-static inline int get_te0_golomb(GetBitContext *gb, int range)
+static inline int get_te0_golomb(BitstreamContext *bb, int range)
 {
 assert(range >= 1);
 
 if (range == 1)
 return 0;
 else if (range == 2)
-return get_bits1(gb) ^ 1;
+return bitstream_read_bit(bb) ^ 1;
 else
-return get_ue_golomb(gb);
+return get_ue_golomb(bb);
 }
 
 /**
  * read unsigned truncated exp golomb code.
  */
-static inline int get_te_golomb(GetBitContext *gb, int range)
+static inline int get_te_golomb(BitstreamContext *bb, int range)
 {
 assert(range >= 1);
 
 if (range == 2)
-return get_bits1(gb) ^ 1;
+return bitstream_read_bit(bb) ^ 1;
 else
-return get_ue_golomb(gb);
+return get_ue_golomb(bb);
 }
 
 /**
  * read signed exp 

[libav-devel] [PATCH 28/38] cavsdec: Convert to the new bitstream reader

2016-05-20 Thread Alexandra Hájková
---
 libavcodec/cavs.c|   6 +-
 libavcodec/cavs.h|   4 +-
 libavcodec/cavsdec.c | 176 +--
 3 files changed, 93 insertions(+), 93 deletions(-)

diff --git a/libavcodec/cavs.c b/libavcodec/cavs.c
index 3050b9a..4a4d418 100644
--- a/libavcodec/cavs.c
+++ b/libavcodec/cavs.c
@@ -26,7 +26,7 @@
  */
 
 #include "avcodec.h"
-#include "get_bits.h"
+#include "bitstream.h"
 #include "golomb.h"
 #include "h264chroma.h"
 #include "idctdsp.h"
@@ -603,8 +603,8 @@ void ff_cavs_mv(AVSContext *h, enum cavs_mv_loc nP, enum 
cavs_mv_loc nC,
 mv_pred_median(h, mvP, mvA, mvB, mvC);
 
 if (mode < MV_PRED_PSKIP) {
-mvP->x += get_se_golomb(>gb);
-mvP->y += get_se_golomb(>gb);
+mvP->x += get_se_golomb(>bc);
+mvP->y += get_se_golomb(>bc);
 }
 set_mvs(mvP, size);
 }
diff --git a/libavcodec/cavs.h b/libavcodec/cavs.h
index cfae055..f037d6c 100644
--- a/libavcodec/cavs.h
+++ b/libavcodec/cavs.h
@@ -22,11 +22,11 @@
 #ifndef AVCODEC_CAVS_H
 #define AVCODEC_CAVS_H
 
+#include "bitstream.h"
 #include "cavsdsp.h"
 #include "blockdsp.h"
 #include "h264chroma.h"
 #include "idctdsp.h"
-#include "get_bits.h"
 #include "videodsp.h"
 
 #define SLICE_MAX_START_CODE0x01af
@@ -167,7 +167,7 @@ typedef struct AVSContext {
 IDCTDSPContext idsp;
 VideoDSPContext vdsp;
 CAVSDSPContext  cdsp;
-GetBitContext gb;
+BitstreamContext bc;
 AVSFrame cur; ///< currently decoded frame
 AVSFrame DPB[2];  ///< reference frames
 int dist[2]; ///< temporal distances from current frame to ref frames
diff --git a/libavcodec/cavsdec.c b/libavcodec/cavsdec.c
index a455a34..59cbd81 100644
--- a/libavcodec/cavsdec.c
+++ b/libavcodec/cavsdec.c
@@ -26,7 +26,7 @@
  */
 
 #include "avcodec.h"
-#include "get_bits.h"
+#include "bitstream.h"
 #include "golomb.h"
 #include "cavs.h"
 #include "internal.h"
@@ -506,13 +506,13 @@ static inline void mv_pred_sym(AVSContext *h, cavs_vector 
*src,
  /
 
 /** kth-order exponential golomb code */
-static inline int get_ue_code(GetBitContext *gb, int order)
+static inline int get_ue_code(BitstreamContext *bc, int order)
 {
 if (order) {
-int ret = get_ue_golomb(gb) << order;
-return ret + get_bits(gb, order);
+int ret = get_ue_golomb(bc) << order;
+return ret + bitstream_read(bc, order);
 }
-return get_ue_golomb(gb);
+return get_ue_golomb(bc);
 }
 
 static inline int dequant(AVSContext *h, int16_t *level_buf, uint8_t *run_buf,
@@ -545,7 +545,7 @@ static inline int dequant(AVSContext *h, int16_t 
*level_buf, uint8_t *run_buf,
  * @param dst location of sample block
  * @param stride line stride in frame buffer
  */
-static int decode_residual_block(AVSContext *h, GetBitContext *gb,
+static int decode_residual_block(AVSContext *h, BitstreamContext *bc,
  const struct dec_2dvlc *r, int 
esc_golomb_order,
  int qp, uint8_t *dst, int stride)
 {
@@ -555,10 +555,10 @@ static int decode_residual_block(AVSContext *h, 
GetBitContext *gb,
 int16_t *block = h->block;
 
 for (i = 0;i < 65; i++) {
-level_code = get_ue_code(gb, r->golomb_order);
+level_code = get_ue_code(bc, r->golomb_order);
 if (level_code >= ESCAPE_CODE) {
 run  = ((level_code - ESCAPE_CODE) >> 1) + 1;
-esc_code = get_ue_code(gb, esc_golomb_order);
+esc_code = get_ue_code(bc, esc_golomb_order);
 level= esc_code + (run > r->max_run ? 1 : r->level_add[run]);
 while (level > r->inc_limit)
 r++;
@@ -588,10 +588,10 @@ static int decode_residual_block(AVSContext *h, 
GetBitContext *gb,
 static inline void decode_residual_chroma(AVSContext *h)
 {
 if (h->cbp & (1 << 4))
-decode_residual_block(h, >gb, chroma_dec, 0,
+decode_residual_block(h, >bc, chroma_dec, 0,
   cavs_chroma_qp[h->qp], h->cu, h->c_stride);
 if (h->cbp & (1 << 5))
-decode_residual_block(h, >gb, chroma_dec, 0,
+decode_residual_block(h, >bc, chroma_dec, 0,
   cavs_chroma_qp[h->qp], h->cv, h->c_stride);
 }
 
@@ -600,7 +600,7 @@ static inline int decode_residual_inter(AVSContext *h)
 int block;
 
 /* get coded block pattern */
-int cbp = get_ue_golomb(>gb);
+int cbp = get_ue_golomb(>bc);
 if (cbp > 63 || cbp < 0) {
 av_log(h->avctx, AV_LOG_ERROR, "illegal inter cbp %d\n", cbp);
 return AVERROR_INVALIDDATA;
@@ -609,10 +609,10 @@ static inline int decode_residual_inter(AVSContext *h)
 
 /* get quantizer */
 if (h->cbp && !h->qp_fixed)
-h->qp = (h->qp + get_se_golomb(>gb)) & 63;
+h->qp = (h->qp + get_se_golomb(>bc)) & 63;
 for (block = 0; block < 4; block++)
 if (h->cbp & (1 << block))
-

[libav-devel] [PATCH 37/38] mxpegdec: Convert to the new bitstream reader

2016-05-20 Thread Alexandra Hájková
---
 libavcodec/mxpegdec.c | 9 +
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/libavcodec/mxpegdec.c b/libavcodec/mxpegdec.c
index a8ef6d0..6510077 100644
--- a/libavcodec/mxpegdec.c
+++ b/libavcodec/mxpegdec.c
@@ -25,6 +25,7 @@
  * MxPEG decoder
  */
 
+#include "bitstream.h"
 #include "internal.h"
 #include "mjpeg.h"
 #include "mjpegdec.h"
@@ -82,7 +83,7 @@ static int mxpeg_decode_app(MXpegDecodeContext *s,
 if (buf_size < 2)
 return 0;
 len = AV_RB16(buf_ptr);
-skip_bits(>jpg.gb, 8*FFMIN(len,buf_size));
+bitstream_skip(>jpg.bc, 8 * FFMIN(len,buf_size));
 
 return 0;
 }
@@ -149,7 +150,7 @@ static int mxpeg_decode_com(MXpegDecodeContext *s,
 if (len > 14 && len <= buf_size && !strncmp(buf_ptr + 2, "MXM", 3)) {
 ret = mxpeg_decode_mxm(s, buf_ptr + 2, len - 2);
 }
-skip_bits(>jpg.gb, 8*FFMIN(len,buf_size));
+bitstream_skip(>jpg.bc, 8*FFMIN(len,buf_size));
 
 return ret;
 }
@@ -203,7 +204,7 @@ static int mxpeg_decode_frame(AVCodecContext *avctx,
 if (start_code < 0)
 goto the_end;
 {
-init_get_bits(>gb, unescaped_buf_ptr, unescaped_buf_size*8);
+bitstream_init8(>bc, unescaped_buf_ptr, unescaped_buf_size);
 
 if (start_code >= APP0 && start_code <= APP15) {
 mxpeg_decode_app(s, unescaped_buf_ptr, unescaped_buf_size);
@@ -310,7 +311,7 @@ static int mxpeg_decode_frame(AVCodecContext *avctx,
 break;
 }
 
-buf_ptr += (get_bits_count(>gb)+7) >> 3;
+buf_ptr += (bitstream_tell(>bc) + 7) >> 3;
 }
 
 }
-- 
2.1.4

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH 29/38] dirac: Convert to the new bitstream reader

2016-05-20 Thread Alexandra Hájková
---
 libavcodec/dirac.c | 87 +++---
 1 file changed, 44 insertions(+), 43 deletions(-)

diff --git a/libavcodec/dirac.c b/libavcodec/dirac.c
index aced2ac..b0455e5 100644
--- a/libavcodec/dirac.c
+++ b/libavcodec/dirac.c
@@ -28,6 +28,7 @@
 #include "libavutil/imgutils.h"
 
 #include "avcodec.h"
+#include "bitstream.h"
 #include "dirac.h"
 #include "golomb.h"
 #include "internal.h"
@@ -138,7 +139,7 @@ static const enum AVPixelFormat dirac_pix_fmt[2][3] = {
 
 /* [DIRAC_STD] 10.3 Parse Source Parameters.
  * source_parameters(base_video_format) */
-static int parse_source_parameters(AVDiracSeqHeader *dsh, GetBitContext *gb,
+static int parse_source_parameters(AVDiracSeqHeader *dsh, BitstreamContext *bc,
void *log_ctx)
 {
 AVRational frame_rate = { 0, 0 };
@@ -147,17 +148,17 @@ static int parse_source_parameters(AVDiracSeqHeader *dsh, 
GetBitContext *gb,
 
 /* [DIRAC_STD] 10.3.2 Frame size. frame_size(video_params) */
 /* [DIRAC_STD] custom_dimensions_flag */
-if (get_bits1(gb)) {
-dsh->width  = svq3_get_ue_golomb(gb); /* [DIRAC_STD] FRAME_WIDTH  */
-dsh->height = svq3_get_ue_golomb(gb); /* [DIRAC_STD] FRAME_HEIGHT */
+if (bitstream_read_bit(bc)) {
+dsh->width  = svq3_get_ue_golomb(bc); /* [DIRAC_STD] FRAME_WIDTH  */
+dsh->height = svq3_get_ue_golomb(bc); /* [DIRAC_STD] FRAME_HEIGHT */
 }
 
 /* [DIRAC_STD] 10.3.3 Chroma Sampling Format.
  *  chroma_sampling_format(video_params) */
 /* [DIRAC_STD] custom_chroma_format_flag */
-if (get_bits1(gb))
+if (bitstream_read_bit(bc))
 /* [DIRAC_STD] CHROMA_FORMAT_INDEX */
-dsh->chroma_format = svq3_get_ue_golomb(gb);
+dsh->chroma_format = svq3_get_ue_golomb(bc);
 if (dsh->chroma_format > 2) {
 if (log_ctx)
 av_log(log_ctx, AV_LOG_ERROR, "Unknown chroma format %d\n",
@@ -167,24 +168,24 @@ static int parse_source_parameters(AVDiracSeqHeader *dsh, 
GetBitContext *gb,
 
 /* [DIRAC_STD] 10.3.4 Scan Format. scan_format(video_params) */
 /* [DIRAC_STD] custom_scan_format_flag */
-if (get_bits1(gb))
+if (bitstream_read_bit(bc))
 /* [DIRAC_STD] SOURCE_SAMPLING */
-dsh->interlaced = svq3_get_ue_golomb(gb);
+dsh->interlaced = svq3_get_ue_golomb(bc);
 if (dsh->interlaced > 1)
 return AVERROR_INVALIDDATA;
 
 /* [DIRAC_STD] 10.3.5 Frame Rate. frame_rate(video_params) */
-if (get_bits1(gb)) { /* [DIRAC_STD] custom_frame_rate_flag */
-dsh->frame_rate_index = svq3_get_ue_golomb(gb);
+if (bitstream_read_bit(bc)) { /* [DIRAC_STD] custom_frame_rate_flag */
+dsh->frame_rate_index = svq3_get_ue_golomb(bc);
 
 if (dsh->frame_rate_index > 10)
 return AVERROR_INVALIDDATA;
 
 if (!dsh->frame_rate_index) {
 /* [DIRAC_STD] FRAME_RATE_NUMER */
-frame_rate.num = svq3_get_ue_golomb(gb);
+frame_rate.num = svq3_get_ue_golomb(bc);
 /* [DIRAC_STD] FRAME_RATE_DENOM */
-frame_rate.den = svq3_get_ue_golomb(gb);
+frame_rate.den = svq3_get_ue_golomb(bc);
 }
 }
 /* [DIRAC_STD] preset_frame_rate(video_params, index) */
@@ -199,16 +200,16 @@ static int parse_source_parameters(AVDiracSeqHeader *dsh, 
GetBitContext *gb,
 
 /* [DIRAC_STD] 10.3.6 Pixel Aspect Ratio.
  * pixel_aspect_ratio(video_params) */
-if (get_bits1(gb)) { /* [DIRAC_STD] custom_pixel_aspect_ratio_flag */
+if (bitstream_read_bit(bc)) { /* [DIRAC_STD] 
custom_pixel_aspect_ratio_flag */
 /* [DIRAC_STD] index */
-dsh->aspect_ratio_index = svq3_get_ue_golomb(gb);
+dsh->aspect_ratio_index = svq3_get_ue_golomb(bc);
 
 if (dsh->aspect_ratio_index > 6)
 return AVERROR_INVALIDDATA;
 
 if (!dsh->aspect_ratio_index) {
-dsh->sample_aspect_ratio.num = svq3_get_ue_golomb(gb);
-dsh->sample_aspect_ratio.den = svq3_get_ue_golomb(gb);
+dsh->sample_aspect_ratio.num = svq3_get_ue_golomb(bc);
+dsh->sample_aspect_ratio.den = svq3_get_ue_golomb(bc);
 }
 }
 /* [DIRAC_STD] Take value from Table 10.4 Available preset pixel
@@ -218,33 +219,33 @@ static int parse_source_parameters(AVDiracSeqHeader *dsh, 
GetBitContext *gb,
 dirac_preset_aspect_ratios[dsh->aspect_ratio_index - 1];
 
 /* [DIRAC_STD] 10.3.7 Clean area. clean_area(video_params) */
-if (get_bits1(gb)) { /* [DIRAC_STD] custom_clean_area_flag */
+if (bitstream_read_bit(bc)) { /* [DIRAC_STD] custom_clean_area_flag */
 /* [DIRAC_STD] CLEAN_WIDTH */
-dsh->clean_width = svq3_get_ue_golomb(gb);
+dsh->clean_width = svq3_get_ue_golomb(bc);
 /* [DIRAC_STD] CLEAN_HEIGHT */
-dsh->clean_height = svq3_get_ue_golomb(gb);
+dsh->clean_height = svq3_get_ue_golomb(bc);
 /* [DIRAC_STD] CLEAN_LEFT_OFFSET */
-

[libav-devel] [PATCH 33/38] jpeglsdec, mjpegdec: Convert to the new bitstream reader

2016-05-20 Thread Alexandra Hájková
---
 libavcodec/jpeglsdec.c |  46 -
 libavcodec/mjpegbdec.c |  41 
 libavcodec/mjpegdec.c  | 266 +
 libavcodec/mjpegdec.h  |   5 +-
 4 files changed, 163 insertions(+), 195 deletions(-)

diff --git a/libavcodec/jpeglsdec.c b/libavcodec/jpeglsdec.c
index 9f8ccec..6c49e46 100644
--- a/libavcodec/jpeglsdec.c
+++ b/libavcodec/jpeglsdec.c
@@ -26,7 +26,7 @@
  */
 
 #include "avcodec.h"
-#include "get_bits.h"
+#include "bitstream.h"
 #include "golomb.h"
 #include "internal.h"
 #include "mathops.h"
@@ -52,16 +52,16 @@ int ff_jpegls_decode_lse(MJpegDecodeContext *s)
 {
 int id;
 
-skip_bits(>gb, 16);  /* length: FIXME: verify field validity */
-id = get_bits(>gb, 8);
+bitstream_skip(>bc, 16);  /* length: FIXME: verify field validity */
+id = bitstream_read(>bc, 8);
 
 switch (id) {
 case 1:
-s->maxval = get_bits(>gb, 16);
-s->t1 = get_bits(>gb, 16);
-s->t2 = get_bits(>gb, 16);
-s->t3 = get_bits(>gb, 16);
-s->reset  = get_bits(>gb, 16);
+s->maxval = bitstream_read(>bc, 16);
+s->t1 = bitstream_read(>bc, 16);
+s->t2 = bitstream_read(>bc, 16);
+s->t3 = bitstream_read(>bc, 16);
+s->reset  = bitstream_read(>bc, 16);
 
 //ff_jpegls_reset_coding_parameters(s, 0);
 //FIXME quant table?
@@ -85,7 +85,7 @@ int ff_jpegls_decode_lse(MJpegDecodeContext *s)
 /**
  * Get context-dependent Golomb code, decode it and update context
  */
-static inline int ls_get_code_regular(GetBitContext *gb, JLSState *state, int 
Q)
+static inline int ls_get_code_regular(BitstreamContext *bc, JLSState *state, 
int Q)
 {
 int k, ret;
 
@@ -93,10 +93,10 @@ static inline int ls_get_code_regular(GetBitContext *gb, 
JLSState *state, int Q)
 ;
 
 #ifdef JLS_BROKEN
-if (!show_bits_long(gb, 32))
+if (!bitstream_skip(bc, 32))
 return -1;
 #endif
-ret = get_ur_golomb_jpegls(gb, k, state->limit, state->qbpp);
+ret = get_ur_golomb_jpegls(bc, k, state->limit, state->qbpp);
 
 /* decode mapped error */
 if (ret & 1)
@@ -116,7 +116,7 @@ static inline int ls_get_code_regular(GetBitContext *gb, 
JLSState *state, int Q)
 /**
  * Get Golomb code, decode it and update state for run termination
  */
-static inline int ls_get_code_runterm(GetBitContext *gb, JLSState *state,
+static inline int ls_get_code_runterm(BitstreamContext *bc, JLSState *state,
   int RItype, int limit_add)
 {
 int k, ret, temp, map;
@@ -130,10 +130,10 @@ static inline int ls_get_code_runterm(GetBitContext *gb, 
JLSState *state,
 ;
 
 #ifdef JLS_BROKEN
-if (!show_bits_long(gb, 32))
+if (!bitstream_skip(bc, 32))
 return -1;
 #endif
-ret = get_ur_golomb_jpegls(gb, k, state->limit - limit_add - 1,
+ret = get_ur_golomb_jpegls(bc, k, state->limit - limit_add - 1,
state->qbpp);
 
 /* decode mapped error */
@@ -187,7 +187,7 @@ static inline void ls_decode_line(JLSState *state, 
MJpegDecodeContext *s,
 int RItype;
 
 /* decode full runs while available */
-while (get_bits1(>gb)) {
+while (bitstream_read_bit(>bc)) {
 int r;
 r = 1 << ff_log2_run[state->run_index[comp]];
 if (x + r * stride > w)
@@ -207,7 +207,7 @@ static inline void ls_decode_line(JLSState *state, 
MJpegDecodeContext *s,
 /* decode aborted run */
 r = ff_log2_run[state->run_index[comp]];
 if (r)
-r = get_bits_long(>gb, r);
+r = bitstream_read(>bc, r);
 for (i = 0; i < r; i++) {
 W(dst, x, Ra);
 x += stride;
@@ -216,7 +216,7 @@ static inline void ls_decode_line(JLSState *state, 
MJpegDecodeContext *s,
 /* decode run termination value */
 Rb = R(last, x);
 RItype = (FFABS(Ra - Rb) <= state->near) ? 1 : 0;
-err= ls_get_code_runterm(>gb, state, RItype,
+err= ls_get_code_runterm(>bc, state, RItype,
  ff_log2_run[state->run_index[comp]]);
 if (state->run_index[comp])
 state->run_index[comp]--;
@@ -246,10 +246,10 @@ static inline void ls_decode_line(JLSState *state, 
MJpegDecodeContext *s,
 
 if (sign) {
 pred = av_clip(pred - state->C[context], 0, state->maxval);
-err  = -ls_get_code_regular(>gb, state, context);
+err  = -ls_get_code_regular(>bc, state, context);
 } else {
 pred = av_clip(pred + state->C[context], 0, state->maxval);
-err  = ls_get_code_regular(>gb, state, context);
+err  = ls_get_code_regular(>bc, state, context);
 }
 
 /* we have to do something more for near-lossless coding */
@@ -333,8 

[libav-devel] [PATCH 30/38] ffv1dec: Convert to the new bitstream reader

2016-05-20 Thread Alexandra Hájková
---
 libavcodec/ffv1.c|  2 +-
 libavcodec/ffv1.h|  4 ++--
 libavcodec/ffv1dec.c | 22 +++---
 3 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/libavcodec/ffv1.c b/libavcodec/ffv1.c
index 21d3583..69bc368 100644
--- a/libavcodec/ffv1.c
+++ b/libavcodec/ffv1.c
@@ -28,7 +28,7 @@
 #include "libavutil/attributes.h"
 
 #include "avcodec.h"
-#include "get_bits.h"
+#include "bitstream.h"
 #include "put_bits.h"
 #include "rangecoder.h"
 #include "golomb.h"
diff --git a/libavcodec/ffv1.h b/libavcodec/ffv1.h
index 34370fa..7e0465a 100644
--- a/libavcodec/ffv1.h
+++ b/libavcodec/ffv1.h
@@ -26,7 +26,7 @@
 #include 
 
 #include "avcodec.h"
-#include "get_bits.h"
+#include "bitstream.h"
 #include "put_bits.h"
 #include "rangecoder.h"
 
@@ -70,7 +70,7 @@ typedef struct FFV1Context {
 AVClass *class;
 AVCodecContext *avctx;
 RangeCoder c;
-GetBitContext gb;
+BitstreamContext bc;
 PutBitContext pb;
 uint64_t rc_stat[256][2];
 uint64_t (*rc_stat2[MAX_QUANT_TABLES])[32][2];
diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c
index 467fd0d..69ad0f0 100644
--- a/libavcodec/ffv1dec.c
+++ b/libavcodec/ffv1dec.c
@@ -32,8 +32,8 @@
 #include "libavutil/imgutils.h"
 #include "libavutil/timer.h"
 #include "avcodec.h"
+#include "bitstream.h"
 #include "internal.h"
-#include "get_bits.h"
 #include "put_bits.h"
 #include "rangecoder.h"
 #include "golomb.h"
@@ -65,7 +65,7 @@ static av_noinline int get_symbol(RangeCoder *c, uint8_t 
*state, int is_signed)
 return get_symbol_inline(c, state, is_signed);
 }
 
-static inline int get_vlc_symbol(GetBitContext *gb, VlcState *const state,
+static inline int get_vlc_symbol(BitstreamContext *bc, VlcState *const state,
  int bits)
 {
 int k, i, v, ret;
@@ -79,7 +79,7 @@ static inline int get_vlc_symbol(GetBitContext *gb, VlcState 
*const state,
 
 assert(k <= 8);
 
-v = get_sr_golomb(gb, k, 12, bits);
+v = get_sr_golomb(bc, k, 12, bits);
 ff_dlog(NULL, "v:%d bias:%d error:%d drift:%d count:%d k:%d",
 v, state->bias, state->error_sum, state->drift, state->count, k);
 
@@ -128,13 +128,13 @@ static av_always_inline void decode_line(FFV1Context *s, 
int w,
 
 if (run_mode) {
 if (run_count == 0 && run_mode == 1) {
-if (get_bits1(>gb)) {
+if (bitstream_read_bit(>bc)) {
 run_count = 1 << ff_log2_run[run_index];
 if (x + run_count <= w)
 run_index++;
 } else {
 if (ff_log2_run[run_index])
-run_count = get_bits(>gb, 
ff_log2_run[run_index]);
+run_count = bitstream_read(>bc, 
ff_log2_run[run_index]);
 else
 run_count = 0;
 if (run_index)
@@ -146,17 +146,17 @@ static av_always_inline void decode_line(FFV1Context *s, 
int w,
 if (run_count < 0) {
 run_mode  = 0;
 run_count = 0;
-diff  = get_vlc_symbol(>gb, >vlc_state[context],
+diff  = get_vlc_symbol(>bc, >vlc_state[context],
bits);
 if (diff >= 0)
 diff++;
 } else
 diff = 0;
 } else
-diff = get_vlc_symbol(>gb, >vlc_state[context], bits);
+diff = get_vlc_symbol(>bc, >vlc_state[context], bits);
 
 ff_dlog(s->avctx, "count:%d index:%d, mode:%d, x:%d pos:%d\n",
-run_count, run_index, run_mode, x, get_bits_count(>gb));
+run_count, run_index, run_mode, x, bitstream_tell(>bc));
 }
 
 if (sign)
@@ -368,9 +368,9 @@ static int decode_slice(AVCodecContext *c, void *arg)
 if (f->version == 3 && f->minor_version > 1 || f->version > 3)
 get_rac(>c, (uint8_t[]) { 129 });
 fs->ac_byte_count = f->version > 2 || (!x && !y) ? fs->c.bytestream - 
fs->c.bytestream_start - 1 : 0;
-init_get_bits(>gb, fs->c.bytestream_start + fs->ac_byte_count,
-  (fs->c.bytestream_end - fs->c.bytestream_start -
-   fs->ac_byte_count) * 8);
+bitstream_init8(>bc, fs->c.bytestream_start + fs->ac_byte_count,
+(fs->c.bytestream_end - fs->c.bytestream_start -
+ fs->ac_byte_count));
 }
 
 av_assert1(width && height);
-- 
2.1.4

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH 35/38] shorten: Convert to the new bitstream reader

2016-05-20 Thread Alexandra Hájková
---
 libavcodec/shorten.c | 47 ---
 1 file changed, 24 insertions(+), 23 deletions(-)

diff --git a/libavcodec/shorten.c b/libavcodec/shorten.c
index ee6dc70..34b6629 100644
--- a/libavcodec/shorten.c
+++ b/libavcodec/shorten.c
@@ -27,8 +27,8 @@
 
 #include 
 #include "avcodec.h"
+#include "bitstream.h"
 #include "bytestream.h"
-#include "get_bits.h"
 #include "golomb.h"
 #include "internal.h"
 
@@ -79,7 +79,7 @@ static const uint8_t is_audio_command[10] = { 1, 1, 1, 1, 0, 
0, 0, 1, 1, 0 };
 
 typedef struct ShortenContext {
 AVCodecContext *avctx;
-GetBitContext gb;
+BitstreamContext bc;
 
 int min_framesize, max_framesize;
 unsigned channels;
@@ -154,8 +154,8 @@ static int allocate_buffers(ShortenContext *s)
 static inline unsigned int get_uint(ShortenContext *s, int k)
 {
 if (s->version != 0)
-k = get_ur_golomb_shorten(>gb, ULONGSIZE);
-return get_ur_golomb_shorten(>gb, k);
+k = get_ur_golomb_shorten(>bc, ULONGSIZE);
+return get_ur_golomb_shorten(>bc, k);
 }
 
 static void fix_bitshift(ShortenContext *s, int32_t *buffer)
@@ -280,7 +280,7 @@ static int decode_subframe_lpc(ShortenContext *s, int 
command, int channel,
 
 if (command == FN_QLPC) {
 /* read/validate prediction order */
-pred_order = get_ur_golomb_shorten(>gb, LPCQSIZE);
+pred_order = get_ur_golomb_shorten(>bc, LPCQSIZE);
 if (pred_order > s->nwrap) {
 av_log(s->avctx, AV_LOG_ERROR, "invalid pred_order %d\n",
pred_order);
@@ -288,7 +288,7 @@ static int decode_subframe_lpc(ShortenContext *s, int 
command, int channel,
 }
 /* read LPC coefficients */
 for (i = 0; i < pred_order; i++)
-s->coeffs[i] = get_sr_golomb_shorten(>gb, LPCQUANT);
+s->coeffs[i] = get_sr_golomb_shorten(>bc, LPCQUANT);
 coeffs = s->coeffs;
 
 qshift = LPCQUANT;
@@ -315,7 +315,7 @@ static int decode_subframe_lpc(ShortenContext *s, int 
command, int channel,
 sum = init_sum;
 for (j = 0; j < pred_order; j++)
 sum += coeffs[j] * s->decoded[channel][i - j - 1];
-s->decoded[channel][i] = get_sr_golomb_shorten(>gb, residual_size) +
+s->decoded[channel][i] = get_sr_golomb_shorten(>bc, residual_size) +
  (sum >> qshift);
 }
 
@@ -332,7 +332,7 @@ static int read_header(ShortenContext *s)
 int i, ret;
 int maxnlpc = 0;
 /* shorten signature */
-if (get_bits_long(>gb, 32) != AV_RB32("ajkg")) {
+if (bitstream_read(>bc, 32) != AV_RB32("ajkg")) {
 av_log(s->avctx, AV_LOG_ERROR, "missing shorten magic 'ajkg'\n");
 return AVERROR_INVALIDDATA;
 }
@@ -340,7 +340,7 @@ static int read_header(ShortenContext *s)
 s->lpcqoffset = 0;
 s->blocksize  = DEFAULT_BLOCK_SIZE;
 s->nmean  = -1;
-s->version= get_bits(>gb, 8);
+s->version= bitstream_read(>bc, 8);
 s->internal_ftype = get_uint(s, TYPESIZE);
 
 s->channels = get_uint(s, CHANSIZE);
@@ -374,7 +374,7 @@ static int read_header(ShortenContext *s)
 
 skip_bytes = get_uint(s, NSKIPSIZE);
 for (i = 0; i < skip_bytes; i++)
-skip_bits(>gb, 8);
+bitstream_skip(>bc, 8);
 }
 s->nwrap = FFMAX(NWRAP, maxnlpc);
 
@@ -387,13 +387,13 @@ static int read_header(ShortenContext *s)
 if (s->version > 1)
 s->lpcqoffset = V2LPCQOFFSET;
 
-if (get_ur_golomb_shorten(>gb, FNSIZE) != FN_VERBATIM) {
+if (get_ur_golomb_shorten(>bc, FNSIZE) != FN_VERBATIM) {
 av_log(s->avctx, AV_LOG_ERROR,
"missing verbatim section at beginning of stream\n");
 return AVERROR_INVALIDDATA;
 }
 
-s->header_size = get_ur_golomb_shorten(>gb, VERBATIM_CKSIZE_SIZE);
+s->header_size = get_ur_golomb_shorten(>bc, VERBATIM_CKSIZE_SIZE);
 if (s->header_size >= OUT_BUFFER_SIZE ||
 s->header_size < CANONICAL_HEADER_SIZE) {
 av_log(s->avctx, AV_LOG_ERROR, "header is wrong size: %d\n",
@@ -402,7 +402,7 @@ static int read_header(ShortenContext *s)
 }
 
 for (i = 0; i < s->header_size; i++)
-s->header[i] = (char)get_ur_golomb_shorten(>gb, VERBATIM_BYTE_SIZE);
+s->header[i] = (char)get_ur_golomb_shorten(>bc, VERBATIM_BYTE_SIZE);
 
 if ((ret = decode_wave_header(s->avctx, s->header, s->header_size)) < 0)
 return ret;
@@ -464,8 +464,8 @@ static int shorten_decode_frame(AVCodecContext *avctx, void 
*data,
 }
 }
 /* init and position bitstream reader */
-init_get_bits(>gb, buf, buf_size * 8);
-skip_bits(>gb, s->bitindex);
+bitstream_init8(>bc, buf, buf_size);
+bitstream_skip(>bc, s->bitindex);
 
 /* process header or next subblock */
 if (!s->got_header) {
@@ -486,12 +486,12 @@ static int shorten_decode_frame(AVCodecContext *avctx, 
void *data,
 unsigned cmd;
 int len;
 
-if 

[libav-devel] [PATCH 12/38] unary.h: Convert to the new bitstream reader

2016-05-20 Thread Alexandra Hájková
---
 libavcodec/unary.h | 18 +-
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/libavcodec/unary.h b/libavcodec/unary.h
index d14929f..5276c31 100644
--- a/libavcodec/unary.h
+++ b/libavcodec/unary.h
@@ -21,36 +21,36 @@
 #ifndef AVCODEC_UNARY_H
 #define AVCODEC_UNARY_H
 
-#include "get_bits.h"
+#include "bitstream.h"
 
 /**
  * Get unary code of limited length
- * @param gb GetBitContext
+:* @param bc BitstreamContext
  * @param[in] stop The bitstop value (unary code of 1's or 0's)
  * @param[in] len Maximum length
  * @return Unary length/index
  */
-static inline int get_unary(GetBitContext *gb, int stop, int len)
+static inline int get_unary(BitstreamContext *bc, int stop, int len)
 {
 int i;
 
-for(i = 0; i < len && get_bits1(gb) != stop; i++);
+for (i = 0; i < len && bitstream_read_bit(bc) != stop; i++);
 return i;
 }
 
 /**
  * Get unary code terminated by a 0 with a maximum length of 33
- * @param gb GetBitContext
+ * @param bc BitstreamContext
  * @return Unary length/index
  */
-static inline int get_unary_0_33(GetBitContext *gb)
+static inline int get_unary_0_33(BitstreamContext *bc)
 {
-return get_unary(gb, 0, 33);
+return get_unary(bc, 0, 33);
 }
 
-static inline int get_unary_0_9(GetBitContext *gb)
+static inline int get_unary_0_9(BitstreamContext *bc)
 {
-return get_unary(gb, 0, 9);
+return get_unary(bc, 0, 9);
 }
 
 #endif /* AVCODEC_UNARY_H */
-- 
2.1.4

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH 21/38] mpc8 (demuxer): Convert to the new bitstream reader

2016-05-20 Thread Alexandra Hájková
---
 libavformat/mpc8.c | 24 
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/libavformat/mpc8.c b/libavformat/mpc8.c
index 2349ea5..4dd7707 100644
--- a/libavformat/mpc8.c
+++ b/libavformat/mpc8.c
@@ -19,7 +19,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#include "libavcodec/get_bits.h"
+#include "libavcodec/bitstream.h"
 #include "libavcodec/unary.h"
 #include "apetag.h"
 #include "avformat.h"
@@ -106,17 +106,17 @@ static int mpc8_probe(AVProbeData *p)
 return 0;
 }
 
-static inline int64_t gb_get_v(GetBitContext *gb)
+static inline int64_t gb_get_v(BitstreamContext *bc)
 {
 int64_t v = 0;
 int bits = 0;
-while(get_bits1(gb) && bits < 64-7){
+while (bitstream_read_bit(bc) && bits < 64 - 7) {
 v <<= 7;
-v |= get_bits(gb, 7);
+v |= bitstream_read(bc, 7);
 bits += 7;
 }
 v <<= 7;
-v |= get_bits(gb, 7);
+v |= bitstream_read(bc, 7);
 
 return v;
 }
@@ -137,7 +137,7 @@ static void mpc8_parse_seektable(AVFormatContext *s, 
int64_t off)
 int64_t size, pos, ppos[2];
 uint8_t *buf;
 int i, t, seekd;
-GetBitContext gb;
+BitstreamContext bc;
 
 if (s->nb_streams == 0) {
 av_log(s, AV_LOG_ERROR, "No stream added before parsing seek table\n");
@@ -157,21 +157,21 @@ static void mpc8_parse_seektable(AVFormatContext *s, 
int64_t off)
 if(!(buf = av_malloc(size + AV_INPUT_BUFFER_PADDING_SIZE)))
 return;
 avio_read(s->pb, buf, size);
-init_get_bits(, buf, size * 8);
-size = gb_get_v();
+bitstream_init8(, buf, size);
+size = gb_get_v();
 if(size > UINT_MAX/4 || size > c->samples/1152){
 av_log(s, AV_LOG_ERROR, "Seek table is too big\n");
 return;
 }
-seekd = get_bits(, 4);
+seekd = bitstream_read(, 4);
 for(i = 0; i < 2; i++){
-pos = gb_get_v() + c->header_pos;
+pos = gb_get_v() + c->header_pos;
 ppos[1 - i] = pos;
 av_add_index_entry(s->streams[0], pos, i, 0, 0, AVINDEX_KEYFRAME);
 }
 for(; i < size; i++){
-t = get_unary(, 1, 33) << 12;
-t += get_bits(, 12);
+t = get_unary(, 1, 33) << 12;
+t += bitstream_read(, 12);
 if(t & 1)
 t = -(t & ~1);
 pos = (t >> 1) + ppos[0]*2 - ppos[1];
-- 
2.1.4

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH 18/38] dca: Convert to the new bitstream reader

2016-05-20 Thread Alexandra Hájková
---
 libavcodec/dca.h|   6 +-
 libavcodec/dca_exss.c   | 166 ++--
 libavcodec/dca_parser.c |  16 ++--
 libavcodec/dca_xll.c| 158 +-
 libavcodec/dcadec.c | 219 
 5 files changed, 283 insertions(+), 282 deletions(-)

diff --git a/libavcodec/dca.h b/libavcodec/dca.h
index 787a9c7..04d4487 100644
--- a/libavcodec/dca.h
+++ b/libavcodec/dca.h
@@ -31,9 +31,9 @@
 #include "libavutil/internal.h"
 
 #include "avcodec.h"
+#include "bitstream.h"
 #include "dcadsp.h"
 #include "fmtconvert.h"
-#include "get_bits.h"
 
 #define DCA_PRIM_CHANNELS_MAX  (7)
 #define DCA_ABITS_MAX (32)  /* Should be 28 */
@@ -117,7 +117,7 @@ typedef struct XllChSetSubHeader {
 } XllChSetSubHeader;
 
 typedef struct XllNavi {
-GetBitContext gb;  // Context for parsing the data segments
+BitstreamContext bc;  // Context for parsing the data segments
 unsigned band_size[DCA_XLL_FBANDS_MAX];
 unsigned segment_size[DCA_XLL_FBANDS_MAX][DCA_XLL_SEGMENTS_MAX];
 unsigned 
chset_size[DCA_XLL_FBANDS_MAX][DCA_XLL_SEGMENTS_MAX][DCA_XLL_CHSETS_MAX];
@@ -239,7 +239,7 @@ typedef struct DCAContext {
 int dca_buffer_size;///< how much data is in the dca_buffer
 
 const int8_t *channel_order_tab;  ///< channel reordering table, lfe and 
non lfe
-GetBitContext gb;
+BitstreamContext bc;
 /* Current position in DCA frame */
 int current_subframe;
 int current_subsubframe;
diff --git a/libavcodec/dca_exss.c b/libavcodec/dca_exss.c
index 2895e20..846be41 100644
--- a/libavcodec/dca_exss.c
+++ b/libavcodec/dca_exss.c
@@ -21,9 +21,9 @@
 #include "libavutil/common.h"
 #include "libavutil/log.h"
 
+#include "bitstream.h"
 #include "dca.h"
 #include "dca_syncwords.h"
-#include "get_bits.h"
 
 /* extensions that reside in core substream */
 #define DCA_CORE_EXTS (DCA_EXT_XCH | DCA_EXT_XXCH | DCA_EXT_X96)
@@ -69,14 +69,14 @@ static int dca_exss_mask2count(int mask)
 /**
  * Skip mixing coefficients of a single mix out configuration (HD)
  */
-static void dca_exss_skip_mix_coeffs(GetBitContext *gb, int channels, int 
out_ch)
+static void dca_exss_skip_mix_coeffs(BitstreamContext *bc, int channels, int 
out_ch)
 {
 int i;
 
 for (i = 0; i < channels; i++) {
-int mix_map_mask = get_bits(gb, out_ch);
+int mix_map_mask = bitstream_read(bc, out_ch);
 int num_coeffs = av_popcount(mix_map_mask);
-skip_bits_long(gb, num_coeffs * 6);
+bitstream_skip(bc, num_coeffs * 6);
 }
 }
 
@@ -85,7 +85,7 @@ static void dca_exss_skip_mix_coeffs(GetBitContext *gb, int 
channels, int out_ch
  */
 static int dca_exss_parse_asset_header(DCAContext *s)
 {
-int header_pos = get_bits_count(>gb);
+int header_pos = bitstream_tell(>bc);
 int header_size;
 int channels = 0;
 int embedded_stereo = 0;
@@ -94,112 +94,112 @@ static int dca_exss_parse_asset_header(DCAContext *s)
 int extensions_mask = 0;
 int i, j;
 
-if (get_bits_left(>gb) < 16)
+if (bitstream_bits_left(>bc) < 16)
 return AVERROR_INVALIDDATA;
 
 /* We will parse just enough to get to the extensions bitmask with which
  * we can set the profile value. */
 
-header_size = get_bits(>gb, 9) + 1;
-skip_bits(>gb, 3); // asset index
+header_size = bitstream_read(>bc, 9) + 1;
+bitstream_skip(>bc, 3); // asset index
 
 if (s->static_fields) {
-if (get_bits1(>gb))
-skip_bits(>gb, 4); // asset type descriptor
-if (get_bits1(>gb))
-skip_bits_long(>gb, 24); // language descriptor
+if (bitstream_read_bit(>bc))
+bitstream_skip(>bc, 4); // asset type descriptor
+if (bitstream_read_bit(>bc))
+bitstream_skip(>bc, 24); // language descriptor
 
-if (get_bits1(>gb)) {
+if (bitstream_read_bit(>bc)) {
 /* How can one fit 1024 bytes of text here if the maximum value
  * for the asset header size field above was 512 bytes? */
-int text_length = get_bits(>gb, 10) + 1;
-if (get_bits_left(>gb) < text_length * 8)
+int text_length = bitstream_read(>bc, 10) + 1;
+if (bitstream_bits_left(>bc) < text_length * 8)
 return AVERROR_INVALIDDATA;
-skip_bits_long(>gb, text_length * 8); // info text
+bitstream_skip(>bc, text_length * 8); // info text
 }
 
-skip_bits(>gb, 5); // bit resolution - 1
-skip_bits(>gb, 4); // max sample rate code
-channels = get_bits(>gb, 8) + 1;
+bitstream_skip(>bc, 5); // bit resolution - 1
+bitstream_skip(>bc, 4); // max sample rate code
+channels = bitstream_read(>bc, 8) + 1;
 
-s->one2one_map_chtospkr = get_bits1(>gb);
+s->one2one_map_chtospkr = bitstream_read_bit(>bc);
 if (s->one2one_map_chtospkr) {
 int spkr_remap_sets;
 int 

[libav-devel] [PATCH 32/38] flac: Convert to the new bitstream reader

2016-05-20 Thread Alexandra Hájková
---
 libavcodec/flac.c| 67 
 libavcodec/flac.h|  6 ++---
 libavcodec/flac_parser.c |  6 ++---
 libavcodec/flacdec.c | 56 
 libavcodec/flacenc.c |  1 -
 5 files changed, 68 insertions(+), 68 deletions(-)

diff --git a/libavcodec/flac.c b/libavcodec/flac.c
index 3e51fde..2e5c843 100644
--- a/libavcodec/flac.c
+++ b/libavcodec/flac.c
@@ -22,8 +22,9 @@
 #include "libavutil/channel_layout.h"
 #include "libavutil/crc.h"
 #include "libavutil/log.h"
+
+#include "bitstream.h"
 #include "bytestream.h"
-#include "get_bits.h"
 #include "flac.h"
 #include "flacdata.h"
 
@@ -40,33 +41,33 @@ static const uint64_t flac_channel_layouts[8] = {
 AV_CH_LAYOUT_7POINT1
 };
 
-static int64_t get_utf8(GetBitContext *gb)
+static int64_t get_utf8(BitstreamContext *bc)
 {
 int64_t val;
-GET_UTF8(val, get_bits(gb, 8), return -1;)
+GET_UTF8(val, bitstream_read(bc, 8), return -1;)
 return val;
 }
 
-int ff_flac_decode_frame_header(AVCodecContext *avctx, GetBitContext *gb,
+int ff_flac_decode_frame_header(AVCodecContext *avctx, BitstreamContext *bc,
 FLACFrameInfo *fi, int log_level_offset)
 {
 int bs_code, sr_code, bps_code;
 
 /* frame sync code */
-if ((get_bits(gb, 15) & 0x7FFF) != 0x7FFC) {
+if ((bitstream_read(bc, 15) & 0x7FFF) != 0x7FFC) {
 av_log(avctx, AV_LOG_ERROR + log_level_offset, "invalid sync code\n");
 return AVERROR_INVALIDDATA;
 }
 
 /* variable block size stream code */
-fi->is_var_size = get_bits1(gb);
+fi->is_var_size = bitstream_read_bit(bc);
 
 /* block size and sample rate codes */
-bs_code = get_bits(gb, 4);
-sr_code = get_bits(gb, 4);
+bs_code = bitstream_read(bc, 4);
+sr_code = bitstream_read(bc, 4);
 
 /* channels and decorrelation */
-fi->ch_mode = get_bits(gb, 4);
+fi->ch_mode = bitstream_read(bc, 4);
 if (fi->ch_mode < FLAC_MAX_CHANNELS) {
 fi->channels = fi->ch_mode + 1;
 fi->ch_mode = FLAC_CHMODE_INDEPENDENT;
@@ -80,7 +81,7 @@ int ff_flac_decode_frame_header(AVCodecContext *avctx, 
GetBitContext *gb,
 }
 
 /* bits per sample */
-bps_code = get_bits(gb, 3);
+bps_code = bitstream_read(bc, 3);
 if (bps_code == 3 || bps_code == 7) {
 av_log(avctx, AV_LOG_ERROR + log_level_offset,
"invalid sample size code (%d)\n",
@@ -90,14 +91,14 @@ int ff_flac_decode_frame_header(AVCodecContext *avctx, 
GetBitContext *gb,
 fi->bps = sample_size_table[bps_code];
 
 /* reserved bit */
-if (get_bits1(gb)) {
+if (bitstream_read_bit(bc)) {
 av_log(avctx, AV_LOG_ERROR + log_level_offset,
"broken stream, invalid padding\n");
 return AVERROR_INVALIDDATA;
 }
 
 /* sample or frame count */
-fi->frame_or_sample_num = get_utf8(gb);
+fi->frame_or_sample_num = get_utf8(bc);
 if (fi->frame_or_sample_num < 0) {
 av_log(avctx, AV_LOG_ERROR + log_level_offset,
"sample/frame number invalid; utf8 fscked\n");
@@ -110,9 +111,9 @@ int ff_flac_decode_frame_header(AVCodecContext *avctx, 
GetBitContext *gb,
"reserved blocksize code: 0\n");
 return AVERROR_INVALIDDATA;
 } else if (bs_code == 6) {
-fi->blocksize = get_bits(gb, 8) + 1;
+fi->blocksize = bitstream_read(bc, 8) + 1;
 } else if (bs_code == 7) {
-fi->blocksize = get_bits(gb, 16) + 1;
+fi->blocksize = bitstream_read(bc, 16) + 1;
 } else {
 fi->blocksize = ff_flac_blocksize_table[bs_code];
 }
@@ -121,11 +122,11 @@ int ff_flac_decode_frame_header(AVCodecContext *avctx, 
GetBitContext *gb,
 if (sr_code < 12) {
 fi->samplerate = ff_flac_sample_rate_table[sr_code];
 } else if (sr_code == 12) {
-fi->samplerate = get_bits(gb, 8) * 1000;
+fi->samplerate = bitstream_read(bc, 8) * 1000;
 } else if (sr_code == 13) {
-fi->samplerate = get_bits(gb, 16);
+fi->samplerate = bitstream_read(bc, 16);
 } else if (sr_code == 14) {
-fi->samplerate = get_bits(gb, 16) * 10;
+fi->samplerate = bitstream_read(bc, 16) * 10;
 } else {
 av_log(avctx, AV_LOG_ERROR + log_level_offset,
"illegal sample rate code %d\n",
@@ -134,9 +135,9 @@ int ff_flac_decode_frame_header(AVCodecContext *avctx, 
GetBitContext *gb,
 }
 
 /* header CRC-8 check */
-skip_bits(gb, 8);
-if (av_crc(av_crc_get_table(AV_CRC_8_ATM), 0, gb->buffer,
-   get_bits_count(gb)/8)) {
+bitstream_skip(bc, 8);
+if (av_crc(av_crc_get_table(AV_CRC_8_ATM), 0, bc->buffer,
+   bitstream_tell(bc)/8)) {
 av_log(avctx, AV_LOG_ERROR + log_level_offset,
"header crc mismatch\n");
 return AVERROR_INVALIDDATA;
@@ -204,23 +205,23 @@ void ff_flac_set_channel_layout(AVCodecContext *avctx)
 void 

[libav-devel] [PATCH 24/38] golomb.h: Optimise svq3_get_ue_golomb

2016-05-20 Thread Alexandra Hájková
Do not prefetch data too often for short codes.
---
 libavcodec/golomb.h | 13 +++--
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/libavcodec/golomb.h b/libavcodec/golomb.h
index 3b81327..49fde77 100644
--- a/libavcodec/golomb.h
+++ b/libavcodec/golomb.h
@@ -107,18 +107,19 @@ static inline unsigned 
svq3_get_ue_golomb(BitstreamContext *bb)
 {
 uint32_t buf;
 
-buf = bitstream_peek(bb, 32);
+buf = bitstream_peek(bb, 9);
 
-if (buf & 0xAA80) {
-buf >>= 32 - 8;
+if (buf & 0x155) {
+buf >>= 1;
 bitstream_skip(bb, ff_interleaved_golomb_vlc_len[buf]);
 
 return ff_interleaved_ue_golomb_vlc_code[buf];
 } else {
-unsigned ret = 1;
+unsigned ret = (1 << 4) | ff_interleaved_dirac_golomb_vlc_code[buf >> 
1];
 
+bitstream_skip(bb, 8);
+buf = bitstream_peek(bb, 8);
 do {
-buf >>= 32 - 8;
 bitstream_skip(bb, FFMIN(ff_interleaved_golomb_vlc_len[buf], 8));
 
 if (ff_interleaved_golomb_vlc_len[buf] != 9) {
@@ -127,7 +128,7 @@ static inline unsigned svq3_get_ue_golomb(BitstreamContext 
*bb)
 break;
 }
 ret = (ret << 4) | ff_interleaved_dirac_golomb_vlc_code[buf];
-buf = bitstream_peek(bb, 32);
+buf = bitstream_peek(bb, 8);
 } while (bitstream_bits_left(bb) > 0);
 
 return ret - 1;
-- 
2.1.4

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH 11/38] rv10, rv30, rv40: Convert to the new bitstream reader

2016-05-20 Thread Alexandra Hájková
---
 libavcodec/rv10.c |  84 ++-
 libavcodec/rv30.c |  31 ++---
 libavcodec/rv34.c | 130 --
 libavcodec/rv34.h |   8 ++--
 libavcodec/rv40.c |  64 ++-
 5 files changed, 165 insertions(+), 152 deletions(-)

diff --git a/libavcodec/rv10.c b/libavcodec/rv10.c
index 3b5f4df..e816bc2 100644
--- a/libavcodec/rv10.c
+++ b/libavcodec/rv10.c
@@ -30,6 +30,7 @@
 #include "libavutil/imgutils.h"
 
 #include "avcodec.h"
+#include "bitstream.h"
 #include "error_resilience.h"
 #include "h263.h"
 #include "h263data.h"
@@ -40,6 +41,7 @@
 #include "mpeg4video.h"
 #include "mpegvideodata.h"
 #include "rv10.h"
+#include "vlc.h"
 
 #define RV_GET_MAJOR_VER(x)  ((x) >> 28)
 #define RV_GET_MINOR_VER(x) (((x) >> 20) & 0xFF)
@@ -200,39 +202,39 @@ int ff_rv_decode_dc(MpegEncContext *s, int n)
 int code;
 
 if (n < 4) {
-code = get_vlc2(>gb, rv_dc_lum.table, DC_VLC_BITS, 2);
+code = bitstream_read_vlc(>bc, rv_dc_lum.table, DC_VLC_BITS, 2);
 if (code < 0) {
 /* XXX: I don't understand why they use LONGER codes than
  * necessary. The following code would be completely useless
  * if they had thought about it !!! */
-code = get_bits(>gb, 7);
+code = bitstream_read(>bc, 7);
 if (code == 0x7c) {
-code = (int8_t) (get_bits(>gb, 7) + 1);
+code = (int8_t) (bitstream_read(>bc, 7) + 1);
 } else if (code == 0x7d) {
-code = -128 + get_bits(>gb, 7);
+code = -128 + bitstream_read(>bc, 7);
 } else if (code == 0x7e) {
-if (get_bits1(>gb) == 0)
-code = (int8_t) (get_bits(>gb, 8) + 1);
+if (bitstream_read_bit(>bc) == 0)
+code = (int8_t) (bitstream_read(>bc, 8) + 1);
 else
-code = (int8_t) (get_bits(>gb, 8));
+code = (int8_t) (bitstream_read(>bc, 8));
 } else if (code == 0x7f) {
-skip_bits(>gb, 11);
+bitstream_skip(>bc, 11);
 code = 1;
 }
 } else {
 code -= 128;
 }
 } else {
-code = get_vlc2(>gb, rv_dc_chrom.table, DC_VLC_BITS, 2);
+code = bitstream_read_vlc(>bc, rv_dc_chrom.table, DC_VLC_BITS, 2);
 /* same remark */
 if (code < 0) {
-code = get_bits(>gb, 9);
+code = bitstream_read(>bc, 9);
 if (code == 0x1fc) {
-code = (int8_t) (get_bits(>gb, 7) + 1);
+code = (int8_t) (bitstream_read(>bc, 7) + 1);
 } else if (code == 0x1fd) {
-code = -128 + get_bits(>gb, 7);
+code = -128 + bitstream_read(>bc, 7);
 } else if (code == 0x1fe) {
-skip_bits(>gb, 9);
+bitstream_skip(>bc, 9);
 code = 1;
 } else {
 av_log(s->avctx, AV_LOG_ERROR, "chroma dc error\n");
@@ -250,9 +252,9 @@ static int rv10_decode_picture_header(MpegEncContext *s)
 {
 int mb_count, pb_frame, marker, mb_xy;
 
-marker = get_bits1(>gb);
+marker = bitstream_read_bit(>bc);
 
-if (get_bits1(>gb))
+if (bitstream_read_bit(>bc))
 s->pict_type = AV_PICTURE_TYPE_P;
 else
 s->pict_type = AV_PICTURE_TYPE_I;
@@ -260,7 +262,7 @@ static int rv10_decode_picture_header(MpegEncContext *s)
 if (!marker)
 av_log(s->avctx, AV_LOG_ERROR, "marker missing\n");
 
-pb_frame = get_bits1(>gb);
+pb_frame = bitstream_read_bit(>bc);
 
 ff_dlog(s->avctx, "pict_type=%d pb_frame=%d\n", s->pict_type, pb_frame);
 
@@ -269,7 +271,7 @@ static int rv10_decode_picture_header(MpegEncContext *s)
 return AVERROR_PATCHWELCOME;
 }
 
-s->qscale = get_bits(>gb, 5);
+s->qscale = bitstream_read(>bc, 5);
 if (s->qscale == 0) {
 av_log(s->avctx, AV_LOG_ERROR, "Invalid qscale value: 0\n");
 return AVERROR_INVALIDDATA;
@@ -278,9 +280,9 @@ static int rv10_decode_picture_header(MpegEncContext *s)
 if (s->pict_type == AV_PICTURE_TYPE_I) {
 if (s->rv10_version == 3) {
 /* specific MPEG like DC coding not used */
-s->last_dc[0] = get_bits(>gb, 8);
-s->last_dc[1] = get_bits(>gb, 8);
-s->last_dc[2] = get_bits(>gb, 8);
+s->last_dc[0] = bitstream_read(>bc, 8);
+s->last_dc[1] = bitstream_read(>bc, 8);
+s->last_dc[2] = bitstream_read(>bc, 8);
 ff_dlog(s->avctx, "DC:%d %d %d\n", s->last_dc[0],
 s->last_dc[1], s->last_dc[2]);
 }
@@ -289,16 +291,16 @@ static int rv10_decode_picture_header(MpegEncContext *s)
  * to display the macroblocks is coded here */
 
 mb_xy = s->mb_x + s->mb_y * s->mb_width;
-if (show_bits(>gb, 12) == 0 || (mb_xy && mb_xy < s->mb_num)) 

[libav-devel] [PATCH 31/38] fic: Convert to the new bitstream reader

2016-05-20 Thread Alexandra Hájková
---
 libavcodec/fic.c | 16 
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/libavcodec/fic.c b/libavcodec/fic.c
index b1286eb..455d88e 100644
--- a/libavcodec/fic.c
+++ b/libavcodec/fic.c
@@ -23,8 +23,8 @@
 
 #include "libavutil/common.h"
 #include "avcodec.h"
+#include "bitstream.h"
 #include "internal.h"
-#include "get_bits.h"
 #include "golomb.h"
 
 typedef struct FICThreadContext {
@@ -128,13 +128,13 @@ static void fic_idct_put(uint8_t *dst, int stride, 
int16_t *block)
 ptr += 8;
 }
 }
-static int fic_decode_block(FICContext *ctx, GetBitContext *gb,
+static int fic_decode_block(FICContext *ctx, BitstreamContext *bc,
 uint8_t *dst, int stride, int16_t *block)
 {
 int i, num_coeff;
 
 /* Is it a skip block? */
-if (get_bits1(gb)) {
+if (bitstream_read_bit(bc)) {
 /* This is a P-frame. */
 ctx->frame->key_frame = 0;
 ctx->frame->pict_type = AV_PICTURE_TYPE_P;
@@ -144,12 +144,12 @@ static int fic_decode_block(FICContext *ctx, 
GetBitContext *gb,
 
 memset(block, 0, sizeof(*block) * 64);
 
-num_coeff = get_bits(gb, 7);
+num_coeff = bitstream_read(bc, 7);
 if (num_coeff > 64)
 return AVERROR_INVALIDDATA;
 
 for (i = 0; i < num_coeff; i++)
-block[ff_zigzag_direct[i]] = get_se_golomb(gb) *
+block[ff_zigzag_direct[i]] = get_se_golomb(bc) *
  ctx->qmat[ff_zigzag_direct[i]];
 
 fic_idct_put(dst, stride, block);
@@ -161,14 +161,14 @@ static int fic_decode_slice(AVCodecContext *avctx, void 
*tdata)
 {
 FICContext *ctx= avctx->priv_data;
 FICThreadContext *tctx = tdata;
-GetBitContext gb;
+BitstreamContext bc;
 uint8_t *src = tctx->src;
 int slice_h  = tctx->slice_h;
 int src_size = tctx->src_size;
 int y_off= tctx->y_off;
 int x, y, p;
 
-init_get_bits(, src, src_size * 8);
+bitstream_init8(, src, src_size);
 
 for (p = 0; p < 3; p++) {
 int stride   = ctx->frame->linesize[p];
@@ -178,7 +178,7 @@ static int fic_decode_slice(AVCodecContext *avctx, void 
*tdata)
 for (x = 0; x < (ctx->aligned_width >> !!p); x += 8) {
 int ret;
 
-if ((ret = fic_decode_block(ctx, , dst + x, stride, 
tctx->block)) != 0)
+if ((ret = fic_decode_block(ctx, , dst + x, stride, 
tctx->block)) != 0)
 return ret;
 }
 
-- 
2.1.4

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH 27/38] svq3: Convert to the new bitstream reader

2016-05-20 Thread Alexandra Hájková
---
 libavcodec/svq3.c | 134 +++---
 1 file changed, 68 insertions(+), 66 deletions(-)

diff --git a/libavcodec/svq3.c b/libavcodec/svq3.c
index b11e6ff..b9fe030 100644
--- a/libavcodec/svq3.c
+++ b/libavcodec/svq3.c
@@ -45,6 +45,7 @@
 #include "libavutil/attributes.h"
 #include "internal.h"
 #include "avcodec.h"
+#include "bitstream.h"
 #include "mpegutils.h"
 #include "h264.h"
 #include "h264data.h"
@@ -77,8 +78,8 @@ typedef struct SVQ3Context {
 H264Picture *cur_pic;
 H264Picture *next_pic;
 H264Picture *last_pic;
-GetBitContext gb;
-GetBitContext gb_slice;
+BitstreamContext bc;
+BitstreamContext bc_slice;
 uint8_t *slice_buf;
 int slice_size;
 int halfpel_flag;
@@ -277,7 +278,7 @@ static void svq3_add_idct_c(uint8_t *dst, int16_t *block,
 memset(block, 0, 16 * sizeof(int16_t));
 }
 
-static inline int svq3_decode_block(GetBitContext *gb, int16_t *block,
+static inline int svq3_decode_block(BitstreamContext *bc, int16_t *block,
 int index, const int type)
 {
 static const uint8_t *const scan_patterns[4] = {
@@ -290,7 +291,7 @@ static inline int svq3_decode_block(GetBitContext *gb, 
int16_t *block,
 const uint8_t *const scan = scan_patterns[type];
 
 for (limit = (16 >> intra); index < 16; index = limit, limit += 8) {
-for (; (vlc = svq3_get_ue_golomb(gb)) != 0; index++) {
+for (; (vlc = svq3_get_ue_golomb(bc)) != 0; index++) {
 int sign = (vlc & 1) ? 0 : -1;
 vlc  = vlc + 1 >> 1;
 
@@ -527,8 +528,8 @@ static inline int svq3_mc_dir(SVQ3Context *s, int size, int 
mode,
 if (mode == PREDICT_MODE) {
 dx = dy = 0;
 } else {
-dy = svq3_get_se_golomb(>gb_slice);
-dx = svq3_get_se_golomb(>gb_slice);
+dy = svq3_get_se_golomb(>bc_slice);
+dx = svq3_get_se_golomb(>bc_slice);
 
 if (dx == INVALID_VLC || dy == INVALID_VLC) {
 av_log(s->avctx, AV_LOG_ERROR, "invalid MV vlc\n");
@@ -734,10 +735,10 @@ static int svq3_decode_mb(SVQ3Context *s, unsigned int 
mb_type)
 mb_type = MB_TYPE_16x16;
 }
 } else if (mb_type < 8) { /* INTER */
-if (s->thirdpel_flag && s->halfpel_flag == !get_bits1(>gb_slice))
+if (s->thirdpel_flag && s->halfpel_flag == 
!bitstream_read_bit(>bc_slice))
 mode = THIRDPEL_MODE;
 else if (s->halfpel_flag &&
- s->thirdpel_flag == !get_bits1(>gb_slice))
+ s->thirdpel_flag == !bitstream_read_bit(>bc_slice))
 mode = HALFPEL_MODE;
 else
 mode = FULLPEL_MODE;
@@ -839,7 +840,7 @@ static int svq3_decode_mb(SVQ3Context *s, unsigned int 
mb_type)
 
 /* decode prediction codes for luma blocks */
 for (i = 0; i < 16; i += 2) {
-vlc = svq3_get_ue_golomb(>gb_slice);
+vlc = svq3_get_ue_golomb(>bc_slice);
 
 if (vlc >= 25) {
 av_log(s->avctx, AV_LOG_ERROR,
@@ -917,7 +918,7 @@ static int svq3_decode_mb(SVQ3Context *s, unsigned int 
mb_type)
 
 if (!IS_INTRA16x16(mb_type) &&
 (!IS_SKIP(mb_type) || s->pict_type == AV_PICTURE_TYPE_B)) {
-if ((vlc = svq3_get_ue_golomb(>gb_slice)) >= 48) {
+if ((vlc = svq3_get_ue_golomb(>bc_slice)) >= 48) {
 av_log(s->avctx, AV_LOG_ERROR, "cbp_vlc=%"PRIu32"\n", vlc);
 return -1;
 }
@@ -927,7 +928,7 @@ static int svq3_decode_mb(SVQ3Context *s, unsigned int 
mb_type)
 }
 if (IS_INTRA16x16(mb_type) ||
 (s->pict_type != AV_PICTURE_TYPE_I && s->adaptive_quant && cbp)) {
-s->qscale += svq3_get_se_golomb(>gb_slice);
+s->qscale += svq3_get_se_golomb(>bc_slice);
 
 if (s->qscale > 31u) {
 av_log(s->avctx, AV_LOG_ERROR, "qscale:%d\n", s->qscale);
@@ -937,7 +938,7 @@ static int svq3_decode_mb(SVQ3Context *s, unsigned int 
mb_type)
 if (IS_INTRA16x16(mb_type)) {
 AV_ZERO128(s->mb_luma_dc[0] + 0);
 AV_ZERO128(s->mb_luma_dc[0] + 8);
-if (svq3_decode_block(>gb_slice, s->mb_luma_dc[0], 0, 1)) {
+if (svq3_decode_block(>bc_slice, s->mb_luma_dc[0], 0, 1)) {
 av_log(s->avctx, AV_LOG_ERROR,
"error while decoding intra luma dc\n");
 return -1;
@@ -956,7 +957,7 @@ static int svq3_decode_mb(SVQ3Context *s, unsigned int 
mb_type)
   : (4 * i + j);
 s->non_zero_count_cache[scan8[k]] = 1;
 
-if (svq3_decode_block(>gb_slice, >mb[16 * k], index, 
type)) {
+if (svq3_decode_block(>bc_slice, >mb[16 * k], index, 
type)) {
 av_log(s->avctx, AV_LOG_ERROR,
"error while decoding block\n");
 return -1;
@@ -966,7 +967,7 @@ static int 

[libav-devel] [PATCH 23/38] golomb.h: Optimise get_ue/se_golomb

2016-05-20 Thread Alexandra Hájková
Do not prefetch data too often for short codes.
---
 libavcodec/golomb.h | 32 
 1 file changed, 16 insertions(+), 16 deletions(-)

diff --git a/libavcodec/golomb.h b/libavcodec/golomb.h
index 371db4e..3b81327 100644
--- a/libavcodec/golomb.h
+++ b/libavcodec/golomb.h
@@ -55,21 +55,21 @@ static inline int get_ue_golomb(BitstreamContext *bb)
 unsigned int buf;
 int ret;
 
-buf = bitstream_peek(bb, 32);
+buf = bitstream_peek(bb, 9);
 
-if (buf >= (1 << 27)) {
-buf >>= 32 - 9;
+if (buf >= (1 << 4)) {
 bitstream_skip(bb, ff_golomb_vlc_len[buf]);
 
 ret = ff_ue_golomb_vlc_code[buf];
 return ret;
 } else {
-int log = 2 * av_log2(buf) - 31;
-buf >>= log;
-buf--;
+int buf2 = bitstream_peek(bb, 32);
+int log = 2 * av_log2(buf2) - 31;
+buf2 >>= log;
+buf2--;
 bitstream_skip(bb, 32 - log);
 
-return buf;
+return buf2;
 }
 }
 
@@ -169,25 +169,25 @@ static inline int get_se_golomb(BitstreamContext *bb)
 {
 unsigned int buf;
 
-buf = bitstream_peek(bb, 32);
+buf = bitstream_peek(bb, 9);
 
-if (buf >= (1 << 27)) {
-buf >>= 32 - 9;
+if (buf >= (1 << 4)) {
 bitstream_skip(bb, ff_golomb_vlc_len[buf]);
 
 return ff_se_golomb_vlc_code[buf];
 } else {
-int log = 2 * av_log2(buf) - 31;
-buf >>= log;
+int buf2 = bitstream_peek(bb, 32);
+int log = 2 * av_log2(buf2) - 31;
+buf2 >>= log;
 
 bitstream_skip(bb, 32 - log);
 
-if (buf & 1)
-buf = -(buf >> 1);
+if (buf2 & 1)
+buf2 = -(buf2 >> 1);
 else
-buf = (buf >> 1);
+buf2 = (buf2 >> 1);
 
-return buf;
+return buf2;
 }
 }
 
-- 
2.1.4

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH 38/38] alac: Convert to the new bitstream reader

2016-05-20 Thread Alexandra Hájková
---
 libavcodec/alac.c | 62 +++
 1 file changed, 31 insertions(+), 31 deletions(-)

diff --git a/libavcodec/alac.c b/libavcodec/alac.c
index 1f24e1b..28be14b 100644
--- a/libavcodec/alac.c
+++ b/libavcodec/alac.c
@@ -49,7 +49,7 @@
 
 #include "libavutil/channel_layout.h"
 #include "avcodec.h"
-#include "get_bits.h"
+#include "bitstream.h"
 #include "bytestream.h"
 #include "internal.h"
 #include "unary.h"
@@ -60,7 +60,7 @@
 
 typedef struct ALACContext {
 AVCodecContext *avctx;
-GetBitContext gb;
+BitstreamContext bc;
 int channels;
 
 int32_t *predict_error_buffer[2];
@@ -77,24 +77,24 @@ typedef struct ALACContext {
 int nb_samples; /**< number of samples in the current frame */
 } ALACContext;
 
-static inline unsigned int decode_scalar(GetBitContext *gb, int k, int bps)
+static inline unsigned int decode_scalar(BitstreamContext *bc, int k, int bps)
 {
-unsigned int x = get_unary_0_9(gb);
+unsigned int x = get_unary_0_9(bc);
 
 if (x > 8) { /* RICE THRESHOLD */
 /* use alternative encoding */
-x = get_bits_long(gb, bps);
+x = bitstream_read(bc, bps);
 } else if (k != 1) {
-int extrabits = show_bits(gb, k);
+int extrabits = bitstream_peek(bc, k);
 
 /* multiply x by 2^k - 1, as part of their strange algorithm */
 x = (x << k) - x;
 
 if (extrabits > 1) {
 x += extrabits - 1;
-skip_bits(gb, k);
+bitstream_skip(bc, k);
 } else
-skip_bits(gb, k - 1);
+bitstream_skip(bc, k - 1);
 }
 return x;
 }
@@ -113,7 +113,7 @@ static void rice_decompress(ALACContext *alac, int32_t 
*output_buffer,
 /* calculate rice param and decode next value */
 k = av_log2((history >> 9) + 3);
 k = FFMIN(k, alac->rice_limit);
-x = decode_scalar(>gb, k, bps);
+x = decode_scalar(>bc, k, bps);
 x += sign_modifier;
 sign_modifier = 0;
 output_buffer[i] = (x >> 1) ^ -(x & 1);
@@ -132,7 +132,7 @@ static void rice_decompress(ALACContext *alac, int32_t 
*output_buffer,
 /* calculate rice param and decode block size */
 k = 7 - av_log2(history) + ((history + 16) >> 6);
 k = FFMIN(k, alac->rice_limit);
-block_size = decode_scalar(>gb, k, 16);
+block_size = decode_scalar(>bc, k, 16);
 
 if (block_size > 0) {
 if (block_size >= nb_samples - i) {
@@ -257,13 +257,13 @@ static int decode_element(AVCodecContext *avctx, AVFrame 
*frame, int ch_index,
 uint32_t output_samples;
 int i, ch;
 
-skip_bits(>gb, 4);  /* element instance tag */
-skip_bits(>gb, 12); /* unused header bits */
+bitstream_skip(>bc, 4);  /* element instance tag */
+bitstream_skip(>bc, 12); /* unused header bits */
 
 /* the number of output samples is stored in the frame */
-has_size = get_bits1(>gb);
+has_size = bitstream_read_bit(>bc);
 
-alac->extra_bits = get_bits(>gb, 2) << 3;
+alac->extra_bits = bitstream_read(>bc, 2) << 3;
 bps = alac->sample_size - alac->extra_bits + channels - 1;
 if (bps > 32) {
 av_log(avctx, AV_LOG_ERROR, "bps is unsupported: %d\n", bps);
@@ -271,10 +271,10 @@ static int decode_element(AVCodecContext *avctx, AVFrame 
*frame, int ch_index,
 }
 
 /* whether the frame is compressed */
-is_compressed = !get_bits1(>gb);
+is_compressed = !bitstream_read_bit(>bc);
 
 if (has_size)
-output_samples = get_bits_long(>gb, 32);
+output_samples = bitstream_read(>bc, 32);
 else
 output_samples = alac->max_samples_per_frame;
 if (!output_samples || output_samples > alac->max_samples_per_frame) {
@@ -313,27 +313,27 @@ static int decode_element(AVCodecContext *avctx, AVFrame 
*frame, int ch_index,
 return AVERROR(ENOSYS);
 }
 
-decorr_shift   = get_bits(>gb, 8);
-decorr_left_weight = get_bits(>gb, 8);
+decorr_shift   = bitstream_read(>bc, 8);
+decorr_left_weight = bitstream_read(>bc, 8);
 
 for (ch = 0; ch < channels; ch++) {
-prediction_type[ch]   = get_bits(>gb, 4);
-lpc_quant[ch] = get_bits(>gb, 4);
-rice_history_mult[ch] = get_bits(>gb, 3);
-lpc_order[ch] = get_bits(>gb, 5);
+prediction_type[ch]   = bitstream_read(>bc, 4);
+lpc_quant[ch] = bitstream_read(>bc, 4);
+rice_history_mult[ch] = bitstream_read(>bc, 3);
+lpc_order[ch] = bitstream_read(>bc, 5);
 
 if (lpc_order[ch] >= alac->max_samples_per_frame)
 return AVERROR_INVALIDDATA;
 
 /* read the predictor table */
 for (i = lpc_order[ch] - 1; i >= 0; i--)
-lpc_coefs[ch][i] = get_sbits(>gb, 16);
+lpc_coefs[ch][i] = bitstream_read_signed(>bc, 16);
 

[libav-devel] [PATCH 36/38] hevc: Convert to the new bitstream reader

2016-05-20 Thread Alexandra Hájková
---
 libavcodec/hevc.c | 164 +++
 libavcodec/hevc.h |  14 +-
 libavcodec/hevc_cabac.c   |  11 +-
 libavcodec/hevc_parser.c  |  14 +-
 libavcodec/hevc_ps.c  | 455 +-
 libavcodec/hevc_sei.c |  69 +++
 libavcodec/hevcdsp.h  |   4 +-
 libavcodec/hevcdsp_template.c |   6 +-
 8 files changed, 371 insertions(+), 366 deletions(-)

diff --git a/libavcodec/hevc.c b/libavcodec/hevc.c
index 177cf93..0ca42b8 100644
--- a/libavcodec/hevc.c
+++ b/libavcodec/hevc.c
@@ -32,6 +32,7 @@
 #include "libavutil/pixdesc.h"
 #include "libavutil/stereo3d.h"
 
+#include "bitstream.h"
 #include "bswapdsp.h"
 #include "bytestream.h"
 #include "cabac_functions.h"
@@ -191,7 +192,7 @@ fail:
 return AVERROR(ENOMEM);
 }
 
-static void pred_weight_table(HEVCContext *s, GetBitContext *gb)
+static void pred_weight_table(HEVCContext *s, BitstreamContext *bc)
 {
 int i = 0;
 int j = 0;
@@ -200,14 +201,14 @@ static void pred_weight_table(HEVCContext *s, 
GetBitContext *gb)
 uint8_t luma_weight_l1_flag[16];
 uint8_t chroma_weight_l1_flag[16];
 
-s->sh.luma_log2_weight_denom = av_clip(get_ue_golomb_long(gb), 0, 7);
+s->sh.luma_log2_weight_denom = av_clip(get_ue_golomb_long(bc), 0, 7);
 if (s->ps.sps->chroma_format_idc != 0) {
-int delta = get_se_golomb(gb);
+int delta = get_se_golomb(bc);
 s->sh.chroma_log2_weight_denom = av_clip(s->sh.luma_log2_weight_denom 
+ delta, 0, 7);
 }
 
 for (i = 0; i < s->sh.nb_refs[L0]; i++) {
-luma_weight_l0_flag[i] = get_bits1(gb);
+luma_weight_l0_flag[i] = bitstream_read_bit(bc);
 if (!luma_weight_l0_flag[i]) {
 s->sh.luma_weight_l0[i] = 1 << s->sh.luma_log2_weight_denom;
 s->sh.luma_offset_l0[i] = 0;
@@ -215,21 +216,21 @@ static void pred_weight_table(HEVCContext *s, 
GetBitContext *gb)
 }
 if (s->ps.sps->chroma_format_idc != 0) { // FIXME: invert "if" and "for"
 for (i = 0; i < s->sh.nb_refs[L0]; i++)
-chroma_weight_l0_flag[i] = get_bits1(gb);
+chroma_weight_l0_flag[i] = bitstream_read_bit(bc);
 } else {
 for (i = 0; i < s->sh.nb_refs[L0]; i++)
 chroma_weight_l0_flag[i] = 0;
 }
 for (i = 0; i < s->sh.nb_refs[L0]; i++) {
 if (luma_weight_l0_flag[i]) {
-int delta_luma_weight_l0 = get_se_golomb(gb);
+int delta_luma_weight_l0 = get_se_golomb(bc);
 s->sh.luma_weight_l0[i] = (1 << s->sh.luma_log2_weight_denom) + 
delta_luma_weight_l0;
-s->sh.luma_offset_l0[i] = get_se_golomb(gb);
+s->sh.luma_offset_l0[i] = get_se_golomb(bc);
 }
 if (chroma_weight_l0_flag[i]) {
 for (j = 0; j < 2; j++) {
-int delta_chroma_weight_l0 = get_se_golomb(gb);
-int delta_chroma_offset_l0 = get_se_golomb(gb);
+int delta_chroma_weight_l0 = get_se_golomb(bc);
+int delta_chroma_offset_l0 = get_se_golomb(bc);
 s->sh.chroma_weight_l0[i][j] = (1 << 
s->sh.chroma_log2_weight_denom) + delta_chroma_weight_l0;
 s->sh.chroma_offset_l0[i][j] = av_clip((delta_chroma_offset_l0 
- ((128 * s->sh.chroma_weight_l0[i][j])

 >> s->sh.chroma_log2_weight_denom) + 128), -128, 127);
@@ -243,7 +244,7 @@ static void pred_weight_table(HEVCContext *s, GetBitContext 
*gb)
 }
 if (s->sh.slice_type == B_SLICE) {
 for (i = 0; i < s->sh.nb_refs[L1]; i++) {
-luma_weight_l1_flag[i] = get_bits1(gb);
+luma_weight_l1_flag[i] = bitstream_read_bit(bc);
 if (!luma_weight_l1_flag[i]) {
 s->sh.luma_weight_l1[i] = 1 << s->sh.luma_log2_weight_denom;
 s->sh.luma_offset_l1[i] = 0;
@@ -251,21 +252,21 @@ static void pred_weight_table(HEVCContext *s, 
GetBitContext *gb)
 }
 if (s->ps.sps->chroma_format_idc != 0) {
 for (i = 0; i < s->sh.nb_refs[L1]; i++)
-chroma_weight_l1_flag[i] = get_bits1(gb);
+chroma_weight_l1_flag[i] = bitstream_read_bit(bc);
 } else {
 for (i = 0; i < s->sh.nb_refs[L1]; i++)
 chroma_weight_l1_flag[i] = 0;
 }
 for (i = 0; i < s->sh.nb_refs[L1]; i++) {
 if (luma_weight_l1_flag[i]) {
-int delta_luma_weight_l1 = get_se_golomb(gb);
+int delta_luma_weight_l1 = get_se_golomb(bc);
 s->sh.luma_weight_l1[i] = (1 << s->sh.luma_log2_weight_denom) 
+ delta_luma_weight_l1;
-s->sh.luma_offset_l1[i] = get_se_golomb(gb);
+s->sh.luma_offset_l1[i] = get_se_golomb(bc);
 }
 if (chroma_weight_l1_flag[i]) {
 for (j = 0; j < 2; j++) {
-int delta_chroma_weight_l1 = get_se_golomb(gb);
-   

[libav-devel] [PATCH 20/38] alsdec, bgmc: Convert to the new bitstream reader

2016-05-20 Thread Alexandra Hájková
---
 libavcodec/alsdec.c | 228 ++--
 libavcodec/bgmc.c   |  15 ++--
 libavcodec/bgmc.h   |   8 +-
 3 files changed, 127 insertions(+), 124 deletions(-)

diff --git a/libavcodec/alsdec.c b/libavcodec/alsdec.c
index f356a70..37f2795 100644
--- a/libavcodec/alsdec.c
+++ b/libavcodec/alsdec.c
@@ -28,7 +28,7 @@
 #include 
 
 #include "avcodec.h"
-#include "get_bits.h"
+#include "bitstream.h"
 #include "unary.h"
 #include "mpeg4audio.h"
 #include "bytestream.h"
@@ -191,7 +191,7 @@ typedef struct ALSChannelData {
 typedef struct ALSDecContext {
 AVCodecContext *avctx;
 ALSSpecificConfig sconf;
-GetBitContext gb;
+BitstreamContext bc;
 BswapDSPContext bdsp;
 const AVCRC *crc_table;
 uint32_t crc_org;   ///< CRC value of the original input data
@@ -278,7 +278,7 @@ static av_cold void dprint_specific_config(ALSDecContext 
*ctx)
  */
 static av_cold int read_specific_config(ALSDecContext *ctx)
 {
-GetBitContext gb;
+BitstreamContext bc;
 uint64_t ht_size;
 int i, config_offset;
 MPEG4AudioConfig m4ac;
@@ -286,7 +286,7 @@ static av_cold int read_specific_config(ALSDecContext *ctx)
 AVCodecContext *avctx= ctx->avctx;
 uint32_t als_id, header_size, trailer_size;
 
-init_get_bits(, avctx->extradata, avctx->extradata_size * 8);
+bitstream_init8(, avctx->extradata, avctx->extradata_size);
 
 config_offset = avpriv_mpeg4audio_get_config(, avctx->extradata,
  avctx->extradata_size * 8, 1);
@@ -294,40 +294,40 @@ static av_cold int read_specific_config(ALSDecContext 
*ctx)
 if (config_offset < 0)
 return AVERROR_INVALIDDATA;
 
-skip_bits_long(, config_offset);
+bitstream_skip(, config_offset);
 
-if (get_bits_left() < (30 << 3))
+if (bitstream_bits_left() < (30 << 3))
 return AVERROR_INVALIDDATA;
 
 // read the fixed items
-als_id  = get_bits_long(, 32);
+als_id  = bitstream_read(, 32);
 avctx->sample_rate  = m4ac.sample_rate;
-skip_bits_long(, 32); // sample rate already known
-sconf->samples  = get_bits_long(, 32);
+bitstream_skip(, 32); // sample rate already known
+sconf->samples  = bitstream_read(, 32);
 avctx->channels = m4ac.channels;
-skip_bits(, 16);  // number of channels already known
-skip_bits(, 3);   // skip file_type
-sconf->resolution   = get_bits(, 3);
-sconf->floating = get_bits1();
-sconf->msb_first= get_bits1();
-sconf->frame_length = get_bits(, 16) + 1;
-sconf->ra_distance  = get_bits(, 8);
-sconf->ra_flag  = get_bits(, 2);
-sconf->adapt_order  = get_bits1();
-sconf->coef_table   = get_bits(, 2);
-sconf->long_term_prediction = get_bits1();
-sconf->max_order= get_bits(, 10);
-sconf->block_switching  = get_bits(, 2);
-sconf->bgmc = get_bits1();
-sconf->sb_part  = get_bits1();
-sconf->joint_stereo = get_bits1();
-sconf->mc_coding= get_bits1();
-sconf->chan_config  = get_bits1();
-sconf->chan_sort= get_bits1();
-sconf->crc_enabled  = get_bits1();
-sconf->rlslms   = get_bits1();
-skip_bits(, 5);   // skip 5 reserved bits
-skip_bits1(); // skip aux_data_enabled
+bitstream_skip(, 16); // number of channels already knwon
+bitstream_skip(, 3);  // skip file_type
+sconf->resolution   = bitstream_read(, 3);
+sconf->floating = bitstream_read_bit();
+sconf->msb_first= bitstream_read_bit();
+sconf->frame_length = bitstream_read(, 16) + 1;
+sconf->ra_distance  = bitstream_read(, 8);
+sconf->ra_flag  = bitstream_read(, 2);
+sconf->adapt_order  = bitstream_read_bit();
+sconf->coef_table   = bitstream_read(, 2);
+sconf->long_term_prediction = bitstream_read_bit();
+sconf->max_order= bitstream_read(, 10);
+sconf->block_switching  = bitstream_read(, 2);
+sconf->bgmc = bitstream_read_bit();
+sconf->sb_part  = bitstream_read_bit();
+sconf->joint_stereo = bitstream_read_bit();
+sconf->mc_coding= bitstream_read_bit();
+sconf->chan_config  = bitstream_read_bit();
+sconf->chan_sort= bitstream_read_bit();
+sconf->crc_enabled  = bitstream_read_bit();
+sconf->rlslms   = bitstream_read_bit();
+bitstream_skip(, 5);  // skip 5 reserved bits
+bitstream_skip(, 1);  // skip aux_data_enabled
 
 
 // check for ALSSpecificConfig struct
@@ -338,7 +338,7 @@ static av_cold int read_specific_config(ALSDecContext *ctx)
 
 // read channel config
 if 

[libav-devel] [PATCH 19/38] apedec: Convert to the new bitstream reader

2016-05-20 Thread Alexandra Hájková
---
 libavcodec/apedec.c | 44 ++--
 1 file changed, 22 insertions(+), 22 deletions(-)

diff --git a/libavcodec/apedec.c b/libavcodec/apedec.c
index 2f64488..50e3ab2 100644
--- a/libavcodec/apedec.c
+++ b/libavcodec/apedec.c
@@ -27,10 +27,10 @@
 #include "libavutil/opt.h"
 #include "apedsp.h"
 #include "avcodec.h"
+#include "bitstream.h"
 #include "bswapdsp.h"
 #include "bytestream.h"
 #include "internal.h"
-#include "get_bits.h"
 #include "unary.h"
 
 /**
@@ -162,7 +162,7 @@ typedef struct APEContext {
 APERice riceX;   ///< rice code parameters for the 
second channel
 APERice riceY;   ///< rice code parameters for the 
first channel
 APEFilter filters[APE_FILTER_LEVELS][2]; ///< filters used for 
reconstruction
-GetBitContext gb;
+BitstreamContext bc;
 
 uint8_t *data;   ///< current frame data
 uint8_t *data_end;   ///< frame data end
@@ -484,24 +484,24 @@ static inline void update_rice(APERice *rice, unsigned 
int x)
 rice->k++;
 }
 
-static inline int get_rice_ook(GetBitContext *gb, int k)
+static inline int get_rice_ook(BitstreamContext *bc, int k)
 {
 unsigned int x;
 
-x = get_unary(gb, 1, get_bits_left(gb));
+x = get_unary(bc, 1, bitstream_bits_left(bc));
 
 if (k)
-x = (x << k) | get_bits(gb, k);
+x = (x << k) | bitstream_read(bc, k);
 
 return x;
 }
 
-static inline int ape_decode_value_3860(APEContext *ctx, GetBitContext *gb,
+static inline int ape_decode_value_3860(APEContext *ctx, BitstreamContext *bc,
 APERice *rice)
 {
 unsigned int x, overflow;
 
-overflow = get_unary(gb, 1, get_bits_left(gb));
+overflow = get_unary(bc, 1, bitstream_bits_left(bc));
 
 if (ctx->fileversion > 3880) {
 while (overflow >= 16) {
@@ -513,7 +513,7 @@ static inline int ape_decode_value_3860(APEContext *ctx, 
GetBitContext *gb,
 if (!rice->k)
 x = overflow;
 else
-x = (overflow << rice->k) + get_bits(gb, rice->k);
+x = (overflow << rice->k) + bitstream_read(bc, rice->k);
 
 rice->ksum += x - (rice->ksum + 8 >> 4);
 if (rice->ksum < (rice->k ? 1 << (rice->k + 4) : 0))
@@ -607,7 +607,7 @@ static inline int ape_decode_value_3990(APEContext *ctx, 
APERice *rice)
 return -(x >> 1);
 }
 
-static void decode_array_(APEContext *ctx, GetBitContext *gb,
+static void decode_array_(APEContext *ctx, BitstreamContext *bc,
   int32_t *out, APERice *rice, int blockstodecode)
 {
 int i;
@@ -615,19 +615,19 @@ static void decode_array_(APEContext *ctx, 
GetBitContext *gb,
 
 rice->ksum = 0;
 for (i = 0; i < FFMIN(blockstodecode, 5); i++) {
-out[i] = get_rice_ook(>gb, 10);
+out[i] = get_rice_ook(>bc, 10);
 rice->ksum += out[i];
 }
 rice->k = av_log2(rice->ksum / 10) + 1;
 for (; i < FFMIN(blockstodecode, 64); i++) {
-out[i] = get_rice_ook(>gb, rice->k);
+out[i] = get_rice_ook(>bc, rice->k);
 rice->ksum += out[i];
 rice->k = av_log2(rice->ksum / ((i + 1) * 2)) + 1;
 }
 ksummax = 1 << rice->k + 7;
 ksummin = rice->k ? (1 << rice->k + 6) : 0;
 for (; i < blockstodecode; i++) {
-out[i] = get_rice_ook(>gb, rice->k);
+out[i] = get_rice_ook(>bc, rice->k);
 rice->ksum += out[i] - out[i - 64];
 while (rice->ksum < ksummin) {
 rice->k--;
@@ -653,15 +653,15 @@ static void decode_array_(APEContext *ctx, 
GetBitContext *gb,
 
 static void entropy_decode_mono_(APEContext *ctx, int blockstodecode)
 {
-decode_array_(ctx, >gb, ctx->decoded[0], >riceY,
+decode_array_(ctx, >bc, ctx->decoded[0], >riceY,
   blockstodecode);
 }
 
 static void entropy_decode_stereo_(APEContext *ctx, int blockstodecode)
 {
-decode_array_(ctx, >gb, ctx->decoded[0], >riceY,
+decode_array_(ctx, >bc, ctx->decoded[0], >riceY,
   blockstodecode);
-decode_array_(ctx, >gb, ctx->decoded[1], >riceX,
+decode_array_(ctx, >bc, ctx->decoded[1], >riceX,
   blockstodecode);
 }
 
@@ -670,7 +670,7 @@ static void entropy_decode_mono_3860(APEContext *ctx, int 
blockstodecode)
 int32_t *decoded0 = ctx->decoded[0];
 
 while (blockstodecode--)
-*decoded0++ = ape_decode_value_3860(ctx, >gb, >riceY);
+*decoded0++ = ape_decode_value_3860(ctx, >bc, >riceY);
 }
 
 static void entropy_decode_stereo_3860(APEContext *ctx, int blockstodecode)
@@ -680,9 +680,9 @@ static void entropy_decode_stereo_3860(APEContext *ctx, int 
blockstodecode)
 int blocks = blockstodecode;
 
 while (blockstodecode--)
-*decoded0++ = ape_decode_value_3860(ctx, >gb, >riceY);
+*decoded0++ = ape_decode_value_3860(ctx, >bc, >riceY);
 while (blocks--)
-*decoded1++ = 

[libav-devel] [PATCH 15/38] tak: Convert to the new bitstream reader

2016-05-20 Thread Alexandra Hájková
---
 libavcodec/tak.c|  49 
 libavcodec/tak.h|  10 ++--
 libavcodec/tak_parser.c |  14 ++---
 libavcodec/takdec.c | 147 
 libavformat/takdec.c|  12 ++--
 5 files changed, 117 insertions(+), 115 deletions(-)

diff --git a/libavcodec/tak.c b/libavcodec/tak.c
index 867a84b..da4c249 100644
--- a/libavcodec/tak.c
+++ b/libavcodec/tak.c
@@ -22,6 +22,7 @@
 #include "libavutil/bswap.h"
 #include "libavutil/crc.h"
 #include "libavutil/intreadwrite.h"
+
 #include "tak.h"
 
 static const uint16_t frame_duration_type_quants[] = {
@@ -83,30 +84,30 @@ int ff_tak_check_crc(const uint8_t *buf, unsigned int 
buf_size)
 return 0;
 }
 
-void avpriv_tak_parse_streaminfo(GetBitContext *gb, TAKStreamInfo *s)
+void avpriv_tak_parse_streaminfo(BitstreamContext *bc, TAKStreamInfo *s)
 {
 uint64_t channel_mask = 0;
 int frame_type, i;
 
-s->codec = get_bits(gb, TAK_ENCODER_CODEC_BITS);
-skip_bits(gb, TAK_ENCODER_PROFILE_BITS);
+s->codec = bitstream_read(bc, TAK_ENCODER_CODEC_BITS);
+bitstream_skip(bc, TAK_ENCODER_PROFILE_BITS);
 
-frame_type = get_bits(gb, TAK_SIZE_FRAME_DURATION_BITS);
-s->samples = get_bits64(gb, TAK_SIZE_SAMPLES_NUM_BITS);
+frame_type = bitstream_read(bc, TAK_SIZE_FRAME_DURATION_BITS);
+s->samples = bitstream_read_63(bc, TAK_SIZE_SAMPLES_NUM_BITS);
 
-s->data_type   = get_bits(gb, TAK_FORMAT_DATA_TYPE_BITS);
-s->sample_rate = get_bits(gb, TAK_FORMAT_SAMPLE_RATE_BITS) +
+s->data_type   = bitstream_read(bc, TAK_FORMAT_DATA_TYPE_BITS);
+s->sample_rate = bitstream_read(bc, TAK_FORMAT_SAMPLE_RATE_BITS) +
  TAK_SAMPLE_RATE_MIN;
-s->bps = get_bits(gb, TAK_FORMAT_BPS_BITS) +
+s->bps = bitstream_read(bc, TAK_FORMAT_BPS_BITS) +
  TAK_BPS_MIN;
-s->channels= get_bits(gb, TAK_FORMAT_CHANNEL_BITS) +
+s->channels= bitstream_read(bc, TAK_FORMAT_CHANNEL_BITS) +
  TAK_CHANNELS_MIN;
 
-if (get_bits1(gb)) {
-skip_bits(gb, TAK_FORMAT_VALID_BITS);
-if (get_bits1(gb)) {
+if (bitstream_read_bit(bc)) {
+bitstream_skip(bc, TAK_FORMAT_VALID_BITS);
+if (bitstream_read_bit(bc)) {
 for (i = 0; i < s->channels; i++) {
-int value = get_bits(gb, TAK_FORMAT_CH_LAYOUT_BITS);
+int value = bitstream_read(bc, TAK_FORMAT_CH_LAYOUT_BITS);
 
 if (value > 0 && value <= 18)
 channel_mask |= 1 << (value - 1);
@@ -118,33 +119,33 @@ void avpriv_tak_parse_streaminfo(GetBitContext *gb, 
TAKStreamInfo *s)
 s->frame_samples = tak_get_nb_samples(s->sample_rate, frame_type);
 }
 
-int ff_tak_decode_frame_header(AVCodecContext *avctx, GetBitContext *gb,
+int ff_tak_decode_frame_header(AVCodecContext *avctx, BitstreamContext *bc,
TAKStreamInfo *ti, int log_level_offset)
 {
-if (get_bits(gb, TAK_FRAME_HEADER_SYNC_ID_BITS) != 
TAK_FRAME_HEADER_SYNC_ID) {
+if (bitstream_read(bc, TAK_FRAME_HEADER_SYNC_ID_BITS) != 
TAK_FRAME_HEADER_SYNC_ID) {
 av_log(avctx, AV_LOG_ERROR + log_level_offset, "missing sync id\n");
 return AVERROR_INVALIDDATA;
 }
 
-ti->flags = get_bits(gb, TAK_FRAME_HEADER_FLAGS_BITS);
-ti->frame_num = get_bits(gb, TAK_FRAME_HEADER_NO_BITS);
+ti->flags = bitstream_read(bc, TAK_FRAME_HEADER_FLAGS_BITS);
+ti->frame_num = bitstream_read(bc, TAK_FRAME_HEADER_NO_BITS);
 
 if (ti->flags & TAK_FRAME_FLAG_IS_LAST) {
-ti->last_frame_samples = get_bits(gb, 
TAK_FRAME_HEADER_SAMPLE_COUNT_BITS) + 1;
-skip_bits(gb, 2);
+ti->last_frame_samples = bitstream_read(bc, 
TAK_FRAME_HEADER_SAMPLE_COUNT_BITS) + 1;
+bitstream_skip(bc, 2);
 } else {
 ti->last_frame_samples = 0;
 }
 
 if (ti->flags & TAK_FRAME_FLAG_HAS_INFO) {
-avpriv_tak_parse_streaminfo(gb, ti);
+avpriv_tak_parse_streaminfo(bc, ti);
 
-if (get_bits(gb, 6))
-skip_bits(gb, 25);
-align_get_bits(gb);
+if (bitstream_read(bc, 6))
+bitstream_skip(bc, 25);
+bitstream_align(bc);
 }
 
-skip_bits(gb, 24);
+bitstream_skip(bc, 24);
 
 return 0;
 }
diff --git a/libavcodec/tak.h b/libavcodec/tak.h
index fa91149..c079561 100644
--- a/libavcodec/tak.h
+++ b/libavcodec/tak.h
@@ -30,8 +30,8 @@
 #include 
 
 #define BITSTREAM_READER_LE
-#include "get_bits.h"
 #include "avcodec.h"
+#include "bitstream.h"
 
 #define TAK_FORMAT_DATA_TYPE_BITS   3
 #define TAK_FORMAT_SAMPLE_RATE_BITS18
@@ -146,21 +146,21 @@ int ff_tak_check_crc(const uint8_t *buf, unsigned int 
buf_size);
 
 /**
  * Parse the Streaminfo metadata block.
- * @param[in]  gb pointer to GetBitContext
+ * @param[in]  bc pointer to BitstreamContext
  * @param[out] s  storage for parsed information
  */
-void avpriv_tak_parse_streaminfo(GetBitContext *gb, 

[libav-devel] [PATCH 10/38] wmv2dec: Convert to the new bitstream reader

2016-05-20 Thread Alexandra Hájková
---
 libavcodec/wmv2dec.c | 100 ++-
 1 file changed, 52 insertions(+), 48 deletions(-)

diff --git a/libavcodec/wmv2dec.c b/libavcodec/wmv2dec.c
index e1f86d8..7dc3688 100644
--- a/libavcodec/wmv2dec.c
+++ b/libavcodec/wmv2dec.c
@@ -19,6 +19,7 @@
  */
 
 #include "avcodec.h"
+#include "bitstream.h"
 #include "h263.h"
 #include "internal.h"
 #include "intrax8.h"
@@ -36,7 +37,7 @@ static void parse_mb_skip(Wmv2Context *w)
 MpegEncContext *const s = >s;
 uint32_t *const mb_type = s->current_picture_ptr->mb_type;
 
-w->skip_type = get_bits(>gb, 2);
+w->skip_type = bitstream_read(>bc, 2);
 switch (w->skip_type) {
 case SKIP_TYPE_NONE:
 for (mb_y = 0; mb_y < s->mb_height; mb_y++)
@@ -48,31 +49,34 @@ static void parse_mb_skip(Wmv2Context *w)
 for (mb_y = 0; mb_y < s->mb_height; mb_y++)
 for (mb_x = 0; mb_x < s->mb_width; mb_x++)
 mb_type[mb_y * s->mb_stride + mb_x] =
-(get_bits1(>gb) ? MB_TYPE_SKIP : 0) | MB_TYPE_16x16 | 
MB_TYPE_L0;
+(bitstream_read_bit(>bc) ? MB_TYPE_SKIP : 0) |
+MB_TYPE_16x16 | MB_TYPE_L0;
 break;
 case SKIP_TYPE_ROW:
 for (mb_y = 0; mb_y < s->mb_height; mb_y++) {
-if (get_bits1(>gb)) {
+if (bitstream_read_bit(>bc)) {
 for (mb_x = 0; mb_x < s->mb_width; mb_x++)
 mb_type[mb_y * s->mb_stride + mb_x] =
 MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_L0;
 } else {
 for (mb_x = 0; mb_x < s->mb_width; mb_x++)
 mb_type[mb_y * s->mb_stride + mb_x] =
-(get_bits1(>gb) ? MB_TYPE_SKIP : 0) | MB_TYPE_16x16 
| MB_TYPE_L0;
+(bitstream_read_bit(>bc) ? MB_TYPE_SKIP : 0) |
+MB_TYPE_16x16 | MB_TYPE_L0;
 }
 }
 break;
 case SKIP_TYPE_COL:
 for (mb_x = 0; mb_x < s->mb_width; mb_x++) {
-if (get_bits1(>gb)) {
+if (bitstream_read_bit(>bc)) {
 for (mb_y = 0; mb_y < s->mb_height; mb_y++)
 mb_type[mb_y * s->mb_stride + mb_x] =
 MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_L0;
 } else {
 for (mb_y = 0; mb_y < s->mb_height; mb_y++)
 mb_type[mb_y * s->mb_stride + mb_x] =
-(get_bits1(>gb) ? MB_TYPE_SKIP : 0) | MB_TYPE_16x16 
| MB_TYPE_L0;
+(bitstream_read_bit(>bc) ? MB_TYPE_SKIP : 0) |
+MB_TYPE_16x16 | MB_TYPE_L0;
 }
 }
 break;
@@ -82,24 +86,24 @@ static void parse_mb_skip(Wmv2Context *w)
 static int decode_ext_header(Wmv2Context *w)
 {
 MpegEncContext *const s = >s;
-GetBitContext gb;
+BitstreamContext bc;
 int fps;
 int code;
 
 if (s->avctx->extradata_size < 4)
 return AVERROR_INVALIDDATA;
 
-init_get_bits(, s->avctx->extradata, 32);
+bitstream_init(, s->avctx->extradata, 32);
 
-fps = get_bits(, 5);
-s->bit_rate = get_bits(, 11) * 1024;
-w->mspel_bit= get_bits1();
-s->loop_filter  = get_bits1();
-w->abt_flag = get_bits1();
-w->j_type_bit   = get_bits1();
-w->top_left_mv_flag = get_bits1();
-w->per_mb_rl_bit= get_bits1();
-code= get_bits(, 3);
+fps = bitstream_read(, 5);
+s->bit_rate = bitstream_read(, 11) * 1024;
+w->mspel_bit= bitstream_read_bit();
+s->loop_filter  = bitstream_read_bit();
+w->abt_flag = bitstream_read_bit();
+w->j_type_bit   = bitstream_read_bit();
+w->top_left_mv_flag = bitstream_read_bit();
+w->per_mb_rl_bit= bitstream_read_bit();
+code= bitstream_read(, 3);
 
 if (code == 0)
 return AVERROR_INVALIDDATA;
@@ -125,12 +129,12 @@ int ff_wmv2_decode_picture_header(MpegEncContext *s)
 if (s->picture_number == 0)
 decode_ext_header(w);
 
-s->pict_type = get_bits1(>gb) + 1;
+s->pict_type = bitstream_read_bit(>bc) + 1;
 if (s->pict_type == AV_PICTURE_TYPE_I) {
-code = get_bits(>gb, 7);
+code = bitstream_read(>bc, 7);
 av_log(s->avctx, AV_LOG_DEBUG, "I7:%X/\n", code);
 }
-s->chroma_qscale = s->qscale = get_bits(>gb, 5);
+s->chroma_qscale = s->qscale = bitstream_read(>bc, 5);
 if (s->qscale <= 0)
 return AVERROR_INVALIDDATA;
 
@@ -143,22 +147,22 @@ int 
ff_wmv2_decode_secondary_picture_header(MpegEncContext *s)
 
 if (s->pict_type == AV_PICTURE_TYPE_I) {
 if (w->j_type_bit)
-w->j_type = get_bits1(>gb);
+w->j_type = bitstream_read_bit(>bc);
 else
 w->j_type = 0; // FIXME check
 
 if (!w->j_type) {
 if (w->per_mb_rl_bit)
-s->per_mb_rl_table = 

[libav-devel] [PATCH 09/38] vc1: Convert to the new bitstream reader

2016-05-20 Thread Alexandra Hájková
---
 libavcodec/dxva2_vc1.c  |   3 +-
 libavcodec/vaapi_vc1.c  |   3 +-
 libavcodec/vc1.c| 448 
 libavcodec/vc1.h|  12 +-
 libavcodec/vc1_block.c  | 322 +++---
 libavcodec/vc1_parser.c |  15 +-
 libavcodec/vc1_pred.c   |  13 +-
 libavcodec/vc1data.h|   4 +-
 libavcodec/vc1dec.c | 127 +++---
 9 files changed, 502 insertions(+), 445 deletions(-)

diff --git a/libavcodec/dxva2_vc1.c b/libavcodec/dxva2_vc1.c
index d170e18..cbfca24 100644
--- a/libavcodec/dxva2_vc1.c
+++ b/libavcodec/dxva2_vc1.c
@@ -20,6 +20,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "bitstream.h"
 #include "mpegutils.h"
 #include "vc1.h"
 #include "vc1data.h"
@@ -154,7 +155,7 @@ static void fill_slice(AVCodecContext *avctx, 
DXVA_SliceInfo *slice,
 slice->dwSliceDataLocation = position;
 slice->bStartCodeBitOffset = 0;
 slice->bReservedBits   = 0;
-slice->wMBbitOffset= get_bits_count(>gb);
+slice->wMBbitOffset= bitstream_tell(>bc);
 slice->wNumberMBsInSlice   = s->mb_width * s->mb_height; /* XXX We assume 
1 slice */
 slice->wQuantizerScaleCode = v->pq;
 slice->wBadSliceChopping   = 0;
diff --git a/libavcodec/vaapi_vc1.c b/libavcodec/vaapi_vc1.c
index 4022549..7c84284 100644
--- a/libavcodec/vaapi_vc1.c
+++ b/libavcodec/vaapi_vc1.c
@@ -20,6 +20,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "bitstream.h"
 #include "vaapi_internal.h"
 #include "internal.h"
 #include "vc1.h"
@@ -325,7 +326,7 @@ static int vaapi_vc1_decode_slice(AVCodecContext *avctx, 
const uint8_t *buffer,
 slice_param = (VASliceParameterBufferVC1 
*)ff_vaapi_alloc_slice(avctx->hwaccel_context, buffer, size);
 if (!slice_param)
 return -1;
-slice_param->macroblock_offset   = get_bits_count(>gb);
+slice_param->macroblock_offset   = bitstream_tell(>bc);
 slice_param->slice_vertical_position = s->mb_y;
 return 0;
 }
diff --git a/libavcodec/vc1.c b/libavcodec/vc1.c
index 7a93e97..a57cc6f 100644
--- a/libavcodec/vc1.c
+++ b/libavcodec/vc1.c
@@ -29,12 +29,14 @@
 #include "libavutil/attributes.h"
 #include "internal.h"
 #include "avcodec.h"
+#include "bitstream.h"
 #include "mpegvideo.h"
 #include "vc1.h"
 #include "vc1data.h"
 #include "wmv2data.h"
 #include "unary.h"
 #include "simple_idct.h"
+#include "vlc.h"
 
 /***/
 /**
@@ -65,16 +67,16 @@ enum Imode {
  * @param[in] stride of this buffer
  */
 static void decode_rowskip(uint8_t* plane, int width, int height, int stride,
-   GetBitContext *gb)
+   BitstreamContext *bc)
 {
 int x, y;
 
 for (y = 0; y < height; y++) {
-if (!get_bits1(gb)) //rowskip
+if (!bitstream_read_bit(bc)) //rowskip
 memset(plane, 0, width);
 else
 for (x = 0; x < width; x++)
-plane[x] = get_bits1(gb);
+plane[x] = bitstream_read_bit(bc);
 plane += stride;
 }
 }
@@ -87,17 +89,17 @@ static void decode_rowskip(uint8_t* plane, int width, int 
height, int stride,
  * @todo FIXME: Optimize
  */
 static void decode_colskip(uint8_t* plane, int width, int height, int stride,
-   GetBitContext *gb)
+   BitstreamContext *bc)
 {
 int x, y;
 
 for (x = 0; x < width; x++) {
-if (!get_bits1(gb)) //colskip
+if (!bitstream_read_bit(bc)) //colskip
 for (y = 0; y < height; y++)
 plane[y*stride] = 0;
 else
 for (y = 0; y < height; y++)
-plane[y*stride] = get_bits1(gb);
+plane[y*stride] = bitstream_read_bit(bc);
 plane ++;
 }
 }
@@ -111,7 +113,7 @@ static void decode_colskip(uint8_t* plane, int width, int 
height, int stride,
  */
 static int bitplane_decoding(uint8_t* data, int *raw_flag, VC1Context *v)
 {
-GetBitContext *gb = >s.gb;
+BitstreamContext *bc = >s.bc;
 
 int imode, x, y, code, offset;
 uint8_t invert, *planep = data;
@@ -120,8 +122,8 @@ static int bitplane_decoding(uint8_t* data, int *raw_flag, 
VC1Context *v)
 width  = v->s.mb_width;
 height = v->s.mb_height >> v->field_mode;
 stride = v->s.mb_stride;
-invert = get_bits1(gb);
-imode = get_vlc2(gb, ff_vc1_imode_vlc.table, VC1_IMODE_VLC_BITS, 1);
+invert = bitstream_read_bit(bc);
+imode = bitstream_read_vlc(bc, ff_vc1_imode_vlc.table, VC1_IMODE_VLC_BITS, 
1);
 
 *raw_flag = 0;
 switch (imode) {
@@ -132,14 +134,14 @@ static int bitplane_decoding(uint8_t* data, int 
*raw_flag, VC1Context *v)
 case IMODE_DIFF2:
 case IMODE_NORM2:
 if ((height * width) & 1) {
-*planep++ = get_bits1(gb);
+*planep++ = bitstream_read_bit(bc);
 offset= 

[libav-devel] [PATCH 13/38] aic: Convert to the new bitstream reader

2016-05-20 Thread Alexandra Hájková
---
 libavcodec/aic.c | 36 ++--
 1 file changed, 18 insertions(+), 18 deletions(-)

diff --git a/libavcodec/aic.c b/libavcodec/aic.c
index 9ea27a7..b236aff 100644
--- a/libavcodec/aic.c
+++ b/libavcodec/aic.c
@@ -23,9 +23,9 @@
 #include 
 
 #include "avcodec.h"
+#include "bitstream.h"
 #include "bytestream.h"
 #include "internal.h"
-#include "get_bits.h"
 #include "golomb.h"
 #include "idctdsp.h"
 #include "unary.h"
@@ -187,17 +187,17 @@ static int aic_decode_header(AICContext *ctx, const 
uint8_t *src, int size)
 return 0;
 }
 
-#define GET_CODE(val, type, add_bits) \
-do {  \
-if (type) \
-val = get_ue_golomb(gb);  \
-else  \
-val = get_unary(gb, 1, 31);   \
-if (add_bits) \
-val = (val << add_bits) + get_bits(gb, add_bits); \
+#define GET_CODE(val, type, add_bits)  \
+do {   \
+if (type)  \
+val = get_ue_golomb(bc);   \
+else   \
+val = get_unary(bc, 1, 31);\
+if (add_bits)  \
+val = (val << add_bits) + bitstream_read(bc, add_bits);\
 } while (0)
 
-static int aic_decode_coeffs(GetBitContext *gb, int16_t *dst,
+static int aic_decode_coeffs(BitstreamContext *bc, int16_t *dst,
  int band, int slice_width, int force_chroma)
 {
 int has_skips, coeff_type, coeff_bits, skip_type, skip_bits;
@@ -205,13 +205,13 @@ static int aic_decode_coeffs(GetBitContext *gb, int16_t 
*dst,
 const uint8_t *scan = aic_scan[band | force_chroma];
 int mb, idx, val;
 
-has_skips  = get_bits1(gb);
-coeff_type = get_bits1(gb);
-coeff_bits = get_bits(gb, 3);
+has_skips  = bitstream_read_bit(bc);
+coeff_type = bitstream_read_bit(bc);
+coeff_bits = bitstream_read(bc, 3);
 
 if (has_skips) {
-skip_type = get_bits1(gb);
-skip_bits = get_bits(gb, 3);
+skip_type = bitstream_read_bit(bc);
+skip_bits = bitstream_read(bc, 3);
 
 for (mb = 0; mb < slice_width; mb++) {
 idx = -1;
@@ -302,7 +302,7 @@ static void unquant_block(int16_t *block, int q)
 static int aic_decode_slice(AICContext *ctx, int mb_x, int mb_y,
 const uint8_t *src, int src_size)
 {
-GetBitContext gb;
+BitstreamContext bc;
 int ret, i, mb, blk;
 int slice_width = FFMIN(ctx->slice_width, ctx->mb_width - mb_x);
 uint8_t *Y, *C[2];
@@ -317,12 +317,12 @@ static int aic_decode_slice(AICContext *ctx, int mb_x, 
int mb_y,
 for (i = 0; i < 2; i++)
 C[i] = ctx->frame->data[i + 1] + mb_x * 8
+ mb_y * 8 * ctx->frame->linesize[i + 1];
-init_get_bits(, src, src_size * 8);
+bitstream_init8(, src, src_size);
 
 memset(ctx->slice_data, 0,
sizeof(*ctx->slice_data) * slice_width * AIC_BAND_COEFFS);
 for (i = 0; i < NUM_BANDS; i++)
-if ((ret = aic_decode_coeffs(, ctx->data_ptr[i],
+if ((ret = aic_decode_coeffs(, ctx->data_ptr[i],
  i, slice_width,
  !ctx->interlaced)) < 0)
 return ret;
-- 
2.1.4

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH 08/38] msmpeg4: Convert to the new bitstream reader

2016-05-20 Thread Alexandra Hájková
---
 libavcodec/msmpeg4data.h |   3 +-
 libavcodec/msmpeg4dec.c  | 195 +--
 2 files changed, 104 insertions(+), 94 deletions(-)

diff --git a/libavcodec/msmpeg4data.h b/libavcodec/msmpeg4data.h
index 9d57d41..028f776 100644
--- a/libavcodec/msmpeg4data.h
+++ b/libavcodec/msmpeg4data.h
@@ -31,8 +31,9 @@
 #define AVCODEC_MSMPEG4DATA_H
 
 #include "libavutil/common.h"
-#include "get_bits.h"
+#include "bitstream.h"
 #include "rl.h"
+#include "vlc.h"
 
 /* motion vector table */
 typedef struct MVTable {
diff --git a/libavcodec/msmpeg4dec.c b/libavcodec/msmpeg4dec.c
index 1c8..f2c8fdc 100644
--- a/libavcodec/msmpeg4dec.c
+++ b/libavcodec/msmpeg4dec.c
@@ -23,6 +23,7 @@
  */
 
 #include "avcodec.h"
+#include "bitstream.h"
 #include "internal.h"
 #include "mpegutils.h"
 #include "mpegvideo.h"
@@ -32,6 +33,7 @@
 #include "mpeg4video.h"
 #include "msmpeg4data.h"
 #include "vc1data.h"
+#include "vlc.h"
 #include "wmv2.h"
 
 #define DC_VLC_BITS 9
@@ -74,19 +76,19 @@ static int msmpeg4v2_decode_motion(MpegEncContext * s, int 
pred, int f_code)
 {
 int code, val, sign, shift;
 
-code = get_vlc2(>gb, v2_mv_vlc.table, V2_MV_VLC_BITS, 2);
+code = bitstream_read_vlc(>bc, v2_mv_vlc.table, V2_MV_VLC_BITS, 2);
 ff_dlog(s, "MV code %d at %d %d pred: %d\n", code, s->mb_x,s->mb_y, pred);
 if (code < 0)
 return 0x;
 
 if (code == 0)
 return pred;
-sign = get_bits1(>gb);
+sign = bitstream_read_bit(>bc);
 shift = f_code - 1;
 val = code;
 if (shift) {
 val = (val - 1) << shift;
-val |= get_bits(>gb, shift);
+val |= bitstream_read(>bc, shift);
 val++;
 }
 if (sign)
@@ -107,7 +109,7 @@ static int msmpeg4v12_decode_mb(MpegEncContext *s, int16_t 
block[6][64])
 
 if (s->pict_type == AV_PICTURE_TYPE_P) {
 if (s->use_skip_mb_code) {
-if (get_bits1(>gb)) {
+if (bitstream_read_bit(>bc)) {
 /* skip mb */
 s->mb_intra = 0;
 for(i=0;i<6;i++)
@@ -122,9 +124,11 @@ static int msmpeg4v12_decode_mb(MpegEncContext *s, int16_t 
block[6][64])
 }
 
 if(s->msmpeg4_version==2)
-code = get_vlc2(>gb, v2_mb_type_vlc.table, V2_MB_TYPE_VLC_BITS, 
1);
+code = bitstream_read_vlc(>bc, v2_mb_type_vlc.table,
+  V2_MB_TYPE_VLC_BITS, 1);
 else
-code = get_vlc2(>gb, ff_h263_inter_MCBPC_vlc.table, 
INTER_MCBPC_VLC_BITS, 2);
+code = bitstream_read_vlc(>bc, ff_h263_inter_MCBPC_vlc.table,
+  INTER_MCBPC_VLC_BITS, 2);
 if(code<0 || code>7){
 av_log(s->avctx, AV_LOG_ERROR, "cbpc %d invalid at %d %d\n", code, 
s->mb_x, s->mb_y);
 return -1;
@@ -136,9 +140,11 @@ static int msmpeg4v12_decode_mb(MpegEncContext *s, int16_t 
block[6][64])
 } else {
 s->mb_intra = 1;
 if(s->msmpeg4_version==2)
-cbp= get_vlc2(>gb, v2_intra_cbpc_vlc.table, 
V2_INTRA_CBPC_VLC_BITS, 1);
+cbp= bitstream_read_vlc(>bc, v2_intra_cbpc_vlc.table,
+V2_INTRA_CBPC_VLC_BITS, 1);
 else
-cbp= get_vlc2(>gb, ff_h263_intra_MCBPC_vlc.table, 
INTRA_MCBPC_VLC_BITS, 1);
+cbp= bitstream_read_vlc(>bc, ff_h263_intra_MCBPC_vlc.table,
+INTRA_MCBPC_VLC_BITS, 1);
 if(cbp<0 || cbp>3){
 av_log(s->avctx, AV_LOG_ERROR, "cbpc %d invalid at %d %d\n", cbp, 
s->mb_x, s->mb_y);
 return -1;
@@ -148,7 +154,7 @@ static int msmpeg4v12_decode_mb(MpegEncContext *s, int16_t 
block[6][64])
 if (!s->mb_intra) {
 int mx, my, cbpy;
 
-cbpy= get_vlc2(>gb, ff_h263_cbpy_vlc.table, CBPY_VLC_BITS, 1);
+cbpy= bitstream_read_vlc(>bc, ff_h263_cbpy_vlc.table, 
CBPY_VLC_BITS, 1);
 if(cbpy<0){
 av_log(s->avctx, AV_LOG_ERROR, "cbpy %d invalid at %d %d\n", cbp, 
s->mb_x, s->mb_y);
 return -1;
@@ -167,11 +173,13 @@ static int msmpeg4v12_decode_mb(MpegEncContext *s, 
int16_t block[6][64])
 s->mv[0][0][1] = my;
 } else {
 if(s->msmpeg4_version==2){
-s->ac_pred = get_bits1(>gb);
-cbp|= get_vlc2(>gb, ff_h263_cbpy_vlc.table, CBPY_VLC_BITS, 
1)<<2; //FIXME check errors
+s->ac_pred = bitstream_read_bit(>bc);
+cbp|= bitstream_read_vlc(>bc, ff_h263_cbpy_vlc.table,
+ CBPY_VLC_BITS, 1) << 2; //FIXME check 
errors
 } else{
 s->ac_pred = 0;
-cbp|= get_vlc2(>gb, ff_h263_cbpy_vlc.table, CBPY_VLC_BITS, 
1)<<2; //FIXME check errors
+cbp|= bitstream_read_vlc(>bc, ff_h263_cbpy_vlc.table,
+ CBPY_VLC_BITS, 1) << 2; //FIXME check 
errors
 if(s->pict_type==AV_PICTURE_TYPE_P) cbp^=0x3C;
 }
 }
@@ -195,7 +203,7 @@ static int 

[libav-devel] [PATCH 17/38] dxtory: Convert to the new bitstream reader

2016-05-20 Thread Alexandra Hájková
---
 libavcodec/dxtory.c | 86 ++---
 1 file changed, 43 insertions(+), 43 deletions(-)

diff --git a/libavcodec/dxtory.c b/libavcodec/dxtory.c
index 01726b9..33da703 100644
--- a/libavcodec/dxtory.c
+++ b/libavcodec/dxtory.c
@@ -24,8 +24,8 @@
 
 #define BITSTREAM_READER_LE
 #include "avcodec.h"
+#include "bitstream.h"
 #include "bytestream.h"
-#include "get_bits.h"
 #include "internal.h"
 #include "unary.h"
 #include "libavutil/common.h"
@@ -175,13 +175,13 @@ static const uint8_t def_lru[8] = { 0x00, 0x20, 0x40, 
0x60, 0x80, 0xA0, 0xC0, 0x
 static const uint8_t def_lru_555[8] = { 0x00, 0x08, 0x10, 0x18, 0x1F };
 static const uint8_t def_lru_565[8] = { 0x00, 0x08, 0x10, 0x20, 0x30, 0x3F };
 
-static inline uint8_t decode_sym(GetBitContext *gb, uint8_t lru[8])
+static inline uint8_t decode_sym(BitstreamContext *bc, uint8_t lru[8])
 {
 uint8_t c, val;
 
-c = get_unary(gb, 0, 8);
+c = get_unary(bc, 0, 8);
 if (!c) {
-val = get_bits(gb, 8);
+val = bitstream_read(bc, 8);
 memmove(lru + 1, lru, sizeof(*lru) * (8 - 1));
 } else {
 val = lru[c - 1];
@@ -242,14 +242,14 @@ static int load_buffer(AVCodecContext *avctx,
 return 0;
 }
 
-static inline uint8_t decode_sym_565(GetBitContext *gb, uint8_t lru[8],
+static inline uint8_t decode_sym_565(BitstreamContext *bc, uint8_t lru[8],
  int bits)
 {
 uint8_t c, val;
 
-c = get_unary(gb, 0, bits);
+c = get_unary(bc, 0, bits);
 if (!c) {
-val = get_bits(gb, bits);
+val = bitstream_read(bc, bits);
 memmove(lru + 1, lru, sizeof(*lru) * (6 - 1));
 } else {
 val = lru[c - 1];
@@ -260,7 +260,7 @@ static inline uint8_t decode_sym_565(GetBitContext *gb, 
uint8_t lru[8],
 return val;
 }
 
-typedef int (*decode_slice_func)(GetBitContext *gb, AVFrame *frame,
+typedef int (*decode_slice_func)(BitstreamContext *bc, AVFrame *frame,
  int line, int height, uint8_t lru[3][8]);
 
 typedef void (*setup_lru_func)(uint8_t lru[3][8]);
@@ -272,7 +272,7 @@ static int dxtory_decode_v2(AVCodecContext *avctx, AVFrame 
*pic,
 enum AVPixelFormat fmt)
 {
 GetByteContext gb;
-GetBitContext  gb2;
+BitstreamContext  bc;
 int nslices, slice, line = 0;
 uint32_t off, slice_size;
 uint8_t lru[3][8];
@@ -295,9 +295,9 @@ static int dxtory_decode_v2(AVCodecContext *avctx, AVFrame 
*pic,
 if (ret < 0)
 return ret;
 
-init_get_bits(, src + off + 16, (slice_size - 16) * 8);
+bitstream_init8(, src + off + 16, (slice_size - 16));
 
-line += decode_slice(, pic, line, avctx->height - line, lru);
+line += decode_slice(, pic, line, avctx->height - line, lru);
 
 off += slice_size;
 }
@@ -314,7 +314,7 @@ static int dxtory_decode_v2(AVCodecContext *avctx, AVFrame 
*pic,
 }
 
 av_always_inline
-static int dx2_decode_slice_5x5(GetBitContext *gb, AVFrame *frame,
+static int dx2_decode_slice_5x5(BitstreamContext *bc, AVFrame *frame,
 int line, int left, uint8_t lru[3][8],
 int is_565)
 {
@@ -324,11 +324,11 @@ static int dx2_decode_slice_5x5(GetBitContext *gb, 
AVFrame *frame,
 int stride   = frame->linesize[0];
 uint8_t *dst = frame->data[0] + stride * line;
 
-for (y = 0; y < left && get_bits_left(gb) > 16; y++) {
+for (y = 0; y < left && bitstream_bits_left(bc) > 16; y++) {
 for (x = 0; x < width; x++) {
-b = decode_sym_565(gb, lru[0], 5);
-g = decode_sym_565(gb, lru[1], is_565 ? 6 : 5);
-r = decode_sym_565(gb, lru[2], 5);
+b = decode_sym_565(bc, lru[0], 5);
+g = decode_sym_565(bc, lru[1], is_565 ? 6 : 5);
+r = decode_sym_565(bc, lru[2], 5);
 dst[x * 3 + 0] = (r << 3) | (r >> 2);
 dst[x * 3 + 1] = is_565 ? (g << 2) | (g >> 4) : (g << 3) | (g >> 
2);
 dst[x * 3 + 2] = (b << 3) | (b >> 2);
@@ -354,16 +354,16 @@ static void setup_lru_565(uint8_t lru[3][8])
 memcpy(lru[2], def_lru_555, 8 * sizeof(*def_lru));
 }
 
-static int dx2_decode_slice_555(GetBitContext *gb, AVFrame *frame,
+static int dx2_decode_slice_555(BitstreamContext *bc, AVFrame *frame,
 int line, int left, uint8_t lru[3][8])
 {
-return dx2_decode_slice_5x5(gb, frame, line, left, lru, 0);
+return dx2_decode_slice_5x5(bc, frame, line, left, lru, 0);
 }
 
-static int dx2_decode_slice_565(GetBitContext *gb, AVFrame *frame,
+static int dx2_decode_slice_565(BitstreamContext *bc, AVFrame *frame,
 int line, int left, uint8_t lru[3][8])
 {
-return dx2_decode_slice_5x5(gb, frame, line, left, lru, 1);
+return dx2_decode_slice_5x5(bc, frame, line, left, lru, 1);
 }
 
 static int dxtory_decode_v2_565(AVCodecContext *avctx, AVFrame *pic,
@@ -382,7 +382,7 @@ static 

[libav-devel] [PATCH 16/38] ralf: Convert to the new bitstream reader

2016-05-20 Thread Alexandra Hájková
---
 libavcodec/ralf.c | 63 ---
 1 file changed, 32 insertions(+), 31 deletions(-)

diff --git a/libavcodec/ralf.c b/libavcodec/ralf.c
index bed5adf..517a5e4 100644
--- a/libavcodec/ralf.c
+++ b/libavcodec/ralf.c
@@ -29,11 +29,12 @@
 #include "libavutil/attributes.h"
 #include "libavutil/channel_layout.h"
 #include "avcodec.h"
-#include "get_bits.h"
+#include "bitstream.h"
 #include "golomb.h"
 #include "internal.h"
 #include "unary.h"
 #include "ralfdata.h"
+#include "vlc.h"
 
 #define FILTER_NONE 0
 #define FILTER_RAW  642
@@ -210,21 +211,21 @@ static av_cold int decode_init(AVCodecContext *avctx)
 return 0;
 }
 
-static inline int extend_code(GetBitContext *gb, int val, int range, int bits)
+static inline int extend_code(BitstreamContext *bc, int val, int range, int 
bits)
 {
 if (val == 0) {
-val = -range - get_ue_golomb(gb);
+val = -range - get_ue_golomb(bc);
 } else if (val == range * 2) {
-val =  range + get_ue_golomb(gb);
+val =  range + get_ue_golomb(bc);
 } else {
 val -= range;
 }
 if (bits)
-val = (val << bits) | get_bits(gb, bits);
+val = (val << bits) | bitstream_read(bc, bits);
 return val;
 }
 
-static int decode_channel(RALFContext *ctx, GetBitContext *gb, int ch,
+static int decode_channel(RALFContext *ctx, BitstreamContext *bc, int ch,
   int length, int mode, int bits)
 {
 int i, t;
@@ -233,19 +234,19 @@ static int decode_channel(RALFContext *ctx, GetBitContext 
*gb, int ch,
 VLC *code_vlc; int range, range2, add_bits;
 int *dst = ctx->channel_data[ch];
 
-ctx->filter_params = get_vlc2(gb, set->filter_params.table, 9, 2);
+ctx->filter_params = bitstream_read_vlc(bc, set->filter_params.table, 9, 
2);
 ctx->filter_bits   = (ctx->filter_params - 2) >> 6;
 ctx->filter_length = ctx->filter_params - (ctx->filter_bits << 6) - 1;
 
 if (ctx->filter_params == FILTER_RAW) {
 for (i = 0; i < length; i++)
-dst[i] = get_bits(gb, bits);
+dst[i] = bitstream_read(bc, bits);
 ctx->bias[ch] = 0;
 return 0;
 }
 
-ctx->bias[ch] = get_vlc2(gb, set->bias.table, 9, 2);
-ctx->bias[ch] = extend_code(gb, ctx->bias[ch], 127, 4);
+ctx->bias[ch] = bitstream_read_vlc(bc, set->bias.table, 9, 2);
+ctx->bias[ch] = extend_code(bc, ctx->bias[ch], 127, 4);
 
 if (ctx->filter_params == FILTER_NONE) {
 memset(dst, 0, sizeof(*dst) * length);
@@ -259,8 +260,8 @@ static int decode_channel(RALFContext *ctx, GetBitContext 
*gb, int ch,
 add_bits = ctx->filter_bits;
 
 for (i = 0; i < ctx->filter_length; i++) {
-t = get_vlc2(gb, vlc[cmode].table, vlc[cmode].bits, 2);
-t = extend_code(gb, t, 21, add_bits);
+t = bitstream_read_vlc(bc, vlc[cmode].table, vlc[cmode].bits, 2);
+t = extend_code(bc, t, 21, add_bits);
 if (!cmode)
 coeff -= 12 << add_bits;
 coeff = t - coeff;
@@ -279,7 +280,7 @@ static int decode_channel(RALFContext *ctx, GetBitContext 
*gb, int ch,
 }
 }
 
-code_params = get_vlc2(gb, set->coding_mode.table, set->coding_mode.bits, 
2);
+code_params = bitstream_read_vlc(bc, set->coding_mode.table, 
set->coding_mode.bits, 2);
 if (code_params >= 15) {
 add_bits = av_clip((code_params / 5 - 3) / 2, 0, 10);
 if (add_bits > 9 && (code_params % 5) != 2)
@@ -297,14 +298,14 @@ static int decode_channel(RALFContext *ctx, GetBitContext 
*gb, int ch,
 for (i = 0; i < length; i += 2) {
 int code1, code2;
 
-t = get_vlc2(gb, code_vlc->table, code_vlc->bits, 2);
+t = bitstream_read_vlc(bc, code_vlc->table, code_vlc->bits, 2);
 code1 = t / range2;
 code2 = t % range2;
-dst[i] = extend_code(gb, code1, range, 0) << add_bits;
-dst[i + 1] = extend_code(gb, code2, range, 0) << add_bits;
+dst[i] = extend_code(bc, code1, range, 0) << add_bits;
+dst[i + 1] = extend_code(bc, code2, range, 0) << add_bits;
 if (add_bits) {
-dst[i] |= get_bits(gb, add_bits);
-dst[i + 1] |= get_bits(gb, add_bits);
+dst[i] |= bitstream_read(bc, add_bits);
+dst[i + 1] |= bitstream_read(bc, add_bits);
 }
 }
 
@@ -335,7 +336,7 @@ static void apply_lpc(RALFContext *ctx, int ch, int length, 
int bits)
 }
 }
 
-static int decode_block(AVCodecContext *avctx, GetBitContext *gb,
+static int decode_block(AVCodecContext *avctx, BitstreamContext *bc,
 int16_t *dst0, int16_t *dst1)
 {
 RALFContext *ctx = avctx->priv_data;
@@ -344,7 +345,7 @@ static int decode_block(AVCodecContext *avctx, 
GetBitContext *gb,
 int *ch0, *ch1;
 int i, t, t2;
 
-len = 12 - get_unary(gb, 0, 6);
+len = 12 - get_unary(bc, 0, 6);
 
 if (len <= 7) len ^= 1; // codes for length = 6 and 7 

[libav-devel] [PATCH 00/38] Convert to the new bitstream reader, set 3

2016-05-20 Thread Alexandra Hájková
This set is compilable together only.

Alexandra Hájková (38):
  h261dec: Convert to the new bitstream reader
  flv: Convert to the new bitstream reader
  mpeg4video: Convert to the new bitstream reader
  h263dec: Convert to the new bitstream reader
  intrax8: Convert to the new bitstream reader
  ituh263dec: Convert to the new bitstream reader
  mss1, mss2, mss4: Convert to the new bitstream reader
  msmpeg4: Convert to the new bitstream reader
  vc1: Convert to the new bitstream reader
  wmv2dec: Convert to the new bitstream reader
  rv10, rv30, rv40: Convert to the new bitstream reader
  unary.h: Convert to the new bitstream reader
  aic: Convert to the new bitstream reader
  wavpack: Convert to the new bitstream reader
  tak: Convert to the new bitstream reader
  ralf: Convert to the new bitstream reader
  dxtory: Convert to the new bitstream reader
  dca: Convert to the new bitstream reader
  apedec: Convert to the new bitstream reader
  alsdec, bgmc: Convert to the new bitstream reader
  mpc8 (demuxer): Convert to the new bitstream reader
  golomb: Convert to the new bitstream reader
  golomb.h: Optimise get_ue/se_golomb
  golomb.h: Optimise svq3_get_ue_golomb
  h264: Convert to the new bitstream reader
  on2avc: Convert to the new bitstream reader
  svq3: Convert to the new bitstream reader
  cavsdec: Convert to the new bitstream reader
  dirac: Convert to the new bitstream reader
  ffv1dec: Convert to the new bitstream reader
  fic: Convert to the new bitstream reader
  flac: Convert to the new bitstream reader
  jpeglsdec, mjpegdec: Convert to the new bitstream reader
  loco: Convert to the new bitstream reader
  shorten: Convert to the new bitstream reader
  hevc: Convert to the new bitstream reader
  mxpegdec: Convert to the new bitstream reader
  alac: Convert to the new bitstream reader

 libavcodec/aic.c   |  36 +--
 libavcodec/alac.c  |  62 ++---
 libavcodec/alsdec.c| 228 +++
 libavcodec/apedec.c|  44 +--
 libavcodec/bgmc.c  |  15 +-
 libavcodec/bgmc.h  |   8 +-
 libavcodec/cavs.c  |   6 +-
 libavcodec/cavs.h  |   4 +-
 libavcodec/cavsdec.c   | 176 ++--
 libavcodec/dca.h   |   6 +-
 libavcodec/dca_exss.c  | 166 +--
 libavcodec/dca_parser.c|  16 +-
 libavcodec/dca_xll.c   | 158 +--
 libavcodec/dcadec.c| 219 +++
 libavcodec/dirac.c |  87 +++---
 libavcodec/dxtory.c|  86 +++---
 libavcodec/dxva2_vc1.c |   3 +-
 libavcodec/ffv1.c  |   2 +-
 libavcodec/ffv1.h  |   4 +-
 libavcodec/ffv1dec.c   |  22 +-
 libavcodec/fic.c   |  16 +-
 libavcodec/flac.c  |  67 ++---
 libavcodec/flac.h  |   6 +-
 libavcodec/flac_parser.c   |   6 +-
 libavcodec/flacdec.c   |  56 ++--
 libavcodec/flacenc.c   |   1 -
 libavcodec/flv.h   |   4 +-
 libavcodec/flvdec.c|  39 +--
 libavcodec/golomb.h| 236 +++-
 libavcodec/h261dec.c   |  90 +++---
 libavcodec/h263.h  |   3 +-
 libavcodec/h263dec.c   |  54 ++--
 libavcodec/h264.c  |  15 +-
 libavcodec/h264.h  |  13 +-
 libavcodec/h2645_parse.c   |  21 +-
 libavcodec/h2645_parse.h   |   4 +-
 libavcodec/h264_cabac.c|   2 +
 libavcodec/h264_cavlc.c| 167 +--
 libavcodec/h264_mb_template.c  |  16 +-
 libavcodec/h264_parse.c|  32 +--
 libavcodec/h264_parse.h|   6 +-
 libavcodec/h264_parser.c   |  64 ++---
 libavcodec/h264_ps.c   | 260 -
 libavcodec/h264_refs.c |  23 +-
 libavcodec/h264_sei.c  | 192 ++---
 libavcodec/h264_sei.h  |   4 +-
 libavcodec/h264_slice.c|  68 ++---
 libavcodec/hevc.c  | 164 +--
 libavcodec/hevc.h  |  14 +-
 libavcodec/hevc_cabac.c|  11 +-
 libavcodec/hevc_parser.c   |  14 +-
 libavcodec/hevc_ps.c   | 455 +++---
 libavcodec/hevc_sei.c  |  69 ++---
 libavcodec/hevcdsp.h   |   4 +-
 libavcodec/hevcdsp_template.c  |   6 +-
 libavcodec/intelh263dec.c  |  69 ++---
 libavcodec/intrax8.c   |  37 +--
 libavcodec/intrax8.h   |   7 +-
 libavcodec/ituh263dec.c| 327 +++---
 libavcodec/jpeglsdec.c |  46 +--
 libavcodec/loco.c  |  12 +-
 libavcodec/mjpegbdec.c |  41 +--
 libavcodec/mjpegdec.c  | 266 --
 libavcodec/mjpegdec.h  |   5 +-
 libavcodec/mpeg4video.h|   4 +-
 libavcodec/mpeg4video_parser.c |  11 +-
 libavcodec/mpeg4videodec.c | 620 -
 libavcodec/mpegvideo.h |   4 +-
 libavcodec/msmpeg4data.h   |   3 +-
 libavcodec/msmpeg4dec.c| 195 ++---
 libavcodec/mss1.c  

[libav-devel] [PATCH 14/38] wavpack: Convert to the new bitstream reader

2016-05-20 Thread Alexandra Hájková
---
 libavcodec/wavpack.c | 90 ++--
 1 file changed, 45 insertions(+), 45 deletions(-)

diff --git a/libavcodec/wavpack.c b/libavcodec/wavpack.c
index ab9dec9..ff4ae08 100644
--- a/libavcodec/wavpack.c
+++ b/libavcodec/wavpack.c
@@ -23,7 +23,7 @@
 
 #include "libavutil/channel_layout.h"
 #include "avcodec.h"
-#include "get_bits.h"
+#include "bitstream.h"
 #include "internal.h"
 #include "unary.h"
 #include "bytestream.h"
@@ -109,10 +109,10 @@ typedef struct WavpackFrameContext {
 int stereo, stereo_in;
 int joint;
 uint32_t CRC;
-GetBitContext gb;
+BitstreamContext bc;
 int got_extra_bits;
 uint32_t crc_extra_bits;
-GetBitContext gb_extra_bits;
+BitstreamContext bc_extra_bits;
 int data_size; // in bits
 int samples;
 int terms;
@@ -240,7 +240,7 @@ static av_always_inline int wp_log2(int32_t val)
 } \
 }
 
-static av_always_inline int get_tail(GetBitContext *gb, int k)
+static av_always_inline int get_tail(BitstreamContext *bc, int k)
 {
 int p, e, res;
 
@@ -248,9 +248,9 @@ static av_always_inline int get_tail(GetBitContext *gb, int 
k)
 return 0;
 p   = av_log2(k);
 e   = (1 << (p + 1)) - k - 1;
-res = get_bitsz(gb, p);
+res = bitstream_read(bc, p);
 if (res >= e)
-res = (res << 1) - e + get_bits1(gb);
+res = (res << 1) - e + bitstream_read_bit(bc);
 return res;
 }
 
@@ -288,7 +288,7 @@ static void update_error_limit(WavpackFrameContext *ctx)
 }
 }
 
-static int wv_get_value(WavpackFrameContext *ctx, GetBitContext *gb,
+static int wv_get_value(WavpackFrameContext *ctx, BitstreamContext *bc,
 int channel, int *last)
 {
 int t, t2;
@@ -306,13 +306,13 @@ static int wv_get_value(WavpackFrameContext *ctx, 
GetBitContext *gb,
 return 0;
 }
 } else {
-t = get_unary_0_33(gb);
+t = get_unary_0_33(bc);
 if (t >= 2) {
-if (get_bits_left(gb) < t - 1)
+if (bitstream_bits_left(bc) < t - 1)
 goto error;
-t = get_bits(gb, t - 1) | (1 << (t - 1));
+t = bitstream_read(bc, t - 1) | (1 << (t - 1));
 } else {
-if (get_bits_left(gb) < 0)
+if (bitstream_bits_left(bc) < 0)
 goto error;
 }
 ctx->zeroes = t;
@@ -329,19 +329,19 @@ static int wv_get_value(WavpackFrameContext *ctx, 
GetBitContext *gb,
 t = 0;
 ctx->zero = 0;
 } else {
-t = get_unary_0_33(gb);
-if (get_bits_left(gb) < 0)
+t = get_unary_0_33(bc);
+if (bitstream_bits_left(bc) < 0)
 goto error;
 if (t == 16) {
-t2 = get_unary_0_33(gb);
+t2 = get_unary_0_33(bc);
 if (t2 < 2) {
-if (get_bits_left(gb) < 0)
+if (bitstream_bits_left(bc) < 0)
 goto error;
 t += t2;
 } else {
-if (get_bits_left(gb) < t2 - 1)
+if (bitstream_bits_left(bc) < t2 - 1)
 goto error;
-t += get_bits(gb, t2 - 1) | (1 << (t2 - 1));
+t += bitstream_read(bc, t2 - 1) | (1 << (t2 - 1));
 }
 }
 
@@ -381,15 +381,15 @@ static int wv_get_value(WavpackFrameContext *ctx, 
GetBitContext *gb,
 INC_MED(2);
 }
 if (!c->error_limit) {
-ret = base + get_tail(gb, add);
-if (get_bits_left(gb) <= 0)
+ret = base + get_tail(bc, add);
+if (bitstream_bits_left(bc) <= 0)
 goto error;
 } else {
 int mid = (base * 2 + add + 1) >> 1;
 while (add > c->error_limit) {
-if (get_bits_left(gb) <= 0)
+if (bitstream_bits_left(bc) <= 0)
 goto error;
-if (get_bits1(gb)) {
+if (bitstream_read_bit(bc)) {
 add -= (mid - base);
 base = mid;
 } else
@@ -398,7 +398,7 @@ static int wv_get_value(WavpackFrameContext *ctx, 
GetBitContext *gb,
 }
 ret = mid;
 }
-sign = get_bits1(gb);
+sign = bitstream_read_bit(bc);
 if (ctx->hybrid_bitrate)
 c->slow_level += wp_log2(ret) - LEVEL_DECAY(c->slow_level);
 return sign ? ~ret : ret;
@@ -417,8 +417,8 @@ static inline int wv_get_value_integer(WavpackFrameContext 
*s, uint32_t *crc,
 S <<= s->extra_bits;
 
 if (s->got_extra_bits &&
-get_bits_left(>gb_extra_bits) >= s->extra_bits) {
-S   |= get_bits(>gb_extra_bits, s->extra_bits);
+bitstream_bits_left(>bc_extra_bits) >= s->extra_bits) {
+S   |= bitstream_read(>bc_extra_bits, s->extra_bits);
 *crc = *crc * 9 + (S & 0x) * 3 + ((unsigned)S >> 16);
 }
 }
@@ -444,7 +444,7 @@ static float wv_get_value_float(WavpackFrameContext 

[libav-devel] [PATCH 03/38] mpeg4video: Convert to the new bitstream reader

2016-05-20 Thread Alexandra Hájková
---
 libavcodec/mpeg4video.h|   4 +-
 libavcodec/mpeg4video_parser.c |  11 +-
 libavcodec/mpeg4videodec.c | 620 -
 libavcodec/mpegvideo.h |   4 +-
 libavcodec/vaapi_mpeg4.c   |   4 +-
 5 files changed, 320 insertions(+), 323 deletions(-)

diff --git a/libavcodec/mpeg4video.h b/libavcodec/mpeg4video.h
index 4a4995e..eeba134 100644
--- a/libavcodec/mpeg4video.h
+++ b/libavcodec/mpeg4video.h
@@ -25,7 +25,7 @@
 
 #include 
 
-#include "get_bits.h"
+#include "bitstream.h"
 #include "mpegvideo.h"
 #include "rl.h"
 
@@ -137,7 +137,7 @@ void ff_mpeg4_pred_ac(MpegEncContext *s, int16_t *block, 
int n,
 void ff_set_mpeg4_time(MpegEncContext *s);
 void ff_mpeg4_encode_picture_header(MpegEncContext *s, int picture_number);
 
-int ff_mpeg4_decode_picture_header(Mpeg4DecContext *ctx, GetBitContext *gb);
+int ff_mpeg4_decode_picture_header(Mpeg4DecContext *ctx, BitstreamContext *bc);
 void ff_mpeg4_encode_video_packet_header(MpegEncContext *s);
 void ff_mpeg4_clean_buffers(MpegEncContext *s);
 void ff_mpeg4_stuffing(PutBitContext *pbc);
diff --git a/libavcodec/mpeg4video_parser.c b/libavcodec/mpeg4video_parser.c
index e2203f9..de91ba3 100644
--- a/libavcodec/mpeg4video_parser.c
+++ b/libavcodec/mpeg4video_parser.c
@@ -20,6 +20,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "bitstream.h"
 #include "internal.h"
 #include "parser.h"
 #include "mpegvideo.h"
@@ -77,19 +78,19 @@ static int mpeg4_decode_header(AVCodecParserContext *s1, 
AVCodecContext *avctx,
 struct Mp4vParseContext *pc = s1->priv_data;
 Mpeg4DecContext *dec_ctx = >dec_ctx;
 MpegEncContext *s = _ctx->m;
-GetBitContext gb1, *gb = 
+BitstreamContext bc1, *bc = 
 int ret;
 
 s->avctx   = avctx;
 s->current_picture_ptr = >current_picture;
 
 if (avctx->extradata_size && pc->first_picture) {
-init_get_bits(gb, avctx->extradata, avctx->extradata_size * 8);
-ret = ff_mpeg4_decode_picture_header(dec_ctx, gb);
+bitstream_init8(bc, avctx->extradata, avctx->extradata_size);
+ret = ff_mpeg4_decode_picture_header(dec_ctx, bc);
 }
 
-init_get_bits(gb, buf, 8 * buf_size);
-ret = ff_mpeg4_decode_picture_header(dec_ctx, gb);
+bitstream_init8(bc, buf, buf_size);
+ret = ff_mpeg4_decode_picture_header(dec_ctx, bc);
 if (s->width && (!avctx->width || !avctx->height ||
  !avctx->coded_width || !avctx->coded_height)) {
 ret = ff_set_dimensions(avctx, s->width, s->height);
diff --git a/libavcodec/mpeg4videodec.c b/libavcodec/mpeg4videodec.c
index e16d482..4cf8d96 100644
--- a/libavcodec/mpeg4videodec.c
+++ b/libavcodec/mpeg4videodec.c
@@ -20,6 +20,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "bitstream.h"
 #include "error_resilience.h"
 #include "idctdsp.h"
 #include "internal.h"
@@ -30,6 +31,7 @@
 #include "h263.h"
 #include "profiles.h"
 #include "thread.h"
+#include "vlc.h"
 #include "xvididct.h"
 
 /* The defines below define the number of bits that are read at once for
@@ -51,9 +53,9 @@ static const int mb_type_b_map[4] = {
 MB_TYPE_L0  | MB_TYPE_16x16,
 };
 
-static inline int check_marker(AVCodecContext *avctx, GetBitContext *s, const 
char *msg)
+static inline int check_marker(AVCodecContext *avctx, BitstreamContext *bc, 
const char *msg)
 {
-int bit = get_bits1(s);
+int bit = bitstream_read_bit(bc);
 if (!bit)
 av_log(avctx, AV_LOG_INFO, "Marker bit missing %s\n", msg);
 
@@ -122,8 +124,8 @@ void ff_mpeg4_pred_ac(MpegEncContext *s, int16_t *block, 
int n, int dir)
  */
 static inline int mpeg4_is_resync(MpegEncContext *s)
 {
-int bits_count = get_bits_count(>gb);
-int v  = show_bits(>gb, 16);
+int bits_count = bitstream_tell(>bc);
+int v  = bitstream_peek(>bc, 16);
 
 if (s->workaround_bugs & FF_BUG_NO_PADDING)
 return 0;
@@ -132,12 +134,12 @@ static inline int mpeg4_is_resync(MpegEncContext *s)
 if (s->pict_type == AV_PICTURE_TYPE_B ||
 (v >> (8 - s->pict_type) != 1) || s->partitioned_frame)
 break;
-skip_bits(>gb, 8 + s->pict_type);
+bitstream_skip(>bc, 8 + s->pict_type);
 bits_count += 8 + s->pict_type;
-v = show_bits(>gb, 16);
+v = bitstream_peek(>bc, 16);
 }
 
-if (bits_count + 8 >= s->gb.size_in_bits) {
+if (bitstream_bits_left(>bc) <= 8) {
 v >>= 8;
 v  |= 0x7F >> (7 - (bits_count & 7));
 
@@ -146,16 +148,16 @@ static inline int mpeg4_is_resync(MpegEncContext *s)
 } else {
 if (v == ff_mpeg4_resync_prefix[bits_count & 7]) {
 int len;
-GetBitContext gb = s->gb;
+BitstreamContext bc = s->bc;
 
-skip_bits(>gb, 1);
-align_get_bits(>gb);
+bitstream_skip(>bc, 1);
+bitstream_align(>bc);
 
 for 

[libav-devel] [PATCH 07/38] mss1, mss2, mss4: Convert to the new bitstream reader

2016-05-20 Thread Alexandra Hájková
---
 libavcodec/mss1.c  | 15 +-
 libavcodec/mss12.h |  4 +--
 libavcodec/mss2.c  | 79 ++-
 libavcodec/mss4.c  | 83 +++---
 4 files changed, 93 insertions(+), 88 deletions(-)

diff --git a/libavcodec/mss1.c b/libavcodec/mss1.c
index a31af06..9f4d6bc 100644
--- a/libavcodec/mss1.c
+++ b/libavcodec/mss1.c
@@ -25,6 +25,7 @@
  */
 
 #include "avcodec.h"
+#include "bitstream.h"
 #include "internal.h"
 #include "mss12.h"
 
@@ -56,7 +57,7 @@ static void arith_normalise(ArithCoder *c)
 c->low   <<= 1;
 c->high  <<= 1;
 c->high   |= 1;
-c->value  |= get_bits1(c->gbc.gb);
+c->value  |= bitstream_read_bit(c->gbc.bc);
 }
 }
 
@@ -107,12 +108,12 @@ static int arith_get_prob(ArithCoder *c, int16_t *probs)
 
 ARITH_GET_MODEL_SYM()
 
-static void arith_init(ArithCoder *c, GetBitContext *gb)
+static void arith_init(ArithCoder *c, BitstreamContext *bc)
 {
 c->low   = 0;
 c->high  = 0x;
-c->value = get_bits(gb, 16);
-c->gbc.gb= gb;
+c->value = bitstream_read(bc, 16);
+c->gbc.bc= bc;
 c->get_model_sym = arith_get_model_sym;
 c->get_number= arith_get_number;
 }
@@ -143,13 +144,13 @@ static int mss1_decode_frame(AVCodecContext *avctx, void 
*data, int *got_frame,
 int buf_size = avpkt->size;
 MSS1Context *ctx = avctx->priv_data;
 MSS12Context *c = >ctx;
-GetBitContext gb;
+BitstreamContext bc;
 ArithCoder acoder;
 int pal_changed = 0;
 int ret;
 
-init_get_bits(, buf, buf_size * 8);
-arith_init(, );
+bitstream_init8(, buf, buf_size);
+arith_init(, );
 
 if ((ret = ff_reget_buffer(avctx, ctx->pic)) < 0) {
 av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n");
diff --git a/libavcodec/mss12.h b/libavcodec/mss12.h
index 5b1fee8..6936951 100644
--- a/libavcodec/mss12.h
+++ b/libavcodec/mss12.h
@@ -28,7 +28,7 @@
 
 #include "libavutil/intreadwrite.h"
 #include "avcodec.h"
-#include "get_bits.h"
+#include "bitstream.h"
 #include "bytestream.h"
 
 #define MODEL_MIN_SYMS2
@@ -48,7 +48,7 @@ typedef struct Model {
 typedef struct ArithCoder {
 int low, high, value;
 union {
-GetBitContext *gb;
+BitstreamContext *bc;
 GetByteContext *gB;
 } gbc;
 int (*get_model_sym)(struct ArithCoder *c, Model *m);
diff --git a/libavcodec/mss2.c b/libavcodec/mss2.c
index 2c993f6..50eec86 100644
--- a/libavcodec/mss2.c
+++ b/libavcodec/mss2.c
@@ -24,6 +24,8 @@
  */
 
 #include "libavutil/avassert.h"
+
+#include "bitstream.h"
 #include "error_resilience.h"
 #include "internal.h"
 #include "mpeg_er.h"
@@ -33,6 +35,7 @@
 #include "wmv2data.h"
 #include "mss12.h"
 #include "mss2dsp.h"
+#include "vlc.h"
 
 typedef struct MSS2Context {
 VC1Context v;
@@ -232,7 +235,7 @@ static int decode_555(GetByteContext *gB, uint16_t *dst, 
int stride,
 return 0;
 }
 
-static int decode_rle(GetBitContext *gb, uint8_t *pal_dst, int pal_stride,
+static int decode_rle(BitstreamContext *bc, uint8_t *pal_dst, int pal_stride,
   uint8_t *rgb_dst, int rgb_stride, uint32_t *pal,
   int keyframe, int kf_slipt, int slice, int w, int h)
 {
@@ -250,10 +253,10 @@ static int decode_rle(GetBitContext *gb, uint8_t 
*pal_dst, int pal_stride,
 if (!keyframe) {
 int x, y, clipw, cliph;
 
-x = get_bits(gb, 12);
-y = get_bits(gb, 12);
-clipw = get_bits(gb, 12) + 1;
-cliph = get_bits(gb, 12) + 1;
+x = bitstream_read(bc, 12);
+y = bitstream_read(bc, 12);
+clipw = bitstream_read(bc, 12) + 1;
+cliph = bitstream_read(bc, 12) + 1;
 
 if (x + clipw > w || y + cliph > h)
 return AVERROR_INVALIDDATA;
@@ -276,11 +279,11 @@ static int decode_rle(GetBitContext *gb, uint8_t 
*pal_dst, int pal_stride,
 /* read explicit codes */
 do {
 while (current_codes--) {
-int symbol = get_bits(gb, 8);
+int symbol = bitstream_read(bc, 8);
 if (symbol >= 204 - keyframe)
 symbol += 14 - keyframe;
 else if (symbol > 189)
-symbol = get_bits1(gb) + (symbol << 1) - 190;
+symbol = bitstream_read_bit(bc) + (symbol << 1) - 190;
 if (bits[symbol])
 return AVERROR_INVALIDDATA;
 bits[symbol]  = current_length;
@@ -290,7 +293,7 @@ static int decode_rle(GetBitContext *gb, uint8_t *pal_dst, 
int pal_stride,
 current_length++;
 next_code <<= 1;
 remaining_codes = (1 << current_length) - next_code;
-current_codes   = get_bits(gb, av_ceil_log2(remaining_codes + 1));
+current_codes   = bitstream_read(bc, av_ceil_log2(remaining_codes + 
1));
 if (current_length > 22 || current_codes > remaining_codes)
 return AVERROR_INVALIDDATA;

[libav-devel] [PATCH 02/38] flv: Convert to the new bitstream reader

2016-05-20 Thread Alexandra Hájková
---
 libavcodec/flv.h|  4 ++--
 libavcodec/flvdec.c | 39 ---
 2 files changed, 22 insertions(+), 21 deletions(-)

diff --git a/libavcodec/flv.h b/libavcodec/flv.h
index 801e357..7ea2e1d 100644
--- a/libavcodec/flv.h
+++ b/libavcodec/flv.h
@@ -21,7 +21,7 @@
 #ifndef AVCODEC_FLV_H
 #define AVCODEC_FLV_H
 
-#include "get_bits.h"
+#include "bitstream.h"
 #include "mpegvideo.h"
 #include "put_bits.h"
 
@@ -30,6 +30,6 @@ void ff_flv2_encode_ac_esc(PutBitContext *pb, int slevel, int 
level, int run,
int last);
 
 int ff_flv_decode_picture_header(MpegEncContext *s);
-void ff_flv2_decode_ac_esc(GetBitContext *gb, int *level, int *run, int *last);
+void ff_flv2_decode_ac_esc(BitstreamContext *bc, int *level, int *run, int 
*last);
 
 #endif /* AVCODEC_FLV_H */
diff --git a/libavcodec/flvdec.c b/libavcodec/flvdec.c
index f2d4929..c258f24 100644
--- a/libavcodec/flvdec.c
+++ b/libavcodec/flvdec.c
@@ -20,20 +20,21 @@
 
 #include "libavutil/imgutils.h"
 
+#include "bitstream.h"
 #include "flv.h"
 #include "h263.h"
 #include "mpegvideo.h"
 #include "mpegvideodata.h"
 
-void ff_flv2_decode_ac_esc(GetBitContext *gb, int *level, int *run, int *last)
+void ff_flv2_decode_ac_esc(BitstreamContext *bc, int *level, int *run, int 
*last)
 {
-int is11 = get_bits1(gb);
-*last = get_bits1(gb);
-*run  = get_bits(gb, 6);
+int is11 = bitstream_read_bit(bc);
+*last = bitstream_read_bit(bc);
+*run  = bitstream_read(bc, 6);
 if (is11)
-*level = get_sbits(gb, 11);
+*level = bitstream_read_signed(bc, 11);
 else
-*level = get_sbits(gb, 7);
+*level = bitstream_read_signed(bc, 7);
 }
 
 int ff_flv_decode_picture_header(MpegEncContext *s)
@@ -41,26 +42,26 @@ int ff_flv_decode_picture_header(MpegEncContext *s)
 int format, width, height;
 
 /* picture header */
-if (get_bits_long(>gb, 17) != 1) {
+if (bitstream_read(>bc, 17) != 1) {
 av_log(s->avctx, AV_LOG_ERROR, "Bad picture start code\n");
 return -1;
 }
-format = get_bits(>gb, 5);
+format = bitstream_read(>bc, 5);
 if (format != 0 && format != 1) {
 av_log(s->avctx, AV_LOG_ERROR, "Bad picture format\n");
 return -1;
 }
 s->h263_flv   = format + 1;
-s->picture_number = get_bits(>gb, 8); /* picture timestamp */
-format= get_bits(>gb, 3);
+s->picture_number = bitstream_read(>bc, 8); /* picture timestamp */
+format= bitstream_read(>bc, 3);
 switch (format) {
 case 0:
-width  = get_bits(>gb, 8);
-height = get_bits(>gb, 8);
+width  = bitstream_read(>bc, 8);
+height = bitstream_read(>bc, 8);
 break;
 case 1:
-width  = get_bits(>gb, 16);
-height = get_bits(>gb, 16);
+width  = bitstream_read(>bc, 16);
+height = bitstream_read(>bc, 16);
 break;
 case 2:
 width  = 352;
@@ -91,13 +92,13 @@ int ff_flv_decode_picture_header(MpegEncContext *s)
 s->width  = width;
 s->height = height;
 
-s->pict_type = AV_PICTURE_TYPE_I + get_bits(>gb, 2);
+s->pict_type = AV_PICTURE_TYPE_I + bitstream_read(>bc, 2);
 s->droppable = s->pict_type > AV_PICTURE_TYPE_P;
 if (s->droppable)
 s->pict_type = AV_PICTURE_TYPE_P;
 
-skip_bits1(>gb); /* deblocking flag */
-s->chroma_qscale = s->qscale = get_bits(>gb, 5);
+bitstream_skip(>bc, 1); /* deblocking flag */
+s->chroma_qscale = s->qscale = bitstream_read(>bc, 5);
 
 s->h263_plus = 0;
 
@@ -105,8 +106,8 @@ int ff_flv_decode_picture_header(MpegEncContext *s)
 s->h263_long_vectors = 0;
 
 /* PEI */
-while (get_bits1(>gb) != 0)
-skip_bits(>gb, 8);
+while (bitstream_read_bit(>bc) != 0)
+bitstream_skip(>bc, 8);
 s->f_code = 1;
 
 if (s->avctx->debug & FF_DEBUG_PICT_INFO) {
-- 
2.1.4

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH 01/38] h261dec: Convert to the new bitstream reader

2016-05-20 Thread Alexandra Hájková
---
 libavcodec/h261dec.c | 90 +++-
 1 file changed, 46 insertions(+), 44 deletions(-)

diff --git a/libavcodec/h261dec.c b/libavcodec/h261dec.c
index 9a323ec..47755f0 100644
--- a/libavcodec/h261dec.c
+++ b/libavcodec/h261dec.c
@@ -26,12 +26,14 @@
  */
 
 #include "avcodec.h"
+#include "bitstream.h"
 #include "mpeg_er.h"
 #include "mpegutils.h"
 #include "mpegvideo.h"
 #include "h263.h"
 #include "h261.h"
 #include "internal.h"
+#include "vlc.h"
 
 #define H261_MBA_VLC_BITS 9
 #define H261_MTYPE_VLC_BITS 6
@@ -103,18 +105,18 @@ static int h261_decode_gob_header(H261Context *h)
 
 if (!h->gob_start_code_skipped) {
 /* Check for GOB Start Code */
-val = show_bits(>gb, 15);
+val = bitstream_peek(>bc, 15);
 if (val)
 return -1;
 
 /* We have a GBSC */
-skip_bits(>gb, 16);
+bitstream_skip(>bc, 16);
 }
 
 h->gob_start_code_skipped = 0;
 
-h->gob_number = get_bits(>gb, 4); /* GN */
-s->qscale = get_bits(>gb, 5); /* GQUANT */
+h->gob_number = bitstream_read(>bc, 4); /* GN */
+s->qscale = bitstream_read(>bc, 5); /* GQUANT */
 
 /* Check if gob_number is valid */
 if (s->mb_height == 18) { // CIF
@@ -127,8 +129,8 @@ static int h261_decode_gob_header(H261Context *h)
 }
 
 /* GEI */
-while (get_bits1(>gb) != 0)
-skip_bits(>gb, 8);
+while (bitstream_read_bit(>bc) != 0)
+bitstream_skip(>bc, 8);
 
 if (s->qscale == 0) {
 av_log(s->avctx, AV_LOG_ERROR, "qscale has forbidden 0 value\n");
@@ -160,27 +162,27 @@ static int h261_resync(H261Context *h)
 if (ret >= 0)
 return 0;
 } else {
-if (show_bits(>gb, 15) == 0) {
+if (bitstream_peek(>bc, 15) == 0) {
 ret = h261_decode_gob_header(h);
 if (ret >= 0)
 return 0;
 }
 // OK, it is not where it is supposed to be ...
-s->gb = s->last_resync_gb;
-align_get_bits(>gb);
-left = get_bits_left(>gb);
+s->bc = s->last_resync_bc;
+bitstream_align(>bc);
+left = bitstream_bits_left(>bc);
 
 for (; left > 15 + 1 + 4 + 5; left -= 8) {
-if (show_bits(>gb, 15) == 0) {
-GetBitContext bak = s->gb;
+if (bitstream_peek(>bc, 15) == 0) {
+BitstreamContext bak = s->bc;
 
 ret = h261_decode_gob_header(h);
 if (ret >= 0)
 return 0;
 
-s->gb = bak;
+s->bc = bak;
 }
-skip_bits(>gb, 8);
+bitstream_skip(>bc, 8);
 }
 }
 
@@ -228,9 +230,9 @@ static const int mvmap[17] = {
 0, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, -12, -13, -14, -15, -16
 };
 
-static int decode_mv_component(GetBitContext *gb, int v)
+static int decode_mv_component(BitstreamContext *bc, int v)
 {
-int mv_diff = get_vlc2(gb, h261_mv_vlc.table, H261_MV_VLC_BITS, 2);
+int mv_diff = bitstream_read_vlc(bc, h261_mv_vlc.table, H261_MV_VLC_BITS, 
2);
 
 /* check if mv_diff is valid */
 if (mv_diff < 0)
@@ -238,7 +240,7 @@ static int decode_mv_component(GetBitContext *gb, int v)
 
 mv_diff = mvmap[mv_diff];
 
-if (mv_diff && !get_bits1(gb))
+if (mv_diff && !bitstream_read_bit(bc))
 mv_diff = -mv_diff;
 
 v += mv_diff;
@@ -270,7 +272,7 @@ static int h261_decode_block(H261Context *h, int16_t 
*block, int n, int coded)
 scan_table = s->intra_scantable.permutated;
 if (s->mb_intra) {
 /* DC coef */
-level = get_bits(>gb, 8);
+level = bitstream_read(>bc, 8);
 // 0 (b) and -128 (1000b) are FORBIDDEN
 if ((level & 0x7F) == 0) {
 av_log(s->avctx, AV_LOG_ERROR, "illegal dc %d at %d %d\n",
@@ -288,10 +290,10 @@ static int h261_decode_block(H261Context *h, int16_t 
*block, int n, int coded)
 // EOB  Not possible for first level when cbp is available 
(that's why the table is different)
 // 01   1s
 // **   0*
-int check = show_bits(>gb, 2);
+int check = bitstream_peek(>bc, 2);
 i = 0;
 if (check & 0x2) {
-skip_bits(>gb, 2);
+bitstream_skip(>bc, 2);
 block[0] = (check & 0x1) ? -1 : 1;
 i= 1;
 }
@@ -303,7 +305,7 @@ static int h261_decode_block(H261Context *h, int16_t 
*block, int n, int coded)
 return 0;
 }
 for (;;) {
-code = get_vlc2(>gb, rl->vlc.table, TCOEFF_VLC_BITS, 2);
+code = bitstream_read_vlc(>bc, rl->vlc.table, TCOEFF_VLC_BITS, 2);
 if (code < 0) {
 av_log(s->avctx, AV_LOG_ERROR, "illegal ac vlc code at %dx%d\n",
s->mb_x, s->mb_y);
@@ -314,14 +316,14 @@ static int h261_decode_block(H261Context *h, int16_t 
*block, int n, int coded)
 /* The remaining combinations of (run, 

[libav-devel] [PATCH 05/38] intrax8: Convert to the new bitstream reader

2016-05-20 Thread Alexandra Hájková
---
 libavcodec/intrax8.c | 37 +++--
 libavcodec/intrax8.h |  7 ---
 2 files changed, 23 insertions(+), 21 deletions(-)

diff --git a/libavcodec/intrax8.c b/libavcodec/intrax8.c
index eb4c1ef..28b89f8 100644
--- a/libavcodec/intrax8.c
+++ b/libavcodec/intrax8.c
@@ -22,13 +22,14 @@
  */
 
 #include "avcodec.h"
-#include "get_bits.h"
+#include "bitstream.h"
 #include "idctdsp.h"
 #include "msmpeg4data.h"
 #include "intrax8huf.h"
 #include "intrax8.h"
 #include "intrax8dsp.h"
 #include "mpegutils.h"
+#include "vlc.h"
 
 #define MAX_TABLE_DEPTH(table_bits, max_bits) \
 ((max_bits + table_bits - 1) / table_bits)
@@ -139,7 +140,7 @@ static inline void x8_select_ac_table(IntraX8Context *const 
w, int mode)
 if (w->j_ac_vlc[mode])
 return;
 
-table_index   = get_bits(w->gb, 3);
+table_index   = bitstream_read(w->bc, 3);
 // 2 modes use same tables
 w->j_ac_vlc[mode] = _ac_vlc[w->quant < 13][mode >> 1][table_index];
 
@@ -149,13 +150,13 @@ static inline void x8_select_ac_table(IntraX8Context 
*const w, int mode)
 static inline int x8_get_orient_vlc(IntraX8Context *w)
 {
 if (!w->j_orient_vlc) {
-int table_index = get_bits(w->gb, 1 + (w->quant < 13));
+int table_index = bitstream_read(w->bc, 1 + (w->quant < 13));
 w->j_orient_vlc = _orient_vlc[w->quant < 13][table_index];
 }
 assert(w->j_orient_vlc);
 assert(w->j_orient_vlc->table);
 
-return get_vlc2(w->gb, w->j_orient_vlc->table, OR_VLC_BITS, OR_VLC_MTD);
+return bitstream_read_vlc(w->bc, w->j_orient_vlc->table, OR_VLC_BITS, 
OR_VLC_MTD);
 }
 
 #define extra_bits(eb)  (eb)// 3 bits
@@ -211,7 +212,7 @@ static void x8_get_ac_rlf(IntraX8Context *const w, const 
int mode,
 int i, e;
 
 //x8_select_ac_table(w, mode);
-i = get_vlc2(w->gb, w->j_ac_vlc[mode]->table, AC_VLC_BITS, AC_VLC_MTD);
+i = bitstream_read_vlc(w->bc, w->j_ac_vlc[mode]->table, AC_VLC_BITS, 
AC_VLC_MTD);
 
 if (i < 46) { // [0-45]
 int t, l;
@@ -250,8 +251,8 @@ static void x8_get_ac_rlf(IntraX8Context *const w, const 
int mode,
 i -= 46;
 sm = ac_decode_table[i];
 
-e= get_bits(w->gb, sm & 0xF);
-sm >>= 8;   // 3 bits
+e= bitstream_read(w->bc, sm & 0xF);
+sm >>= 8;   // 3bits
 mask = sm & 0xff;
 sm >>= 8;   // 1 bit
 
@@ -267,13 +268,13 @@ static void x8_get_ac_rlf(IntraX8Context *const w, const 
int mode,
 };
 
 *final = !(i & 1);
-e  = get_bits(w->gb, 5); // get the extra bits
+e  = bitstream_read(w->bc, 5); // get the extra bits
 *run   = crazy_mix_runlevel[e] >> 4;
 *level = crazy_mix_runlevel[e] & 0x0F;
 } else {
-*level = get_bits(w->gb, 7 - 3 * (i & 1));
-*run   = get_bits(w->gb, 6);
-*final = get_bits1(w->gb);
+*level = bitstream_read(w->bc, 7 - 3 * (i & 1));
+*run   = bitstream_read(w->bc, 6);
+*final = bitstream_read_bit(w->bc);
 }
 return;
 }
@@ -292,14 +293,14 @@ static int x8_get_dc_rlf(IntraX8Context *const w, const 
int mode,
 
 assert(mode < 3);
 if (!w->j_dc_vlc[mode]) {
-int table_index = get_bits(w->gb, 3);
+int table_index = bitstream_read(w->bc, 3);
 // 4 modes, same table
 w->j_dc_vlc[mode] = _dc_vlc[w->quant < 13][table_index];
 }
 assert(w->j_dc_vlc);
 assert(w->j_dc_vlc[mode]->table);
 
-i = get_vlc2(w->gb, w->j_dc_vlc[mode]->table, DC_VLC_BITS, DC_VLC_MTD);
+i = bitstream_read_vlc(w->bc, w->j_dc_vlc[mode]->table, DC_VLC_BITS, 
DC_VLC_MTD);
 
 /* (i >= 17) { i -= 17; final =1; } */
 c  = i > 16;
@@ -313,7 +314,7 @@ static int x8_get_dc_rlf(IntraX8Context *const w, const int 
mode,
 c  = (i + 1) >> 1; // hackish way to calculate dc_extra_sbits[]
 c -= c > 1;
 
-e = get_bits(w->gb, c); // get the extra bits
+e = bitstream_read(w->bc, c); // get the extra bits
 i = dc_index_offset[i] + (e >> 1);
 
 e  = -(e & 1); // 0, 0xff
@@ -634,7 +635,7 @@ static int x8_decode_intra_mb(IntraX8Context *const w, 
const int chroma)
 level  = (level + 1) * w->dquant;
 level += w->qsum;
 
-sign  = -get_bits1(w->gb);
+sign  = -bitstream_read_bit(w->bc);
 level = (level ^ sign) - sign;
 
 if (use_quant_matrix)
@@ -770,19 +771,19 @@ av_cold void ff_intrax8_common_end(IntraX8Context *w)
 }
 
 int ff_intrax8_decode_picture(IntraX8Context *const w, Picture *pict,
-  GetBitContext *gb, int *mb_x, int *mb_y,
+  BitstreamContext *bc, int *mb_x, int *mb_y,
   int dquant, int quant_offset,
   int loopfilter, int lowdelay)
 {
 int mb_xy;
 
-w->gb = gb;
+w->bc = bc;
 w->dquant 

[libav-devel] [PATCH 04/38] h263dec: Convert to the new bitstream reader

2016-05-20 Thread Alexandra Hájková
---
 libavcodec/h263.h |  3 ++-
 libavcodec/h263dec.c  | 54 +++--
 libavcodec/intelh263dec.c | 69 ---
 3 files changed, 65 insertions(+), 61 deletions(-)

diff --git a/libavcodec/h263.h b/libavcodec/h263.h
index 42c78f4..5377813 100644
--- a/libavcodec/h263.h
+++ b/libavcodec/h263.h
@@ -22,10 +22,11 @@
 
 #include 
 #include "libavutil/rational.h"
-#include "get_bits.h"
+#include "bitstream.h"
 #include "mpegvideo.h"
 #include "h263data.h"
 #include "rl.h"
+#include "vlc.h"
 
 #if !FF_API_ASPECT_EXTENDED
 #define FF_ASPECT_EXTENDED 15
diff --git a/libavcodec/h263dec.c b/libavcodec/h263dec.c
index e4a7227..0335ebb 100644
--- a/libavcodec/h263dec.c
+++ b/libavcodec/h263dec.c
@@ -27,6 +27,7 @@
 
 #include "libavutil/cpu.h"
 #include "avcodec.h"
+#include "bitstream.h"
 #include "error_resilience.h"
 #include "flv.h"
 #include "h263.h"
@@ -146,7 +147,7 @@ av_cold int ff_h263_decode_end(AVCodecContext *avctx)
  */
 static int get_consumed_bytes(MpegEncContext *s, int buf_size)
 {
-int pos = (get_bits_count(>gb) + 7) >> 3;
+int pos = (bitstream_tell(>bc) + 7) >> 3;
 
 if (s->divx_packed || s->avctx->hwaccel) {
 /* We would have to scan through the whole buf to handle the weird
@@ -177,7 +178,7 @@ static int decode_slice(MpegEncContext *s)
 const int mb_size = 16;
 int ret;
 
-s->last_resync_gb   = s->gb;
+s->last_resync_bc   = s->bc;
 s->first_slice_line = 1;
 s->resync_mb_x  = s->mb_x;
 s->resync_mb_y  = s->mb_y;
@@ -185,10 +186,10 @@ static int decode_slice(MpegEncContext *s)
 ff_set_qscale(s, s->qscale);
 
 if (s->avctx->hwaccel) {
-const uint8_t *start = s->gb.buffer + get_bits_count(>gb) / 8;
+const uint8_t *start = s->bc.buffer + bitstream_tell(>bc) / 8;
 const uint8_t *end   = ff_h263_find_resync_marker(start + 1,
-  s->gb.buffer_end);
-skip_bits_long(>gb, 8 * (end - start));
+  s->bc.buffer_end);
+bitstream_skip(>bc, 8 * (end - start));
 return s->avctx->hwaccel->decode_slice(s->avctx, start, end - start);
 }
 
@@ -237,7 +238,7 @@ static int decode_slice(MpegEncContext *s)
 s->mv_dir  = MV_DIR_FORWARD;
 s->mv_type = MV_TYPE_16X16;
 ff_dlog(s, "%d %06X\n",
-get_bits_count(>gb), show_bits(>gb, 24));
+bitstream_tell(>bc), bitstream_peek(>bc, 24));
 ret = s->decode_mb(s, s->block);
 
 if (s->pict_type != AV_PICTURE_TYPE_B)
@@ -292,29 +293,30 @@ static int decode_slice(MpegEncContext *s)
 
 if (s->codec_id == AV_CODEC_ID_MPEG4 &&
 (s->workaround_bugs & FF_BUG_AUTODETECT) &&
-get_bits_left(>gb) >= 48  &&
-show_bits(>gb, 24) == 0x4010  &&
+bitstream_bits_left(>bc) >= 48&&
+bitstream_peek(>bc, 24) == 0x4010 &&
 !s->data_partitioning)
 s->padding_bug_score += 32;
 
 /* try to detect the padding bug */
 if (s->codec_id == AV_CODEC_ID_MPEG4 &&
 (s->workaround_bugs & FF_BUG_AUTODETECT) &&
-get_bits_left(>gb) >= 0   &&
-get_bits_left(>gb) < 48   &&
+bitstream_bits_left(>bc) >= 0 &&
+bitstream_bits_left(>bc) < 48 &&
 !s->data_partitioning) {
-const int bits_count = get_bits_count(>gb);
-const int bits_left  = s->gb.size_in_bits - bits_count;
+const int bits_count = bitstream_tell(>bc);
+const int bits_left = bitstream_bits_left(>bc);
+//printf("h263: bits_left %d\n", bits_left);
 
 if (bits_left == 0) {
 s->padding_bug_score += 16;
 } else if (bits_left != 1) {
-int v = show_bits(>gb, 8);
+int v = bitstream_peek(>bc, 8);
 v |= 0x7F >> (7 - (bits_count & 7));
 
 if (v == 0x7F && bits_left <= 8)
 s->padding_bug_score--;
-else if (v == 0x7F && ((get_bits_count(>gb) + 8) & 8) &&
+else if (v == 0x7F && ((bitstream_tell(>bc) + 8) & 8) &&
  bits_left <= 16)
 s->padding_bug_score += 4;
 else
@@ -332,7 +334,7 @@ static int decode_slice(MpegEncContext *s)
 
 // handle formats which don't have unique end markers
 if (s->msmpeg4_version || (s->workaround_bugs & FF_BUG_NO_PADDING)) { // 
FIXME perhaps solve this more cleanly
-int left  = get_bits_left(>gb);
+int left  = bitstream_bits_left(>bc);
 int max_extra = 7;
 
 /* no markers in M$ crap */
@@ -350,7 +352,7 @@ static int decode_slice(MpegEncContext *s)
 if (left > max_extra)
 av_log(s->avctx, AV_LOG_ERROR,
"discarding %d junk bits at end, next would be %X\n",
-   

Re: [libav-devel] [PATCH 2/7] attributes: Add av_unlikely macro

2016-05-20 Thread Vittorio Giovara
On Fri, May 20, 2016 at 11:37 AM, Alexandra Hájková
 wrote:
> ---
>
> Rebased patch.
>
>  doc/APIchanges | 3 +++
>  libavutil/attributes.h | 6 ++
>  libavutil/version.h| 2 +-
>  3 files changed, 10 insertions(+), 1 deletion(-)
>
> diff --git a/doc/APIchanges b/doc/APIchanges
> index 8f6cdca..573c221 100644
> --- a/doc/APIchanges
> +++ b/doc/APIchanges
> @@ -13,6 +13,9 @@ libavutil: 2015-08-28
>
>  API changes, most recent first:
>
> +2016-xx-xx - xxx - lavu 55.11.0 - attributes.h

version mismatch

> diff --git a/libavutil/version.h b/libavutil/version.h
> index 4cee2b0..48a5878 100644
> --- a/libavutil/version.h
> +++ b/libavutil/version.h
> @@ -54,7 +54,7 @@
>   */
>
>  #define LIBAVUTIL_VERSION_MAJOR 55
> -#define LIBAVUTIL_VERSION_MINOR 12
> +#define LIBAVUTIL_VERSION_MINOR 13
>  #define LIBAVUTIL_VERSION_MICRO  0
>
>  #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \

-- 
Vittorio
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel

Re: [libav-devel] [PATCH 3/7] Add the new bitstream reader

2016-05-20 Thread Luca Barbato
On 20/05/16 17:35, Alexandra Hájková wrote:
> ---
>  * Use the simplified comments instead of doxygen because it's an internal 
> header.
>  * Remove print_bin debugging function.
>  * Cosmetics.
> 

Looks good, whoever will push it should drop the stray * from there though.

lu

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel

[libav-devel] [PATCH 2/7] attributes: Add av_unlikely macro

2016-05-20 Thread Alexandra Hájková
---

Rebased patch.

 doc/APIchanges | 3 +++
 libavutil/attributes.h | 6 ++
 libavutil/version.h| 2 +-
 3 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index 8f6cdca..573c221 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -13,6 +13,9 @@ libavutil: 2015-08-28
 
 API changes, most recent first:
 
+2016-xx-xx - xxx - lavu 55.11.0 - attributes.h
+  Add av_unlikely macro.
+
 2016-xx-xx - xxx - lavf 57.7.0 - avio.h
   Add AVIODataMarkerType, write_data_type, ignore_boundary_point and
   avio_write_marker.
diff --git a/libavutil/attributes.h b/libavutil/attributes.h
index d7f2bb5..1a8d738 100644
--- a/libavutil/attributes.h
+++ b/libavutil/attributes.h
@@ -123,4 +123,10 @@
 #define av_noreturn
 #endif
 
+#if AV_GCC_VERSION_AT_LEAST(4,3)
+#   define av_unlikely(x) __builtin_expect((x) != 0, 0)
+#else
+#   define av_unlikely(x) x
+#endif
+
 #endif /* AVUTIL_ATTRIBUTES_H */
diff --git a/libavutil/version.h b/libavutil/version.h
index 4cee2b0..48a5878 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -54,7 +54,7 @@
  */
 
 #define LIBAVUTIL_VERSION_MAJOR 55
-#define LIBAVUTIL_VERSION_MINOR 12
+#define LIBAVUTIL_VERSION_MINOR 13
 #define LIBAVUTIL_VERSION_MICRO  0
 
 #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
-- 
2.1.4

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH 3/7] Add the new bitstream reader

2016-05-20 Thread Alexandra Hájková
---
 * Use the simplified comments instead of doxygen because it's an internal 
header.
 * Remove print_bin debugging function.
 * Cosmetics.

 libavcodec/bitstream.h | 439 +
 1 file changed, 439 insertions(+)
 create mode 100644 libavcodec/bitstream.h

diff --git a/libavcodec/bitstream.h b/libavcodec/bitstream.h
new file mode 100644
index 000..745146f
--- /dev/null
+++ b/libavcodec/bitstream.h
@@ -0,0 +1,439 @@
+/*
+ * copyright (c) 2016 Alexandra Hájková
+ *
+ * This file is part of Libav.
+ *
+ * Libav is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * Libav is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Libav; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * bitstream reader API header.
+ */
+
+#ifndef AVCODEC_BITSTREAM_H
+#define AVCODEC_BITSTREAM_H
+
+#include 
+
+#include "libavutil/common.h"
+#include "libavutil/intreadwrite.h"
+#include "libavutil/log.h"
+
+#include "mathops.h"
+#include "vlc.h"
+
+typedef struct BitstreamContext {
+uint64_t bits;  // stores bits read from the buffer
+const uint8_t *buffer, *buffer_end;
+const uint8_t *ptr; // pointer to the position inside a buffer
+unsigned bits_left; // number of bits left in bits field
+unsigned size_in_bits;
+} BitstreamContext;
+
+/**
+ * Return number of bits already read.
+ */
+static inline int bitstream_tell(const BitstreamContext *s)
+{
+return (s->ptr - s->buffer) * 8 - s->bits_left;
+}
+
+static inline void refill_64(BitstreamContext *s)
+{
+if (av_unlikely(s->ptr >= s->buffer_end || !s->buffer))
+return;
+
+#ifdef BITSTREAM_READER_LE
+s->bits  = AV_RL64(s->ptr);
+#else
+s->bits  = AV_RB64(s->ptr);
+#endif
+s->ptr  += 8;
+s->bits_left = 64;
+}
+
+static inline uint64_t get_val(BitstreamContext *s, unsigned int n)
+{
+uint64_t ret;
+
+#ifdef BITSTREAM_READER_LE
+ret = s->bits & ((UINT64_C(1) << n) - 1);
+s->bits >>= n;
+#else
+ret = s->bits >> (64 - n);
+s->bits <<= n;
+#endif
+s->bits_left -= n;
+
+return ret;
+}
+
+/**
+ * Return one bit from the buffer.
+ */
+static inline unsigned int bitstream_read_bit(BitstreamContext *s)
+{
+if (av_unlikely(!s->bits_left))
+refill_64(s);
+
+return get_val(s, 1);
+}
+
+/**
+ * Return n bits from the buffer, n has to be in the 0-63 range.
+ */
+static inline uint64_t bitstream_read_63(BitstreamContext *s, unsigned int n)
+{
+uint64_t ret = 0;
+#ifdef BITSTREAM_READER_LE
+uint64_t left = 0;
+#endif
+
+if (av_unlikely(!n))
+return 0;
+
+if (av_unlikely(n > s->bits_left)) {
+n -= s->bits_left;
+#ifdef BITSTREAM_READER_LE
+left = s->bits_left;
+#endif
+ret = get_val(s, s->bits_left);
+refill_64(s);
+}
+
+#ifdef BITSTREAM_READER_LE
+ret = get_val(s, n) << left | ret;
+#else
+ret = get_val(s, n) | ret << n;
+#endif
+
+return ret;
+}
+
+static inline void refill_32(BitstreamContext *s)
+{
+if (av_unlikely(s->ptr >= s->buffer_end || !s->buffer))
+return;
+
+#ifdef BITSTREAM_READER_LE
+s->bits   = (uint64_t)AV_RL32(s->ptr) << s->bits_left | s->bits;
+#else
+s->bits   = s->bits | (uint64_t)AV_RB32(s->ptr) << (32 - s->bits_left);
+#endif
+s->ptr   += 4;
+s->bits_left += 32;
+}
+
+/**
+ * Return n bits from the buffer, n has to be in the 0-32  range.
+ */
+static inline uint32_t bitstream_read(BitstreamContext *s, unsigned int n)
+{
+if (av_unlikely(!n))
+return 0;
+
+if (av_unlikely(n > s->bits_left)) {
+refill_32(s);
+if (av_unlikely(s->bits_left < 32))
+s->bits_left = n;
+}
+
+return get_val(s, n);
+}
+
+static inline unsigned int show_val(BitstreamContext *s, unsigned int n)
+{
+int ret;
+
+#ifdef BITSTREAM_READER_LE
+ret = s->bits & ((UINT64_C(1) << n) - 1);
+#else
+ret = s->bits >> (64 - n);
+#endif
+
+return ret;
+}
+
+/**
+ * Return n bits from the buffer but do not change the buffer state.
+ * n has to be in the 0-32 range.
+ */
+static inline unsigned int bitstream_peek(BitstreamContext *s, unsigned int n)
+{
+if (av_unlikely(n > s->bits_left))
+refill_32(s);
+
+return show_val(s, n);
+}
+
+static inline void skip_remaining(BitstreamContext *s, unsigned int n)
+{
+#ifdef BITSTREAM_READER_LE
+s->bits >>= n;
+#else
+s->bits <<= n;
+#endif
+s->bits_left -= n;

[libav-devel] [PATCH] hwcontext_vaapi: implement device creation

2016-05-20 Thread Anton Khirnov
---
 libavutil/hwcontext_vaapi.c | 124 
 1 file changed, 124 insertions(+)

diff --git a/libavutil/hwcontext_vaapi.c b/libavutil/hwcontext_vaapi.c
index 1a385ba..086fa74 100644
--- a/libavutil/hwcontext_vaapi.c
+++ b/libavutil/hwcontext_vaapi.c
@@ -16,6 +16,21 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "config.h"
+
+#if HAVE_VAAPI_X11
+#   include 
+#endif
+#if HAVE_VAAPI_DRM
+#   include 
+#endif
+
+#include 
+#if HAVE_UNISTD_H
+#   include 
+#endif
+
+
 #include "avassert.h"
 #include "buffer.h"
 #include "common.h"
@@ -26,6 +41,14 @@
 #include "pixdesc.h"
 #include "pixfmt.h"
 
+typedef struct VAAPIDevicePriv {
+#if HAVE_VAAPI_X11
+Display *x11_display;
+#endif
+
+int drm_fd;
+} VAAPIDevicePriv;
+
 typedef struct VAAPISurfaceFormat {
 enum AVPixelFormat pix_fmt;
 VAImageFormat image_format;
@@ -823,6 +846,106 @@ fail:
 return err;
 }
 
+static void vaapi_device_free(AVHWDeviceContext *ctx)
+{
+AVVAAPIDeviceContext *hwctx = ctx->hwctx;
+VAAPIDevicePriv  *priv  = ctx->user_opaque;
+
+if (hwctx->display)
+vaTerminate(hwctx->display);
+
+#if HAVE_VAAPI_X11
+if (priv->x11_display)
+XCloseDisplay(priv->x11_display);
+#endif
+
+if (priv->drm_fd >= 0)
+close(priv->drm_fd);
+
+av_freep();
+}
+
+static int vaapi_device_create(AVHWDeviceContext *ctx, const char *device,
+   AVDictionary *opts, int flags)
+{
+AVVAAPIDeviceContext *hwctx = ctx->hwctx;
+VAAPIDevicePriv *priv;
+VADisplay display = 0;
+VAStatus vas;
+int major, minor;
+
+priv = av_mallocz(sizeof(*priv));
+if (!priv)
+return AVERROR(ENOMEM);
+
+priv->drm_fd = -1;
+
+ctx->user_opaque = priv;
+ctx->free= vaapi_device_free;
+
+#if HAVE_VAAPI_X11
+if (!display && !(device && device[0] == '/')) {
+// Try to open the device as an X11 display.
+priv->x11_display = XOpenDisplay(device);
+if (!priv->x11_display) {
+av_log(ctx, AV_LOG_VERBOSE, "Cannot open X11 display "
+   "%s.\n", XDisplayName(device));
+} else {
+display = vaGetDisplay(priv->x11_display);
+if (!display) {
+av_log(ctx, AV_LOG_ERROR, "Cannot open a VA display "
+   "from X11 display %s.\n", XDisplayName(device));
+return AVERROR_UNKNOWN;
+}
+
+av_log(ctx, AV_LOG_VERBOSE, "Opened VA display via "
+   "X11 display %s.\n", XDisplayName(device));
+}
+}
+#endif
+
+#if HAVE_VAAPI_DRM
+if (!display && device) {
+// Try to open the device as a DRM path.
+priv->drm_fd = open(device, O_RDWR);
+if (priv->drm_fd < 0) {
+av_log(ctx, AV_LOG_VERBOSE, "Cannot open DRM device %s.\n",
+   device);
+} else {
+display = vaGetDisplayDRM(priv->drm_fd);
+if (!display) {
+av_log(ctx, AV_LOG_ERROR, "Cannot open a VA display "
+   "from DRM device %s.\n", device);
+return AVERROR_UNKNOWN;
+}
+
+av_log(ctx, AV_LOG_VERBOSE, "Opened VA display via "
+   "DRM device %s.\n", device);
+}
+}
+#endif
+
+if (!display) {
+av_log(ctx, AV_LOG_ERROR, "No VA display found for "
+   "device: %s.\n", device ? device : "");
+return AVERROR(EINVAL);
+}
+
+hwctx->display = display;
+
+vas = vaInitialize(display, , );
+if (vas != VA_STATUS_SUCCESS) {
+av_log(ctx, AV_LOG_ERROR, "Failed to initialise VAAPI "
+   "connection: %d (%s).\n", vas, vaErrorStr(vas));
+return AVERROR(EIO);
+}
+av_log(ctx, AV_LOG_VERBOSE, "Initialised VAAPI connection: "
+   "version %d.%d\n", major, minor);
+
+
+return 0;
+}
+
 const HWContextType ff_hwcontext_type_vaapi = {
 .type   = AV_HWDEVICE_TYPE_VAAPI,
 .name   = "VAAPI",
@@ -833,6 +956,7 @@ const HWContextType ff_hwcontext_type_vaapi = {
 .frames_hwctx_size  = sizeof(AVVAAPIFramesContext),
 .frames_priv_size   = sizeof(VAAPIFramesContext),
 
+.device_create  = _device_create,
 .device_init= _device_init,
 .device_uninit  = _device_uninit,
 .frames_get_constraints = _frames_get_constraints,
-- 
2.0.0

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel