ffmpeg | branch: master | Alexandra Hájková <alexan...@khirnov.net> | Mon Apr 
18 10:38:43 2016 +0200| [2188d53906015ea5dd5b2e446f8e5374beacbffe] | committer: 
Anton Khirnov

g72x: Convert to the new bitstream reader

Signed-off-by: Anton Khirnov <an...@khirnov.net>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=2188d53906015ea5dd5b2e446f8e5374beacbffe
---

 libavcodec/g722dec.c   | 13 ++++-----
 libavcodec/g723_1dec.c | 72 +++++++++++++++++++++++++-------------------------
 libavcodec/g726.c      | 11 ++++----
 3 files changed, 49 insertions(+), 47 deletions(-)

diff --git a/libavcodec/g722dec.c b/libavcodec/g722dec.c
index c4c0ec8..bfd4b42 100644
--- a/libavcodec/g722dec.c
+++ b/libavcodec/g722dec.c
@@ -36,8 +36,9 @@
 
 #include "libavutil/channel_layout.h"
 #include "libavutil/opt.h"
+
 #include "avcodec.h"
-#include "get_bits.h"
+#include "bitstream.h"
 #include "g722.h"
 #include "internal.h"
 
@@ -92,7 +93,7 @@ static int g722_decode_frame(AVCodecContext *avctx, void 
*data,
     int j, ret;
     const int skip = 8 - c->bits_per_codeword;
     const int16_t *quantizer_table = low_inv_quants[skip];
-    GetBitContext gb;
+    BitstreamContext bc;
 
     /* get output buffer */
     frame->nb_samples = avpkt->size * 2;
@@ -102,15 +103,15 @@ static int g722_decode_frame(AVCodecContext *avctx, void 
*data,
     }
     out_buf = (int16_t *)frame->data[0];
 
-    init_get_bits(&gb, avpkt->data, avpkt->size * 8);
+    bitstream_init(&bc, avpkt->data, avpkt->size * 8);
 
     for (j = 0; j < avpkt->size; j++) {
         int ilow, ihigh, rlow, rhigh, dhigh;
         int xout[2];
 
-        ihigh = get_bits(&gb, 2);
-        ilow = get_bits(&gb, 6 - skip);
-        skip_bits(&gb, skip);
+        ihigh = bitstream_read(&bc, 2);
+        ilow  = bitstream_read(&bc, 6 - skip);
+        bitstream_skip(&bc, skip);
 
         rlow = av_clip_intp2((c->band[0].scale_factor * quantizer_table[ilow] 
>> 10)
                       + c->band[0].s_predictor, 14);
diff --git a/libavcodec/g723_1dec.c b/libavcodec/g723_1dec.c
index f50bed1..2ea3bbf 100644
--- a/libavcodec/g723_1dec.c
+++ b/libavcodec/g723_1dec.c
@@ -32,8 +32,8 @@
 #define BITSTREAM_READER_LE
 #include "acelp_vectors.h"
 #include "avcodec.h"
+#include "bitstream.h"
 #include "celp_filters.h"
-#include "get_bits.h"
 #include "internal.h"
 #include "g723_1.h"
 
@@ -68,14 +68,14 @@ static av_cold int g723_1_decode_init(AVCodecContext *avctx)
 static int unpack_bitstream(G723_1_Context *p, const uint8_t *buf,
                             int buf_size)
 {
-    GetBitContext gb;
+    BitstreamContext bc;
     int ad_cb_len;
     int temp, info_bits, i;
 
-    init_get_bits(&gb, buf, buf_size * 8);
+    bitstream_init(&bc, buf, buf_size * 8);
 
     /* Extract frame type and rate info */
-    info_bits = get_bits(&gb, 2);
+    info_bits = bitstream_read(&bc, 2);
 
     if (info_bits == 3) {
         p->cur_frame_type = UNTRANSMITTED_FRAME;
@@ -83,13 +83,13 @@ static int unpack_bitstream(G723_1_Context *p, const 
uint8_t *buf,
     }
 
     /* Extract 24 bit lsp indices, 8 bit for each band */
-    p->lsp_index[2] = get_bits(&gb, 8);
-    p->lsp_index[1] = get_bits(&gb, 8);
-    p->lsp_index[0] = get_bits(&gb, 8);
+    p->lsp_index[2] = bitstream_read(&bc, 8);
+    p->lsp_index[1] = bitstream_read(&bc, 8);
+    p->lsp_index[0] = bitstream_read(&bc, 8);
 
     if (info_bits == 2) {
         p->cur_frame_type = SID_FRAME;
-        p->subframe[0].amp_index = get_bits(&gb, 6);
+        p->subframe[0].amp_index = bitstream_read(&bc, 6);
         return 0;
     }
 
@@ -97,23 +97,23 @@ static int unpack_bitstream(G723_1_Context *p, const 
uint8_t *buf,
     p->cur_rate       = info_bits ? RATE_5300 : RATE_6300;
     p->cur_frame_type = ACTIVE_FRAME;
 
-    p->pitch_lag[0] = get_bits(&gb, 7);
+    p->pitch_lag[0] = bitstream_read(&bc, 7);
     if (p->pitch_lag[0] > 123)       /* test if forbidden code */
         return -1;
     p->pitch_lag[0] += PITCH_MIN;
-    p->subframe[1].ad_cb_lag = get_bits(&gb, 2);
+    p->subframe[1].ad_cb_lag = bitstream_read(&bc, 2);
 
-    p->pitch_lag[1] = get_bits(&gb, 7);
+    p->pitch_lag[1] = bitstream_read(&bc, 7);
     if (p->pitch_lag[1] > 123)
         return -1;
     p->pitch_lag[1] += PITCH_MIN;
-    p->subframe[3].ad_cb_lag = get_bits(&gb, 2);
+    p->subframe[3].ad_cb_lag = bitstream_read(&bc, 2);
     p->subframe[0].ad_cb_lag = 1;
     p->subframe[2].ad_cb_lag = 1;
 
     for (i = 0; i < SUBFRAMES; i++) {
         /* Extract combined gain */
-        temp = get_bits(&gb, 12);
+        temp = bitstream_read(&bc, 12);
         ad_cb_len = 170;
         p->subframe[i].dirac_train = 0;
         if (p->cur_rate == RATE_6300 && p->pitch_lag[i >> 1] < SUBFRAME_LEN - 
2) {
@@ -130,16 +130,16 @@ static int unpack_bitstream(G723_1_Context *p, const 
uint8_t *buf,
         }
     }
 
-    p->subframe[0].grid_index = get_bits(&gb, 1);
-    p->subframe[1].grid_index = get_bits(&gb, 1);
-    p->subframe[2].grid_index = get_bits(&gb, 1);
-    p->subframe[3].grid_index = get_bits(&gb, 1);
+    p->subframe[0].grid_index = bitstream_read(&bc, 1);
+    p->subframe[1].grid_index = bitstream_read(&bc, 1);
+    p->subframe[2].grid_index = bitstream_read(&bc, 1);
+    p->subframe[3].grid_index = bitstream_read(&bc, 1);
 
     if (p->cur_rate == RATE_6300) {
-        skip_bits(&gb, 1);  /* skip reserved bit */
+        bitstream_skip(&bc, 1); /* skip reserved bit */
 
         /* Compute pulse_pos index using the 13-bit combined position index */
-        temp = get_bits(&gb, 13);
+        temp = bitstream_read(&bc, 13);
         p->subframe[0].pulse_pos = temp / 810;
 
         temp -= p->subframe[0].pulse_pos * 810;
@@ -150,28 +150,28 @@ static int unpack_bitstream(G723_1_Context *p, const 
uint8_t *buf,
         p->subframe[3].pulse_pos = temp - p->subframe[2].pulse_pos * 9;
 
         p->subframe[0].pulse_pos = (p->subframe[0].pulse_pos << 16) +
-                                   get_bits(&gb, 16);
+                                   bitstream_read(&bc, 16);
         p->subframe[1].pulse_pos = (p->subframe[1].pulse_pos << 14) +
-                                   get_bits(&gb, 14);
+                                   bitstream_read(&bc, 14);
         p->subframe[2].pulse_pos = (p->subframe[2].pulse_pos << 16) +
-                                   get_bits(&gb, 16);
+                                   bitstream_read(&bc, 16);
         p->subframe[3].pulse_pos = (p->subframe[3].pulse_pos << 14) +
-                                   get_bits(&gb, 14);
+                                   bitstream_read(&bc, 14);
 
-        p->subframe[0].pulse_sign = get_bits(&gb, 6);
-        p->subframe[1].pulse_sign = get_bits(&gb, 5);
-        p->subframe[2].pulse_sign = get_bits(&gb, 6);
-        p->subframe[3].pulse_sign = get_bits(&gb, 5);
+        p->subframe[0].pulse_sign = bitstream_read(&bc, 6);
+        p->subframe[1].pulse_sign = bitstream_read(&bc, 5);
+        p->subframe[2].pulse_sign = bitstream_read(&bc, 6);
+        p->subframe[3].pulse_sign = bitstream_read(&bc, 5);
     } else { /* 5300 bps */
-        p->subframe[0].pulse_pos  = get_bits(&gb, 12);
-        p->subframe[1].pulse_pos  = get_bits(&gb, 12);
-        p->subframe[2].pulse_pos  = get_bits(&gb, 12);
-        p->subframe[3].pulse_pos  = get_bits(&gb, 12);
-
-        p->subframe[0].pulse_sign = get_bits(&gb, 4);
-        p->subframe[1].pulse_sign = get_bits(&gb, 4);
-        p->subframe[2].pulse_sign = get_bits(&gb, 4);
-        p->subframe[3].pulse_sign = get_bits(&gb, 4);
+        p->subframe[0].pulse_pos  = bitstream_read(&bc, 12);
+        p->subframe[1].pulse_pos  = bitstream_read(&bc, 12);
+        p->subframe[2].pulse_pos  = bitstream_read(&bc, 12);
+        p->subframe[3].pulse_pos  = bitstream_read(&bc, 12);
+
+        p->subframe[0].pulse_sign = bitstream_read(&bc, 4);
+        p->subframe[1].pulse_sign = bitstream_read(&bc, 4);
+        p->subframe[2].pulse_sign = bitstream_read(&bc, 4);
+        p->subframe[3].pulse_sign = bitstream_read(&bc, 4);
     }
 
     return 0;
diff --git a/libavcodec/g726.c b/libavcodec/g726.c
index e783e74..007cdb6 100644
--- a/libavcodec/g726.c
+++ b/libavcodec/g726.c
@@ -25,9 +25,10 @@
 
 #include "libavutil/channel_layout.h"
 #include "libavutil/opt.h"
+
 #include "avcodec.h"
+#include "bitstream.h"
 #include "internal.h"
-#include "get_bits.h"
 #include "put_bits.h"
 
 /**
@@ -429,7 +430,7 @@ static int g726_decode_frame(AVCodecContext *avctx, void 
*data,
     int buf_size = avpkt->size;
     G726Context *c = avctx->priv_data;
     int16_t *samples;
-    GetBitContext gb;
+    BitstreamContext bc;
     int out_samples, ret;
 
     out_samples = buf_size * 8 / c->code_size;
@@ -442,12 +443,12 @@ static int g726_decode_frame(AVCodecContext *avctx, void 
*data,
     }
     samples = (int16_t *)frame->data[0];
 
-    init_get_bits(&gb, buf, buf_size * 8);
+    bitstream_init(&bc, buf, buf_size * 8);
 
     while (out_samples--)
-        *samples++ = g726_decode(c, get_bits(&gb, c->code_size));
+        *samples++ = g726_decode(c, bitstream_read(&bc, c->code_size));
 
-    if (get_bits_left(&gb) > 0)
+    if (bitstream_bits_left(&bc) > 0)
         av_log(avctx, AV_LOG_ERROR, "Frame invalidly split, missing 
parser?\n");
 
     *got_frame_ptr = 1;

_______________________________________________
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

Reply via email to