1 /*
2 * cached bitstream reader test
3 * copyright (c) 2022 Anton Khirnov <anton@khirnov.net>
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 #define ASSERT_LEVEL 2
23
27
30
31 #ifdef BITSTREAM_LE
32 #define BITSTREAM_WRITER_LE
33 #endif
35
37
49 };
50
51 int main(
int argc,
char **argv)
52 {
56
59
60 uint32_t random_seed;
63 unsigned count;
65
66 /* generate random input, using a given or random seed */
67 if (argc > 1)
68 random_seed = strtoul(argv[1],
NULL, 0);
69 else
71
72 fprintf(stderr, "Testing with LFG seed: %"PRIu32"\n", random_seed);
74
75 for (
unsigned i = 0;
i <
SIZE;
i++)
77
81
82 /* use a random sequence of bitreading operations to transfer data
83 * from BitstreamContext to PutBitContext */
86
92
93 fprintf(stderr,
"%d read %u: %"PRIu64
"\n",
bits_tell(&bc) - count, count,
val);
94
96
98 break;
101 count =
FFMAX(count, 1);
104
105 fprintf(stderr,
"%d read_nz %u: %"PRIu64
"\n",
bits_tell(&bc) - count, count,
val);
106
108
110 break;
113
114 fprintf(stderr,
"%d read_bit: %"PRIu64
"\n",
bits_tell(&bc) - 1,
val);
115
117 break;
121
122 fprintf(stderr,
"%d read_63 %u: %"PRIu64
"\n",
bits_tell(&bc) - count, count,
val);
123
125 break;
129
130 fprintf(stderr,
"%d read_64 %u: %"PRIu64
"\n",
bits_tell(&bc) - count, count,
val);
131
133 break;
138
139 fprintf(stderr,
"%d read_signed %u: %"PRId32
"\n",
bits_tell(&bc) - count, count, sval);
140
142
145 break;
148 count =
FFMAX(count, 1);
151
152 fprintf(stderr,
"%d read_signed_nz %u: %"PRId32
"\n",
bits_tell(&bc) - count, count, sval);
153
155
158 break;
161
162 fprintf(stderr,
"%d align %u\n",
bits_tell(&bc), count);
163
166 break;
169 continue;
170
172 count =
FFMAX(count, 1);
173
175 continue;
176
179
180 fprintf(stderr, "%d apply_sign %u %"PRId32"\n",
181 bits_tell(&bc) - count - 1, count, sval);
182
185
186 break;
187 default:
189 }
190 }
191
193
194 for (
unsigned i = 0;
i <
SIZE;
i++)
195 if (buf[
i] != dst[
i]) {
196 fprintf(stderr, "Mismatch at byte %u: %hhu %hhu; seed %"PRIu32"\n",
197 i, buf[
i], dst[
i], random_seed);
198 return 1;
199 }
200
201 return 0;
202 }