mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-01-08 13:22:53 +02:00
apedec: Convert to the new bitstream reader
This commit is contained in:
parent
b4a911c189
commit
4d49a4c550
@ -25,13 +25,14 @@
|
||||
#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
|
||||
@ -162,7 +163,7 @@ typedef struct APEContext {
|
||||
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
|
||||
@ -484,24 +485,24 @@ static inline void update_rice(APERice *rice, unsigned int x)
|
||||
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) {
|
||||
@ -513,7 +514,7 @@ static inline int ape_decode_value_3860(APEContext *ctx, GetBitContext *gb,
|
||||
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))
|
||||
@ -607,7 +608,7 @@ static inline int ape_decode_value_3990(APEContext *ctx, APERice *rice)
|
||||
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;
|
||||
@ -615,19 +616,19 @@ static void decode_array_0000(APEContext *ctx, GetBitContext *gb,
|
||||
|
||||
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--;
|
||||
@ -653,15 +654,15 @@ static void decode_array_0000(APEContext *ctx, GetBitContext *gb,
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@ -670,7 +671,7 @@ static void entropy_decode_mono_3860(APEContext *ctx, int 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)
|
||||
@ -680,9 +681,9 @@ 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)
|
||||
@ -747,7 +748,7 @@ static int init_entropy_decoder(APEContext *ctx)
|
||||
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 */
|
||||
@ -1480,11 +1481,11 @@ static int ape_decode_frame(AVCodecContext *avctx, void *data,
|
||||
}
|
||||
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) {
|
||||
|
Loading…
Reference in New Issue
Block a user