FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/hevc/cabac.c
Date: 2026-10-06 20:08:58
Exec Total Coverage
Lines: 681 708 96.2%
Functions: 56 57 98.2%
Branches: 513 551 93.1%

Line Branch Exec Source
1 /*
2 * HEVC CABAC decoding
3 *
4 * Copyright (C) 2012 - 2013 Guillaume Martres
5 * Copyright (C) 2012 - 2013 Gildas Cocherel
6 *
7 * This file is part of FFmpeg.
8 *
9 * FFmpeg is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
13 *
14 * FFmpeg is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with FFmpeg; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
24 #include "libavutil/attributes.h"
25 #include "libavutil/common.h"
26
27 #include "libavcodec/cabac_functions.h"
28 #include "data.h"
29 #include "hevc.h"
30 #include "hevcdec.h"
31
32 #define CABAC_MAX_BIN 31
33
34 // ELEM(NAME, NUM_BINS)
35 #define CABAC_ELEMS(ELEM) \
36 ELEM(SAO_MERGE_FLAG, 1) \
37 ELEM(SAO_TYPE_IDX, 1) \
38 ELEM(SAO_EO_CLASS, 0) \
39 ELEM(SAO_BAND_POSITION, 0) \
40 ELEM(SAO_OFFSET_ABS, 0) \
41 ELEM(SAO_OFFSET_SIGN, 0) \
42 ELEM(END_OF_SLICE_FLAG, 0) \
43 ELEM(SPLIT_CODING_UNIT_FLAG, 3) \
44 ELEM(CU_TRANSQUANT_BYPASS_FLAG, 1) \
45 ELEM(SKIP_FLAG, 3) \
46 ELEM(CU_QP_DELTA, 3) \
47 ELEM(PRED_MODE_FLAG, 1) \
48 ELEM(PART_MODE, 4) \
49 ELEM(PCM_FLAG, 0) \
50 ELEM(PREV_INTRA_LUMA_PRED_FLAG, 1) \
51 ELEM(MPM_IDX, 0) \
52 ELEM(REM_INTRA_LUMA_PRED_MODE, 0) \
53 ELEM(INTRA_CHROMA_PRED_MODE, 2) \
54 ELEM(MERGE_FLAG, 1) \
55 ELEM(MERGE_IDX, 1) \
56 ELEM(INTER_PRED_IDC, 5) \
57 ELEM(REF_IDX_L0, 2) \
58 ELEM(REF_IDX_L1, 2) \
59 ELEM(ABS_MVD_GREATER0_FLAG, 2) \
60 ELEM(ABS_MVD_GREATER1_FLAG, 2) \
61 ELEM(ABS_MVD_MINUS2, 0) \
62 ELEM(MVD_SIGN_FLAG, 0) \
63 ELEM(MVP_LX_FLAG, 1) \
64 ELEM(NO_RESIDUAL_DATA_FLAG, 1) \
65 ELEM(SPLIT_TRANSFORM_FLAG, 3) \
66 ELEM(CBF_LUMA, 2) \
67 ELEM(CBF_CB_CR, 5) \
68 ELEM(TRANSFORM_SKIP_FLAG, 2) \
69 ELEM(EXPLICIT_RDPCM_FLAG, 2) \
70 ELEM(EXPLICIT_RDPCM_DIR_FLAG, 2) \
71 ELEM(LAST_SIGNIFICANT_COEFF_X_PREFIX, 18) \
72 ELEM(LAST_SIGNIFICANT_COEFF_Y_PREFIX, 18) \
73 ELEM(LAST_SIGNIFICANT_COEFF_X_SUFFIX, 0) \
74 ELEM(LAST_SIGNIFICANT_COEFF_Y_SUFFIX, 0) \
75 ELEM(SIGNIFICANT_COEFF_GROUP_FLAG, 4) \
76 ELEM(SIGNIFICANT_COEFF_FLAG, 44) \
77 ELEM(COEFF_ABS_LEVEL_GREATER1_FLAG, 24) \
78 ELEM(COEFF_ABS_LEVEL_GREATER2_FLAG, 6) \
79 ELEM(COEFF_ABS_LEVEL_REMAINING, 0) \
80 ELEM(COEFF_SIGN_FLAG, 0) \
81 ELEM(LOG2_RES_SCALE_ABS, 8) \
82 ELEM(RES_SCALE_SIGN_FLAG, 2) \
83 ELEM(CU_CHROMA_QP_OFFSET_FLAG, 1) \
84 ELEM(CU_CHROMA_QP_OFFSET_IDX, 1) \
85
86 /**
87 * Offset to ctxIdx 0 in init_values and states.
88 */
89 enum {
90 #define OFFSET(NAME, NUM_BINS) \
91 NAME ## _OFFSET, \
92 NAME ## _END = NAME ## _OFFSET + NUM_BINS - 1,
93 CABAC_ELEMS(OFFSET)
94 };
95
96 #define CNU 154
97 /**
98 * Indexed by init_type
99 */
100 static const uint8_t init_values[3][HEVC_CONTEXTS] = {
101 { // sao_merge_flag
102 153,
103 // sao_type_idx
104 200,
105 // split_coding_unit_flag
106 139, 141, 157,
107 // cu_transquant_bypass_flag
108 154,
109 // skip_flag
110 CNU, CNU, CNU,
111 // cu_qp_delta
112 154, 154, 154,
113 // pred_mode
114 CNU,
115 // part_mode
116 184, CNU, CNU, CNU,
117 // prev_intra_luma_pred_mode
118 184,
119 // intra_chroma_pred_mode
120 63, 139,
121 // merge_flag
122 CNU,
123 // merge_idx
124 CNU,
125 // inter_pred_idc
126 CNU, CNU, CNU, CNU, CNU,
127 // ref_idx_l0
128 CNU, CNU,
129 // ref_idx_l1
130 CNU, CNU,
131 // abs_mvd_greater1_flag
132 CNU, CNU,
133 // abs_mvd_greater1_flag
134 CNU, CNU,
135 // mvp_lx_flag
136 CNU,
137 // no_residual_data_flag
138 CNU,
139 // split_transform_flag
140 153, 138, 138,
141 // cbf_luma
142 111, 141,
143 // cbf_cb, cbf_cr
144 94, 138, 182, 154, 154,
145 // transform_skip_flag
146 139, 139,
147 // explicit_rdpcm_flag
148 139, 139,
149 // explicit_rdpcm_dir_flag
150 139, 139,
151 // last_significant_coeff_x_prefix
152 110, 110, 124, 125, 140, 153, 125, 127, 140, 109, 111, 143, 127, 111,
153 79, 108, 123, 63,
154 // last_significant_coeff_y_prefix
155 110, 110, 124, 125, 140, 153, 125, 127, 140, 109, 111, 143, 127, 111,
156 79, 108, 123, 63,
157 // significant_coeff_group_flag
158 91, 171, 134, 141,
159 // significant_coeff_flag
160 111, 111, 125, 110, 110, 94, 124, 108, 124, 107, 125, 141, 179, 153,
161 125, 107, 125, 141, 179, 153, 125, 107, 125, 141, 179, 153, 125, 140,
162 139, 182, 182, 152, 136, 152, 136, 153, 136, 139, 111, 136, 139, 111,
163 141, 111,
164 // coeff_abs_level_greater1_flag
165 140, 92, 137, 138, 140, 152, 138, 139, 153, 74, 149, 92, 139, 107,
166 122, 152, 140, 179, 166, 182, 140, 227, 122, 197,
167 // coeff_abs_level_greater2_flag
168 138, 153, 136, 167, 152, 152,
169 // log2_res_scale_abs
170 154, 154, 154, 154, 154, 154, 154, 154,
171 // res_scale_sign_flag
172 154, 154,
173 // cu_chroma_qp_offset_flag
174 154,
175 // cu_chroma_qp_offset_idx
176 154,
177 },
178 { // sao_merge_flag
179 153,
180 // sao_type_idx
181 185,
182 // split_coding_unit_flag
183 107, 139, 126,
184 // cu_transquant_bypass_flag
185 154,
186 // skip_flag
187 197, 185, 201,
188 // cu_qp_delta
189 154, 154, 154,
190 // pred_mode
191 149,
192 // part_mode
193 154, 139, 154, 154,
194 // prev_intra_luma_pred_mode
195 154,
196 // intra_chroma_pred_mode
197 152, 139,
198 // merge_flag
199 110,
200 // merge_idx
201 122,
202 // inter_pred_idc
203 95, 79, 63, 31, 31,
204 // ref_idx_l0
205 153, 153,
206 // ref_idx_l1
207 153, 153,
208 // abs_mvd_greater1_flag
209 140, 198,
210 // abs_mvd_greater1_flag
211 140, 198,
212 // mvp_lx_flag
213 168,
214 // no_residual_data_flag
215 79,
216 // split_transform_flag
217 124, 138, 94,
218 // cbf_luma
219 153, 111,
220 // cbf_cb, cbf_cr
221 149, 107, 167, 154, 154,
222 // transform_skip_flag
223 139, 139,
224 // explicit_rdpcm_flag
225 139, 139,
226 // explicit_rdpcm_dir_flag
227 139, 139,
228 // last_significant_coeff_x_prefix
229 125, 110, 94, 110, 95, 79, 125, 111, 110, 78, 110, 111, 111, 95,
230 94, 108, 123, 108,
231 // last_significant_coeff_y_prefix
232 125, 110, 94, 110, 95, 79, 125, 111, 110, 78, 110, 111, 111, 95,
233 94, 108, 123, 108,
234 // significant_coeff_group_flag
235 121, 140, 61, 154,
236 // significant_coeff_flag
237 155, 154, 139, 153, 139, 123, 123, 63, 153, 166, 183, 140, 136, 153,
238 154, 166, 183, 140, 136, 153, 154, 166, 183, 140, 136, 153, 154, 170,
239 153, 123, 123, 107, 121, 107, 121, 167, 151, 183, 140, 151, 183, 140,
240 140, 140,
241 // coeff_abs_level_greater1_flag
242 154, 196, 196, 167, 154, 152, 167, 182, 182, 134, 149, 136, 153, 121,
243 136, 137, 169, 194, 166, 167, 154, 167, 137, 182,
244 // coeff_abs_level_greater2_flag
245 107, 167, 91, 122, 107, 167,
246 // log2_res_scale_abs
247 154, 154, 154, 154, 154, 154, 154, 154,
248 // res_scale_sign_flag
249 154, 154,
250 // cu_chroma_qp_offset_flag
251 154,
252 // cu_chroma_qp_offset_idx
253 154,
254 },
255 { // sao_merge_flag
256 153,
257 // sao_type_idx
258 160,
259 // split_coding_unit_flag
260 107, 139, 126,
261 // cu_transquant_bypass_flag
262 154,
263 // skip_flag
264 197, 185, 201,
265 // cu_qp_delta
266 154, 154, 154,
267 // pred_mode
268 134,
269 // part_mode
270 154, 139, 154, 154,
271 // prev_intra_luma_pred_mode
272 183,
273 // intra_chroma_pred_mode
274 152, 139,
275 // merge_flag
276 154,
277 // merge_idx
278 137,
279 // inter_pred_idc
280 95, 79, 63, 31, 31,
281 // ref_idx_l0
282 153, 153,
283 // ref_idx_l1
284 153, 153,
285 // abs_mvd_greater1_flag
286 169, 198,
287 // abs_mvd_greater1_flag
288 169, 198,
289 // mvp_lx_flag
290 168,
291 // no_residual_data_flag
292 79,
293 // split_transform_flag
294 224, 167, 122,
295 // cbf_luma
296 153, 111,
297 // cbf_cb, cbf_cr
298 149, 92, 167, 154, 154,
299 // transform_skip_flag
300 139, 139,
301 // explicit_rdpcm_flag
302 139, 139,
303 // explicit_rdpcm_dir_flag
304 139, 139,
305 // last_significant_coeff_x_prefix
306 125, 110, 124, 110, 95, 94, 125, 111, 111, 79, 125, 126, 111, 111,
307 79, 108, 123, 93,
308 // last_significant_coeff_y_prefix
309 125, 110, 124, 110, 95, 94, 125, 111, 111, 79, 125, 126, 111, 111,
310 79, 108, 123, 93,
311 // significant_coeff_group_flag
312 121, 140, 61, 154,
313 // significant_coeff_flag
314 170, 154, 139, 153, 139, 123, 123, 63, 124, 166, 183, 140, 136, 153,
315 154, 166, 183, 140, 136, 153, 154, 166, 183, 140, 136, 153, 154, 170,
316 153, 138, 138, 122, 121, 122, 121, 167, 151, 183, 140, 151, 183, 140,
317 140, 140,
318 // coeff_abs_level_greater1_flag
319 154, 196, 167, 167, 154, 152, 167, 182, 182, 134, 149, 136, 153, 121,
320 136, 122, 169, 208, 166, 167, 154, 152, 167, 182,
321 // coeff_abs_level_greater2_flag
322 107, 167, 91, 107, 107, 167,
323 // log2_res_scale_abs
324 154, 154, 154, 154, 154, 154, 154, 154,
325 // res_scale_sign_flag
326 154, 154,
327 // cu_chroma_qp_offset_flag
328 154,
329 // cu_chroma_qp_offset_idx
330 154,
331 },
332 };
333
334 static const uint8_t scan_1x1[1] = {
335 0,
336 };
337
338 static const uint8_t horiz_scan2x2_x[4] = {
339 0, 1, 0, 1,
340 };
341
342 static const uint8_t horiz_scan2x2_y[4] = {
343 0, 0, 1, 1
344 };
345
346 static const uint8_t horiz_scan4x4_x[16] = {
347 0, 1, 2, 3,
348 0, 1, 2, 3,
349 0, 1, 2, 3,
350 0, 1, 2, 3,
351 };
352
353 static const uint8_t horiz_scan4x4_y[16] = {
354 0, 0, 0, 0,
355 1, 1, 1, 1,
356 2, 2, 2, 2,
357 3, 3, 3, 3,
358 };
359
360 static const uint8_t horiz_scan8x8_inv[8][8] = {
361 { 0, 1, 2, 3, 16, 17, 18, 19, },
362 { 4, 5, 6, 7, 20, 21, 22, 23, },
363 { 8, 9, 10, 11, 24, 25, 26, 27, },
364 { 12, 13, 14, 15, 28, 29, 30, 31, },
365 { 32, 33, 34, 35, 48, 49, 50, 51, },
366 { 36, 37, 38, 39, 52, 53, 54, 55, },
367 { 40, 41, 42, 43, 56, 57, 58, 59, },
368 { 44, 45, 46, 47, 60, 61, 62, 63, },
369 };
370
371 static const uint8_t diag_scan2x2_x[4] = {
372 0, 0, 1, 1,
373 };
374
375 static const uint8_t diag_scan2x2_y[4] = {
376 0, 1, 0, 1,
377 };
378
379 static const uint8_t diag_scan2x2_inv[2][2] = {
380 { 0, 2, },
381 { 1, 3, },
382 };
383
384 static const uint8_t diag_scan4x4_inv[4][4] = {
385 { 0, 2, 5, 9, },
386 { 1, 4, 8, 12, },
387 { 3, 7, 11, 14, },
388 { 6, 10, 13, 15, },
389 };
390
391 static const uint8_t diag_scan8x8_inv[8][8] = {
392 { 0, 2, 5, 9, 14, 20, 27, 35, },
393 { 1, 4, 8, 13, 19, 26, 34, 42, },
394 { 3, 7, 12, 18, 25, 33, 41, 48, },
395 { 6, 11, 17, 24, 32, 40, 47, 53, },
396 { 10, 16, 23, 31, 39, 46, 52, 57, },
397 { 15, 22, 30, 38, 45, 51, 56, 60, },
398 { 21, 29, 37, 44, 50, 55, 59, 62, },
399 { 28, 36, 43, 49, 54, 58, 61, 63, },
400 };
401
402 1941393 void ff_hevc_save_states(HEVCLocalContext *lc, const HEVCPPS *pps,
403 int ctb_addr_ts)
404 {
405 1941393 const HEVCSPS *const sps = pps->sps;
406
2/2
✓ Branch 0 taken 168556 times.
✓ Branch 1 taken 1772837 times.
1941393 if (pps->entropy_coding_sync_enabled_flag &&
407
2/2
✓ Branch 0 taken 161382 times.
✓ Branch 1 taken 7174 times.
168556 (ctb_addr_ts % sps->ctb_width == 2 ||
408
2/2
✓ Branch 0 taken 768 times.
✓ Branch 1 taken 160614 times.
161382 (sps->ctb_width == 2 &&
409
2/2
✓ Branch 0 taken 384 times.
✓ Branch 1 taken 384 times.
768 ctb_addr_ts % sps->ctb_width == 0))) {
410 7558 memcpy(lc->common_cabac_state->state, lc->cabac_state, HEVC_CONTEXTS);
411
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 7522 times.
7558 if (sps->persistent_rice_adaptation_enabled) {
412 36 memcpy(lc->common_cabac_state->stat_coeff, lc->stat_coeff, HEVC_STAT_COEFFS);
413 }
414 }
415 1941393 }
416
417 6283 static void load_states(HEVCLocalContext *lc, const HEVCSPS *sps)
418 {
419 6283 memcpy(lc->cabac_state, lc->common_cabac_state->state, HEVC_CONTEXTS);
420
2/2
✓ Branch 0 taken 33 times.
✓ Branch 1 taken 6250 times.
6283 if (sps->persistent_rice_adaptation_enabled) {
421 33 memcpy(lc->stat_coeff, lc->common_cabac_state->stat_coeff, HEVC_STAT_COEFFS);
422 }
423 6283 }
424
425 9862 static int cabac_reinit(HEVCLocalContext *lc)
426 {
427
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 9862 times.
9862 return skip_bytes(&lc->cc, 0) == NULL ? AVERROR_INVALIDDATA : 0;
428 }
429
430 28312 static void cabac_init_state(HEVCLocalContext *lc, const HEVCContext *s)
431 {
432 28312 int init_type = 2 - s->sh.slice_type;
433 int i;
434
435
4/4
✓ Branch 0 taken 6607 times.
✓ Branch 1 taken 21705 times.
✓ Branch 2 taken 6463 times.
✓ Branch 3 taken 144 times.
28312 if (s->sh.cabac_init_flag && s->sh.slice_type != HEVC_SLICE_I)
436 6463 init_type ^= 3;
437
438
2/2
✓ Branch 0 taken 5634088 times.
✓ Branch 1 taken 28312 times.
5662400 for (i = 0; i < HEVC_CONTEXTS; i++) {
439 5634088 int init_value = init_values[init_type][i];
440 5634088 int m = (init_value >> 4) * 5 - 45;
441 5634088 int n = ((init_value & 15) << 3) - 16;
442 5634088 int pre = 2 * (((m * av_clip(s->sh.slice_qp, 0, 51)) >> 4) + n) - 127;
443
444 5634088 pre ^= pre >> 31;
445
2/2
✓ Branch 0 taken 577591 times.
✓ Branch 1 taken 5056497 times.
5634088 if (pre > 124)
446 577591 pre = 124 + (pre & 1);
447 5634088 lc->cabac_state[i] = pre;
448 }
449
450
2/2
✓ Branch 0 taken 113248 times.
✓ Branch 1 taken 28312 times.
141560 for (i = 0; i < 4; i++)
451 113248 lc->stat_coeff[i] = 0;
452 28312 }
453
454 1993954 int ff_hevc_cabac_init(HEVCLocalContext *lc, const HEVCPPS *pps,
455 int ctb_addr_ts, const uint8_t *data, size_t size,
456 int is_wpp)
457 {
458 1993954 const HEVCContext *const s = lc->parent;
459 1993954 const HEVCSPS *const sps = pps->sps;
460
461
2/2
✓ Branch 0 taken 28471 times.
✓ Branch 1 taken 1965483 times.
1993954 if (ctb_addr_ts == pps->ctb_addr_rs_to_ts[s->sh.slice_ctb_addr_rs]) {
462 28471 int ret = ff_init_cabac_decoder(&lc->cc, data, size);
463
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 28471 times.
28471 if (ret < 0)
464 ✗ return ret;
465
2/2
✓ Branch 0 taken 7794 times.
✓ Branch 1 taken 20677 times.
28471 if (s->sh.dependent_slice_segment_flag == 0 ||
466
2/2
✓ Branch 0 taken 844 times.
✓ Branch 1 taken 6950 times.
7794 (pps->tiles_enabled_flag &&
467
2/2
✓ Branch 0 taken 298 times.
✓ Branch 1 taken 546 times.
844 pps->tile_id[ctb_addr_ts] != pps->tile_id[ctb_addr_ts - 1]))
468 20975 cabac_init_state(lc, s);
469
470
2/2
✓ Branch 0 taken 17996 times.
✓ Branch 1 taken 10475 times.
28471 if (!s->sh.first_slice_in_pic_flag &&
471
2/2
✓ Branch 0 taken 3820 times.
✓ Branch 1 taken 14176 times.
17996 pps->entropy_coding_sync_enabled_flag) {
472
2/2
✓ Branch 0 taken 1620 times.
✓ Branch 1 taken 2200 times.
3820 if (ctb_addr_ts % sps->ctb_width == 0) {
473
2/2
✓ Branch 0 taken 92 times.
✓ Branch 1 taken 1528 times.
1620 if (sps->ctb_width == 1)
474 92 cabac_init_state(lc, s);
475
2/2
✓ Branch 0 taken 1146 times.
✓ Branch 1 taken 382 times.
1528 else if (s->sh.dependent_slice_segment_flag == 1)
476 1146 load_states(lc, sps);
477 }
478 }
479 } else {
480
2/2
✓ Branch 0 taken 704612 times.
✓ Branch 1 taken 1260871 times.
1965483 if (pps->tiles_enabled_flag &&
481
2/2
✓ Branch 0 taken 7049 times.
✓ Branch 1 taken 697563 times.
704612 pps->tile_id[ctb_addr_ts] != pps->tile_id[ctb_addr_ts - 1]) {
482 int ret;
483
2/2
✓ Branch 0 taken 4529 times.
✓ Branch 1 taken 2520 times.
7049 if (!is_wpp)
484 4529 ret = cabac_reinit(lc);
485 else {
486 2520 ret = ff_init_cabac_decoder(&lc->cc, data, size);
487 }
488
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7049 times.
7049 if (ret < 0)
489 ✗ return ret;
490 7049 cabac_init_state(lc, s);
491 }
492
2/2
✓ Branch 0 taken 163747 times.
✓ Branch 1 taken 1801736 times.
1965483 if (pps->entropy_coding_sync_enabled_flag) {
493
2/2
✓ Branch 0 taken 5333 times.
✓ Branch 1 taken 158414 times.
163747 if (ctb_addr_ts % sps->ctb_width == 0) {
494 int ret;
495 5333 get_cabac_terminate(&lc->cc);
496
1/2
✓ Branch 0 taken 5333 times.
✗ Branch 1 not taken.
5333 if (!is_wpp)
497 5333 ret = cabac_reinit(lc);
498 else {
499 ✗ ret = ff_init_cabac_decoder(&lc->cc, data, size);
500 }
501
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5333 times.
5333 if (ret < 0)
502 ✗ return ret;
503
504
2/2
✓ Branch 0 taken 196 times.
✓ Branch 1 taken 5137 times.
5333 if (sps->ctb_width == 1)
505 196 cabac_init_state(lc, s);
506 else
507 5137 load_states(lc, sps);
508 }
509 }
510 }
511 1993954 return 0;
512 }
513
514 #define GET_CABAC(ctx) get_cabac(&lc->cc, &lc->cabac_state[ctx])
515
516 1430222 int ff_hevc_sao_merge_flag_decode(HEVCLocalContext *lc)
517 {
518 1430222 return GET_CABAC(SAO_MERGE_FLAG_OFFSET);
519 }
520
521 561205 int ff_hevc_sao_type_idx_decode(HEVCLocalContext *lc)
522 {
523
2/2
✓ Branch 1 taken 390736 times.
✓ Branch 2 taken 170469 times.
561205 if (!GET_CABAC(SAO_TYPE_IDX_OFFSET))
524 390736 return 0;
525
526
2/2
✓ Branch 1 taken 50547 times.
✓ Branch 2 taken 119922 times.
170469 if (!get_cabac_bypass(&lc->cc))
527 50547 return SAO_BAND;
528 119922 return SAO_EDGE;
529 }
530
531 72036 int ff_hevc_sao_band_position_decode(HEVCLocalContext *lc)
532 {
533 int i;
534 72036 int value = get_cabac_bypass(&lc->cc);
535
536
2/2
✓ Branch 0 taken 288144 times.
✓ Branch 1 taken 72036 times.
360180 for (i = 0; i < 4; i++)
537 288144 value = (value << 1) | get_cabac_bypass(&lc->cc);
538 72036 return value;
539 }
540
541 875640 int ff_hevc_sao_offset_abs_decode(HEVCLocalContext *lc, int bit_depth)
542 {
543 875640 int i = 0;
544 875640 int length = (1 << (FFMIN(bit_depth, 10) - 5)) - 1;
545
546
4/4
✓ Branch 0 taken 2409493 times.
✓ Branch 1 taken 118188 times.
✓ Branch 3 taken 1652041 times.
✓ Branch 4 taken 757452 times.
2527681 while (i < length && get_cabac_bypass(&lc->cc))
547 1652041 i++;
548 875640 return i;
549 }
550
551 223920 int ff_hevc_sao_offset_sign_decode(HEVCLocalContext *lc)
552 {
553 223920 return get_cabac_bypass(&lc->cc);
554 }
555
556 119922 int ff_hevc_sao_eo_class_decode(HEVCLocalContext *lc)
557 {
558 119922 int ret = get_cabac_bypass(&lc->cc) << 1;
559 119922 ret |= get_cabac_bypass(&lc->cc);
560 119922 return ret;
561 }
562
563 1993953 int ff_hevc_end_of_slice_flag_decode(HEVCLocalContext *lc)
564 {
565 1993953 return get_cabac_terminate(&lc->cc);
566 }
567
568 179649 int ff_hevc_cu_transquant_bypass_flag_decode(HEVCLocalContext *lc)
569 {
570 179649 return GET_CABAC(CU_TRANSQUANT_BYPASS_FLAG_OFFSET);
571 }
572
573 10114738 int ff_hevc_skip_flag_decode(HEVCLocalContext *lc, uint8_t *skip_flag,
574 int x0, int y0, int x_cb, int y_cb, int min_cb_width)
575 {
576 10114738 int inc = 0;
577
578
4/4
✓ Branch 0 taken 871713 times.
✓ Branch 1 taken 9243025 times.
✓ Branch 2 taken 610395 times.
✓ Branch 3 taken 261318 times.
10114738 if (lc->ctb_left_flag || x0)
579 9853420 inc = !!SAMPLE_CTB(skip_flag, x_cb - 1, y_cb);
580
4/4
✓ Branch 0 taken 1812042 times.
✓ Branch 1 taken 8302696 times.
✓ Branch 2 taken 1302336 times.
✓ Branch 3 taken 509706 times.
10114738 if (lc->ctb_up_flag || y0)
581 9605032 inc += !!SAMPLE_CTB(skip_flag, x_cb, y_cb - 1);
582
583 10114738 return GET_CABAC(SKIP_FLAG_OFFSET + inc);
584 }
585
586 920252 int ff_hevc_cu_qp_delta_abs(HEVCLocalContext *lc)
587 {
588 920252 int prefix_val = 0;
589 920252 int suffix_val = 0;
590 920252 int inc = 0;
591
592
4/4
✓ Branch 0 taken 2062233 times.
✓ Branch 1 taken 141978 times.
✓ Branch 3 taken 1283959 times.
✓ Branch 4 taken 778274 times.
2204211 while (prefix_val < 5 && GET_CABAC(CU_QP_DELTA_OFFSET + inc)) {
593 1283959 prefix_val++;
594 1283959 inc = 1;
595 }
596
2/2
✓ Branch 0 taken 141978 times.
✓ Branch 1 taken 778274 times.
920252 if (prefix_val >= 5) {
597 141978 int k = 0;
598
3/4
✓ Branch 0 taken 438128 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 296150 times.
✓ Branch 4 taken 141978 times.
438128 while (k < 7 && get_cabac_bypass(&lc->cc)) {
599 296150 suffix_val += 1 << k;
600 296150 k++;
601 }
602
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 141978 times.
141978 if (k == 7) {
603 ✗ av_log(lc->logctx, AV_LOG_ERROR, "CABAC_MAX_BIN : %d\n", k);
604 ✗ return AVERROR_INVALIDDATA;
605 }
606
607
2/2
✓ Branch 0 taken 296150 times.
✓ Branch 1 taken 141978 times.
438128 while (k--)
608 296150 suffix_val += get_cabac_bypass(&lc->cc) << k;
609 }
610 920252 return prefix_val + suffix_val;
611 }
612
613 485048 int ff_hevc_cu_qp_delta_sign_flag(HEVCLocalContext *lc)
614 {
615 485048 return get_cabac_bypass(&lc->cc);
616 }
617
618 228078 int ff_hevc_cu_chroma_qp_offset_flag(HEVCLocalContext *lc)
619 {
620 228078 return GET_CABAC(CU_CHROMA_QP_OFFSET_FLAG_OFFSET);
621 }
622
623 ✗ int ff_hevc_cu_chroma_qp_offset_idx(HEVCLocalContext *lc, int chroma_qp_offset_list_len_minus1)
624 {
625 ✗ int c_max= FFMAX(5, chroma_qp_offset_list_len_minus1);
626 ✗ int i = 0;
627
628 ✗ while (i < c_max && GET_CABAC(CU_CHROMA_QP_OFFSET_IDX_OFFSET))
629 ✗ i++;
630
631 ✗ return i;
632 }
633
634 5390646 int ff_hevc_pred_mode_decode(HEVCLocalContext *lc)
635 {
636 5390646 return GET_CABAC(PRED_MODE_FLAG_OFFSET);
637 }
638
639 8950583 int ff_hevc_split_coding_unit_flag_decode(HEVCLocalContext *lc, uint8_t *tab_ct_depth,
640 const HEVCSPS *sps,
641 int ct_depth, int x0, int y0)
642 {
643 8950583 int inc = 0, depth_left = 0, depth_top = 0;
644 8950583 int x0b = av_zero_extend(x0, sps->log2_ctb_size);
645 8950583 int y0b = av_zero_extend(y0, sps->log2_ctb_size);
646 8950583 int x_cb = x0 >> sps->log2_min_cb_size;
647 8950583 int y_cb = y0 >> sps->log2_min_cb_size;
648
649
4/4
✓ Branch 0 taken 779202 times.
✓ Branch 1 taken 8171381 times.
✓ Branch 2 taken 423841 times.
✓ Branch 3 taken 355361 times.
8950583 if (lc->ctb_left_flag || x0b)
650 8595222 depth_left = tab_ct_depth[(y_cb) * sps->min_cb_width + x_cb - 1];
651
4/4
✓ Branch 0 taken 1562217 times.
✓ Branch 1 taken 7388366 times.
✓ Branch 2 taken 860527 times.
✓ Branch 3 taken 701690 times.
8950583 if (lc->ctb_up_flag || y0b)
652 8248893 depth_top = tab_ct_depth[(y_cb - 1) * sps->min_cb_width + x_cb];
653
654 8950583 inc += (depth_left > ct_depth);
655 8950583 inc += (depth_top > ct_depth);
656
657 8950583 return GET_CABAC(SPLIT_CODING_UNIT_FLAG_OFFSET + inc);
658 }
659
660 6877286 int ff_hevc_part_mode_decode(HEVCLocalContext *lc, const HEVCSPS *sps, int log2_cb_size)
661 {
662
2/2
✓ Branch 1 taken 4291861 times.
✓ Branch 2 taken 2585425 times.
6877286 if (GET_CABAC(PART_MODE_OFFSET)) // 1
663 4291861 return PART_2Nx2N;
664
2/2
✓ Branch 0 taken 1824761 times.
✓ Branch 1 taken 760664 times.
2585425 if (log2_cb_size == sps->log2_min_cb_size) {
665
2/2
✓ Branch 0 taken 1049600 times.
✓ Branch 1 taken 775161 times.
1824761 if (lc->cu.pred_mode == MODE_INTRA) // 0
666 1049600 return PART_NxN;
667
2/2
✓ Branch 1 taken 317747 times.
✓ Branch 2 taken 457414 times.
775161 if (GET_CABAC(PART_MODE_OFFSET + 1)) // 01
668 317747 return PART_2NxN;
669
2/2
✓ Branch 0 taken 233272 times.
✓ Branch 1 taken 224142 times.
457414 if (log2_cb_size == 3) // 00
670 233272 return PART_Nx2N;
671
2/2
✓ Branch 1 taken 115987 times.
✓ Branch 2 taken 108155 times.
224142 if (GET_CABAC(PART_MODE_OFFSET + 2)) // 001
672 115987 return PART_Nx2N;
673 108155 return PART_NxN; // 000
674 }
675
676
2/2
✓ Branch 0 taken 155425 times.
✓ Branch 1 taken 605239 times.
760664 if (!sps->amp_enabled) {
677
2/2
✓ Branch 1 taken 74928 times.
✓ Branch 2 taken 80497 times.
155425 if (GET_CABAC(PART_MODE_OFFSET + 1)) // 01
678 74928 return PART_2NxN;
679 80497 return PART_Nx2N;
680 }
681
682
2/2
✓ Branch 1 taken 241410 times.
✓ Branch 2 taken 363829 times.
605239 if (GET_CABAC(PART_MODE_OFFSET + 1)) { // 01X, 01XX
683
2/2
✓ Branch 1 taken 115907 times.
✓ Branch 2 taken 125503 times.
241410 if (GET_CABAC(PART_MODE_OFFSET + 3)) // 011
684 115907 return PART_2NxN;
685
2/2
✓ Branch 1 taken 58153 times.
✓ Branch 2 taken 67350 times.
125503 if (get_cabac_bypass(&lc->cc)) // 0101
686 58153 return PART_2NxnD;
687 67350 return PART_2NxnU; // 0100
688 }
689
690
2/2
✓ Branch 1 taken 177705 times.
✓ Branch 2 taken 186124 times.
363829 if (GET_CABAC(PART_MODE_OFFSET + 3)) // 001
691 177705 return PART_Nx2N;
692
2/2
✓ Branch 1 taken 85843 times.
✓ Branch 2 taken 100281 times.
186124 if (get_cabac_bypass(&lc->cc)) // 0001
693 85843 return PART_nRx2N;
694 100281 return PART_nLx2N; // 0000
695 }
696
697 126478 int ff_hevc_pcm_flag_decode(HEVCLocalContext *lc)
698 {
699 126478 return get_cabac_terminate(&lc->cc);
700 }
701
702 6821846 int ff_hevc_prev_intra_luma_pred_flag_decode(HEVCLocalContext *lc)
703 {
704 6821846 return GET_CABAC(PREV_INTRA_LUMA_PRED_FLAG_OFFSET);
705 }
706
707 4052132 int ff_hevc_mpm_idx_decode(HEVCLocalContext *lc)
708 {
709 4052132 int i = 0;
710
4/4
✓ Branch 0 taken 6053132 times.
✓ Branch 1 taken 849050 times.
✓ Branch 3 taken 2850050 times.
✓ Branch 4 taken 3203082 times.
6902182 while (i < 2 && get_cabac_bypass(&lc->cc))
711 2850050 i++;
712 4052132 return i;
713 }
714
715 2769714 int ff_hevc_rem_intra_luma_pred_mode_decode(HEVCLocalContext *lc)
716 {
717 int i;
718 2769714 int value = get_cabac_bypass(&lc->cc);
719
720
2/2
✓ Branch 0 taken 11078856 times.
✓ Branch 1 taken 2769714 times.
13848570 for (i = 0; i < 4; i++)
721 11078856 value = (value << 1) | get_cabac_bypass(&lc->cc);
722 2769714 return value;
723 }
724
725 3728882 int ff_hevc_intra_chroma_pred_mode_decode(HEVCLocalContext *lc)
726 {
727 int ret;
728
2/2
✓ Branch 1 taken 2840011 times.
✓ Branch 2 taken 888871 times.
3728882 if (!GET_CABAC(INTRA_CHROMA_PRED_MODE_OFFSET))
729 2840011 return 4;
730
731 888871 ret = get_cabac_bypass(&lc->cc) << 1;
732 888871 ret |= get_cabac_bypass(&lc->cc);
733 888871 return ret;
734 }
735
736 7584119 int ff_hevc_merge_idx_decode(HEVCLocalContext *lc)
737 {
738 7584119 int i = GET_CABAC(MERGE_IDX_OFFSET);
739
740
2/2
✓ Branch 0 taken 3013142 times.
✓ Branch 1 taken 4570977 times.
7584119 if (i != 0) {
741
4/4
✓ Branch 0 taken 4430211 times.
✓ Branch 1 taken 412513 times.
✓ Branch 3 taken 1829582 times.
✓ Branch 4 taken 2600629 times.
4842724 while (i < lc->parent->sh.max_num_merge_cand-1 && get_cabac_bypass(&lc->cc))
742 1829582 i++;
743 }
744 7584119 return i;
745 }
746
747 5861787 int ff_hevc_merge_flag_decode(HEVCLocalContext *lc)
748 {
749 5861787 return GET_CABAC(MERGE_FLAG_OFFSET);
750 }
751
752 1923220 int ff_hevc_inter_pred_idc_decode(HEVCLocalContext *lc, int nPbW, int nPbH)
753 {
754
2/2
✓ Branch 0 taken 248669 times.
✓ Branch 1 taken 1674551 times.
1923220 if (nPbW + nPbH == 12)
755 248669 return GET_CABAC(INTER_PRED_IDC_OFFSET + 4);
756
2/2
✓ Branch 1 taken 424978 times.
✓ Branch 2 taken 1249573 times.
1674551 if (GET_CABAC(INTER_PRED_IDC_OFFSET + lc->ct_depth))
757 424978 return PRED_BI;
758
759 1249573 return GET_CABAC(INTER_PRED_IDC_OFFSET + 4);
760 }
761
762 3349885 int ff_hevc_ref_idx_lx_decode(HEVCLocalContext *lc, int num_ref_idx_lx)
763 {
764 3349885 int i = 0;
765 3349885 int max = num_ref_idx_lx - 1;
766 3349885 int max_ctx = FFMIN(max, 2);
767
768
4/4
✓ Branch 0 taken 3140027 times.
✓ Branch 1 taken 1241225 times.
✓ Branch 3 taken 1031367 times.
✓ Branch 4 taken 2108660 times.
4381252 while (i < max_ctx && GET_CABAC(REF_IDX_L0_OFFSET + i))
769 1031367 i++;
770
2/2
✓ Branch 0 taken 203609 times.
✓ Branch 1 taken 3146276 times.
3349885 if (i == 2) {
771
4/4
✓ Branch 0 taken 162576 times.
✓ Branch 1 taken 127630 times.
✓ Branch 3 taken 86597 times.
✓ Branch 4 taken 75979 times.
290206 while (i < max && get_cabac_bypass(&lc->cc))
772 86597 i++;
773 }
774
775 3349885 return i;
776 }
777
778 3349885 int ff_hevc_mvp_lx_flag_decode(HEVCLocalContext *lc)
779 {
780 3349885 return GET_CABAC(MVP_LX_FLAG_OFFSET);
781 }
782
783 2901573 int ff_hevc_no_residual_syntax_flag_decode(HEVCLocalContext *lc)
784 {
785 2901573 return GET_CABAC(NO_RESIDUAL_DATA_FLAG_OFFSET);
786 }
787
788 6372560 static av_always_inline int abs_mvd_greater0_flag_decode(HEVCLocalContext *lc)
789 {
790 6372560 return GET_CABAC(ABS_MVD_GREATER0_FLAG_OFFSET);
791 }
792
793 4361287 static av_always_inline int abs_mvd_greater1_flag_decode(HEVCLocalContext *lc)
794 {
795 4361287 return GET_CABAC(ABS_MVD_GREATER1_FLAG_OFFSET + 1);
796 }
797
798 3048092 static av_always_inline int mvd_decode(HEVCLocalContext *lc)
799 {
800 3048092 int ret = 2;
801 3048092 int k = 1;
802
803
3/4
✓ Branch 0 taken 7362816 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 4314724 times.
✓ Branch 4 taken 3048092 times.
7362816 while (k < CABAC_MAX_BIN && get_cabac_bypass(&lc->cc)) {
804 4314724 ret += 1U << k;
805 4314724 k++;
806 }
807
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3048092 times.
3048092 if (k == CABAC_MAX_BIN) {
808 ✗ av_log(lc->logctx, AV_LOG_ERROR, "CABAC_MAX_BIN : %d\n", k);
809 ✗ return 0;
810 }
811
2/2
✓ Branch 0 taken 7362816 times.
✓ Branch 1 taken 3048092 times.
10410908 while (k--)
812 7362816 ret += get_cabac_bypass(&lc->cc) << k;
813 3048092 return get_cabac_bypass_sign(&lc->cc, -ret);
814 }
815
816 1313195 static av_always_inline int mvd_sign_flag_decode(HEVCLocalContext *lc)
817 {
818 1313195 return get_cabac_bypass_sign(&lc->cc, -1);
819 }
820
821 6928759 int ff_hevc_split_transform_flag_decode(HEVCLocalContext *lc, int log2_trafo_size)
822 {
823 6928759 return GET_CABAC(SPLIT_TRANSFORM_FLAG_OFFSET + 5 - log2_trafo_size);
824 }
825
826 15653858 int ff_hevc_cbf_cb_cr_decode(HEVCLocalContext *lc, int trafo_depth)
827 {
828 15653858 return GET_CABAC(CBF_CB_CR_OFFSET + trafo_depth);
829 }
830
831 14531061 int ff_hevc_cbf_luma_decode(HEVCLocalContext *lc, int trafo_depth)
832 {
833
2/2
✓ Branch 0 taken 2758446 times.
✓ Branch 1 taken 11772615 times.
14531061 return GET_CABAC(CBF_LUMA_OFFSET + !trafo_depth);
834 }
835
836 5689341 static int hevc_transform_skip_flag_decode(HEVCLocalContext *lc, int c_idx)
837 {
838
2/2
✓ Branch 0 taken 1846000 times.
✓ Branch 1 taken 3843341 times.
5689341 return GET_CABAC(TRANSFORM_SKIP_FLAG_OFFSET + !!c_idx);
839 }
840
841 35234 static int explicit_rdpcm_flag_decode(HEVCLocalContext *lc, int c_idx)
842 {
843
2/2
✓ Branch 0 taken 29253 times.
✓ Branch 1 taken 5981 times.
35234 return GET_CABAC(EXPLICIT_RDPCM_FLAG_OFFSET + !!c_idx);
844 }
845
846 3090 static int explicit_rdpcm_dir_flag_decode(HEVCLocalContext *lc, int c_idx)
847 {
848
2/2
✓ Branch 0 taken 1813 times.
✓ Branch 1 taken 1277 times.
3090 return GET_CABAC(EXPLICIT_RDPCM_DIR_FLAG_OFFSET + !!c_idx);
849 }
850
851 251428 int ff_hevc_log2_res_scale_abs(HEVCLocalContext *lc, int idx)
852 {
853 251428 int i =0;
854
855
4/4
✓ Branch 0 taken 668172 times.
✓ Branch 1 taken 84789 times.
✓ Branch 3 taken 501533 times.
✓ Branch 4 taken 166639 times.
752961 while (i < 4 && GET_CABAC(LOG2_RES_SCALE_ABS_OFFSET + 4 * idx + i))
856 501533 i++;
857
858 251428 return i;
859 }
860
861 142161 int ff_hevc_res_scale_sign_flag(HEVCLocalContext *lc, int idx)
862 {
863 142161 return GET_CABAC(RES_SCALE_SIGN_FLAG_OFFSET + idx);
864 }
865
866 14008756 static av_always_inline void last_significant_coeff_xy_prefix_decode(HEVCLocalContext *lc, int c_idx,
867 int log2_size, int *last_scx_prefix, int *last_scy_prefix)
868 {
869 14008756 int i = 0;
870 14008756 int max = (log2_size << 1) - 1;
871 int ctx_offset, ctx_shift;
872
873
2/2
✓ Branch 0 taken 9875694 times.
✓ Branch 1 taken 4133062 times.
14008756 if (!c_idx) {
874 9875694 ctx_offset = 3 * (log2_size - 2) + ((log2_size - 1) >> 2);
875 9875694 ctx_shift = (log2_size + 1) >> 2;
876 } else {
877 4133062 ctx_offset = 15;
878 4133062 ctx_shift = log2_size - 2;
879 }
880
4/4
✓ Branch 0 taken 34074915 times.
✓ Branch 1 taken 1864566 times.
✓ Branch 2 taken 21930725 times.
✓ Branch 3 taken 12144190 times.
70014396 while (i < max &&
881 34074915 GET_CABAC(LAST_SIGNIFICANT_COEFF_X_PREFIX_OFFSET + (i >> ctx_shift) + ctx_offset))
882 21930725 i++;
883 14008756 *last_scx_prefix = i;
884
885 14008756 i = 0;
886
4/4
✓ Branch 0 taken 29906404 times.
✓ Branch 1 taken 1507642 times.
✓ Branch 2 taken 17405290 times.
✓ Branch 3 taken 12501114 times.
61320450 while (i < max &&
887 29906404 GET_CABAC(LAST_SIGNIFICANT_COEFF_Y_PREFIX_OFFSET + (i >> ctx_shift) + ctx_offset))
888 17405290 i++;
889 14008756 *last_scy_prefix = i;
890 14008756 }
891
892 3179584 static av_always_inline int last_significant_coeff_suffix_decode(HEVCLocalContext *lc,
893 int last_significant_coeff_prefix)
894 {
895 int i;
896 3179584 int length = (last_significant_coeff_prefix >> 1) - 1;
897 3179584 int value = get_cabac_bypass(&lc->cc);
898
899
2/2
✓ Branch 0 taken 877920 times.
✓ Branch 1 taken 3179584 times.
4057504 for (i = 1; i < length; i++)
900 877920 value = (value << 1) | get_cabac_bypass(&lc->cc);
901 3179584 return value;
902 }
903
904 8341518 static av_always_inline int significant_coeff_group_flag_decode(HEVCLocalContext *lc, int c_idx, int ctx_cg)
905 {
906 int inc;
907
908
2/2
✓ Branch 0 taken 1179417 times.
✓ Branch 1 taken 7162101 times.
8341518 inc = FFMIN(ctx_cg, 1) + (c_idx>0 ? 2 : 0);
909
910 8341518 return GET_CABAC(SIGNIFICANT_COEFF_GROUP_FLAG_OFFSET + inc);
911 }
912 167750516 static av_always_inline int significant_coeff_flag_decode(HEVCLocalContext *lc, int n,
913 int offset, const uint8_t *ctx_idx_map)
914 {
915 167750516 int inc = ctx_idx_map[n] + offset;
916 167750516 return GET_CABAC(SIGNIFICANT_COEFF_FLAG_OFFSET + inc);
917 }
918
919 18079255 static av_always_inline int significant_coeff_flag_decode_0(HEVCLocalContext *lc, int c_idx, int offset)
920 {
921 18079255 return GET_CABAC(SIGNIFICANT_COEFF_FLAG_OFFSET + offset);
922 }
923
924 85806979 static av_always_inline int coeff_abs_level_greater1_flag_decode(HEVCLocalContext *lc, int c_idx, int inc)
925 {
926
927
2/2
✓ Branch 0 taken 18317135 times.
✓ Branch 1 taken 67489844 times.
85806979 if (c_idx > 0)
928 18317135 inc += 16;
929
930 85806979 return GET_CABAC(COEFF_ABS_LEVEL_GREATER1_FLAG_OFFSET + inc);
931 }
932
933 9336940 static av_always_inline int coeff_abs_level_greater2_flag_decode(HEVCLocalContext *lc, int c_idx, int inc)
934 {
935
2/2
✓ Branch 0 taken 1792718 times.
✓ Branch 1 taken 7544222 times.
9336940 if (c_idx > 0)
936 1792718 inc += 4;
937
938 9336940 return GET_CABAC(COEFF_ABS_LEVEL_GREATER2_FLAG_OFFSET + inc);
939 }
940
941 /* a run of bypass bins is the quotient of the offset by range << 17 */
942 17195541 static int cabac_bypass_bits(CABACContext *c, int n)
943 {
944 17195541 int avail = CABAC_BITS - ff_ctz(c->low);
945 17195541 uint64_t x, r = (uint64_t)c->range << (CABAC_BITS + 1);
946 17195541 const uint8_t *bytestream = c->bytestream;
947
948
2/2
✓ Branch 0 taken 10728417 times.
✓ Branch 1 taken 6467124 times.
17195541 if (n < avail) {
949 10728417 x = (uint64_t)c->low << n;
950 } else {
951 6467124 int fill = (bytestream[0] << 9) + (bytestream[1] << 1) - CABAC_MASK;
952
953 6467124 x = (uint64_t)((((int64_t)c->low << avail) + fill)) << (n - avail);
954 #if !UNCHECKED_BITSTREAM_READER
955
2/2
✓ Branch 0 taken 6466933 times.
✓ Branch 1 taken 191 times.
6467124 if (bytestream < c->bytestream_end)
956 #endif
957 6466933 bytestream += CABAC_BITS / 8;
958 }
959
960
1/2
✓ Branch 0 taken 17195541 times.
✗ Branch 1 not taken.
17195541 if (x < r << n) {
961 17195541 c->low = x % r;
962 17195541 c->bytestream = bytestream;
963 17195541 return x / r;
964 } else {
965 ✗ int ret = 0;
966
967 ✗ for (int i = 0; i < n; i++)
968 ✗ ret = (ret << 1) | get_cabac_bypass(c);
969 ✗ return ret;
970 }
971 }
972
973 /* leading ones of the quotient, consumed only up to the first zero */
974 36794330 static int cabac_unary_prefix(CABACContext *c, int max)
975 {
976 36794330 int prefix = 0;
977
978
1/2
✓ Branch 0 taken 42102548 times.
✗ Branch 1 not taken.
42102548 while (prefix < max) {
979 42102548 int avail = CABAC_BITS - ff_ctz(c->low);
980 42102548 int n = FFMIN(avail - 1, max - prefix);
981 42102548 uint64_t r = (uint64_t)c->range << (CABAC_BITS + 1);
982 42102548 uint64_t x = (uint64_t)c->low << n;
983 int q, t;
984
985
3/4
✓ Branch 0 taken 37147564 times.
✓ Branch 1 taken 4954984 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 37147564 times.
42102548 if (n < 1 || x >= r << n) {
986
2/2
✓ Branch 1 taken 2300278 times.
✓ Branch 2 taken 2654706 times.
4954984 if (!get_cabac_bypass(c))
987 2300278 return prefix;
988 2654706 prefix++;
989 2654706 continue;
990 }
991
992 37147564 q = x / r;
993 37147564 t = ~q & ((1 << n) - 1);
994
2/2
✓ Branch 0 taken 34494052 times.
✓ Branch 1 taken 2653512 times.
37147564 if (t) {
995 34494052 int p = n - 1 - av_log2(t);
996 34494052 int k = n - (p + 1);
997
998 34494052 c->low = (x >> k) - ((uint64_t)(q >> k) * r);
999 34494052 return prefix + p;
1000 }
1001 2653512 c->low = x - (uint64_t)q * r;
1002 2653512 prefix += n;
1003 }
1004 ✗ return prefix;
1005 }
1006
1007 36794330 static av_always_inline int coeff_abs_level_remaining_decode(HEVCLocalContext *lc, int rc_rice_param)
1008 {
1009 int prefix;
1010 36794330 int suffix = 0;
1011 int last_coeff_abs_level_remaining;
1012 int i;
1013
1014 36794330 prefix = cabac_unary_prefix(&lc->cc, CABAC_MAX_BIN);
1015
1016
2/2
✓ Branch 0 taken 31765174 times.
✓ Branch 1 taken 5029156 times.
36794330 if (prefix < 3) {
1017
2/2
✓ Branch 0 taken 3399363 times.
✓ Branch 1 taken 28365811 times.
31765174 if (rc_rice_param > 2)
1018 3399363 suffix = cabac_bypass_bits(&lc->cc, rc_rice_param);
1019 else
1020
2/2
✓ Branch 0 taken 19448598 times.
✓ Branch 1 taken 28365811 times.
47814409 for (i = 0; i < rc_rice_param; i++)
1021 19448598 suffix = (suffix << 1) | get_cabac_bypass(&lc->cc);
1022 31765174 last_coeff_abs_level_remaining = (prefix << rc_rice_param) + suffix;
1023 } else {
1024 5029156 int prefix_minus3 = prefix - 3;
1025 int k;
1026
1027
2/4
✓ Branch 0 taken 5029156 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 5029156 times.
5029156 if (prefix == CABAC_MAX_BIN || prefix_minus3 + rc_rice_param > 16 + 6) {
1028 ✗ av_log(lc->logctx, AV_LOG_ERROR, "CABAC_MAX_BIN : %d\n", prefix);
1029 ✗ return 0;
1030 }
1031
1032 5029156 k = prefix_minus3 + rc_rice_param;
1033
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5029156 times.
5029156 if (k > 16) {
1034 ✗ suffix = cabac_bypass_bits(&lc->cc, 16) << (k - 16);
1035 ✗ suffix |= cabac_bypass_bits(&lc->cc, k - 16);
1036
2/2
✓ Branch 0 taken 2173385 times.
✓ Branch 1 taken 2855771 times.
5029156 } else if (k > 2) {
1037 2173385 suffix = cabac_bypass_bits(&lc->cc, k);
1038 } else {
1039
2/2
✓ Branch 0 taken 2796618 times.
✓ Branch 1 taken 2855771 times.
5652389 for (i = 0; i < k; i++)
1040 2796618 suffix = (suffix << 1) | get_cabac_bypass(&lc->cc);
1041 }
1042 5029156 last_coeff_abs_level_remaining = (((1 << prefix_minus3) + 3 - 1)
1043 5029156 << rc_rice_param) + suffix;
1044 }
1045 36794330 return last_coeff_abs_level_remaining;
1046 }
1047
1048 21452067 static av_always_inline int coeff_sign_flag_decode(HEVCLocalContext *lc, uint8_t nb)
1049 {
1050 int i;
1051 21452067 int ret = 0;
1052
1053
2/2
✓ Branch 0 taken 11622793 times.
✓ Branch 1 taken 9829274 times.
21452067 if (nb > 2)
1054 11622793 return cabac_bypass_bits(&lc->cc, nb);
1055
1056
2/2
✓ Branch 0 taken 13854252 times.
✓ Branch 1 taken 9829274 times.
23683526 for (i = 0; i < nb; i++)
1057 13854252 ret = (ret << 1) | get_cabac_bypass(&lc->cc);
1058 9829274 return ret;
1059 }
1060
1061 14008756 void ff_hevc_hls_residual_coding(HEVCLocalContext *lc, const HEVCPPS *pps,
1062 int x0, int y0,
1063 int log2_trafo_size, enum ScanType scan_idx,
1064 int c_idx)
1065 {
1066 #define GET_COORD(offset, n) \
1067 do { \
1068 x_c = (x_cg << 2) + scan_x_off[n]; \
1069 y_c = (y_cg << 2) + scan_y_off[n]; \
1070 } while (0)
1071 14008756 const HEVCContext *const s = lc->parent;
1072 14008756 const HEVCSPS *const sps = pps->sps;
1073 14008756 int transform_skip_flag = 0;
1074
1075 int last_significant_coeff_x, last_significant_coeff_y;
1076 int last_scan_pos;
1077 int n_end;
1078 14008756 int num_coeff = 0;
1079 14008756 int greater1_ctx = 1;
1080
1081 int num_last_subset;
1082 int max_xy, col_limit, clear_rows;
1083 int x_cg_last_sig, y_cg_last_sig;
1084
1085 const uint8_t *scan_x_cg, *scan_y_cg, *scan_x_off, *scan_y_off;
1086
1087 14008756 ptrdiff_t stride = s->cur_frame->f->linesize[c_idx];
1088 14008756 int hshift = sps->hshift[c_idx];
1089 14008756 int vshift = sps->vshift[c_idx];
1090 14008756 uint8_t *dst = &s->cur_frame->f->data[c_idx][(y0 >> vshift) * stride +
1091 14008756 ((x0 >> hshift) << sps->pixel_shift)];
1092
2/2
✓ Branch 0 taken 4133062 times.
✓ Branch 1 taken 9875694 times.
14008756 int16_t *coeffs = (int16_t*)(c_idx ? lc->edge_emu_buffer2 : lc->edge_emu_buffer);
1093 14008756 uint8_t significant_coeff_group_flag[8][8] = {{0}};
1094 14008756 int explicit_rdpcm_flag = 0;
1095 int explicit_rdpcm_dir_flag;
1096
1097 14008756 int trafo_size = 1 << log2_trafo_size;
1098 int i;
1099 int qp,shift,add,scale,scale_m;
1100 static const uint8_t level_scale[] = { 40, 45, 51, 57, 64, 72 };
1101 14008756 const uint8_t *scale_matrix = NULL;
1102 uint8_t dc_scale;
1103
2/2
✓ Branch 0 taken 9875694 times.
✓ Branch 1 taken 4133062 times.
14008756 int pred_mode_intra = (c_idx == 0) ? lc->tu.intra_pred_mode :
1104 lc->tu.intra_pred_mode_c;
1105
1106 // Derive QP for dequant
1107
2/2
✓ Branch 0 taken 13588048 times.
✓ Branch 1 taken 420708 times.
14008756 if (!lc->cu.cu_transquant_bypass_flag) {
1108 static const int qp_c[] = { 29, 30, 31, 32, 33, 33, 34, 34, 35, 35, 36, 36, 37, 37 };
1109 static const uint8_t rem6[51 + 4 * 6 + 1] = {
1110 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2,
1111 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5,
1112 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3,
1113 4, 5, 0, 1, 2, 3, 4, 5, 0, 1
1114 };
1115
1116 static const uint8_t div6[51 + 4 * 6 + 1] = {
1117 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3,
1118 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6,
1119 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10,
1120 10, 10, 11, 11, 11, 11, 11, 11, 12, 12
1121 };
1122 13588048 int qp_y = lc->qp_y;
1123
1124
2/2
✓ Branch 0 taken 10291427 times.
✓ Branch 1 taken 3296621 times.
13588048 if (pps->transform_skip_enabled_flag &&
1125
2/2
✓ Branch 0 taken 5689341 times.
✓ Branch 1 taken 4602086 times.
10291427 log2_trafo_size <= pps->log2_max_transform_skip_block_size) {
1126 5689341 transform_skip_flag = hevc_transform_skip_flag_decode(lc, c_idx);
1127 }
1128
1129
2/2
✓ Branch 0 taken 9616341 times.
✓ Branch 1 taken 3971707 times.
13588048 if (c_idx == 0) {
1130 9616341 qp = qp_y + sps->qp_bd_offset;
1131 } else {
1132 int qp_i, offset;
1133
1134
2/2
✓ Branch 0 taken 1907273 times.
✓ Branch 1 taken 2064434 times.
3971707 if (c_idx == 1)
1135 1907273 offset = pps->cb_qp_offset + s->sh.slice_cb_qp_offset +
1136 1907273 lc->tu.cu_qp_offset_cb;
1137 else
1138 2064434 offset = pps->cr_qp_offset + s->sh.slice_cr_qp_offset +
1139 2064434 lc->tu.cu_qp_offset_cr;
1140
1141 3971707 qp_i = av_clip(qp_y + offset, - sps->qp_bd_offset, 57);
1142
2/2
✓ Branch 0 taken 2575395 times.
✓ Branch 1 taken 1396312 times.
3971707 if (sps->chroma_format_idc == 1) {
1143
2/2
✓ Branch 0 taken 952042 times.
✓ Branch 1 taken 1623353 times.
2575395 if (qp_i < 30)
1144 952042 qp = qp_i;
1145
2/2
✓ Branch 0 taken 11213 times.
✓ Branch 1 taken 1612140 times.
1623353 else if (qp_i > 43)
1146 11213 qp = qp_i - 6;
1147 else
1148 1612140 qp = qp_c[qp_i - 30];
1149 } else {
1150
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1396312 times.
1396312 if (qp_i > 51)
1151 ✗ qp = 51;
1152 else
1153 1396312 qp = qp_i;
1154 }
1155
1156 3971707 qp += sps->qp_bd_offset;
1157 }
1158
1159 13588048 shift = sps->bit_depth + log2_trafo_size - 5;
1160 13588048 add = 1 << (shift-1);
1161 13588048 scale = level_scale[rem6[qp]] << (div6[qp]);
1162 13588048 scale_m = 16; // default when no custom scaling lists.
1163 13588048 dc_scale = 16;
1164
1165
6/6
✓ Branch 0 taken 613107 times.
✓ Branch 1 taken 12974941 times.
✓ Branch 2 taken 19500 times.
✓ Branch 3 taken 593607 times.
✓ Branch 4 taken 11407 times.
✓ Branch 5 taken 8093 times.
13588048 if (sps->scaling_list_enabled && !(transform_skip_flag && log2_trafo_size > 2)) {
1166 1210028 const ScalingList *sl = pps->scaling_list_data_present_flag ?
1167
2/2
✓ Branch 0 taken 347752 times.
✓ Branch 1 taken 257262 times.
605014 &pps->scaling_list : &sps->scaling_list;
1168 605014 int matrix_id = lc->cu.pred_mode != MODE_INTRA;
1169
1170 605014 matrix_id = 3 * matrix_id + c_idx;
1171
1172 605014 scale_matrix = sl->sl[log2_trafo_size - 2][matrix_id];
1173
2/2
✓ Branch 0 taken 112450 times.
✓ Branch 1 taken 492564 times.
605014 if (log2_trafo_size >= 4)
1174 112450 dc_scale = sl->sl_dc[log2_trafo_size - 4][matrix_id];
1175 }
1176 } else {
1177 420708 shift = 0;
1178 420708 add = 0;
1179 420708 scale = 0;
1180 420708 dc_scale = 0;
1181 }
1182
1183
6/6
✓ Branch 0 taken 5808386 times.
✓ Branch 1 taken 8200370 times.
✓ Branch 2 taken 225511 times.
✓ Branch 3 taken 5582875 times.
✓ Branch 4 taken 190277 times.
✓ Branch 5 taken 35234 times.
14008756 if (lc->cu.pred_mode == MODE_INTER && sps->explicit_rdpcm_enabled &&
1184
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 190277 times.
190277 (transform_skip_flag || lc->cu.cu_transquant_bypass_flag)) {
1185 35234 explicit_rdpcm_flag = explicit_rdpcm_flag_decode(lc, c_idx);
1186
2/2
✓ Branch 0 taken 3090 times.
✓ Branch 1 taken 32144 times.
35234 if (explicit_rdpcm_flag) {
1187 3090 explicit_rdpcm_dir_flag = explicit_rdpcm_dir_flag_decode(lc, c_idx);
1188 }
1189 }
1190
1191 14008756 last_significant_coeff_xy_prefix_decode(lc, c_idx, log2_trafo_size,
1192 &last_significant_coeff_x, &last_significant_coeff_y);
1193
1194
2/2
✓ Branch 0 taken 1831747 times.
✓ Branch 1 taken 12177009 times.
14008756 if (last_significant_coeff_x > 3) {
1195 1831747 int suffix = last_significant_coeff_suffix_decode(lc, last_significant_coeff_x);
1196 1831747 last_significant_coeff_x = (1 << ((last_significant_coeff_x >> 1) - 1)) *
1197 1831747 (2 + (last_significant_coeff_x & 1)) +
1198 suffix;
1199 }
1200
1201
2/2
✓ Branch 0 taken 1347837 times.
✓ Branch 1 taken 12660919 times.
14008756 if (last_significant_coeff_y > 3) {
1202 1347837 int suffix = last_significant_coeff_suffix_decode(lc, last_significant_coeff_y);
1203 1347837 last_significant_coeff_y = (1 << ((last_significant_coeff_y >> 1) - 1)) *
1204 1347837 (2 + (last_significant_coeff_y & 1)) +
1205 suffix;
1206 }
1207
1208
2/2
✓ Branch 0 taken 1497897 times.
✓ Branch 1 taken 12510859 times.
14008756 if (scan_idx == SCAN_VERT)
1209 1497897 FFSWAP(int, last_significant_coeff_x, last_significant_coeff_y);
1210
1211 14008756 x_cg_last_sig = last_significant_coeff_x >> 2;
1212 14008756 y_cg_last_sig = last_significant_coeff_y >> 2;
1213
1214
3/3
✓ Branch 0 taken 10715078 times.
✓ Branch 1 taken 1795781 times.
✓ Branch 2 taken 1497897 times.
14008756 switch (scan_idx) {
1215 10715078 case SCAN_DIAG: {
1216 10715078 int last_x_c = last_significant_coeff_x & 3;
1217 10715078 int last_y_c = last_significant_coeff_y & 3;
1218
1219 10715078 scan_x_off = ff_hevc_diag_scan4x4_x;
1220 10715078 scan_y_off = ff_hevc_diag_scan4x4_y;
1221 10715078 num_coeff = diag_scan4x4_inv[last_y_c][last_x_c];
1222
2/2
✓ Branch 0 taken 4842217 times.
✓ Branch 1 taken 5872861 times.
10715078 if (trafo_size == 4) {
1223 4842217 scan_x_cg = scan_1x1;
1224 4842217 scan_y_cg = scan_1x1;
1225
2/2
✓ Branch 0 taken 3020646 times.
✓ Branch 1 taken 2852215 times.
5872861 } else if (trafo_size == 8) {
1226 3020646 num_coeff += diag_scan2x2_inv[y_cg_last_sig][x_cg_last_sig] << 4;
1227 3020646 scan_x_cg = diag_scan2x2_x;
1228 3020646 scan_y_cg = diag_scan2x2_y;
1229
2/2
✓ Branch 0 taken 2065283 times.
✓ Branch 1 taken 786932 times.
2852215 } else if (trafo_size == 16) {
1230 2065283 num_coeff += diag_scan4x4_inv[y_cg_last_sig][x_cg_last_sig] << 4;
1231 2065283 scan_x_cg = ff_hevc_diag_scan4x4_x;
1232 2065283 scan_y_cg = ff_hevc_diag_scan4x4_y;
1233 } else { // trafo_size == 32
1234 786932 num_coeff += diag_scan8x8_inv[y_cg_last_sig][x_cg_last_sig] << 4;
1235 786932 scan_x_cg = ff_hevc_diag_scan8x8_x;
1236 786932 scan_y_cg = ff_hevc_diag_scan8x8_y;
1237 }
1238 10715078 break;
1239 }
1240 1795781 case SCAN_HORIZ:
1241 1795781 scan_x_cg = horiz_scan2x2_x;
1242 1795781 scan_y_cg = horiz_scan2x2_y;
1243 1795781 scan_x_off = horiz_scan4x4_x;
1244 1795781 scan_y_off = horiz_scan4x4_y;
1245 1795781 num_coeff = horiz_scan8x8_inv[last_significant_coeff_y][last_significant_coeff_x];
1246 1795781 break;
1247 1497897 default: //SCAN_VERT
1248 1497897 scan_x_cg = horiz_scan2x2_y;
1249 1497897 scan_y_cg = horiz_scan2x2_x;
1250 1497897 scan_x_off = horiz_scan4x4_y;
1251 1497897 scan_y_off = horiz_scan4x4_x;
1252 1497897 num_coeff = horiz_scan8x8_inv[last_significant_coeff_x][last_significant_coeff_y];
1253 1497897 break;
1254 }
1255 14008756 num_coeff++;
1256 14008756 num_last_subset = (num_coeff - 1) >> 4;
1257
1258 14008756 max_xy = FFMAX(last_significant_coeff_x, last_significant_coeff_y);
1259 14008756 col_limit = last_significant_coeff_x + last_significant_coeff_y + 4;
1260
2/2
✓ Branch 0 taken 11555141 times.
✓ Branch 1 taken 2453615 times.
14008756 if (max_xy < 4)
1261 11555141 col_limit = FFMIN(4, col_limit);
1262
2/2
✓ Branch 0 taken 1827188 times.
✓ Branch 1 taken 626427 times.
2453615 else if (max_xy < 8)
1263 1827188 col_limit = FFMIN(8, col_limit);
1264
2/2
✓ Branch 0 taken 286392 times.
✓ Branch 1 taken 340035 times.
626427 else if (max_xy < 12)
1265 286392 col_limit = FFMIN(24, col_limit);
1266
1267 // idct_dc reads coeffs[0] only and writes the whole block: no clear needed
1268 14008756 clear_rows = trafo_size;
1269
4/4
✓ Branch 0 taken 13588048 times.
✓ Branch 1 taken 420708 times.
✓ Branch 2 taken 13195410 times.
✓ Branch 3 taken 392638 times.
14008756 if (!lc->cu.cu_transquant_bypass_flag && !transform_skip_flag &&
1270
6/6
✓ Branch 0 taken 7782994 times.
✓ Branch 1 taken 5412416 times.
✓ Branch 2 taken 5471722 times.
✓ Branch 3 taken 2311272 times.
✓ Branch 4 taken 2343115 times.
✓ Branch 5 taken 3128607 times.
13195410 !(lc->cu.pred_mode == MODE_INTRA && c_idx == 0 && log2_trafo_size == 2)) {
1271
2/2
✓ Branch 0 taken 2455935 times.
✓ Branch 1 taken 7610868 times.
10066803 if (max_xy == 0)
1272 2455935 clear_rows = 0;
1273 }
1274
2/2
✓ Branch 0 taken 11552821 times.
✓ Branch 1 taken 2455935 times.
14008756 if (clear_rows)
1275 11552821 memset(coeffs, 0, clear_rows * trafo_size * sizeof(int16_t));
1276
1277
2/2
✓ Branch 0 taken 24803889 times.
✓ Branch 1 taken 14008756 times.
38812645 for (i = num_last_subset; i >= 0; i--) {
1278 int n, m;
1279 int x_cg, y_cg, x_c, y_c, pos;
1280 24803889 int implicit_non_zero_coeff = 0;
1281 int64_t trans_coeff_level;
1282 24803889 int prev_sig = 0;
1283 24803889 int offset = i << 4;
1284 24803889 int rice_init = 0;
1285
1286 uint8_t significant_coeff_flag_idx[16];
1287 24803889 uint8_t nb_significant_coeff_flag = 0;
1288
1289 24803889 x_cg = scan_x_cg[i];
1290 24803889 y_cg = scan_y_cg[i];
1291
1292
4/4
✓ Branch 0 taken 10795133 times.
✓ Branch 1 taken 14008756 times.
✓ Branch 2 taken 8341518 times.
✓ Branch 3 taken 2453615 times.
24803889 if ((i < num_last_subset) && (i > 0)) {
1293 8341518 int ctx_cg = 0;
1294
2/2
✓ Branch 0 taken 7671979 times.
✓ Branch 1 taken 669539 times.
8341518 if (x_cg < (1 << (log2_trafo_size - 2)) - 1)
1295 7671979 ctx_cg += significant_coeff_group_flag[x_cg + 1][y_cg];
1296
2/2
✓ Branch 0 taken 7066975 times.
✓ Branch 1 taken 1274543 times.
8341518 if (y_cg < (1 << (log2_trafo_size - 2)) - 1)
1297 7066975 ctx_cg += significant_coeff_group_flag[x_cg][y_cg + 1];
1298
1299 8341518 significant_coeff_group_flag[x_cg][y_cg] =
1300 8341518 significant_coeff_group_flag_decode(lc, c_idx, ctx_cg);
1301 8341518 implicit_non_zero_coeff = 1;
1302 } else {
1303 16462371 significant_coeff_group_flag[x_cg][y_cg] =
1304
5/6
✓ Branch 0 taken 14712842 times.
✓ Branch 1 taken 1749529 times.
✓ Branch 2 taken 704086 times.
✓ Branch 3 taken 14008756 times.
✓ Branch 4 taken 2453615 times.
✗ Branch 5 not taken.
18915986 ((x_cg == x_cg_last_sig && y_cg == y_cg_last_sig) ||
1305
1/2
✓ Branch 0 taken 2453615 times.
✗ Branch 1 not taken.
2453615 (x_cg == 0 && y_cg == 0));
1306 }
1307
1308 24803889 last_scan_pos = num_coeff - offset - 1;
1309
1310
2/2
✓ Branch 0 taken 14008756 times.
✓ Branch 1 taken 10795133 times.
24803889 if (i == num_last_subset) {
1311 14008756 n_end = last_scan_pos - 1;
1312 14008756 significant_coeff_flag_idx[0] = last_scan_pos;
1313 14008756 nb_significant_coeff_flag = 1;
1314 } else {
1315 10795133 n_end = 15;
1316 }
1317
1318
2/2
✓ Branch 0 taken 15829575 times.
✓ Branch 1 taken 8974314 times.
24803889 if (x_cg < ((1 << log2_trafo_size) - 1) >> 2)
1319 15829575 prev_sig = !!significant_coeff_group_flag[x_cg + 1][y_cg];
1320
2/2
✓ Branch 0 taken 15358188 times.
✓ Branch 1 taken 9445701 times.
24803889 if (y_cg < ((1 << log2_trafo_size) - 1) >> 2)
1321
2/2
✓ Branch 0 taken 5140631 times.
✓ Branch 1 taken 10217557 times.
15358188 prev_sig += (!!significant_coeff_group_flag[x_cg][y_cg + 1] << 1);
1322
1323
4/4
✓ Branch 0 taken 21573812 times.
✓ Branch 1 taken 3230077 times.
✓ Branch 2 taken 18159835 times.
✓ Branch 3 taken 3413977 times.
24803889 if (significant_coeff_group_flag[x_cg][y_cg] && n_end >= 0) {
1324 // ctx_idx_map composed with the intra-CG scan, indexed by scan position
1325 static const uint8_t ctx_idx_map[3][5 * 16] = {
1326 { // SCAN_DIAG
1327 0, 2, 1, 6, 3, 4, 7, 6, 4, 5, 7, 8, 5, 8, 8, 8, // log2_trafo_size == 2
1328 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // prev_sig == 0
1329 2, 1, 2, 0, 1, 2, 0, 0, 1, 2, 0, 0, 1, 0, 0, 0, // prev_sig == 1
1330 2, 2, 1, 2, 1, 0, 2, 1, 0, 0, 1, 0, 0, 0, 0, 0, // prev_sig == 2
1331 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, // default
1332 },
1333 { // SCAN_HORIZ
1334 0, 1, 4, 5, 2, 3, 4, 5, 6, 6, 8, 8, 7, 7, 8, 8,
1335 1, 1, 1, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0,
1336 2, 2, 2, 2, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0,
1337 2, 1, 0, 0, 2, 1, 0, 0, 2, 1, 0, 0, 2, 1, 0, 0,
1338 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1339 },
1340 { // SCAN_VERT
1341 0, 2, 6, 7, 1, 3, 6, 7, 4, 4, 8, 8, 5, 5, 8, 8,
1342 1, 1, 1, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0,
1343 2, 1, 0, 0, 2, 1, 0, 0, 2, 1, 0, 0, 2, 1, 0, 0,
1344 2, 2, 2, 2, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0,
1345 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1346 },
1347 };
1348 const uint8_t *ctx_idx_map_p;
1349 18159835 int scf_offset = 0;
1350 int nb0;
1351
4/4
✓ Branch 0 taken 687068 times.
✓ Branch 1 taken 17472767 times.
✓ Branch 2 taken 592618 times.
✓ Branch 3 taken 94450 times.
18159835 if (sps->transform_skip_context_enabled &&
1352
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 592618 times.
592618 (transform_skip_flag || lc->cu.cu_transquant_bypass_flag)) {
1353 94450 ctx_idx_map_p = &ctx_idx_map[scan_idx][4 * 16];
1354
2/2
✓ Branch 0 taken 41170 times.
✓ Branch 1 taken 53280 times.
94450 if (c_idx == 0) {
1355 41170 scf_offset = 40;
1356 } else {
1357 53280 scf_offset = 14 + 27;
1358 }
1359 } else {
1360
2/2
✓ Branch 0 taken 3799971 times.
✓ Branch 1 taken 14265414 times.
18065385 if (c_idx != 0)
1361 3799971 scf_offset = 27;
1362
2/2
✓ Branch 0 taken 5626577 times.
✓ Branch 1 taken 12438808 times.
18065385 if (log2_trafo_size == 2) {
1363 5626577 ctx_idx_map_p = &ctx_idx_map[scan_idx][0];
1364 } else {
1365 12438808 ctx_idx_map_p = &ctx_idx_map[scan_idx][(prev_sig + 1) << 4];
1366
2/2
✓ Branch 0 taken 10292564 times.
✓ Branch 1 taken 2146244 times.
12438808 if (c_idx == 0) {
1367
4/4
✓ Branch 0 taken 6341581 times.
✓ Branch 1 taken 3950983 times.
✓ Branch 2 taken 2085587 times.
✓ Branch 3 taken 4255994 times.
10292564 if ((x_cg > 0 || y_cg > 0))
1368 6036570 scf_offset += 3;
1369
2/2
✓ Branch 0 taken 3705801 times.
✓ Branch 1 taken 6586763 times.
10292564 if (log2_trafo_size == 3) {
1370
2/2
✓ Branch 0 taken 2723010 times.
✓ Branch 1 taken 982791 times.
3705801 scf_offset += (scan_idx == SCAN_DIAG) ? 9 : 15;
1371 } else {
1372 6586763 scf_offset += 21;
1373 }
1374 } else {
1375
2/2
✓ Branch 0 taken 995890 times.
✓ Branch 1 taken 1150354 times.
2146244 if (log2_trafo_size == 3)
1376 995890 scf_offset += 9;
1377 else
1378 1150354 scf_offset += 12;
1379 }
1380 }
1381 }
1382 // the flag is a fresh bin: store always, advance conditionally
1383 18159835 nb0 = nb_significant_coeff_flag;
1384
2/2
✓ Branch 0 taken 167750516 times.
✓ Branch 1 taken 18159835 times.
185910351 for (n = n_end; n > 0; n--) {
1385 167750516 int sig = significant_coeff_flag_decode(lc, n, scf_offset, ctx_idx_map_p);
1386 167750516 significant_coeff_flag_idx[nb_significant_coeff_flag] = n;
1387 167750516 nb_significant_coeff_flag += sig;
1388 }
1389
2/2
✓ Branch 0 taken 14625759 times.
✓ Branch 1 taken 3534076 times.
18159835 if (nb_significant_coeff_flag != nb0)
1390 14625759 implicit_non_zero_coeff = 0;
1391
2/2
✓ Branch 0 taken 18079255 times.
✓ Branch 1 taken 80580 times.
18159835 if (implicit_non_zero_coeff == 0) {
1392
4/4
✓ Branch 0 taken 685361 times.
✓ Branch 1 taken 17393894 times.
✓ Branch 2 taken 591196 times.
✓ Branch 3 taken 94165 times.
18079255 if (sps->transform_skip_context_enabled &&
1393
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 591196 times.
591196 (transform_skip_flag || lc->cu.cu_transquant_bypass_flag)) {
1394
2/2
✓ Branch 0 taken 40977 times.
✓ Branch 1 taken 53188 times.
94165 if (c_idx == 0) {
1395 40977 scf_offset = 42;
1396 } else {
1397 53188 scf_offset = 16 + 27;
1398 }
1399 } else {
1400
2/2
✓ Branch 0 taken 10874915 times.
✓ Branch 1 taken 7110175 times.
17985090 if (i == 0) {
1401
2/2
✓ Branch 0 taken 8228844 times.
✓ Branch 1 taken 2646071 times.
10874915 if (c_idx == 0)
1402 8228844 scf_offset = 0;
1403 else
1404 2646071 scf_offset = 27;
1405 } else {
1406 7110175 scf_offset = 2 + scf_offset;
1407 }
1408 }
1409 18079255 significant_coeff_flag_idx[nb_significant_coeff_flag] = 0;
1410 18079255 nb_significant_coeff_flag +=
1411 18079255 significant_coeff_flag_decode_0(lc, c_idx, scf_offset);
1412 } else {
1413 80580 significant_coeff_flag_idx[nb_significant_coeff_flag] = 0;
1414 80580 nb_significant_coeff_flag++;
1415 }
1416 }
1417
1418 24803889 n_end = nb_significant_coeff_flag;
1419
1420
1421
2/2
✓ Branch 0 taken 21452067 times.
✓ Branch 1 taken 3351822 times.
24803889 if (n_end) {
1422 int first_nz_pos_in_cg;
1423 int last_nz_pos_in_cg;
1424 21452067 int c_rice_param = 0;
1425 21452067 int first_greater1_coeff_idx = -1;
1426 uint8_t coeff_abs_level_greater1_flag[8];
1427 uint16_t coeff_sign_flag;
1428 21452067 int sum_abs = 0;
1429 int sign_hidden;
1430 int sb_type;
1431 21452067 int gt1_mask = 0;
1432
1433
1434 // initialize first elem of coeff_bas_level_greater1_flag
1435
4/4
✓ Branch 0 taken 7565056 times.
✓ Branch 1 taken 13887011 times.
✓ Branch 2 taken 6342827 times.
✓ Branch 3 taken 1222229 times.
21452067 int ctx_set = (i > 0 && c_idx == 0) ? 2 : 0;
1436
1437
2/2
✓ Branch 0 taken 769625 times.
✓ Branch 1 taken 20682442 times.
21452067 if (sps->persistent_rice_adaptation_enabled) {
1438
3/4
✓ Branch 0 taken 685062 times.
✓ Branch 1 taken 84563 times.
✓ Branch 2 taken 685062 times.
✗ Branch 3 not taken.
769625 if (!transform_skip_flag && !lc->cu.cu_transquant_bypass_flag)
1439
2/2
✓ Branch 0 taken 224053 times.
✓ Branch 1 taken 461009 times.
685062 sb_type = 2 * (c_idx == 0 ? 1 : 0);
1440 else
1441
2/2
✓ Branch 0 taken 36677 times.
✓ Branch 1 taken 47886 times.
84563 sb_type = 2 * (c_idx == 0 ? 1 : 0) + 1;
1442 769625 c_rice_param = lc->stat_coeff[sb_type] / 4;
1443 }
1444
1445
4/4
✓ Branch 0 taken 7443311 times.
✓ Branch 1 taken 14008756 times.
✓ Branch 2 taken 3064118 times.
✓ Branch 3 taken 4379193 times.
21452067 if (!(i == num_last_subset) && greater1_ctx == 0)
1446 3064118 ctx_set++;
1447 21452067 greater1_ctx = 1;
1448 21452067 last_nz_pos_in_cg = significant_coeff_flag_idx[0];
1449
1450 // fresh bins: branchless context update, first set index from the mask
1451
2/2
✓ Branch 0 taken 85806979 times.
✓ Branch 1 taken 21452067 times.
107259046 for (m = 0; m < (n_end > 8 ? 8 : n_end); m++) {
1452 85806979 int inc = (ctx_set << 2) + greater1_ctx;
1453 85806979 int flag = coeff_abs_level_greater1_flag_decode(lc, c_idx, inc);
1454 85806979 coeff_abs_level_greater1_flag[m] = flag;
1455 85806979 gt1_mask |= flag << m;
1456 85806979 greater1_ctx = (greater1_ctx + (greater1_ctx - 1U < 2)) & (flag - 1);
1457 }
1458
2/2
✓ Branch 0 taken 9336940 times.
✓ Branch 1 taken 12115127 times.
21452067 if (gt1_mask)
1459 9336940 first_greater1_coeff_idx = ff_ctz(gt1_mask);
1460 21452067 first_nz_pos_in_cg = significant_coeff_flag_idx[n_end - 1];
1461
1462
2/2
✓ Branch 0 taken 20737103 times.
✓ Branch 1 taken 714964 times.
21452067 if (lc->cu.cu_transquant_bypass_flag ||
1463
2/2
✓ Branch 0 taken 11400148 times.
✓ Branch 1 taken 9336955 times.
20737103 (lc->cu.pred_mode == MODE_INTRA &&
1464
6/6
✓ Branch 0 taken 505772 times.
✓ Branch 1 taken 10894376 times.
✓ Branch 2 taken 57405 times.
✓ Branch 3 taken 448367 times.
✓ Branch 4 taken 29611 times.
✓ Branch 5 taken 27794 times.
11400148 sps->implicit_rdpcm_enabled && transform_skip_flag &&
1465
4/4
✓ Branch 0 taken 16913 times.
✓ Branch 1 taken 12698 times.
✓ Branch 2 taken 5999 times.
✓ Branch 3 taken 20690612 times.
20709309 (pred_mode_intra == 10 || pred_mode_intra == 26 )) ||
1466 explicit_rdpcm_flag)
1467 761455 sign_hidden = 0;
1468 else
1469 20690612 sign_hidden = (last_nz_pos_in_cg - first_nz_pos_in_cg >= 4);
1470
1471
2/2
✓ Branch 0 taken 9336940 times.
✓ Branch 1 taken 12115127 times.
21452067 if (first_greater1_coeff_idx != -1) {
1472 9336940 coeff_abs_level_greater1_flag[first_greater1_coeff_idx] += coeff_abs_level_greater2_flag_decode(lc, c_idx, ctx_set);
1473 }
1474
4/4
✓ Branch 0 taken 17507855 times.
✓ Branch 1 taken 3944212 times.
✓ Branch 2 taken 7794410 times.
✓ Branch 3 taken 9713445 times.
21452067 if (!pps->sign_data_hiding_flag || !sign_hidden ) {
1475 11738622 coeff_sign_flag = coeff_sign_flag_decode(lc, nb_significant_coeff_flag) << (16 - nb_significant_coeff_flag);
1476 } else {
1477 9713445 coeff_sign_flag = coeff_sign_flag_decode(lc, nb_significant_coeff_flag - 1) << (16 - (nb_significant_coeff_flag - 1));
1478 }
1479
1480
2/2
✓ Branch 0 taken 101797333 times.
✓ Branch 1 taken 21452067 times.
123249400 for (m = 0; m < n_end; m++) {
1481 int64_t sign;
1482
1483 101797333 n = significant_coeff_flag_idx[m];
1484 101797333 GET_COORD(offset, n);
1485
2/2
✓ Branch 0 taken 85806979 times.
✓ Branch 1 taken 15990354 times.
101797333 if (m < 8) {
1486 85806979 trans_coeff_level = 1 + coeff_abs_level_greater1_flag[m];
1487
4/4
✓ Branch 0 taken 9336940 times.
✓ Branch 1 taken 76470039 times.
✓ Branch 2 taken 20803976 times.
✓ Branch 3 taken 65003003 times.
85806979 if (trans_coeff_level == ((m == first_greater1_coeff_idx) ? 3 : 2)) {
1488 20803976 int last_coeff_abs_level_remaining = coeff_abs_level_remaining_decode(lc, c_rice_param);
1489
1490 20803976 trans_coeff_level += last_coeff_abs_level_remaining;
1491
2/2
✓ Branch 0 taken 5262029 times.
✓ Branch 1 taken 15541947 times.
20803976 if (trans_coeff_level > (3 << c_rice_param))
1492
2/2
✓ Branch 0 taken 107884 times.
✓ Branch 1 taken 5154145 times.
5262029 c_rice_param = sps->persistent_rice_adaptation_enabled ? c_rice_param + 1 : FFMIN(c_rice_param + 1, 4);
1493
4/4
✓ Branch 0 taken 601790 times.
✓ Branch 1 taken 20202186 times.
✓ Branch 2 taken 182004 times.
✓ Branch 3 taken 419786 times.
20803976 if (sps->persistent_rice_adaptation_enabled && !rice_init) {
1494 182004 int c_rice_p_init = lc->stat_coeff[sb_type] / 4;
1495
2/2
✓ Branch 0 taken 20309 times.
✓ Branch 1 taken 161695 times.
182004 if (last_coeff_abs_level_remaining >= (3 << c_rice_p_init))
1496 20309 lc->stat_coeff[sb_type]++;
1497
2/2
✓ Branch 0 taken 93774 times.
✓ Branch 1 taken 67921 times.
161695 else if (2 * last_coeff_abs_level_remaining < (1 << c_rice_p_init))
1498
2/2
✓ Branch 0 taken 20285 times.
✓ Branch 1 taken 73489 times.
93774 if (lc->stat_coeff[sb_type] > 0)
1499 20285 lc->stat_coeff[sb_type]--;
1500 182004 rice_init = 1;
1501 }
1502 }
1503 } else {
1504 15990354 int last_coeff_abs_level_remaining = coeff_abs_level_remaining_decode(lc, c_rice_param);
1505
1506 15990354 trans_coeff_level = 1 + last_coeff_abs_level_remaining;
1507
2/2
✓ Branch 0 taken 1826958 times.
✓ Branch 1 taken 14163396 times.
15990354 if (trans_coeff_level > (3 << c_rice_param))
1508
2/2
✓ Branch 0 taken 47948 times.
✓ Branch 1 taken 1779010 times.
1826958 c_rice_param = sps->persistent_rice_adaptation_enabled ? c_rice_param + 1 : FFMIN(c_rice_param + 1, 4);
1509
4/4
✓ Branch 0 taken 495525 times.
✓ Branch 1 taken 15494829 times.
✓ Branch 2 taken 22670 times.
✓ Branch 3 taken 472855 times.
15990354 if (sps->persistent_rice_adaptation_enabled && !rice_init) {
1510 22670 int c_rice_p_init = lc->stat_coeff[sb_type] / 4;
1511
2/2
✓ Branch 0 taken 785 times.
✓ Branch 1 taken 21885 times.
22670 if (last_coeff_abs_level_remaining >= (3 << c_rice_p_init))
1512 785 lc->stat_coeff[sb_type]++;
1513
2/2
✓ Branch 0 taken 15387 times.
✓ Branch 1 taken 6498 times.
21885 else if (2 * last_coeff_abs_level_remaining < (1 << c_rice_p_init))
1514
2/2
✓ Branch 0 taken 744 times.
✓ Branch 1 taken 14643 times.
15387 if (lc->stat_coeff[sb_type] > 0)
1515 744 lc->stat_coeff[sb_type]--;
1516 22670 rice_init = 1;
1517 }
1518 }
1519
4/4
✓ Branch 0 taken 90650668 times.
✓ Branch 1 taken 11146665 times.
✓ Branch 2 taken 69807660 times.
✓ Branch 3 taken 20843008 times.
101797333 if (pps->sign_data_hiding_flag && sign_hidden) {
1520 69807660 sum_abs += trans_coeff_level;
1521
4/4
✓ Branch 0 taken 9713445 times.
✓ Branch 1 taken 60094215 times.
✓ Branch 2 taken 4839491 times.
✓ Branch 3 taken 4873954 times.
69807660 if (n == first_nz_pos_in_cg && (sum_abs&1))
1522 4839491 trans_coeff_level = -trans_coeff_level;
1523 }
1524 // equiprobable sign: apply it branchless
1525 101797333 sign = -(int64_t)(coeff_sign_flag >> 15);
1526 101797333 trans_coeff_level = (trans_coeff_level ^ sign) - sign;
1527 101797333 coeff_sign_flag <<= 1;
1528
2/2
✓ Branch 0 taken 93019486 times.
✓ Branch 1 taken 8777847 times.
101797333 if(!lc->cu.cu_transquant_bypass_flag) {
1529
6/6
✓ Branch 0 taken 3256495 times.
✓ Branch 1 taken 89762991 times.
✓ Branch 2 taken 124715 times.
✓ Branch 3 taken 3131780 times.
✓ Branch 4 taken 25373 times.
✓ Branch 5 taken 99342 times.
93019486 if (sps->scaling_list_enabled && !(transform_skip_flag && log2_trafo_size > 2)) {
1530
6/6
✓ Branch 0 taken 1014069 times.
✓ Branch 1 taken 2143084 times.
✓ Branch 2 taken 456467 times.
✓ Branch 3 taken 557602 times.
✓ Branch 4 taken 372832 times.
✓ Branch 5 taken 83635 times.
3157153 if(y_c || x_c || log2_trafo_size < 4) {
1531
4/4
✓ Branch 0 taken 731538 times.
✓ Branch 1 taken 926236 times.
✓ Branch 2 taken 413079 times.
✓ Branch 3 taken 1002665 times.
3073518 switch(log2_trafo_size) {
1532 731538 case 3: pos = (y_c << 3) + x_c; break;
1533 926236 case 4: pos = ((y_c >> 1) << 3) + (x_c >> 1); break;
1534 413079 case 5: pos = ((y_c >> 2) << 3) + (x_c >> 2); break;
1535 1002665 default: pos = (y_c << 2) + x_c; break;
1536 }
1537 3073518 scale_m = scale_matrix[pos];
1538 } else {
1539 83635 scale_m = dc_scale;
1540 }
1541 }
1542 93019486 trans_coeff_level = (trans_coeff_level * (int64_t)scale * (int64_t)scale_m + add) >> shift;
1543 93019486 trans_coeff_level = FFMAX(FFMIN(trans_coeff_level, 32767), -32768);
1544 }
1545 101797333 coeffs[y_c * trafo_size + x_c] = trans_coeff_level;
1546 }
1547 }
1548 }
1549
1550
2/2
✓ Branch 0 taken 420708 times.
✓ Branch 1 taken 13588048 times.
14008756 if (lc->cu.cu_transquant_bypass_flag) {
1551
2/6
✓ Branch 0 taken 420708 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 420708 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
420708 if (explicit_rdpcm_flag || (sps->implicit_rdpcm_enabled &&
1552 ✗ (pred_mode_intra == 10 || pred_mode_intra == 26))) {
1553 ✗ int mode = sps->implicit_rdpcm_enabled ? (pred_mode_intra == 26) : explicit_rdpcm_dir_flag;
1554
1555 ✗ s->hevcdsp.transform_rdpcm(coeffs, log2_trafo_size, mode);
1556 }
1557 } else {
1558
2/2
✓ Branch 0 taken 392638 times.
✓ Branch 1 taken 13195410 times.
13588048 if (transform_skip_flag) {
1559
2/2
✓ Branch 0 taken 45633 times.
✓ Branch 1 taken 14213 times.
59846 int rot = sps->transform_skip_rotation_enabled &&
1560
2/2
✓ Branch 0 taken 59846 times.
✓ Branch 1 taken 332792 times.
452484 log2_trafo_size == 2 &&
1561
2/2
✓ Branch 0 taken 11850 times.
✓ Branch 1 taken 33783 times.
45633 lc->cu.pred_mode == MODE_INTRA;
1562
2/2
✓ Branch 0 taken 11850 times.
✓ Branch 1 taken 380788 times.
392638 if (rot) {
1563
2/2
✓ Branch 0 taken 94800 times.
✓ Branch 1 taken 11850 times.
106650 for (i = 0; i < 8; i++)
1564 94800 FFSWAP(int16_t, coeffs[i], coeffs[16 - i - 1]);
1565 }
1566
1567 392638 s->hevcdsp.dequant(coeffs, log2_trafo_size);
1568
1569
4/4
✓ Branch 0 taken 389548 times.
✓ Branch 1 taken 3090 times.
✓ Branch 2 taken 56756 times.
✓ Branch 3 taken 332792 times.
392638 if (explicit_rdpcm_flag || (sps->implicit_rdpcm_enabled &&
1570
4/4
✓ Branch 0 taken 24612 times.
✓ Branch 1 taken 32144 times.
✓ Branch 2 taken 15060 times.
✓ Branch 3 taken 9552 times.
56756 lc->cu.pred_mode == MODE_INTRA &&
1571
2/2
✓ Branch 0 taken 5302 times.
✓ Branch 1 taken 9758 times.
15060 (pred_mode_intra == 10 || pred_mode_intra == 26))) {
1572
2/2
✓ Branch 0 taken 14854 times.
✓ Branch 1 taken 3090 times.
17944 int mode = explicit_rdpcm_flag ? explicit_rdpcm_dir_flag : (pred_mode_intra == 26);
1573
1574 17944 s->hevcdsp.transform_rdpcm(coeffs, log2_trafo_size, mode);
1575 }
1576
6/6
✓ Branch 0 taken 7782994 times.
✓ Branch 1 taken 5412416 times.
✓ Branch 2 taken 5471722 times.
✓ Branch 3 taken 2311272 times.
✓ Branch 4 taken 3128607 times.
✓ Branch 5 taken 2343115 times.
13195410 } else if (lc->cu.pred_mode == MODE_INTRA && c_idx == 0 && log2_trafo_size == 2) {
1577 3128607 s->hevcdsp.transform_4x4_luma(coeffs);
1578 } else {
1579
2/2
✓ Branch 0 taken 2455935 times.
✓ Branch 1 taken 7610868 times.
10066803 if (max_xy == 0)
1580 2455935 s->hevcdsp.idct_dc[log2_trafo_size - 2](coeffs);
1581 else
1582 7610868 s->hevcdsp.idct[log2_trafo_size - 2](coeffs, col_limit);
1583 }
1584 }
1585
2/2
✓ Branch 0 taken 171429 times.
✓ Branch 1 taken 13837327 times.
14008756 if (lc->tu.cross_pf) {
1586 171429 int16_t *coeffs_y = (int16_t*)lc->edge_emu_buffer;
1587
1588
2/2
✓ Branch 0 taken 13540080 times.
✓ Branch 1 taken 171429 times.
13711509 for (i = 0; i < (trafo_size * trafo_size); i++) {
1589 13540080 coeffs[i] = coeffs[i] + ((lc->tu.res_scale_val * coeffs_y[i]) >> 3);
1590 }
1591 }
1592 14008756 s->hevcdsp.add_residual[log2_trafo_size-2](dst, coeffs, stride);
1593 14008756 }
1594
1595 3186280 void ff_hevc_hls_mvd_coding(HEVCLocalContext *lc, int x0, int y0, int log2_cb_size)
1596 {
1597 3186280 int x = abs_mvd_greater0_flag_decode(lc);
1598 3186280 int y = abs_mvd_greater0_flag_decode(lc);
1599
1600
2/2
✓ Branch 0 taken 2224593 times.
✓ Branch 1 taken 961687 times.
3186280 if (x)
1601 2224593 x += abs_mvd_greater1_flag_decode(lc);
1602
2/2
✓ Branch 0 taken 2136694 times.
✓ Branch 1 taken 1049586 times.
3186280 if (y)
1603 2136694 y += abs_mvd_greater1_flag_decode(lc);
1604
1605
3/4
✓ Branch 0 taken 1575449 times.
✓ Branch 1 taken 649144 times.
✓ Branch 2 taken 961687 times.
✗ Branch 3 not taken.
3186280 switch (x) {
1606 1575449 case 2: lc->pu.mvd.x = mvd_decode(lc); break;
1607 649144 case 1: lc->pu.mvd.x = mvd_sign_flag_decode(lc); break;
1608 961687 case 0: lc->pu.mvd.x = 0; break;
1609 }
1610
1611
3/4
✓ Branch 0 taken 1472643 times.
✓ Branch 1 taken 664051 times.
✓ Branch 2 taken 1049586 times.
✗ Branch 3 not taken.
3186280 switch (y) {
1612 1472643 case 2: lc->pu.mvd.y = mvd_decode(lc); break;
1613 664051 case 1: lc->pu.mvd.y = mvd_sign_flag_decode(lc); break;
1614 1049586 case 0: lc->pu.mvd.y = 0; break;
1615 }
1616 3186280 }
1617