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 "cabac_functions.h" | ||
28 | #include "hevc_data.h" | ||
29 | #include "hevc.h" | ||
30 | #include "hevcdec.h" | ||
31 | |||
32 | #define CABAC_MAX_BIN 31 | ||
33 | |||
34 | /** | ||
35 | * number of bin by SyntaxElement. | ||
36 | */ | ||
37 | static const int8_t num_bins_in_se[] = { | ||
38 | 1, // sao_merge_flag | ||
39 | 1, // sao_type_idx | ||
40 | 0, // sao_eo_class | ||
41 | 0, // sao_band_position | ||
42 | 0, // sao_offset_abs | ||
43 | 0, // sao_offset_sign | ||
44 | 0, // end_of_slice_flag | ||
45 | 3, // split_coding_unit_flag | ||
46 | 1, // cu_transquant_bypass_flag | ||
47 | 3, // skip_flag | ||
48 | 3, // cu_qp_delta | ||
49 | 1, // pred_mode | ||
50 | 4, // part_mode | ||
51 | 0, // pcm_flag | ||
52 | 1, // prev_intra_luma_pred_mode | ||
53 | 0, // mpm_idx | ||
54 | 0, // rem_intra_luma_pred_mode | ||
55 | 2, // intra_chroma_pred_mode | ||
56 | 1, // merge_flag | ||
57 | 1, // merge_idx | ||
58 | 5, // inter_pred_idc | ||
59 | 2, // ref_idx_l0 | ||
60 | 2, // ref_idx_l1 | ||
61 | 2, // abs_mvd_greater0_flag | ||
62 | 2, // abs_mvd_greater1_flag | ||
63 | 0, // abs_mvd_minus2 | ||
64 | 0, // mvd_sign_flag | ||
65 | 1, // mvp_lx_flag | ||
66 | 1, // no_residual_data_flag | ||
67 | 3, // split_transform_flag | ||
68 | 2, // cbf_luma | ||
69 | 5, // cbf_cb, cbf_cr | ||
70 | 2, // transform_skip_flag[][] | ||
71 | 2, // explicit_rdpcm_flag[][] | ||
72 | 2, // explicit_rdpcm_dir_flag[][] | ||
73 | 18, // last_significant_coeff_x_prefix | ||
74 | 18, // last_significant_coeff_y_prefix | ||
75 | 0, // last_significant_coeff_x_suffix | ||
76 | 0, // last_significant_coeff_y_suffix | ||
77 | 4, // significant_coeff_group_flag | ||
78 | 44, // significant_coeff_flag | ||
79 | 24, // coeff_abs_level_greater1_flag | ||
80 | 6, // coeff_abs_level_greater2_flag | ||
81 | 0, // coeff_abs_level_remaining | ||
82 | 0, // coeff_sign_flag | ||
83 | 8, // log2_res_scale_abs | ||
84 | 2, // res_scale_sign_flag | ||
85 | 1, // cu_chroma_qp_offset_flag | ||
86 | 1, // cu_chroma_qp_offset_idx | ||
87 | }; | ||
88 | |||
89 | /** | ||
90 | * Offset to ctxIdx 0 in init_values and states, indexed by SyntaxElement. | ||
91 | */ | ||
92 | static const int elem_offset[sizeof(num_bins_in_se)] = { | ||
93 | 0, // sao_merge_flag | ||
94 | 1, // sao_type_idx | ||
95 | 2, // sao_eo_class | ||
96 | 2, // sao_band_position | ||
97 | 2, // sao_offset_abs | ||
98 | 2, // sao_offset_sign | ||
99 | 2, // end_of_slice_flag | ||
100 | 2, // split_coding_unit_flag | ||
101 | 5, // cu_transquant_bypass_flag | ||
102 | 6, // skip_flag | ||
103 | 9, // cu_qp_delta | ||
104 | 12, // pred_mode | ||
105 | 13, // part_mode | ||
106 | 17, // pcm_flag | ||
107 | 17, // prev_intra_luma_pred_mode | ||
108 | 18, // mpm_idx | ||
109 | 18, // rem_intra_luma_pred_mode | ||
110 | 18, // intra_chroma_pred_mode | ||
111 | 20, // merge_flag | ||
112 | 21, // merge_idx | ||
113 | 22, // inter_pred_idc | ||
114 | 27, // ref_idx_l0 | ||
115 | 29, // ref_idx_l1 | ||
116 | 31, // abs_mvd_greater0_flag | ||
117 | 33, // abs_mvd_greater1_flag | ||
118 | 35, // abs_mvd_minus2 | ||
119 | 35, // mvd_sign_flag | ||
120 | 35, // mvp_lx_flag | ||
121 | 36, // no_residual_data_flag | ||
122 | 37, // split_transform_flag | ||
123 | 40, // cbf_luma | ||
124 | 42, // cbf_cb, cbf_cr | ||
125 | 47, // transform_skip_flag[][] | ||
126 | 49, // explicit_rdpcm_flag[][] | ||
127 | 51, // explicit_rdpcm_dir_flag[][] | ||
128 | 53, // last_significant_coeff_x_prefix | ||
129 | 71, // last_significant_coeff_y_prefix | ||
130 | 89, // last_significant_coeff_x_suffix | ||
131 | 89, // last_significant_coeff_y_suffix | ||
132 | 89, // significant_coeff_group_flag | ||
133 | 93, // significant_coeff_flag | ||
134 | 137, // coeff_abs_level_greater1_flag | ||
135 | 161, // coeff_abs_level_greater2_flag | ||
136 | 167, // coeff_abs_level_remaining | ||
137 | 167, // coeff_sign_flag | ||
138 | 167, // log2_res_scale_abs | ||
139 | 175, // res_scale_sign_flag | ||
140 | 177, // cu_chroma_qp_offset_flag | ||
141 | 178, // cu_chroma_qp_offset_idx | ||
142 | }; | ||
143 | |||
144 | #define CNU 154 | ||
145 | /** | ||
146 | * Indexed by init_type | ||
147 | */ | ||
148 | static const uint8_t init_values[3][HEVC_CONTEXTS] = { | ||
149 | { // sao_merge_flag | ||
150 | 153, | ||
151 | // sao_type_idx | ||
152 | 200, | ||
153 | // split_coding_unit_flag | ||
154 | 139, 141, 157, | ||
155 | // cu_transquant_bypass_flag | ||
156 | 154, | ||
157 | // skip_flag | ||
158 | CNU, CNU, CNU, | ||
159 | // cu_qp_delta | ||
160 | 154, 154, 154, | ||
161 | // pred_mode | ||
162 | CNU, | ||
163 | // part_mode | ||
164 | 184, CNU, CNU, CNU, | ||
165 | // prev_intra_luma_pred_mode | ||
166 | 184, | ||
167 | // intra_chroma_pred_mode | ||
168 | 63, 139, | ||
169 | // merge_flag | ||
170 | CNU, | ||
171 | // merge_idx | ||
172 | CNU, | ||
173 | // inter_pred_idc | ||
174 | CNU, CNU, CNU, CNU, CNU, | ||
175 | // ref_idx_l0 | ||
176 | CNU, CNU, | ||
177 | // ref_idx_l1 | ||
178 | CNU, CNU, | ||
179 | // abs_mvd_greater1_flag | ||
180 | CNU, CNU, | ||
181 | // abs_mvd_greater1_flag | ||
182 | CNU, CNU, | ||
183 | // mvp_lx_flag | ||
184 | CNU, | ||
185 | // no_residual_data_flag | ||
186 | CNU, | ||
187 | // split_transform_flag | ||
188 | 153, 138, 138, | ||
189 | // cbf_luma | ||
190 | 111, 141, | ||
191 | // cbf_cb, cbf_cr | ||
192 | 94, 138, 182, 154, 154, | ||
193 | // transform_skip_flag | ||
194 | 139, 139, | ||
195 | // explicit_rdpcm_flag | ||
196 | 139, 139, | ||
197 | // explicit_rdpcm_dir_flag | ||
198 | 139, 139, | ||
199 | // last_significant_coeff_x_prefix | ||
200 | 110, 110, 124, 125, 140, 153, 125, 127, 140, 109, 111, 143, 127, 111, | ||
201 | 79, 108, 123, 63, | ||
202 | // last_significant_coeff_y_prefix | ||
203 | 110, 110, 124, 125, 140, 153, 125, 127, 140, 109, 111, 143, 127, 111, | ||
204 | 79, 108, 123, 63, | ||
205 | // significant_coeff_group_flag | ||
206 | 91, 171, 134, 141, | ||
207 | // significant_coeff_flag | ||
208 | 111, 111, 125, 110, 110, 94, 124, 108, 124, 107, 125, 141, 179, 153, | ||
209 | 125, 107, 125, 141, 179, 153, 125, 107, 125, 141, 179, 153, 125, 140, | ||
210 | 139, 182, 182, 152, 136, 152, 136, 153, 136, 139, 111, 136, 139, 111, | ||
211 | 141, 111, | ||
212 | // coeff_abs_level_greater1_flag | ||
213 | 140, 92, 137, 138, 140, 152, 138, 139, 153, 74, 149, 92, 139, 107, | ||
214 | 122, 152, 140, 179, 166, 182, 140, 227, 122, 197, | ||
215 | // coeff_abs_level_greater2_flag | ||
216 | 138, 153, 136, 167, 152, 152, | ||
217 | // log2_res_scale_abs | ||
218 | 154, 154, 154, 154, 154, 154, 154, 154, | ||
219 | // res_scale_sign_flag | ||
220 | 154, 154, | ||
221 | // cu_chroma_qp_offset_flag | ||
222 | 154, | ||
223 | // cu_chroma_qp_offset_idx | ||
224 | 154, | ||
225 | }, | ||
226 | { // sao_merge_flag | ||
227 | 153, | ||
228 | // sao_type_idx | ||
229 | 185, | ||
230 | // split_coding_unit_flag | ||
231 | 107, 139, 126, | ||
232 | // cu_transquant_bypass_flag | ||
233 | 154, | ||
234 | // skip_flag | ||
235 | 197, 185, 201, | ||
236 | // cu_qp_delta | ||
237 | 154, 154, 154, | ||
238 | // pred_mode | ||
239 | 149, | ||
240 | // part_mode | ||
241 | 154, 139, 154, 154, | ||
242 | // prev_intra_luma_pred_mode | ||
243 | 154, | ||
244 | // intra_chroma_pred_mode | ||
245 | 152, 139, | ||
246 | // merge_flag | ||
247 | 110, | ||
248 | // merge_idx | ||
249 | 122, | ||
250 | // inter_pred_idc | ||
251 | 95, 79, 63, 31, 31, | ||
252 | // ref_idx_l0 | ||
253 | 153, 153, | ||
254 | // ref_idx_l1 | ||
255 | 153, 153, | ||
256 | // abs_mvd_greater1_flag | ||
257 | 140, 198, | ||
258 | // abs_mvd_greater1_flag | ||
259 | 140, 198, | ||
260 | // mvp_lx_flag | ||
261 | 168, | ||
262 | // no_residual_data_flag | ||
263 | 79, | ||
264 | // split_transform_flag | ||
265 | 124, 138, 94, | ||
266 | // cbf_luma | ||
267 | 153, 111, | ||
268 | // cbf_cb, cbf_cr | ||
269 | 149, 107, 167, 154, 154, | ||
270 | // transform_skip_flag | ||
271 | 139, 139, | ||
272 | // explicit_rdpcm_flag | ||
273 | 139, 139, | ||
274 | // explicit_rdpcm_dir_flag | ||
275 | 139, 139, | ||
276 | // last_significant_coeff_x_prefix | ||
277 | 125, 110, 94, 110, 95, 79, 125, 111, 110, 78, 110, 111, 111, 95, | ||
278 | 94, 108, 123, 108, | ||
279 | // last_significant_coeff_y_prefix | ||
280 | 125, 110, 94, 110, 95, 79, 125, 111, 110, 78, 110, 111, 111, 95, | ||
281 | 94, 108, 123, 108, | ||
282 | // significant_coeff_group_flag | ||
283 | 121, 140, 61, 154, | ||
284 | // significant_coeff_flag | ||
285 | 155, 154, 139, 153, 139, 123, 123, 63, 153, 166, 183, 140, 136, 153, | ||
286 | 154, 166, 183, 140, 136, 153, 154, 166, 183, 140, 136, 153, 154, 170, | ||
287 | 153, 123, 123, 107, 121, 107, 121, 167, 151, 183, 140, 151, 183, 140, | ||
288 | 140, 140, | ||
289 | // coeff_abs_level_greater1_flag | ||
290 | 154, 196, 196, 167, 154, 152, 167, 182, 182, 134, 149, 136, 153, 121, | ||
291 | 136, 137, 169, 194, 166, 167, 154, 167, 137, 182, | ||
292 | // coeff_abs_level_greater2_flag | ||
293 | 107, 167, 91, 122, 107, 167, | ||
294 | // log2_res_scale_abs | ||
295 | 154, 154, 154, 154, 154, 154, 154, 154, | ||
296 | // res_scale_sign_flag | ||
297 | 154, 154, | ||
298 | // cu_chroma_qp_offset_flag | ||
299 | 154, | ||
300 | // cu_chroma_qp_offset_idx | ||
301 | 154, | ||
302 | }, | ||
303 | { // sao_merge_flag | ||
304 | 153, | ||
305 | // sao_type_idx | ||
306 | 160, | ||
307 | // split_coding_unit_flag | ||
308 | 107, 139, 126, | ||
309 | // cu_transquant_bypass_flag | ||
310 | 154, | ||
311 | // skip_flag | ||
312 | 197, 185, 201, | ||
313 | // cu_qp_delta | ||
314 | 154, 154, 154, | ||
315 | // pred_mode | ||
316 | 134, | ||
317 | // part_mode | ||
318 | 154, 139, 154, 154, | ||
319 | // prev_intra_luma_pred_mode | ||
320 | 183, | ||
321 | // intra_chroma_pred_mode | ||
322 | 152, 139, | ||
323 | // merge_flag | ||
324 | 154, | ||
325 | // merge_idx | ||
326 | 137, | ||
327 | // inter_pred_idc | ||
328 | 95, 79, 63, 31, 31, | ||
329 | // ref_idx_l0 | ||
330 | 153, 153, | ||
331 | // ref_idx_l1 | ||
332 | 153, 153, | ||
333 | // abs_mvd_greater1_flag | ||
334 | 169, 198, | ||
335 | // abs_mvd_greater1_flag | ||
336 | 169, 198, | ||
337 | // mvp_lx_flag | ||
338 | 168, | ||
339 | // no_residual_data_flag | ||
340 | 79, | ||
341 | // split_transform_flag | ||
342 | 224, 167, 122, | ||
343 | // cbf_luma | ||
344 | 153, 111, | ||
345 | // cbf_cb, cbf_cr | ||
346 | 149, 92, 167, 154, 154, | ||
347 | // transform_skip_flag | ||
348 | 139, 139, | ||
349 | // explicit_rdpcm_flag | ||
350 | 139, 139, | ||
351 | // explicit_rdpcm_dir_flag | ||
352 | 139, 139, | ||
353 | // last_significant_coeff_x_prefix | ||
354 | 125, 110, 124, 110, 95, 94, 125, 111, 111, 79, 125, 126, 111, 111, | ||
355 | 79, 108, 123, 93, | ||
356 | // last_significant_coeff_y_prefix | ||
357 | 125, 110, 124, 110, 95, 94, 125, 111, 111, 79, 125, 126, 111, 111, | ||
358 | 79, 108, 123, 93, | ||
359 | // significant_coeff_group_flag | ||
360 | 121, 140, 61, 154, | ||
361 | // significant_coeff_flag | ||
362 | 170, 154, 139, 153, 139, 123, 123, 63, 124, 166, 183, 140, 136, 153, | ||
363 | 154, 166, 183, 140, 136, 153, 154, 166, 183, 140, 136, 153, 154, 170, | ||
364 | 153, 138, 138, 122, 121, 122, 121, 167, 151, 183, 140, 151, 183, 140, | ||
365 | 140, 140, | ||
366 | // coeff_abs_level_greater1_flag | ||
367 | 154, 196, 167, 167, 154, 152, 167, 182, 182, 134, 149, 136, 153, 121, | ||
368 | 136, 122, 169, 208, 166, 167, 154, 152, 167, 182, | ||
369 | // coeff_abs_level_greater2_flag | ||
370 | 107, 167, 91, 107, 107, 167, | ||
371 | // log2_res_scale_abs | ||
372 | 154, 154, 154, 154, 154, 154, 154, 154, | ||
373 | // res_scale_sign_flag | ||
374 | 154, 154, | ||
375 | // cu_chroma_qp_offset_flag | ||
376 | 154, | ||
377 | // cu_chroma_qp_offset_idx | ||
378 | 154, | ||
379 | }, | ||
380 | }; | ||
381 | |||
382 | static const uint8_t scan_1x1[1] = { | ||
383 | 0, | ||
384 | }; | ||
385 | |||
386 | static const uint8_t horiz_scan2x2_x[4] = { | ||
387 | 0, 1, 0, 1, | ||
388 | }; | ||
389 | |||
390 | static const uint8_t horiz_scan2x2_y[4] = { | ||
391 | 0, 0, 1, 1 | ||
392 | }; | ||
393 | |||
394 | static const uint8_t horiz_scan4x4_x[16] = { | ||
395 | 0, 1, 2, 3, | ||
396 | 0, 1, 2, 3, | ||
397 | 0, 1, 2, 3, | ||
398 | 0, 1, 2, 3, | ||
399 | }; | ||
400 | |||
401 | static const uint8_t horiz_scan4x4_y[16] = { | ||
402 | 0, 0, 0, 0, | ||
403 | 1, 1, 1, 1, | ||
404 | 2, 2, 2, 2, | ||
405 | 3, 3, 3, 3, | ||
406 | }; | ||
407 | |||
408 | static const uint8_t horiz_scan8x8_inv[8][8] = { | ||
409 | { 0, 1, 2, 3, 16, 17, 18, 19, }, | ||
410 | { 4, 5, 6, 7, 20, 21, 22, 23, }, | ||
411 | { 8, 9, 10, 11, 24, 25, 26, 27, }, | ||
412 | { 12, 13, 14, 15, 28, 29, 30, 31, }, | ||
413 | { 32, 33, 34, 35, 48, 49, 50, 51, }, | ||
414 | { 36, 37, 38, 39, 52, 53, 54, 55, }, | ||
415 | { 40, 41, 42, 43, 56, 57, 58, 59, }, | ||
416 | { 44, 45, 46, 47, 60, 61, 62, 63, }, | ||
417 | }; | ||
418 | |||
419 | static const uint8_t diag_scan2x2_x[4] = { | ||
420 | 0, 0, 1, 1, | ||
421 | }; | ||
422 | |||
423 | static const uint8_t diag_scan2x2_y[4] = { | ||
424 | 0, 1, 0, 1, | ||
425 | }; | ||
426 | |||
427 | static const uint8_t diag_scan2x2_inv[2][2] = { | ||
428 | { 0, 2, }, | ||
429 | { 1, 3, }, | ||
430 | }; | ||
431 | |||
432 | static const uint8_t diag_scan4x4_inv[4][4] = { | ||
433 | { 0, 2, 5, 9, }, | ||
434 | { 1, 4, 8, 12, }, | ||
435 | { 3, 7, 11, 14, }, | ||
436 | { 6, 10, 13, 15, }, | ||
437 | }; | ||
438 | |||
439 | static const uint8_t diag_scan8x8_inv[8][8] = { | ||
440 | { 0, 2, 5, 9, 14, 20, 27, 35, }, | ||
441 | { 1, 4, 8, 13, 19, 26, 34, 42, }, | ||
442 | { 3, 7, 12, 18, 25, 33, 41, 48, }, | ||
443 | { 6, 11, 17, 24, 32, 40, 47, 53, }, | ||
444 | { 10, 16, 23, 31, 39, 46, 52, 57, }, | ||
445 | { 15, 22, 30, 38, 45, 51, 56, 60, }, | ||
446 | { 21, 29, 37, 44, 50, 55, 59, 62, }, | ||
447 | { 28, 36, 43, 49, 54, 58, 61, 63, }, | ||
448 | }; | ||
449 | |||
450 | 1413785 | void ff_hevc_save_states(HEVCLocalContext *lc, int ctb_addr_ts) | |
451 | { | ||
452 | 1413785 | const HEVCContext *const s = lc->parent; | |
453 | |||
454 |
2/2✓ Branch 0 taken 102424 times.
✓ Branch 1 taken 1311361 times.
|
1413785 | if (s->ps.pps->entropy_coding_sync_enabled_flag && |
455 |
2/2✓ Branch 0 taken 97674 times.
✓ Branch 1 taken 4750 times.
|
102424 | (ctb_addr_ts % s->ps.sps->ctb_width == 2 || |
456 |
2/2✓ Branch 0 taken 784 times.
✓ Branch 1 taken 96890 times.
|
97674 | (s->ps.sps->ctb_width == 2 && |
457 |
2/2✓ Branch 0 taken 392 times.
✓ Branch 1 taken 392 times.
|
784 | ctb_addr_ts % s->ps.sps->ctb_width == 0))) { |
458 | 5142 | memcpy(lc->common_cabac_state->state, lc->cabac_state, HEVC_CONTEXTS); | |
459 |
2/2✓ Branch 0 taken 48 times.
✓ Branch 1 taken 5094 times.
|
5142 | if (s->ps.sps->persistent_rice_adaptation_enabled_flag) { |
460 | 48 | memcpy(lc->common_cabac_state->stat_coeff, lc->stat_coeff, HEVC_STAT_COEFFS); | |
461 | } | ||
462 | } | ||
463 | 1413785 | } | |
464 | |||
465 | 4127 | static void load_states(HEVCLocalContext *lc, const HEVCContext *s) | |
466 | { | ||
467 | 4127 | memcpy(lc->cabac_state, lc->common_cabac_state->state, HEVC_CONTEXTS); | |
468 |
2/2✓ Branch 0 taken 44 times.
✓ Branch 1 taken 4083 times.
|
4127 | if (s->ps.sps->persistent_rice_adaptation_enabled_flag) { |
469 | 44 | memcpy(lc->stat_coeff, lc->common_cabac_state->stat_coeff, HEVC_STAT_COEFFS); | |
470 | } | ||
471 | 4127 | } | |
472 | |||
473 | 7792 | static int cabac_reinit(HEVCLocalContext *lc) | |
474 | { | ||
475 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 7792 times.
|
7792 | return skip_bytes(&lc->cc, 0) == NULL ? AVERROR_INVALIDDATA : 0; |
476 | } | ||
477 | |||
478 | 27503 | static int cabac_init_decoder(HEVCLocalContext *lc) | |
479 | { | ||
480 | 27503 | GetBitContext *gb = &lc->gb; | |
481 | 27503 | skip_bits(gb, 1); | |
482 | 27503 | align_get_bits(gb); | |
483 | 82509 | return ff_init_cabac_decoder(&lc->cc, | |
484 | 27503 | gb->buffer + get_bits_count(gb) / 8, | |
485 | 27503 | (get_bits_left(gb) + 7) / 8); | |
486 | } | ||
487 | |||
488 | 24784 | static void cabac_init_state(HEVCLocalContext *lc, const HEVCContext *s) | |
489 | { | ||
490 | 24784 | int init_type = 2 - s->sh.slice_type; | |
491 | int i; | ||
492 | |||
493 |
4/4✓ Branch 0 taken 6488 times.
✓ Branch 1 taken 18296 times.
✓ Branch 2 taken 6345 times.
✓ Branch 3 taken 143 times.
|
24784 | if (s->sh.cabac_init_flag && s->sh.slice_type != HEVC_SLICE_I) |
494 | 6345 | init_type ^= 3; | |
495 | |||
496 |
2/2✓ Branch 0 taken 4932016 times.
✓ Branch 1 taken 24784 times.
|
4956800 | for (i = 0; i < HEVC_CONTEXTS; i++) { |
497 | 4932016 | int init_value = init_values[init_type][i]; | |
498 | 4932016 | int m = (init_value >> 4) * 5 - 45; | |
499 | 4932016 | int n = ((init_value & 15) << 3) - 16; | |
500 | 4932016 | int pre = 2 * (((m * av_clip(s->sh.slice_qp, 0, 51)) >> 4) + n) - 127; | |
501 | |||
502 | 4932016 | pre ^= pre >> 31; | |
503 |
2/2✓ Branch 0 taken 506332 times.
✓ Branch 1 taken 4425684 times.
|
4932016 | if (pre > 124) |
504 | 506332 | pre = 124 + (pre & 1); | |
505 | 4932016 | lc->cabac_state[i] = pre; | |
506 | } | ||
507 | |||
508 |
2/2✓ Branch 0 taken 99136 times.
✓ Branch 1 taken 24784 times.
|
123920 | for (i = 0; i < 4; i++) |
509 | 99136 | lc->stat_coeff[i] = 0; | |
510 | 24784 | } | |
511 | |||
512 | 1413786 | int ff_hevc_cabac_init(HEVCLocalContext *lc, int ctb_addr_ts) | |
513 | { | ||
514 | 1413786 | const HEVCContext *const s = lc->parent; | |
515 | |||
516 |
2/2✓ Branch 0 taken 27503 times.
✓ Branch 1 taken 1386283 times.
|
1413786 | if (ctb_addr_ts == s->ps.pps->ctb_addr_rs_to_ts[s->sh.slice_ctb_addr_rs]) { |
517 | 27503 | int ret = cabac_init_decoder(lc); | |
518 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 27503 times.
|
27503 | if (ret < 0) |
519 | ✗ | return ret; | |
520 |
2/2✓ Branch 0 taken 7947 times.
✓ Branch 1 taken 19556 times.
|
27503 | if (s->sh.dependent_slice_segment_flag == 0 || |
521 |
2/2✓ Branch 0 taken 876 times.
✓ Branch 1 taken 7071 times.
|
7947 | (s->ps.pps->tiles_enabled_flag && |
522 |
2/2✓ Branch 0 taken 309 times.
✓ Branch 1 taken 567 times.
|
876 | s->ps.pps->tile_id[ctb_addr_ts] != s->ps.pps->tile_id[ctb_addr_ts - 1])) |
523 | 19865 | cabac_init_state(lc, s); | |
524 | |||
525 |
2/2✓ Branch 0 taken 17989 times.
✓ Branch 1 taken 9514 times.
|
27503 | if (!s->sh.first_slice_in_pic_flag && |
526 |
2/2✓ Branch 0 taken 3853 times.
✓ Branch 1 taken 14136 times.
|
17989 | s->ps.pps->entropy_coding_sync_enabled_flag) { |
527 |
2/2✓ Branch 0 taken 1636 times.
✓ Branch 1 taken 2217 times.
|
3853 | if (ctb_addr_ts % s->ps.sps->ctb_width == 0) { |
528 |
2/2✓ Branch 0 taken 92 times.
✓ Branch 1 taken 1544 times.
|
1636 | if (s->ps.sps->ctb_width == 1) |
529 | 92 | cabac_init_state(lc, s); | |
530 |
2/2✓ Branch 0 taken 1162 times.
✓ Branch 1 taken 382 times.
|
1544 | else if (s->sh.dependent_slice_segment_flag == 1) |
531 | 1162 | load_states(lc, s); | |
532 | } | ||
533 | } | ||
534 | } else { | ||
535 |
2/2✓ Branch 0 taken 287199 times.
✓ Branch 1 taken 1099084 times.
|
1386283 | if (s->ps.pps->tiles_enabled_flag && |
536 |
2/2✓ Branch 0 taken 4625 times.
✓ Branch 1 taken 282574 times.
|
287199 | s->ps.pps->tile_id[ctb_addr_ts] != s->ps.pps->tile_id[ctb_addr_ts - 1]) { |
537 | int ret; | ||
538 |
1/2✓ Branch 0 taken 4625 times.
✗ Branch 1 not taken.
|
4625 | if (s->threads_number == 1) |
539 | 4625 | ret = cabac_reinit(lc); | |
540 | else { | ||
541 | ✗ | ret = cabac_init_decoder(lc); | |
542 | } | ||
543 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4625 times.
|
4625 | if (ret < 0) |
544 | ✗ | return ret; | |
545 | 4625 | cabac_init_state(lc, s); | |
546 | } | ||
547 |
2/2✓ Branch 0 taken 97840 times.
✓ Branch 1 taken 1288443 times.
|
1386283 | if (s->ps.pps->entropy_coding_sync_enabled_flag) { |
548 |
2/2✓ Branch 0 taken 3167 times.
✓ Branch 1 taken 94673 times.
|
97840 | if (ctb_addr_ts % s->ps.sps->ctb_width == 0) { |
549 | int ret; | ||
550 | 3167 | get_cabac_terminate(&lc->cc); | |
551 |
1/2✓ Branch 0 taken 3167 times.
✗ Branch 1 not taken.
|
3167 | if (s->threads_number == 1) |
552 | 3167 | ret = cabac_reinit(lc); | |
553 | else { | ||
554 | ✗ | ret = cabac_init_decoder(lc); | |
555 | } | ||
556 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3167 times.
|
3167 | if (ret < 0) |
557 | ✗ | return ret; | |
558 | |||
559 |
2/2✓ Branch 0 taken 202 times.
✓ Branch 1 taken 2965 times.
|
3167 | if (s->ps.sps->ctb_width == 1) |
560 | 202 | cabac_init_state(lc, s); | |
561 | else | ||
562 | 2965 | load_states(lc, s); | |
563 | } | ||
564 | } | ||
565 | } | ||
566 | 1413786 | return 0; | |
567 | } | ||
568 | |||
569 | #define GET_CABAC(ctx) get_cabac(&lc->cc, &lc->cabac_state[ctx]) | ||
570 | |||
571 | 815960 | int ff_hevc_sao_merge_flag_decode(HEVCLocalContext *lc) | |
572 | { | ||
573 | 815960 | return GET_CABAC(elem_offset[SAO_MERGE_FLAG]); | |
574 | } | ||
575 | |||
576 | 374219 | int ff_hevc_sao_type_idx_decode(HEVCLocalContext *lc) | |
577 | { | ||
578 |
2/2✓ Branch 1 taken 211508 times.
✓ Branch 2 taken 162711 times.
|
374219 | if (!GET_CABAC(elem_offset[SAO_TYPE_IDX])) |
579 | 211508 | return 0; | |
580 | |||
581 |
2/2✓ Branch 1 taken 53967 times.
✓ Branch 2 taken 108744 times.
|
162711 | if (!get_cabac_bypass(&lc->cc)) |
582 | 53967 | return SAO_BAND; | |
583 | 108744 | return SAO_EDGE; | |
584 | } | ||
585 | |||
586 | 77940 | int ff_hevc_sao_band_position_decode(HEVCLocalContext *lc) | |
587 | { | ||
588 | int i; | ||
589 | 77940 | int value = get_cabac_bypass(&lc->cc); | |
590 | |||
591 |
2/2✓ Branch 0 taken 311760 times.
✓ Branch 1 taken 77940 times.
|
389700 | for (i = 0; i < 4; i++) |
592 | 311760 | value = (value << 1) | get_cabac_bypass(&lc->cc); | |
593 | 77940 | return value; | |
594 | } | ||
595 | |||
596 | 870608 | int ff_hevc_sao_offset_abs_decode(HEVCLocalContext *lc) | |
597 | { | ||
598 | 870608 | int i = 0; | |
599 | 870608 | int length = (1 << (FFMIN(lc->parent->ps.sps->bit_depth, 10) - 5)) - 1; | |
600 | |||
601 |
4/4✓ Branch 0 taken 2460519 times.
✓ Branch 1 taken 127355 times.
✓ Branch 3 taken 1717266 times.
✓ Branch 4 taken 743253 times.
|
2587874 | while (i < length && get_cabac_bypass(&lc->cc)) |
602 | 1717266 | i++; | |
603 | 870608 | return i; | |
604 | } | ||
605 | |||
606 | 243123 | int ff_hevc_sao_offset_sign_decode(HEVCLocalContext *lc) | |
607 | { | ||
608 | 243123 | return get_cabac_bypass(&lc->cc); | |
609 | } | ||
610 | |||
611 | 108744 | int ff_hevc_sao_eo_class_decode(HEVCLocalContext *lc) | |
612 | { | ||
613 | 108744 | int ret = get_cabac_bypass(&lc->cc) << 1; | |
614 | 108744 | ret |= get_cabac_bypass(&lc->cc); | |
615 | 108744 | return ret; | |
616 | } | ||
617 | |||
618 | 1413785 | int ff_hevc_end_of_slice_flag_decode(HEVCLocalContext *lc) | |
619 | { | ||
620 | 1413785 | return get_cabac_terminate(&lc->cc); | |
621 | } | ||
622 | |||
623 | 200139 | int ff_hevc_cu_transquant_bypass_flag_decode(HEVCLocalContext *lc) | |
624 | { | ||
625 | 200139 | return GET_CABAC(elem_offset[CU_TRANSQUANT_BYPASS_FLAG]); | |
626 | } | ||
627 | |||
628 | 8087416 | int ff_hevc_skip_flag_decode(HEVCLocalContext *lc, int x0, int y0, int x_cb, int y_cb) | |
629 | { | ||
630 | 8087416 | const HEVCContext *const s = lc->parent; | |
631 | 8087416 | int min_cb_width = s->ps.sps->min_cb_width; | |
632 | 8087416 | int inc = 0; | |
633 | 8087416 | int x0b = av_mod_uintp2(x0, s->ps.sps->log2_ctb_size); | |
634 | 8087416 | int y0b = av_mod_uintp2(y0, s->ps.sps->log2_ctb_size); | |
635 | |||
636 |
4/4✓ Branch 0 taken 736797 times.
✓ Branch 1 taken 7350619 times.
✓ Branch 2 taken 532126 times.
✓ Branch 3 taken 204671 times.
|
8087416 | if (lc->ctb_left_flag || x0b) |
637 | 7882745 | inc = !!SAMPLE_CTB(s->skip_flag, x_cb - 1, y_cb); | |
638 |
4/4✓ Branch 0 taken 1679232 times.
✓ Branch 1 taken 6408184 times.
✓ Branch 2 taken 1222201 times.
✓ Branch 3 taken 457031 times.
|
8087416 | if (lc->ctb_up_flag || y0b) |
639 | 7630385 | inc += !!SAMPLE_CTB(s->skip_flag, x_cb, y_cb - 1); | |
640 | |||
641 | 8087416 | return GET_CABAC(elem_offset[SKIP_FLAG] + inc); | |
642 | } | ||
643 | |||
644 | 608888 | int ff_hevc_cu_qp_delta_abs(HEVCLocalContext *lc) | |
645 | { | ||
646 | 608888 | int prefix_val = 0; | |
647 | 608888 | int suffix_val = 0; | |
648 | 608888 | int inc = 0; | |
649 | |||
650 |
4/4✓ Branch 0 taken 1480406 times.
✓ Branch 1 taken 106004 times.
✓ Branch 3 taken 977522 times.
✓ Branch 4 taken 502884 times.
|
1586410 | while (prefix_val < 5 && GET_CABAC(elem_offset[CU_QP_DELTA] + inc)) { |
651 | 977522 | prefix_val++; | |
652 | 977522 | inc = 1; | |
653 | } | ||
654 |
2/2✓ Branch 0 taken 106004 times.
✓ Branch 1 taken 502884 times.
|
608888 | if (prefix_val >= 5) { |
655 | 106004 | int k = 0; | |
656 |
3/4✓ Branch 0 taken 360090 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 254086 times.
✓ Branch 4 taken 106004 times.
|
360090 | while (k < 7 && get_cabac_bypass(&lc->cc)) { |
657 | 254086 | suffix_val += 1 << k; | |
658 | 254086 | k++; | |
659 | } | ||
660 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 106004 times.
|
106004 | if (k == 7) { |
661 | ✗ | av_log(lc->logctx, AV_LOG_ERROR, "CABAC_MAX_BIN : %d\n", k); | |
662 | ✗ | return AVERROR_INVALIDDATA; | |
663 | } | ||
664 | |||
665 |
2/2✓ Branch 0 taken 254086 times.
✓ Branch 1 taken 106004 times.
|
360090 | while (k--) |
666 | 254086 | suffix_val += get_cabac_bypass(&lc->cc) << k; | |
667 | } | ||
668 | 608888 | return prefix_val + suffix_val; | |
669 | } | ||
670 | |||
671 | 369825 | int ff_hevc_cu_qp_delta_sign_flag(HEVCLocalContext *lc) | |
672 | { | ||
673 | 369825 | return get_cabac_bypass(&lc->cc); | |
674 | } | ||
675 | |||
676 | 266275 | int ff_hevc_cu_chroma_qp_offset_flag(HEVCLocalContext *lc) | |
677 | { | ||
678 | 266275 | return GET_CABAC(elem_offset[CU_CHROMA_QP_OFFSET_FLAG]); | |
679 | } | ||
680 | |||
681 | ✗ | int ff_hevc_cu_chroma_qp_offset_idx(HEVCLocalContext *lc) | |
682 | { | ||
683 | ✗ | int c_max= FFMAX(5, lc->parent->ps.pps->chroma_qp_offset_list_len_minus1); | |
684 | ✗ | int i = 0; | |
685 | |||
686 | ✗ | while (i < c_max && GET_CABAC(elem_offset[CU_CHROMA_QP_OFFSET_IDX])) | |
687 | ✗ | i++; | |
688 | |||
689 | ✗ | return i; | |
690 | } | ||
691 | |||
692 | 4197485 | int ff_hevc_pred_mode_decode(HEVCLocalContext *lc) | |
693 | { | ||
694 | 4197485 | return GET_CABAC(elem_offset[PRED_MODE_FLAG]); | |
695 | } | ||
696 | |||
697 | 7484063 | int ff_hevc_split_coding_unit_flag_decode(HEVCLocalContext *lc, int ct_depth, int x0, int y0) | |
698 | { | ||
699 | 7484063 | const HEVCContext *const s = lc->parent; | |
700 | 7484063 | const HEVCSPS *const sps = s->ps.sps; | |
701 | 7484063 | int inc = 0, depth_left = 0, depth_top = 0; | |
702 | 7484063 | int x0b = av_mod_uintp2(x0, sps->log2_ctb_size); | |
703 | 7484063 | int y0b = av_mod_uintp2(y0, sps->log2_ctb_size); | |
704 | 7484063 | int x_cb = x0 >> sps->log2_min_cb_size; | |
705 | 7484063 | int y_cb = y0 >> sps->log2_min_cb_size; | |
706 | |||
707 |
4/4✓ Branch 0 taken 694893 times.
✓ Branch 1 taken 6789170 times.
✓ Branch 2 taken 396812 times.
✓ Branch 3 taken 298081 times.
|
7484063 | if (lc->ctb_left_flag || x0b) |
708 | 7185982 | depth_left = s->tab_ct_depth[(y_cb) * sps->min_cb_width + x_cb - 1]; | |
709 |
4/4✓ Branch 0 taken 1491227 times.
✓ Branch 1 taken 5992836 times.
✓ Branch 2 taken 839471 times.
✓ Branch 3 taken 651756 times.
|
7484063 | if (lc->ctb_up_flag || y0b) |
710 | 6832307 | depth_top = s->tab_ct_depth[(y_cb - 1) * sps->min_cb_width + x_cb]; | |
711 | |||
712 | 7484063 | inc += (depth_left > ct_depth); | |
713 | 7484063 | inc += (depth_top > ct_depth); | |
714 | |||
715 | 7484063 | return GET_CABAC(elem_offset[SPLIT_CODING_UNIT_FLAG] + inc); | |
716 | } | ||
717 | |||
718 | 6167190 | int ff_hevc_part_mode_decode(HEVCLocalContext *lc, int log2_cb_size) | |
719 | { | ||
720 |
2/2✓ Branch 1 taken 3593309 times.
✓ Branch 2 taken 2573881 times.
|
6167190 | if (GET_CABAC(elem_offset[PART_MODE])) // 1 |
721 | 3593309 | return PART_2Nx2N; | |
722 |
2/2✓ Branch 0 taken 1943331 times.
✓ Branch 1 taken 630550 times.
|
2573881 | if (log2_cb_size == lc->parent->ps.sps->log2_min_cb_size) { |
723 |
2/2✓ Branch 0 taken 1194141 times.
✓ Branch 1 taken 749190 times.
|
1943331 | if (lc->cu.pred_mode == MODE_INTRA) // 0 |
724 | 1194141 | return PART_NxN; | |
725 |
2/2✓ Branch 1 taken 308106 times.
✓ Branch 2 taken 441084 times.
|
749190 | if (GET_CABAC(elem_offset[PART_MODE] + 1)) // 01 |
726 | 308106 | return PART_2NxN; | |
727 |
2/2✓ Branch 0 taken 223043 times.
✓ Branch 1 taken 218041 times.
|
441084 | if (log2_cb_size == 3) // 00 |
728 | 223043 | return PART_Nx2N; | |
729 |
2/2✓ Branch 1 taken 112405 times.
✓ Branch 2 taken 105636 times.
|
218041 | if (GET_CABAC(elem_offset[PART_MODE] + 2)) // 001 |
730 | 112405 | return PART_Nx2N; | |
731 | 105636 | return PART_NxN; // 000 | |
732 | } | ||
733 | |||
734 |
2/2✓ Branch 0 taken 65275 times.
✓ Branch 1 taken 565275 times.
|
630550 | if (!lc->parent->ps.sps->amp_enabled_flag) { |
735 |
2/2✓ Branch 1 taken 29519 times.
✓ Branch 2 taken 35756 times.
|
65275 | if (GET_CABAC(elem_offset[PART_MODE] + 1)) // 01 |
736 | 29519 | return PART_2NxN; | |
737 | 35756 | return PART_Nx2N; | |
738 | } | ||
739 | |||
740 |
2/2✓ Branch 1 taken 227404 times.
✓ Branch 2 taken 337871 times.
|
565275 | if (GET_CABAC(elem_offset[PART_MODE] + 1)) { // 01X, 01XX |
741 |
2/2✓ Branch 1 taken 108414 times.
✓ Branch 2 taken 118990 times.
|
227404 | if (GET_CABAC(elem_offset[PART_MODE] + 3)) // 011 |
742 | 108414 | return PART_2NxN; | |
743 |
2/2✓ Branch 1 taken 55211 times.
✓ Branch 2 taken 63779 times.
|
118990 | if (get_cabac_bypass(&lc->cc)) // 0101 |
744 | 55211 | return PART_2NxnD; | |
745 | 63779 | return PART_2NxnU; // 0100 | |
746 | } | ||
747 | |||
748 |
2/2✓ Branch 1 taken 164546 times.
✓ Branch 2 taken 173325 times.
|
337871 | if (GET_CABAC(elem_offset[PART_MODE] + 3)) // 001 |
749 | 164546 | return PART_Nx2N; | |
750 |
2/2✓ Branch 1 taken 80098 times.
✓ Branch 2 taken 93227 times.
|
173325 | if (get_cabac_bypass(&lc->cc)) // 0001 |
751 | 80098 | return PART_nRx2N; | |
752 | 93227 | return PART_nLx2N; // 0000 | |
753 | } | ||
754 | |||
755 | 153183 | int ff_hevc_pcm_flag_decode(HEVCLocalContext *lc) | |
756 | { | ||
757 | 153183 | return get_cabac_terminate(&lc->cc); | |
758 | } | ||
759 | |||
760 | 7542854 | int ff_hevc_prev_intra_luma_pred_flag_decode(HEVCLocalContext *lc) | |
761 | { | ||
762 | 7542854 | return GET_CABAC(elem_offset[PREV_INTRA_LUMA_PRED_FLAG]); | |
763 | } | ||
764 | |||
765 | 4523399 | int ff_hevc_mpm_idx_decode(HEVCLocalContext *lc) | |
766 | { | ||
767 | 4523399 | int i = 0; | |
768 |
4/4✓ Branch 0 taken 6738024 times.
✓ Branch 1 taken 939229 times.
✓ Branch 3 taken 3153854 times.
✓ Branch 4 taken 3584170 times.
|
7677253 | while (i < 2 && get_cabac_bypass(&lc->cc)) |
769 | 3153854 | i++; | |
770 | 4523399 | return i; | |
771 | } | ||
772 | |||
773 | 3019455 | int ff_hevc_rem_intra_luma_pred_mode_decode(HEVCLocalContext *lc) | |
774 | { | ||
775 | int i; | ||
776 | 3019455 | int value = get_cabac_bypass(&lc->cc); | |
777 | |||
778 |
2/2✓ Branch 0 taken 12077820 times.
✓ Branch 1 taken 3019455 times.
|
15097275 | for (i = 0; i < 4; i++) |
779 | 12077820 | value = (value << 1) | get_cabac_bypass(&lc->cc); | |
780 | 3019455 | return value; | |
781 | } | ||
782 | |||
783 | 4061792 | int ff_hevc_intra_chroma_pred_mode_decode(HEVCLocalContext *lc) | |
784 | { | ||
785 | int ret; | ||
786 |
2/2✓ Branch 1 taken 3032029 times.
✓ Branch 2 taken 1029763 times.
|
4061792 | if (!GET_CABAC(elem_offset[INTRA_CHROMA_PRED_MODE])) |
787 | 3032029 | return 4; | |
788 | |||
789 | 1029763 | ret = get_cabac_bypass(&lc->cc) << 1; | |
790 | 1029763 | ret |= get_cabac_bypass(&lc->cc); | |
791 | 1029763 | return ret; | |
792 | } | ||
793 | |||
794 | 6147543 | int ff_hevc_merge_idx_decode(HEVCLocalContext *lc) | |
795 | { | ||
796 | 6147543 | int i = GET_CABAC(elem_offset[MERGE_IDX]); | |
797 | |||
798 |
2/2✓ Branch 0 taken 2508492 times.
✓ Branch 1 taken 3639051 times.
|
6147543 | if (i != 0) { |
799 |
4/4✓ Branch 0 taken 3861778 times.
✓ Branch 1 taken 297803 times.
✓ Branch 3 taken 1651089 times.
✓ Branch 4 taken 2210689 times.
|
4159581 | while (i < lc->parent->sh.max_num_merge_cand-1 && get_cabac_bypass(&lc->cc)) |
800 | 1651089 | i++; | |
801 | } | ||
802 | 6147543 | return i; | |
803 | } | ||
804 | |||
805 | 4717553 | int ff_hevc_merge_flag_decode(HEVCLocalContext *lc) | |
806 | { | ||
807 | 4717553 | return GET_CABAC(elem_offset[MERGE_FLAG]); | |
808 | } | ||
809 | |||
810 | 1811787 | int ff_hevc_inter_pred_idc_decode(HEVCLocalContext *lc, int nPbW, int nPbH) | |
811 | { | ||
812 |
2/2✓ Branch 0 taken 239847 times.
✓ Branch 1 taken 1571940 times.
|
1811787 | if (nPbW + nPbH == 12) |
813 | 239847 | return GET_CABAC(elem_offset[INTER_PRED_IDC] + 4); | |
814 |
2/2✓ Branch 1 taken 404149 times.
✓ Branch 2 taken 1167791 times.
|
1571940 | if (GET_CABAC(elem_offset[INTER_PRED_IDC] + lc->ct_depth)) |
815 | 404149 | return PRED_BI; | |
816 | |||
817 | 1167791 | return GET_CABAC(elem_offset[INTER_PRED_IDC] + 4); | |
818 | } | ||
819 | |||
820 | 2787237 | int ff_hevc_ref_idx_lx_decode(HEVCLocalContext *lc, int num_ref_idx_lx) | |
821 | { | ||
822 | 2787237 | int i = 0; | |
823 | 2787237 | int max = num_ref_idx_lx - 1; | |
824 | 2787237 | int max_ctx = FFMIN(max, 2); | |
825 | |||
826 |
4/4✓ Branch 0 taken 2779079 times.
✓ Branch 1 taken 950388 times.
✓ Branch 3 taken 942230 times.
✓ Branch 4 taken 1836849 times.
|
3729467 | while (i < max_ctx && GET_CABAC(elem_offset[REF_IDX_L0] + i)) |
827 | 942230 | i++; | |
828 |
2/2✓ Branch 0 taken 195868 times.
✓ Branch 1 taken 2591369 times.
|
2787237 | if (i == 2) { |
829 |
4/4✓ Branch 0 taken 160433 times.
✓ Branch 1 taken 120844 times.
✓ Branch 3 taken 85409 times.
✓ Branch 4 taken 75024 times.
|
281277 | while (i < max && get_cabac_bypass(&lc->cc)) |
830 | 85409 | i++; | |
831 | } | ||
832 | |||
833 | 2787237 | return i; | |
834 | } | ||
835 | |||
836 | 2787237 | int ff_hevc_mvp_lx_flag_decode(HEVCLocalContext *lc) | |
837 | { | ||
838 | 2787237 | return GET_CABAC(elem_offset[MVP_LX_FLAG]); | |
839 | } | ||
840 | |||
841 | 2351443 | int ff_hevc_no_residual_syntax_flag_decode(HEVCLocalContext *lc) | |
842 | { | ||
843 | 2351443 | return GET_CABAC(elem_offset[NO_RESIDUAL_DATA_FLAG]); | |
844 | } | ||
845 | |||
846 | 5258886 | static av_always_inline int abs_mvd_greater0_flag_decode(HEVCLocalContext *lc) | |
847 | { | ||
848 | 5258886 | return GET_CABAC(elem_offset[ABS_MVD_GREATER0_FLAG]); | |
849 | } | ||
850 | |||
851 | 3598549 | static av_always_inline int abs_mvd_greater1_flag_decode(HEVCLocalContext *lc) | |
852 | { | ||
853 | 3598549 | return GET_CABAC(elem_offset[ABS_MVD_GREATER1_FLAG] + 1); | |
854 | } | ||
855 | |||
856 | 2583689 | static av_always_inline int mvd_decode(HEVCLocalContext *lc) | |
857 | { | ||
858 | 2583689 | int ret = 2; | |
859 | 2583689 | int k = 1; | |
860 | |||
861 |
3/4✓ Branch 0 taken 6329274 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 3745585 times.
✓ Branch 4 taken 2583689 times.
|
6329274 | while (k < CABAC_MAX_BIN && get_cabac_bypass(&lc->cc)) { |
862 | 3745585 | ret += 1U << k; | |
863 | 3745585 | k++; | |
864 | } | ||
865 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2583689 times.
|
2583689 | if (k == CABAC_MAX_BIN) { |
866 | ✗ | av_log(lc->logctx, AV_LOG_ERROR, "CABAC_MAX_BIN : %d\n", k); | |
867 | ✗ | return 0; | |
868 | } | ||
869 |
2/2✓ Branch 0 taken 6329274 times.
✓ Branch 1 taken 2583689 times.
|
8912963 | while (k--) |
870 | 6329274 | ret += get_cabac_bypass(&lc->cc) << k; | |
871 | 2583689 | return get_cabac_bypass_sign(&lc->cc, -ret); | |
872 | } | ||
873 | |||
874 | 1014860 | static av_always_inline int mvd_sign_flag_decode(HEVCLocalContext *lc) | |
875 | { | ||
876 | 1014860 | return get_cabac_bypass_sign(&lc->cc, -1); | |
877 | } | ||
878 | |||
879 | 6855308 | int ff_hevc_split_transform_flag_decode(HEVCLocalContext *lc, int log2_trafo_size) | |
880 | { | ||
881 | 6855308 | return GET_CABAC(elem_offset[SPLIT_TRANSFORM_FLAG] + 5 - log2_trafo_size); | |
882 | } | ||
883 | |||
884 | 15113001 | int ff_hevc_cbf_cb_cr_decode(HEVCLocalContext *lc, int trafo_depth) | |
885 | { | ||
886 | 15113001 | return GET_CABAC(elem_offset[CBF_CB_CR] + trafo_depth); | |
887 | } | ||
888 | |||
889 | 14608535 | int ff_hevc_cbf_luma_decode(HEVCLocalContext *lc, int trafo_depth) | |
890 | { | ||
891 | 14608535 | return GET_CABAC(elem_offset[CBF_LUMA] + !trafo_depth); | |
892 | } | ||
893 | |||
894 | 6506260 | static int hevc_transform_skip_flag_decode(HEVCLocalContext *lc, int c_idx) | |
895 | { | ||
896 | 6506260 | return GET_CABAC(elem_offset[TRANSFORM_SKIP_FLAG] + !!c_idx); | |
897 | } | ||
898 | |||
899 | 35234 | static int explicit_rdpcm_flag_decode(HEVCLocalContext *lc, int c_idx) | |
900 | { | ||
901 | 35234 | return GET_CABAC(elem_offset[EXPLICIT_RDPCM_FLAG] + !!c_idx); | |
902 | } | ||
903 | |||
904 | 3090 | static int explicit_rdpcm_dir_flag_decode(HEVCLocalContext *lc, int c_idx) | |
905 | { | ||
906 | 3090 | return GET_CABAC(elem_offset[EXPLICIT_RDPCM_DIR_FLAG] + !!c_idx); | |
907 | } | ||
908 | |||
909 | 384850 | int ff_hevc_log2_res_scale_abs(HEVCLocalContext *lc, int idx) | |
910 | { | ||
911 | 384850 | int i =0; | |
912 | |||
913 |
4/4✓ Branch 0 taken 1076510 times.
✓ Branch 1 taken 146082 times.
✓ Branch 3 taken 837742 times.
✓ Branch 4 taken 238768 times.
|
1222592 | while (i < 4 && GET_CABAC(elem_offset[LOG2_RES_SCALE_ABS] + 4 * idx + i)) |
914 | 837742 | i++; | |
915 | |||
916 | 384850 | return i; | |
917 | } | ||
918 | |||
919 | 235843 | int ff_hevc_res_scale_sign_flag(HEVCLocalContext *lc, int idx) | |
920 | { | ||
921 | 235843 | return GET_CABAC(elem_offset[RES_SCALE_SIGN_FLAG] + idx); | |
922 | } | ||
923 | |||
924 | 14143426 | static av_always_inline void last_significant_coeff_xy_prefix_decode(HEVCLocalContext *lc, int c_idx, | |
925 | int log2_size, int *last_scx_prefix, int *last_scy_prefix) | ||
926 | { | ||
927 | 14143426 | int i = 0; | |
928 | 14143426 | int max = (log2_size << 1) - 1; | |
929 | int ctx_offset, ctx_shift; | ||
930 | |||
931 |
2/2✓ Branch 0 taken 9692252 times.
✓ Branch 1 taken 4451174 times.
|
14143426 | if (!c_idx) { |
932 | 9692252 | ctx_offset = 3 * (log2_size - 2) + ((log2_size - 1) >> 2); | |
933 | 9692252 | ctx_shift = (log2_size + 1) >> 2; | |
934 | } else { | ||
935 | 4451174 | ctx_offset = 15; | |
936 | 4451174 | ctx_shift = log2_size - 2; | |
937 | } | ||
938 |
4/4✓ Branch 0 taken 34615878 times.
✓ Branch 1 taken 2099143 times.
✓ Branch 2 taken 22571595 times.
✓ Branch 3 taken 12044283 times.
|
71330899 | while (i < max && |
939 | 34615878 | GET_CABAC(elem_offset[LAST_SIGNIFICANT_COEFF_X_PREFIX] + (i >> ctx_shift) + ctx_offset)) | |
940 | 22571595 | i++; | |
941 | 14143426 | *last_scx_prefix = i; | |
942 | |||
943 | 14143426 | i = 0; | |
944 |
4/4✓ Branch 0 taken 30014219 times.
✓ Branch 1 taken 1643972 times.
✓ Branch 2 taken 17514765 times.
✓ Branch 3 taken 12499454 times.
|
61672410 | while (i < max && |
945 | 30014219 | GET_CABAC(elem_offset[LAST_SIGNIFICANT_COEFF_Y_PREFIX] + (i >> ctx_shift) + ctx_offset)) | |
946 | 17514765 | i++; | |
947 | 14143426 | *last_scy_prefix = i; | |
948 | 14143426 | } | |
949 | |||
950 | 3078261 | static av_always_inline int last_significant_coeff_suffix_decode(HEVCLocalContext *lc, | |
951 | int last_significant_coeff_prefix) | ||
952 | { | ||
953 | int i; | ||
954 | 3078261 | int length = (last_significant_coeff_prefix >> 1) - 1; | |
955 | 3078261 | int value = get_cabac_bypass(&lc->cc); | |
956 | |||
957 |
2/2✓ Branch 0 taken 861731 times.
✓ Branch 1 taken 3078261 times.
|
3939992 | for (i = 1; i < length; i++) |
958 | 861731 | value = (value << 1) | get_cabac_bypass(&lc->cc); | |
959 | 3078261 | return value; | |
960 | } | ||
961 | |||
962 | 8261388 | static av_always_inline int significant_coeff_group_flag_decode(HEVCLocalContext *lc, int c_idx, int ctx_cg) | |
963 | { | ||
964 | int inc; | ||
965 | |||
966 |
2/2✓ Branch 0 taken 1336740 times.
✓ Branch 1 taken 6924648 times.
|
8261388 | inc = FFMIN(ctx_cg, 1) + (c_idx>0 ? 2 : 0); |
967 | |||
968 | 8261388 | return GET_CABAC(elem_offset[SIGNIFICANT_COEFF_GROUP_FLAG] + inc); | |
969 | } | ||
970 | 169312398 | static av_always_inline int significant_coeff_flag_decode(HEVCLocalContext *lc, int x_c, int y_c, | |
971 | int offset, const uint8_t *ctx_idx_map) | ||
972 | { | ||
973 | 169312398 | int inc = ctx_idx_map[(y_c << 2) + x_c] + offset; | |
974 | 169312398 | return GET_CABAC(elem_offset[SIGNIFICANT_COEFF_FLAG] + inc); | |
975 | } | ||
976 | |||
977 | 18390846 | static av_always_inline int significant_coeff_flag_decode_0(HEVCLocalContext *lc, int c_idx, int offset) | |
978 | { | ||
979 | 18390846 | return GET_CABAC(elem_offset[SIGNIFICANT_COEFF_FLAG] + offset); | |
980 | } | ||
981 | |||
982 | 90436048 | static av_always_inline int coeff_abs_level_greater1_flag_decode(HEVCLocalContext *lc, int c_idx, int inc) | |
983 | { | ||
984 | |||
985 |
2/2✓ Branch 0 taken 21327364 times.
✓ Branch 1 taken 69108684 times.
|
90436048 | if (c_idx > 0) |
986 | 21327364 | inc += 16; | |
987 | |||
988 | 90436048 | return GET_CABAC(elem_offset[COEFF_ABS_LEVEL_GREATER1_FLAG] + inc); | |
989 | } | ||
990 | |||
991 | 10068584 | static av_always_inline int coeff_abs_level_greater2_flag_decode(HEVCLocalContext *lc, int c_idx, int inc) | |
992 | { | ||
993 |
2/2✓ Branch 0 taken 2130155 times.
✓ Branch 1 taken 7938429 times.
|
10068584 | if (c_idx > 0) |
994 | 2130155 | inc += 4; | |
995 | |||
996 | 10068584 | return GET_CABAC(elem_offset[COEFF_ABS_LEVEL_GREATER2_FLAG] + inc); | |
997 | } | ||
998 | |||
999 | 40707377 | static av_always_inline int coeff_abs_level_remaining_decode(HEVCLocalContext *lc, int rc_rice_param) | |
1000 | { | ||
1001 | 40707377 | int prefix = 0; | |
1002 | 40707377 | int suffix = 0; | |
1003 | int last_coeff_abs_level_remaining; | ||
1004 | int i; | ||
1005 | |||
1006 |
3/4✓ Branch 0 taken 89346718 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 48639341 times.
✓ Branch 4 taken 40707377 times.
|
89346718 | while (prefix < CABAC_MAX_BIN && get_cabac_bypass(&lc->cc)) |
1007 | 48639341 | prefix++; | |
1008 | |||
1009 |
2/2✓ Branch 0 taken 34774665 times.
✓ Branch 1 taken 5932712 times.
|
40707377 | if (prefix < 3) { |
1010 |
2/2✓ Branch 0 taken 36987189 times.
✓ Branch 1 taken 34774665 times.
|
71761854 | for (i = 0; i < rc_rice_param; i++) |
1011 | 36987189 | suffix = (suffix << 1) | get_cabac_bypass(&lc->cc); | |
1012 | 34774665 | last_coeff_abs_level_remaining = (prefix << rc_rice_param) + suffix; | |
1013 | } else { | ||
1014 | 5932712 | int prefix_minus3 = prefix - 3; | |
1015 | |||
1016 |
2/4✓ Branch 0 taken 5932712 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 5932712 times.
|
5932712 | if (prefix == CABAC_MAX_BIN || prefix_minus3 + rc_rice_param > 16 + 6) { |
1017 | ✗ | av_log(lc->logctx, AV_LOG_ERROR, "CABAC_MAX_BIN : %d\n", prefix); | |
1018 | ✗ | return 0; | |
1019 | } | ||
1020 | |||
1021 |
2/2✓ Branch 0 taken 19437987 times.
✓ Branch 1 taken 5932712 times.
|
25370699 | for (i = 0; i < prefix_minus3 + rc_rice_param; i++) |
1022 | 19437987 | suffix = (suffix << 1) | get_cabac_bypass(&lc->cc); | |
1023 | 5932712 | last_coeff_abs_level_remaining = (((1 << prefix_minus3) + 3 - 1) | |
1024 | 5932712 | << rc_rice_param) + suffix; | |
1025 | } | ||
1026 | 40707377 | return last_coeff_abs_level_remaining; | |
1027 | } | ||
1028 | |||
1029 | 21574215 | static av_always_inline int coeff_sign_flag_decode(HEVCLocalContext *lc, uint8_t nb) | |
1030 | { | ||
1031 | int i; | ||
1032 | 21574215 | int ret = 0; | |
1033 | |||
1034 |
2/2✓ Branch 0 taken 97403803 times.
✓ Branch 1 taken 21574215 times.
|
118978018 | for (i = 0; i < nb; i++) |
1035 | 97403803 | ret = (ret << 1) | get_cabac_bypass(&lc->cc); | |
1036 | 21574215 | return ret; | |
1037 | } | ||
1038 | |||
1039 | 14143426 | void ff_hevc_hls_residual_coding(HEVCLocalContext *lc, int x0, int y0, | |
1040 | int log2_trafo_size, enum ScanType scan_idx, | ||
1041 | int c_idx) | ||
1042 | { | ||
1043 | #define GET_COORD(offset, n) \ | ||
1044 | do { \ | ||
1045 | x_c = (x_cg << 2) + scan_x_off[n]; \ | ||
1046 | y_c = (y_cg << 2) + scan_y_off[n]; \ | ||
1047 | } while (0) | ||
1048 | 14143426 | const HEVCContext *const s = lc->parent; | |
1049 | 14143426 | int transform_skip_flag = 0; | |
1050 | |||
1051 | int last_significant_coeff_x, last_significant_coeff_y; | ||
1052 | int last_scan_pos; | ||
1053 | int n_end; | ||
1054 | 14143426 | int num_coeff = 0; | |
1055 | 14143426 | int greater1_ctx = 1; | |
1056 | |||
1057 | int num_last_subset; | ||
1058 | int x_cg_last_sig, y_cg_last_sig; | ||
1059 | |||
1060 | const uint8_t *scan_x_cg, *scan_y_cg, *scan_x_off, *scan_y_off; | ||
1061 | |||
1062 | 14143426 | ptrdiff_t stride = s->frame->linesize[c_idx]; | |
1063 | 14143426 | int hshift = s->ps.sps->hshift[c_idx]; | |
1064 | 14143426 | int vshift = s->ps.sps->vshift[c_idx]; | |
1065 | 14143426 | uint8_t *dst = &s->frame->data[c_idx][(y0 >> vshift) * stride + | |
1066 | 14143426 | ((x0 >> hshift) << s->ps.sps->pixel_shift)]; | |
1067 |
2/2✓ Branch 0 taken 4451174 times.
✓ Branch 1 taken 9692252 times.
|
14143426 | int16_t *coeffs = (int16_t*)(c_idx ? lc->edge_emu_buffer2 : lc->edge_emu_buffer); |
1068 | 14143426 | uint8_t significant_coeff_group_flag[8][8] = {{0}}; | |
1069 | 14143426 | int explicit_rdpcm_flag = 0; | |
1070 | int explicit_rdpcm_dir_flag; | ||
1071 | |||
1072 | 14143426 | int trafo_size = 1 << log2_trafo_size; | |
1073 | int i; | ||
1074 | int qp,shift,add,scale,scale_m; | ||
1075 | static const uint8_t level_scale[] = { 40, 45, 51, 57, 64, 72 }; | ||
1076 | 14143426 | const uint8_t *scale_matrix = NULL; | |
1077 | uint8_t dc_scale; | ||
1078 |
2/2✓ Branch 0 taken 9692252 times.
✓ Branch 1 taken 4451174 times.
|
14143426 | int pred_mode_intra = (c_idx == 0) ? lc->tu.intra_pred_mode : |
1079 | lc->tu.intra_pred_mode_c; | ||
1080 | |||
1081 | 14143426 | memset(coeffs, 0, trafo_size * trafo_size * sizeof(int16_t)); | |
1082 | |||
1083 | // Derive QP for dequant | ||
1084 |
2/2✓ Branch 0 taken 13705060 times.
✓ Branch 1 taken 438366 times.
|
14143426 | if (!lc->cu.cu_transquant_bypass_flag) { |
1085 | static const int qp_c[] = { 29, 30, 31, 32, 33, 33, 34, 34, 35, 35, 36, 36, 37, 37 }; | ||
1086 | static const uint8_t rem6[51 + 4 * 6 + 1] = { | ||
1087 | 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, | ||
1088 | 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, | ||
1089 | 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, | ||
1090 | 4, 5, 0, 1, 2, 3, 4, 5, 0, 1 | ||
1091 | }; | ||
1092 | |||
1093 | static const uint8_t div6[51 + 4 * 6 + 1] = { | ||
1094 | 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, | ||
1095 | 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, | ||
1096 | 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, | ||
1097 | 10, 10, 11, 11, 11, 11, 11, 11, 12, 12 | ||
1098 | }; | ||
1099 | 13705060 | int qp_y = lc->qp_y; | |
1100 | |||
1101 |
2/2✓ Branch 0 taken 11257982 times.
✓ Branch 1 taken 2447078 times.
|
13705060 | if (s->ps.pps->transform_skip_enabled_flag && |
1102 |
2/2✓ Branch 0 taken 6506260 times.
✓ Branch 1 taken 4751722 times.
|
11257982 | log2_trafo_size <= s->ps.pps->log2_max_transform_skip_block_size) { |
1103 | 6506260 | transform_skip_flag = hevc_transform_skip_flag_decode(lc, c_idx); | |
1104 | } | ||
1105 | |||
1106 |
2/2✓ Branch 0 taken 9417004 times.
✓ Branch 1 taken 4288056 times.
|
13705060 | if (c_idx == 0) { |
1107 | 9417004 | qp = qp_y + s->ps.sps->qp_bd_offset; | |
1108 | } else { | ||
1109 | int qp_i, offset; | ||
1110 | |||
1111 |
2/2✓ Branch 0 taken 2046559 times.
✓ Branch 1 taken 2241497 times.
|
4288056 | if (c_idx == 1) |
1112 | 2046559 | offset = s->ps.pps->cb_qp_offset + s->sh.slice_cb_qp_offset + | |
1113 | 2046559 | lc->tu.cu_qp_offset_cb; | |
1114 | else | ||
1115 | 2241497 | offset = s->ps.pps->cr_qp_offset + s->sh.slice_cr_qp_offset + | |
1116 | 2241497 | lc->tu.cu_qp_offset_cr; | |
1117 | |||
1118 | 4288056 | qp_i = av_clip(qp_y + offset, - s->ps.sps->qp_bd_offset, 57); | |
1119 |
2/2✓ Branch 0 taken 2421951 times.
✓ Branch 1 taken 1866105 times.
|
4288056 | if (s->ps.sps->chroma_format_idc == 1) { |
1120 |
2/2✓ Branch 0 taken 738077 times.
✓ Branch 1 taken 1683874 times.
|
2421951 | if (qp_i < 30) |
1121 | 738077 | qp = qp_i; | |
1122 |
2/2✓ Branch 0 taken 9230 times.
✓ Branch 1 taken 1674644 times.
|
1683874 | else if (qp_i > 43) |
1123 | 9230 | qp = qp_i - 6; | |
1124 | else | ||
1125 | 1674644 | qp = qp_c[qp_i - 30]; | |
1126 | } else { | ||
1127 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1866105 times.
|
1866105 | if (qp_i > 51) |
1128 | ✗ | qp = 51; | |
1129 | else | ||
1130 | 1866105 | qp = qp_i; | |
1131 | } | ||
1132 | |||
1133 | 4288056 | qp += s->ps.sps->qp_bd_offset; | |
1134 | } | ||
1135 | |||
1136 | 13705060 | shift = s->ps.sps->bit_depth + log2_trafo_size - 5; | |
1137 | 13705060 | add = 1 << (shift-1); | |
1138 | 13705060 | scale = level_scale[rem6[qp]] << (div6[qp]); | |
1139 | 13705060 | scale_m = 16; // default when no custom scaling lists. | |
1140 | 13705060 | dc_scale = 16; | |
1141 | |||
1142 |
6/6✓ Branch 0 taken 484014 times.
✓ Branch 1 taken 13221046 times.
✓ Branch 2 taken 26526 times.
✓ Branch 3 taken 457488 times.
✓ Branch 4 taken 14292 times.
✓ Branch 5 taken 12234 times.
|
13705060 | if (s->ps.sps->scaling_list_enable_flag && !(transform_skip_flag && log2_trafo_size > 2)) { |
1143 | 943560 | const ScalingList *sl = s->ps.pps->scaling_list_data_present_flag ? | |
1144 |
2/2✓ Branch 0 taken 357638 times.
✓ Branch 1 taken 114142 times.
|
471780 | &s->ps.pps->scaling_list : &s->ps.sps->scaling_list; |
1145 | 471780 | int matrix_id = lc->cu.pred_mode != MODE_INTRA; | |
1146 | |||
1147 | 471780 | matrix_id = 3 * matrix_id + c_idx; | |
1148 | |||
1149 | 471780 | scale_matrix = sl->sl[log2_trafo_size - 2][matrix_id]; | |
1150 |
2/2✓ Branch 0 taken 42637 times.
✓ Branch 1 taken 429143 times.
|
471780 | if (log2_trafo_size >= 4) |
1151 | 42637 | dc_scale = sl->sl_dc[log2_trafo_size - 4][matrix_id]; | |
1152 | } | ||
1153 | } else { | ||
1154 | 438366 | shift = 0; | |
1155 | 438366 | add = 0; | |
1156 | 438366 | scale = 0; | |
1157 | 438366 | dc_scale = 0; | |
1158 | } | ||
1159 | |||
1160 |
6/6✓ Branch 0 taken 4619226 times.
✓ Branch 1 taken 9524200 times.
✓ Branch 2 taken 225511 times.
✓ Branch 3 taken 4393715 times.
✓ Branch 4 taken 190277 times.
✓ Branch 5 taken 35234 times.
|
14143426 | if (lc->cu.pred_mode == MODE_INTER && s->ps.sps->explicit_rdpcm_enabled_flag && |
1161 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 190277 times.
|
190277 | (transform_skip_flag || lc->cu.cu_transquant_bypass_flag)) { |
1162 | 35234 | explicit_rdpcm_flag = explicit_rdpcm_flag_decode(lc, c_idx); | |
1163 |
2/2✓ Branch 0 taken 3090 times.
✓ Branch 1 taken 32144 times.
|
35234 | if (explicit_rdpcm_flag) { |
1164 | 3090 | explicit_rdpcm_dir_flag = explicit_rdpcm_dir_flag_decode(lc, c_idx); | |
1165 | } | ||
1166 | } | ||
1167 | |||
1168 | 14143426 | last_significant_coeff_xy_prefix_decode(lc, c_idx, log2_trafo_size, | |
1169 | &last_significant_coeff_x, &last_significant_coeff_y); | ||
1170 | |||
1171 |
2/2✓ Branch 0 taken 1800863 times.
✓ Branch 1 taken 12342563 times.
|
14143426 | if (last_significant_coeff_x > 3) { |
1172 | 1800863 | int suffix = last_significant_coeff_suffix_decode(lc, last_significant_coeff_x); | |
1173 | 1800863 | last_significant_coeff_x = (1 << ((last_significant_coeff_x >> 1) - 1)) * | |
1174 | 1800863 | (2 + (last_significant_coeff_x & 1)) + | |
1175 | suffix; | ||
1176 | } | ||
1177 | |||
1178 |
2/2✓ Branch 0 taken 1277398 times.
✓ Branch 1 taken 12866028 times.
|
14143426 | if (last_significant_coeff_y > 3) { |
1179 | 1277398 | int suffix = last_significant_coeff_suffix_decode(lc, last_significant_coeff_y); | |
1180 | 1277398 | last_significant_coeff_y = (1 << ((last_significant_coeff_y >> 1) - 1)) * | |
1181 | 1277398 | (2 + (last_significant_coeff_y & 1)) + | |
1182 | suffix; | ||
1183 | } | ||
1184 | |||
1185 |
2/2✓ Branch 0 taken 1814684 times.
✓ Branch 1 taken 12328742 times.
|
14143426 | if (scan_idx == SCAN_VERT) |
1186 | 1814684 | FFSWAP(int, last_significant_coeff_x, last_significant_coeff_y); | |
1187 | |||
1188 | 14143426 | x_cg_last_sig = last_significant_coeff_x >> 2; | |
1189 | 14143426 | y_cg_last_sig = last_significant_coeff_y >> 2; | |
1190 | |||
1191 |
3/3✓ Branch 0 taken 10299460 times.
✓ Branch 1 taken 2029282 times.
✓ Branch 2 taken 1814684 times.
|
14143426 | switch (scan_idx) { |
1192 | 10299460 | case SCAN_DIAG: { | |
1193 | 10299460 | int last_x_c = last_significant_coeff_x & 3; | |
1194 | 10299460 | int last_y_c = last_significant_coeff_y & 3; | |
1195 | |||
1196 | 10299460 | scan_x_off = ff_hevc_diag_scan4x4_x; | |
1197 | 10299460 | scan_y_off = ff_hevc_diag_scan4x4_y; | |
1198 | 10299460 | num_coeff = diag_scan4x4_inv[last_y_c][last_x_c]; | |
1199 |
2/2✓ Branch 0 taken 5246613 times.
✓ Branch 1 taken 5052847 times.
|
10299460 | if (trafo_size == 4) { |
1200 | 5246613 | scan_x_cg = scan_1x1; | |
1201 | 5246613 | scan_y_cg = scan_1x1; | |
1202 |
2/2✓ Branch 0 taken 2776288 times.
✓ Branch 1 taken 2276559 times.
|
5052847 | } else if (trafo_size == 8) { |
1203 | 2776288 | num_coeff += diag_scan2x2_inv[y_cg_last_sig][x_cg_last_sig] << 4; | |
1204 | 2776288 | scan_x_cg = diag_scan2x2_x; | |
1205 | 2776288 | scan_y_cg = diag_scan2x2_y; | |
1206 |
2/2✓ Branch 0 taken 1687847 times.
✓ Branch 1 taken 588712 times.
|
2276559 | } else if (trafo_size == 16) { |
1207 | 1687847 | num_coeff += diag_scan4x4_inv[y_cg_last_sig][x_cg_last_sig] << 4; | |
1208 | 1687847 | scan_x_cg = ff_hevc_diag_scan4x4_x; | |
1209 | 1687847 | scan_y_cg = ff_hevc_diag_scan4x4_y; | |
1210 | } else { // trafo_size == 32 | ||
1211 | 588712 | num_coeff += diag_scan8x8_inv[y_cg_last_sig][x_cg_last_sig] << 4; | |
1212 | 588712 | scan_x_cg = ff_hevc_diag_scan8x8_x; | |
1213 | 588712 | scan_y_cg = ff_hevc_diag_scan8x8_y; | |
1214 | } | ||
1215 | 10299460 | break; | |
1216 | } | ||
1217 | 2029282 | case SCAN_HORIZ: | |
1218 | 2029282 | scan_x_cg = horiz_scan2x2_x; | |
1219 | 2029282 | scan_y_cg = horiz_scan2x2_y; | |
1220 | 2029282 | scan_x_off = horiz_scan4x4_x; | |
1221 | 2029282 | scan_y_off = horiz_scan4x4_y; | |
1222 | 2029282 | num_coeff = horiz_scan8x8_inv[last_significant_coeff_y][last_significant_coeff_x]; | |
1223 | 2029282 | break; | |
1224 | 1814684 | default: //SCAN_VERT | |
1225 | 1814684 | scan_x_cg = horiz_scan2x2_y; | |
1226 | 1814684 | scan_y_cg = horiz_scan2x2_x; | |
1227 | 1814684 | scan_x_off = horiz_scan4x4_y; | |
1228 | 1814684 | scan_y_off = horiz_scan4x4_x; | |
1229 | 1814684 | num_coeff = horiz_scan8x8_inv[last_significant_coeff_x][last_significant_coeff_y]; | |
1230 | 1814684 | break; | |
1231 | } | ||
1232 | 14143426 | num_coeff++; | |
1233 | 14143426 | num_last_subset = (num_coeff - 1) >> 4; | |
1234 | |||
1235 |
2/2✓ Branch 0 taken 24772746 times.
✓ Branch 1 taken 14143426 times.
|
38916172 | for (i = num_last_subset; i >= 0; i--) { |
1236 | int n, m; | ||
1237 | int x_cg, y_cg, x_c, y_c, pos; | ||
1238 | 24772746 | int implicit_non_zero_coeff = 0; | |
1239 | int64_t trans_coeff_level; | ||
1240 | 24772746 | int prev_sig = 0; | |
1241 | 24772746 | int offset = i << 4; | |
1242 | 24772746 | int rice_init = 0; | |
1243 | |||
1244 | uint8_t significant_coeff_flag_idx[16]; | ||
1245 | 24772746 | uint8_t nb_significant_coeff_flag = 0; | |
1246 | |||
1247 | 24772746 | x_cg = scan_x_cg[i]; | |
1248 | 24772746 | y_cg = scan_y_cg[i]; | |
1249 | |||
1250 |
4/4✓ Branch 0 taken 10629320 times.
✓ Branch 1 taken 14143426 times.
✓ Branch 2 taken 8261388 times.
✓ Branch 3 taken 2367932 times.
|
24772746 | if ((i < num_last_subset) && (i > 0)) { |
1251 | 8261388 | int ctx_cg = 0; | |
1252 |
2/2✓ Branch 0 taken 7552362 times.
✓ Branch 1 taken 709026 times.
|
8261388 | if (x_cg < (1 << (log2_trafo_size - 2)) - 1) |
1253 | 7552362 | ctx_cg += significant_coeff_group_flag[x_cg + 1][y_cg]; | |
1254 |
2/2✓ Branch 0 taken 6969601 times.
✓ Branch 1 taken 1291787 times.
|
8261388 | if (y_cg < (1 << (log2_trafo_size - 2)) - 1) |
1255 | 6969601 | ctx_cg += significant_coeff_group_flag[x_cg][y_cg + 1]; | |
1256 | |||
1257 | 8261388 | significant_coeff_group_flag[x_cg][y_cg] = | |
1258 | 8261388 | significant_coeff_group_flag_decode(lc, c_idx, ctx_cg); | |
1259 | 8261388 | implicit_non_zero_coeff = 1; | |
1260 | } else { | ||
1261 | 16511358 | significant_coeff_group_flag[x_cg][y_cg] = | |
1262 |
5/6✓ Branch 0 taken 14817435 times.
✓ Branch 1 taken 1693923 times.
✓ Branch 2 taken 674009 times.
✓ Branch 3 taken 14143426 times.
✓ Branch 4 taken 2367932 times.
✗ Branch 5 not taken.
|
18879290 | ((x_cg == x_cg_last_sig && y_cg == y_cg_last_sig) || |
1263 |
1/2✓ Branch 0 taken 2367932 times.
✗ Branch 1 not taken.
|
2367932 | (x_cg == 0 && y_cg == 0)); |
1264 | } | ||
1265 | |||
1266 | 24772746 | last_scan_pos = num_coeff - offset - 1; | |
1267 | |||
1268 |
2/2✓ Branch 0 taken 14143426 times.
✓ Branch 1 taken 10629320 times.
|
24772746 | if (i == num_last_subset) { |
1269 | 14143426 | n_end = last_scan_pos - 1; | |
1270 | 14143426 | significant_coeff_flag_idx[0] = last_scan_pos; | |
1271 | 14143426 | nb_significant_coeff_flag = 1; | |
1272 | } else { | ||
1273 | 10629320 | n_end = 15; | |
1274 | } | ||
1275 | |||
1276 |
2/2✓ Branch 0 taken 14862181 times.
✓ Branch 1 taken 9910565 times.
|
24772746 | if (x_cg < ((1 << log2_trafo_size) - 1) >> 2) |
1277 | 14862181 | prev_sig = !!significant_coeff_group_flag[x_cg + 1][y_cg]; | |
1278 |
2/2✓ Branch 0 taken 14436113 times.
✓ Branch 1 taken 10336633 times.
|
24772746 | if (y_cg < ((1 << log2_trafo_size) - 1) >> 2) |
1279 |
2/2✓ Branch 0 taken 5136119 times.
✓ Branch 1 taken 9299994 times.
|
14436113 | prev_sig += (!!significant_coeff_group_flag[x_cg][y_cg + 1] << 1); |
1280 | |||
1281 |
4/4✓ Branch 0 taken 21659396 times.
✓ Branch 1 taken 3113350 times.
✓ Branch 2 taken 18461327 times.
✓ Branch 3 taken 3198069 times.
|
24772746 | if (significant_coeff_group_flag[x_cg][y_cg] && n_end >= 0) { |
1282 | static const uint8_t ctx_idx_map[] = { | ||
1283 | 0, 1, 4, 5, 2, 3, 4, 5, 6, 6, 8, 8, 7, 7, 8, 8, // log2_trafo_size == 2 | ||
1284 | 1, 1, 1, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, // prev_sig == 0 | ||
1285 | 2, 2, 2, 2, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, // prev_sig == 1 | ||
1286 | 2, 1, 0, 0, 2, 1, 0, 0, 2, 1, 0, 0, 2, 1, 0, 0, // prev_sig == 2 | ||
1287 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 // default | ||
1288 | }; | ||
1289 | const uint8_t *ctx_idx_map_p; | ||
1290 | 18461327 | int scf_offset = 0; | |
1291 |
4/4✓ Branch 0 taken 1017071 times.
✓ Branch 1 taken 17444256 times.
✓ Branch 2 taken 886760 times.
✓ Branch 3 taken 130311 times.
|
18461327 | if (s->ps.sps->transform_skip_context_enabled_flag && |
1292 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 886760 times.
|
886760 | (transform_skip_flag || lc->cu.cu_transquant_bypass_flag)) { |
1293 | 130311 | ctx_idx_map_p = &ctx_idx_map[4 * 16]; | |
1294 |
2/2✓ Branch 0 taken 61311 times.
✓ Branch 1 taken 69000 times.
|
130311 | if (c_idx == 0) { |
1295 | 61311 | scf_offset = 40; | |
1296 | } else { | ||
1297 | 69000 | scf_offset = 14 + 27; | |
1298 | } | ||
1299 | } else { | ||
1300 |
2/2✓ Branch 0 taken 4404582 times.
✓ Branch 1 taken 13926434 times.
|
18331016 | if (c_idx != 0) |
1301 | 4404582 | scf_offset = 27; | |
1302 |
2/2✓ Branch 0 taken 6335160 times.
✓ Branch 1 taken 11995856 times.
|
18331016 | if (log2_trafo_size == 2) { |
1303 | 6335160 | ctx_idx_map_p = &ctx_idx_map[0]; | |
1304 | } else { | ||
1305 | 11995856 | ctx_idx_map_p = &ctx_idx_map[(prev_sig + 1) << 4]; | |
1306 |
2/2✓ Branch 0 taken 9608649 times.
✓ Branch 1 taken 2387207 times.
|
11995856 | if (c_idx == 0) { |
1307 |
4/4✓ Branch 0 taken 5801543 times.
✓ Branch 1 taken 3807106 times.
✓ Branch 2 taken 2014576 times.
✓ Branch 3 taken 3786967 times.
|
9608649 | if ((x_cg > 0 || y_cg > 0)) |
1308 | 5821682 | scf_offset += 3; | |
1309 |
2/2✓ Branch 0 taken 3602748 times.
✓ Branch 1 taken 6005901 times.
|
9608649 | if (log2_trafo_size == 3) { |
1310 |
2/2✓ Branch 0 taken 2501124 times.
✓ Branch 1 taken 1101624 times.
|
3602748 | scf_offset += (scan_idx == SCAN_DIAG) ? 9 : 15; |
1311 | } else { | ||
1312 | 6005901 | scf_offset += 21; | |
1313 | } | ||
1314 | } else { | ||
1315 |
2/2✓ Branch 0 taken 1135099 times.
✓ Branch 1 taken 1252108 times.
|
2387207 | if (log2_trafo_size == 3) |
1316 | 1135099 | scf_offset += 9; | |
1317 | else | ||
1318 | 1252108 | scf_offset += 12; | |
1319 | } | ||
1320 | } | ||
1321 | } | ||
1322 |
2/2✓ Branch 0 taken 169312398 times.
✓ Branch 1 taken 18461327 times.
|
187773725 | for (n = n_end; n > 0; n--) { |
1323 | 169312398 | x_c = scan_x_off[n]; | |
1324 | 169312398 | y_c = scan_y_off[n]; | |
1325 |
2/2✓ Branch 1 taken 81612833 times.
✓ Branch 2 taken 87699565 times.
|
169312398 | if (significant_coeff_flag_decode(lc, x_c, y_c, scf_offset, ctx_idx_map_p)) { |
1326 | 81612833 | significant_coeff_flag_idx[nb_significant_coeff_flag] = n; | |
1327 | 81612833 | nb_significant_coeff_flag++; | |
1328 | 81612833 | implicit_non_zero_coeff = 0; | |
1329 | } | ||
1330 | } | ||
1331 |
2/2✓ Branch 0 taken 18390846 times.
✓ Branch 1 taken 70481 times.
|
18461327 | if (implicit_non_zero_coeff == 0) { |
1332 |
4/4✓ Branch 0 taken 1014653 times.
✓ Branch 1 taken 17376193 times.
✓ Branch 2 taken 884736 times.
✓ Branch 3 taken 129917 times.
|
18390846 | if (s->ps.sps->transform_skip_context_enabled_flag && |
1333 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 884736 times.
|
884736 | (transform_skip_flag || lc->cu.cu_transquant_bypass_flag)) { |
1334 |
2/2✓ Branch 0 taken 61056 times.
✓ Branch 1 taken 68861 times.
|
129917 | if (c_idx == 0) { |
1335 | 61056 | scf_offset = 42; | |
1336 | } else { | ||
1337 | 68861 | scf_offset = 16 + 27; | |
1338 | } | ||
1339 | } else { | ||
1340 |
2/2✓ Branch 0 taken 11189002 times.
✓ Branch 1 taken 7071927 times.
|
18260929 | if (i == 0) { |
1341 |
2/2✓ Branch 0 taken 8104752 times.
✓ Branch 1 taken 3084250 times.
|
11189002 | if (c_idx == 0) |
1342 | 8104752 | scf_offset = 0; | |
1343 | else | ||
1344 | 3084250 | scf_offset = 27; | |
1345 | } else { | ||
1346 | 7071927 | scf_offset = 2 + scf_offset; | |
1347 | } | ||
1348 | } | ||
1349 |
2/2✓ Branch 1 taken 12399414 times.
✓ Branch 2 taken 5991432 times.
|
18390846 | if (significant_coeff_flag_decode_0(lc, c_idx, scf_offset) == 1) { |
1350 | 12399414 | significant_coeff_flag_idx[nb_significant_coeff_flag] = 0; | |
1351 | 12399414 | nb_significant_coeff_flag++; | |
1352 | } | ||
1353 | } else { | ||
1354 | 70481 | significant_coeff_flag_idx[nb_significant_coeff_flag] = 0; | |
1355 | 70481 | nb_significant_coeff_flag++; | |
1356 | } | ||
1357 | } | ||
1358 | |||
1359 | 24772746 | n_end = nb_significant_coeff_flag; | |
1360 | |||
1361 | |||
1362 |
2/2✓ Branch 0 taken 21574215 times.
✓ Branch 1 taken 3198531 times.
|
24772746 | if (n_end) { |
1363 | int first_nz_pos_in_cg; | ||
1364 | int last_nz_pos_in_cg; | ||
1365 | 21574215 | int c_rice_param = 0; | |
1366 | 21574215 | int first_greater1_coeff_idx = -1; | |
1367 | uint8_t coeff_abs_level_greater1_flag[8]; | ||
1368 | uint16_t coeff_sign_flag; | ||
1369 | 21574215 | int sum_abs = 0; | |
1370 | int sign_hidden; | ||
1371 | int sb_type; | ||
1372 | |||
1373 | |||
1374 | // initialize first elem of coeff_bas_level_greater1_flag | ||
1375 |
4/4✓ Branch 0 taken 7515970 times.
✓ Branch 1 taken 14058245 times.
✓ Branch 2 taken 6105892 times.
✓ Branch 3 taken 1410078 times.
|
21574215 | int ctx_set = (i > 0 && c_idx == 0) ? 2 : 0; |
1376 | |||
1377 |
2/2✓ Branch 0 taken 1166629 times.
✓ Branch 1 taken 20407586 times.
|
21574215 | if (s->ps.sps->persistent_rice_adaptation_enabled_flag) { |
1378 |
3/4✓ Branch 0 taken 1047040 times.
✓ Branch 1 taken 119589 times.
✓ Branch 2 taken 1047040 times.
✗ Branch 3 not taken.
|
1166629 | if (!transform_skip_flag && !lc->cu.cu_transquant_bypass_flag) |
1379 |
2/2✓ Branch 0 taken 365016 times.
✓ Branch 1 taken 682024 times.
|
1047040 | sb_type = 2 * (c_idx == 0 ? 1 : 0); |
1380 | else | ||
1381 |
2/2✓ Branch 0 taken 56576 times.
✓ Branch 1 taken 63013 times.
|
119589 | sb_type = 2 * (c_idx == 0 ? 1 : 0) + 1; |
1382 | 1166629 | c_rice_param = lc->stat_coeff[sb_type] / 4; | |
1383 | } | ||
1384 | |||
1385 |
4/4✓ Branch 0 taken 7430789 times.
✓ Branch 1 taken 14143426 times.
✓ Branch 2 taken 3314129 times.
✓ Branch 3 taken 4116660 times.
|
21574215 | if (!(i == num_last_subset) && greater1_ctx == 0) |
1386 | 3314129 | ctx_set++; | |
1387 | 21574215 | greater1_ctx = 1; | |
1388 | 21574215 | last_nz_pos_in_cg = significant_coeff_flag_idx[0]; | |
1389 | |||
1390 |
2/2✓ Branch 0 taken 90436048 times.
✓ Branch 1 taken 21574215 times.
|
112010263 | for (m = 0; m < (n_end > 8 ? 8 : n_end); m++) { |
1391 | 90436048 | int inc = (ctx_set << 2) + greater1_ctx; | |
1392 | 90436048 | coeff_abs_level_greater1_flag[m] = | |
1393 | 90436048 | coeff_abs_level_greater1_flag_decode(lc, c_idx, inc); | |
1394 |
2/2✓ Branch 0 taken 29793917 times.
✓ Branch 1 taken 60642131 times.
|
90436048 | if (coeff_abs_level_greater1_flag[m]) { |
1395 | 29793917 | greater1_ctx = 0; | |
1396 |
2/2✓ Branch 0 taken 10068584 times.
✓ Branch 1 taken 19725333 times.
|
29793917 | if (first_greater1_coeff_idx == -1) |
1397 | 10068584 | first_greater1_coeff_idx = m; | |
1398 |
4/4✓ Branch 0 taken 48086775 times.
✓ Branch 1 taken 12555356 times.
✓ Branch 2 taken 29617589 times.
✓ Branch 3 taken 18469186 times.
|
60642131 | } else if (greater1_ctx > 0 && greater1_ctx < 3) { |
1399 | 29617589 | greater1_ctx++; | |
1400 | } | ||
1401 | } | ||
1402 | 21574215 | first_nz_pos_in_cg = significant_coeff_flag_idx[n_end - 1]; | |
1403 | |||
1404 |
2/2✓ Branch 0 taken 20870728 times.
✓ Branch 1 taken 703487 times.
|
21574215 | if (lc->cu.cu_transquant_bypass_flag || |
1405 |
2/2✓ Branch 0 taken 13467826 times.
✓ Branch 1 taken 7402902 times.
|
20870728 | (lc->cu.pred_mode == MODE_INTRA && |
1406 |
6/6✓ Branch 0 taken 902776 times.
✓ Branch 1 taken 12565050 times.
✓ Branch 2 taken 92431 times.
✓ Branch 3 taken 810345 times.
✓ Branch 4 taken 47376 times.
✓ Branch 5 taken 45055 times.
|
13467826 | s->ps.sps->implicit_rdpcm_enabled_flag && transform_skip_flag && |
1407 |
4/4✓ Branch 0 taken 28377 times.
✓ Branch 1 taken 18999 times.
✓ Branch 2 taken 5999 times.
✓ Branch 3 taken 20800675 times.
|
20825673 | (pred_mode_intra == 10 || pred_mode_intra == 26 )) || |
1408 | explicit_rdpcm_flag) | ||
1409 | 773540 | sign_hidden = 0; | |
1410 | else | ||
1411 | 20800675 | sign_hidden = (last_nz_pos_in_cg - first_nz_pos_in_cg >= 4); | |
1412 | |||
1413 |
2/2✓ Branch 0 taken 10068584 times.
✓ Branch 1 taken 11505631 times.
|
21574215 | if (first_greater1_coeff_idx != -1) { |
1414 | 10068584 | coeff_abs_level_greater1_flag[first_greater1_coeff_idx] += coeff_abs_level_greater2_flag_decode(lc, c_idx, ctx_set); | |
1415 | } | ||
1416 |
4/4✓ Branch 0 taken 19222514 times.
✓ Branch 1 taken 2351701 times.
✓ Branch 2 taken 8400163 times.
✓ Branch 3 taken 10822351 times.
|
21574215 | if (!s->ps.pps->sign_data_hiding_flag || !sign_hidden ) { |
1417 | 10751864 | coeff_sign_flag = coeff_sign_flag_decode(lc, nb_significant_coeff_flag) << (16 - nb_significant_coeff_flag); | |
1418 | } else { | ||
1419 | 10822351 | coeff_sign_flag = coeff_sign_flag_decode(lc, nb_significant_coeff_flag - 1) << (16 - (nb_significant_coeff_flag - 1)); | |
1420 | } | ||
1421 | |||
1422 |
2/2✓ Branch 0 taken 108226154 times.
✓ Branch 1 taken 21574215 times.
|
129800369 | for (m = 0; m < n_end; m++) { |
1423 | 108226154 | n = significant_coeff_flag_idx[m]; | |
1424 | 108226154 | GET_COORD(offset, n); | |
1425 |
2/2✓ Branch 0 taken 90436048 times.
✓ Branch 1 taken 17790106 times.
|
108226154 | if (m < 8) { |
1426 | 90436048 | trans_coeff_level = 1 + coeff_abs_level_greater1_flag[m]; | |
1427 |
4/4✓ Branch 0 taken 10068584 times.
✓ Branch 1 taken 80367464 times.
✓ Branch 2 taken 22917271 times.
✓ Branch 3 taken 67518777 times.
|
90436048 | if (trans_coeff_level == ((m == first_greater1_coeff_idx) ? 3 : 2)) { |
1428 | 22917271 | int last_coeff_abs_level_remaining = coeff_abs_level_remaining_decode(lc, c_rice_param); | |
1429 | |||
1430 | 22917271 | trans_coeff_level += last_coeff_abs_level_remaining; | |
1431 |
2/2✓ Branch 0 taken 5953265 times.
✓ Branch 1 taken 16964006 times.
|
22917271 | if (trans_coeff_level > (3 << c_rice_param)) |
1432 |
2/2✓ Branch 0 taken 197734 times.
✓ Branch 1 taken 5755531 times.
|
5953265 | c_rice_param = s->ps.sps->persistent_rice_adaptation_enabled_flag ? c_rice_param + 1 : FFMIN(c_rice_param + 1, 4); |
1433 |
4/4✓ Branch 0 taken 1114125 times.
✓ Branch 1 taken 21803146 times.
✓ Branch 2 taken 315677 times.
✓ Branch 3 taken 798448 times.
|
22917271 | if (s->ps.sps->persistent_rice_adaptation_enabled_flag && !rice_init) { |
1434 | 315677 | int c_rice_p_init = lc->stat_coeff[sb_type] / 4; | |
1435 |
2/2✓ Branch 0 taken 37785 times.
✓ Branch 1 taken 277892 times.
|
315677 | if (last_coeff_abs_level_remaining >= (3 << c_rice_p_init)) |
1436 | 37785 | lc->stat_coeff[sb_type]++; | |
1437 |
2/2✓ Branch 0 taken 157067 times.
✓ Branch 1 taken 120825 times.
|
277892 | else if (2 * last_coeff_abs_level_remaining < (1 << c_rice_p_init)) |
1438 |
2/2✓ Branch 0 taken 37744 times.
✓ Branch 1 taken 119323 times.
|
157067 | if (lc->stat_coeff[sb_type] > 0) |
1439 | 37744 | lc->stat_coeff[sb_type]--; | |
1440 | 315677 | rice_init = 1; | |
1441 | } | ||
1442 | } | ||
1443 | } else { | ||
1444 | 17790106 | int last_coeff_abs_level_remaining = coeff_abs_level_remaining_decode(lc, c_rice_param); | |
1445 | |||
1446 | 17790106 | trans_coeff_level = 1 + last_coeff_abs_level_remaining; | |
1447 |
2/2✓ Branch 0 taken 2222200 times.
✓ Branch 1 taken 15567906 times.
|
17790106 | if (trans_coeff_level > (3 << c_rice_param)) |
1448 |
2/2✓ Branch 0 taken 89299 times.
✓ Branch 1 taken 2132901 times.
|
2222200 | c_rice_param = s->ps.sps->persistent_rice_adaptation_enabled_flag ? c_rice_param + 1 : FFMIN(c_rice_param + 1, 4); |
1449 |
4/4✓ Branch 0 taken 938151 times.
✓ Branch 1 taken 16851955 times.
✓ Branch 2 taken 36551 times.
✓ Branch 3 taken 901600 times.
|
17790106 | if (s->ps.sps->persistent_rice_adaptation_enabled_flag && !rice_init) { |
1450 | 36551 | int c_rice_p_init = lc->stat_coeff[sb_type] / 4; | |
1451 |
2/2✓ Branch 0 taken 1344 times.
✓ Branch 1 taken 35207 times.
|
36551 | if (last_coeff_abs_level_remaining >= (3 << c_rice_p_init)) |
1452 | 1344 | lc->stat_coeff[sb_type]++; | |
1453 |
2/2✓ Branch 0 taken 24604 times.
✓ Branch 1 taken 10603 times.
|
35207 | else if (2 * last_coeff_abs_level_remaining < (1 << c_rice_p_init)) |
1454 |
2/2✓ Branch 0 taken 1307 times.
✓ Branch 1 taken 23297 times.
|
24604 | if (lc->stat_coeff[sb_type] > 0) |
1455 | 1307 | lc->stat_coeff[sb_type]--; | |
1456 | 36551 | rice_init = 1; | |
1457 | } | ||
1458 | } | ||
1459 |
4/4✓ Branch 0 taken 100343691 times.
✓ Branch 1 taken 7882463 times.
✓ Branch 2 taken 78325144 times.
✓ Branch 3 taken 22018547 times.
|
108226154 | if (s->ps.pps->sign_data_hiding_flag && sign_hidden) { |
1460 | 78325144 | sum_abs += trans_coeff_level; | |
1461 |
4/4✓ Branch 0 taken 10822351 times.
✓ Branch 1 taken 67502793 times.
✓ Branch 2 taken 5403489 times.
✓ Branch 3 taken 5418862 times.
|
78325144 | if (n == first_nz_pos_in_cg && (sum_abs&1)) |
1462 | 5403489 | trans_coeff_level = -trans_coeff_level; | |
1463 | } | ||
1464 |
2/2✓ Branch 0 taken 49208766 times.
✓ Branch 1 taken 59017388 times.
|
108226154 | if (coeff_sign_flag >> 15) |
1465 | 49208766 | trans_coeff_level = -trans_coeff_level; | |
1466 | 108226154 | coeff_sign_flag <<= 1; | |
1467 |
2/2✓ Branch 0 taken 99541768 times.
✓ Branch 1 taken 8684386 times.
|
108226154 | if(!lc->cu.cu_transquant_bypass_flag) { |
1468 |
6/6✓ Branch 0 taken 2778647 times.
✓ Branch 1 taken 96763121 times.
✓ Branch 2 taken 190401 times.
✓ Branch 3 taken 2588246 times.
✓ Branch 4 taken 30375 times.
✓ Branch 5 taken 160026 times.
|
99541768 | if (s->ps.sps->scaling_list_enable_flag && !(transform_skip_flag && log2_trafo_size > 2)) { |
1469 |
6/6✓ Branch 0 taken 822457 times.
✓ Branch 1 taken 1796164 times.
✓ Branch 2 taken 369421 times.
✓ Branch 3 taken 453036 times.
✓ Branch 4 taken 338164 times.
✓ Branch 5 taken 31257 times.
|
2618621 | if(y_c || x_c || log2_trafo_size < 4) { |
1470 |
4/4✓ Branch 0 taken 650713 times.
✓ Branch 1 taken 814838 times.
✓ Branch 2 taken 298445 times.
✓ Branch 3 taken 823368 times.
|
2587364 | switch(log2_trafo_size) { |
1471 | 650713 | case 3: pos = (y_c << 3) + x_c; break; | |
1472 | 814838 | case 4: pos = ((y_c >> 1) << 3) + (x_c >> 1); break; | |
1473 | 298445 | case 5: pos = ((y_c >> 2) << 3) + (x_c >> 2); break; | |
1474 | 823368 | default: pos = (y_c << 2) + x_c; break; | |
1475 | } | ||
1476 | 2587364 | scale_m = scale_matrix[pos]; | |
1477 | } else { | ||
1478 | 31257 | scale_m = dc_scale; | |
1479 | } | ||
1480 | } | ||
1481 | 99541768 | trans_coeff_level = (trans_coeff_level * (int64_t)scale * (int64_t)scale_m + add) >> shift; | |
1482 |
2/2✓ Branch 0 taken 50241437 times.
✓ Branch 1 taken 49300331 times.
|
99541768 | if(trans_coeff_level < 0) { |
1483 |
2/2✓ Branch 0 taken 162681 times.
✓ Branch 1 taken 50078756 times.
|
50241437 | if((~trans_coeff_level) & 0xFffffffffff8000) |
1484 | 162681 | trans_coeff_level = -32768; | |
1485 | } else { | ||
1486 |
2/2✓ Branch 0 taken 162295 times.
✓ Branch 1 taken 49138036 times.
|
49300331 | if(trans_coeff_level & 0xffffffffffff8000) |
1487 | 162295 | trans_coeff_level = 32767; | |
1488 | } | ||
1489 | } | ||
1490 | 108226154 | coeffs[y_c * trafo_size + x_c] = trans_coeff_level; | |
1491 | } | ||
1492 | } | ||
1493 | } | ||
1494 | |||
1495 |
2/2✓ Branch 0 taken 438366 times.
✓ Branch 1 taken 13705060 times.
|
14143426 | if (lc->cu.cu_transquant_bypass_flag) { |
1496 |
2/6✓ Branch 0 taken 438366 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 438366 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
438366 | if (explicit_rdpcm_flag || (s->ps.sps->implicit_rdpcm_enabled_flag && |
1497 | ✗ | (pred_mode_intra == 10 || pred_mode_intra == 26))) { | |
1498 | ✗ | int mode = s->ps.sps->implicit_rdpcm_enabled_flag ? (pred_mode_intra == 26) : explicit_rdpcm_dir_flag; | |
1499 | |||
1500 | ✗ | s->hevcdsp.transform_rdpcm(coeffs, log2_trafo_size, mode); | |
1501 | } | ||
1502 | } else { | ||
1503 |
2/2✓ Branch 0 taken 432141 times.
✓ Branch 1 taken 13272919 times.
|
13705060 | if (transform_skip_flag) { |
1504 |
2/2✓ Branch 0 taken 54609 times.
✓ Branch 1 taken 21520 times.
|
76129 | int rot = s->ps.sps->transform_skip_rotation_enabled_flag && |
1505 |
2/2✓ Branch 0 taken 76129 times.
✓ Branch 1 taken 356012 times.
|
508270 | log2_trafo_size == 2 && |
1506 |
2/2✓ Branch 0 taken 20826 times.
✓ Branch 1 taken 33783 times.
|
54609 | lc->cu.pred_mode == MODE_INTRA; |
1507 |
2/2✓ Branch 0 taken 20826 times.
✓ Branch 1 taken 411315 times.
|
432141 | if (rot) { |
1508 |
2/2✓ Branch 0 taken 166608 times.
✓ Branch 1 taken 20826 times.
|
187434 | for (i = 0; i < 8; i++) |
1509 | 166608 | FFSWAP(int16_t, coeffs[i], coeffs[16 - i - 1]); | |
1510 | } | ||
1511 | |||
1512 | 432141 | s->hevcdsp.dequant(coeffs, log2_trafo_size); | |
1513 | |||
1514 |
4/4✓ Branch 0 taken 429051 times.
✓ Branch 1 taken 3090 times.
✓ Branch 2 taken 73039 times.
✓ Branch 3 taken 356012 times.
|
432141 | if (explicit_rdpcm_flag || (s->ps.sps->implicit_rdpcm_enabled_flag && |
1515 |
4/4✓ Branch 0 taken 40895 times.
✓ Branch 1 taken 32144 times.
✓ Branch 2 taken 25185 times.
✓ Branch 3 taken 15710 times.
|
73039 | lc->cu.pred_mode == MODE_INTRA && |
1516 |
2/2✓ Branch 0 taken 8263 times.
✓ Branch 1 taken 16922 times.
|
25185 | (pred_mode_intra == 10 || pred_mode_intra == 26))) { |
1517 |
2/2✓ Branch 0 taken 23973 times.
✓ Branch 1 taken 3090 times.
|
27063 | int mode = explicit_rdpcm_flag ? explicit_rdpcm_dir_flag : (pred_mode_intra == 26); |
1518 | |||
1519 | 27063 | s->hevcdsp.transform_rdpcm(coeffs, log2_trafo_size, mode); | |
1520 | } | ||
1521 |
6/6✓ Branch 0 taken 9020574 times.
✓ Branch 1 taken 4252345 times.
✓ Branch 2 taken 6094600 times.
✓ Branch 3 taken 2925974 times.
✓ Branch 4 taken 3570671 times.
✓ Branch 5 taken 2523929 times.
|
13272919 | } else if (lc->cu.pred_mode == MODE_INTRA && c_idx == 0 && log2_trafo_size == 2) { |
1522 | 3570671 | s->hevcdsp.transform_4x4_luma(coeffs); | |
1523 | } else { | ||
1524 | 9702248 | int max_xy = FFMAX(last_significant_coeff_x, last_significant_coeff_y); | |
1525 |
2/2✓ Branch 0 taken 2179005 times.
✓ Branch 1 taken 7523243 times.
|
9702248 | if (max_xy == 0) |
1526 | 2179005 | s->hevcdsp.idct_dc[log2_trafo_size - 2](coeffs); | |
1527 | else { | ||
1528 | 7523243 | int col_limit = last_significant_coeff_x + last_significant_coeff_y + 4; | |
1529 |
2/2✓ Branch 0 taken 5210851 times.
✓ Branch 1 taken 2312392 times.
|
7523243 | if (max_xy < 4) |
1530 | 5210851 | col_limit = FFMIN(4, col_limit); | |
1531 |
2/2✓ Branch 0 taken 1727116 times.
✓ Branch 1 taken 585276 times.
|
2312392 | else if (max_xy < 8) |
1532 | 1727116 | col_limit = FFMIN(8, col_limit); | |
1533 |
2/2✓ Branch 0 taken 250731 times.
✓ Branch 1 taken 334545 times.
|
585276 | else if (max_xy < 12) |
1534 | 250731 | col_limit = FFMIN(24, col_limit); | |
1535 | 7523243 | s->hevcdsp.idct[log2_trafo_size - 2](coeffs, col_limit); | |
1536 | } | ||
1537 | } | ||
1538 | } | ||
1539 |
2/2✓ Branch 0 taken 269268 times.
✓ Branch 1 taken 13874158 times.
|
14143426 | if (lc->tu.cross_pf) { |
1540 | 269268 | int16_t *coeffs_y = (int16_t*)lc->edge_emu_buffer; | |
1541 | |||
1542 |
2/2✓ Branch 0 taken 20252880 times.
✓ Branch 1 taken 269268 times.
|
20522148 | for (i = 0; i < (trafo_size * trafo_size); i++) { |
1543 | 20252880 | coeffs[i] = coeffs[i] + ((lc->tu.res_scale_val * coeffs_y[i]) >> 3); | |
1544 | } | ||
1545 | } | ||
1546 | 14143426 | s->hevcdsp.add_residual[log2_trafo_size-2](dst, coeffs, stride); | |
1547 | 14143426 | } | |
1548 | |||
1549 | 2629443 | void ff_hevc_hls_mvd_coding(HEVCLocalContext *lc, int x0, int y0, int log2_cb_size) | |
1550 | { | ||
1551 | 2629443 | int x = abs_mvd_greater0_flag_decode(lc); | |
1552 | 2629443 | int y = abs_mvd_greater0_flag_decode(lc); | |
1553 | |||
1554 |
2/2✓ Branch 0 taken 1835512 times.
✓ Branch 1 taken 793931 times.
|
2629443 | if (x) |
1555 | 1835512 | x += abs_mvd_greater1_flag_decode(lc); | |
1556 |
2/2✓ Branch 0 taken 1763037 times.
✓ Branch 1 taken 866406 times.
|
2629443 | if (y) |
1557 | 1763037 | y += abs_mvd_greater1_flag_decode(lc); | |
1558 | |||
1559 |
3/4✓ Branch 0 taken 1333476 times.
✓ Branch 1 taken 502036 times.
✓ Branch 2 taken 793931 times.
✗ Branch 3 not taken.
|
2629443 | switch (x) { |
1560 | 1333476 | case 2: lc->pu.mvd.x = mvd_decode(lc); break; | |
1561 | 502036 | case 1: lc->pu.mvd.x = mvd_sign_flag_decode(lc); break; | |
1562 | 793931 | case 0: lc->pu.mvd.x = 0; break; | |
1563 | } | ||
1564 | |||
1565 |
3/4✓ Branch 0 taken 1250213 times.
✓ Branch 1 taken 512824 times.
✓ Branch 2 taken 866406 times.
✗ Branch 3 not taken.
|
2629443 | switch (y) { |
1566 | 1250213 | case 2: lc->pu.mvd.y = mvd_decode(lc); break; | |
1567 | 512824 | case 1: lc->pu.mvd.y = mvd_sign_flag_decode(lc); break; | |
1568 | 866406 | case 0: lc->pu.mvd.y = 0; break; | |
1569 | } | ||
1570 | 2629443 | } | |
1571 | |||
1572 |