Bug Summary

File:root/firefox-clang/third_party/aom/av1/decoder/decodemv.c
Warning:line 505, column 5
The first element of the 2nd argument is undefined
Note:line 505, column 5
Other elements might also be undefined

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 decodemv.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/libaom -fcoverage-compilation-dir=/root/firefox-clang/obj-x86_64-pc-linux-gnu/media/libaom -resource-dir /usr/lib/llvm-23/lib/clang/23 -include /root/firefox-clang/obj-x86_64-pc-linux-gnu/mozilla-config.h -U _FORTIFY_SOURCE -D _FORTIFY_SOURCE=2 -D DEBUG=1 -D MOZ_HAS_MOZGLUE -I /root/firefox-clang/media/libaom -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/media/libaom -I /root/firefox-clang/media/libaom/config/linux/x64 -I /root/firefox-clang/media/libaom/config -I /root/firefox-clang/third_party/aom -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-sign-compare -Wno-unused-function -Wno-unreachable-code -Wno-unneeded-internal-declaration -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/third_party/aom/av1/decoder/decodemv.c
1/*
2 * Copyright (c) 2016, Alliance for Open Media. All rights reserved.
3 *
4 * This source code is subject to the terms of the BSD 2 Clause License and
5 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6 * was not distributed with this source code in the LICENSE file, you can
7 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8 * Media Patent License 1.0 was not distributed with this source code in the
9 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10 */
11
12#include <assert.h>
13
14#include "av1/common/cfl.h"
15#include "av1/common/common.h"
16#include "av1/common/entropy.h"
17#include "av1/common/entropymode.h"
18#include "av1/common/entropymv.h"
19#include "av1/common/mvref_common.h"
20#include "av1/common/pred_common.h"
21#include "av1/common/reconinter.h"
22#include "av1/common/reconintra.h"
23#include "av1/common/seg_common.h"
24#include "av1/common/warped_motion.h"
25
26#include "av1/decoder/decodeframe.h"
27#include "av1/decoder/decodemv.h"
28
29#include "aom_dsp/aom_dsp_common.h"
30#include "aom_ports/bitops.h"
31
32#define ACCT_STR__func__ __func__
33
34#define DEC_MISMATCH_DEBUG0 0
35
36static PREDICTION_MODE read_intra_mode(aom_reader *r, aom_cdf_prob *cdf) {
37 return (PREDICTION_MODE)aom_read_symbol(r, cdf, INTRA_MODES, ACCT_STR)aom_read_symbol_(r, cdf, INTRA_MODES );
38}
39
40static void read_cdef(AV1_COMMON *cm, aom_reader *r, MACROBLOCKD *const xd) {
41 const int skip_txfm = xd->mi[0]->skip_txfm;
42 if (cm->features.coded_lossless) return;
43 if (cm->features.allow_intrabc) {
44 assert(cm->cdef_info.cdef_bits == 0)((void) sizeof ((cm->cdef_info.cdef_bits == 0) ? 1 : 0), __extension__
({ if (cm->cdef_info.cdef_bits == 0) ; else __assert_fail
("cm->cdef_info.cdef_bits == 0", "/root/firefox-clang/third_party/aom/av1/decoder/decodemv.c"
, 44, __extension__ __PRETTY_FUNCTION__); }))
;
45 return;
46 }
47
48 // At the start of a superblock, mark that we haven't yet read CDEF strengths
49 // for any of the CDEF units contained in this superblock.
50 const int sb_mask = (cm->seq_params->mib_size - 1);
51 const int mi_row_in_sb = (xd->mi_row & sb_mask);
52 const int mi_col_in_sb = (xd->mi_col & sb_mask);
53 if (mi_row_in_sb == 0 && mi_col_in_sb == 0) {
54 xd->cdef_transmitted[0] = xd->cdef_transmitted[1] =
55 xd->cdef_transmitted[2] = xd->cdef_transmitted[3] = false0;
56 }
57
58 // CDEF unit size is 64x64 irrespective of the superblock size.
59 const int cdef_size = 1 << (6 - MI_SIZE_LOG22);
60
61 // Find index of this CDEF unit in this superblock.
62 const int index_mask = cdef_size;
63 const int cdef_unit_row_in_sb = ((xd->mi_row & index_mask) != 0);
64 const int cdef_unit_col_in_sb = ((xd->mi_col & index_mask) != 0);
65 const int index = (cm->seq_params->sb_size == BLOCK_128X128)
66 ? cdef_unit_col_in_sb + 2 * cdef_unit_row_in_sb
67 : 0;
68
69 // Read CDEF strength from the first non-skip coding block in this CDEF unit.
70 if (!xd->cdef_transmitted[index] && !skip_txfm) {
71 // CDEF strength for this CDEF unit needs to be read into the MB_MODE_INFO
72 // of the 1st block in this CDEF unit.
73 const int first_block_mask = ~(cdef_size - 1);
74 CommonModeInfoParams *const mi_params = &cm->mi_params;
75 const int grid_idx =
76 get_mi_grid_idx(mi_params, xd->mi_row & first_block_mask,
77 xd->mi_col & first_block_mask);
78 MB_MODE_INFO *const mbmi = mi_params->mi_grid_base[grid_idx];
79 mbmi->cdef_strength =
80 aom_read_literal(r, cm->cdef_info.cdef_bits, ACCT_STR)aom_read_literal_(r, cm->cdef_info.cdef_bits );
81 xd->cdef_transmitted[index] = true1;
82 }
83}
84
85static int read_delta_qindex(AV1_COMMON *cm, const MACROBLOCKD *xd,
86 aom_reader *r, MB_MODE_INFO *const mbmi) {
87 int sign, abs, reduced_delta_qindex = 0;
88 BLOCK_SIZE bsize = mbmi->bsize;
89 const int b_col = xd->mi_col & (cm->seq_params->mib_size - 1);
90 const int b_row = xd->mi_row & (cm->seq_params->mib_size - 1);
91 const int read_delta_q_flag = (b_col == 0 && b_row == 0);
92 FRAME_CONTEXT *ec_ctx = xd->tile_ctx;
93
94 if ((bsize != cm->seq_params->sb_size || mbmi->skip_txfm == 0) &&
95 read_delta_q_flag) {
96 abs = aom_read_symbol(r, ec_ctx->delta_q_cdf, DELTA_Q_PROBS + 1, ACCT_STR)aom_read_symbol_(r, ec_ctx->delta_q_cdf, (3) + 1 );
97 const int smallval = (abs < DELTA_Q_SMALL3);
98
99 if (!smallval) {
100 const int rem_bits = aom_read_literal(r, 3, ACCT_STR)aom_read_literal_(r, 3 ) + 1;
101 const int thr = (1 << rem_bits) + 1;
102 abs = aom_read_literal(r, rem_bits, ACCT_STR)aom_read_literal_(r, rem_bits ) + thr;
103 }
104
105 if (abs) {
106 sign = aom_read_bit(r, ACCT_STR)aom_read_bit_(r );
107 } else {
108 sign = 1;
109 }
110
111 reduced_delta_qindex = sign ? -abs : abs;
112 }
113 return reduced_delta_qindex;
114}
115static int read_delta_lflevel(const AV1_COMMON *const cm, aom_reader *r,
116 aom_cdf_prob *const cdf,
117 const MB_MODE_INFO *const mbmi, int mi_col,
118 int mi_row) {
119 int reduced_delta_lflevel = 0;
120 const BLOCK_SIZE bsize = mbmi->bsize;
121 const int b_col = mi_col & (cm->seq_params->mib_size - 1);
122 const int b_row = mi_row & (cm->seq_params->mib_size - 1);
123 const int read_delta_lf_flag = (b_col == 0 && b_row == 0);
124
125 if ((bsize != cm->seq_params->sb_size || mbmi->skip_txfm == 0) &&
126 read_delta_lf_flag) {
127 int abs = aom_read_symbol(r, cdf, DELTA_LF_PROBS + 1, ACCT_STR)aom_read_symbol_(r, cdf, (3) + 1 );
128 const int smallval = (abs < DELTA_LF_SMALL3);
129 if (!smallval) {
130 const int rem_bits = aom_read_literal(r, 3, ACCT_STR)aom_read_literal_(r, 3 ) + 1;
131 const int thr = (1 << rem_bits) + 1;
132 abs = aom_read_literal(r, rem_bits, ACCT_STR)aom_read_literal_(r, rem_bits ) + thr;
133 }
134 const int sign = abs ? aom_read_bit(r, ACCT_STR)aom_read_bit_(r ) : 1;
135 reduced_delta_lflevel = sign ? -abs : abs;
136 }
137 return reduced_delta_lflevel;
138}
139
140static UV_PREDICTION_MODE read_intra_mode_uv(FRAME_CONTEXT *ec_ctx,
141 aom_reader *r,
142 CFL_ALLOWED_TYPE cfl_allowed,
143 PREDICTION_MODE y_mode) {
144 const UV_PREDICTION_MODE uv_mode =
145 aom_read_symbol(r, ec_ctx->uv_mode_cdf[cfl_allowed][y_mode],aom_read_symbol_(r, ec_ctx->uv_mode_cdf[cfl_allowed][y_mode
], UV_INTRA_MODES - !cfl_allowed )
146 UV_INTRA_MODES - !cfl_allowed, ACCT_STR)aom_read_symbol_(r, ec_ctx->uv_mode_cdf[cfl_allowed][y_mode
], UV_INTRA_MODES - !cfl_allowed )
;
147 return uv_mode;
148}
149
150static uint8_t read_cfl_alphas(FRAME_CONTEXT *const ec_ctx, aom_reader *r,
151 int8_t *signs_out) {
152 const int8_t joint_sign =
153 aom_read_symbol(r, ec_ctx->cfl_sign_cdf, CFL_JOINT_SIGNS, "cfl:signs")aom_read_symbol_(r, ec_ctx->cfl_sign_cdf, (CFL_SIGNS * CFL_SIGNS
- 1) )
;
154 uint8_t idx = 0;
155 // Magnitudes are only coded for nonzero values
156 if (CFL_SIGN_U(joint_sign)(((joint_sign + 1) * 11) >> 5) != CFL_SIGN_ZERO) {
157 aom_cdf_prob *cdf_u = ec_ctx->cfl_alpha_cdf[CFL_CONTEXT_U(joint_sign)(joint_sign + 1 - CFL_SIGNS)];
158 idx = (uint8_t)aom_read_symbol(r, cdf_u, CFL_ALPHABET_SIZE, "cfl:alpha_u")aom_read_symbol_(r, cdf_u, (1 << 4) )
159 << CFL_ALPHABET_SIZE_LOG24;
160 }
161 if (CFL_SIGN_V(joint_sign)((joint_sign + 1) - CFL_SIGNS * (((joint_sign + 1) * 11) >>
5))
!= CFL_SIGN_ZERO) {
162 aom_cdf_prob *cdf_v = ec_ctx->cfl_alpha_cdf[CFL_CONTEXT_V(joint_sign)(((joint_sign + 1) - CFL_SIGNS * (((joint_sign + 1) * 11) >>
5)) * CFL_SIGNS + (((joint_sign + 1) * 11) >> 5) - CFL_SIGNS
)
];
163 idx += (uint8_t)aom_read_symbol(r, cdf_v, CFL_ALPHABET_SIZE, "cfl:alpha_v")aom_read_symbol_(r, cdf_v, (1 << 4) );
164 }
165 *signs_out = joint_sign;
166 return idx;
167}
168
169static INTERINTRA_MODE read_interintra_mode(MACROBLOCKD *xd, aom_reader *r,
170 int size_group) {
171 const INTERINTRA_MODE ii_mode = (INTERINTRA_MODE)aom_read_symbol(aom_read_symbol_(r, xd->tile_ctx->interintra_mode_cdf[size_group
], INTERINTRA_MODES )
172 r, xd->tile_ctx->interintra_mode_cdf[size_group], INTERINTRA_MODES,aom_read_symbol_(r, xd->tile_ctx->interintra_mode_cdf[size_group
], INTERINTRA_MODES )
173 ACCT_STR)aom_read_symbol_(r, xd->tile_ctx->interintra_mode_cdf[size_group
], INTERINTRA_MODES )
;
174 return ii_mode;
175}
176
177static PREDICTION_MODE read_inter_mode(FRAME_CONTEXT *ec_ctx, aom_reader *r,
178 int16_t ctx) {
179 int16_t mode_ctx = ctx & NEWMV_CTX_MASK((1 << 3) - 1);
180 int is_newmv, is_zeromv, is_refmv;
181 is_newmv = aom_read_symbol(r, ec_ctx->newmv_cdf[mode_ctx], 2, ACCT_STR)aom_read_symbol_(r, ec_ctx->newmv_cdf[mode_ctx], 2 ) == 0;
182 if (is_newmv) return NEWMV;
183
184 mode_ctx = (ctx >> GLOBALMV_OFFSET3) & GLOBALMV_CTX_MASK((1 << (4 - 3)) - 1);
185 is_zeromv =
186 aom_read_symbol(r, ec_ctx->zeromv_cdf[mode_ctx], 2, ACCT_STR)aom_read_symbol_(r, ec_ctx->zeromv_cdf[mode_ctx], 2 ) == 0;
187 if (is_zeromv) return GLOBALMV;
188
189 mode_ctx = (ctx >> REFMV_OFFSET4) & REFMV_CTX_MASK((1 << (8 - 4)) - 1);
190 is_refmv = aom_read_symbol(r, ec_ctx->refmv_cdf[mode_ctx], 2, ACCT_STR)aom_read_symbol_(r, ec_ctx->refmv_cdf[mode_ctx], 2 ) == 0;
191 if (is_refmv)
192 return NEARESTMV;
193 else
194 return NEARMV;
195}
196
197static void read_drl_idx(FRAME_CONTEXT *ec_ctx, DecoderCodingBlock *dcb,
198 MB_MODE_INFO *mbmi, aom_reader *r) {
199 MACROBLOCKD *const xd = &dcb->xd;
200 uint8_t ref_frame_type = av1_ref_frame_type(mbmi->ref_frame);
201 mbmi->ref_mv_idx = 0;
202 if (mbmi->mode == NEWMV || mbmi->mode == NEW_NEWMV) {
203 for (int idx = 0; idx < 2; ++idx) {
204 if (dcb->ref_mv_count[ref_frame_type] > idx + 1) {
205 uint8_t drl_ctx = av1_drl_ctx(xd->weight[ref_frame_type], idx);
206 int drl_idx = aom_read_symbol(r, ec_ctx->drl_cdf[drl_ctx], 2, ACCT_STR)aom_read_symbol_(r, ec_ctx->drl_cdf[drl_ctx], 2 );
207 mbmi->ref_mv_idx = idx + drl_idx;
208 if (!drl_idx) return;
209 }
210 }
211 }
212 if (have_nearmv_in_inter_mode(mbmi->mode)) {
213 // Offset the NEARESTMV mode.
214 // TODO(jingning): Unify the two syntax decoding loops after the NEARESTMV
215 // mode is factored in.
216 for (int idx = 1; idx < 3; ++idx) {
217 if (dcb->ref_mv_count[ref_frame_type] > idx + 1) {
218 uint8_t drl_ctx = av1_drl_ctx(xd->weight[ref_frame_type], idx);
219 int drl_idx = aom_read_symbol(r, ec_ctx->drl_cdf[drl_ctx], 2, ACCT_STR)aom_read_symbol_(r, ec_ctx->drl_cdf[drl_ctx], 2 );
220 mbmi->ref_mv_idx = idx + drl_idx - 1;
221 if (!drl_idx) return;
222 }
223 }
224 }
225}
226
227static MOTION_MODE read_motion_mode(AV1_COMMON *cm, MACROBLOCKD *xd,
228 MB_MODE_INFO *mbmi, aom_reader *r) {
229 if (cm->features.switchable_motion_mode == 0) return SIMPLE_TRANSLATION;
230 if (mbmi->skip_mode) return SIMPLE_TRANSLATION;
231
232 const MOTION_MODE last_motion_mode_allowed = motion_mode_allowed(
233 xd->global_motion, xd, mbmi, cm->features.allow_warped_motion);
234 int motion_mode;
235
236 if (last_motion_mode_allowed == SIMPLE_TRANSLATION) return SIMPLE_TRANSLATION;
237
238 if (last_motion_mode_allowed == OBMC_CAUSAL) {
239 motion_mode =
240 aom_read_symbol(r, xd->tile_ctx->obmc_cdf[mbmi->bsize], 2, ACCT_STR)aom_read_symbol_(r, xd->tile_ctx->obmc_cdf[mbmi->bsize
], 2 )
;
241 return (MOTION_MODE)(SIMPLE_TRANSLATION + motion_mode);
242 } else {
243 motion_mode = aom_read_symbol(r, xd->tile_ctx->motion_mode_cdf[mbmi->bsize],aom_read_symbol_(r, xd->tile_ctx->motion_mode_cdf[mbmi->
bsize], MOTION_MODES )
244 MOTION_MODES, ACCT_STR)aom_read_symbol_(r, xd->tile_ctx->motion_mode_cdf[mbmi->
bsize], MOTION_MODES )
;
245 return (MOTION_MODE)(SIMPLE_TRANSLATION + motion_mode);
246 }
247}
248
249static PREDICTION_MODE read_inter_compound_mode(MACROBLOCKD *xd, aom_reader *r,
250 int16_t ctx) {
251 const int mode =
252 aom_read_symbol(r, xd->tile_ctx->inter_compound_mode_cdf[ctx],aom_read_symbol_(r, xd->tile_ctx->inter_compound_mode_cdf
[ctx], (1 + NEW_NEWMV - NEAREST_NEARESTMV) )
253 INTER_COMPOUND_MODES, ACCT_STR)aom_read_symbol_(r, xd->tile_ctx->inter_compound_mode_cdf
[ctx], (1 + NEW_NEWMV - NEAREST_NEARESTMV) )
;
254 assert(is_inter_compound_mode(NEAREST_NEARESTMV + mode))((void) sizeof ((is_inter_compound_mode(NEAREST_NEARESTMV + mode
)) ? 1 : 0), __extension__ ({ if (is_inter_compound_mode(NEAREST_NEARESTMV
+ mode)) ; else __assert_fail ("is_inter_compound_mode(NEAREST_NEARESTMV + mode)"
, "/root/firefox-clang/third_party/aom/av1/decoder/decodemv.c"
, 254, __extension__ __PRETTY_FUNCTION__); }))
;
255 return NEAREST_NEARESTMV + mode;
256}
257
258int av1_neg_deinterleave(int diff, int ref, int max) {
259 if (!ref) return diff;
260 if (ref >= (max - 1)) return max - diff - 1;
261 if (2 * ref < max) {
262 if (diff <= 2 * ref) {
263 if (diff & 1)
264 return ref + ((diff + 1) >> 1);
265 else
266 return ref - (diff >> 1);
267 }
268 return diff;
269 } else {
270 if (diff <= 2 * (max - ref - 1)) {
271 if (diff & 1)
272 return ref + ((diff + 1) >> 1);
273 else
274 return ref - (diff >> 1);
275 }
276 return max - (diff + 1);
277 }
278}
279
280static int read_segment_id(AV1_COMMON *const cm, const MACROBLOCKD *const xd,
281 aom_reader *r, int skip) {
282 int cdf_num;
283 const uint8_t pred = av1_get_spatial_seg_pred(cm, xd, &cdf_num, 0);
284 if (skip) return pred;
285
286 FRAME_CONTEXT *ec_ctx = xd->tile_ctx;
287 struct segmentation *const seg = &cm->seg;
288 struct segmentation_probs *const segp = &ec_ctx->seg;
289 aom_cdf_prob *pred_cdf = segp->spatial_pred_seg_cdf[cdf_num];
290 const int coded_id = aom_read_symbol(r, pred_cdf, MAX_SEGMENTS, ACCT_STR)aom_read_symbol_(r, pred_cdf, 8 );
291 const int segment_id =
292 av1_neg_deinterleave(coded_id, pred, seg->last_active_segid + 1);
293
294 if (segment_id < 0 || segment_id > seg->last_active_segid) {
295 aom_internal_error(xd->error_info, AOM_CODEC_CORRUPT_FRAME,
296 "Corrupted segment_ids");
297 }
298 return segment_id;
299}
300
301static int dec_get_segment_id(const AV1_COMMON *cm, const uint8_t *segment_ids,
302 int mi_offset, int x_mis, int y_mis) {
303 int segment_id = INT_MAX2147483647;
304
305 for (int y = 0; y < y_mis; y++)
306 for (int x = 0; x < x_mis; x++)
307 segment_id = AOMMIN((((segment_id) < (segment_ids[mi_offset + y * cm->mi_params
.mi_cols + x])) ? (segment_id) : (segment_ids[mi_offset + y *
cm->mi_params.mi_cols + x]))
308 segment_id, segment_ids[mi_offset + y * cm->mi_params.mi_cols + x])(((segment_id) < (segment_ids[mi_offset + y * cm->mi_params
.mi_cols + x])) ? (segment_id) : (segment_ids[mi_offset + y *
cm->mi_params.mi_cols + x]))
;
309
310 assert(segment_id >= 0 && segment_id < MAX_SEGMENTS)((void) sizeof ((segment_id >= 0 && segment_id <
8) ? 1 : 0), __extension__ ({ if (segment_id >= 0 &&
segment_id < 8) ; else __assert_fail ("segment_id >= 0 && segment_id < MAX_SEGMENTS"
, "/root/firefox-clang/third_party/aom/av1/decoder/decodemv.c"
, 310, __extension__ __PRETTY_FUNCTION__); }))
;
311 return segment_id;
312}
313
314static int read_intra_segment_id(AV1_COMMON *const cm,
315 const MACROBLOCKD *const xd, BLOCK_SIZE bsize,
316 aom_reader *r, int skip) {
317 struct segmentation *const seg = &cm->seg;
318 if (!seg->enabled) return 0; // Default for disabled segmentation
319 assert(seg->update_map && !seg->temporal_update)((void) sizeof ((seg->update_map && !seg->temporal_update
) ? 1 : 0), __extension__ ({ if (seg->update_map &&
!seg->temporal_update) ; else __assert_fail ("seg->update_map && !seg->temporal_update"
, "/root/firefox-clang/third_party/aom/av1/decoder/decodemv.c"
, 319, __extension__ __PRETTY_FUNCTION__); }))
;
320
321 const CommonModeInfoParams *const mi_params = &cm->mi_params;
322 const int mi_row = xd->mi_row;
323 const int mi_col = xd->mi_col;
324 const int mi_stride = cm->mi_params.mi_cols;
325 const int mi_offset = mi_row * mi_stride + mi_col;
326 const int bw = mi_size_wide[bsize];
327 const int bh = mi_size_high[bsize];
328 const int x_mis = AOMMIN(mi_params->mi_cols - mi_col, bw)(((mi_params->mi_cols - mi_col) < (bw)) ? (mi_params->
mi_cols - mi_col) : (bw))
;
329 const int y_mis = AOMMIN(mi_params->mi_rows - mi_row, bh)(((mi_params->mi_rows - mi_row) < (bh)) ? (mi_params->
mi_rows - mi_row) : (bh))
;
330 const int segment_id = read_segment_id(cm, xd, r, skip);
331 set_segment_id(cm->cur_frame->seg_map, mi_offset, x_mis, y_mis, mi_stride,
332 segment_id);
333 return segment_id;
334}
335
336static void copy_segment_id(const CommonModeInfoParams *const mi_params,
337 const uint8_t *last_segment_ids,
338 uint8_t *current_segment_ids, int mi_offset,
339 int x_mis, int y_mis) {
340 const int stride = mi_params->mi_cols;
341 if (last_segment_ids) {
342 assert(last_segment_ids != current_segment_ids)((void) sizeof ((last_segment_ids != current_segment_ids) ? 1
: 0), __extension__ ({ if (last_segment_ids != current_segment_ids
) ; else __assert_fail ("last_segment_ids != current_segment_ids"
, "/root/firefox-clang/third_party/aom/av1/decoder/decodemv.c"
, 342, __extension__ __PRETTY_FUNCTION__); }))
;
343 for (int y = 0; y < y_mis; y++) {
344 memcpy(&current_segment_ids[mi_offset + y * stride],
345 &last_segment_ids[mi_offset + y * stride],
346 sizeof(current_segment_ids[0]) * x_mis);
347 }
348 } else {
349 for (int y = 0; y < y_mis; y++) {
350 memset(&current_segment_ids[mi_offset + y * stride], 0,
351 sizeof(current_segment_ids[0]) * x_mis);
352 }
353 }
354}
355
356static int get_predicted_segment_id(AV1_COMMON *const cm, int mi_offset,
357 int x_mis, int y_mis) {
358 return cm->last_frame_seg_map ? dec_get_segment_id(cm, cm->last_frame_seg_map,
359 mi_offset, x_mis, y_mis)
360 : 0;
361}
362
363static int read_inter_segment_id(AV1_COMMON *const cm, MACROBLOCKD *const xd,
364 int preskip, aom_reader *r) {
365 struct segmentation *const seg = &cm->seg;
366 const CommonModeInfoParams *const mi_params = &cm->mi_params;
367 MB_MODE_INFO *const mbmi = xd->mi[0];
368 const int mi_row = xd->mi_row;
369 const int mi_col = xd->mi_col;
370 const int mi_offset = mi_row * mi_params->mi_cols + mi_col;
371 const int bw = mi_size_wide[mbmi->bsize];
372 const int bh = mi_size_high[mbmi->bsize];
373
374 // TODO(slavarnway): move x_mis, y_mis into xd ?????
375 const int x_mis = AOMMIN(mi_params->mi_cols - mi_col, bw)(((mi_params->mi_cols - mi_col) < (bw)) ? (mi_params->
mi_cols - mi_col) : (bw))
;
376 const int y_mis = AOMMIN(mi_params->mi_rows - mi_row, bh)(((mi_params->mi_rows - mi_row) < (bh)) ? (mi_params->
mi_rows - mi_row) : (bh))
;
377
378 if (!seg->enabled) return 0; // Default for disabled segmentation
379
380 if (!seg->update_map) {
381 copy_segment_id(mi_params, cm->last_frame_seg_map, cm->cur_frame->seg_map,
382 mi_offset, x_mis, y_mis);
383 return get_predicted_segment_id(cm, mi_offset, x_mis, y_mis);
384 }
385
386 uint8_t segment_id;
387 const int mi_stride = cm->mi_params.mi_cols;
388 if (preskip) {
389 if (!seg->segid_preskip) return 0;
390 } else {
391 if (mbmi->skip_txfm) {
392 if (seg->temporal_update) {
393 mbmi->seg_id_predicted = 0;
394 }
395 segment_id = read_segment_id(cm, xd, r, 1);
396 set_segment_id(cm->cur_frame->seg_map, mi_offset, x_mis, y_mis, mi_stride,
397 segment_id);
398 return segment_id;
399 }
400 }
401
402 if (seg->temporal_update) {
403 const uint8_t ctx = av1_get_pred_context_seg_id(xd);
404 FRAME_CONTEXT *ec_ctx = xd->tile_ctx;
405 struct segmentation_probs *const segp = &ec_ctx->seg;
406 aom_cdf_prob *pred_cdf = segp->pred_cdf[ctx];
407 mbmi->seg_id_predicted = aom_read_symbol(r, pred_cdf, 2, ACCT_STR)aom_read_symbol_(r, pred_cdf, 2 );
408 if (mbmi->seg_id_predicted) {
409 segment_id = get_predicted_segment_id(cm, mi_offset, x_mis, y_mis);
410 } else {
411 segment_id = read_segment_id(cm, xd, r, 0);
412 }
413 } else {
414 segment_id = read_segment_id(cm, xd, r, 0);
415 }
416 set_segment_id(cm->cur_frame->seg_map, mi_offset, x_mis, y_mis, mi_stride,
417 segment_id);
418 return segment_id;
419}
420
421static int read_skip_mode(AV1_COMMON *cm, const MACROBLOCKD *xd, int segment_id,
422 aom_reader *r) {
423 if (!cm->current_frame.skip_mode_info.skip_mode_flag) return 0;
424
425 if (segfeature_active(&cm->seg, segment_id, SEG_LVL_SKIP)) {
426 return 0;
427 }
428
429 if (!is_comp_ref_allowed(xd->mi[0]->bsize)) return 0;
430
431 if (segfeature_active(&cm->seg, segment_id, SEG_LVL_REF_FRAME) ||
432 segfeature_active(&cm->seg, segment_id, SEG_LVL_GLOBALMV)) {
433 // These features imply single-reference mode, while skip mode implies
434 // compound reference. Hence, the two are mutually exclusive.
435 // In other words, skip_mode is implicitly 0 here.
436 return 0;
437 }
438
439 const int ctx = av1_get_skip_mode_context(xd);
440 FRAME_CONTEXT *ec_ctx = xd->tile_ctx;
441 const int skip_mode =
442 aom_read_symbol(r, ec_ctx->skip_mode_cdfs[ctx], 2, ACCT_STR)aom_read_symbol_(r, ec_ctx->skip_mode_cdfs[ctx], 2 );
443 return skip_mode;
444}
445
446static int read_skip_txfm(AV1_COMMON *cm, const MACROBLOCKD *xd, int segment_id,
447 aom_reader *r) {
448 if (segfeature_active(&cm->seg, segment_id, SEG_LVL_SKIP)) {
449 return 1;
450 } else {
451 const int ctx = av1_get_skip_txfm_context(xd);
452 FRAME_CONTEXT *ec_ctx = xd->tile_ctx;
453 const int skip_txfm =
454 aom_read_symbol(r, ec_ctx->skip_txfm_cdfs[ctx], 2, ACCT_STR)aom_read_symbol_(r, ec_ctx->skip_txfm_cdfs[ctx], 2 );
455 return skip_txfm;
456 }
457}
458
459// Merge the sorted list of cached colors(cached_colors[0...n_cached_colors-1])
460// and the sorted list of transmitted colors(colors[n_cached_colors...n-1]) into
461// one single sorted list(colors[...]).
462static void merge_colors(uint16_t *colors, uint16_t *cached_colors,
463 int n_colors, int n_cached_colors) {
464 if (n_cached_colors == 0) return;
465 int cache_idx = 0, trans_idx = n_cached_colors;
466 for (int i = 0; i < n_colors; ++i) {
467 if (cache_idx < n_cached_colors &&
468 (trans_idx >= n_colors ||
469 cached_colors[cache_idx] <= colors[trans_idx])) {
470 colors[i] = cached_colors[cache_idx++];
471 } else {
472 assert(trans_idx < n_colors)((void) sizeof ((trans_idx < n_colors) ? 1 : 0), __extension__
({ if (trans_idx < n_colors) ; else __assert_fail ("trans_idx < n_colors"
, "/root/firefox-clang/third_party/aom/av1/decoder/decodemv.c"
, 472, __extension__ __PRETTY_FUNCTION__); }))
;
473 colors[i] = colors[trans_idx++];
474 }
475 }
476}
477
478static void read_palette_colors_y(MACROBLOCKD *const xd, int bit_depth,
479 PALETTE_MODE_INFO *const pmi, aom_reader *r) {
480 uint16_t color_cache[2 * PALETTE_MAX_SIZE8];
481 uint16_t cached_colors[PALETTE_MAX_SIZE8];
7
'cached_colors' declared without an initial value
482 const int n_cache = av1_get_palette_cache(xd, 0, color_cache);
483 const int n = pmi->palette_size[0];
484 int idx = 0;
485 for (int i = 0; i < n_cache && idx < n; ++i)
8
Assuming 'i' is >= 'n_cache'
486 if (aom_read_bit(r, ACCT_STR)aom_read_bit_(r )) cached_colors[idx++] = color_cache[i];
487 if (idx < n) {
9
Assuming 'idx' is >= 'n'
10
Taking false branch
488 const int n_cached_colors = idx;
489 pmi->palette_colors[idx++] = aom_read_literal(r, bit_depth, ACCT_STR)aom_read_literal_(r, bit_depth );
490 if (idx < n) {
491 const int min_bits = bit_depth - 3;
492 int bits = min_bits + aom_read_literal(r, 2, ACCT_STR)aom_read_literal_(r, 2 );
493 int range = (1 << bit_depth) - pmi->palette_colors[idx - 1] - 1;
494 for (; idx < n; ++idx) {
495 assert(range >= 0)((void) sizeof ((range >= 0) ? 1 : 0), __extension__ ({ if
(range >= 0) ; else __assert_fail ("range >= 0", "/root/firefox-clang/third_party/aom/av1/decoder/decodemv.c"
, 495, __extension__ __PRETTY_FUNCTION__); }))
;
496 const int delta = aom_read_literal(r, bits, ACCT_STR)aom_read_literal_(r, bits ) + 1;
497 pmi->palette_colors[idx] = clamp(pmi->palette_colors[idx - 1] + delta,
498 0, (1 << bit_depth) - 1);
499 range -= (pmi->palette_colors[idx] - pmi->palette_colors[idx - 1]);
500 bits = AOMMIN(bits, aom_ceil_log2(range))(((bits) < (aom_ceil_log2(range))) ? (bits) : (aom_ceil_log2
(range)))
;
501 }
502 }
503 merge_colors(pmi->palette_colors, cached_colors, n, n_cached_colors);
504 } else {
505 memcpy(pmi->palette_colors, cached_colors, n * sizeof(cached_colors[0]));
Other elements might also be undefined
11
The first element of the 2nd argument is undefined
506 }
507}
508
509static void read_palette_colors_uv(MACROBLOCKD *const xd, int bit_depth,
510 PALETTE_MODE_INFO *const pmi,
511 aom_reader *r) {
512 const int n = pmi->palette_size[1];
513 // U channel colors.
514 uint16_t color_cache[2 * PALETTE_MAX_SIZE8];
515 uint16_t cached_colors[PALETTE_MAX_SIZE8];
516 const int n_cache = av1_get_palette_cache(xd, 1, color_cache);
517 int idx = 0;
518 for (int i = 0; i < n_cache && idx < n; ++i)
519 if (aom_read_bit(r, ACCT_STR)aom_read_bit_(r )) cached_colors[idx++] = color_cache[i];
520 if (idx < n) {
521 const int n_cached_colors = idx;
522 idx += PALETTE_MAX_SIZE8;
523 pmi->palette_colors[idx++] = aom_read_literal(r, bit_depth, ACCT_STR)aom_read_literal_(r, bit_depth );
524 if (idx < PALETTE_MAX_SIZE8 + n) {
525 const int min_bits = bit_depth - 3;
526 int bits = min_bits + aom_read_literal(r, 2, ACCT_STR)aom_read_literal_(r, 2 );
527 int range = (1 << bit_depth) - pmi->palette_colors[idx - 1];
528 for (; idx < PALETTE_MAX_SIZE8 + n; ++idx) {
529 assert(range >= 0)((void) sizeof ((range >= 0) ? 1 : 0), __extension__ ({ if
(range >= 0) ; else __assert_fail ("range >= 0", "/root/firefox-clang/third_party/aom/av1/decoder/decodemv.c"
, 529, __extension__ __PRETTY_FUNCTION__); }))
;
530 const int delta = aom_read_literal(r, bits, ACCT_STR)aom_read_literal_(r, bits );
531 pmi->palette_colors[idx] = clamp(pmi->palette_colors[idx - 1] + delta,
532 0, (1 << bit_depth) - 1);
533 range -= (pmi->palette_colors[idx] - pmi->palette_colors[idx - 1]);
534 bits = AOMMIN(bits, aom_ceil_log2(range))(((bits) < (aom_ceil_log2(range))) ? (bits) : (aom_ceil_log2
(range)))
;
535 }
536 }
537 merge_colors(pmi->palette_colors + PALETTE_MAX_SIZE8, cached_colors, n,
538 n_cached_colors);
539 } else {
540 memcpy(pmi->palette_colors + PALETTE_MAX_SIZE8, cached_colors,
541 n * sizeof(cached_colors[0]));
542 }
543
544 // V channel colors.
545 if (aom_read_bit(r, ACCT_STR)aom_read_bit_(r )) { // Delta encoding.
546 const int min_bits_v = bit_depth - 4;
547 const int max_val = 1 << bit_depth;
548 int bits = min_bits_v + aom_read_literal(r, 2, ACCT_STR)aom_read_literal_(r, 2 );
549 pmi->palette_colors[2 * PALETTE_MAX_SIZE8] =
550 aom_read_literal(r, bit_depth, ACCT_STR)aom_read_literal_(r, bit_depth );
551 for (int i = 1; i < n; ++i) {
552 int delta = aom_read_literal(r, bits, ACCT_STR)aom_read_literal_(r, bits );
553 if (delta && aom_read_bit(r, ACCT_STR)aom_read_bit_(r )) delta = -delta;
554 int val = (int)pmi->palette_colors[2 * PALETTE_MAX_SIZE8 + i - 1] + delta;
555 if (val < 0) val += max_val;
556 if (val >= max_val) val -= max_val;
557 pmi->palette_colors[2 * PALETTE_MAX_SIZE8 + i] = val;
558 }
559 } else {
560 for (int i = 0; i < n; ++i) {
561 pmi->palette_colors[2 * PALETTE_MAX_SIZE8 + i] =
562 aom_read_literal(r, bit_depth, ACCT_STR)aom_read_literal_(r, bit_depth );
563 }
564 }
565}
566
567static void read_palette_mode_info(AV1_COMMON *const cm, MACROBLOCKD *const xd,
568 aom_reader *r) {
569 const int num_planes = av1_num_planes(cm);
570 MB_MODE_INFO *const mbmi = xd->mi[0];
571 const BLOCK_SIZE bsize = mbmi->bsize;
572 assert(av1_allow_palette(cm->features.allow_screen_content_tools, bsize))((void) sizeof ((av1_allow_palette(cm->features.allow_screen_content_tools
, bsize)) ? 1 : 0), __extension__ ({ if (av1_allow_palette(cm
->features.allow_screen_content_tools, bsize)) ; else __assert_fail
("av1_allow_palette(cm->features.allow_screen_content_tools, bsize)"
, "/root/firefox-clang/third_party/aom/av1/decoder/decodemv.c"
, 572, __extension__ __PRETTY_FUNCTION__); }))
;
1
Taking true branch
573 PALETTE_MODE_INFO *const pmi = &mbmi->palette_mode_info;
574 const int bsize_ctx = av1_get_palette_bsize_ctx(bsize);
575
576 if (mbmi->mode == DC_PRED) {
2
Assuming field 'mode' is equal to DC_PRED
3
Taking true branch
577 const int palette_mode_ctx = av1_get_palette_mode_ctx(xd);
578 const int modev = aom_read_symbol(aom_read_symbol_(r, xd->tile_ctx->palette_y_mode_cdf[bsize_ctx
][palette_mode_ctx], 2 )
579 r, xd->tile_ctx->palette_y_mode_cdf[bsize_ctx][palette_mode_ctx], 2,aom_read_symbol_(r, xd->tile_ctx->palette_y_mode_cdf[bsize_ctx
][palette_mode_ctx], 2 )
580 ACCT_STR)aom_read_symbol_(r, xd->tile_ctx->palette_y_mode_cdf[bsize_ctx
][palette_mode_ctx], 2 )
;
581 if (modev) {
4
Assuming 'modev' is not equal to 0
5
Taking true branch
582 pmi->palette_size[0] =
583 aom_read_symbol(r, xd->tile_ctx->palette_y_size_cdf[bsize_ctx],aom_read_symbol_(r, xd->tile_ctx->palette_y_size_cdf[bsize_ctx
], PALETTE_SIZES )
584 PALETTE_SIZES, ACCT_STR)aom_read_symbol_(r, xd->tile_ctx->palette_y_size_cdf[bsize_ctx
], PALETTE_SIZES )
+
585 2;
586 read_palette_colors_y(xd, cm->seq_params->bit_depth, pmi, r);
6
Calling 'read_palette_colors_y'
587 }
588 }
589 if (num_planes > 1 && mbmi->uv_mode == UV_DC_PRED && xd->is_chroma_ref) {
590 const int palette_uv_mode_ctx = (pmi->palette_size[0] > 0);
591 const int modev = aom_read_symbol(aom_read_symbol_(r, xd->tile_ctx->palette_uv_mode_cdf[palette_uv_mode_ctx
], 2 )
592 r, xd->tile_ctx->palette_uv_mode_cdf[palette_uv_mode_ctx], 2, ACCT_STR)aom_read_symbol_(r, xd->tile_ctx->palette_uv_mode_cdf[palette_uv_mode_ctx
], 2 )
;
593 if (modev) {
594 pmi->palette_size[1] =
595 aom_read_symbol(r, xd->tile_ctx->palette_uv_size_cdf[bsize_ctx],aom_read_symbol_(r, xd->tile_ctx->palette_uv_size_cdf[bsize_ctx
], PALETTE_SIZES )
596 PALETTE_SIZES, ACCT_STR)aom_read_symbol_(r, xd->tile_ctx->palette_uv_size_cdf[bsize_ctx
], PALETTE_SIZES )
+
597 2;
598 read_palette_colors_uv(xd, cm->seq_params->bit_depth, pmi, r);
599 }
600 }
601}
602
603static int read_angle_delta(aom_reader *r, aom_cdf_prob *cdf) {
604 const int sym = aom_read_symbol(r, cdf, 2 * MAX_ANGLE_DELTA + 1, ACCT_STR)aom_read_symbol_(r, cdf, 2 * 3 + 1 );
605 return sym - MAX_ANGLE_DELTA3;
606}
607
608static void read_filter_intra_mode_info(const AV1_COMMON *const cm,
609 MACROBLOCKD *const xd, aom_reader *r) {
610 MB_MODE_INFO *const mbmi = xd->mi[0];
611 FILTER_INTRA_MODE_INFO *filter_intra_mode_info =
612 &mbmi->filter_intra_mode_info;
613
614 if (av1_filter_intra_allowed(cm, mbmi)) {
615 filter_intra_mode_info->use_filter_intra = aom_read_symbol(aom_read_symbol_(r, xd->tile_ctx->filter_intra_cdfs[mbmi
->bsize], 2 )
616 r, xd->tile_ctx->filter_intra_cdfs[mbmi->bsize], 2, ACCT_STR)aom_read_symbol_(r, xd->tile_ctx->filter_intra_cdfs[mbmi
->bsize], 2 )
;
617 if (filter_intra_mode_info->use_filter_intra) {
618 filter_intra_mode_info->filter_intra_mode = aom_read_symbol(aom_read_symbol_(r, xd->tile_ctx->filter_intra_mode_cdf
, FILTER_INTRA_MODES )
619 r, xd->tile_ctx->filter_intra_mode_cdf, FILTER_INTRA_MODES, ACCT_STR)aom_read_symbol_(r, xd->tile_ctx->filter_intra_mode_cdf
, FILTER_INTRA_MODES )
;
620 }
621 } else {
622 filter_intra_mode_info->use_filter_intra = 0;
623 }
624}
625
626void av1_read_tx_type(const AV1_COMMON *const cm, MACROBLOCKD *xd, int blk_row,
627 int blk_col, TX_SIZE tx_size, aom_reader *r) {
628 MB_MODE_INFO *mbmi = xd->mi[0];
629 uint8_t *tx_type =
630 &xd->tx_type_map[blk_row * xd->tx_type_map_stride + blk_col];
631 *tx_type = DCT_DCT;
632
633 // No need to read transform type if block is skipped.
634 if (mbmi->skip_txfm ||
635 segfeature_active(&cm->seg, mbmi->segment_id, SEG_LVL_SKIP))
636 return;
637
638 // No need to read transform type for lossless mode(qindex==0).
639 const int qindex = xd->qindex[mbmi->segment_id];
640 if (qindex == 0) return;
641
642 const int inter_block = is_inter_block(mbmi);
643 if (get_ext_tx_types(tx_size, inter_block, cm->features.reduced_tx_set_used) >
644 1) {
645 const TxSetType tx_set_type = av1_get_ext_tx_set_type(
646 tx_size, inter_block, cm->features.reduced_tx_set_used);
647 const int eset =
648 get_ext_tx_set(tx_size, inter_block, cm->features.reduced_tx_set_used);
649 // eset == 0 should correspond to a set with only DCT_DCT and
650 // there is no need to read the tx_type
651 assert(eset != 0)((void) sizeof ((eset != 0) ? 1 : 0), __extension__ ({ if (eset
!= 0) ; else __assert_fail ("eset != 0", "/root/firefox-clang/third_party/aom/av1/decoder/decodemv.c"
, 651, __extension__ __PRETTY_FUNCTION__); }))
;
652
653 const TX_SIZE square_tx_size = txsize_sqr_map[tx_size];
654 FRAME_CONTEXT *ec_ctx = xd->tile_ctx;
655 if (inter_block) {
656 *tx_type = av1_ext_tx_inv[tx_set_type][aom_read_symbol(aom_read_symbol_(r, ec_ctx->inter_ext_tx_cdf[eset][square_tx_size
], av1_num_ext_tx_set[tx_set_type] )
657 r, ec_ctx->inter_ext_tx_cdf[eset][square_tx_size],aom_read_symbol_(r, ec_ctx->inter_ext_tx_cdf[eset][square_tx_size
], av1_num_ext_tx_set[tx_set_type] )
658 av1_num_ext_tx_set[tx_set_type], ACCT_STR)aom_read_symbol_(r, ec_ctx->inter_ext_tx_cdf[eset][square_tx_size
], av1_num_ext_tx_set[tx_set_type] )
];
659 } else {
660 const PREDICTION_MODE intra_mode =
661 mbmi->filter_intra_mode_info.use_filter_intra
662 ? fimode_to_intradir[mbmi->filter_intra_mode_info
663 .filter_intra_mode]
664 : mbmi->mode;
665 *tx_type = av1_ext_tx_inv[tx_set_type][aom_read_symbol(aom_read_symbol_(r, ec_ctx->intra_ext_tx_cdf[eset][square_tx_size
][intra_mode], av1_num_ext_tx_set[tx_set_type] )
666 r, ec_ctx->intra_ext_tx_cdf[eset][square_tx_size][intra_mode],aom_read_symbol_(r, ec_ctx->intra_ext_tx_cdf[eset][square_tx_size
][intra_mode], av1_num_ext_tx_set[tx_set_type] )
667 av1_num_ext_tx_set[tx_set_type], ACCT_STR)aom_read_symbol_(r, ec_ctx->intra_ext_tx_cdf[eset][square_tx_size
][intra_mode], av1_num_ext_tx_set[tx_set_type] )
];
668 }
669 }
670}
671
672static inline void read_mv(aom_reader *r, MV *mv, const MV *ref,
673 nmv_context *ctx, MvSubpelPrecision precision);
674
675static inline int is_mv_valid(const MV *mv);
676
677static inline int assign_dv(AV1_COMMON *cm, MACROBLOCKD *xd, int_mv *mv,
678 const int_mv *ref_mv, int mi_row, int mi_col,
679 BLOCK_SIZE bsize, aom_reader *r) {
680 FRAME_CONTEXT *ec_ctx = xd->tile_ctx;
681 read_mv(r, &mv->as_mv, &ref_mv->as_mv, &ec_ctx->ndvc, MV_SUBPEL_NONE);
682 // DV should not have sub-pel.
683 assert((mv->as_mv.col & 7) == 0)((void) sizeof (((mv->as_mv.col & 7) == 0) ? 1 : 0), __extension__
({ if ((mv->as_mv.col & 7) == 0) ; else __assert_fail
("(mv->as_mv.col & 7) == 0", "/root/firefox-clang/third_party/aom/av1/decoder/decodemv.c"
, 683, __extension__ __PRETTY_FUNCTION__); }))
;
684 assert((mv->as_mv.row & 7) == 0)((void) sizeof (((mv->as_mv.row & 7) == 0) ? 1 : 0), __extension__
({ if ((mv->as_mv.row & 7) == 0) ; else __assert_fail
("(mv->as_mv.row & 7) == 0", "/root/firefox-clang/third_party/aom/av1/decoder/decodemv.c"
, 684, __extension__ __PRETTY_FUNCTION__); }))
;
685 mv->as_mv.col = (mv->as_mv.col >> 3) * 8;
686 mv->as_mv.row = (mv->as_mv.row >> 3) * 8;
687 int valid = is_mv_valid(&mv->as_mv) &&
688 av1_is_dv_valid(mv->as_mv, cm, xd, mi_row, mi_col, bsize,
689 cm->seq_params->mib_size_log2);
690 return valid;
691}
692
693static void read_intrabc_info(AV1_COMMON *const cm, DecoderCodingBlock *dcb,
694 aom_reader *r) {
695 MACROBLOCKD *const xd = &dcb->xd;
696 MB_MODE_INFO *const mbmi = xd->mi[0];
697 FRAME_CONTEXT *ec_ctx = xd->tile_ctx;
698 mbmi->use_intrabc = aom_read_symbol(r, ec_ctx->intrabc_cdf, 2, ACCT_STR)aom_read_symbol_(r, ec_ctx->intrabc_cdf, 2 );
699 if (mbmi->use_intrabc) {
700 BLOCK_SIZE bsize = mbmi->bsize;
701 mbmi->mode = DC_PRED;
702 mbmi->uv_mode = UV_DC_PRED;
703 mbmi->interp_filters = av1_broadcast_interp_filter(BILINEAR);
704 mbmi->motion_mode = SIMPLE_TRANSLATION;
705
706 int16_t inter_mode_ctx[MODE_CTX_REF_FRAMES(REF_FRAMES + (FWD_REFS * BWD_REFS + TOTAL_UNIDIR_COMP_REFS))];
707 int_mv ref_mvs[INTRA_FRAME + 1][MAX_MV_REF_CANDIDATES2];
708
709 av1_find_mv_refs(cm, xd, mbmi, INTRA_FRAME, dcb->ref_mv_count,
710 xd->ref_mv_stack, xd->weight, ref_mvs, /*global_mvs=*/NULL((void*)0),
711 inter_mode_ctx);
712
713 int_mv nearestmv, nearmv;
714
715 av1_find_best_ref_mvs(0, ref_mvs[INTRA_FRAME], &nearestmv, &nearmv, 0);
716 int_mv dv_ref = nearestmv.as_int == 0 ? nearmv : nearestmv;
717 if (dv_ref.as_int == 0)
718 av1_find_ref_dv(&dv_ref, &xd->tile, cm->seq_params->mib_size, xd->mi_row);
719 // Ref DV should not have sub-pel.
720 int valid_dv = (dv_ref.as_mv.col & 7) == 0 && (dv_ref.as_mv.row & 7) == 0;
721 dv_ref.as_mv.col = (dv_ref.as_mv.col >> 3) * 8;
722 dv_ref.as_mv.row = (dv_ref.as_mv.row >> 3) * 8;
723 valid_dv = valid_dv && assign_dv(cm, xd, &mbmi->mv[0], &dv_ref, xd->mi_row,
724 xd->mi_col, bsize, r);
725 if (!valid_dv) {
726 // Intra bc motion vectors are not valid - signal corrupt frame
727 aom_internal_error(xd->error_info, AOM_CODEC_CORRUPT_FRAME,
728 "Invalid intrabc dv");
729 }
730 }
731}
732
733// If delta q is present, reads delta_q index.
734// Also reads delta_q loop filter levels, if present.
735static void read_delta_q_params(AV1_COMMON *const cm, MACROBLOCKD *const xd,
736 aom_reader *r) {
737 DeltaQInfo *const delta_q_info = &cm->delta_q_info;
738
739 if (delta_q_info->delta_q_present_flag) {
740 MB_MODE_INFO *const mbmi = xd->mi[0];
741 xd->current_base_qindex +=
742 read_delta_qindex(cm, xd, r, mbmi) * delta_q_info->delta_q_res;
743 /* Normative: Clamp to [1,MAXQ] to not interfere with lossless mode */
744 xd->current_base_qindex = clamp(xd->current_base_qindex, 1, MAXQ255);
745 FRAME_CONTEXT *const ec_ctx = xd->tile_ctx;
746 if (delta_q_info->delta_lf_present_flag) {
747 const int mi_row = xd->mi_row;
748 const int mi_col = xd->mi_col;
749 if (delta_q_info->delta_lf_multi) {
750 const int frame_lf_count =
751 av1_num_planes(cm) > 1 ? FRAME_LF_COUNT4 : FRAME_LF_COUNT4 - 2;
752 for (int lf_id = 0; lf_id < frame_lf_count; ++lf_id) {
753 const int tmp_lvl =
754 xd->delta_lf[lf_id] +
755 read_delta_lflevel(cm, r, ec_ctx->delta_lf_multi_cdf[lf_id], mbmi,
756 mi_col, mi_row) *
757 delta_q_info->delta_lf_res;
758 mbmi->delta_lf[lf_id] = xd->delta_lf[lf_id] =
759 clamp(tmp_lvl, -MAX_LOOP_FILTER63, MAX_LOOP_FILTER63);
760 }
761 } else {
762 const int tmp_lvl = xd->delta_lf_from_base +
763 read_delta_lflevel(cm, r, ec_ctx->delta_lf_cdf,
764 mbmi, mi_col, mi_row) *
765 delta_q_info->delta_lf_res;
766 mbmi->delta_lf_from_base = xd->delta_lf_from_base =
767 clamp(tmp_lvl, -MAX_LOOP_FILTER63, MAX_LOOP_FILTER63);
768 }
769 }
770 }
771}
772
773static void read_intra_frame_mode_info(AV1_COMMON *const cm,
774 DecoderCodingBlock *dcb, aom_reader *r) {
775 MACROBLOCKD *const xd = &dcb->xd;
776 MB_MODE_INFO *const mbmi = xd->mi[0];
777 const MB_MODE_INFO *above_mi = xd->above_mbmi;
778 const MB_MODE_INFO *left_mi = xd->left_mbmi;
779 const BLOCK_SIZE bsize = mbmi->bsize;
780 struct segmentation *const seg = &cm->seg;
781
782 FRAME_CONTEXT *ec_ctx = xd->tile_ctx;
783
784 if (seg->segid_preskip)
785 mbmi->segment_id = read_intra_segment_id(cm, xd, bsize, r, 0);
786
787 mbmi->skip_txfm = read_skip_txfm(cm, xd, mbmi->segment_id, r);
788
789 if (!seg->segid_preskip)
790 mbmi->segment_id = read_intra_segment_id(cm, xd, bsize, r, mbmi->skip_txfm);
791
792 read_cdef(cm, r, xd);
793
794 read_delta_q_params(cm, xd, r);
795
796 mbmi->current_qindex = xd->current_base_qindex;
797
798 mbmi->ref_frame[0] = INTRA_FRAME;
799 mbmi->ref_frame[1] = NONE_FRAME;
800 mbmi->palette_mode_info.palette_size[0] = 0;
801 mbmi->palette_mode_info.palette_size[1] = 0;
802 mbmi->filter_intra_mode_info.use_filter_intra = 0;
803
804 const int mi_row = xd->mi_row;
805 const int mi_col = xd->mi_col;
806 xd->above_txfm_context = cm->above_contexts.txfm[xd->tile.tile_row] + mi_col;
807 xd->left_txfm_context =
808 xd->left_txfm_context_buffer + (mi_row & MAX_MIB_MASK((1 << (7 - 2)) - 1));
809
810 if (av1_allow_intrabc(cm)) {
811 read_intrabc_info(cm, dcb, r);
812 if (is_intrabc_block(mbmi)) return;
813 }
814
815 mbmi->mode = read_intra_mode(r, get_y_mode_cdf(ec_ctx, above_mi, left_mi));
816
817 const int use_angle_delta = av1_use_angle_delta(bsize);
818 mbmi->angle_delta[PLANE_TYPE_Y] =
819 (use_angle_delta && av1_is_directional_mode(mbmi->mode))
820 ? read_angle_delta(r, ec_ctx->angle_delta_cdf[mbmi->mode - V_PRED])
821 : 0;
822
823 if (!cm->seq_params->monochrome && xd->is_chroma_ref) {
824 mbmi->uv_mode =
825 read_intra_mode_uv(ec_ctx, r, is_cfl_allowed(xd), mbmi->mode);
826 if (mbmi->uv_mode == UV_CFL_PRED) {
827 mbmi->cfl_alpha_idx = read_cfl_alphas(ec_ctx, r, &mbmi->cfl_alpha_signs);
828 }
829 const PREDICTION_MODE intra_mode = get_uv_mode(mbmi->uv_mode);
830 mbmi->angle_delta[PLANE_TYPE_UV] =
831 (use_angle_delta && av1_is_directional_mode(intra_mode))
832 ? read_angle_delta(r, ec_ctx->angle_delta_cdf[intra_mode - V_PRED])
833 : 0;
834 } else {
835 // Avoid decoding angle_info if there is no chroma prediction
836 mbmi->uv_mode = UV_DC_PRED;
837 }
838 xd->cfl.store_y = store_cfl_required(cm, xd);
839
840 if (av1_allow_palette(cm->features.allow_screen_content_tools, bsize))
841 read_palette_mode_info(cm, xd, r);
842
843 read_filter_intra_mode_info(cm, xd, r);
844}
845
846static int read_mv_component(aom_reader *r, nmv_component *mvcomp,
847 int use_subpel, int usehp) {
848 int mag, d, fr, hp;
849 const int sign = aom_read_symbol(r, mvcomp->sign_cdf, 2, ACCT_STR)aom_read_symbol_(r, mvcomp->sign_cdf, 2 );
850 const int mv_class =
851 aom_read_symbol(r, mvcomp->classes_cdf, MV_CLASSES, ACCT_STR)aom_read_symbol_(r, mvcomp->classes_cdf, 11 );
852 const int class0 = mv_class == MV_CLASS_0;
853
854 // Integer part
855 if (class0) {
856 d = aom_read_symbol(r, mvcomp->class0_cdf, CLASS0_SIZE, ACCT_STR)aom_read_symbol_(r, mvcomp->class0_cdf, (1 << 1) );
857 mag = 0;
858 } else {
859 const int n = mv_class + CLASS0_BITS1 - 1; // number of bits
860 d = 0;
861 for (int i = 0; i < n; ++i)
862 d |= aom_read_symbol(r, mvcomp->bits_cdf[i], 2, ACCT_STR)aom_read_symbol_(r, mvcomp->bits_cdf[i], 2 ) << i;
863 mag = CLASS0_SIZE(1 << 1) << (mv_class + 2);
864 }
865
866 if (use_subpel) {
867 // Fractional part
868 fr = aom_read_symbol(r, class0 ? mvcomp->class0_fp_cdf[d] : mvcomp->fp_cdf,aom_read_symbol_(r, class0 ? mvcomp->class0_fp_cdf[d] : mvcomp
->fp_cdf, 4 )
869 MV_FP_SIZE, ACCT_STR)aom_read_symbol_(r, class0 ? mvcomp->class0_fp_cdf[d] : mvcomp
->fp_cdf, 4 )
;
870
871 // High precision part (if hp is not used, the default value of the hp is 1)
872 hp = usehp ? aom_read_symbol(aom_read_symbol_(r, class0 ? mvcomp->class0_hp_cdf : mvcomp
->hp_cdf, 2 )
873 r, class0 ? mvcomp->class0_hp_cdf : mvcomp->hp_cdf, 2,aom_read_symbol_(r, class0 ? mvcomp->class0_hp_cdf : mvcomp
->hp_cdf, 2 )
874 ACCT_STR)aom_read_symbol_(r, class0 ? mvcomp->class0_hp_cdf : mvcomp
->hp_cdf, 2 )
875 : 1;
876 } else {
877 fr = 3;
878 hp = 1;
879 }
880
881 // Result
882 mag += ((d << 3) | (fr << 1) | hp) + 1;
883 return sign ? -mag : mag;
884}
885
886static inline void read_mv(aom_reader *r, MV *mv, const MV *ref,
887 nmv_context *ctx, MvSubpelPrecision precision) {
888 MV diff = kZeroMv;
889 const MV_JOINT_TYPE joint_type =
890 (MV_JOINT_TYPE)aom_read_symbol(r, ctx->joints_cdf, MV_JOINTS, ACCT_STR)aom_read_symbol_(r, ctx->joints_cdf, 4 );
891
892 if (mv_joint_vertical(joint_type))
893 diff.row = read_mv_component(r, &ctx->comps[0], precision > MV_SUBPEL_NONE,
894 precision > MV_SUBPEL_LOW_PRECISION);
895
896 if (mv_joint_horizontal(joint_type))
897 diff.col = read_mv_component(r, &ctx->comps[1], precision > MV_SUBPEL_NONE,
898 precision > MV_SUBPEL_LOW_PRECISION);
899
900 mv->row = ref->row + diff.row;
901 mv->col = ref->col + diff.col;
902}
903
904static REFERENCE_MODE read_block_reference_mode(AV1_COMMON *cm,
905 const MACROBLOCKD *xd,
906 aom_reader *r) {
907 if (!is_comp_ref_allowed(xd->mi[0]->bsize)) return SINGLE_REFERENCE;
908 if (cm->current_frame.reference_mode == REFERENCE_MODE_SELECT) {
909 const int ctx = av1_get_reference_mode_context(xd);
910 const REFERENCE_MODE mode = (REFERENCE_MODE)aom_read_symbol(aom_read_symbol_(r, xd->tile_ctx->comp_inter_cdf[ctx], 2
)
911 r, xd->tile_ctx->comp_inter_cdf[ctx], 2, ACCT_STR)aom_read_symbol_(r, xd->tile_ctx->comp_inter_cdf[ctx], 2
)
;
912 return mode; // SINGLE_REFERENCE or COMPOUND_REFERENCE
913 } else {
914 assert(cm->current_frame.reference_mode == SINGLE_REFERENCE)((void) sizeof ((cm->current_frame.reference_mode == SINGLE_REFERENCE
) ? 1 : 0), __extension__ ({ if (cm->current_frame.reference_mode
== SINGLE_REFERENCE) ; else __assert_fail ("cm->current_frame.reference_mode == SINGLE_REFERENCE"
, "/root/firefox-clang/third_party/aom/av1/decoder/decodemv.c"
, 914, __extension__ __PRETTY_FUNCTION__); }))
;
915 return cm->current_frame.reference_mode;
916 }
917}
918
919#define READ_REF_BIT(pname)aom_read_symbol_(r, av1_get_pred_cdf_pname(xd), 2 ) \
920 aom_read_symbol(r, av1_get_pred_cdf_##pname(xd), 2, ACCT_STR)aom_read_symbol_(r, av1_get_pred_cdf_##pname(xd), 2 )
921
922static COMP_REFERENCE_TYPE read_comp_reference_type(const MACROBLOCKD *xd,
923 aom_reader *r) {
924 const int ctx = av1_get_comp_reference_type_context(xd);
925 const COMP_REFERENCE_TYPE comp_ref_type =
926 (COMP_REFERENCE_TYPE)aom_read_symbol(aom_read_symbol_(r, xd->tile_ctx->comp_ref_type_cdf[ctx
], 2 )
927 r, xd->tile_ctx->comp_ref_type_cdf[ctx], 2, ACCT_STR)aom_read_symbol_(r, xd->tile_ctx->comp_ref_type_cdf[ctx
], 2 )
;
928 return comp_ref_type; // UNIDIR_COMP_REFERENCE or BIDIR_COMP_REFERENCE
929}
930
931static void set_ref_frames_for_skip_mode(AV1_COMMON *const cm,
932 MV_REFERENCE_FRAME ref_frame[2]) {
933 ref_frame[0] = LAST_FRAME + cm->current_frame.skip_mode_info.ref_frame_idx_0;
934 ref_frame[1] = LAST_FRAME + cm->current_frame.skip_mode_info.ref_frame_idx_1;
935}
936
937// Read the referncence frame
938static void read_ref_frames(AV1_COMMON *const cm, MACROBLOCKD *const xd,
939 aom_reader *r, int segment_id,
940 MV_REFERENCE_FRAME ref_frame[2]) {
941 if (xd->mi[0]->skip_mode) {
942 set_ref_frames_for_skip_mode(cm, ref_frame);
943 return;
944 }
945
946 if (segfeature_active(&cm->seg, segment_id, SEG_LVL_REF_FRAME)) {
947 ref_frame[0] = (MV_REFERENCE_FRAME)get_segdata(&cm->seg, segment_id,
948 SEG_LVL_REF_FRAME);
949 ref_frame[1] = NONE_FRAME;
950 } else if (segfeature_active(&cm->seg, segment_id, SEG_LVL_SKIP) ||
951 segfeature_active(&cm->seg, segment_id, SEG_LVL_GLOBALMV)) {
952 ref_frame[0] = LAST_FRAME;
953 ref_frame[1] = NONE_FRAME;
954 } else {
955 const REFERENCE_MODE mode = read_block_reference_mode(cm, xd, r);
956
957 if (mode == COMPOUND_REFERENCE) {
958 const COMP_REFERENCE_TYPE comp_ref_type = read_comp_reference_type(xd, r);
959
960 if (comp_ref_type == UNIDIR_COMP_REFERENCE) {
961 const int bit = READ_REF_BIT(uni_comp_ref_p)aom_read_symbol_(r, av1_get_pred_cdf_uni_comp_ref_p(xd), 2 );
962 if (bit) {
963 ref_frame[0] = BWDREF_FRAME;
964 ref_frame[1] = ALTREF_FRAME;
965 } else {
966 const int bit1 = READ_REF_BIT(uni_comp_ref_p1)aom_read_symbol_(r, av1_get_pred_cdf_uni_comp_ref_p1(xd), 2 );
967 if (bit1) {
968 const int bit2 = READ_REF_BIT(uni_comp_ref_p2)aom_read_symbol_(r, av1_get_pred_cdf_uni_comp_ref_p2(xd), 2 );
969 if (bit2) {
970 ref_frame[0] = LAST_FRAME;
971 ref_frame[1] = GOLDEN_FRAME;
972 } else {
973 ref_frame[0] = LAST_FRAME;
974 ref_frame[1] = LAST3_FRAME;
975 }
976 } else {
977 ref_frame[0] = LAST_FRAME;
978 ref_frame[1] = LAST2_FRAME;
979 }
980 }
981
982 return;
983 }
984
985 assert(comp_ref_type == BIDIR_COMP_REFERENCE)((void) sizeof ((comp_ref_type == BIDIR_COMP_REFERENCE) ? 1 :
0), __extension__ ({ if (comp_ref_type == BIDIR_COMP_REFERENCE
) ; else __assert_fail ("comp_ref_type == BIDIR_COMP_REFERENCE"
, "/root/firefox-clang/third_party/aom/av1/decoder/decodemv.c"
, 985, __extension__ __PRETTY_FUNCTION__); }))
;
986
987 const int idx = 1;
988 const int bit = READ_REF_BIT(comp_ref_p)aom_read_symbol_(r, av1_get_pred_cdf_comp_ref_p(xd), 2 );
989 // Decode forward references.
990 if (!bit) {
991 const int bit1 = READ_REF_BIT(comp_ref_p1)aom_read_symbol_(r, av1_get_pred_cdf_comp_ref_p1(xd), 2 );
992 ref_frame[!idx] = bit1 ? LAST2_FRAME : LAST_FRAME;
993 } else {
994 const int bit2 = READ_REF_BIT(comp_ref_p2)aom_read_symbol_(r, av1_get_pred_cdf_comp_ref_p2(xd), 2 );
995 ref_frame[!idx] = bit2 ? GOLDEN_FRAME : LAST3_FRAME;
996 }
997
998 // Decode backward references.
999 const int bit_bwd = READ_REF_BIT(comp_bwdref_p)aom_read_symbol_(r, av1_get_pred_cdf_comp_bwdref_p(xd), 2 );
1000 if (!bit_bwd) {
1001 const int bit1_bwd = READ_REF_BIT(comp_bwdref_p1)aom_read_symbol_(r, av1_get_pred_cdf_comp_bwdref_p1(xd), 2 );
1002 ref_frame[idx] = bit1_bwd ? ALTREF2_FRAME : BWDREF_FRAME;
1003 } else {
1004 ref_frame[idx] = ALTREF_FRAME;
1005 }
1006 } else if (mode == SINGLE_REFERENCE) {
1007 const int bit0 = READ_REF_BIT(single_ref_p1)aom_read_symbol_(r, av1_get_pred_cdf_single_ref_p1(xd), 2 );
1008 if (bit0) {
1009 const int bit1 = READ_REF_BIT(single_ref_p2)aom_read_symbol_(r, av1_get_pred_cdf_single_ref_p2(xd), 2 );
1010 if (!bit1) {
1011 const int bit5 = READ_REF_BIT(single_ref_p6)aom_read_symbol_(r, av1_get_pred_cdf_single_ref_p6(xd), 2 );
1012 ref_frame[0] = bit5 ? ALTREF2_FRAME : BWDREF_FRAME;
1013 } else {
1014 ref_frame[0] = ALTREF_FRAME;
1015 }
1016 } else {
1017 const int bit2 = READ_REF_BIT(single_ref_p3)aom_read_symbol_(r, av1_get_pred_cdf_single_ref_p3(xd), 2 );
1018 if (bit2) {
1019 const int bit4 = READ_REF_BIT(single_ref_p5)aom_read_symbol_(r, av1_get_pred_cdf_single_ref_p5(xd), 2 );
1020 ref_frame[0] = bit4 ? GOLDEN_FRAME : LAST3_FRAME;
1021 } else {
1022 const int bit3 = READ_REF_BIT(single_ref_p4)aom_read_symbol_(r, av1_get_pred_cdf_single_ref_p4(xd), 2 );
1023 ref_frame[0] = bit3 ? LAST2_FRAME : LAST_FRAME;
1024 }
1025 }
1026
1027 ref_frame[1] = NONE_FRAME;
1028 } else {
1029 assert(0 && "Invalid prediction mode.")((void) sizeof ((0 && "Invalid prediction mode.") ? 1
: 0), __extension__ ({ if (0 && "Invalid prediction mode."
) ; else __assert_fail ("0 && \"Invalid prediction mode.\""
, "/root/firefox-clang/third_party/aom/av1/decoder/decodemv.c"
, 1029, __extension__ __PRETTY_FUNCTION__); }))
;
1030 }
1031 }
1032}
1033
1034static inline void read_mb_interp_filter(const MACROBLOCKD *const xd,
1035 InterpFilter interp_filter,
1036 bool_Bool enable_dual_filter,
1037 MB_MODE_INFO *const mbmi,
1038 aom_reader *r) {
1039 FRAME_CONTEXT *ec_ctx = xd->tile_ctx;
1040
1041 if (!av1_is_interp_needed(xd)) {
1042 set_default_interp_filters(mbmi, interp_filter);
1043 return;
1044 }
1045
1046 if (interp_filter != SWITCHABLE) {
1047 mbmi->interp_filters = av1_broadcast_interp_filter(interp_filter);
1048 } else {
1049 InterpFilter ref0_filter[2] = { EIGHTTAP_REGULAR, EIGHTTAP_REGULAR };
1050 for (int dir = 0; dir < 2; ++dir) {
1051 const int ctx = av1_get_pred_context_switchable_interp(xd, dir);
1052 ref0_filter[dir] = (InterpFilter)aom_read_symbol(aom_read_symbol_(r, ec_ctx->switchable_interp_cdf[ctx], SWITCHABLE_FILTERS
)
1053 r, ec_ctx->switchable_interp_cdf[ctx], SWITCHABLE_FILTERS, ACCT_STR)aom_read_symbol_(r, ec_ctx->switchable_interp_cdf[ctx], SWITCHABLE_FILTERS
)
;
1054 if (!enable_dual_filter) {
1055 ref0_filter[1] = ref0_filter[0];
1056 break;
1057 }
1058 }
1059 // The index system works as: (0, 1) -> (vertical, horizontal) filter types
1060 mbmi->interp_filters.as_filters.x_filter = ref0_filter[1];
1061 mbmi->interp_filters.as_filters.y_filter = ref0_filter[0];
1062 }
1063}
1064
1065static void read_intra_block_mode_info(AV1_COMMON *const cm,
1066 MACROBLOCKD *const xd,
1067 MB_MODE_INFO *const mbmi,
1068 aom_reader *r) {
1069 const BLOCK_SIZE bsize = mbmi->bsize;
1070 const int use_angle_delta = av1_use_angle_delta(bsize);
1071
1072 mbmi->ref_frame[0] = INTRA_FRAME;
1073 mbmi->ref_frame[1] = NONE_FRAME;
1074
1075 FRAME_CONTEXT *ec_ctx = xd->tile_ctx;
1076
1077 mbmi->mode = read_intra_mode(r, ec_ctx->y_mode_cdf[size_group_lookup[bsize]]);
1078
1079 mbmi->angle_delta[PLANE_TYPE_Y] =
1080 use_angle_delta && av1_is_directional_mode(mbmi->mode)
1081 ? read_angle_delta(r, ec_ctx->angle_delta_cdf[mbmi->mode - V_PRED])
1082 : 0;
1083 if (!cm->seq_params->monochrome && xd->is_chroma_ref) {
1084 mbmi->uv_mode =
1085 read_intra_mode_uv(ec_ctx, r, is_cfl_allowed(xd), mbmi->mode);
1086 if (mbmi->uv_mode == UV_CFL_PRED) {
1087 mbmi->cfl_alpha_idx =
1088 read_cfl_alphas(xd->tile_ctx, r, &mbmi->cfl_alpha_signs);
1089 }
1090 const PREDICTION_MODE intra_mode = get_uv_mode(mbmi->uv_mode);
1091 mbmi->angle_delta[PLANE_TYPE_UV] =
1092 use_angle_delta && av1_is_directional_mode(intra_mode)
1093 ? read_angle_delta(r, ec_ctx->angle_delta_cdf[intra_mode - V_PRED])
1094 : 0;
1095 } else {
1096 // Avoid decoding angle_info if there is no chroma prediction
1097 mbmi->uv_mode = UV_DC_PRED;
1098 }
1099 xd->cfl.store_y = store_cfl_required(cm, xd);
1100
1101 mbmi->palette_mode_info.palette_size[0] = 0;
1102 mbmi->palette_mode_info.palette_size[1] = 0;
1103 if (av1_allow_palette(cm->features.allow_screen_content_tools, bsize))
1104 read_palette_mode_info(cm, xd, r);
1105
1106 read_filter_intra_mode_info(cm, xd, r);
1107}
1108
1109static inline int is_mv_valid(const MV *mv) {
1110 return mv->row > MV_LOW(-(1 << 14)) && mv->row < MV_UPP(1 << 14) && mv->col > MV_LOW(-(1 << 14)) &&
1111 mv->col < MV_UPP(1 << 14);
1112}
1113
1114static inline int assign_mv(AV1_COMMON *cm, MACROBLOCKD *xd,
1115 PREDICTION_MODE mode,
1116 MV_REFERENCE_FRAME ref_frame[2], int_mv mv[2],
1117 int_mv ref_mv[2], int_mv nearest_mv[2],
1118 int_mv near_mv[2], int is_compound, int allow_hp,
1119 aom_reader *r) {
1120 FRAME_CONTEXT *ec_ctx = xd->tile_ctx;
1121 MB_MODE_INFO *mbmi = xd->mi[0];
1122 BLOCK_SIZE bsize = mbmi->bsize;
1123 FeatureFlags *const features = &cm->features;
1124 if (features->cur_frame_force_integer_mv) {
1125 allow_hp = MV_SUBPEL_NONE;
1126 }
1127 switch (mode) {
1128 case NEWMV: {
1129 nmv_context *const nmvc = &ec_ctx->nmvc;
1130 read_mv(r, &mv[0].as_mv, &ref_mv[0].as_mv, nmvc, allow_hp);
1131 break;
1132 }
1133 case NEARESTMV: {
1134 mv[0].as_int = nearest_mv[0].as_int;
1135 break;
1136 }
1137 case NEARMV: {
1138 mv[0].as_int = near_mv[0].as_int;
1139 break;
1140 }
1141 case GLOBALMV: {
1142 mv[0].as_int = gm_get_motion_vector(&cm->global_motion[ref_frame[0]],
1143 features->allow_high_precision_mv,
1144 bsize, xd->mi_col, xd->mi_row,
1145 features->cur_frame_force_integer_mv)
1146 .as_int;
1147 break;
1148 }
1149 case NEW_NEWMV: {
1150 assert(is_compound)((void) sizeof ((is_compound) ? 1 : 0), __extension__ ({ if (
is_compound) ; else __assert_fail ("is_compound", "/root/firefox-clang/third_party/aom/av1/decoder/decodemv.c"
, 1150, __extension__ __PRETTY_FUNCTION__); }))
;
1151 for (int i = 0; i < 2; ++i) {
1152 nmv_context *const nmvc = &ec_ctx->nmvc;
1153 read_mv(r, &mv[i].as_mv, &ref_mv[i].as_mv, nmvc, allow_hp);
1154 }
1155 break;
1156 }
1157 case NEAREST_NEARESTMV: {
1158 assert(is_compound)((void) sizeof ((is_compound) ? 1 : 0), __extension__ ({ if (
is_compound) ; else __assert_fail ("is_compound", "/root/firefox-clang/third_party/aom/av1/decoder/decodemv.c"
, 1158, __extension__ __PRETTY_FUNCTION__); }))
;
1159 mv[0].as_int = nearest_mv[0].as_int;
1160 mv[1].as_int = nearest_mv[1].as_int;
1161 break;
1162 }
1163 case NEAR_NEARMV: {
1164 assert(is_compound)((void) sizeof ((is_compound) ? 1 : 0), __extension__ ({ if (
is_compound) ; else __assert_fail ("is_compound", "/root/firefox-clang/third_party/aom/av1/decoder/decodemv.c"
, 1164, __extension__ __PRETTY_FUNCTION__); }))
;
1165 mv[0].as_int = near_mv[0].as_int;
1166 mv[1].as_int = near_mv[1].as_int;
1167 break;
1168 }
1169 case NEW_NEARESTMV: {
1170 nmv_context *const nmvc = &ec_ctx->nmvc;
1171 read_mv(r, &mv[0].as_mv, &ref_mv[0].as_mv, nmvc, allow_hp);
1172 assert(is_compound)((void) sizeof ((is_compound) ? 1 : 0), __extension__ ({ if (
is_compound) ; else __assert_fail ("is_compound", "/root/firefox-clang/third_party/aom/av1/decoder/decodemv.c"
, 1172, __extension__ __PRETTY_FUNCTION__); }))
;
1173 mv[1].as_int = nearest_mv[1].as_int;
1174 break;
1175 }
1176 case NEAREST_NEWMV: {
1177 nmv_context *const nmvc = &ec_ctx->nmvc;
1178 mv[0].as_int = nearest_mv[0].as_int;
1179 read_mv(r, &mv[1].as_mv, &ref_mv[1].as_mv, nmvc, allow_hp);
1180 assert(is_compound)((void) sizeof ((is_compound) ? 1 : 0), __extension__ ({ if (
is_compound) ; else __assert_fail ("is_compound", "/root/firefox-clang/third_party/aom/av1/decoder/decodemv.c"
, 1180, __extension__ __PRETTY_FUNCTION__); }))
;
1181 break;
1182 }
1183 case NEAR_NEWMV: {
1184 nmv_context *const nmvc = &ec_ctx->nmvc;
1185 mv[0].as_int = near_mv[0].as_int;
1186 read_mv(r, &mv[1].as_mv, &ref_mv[1].as_mv, nmvc, allow_hp);
1187 assert(is_compound)((void) sizeof ((is_compound) ? 1 : 0), __extension__ ({ if (
is_compound) ; else __assert_fail ("is_compound", "/root/firefox-clang/third_party/aom/av1/decoder/decodemv.c"
, 1187, __extension__ __PRETTY_FUNCTION__); }))
;
1188 break;
1189 }
1190 case NEW_NEARMV: {
1191 nmv_context *const nmvc = &ec_ctx->nmvc;
1192 read_mv(r, &mv[0].as_mv, &ref_mv[0].as_mv, nmvc, allow_hp);
1193 assert(is_compound)((void) sizeof ((is_compound) ? 1 : 0), __extension__ ({ if (
is_compound) ; else __assert_fail ("is_compound", "/root/firefox-clang/third_party/aom/av1/decoder/decodemv.c"
, 1193, __extension__ __PRETTY_FUNCTION__); }))
;
1194 mv[1].as_int = near_mv[1].as_int;
1195 break;
1196 }
1197 case GLOBAL_GLOBALMV: {
1198 assert(is_compound)((void) sizeof ((is_compound) ? 1 : 0), __extension__ ({ if (
is_compound) ; else __assert_fail ("is_compound", "/root/firefox-clang/third_party/aom/av1/decoder/decodemv.c"
, 1198, __extension__ __PRETTY_FUNCTION__); }))
;
1199 mv[0].as_int = gm_get_motion_vector(&cm->global_motion[ref_frame[0]],
1200 features->allow_high_precision_mv,
1201 bsize, xd->mi_col, xd->mi_row,
1202 features->cur_frame_force_integer_mv)
1203 .as_int;
1204 mv[1].as_int = gm_get_motion_vector(&cm->global_motion[ref_frame[1]],
1205 features->allow_high_precision_mv,
1206 bsize, xd->mi_col, xd->mi_row,
1207 features->cur_frame_force_integer_mv)
1208 .as_int;
1209 break;
1210 }
1211 default: {
1212 return 0;
1213 }
1214 }
1215
1216 int ret = is_mv_valid(&mv[0].as_mv);
1217 if (is_compound) {
1218 ret = ret && is_mv_valid(&mv[1].as_mv);
1219 }
1220 return ret;
1221}
1222
1223static int read_is_inter_block(AV1_COMMON *const cm, MACROBLOCKD *const xd,
1224 int segment_id, aom_reader *r) {
1225 if (segfeature_active(&cm->seg, segment_id, SEG_LVL_REF_FRAME)) {
1226 const int frame = get_segdata(&cm->seg, segment_id, SEG_LVL_REF_FRAME);
1227 if (frame < LAST_FRAME) return 0;
1228 return frame != INTRA_FRAME;
1229 }
1230 if (segfeature_active(&cm->seg, segment_id, SEG_LVL_GLOBALMV)) {
1231 return 1;
1232 }
1233 const int ctx = av1_get_intra_inter_context(xd);
1234 FRAME_CONTEXT *ec_ctx = xd->tile_ctx;
1235 const int is_inter =
1236 aom_read_symbol(r, ec_ctx->intra_inter_cdf[ctx], 2, ACCT_STR)aom_read_symbol_(r, ec_ctx->intra_inter_cdf[ctx], 2 );
1237 return is_inter;
1238}
1239
1240#if DEC_MISMATCH_DEBUG0
1241static void dec_dump_logs(AV1_COMMON *cm, MB_MODE_INFO *const mbmi, int mi_row,
1242 int mi_col, int16_t mode_ctx) {
1243 int_mv mv[2] = { { 0 } };
1244 for (int ref = 0; ref < 1 + has_second_ref(mbmi); ++ref)
1245 mv[ref].as_mv = mbmi->mv[ref].as_mv;
1246
1247 const int16_t newmv_ctx = mode_ctx & NEWMV_CTX_MASK((1 << 3) - 1);
1248 int16_t zeromv_ctx = -1;
1249 int16_t refmv_ctx = -1;
1250 if (mbmi->mode != NEWMV) {
1251 zeromv_ctx = (mode_ctx >> GLOBALMV_OFFSET3) & GLOBALMV_CTX_MASK((1 << (4 - 3)) - 1);
1252 if (mbmi->mode != GLOBALMV)
1253 refmv_ctx = (mode_ctx >> REFMV_OFFSET4) & REFMV_CTX_MASK((1 << (8 - 4)) - 1);
1254 }
1255
1256#define FRAME_TO_CHECK 11
1257 if (cm->current_frame.frame_number == FRAME_TO_CHECK && cm->show_frame == 1) {
1258 printf(
1259 "=== DECODER ===: "
1260 "Frame=%d, (mi_row,mi_col)=(%d,%d), skip_mode=%d, mode=%d, bsize=%d, "
1261 "show_frame=%d, mv[0]=(%d,%d), mv[1]=(%d,%d), ref[0]=%d, "
1262 "ref[1]=%d, motion_mode=%d, mode_ctx=%d, "
1263 "newmv_ctx=%d, zeromv_ctx=%d, refmv_ctx=%d, tx_size=%d\n",
1264 cm->current_frame.frame_number, mi_row, mi_col, mbmi->skip_mode,
1265 mbmi->mode, mbmi->sb_type, cm->show_frame, mv[0].as_mv.row,
1266 mv[0].as_mv.col, mv[1].as_mv.row, mv[1].as_mv.col, mbmi->ref_frame[0],
1267 mbmi->ref_frame[1], mbmi->motion_mode, mode_ctx, newmv_ctx, zeromv_ctx,
1268 refmv_ctx, mbmi->tx_size);
1269 }
1270}
1271#endif // DEC_MISMATCH_DEBUG
1272
1273static void read_inter_block_mode_info(AV1Decoder *const pbi,
1274 DecoderCodingBlock *dcb,
1275 MB_MODE_INFO *const mbmi,
1276 aom_reader *r) {
1277 AV1_COMMON *const cm = &pbi->common;
1278 FeatureFlags *const features = &cm->features;
1279 const BLOCK_SIZE bsize = mbmi->bsize;
1280 const int allow_hp = features->allow_high_precision_mv;
1281 int_mv nearestmv[2], nearmv[2];
1282 int_mv ref_mvs[MODE_CTX_REF_FRAMES(REF_FRAMES + (FWD_REFS * BWD_REFS + TOTAL_UNIDIR_COMP_REFS))][MAX_MV_REF_CANDIDATES2] = { { { 0 } } };
1283 int16_t inter_mode_ctx[MODE_CTX_REF_FRAMES(REF_FRAMES + (FWD_REFS * BWD_REFS + TOTAL_UNIDIR_COMP_REFS))];
1284 int pts[SAMPLES_ARRAY_SIZE((1 << 3) * 2)], pts_inref[SAMPLES_ARRAY_SIZE((1 << 3) * 2)];
1285 MACROBLOCKD *const xd = &dcb->xd;
1286 FRAME_CONTEXT *ec_ctx = xd->tile_ctx;
1287
1288 mbmi->uv_mode = UV_DC_PRED;
1289 mbmi->palette_mode_info.palette_size[0] = 0;
1290 mbmi->palette_mode_info.palette_size[1] = 0;
1291
1292 av1_collect_neighbors_ref_counts(xd);
1293
1294 read_ref_frames(cm, xd, r, mbmi->segment_id, mbmi->ref_frame);
1295 const int is_compound = has_second_ref(mbmi);
1296
1297 const MV_REFERENCE_FRAME ref_frame = av1_ref_frame_type(mbmi->ref_frame);
1298 av1_find_mv_refs(cm, xd, mbmi, ref_frame, dcb->ref_mv_count, xd->ref_mv_stack,
1299 xd->weight, ref_mvs, /*global_mvs=*/NULL((void*)0), inter_mode_ctx);
1300
1301 mbmi->ref_mv_idx = 0;
1302
1303 if (mbmi->skip_mode) {
1304 assert(is_compound)((void) sizeof ((is_compound) ? 1 : 0), __extension__ ({ if (
is_compound) ; else __assert_fail ("is_compound", "/root/firefox-clang/third_party/aom/av1/decoder/decodemv.c"
, 1304, __extension__ __PRETTY_FUNCTION__); }))
;
1305 mbmi->mode = NEAREST_NEARESTMV;
1306 } else {
1307 if (segfeature_active(&cm->seg, mbmi->segment_id, SEG_LVL_SKIP) ||
1308 segfeature_active(&cm->seg, mbmi->segment_id, SEG_LVL_GLOBALMV)) {
1309 mbmi->mode = GLOBALMV;
1310 } else {
1311 const int mode_ctx =
1312 av1_mode_context_analyzer(inter_mode_ctx, mbmi->ref_frame);
1313 if (is_compound)
1314 mbmi->mode = read_inter_compound_mode(xd, r, mode_ctx);
1315 else
1316 mbmi->mode = read_inter_mode(ec_ctx, r, mode_ctx);
1317 if (mbmi->mode == NEWMV || mbmi->mode == NEW_NEWMV ||
1318 have_nearmv_in_inter_mode(mbmi->mode))
1319 read_drl_idx(ec_ctx, dcb, mbmi, r);
1320 }
1321 }
1322
1323 if (is_compound != is_inter_compound_mode(mbmi->mode)) {
1324 aom_internal_error(xd->error_info, AOM_CODEC_CORRUPT_FRAME,
1325 "Prediction mode %d invalid with ref frame %d %d",
1326 mbmi->mode, mbmi->ref_frame[0], mbmi->ref_frame[1]);
1327 }
1328
1329 if (!is_compound && mbmi->mode != GLOBALMV) {
1330 av1_find_best_ref_mvs(allow_hp, ref_mvs[mbmi->ref_frame[0]], &nearestmv[0],
1331 &nearmv[0], features->cur_frame_force_integer_mv);
1332 }
1333
1334 if (is_compound && mbmi->mode != GLOBAL_GLOBALMV) {
1335 const int ref_mv_idx = mbmi->ref_mv_idx + 1;
1336 nearestmv[0] = xd->ref_mv_stack[ref_frame][0].this_mv;
1337 nearestmv[1] = xd->ref_mv_stack[ref_frame][0].comp_mv;
1338 nearmv[0] = xd->ref_mv_stack[ref_frame][ref_mv_idx].this_mv;
1339 nearmv[1] = xd->ref_mv_stack[ref_frame][ref_mv_idx].comp_mv;
1340 lower_mv_precision(&nearestmv[0].as_mv, allow_hp,
1341 features->cur_frame_force_integer_mv);
1342 lower_mv_precision(&nearestmv[1].as_mv, allow_hp,
1343 features->cur_frame_force_integer_mv);
1344 lower_mv_precision(&nearmv[0].as_mv, allow_hp,
1345 features->cur_frame_force_integer_mv);
1346 lower_mv_precision(&nearmv[1].as_mv, allow_hp,
1347 features->cur_frame_force_integer_mv);
1348 } else if (mbmi->ref_mv_idx > 0 && mbmi->mode == NEARMV) {
1349 nearmv[0] =
1350 xd->ref_mv_stack[mbmi->ref_frame[0]][1 + mbmi->ref_mv_idx].this_mv;
1351 }
1352
1353 int_mv ref_mv[2] = { nearestmv[0], nearestmv[1] };
1354
1355 if (is_compound) {
1356 int ref_mv_idx = mbmi->ref_mv_idx;
1357 // Special case: NEAR_NEWMV and NEW_NEARMV modes use
1358 // 1 + mbmi->ref_mv_idx (like NEARMV) instead of
1359 // mbmi->ref_mv_idx (like NEWMV)
1360 if (mbmi->mode == NEAR_NEWMV || mbmi->mode == NEW_NEARMV)
1361 ref_mv_idx = 1 + mbmi->ref_mv_idx;
1362
1363 // TODO(jingning, yunqing): Do we need a lower_mv_precision() call here?
1364 if (compound_ref0_mode(mbmi->mode) == NEWMV)
1365 ref_mv[0] = xd->ref_mv_stack[ref_frame][ref_mv_idx].this_mv;
1366
1367 if (compound_ref1_mode(mbmi->mode) == NEWMV)
1368 ref_mv[1] = xd->ref_mv_stack[ref_frame][ref_mv_idx].comp_mv;
1369 } else {
1370 if (mbmi->mode == NEWMV) {
1371 if (dcb->ref_mv_count[ref_frame] > 1)
1372 ref_mv[0] = xd->ref_mv_stack[ref_frame][mbmi->ref_mv_idx].this_mv;
1373 }
1374 }
1375
1376 if (mbmi->skip_mode) assert(mbmi->mode == NEAREST_NEARESTMV)((void) sizeof ((mbmi->mode == NEAREST_NEARESTMV) ? 1 : 0)
, __extension__ ({ if (mbmi->mode == NEAREST_NEARESTMV) ; else
__assert_fail ("mbmi->mode == NEAREST_NEARESTMV", "/root/firefox-clang/third_party/aom/av1/decoder/decodemv.c"
, 1376, __extension__ __PRETTY_FUNCTION__); }))
;
1377
1378 const int mv_corrupted_flag =
1379 !assign_mv(cm, xd, mbmi->mode, mbmi->ref_frame, mbmi->mv, ref_mv,
1380 nearestmv, nearmv, is_compound, allow_hp, r);
1381 aom_merge_corrupted_flag(&dcb->corrupted, mv_corrupted_flag);
1382
1383 mbmi->use_wedge_interintra = 0;
1384 if (cm->seq_params->enable_interintra_compound && !mbmi->skip_mode &&
1385 is_interintra_allowed(mbmi)) {
1386 const int bsize_group = size_group_lookup[bsize];
1387 const int interintra =
1388 aom_read_symbol(r, ec_ctx->interintra_cdf[bsize_group], 2, ACCT_STR)aom_read_symbol_(r, ec_ctx->interintra_cdf[bsize_group], 2
)
;
1389 assert(mbmi->ref_frame[1] == NONE_FRAME)((void) sizeof ((mbmi->ref_frame[1] == NONE_FRAME) ? 1 : 0
), __extension__ ({ if (mbmi->ref_frame[1] == NONE_FRAME) ;
else __assert_fail ("mbmi->ref_frame[1] == NONE_FRAME", "/root/firefox-clang/third_party/aom/av1/decoder/decodemv.c"
, 1389, __extension__ __PRETTY_FUNCTION__); }))
;
1390 if (interintra) {
1391 const INTERINTRA_MODE interintra_mode =
1392 read_interintra_mode(xd, r, bsize_group);
1393 mbmi->ref_frame[1] = INTRA_FRAME;
1394 mbmi->interintra_mode = interintra_mode;
1395 mbmi->angle_delta[PLANE_TYPE_Y] = 0;
1396 mbmi->angle_delta[PLANE_TYPE_UV] = 0;
1397 mbmi->filter_intra_mode_info.use_filter_intra = 0;
1398 if (av1_is_wedge_used(bsize)) {
1399 mbmi->use_wedge_interintra = aom_read_symbol(aom_read_symbol_(r, ec_ctx->wedge_interintra_cdf[bsize], 2
)
1400 r, ec_ctx->wedge_interintra_cdf[bsize], 2, ACCT_STR)aom_read_symbol_(r, ec_ctx->wedge_interintra_cdf[bsize], 2
)
;
1401 if (mbmi->use_wedge_interintra) {
1402 mbmi->interintra_wedge_index = (int8_t)aom_read_symbol(aom_read_symbol_(r, ec_ctx->wedge_idx_cdf[bsize], 16 )
1403 r, ec_ctx->wedge_idx_cdf[bsize], MAX_WEDGE_TYPES, ACCT_STR)aom_read_symbol_(r, ec_ctx->wedge_idx_cdf[bsize], 16 );
1404 }
1405 }
1406 }
1407 }
1408
1409 for (int ref = 0; ref < 1 + has_second_ref(mbmi); ++ref) {
1410 const MV_REFERENCE_FRAME frame = mbmi->ref_frame[ref];
1411 xd->block_ref_scale_factors[ref] = get_ref_scale_factors_const(cm, frame);
1412 }
1413
1414 mbmi->motion_mode = SIMPLE_TRANSLATION;
1415 if (is_motion_variation_allowed_bsize(mbmi->bsize) && !mbmi->skip_mode &&
1416 !has_second_ref(mbmi)) {
1417 mbmi->num_proj_ref = av1_findSamples(cm, xd, pts, pts_inref);
1418 }
1419 av1_count_overlappable_neighbors(cm, xd);
1420
1421 if (mbmi->ref_frame[1] != INTRA_FRAME)
1422 mbmi->motion_mode = read_motion_mode(cm, xd, mbmi, r);
1423
1424 // init
1425 mbmi->comp_group_idx = 0;
1426 mbmi->compound_idx = 1;
1427 mbmi->interinter_comp.type = COMPOUND_AVERAGE;
1428
1429 if (has_second_ref(mbmi) && !mbmi->skip_mode) {
1430 // Read idx to indicate current compound inter prediction mode group
1431 const int masked_compound_used = is_any_masked_compound_used(bsize) &&
1432 cm->seq_params->enable_masked_compound;
1433
1434 if (masked_compound_used) {
1435 const int ctx_comp_group_idx = get_comp_group_idx_context(xd);
1436 mbmi->comp_group_idx = (uint8_t)aom_read_symbol(aom_read_symbol_(r, ec_ctx->comp_group_idx_cdf[ctx_comp_group_idx
], 2 )
1437 r, ec_ctx->comp_group_idx_cdf[ctx_comp_group_idx], 2, ACCT_STR)aom_read_symbol_(r, ec_ctx->comp_group_idx_cdf[ctx_comp_group_idx
], 2 )
;
1438 }
1439
1440 if (mbmi->comp_group_idx == 0) {
1441 if (cm->seq_params->order_hint_info.enable_dist_wtd_comp) {
1442 const int comp_index_ctx = get_comp_index_context(cm, xd);
1443 mbmi->compound_idx = (uint8_t)aom_read_symbol(aom_read_symbol_(r, ec_ctx->compound_index_cdf[comp_index_ctx
], 2 )
1444 r, ec_ctx->compound_index_cdf[comp_index_ctx], 2, ACCT_STR)aom_read_symbol_(r, ec_ctx->compound_index_cdf[comp_index_ctx
], 2 )
;
1445 mbmi->interinter_comp.type =
1446 mbmi->compound_idx ? COMPOUND_AVERAGE : COMPOUND_DISTWTD;
1447 } else {
1448 // Distance-weighted compound is disabled, so always use average
1449 mbmi->compound_idx = 1;
1450 mbmi->interinter_comp.type = COMPOUND_AVERAGE;
1451 }
1452 } else {
1453 assert(cm->current_frame.reference_mode != SINGLE_REFERENCE &&((void) sizeof ((cm->current_frame.reference_mode != SINGLE_REFERENCE
&& is_inter_compound_mode(mbmi->mode) && mbmi
->motion_mode == SIMPLE_TRANSLATION) ? 1 : 0), __extension__
({ if (cm->current_frame.reference_mode != SINGLE_REFERENCE
&& is_inter_compound_mode(mbmi->mode) && mbmi
->motion_mode == SIMPLE_TRANSLATION) ; else __assert_fail (
"cm->current_frame.reference_mode != SINGLE_REFERENCE && is_inter_compound_mode(mbmi->mode) && mbmi->motion_mode == SIMPLE_TRANSLATION"
, "/root/firefox-clang/third_party/aom/av1/decoder/decodemv.c"
, 1455, __extension__ __PRETTY_FUNCTION__); }))
1454 is_inter_compound_mode(mbmi->mode) &&((void) sizeof ((cm->current_frame.reference_mode != SINGLE_REFERENCE
&& is_inter_compound_mode(mbmi->mode) && mbmi
->motion_mode == SIMPLE_TRANSLATION) ? 1 : 0), __extension__
({ if (cm->current_frame.reference_mode != SINGLE_REFERENCE
&& is_inter_compound_mode(mbmi->mode) && mbmi
->motion_mode == SIMPLE_TRANSLATION) ; else __assert_fail (
"cm->current_frame.reference_mode != SINGLE_REFERENCE && is_inter_compound_mode(mbmi->mode) && mbmi->motion_mode == SIMPLE_TRANSLATION"
, "/root/firefox-clang/third_party/aom/av1/decoder/decodemv.c"
, 1455, __extension__ __PRETTY_FUNCTION__); }))
1455 mbmi->motion_mode == SIMPLE_TRANSLATION)((void) sizeof ((cm->current_frame.reference_mode != SINGLE_REFERENCE
&& is_inter_compound_mode(mbmi->mode) && mbmi
->motion_mode == SIMPLE_TRANSLATION) ? 1 : 0), __extension__
({ if (cm->current_frame.reference_mode != SINGLE_REFERENCE
&& is_inter_compound_mode(mbmi->mode) && mbmi
->motion_mode == SIMPLE_TRANSLATION) ; else __assert_fail (
"cm->current_frame.reference_mode != SINGLE_REFERENCE && is_inter_compound_mode(mbmi->mode) && mbmi->motion_mode == SIMPLE_TRANSLATION"
, "/root/firefox-clang/third_party/aom/av1/decoder/decodemv.c"
, 1455, __extension__ __PRETTY_FUNCTION__); }))
;
1456 assert(masked_compound_used)((void) sizeof ((masked_compound_used) ? 1 : 0), __extension__
({ if (masked_compound_used) ; else __assert_fail ("masked_compound_used"
, "/root/firefox-clang/third_party/aom/av1/decoder/decodemv.c"
, 1456, __extension__ __PRETTY_FUNCTION__); }))
;
1457
1458 // compound_diffwtd, wedge
1459 if (is_interinter_compound_used(COMPOUND_WEDGE, bsize)) {
1460 mbmi->interinter_comp.type =
1461 COMPOUND_WEDGE + aom_read_symbol(r,aom_read_symbol_(r, ec_ctx->compound_type_cdf[bsize], MASKED_COMPOUND_TYPES
)
1462 ec_ctx->compound_type_cdf[bsize],aom_read_symbol_(r, ec_ctx->compound_type_cdf[bsize], MASKED_COMPOUND_TYPES
)
1463 MASKED_COMPOUND_TYPES, ACCT_STR)aom_read_symbol_(r, ec_ctx->compound_type_cdf[bsize], MASKED_COMPOUND_TYPES
)
;
1464 } else {
1465 mbmi->interinter_comp.type = COMPOUND_DIFFWTD;
1466 }
1467
1468 if (mbmi->interinter_comp.type == COMPOUND_WEDGE) {
1469 assert(is_interinter_compound_used(COMPOUND_WEDGE, bsize))((void) sizeof ((is_interinter_compound_used(COMPOUND_WEDGE, bsize
)) ? 1 : 0), __extension__ ({ if (is_interinter_compound_used
(COMPOUND_WEDGE, bsize)) ; else __assert_fail ("is_interinter_compound_used(COMPOUND_WEDGE, bsize)"
, "/root/firefox-clang/third_party/aom/av1/decoder/decodemv.c"
, 1469, __extension__ __PRETTY_FUNCTION__); }))
;
1470 mbmi->interinter_comp.wedge_index = (int8_t)aom_read_symbol(aom_read_symbol_(r, ec_ctx->wedge_idx_cdf[bsize], 16 )
1471 r, ec_ctx->wedge_idx_cdf[bsize], MAX_WEDGE_TYPES, ACCT_STR)aom_read_symbol_(r, ec_ctx->wedge_idx_cdf[bsize], 16 );
1472 mbmi->interinter_comp.wedge_sign = (int8_t)aom_read_bit(r, ACCT_STR)aom_read_bit_(r );
1473 } else {
1474 assert(mbmi->interinter_comp.type == COMPOUND_DIFFWTD)((void) sizeof ((mbmi->interinter_comp.type == COMPOUND_DIFFWTD
) ? 1 : 0), __extension__ ({ if (mbmi->interinter_comp.type
== COMPOUND_DIFFWTD) ; else __assert_fail ("mbmi->interinter_comp.type == COMPOUND_DIFFWTD"
, "/root/firefox-clang/third_party/aom/av1/decoder/decodemv.c"
, 1474, __extension__ __PRETTY_FUNCTION__); }))
;
1475 mbmi->interinter_comp.mask_type =
1476 aom_read_literal(r, MAX_DIFFWTD_MASK_BITS, ACCT_STR)aom_read_literal_(r, 1 );
1477 }
1478 }
1479 }
1480
1481 read_mb_interp_filter(xd, features->interp_filter,
1482 cm->seq_params->enable_dual_filter, mbmi, r);
1483
1484 if (mbmi->motion_mode == WARPED_CAUSAL) {
1485 const int mi_row = xd->mi_row;
1486 const int mi_col = xd->mi_col;
1487 mbmi->wm_params.wmtype = DEFAULT_WMTYPEAFFINE;
1488 mbmi->wm_params.invalid = 0;
1489
1490 if (mbmi->num_proj_ref > 1) {
1491 mbmi->num_proj_ref = av1_selectSamples(&mbmi->mv[0].as_mv, pts, pts_inref,
1492 mbmi->num_proj_ref, bsize);
1493 }
1494
1495 if (av1_find_projection(mbmi->num_proj_ref, pts, pts_inref, bsize,
1496 mbmi->mv[0].as_mv.row, mbmi->mv[0].as_mv.col,
1497 &mbmi->wm_params, mi_row, mi_col)) {
1498#if WARPED_MOTION_DEBUG0
1499 printf("Warning: unexpected warped model from aomenc\n");
1500#endif
1501 mbmi->wm_params.invalid = 1;
1502 }
1503 }
1504
1505 xd->cfl.store_y = store_cfl_required(cm, xd);
1506
1507#if DEC_MISMATCH_DEBUG0
1508 dec_dump_logs(cm, mi, mi_row, mi_col, mode_ctx);
1509#endif // DEC_MISMATCH_DEBUG
1510}
1511
1512static void read_inter_frame_mode_info(AV1Decoder *const pbi,
1513 DecoderCodingBlock *dcb, aom_reader *r) {
1514 AV1_COMMON *const cm = &pbi->common;
1515 MACROBLOCKD *const xd = &dcb->xd;
1516 MB_MODE_INFO *const mbmi = xd->mi[0];
1517 int inter_block = 1;
1518
1519 mbmi->mv[0].as_int = 0;
1520 mbmi->mv[1].as_int = 0;
1521 mbmi->segment_id = read_inter_segment_id(cm, xd, 1, r);
1522
1523 mbmi->skip_mode = read_skip_mode(cm, xd, mbmi->segment_id, r);
1524
1525 if (mbmi->skip_mode)
1526 mbmi->skip_txfm = 1;
1527 else
1528 mbmi->skip_txfm = read_skip_txfm(cm, xd, mbmi->segment_id, r);
1529
1530 if (!cm->seg.segid_preskip)
1531 mbmi->segment_id = read_inter_segment_id(cm, xd, 0, r);
1532
1533 read_cdef(cm, r, xd);
1534
1535 read_delta_q_params(cm, xd, r);
1536
1537 if (!mbmi->skip_mode)
1538 inter_block = read_is_inter_block(cm, xd, mbmi->segment_id, r);
1539
1540 mbmi->current_qindex = xd->current_base_qindex;
1541
1542 xd->above_txfm_context =
1543 cm->above_contexts.txfm[xd->tile.tile_row] + xd->mi_col;
1544 xd->left_txfm_context =
1545 xd->left_txfm_context_buffer + (xd->mi_row & MAX_MIB_MASK((1 << (7 - 2)) - 1));
1546
1547 if (inter_block)
1548 read_inter_block_mode_info(pbi, dcb, mbmi, r);
1549 else
1550 read_intra_block_mode_info(cm, xd, mbmi, r);
1551}
1552
1553static void intra_copy_frame_mvs(AV1_COMMON *const cm, int mi_row, int mi_col,
1554 int x_mis, int y_mis) {
1555 const int frame_mvs_stride = ROUND_POWER_OF_TWO(cm->mi_params.mi_cols, 1)(((cm->mi_params.mi_cols) + (((1 << (1)) >> 1)
)) >> (1))
;
1556 MV_REF *frame_mvs =
1557 cm->cur_frame->mvs + (mi_row >> 1) * frame_mvs_stride + (mi_col >> 1);
1558 x_mis = ROUND_POWER_OF_TWO(x_mis, 1)(((x_mis) + (((1 << (1)) >> 1))) >> (1));
1559 y_mis = ROUND_POWER_OF_TWO(y_mis, 1)(((y_mis) + (((1 << (1)) >> 1))) >> (1));
1560
1561 for (int h = 0; h < y_mis; h++) {
1562 MV_REF *mv = frame_mvs;
1563 for (int w = 0; w < x_mis; w++) {
1564 mv->ref_frame = NONE_FRAME;
1565 mv++;
1566 }
1567 frame_mvs += frame_mvs_stride;
1568 }
1569}
1570
1571void av1_read_mode_info(AV1Decoder *const pbi, DecoderCodingBlock *dcb,
1572 aom_reader *r, int x_mis, int y_mis) {
1573 AV1_COMMON *const cm = &pbi->common;
1574 MACROBLOCKD *const xd = &dcb->xd;
1575 MB_MODE_INFO *const mi = xd->mi[0];
1576 mi->use_intrabc = 0;
1577
1578 if (frame_is_intra_only(cm)) {
1579 read_intra_frame_mode_info(cm, dcb, r);
1580 if (cm->seq_params->order_hint_info.enable_ref_frame_mvs)
1581 intra_copy_frame_mvs(cm, xd->mi_row, xd->mi_col, x_mis, y_mis);
1582 } else {
1583 read_inter_frame_mode_info(pbi, dcb, r);
1584 if (cm->seq_params->order_hint_info.enable_ref_frame_mvs)
1585 av1_copy_frame_mvs(cm, mi, xd->mi_row, xd->mi_col, x_mis, y_mis);
1586 }
1587}