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