../../../ffmpeg/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
689 / 716
96.2%
Branches:
514 / 553
92.9%
Functions:
57 / 58
98.3%

libavcodec/hevc/cabac.c
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 2044225 void ff_hevc_save_states(HEVCLocalContext *lc, const HEVCPPS *pps,
403 int ctb_addr_ts)
404 {
405 2044225 const HEVCSPS *const sps = pps->sps;
406
2/2
✓ Branch 2 → 3 taken 168556 times.
✓ Branch 2 → 8 taken 1875669 times.
2044225 if (pps->entropy_coding_sync_enabled_flag &&
407
2/2
✓ Branch 3 → 4 taken 161382 times.
✓ Branch 3 → 6 taken 7174 times.
168556 (ctb_addr_ts % sps->ctb_width == 2 ||
408
2/2
✓ Branch 4 → 5 taken 768 times.
✓ Branch 4 → 8 taken 160614 times.
161382 (sps->ctb_width == 2 &&
409
2/2
✓ Branch 5 → 6 taken 384 times.
✓ Branch 5 → 8 taken 384 times.
768 ctb_addr_ts % sps->ctb_width == 0))) {
410 7558 memcpy(lc->common_cabac_state->state, lc->sub.cabac_state, HEVC_CONTEXTS);
411
2/2
✓ Branch 6 → 7 taken 36 times.
✓ Branch 6 → 8 taken 7522 times.
7558 if (sps->persistent_rice_adaptation_enabled) {
412 36 memcpy(lc->common_cabac_state->stat_coeff, lc->sub.stat_coeff, HEVC_STAT_COEFFS);
413 }
414 }
415 2044225 }
416
417 6283 static void load_states(HEVCLocalContext *lc, const HEVCSPS *sps)
418 {
419 6283 memcpy(lc->sub.cabac_state, lc->common_cabac_state->state, HEVC_CONTEXTS);
420
2/2
✓ Branch 2 → 3 taken 33 times.
✓ Branch 2 → 4 taken 6250 times.
6283 if (sps->persistent_rice_adaptation_enabled) {
421 33 memcpy(lc->sub.stat_coeff, lc->common_cabac_state->stat_coeff, HEVC_STAT_COEFFS);
422 }
423 6283 }
424
425 10886 static int cabac_reinit(HEVCLocalContext *lc)
426 {
427
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 10886 times.
10886 return skip_bytes(&lc->sub.cc, 0) == NULL ? AVERROR_INVALIDDATA : 0;
428 }
429
430 33514 static void cabac_init_state(HEVCLocalContext *lc, const HEVCContext *s)
431 {
432 33514 int init_type = 2 - lc->sh->slice_type;
433 int i;
434
435
4/4
✓ Branch 2 → 3 taken 6681 times.
✓ Branch 2 → 5 taken 26833 times.
✓ Branch 3 → 4 taken 6503 times.
✓ Branch 3 → 5 taken 178 times.
33514 if (lc->sh->cabac_init_flag && lc->sh->slice_type != HEVC_SLICE_I)
436 6503 init_type ^= 3;
437
438
2/2
✓ Branch 9 → 6 taken 6669286 times.
✓ Branch 9 → 10 taken 33514 times.
6702800 for (i = 0; i < HEVC_CONTEXTS; i++) {
439 6669286 int init_value = init_values[init_type][i];
440 6669286 int m = (init_value >> 4) * 5 - 45;
441 6669286 int n = ((init_value & 15) << 3) - 16;
442 6669286 int pre = 2 * (((m * av_clip(lc->sh->slice_qp, 0, 51)) >> 4) + n) - 127;
443
444 6669286 pre ^= pre >> 31;
445
2/2
✓ Branch 6 → 7 taken 681723 times.
✓ Branch 6 → 8 taken 5987563 times.
6669286 if (pre > 124)
446 681723 pre = 124 + (pre & 1);
447 6669286 lc->sub.cabac_state[i] = pre;
448 }
449
450
2/2
✓ Branch 12 → 11 taken 134056 times.
✓ Branch 12 → 13 taken 33514 times.
167570 for (i = 0; i < 4; i++)
451 134056 lc->sub.stat_coeff[i] = 0;
452 33514 }
453
454 /* Open CABAC on this substream's data, or continue byte-aligned in it if it
455 * is already open (one slice read from a single buffer). */
456 15974 static int substream_continue(HEVCLocalContext *lc)
457 {
458 15974 HEVCSubstream *const sub = &lc->sub;
459 int ret;
460
461
2/2
✓ Branch 2 → 3 taken 10886 times.
✓ Branch 2 → 5 taken 5088 times.
15974 if (sub->opened)
462 10886 return cabac_reinit(lc);
463
464 5088 ret = ff_init_cabac_decoder(&sub->cc, sub->data, sub->size);
465
1/2
✗ Branch 6 → 7 not taken.
✓ Branch 6 → 8 taken 5088 times.
5088 if (ret < 0)
466 ✗ return ret;
467 5088 sub->opened = 1;
468
469 5088 return 0;
470 }
471
472 2096786 int ff_hevc_cabac_init(HEVCLocalContext *lc, const HEVCPPS *pps,
473 int ctb_addr_ts)
474 {
475 2096786 const HEVCContext *const s = lc->parent;
476 2096786 const HEVCSPS *const sps = pps->sps;
477 2096786 HEVCSubstream *const sub = &lc->sub;
478
479
2/2
✓ Branch 2 → 3 taken 30081 times.
✓ Branch 2 → 17 taken 2066705 times.
2096786 if (ctb_addr_ts == pps->ctb_addr_rs_to_ts[lc->sh->slice_ctb_addr_rs]) {
480 /* First CTB of a slice segment. For a dependent slice segment the
481 * data still belongs to the new segment. */
482 30081 int ret = ff_init_cabac_decoder(&sub->cc, sub->data, sub->size);
483
1/2
✗ Branch 4 → 5 not taken.
✓ Branch 4 → 6 taken 30081 times.
30081 if (ret < 0)
484 ✗ return ret;
485 30081 sub->opened = 1;
486
2/2
✓ Branch 6 → 7 taken 7794 times.
✓ Branch 6 → 9 taken 22287 times.
30081 if (lc->sh->dependent_slice_segment_flag == 0 ||
487
2/2
✓ Branch 7 → 8 taken 844 times.
✓ Branch 7 → 10 taken 6950 times.
7794 (pps->tiles_enabled_flag &&
488
2/2
✓ Branch 8 → 9 taken 298 times.
✓ Branch 8 → 10 taken 546 times.
844 pps->tile_id[ctb_addr_ts] != pps->tile_id[ctb_addr_ts - 1]))
489 22585 cabac_init_state(lc, s);
490
491
2/2
✓ Branch 10 → 11 taken 19381 times.
✓ Branch 10 → 33 taken 10700 times.
30081 if (!lc->sh->first_slice_in_pic_flag &&
492
2/2
✓ Branch 11 → 12 taken 3820 times.
✓ Branch 11 → 33 taken 15561 times.
19381 pps->entropy_coding_sync_enabled_flag) {
493
2/2
✓ Branch 12 → 13 taken 1620 times.
✓ Branch 12 → 33 taken 2200 times.
3820 if (ctb_addr_ts % sps->ctb_width == 0) {
494
2/2
✓ Branch 13 → 14 taken 92 times.
✓ Branch 13 → 15 taken 1528 times.
1620 if (sps->ctb_width == 1)
495 92 cabac_init_state(lc, s);
496
2/2
✓ Branch 15 → 16 taken 1146 times.
✓ Branch 15 → 33 taken 382 times.
1528 else if (lc->sh->dependent_slice_segment_flag == 1)
497 1146 load_states(lc, sps);
498 }
499 }
500 } else {
501
2/2
✓ Branch 17 → 18 taken 805264 times.
✓ Branch 17 → 23 taken 1261441 times.
2066705 if (pps->tiles_enabled_flag &&
502
2/2
✓ Branch 18 → 19 taken 10641 times.
✓ Branch 18 → 23 taken 794623 times.
805264 pps->tile_id[ctb_addr_ts] != pps->tile_id[ctb_addr_ts - 1]) {
503 10641 int ret = substream_continue(lc);
504
1/2
✗ Branch 20 → 21 not taken.
✓ Branch 20 → 22 taken 10641 times.
10641 if (ret < 0)
505 ✗ return ret;
506 10641 cabac_init_state(lc, s);
507 }
508
2/2
✓ Branch 23 → 24 taken 163747 times.
✓ Branch 23 → 33 taken 1902958 times.
2066705 if (pps->entropy_coding_sync_enabled_flag) {
509
2/2
✓ Branch 24 → 25 taken 5333 times.
✓ Branch 24 → 33 taken 158414 times.
163747 if (ctb_addr_ts % sps->ctb_width == 0) {
510 int ret;
511 /* The end of row terminate bit is read only when continuing */
512
1/2
✓ Branch 25 → 26 taken 5333 times.
✗ Branch 25 → 27 not taken.
5333 if (sub->opened)
513 5333 get_cabac_terminate(&sub->cc);
514 5333 ret = substream_continue(lc);
515
1/2
✗ Branch 28 → 29 not taken.
✓ Branch 28 → 30 taken 5333 times.
5333 if (ret < 0)
516 ✗ return ret;
517
518
2/2
✓ Branch 30 → 31 taken 196 times.
✓ Branch 30 → 32 taken 5137 times.
5333 if (sps->ctb_width == 1)
519 196 cabac_init_state(lc, s);
520 else
521 5137 load_states(lc, sps);
522 }
523 }
524 }
525 2096786 return 0;
526 }
527
528 #define GET_CABAC(ctx) get_cabac(&lc->sub.cc, &lc->sub.cabac_state[ctx])
529
530 1430254 int ff_hevc_sao_merge_flag_decode(HEVCLocalContext *lc)
531 {
532 1430254 return GET_CABAC(SAO_MERGE_FLAG_OFFSET);
533 }
534
535 561241 int ff_hevc_sao_type_idx_decode(HEVCLocalContext *lc)
536 {
537
2/2
✓ Branch 3 → 4 taken 390750 times.
✓ Branch 3 → 5 taken 170491 times.
561241 if (!GET_CABAC(SAO_TYPE_IDX_OFFSET))
538 390750 return 0;
539
540
2/2
✓ Branch 6 → 7 taken 50549 times.
✓ Branch 6 → 8 taken 119942 times.
170491 if (!get_cabac_bypass(&lc->sub.cc))
541 50549 return SAO_BAND;
542 119942 return SAO_EDGE;
543 }
544
545 72038 int ff_hevc_sao_band_position_decode(HEVCLocalContext *lc)
546 {
547 int i;
548 72038 int value = get_cabac_bypass(&lc->sub.cc);
549
550
2/2
✓ Branch 6 → 4 taken 288152 times.
✓ Branch 6 → 7 taken 72038 times.
360190 for (i = 0; i < 4; i++)
551 288152 value = (value << 1) | get_cabac_bypass(&lc->sub.cc);
552 72038 return value;
553 }
554
555 875768 int ff_hevc_sao_offset_abs_decode(HEVCLocalContext *lc, int bit_depth)
556 {
557 875768 int i = 0;
558 875768 int length = (1 << (FFMIN(bit_depth, 10) - 5)) - 1;
559
560
4/4
✓ Branch 4 → 5 taken 2410063 times.
✓ Branch 4 → 7 taken 118188 times.
✓ Branch 6 → 3 taken 1652483 times.
✓ Branch 6 → 7 taken 757580 times.
2528251 while (i < length && get_cabac_bypass(&lc->sub.cc))
561 1652483 i++;
562 875768 return i;
563 }
564
565 223924 int ff_hevc_sao_offset_sign_decode(HEVCLocalContext *lc)
566 {
567 223924 return get_cabac_bypass(&lc->sub.cc);
568 }
569
570 119942 int ff_hevc_sao_eo_class_decode(HEVCLocalContext *lc)
571 {
572 119942 int ret = get_cabac_bypass(&lc->sub.cc) << 1;
573 119942 ret |= get_cabac_bypass(&lc->sub.cc);
574 119942 return ret;
575 }
576
577 2096785 int ff_hevc_end_of_slice_flag_decode(HEVCLocalContext *lc)
578 {
579 2096785 return get_cabac_terminate(&lc->sub.cc);
580 }
581
582 180080 int ff_hevc_cu_transquant_bypass_flag_decode(HEVCLocalContext *lc)
583 {
584 180080 return GET_CABAC(CU_TRANSQUANT_BYPASS_FLAG_OFFSET);
585 }
586
587 10722676 int ff_hevc_skip_flag_decode(HEVCLocalContext *lc, uint8_t *skip_flag,
588 int x0, int y0, int x_cb, int y_cb, int min_cb_width)
589 {
590 10722676 int inc = 0;
591
592
4/4
✓ Branch 2 → 3 taken 969903 times.
✓ Branch 2 → 4 taken 9752773 times.
✓ Branch 3 → 4 taken 677501 times.
✓ Branch 3 → 5 taken 292402 times.
10722676 if (lc->ctb_left_flag || x0)
593 10430274 inc = !!SAMPLE_CTB(skip_flag, x_cb - 1, y_cb);
594
4/4
✓ Branch 5 → 6 taken 2020657 times.
✓ Branch 5 → 7 taken 8702019 times.
✓ Branch 6 → 7 taken 1452967 times.
✓ Branch 6 → 8 taken 567690 times.
10722676 if (lc->ctb_up_flag || y0)
595 10154986 inc += !!SAMPLE_CTB(skip_flag, x_cb, y_cb - 1);
596
597 10722676 return GET_CABAC(SKIP_FLAG_OFFSET + inc);
598 }
599
600 920312 int ff_hevc_cu_qp_delta_abs(HEVCLocalContext *lc)
601 {
602 920312 int prefix_val = 0;
603 920312 int suffix_val = 0;
604 920312 int inc = 0;
605
606
4/4
✓ Branch 4 → 5 taken 2062387 times.
✓ Branch 4 → 7 taken 141978 times.
✓ Branch 6 → 3 taken 1284053 times.
✓ Branch 6 → 7 taken 778334 times.
2204365 while (prefix_val < 5 && GET_CABAC(CU_QP_DELTA_OFFSET + inc)) {
607 1284053 prefix_val++;
608 1284053 inc = 1;
609 }
610
2/2
✓ Branch 7 → 8 taken 141978 times.
✓ Branch 7 → 20 taken 778334 times.
920312 if (prefix_val >= 5) {
611 141978 int k = 0;
612
3/4
✓ Branch 10 → 11 taken 438128 times.
✗ Branch 10 → 13 not taken.
✓ Branch 12 → 9 taken 296150 times.
✓ Branch 12 → 13 taken 141978 times.
438128 while (k < 7 && get_cabac_bypass(&lc->sub.cc)) {
613 296150 suffix_val += 1 << k;
614 296150 k++;
615 }
616
1/2
✗ Branch 13 → 14 not taken.
✓ Branch 13 → 16 taken 141978 times.
141978 if (k == 7) {
617 ✗ av_log(lc->logctx, AV_LOG_ERROR, "CABAC_MAX_BIN : %d\n", k);
618 ✗ return AVERROR_INVALIDDATA;
619 }
620
621
2/2
✓ Branch 19 → 17 taken 296150 times.
✓ Branch 19 → 20 taken 141978 times.
438128 while (k--)
622 296150 suffix_val += get_cabac_bypass(&lc->sub.cc) << k;
623 }
624 920312 return prefix_val + suffix_val;
625 }
626
627 485098 int ff_hevc_cu_qp_delta_sign_flag(HEVCLocalContext *lc)
628 {
629 485098 return get_cabac_bypass(&lc->sub.cc);
630 }
631
632 228078 int ff_hevc_cu_chroma_qp_offset_flag(HEVCLocalContext *lc)
633 {
634 228078 return GET_CABAC(CU_CHROMA_QP_OFFSET_FLAG_OFFSET);
635 }
636
637 ✗ int ff_hevc_cu_chroma_qp_offset_idx(HEVCLocalContext *lc, int chroma_qp_offset_list_len_minus1)
638 {
639 ✗ int c_max= FFMAX(5, chroma_qp_offset_list_len_minus1);
640 ✗ int i = 0;
641
642
0/4
✗ Branch 4 → 5 not taken.
✗ Branch 4 → 7 not taken.
✗ Branch 6 → 3 not taken.
✗ Branch 6 → 7 not taken.
✗ while (i < c_max && GET_CABAC(CU_CHROMA_QP_OFFSET_IDX_OFFSET))
643 ✗ i++;
644
645 ✗ return i;
646 }
647
648 5581896 int ff_hevc_pred_mode_decode(HEVCLocalContext *lc)
649 {
650 5581896 return GET_CABAC(PRED_MODE_FLAG_OFFSET);
651 }
652
653 9482901 int ff_hevc_split_coding_unit_flag_decode(HEVCLocalContext *lc, uint8_t *tab_ct_depth,
654 const HEVCSPS *sps,
655 int ct_depth, int x0, int y0)
656 {
657 9482901 int inc = 0, depth_left = 0, depth_top = 0;
658 9482901 int x0b = av_zero_extend(x0, sps->log2_ctb_size);
659 9482901 int y0b = av_zero_extend(y0, sps->log2_ctb_size);
660 9482901 int x_cb = x0 >> sps->log2_min_cb_size;
661 9482901 int y_cb = y0 >> sps->log2_min_cb_size;
662
663
4/4
✓ Branch 2 → 3 taken 864837 times.
✓ Branch 2 → 4 taken 8618064 times.
✓ Branch 3 → 4 taken 469162 times.
✓ Branch 3 → 5 taken 395675 times.
9482901 if (lc->ctb_left_flag || x0b)
664 9087226 depth_left = tab_ct_depth[(y_cb) * sps->min_cb_width + x_cb - 1];
665
4/4
✓ Branch 5 → 6 taken 1733373 times.
✓ Branch 5 → 7 taken 7749528 times.
✓ Branch 6 → 7 taken 953263 times.
✓ Branch 6 → 8 taken 780110 times.
9482901 if (lc->ctb_up_flag || y0b)
666 8702791 depth_top = tab_ct_depth[(y_cb - 1) * sps->min_cb_width + x_cb];
667
668 9482901 inc += (depth_left > ct_depth);
669 9482901 inc += (depth_top > ct_depth);
670
671 9482901 return GET_CABAC(SPLIT_CODING_UNIT_FLAG_OFFSET + inc);
672 }
673
674 7103755 int ff_hevc_part_mode_decode(HEVCLocalContext *lc, const HEVCSPS *sps, int log2_cb_size)
675 {
676
2/2
✓ Branch 3 → 4 taken 4471903 times.
✓ Branch 3 → 5 taken 2631852 times.
7103755 if (GET_CABAC(PART_MODE_OFFSET)) // 1
677 4471903 return PART_2Nx2N;
678
2/2
✓ Branch 5 → 6 taken 1845642 times.
✓ Branch 5 → 17 taken 786210 times.
2631852 if (log2_cb_size == sps->log2_min_cb_size) {
679
2/2
✓ Branch 6 → 7 taken 1070260 times.
✓ Branch 6 → 8 taken 775382 times.
1845642 if (lc->cu.pred_mode == MODE_INTRA) // 0
680 1070260 return PART_NxN;
681
2/2
✓ Branch 9 → 10 taken 317827 times.
✓ Branch 9 → 11 taken 457555 times.
775382 if (GET_CABAC(PART_MODE_OFFSET + 1)) // 01
682 317827 return PART_2NxN;
683
2/2
✓ Branch 11 → 12 taken 233413 times.
✓ Branch 11 → 13 taken 224142 times.
457555 if (log2_cb_size == 3) // 00
684 233413 return PART_Nx2N;
685
2/2
✓ Branch 14 → 15 taken 115987 times.
✓ Branch 14 → 16 taken 108155 times.
224142 if (GET_CABAC(PART_MODE_OFFSET + 2)) // 001
686 115987 return PART_Nx2N;
687 108155 return PART_NxN; // 000
688 }
689
690
2/2
✓ Branch 17 → 18 taken 180593 times.
✓ Branch 17 → 22 taken 605617 times.
786210 if (!sps->amp_enabled) {
691
2/2
✓ Branch 19 → 20 taken 88775 times.
✓ Branch 19 → 21 taken 91818 times.
180593 if (GET_CABAC(PART_MODE_OFFSET + 1)) // 01
692 88775 return PART_2NxN;
693 91818 return PART_Nx2N;
694 }
695
696
2/2
✓ Branch 23 → 24 taken 241563 times.
✓ Branch 23 → 31 taken 364054 times.
605617 if (GET_CABAC(PART_MODE_OFFSET + 1)) { // 01X, 01XX
697
2/2
✓ Branch 25 → 26 taken 115990 times.
✓ Branch 25 → 27 taken 125573 times.
241563 if (GET_CABAC(PART_MODE_OFFSET + 3)) // 011
698 115990 return PART_2NxN;
699
2/2
✓ Branch 28 → 29 taken 58179 times.
✓ Branch 28 → 30 taken 67394 times.
125573 if (get_cabac_bypass(&lc->sub.cc)) // 0101
700 58179 return PART_2NxnD;
701 67394 return PART_2NxnU; // 0100
702 }
703
704
2/2
✓ Branch 32 → 33 taken 177818 times.
✓ Branch 32 → 34 taken 186236 times.
364054 if (GET_CABAC(PART_MODE_OFFSET + 3)) // 001
705 177818 return PART_Nx2N;
706
2/2
✓ Branch 35 → 36 taken 85890 times.
✓ Branch 35 → 37 taken 100346 times.
186236 if (get_cabac_bypass(&lc->sub.cc)) // 0001
707 85890 return PART_nRx2N;
708 100346 return PART_nLx2N; // 0000
709 }
710
711 126478 int ff_hevc_pcm_flag_decode(HEVCLocalContext *lc)
712 {
713 126478 return get_cabac_terminate(&lc->sub.cc);
714 }
715
716 6956540 int ff_hevc_prev_intra_luma_pred_flag_decode(HEVCLocalContext *lc)
717 {
718 6956540 return GET_CABAC(PREV_INTRA_LUMA_PRED_FLAG_OFFSET);
719 }
720
721 4139582 int ff_hevc_mpm_idx_decode(HEVCLocalContext *lc)
722 {
723 4139582 int i = 0;
724
4/4
✓ Branch 4 → 5 taken 6179908 times.
✓ Branch 4 → 7 taken 867785 times.
✓ Branch 6 → 3 taken 2908111 times.
✓ Branch 6 → 7 taken 3271797 times.
7047693 while (i < 2 && get_cabac_bypass(&lc->sub.cc))
725 2908111 i++;
726 4139582 return i;
727 }
728
729 2816958 int ff_hevc_rem_intra_luma_pred_mode_decode(HEVCLocalContext *lc)
730 {
731 int i;
732 2816958 int value = get_cabac_bypass(&lc->sub.cc);
733
734
2/2
✓ Branch 6 → 4 taken 11267832 times.
✓ Branch 6 → 7 taken 2816958 times.
14084790 for (i = 0; i < 4; i++)
735 11267832 value = (value << 1) | get_cabac_bypass(&lc->sub.cc);
736 2816958 return value;
737 }
738
739 3802033 int ff_hevc_intra_chroma_pred_mode_decode(HEVCLocalContext *lc)
740 {
741 int ret;
742
2/2
✓ Branch 3 → 4 taken 2911444 times.
✓ Branch 3 → 5 taken 890589 times.
3802033 if (!GET_CABAC(INTRA_CHROMA_PRED_MODE_OFFSET))
743 2911444 return 4;
744
745 890589 ret = get_cabac_bypass(&lc->sub.cc) << 1;
746 890589 ret |= get_cabac_bypass(&lc->sub.cc);
747 890589 return ret;
748 }
749
750 8001708 int ff_hevc_merge_idx_decode(HEVCLocalContext *lc)
751 {
752 8001708 int i = GET_CABAC(MERGE_IDX_OFFSET);
753
754
2/2
✓ Branch 3 → 4 taken 3166409 times.
✓ Branch 3 → 9 taken 4835299 times.
8001708 if (i != 0) {
755
4/4
✓ Branch 6 → 7 taken 4604657 times.
✓ Branch 6 → 9 taken 412562 times.
✓ Branch 8 → 5 taken 1850810 times.
✓ Branch 8 → 9 taken 2753847 times.
5017219 while (i < lc->sh->max_num_merge_cand-1 && get_cabac_bypass(&lc->sub.cc))
756 1850810 i++;
757 }
758 8001708 return i;
759 }
760
761 6055589 int ff_hevc_merge_flag_decode(HEVCLocalContext *lc)
762 {
763 6055589 return GET_CABAC(MERGE_FLAG_OFFSET);
764 }
765
766 1923691 int ff_hevc_inter_pred_idc_decode(HEVCLocalContext *lc, int nPbW, int nPbH)
767 {
768
2/2
✓ Branch 2 → 3 taken 248743 times.
✓ Branch 2 → 5 taken 1674948 times.
1923691 if (nPbW + nPbH == 12)
769 248743 return GET_CABAC(INTER_PRED_IDC_OFFSET + 4);
770
2/2
✓ Branch 6 → 7 taken 425087 times.
✓ Branch 6 → 8 taken 1249861 times.
1674948 if (GET_CABAC(INTER_PRED_IDC_OFFSET + lc->ct_depth))
771 425087 return PRED_BI;
772
773 1249861 return GET_CABAC(INTER_PRED_IDC_OFFSET + 4);
774 }
775
776 3542895 int ff_hevc_ref_idx_lx_decode(HEVCLocalContext *lc, int num_ref_idx_lx)
777 {
778 3542895 int i = 0;
779 3542895 int max = num_ref_idx_lx - 1;
780 3542895 int max_ctx = FFMIN(max, 2);
781
782
4/4
✓ Branch 4 → 5 taken 3331553 times.
✓ Branch 4 → 7 taken 1311637 times.
✓ Branch 6 → 3 taken 1100295 times.
✓ Branch 6 → 7 taken 2231258 times.
4643190 while (i < max_ctx && GET_CABAC(REF_IDX_L0_OFFSET + i))
783 1100295 i++;
784
2/2
✓ Branch 7 → 8 taken 203613 times.
✓ Branch 7 → 13 taken 3339282 times.
3542895 if (i == 2) {
785
4/4
✓ Branch 10 → 11 taken 162576 times.
✓ Branch 10 → 13 taken 127634 times.
✓ Branch 12 → 9 taken 86597 times.
✓ Branch 12 → 13 taken 75979 times.
290210 while (i < max && get_cabac_bypass(&lc->sub.cc))
786 86597 i++;
787 }
788
789 3542895 return i;
790 }
791
792 3542895 int ff_hevc_mvp_lx_flag_decode(HEVCLocalContext *lc)
793 {
794 3542895 return GET_CABAC(MVP_LX_FLAG_OFFSET);
795 }
796
797 3069183 int ff_hevc_no_residual_syntax_flag_decode(HEVCLocalContext *lc)
798 {
799 3069183 return GET_CABAC(NO_RESIDUAL_DATA_FLAG_OFFSET);
800 }
801
802 6758580 static av_always_inline int abs_mvd_greater0_flag_decode(HEVCLocalContext *lc)
803 {
804 6758580 return GET_CABAC(ABS_MVD_GREATER0_FLAG_OFFSET);
805 }
806
807 4542630 static av_always_inline int abs_mvd_greater1_flag_decode(HEVCLocalContext *lc)
808 {
809 4542630 return GET_CABAC(ABS_MVD_GREATER1_FLAG_OFFSET + 1);
810 }
811
812 3112746 static av_always_inline int mvd_decode(HEVCLocalContext *lc)
813 {
814 3112746 int ret = 2;
815 3112746 int k = 1;
816
817
3/4
✓ Branch 4 → 5 taken 7472048 times.
✗ Branch 4 → 7 not taken.
✓ Branch 6 → 3 taken 4359302 times.
✓ Branch 6 → 7 taken 3112746 times.
7472048 while (k < CABAC_MAX_BIN && get_cabac_bypass(&lc->sub.cc)) {
818 4359302 ret += 1U << k;
819 4359302 k++;
820 }
821
1/2
✗ Branch 7 → 8 not taken.
✓ Branch 7 → 10 taken 3112746 times.
3112746 if (k == CABAC_MAX_BIN) {
822 ✗ av_log(lc->logctx, AV_LOG_ERROR, "CABAC_MAX_BIN : %d\n", k);
823 ✗ return 0;
824 }
825
2/2
✓ Branch 13 → 11 taken 7472048 times.
✓ Branch 13 → 14 taken 3112746 times.
10584794 while (k--)
826 7472048 ret += get_cabac_bypass(&lc->sub.cc) << k;
827 3112746 return get_cabac_bypass_sign(&lc->sub.cc, -ret);
828 }
829
830 1429884 static av_always_inline int mvd_sign_flag_decode(HEVCLocalContext *lc)
831 {
832 1429884 return get_cabac_bypass_sign(&lc->sub.cc, -1);
833 }
834
835 7166603 int ff_hevc_split_transform_flag_decode(HEVCLocalContext *lc, int log2_trafo_size)
836 {
837 7166603 return GET_CABAC(SPLIT_TRANSFORM_FLAG_OFFSET + 5 - log2_trafo_size);
838 }
839
840 15960662 int ff_hevc_cbf_cb_cr_decode(HEVCLocalContext *lc, int trafo_depth)
841 {
842 15960662 return GET_CABAC(CBF_CB_CR_OFFSET + trafo_depth);
843 }
844
845 14966542 int ff_hevc_cbf_luma_decode(HEVCLocalContext *lc, int trafo_depth)
846 {
847
2/2
✓ Branch 2 → 3 taken 2811262 times.
✓ Branch 2 → 4 taken 12155280 times.
14966542 return GET_CABAC(CBF_LUMA_OFFSET + !trafo_depth);
848 }
849
850 5701370 static int hevc_transform_skip_flag_decode(HEVCLocalContext *lc, int c_idx)
851 {
852
2/2
✓ Branch 2 → 3 taken 1848777 times.
✓ Branch 2 → 4 taken 3852593 times.
5701370 return GET_CABAC(TRANSFORM_SKIP_FLAG_OFFSET + !!c_idx);
853 }
854
855 35234 static int explicit_rdpcm_flag_decode(HEVCLocalContext *lc, int c_idx)
856 {
857
2/2
✓ Branch 2 → 3 taken 29253 times.
✓ Branch 2 → 4 taken 5981 times.
35234 return GET_CABAC(EXPLICIT_RDPCM_FLAG_OFFSET + !!c_idx);
858 }
859
860 3090 static int explicit_rdpcm_dir_flag_decode(HEVCLocalContext *lc, int c_idx)
861 {
862
2/2
✓ Branch 2 → 3 taken 1813 times.
✓ Branch 2 → 4 taken 1277 times.
3090 return GET_CABAC(EXPLICIT_RDPCM_DIR_FLAG_OFFSET + !!c_idx);
863 }
864
865 251428 int ff_hevc_log2_res_scale_abs(HEVCLocalContext *lc, int idx)
866 {
867 251428 int i =0;
868
869
4/4
✓ Branch 4 → 5 taken 668172 times.
✓ Branch 4 → 7 taken 84789 times.
✓ Branch 6 → 3 taken 501533 times.
✓ Branch 6 → 7 taken 166639 times.
752961 while (i < 4 && GET_CABAC(LOG2_RES_SCALE_ABS_OFFSET + 4 * idx + i))
870 501533 i++;
871
872 251428 return i;
873 }
874
875 142161 int ff_hevc_res_scale_sign_flag(HEVCLocalContext *lc, int idx)
876 {
877 142161 return GET_CABAC(RES_SCALE_SIGN_FLAG_OFFSET + idx);
878 }
879
880 14292833 static av_always_inline void last_significant_coeff_xy_prefix_decode(HEVCLocalContext *lc, int c_idx,
881 int log2_size, int *last_scx_prefix, int *last_scy_prefix)
882 {
883 14292833 int i = 0;
884 14292833 int max = (log2_size << 1) - 1;
885 int ctx_offset, ctx_shift;
886
887
2/2
✓ Branch 2 → 3 taken 10136428 times.
✓ Branch 2 → 4 taken 4156405 times.
14292833 if (!c_idx) {
888 10136428 ctx_offset = 3 * (log2_size - 2) + ((log2_size - 1) >> 2);
889 10136428 ctx_shift = (log2_size + 1) >> 2;
890 } else {
891 4156405 ctx_offset = 15;
892 4156405 ctx_shift = log2_size - 2;
893 }
894
4/4
✓ Branch 7 → 8 taken 34757311 times.
✓ Branch 7 → 10 taken 1882212 times.
✓ Branch 9 → 6 taken 22346690 times.
✓ Branch 9 → 10 taken 12410621 times.
71396834 while (i < max &&
895 34757311 GET_CABAC(LAST_SIGNIFICANT_COEFF_X_PREFIX_OFFSET + (i >> ctx_shift) + ctx_offset))
896 22346690 i++;
897 14292833 *last_scx_prefix = i;
898
899 14292833 i = 0;
900
4/4
✓ Branch 12 → 13 taken 30558668 times.
✓ Branch 12 → 15 taken 1527191 times.
✓ Branch 14 → 11 taken 17793026 times.
✓ Branch 14 → 15 taken 12765642 times.
62644527 while (i < max &&
901 30558668 GET_CABAC(LAST_SIGNIFICANT_COEFF_Y_PREFIX_OFFSET + (i >> ctx_shift) + ctx_offset))
902 17793026 i++;
903 14292833 *last_scy_prefix = i;
904 14292833 }
905
906 3264097 static av_always_inline int last_significant_coeff_suffix_decode(HEVCLocalContext *lc,
907 int last_significant_coeff_prefix)
908 {
909 int i;
910 3264097 int length = (last_significant_coeff_prefix >> 1) - 1;
911 3264097 int value = get_cabac_bypass(&lc->sub.cc);
912
913
2/2
✓ Branch 6 → 4 taken 878289 times.
✓ Branch 6 → 7 taken 3264097 times.
4142386 for (i = 1; i < length; i++)
914 878289 value = (value << 1) | get_cabac_bypass(&lc->sub.cc);
915 3264097 return value;
916 }
917
918 8388333 static av_always_inline int significant_coeff_group_flag_decode(HEVCLocalContext *lc, int c_idx, int ctx_cg)
919 {
920 int inc;
921
922
2/2
✓ Branch 2 → 3 taken 1179815 times.
✓ Branch 2 → 4 taken 7208518 times.
8388333 inc = FFMIN(ctx_cg, 1) + (c_idx>0 ? 2 : 0);
923
924 8388333 return GET_CABAC(SIGNIFICANT_COEFF_GROUP_FLAG_OFFSET + inc);
925 }
926 170110216 static av_always_inline int significant_coeff_flag_decode(HEVCLocalContext *lc, int n,
927 int offset, const uint8_t *ctx_idx_map)
928 {
929 170110216 int inc = ctx_idx_map[n] + offset;
930 170110216 return GET_CABAC(SIGNIFICANT_COEFF_FLAG_OFFSET + inc);
931 }
932
933 18389127 static av_always_inline int significant_coeff_flag_decode_0(HEVCLocalContext *lc, int c_idx, int offset)
934 {
935 18389127 return GET_CABAC(SIGNIFICANT_COEFF_FLAG_OFFSET + offset);
936 }
937
938 86532352 static av_always_inline int coeff_abs_level_greater1_flag_decode(HEVCLocalContext *lc, int c_idx, int inc)
939 {
940
941
2/2
✓ Branch 2 → 3 taken 18371855 times.
✓ Branch 2 → 4 taken 68160497 times.
86532352 if (c_idx > 0)
942 18371855 inc += 16;
943
944 86532352 return GET_CABAC(COEFF_ABS_LEVEL_GREATER1_FLAG_OFFSET + inc);
945 }
946
947 9392820 static av_always_inline int coeff_abs_level_greater2_flag_decode(HEVCLocalContext *lc, int c_idx, int inc)
948 {
949
2/2
✓ Branch 2 → 3 taken 1798205 times.
✓ Branch 2 → 4 taken 7594615 times.
9392820 if (c_idx > 0)
950 1798205 inc += 4;
951
952 9392820 return GET_CABAC(COEFF_ABS_LEVEL_GREATER2_FLAG_OFFSET + inc);
953 }
954
955 /* a run of bypass bins is the quotient of the offset by range << 17 */
956 17297167 static int cabac_bypass_bits(CABACContext *c, int n)
957 {
958 17297167 int avail = CABAC_BITS - ff_ctz(c->low);
959 17297167 uint64_t x, r = (uint64_t)c->range << (CABAC_BITS + 1);
960 17297167 const uint8_t *bytestream = c->bytestream;
961
962
2/2
✓ Branch 2 → 3 taken 10800501 times.
✓ Branch 2 → 4 taken 6496666 times.
17297167 if (n < avail) {
963 10800501 x = (uint64_t)c->low << n;
964 } else {
965 6496666 int fill = (bytestream[0] << 9) + (bytestream[1] << 1) - CABAC_MASK;
966
967 6496666 x = (uint64_t)((((int64_t)c->low << avail) + fill)) << (n - avail);
968 #if !UNCHECKED_BITSTREAM_READER
969
2/2
✓ Branch 4 → 5 taken 6496466 times.
✓ Branch 4 → 6 taken 200 times.
6496666 if (bytestream < c->bytestream_end)
970 #endif
971 6496466 bytestream += CABAC_BITS / 8;
972 }
973
974
1/2
✓ Branch 6 → 7 taken 17297167 times.
✗ Branch 6 → 8 not taken.
17297167 if (x < r << n) {
975 17297167 c->low = x % r;
976 17297167 c->bytestream = bytestream;
977 17297167 return x / r;
978 } else {
979 ✗ int ret = 0;
980
981
0/2
✗ Branch 11 → 9 not taken.
✗ Branch 11 → 12 not taken.
✗ for (int i = 0; i < n; i++)
982 ✗ ret = (ret << 1) | get_cabac_bypass(c);
983 ✗ return ret;
984 }
985 }
986
987 /* leading ones of the quotient, consumed only up to the first zero */
988 36908098 static int cabac_unary_prefix(CABACContext *c, int max)
989 {
990 36908098 int prefix = 0;
991
992
1/2
✓ Branch 13 → 3 taken 42229674 times.
✗ Branch 13 → 14 not taken.
42229674 while (prefix < max) {
993 42229674 int avail = CABAC_BITS - ff_ctz(c->low);
994 42229674 int n = FFMIN(avail - 1, max - prefix);
995 42229674 uint64_t r = (uint64_t)c->range << (CABAC_BITS + 1);
996 42229674 uint64_t x = (uint64_t)c->low << n;
997 int q, t;
998
999
3/4
✓ Branch 3 → 4 taken 37260925 times.
✓ Branch 3 → 5 taken 4968749 times.
✗ Branch 4 → 5 not taken.
✓ Branch 4 → 9 taken 37260925 times.
42229674 if (n < 1 || x >= r << n) {
1000
2/2
✓ Branch 6 → 7 taken 2307340 times.
✓ Branch 6 → 8 taken 2661409 times.
4968749 if (!get_cabac_bypass(c))
1001 2307340 return prefix;
1002 2661409 prefix++;
1003 2661409 continue;
1004 }
1005
1006 37260925 q = x / r;
1007 37260925 t = ~q & ((1 << n) - 1);
1008
2/2
✓ Branch 9 → 10 taken 34600758 times.
✓ Branch 9 → 11 taken 2660167 times.
37260925 if (t) {
1009 34600758 int p = n - 1 - av_log2(t);
1010 34600758 int k = n - (p + 1);
1011
1012 34600758 c->low = (x >> k) - ((uint64_t)(q >> k) * r);
1013 34600758 return prefix + p;
1014 }
1015 2660167 c->low = x - (uint64_t)q * r;
1016 2660167 prefix += n;
1017 }
1018 ✗ return prefix;
1019 }
1020
1021 36908098 static av_always_inline int coeff_abs_level_remaining_decode(HEVCLocalContext *lc, int rc_rice_param)
1022 {
1023 int prefix;
1024 36908098 int suffix = 0;
1025 int last_coeff_abs_level_remaining;
1026 int i;
1027
1028 36908098 prefix = cabac_unary_prefix(&lc->sub.cc, CABAC_MAX_BIN);
1029
1030
2/2
✓ Branch 3 → 4 taken 31865466 times.
✓ Branch 3 → 11 taken 5042632 times.
36908098 if (prefix < 3) {
1031
2/2
✓ Branch 4 → 5 taken 3411495 times.
✓ Branch 4 → 6 taken 28453971 times.
31865466 if (rc_rice_param > 2)
1032 3411495 suffix = cabac_bypass_bits(&lc->sub.cc, rc_rice_param);
1033 else
1034
2/2
✓ Branch 9 → 7 taken 19496195 times.
✓ Branch 9 → 10 taken 28453971 times.
47950166 for (i = 0; i < rc_rice_param; i++)
1035 19496195 suffix = (suffix << 1) | get_cabac_bypass(&lc->sub.cc);
1036 31865466 last_coeff_abs_level_remaining = (prefix << rc_rice_param) + suffix;
1037 } else {
1038 5042632 int prefix_minus3 = prefix - 3;
1039 int k;
1040
1041
2/4
✓ Branch 11 → 12 taken 5042632 times.
✗ Branch 11 → 13 not taken.
✗ Branch 12 → 13 not taken.
✓ Branch 12 → 15 taken 5042632 times.
5042632 if (prefix == CABAC_MAX_BIN || prefix_minus3 + rc_rice_param > 16 + 6) {
1042 ✗ av_log(lc->logctx, AV_LOG_ERROR, "CABAC_MAX_BIN : %d\n", prefix);
1043 ✗ return 0;
1044 }
1045
1046 5042632 k = prefix_minus3 + rc_rice_param;
1047
1/2
✗ Branch 15 → 16 not taken.
✓ Branch 15 → 19 taken 5042632 times.
5042632 if (k > 16) {
1048 ✗ suffix = cabac_bypass_bits(&lc->sub.cc, 16) << (k - 16);
1049 ✗ suffix |= cabac_bypass_bits(&lc->sub.cc, k - 16);
1050
2/2
✓ Branch 19 → 20 taken 2177892 times.
✓ Branch 19 → 21 taken 2864740 times.
5042632 } else if (k > 2) {
1051 2177892 suffix = cabac_bypass_bits(&lc->sub.cc, k);
1052 } else {
1053
2/2
✓ Branch 24 → 22 taken 2805419 times.
✓ Branch 24 → 25 taken 2864740 times.
5670159 for (i = 0; i < k; i++)
1054 2805419 suffix = (suffix << 1) | get_cabac_bypass(&lc->sub.cc);
1055 }
1056 5042632 last_coeff_abs_level_remaining = (((1 << prefix_minus3) + 3 - 1)
1057 5042632 << rc_rice_param) + suffix;
1058 }
1059 36908098 return last_coeff_abs_level_remaining;
1060 }
1061
1062 21796811 static av_always_inline int coeff_sign_flag_decode(HEVCLocalContext *lc, uint8_t nb)
1063 {
1064 int i;
1065 21796811 int ret = 0;
1066
1067
2/2
✓ Branch 2 → 3 taken 11707780 times.
✓ Branch 2 → 5 taken 10089031 times.
21796811 if (nb > 2)
1068 11707780 return cabac_bypass_bits(&lc->sub.cc, nb);
1069
1070
2/2
✓ Branch 8 → 6 taken 14194270 times.
✓ Branch 8 → 9 taken 10089031 times.
24283301 for (i = 0; i < nb; i++)
1071 14194270 ret = (ret << 1) | get_cabac_bypass(&lc->sub.cc);
1072 10089031 return ret;
1073 }
1074
1075 14292833 void ff_hevc_hls_residual_coding(HEVCLocalContext *lc, const HEVCPPS *pps,
1076 int x0, int y0,
1077 int log2_trafo_size, enum ScanType scan_idx,
1078 int c_idx)
1079 {
1080 #define GET_COORD(offset, n) \
1081 do { \
1082 x_c = (x_cg << 2) + scan_x_off[n]; \
1083 y_c = (y_cg << 2) + scan_y_off[n]; \
1084 } while (0)
1085 14292833 const HEVCContext *const s = lc->parent;
1086 14292833 const HEVCSPS *const sps = pps->sps;
1087 14292833 int transform_skip_flag = 0;
1088
1089 int last_significant_coeff_x, last_significant_coeff_y;
1090 int last_scan_pos;
1091 int n_end;
1092 14292833 int num_coeff = 0;
1093 14292833 int greater1_ctx = 1;
1094
1095 int num_last_subset;
1096 int max_xy, col_limit, clear_rows;
1097 int x_cg_last_sig, y_cg_last_sig;
1098
1099 const uint8_t *scan_x_cg, *scan_y_cg, *scan_x_off, *scan_y_off;
1100
1101 14292833 ptrdiff_t stride = s->cur_frame->f->linesize[c_idx];
1102 14292833 int hshift = sps->hshift[c_idx];
1103 14292833 int vshift = sps->vshift[c_idx];
1104 14292833 uint8_t *dst = &s->cur_frame->f->data[c_idx][(y0 >> vshift) * stride +
1105 14292833 ((x0 >> hshift) << sps->pixel_shift)];
1106
2/2
✓ Branch 2 → 3 taken 4156405 times.
✓ Branch 2 → 4 taken 10136428 times.
14292833 int16_t *coeffs = (int16_t*)(c_idx ? lc->edge_emu_buffer2 : lc->edge_emu_buffer);
1107 14292833 uint8_t significant_coeff_group_flag[8][8] = {{0}};
1108 14292833 int explicit_rdpcm_flag = 0;
1109 int explicit_rdpcm_dir_flag;
1110
1111 14292833 int trafo_size = 1 << log2_trafo_size;
1112 int i;
1113 int qp,shift,add,scale,scale_m;
1114 static const uint8_t level_scale[] = { 40, 45, 51, 57, 64, 72 };
1115 14292833 const uint8_t *scale_matrix = NULL;
1116 uint8_t dc_scale;
1117
2/2
✓ Branch 5 → 6 taken 10136428 times.
✓ Branch 5 → 7 taken 4156405 times.
14292833 int pred_mode_intra = (c_idx == 0) ? lc->tu.intra_pred_mode :
1118 lc->tu.intra_pred_mode_c;
1119
1120 // Derive QP for dequant
1121
2/2
✓ Branch 8 → 9 taken 13868635 times.
✓ Branch 8 → 35 taken 424198 times.
14292833 if (!lc->cu.cu_transquant_bypass_flag) {
1122 static const int qp_c[] = { 29, 30, 31, 32, 33, 33, 34, 34, 35, 35, 36, 36, 37, 37 };
1123 static const uint8_t rem6[51 + 4 * 6 + 1] = {
1124 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2,
1125 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5,
1126 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3,
1127 4, 5, 0, 1, 2, 3, 4, 5, 0, 1
1128 };
1129
1130 static const uint8_t div6[51 + 4 * 6 + 1] = {
1131 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3,
1132 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6,
1133 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10,
1134 10, 10, 11, 11, 11, 11, 11, 11, 12, 12
1135 };
1136 13868635 int qp_y = lc->sub.qp_y;
1137
1138
2/2
✓ Branch 9 → 10 taken 10307969 times.
✓ Branch 9 → 12 taken 3560666 times.
13868635 if (pps->transform_skip_enabled_flag &&
1139
2/2
✓ Branch 10 → 11 taken 5701370 times.
✓ Branch 10 → 12 taken 4606599 times.
10307969 log2_trafo_size <= pps->log2_max_transform_skip_block_size) {
1140 5701370 transform_skip_flag = hevc_transform_skip_flag_decode(lc, c_idx);
1141 }
1142
1143
2/2
✓ Branch 12 → 13 taken 9875633 times.
✓ Branch 12 → 14 taken 3993002 times.
13868635 if (c_idx == 0) {
1144 9875633 qp = qp_y + sps->qp_bd_offset;
1145 } else {
1146 int qp_i, offset;
1147
1148
2/2
✓ Branch 14 → 15 taken 1919632 times.
✓ Branch 14 → 16 taken 2073370 times.
3993002 if (c_idx == 1)
1149 1919632 offset = pps->cb_qp_offset + lc->sh->slice_cb_qp_offset +
1150 1919632 lc->sub.cu_qp_offset_cb;
1151 else
1152 2073370 offset = pps->cr_qp_offset + lc->sh->slice_cr_qp_offset +
1153 2073370 lc->sub.cu_qp_offset_cr;
1154
1155 3993002 qp_i = av_clip(qp_y + offset, - sps->qp_bd_offset, 57);
1156
2/2
✓ Branch 17 → 18 taken 2596690 times.
✓ Branch 17 → 23 taken 1396312 times.
3993002 if (sps->chroma_format_idc == 1) {
1157
2/2
✓ Branch 18 → 19 taken 953576 times.
✓ Branch 18 → 20 taken 1643114 times.
2596690 if (qp_i < 30)
1158 953576 qp = qp_i;
1159
2/2
✓ Branch 20 → 21 taken 11213 times.
✓ Branch 20 → 22 taken 1631901 times.
1643114 else if (qp_i > 43)
1160 11213 qp = qp_i - 6;
1161 else
1162 1631901 qp = qp_c[qp_i - 30];
1163 } else {
1164
1/2
✗ Branch 23 → 24 not taken.
✓ Branch 23 → 25 taken 1396312 times.
1396312 if (qp_i > 51)
1165 ✗ qp = 51;
1166 else
1167 1396312 qp = qp_i;
1168 }
1169
1170 3993002 qp += sps->qp_bd_offset;
1171 }
1172
1173 13868635 shift = sps->bit_depth + log2_trafo_size - 5;
1174 13868635 add = 1 << (shift-1);
1175 13868635 scale = level_scale[rem6[qp]] << (div6[qp]);
1176 13868635 scale_m = 16; // default when no custom scaling lists.
1177 13868635 dc_scale = 16;
1178
1179
6/6
✓ Branch 27 → 28 taken 613107 times.
✓ Branch 27 → 36 taken 13255528 times.
✓ Branch 28 → 29 taken 19500 times.
✓ Branch 28 → 30 taken 593607 times.
✓ Branch 29 → 30 taken 11407 times.
✓ Branch 29 → 36 taken 8093 times.
13868635 if (sps->scaling_list_enabled && !(transform_skip_flag && log2_trafo_size > 2)) {
1180 605014 const ScalingList *sl = pps->scaling_list_data_present_flag ?
1181
2/2
✓ Branch 30 → 31 taken 347752 times.
✓ Branch 30 → 32 taken 257262 times.
605014 &pps->scaling_list : &sps->scaling_list;
1182 605014 int matrix_id = lc->cu.pred_mode != MODE_INTRA;
1183
1184 605014 matrix_id = 3 * matrix_id + c_idx;
1185
1186 605014 scale_matrix = sl->sl[log2_trafo_size - 2][matrix_id];
1187
2/2
✓ Branch 33 → 34 taken 112450 times.
✓ Branch 33 → 36 taken 492564 times.
605014 if (log2_trafo_size >= 4)
1188 112450 dc_scale = sl->sl_dc[log2_trafo_size - 4][matrix_id];
1189 }
1190 } else {
1191 424198 shift = 0;
1192 424198 add = 0;
1193 424198 scale = 0;
1194 424198 dc_scale = 0;
1195 }
1196
1197
6/6
✓ Branch 36 → 37 taken 5995358 times.
✓ Branch 36 → 43 taken 8297475 times.
✓ Branch 37 → 38 taken 225511 times.
✓ Branch 37 → 43 taken 5769847 times.
✓ Branch 38 → 39 taken 190277 times.
✓ Branch 38 → 40 taken 35234 times.
14292833 if (lc->cu.pred_mode == MODE_INTER && sps->explicit_rdpcm_enabled &&
1198
1/2
✗ Branch 39 → 40 not taken.
✓ Branch 39 → 43 taken 190277 times.
190277 (transform_skip_flag || lc->cu.cu_transquant_bypass_flag)) {
1199 35234 explicit_rdpcm_flag = explicit_rdpcm_flag_decode(lc, c_idx);
1200
2/2
✓ Branch 41 → 42 taken 3090 times.
✓ Branch 41 → 43 taken 32144 times.
35234 if (explicit_rdpcm_flag) {
1201 3090 explicit_rdpcm_dir_flag = explicit_rdpcm_dir_flag_decode(lc, c_idx);
1202 }
1203 }
1204
1205 14292833 last_significant_coeff_xy_prefix_decode(lc, c_idx, log2_trafo_size,
1206 &last_significant_coeff_x, &last_significant_coeff_y);
1207
1208
2/2
✓ Branch 44 → 45 taken 1874770 times.
✓ Branch 44 → 47 taken 12418063 times.
14292833 if (last_significant_coeff_x > 3) {
1209 1874770 int suffix = last_significant_coeff_suffix_decode(lc, last_significant_coeff_x);
1210 1874770 last_significant_coeff_x = (1 << ((last_significant_coeff_x >> 1) - 1)) *
1211 1874770 (2 + (last_significant_coeff_x & 1)) +
1212 suffix;
1213 }
1214
1215
2/2
✓ Branch 47 → 48 taken 1389327 times.
✓ Branch 47 → 50 taken 12903506 times.
14292833 if (last_significant_coeff_y > 3) {
1216 1389327 int suffix = last_significant_coeff_suffix_decode(lc, last_significant_coeff_y);
1217 1389327 last_significant_coeff_y = (1 << ((last_significant_coeff_y >> 1) - 1)) *
1218 1389327 (2 + (last_significant_coeff_y & 1)) +
1219 suffix;
1220 }
1221
1222
2/2
✓ Branch 50 → 51 taken 1518700 times.
✓ Branch 50 → 52 taken 12774133 times.
14292833 if (scan_idx == SCAN_VERT)
1223 1518700 FFSWAP(int, last_significant_coeff_x, last_significant_coeff_y);
1224
1225 14292833 x_cg_last_sig = last_significant_coeff_x >> 2;
1226 14292833 y_cg_last_sig = last_significant_coeff_y >> 2;
1227
1228
3/3
✓ Branch 52 → 53 taken 10952396 times.
✓ Branch 52 → 61 taken 1821737 times.
✓ Branch 52 → 62 taken 1518700 times.
14292833 switch (scan_idx) {
1229 10952396 case SCAN_DIAG: {
1230 10952396 int last_x_c = last_significant_coeff_x & 3;
1231 10952396 int last_y_c = last_significant_coeff_y & 3;
1232
1233 10952396 scan_x_off = ff_hevc_diag_scan4x4_x;
1234 10952396 scan_y_off = ff_hevc_diag_scan4x4_y;
1235 10952396 num_coeff = diag_scan4x4_inv[last_y_c][last_x_c];
1236
2/2
✓ Branch 53 → 54 taken 4913250 times.
✓ Branch 53 → 55 taken 6039146 times.
10952396 if (trafo_size == 4) {
1237 4913250 scan_x_cg = scan_1x1;
1238 4913250 scan_y_cg = scan_1x1;
1239
2/2
✓ Branch 55 → 56 taken 3115410 times.
✓ Branch 55 → 57 taken 2923736 times.
6039146 } else if (trafo_size == 8) {
1240 3115410 num_coeff += diag_scan2x2_inv[y_cg_last_sig][x_cg_last_sig] << 4;
1241 3115410 scan_x_cg = diag_scan2x2_x;
1242 3115410 scan_y_cg = diag_scan2x2_y;
1243
2/2
✓ Branch 57 → 58 taken 2119172 times.
✓ Branch 57 → 59 taken 804564 times.
2923736 } else if (trafo_size == 16) {
1244 2119172 num_coeff += diag_scan4x4_inv[y_cg_last_sig][x_cg_last_sig] << 4;
1245 2119172 scan_x_cg = ff_hevc_diag_scan4x4_x;
1246 2119172 scan_y_cg = ff_hevc_diag_scan4x4_y;
1247 } else { // trafo_size == 32
1248 804564 num_coeff += diag_scan8x8_inv[y_cg_last_sig][x_cg_last_sig] << 4;
1249 804564 scan_x_cg = ff_hevc_diag_scan8x8_x;
1250 804564 scan_y_cg = ff_hevc_diag_scan8x8_y;
1251 }
1252 10952396 break;
1253 }
1254 1821737 case SCAN_HORIZ:
1255 1821737 scan_x_cg = horiz_scan2x2_x;
1256 1821737 scan_y_cg = horiz_scan2x2_y;
1257 1821737 scan_x_off = horiz_scan4x4_x;
1258 1821737 scan_y_off = horiz_scan4x4_y;
1259 1821737 num_coeff = horiz_scan8x8_inv[last_significant_coeff_y][last_significant_coeff_x];
1260 1821737 break;
1261 1518700 default: //SCAN_VERT
1262 1518700 scan_x_cg = horiz_scan2x2_y;
1263 1518700 scan_y_cg = horiz_scan2x2_x;
1264 1518700 scan_x_off = horiz_scan4x4_y;
1265 1518700 scan_y_off = horiz_scan4x4_x;
1266 1518700 num_coeff = horiz_scan8x8_inv[last_significant_coeff_x][last_significant_coeff_y];
1267 1518700 break;
1268 }
1269 14292833 num_coeff++;
1270 14292833 num_last_subset = (num_coeff - 1) >> 4;
1271
1272 14292833 max_xy = FFMAX(last_significant_coeff_x, last_significant_coeff_y);
1273 14292833 col_limit = last_significant_coeff_x + last_significant_coeff_y + 4;
1274
2/2
✓ Branch 63 → 64 taken 11759299 times.
✓ Branch 63 → 65 taken 2533534 times.
14292833 if (max_xy < 4)
1275 11759299 col_limit = FFMIN(4, col_limit);
1276
2/2
✓ Branch 65 → 66 taken 1906850 times.
✓ Branch 65 → 67 taken 626684 times.
2533534 else if (max_xy < 8)
1277 1906850 col_limit = FFMIN(8, col_limit);
1278
2/2
✓ Branch 67 → 68 taken 286500 times.
✓ Branch 67 → 69 taken 340184 times.
626684 else if (max_xy < 12)
1279 286500 col_limit = FFMIN(24, col_limit);
1280
1281 // idct_dc reads coeffs[0] only and writes the whole block: no clear needed
1282 14292833 clear_rows = trafo_size;
1283
4/4
✓ Branch 69 → 70 taken 13868635 times.
✓ Branch 69 → 76 taken 424198 times.
✓ Branch 70 → 71 taken 13473926 times.
✓ Branch 70 → 76 taken 394709 times.
14292833 if (!lc->cu.cu_transquant_bypass_flag && !transform_skip_flag &&
1284
6/6
✓ Branch 71 → 72 taken 7874895 times.
✓ Branch 71 → 74 taken 5599031 times.
✓ Branch 72 → 73 taken 5547867 times.
✓ Branch 72 → 74 taken 2327028 times.
✓ Branch 73 → 74 taken 2375088 times.
✓ Branch 73 → 76 taken 3172779 times.
13473926 !(lc->cu.pred_mode == MODE_INTRA && c_idx == 0 && log2_trafo_size == 2)) {
1285
2/2
✓ Branch 74 → 75 taken 2494563 times.
✓ Branch 74 → 76 taken 7806584 times.
10301147 if (max_xy == 0)
1286 2494563 clear_rows = 0;
1287 }
1288
2/2
✓ Branch 76 → 77 taken 11798270 times.
✓ Branch 76 → 78 taken 2494563 times.
14292833 if (clear_rows)
1289 11798270 memset(coeffs, 0, clear_rows * trafo_size * sizeof(int16_t));
1290
1291
2/2
✓ Branch 251 → 79 taken 25214700 times.
✓ Branch 251 → 252 taken 14292833 times.
39507533 for (i = num_last_subset; i >= 0; i--) {
1292 int n, m;
1293 int x_cg, y_cg, x_c, y_c, pos;
1294 25214700 int implicit_non_zero_coeff = 0;
1295 int64_t trans_coeff_level;
1296 25214700 int prev_sig = 0;
1297 25214700 int offset = i << 4;
1298 25214700 int rice_init = 0;
1299
1300 uint8_t significant_coeff_flag_idx[16];
1301 25214700 uint8_t nb_significant_coeff_flag = 0;
1302
1303 25214700 x_cg = scan_x_cg[i];
1304 25214700 y_cg = scan_y_cg[i];
1305
1306
4/4
✓ Branch 79 → 80 taken 10921867 times.
✓ Branch 79 → 87 taken 14292833 times.
✓ Branch 80 → 81 taken 8388333 times.
✓ Branch 80 → 87 taken 2533534 times.
25214700 if ((i < num_last_subset) && (i > 0)) {
1307 8388333 int ctx_cg = 0;
1308
2/2
✓ Branch 81 → 82 taken 7715540 times.
✓ Branch 81 → 83 taken 672793 times.
8388333 if (x_cg < (1 << (log2_trafo_size - 2)) - 1)
1309 7715540 ctx_cg += significant_coeff_group_flag[x_cg + 1][y_cg];
1310
2/2
✓ Branch 83 → 84 taken 7091952 times.
✓ Branch 83 → 85 taken 1296381 times.
8388333 if (y_cg < (1 << (log2_trafo_size - 2)) - 1)
1311 7091952 ctx_cg += significant_coeff_group_flag[x_cg][y_cg + 1];
1312
1313 8388333 significant_coeff_group_flag[x_cg][y_cg] =
1314 8388333 significant_coeff_group_flag_decode(lc, c_idx, ctx_cg);
1315 8388333 implicit_non_zero_coeff = 1;
1316 } else {
1317 16826367 significant_coeff_group_flag[x_cg][y_cg] =
1318
5/6
✓ Branch 87 → 88 taken 15035204 times.
✓ Branch 87 → 89 taken 1791163 times.
✓ Branch 88 → 89 taken 742371 times.
✓ Branch 88 → 91 taken 14292833 times.
✓ Branch 89 → 90 taken 2533534 times.
✗ Branch 89 → 92 not taken.
19359901 ((x_cg == x_cg_last_sig && y_cg == y_cg_last_sig) ||
1319
1/2
✓ Branch 90 → 91 taken 2533534 times.
✗ Branch 90 → 92 not taken.
2533534 (x_cg == 0 && y_cg == 0));
1320 }
1321
1322 25214700 last_scan_pos = num_coeff - offset - 1;
1323
1324
2/2
✓ Branch 94 → 95 taken 14292833 times.
✓ Branch 94 → 96 taken 10921867 times.
25214700 if (i == num_last_subset) {
1325 14292833 n_end = last_scan_pos - 1;
1326 14292833 significant_coeff_flag_idx[0] = last_scan_pos;
1327 14292833 nb_significant_coeff_flag = 1;
1328 } else {
1329 10921867 n_end = 15;
1330 }
1331
1332
2/2
✓ Branch 97 → 98 taken 16109627 times.
✓ Branch 97 → 99 taken 9105073 times.
25214700 if (x_cg < ((1 << log2_trafo_size) - 1) >> 2)
1333 16109627 prev_sig = !!significant_coeff_group_flag[x_cg + 1][y_cg];
1334
2/2
✓ Branch 99 → 100 taken 15623208 times.
✓ Branch 99 → 104 taken 9591492 times.
25214700 if (y_cg < ((1 << log2_trafo_size) - 1) >> 2)
1335
2/2
✓ Branch 100 → 101 taken 5193080 times.
✓ Branch 100 → 102 taken 10430128 times.
15623208 prev_sig += (!!significant_coeff_group_flag[x_cg][y_cg + 1] << 1);
1336
1337
4/4
✓ Branch 104 → 105 taken 21950178 times.
✓ Branch 104 → 152 taken 3264522 times.
✓ Branch 105 → 106 taken 18470864 times.
✓ Branch 105 → 152 taken 3479314 times.
25214700 if (significant_coeff_group_flag[x_cg][y_cg] && n_end >= 0) {
1338 // ctx_idx_map composed with the intra-CG scan, indexed by scan position
1339 static const uint8_t ctx_idx_map[3][5 * 16] = {
1340 { // SCAN_DIAG
1341 0, 2, 1, 6, 3, 4, 7, 6, 4, 5, 7, 8, 5, 8, 8, 8, // log2_trafo_size == 2
1342 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // prev_sig == 0
1343 2, 1, 2, 0, 1, 2, 0, 0, 1, 2, 0, 0, 1, 0, 0, 0, // prev_sig == 1
1344 2, 2, 1, 2, 1, 0, 2, 1, 0, 0, 1, 0, 0, 0, 0, 0, // prev_sig == 2
1345 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, // default
1346 },
1347 { // SCAN_HORIZ
1348 0, 1, 4, 5, 2, 3, 4, 5, 6, 6, 8, 8, 7, 7, 8, 8,
1349 1, 1, 1, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0,
1350 2, 2, 2, 2, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0,
1351 2, 1, 0, 0, 2, 1, 0, 0, 2, 1, 0, 0, 2, 1, 0, 0,
1352 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1353 },
1354 { // SCAN_VERT
1355 0, 2, 6, 7, 1, 3, 6, 7, 4, 4, 8, 8, 5, 5, 8, 8,
1356 1, 1, 1, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0,
1357 2, 1, 0, 0, 2, 1, 0, 0, 2, 1, 0, 0, 2, 1, 0, 0,
1358 2, 2, 2, 2, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0,
1359 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1360 },
1361 };
1362 const uint8_t *ctx_idx_map_p;
1363 18470864 int scf_offset = 0;
1364 int nb0;
1365
4/4
✓ Branch 106 → 107 taken 687068 times.
✓ Branch 106 → 113 taken 17783796 times.
✓ Branch 107 → 108 taken 592618 times.
✓ Branch 107 → 109 taken 94450 times.
18470864 if (sps->transform_skip_context_enabled &&
1366
1/2
✗ Branch 108 → 109 not taken.
✓ Branch 108 → 113 taken 592618 times.
592618 (transform_skip_flag || lc->cu.cu_transquant_bypass_flag)) {
1367 94450 ctx_idx_map_p = &ctx_idx_map[scan_idx][4 * 16];
1368
2/2
✓ Branch 109 → 110 taken 41170 times.
✓ Branch 109 → 111 taken 53280 times.
94450 if (c_idx == 0) {
1369 41170 scf_offset = 40;
1370 } else {
1371 53280 scf_offset = 14 + 27;
1372 }
1373 } else {
1374
2/2
✓ Branch 113 → 114 taken 3812420 times.
✓ Branch 113 → 115 taken 14563994 times.
18376414 if (c_idx != 0)
1375 3812420 scf_offset = 27;
1376
2/2
✓ Branch 115 → 116 taken 5707705 times.
✓ Branch 115 → 117 taken 12668709 times.
18376414 if (log2_trafo_size == 2) {
1377 5707705 ctx_idx_map_p = &ctx_idx_map[scan_idx][0];
1378 } else {
1379 12668709 ctx_idx_map_p = &ctx_idx_map[scan_idx][(prev_sig + 1) << 4];
1380
2/2
✓ Branch 117 → 118 taken 10519775 times.
✓ Branch 117 → 127 taken 2148934 times.
12668709 if (c_idx == 0) {
1381
4/4
✓ Branch 118 → 119 taken 6535763 times.
✓ Branch 118 → 120 taken 3984012 times.
✓ Branch 119 → 120 taken 2125001 times.
✓ Branch 119 → 121 taken 4410762 times.
10519775 if ((x_cg > 0 || y_cg > 0))
1382 6109013 scf_offset += 3;
1383
2/2
✓ Branch 121 → 122 taken 3842128 times.
✓ Branch 121 → 126 taken 6677647 times.
10519775 if (log2_trafo_size == 3) {
1384
2/2
✓ Branch 122 → 123 taken 2838646 times.
✓ Branch 122 → 124 taken 1003482 times.
3842128 scf_offset += (scan_idx == SCAN_DIAG) ? 9 : 15;
1385 } else {
1386 6677647 scf_offset += 21;
1387 }
1388 } else {
1389
2/2
✓ Branch 127 → 128 taken 997694 times.
✓ Branch 127 → 129 taken 1151240 times.
2148934 if (log2_trafo_size == 3)
1390 997694 scf_offset += 9;
1391 else
1392 1151240 scf_offset += 12;
1393 }
1394 }
1395 }
1396 // the flag is a fresh bin: store always, advance conditionally
1397 18470864 nb0 = nb_significant_coeff_flag;
1398
2/2
✓ Branch 133 → 131 taken 170110216 times.
✓ Branch 133 → 134 taken 18470864 times.
188581080 for (n = n_end; n > 0; n--) {
1399 170110216 int sig = significant_coeff_flag_decode(lc, n, scf_offset, ctx_idx_map_p);
1400 170110216 significant_coeff_flag_idx[nb_significant_coeff_flag] = n;
1401 170110216 nb_significant_coeff_flag += sig;
1402 }
1403
2/2
✓ Branch 134 → 135 taken 14776659 times.
✓ Branch 134 → 136 taken 3694205 times.
18470864 if (nb_significant_coeff_flag != nb0)
1404 14776659 implicit_non_zero_coeff = 0;
1405
2/2
✓ Branch 136 → 137 taken 18389127 times.
✓ Branch 136 → 151 taken 81737 times.
18470864 if (implicit_non_zero_coeff == 0) {
1406
4/4
✓ Branch 137 → 138 taken 685361 times.
✓ Branch 137 → 144 taken 17703766 times.
✓ Branch 138 → 139 taken 591196 times.
✓ Branch 138 → 140 taken 94165 times.
18389127 if (sps->transform_skip_context_enabled &&
1407
1/2
✗ Branch 139 → 140 not taken.
✓ Branch 139 → 144 taken 591196 times.
591196 (transform_skip_flag || lc->cu.cu_transquant_bypass_flag)) {
1408
2/2
✓ Branch 140 → 141 taken 40977 times.
✓ Branch 140 → 142 taken 53188 times.
94165 if (c_idx == 0) {
1409 40977 scf_offset = 42;
1410 } else {
1411 53188 scf_offset = 16 + 27;
1412 }
1413 } else {
1414
2/2
✓ Branch 144 → 145 taken 11113030 times.
✓ Branch 144 → 148 taken 7181932 times.
18294962 if (i == 0) {
1415
2/2
✓ Branch 145 → 146 taken 8454981 times.
✓ Branch 145 → 147 taken 2658049 times.
11113030 if (c_idx == 0)
1416 8454981 scf_offset = 0;
1417 else
1418 2658049 scf_offset = 27;
1419 } else {
1420 7181932 scf_offset = 2 + scf_offset;
1421 }
1422 }
1423 18389127 significant_coeff_flag_idx[nb_significant_coeff_flag] = 0;
1424 18389127 nb_significant_coeff_flag +=
1425 18389127 significant_coeff_flag_decode_0(lc, c_idx, scf_offset);
1426 } else {
1427 81737 significant_coeff_flag_idx[nb_significant_coeff_flag] = 0;
1428 81737 nb_significant_coeff_flag++;
1429 }
1430 }
1431
1432 25214700 n_end = nb_significant_coeff_flag;
1433
1434
1435
2/2
✓ Branch 152 → 153 taken 21796811 times.
✓ Branch 152 → 250 taken 3417889 times.
25214700 if (n_end) {
1436 int first_nz_pos_in_cg;
1437 int last_nz_pos_in_cg;
1438 21796811 int c_rice_param = 0;
1439 21796811 int first_greater1_coeff_idx = -1;
1440 uint8_t coeff_abs_level_greater1_flag[8];
1441 uint16_t coeff_sign_flag;
1442 21796811 int sum_abs = 0;
1443 int sign_hidden;
1444 int sb_type;
1445 21796811 int gt1_mask = 0;
1446
1447
1448 // initialize first elem of coeff_bas_level_greater1_flag
1449
4/4
✓ Branch 153 → 154 taken 7657345 times.
✓ Branch 153 → 156 taken 14139466 times.
✓ Branch 154 → 155 taken 6434494 times.
✓ Branch 154 → 156 taken 1222851 times.
21796811 int ctx_set = (i > 0 && c_idx == 0) ? 2 : 0;
1450
1451
2/2
✓ Branch 157 → 158 taken 769625 times.
✓ Branch 157 → 168 taken 21027186 times.
21796811 if (sps->persistent_rice_adaptation_enabled) {
1452
3/4
✓ Branch 158 → 159 taken 685062 times.
✓ Branch 158 → 164 taken 84563 times.
✓ Branch 159 → 160 taken 685062 times.
✗ Branch 159 → 164 not taken.
769625 if (!transform_skip_flag && !lc->cu.cu_transquant_bypass_flag)
1453
2/2
✓ Branch 160 → 161 taken 224053 times.
✓ Branch 160 → 162 taken 461009 times.
685062 sb_type = 2 * (c_idx == 0 ? 1 : 0);
1454 else
1455
2/2
✓ Branch 164 → 165 taken 36677 times.
✓ Branch 164 → 166 taken 47886 times.
84563 sb_type = 2 * (c_idx == 0 ? 1 : 0) + 1;
1456 769625 c_rice_param = lc->sub.stat_coeff[sb_type] / 4;
1457 }
1458
1459
4/4
✓ Branch 168 → 169 taken 7503978 times.
✓ Branch 168 → 171 taken 14292833 times.
✓ Branch 169 → 170 taken 3068711 times.
✓ Branch 169 → 171 taken 4435267 times.
21796811 if (!(i == num_last_subset) && greater1_ctx == 0)
1460 3068711 ctx_set++;
1461 21796811 greater1_ctx = 1;
1462 21796811 last_nz_pos_in_cg = significant_coeff_flag_idx[0];
1463
1464 // fresh bins: branchless context update, first set index from the mask
1465
2/2
✓ Branch 174 → 172 taken 86532352 times.
✓ Branch 174 → 175 taken 21796811 times.
108329163 for (m = 0; m < (n_end > 8 ? 8 : n_end); m++) {
1466 86532352 int inc = (ctx_set << 2) + greater1_ctx;
1467 86532352 int flag = coeff_abs_level_greater1_flag_decode(lc, c_idx, inc);
1468 86532352 coeff_abs_level_greater1_flag[m] = flag;
1469 86532352 gt1_mask |= flag << m;
1470 86532352 greater1_ctx = (greater1_ctx + (greater1_ctx - 1U < 2)) & (flag - 1);
1471 }
1472
2/2
✓ Branch 175 → 176 taken 9392820 times.
✓ Branch 175 → 177 taken 12403991 times.
21796811 if (gt1_mask)
1473 9392820 first_greater1_coeff_idx = ff_ctz(gt1_mask);
1474 21796811 first_nz_pos_in_cg = significant_coeff_flag_idx[n_end - 1];
1475
1476
2/2
✓ Branch 177 → 178 taken 21077869 times.
✓ Branch 177 → 184 taken 718942 times.
21796811 if (lc->cu.cu_transquant_bypass_flag ||
1477
2/2
✓ Branch 178 → 179 taken 11508968 times.
✓ Branch 178 → 183 taken 9568901 times.
21077869 (lc->cu.pred_mode == MODE_INTRA &&
1478
6/6
✓ Branch 179 → 180 taken 505772 times.
✓ Branch 179 → 183 taken 11003196 times.
✓ Branch 180 → 181 taken 57405 times.
✓ Branch 180 → 183 taken 448367 times.
✓ Branch 181 → 182 taken 29611 times.
✓ Branch 181 → 184 taken 27794 times.
11508968 sps->implicit_rdpcm_enabled && transform_skip_flag &&
1479
4/4
✓ Branch 182 → 183 taken 16913 times.
✓ Branch 182 → 184 taken 12698 times.
✓ Branch 183 → 184 taken 5999 times.
✓ Branch 183 → 185 taken 21031378 times.
21050075 (pred_mode_intra == 10 || pred_mode_intra == 26 )) ||
1480 explicit_rdpcm_flag)
1481 765433 sign_hidden = 0;
1482 else
1483 21031378 sign_hidden = (last_nz_pos_in_cg - first_nz_pos_in_cg >= 4);
1484
1485
2/2
✓ Branch 186 → 187 taken 9392820 times.
✓ Branch 186 → 189 taken 12403991 times.
21796811 if (first_greater1_coeff_idx != -1) {
1486 9392820 coeff_abs_level_greater1_flag[first_greater1_coeff_idx] += coeff_abs_level_greater2_flag_decode(lc, c_idx, ctx_set);
1487 }
1488
4/4
✓ Branch 189 → 190 taken 17531490 times.
✓ Branch 189 → 191 taken 4265321 times.
✓ Branch 190 → 191 taken 7807557 times.
✓ Branch 190 → 193 taken 9723933 times.
21796811 if (!pps->sign_data_hiding_flag || !sign_hidden ) {
1489 12072878 coeff_sign_flag = coeff_sign_flag_decode(lc, nb_significant_coeff_flag) << (16 - nb_significant_coeff_flag);
1490 } else {
1491 9723933 coeff_sign_flag = coeff_sign_flag_decode(lc, nb_significant_coeff_flag - 1) << (16 - (nb_significant_coeff_flag - 1));
1492 }
1493
1494
2/2
✓ Branch 248 → 196 taken 102561357 times.
✓ Branch 248 → 249 taken 21796811 times.
124358168 for (m = 0; m < n_end; m++) {
1495 int64_t sign;
1496
1497 102561357 n = significant_coeff_flag_idx[m];
1498 102561357 GET_COORD(offset, n);
1499
2/2
✓ Branch 196 → 197 taken 86532352 times.
✓ Branch 196 → 214 taken 16029005 times.
102561357 if (m < 8) {
1500 86532352 trans_coeff_level = 1 + coeff_abs_level_greater1_flag[m];
1501
4/4
✓ Branch 197 → 198 taken 9392820 times.
✓ Branch 197 → 199 taken 77139532 times.
✓ Branch 200 → 201 taken 20879093 times.
✓ Branch 200 → 227 taken 65653259 times.
86532352 if (trans_coeff_level == ((m == first_greater1_coeff_idx) ? 3 : 2)) {
1502 20879093 int last_coeff_abs_level_remaining = coeff_abs_level_remaining_decode(lc, c_rice_param);
1503
1504 20879093 trans_coeff_level += last_coeff_abs_level_remaining;
1505
2/2
✓ Branch 202 → 203 taken 5280154 times.
✓ Branch 202 → 206 taken 15598939 times.
20879093 if (trans_coeff_level > (3 << c_rice_param))
1506
2/2
✓ Branch 203 → 204 taken 107884 times.
✓ Branch 203 → 205 taken 5172270 times.
5280154 c_rice_param = sps->persistent_rice_adaptation_enabled ? c_rice_param + 1 : FFMIN(c_rice_param + 1, 4);
1507
4/4
✓ Branch 206 → 207 taken 601790 times.
✓ Branch 206 → 227 taken 20277303 times.
✓ Branch 207 → 208 taken 182004 times.
✓ Branch 207 → 227 taken 419786 times.
20879093 if (sps->persistent_rice_adaptation_enabled && !rice_init) {
1508 182004 int c_rice_p_init = lc->sub.stat_coeff[sb_type] / 4;
1509
2/2
✓ Branch 208 → 209 taken 20309 times.
✓ Branch 208 → 210 taken 161695 times.
182004 if (last_coeff_abs_level_remaining >= (3 << c_rice_p_init))
1510 20309 lc->sub.stat_coeff[sb_type]++;
1511
2/2
✓ Branch 210 → 211 taken 93774 times.
✓ Branch 210 → 213 taken 67921 times.
161695 else if (2 * last_coeff_abs_level_remaining < (1 << c_rice_p_init))
1512
2/2
✓ Branch 211 → 212 taken 20285 times.
✓ Branch 211 → 213 taken 73489 times.
93774 if (lc->sub.stat_coeff[sb_type] > 0)
1513 20285 lc->sub.stat_coeff[sb_type]--;
1514 182004 rice_init = 1;
1515 }
1516 }
1517 } else {
1518 16029005 int last_coeff_abs_level_remaining = coeff_abs_level_remaining_decode(lc, c_rice_param);
1519
1520 16029005 trans_coeff_level = 1 + last_coeff_abs_level_remaining;
1521
2/2
✓ Branch 215 → 216 taken 1830372 times.
✓ Branch 215 → 219 taken 14198633 times.
16029005 if (trans_coeff_level > (3 << c_rice_param))
1522
2/2
✓ Branch 216 → 217 taken 47948 times.
✓ Branch 216 → 218 taken 1782424 times.
1830372 c_rice_param = sps->persistent_rice_adaptation_enabled ? c_rice_param + 1 : FFMIN(c_rice_param + 1, 4);
1523
4/4
✓ Branch 219 → 220 taken 495525 times.
✓ Branch 219 → 227 taken 15533480 times.
✓ Branch 220 → 221 taken 22670 times.
✓ Branch 220 → 227 taken 472855 times.
16029005 if (sps->persistent_rice_adaptation_enabled && !rice_init) {
1524 22670 int c_rice_p_init = lc->sub.stat_coeff[sb_type] / 4;
1525
2/2
✓ Branch 221 → 222 taken 785 times.
✓ Branch 221 → 223 taken 21885 times.
22670 if (last_coeff_abs_level_remaining >= (3 << c_rice_p_init))
1526 785 lc->sub.stat_coeff[sb_type]++;
1527
2/2
✓ Branch 223 → 224 taken 15387 times.
✓ Branch 223 → 226 taken 6498 times.
21885 else if (2 * last_coeff_abs_level_remaining < (1 << c_rice_p_init))
1528
2/2
✓ Branch 224 → 225 taken 744 times.
✓ Branch 224 → 226 taken 14643 times.
15387 if (lc->sub.stat_coeff[sb_type] > 0)
1529 744 lc->sub.stat_coeff[sb_type]--;
1530 22670 rice_init = 1;
1531 }
1532 }
1533
4/4
✓ Branch 227 → 228 taken 90784632 times.
✓ Branch 227 → 232 taken 11776725 times.
✓ Branch 228 → 229 taken 69875836 times.
✓ Branch 228 → 232 taken 20908796 times.
102561357 if (pps->sign_data_hiding_flag && sign_hidden) {
1534 69875836 sum_abs += trans_coeff_level;
1535
4/4
✓ Branch 229 → 230 taken 9723933 times.
✓ Branch 229 → 232 taken 60151903 times.
✓ Branch 230 → 231 taken 4844351 times.
✓ Branch 230 → 232 taken 4879582 times.
69875836 if (n == first_nz_pos_in_cg && (sum_abs&1))
1536 4844351 trans_coeff_level = -trans_coeff_level;
1537 }
1538 // equiprobable sign: apply it branchless
1539 102561357 sign = -(int64_t)(coeff_sign_flag >> 15);
1540 102561357 trans_coeff_level = (trans_coeff_level ^ sign) - sign;
1541 102561357 coeff_sign_flag <<= 1;
1542
2/2
✓ Branch 232 → 233 taken 93733974 times.
✓ Branch 232 → 247 taken 8827383 times.
102561357 if(!lc->cu.cu_transquant_bypass_flag) {
1543
6/6
✓ Branch 233 → 234 taken 3256495 times.
✓ Branch 233 → 246 taken 90477479 times.
✓ Branch 234 → 235 taken 124715 times.
✓ Branch 234 → 236 taken 3131780 times.
✓ Branch 235 → 236 taken 25373 times.
✓ Branch 235 → 246 taken 99342 times.
93733974 if (sps->scaling_list_enabled && !(transform_skip_flag && log2_trafo_size > 2)) {
1544
6/6
✓ Branch 236 → 237 taken 1014069 times.
✓ Branch 236 → 239 taken 2143084 times.
✓ Branch 237 → 238 taken 456467 times.
✓ Branch 237 → 239 taken 557602 times.
✓ Branch 238 → 239 taken 372832 times.
✓ Branch 238 → 245 taken 83635 times.
3157153 if(y_c || x_c || log2_trafo_size < 4) {
1545
4/4
✓ Branch 239 → 240 taken 731538 times.
✓ Branch 239 → 241 taken 926236 times.
✓ Branch 239 → 242 taken 413079 times.
✓ Branch 239 → 243 taken 1002665 times.
3073518 switch(log2_trafo_size) {
1546 731538 case 3: pos = (y_c << 3) + x_c; break;
1547 926236 case 4: pos = ((y_c >> 1) << 3) + (x_c >> 1); break;
1548 413079 case 5: pos = ((y_c >> 2) << 3) + (x_c >> 2); break;
1549 1002665 default: pos = (y_c << 2) + x_c; break;
1550 }
1551 3073518 scale_m = scale_matrix[pos];
1552 } else {
1553 83635 scale_m = dc_scale;
1554 }
1555 }
1556 93733974 trans_coeff_level = (trans_coeff_level * (int64_t)scale * (int64_t)scale_m + add) >> shift;
1557 93733974 trans_coeff_level = FFMAX(FFMIN(trans_coeff_level, 32767), -32768);
1558 }
1559 102561357 coeffs[y_c * trafo_size + x_c] = trans_coeff_level;
1560 }
1561 }
1562 }
1563
1564
2/2
✓ Branch 252 → 253 taken 424198 times.
✓ Branch 252 → 261 taken 13868635 times.
14292833 if (lc->cu.cu_transquant_bypass_flag) {
1565
2/6
✓ Branch 253 → 254 taken 424198 times.
✗ Branch 253 → 257 not taken.
✗ Branch 254 → 255 not taken.
✓ Branch 254 → 288 taken 424198 times.
✗ Branch 255 → 256 not taken.
✗ Branch 255 → 257 not taken.
424198 if (explicit_rdpcm_flag || (sps->implicit_rdpcm_enabled &&
1566
0/2
✗ Branch 256 → 257 not taken.
✗ Branch 256 → 288 not taken.
✗ (pred_mode_intra == 10 || pred_mode_intra == 26))) {
1567
0/2
✗ Branch 257 → 258 not taken.
✗ Branch 257 → 259 not taken.
✗ int mode = sps->implicit_rdpcm_enabled ? (pred_mode_intra == 26) : explicit_rdpcm_dir_flag;
1568
1569 ✗ s->hevcdsp.transform_rdpcm(coeffs, log2_trafo_size, mode);
1570 }
1571 } else {
1572
2/2
✓ Branch 261 → 262 taken 394709 times.
✓ Branch 261 → 281 taken 13473926 times.
13868635 if (transform_skip_flag) {
1573
2/2
✓ Branch 263 → 264 taken 45633 times.
✓ Branch 263 → 266 taken 14213 times.
59846 int rot = sps->transform_skip_rotation_enabled &&
1574
2/2
✓ Branch 262 → 263 taken 59846 times.
✓ Branch 262 → 266 taken 334863 times.
454555 log2_trafo_size == 2 &&
1575
2/2
✓ Branch 264 → 265 taken 11850 times.
✓ Branch 264 → 266 taken 33783 times.
45633 lc->cu.pred_mode == MODE_INTRA;
1576
2/2
✓ Branch 267 → 268 taken 11850 times.
✓ Branch 267 → 271 taken 382859 times.
394709 if (rot) {
1577
2/2
✓ Branch 270 → 269 taken 94800 times.
✓ Branch 270 → 271 taken 11850 times.
106650 for (i = 0; i < 8; i++)
1578 94800 FFSWAP(int16_t, coeffs[i], coeffs[16 - i - 1]);
1579 }
1580
1581 394709 s->hevcdsp.dequant(coeffs, log2_trafo_size);
1582
1583
4/4
✓ Branch 272 → 273 taken 391619 times.
✓ Branch 272 → 277 taken 3090 times.
✓ Branch 273 → 274 taken 56756 times.
✓ Branch 273 → 288 taken 334863 times.
394709 if (explicit_rdpcm_flag || (sps->implicit_rdpcm_enabled &&
1584
4/4
✓ Branch 274 → 275 taken 24612 times.
✓ Branch 274 → 288 taken 32144 times.
✓ Branch 275 → 276 taken 15060 times.
✓ Branch 275 → 277 taken 9552 times.
56756 lc->cu.pred_mode == MODE_INTRA &&
1585
2/2
✓ Branch 276 → 277 taken 5302 times.
✓ Branch 276 → 288 taken 9758 times.
15060 (pred_mode_intra == 10 || pred_mode_intra == 26))) {
1586
2/2
✓ Branch 277 → 278 taken 14854 times.
✓ Branch 277 → 279 taken 3090 times.
17944 int mode = explicit_rdpcm_flag ? explicit_rdpcm_dir_flag : (pred_mode_intra == 26);
1587
1588 17944 s->hevcdsp.transform_rdpcm(coeffs, log2_trafo_size, mode);
1589 }
1590
6/6
✓ Branch 281 → 282 taken 7874895 times.
✓ Branch 281 → 285 taken 5599031 times.
✓ Branch 282 → 283 taken 5547867 times.
✓ Branch 282 → 285 taken 2327028 times.
✓ Branch 283 → 284 taken 3172779 times.
✓ Branch 283 → 285 taken 2375088 times.
13473926 } else if (lc->cu.pred_mode == MODE_INTRA && c_idx == 0 && log2_trafo_size == 2) {
1591 3172779 s->hevcdsp.transform_4x4_luma(coeffs);
1592 } else {
1593
2/2
✓ Branch 285 → 286 taken 2494563 times.
✓ Branch 285 → 287 taken 7806584 times.
10301147 if (max_xy == 0)
1594 2494563 s->hevcdsp.idct_dc[log2_trafo_size - 2](coeffs);
1595 else
1596 7806584 s->hevcdsp.idct[log2_trafo_size - 2](coeffs, col_limit);
1597 }
1598 }
1599
2/2
✓ Branch 288 → 289 taken 171429 times.
✓ Branch 288 → 292 taken 14121404 times.
14292833 if (lc->tu.cross_pf) {
1600 171429 int16_t *coeffs_y = (int16_t*)lc->edge_emu_buffer;
1601
1602
2/2
✓ Branch 291 → 290 taken 13540080 times.
✓ Branch 291 → 292 taken 171429 times.
13711509 for (i = 0; i < (trafo_size * trafo_size); i++) {
1603 13540080 coeffs[i] = coeffs[i] + ((lc->tu.res_scale_val * coeffs_y[i]) >> 3);
1604 }
1605 }
1606 14292833 s->hevcdsp.add_residual[log2_trafo_size-2](dst, coeffs, stride);
1607 14292833 }
1608
1609 3379290 void ff_hevc_hls_mvd_coding(HEVCLocalContext *lc, int x0, int y0, int log2_cb_size)
1610 {
1611 3379290 int x = abs_mvd_greater0_flag_decode(lc);
1612 3379290 int y = abs_mvd_greater0_flag_decode(lc);
1613
1614
2/2
✓ Branch 4 → 5 taken 2318699 times.
✓ Branch 4 → 7 taken 1060591 times.
3379290 if (x)
1615 2318699 x += abs_mvd_greater1_flag_decode(lc);
1616
2/2
✓ Branch 7 → 8 taken 2223931 times.
✓ Branch 7 → 10 taken 1155359 times.
3379290 if (y)
1617 2223931 y += abs_mvd_greater1_flag_decode(lc);
1618
1619
3/4
✓ Branch 10 → 11 taken 1611646 times.
✓ Branch 10 → 13 taken 707053 times.
✓ Branch 10 → 15 taken 1060591 times.
✗ Branch 10 → 16 not taken.
3379290 switch (x) {
1620 1611646 case 2: lc->pu.mvd.x = mvd_decode(lc); break;
1621 707053 case 1: lc->pu.mvd.x = mvd_sign_flag_decode(lc); break;
1622 1060591 case 0: lc->pu.mvd.x = 0; break;
1623 }
1624
1625
3/4
✓ Branch 16 → 17 taken 1501100 times.
✓ Branch 16 → 19 taken 722831 times.
✓ Branch 16 → 21 taken 1155359 times.
✗ Branch 16 → 22 not taken.
3379290 switch (y) {
1626 1501100 case 2: lc->pu.mvd.y = mvd_decode(lc); break;
1627 722831 case 1: lc->pu.mvd.y = mvd_sign_flag_decode(lc); break;
1628 1155359 case 0: lc->pu.mvd.y = 0; break;
1629 }
1630 3379290 }
1631