]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/escape130.c
mimic: Convert to the new bitstream reader
[ffmpeg] / libavcodec / escape130.c
index 22833d638ba576ed38995ba0c06b6f43db9dde5b..544f36d1ac0560f42ea9d0778d743a32e9ef0b38 100644 (file)
 
 #include "libavutil/attributes.h"
 #include "libavutil/mem.h"
-#include "avcodec.h"
+
 #define BITSTREAM_READER_LE
-#include "get_bits.h"
+#include "avcodec.h"
+#include "bitstream.h"
 #include "internal.h"
 
 typedef struct Escape130Context {
@@ -105,7 +106,7 @@ static const int8_t chroma_adjust[2][8] = {
     { 0, 1, 1,  1,  0, -1, -1, -1 }
 };
 
-const uint8_t chroma_vals[] = {
+static const uint8_t chroma_vals[] = {
      20,  28,  36,  44,  52,  60,  68,  76,
      84,  92, 100, 106, 112, 116, 120, 124,
     128, 132, 136, 140, 144, 150, 156, 164,
@@ -162,23 +163,23 @@ static av_cold int escape130_decode_close(AVCodecContext *avctx)
     return 0;
 }
 
-static int decode_skip_count(GetBitContext* gb)
+static int decode_skip_count(BitstreamContext *bc)
 {
     int value;
 
-    value = get_bits1(gb);
+    value = bitstream_read_bit(bc);
     if (value)
         return 0;
 
-    value = get_bits(gb, 3);
+    value = bitstream_read(bc, 3);
     if (value)
         return value;
 
-    value = get_bits(gb, 8);
+    value = bitstream_read(bc, 8);
     if (value)
         return value + 7;
 
-    value = get_bits(gb, 15);
+    value = bitstream_read(bc, 15);
     if (value)
         return value + 262;
 
@@ -192,7 +193,7 @@ static int escape130_decode_frame(AVCodecContext *avctx, void *data,
     int buf_size        = avpkt->size;
     Escape130Context *s = avctx->priv_data;
     AVFrame *pic        = data;
-    GetBitContext gb;
+    BitstreamContext bc;
     int ret;
 
     uint8_t *old_y, *old_cb, *old_cr,
@@ -215,7 +216,7 @@ static int escape130_decode_frame(AVCodecContext *avctx, void *data,
     if ((ret = ff_get_buffer(avctx, pic, 0)) < 0)
         return ret;
 
-    init_get_bits(&gb, buf + 16, (buf_size - 16) * 8);
+    bitstream_init(&bc, buf + 16, (buf_size - 16) * 8);
 
     new_y  = s->new_y;
     new_cb = s->new_u;
@@ -234,7 +235,7 @@ static int escape130_decode_frame(AVCodecContext *avctx, void *data,
         // Note that this call will make us skip the rest of the blocks
         // if the frame ends prematurely.
         if (skip == -1)
-            skip = decode_skip_count(&gb);
+            skip = decode_skip_count(&bc);
         if (skip == -1) {
             av_log(avctx, AV_LOG_ERROR, "Error decoding skip value\n");
             return AVERROR_INVALIDDATA;
@@ -249,31 +250,31 @@ static int escape130_decode_frame(AVCodecContext *avctx, void *data,
             cb = old_cb[0];
             cr = old_cr[0];
         } else {
-            if (get_bits1(&gb)) {
-                unsigned sign_selector       = get_bits(&gb, 6);
-                unsigned difference_selector = get_bits(&gb, 2);
-                y_avg = 2 * get_bits(&gb, 5);
+            if (bitstream_read_bit(&bc)) {
+                unsigned sign_selector       = bitstream_read(&bc, 6);
+                unsigned difference_selector = bitstream_read(&bc, 2);
+                y_avg = 2 * bitstream_read(&bc, 5);
                 for (i = 0; i < 4; i++) {
                     y[i] = av_clip(y_avg + offset_table[difference_selector] *
                                    sign_table[sign_selector][i], 0, 63);
                 }
-            } else if (get_bits1(&gb)) {
-                if (get_bits1(&gb)) {
-                    y_avg = get_bits(&gb, 6);
+            } else if (bitstream_read_bit(&bc)) {
+                if (bitstream_read_bit(&bc)) {
+                    y_avg = bitstream_read(&bc, 6);
                 } else {
-                    unsigned adjust_index = get_bits(&gb, 3);
+                    unsigned adjust_index = bitstream_read(&bc, 3);
                     y_avg = (y_avg + luma_adjust[adjust_index]) & 63;
                 }
                 for (i = 0; i < 4; i++)
                     y[i] = y_avg;
             }
 
-            if (get_bits1(&gb)) {
-                if (get_bits1(&gb)) {
-                    cb = get_bits(&gb, 5);
-                    cr = get_bits(&gb, 5);
+            if (bitstream_read_bit(&bc)) {
+                if (bitstream_read_bit(&bc)) {
+                    cb = bitstream_read(&bc, 5);
+                    cr = bitstream_read(&bc, 5);
                 } else {
-                    unsigned adjust_index = get_bits(&gb, 3);
+                    unsigned adjust_index = bitstream_read(&bc, 3);
                     cb = (cb + chroma_adjust[0][adjust_index]) & 31;
                     cr = (cr + chroma_adjust[1][adjust_index]) & 31;
                 }
@@ -332,7 +333,7 @@ static int escape130_decode_frame(AVCodecContext *avctx, void *data,
     }
 
     ff_dlog(avctx, "Frame data: provided %d bytes, used %d bytes\n",
-            buf_size, get_bits_count(&gb) >> 3);
+            buf_size, bitstream_tell(&bc) >> 3);
 
     FFSWAP(uint8_t*, s->old_y, s->new_y);
     FFSWAP(uint8_t*, s->old_u, s->new_u);
@@ -352,5 +353,5 @@ AVCodec ff_escape130_decoder = {
     .init           = escape130_decode_init,
     .close          = escape130_decode_close,
     .decode         = escape130_decode_frame,
-    .capabilities   = CODEC_CAP_DR1,
+    .capabilities   = AV_CODEC_CAP_DR1,
 };