You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
2.2KB

  1. /*
  2. * This file is part of FFmpeg.
  3. *
  4. * FFmpeg 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. * FFmpeg 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 FFmpeg; 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 "libavcodec/rangecoder.h"
  23. #define SIZE 1240
  24. int main(void)
  25. {
  26. RangeCoder c;
  27. uint8_t b[9 * SIZE];
  28. uint8_t r[9 * SIZE];
  29. int i, p, actual_length, version;
  30. uint8_t state[10];
  31. AVLFG prng;
  32. av_lfg_init(&prng, 1);
  33. for (version = 0; version < 2; version++) {
  34. for (p = 0; p< 1024; p++) {
  35. ff_init_range_encoder(&c, b, SIZE);
  36. ff_build_rac_states(&c, (1LL << 32) / 20, 128 + 64 + 32 + 16);
  37. memset(state, 128, sizeof(state));
  38. for (i = 0; i < SIZE; i++)
  39. r[i] = av_lfg_get(&prng) % 7;
  40. for (i = 0; i < SIZE; i++)
  41. put_rac(&c, state, r[i] & 1);
  42. actual_length = ff_rac_terminate(&c, version);
  43. ff_init_range_decoder(&c, b, version ? SIZE : actual_length);
  44. memset(state, 128, sizeof(state));
  45. for (i = 0; i < SIZE; i++)
  46. if ((r[i] & 1) != get_rac(&c, state)) {
  47. av_log(NULL, AV_LOG_ERROR, "rac failure at %d pass %d version %d\n", i, p, version);
  48. return 1;
  49. }
  50. if(version)
  51. get_rac(&c, (uint8_t[]) { 129 });
  52. if (c.bytestream - c.bytestream_start - actual_length != version) {
  53. av_log(NULL, AV_LOG_ERROR, "rac failure at pass %d version %d\n", p, version);
  54. return 1;
  55. }
  56. }
  57. }
  58. return 0;
  59. }