avcodec/tests/rangecoder: Test coder more completely

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
pull/304/head^2
Michael Niedermayer 6 years ago
parent 1be9a28f8e
commit 0c4af1390f
  1. 43
      libavcodec/tests/rangecoder.c

@ -24,41 +24,50 @@
#include "libavcodec/rangecoder.h" #include "libavcodec/rangecoder.h"
#define SIZE 10240 #define SIZE 1240
int main(void) int main(void)
{ {
RangeCoder c; RangeCoder c;
uint8_t b[9 * SIZE]; uint8_t b[9 * SIZE];
uint8_t r[9 * SIZE]; uint8_t r[9 * SIZE];
int i; int i, p, actual_length, version;
uint8_t state[10]; uint8_t state[10];
AVLFG prng; AVLFG prng;
av_lfg_init(&prng, 1); av_lfg_init(&prng, 1);
for (version = 0; version < 2; version++) {
for (p = 0; p< 1024; p++) {
ff_init_range_encoder(&c, b, SIZE);
ff_build_rac_states(&c, (1LL << 32) / 20, 128 + 64 + 32 + 16);
ff_init_range_encoder(&c, b, SIZE); memset(state, 128, sizeof(state));
ff_build_rac_states(&c, (1LL << 32) / 20, 128 + 64 + 32 + 16);
memset(state, 128, sizeof(state)); for (i = 0; i < SIZE; i++)
r[i] = av_lfg_get(&prng) % 7;
for (i = 0; i < SIZE; i++) for (i = 0; i < SIZE; i++)
r[i] = av_lfg_get(&prng) % 7; put_rac(&c, state, r[i] & 1);
for (i = 0; i < SIZE; i++) actual_length = ff_rac_terminate(&c, version);
put_rac(&c, state, r[i] & 1);
ff_rac_terminate(&c, 0); ff_init_range_decoder(&c, b, version ? SIZE : actual_length);
ff_init_range_decoder(&c, b, SIZE); memset(state, 128, sizeof(state));
memset(state, 128, sizeof(state)); for (i = 0; i < SIZE; i++)
if ((r[i] & 1) != get_rac(&c, state)) {
for (i = 0; i < SIZE; i++) av_log(NULL, AV_LOG_ERROR, "rac failure at %d pass %d version %d\n", i, p, version);
if ((r[i] & 1) != get_rac(&c, state)) { return 1;
av_log(NULL, AV_LOG_ERROR, "rac failure at %d\n", i); }
return 1; if(version)
get_rac(&c, (uint8_t[]) { 129 });
if (c.bytestream - c.bytestream_start - actual_length != version) {
av_log(NULL, AV_LOG_ERROR, "rac failure at pass %d version %d\n", p, version);
return 1;
}
} }
}
return 0; return 0;
} }

Loading…
Cancel
Save