Re: [libav-devel] [PATCH 08/14] shorten: 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/shorten.c | 49 +
>  1 file changed, 25 insertions(+), 24 deletions(-)

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

[libav-devel] [PATCH 08/14] shorten: Convert to the new bitstream reader

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

---
 libavcodec/shorten.c | 49 +
 1 file changed, 25 insertions(+), 24 deletions(-)

diff --git a/libavcodec/shorten.c b/libavcodec/shorten.c
index 82fa2ab..e040b9c 100644
--- a/libavcodec/shorten.c
+++ b/libavcodec/shorten.c
@@ -26,10 +26,11 @@
  */
 
 #include 
+
 #include "avcodec.h"
+#include "bitstream.h"
 #include "bytestream.h"
-#include "get_bits.h"
-#include "golomb_legacy.h"
+#include "golomb.h"
 #include "internal.h"
 
 #define MAX_CHANNELS 8
@@ -79,7 +80,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 +155,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 +281,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 +289,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 +316,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 +333,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 +341,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 +375,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 +388,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 +403,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 +465,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 +487,12 @@ static int