#include "libavutil/avassert.h"
#include "libavutil/channel_layout.h"
#include "libavutil/opt.h"
+
#include "apedsp.h"
#include "avcodec.h"
+#include "bitstream.h"
#include "bswapdsp.h"
#include "bytestream.h"
#include "internal.h"
-#include "get_bits.h"
-#include "unary_legacy.h"
+#include "unary.h"
/**
* @file
APERice riceX; ///< rice code parameters for the second channel
APERice riceY; ///< rice code parameters for the first channel
APEFilter filters[APE_FILTER_LEVELS][2]; ///< filters used for reconstruction
- GetBitContext gb;
+ BitstreamContext bc;
uint8_t *data; ///< current frame data
uint8_t *data_end; ///< frame data end
rice->k++;
}
-static inline int get_rice_ook(GetBitContext *gb, int k)
+static inline int get_rice_ook(BitstreamContext *bc, int k)
{
unsigned int x;
- x = get_unary(gb, 1, get_bits_left(gb));
+ x = get_unary(bc, 1, bitstream_bits_left(bc));
if (k)
- x = (x << k) | get_bits(gb, k);
+ x = (x << k) | bitstream_read(bc, k);
return x;
}
-static inline int ape_decode_value_3860(APEContext *ctx, GetBitContext *gb,
+static inline int ape_decode_value_3860(APEContext *ctx, BitstreamContext *bc,
APERice *rice)
{
unsigned int x, overflow;
- overflow = get_unary(gb, 1, get_bits_left(gb));
+ overflow = get_unary(bc, 1, bitstream_bits_left(bc));
if (ctx->fileversion > 3880) {
while (overflow >= 16) {
if (!rice->k)
x = overflow;
else
- x = (overflow << rice->k) + get_bits(gb, rice->k);
+ x = (overflow << rice->k) + bitstream_read(bc, rice->k);
rice->ksum += x - (rice->ksum + 8 >> 4);
if (rice->ksum < (rice->k ? 1 << (rice->k + 4) : 0))
return -(x >> 1);
}
-static void decode_array_0000(APEContext *ctx, GetBitContext *gb,
+static void decode_array_0000(APEContext *ctx, BitstreamContext *bc,
int32_t *out, APERice *rice, int blockstodecode)
{
int i;
rice->ksum = 0;
for (i = 0; i < FFMIN(blockstodecode, 5); i++) {
- out[i] = get_rice_ook(&ctx->gb, 10);
+ out[i] = get_rice_ook(&ctx->bc, 10);
rice->ksum += out[i];
}
rice->k = av_log2(rice->ksum / 10) + 1;
for (; i < FFMIN(blockstodecode, 64); i++) {
- out[i] = get_rice_ook(&ctx->gb, rice->k);
+ out[i] = get_rice_ook(&ctx->bc, rice->k);
rice->ksum += out[i];
rice->k = av_log2(rice->ksum / ((i + 1) * 2)) + 1;
}
ksummax = 1 << rice->k + 7;
ksummin = rice->k ? (1 << rice->k + 6) : 0;
for (; i < blockstodecode; i++) {
- out[i] = get_rice_ook(&ctx->gb, rice->k);
+ out[i] = get_rice_ook(&ctx->bc, rice->k);
rice->ksum += out[i] - out[i - 64];
while (rice->ksum < ksummin) {
rice->k--;
static void entropy_decode_mono_0000(APEContext *ctx, int blockstodecode)
{
- decode_array_0000(ctx, &ctx->gb, ctx->decoded[0], &ctx->riceY,
+ decode_array_0000(ctx, &ctx->bc, ctx->decoded[0], &ctx->riceY,
blockstodecode);
}
static void entropy_decode_stereo_0000(APEContext *ctx, int blockstodecode)
{
- decode_array_0000(ctx, &ctx->gb, ctx->decoded[0], &ctx->riceY,
+ decode_array_0000(ctx, &ctx->bc, ctx->decoded[0], &ctx->riceY,
blockstodecode);
- decode_array_0000(ctx, &ctx->gb, ctx->decoded[1], &ctx->riceX,
+ decode_array_0000(ctx, &ctx->bc, ctx->decoded[1], &ctx->riceX,
blockstodecode);
}
int32_t *decoded0 = ctx->decoded[0];
while (blockstodecode--)
- *decoded0++ = ape_decode_value_3860(ctx, &ctx->gb, &ctx->riceY);
+ *decoded0++ = ape_decode_value_3860(ctx, &ctx->bc, &ctx->riceY);
}
static void entropy_decode_stereo_3860(APEContext *ctx, int blockstodecode)
int blocks = blockstodecode;
while (blockstodecode--)
- *decoded0++ = ape_decode_value_3860(ctx, &ctx->gb, &ctx->riceY);
+ *decoded0++ = ape_decode_value_3860(ctx, &ctx->bc, &ctx->riceY);
while (blocks--)
- *decoded1++ = ape_decode_value_3860(ctx, &ctx->gb, &ctx->riceX);
+ *decoded1++ = ape_decode_value_3860(ctx, &ctx->bc, &ctx->riceX);
}
static void entropy_decode_mono_3900(APEContext *ctx, int blockstodecode)
return AVERROR_INVALIDDATA;
ctx->CRC = bytestream_get_be32(&ctx->ptr);
} else {
- ctx->CRC = get_bits_long(&ctx->gb, 32);
+ ctx->CRC = bitstream_read(&ctx->bc, 32);
}
/* Read the frame flags if they exist */
}
s->ptr += offset;
} else {
- init_get_bits(&s->gb, s->ptr, (s->data_end - s->ptr) * 8);
+ bitstream_init8(&s->bc, s->ptr, s->data_end - s->ptr);
if (s->fileversion > 3800)
- skip_bits_long(&s->gb, offset * 8);
+ bitstream_skip(&s->bc, offset * 8);
else
- skip_bits_long(&s->gb, offset);
+ bitstream_skip(&s->bc, offset);
}
if (!nblocks || nblocks > INT_MAX) {