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.

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