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.

99 lines
2.5KB

  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 <stdio.h>
  20. #include "libavutil/mem.h"
  21. #include "get_bits.h"
  22. #include "golomb.h"
  23. #include "put_bits.h"
  24. #undef fprintf
  25. #define COUNT 8191
  26. #define SIZE (COUNT * 4)
  27. int main(void)
  28. {
  29. int i, ret = 0;
  30. uint8_t *temp;
  31. PutBitContext pb;
  32. GetBitContext gb;
  33. temp = av_malloc(SIZE);
  34. if (!temp)
  35. return 2;
  36. init_put_bits(&pb, temp, SIZE);
  37. for (i = 0; i < COUNT; i++)
  38. set_ue_golomb(&pb, i);
  39. flush_put_bits(&pb);
  40. init_get_bits(&gb, temp, 8 * SIZE);
  41. for (i = 0; i < COUNT; i++) {
  42. int j, s = show_bits(&gb, 25);
  43. j = get_ue_golomb(&gb);
  44. if (j != i) {
  45. fprintf(stderr, "get_ue_golomb: expected %d, got %d. bits: %7x\n",
  46. i, j, s);
  47. ret = 1;
  48. }
  49. }
  50. #define EXTEND(i) (i << 3 | i & 7)
  51. init_put_bits(&pb, temp, SIZE);
  52. for (i = 0; i < COUNT; i++)
  53. set_ue_golomb(&pb, EXTEND(i));
  54. flush_put_bits(&pb);
  55. init_get_bits(&gb, temp, 8 * SIZE);
  56. for (i = 0; i < COUNT; i++) {
  57. int j, s = show_bits_long(&gb, 32);
  58. j = get_ue_golomb_long(&gb);
  59. if (j != EXTEND(i)) {
  60. fprintf(stderr, "get_ue_golomb_long: expected %d, got %d. "
  61. "bits: %8x\n", EXTEND(i), j, s);
  62. ret = 1;
  63. }
  64. }
  65. init_put_bits(&pb, temp, SIZE);
  66. for (i = 0; i < COUNT; i++)
  67. set_se_golomb(&pb, i - COUNT / 2);
  68. flush_put_bits(&pb);
  69. init_get_bits(&gb, temp, 8 * SIZE);
  70. for (i = 0; i < COUNT; i++) {
  71. int j, s = show_bits(&gb, 25);
  72. j = get_se_golomb(&gb);
  73. if (j != i - COUNT / 2) {
  74. fprintf(stderr, "get_se_golomb: expected %d, got %d. bits: %7x\n",
  75. i - COUNT / 2, j, s);
  76. ret = 1;
  77. }
  78. }
  79. av_free(temp);
  80. return ret;
  81. }