Re: [libav-devel] [PATCH 11/14] h261dec: Convert to the new bitstream reader

2017-01-26 Thread Vittorio Giovara
On Thu, Jan 26, 2017 at 11:10 AM, Diego Biurrun  wrote:
> From: Alexandra Hájková 
>
> ---
>  libavcodec/h261dec.c   | 92 
> ++
>  libavcodec/mpegvideo.h |  3 ++
>  libavformat/h261dec.c  | 11 +++---
>  3 files changed, 56 insertions(+), 50 deletions(-)

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

[libav-devel] [PATCH 11/14] h261dec: Convert to the new bitstream reader

2017-01-26 Thread Diego Biurrun
From: Alexandra Hájková 

---
 libavcodec/h261dec.c   | 92 ++
 libavcodec/mpegvideo.h |  3 ++
 libavformat/h261dec.c  | 11 +++---
 3 files changed, 56 insertions(+), 50 deletions(-)

diff --git a/libavcodec/h261dec.c b/libavcodec/h261dec.c
index 9a323ec..b08598e 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