Bug Summary

File:root/firefox-clang/media/ffvpx/libavcodec/cbs_vp9_syntax_template.c
Warning:line 475, column 9
6th function call argument is an uninitialized value

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -O2 -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name cbs_vp9.c -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -analyzer-config-compatibility-mode=true -mrelocation-model pic -pic-level 2 -fhalf-no-semantic-interposition -mframe-pointer=all -relaxed-aliasing -ffp-contract=off -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/root/firefox-clang/obj-x86_64-pc-linux-gnu/media/ffvpx/libavcodec -fcoverage-compilation-dir=/root/firefox-clang/obj-x86_64-pc-linux-gnu/media/ffvpx/libavcodec -resource-dir /usr/lib/llvm-23/lib/clang/23 -include /root/firefox-clang/obj-x86_64-pc-linux-gnu/mozilla-config.h -include libavutil_visibility.h -U _FORTIFY_SOURCE -D _FORTIFY_SOURCE=2 -D DEBUG=1 -D HAVE_AV_CONFIG_H -D ASSERT_LEVEL=2 -I /root/firefox-clang/media/ffvpx/libavcodec -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/media/ffvpx/libavcodec -I /root/firefox-clang/modules/fdlibm/inexact-math-override -I /root/firefox-clang/third_party/khronos/vulkan-headers/include -I /root/firefox-clang/media/mozva -I /root/firefox-clang/media/libopus/include -I /root/firefox-clang/media/libvorbis -I /root/firefox-clang/media/libvpx -I /root/firefox-clang/media/ffvpx -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/include -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/include/nspr -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/include/nss -D MOZILLA_CLIENT -internal-isystem /usr/lib/llvm-23/lib/clang/23/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/16/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -Wno-error=tautological-type-limit-compare -Wno-range-loop-analysis -Wno-error=deprecated-declarations -Wno-error=array-bounds -Wno-error=free-nonheap-object -Wno-error=atomic-alignment -Wno-error=deprecated-builtins -Wno-psabi -Wno-error=builtin-macro-redefined -Wno-unknown-warning-option -Wno-character-conversion -Wno-parentheses -Wno-pointer-sign -Wno-sign-compare -Wno-switch -Wno-type-limits -Wno-unused-function -Wno-deprecated-declarations -Wno-absolute-value -Wno-incompatible-pointer-types -Wno-string-conversion -Wno-visibility -ferror-limit 19 -fstrict-flex-arrays=1 -stack-protector 2 -fstack-clash-protection -ftrivial-auto-var-init=pattern -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fdiagnostics-absolute-paths -vectorize-loops -vectorize-slp -analyzer-checker optin.performance.Padding -analyzer-output=html -analyzer-config stable-report-filename=true -mllvm -dwarf-linkage-names=Abstract -faddrsig -fdwarf2-cfi-asm -o /tmp/scan-build-2026-09-01-224014-2642839-1 -x c /root/firefox-clang/media/ffvpx/libavcodec/cbs_vp9.c

/root/firefox-clang/media/ffvpx/libavcodec/cbs_vp9.c

1/*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg 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 * FFmpeg 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 FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19#include "libavutil/avassert.h"
20
21#include "cbs.h"
22#include "cbs_internal.h"
23#include "cbs_vp9.h"
24
25
26static int cbs_vp9_read_s(CodedBitstreamContext *ctx, GetBitContext *gbc,
27 int width, const char *name,
28 const int *subscripts, int32_t *write_to)
29{
30 uint32_t magnitude;
31 int sign;
32 int32_t value;
33
34 CBS_TRACE_READ_START()GetBitContext trace_start; do { if (ctx->trace_enable) trace_start
= *gbc; } while (0)
;
35
36 if (get_bits_left(gbc) < width + 1) {
37 av_log(ctx->log_ctx, AV_LOG_ERROR16, "Invalid signed value at "
38 "%s: bitstream ended.\n", name);
39 return AVERROR_INVALIDDATA(-(int)(('I') | (('N') << 8) | (('D') << 16) | ((
unsigned)('A') << 24)))
;
40 }
41
42 magnitude = get_bits(gbc, width);
43 sign = get_bits1(gbc);
44 value = sign ? -(int32_t)magnitude : magnitude;
45
46 CBS_TRACE_READ_END()do { if (ctx->trace_enable) { int start_position = get_bits_count
(&trace_start); int end_position = get_bits_count(gbc); do
{ if (!(start_position <= end_position)) { av_log(((void*
)0), 0, "Assertion %s failed at %s:%d\n", "start_position <= end_position"
, "/root/firefox-clang/media/ffvpx/libavcodec/cbs_vp9.c", 46)
; abort(); } } while (0); ctx->trace_read_callback(ctx->
trace_context, &trace_start, end_position - start_position
, name, subscripts, value); } } while (0)
;
47
48 *write_to = value;
49 return 0;
50}
51
52static int cbs_vp9_write_s(CodedBitstreamContext *ctx, PutBitContext *pbc,
53 int width, const char *name,
54 const int *subscripts, int32_t value)
55{
56 uint32_t magnitude;
57 int sign;
58
59 CBS_TRACE_WRITE_START()int start_position; do { if (ctx->trace_enable) start_position
= put_bits_count(pbc);; } while (0)
;
60
61 if (put_bits_left(pbc) < width + 1)
62 return AVERROR(ENOSPC)(-(28));
63
64 sign = value < 0;
65 magnitude = sign ? -value : value;
66
67 put_bits(pbc, width, magnitude);
68 put_bits(pbc, 1, sign);
69
70 CBS_TRACE_WRITE_END()do { if (ctx->trace_enable) { int end_position = put_bits_count
(pbc); do { if (!(start_position <= end_position)) { av_log
(((void*)0), 0, "Assertion %s failed at %s:%d\n", "start_position <= end_position"
, "/root/firefox-clang/media/ffvpx/libavcodec/cbs_vp9.c", 70)
; abort(); } } while (0); ctx->trace_write_callback(ctx->
trace_context, pbc, end_position - start_position, name, subscripts
, value); } } while (0)
;
71
72 return 0;
73}
74
75static int cbs_vp9_read_increment(CodedBitstreamContext *ctx, GetBitContext *gbc,
76 uint32_t range_min, uint32_t range_max,
77 const char *name, uint32_t *write_to)
78{
79 uint32_t value;
80
81 CBS_TRACE_READ_START()GetBitContext trace_start; do { if (ctx->trace_enable) trace_start
= *gbc; } while (0)
;
82
83 av_assert0(range_min <= range_max && range_max - range_min < 32)do { if (!(range_min <= range_max && range_max - range_min
< 32)) { av_log(((void*)0), 0, "Assertion %s failed at %s:%d\n"
, "range_min <= range_max && range_max - range_min < 32"
, "/root/firefox-clang/media/ffvpx/libavcodec/cbs_vp9.c", 83)
; abort(); } } while (0)
;
84
85 for (value = range_min; value < range_max;) {
86 if (get_bits_left(gbc) < 1) {
87 av_log(ctx->log_ctx, AV_LOG_ERROR16, "Invalid increment value at "
88 "%s: bitstream ended.\n", name);
89 return AVERROR_INVALIDDATA(-(int)(('I') | (('N') << 8) | (('D') << 16) | ((
unsigned)('A') << 24)))
;
90 }
91 if (get_bits1(gbc))
92 ++value;
93 else
94 break;
95 }
96
97 CBS_TRACE_READ_END_NO_SUBSCRIPTS()do { const int *subscripts = ((void*)0); do { if (ctx->trace_enable
) { int start_position = get_bits_count(&trace_start); int
end_position = get_bits_count(gbc); do { if (!(start_position
<= end_position)) { av_log(((void*)0), 0, "Assertion %s failed at %s:%d\n"
, "start_position <= end_position", "/root/firefox-clang/media/ffvpx/libavcodec/cbs_vp9.c"
, 97); abort(); } } while (0); ctx->trace_read_callback(ctx
->trace_context, &trace_start, end_position - start_position
, name, subscripts, value); } } while (0); } while (0)
;
98
99 *write_to = value;
100 return 0;
101}
102
103static int cbs_vp9_write_increment(CodedBitstreamContext *ctx, PutBitContext *pbc,
104 uint32_t range_min, uint32_t range_max,
105 const char *name, uint32_t value)
106{
107 int len;
108
109 CBS_TRACE_WRITE_START()int start_position; do { if (ctx->trace_enable) start_position
= put_bits_count(pbc);; } while (0)
;
110
111 av_assert0(range_min <= range_max && range_max - range_min < 8)do { if (!(range_min <= range_max && range_max - range_min
< 8)) { av_log(((void*)0), 0, "Assertion %s failed at %s:%d\n"
, "range_min <= range_max && range_max - range_min < 8"
, "/root/firefox-clang/media/ffvpx/libavcodec/cbs_vp9.c", 111
); abort(); } } while (0)
;
112 if (value < range_min || value > range_max) {
113 av_log(ctx->log_ctx, AV_LOG_ERROR16, "%s out of range: "
114 "%"PRIu32"u"", but must be in [%"PRIu32"u"",%"PRIu32"u""].\n",
115 name, value, range_min, range_max);
116 return AVERROR_INVALIDDATA(-(int)(('I') | (('N') << 8) | (('D') << 16) | ((
unsigned)('A') << 24)))
;
117 }
118
119 if (value == range_max)
120 len = range_max - range_min;
121 else
122 len = value - range_min + 1;
123 if (put_bits_left(pbc) < len)
124 return AVERROR(ENOSPC)(-(28));
125
126 if (len > 0)
127 put_bits(pbc, len, (1 << len) - 1 - (value != range_max));
128
129 CBS_TRACE_WRITE_END_NO_SUBSCRIPTS()do { const int *subscripts = ((void*)0); do { if (ctx->trace_enable
) { int end_position = put_bits_count(pbc); do { if (!(start_position
<= end_position)) { av_log(((void*)0), 0, "Assertion %s failed at %s:%d\n"
, "start_position <= end_position", "/root/firefox-clang/media/ffvpx/libavcodec/cbs_vp9.c"
, 129); abort(); } } while (0); ctx->trace_write_callback(
ctx->trace_context, pbc, end_position - start_position, name
, subscripts, value); } } while (0); } while (0)
;
130
131 return 0;
132}
133
134static int cbs_vp9_read_le(CodedBitstreamContext *ctx, GetBitContext *gbc,
135 int width, const char *name,
136 const int *subscripts, uint32_t *write_to)
137{
138 uint32_t value;
139 int b;
140
141 CBS_TRACE_READ_START()GetBitContext trace_start; do { if (ctx->trace_enable) trace_start
= *gbc; } while (0)
;
142
143 av_assert0(width % 8 == 0)do { if (!(width % 8 == 0)) { av_log(((void*)0), 0, "Assertion %s failed at %s:%d\n"
, "width % 8 == 0", "/root/firefox-clang/media/ffvpx/libavcodec/cbs_vp9.c"
, 143); abort(); } } while (0)
;
144
145 if (get_bits_left(gbc) < width) {
146 av_log(ctx->log_ctx, AV_LOG_ERROR16, "Invalid le value at "
147 "%s: bitstream ended.\n", name);
148 return AVERROR_INVALIDDATA(-(int)(('I') | (('N') << 8) | (('D') << 16) | ((
unsigned)('A') << 24)))
;
149 }
150
151 value = 0;
152 for (b = 0; b < width; b += 8)
153 value |= get_bits(gbc, 8) << b;
154
155 CBS_TRACE_READ_END()do { if (ctx->trace_enable) { int start_position = get_bits_count
(&trace_start); int end_position = get_bits_count(gbc); do
{ if (!(start_position <= end_position)) { av_log(((void*
)0), 0, "Assertion %s failed at %s:%d\n", "start_position <= end_position"
, "/root/firefox-clang/media/ffvpx/libavcodec/cbs_vp9.c", 155
); abort(); } } while (0); ctx->trace_read_callback(ctx->
trace_context, &trace_start, end_position - start_position
, name, subscripts, value); } } while (0)
;
156
157 *write_to = value;
158 return 0;
159}
160
161static int cbs_vp9_write_le(CodedBitstreamContext *ctx, PutBitContext *pbc,
162 int width, const char *name,
163 const int *subscripts, uint32_t value)
164{
165 int b;
166
167 CBS_TRACE_WRITE_START()int start_position; do { if (ctx->trace_enable) start_position
= put_bits_count(pbc);; } while (0)
;
168
169 av_assert0(width % 8 == 0)do { if (!(width % 8 == 0)) { av_log(((void*)0), 0, "Assertion %s failed at %s:%d\n"
, "width % 8 == 0", "/root/firefox-clang/media/ffvpx/libavcodec/cbs_vp9.c"
, 169); abort(); } } while (0)
;
170
171 if (put_bits_left(pbc) < width)
172 return AVERROR(ENOSPC)(-(28));
173
174 for (b = 0; b < width; b += 8)
175 put_bits(pbc, 8, value >> b & 0xff);
176
177 CBS_TRACE_WRITE_END()do { if (ctx->trace_enable) { int end_position = put_bits_count
(pbc); do { if (!(start_position <= end_position)) { av_log
(((void*)0), 0, "Assertion %s failed at %s:%d\n", "start_position <= end_position"
, "/root/firefox-clang/media/ffvpx/libavcodec/cbs_vp9.c", 177
); abort(); } } while (0); ctx->trace_write_callback(ctx->
trace_context, pbc, end_position - start_position, name, subscripts
, value); } } while (0)
;
178
179 return 0;
180}
181
182#define HEADER(name)do { ff_cbs_trace_header(ctx, name); } while (0) do { \
183 ff_cbs_trace_header(ctx, name); \
184 } while (0)
185
186#define CHECK(call)do { err = (call); if (err < 0) return err; } while (0) do { \
187 err = (call); \
188 if (err < 0) \
189 return err; \
190 } while (0)
191
192#define FUNC_NAME(rw, codec, name)cbs_codec_rw_name cbs_ ## codec ## _ ## rw ## _ ## name
193#define FUNC_VP9(rw, name)cbs_vp9_rw_name FUNC_NAME(rw, vp9, name)cbs_vp9_rw_name
194#define FUNC(name)cbs_vp9_READWRITE_name FUNC_VP9(READWRITE, name)cbs_vp9_READWRITE_name
195
196#define SUBSCRIPTS(subs, ...)(subs > 0 ? ((int[subs + 1]){ subs, ... }) : ((void*)0)) (subs > 0 ? ((int[subs + 1]){ subs, __VA_ARGS__ }) : NULL((void*)0))
197
198#define s(width, name)xs(width, name, current->name, 0, ) \
199 xs(width, name, current->name, 0, )
200#define fs(width, name, subs, ...)xf(width, name, current->name, subs, ...) \
201 xf(width, name, current->name, subs, __VA_ARGS__)
202#define ss(width, name, subs, ...)xs(width, name, current->name, subs, ...) \
203 xs(width, name, current->name, subs, __VA_ARGS__)
204
205#define READ
206#define READWRITE read
207#define RWContext GetBitContext
208
209#define f(width, name) do { \
210 uint32_t value; \
211 CHECK(ff_cbs_read_simple_unsigned(ctx, rw, width, #name, \do { err = (ff_cbs_read_simple_unsigned(ctx, rw, width, #name
, &value)); if (err < 0) return err; } while (0)
212 &value))do { err = (ff_cbs_read_simple_unsigned(ctx, rw, width, #name
, &value)); if (err < 0) return err; } while (0)
; \
213 current->name = value; \
214 } while (0)
215#define xf(width, name, var, subs, ...) do { \
216 uint32_t value; \
217 CHECK(ff_cbs_read_unsigned(ctx, rw, width, #name, \do { err = (ff_cbs_read_unsigned(ctx, rw, width, #name, (subs
> 0 ? ((int[subs + 1]){ subs, __VA_ARGS__ }) : ((void*)0)
), &value, 0, (1 << width) - 1)); if (err < 0) return
err; } while (0)
218 SUBSCRIPTS(subs, __VA_ARGS__), \do { err = (ff_cbs_read_unsigned(ctx, rw, width, #name, (subs
> 0 ? ((int[subs + 1]){ subs, __VA_ARGS__ }) : ((void*)0)
), &value, 0, (1 << width) - 1)); if (err < 0) return
err; } while (0)
219 &value, 0, (1 << width) - 1))do { err = (ff_cbs_read_unsigned(ctx, rw, width, #name, (subs
> 0 ? ((int[subs + 1]){ subs, __VA_ARGS__ }) : ((void*)0)
), &value, 0, (1 << width) - 1)); if (err < 0) return
err; } while (0)
; \
220 var = value; \
221 } while (0)
222#define xs(width, name, var, subs, ...) do { \
223 int32_t value; \
224 CHECK(cbs_vp9_read_s(ctx, rw, width, #name, \do { err = (cbs_vp9_read_s(ctx, rw, width, #name, (subs > 0
? ((int[subs + 1]){ subs, __VA_ARGS__ }) : ((void*)0)), &
value)); if (err < 0) return err; } while (0)
225 SUBSCRIPTS(subs, __VA_ARGS__), &value))do { err = (cbs_vp9_read_s(ctx, rw, width, #name, (subs > 0
? ((int[subs + 1]){ subs, __VA_ARGS__ }) : ((void*)0)), &
value)); if (err < 0) return err; } while (0)
; \
226 var = value; \
227 } while (0)
228
229
230#define increment(name, min, max) do { \
231 uint32_t value; \
232 CHECK(cbs_vp9_read_increment(ctx, rw, min, max, #name, &value))do { err = (cbs_vp9_read_increment(ctx, rw, min, max, #name, &
value)); if (err < 0) return err; } while (0)
; \
233 current->name = value; \
234 } while (0)
235
236#define fle(width, name, subs, ...) do { \
237 CHECK(cbs_vp9_read_le(ctx, rw, width, #name, \do { err = (cbs_vp9_read_le(ctx, rw, width, #name, (subs >
0 ? ((int[subs + 1]){ subs, __VA_ARGS__ }) : ((void*)0)), &
current->name)); if (err < 0) return err; } while (0)
238 SUBSCRIPTS(subs, __VA_ARGS__), &current->name))do { err = (cbs_vp9_read_le(ctx, rw, width, #name, (subs >
0 ? ((int[subs + 1]){ subs, __VA_ARGS__ }) : ((void*)0)), &
current->name)); if (err < 0) return err; } while (0)
; \
239 } while (0)
240
241#define delta_q(name) do { \
242 uint8_t delta_coded; \
243 int8_t delta_q; \
244 xf(1, name.delta_coded, delta_coded, 0, ); \
245 if (delta_coded) \
246 xs(4, name.delta_q, delta_q, 0, ); \
247 else \
248 delta_q = 0; \
249 current->name = delta_q; \
250 } while (0)
251
252#define prob(name, subs, ...) do { \
253 uint8_t prob_coded; \
254 uint8_t prob; \
255 xf(1, name.prob_coded, prob_coded, subs, __VA_ARGS__); \
256 if (prob_coded) \
257 xf(8, name.prob, prob, subs, __VA_ARGS__); \
258 else \
259 prob = 255; \
260 current->name = prob; \
261 } while (0)
262
263#define fixed(width, name, value) do { \
264 av_unused__attribute__((unused)) uint32_t fixed_value; \
265 CHECK(ff_cbs_read_unsigned(ctx, rw, width, #name, \do { err = (ff_cbs_read_unsigned(ctx, rw, width, #name, 0, &
fixed_value, value, value)); if (err < 0) return err; } while
(0)
266 0, &fixed_value, value, value))do { err = (ff_cbs_read_unsigned(ctx, rw, width, #name, 0, &
fixed_value, value, value)); if (err < 0) return err; } while
(0)
; \
267 } while (0)
268
269#define infer(name, value) do { \
270 current->name = value; \
271 } while (0)
272
273#define byte_alignment(rw) (get_bits_count(rw) % 8)
274
275#include "cbs_vp9_syntax_template.c"
276
277#undef READ
278#undef READWRITE
279#undef RWContext
280#undef f
281#undef xf
282#undef xs
283#undef increment
284#undef fle
285#undef delta_q
286#undef prob
287#undef fixed
288#undef infer
289#undef byte_alignment
290
291
292#define WRITE
293#define READWRITE write
294#define RWContext PutBitContext
295
296#define f(width, name) do { \
297 CHECK(ff_cbs_write_simple_unsigned(ctx, rw, width, #name, \do { err = (ff_cbs_write_simple_unsigned(ctx, rw, width, #name
, current->name)); if (err < 0) return err; } while (0)
298 current->name))do { err = (ff_cbs_write_simple_unsigned(ctx, rw, width, #name
, current->name)); if (err < 0) return err; } while (0)
; \
299 } while (0)
300#define xf(width, name, var, subs, ...) do { \
301 CHECK(ff_cbs_write_unsigned(ctx, rw, width, #name, \do { err = (ff_cbs_write_unsigned(ctx, rw, width, #name, (subs
> 0 ? ((int[subs + 1]){ subs, __VA_ARGS__ }) : ((void*)0)
), var, 0, (1 << width) - 1)); if (err < 0) return err
; } while (0)
302 SUBSCRIPTS(subs, __VA_ARGS__), \do { err = (ff_cbs_write_unsigned(ctx, rw, width, #name, (subs
> 0 ? ((int[subs + 1]){ subs, __VA_ARGS__ }) : ((void*)0)
), var, 0, (1 << width) - 1)); if (err < 0) return err
; } while (0)
303 var, 0, (1 << width) - 1))do { err = (ff_cbs_write_unsigned(ctx, rw, width, #name, (subs
> 0 ? ((int[subs + 1]){ subs, __VA_ARGS__ }) : ((void*)0)
), var, 0, (1 << width) - 1)); if (err < 0) return err
; } while (0)
; \
304 } while (0)
305#define xs(width, name, var, subs, ...) do { \
306 CHECK(cbs_vp9_write_s(ctx, rw, width, #name, \do { err = (cbs_vp9_write_s(ctx, rw, width, #name, (subs >
0 ? ((int[subs + 1]){ subs, __VA_ARGS__ }) : ((void*)0)), var
)); if (err < 0) return err; } while (0)
307 SUBSCRIPTS(subs, __VA_ARGS__), var))do { err = (cbs_vp9_write_s(ctx, rw, width, #name, (subs >
0 ? ((int[subs + 1]){ subs, __VA_ARGS__ }) : ((void*)0)), var
)); if (err < 0) return err; } while (0)
; \
308 } while (0)
309
310#define increment(name, min, max) do { \
311 CHECK(cbs_vp9_write_increment(ctx, rw, min, max, #name, current->name))do { err = (cbs_vp9_write_increment(ctx, rw, min, max, #name,
current->name)); if (err < 0) return err; } while (0)
; \
312 } while (0)
313
314#define fle(width, name, subs, ...) do { \
315 CHECK(cbs_vp9_write_le(ctx, rw, width, #name, \do { err = (cbs_vp9_write_le(ctx, rw, width, #name, (subs >
0 ? ((int[subs + 1]){ subs, __VA_ARGS__ }) : ((void*)0)), current
->name)); if (err < 0) return err; } while (0)
316 SUBSCRIPTS(subs, __VA_ARGS__), current->name))do { err = (cbs_vp9_write_le(ctx, rw, width, #name, (subs >
0 ? ((int[subs + 1]){ subs, __VA_ARGS__ }) : ((void*)0)), current
->name)); if (err < 0) return err; } while (0)
; \
317 } while (0)
318
319#define delta_q(name) do { \
320 xf(1, name.delta_coded, !!current->name, 0, ); \
321 if (current->name) \
322 xs(4, name.delta_q, current->name, 0, ); \
323 } while (0)
324
325#define prob(name, subs, ...) do { \
326 xf(1, name.prob_coded, current->name != 255, subs, __VA_ARGS__); \
327 if (current->name != 255) \
328 xf(8, name.prob, current->name, subs, __VA_ARGS__); \
329 } while (0)
330
331#define fixed(width, name, value) do { \
332 CHECK(ff_cbs_write_unsigned(ctx, rw, width, #name, \do { err = (ff_cbs_write_unsigned(ctx, rw, width, #name, 0, value
, value, value)); if (err < 0) return err; } while (0)
333 0, value, value, value))do { err = (ff_cbs_write_unsigned(ctx, rw, width, #name, 0, value
, value, value)); if (err < 0) return err; } while (0)
; \
334 } while (0)
335
336#define infer(name, value) do { \
337 if (current->name != (value)) { \
338 av_log(ctx->log_ctx, AV_LOG_WARNING24, "Warning: " \
339 "%s does not match inferred value: " \
340 "%"PRId64"l" "d"", but should be %"PRId64"l" "d"".\n", \
341 #name, (int64_t)current->name, (int64_t)(value)); \
342 } \
343 } while (0)
344
345#define byte_alignment(rw) (put_bits_count(rw) % 8)
346
347#include "cbs_vp9_syntax_template.c"
348
349#undef WRITE
350#undef READWRITE
351#undef RWContext
352#undef f
353#undef xf
354#undef xs
355#undef increment
356#undef fle
357#undef delta_q
358#undef prob
359#undef fixed
360#undef infer
361#undef byte_alignment
362
363
364static int cbs_vp9_split_fragment(CodedBitstreamContext *ctx,
365 CodedBitstreamFragment *frag,
366 int header)
367{
368 uint8_t superframe_header;
369 int err;
370
371 if (frag->data_size == 0)
372 return AVERROR_INVALIDDATA(-(int)(('I') | (('N') << 8) | (('D') << 16) | ((
unsigned)('A') << 24)))
;
373
374 // Last byte in the packet.
375 superframe_header = frag->data[frag->data_size - 1];
376
377 if ((superframe_header & 0xe0) == 0xc0) {
378 VP9RawSuperframeIndex sfi = {0};
379 GetBitContext gbc;
380 size_t index_size, pos;
381 int i;
382
383 index_size = 2 + (((superframe_header & 0x18) >> 3) + 1) *
384 ((superframe_header & 0x07) + 1);
385
386 if (index_size > frag->data_size)
387 return AVERROR_INVALIDDATA(-(int)(('I') | (('N') << 8) | (('D') << 16) | ((
unsigned)('A') << 24)))
;
388
389 err = init_get_bits(&gbc, frag->data + frag->data_size - index_size,
390 8 * index_size);
391 if (err < 0)
392 return err;
393
394 err = cbs_vp9_read_superframe_index(ctx, &gbc, &sfi);
395 if (err < 0)
396 return err;
397
398 pos = 0;
399 for (i = 0; i <= sfi.frames_in_superframe_minus_1; i++) {
400 if (pos + sfi.frame_sizes[i] + index_size > frag->data_size) {
401 av_log(ctx->log_ctx, AV_LOG_ERROR16, "Frame %d too large "
402 "in superframe: %"PRIu32"u"" bytes.\n",
403 i, sfi.frame_sizes[i]);
404 return AVERROR_INVALIDDATA(-(int)(('I') | (('N') << 8) | (('D') << 16) | ((
unsigned)('A') << 24)))
;
405 }
406
407 err = ff_cbs_append_unit_data(frag, 0,
408 frag->data + pos,
409 sfi.frame_sizes[i],
410 frag->data_ref);
411 if (err < 0)
412 return err;
413
414 pos += sfi.frame_sizes[i];
415 }
416 if (pos + index_size != frag->data_size) {
417 av_log(ctx->log_ctx, AV_LOG_WARNING24, "Extra padding at "
418 "end of superframe: %zu bytes.\n",
419 frag->data_size - (pos + index_size));
420 }
421
422 return 0;
423
424 } else {
425 err = ff_cbs_append_unit_data(frag, 0,
426 frag->data, frag->data_size,
427 frag->data_ref);
428 if (err < 0)
429 return err;
430 }
431
432 return 0;
433}
434
435static int cbs_vp9_read_unit(CodedBitstreamContext *ctx,
436 CodedBitstreamUnit *unit)
437{
438 VP9RawFrame *frame;
439 GetBitContext gbc;
440 int err, pos;
441
442 err = init_get_bits(&gbc, unit->data, 8 * unit->data_size);
443 if (err < 0)
444 return err;
445
446 err = ff_cbs_alloc_unit_content(ctx, unit);
447 if (err < 0)
448 return err;
449 frame = unit->content;
450
451 err = cbs_vp9_read_frame(ctx, &gbc, frame);
452 if (err < 0)
453 return err;
454
455 pos = get_bits_count(&gbc);
456 av_assert0(pos % 8 == 0)do { if (!(pos % 8 == 0)) { av_log(((void*)0), 0, "Assertion %s failed at %s:%d\n"
, "pos % 8 == 0", "/root/firefox-clang/media/ffvpx/libavcodec/cbs_vp9.c"
, 456); abort(); } } while (0)
;
457 pos /= 8;
458 av_assert0(pos <= unit->data_size)do { if (!(pos <= unit->data_size)) { av_log(((void*)0)
, 0, "Assertion %s failed at %s:%d\n", "pos <= unit->data_size"
, "/root/firefox-clang/media/ffvpx/libavcodec/cbs_vp9.c", 458
); abort(); } } while (0)
;
459
460 if (pos == unit->data_size) {
461 // No data (e.g. a show-existing-frame frame).
462 } else {
463 frame->data_ref = av_buffer_ref(unit->data_ref);
464 if (!frame->data_ref)
465 return AVERROR(ENOMEM)(-(12));
466
467 frame->data = unit->data + pos;
468 frame->data_size = unit->data_size - pos;
469 }
470
471 return 0;
472}
473
474static int cbs_vp9_write_unit(CodedBitstreamContext *ctx,
475 CodedBitstreamUnit *unit,
476 PutBitContext *pbc)
477{
478 VP9RawFrame *frame = unit->content;
479 int err;
480
481 err = cbs_vp9_write_frame(ctx, pbc, frame);
482 if (err < 0)
483 return err;
484
485 // Frame must be byte-aligned.
486 av_assert0(put_bits_count(pbc) % 8 == 0)do { if (!(put_bits_count(pbc) % 8 == 0)) { av_log(((void*)0)
, 0, "Assertion %s failed at %s:%d\n", "put_bits_count(pbc) % 8 == 0"
, "/root/firefox-clang/media/ffvpx/libavcodec/cbs_vp9.c", 486
); abort(); } } while (0)
;
487
488 if (frame->data) {
489 if (frame->data_size > put_bits_left(pbc) / 8)
490 return AVERROR(ENOSPC)(-(28));
491
492 flush_put_bits(pbc);
493 memcpy(put_bits_ptr(pbc), frame->data, frame->data_size);
494 skip_put_bytes(pbc, frame->data_size);
495 }
496
497 return 0;
498}
499
500static int cbs_vp9_assemble_fragment(CodedBitstreamContext *ctx,
501 CodedBitstreamFragment *frag)
502{
503 int err;
504
505 if (frag->nb_units == 1) {
1
Assuming field 'nb_units' is not equal to 1
2
Taking false branch
506 // Output is just the content of the single frame.
507
508 CodedBitstreamUnit *frame = &frag->units[0];
509
510 frag->data_ref = av_buffer_ref(frame->data_ref);
511 if (!frag->data_ref)
512 return AVERROR(ENOMEM)(-(12));
513
514 frag->data = frame->data;
515 frag->data_size = frame->data_size;
516
517 } else {
518 // Build superframe out of frames.
519
520 VP9RawSuperframeIndex sfi;
521 PutBitContext pbc;
522 AVBufferRef *ref;
523 uint8_t *data;
524 size_t size, max, pos;
525 int i, size_len;
526
527 if (frag->nb_units > 8) {
3
Assuming field 'nb_units' is <= 8
4
Taking false branch
528 av_log(ctx->log_ctx, AV_LOG_ERROR16, "Too many frames to "
529 "make superframe: %d.\n", frag->nb_units);
530 return AVERROR(EINVAL)(-(22));
531 }
532
533 max = 0;
534 for (i = 0; i < frag->nb_units; i++)
5
Assuming 'i' is >= field 'nb_units'
6
Loop condition is false. Execution continues on line 538
535 if (max < frag->units[i].data_size)
536 max = frag->units[i].data_size;
537
538 if (max
6.1
'max' is < 2
6.1
'max' is < 2
< 2)
7
Taking true branch
539 size_len = 1;
540 else
541 size_len = av_log2(max)(31 - __builtin_clz((max)|1)) / 8 + 1;
542 av_assert0(size_len <= 4)do { if (!(size_len <= 4)) { av_log(((void*)0), 0, "Assertion %s failed at %s:%d\n"
, "size_len <= 4", "/root/firefox-clang/media/ffvpx/libavcodec/cbs_vp9.c"
, 542); abort(); } } while (0)
;
8
Taking false branch
9
Loop condition is false. Exiting loop
543
544 sfi.superframe_marker = VP9_SUPERFRAME_MARKER;
545 sfi.bytes_per_framesize_minus_1 = size_len - 1;
546 sfi.frames_in_superframe_minus_1 = frag->nb_units - 1;
547
548 size = 2;
549 for (i = 0; i
9.1
'i' is >= field 'nb_units'
9.1
'i' is >= field 'nb_units'
< frag->nb_units; i++) {
10
Loop condition is false. Execution continues on line 554
550 size += size_len + frag->units[i].data_size;
551 sfi.frame_sizes[i] = frag->units[i].data_size;
552 }
553
554 ref = av_buffer_alloc(size + AV_INPUT_BUFFER_PADDING_SIZE64);
555 if (!ref)
11
Assuming 'ref' is non-null
12
Taking false branch
556 return AVERROR(ENOMEM)(-(12));
557 data = ref->data;
558 memset(data + size, 0, AV_INPUT_BUFFER_PADDING_SIZE64);
559
560 pos = 0;
561 for (i = 0; i
12.1
'i' is >= field 'nb_units'
12.1
'i' is >= field 'nb_units'
< frag->nb_units; i++) {
13
Loop condition is false. Execution continues on line 567
562 av_assert0(size - pos > frag->units[i].data_size)do { if (!(size - pos > frag->units[i].data_size)) { av_log
(((void*)0), 0, "Assertion %s failed at %s:%d\n", "size - pos > frag->units[i].data_size"
, "/root/firefox-clang/media/ffvpx/libavcodec/cbs_vp9.c", 562
); abort(); } } while (0)
;
563 memcpy(data + pos, frag->units[i].data,
564 frag->units[i].data_size);
565 pos += frag->units[i].data_size;
566 }
567 av_assert0(size - pos == 2 + frag->nb_units * size_len)do { if (!(size - pos == 2 + frag->nb_units * size_len)) {
av_log(((void*)0), 0, "Assertion %s failed at %s:%d\n", "size - pos == 2 + frag->nb_units * size_len"
, "/root/firefox-clang/media/ffvpx/libavcodec/cbs_vp9.c", 567
); abort(); } } while (0)
;
14
Assuming the condition is true
15
Taking false branch
16
Loop condition is false. Exiting loop
568
569 init_put_bits(&pbc, data + pos, size - pos);
570
571 err = cbs_vp9_write_superframe_index(ctx, &pbc, &sfi);
17
Calling 'cbs_vp9_write_superframe_index'
572 if (err < 0) {
573 av_log(ctx->log_ctx, AV_LOG_ERROR16, "Failed to write "
574 "superframe index.\n");
575 av_buffer_unref(&ref);
576 return err;
577 }
578
579 av_assert0(put_bits_left(&pbc) == 0)do { if (!(put_bits_left(&pbc) == 0)) { av_log(((void*)0)
, 0, "Assertion %s failed at %s:%d\n", "put_bits_left(&pbc) == 0"
, "/root/firefox-clang/media/ffvpx/libavcodec/cbs_vp9.c", 579
); abort(); } } while (0)
;
580 flush_put_bits(&pbc);
581
582 frag->data_ref = ref;
583 frag->data = data;
584 frag->data_size = size;
585 }
586
587 return 0;
588}
589
590static av_cold__attribute__((cold)) void cbs_vp9_flush(CodedBitstreamContext *ctx)
591{
592 CodedBitstreamVP9Context *vp9 = ctx->priv_data;
593
594 memset(vp9->ref, 0, sizeof(vp9->ref));
595}
596
597static CodedBitstreamUnitTypeDescriptor cbs_vp9_unit_types[] = {
598 CBS_UNIT_TYPE_INTERNAL_REF(0, VP9RawFrame, data){ .nb_unit_types = (sizeof((CodedBitstreamUnitType[]){ 0 }) /
sizeof(((CodedBitstreamUnitType[]){ 0 })[0])), .unit_type.list
= { 0 }, .content_type = CBS_CONTENT_TYPE_INTERNAL_REFS, .content_size
= sizeof(VP9RawFrame), .type.ref = { .nb_offsets = 1, .offsets
= { __builtin_offsetof(VP9RawFrame, data) } }, }
,
599 CBS_UNIT_TYPE_END_OF_LIST{ .nb_unit_types = 0 }
600};
601
602const CodedBitstreamType ff_cbs_type_vp9 = {
603 .codec_id = AV_CODEC_ID_VP9,
604
605 .priv_data_size = sizeof(CodedBitstreamVP9Context),
606
607 .unit_types = cbs_vp9_unit_types,
608
609 .split_fragment = &cbs_vp9_split_fragment,
610 .read_unit = &cbs_vp9_read_unit,
611 .write_unit = &cbs_vp9_write_unit,
612
613 .flush = &cbs_vp9_flush,
614
615 .assemble_fragment = &cbs_vp9_assemble_fragment,
616};

/root/firefox-clang/media/ffvpx/libavcodec/cbs_vp9_syntax_template.c

1/*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg 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 * FFmpeg 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 FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19static int FUNC(frame_sync_code)cbs_vp9_READWRITE_frame_sync_code(CodedBitstreamContext *ctx, RWContext *rw,
20 VP9RawFrameHeader *current)
21{
22 int err;
23
24 fixed(8, frame_sync_byte_0, VP9_FRAME_SYNC_0);
25 fixed(8, frame_sync_byte_1, VP9_FRAME_SYNC_1);
26 fixed(8, frame_sync_byte_2, VP9_FRAME_SYNC_2);
27
28 return 0;
29}
30
31static int FUNC(color_config)cbs_vp9_READWRITE_color_config(CodedBitstreamContext *ctx, RWContext *rw,
32 VP9RawFrameHeader *current, int profile)
33{
34 CodedBitstreamVP9Context *vp9 = ctx->priv_data;
35 int err;
36
37 if (profile >= 2) {
38 f(1, ten_or_twelve_bit);
39 vp9->bit_depth = current->ten_or_twelve_bit ? 12 : 10;
40 } else
41 vp9->bit_depth = 8;
42
43 f(3, color_space);
44
45 if (current->color_space != VP9_CS_RGB) {
46 f(1, color_range);
47 if (profile == 1 || profile == 3) {
48 f(1, subsampling_x);
49 f(1, subsampling_y);
50 fixed(1, reserved_zero, 0);
51 } else {
52 infer(subsampling_x, 1);
53 infer(subsampling_y, 1);
54 }
55 } else {
56 infer(color_range, 1);
57 if (profile == 1 || profile == 3) {
58 infer(subsampling_x, 0);
59 infer(subsampling_y, 0);
60 fixed(1, reserved_zero, 0);
61 }
62 }
63
64 vp9->subsampling_x = current->subsampling_x;
65 vp9->subsampling_y = current->subsampling_y;
66
67 return 0;
68}
69
70static int FUNC(frame_size)cbs_vp9_READWRITE_frame_size(CodedBitstreamContext *ctx, RWContext *rw,
71 VP9RawFrameHeader *current)
72{
73 CodedBitstreamVP9Context *vp9 = ctx->priv_data;
74 int err;
75
76 f(16, frame_width_minus_1);
77 f(16, frame_height_minus_1);
78
79 vp9->frame_width = current->frame_width_minus_1 + 1;
80 vp9->frame_height = current->frame_height_minus_1 + 1;
81
82 vp9->mi_cols = (vp9->frame_width + 7) >> 3;
83 vp9->mi_rows = (vp9->frame_height + 7) >> 3;
84 vp9->sb64_cols = (vp9->mi_cols + 7) >> 3;
85 vp9->sb64_rows = (vp9->mi_rows + 7) >> 3;
86
87 return 0;
88}
89
90static int FUNC(render_size)cbs_vp9_READWRITE_render_size(CodedBitstreamContext *ctx, RWContext *rw,
91 VP9RawFrameHeader *current)
92{
93 int err;
94
95 f(1, render_and_frame_size_different);
96
97 if (current->render_and_frame_size_different) {
98 f(16, render_width_minus_1);
99 f(16, render_height_minus_1);
100 }
101
102 return 0;
103}
104
105static int FUNC(frame_size_with_refs)cbs_vp9_READWRITE_frame_size_with_refs(CodedBitstreamContext *ctx, RWContext *rw,
106 VP9RawFrameHeader *current)
107{
108 CodedBitstreamVP9Context *vp9 = ctx->priv_data;
109 int err, i;
110
111 for (i = 0; i < VP9_REFS_PER_FRAME; i++) {
112 fs(1, found_ref[i], 1, i)xf(1, found_ref[i], current->found_ref[i], 1, i);
113 if (current->found_ref[i]) {
114 VP9ReferenceFrameState *ref =
115 &vp9->ref[current->ref_frame_idx[i]];
116
117 vp9->frame_width = ref->frame_width;
118 vp9->frame_height = ref->frame_height;
119
120 vp9->subsampling_x = ref->subsampling_x;
121 vp9->subsampling_y = ref->subsampling_y;
122 vp9->bit_depth = ref->bit_depth;
123
124 break;
125 }
126 }
127 if (i >= VP9_REFS_PER_FRAME)
128 CHECK(FUNC(frame_size)(ctx, rw, current))do { err = (cbs_vp9_READWRITE_frame_size(ctx, rw, current)); if
(err < 0) return err; } while (0)
;
129 else {
130 vp9->mi_cols = (vp9->frame_width + 7) >> 3;
131 vp9->mi_rows = (vp9->frame_height + 7) >> 3;
132 vp9->sb64_cols = (vp9->mi_cols + 7) >> 3;
133 vp9->sb64_rows = (vp9->mi_rows + 7) >> 3;
134 }
135 CHECK(FUNC(render_size)(ctx, rw, current))do { err = (cbs_vp9_READWRITE_render_size(ctx, rw, current));
if (err < 0) return err; } while (0)
;
136
137 return 0;
138}
139
140static int FUNC(interpolation_filter)cbs_vp9_READWRITE_interpolation_filter(CodedBitstreamContext *ctx, RWContext *rw,
141 VP9RawFrameHeader *current)
142{
143 int err;
144
145 f(1, is_filter_switchable);
146 if (!current->is_filter_switchable)
147 f(2, raw_interpolation_filter_type);
148
149 return 0;
150}
151
152static int FUNC(loop_filter_params)cbs_vp9_READWRITE_loop_filter_params(CodedBitstreamContext *ctx, RWContext *rw,
153 VP9RawFrameHeader *current)
154{
155 int err, i;
156
157 f(6, loop_filter_level);
158 f(3, loop_filter_sharpness);
159
160 f(1, loop_filter_delta_enabled);
161 if (current->loop_filter_delta_enabled) {
162 f(1, loop_filter_delta_update);
163 if (current->loop_filter_delta_update) {
164 for (i = 0; i < VP9_MAX_REF_FRAMES; i++) {
165 fs(1, update_ref_delta[i], 1, i)xf(1, update_ref_delta[i], current->update_ref_delta[i], 1
, i)
;
166 if (current->update_ref_delta[i])
167 ss(6, loop_filter_ref_deltas[i], 1, i)xs(6, loop_filter_ref_deltas[i], current->loop_filter_ref_deltas
[i], 1, i)
;
168 }
169 for (i = 0; i < 2; i++) {
170 fs(1, update_mode_delta[i], 1, i)xf(1, update_mode_delta[i], current->update_mode_delta[i],
1, i)
;
171 if (current->update_mode_delta[i])
172 ss(6, loop_filter_mode_deltas[i], 1, i)xs(6, loop_filter_mode_deltas[i], current->loop_filter_mode_deltas
[i], 1, i)
;
173 }
174 }
175 } else {
176 infer(loop_filter_delta_update, 0);
177 }
178
179 return 0;
180}
181
182static int FUNC(quantization_params)cbs_vp9_READWRITE_quantization_params(CodedBitstreamContext *ctx, RWContext *rw,
183 VP9RawFrameHeader *current)
184{
185 int err;
186
187 f(8, base_q_idx);
188
189 delta_q(delta_q_y_dc);
190 delta_q(delta_q_uv_dc);
191 delta_q(delta_q_uv_ac);
192
193 return 0;
194}
195
196static int FUNC(segmentation_params)cbs_vp9_READWRITE_segmentation_params(CodedBitstreamContext *ctx, RWContext *rw,
197 VP9RawFrameHeader *current)
198{
199 static const uint8_t segmentation_feature_bits[VP9_SEG_LVL_MAX] = { 8, 6, 2, 0 };
200 static const uint8_t segmentation_feature_signed[VP9_SEG_LVL_MAX] = { 1, 1, 0, 0 };
201 int err, i, j;
202
203 f(1, segmentation_enabled);
204
205 if (current->segmentation_enabled) {
206 f(1, segmentation_update_map);
207 if (current->segmentation_update_map) {
208 for (i = 0; i < 7; i++)
209 prob(segmentation_tree_probs[i], 1, i);
210 f(1, segmentation_temporal_update);
211 for (i = 0; i < 3; i++) {
212 if (current->segmentation_temporal_update)
213 prob(segmentation_pred_prob[i], 1, i);
214 else
215 infer(segmentation_pred_prob[i], 255);
216 }
217 }
218
219 f(1, segmentation_update_data);
220 if (current->segmentation_update_data) {
221 f(1, segmentation_abs_or_delta_update);
222 for (i = 0; i < VP9_MAX_SEGMENTS; i++) {
223 for (j = 0; j < VP9_SEG_LVL_MAX; j++) {
224 fs(1, feature_enabled[i][j], 2, i, j)xf(1, feature_enabled[i][j], current->feature_enabled[i][j
], 2, i, j)
;
225 if (current->feature_enabled[i][j] &&
226 segmentation_feature_bits[j]) {
227 fs(segmentation_feature_bits[j],xf(segmentation_feature_bits[j], feature_value[i][j], current
->feature_value[i][j], 2, i, j)
228 feature_value[i][j], 2, i, j)xf(segmentation_feature_bits[j], feature_value[i][j], current
->feature_value[i][j], 2, i, j)
;
229 if (segmentation_feature_signed[j])
230 fs(1, feature_sign[i][j], 2, i, j)xf(1, feature_sign[i][j], current->feature_sign[i][j], 2, i
, j)
;
231 else
232 infer(feature_sign[i][j], 0);
233 } else {
234 infer(feature_value[i][j], 0);
235 infer(feature_sign[i][j], 0);
236 }
237 }
238 }
239 }
240 } else {
241 infer(segmentation_update_data, 0);
242 }
243
244 return 0;
245}
246
247static int FUNC(tile_info)cbs_vp9_READWRITE_tile_info(CodedBitstreamContext *ctx, RWContext *rw,
248 VP9RawFrameHeader *current)
249{
250 CodedBitstreamVP9Context *vp9 = ctx->priv_data;
251 int min_log2_tile_cols, max_log2_tile_cols;
252 int err;
253
254 min_log2_tile_cols = 0;
255 while ((VP9_MAX_TILE_WIDTH_B64 << min_log2_tile_cols) < vp9->sb64_cols)
256 ++min_log2_tile_cols;
257 max_log2_tile_cols = 0;
258 while ((vp9->sb64_cols >> (max_log2_tile_cols + 1)) >= VP9_MIN_TILE_WIDTH_B64)
259 ++max_log2_tile_cols;
260
261 increment(tile_cols_log2, min_log2_tile_cols, max_log2_tile_cols);
262
263 increment(tile_rows_log2, 0, 2);
264
265 return 0;
266}
267
268static int FUNC(uncompressed_header)cbs_vp9_READWRITE_uncompressed_header(CodedBitstreamContext *ctx, RWContext *rw,
269 VP9RawFrameHeader *current)
270{
271 CodedBitstreamVP9Context *vp9 = ctx->priv_data;
272 int err, i;
273
274 f(2, frame_marker);
275
276 f(1, profile_low_bit);
277 f(1, profile_high_bit);
278 vp9->profile = (current->profile_high_bit << 1) + current->profile_low_bit;
279 if (vp9->profile == 3)
280 fixed(1, reserved_zero, 0);
281
282 f(1, show_existing_frame);
283 if (current->show_existing_frame) {
284 f(3, frame_to_show_map_idx);
285 infer(header_size_in_bytes, 0);
286 infer(refresh_frame_flags, 0x00);
287 infer(loop_filter_level, 0);
288 return 0;
289 }
290
291 f(1, frame_type);
292 f(1, show_frame);
293 f(1, error_resilient_mode);
294
295 if (current->frame_type == VP9_KEY_FRAME) {
296 CHECK(FUNC(frame_sync_code)(ctx, rw, current))do { err = (cbs_vp9_READWRITE_frame_sync_code(ctx, rw, current
)); if (err < 0) return err; } while (0)
;
297 CHECK(FUNC(color_config)(ctx, rw, current, vp9->profile))do { err = (cbs_vp9_READWRITE_color_config(ctx, rw, current, vp9
->profile)); if (err < 0) return err; } while (0)
;
298 CHECK(FUNC(frame_size)(ctx, rw, current))do { err = (cbs_vp9_READWRITE_frame_size(ctx, rw, current)); if
(err < 0) return err; } while (0)
;
299 CHECK(FUNC(render_size)(ctx, rw, current))do { err = (cbs_vp9_READWRITE_render_size(ctx, rw, current));
if (err < 0) return err; } while (0)
;
300
301 infer(refresh_frame_flags, 0xff);
302
303 } else {
304 if (current->show_frame == 0)
305 f(1, intra_only);
306 else
307 infer(intra_only, 0);
308
309 if (current->error_resilient_mode == 0)
310 f(2, reset_frame_context);
311 else
312 infer(reset_frame_context, 0);
313
314 if (current->intra_only == 1) {
315 CHECK(FUNC(frame_sync_code)(ctx, rw, current))do { err = (cbs_vp9_READWRITE_frame_sync_code(ctx, rw, current
)); if (err < 0) return err; } while (0)
;
316
317 if (vp9->profile > 0) {
318 CHECK(FUNC(color_config)(ctx, rw, current, vp9->profile))do { err = (cbs_vp9_READWRITE_color_config(ctx, rw, current, vp9
->profile)); if (err < 0) return err; } while (0)
;
319 } else {
320 infer(color_space, 1);
321 infer(subsampling_x, 1);
322 infer(subsampling_y, 1);
323 vp9->bit_depth = 8;
324
325 vp9->subsampling_x = current->subsampling_x;
326 vp9->subsampling_y = current->subsampling_y;
327 }
328
329 f(8, refresh_frame_flags);
330
331 CHECK(FUNC(frame_size)(ctx, rw, current))do { err = (cbs_vp9_READWRITE_frame_size(ctx, rw, current)); if
(err < 0) return err; } while (0)
;
332 CHECK(FUNC(render_size)(ctx, rw, current))do { err = (cbs_vp9_READWRITE_render_size(ctx, rw, current));
if (err < 0) return err; } while (0)
;
333 } else {
334 f(8, refresh_frame_flags);
335
336 for (i = 0; i < VP9_REFS_PER_FRAME; i++) {
337 fs(3, ref_frame_idx[i], 1, i)xf(3, ref_frame_idx[i], current->ref_frame_idx[i], 1, i);
338 fs(1, ref_frame_sign_bias[VP9_LAST_FRAME + i],xf(1, ref_frame_sign_bias[VP9_LAST_FRAME + i], current->ref_frame_sign_bias
[VP9_LAST_FRAME + i], 1, VP9_LAST_FRAME + i)
339 1, VP9_LAST_FRAME + i)xf(1, ref_frame_sign_bias[VP9_LAST_FRAME + i], current->ref_frame_sign_bias
[VP9_LAST_FRAME + i], 1, VP9_LAST_FRAME + i)
;
340 }
341
342 CHECK(FUNC(frame_size_with_refs)(ctx, rw, current))do { err = (cbs_vp9_READWRITE_frame_size_with_refs(ctx, rw, current
)); if (err < 0) return err; } while (0)
;
343 f(1, allow_high_precision_mv);
344 CHECK(FUNC(interpolation_filter)(ctx, rw, current))do { err = (cbs_vp9_READWRITE_interpolation_filter(ctx, rw, current
)); if (err < 0) return err; } while (0)
;
345 }
346 }
347
348 if (current->error_resilient_mode == 0) {
349 f(1, refresh_frame_context);
350 f(1, frame_parallel_decoding_mode);
351 } else {
352 infer(refresh_frame_context, 0);
353 infer(frame_parallel_decoding_mode, 1);
354 }
355
356 f(2, frame_context_idx);
357
358 CHECK(FUNC(loop_filter_params)(ctx, rw, current))do { err = (cbs_vp9_READWRITE_loop_filter_params(ctx, rw, current
)); if (err < 0) return err; } while (0)
;
359 CHECK(FUNC(quantization_params)(ctx, rw, current))do { err = (cbs_vp9_READWRITE_quantization_params(ctx, rw, current
)); if (err < 0) return err; } while (0)
;
360 CHECK(FUNC(segmentation_params)(ctx, rw, current))do { err = (cbs_vp9_READWRITE_segmentation_params(ctx, rw, current
)); if (err < 0) return err; } while (0)
;
361 CHECK(FUNC(tile_info)(ctx, rw, current))do { err = (cbs_vp9_READWRITE_tile_info(ctx, rw, current)); if
(err < 0) return err; } while (0)
;
362
363 f(16, header_size_in_bytes);
364
365 for (i = 0; i < VP9_NUM_REF_FRAMES; i++) {
366 if (current->refresh_frame_flags & (1 << i)) {
367 vp9->ref[i] = (VP9ReferenceFrameState) {
368 .frame_width = vp9->frame_width,
369 .frame_height = vp9->frame_height,
370 .subsampling_x = vp9->subsampling_x,
371 .subsampling_y = vp9->subsampling_y,
372 .bit_depth = vp9->bit_depth,
373 };
374 }
375 }
376
377 // Update top-level loop filter and segmentation state with changes
378 // from this frame.
379 if (current->frame_type == VP9_KEY_FRAME ||
380 current->intra_only ||
381 current->error_resilient_mode) {
382 // setup_past_independence() - fill with the initial values.
383
384 vp9->loop_filter_ref_deltas[VP9_INTRA_FRAME] = 1;
385 vp9->loop_filter_ref_deltas[VP9_LAST_FRAME] = 0;
386 vp9->loop_filter_ref_deltas[VP9_GOLDEN_FRAME] = -1;
387 vp9->loop_filter_ref_deltas[VP9_ALTREF_FRAME] = -1;
388
389 vp9->loop_filter_mode_deltas[0] = 0;
390 vp9->loop_filter_mode_deltas[1] = 0;
391
392 memset(vp9->feature_enabled, 0, sizeof(vp9->feature_enabled));
393 memset(vp9->feature_value, 0, sizeof(vp9->feature_value));
394 memset(vp9->feature_sign, 0, sizeof(vp9->feature_sign));
395 }
396
397 // Modify previous state based on updates in this frame.
398 if (current->loop_filter_delta_update) {
399 for (i = 0; i < 4; i++) {
400 if (current->update_ref_delta[i])
401 vp9->loop_filter_ref_deltas[i] =
402 current->loop_filter_ref_deltas[i];
403 }
404 for (i = 0; i < 2; i++) {
405 if (current->update_mode_delta[i])
406 vp9->loop_filter_mode_deltas[i] =
407 current->loop_filter_mode_deltas[i];
408 }
409 }
410
411 if (current->segmentation_update_data) {
412 memcpy(vp9->feature_enabled, current->feature_enabled,
413 sizeof(vp9->feature_enabled));
414 memcpy(vp9->feature_value, current->feature_value,
415 sizeof(vp9->feature_value));
416 memcpy(vp9->feature_sign, current->feature_sign,
417 sizeof(vp9->feature_sign));
418
419 if (current->segmentation_update_map) {
420 memcpy(vp9->segmentation_tree_probs,
421 current->segmentation_tree_probs,
422 sizeof(vp9->segmentation_tree_probs));
423 memcpy(vp9->segmentation_pred_prob,
424 current->segmentation_pred_prob,
425 sizeof(vp9->segmentation_pred_prob));
426 }
427 }
428
429 av_log(ctx->log_ctx, AV_LOG_DEBUG48, "Frame: size %dx%d "
430 "subsample %dx%d bit_depth %d tiles %dx%d.\n",
431 vp9->frame_width, vp9->frame_height,
432 vp9->subsampling_x, vp9->subsampling_y,
433 vp9->bit_depth, 1 << current->tile_cols_log2,
434 1 << current->tile_rows_log2);
435
436 return 0;
437}
438
439static int FUNC(trailing_bits)cbs_vp9_READWRITE_trailing_bits(CodedBitstreamContext *ctx, RWContext *rw)
440{
441 int err;
442 while (byte_alignment(rw) != 0)
443 fixed(1, zero_bit, 0);
444
445 return 0;
446}
447
448static int FUNC(frame)cbs_vp9_READWRITE_frame(CodedBitstreamContext *ctx, RWContext *rw,
449 VP9RawFrame *current)
450{
451 int err;
452
453 HEADER("Frame")do { ff_cbs_trace_header(ctx, "Frame"); } while (0);
454
455 CHECK(FUNC(uncompressed_header)(ctx, rw, &current->header))do { err = (cbs_vp9_READWRITE_uncompressed_header(ctx, rw, &
current->header)); if (err < 0) return err; } while (0)
;
456
457 CHECK(FUNC(trailing_bits)(ctx, rw))do { err = (cbs_vp9_READWRITE_trailing_bits(ctx, rw)); if (err
< 0) return err; } while (0)
;
458
459 return 0;
460}
461
462static int FUNC(superframe_index)cbs_vp9_READWRITE_superframe_index(CodedBitstreamContext *ctx, RWContext *rw,
463 VP9RawSuperframeIndex *current)
464{
465 int err, i;
466
467 HEADER("Superframe Index")do { ff_cbs_trace_header(ctx, "Superframe Index"); } while (0
)
;
18
Loop condition is false. Exiting loop
468
469 f(3, superframe_marker);
19
Assuming 'err' is >= 0
20
Taking false branch
21
Loop condition is false. Exiting loop
22
Loop condition is false. Exiting loop
470 f(2, bytes_per_framesize_minus_1);
23
Assuming 'err' is >= 0
24
Taking false branch
25
Loop condition is false. Exiting loop
26
Loop condition is false. Exiting loop
471 f(3, frames_in_superframe_minus_1);
27
Assuming 'err' is >= 0
28
Taking false branch
29
Loop condition is false. Exiting loop
30
Loop condition is false. Exiting loop
472
473 for (i = 0; i <= current->frames_in_superframe_minus_1; i++) {
31
The value 0 is assigned to 'i'
32
Loop condition is true. Entering loop body
474 // Surprise little-endian!
475 fle(8 * (current->bytes_per_framesize_minus_1 + 1),
33
'?' condition is true
34
6th function call argument is an uninitialized value
476 frame_sizes[i], 1, i);
477 }
478
479 f(3, superframe_marker);
480 f(2, bytes_per_framesize_minus_1);
481 f(3, frames_in_superframe_minus_1);
482
483 return 0;
484}