rangecoder-test.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * This file is part of Libav.
  3. *
  4. * Libav is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2.1 of the License, or (at your option) any later version.
  8. *
  9. * Libav is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with Libav; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #include <stdint.h>
  19. #include <string.h>
  20. #include "libavutil/lfg.h"
  21. #include "libavutil/log.h"
  22. #include "rangecoder.h"
  23. #define SIZE 10240
  24. int main(void)
  25. {
  26. RangeCoder c;
  27. uint8_t b[9 * SIZE];
  28. uint8_t r[9 * SIZE];
  29. int i;
  30. uint8_t state[10];
  31. AVLFG prng;
  32. av_lfg_init(&prng, 1);
  33. ff_init_range_encoder(&c, b, SIZE);
  34. ff_build_rac_states(&c, 0.05 * (1LL << 32), 128 + 64 + 32 + 16);
  35. memset(state, 128, sizeof(state));
  36. for (i = 0; i < SIZE; i++)
  37. r[i] = av_lfg_get(&prng) % 7;
  38. for (i = 0; i < SIZE; i++)
  39. put_rac(&c, state, r[i] & 1);
  40. ff_rac_terminate(&c);
  41. ff_init_range_decoder(&c, b, SIZE);
  42. memset(state, 128, sizeof(state));
  43. for (i = 0; i < SIZE; i++)
  44. if ((r[i] & 1) != get_rac(&c, state)) {
  45. av_log(NULL, AV_LOG_ERROR, "rac failure at %d\n", i);
  46. return 1;
  47. }
  48. return 0;
  49. }