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.

101 lines
2.6KB

  1. /*
  2. * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
  3. *
  4. * This file is part of FFmpeg.
  5. *
  6. * FFmpeg is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * FFmpeg is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with FFmpeg; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #include <stdint.h>
  21. #include <stdio.h>
  22. #include "libavutil/mem.h"
  23. #include "get_bits.h"
  24. #include "golomb.h"
  25. #include "put_bits.h"
  26. #undef fprintf
  27. #define COUNT 8191
  28. #define SIZE (COUNT * 4)
  29. int main(void)
  30. {
  31. int i, ret = 0;
  32. uint8_t *temp;
  33. PutBitContext pb;
  34. GetBitContext gb;
  35. temp = av_malloc(SIZE);
  36. if (!temp)
  37. return 2;
  38. init_put_bits(&pb, temp, SIZE);
  39. for (i = 0; i < COUNT; i++)
  40. set_ue_golomb(&pb, i);
  41. flush_put_bits(&pb);
  42. init_get_bits(&gb, temp, 8 * SIZE);
  43. for (i = 0; i < COUNT; i++) {
  44. int j, s = show_bits(&gb, 25);
  45. j = get_ue_golomb(&gb);
  46. if (j != i) {
  47. fprintf(stderr, "get_ue_golomb: expected %d, got %d. bits: %7x\n",
  48. i, j, s);
  49. ret = 1;
  50. }
  51. }
  52. #define EXTEND(i) (i << 3 | i & 7)
  53. init_put_bits(&pb, temp, SIZE);
  54. for (i = 0; i < COUNT; i++)
  55. set_ue_golomb(&pb, EXTEND(i));
  56. flush_put_bits(&pb);
  57. init_get_bits(&gb, temp, 8 * SIZE);
  58. for (i = 0; i < COUNT; i++) {
  59. int j, s = show_bits_long(&gb, 32);
  60. j = get_ue_golomb_long(&gb);
  61. if (j != EXTEND(i)) {
  62. fprintf(stderr, "get_ue_golomb_long: expected %d, got %d. "
  63. "bits: %8x\n", EXTEND(i), j, s);
  64. ret = 1;
  65. }
  66. }
  67. init_put_bits(&pb, temp, SIZE);
  68. for (i = 0; i < COUNT; i++)
  69. set_se_golomb(&pb, i - COUNT / 2);
  70. flush_put_bits(&pb);
  71. init_get_bits(&gb, temp, 8 * SIZE);
  72. for (i = 0; i < COUNT; i++) {
  73. int j, s = show_bits(&gb, 25);
  74. j = get_se_golomb(&gb);
  75. if (j != i - COUNT / 2) {
  76. fprintf(stderr, "get_se_golomb: expected %d, got %d. bits: %7x\n",
  77. i - COUNT / 2, j, s);
  78. ret = 1;
  79. }
  80. }
  81. av_free(temp);
  82. return ret;
  83. }