[FFmpeg-cvslog] indeo: Convert to the new bitstream reader
Alexandra Hájková
git at videolan.org
Sun Apr 9 16:08:59 EEST 2017
ffmpeg | branch: master | Alexandra Hájková <alexandra at khirnov.net> | Mon Apr 18 10:49:08 2016 +0200| [c3defda0d80e19146e71c7adbdfd9c251f36d8bd] | committer: Diego Biurrun
indeo: Convert to the new bitstream reader
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=c3defda0d80e19146e71c7adbdfd9c251f36d8bd
---
libavcodec/indeo2.c | 16 +++---
libavcodec/indeo3.c | 19 ++++---
libavcodec/indeo4.c | 158 +++++++++++++++++++++++++++-------------------------
libavcodec/indeo5.c | 127 +++++++++++++++++++++--------------------
libavcodec/ivi.c | 71 ++++++++++++-----------
libavcodec/ivi.h | 11 ++--
6 files changed, 206 insertions(+), 196 deletions(-)
diff --git a/libavcodec/indeo2.c b/libavcodec/indeo2.c
index 3154e2314c..de2a9bb2f1 100644
--- a/libavcodec/indeo2.c
+++ b/libavcodec/indeo2.c
@@ -28,7 +28,7 @@
#define BITSTREAM_READER_LE
#include "avcodec.h"
-#include "get_bits.h"
+#include "bitstream.h"
#include "indeo2data.h"
#include "internal.h"
#include "mathops.h"
@@ -36,7 +36,7 @@
typedef struct Ir2Context{
AVCodecContext *avctx;
AVFrame *picture;
- GetBitContext gb;
+ BitstreamContext bc;
int decode_delta;
} Ir2Context;
@@ -44,9 +44,9 @@ typedef struct Ir2Context{
static VLC ir2_vlc;
/* Indeo 2 codes are in range 0x01..0x7F and 0x81..0x90 */
-static inline int ir2_get_code(GetBitContext *gb)
+static inline int ir2_get_code(BitstreamContext *bc)
{
- return get_vlc2(gb, ir2_vlc.table, CODE_VLC_BITS, 1) + 1;
+ return bitstream_read_vlc(bc, ir2_vlc.table, CODE_VLC_BITS, 1) + 1;
}
static int ir2_decode_plane(Ir2Context *ctx, int width, int height, uint8_t *dst,
@@ -63,7 +63,7 @@ static int ir2_decode_plane(Ir2Context *ctx, int width, int height, uint8_t *dst
/* first line contain absolute values, other lines contain deltas */
while (out < width) {
- c = ir2_get_code(&ctx->gb);
+ c = ir2_get_code(&ctx->bc);
if (c >= 0x80) { /* we have a run */
c -= 0x7F;
if (out + c*2 > width)
@@ -80,7 +80,7 @@ static int ir2_decode_plane(Ir2Context *ctx, int width, int height, uint8_t *dst
for (j = 1; j < height; j++) {
out = 0;
while (out < width) {
- c = ir2_get_code(&ctx->gb);
+ c = ir2_get_code(&ctx->bc);
if (c >= 0x80) { /* we have a skip */
c -= 0x7F;
if (out + c*2 > width)
@@ -119,7 +119,7 @@ static int ir2_decode_plane_inter(Ir2Context *ctx, int width, int height, uint8_
for (j = 0; j < height; j++) {
out = 0;
while (out < width) {
- c = ir2_get_code(&ctx->gb);
+ c = ir2_get_code(&ctx->bc);
if (c >= 0x80) { /* we have a skip */
c -= 0x7F;
out += c * 2;
@@ -171,7 +171,7 @@ static int ir2_decode_frame(AVCodecContext *avctx,
buf[i] = ff_reverse[buf[i]];
#endif
- init_get_bits(&s->gb, buf + start, (buf_size - start) * 8);
+ bitstream_init(&s->bc, buf + start, (buf_size - start) * 8);
ltab = buf[0x22] & 3;
ctab = buf[0x22] >> 2;
diff --git a/libavcodec/indeo3.c b/libavcodec/indeo3.c
index 314548f99a..1b5b6505d6 100644
--- a/libavcodec/indeo3.c
+++ b/libavcodec/indeo3.c
@@ -31,9 +31,10 @@
#include "libavutil/imgutils.h"
#include "libavutil/intreadwrite.h"
+
#include "avcodec.h"
+#include "bitstream.h"
#include "bytestream.h"
-#include "get_bits.h"
#include "hpeldsp.h"
#include "internal.h"
@@ -83,7 +84,7 @@ typedef struct Indeo3DecodeContext {
AVCodecContext *avctx;
HpelDSPContext hdsp;
- GetBitContext gb;
+ BitstreamContext bc;
int need_resync;
int skip_bits;
const uint8_t *next_cell_data;
@@ -725,8 +726,8 @@ enum {
ctx->need_resync = 1
#define RESYNC_BITSTREAM \
- if (ctx->need_resync && !(get_bits_count(&ctx->gb) & 7)) { \
- skip_bits_long(&ctx->gb, ctx->skip_bits); \
+ if (ctx->need_resync && !(bitstream_tell(&ctx->bc) & 7)) { \
+ bitstream_skip(&ctx->bc, ctx->skip_bits); \
ctx->skip_bits = 0; \
ctx->need_resync = 0; \
}
@@ -773,7 +774,7 @@ static int parse_bintree(Indeo3DecodeContext *ctx, AVCodecContext *avctx,
while (1) { /* loop until return */
RESYNC_BITSTREAM;
- switch (code = get_bits(&ctx->gb, 2)) {
+ switch (code = bitstream_read(&ctx->bc, 2)) {
case H_SPLIT:
case V_SPLIT:
if (parse_bintree(ctx, avctx, plane, code, &curr_cell, depth - 1, strip_width))
@@ -785,7 +786,7 @@ static int parse_bintree(Indeo3DecodeContext *ctx, AVCodecContext *avctx,
curr_cell.tree = 1; /* enter the VQ tree */
} else { /* VQ tree NULL code */
RESYNC_BITSTREAM;
- code = get_bits(&ctx->gb, 2);
+ code = bitstream_read(&ctx->bc, 2);
if (code >= 2) {
av_log(avctx, AV_LOG_ERROR, "Invalid VQ_NULL code: %d\n", code);
return AVERROR_INVALIDDATA;
@@ -805,7 +806,7 @@ static int parse_bintree(Indeo3DecodeContext *ctx, AVCodecContext *avctx,
unsigned mv_idx;
/* get motion vector index and setup the pointer to the mv set */
if (!ctx->need_resync)
- ctx->next_cell_data = &ctx->gb.buffer[(get_bits_count(&ctx->gb) + 7) >> 3];
+ ctx->next_cell_data = &ctx->bc.buffer[(bitstream_tell(&ctx->bc) + 7) >> 3];
mv_idx = *(ctx->next_cell_data++);
if (mv_idx >= ctx->num_vectors) {
av_log(avctx, AV_LOG_ERROR, "motion vector index out of range\n");
@@ -816,7 +817,7 @@ static int parse_bintree(Indeo3DecodeContext *ctx, AVCodecContext *avctx,
UPDATE_BITPOS(8);
} else { /* VQ tree DATA code */
if (!ctx->need_resync)
- ctx->next_cell_data = &ctx->gb.buffer[(get_bits_count(&ctx->gb) + 7) >> 3];
+ ctx->next_cell_data = &ctx->bc.buffer[(bitstream_tell(&ctx->bc) + 7) >> 3];
CHECK_CELL
bytes_used = decode_cell(ctx, avctx, plane, &curr_cell,
@@ -856,7 +857,7 @@ static int decode_plane(Indeo3DecodeContext *ctx, AVCodecContext *avctx,
ctx->mc_vectors = num_vectors ? data : 0;
/* init the bitreader */
- init_get_bits(&ctx->gb, &data[num_vectors * 2], (data_size - num_vectors * 2) << 3);
+ bitstream_init(&ctx->bc, &data[num_vectors * 2], (data_size - num_vectors * 2) << 3);
ctx->skip_bits = 0;
ctx->need_resync = 0;
diff --git a/libavcodec/indeo4.c b/libavcodec/indeo4.c
index ab42e7bca9..4b3f903e3b 100644
--- a/libavcodec/indeo4.c
+++ b/libavcodec/indeo4.c
@@ -29,7 +29,7 @@
#define BITSTREAM_READER_LE
#include "avcodec.h"
-#include "get_bits.h"
+#include "bitstream.h"
#include "indeo4data.h"
#include "internal.h"
#include "ivi.h"
@@ -70,19 +70,19 @@ static const struct {
* - 4 wavelet bands per plane, size factor 1:4, code pattern: 2,3,3,3,3
* Anything else is either unsupported or corrupt.
*
- * @param[in,out] gb the GetBit context
+ * @param[in,out] bc the Bitstream context
* @return number of wavelet bands or 0 on error
*/
-static int decode_plane_subdivision(GetBitContext *gb)
+static int decode_plane_subdivision(BitstreamContext *bc)
{
int i;
- switch (get_bits(gb, 2)) {
+ switch (bitstream_read(bc, 2)) {
case 3:
return 1;
case 2:
for (i = 0; i < 4; i++)
- if (get_bits(gb, 2) != 3)
+ if (bitstream_read(bc, 2) != 3)
return 0;
return 4;
default:
@@ -107,13 +107,13 @@ static int decode_pic_hdr(IVI45DecContext *ctx, AVCodecContext *avctx)
int pic_size_indx, i, p;
IVIPicConfig pic_conf;
- if (get_bits(&ctx->gb, 18) != 0x3FFF8) {
+ if (bitstream_read(&ctx->bc, 18) != 0x3FFF8) {
av_log(avctx, AV_LOG_ERROR, "Invalid picture start code!\n");
return AVERROR_INVALIDDATA;
}
ctx->prev_frame_type = ctx->frame_type;
- ctx->frame_type = get_bits(&ctx->gb, 3);
+ ctx->frame_type = bitstream_read(&ctx->bc, 3);
if (ctx->frame_type == 7) {
av_log(avctx, AV_LOG_ERROR, "Invalid frame type: %d\n", ctx->frame_type);
return AVERROR_INVALIDDATA;
@@ -122,15 +122,15 @@ static int decode_pic_hdr(IVI45DecContext *ctx, AVCodecContext *avctx)
if (ctx->frame_type == IVI4_FRAMETYPE_BIDIR)
ctx->has_b_frames = 1;
- ctx->has_transp = get_bits1(&ctx->gb);
+ ctx->has_transp = bitstream_read_bit(&ctx->bc);
/* unknown bit: Mac decoder ignores this bit, XANIM returns error */
- if (get_bits1(&ctx->gb)) {
+ if (bitstream_read_bit(&ctx->bc)) {
av_log(avctx, AV_LOG_ERROR, "Sync bit is set!\n");
return AVERROR_INVALIDDATA;
}
- ctx->data_size = get_bits1(&ctx->gb) ? get_bits(&ctx->gb, 24) : 0;
+ ctx->data_size = bitstream_read_bit(&ctx->bc) ? bitstream_read(&ctx->bc, 24) : 0;
/* null frames don't contain anything else so we just return */
if (ctx->frame_type >= IVI4_FRAMETYPE_NULL_FIRST) {
@@ -141,32 +141,32 @@ static int decode_pic_hdr(IVI45DecContext *ctx, AVCodecContext *avctx)
/* Check key lock status. If enabled - ignore lock word. */
/* Usually we have to prompt the user for the password, but */
/* we don't do that because Indeo 4 videos can be decoded anyway */
- if (get_bits1(&ctx->gb)) {
- skip_bits_long(&ctx->gb, 32);
+ if (bitstream_read_bit(&ctx->bc)) {
+ bitstream_skip(&ctx->bc, 32);
ff_dlog(avctx, "Password-protected clip!\n");
}
- pic_size_indx = get_bits(&ctx->gb, 3);
+ pic_size_indx = bitstream_read(&ctx->bc, 3);
if (pic_size_indx == IVI4_PIC_SIZE_ESC) {
- pic_conf.pic_height = get_bits(&ctx->gb, 16);
- pic_conf.pic_width = get_bits(&ctx->gb, 16);
+ pic_conf.pic_height = bitstream_read(&ctx->bc, 16);
+ pic_conf.pic_width = bitstream_read(&ctx->bc, 16);
} else {
pic_conf.pic_height = ivi4_common_pic_sizes[pic_size_indx * 2 + 1];
pic_conf.pic_width = ivi4_common_pic_sizes[pic_size_indx * 2 ];
}
/* Decode tile dimensions. */
- ctx->uses_tiling = get_bits1(&ctx->gb);
+ ctx->uses_tiling = bitstream_read_bit(&ctx->bc);
if (ctx->uses_tiling) {
- pic_conf.tile_height = scale_tile_size(pic_conf.pic_height, get_bits(&ctx->gb, 4));
- pic_conf.tile_width = scale_tile_size(pic_conf.pic_width, get_bits(&ctx->gb, 4));
+ pic_conf.tile_height = scale_tile_size(pic_conf.pic_height, bitstream_read(&ctx->bc, 4));
+ pic_conf.tile_width = scale_tile_size(pic_conf.pic_width, bitstream_read(&ctx->bc, 4));
} else {
pic_conf.tile_height = pic_conf.pic_height;
pic_conf.tile_width = pic_conf.pic_width;
}
/* Decode chroma subsampling. We support only 4:4 aka YVU9. */
- if (get_bits(&ctx->gb, 2)) {
+ if (bitstream_read(&ctx->bc, 2)) {
av_log(avctx, AV_LOG_ERROR, "Only YVU9 picture format is supported!\n");
return AVERROR_INVALIDDATA;
}
@@ -174,9 +174,9 @@ static int decode_pic_hdr(IVI45DecContext *ctx, AVCodecContext *avctx)
pic_conf.chroma_width = (pic_conf.pic_width + 3) >> 2;
/* decode subdivision of the planes */
- pic_conf.luma_bands = decode_plane_subdivision(&ctx->gb);
+ pic_conf.luma_bands = decode_plane_subdivision(&ctx->bc);
if (pic_conf.luma_bands)
- pic_conf.chroma_bands = decode_plane_subdivision(&ctx->gb);
+ pic_conf.chroma_bands = decode_plane_subdivision(&ctx->bc);
ctx->is_scalable = pic_conf.luma_bands != 1 || pic_conf.chroma_bands != 1;
if (ctx->is_scalable && (pic_conf.luma_bands != 4 || pic_conf.chroma_bands != 1)) {
av_log(avctx, AV_LOG_ERROR, "Scalability: unsupported subdivision! Luma bands: %d, chroma bands: %d\n",
@@ -210,40 +210,40 @@ static int decode_pic_hdr(IVI45DecContext *ctx, AVCodecContext *avctx)
}
}
- ctx->frame_num = get_bits1(&ctx->gb) ? get_bits(&ctx->gb, 20) : 0;
+ ctx->frame_num = bitstream_read_bit(&ctx->bc) ? bitstream_read(&ctx->bc, 20) : 0;
/* skip decTimeEst field if present */
- if (get_bits1(&ctx->gb))
- skip_bits(&ctx->gb, 8);
+ if (bitstream_read_bit(&ctx->bc))
+ bitstream_skip(&ctx->bc, 8);
/* decode macroblock and block huffman codebooks */
- if (ff_ivi_dec_huff_desc(&ctx->gb, get_bits1(&ctx->gb), IVI_MB_HUFF, &ctx->mb_vlc, avctx) ||
- ff_ivi_dec_huff_desc(&ctx->gb, get_bits1(&ctx->gb), IVI_BLK_HUFF, &ctx->blk_vlc, avctx))
+ if (ff_ivi_dec_huff_desc(&ctx->bc, bitstream_read_bit(&ctx->bc), IVI_MB_HUFF, &ctx->mb_vlc, avctx) ||
+ ff_ivi_dec_huff_desc(&ctx->bc, bitstream_read_bit(&ctx->bc), IVI_BLK_HUFF, &ctx->blk_vlc, avctx))
return AVERROR_INVALIDDATA;
- ctx->rvmap_sel = get_bits1(&ctx->gb) ? get_bits(&ctx->gb, 3) : 8;
+ ctx->rvmap_sel = bitstream_read_bit(&ctx->bc) ? bitstream_read(&ctx->bc, 3) : 8;
- ctx->in_imf = get_bits1(&ctx->gb);
- ctx->in_q = get_bits1(&ctx->gb);
+ ctx->in_imf = bitstream_read_bit(&ctx->bc);
+ ctx->in_q = bitstream_read_bit(&ctx->bc);
- ctx->pic_glob_quant = get_bits(&ctx->gb, 5);
+ ctx->pic_glob_quant = bitstream_read(&ctx->bc, 5);
/* TODO: ignore this parameter if unused */
- ctx->unknown1 = get_bits1(&ctx->gb) ? get_bits(&ctx->gb, 3) : 0;
+ ctx->unknown1 = bitstream_read_bit(&ctx->bc) ? bitstream_read(&ctx->bc, 3) : 0;
- ctx->checksum = get_bits1(&ctx->gb) ? get_bits(&ctx->gb, 16) : 0;
+ ctx->checksum = bitstream_read_bit(&ctx->bc) ? bitstream_read(&ctx->bc, 16) : 0;
/* skip picture header extension if any */
- while (get_bits1(&ctx->gb)) {
+ while (bitstream_read_bit(&ctx->bc)) {
ff_dlog(avctx, "Pic hdr extension encountered!\n");
- skip_bits(&ctx->gb, 8);
+ bitstream_skip(&ctx->bc, 8);
}
- if (get_bits1(&ctx->gb)) {
+ if (bitstream_read_bit(&ctx->bc)) {
av_log(avctx, AV_LOG_ERROR, "Bad blocks bits encountered!\n");
}
- align_get_bits(&ctx->gb);
+ bitstream_align(&ctx->bc);
return 0;
}
@@ -263,22 +263,22 @@ static int decode_band_hdr(IVI45DecContext *ctx, IVIBandDesc *band,
int plane, band_num, indx, transform_id, scan_indx;
int i;
- plane = get_bits(&ctx->gb, 2);
- band_num = get_bits(&ctx->gb, 4);
+ plane = bitstream_read(&ctx->bc, 2);
+ band_num = bitstream_read(&ctx->bc, 4);
if (band->plane != plane || band->band_num != band_num) {
av_log(avctx, AV_LOG_ERROR, "Invalid band header sequence!\n");
return AVERROR_INVALIDDATA;
}
- band->is_empty = get_bits1(&ctx->gb);
+ band->is_empty = bitstream_read_bit(&ctx->bc);
if (!band->is_empty) {
int old_blk_size = band->blk_size;
/* skip header size
* If header size is not given, header size is 4 bytes. */
- if (get_bits1(&ctx->gb))
- skip_bits(&ctx->gb, 16);
+ if (bitstream_read_bit(&ctx->bc))
+ bitstream_skip(&ctx->bc, 16);
- band->is_halfpel = get_bits(&ctx->gb, 2);
+ band->is_halfpel = bitstream_read(&ctx->bc, 2);
if (band->is_halfpel >= 2) {
av_log(avctx, AV_LOG_ERROR, "Invalid/unsupported mv resolution: %d!\n",
band->is_halfpel);
@@ -287,11 +287,11 @@ static int decode_band_hdr(IVI45DecContext *ctx, IVIBandDesc *band,
if (!band->is_halfpel)
ctx->uses_fullpel = 1;
- band->checksum_present = get_bits1(&ctx->gb);
+ band->checksum_present = bitstream_read_bit(&ctx->bc);
if (band->checksum_present)
- band->checksum = get_bits(&ctx->gb, 16);
+ band->checksum = bitstream_read(&ctx->bc, 16);
- indx = get_bits(&ctx->gb, 2);
+ indx = bitstream_read(&ctx->bc, 2);
if (indx == 3) {
av_log(avctx, AV_LOG_ERROR, "Invalid block size!\n");
return AVERROR_INVALIDDATA;
@@ -299,13 +299,13 @@ static int decode_band_hdr(IVI45DecContext *ctx, IVIBandDesc *band,
band->mb_size = 16 >> indx;
band->blk_size = 8 >> (indx >> 1);
- band->inherit_mv = get_bits1(&ctx->gb);
- band->inherit_qdelta = get_bits1(&ctx->gb);
+ band->inherit_mv = bitstream_read_bit(&ctx->bc);
+ band->inherit_qdelta = bitstream_read_bit(&ctx->bc);
- band->glob_quant = get_bits(&ctx->gb, 5);
+ band->glob_quant = bitstream_read(&ctx->bc, 5);
- if (!get_bits1(&ctx->gb) || ctx->frame_type == IVI4_FRAMETYPE_INTRA) {
- transform_id = get_bits(&ctx->gb, 5);
+ if (!bitstream_read_bit(&ctx->bc) || ctx->frame_type == IVI4_FRAMETYPE_INTRA) {
+ transform_id = bitstream_read(&ctx->bc, 5);
if (transform_id >= FF_ARRAY_ELEMS(transforms) ||
!transforms[transform_id].inv_trans) {
avpriv_request_sample(avctx, "Transform %d", transform_id);
@@ -331,7 +331,7 @@ static int decode_band_hdr(IVI45DecContext *ctx, IVIBandDesc *band,
if (band->blk_size != band->transform_size)
return AVERROR_INVALIDDATA;
- scan_indx = get_bits(&ctx->gb, 4);
+ scan_indx = bitstream_read(&ctx->bc, 4);
if (scan_indx == 15) {
av_log(avctx, AV_LOG_ERROR, "Custom scan pattern encountered!\n");
return AVERROR_INVALIDDATA;
@@ -344,7 +344,7 @@ static int decode_band_hdr(IVI45DecContext *ctx, IVIBandDesc *band,
band->scan = scan_index_to_tab[scan_indx];
- band->quant_mat = get_bits(&ctx->gb, 5);
+ band->quant_mat = bitstream_read(&ctx->bc, 5);
if (band->quant_mat >= FF_ARRAY_ELEMS(quant_index_to_tab)) {
if (band->quant_mat == 31)
@@ -370,20 +370,20 @@ static int decode_band_hdr(IVI45DecContext *ctx, IVIBandDesc *band,
}
/* decode block huffman codebook */
- if (!get_bits1(&ctx->gb))
+ if (!bitstream_read_bit(&ctx->bc))
band->blk_vlc.tab = ctx->blk_vlc.tab;
else
- if (ff_ivi_dec_huff_desc(&ctx->gb, 1, IVI_BLK_HUFF,
+ if (ff_ivi_dec_huff_desc(&ctx->bc, 1, IVI_BLK_HUFF,
&band->blk_vlc, avctx))
return AVERROR_INVALIDDATA;
/* select appropriate rvmap table for this band */
- band->rvmap_sel = get_bits1(&ctx->gb) ? get_bits(&ctx->gb, 3) : 8;
+ band->rvmap_sel = bitstream_read_bit(&ctx->bc) ? bitstream_read(&ctx->bc, 3) : 8;
/* decode rvmap probability corrections if any */
band->num_corr = 0; /* there is no corrections */
- if (get_bits1(&ctx->gb)) {
- band->num_corr = get_bits(&ctx->gb, 8); /* get number of correction pairs */
+ if (bitstream_read_bit(&ctx->bc)) {
+ band->num_corr = bitstream_read(&ctx->bc, 8); /* get number of correction pairs */
if (band->num_corr > 61) {
av_log(avctx, AV_LOG_ERROR, "Too many corrections: %d\n",
band->num_corr);
@@ -392,7 +392,7 @@ static int decode_band_hdr(IVI45DecContext *ctx, IVIBandDesc *band,
/* read correction pairs */
for (i = 0; i < band->num_corr * 2; i++)
- band->corr[i] = get_bits(&ctx->gb, 8);
+ band->corr[i] = bitstream_read(&ctx->bc, 8);
}
}
@@ -408,7 +408,7 @@ static int decode_band_hdr(IVI45DecContext *ctx, IVIBandDesc *band,
band->intra_scale = NULL;
band->inter_scale = NULL;
- align_get_bits(&ctx->gb);
+ bitstream_align(&ctx->bc);
return 0;
}
@@ -453,7 +453,7 @@ static int decode_mb_info(IVI45DecContext *ctx, IVIBandDesc *band,
mb->b_mv_x =
mb->b_mv_y = 0;
- if (get_bits1(&ctx->gb)) {
+ if (bitstream_read_bit(&ctx->bc)) {
if (ctx->frame_type == IVI4_FRAMETYPE_INTRA) {
av_log(avctx, AV_LOG_ERROR, "Empty macroblock in an INTRA picture!\n");
return AVERROR_INVALIDDATA;
@@ -463,8 +463,9 @@ static int decode_mb_info(IVI45DecContext *ctx, IVIBandDesc *band,
mb->q_delta = 0;
if (!band->plane && !band->band_num && ctx->in_q) {
- mb->q_delta = get_vlc2(&ctx->gb, ctx->mb_vlc.tab->table,
- IVI_VLC_BITS, 1);
+ mb->q_delta = bitstream_read_vlc(&ctx->bc,
+ ctx->mb_vlc.tab->table,
+ IVI_VLC_BITS, 1);
mb->q_delta = IVI_TOSIGNED(mb->q_delta);
}
@@ -489,18 +490,19 @@ static int decode_mb_info(IVI45DecContext *ctx, IVIBandDesc *band,
ctx->frame_type == IVI4_FRAMETYPE_INTRA1) {
mb->type = 0; /* mb_type is always INTRA for intra-frames */
} else {
- mb->type = get_bits(&ctx->gb, mb_type_bits);
+ mb->type = bitstream_read(&ctx->bc, mb_type_bits);
}
- mb->cbp = get_bits(&ctx->gb, blks_per_mb);
+ mb->cbp = bitstream_read(&ctx->bc, blks_per_mb);
mb->q_delta = 0;
if (band->inherit_qdelta) {
if (ref_mb) mb->q_delta = ref_mb->q_delta;
} else if (mb->cbp || (!band->plane && !band->band_num &&
ctx->in_q)) {
- mb->q_delta = get_vlc2(&ctx->gb, ctx->mb_vlc.tab->table,
- IVI_VLC_BITS, 1);
+ mb->q_delta = bitstream_read_vlc(&ctx->bc,
+ ctx->mb_vlc.tab->table,
+ IVI_VLC_BITS, 1);
mb->q_delta = IVI_TOSIGNED(mb->q_delta);
}
@@ -519,22 +521,24 @@ static int decode_mb_info(IVI45DecContext *ctx, IVIBandDesc *band,
}
} else {
/* decode motion vector deltas */
- mv_delta = get_vlc2(&ctx->gb, ctx->mb_vlc.tab->table,
- IVI_VLC_BITS, 1);
+ mv_delta = bitstream_read_vlc(&ctx->bc,
+ ctx->mb_vlc.tab->table,
+ IVI_VLC_BITS, 1);
mv_y += IVI_TOSIGNED(mv_delta);
- mv_delta = get_vlc2(&ctx->gb, ctx->mb_vlc.tab->table,
- IVI_VLC_BITS, 1);
+ mv_delta = bitstream_read_vlc(&ctx->bc,
+ ctx->mb_vlc.tab->table,
+ IVI_VLC_BITS, 1);
mv_x += IVI_TOSIGNED(mv_delta);
mb->mv_x = mv_x;
mb->mv_y = mv_y;
if (mb->type == 3) {
- mv_delta = get_vlc2(&ctx->gb,
- ctx->mb_vlc.tab->table,
- IVI_VLC_BITS, 1);
+ mv_delta = bitstream_read_vlc(&ctx->bc,
+ ctx->mb_vlc.tab->table,
+ IVI_VLC_BITS, 1);
mv_y += IVI_TOSIGNED(mv_delta);
- mv_delta = get_vlc2(&ctx->gb,
- ctx->mb_vlc.tab->table,
- IVI_VLC_BITS, 1);
+ mv_delta = bitstream_read_vlc(&ctx->bc,
+ ctx->mb_vlc.tab->table,
+ IVI_VLC_BITS, 1);
mv_x += IVI_TOSIGNED(mv_delta);
mb->b_mv_x = -mv_x;
mb->b_mv_y = -mv_y;
@@ -558,7 +562,7 @@ static int decode_mb_info(IVI45DecContext *ctx, IVIBandDesc *band,
offs += row_offset;
}
- align_get_bits(&ctx->gb);
+ bitstream_align(&ctx->bc);
return 0;
}
diff --git a/libavcodec/indeo5.c b/libavcodec/indeo5.c
index bed915370a..70ae1d324b 100644
--- a/libavcodec/indeo5.c
+++ b/libavcodec/indeo5.c
@@ -29,7 +29,7 @@
#define BITSTREAM_READER_LE
#include "avcodec.h"
-#include "get_bits.h"
+#include "bitstream.h"
#include "ivi.h"
#include "ivi_dsp.h"
#include "indeo5data.h"
@@ -63,14 +63,14 @@ static int decode_gop_header(IVI45DecContext *ctx, AVCodecContext *avctx)
IVIBandDesc *band, *band1, *band2;
IVIPicConfig pic_conf;
- ctx->gop_flags = get_bits(&ctx->gb, 8);
+ ctx->gop_flags = bitstream_read(&ctx->bc, 8);
- ctx->gop_hdr_size = (ctx->gop_flags & 1) ? get_bits(&ctx->gb, 16) : 0;
+ ctx->gop_hdr_size = (ctx->gop_flags & 1) ? bitstream_read(&ctx->bc, 16) : 0;
if (ctx->gop_flags & IVI5_IS_PROTECTED)
- ctx->lock_word = get_bits_long(&ctx->gb, 32);
+ ctx->lock_word = bitstream_read(&ctx->bc, 32);
- tile_size = (ctx->gop_flags & 0x40) ? 64 << get_bits(&ctx->gb, 2) : 0;
+ tile_size = (ctx->gop_flags & 0x40) ? 64 << bitstream_read(&ctx->bc, 2) : 0;
if (tile_size > 256) {
av_log(avctx, AV_LOG_ERROR, "Invalid tile size: %d\n", tile_size);
return AVERROR_INVALIDDATA;
@@ -78,8 +78,8 @@ static int decode_gop_header(IVI45DecContext *ctx, AVCodecContext *avctx)
/* decode number of wavelet bands */
/* num_levels * 3 + 1 */
- pic_conf.luma_bands = get_bits(&ctx->gb, 2) * 3 + 1;
- pic_conf.chroma_bands = get_bits1(&ctx->gb) * 3 + 1;
+ pic_conf.luma_bands = bitstream_read(&ctx->bc, 2) * 3 + 1;
+ pic_conf.chroma_bands = bitstream_read_bit(&ctx->bc) * 3 + 1;
ctx->is_scalable = pic_conf.luma_bands != 1 || pic_conf.chroma_bands != 1;
if (ctx->is_scalable && (pic_conf.luma_bands != 4 || pic_conf.chroma_bands != 1)) {
av_log(avctx, AV_LOG_ERROR, "Scalability: unsupported subdivision! Luma bands: %d, chroma bands: %d\n",
@@ -87,10 +87,10 @@ static int decode_gop_header(IVI45DecContext *ctx, AVCodecContext *avctx)
return AVERROR_INVALIDDATA;
}
- pic_size_indx = get_bits(&ctx->gb, 4);
+ pic_size_indx = bitstream_read(&ctx->bc, 4);
if (pic_size_indx == IVI5_PIC_SIZE_ESC) {
- pic_conf.pic_height = get_bits(&ctx->gb, 13);
- pic_conf.pic_width = get_bits(&ctx->gb, 13);
+ pic_conf.pic_height = bitstream_read(&ctx->bc, 13);
+ pic_conf.pic_width = bitstream_read(&ctx->bc, 13);
} else {
pic_conf.pic_height = ivi5_common_pic_sizes[pic_size_indx * 2 + 1] << 2;
pic_conf.pic_width = ivi5_common_pic_sizes[pic_size_indx * 2 ] << 2;
@@ -126,10 +126,10 @@ static int decode_gop_header(IVI45DecContext *ctx, AVCodecContext *avctx)
for (i = 0; i < (!p ? pic_conf.luma_bands : pic_conf.chroma_bands); i++) {
band = &ctx->planes[p].bands[i];
- band->is_halfpel = get_bits1(&ctx->gb);
+ band->is_halfpel = bitstream_read_bit(&ctx->bc);
- mb_size = get_bits1(&ctx->gb);
- blk_size = 8 >> get_bits1(&ctx->gb);
+ mb_size = bitstream_read_bit(&ctx->bc);
+ blk_size = 8 >> bitstream_read_bit(&ctx->bc);
mb_size = blk_size << !mb_size;
blk_size_changed = mb_size != band->mb_size || blk_size != band->blk_size;
@@ -138,7 +138,7 @@ static int decode_gop_header(IVI45DecContext *ctx, AVCodecContext *avctx)
band->blk_size = blk_size;
}
- if (get_bits1(&ctx->gb)) {
+ if (bitstream_read_bit(&ctx->bc)) {
avpriv_report_missing_feature(avctx, "Extended transform info");
return AVERROR_PATCHWELCOME;
}
@@ -206,7 +206,7 @@ static int decode_gop_header(IVI45DecContext *ctx, AVCodecContext *avctx)
band->inter_scale = ivi5_scale_quant_4x4_inter;
}
- if (get_bits(&ctx->gb, 2)) {
+ if (bitstream_read(&ctx->bc, 2)) {
av_log(avctx, AV_LOG_ERROR, "End marker missing!\n");
return AVERROR_INVALIDDATA;
}
@@ -245,27 +245,27 @@ static int decode_gop_header(IVI45DecContext *ctx, AVCodecContext *avctx)
}
if (ctx->gop_flags & 8) {
- if (get_bits(&ctx->gb, 3)) {
+ if (bitstream_read(&ctx->bc, 3)) {
av_log(avctx, AV_LOG_ERROR, "Alignment bits are not zero!\n");
return AVERROR_INVALIDDATA;
}
- if (get_bits1(&ctx->gb))
- skip_bits_long(&ctx->gb, 24); /* skip transparency fill color */
+ if (bitstream_read_bit(&ctx->bc))
+ bitstream_skip(&ctx->bc, 24); /* skip transparency fill color */
}
- align_get_bits(&ctx->gb);
+ bitstream_align(&ctx->bc);
- skip_bits(&ctx->gb, 23); /* FIXME: unknown meaning */
+ bitstream_skip(&ctx->bc, 23); /* FIXME: unknown meaning */
/* skip GOP extension if any */
- if (get_bits1(&ctx->gb)) {
+ if (bitstream_read_bit(&ctx->bc)) {
do {
- i = get_bits(&ctx->gb, 16);
+ i = bitstream_read(&ctx->bc, 16);
} while (i & 0x8000);
}
- align_get_bits(&ctx->gb);
+ bitstream_align(&ctx->bc);
return 0;
}
@@ -274,15 +274,16 @@ static int decode_gop_header(IVI45DecContext *ctx, AVCodecContext *avctx)
/**
* Skip a header extension.
*
- * @param[in,out] gb the GetBit context
+ * @param[in,out] bc the Bitstream context
*/
-static inline void skip_hdr_extension(GetBitContext *gb)
+static inline void skip_hdr_extension(BitstreamContext *bc)
{
int i, len;
do {
- len = get_bits(gb, 8);
- for (i = 0; i < len; i++) skip_bits(gb, 8);
+ len = bitstream_read(bc, 8);
+ for (i = 0; i < len; i++)
+ bitstream_skip(bc, 8);
} while(len);
}
@@ -298,19 +299,19 @@ static int decode_pic_hdr(IVI45DecContext *ctx, AVCodecContext *avctx)
{
int ret;
- if (get_bits(&ctx->gb, 5) != 0x1F) {
+ if (bitstream_read(&ctx->bc, 5) != 0x1F) {
av_log(avctx, AV_LOG_ERROR, "Invalid picture start code!\n");
return AVERROR_INVALIDDATA;
}
ctx->prev_frame_type = ctx->frame_type;
- ctx->frame_type = get_bits(&ctx->gb, 3);
+ ctx->frame_type = bitstream_read(&ctx->bc, 3);
if (ctx->frame_type >= 5) {
av_log(avctx, AV_LOG_ERROR, "Invalid frame type: %d \n", ctx->frame_type);
return AVERROR_INVALIDDATA;
}
- ctx->frame_num = get_bits(&ctx->gb, 8);
+ ctx->frame_num = bitstream_read(&ctx->bc, 8);
if (ctx->frame_type == FRAMETYPE_INTRA) {
if ((ret = decode_gop_header(ctx, avctx)) < 0) {
@@ -322,26 +323,26 @@ static int decode_pic_hdr(IVI45DecContext *ctx, AVCodecContext *avctx)
}
if (ctx->frame_type != FRAMETYPE_NULL) {
- ctx->frame_flags = get_bits(&ctx->gb, 8);
+ ctx->frame_flags = bitstream_read(&ctx->bc, 8);
- ctx->pic_hdr_size = (ctx->frame_flags & 1) ? get_bits_long(&ctx->gb, 24) : 0;
+ ctx->pic_hdr_size = (ctx->frame_flags & 1) ? bitstream_read(&ctx->bc, 24) : 0;
- ctx->checksum = (ctx->frame_flags & 0x10) ? get_bits(&ctx->gb, 16) : 0;
+ ctx->checksum = (ctx->frame_flags & 0x10) ? bitstream_read(&ctx->bc, 16) : 0;
/* skip unknown extension if any */
if (ctx->frame_flags & 0x20)
- skip_hdr_extension(&ctx->gb); /* XXX: untested */
+ skip_hdr_extension(&ctx->bc); /* XXX: untested */
/* decode macroblock huffman codebook */
- ret = ff_ivi_dec_huff_desc(&ctx->gb, ctx->frame_flags & 0x40,
+ ret = ff_ivi_dec_huff_desc(&ctx->bc, ctx->frame_flags & 0x40,
IVI_MB_HUFF, &ctx->mb_vlc, avctx);
if (ret < 0)
return ret;
- skip_bits(&ctx->gb, 3); /* FIXME: unknown meaning! */
+ bitstream_skip(&ctx->bc, 3); /* FIXME: unknown meaning! */
}
- align_get_bits(&ctx->gb);
+ bitstream_align(&ctx->bc);
return 0;
}
@@ -361,14 +362,14 @@ static int decode_band_hdr(IVI45DecContext *ctx, IVIBandDesc *band,
int i, ret;
uint8_t band_flags;
- band_flags = get_bits(&ctx->gb, 8);
+ band_flags = bitstream_read(&ctx->bc, 8);
if (band_flags & 1) {
band->is_empty = 1;
return 0;
}
- band->data_size = (ctx->frame_flags & 0x80) ? get_bits_long(&ctx->gb, 24) : 0;
+ band->data_size = (ctx->frame_flags & 0x80) ? bitstream_read(&ctx->bc, 24) : 0;
band->inherit_mv = band_flags & 2;
band->inherit_qdelta = band_flags & 8;
@@ -378,7 +379,7 @@ static int decode_band_hdr(IVI45DecContext *ctx, IVIBandDesc *band,
/* decode rvmap probability corrections if any */
band->num_corr = 0; /* there are no corrections */
if (band_flags & 0x10) {
- band->num_corr = get_bits(&ctx->gb, 8); /* get number of correction pairs */
+ band->num_corr = bitstream_read(&ctx->bc, 8); /* get number of correction pairs */
if (band->num_corr > 61) {
av_log(avctx, AV_LOG_ERROR, "Too many corrections: %d\n",
band->num_corr);
@@ -387,31 +388,31 @@ static int decode_band_hdr(IVI45DecContext *ctx, IVIBandDesc *band,
/* read correction pairs */
for (i = 0; i < band->num_corr * 2; i++)
- band->corr[i] = get_bits(&ctx->gb, 8);
+ band->corr[i] = bitstream_read(&ctx->bc, 8);
}
/* select appropriate rvmap table for this band */
- band->rvmap_sel = (band_flags & 0x40) ? get_bits(&ctx->gb, 3) : 8;
+ band->rvmap_sel = (band_flags & 0x40) ? bitstream_read(&ctx->bc, 3) : 8;
/* decode block huffman codebook */
- ret = ff_ivi_dec_huff_desc(&ctx->gb, band_flags & 0x80, IVI_BLK_HUFF,
+ ret = ff_ivi_dec_huff_desc(&ctx->bc, band_flags & 0x80, IVI_BLK_HUFF,
&band->blk_vlc, avctx);
if (ret < 0)
return ret;
- band->checksum_present = get_bits1(&ctx->gb);
+ band->checksum_present = bitstream_read_bit(&ctx->bc);
if (band->checksum_present)
- band->checksum = get_bits(&ctx->gb, 16);
+ band->checksum = bitstream_read(&ctx->bc, 16);
- band->glob_quant = get_bits(&ctx->gb, 5);
+ band->glob_quant = bitstream_read(&ctx->bc, 5);
/* skip unknown extension if any */
if (band_flags & 0x20) { /* XXX: untested */
- align_get_bits(&ctx->gb);
- skip_hdr_extension(&ctx->gb);
+ bitstream_align(&ctx->bc);
+ skip_hdr_extension(&ctx->bc);
}
- align_get_bits(&ctx->gb);
+ bitstream_align(&ctx->bc);
return 0;
}
@@ -461,7 +462,7 @@ static int decode_mb_info(IVI45DecContext *ctx, IVIBandDesc *band,
mb->ypos = y;
mb->buf_offs = mb_offset;
- if (get_bits1(&ctx->gb)) {
+ if (bitstream_read_bit(&ctx->bc)) {
if (ctx->frame_type == FRAMETYPE_INTRA) {
av_log(avctx, AV_LOG_ERROR, "Empty macroblock in an INTRA picture!\n");
return AVERROR_INVALIDDATA;
@@ -471,8 +472,9 @@ static int decode_mb_info(IVI45DecContext *ctx, IVIBandDesc *band,
mb->q_delta = 0;
if (!band->plane && !band->band_num && (ctx->frame_flags & 8)) {
- mb->q_delta = get_vlc2(&ctx->gb, ctx->mb_vlc.tab->table,
- IVI_VLC_BITS, 1);
+ mb->q_delta = bitstream_read_vlc(&ctx->bc,
+ ctx->mb_vlc.tab->table,
+ IVI_VLC_BITS, 1);
mb->q_delta = IVI_TOSIGNED(mb->q_delta);
}
@@ -493,11 +495,11 @@ static int decode_mb_info(IVI45DecContext *ctx, IVIBandDesc *band,
} else if (ctx->frame_type == FRAMETYPE_INTRA) {
mb->type = 0; /* mb_type is always INTRA for intra-frames */
} else {
- mb->type = get_bits1(&ctx->gb);
+ mb->type = bitstream_read_bit(&ctx->bc);
}
blks_per_mb = band->mb_size != band->blk_size ? 4 : 1;
- mb->cbp = get_bits(&ctx->gb, blks_per_mb);
+ mb->cbp = bitstream_read(&ctx->bc, blks_per_mb);
mb->q_delta = 0;
if (band->qdelta_present) {
@@ -505,8 +507,9 @@ static int decode_mb_info(IVI45DecContext *ctx, IVIBandDesc *band,
if (ref_mb) mb->q_delta = ref_mb->q_delta;
} else if (mb->cbp || (!band->plane && !band->band_num &&
(ctx->frame_flags & 8))) {
- mb->q_delta = get_vlc2(&ctx->gb, ctx->mb_vlc.tab->table,
- IVI_VLC_BITS, 1);
+ mb->q_delta = bitstream_read_vlc(&ctx->bc,
+ ctx->mb_vlc.tab->table,
+ IVI_VLC_BITS, 1);
mb->q_delta = IVI_TOSIGNED(mb->q_delta);
}
}
@@ -525,11 +528,13 @@ static int decode_mb_info(IVI45DecContext *ctx, IVIBandDesc *band,
}
} else {
/* decode motion vector deltas */
- mv_delta = get_vlc2(&ctx->gb, ctx->mb_vlc.tab->table,
- IVI_VLC_BITS, 1);
+ mv_delta = bitstream_read_vlc(&ctx->bc,
+ ctx->mb_vlc.tab->table,
+ IVI_VLC_BITS, 1);
mv_y += IVI_TOSIGNED(mv_delta);
- mv_delta = get_vlc2(&ctx->gb, ctx->mb_vlc.tab->table,
- IVI_VLC_BITS, 1);
+ mv_delta = bitstream_read_vlc(&ctx->bc,
+ ctx->mb_vlc.tab->table,
+ IVI_VLC_BITS, 1);
mv_x += IVI_TOSIGNED(mv_delta);
mb->mv_x = mv_x;
mb->mv_y = mv_y;
@@ -546,7 +551,7 @@ static int decode_mb_info(IVI45DecContext *ctx, IVIBandDesc *band,
offs += row_offset;
}
- align_get_bits(&ctx->gb);
+ bitstream_align(&ctx->bc);
return 0;
}
diff --git a/libavcodec/ivi.c b/libavcodec/ivi.c
index 57946a3349..a83773443c 100644
--- a/libavcodec/ivi.c
+++ b/libavcodec/ivi.c
@@ -33,7 +33,7 @@
#define BITSTREAM_READER_LE
#include "avcodec.h"
-#include "get_bits.h"
+#include "bitstream.h"
#include "internal.h"
#include "mathops.h"
#include "ivi.h"
@@ -225,7 +225,7 @@ static int ivi_huff_desc_cmp(const IVIHuffDesc *desc1,
memcmp(desc1->xbits, desc2->xbits, desc1->num_rows);
}
-int ff_ivi_dec_huff_desc(GetBitContext *gb, int desc_coded, int which_tab,
+int ff_ivi_dec_huff_desc(BitstreamContext *bc, int desc_coded, int which_tab,
IVIHuffTab *huff_tab, AVCodecContext *avctx)
{
int i, result;
@@ -238,17 +238,17 @@ int ff_ivi_dec_huff_desc(GetBitContext *gb, int desc_coded, int which_tab,
return 0;
}
- huff_tab->tab_sel = get_bits(gb, 3);
+ huff_tab->tab_sel = bitstream_read(bc, 3);
if (huff_tab->tab_sel == 7) {
/* custom huffman table (explicitly encoded) */
- new_huff.num_rows = get_bits(gb, 4);
+ new_huff.num_rows = bitstream_read(bc, 4);
if (!new_huff.num_rows) {
av_log(avctx, AV_LOG_ERROR, "Empty custom Huffman table!\n");
return AVERROR_INVALIDDATA;
}
for (i = 0; i < new_huff.num_rows; i++)
- new_huff.xbits[i] = get_bits(gb, 4);
+ new_huff.xbits[i] = bitstream_read(bc, 4);
/* Have we got the same custom table? Rebuild if not. */
if (ivi_huff_desc_cmp(&new_huff, &huff_tab->cust_desc)) {
@@ -461,22 +461,22 @@ av_cold int ff_ivi_init_tiles(IVIPlaneDesc *planes,
* if (tile_data_size >= 255) than this field four is byte long: 0xFF X1 X2 X3
* where X1-X3 is size of the tile data
*
- * @param[in,out] gb the GetBit context
+ * @param[in,out] bc the Bitstream context
* @return size of the tile data in bytes
*/
-static int ivi_dec_tile_data_size(GetBitContext *gb)
+static int ivi_dec_tile_data_size(BitstreamContext *bc)
{
int len;
len = 0;
- if (get_bits1(gb)) {
- len = get_bits(gb, 8);
+ if (bitstream_read_bit(bc)) {
+ len = bitstream_read(bc, 8);
if (len == 255)
- len = get_bits_long(gb, 24);
+ len = bitstream_read(bc, 24);
}
/* align the bitstream reader on the byte boundary */
- align_get_bits(gb);
+ bitstream_align(bc);
return len;
}
@@ -500,7 +500,7 @@ static int ivi_dc_transform(IVIBandDesc *band, int *prev_dc, int buf_offs,
return 0;
}
-static int ivi_decode_coded_blocks(GetBitContext *gb, IVIBandDesc *band,
+static int ivi_decode_coded_blocks(BitstreamContext *bc, IVIBandDesc *band,
ivi_mc_func mc, ivi_mc_avg_func mc_avg,
int mv_x, int mv_y,
int mv_x2, int mv_y2,
@@ -536,16 +536,15 @@ static int ivi_decode_coded_blocks(GetBitContext *gb, IVIBandDesc *band,
/* zero column flags */
memset(col_flags, 0, sizeof(col_flags));
while (scan_pos <= num_coeffs) {
- sym = get_vlc2(gb, band->blk_vlc.tab->table,
- IVI_VLC_BITS, 1);
+ sym = bitstream_read_vlc(bc, band->blk_vlc.tab->table, IVI_VLC_BITS, 1);
if (sym == rvmap->eob_sym)
break; /* End of block */
/* Escape - run/val explicitly coded using 3 vlc codes */
if (sym == rvmap->esc_sym) {
- run = get_vlc2(gb, band->blk_vlc.tab->table, IVI_VLC_BITS, 1) + 1;
- lo = get_vlc2(gb, band->blk_vlc.tab->table, IVI_VLC_BITS, 1);
- hi = get_vlc2(gb, band->blk_vlc.tab->table, IVI_VLC_BITS, 1);
+ run = bitstream_read_vlc(bc, band->blk_vlc.tab->table, IVI_VLC_BITS, 1) + 1;
+ lo = bitstream_read_vlc(bc, band->blk_vlc.tab->table, IVI_VLC_BITS, 1);
+ hi = bitstream_read_vlc(bc, band->blk_vlc.tab->table, IVI_VLC_BITS, 1);
/* merge them and convert into signed val */
val = IVI_TOSIGNED((hi << 6) | lo);
} else {
@@ -601,12 +600,12 @@ static int ivi_decode_coded_blocks(GetBitContext *gb, IVIBandDesc *band,
* dequantize them, apply inverse transform and motion compensation
* in order to reconstruct the picture.
*
- * @param[in,out] gb the GetBit context
+ * @param[in,out] bc the Bitstream context
* @param[in] band pointer to the band descriptor
* @param[in] tile pointer to the tile descriptor
* @return result code: 0 - OK, -1 = error (corrupted blocks data)
*/
-static int ivi_decode_blocks(GetBitContext *gb, IVIBandDesc *band,
+static int ivi_decode_blocks(BitstreamContext *bc, IVIBandDesc *band,
IVITile *tile, AVCodecContext *avctx)
{
int mbn, blk, num_blocks, blk_size, ret, is_intra;
@@ -710,7 +709,7 @@ static int ivi_decode_blocks(GetBitContext *gb, IVIBandDesc *band,
}
if (cbp & 1) { /* block coded ? */
- ret = ivi_decode_coded_blocks(gb, band, mc_with_delta_func,
+ ret = ivi_decode_coded_blocks(bc, band, mc_with_delta_func,
mc_avg_with_delta_func,
mv_x, mv_y, mv_x2, mv_y2,
&prev_dc, is_intra,
@@ -739,7 +738,7 @@ static int ivi_decode_blocks(GetBitContext *gb, IVIBandDesc *band,
}// for blk
}// for mbn
- align_get_bits(gb);
+ bitstream_align(bc);
return 0;
}
@@ -925,7 +924,7 @@ static int decode_band(IVI45DecContext *ctx,
band->ref_buf = band->bufs[ctx->ref_buf];
band->b_ref_buf = 0;
}
- band->data_ptr = ctx->frame_data + (get_bits_count(&ctx->gb) >> 3);
+ band->data_ptr = ctx->frame_data + (bitstream_tell(&ctx->bc) >> 3);
result = ctx->decode_band_hdr(ctx, band, avctx);
if (result) {
@@ -949,7 +948,7 @@ static int decode_band(IVI45DecContext *ctx,
FFSWAP(int16_t, band->rv_map->valtab[idx1], band->rv_map->valtab[idx2]);
}
- pos = get_bits_count(&ctx->gb);
+ pos = bitstream_tell(&ctx->bc);
for (t = 0; t < band->num_tiles; t++) {
tile = &band->tiles[t];
@@ -959,7 +958,7 @@ static int decode_band(IVI45DecContext *ctx,
band->mb_size, tile->mb_size);
return AVERROR_INVALIDDATA;
}
- tile->is_empty = get_bits1(&ctx->gb);
+ tile->is_empty = bitstream_read_bit(&ctx->bc);
if (tile->is_empty) {
result = ivi_process_empty_tile(avctx, band, tile,
(ctx->planes[0].bands[0].mb_size >> 3) - (band->mb_size >> 3));
@@ -967,7 +966,7 @@ static int decode_band(IVI45DecContext *ctx,
break;
ff_dlog(avctx, "Empty tile encountered!\n");
} else {
- tile->data_size = ivi_dec_tile_data_size(&ctx->gb);
+ tile->data_size = ivi_dec_tile_data_size(&ctx->bc);
if (!tile->data_size) {
av_log(avctx, AV_LOG_ERROR, "Tile data size is zero!\n");
return AVERROR_INVALIDDATA;
@@ -977,14 +976,14 @@ static int decode_band(IVI45DecContext *ctx,
if (result < 0)
break;
- result = ivi_decode_blocks(&ctx->gb, band, tile, avctx);
+ result = ivi_decode_blocks(&ctx->bc, band, tile, avctx);
if (result < 0) {
av_log(avctx, AV_LOG_ERROR,
"Corrupted tile data encountered!\n");
break;
}
- if (((get_bits_count(&ctx->gb) - pos) >> 3) != tile->data_size) {
+ if (((bitstream_tell(&ctx->bc) - pos) >> 3) != tile->data_size) {
av_log(avctx, AV_LOG_ERROR,
"Tile data_size mismatch!\n");
result = AVERROR_INVALIDDATA;
@@ -1016,7 +1015,7 @@ static int decode_band(IVI45DecContext *ctx,
}
#endif
- align_get_bits(&ctx->gb);
+ bitstream_align(&ctx->bc);
return result;
}
@@ -1030,7 +1029,7 @@ int ff_ivi_decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
int buf_size = avpkt->size;
int result, p, b;
- init_get_bits(&ctx->gb, buf, buf_size * 8);
+ bitstream_init(&ctx->bc, buf, buf_size * 8);
ctx->frame_data = buf;
ctx->frame_size = buf_size;
@@ -1122,14 +1121,14 @@ int ff_ivi_decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
if (ctx->is_indeo4 && ctx->frame_type == IVI4_FRAMETYPE_INTRA) {
int left;
- while (get_bits(&ctx->gb, 8)); // skip version string
- left = get_bits_count(&ctx->gb) & 0x18;
- skip_bits_long(&ctx->gb, 64 - left);
- if (get_bits_left(&ctx->gb) > 18 &&
- show_bits_long(&ctx->gb, 21) == 0xBFFF8) { // syncheader + inter type
+ while (bitstream_read(&ctx->bc, 8)); // skip version string
+ left = bitstream_tell(&ctx->bc) & 0x18;
+ bitstream_skip(&ctx->bc, 64 - left);
+ if (bitstream_bits_left(&ctx->bc) > 18 &&
+ bitstream_peek(&ctx->bc, 21) == 0xBFFF8) { // syncheader + inter type
AVPacket pkt;
- pkt.data = avpkt->data + (get_bits_count(&ctx->gb) >> 3);
- pkt.size = get_bits_left(&ctx->gb) >> 3;
+ pkt.data = avpkt->data + (bitstream_tell(&ctx->bc) >> 3);
+ pkt.size = bitstream_bits_left(&ctx->bc) >> 3;
ff_ivi_decode_frame(avctx, ctx->p_frame, &ctx->got_p_frame, &pkt);
}
}
diff --git a/libavcodec/ivi.h b/libavcodec/ivi.h
index 4082a90de9..bbc8842340 100644
--- a/libavcodec/ivi.h
+++ b/libavcodec/ivi.h
@@ -29,10 +29,11 @@
#ifndef AVCODEC_IVI_H
#define AVCODEC_IVI_H
-#include "avcodec.h"
-#include "get_bits.h"
#include <stdint.h>
+#include "avcodec.h"
+#include "bitstream.h"
+
/**
* Indeo 4 frame types.
*/
@@ -210,7 +211,7 @@ typedef struct IVIPicConfig {
} IVIPicConfig;
typedef struct IVI45DecContext {
- GetBitContext gb;
+ BitstreamContext bc;
RVMapDesc rvmap_tabs[9]; ///< local corrected copy of the static rvmap tables
uint32_t frame_num;
@@ -302,14 +303,14 @@ void ff_ivi_init_static_vlc(void);
* Decode a huffman codebook descriptor from the bitstream
* and select specified huffman table.
*
- * @param[in,out] gb the GetBit context
+ * @param[in,out] bc the Bitstream context
* @param[in] desc_coded flag signalling if table descriptor was coded
* @param[in] which_tab codebook purpose (IVI_MB_HUFF or IVI_BLK_HUFF)
* @param[out] huff_tab pointer to the descriptor of the selected table
* @param[in] avctx AVCodecContext pointer
* @return zero on success, negative value otherwise
*/
-int ff_ivi_dec_huff_desc(GetBitContext *gb, int desc_coded, int which_tab,
+int ff_ivi_dec_huff_desc(BitstreamContext *bc, int desc_coded, int which_tab,
IVIHuffTab *huff_tab, AVCodecContext *avctx);
/**
More information about the ffmpeg-cvslog
mailing list