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 | // 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 | 1415195 | void ff_hevc_save_states(HEVCLocalContext *lc, int ctb_addr_ts) | |
403 | { | ||
404 | 1415195 | const HEVCContext *const s = lc->parent; | |
405 | |||
406 |
2/2✓ Branch 0 taken 103324 times.
✓ Branch 1 taken 1311871 times.
|
1415195 | if (s->ps.pps->entropy_coding_sync_enabled_flag && |
407 |
2/2✓ Branch 0 taken 98474 times.
✓ Branch 1 taken 4850 times.
|
103324 | (ctb_addr_ts % s->ps.sps->ctb_width == 2 || |
408 |
2/2✓ Branch 0 taken 784 times.
✓ Branch 1 taken 97690 times.
|
98474 | (s->ps.sps->ctb_width == 2 && |
409 |
2/2✓ Branch 0 taken 392 times.
✓ Branch 1 taken 392 times.
|
784 | ctb_addr_ts % s->ps.sps->ctb_width == 0))) { |
410 | 5242 | memcpy(lc->common_cabac_state->state, lc->cabac_state, HEVC_CONTEXTS); | |
411 |
2/2✓ Branch 0 taken 48 times.
✓ Branch 1 taken 5194 times.
|
5242 | if (s->ps.sps->persistent_rice_adaptation_enabled_flag) { |
412 | 48 | memcpy(lc->common_cabac_state->stat_coeff, lc->stat_coeff, HEVC_STAT_COEFFS); | |
413 | } | ||
414 | } | ||
415 | 1415195 | } | |
416 | |||
417 | 4207 | static void load_states(HEVCLocalContext *lc, const HEVCContext *s) | |
418 | { | ||
419 | 4207 | memcpy(lc->cabac_state, lc->common_cabac_state->state, HEVC_CONTEXTS); | |
420 |
2/2✓ Branch 0 taken 44 times.
✓ Branch 1 taken 4163 times.
|
4207 | if (s->ps.sps->persistent_rice_adaptation_enabled_flag) { |
421 | 44 | memcpy(lc->stat_coeff, lc->common_cabac_state->stat_coeff, HEVC_STAT_COEFFS); | |
422 | } | ||
423 | 4207 | } | |
424 | |||
425 | 7872 | static int cabac_reinit(HEVCLocalContext *lc) | |
426 | { | ||
427 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 7872 times.
|
7872 | return skip_bytes(&lc->cc, 0) == NULL ? AVERROR_INVALIDDATA : 0; |
428 | } | ||
429 | |||
430 | 27524 | static int cabac_init_decoder(HEVCLocalContext *lc) | |
431 | { | ||
432 | 27524 | GetBitContext *gb = &lc->gb; | |
433 | 27524 | skip_bits(gb, 1); | |
434 | 27524 | align_get_bits(gb); | |
435 | 82572 | return ff_init_cabac_decoder(&lc->cc, | |
436 | 27524 | gb->buffer + get_bits_count(gb) / 8, | |
437 | 27524 | (get_bits_left(gb) + 7) / 8); | |
438 | } | ||
439 | |||
440 | 24805 | static void cabac_init_state(HEVCLocalContext *lc, const HEVCContext *s) | |
441 | { | ||
442 | 24805 | int init_type = 2 - s->sh.slice_type; | |
443 | int i; | ||
444 | |||
445 |
4/4✓ Branch 0 taken 6489 times.
✓ Branch 1 taken 18316 times.
✓ Branch 2 taken 6346 times.
✓ Branch 3 taken 143 times.
|
24805 | if (s->sh.cabac_init_flag && s->sh.slice_type != HEVC_SLICE_I) |
446 | 6346 | init_type ^= 3; | |
447 | |||
448 |
2/2✓ Branch 0 taken 4936195 times.
✓ Branch 1 taken 24805 times.
|
4961000 | for (i = 0; i < HEVC_CONTEXTS; i++) { |
449 | 4936195 | int init_value = init_values[init_type][i]; | |
450 | 4936195 | int m = (init_value >> 4) * 5 - 45; | |
451 | 4936195 | int n = ((init_value & 15) << 3) - 16; | |
452 | 4936195 | int pre = 2 * (((m * av_clip(s->sh.slice_qp, 0, 51)) >> 4) + n) - 127; | |
453 | |||
454 | 4936195 | pre ^= pre >> 31; | |
455 |
2/2✓ Branch 0 taken 506767 times.
✓ Branch 1 taken 4429428 times.
|
4936195 | if (pre > 124) |
456 | 506767 | pre = 124 + (pre & 1); | |
457 | 4936195 | lc->cabac_state[i] = pre; | |
458 | } | ||
459 | |||
460 |
2/2✓ Branch 0 taken 99220 times.
✓ Branch 1 taken 24805 times.
|
124025 | for (i = 0; i < 4; i++) |
461 | 99220 | lc->stat_coeff[i] = 0; | |
462 | 24805 | } | |
463 | |||
464 | 1415196 | int ff_hevc_cabac_init(HEVCLocalContext *lc, int ctb_addr_ts) | |
465 | { | ||
466 | 1415196 | const HEVCContext *const s = lc->parent; | |
467 | |||
468 |
2/2✓ Branch 0 taken 27524 times.
✓ Branch 1 taken 1387672 times.
|
1415196 | if (ctb_addr_ts == s->ps.pps->ctb_addr_rs_to_ts[s->sh.slice_ctb_addr_rs]) { |
469 | 27524 | int ret = cabac_init_decoder(lc); | |
470 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 27524 times.
|
27524 | if (ret < 0) |
471 | ✗ | return ret; | |
472 |
2/2✓ Branch 0 taken 7947 times.
✓ Branch 1 taken 19577 times.
|
27524 | if (s->sh.dependent_slice_segment_flag == 0 || |
473 |
2/2✓ Branch 0 taken 876 times.
✓ Branch 1 taken 7071 times.
|
7947 | (s->ps.pps->tiles_enabled_flag && |
474 |
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])) |
475 | 19886 | cabac_init_state(lc, s); | |
476 | |||
477 |
2/2✓ Branch 0 taken 17989 times.
✓ Branch 1 taken 9535 times.
|
27524 | if (!s->sh.first_slice_in_pic_flag && |
478 |
2/2✓ Branch 0 taken 3853 times.
✓ Branch 1 taken 14136 times.
|
17989 | s->ps.pps->entropy_coding_sync_enabled_flag) { |
479 |
2/2✓ Branch 0 taken 1636 times.
✓ Branch 1 taken 2217 times.
|
3853 | if (ctb_addr_ts % s->ps.sps->ctb_width == 0) { |
480 |
2/2✓ Branch 0 taken 92 times.
✓ Branch 1 taken 1544 times.
|
1636 | if (s->ps.sps->ctb_width == 1) |
481 | 92 | cabac_init_state(lc, s); | |
482 |
2/2✓ Branch 0 taken 1162 times.
✓ Branch 1 taken 382 times.
|
1544 | else if (s->sh.dependent_slice_segment_flag == 1) |
483 | 1162 | load_states(lc, s); | |
484 | } | ||
485 | } | ||
486 | } else { | ||
487 |
2/2✓ Branch 0 taken 287199 times.
✓ Branch 1 taken 1100473 times.
|
1387672 | if (s->ps.pps->tiles_enabled_flag && |
488 |
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]) { |
489 | int ret; | ||
490 |
1/2✓ Branch 0 taken 4625 times.
✗ Branch 1 not taken.
|
4625 | if (s->threads_number == 1) |
491 | 4625 | ret = cabac_reinit(lc); | |
492 | else { | ||
493 | ✗ | ret = cabac_init_decoder(lc); | |
494 | } | ||
495 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4625 times.
|
4625 | if (ret < 0) |
496 | ✗ | return ret; | |
497 | 4625 | cabac_init_state(lc, s); | |
498 | } | ||
499 |
2/2✓ Branch 0 taken 98720 times.
✓ Branch 1 taken 1288952 times.
|
1387672 | if (s->ps.pps->entropy_coding_sync_enabled_flag) { |
500 |
2/2✓ Branch 0 taken 3247 times.
✓ Branch 1 taken 95473 times.
|
98720 | if (ctb_addr_ts % s->ps.sps->ctb_width == 0) { |
501 | int ret; | ||
502 | 3247 | get_cabac_terminate(&lc->cc); | |
503 |
1/2✓ Branch 0 taken 3247 times.
✗ Branch 1 not taken.
|
3247 | if (s->threads_number == 1) |
504 | 3247 | ret = cabac_reinit(lc); | |
505 | else { | ||
506 | ✗ | ret = cabac_init_decoder(lc); | |
507 | } | ||
508 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3247 times.
|
3247 | if (ret < 0) |
509 | ✗ | return ret; | |
510 | |||
511 |
2/2✓ Branch 0 taken 202 times.
✓ Branch 1 taken 3045 times.
|
3247 | if (s->ps.sps->ctb_width == 1) |
512 | 202 | cabac_init_state(lc, s); | |
513 | else | ||
514 | 3045 | load_states(lc, s); | |
515 | } | ||
516 | } | ||
517 | } | ||
518 | 1415196 | return 0; | |
519 | } | ||
520 | |||
521 | #define GET_CABAC(ctx) get_cabac(&lc->cc, &lc->cabac_state[ctx]) | ||
522 | |||
523 | 818026 | int ff_hevc_sao_merge_flag_decode(HEVCLocalContext *lc) | |
524 | { | ||
525 | 818026 | return GET_CABAC(SAO_MERGE_FLAG_OFFSET); | |
526 | } | ||
527 | |||
528 | 375747 | int ff_hevc_sao_type_idx_decode(HEVCLocalContext *lc) | |
529 | { | ||
530 |
2/2✓ Branch 1 taken 212901 times.
✓ Branch 2 taken 162846 times.
|
375747 | if (!GET_CABAC(SAO_TYPE_IDX_OFFSET)) |
531 | 212901 | return 0; | |
532 | |||
533 |
2/2✓ Branch 1 taken 53990 times.
✓ Branch 2 taken 108856 times.
|
162846 | if (!get_cabac_bypass(&lc->cc)) |
534 | 53990 | return SAO_BAND; | |
535 | 108856 | return SAO_EDGE; | |
536 | } | ||
537 | |||
538 | 77972 | int ff_hevc_sao_band_position_decode(HEVCLocalContext *lc) | |
539 | { | ||
540 | int i; | ||
541 | 77972 | int value = get_cabac_bypass(&lc->cc); | |
542 | |||
543 |
2/2✓ Branch 0 taken 311888 times.
✓ Branch 1 taken 77972 times.
|
389860 | for (i = 0; i < 4; i++) |
544 | 311888 | value = (value << 1) | get_cabac_bypass(&lc->cc); | |
545 | 77972 | return value; | |
546 | } | ||
547 | |||
548 | 871288 | int ff_hevc_sao_offset_abs_decode(HEVCLocalContext *lc) | |
549 | { | ||
550 | 871288 | int i = 0; | |
551 | 871288 | int length = (1 << (FFMIN(lc->parent->ps.sps->bit_depth, 10) - 5)) - 1; | |
552 | |||
553 |
4/4✓ Branch 0 taken 2461960 times.
✓ Branch 1 taken 127355 times.
✓ Branch 3 taken 1718027 times.
✓ Branch 4 taken 743933 times.
|
2589315 | while (i < length && get_cabac_bypass(&lc->cc)) |
554 | 1718027 | i++; | |
555 | 871288 | return i; | |
556 | } | ||
557 | |||
558 | 243186 | int ff_hevc_sao_offset_sign_decode(HEVCLocalContext *lc) | |
559 | { | ||
560 | 243186 | return get_cabac_bypass(&lc->cc); | |
561 | } | ||
562 | |||
563 | 108856 | int ff_hevc_sao_eo_class_decode(HEVCLocalContext *lc) | |
564 | { | ||
565 | 108856 | int ret = get_cabac_bypass(&lc->cc) << 1; | |
566 | 108856 | ret |= get_cabac_bypass(&lc->cc); | |
567 | 108856 | return ret; | |
568 | } | ||
569 | |||
570 | 1415195 | int ff_hevc_end_of_slice_flag_decode(HEVCLocalContext *lc) | |
571 | { | ||
572 | 1415195 | return get_cabac_terminate(&lc->cc); | |
573 | } | ||
574 | |||
575 | 200139 | int ff_hevc_cu_transquant_bypass_flag_decode(HEVCLocalContext *lc) | |
576 | { | ||
577 | 200139 | return GET_CABAC(CU_TRANSQUANT_BYPASS_FLAG_OFFSET); | |
578 | } | ||
579 | |||
580 | 8093587 | int ff_hevc_skip_flag_decode(HEVCLocalContext *lc, int x0, int y0, int x_cb, int y_cb) | |
581 | { | ||
582 | 8093587 | const HEVCContext *const s = lc->parent; | |
583 | 8093587 | int min_cb_width = s->ps.sps->min_cb_width; | |
584 | 8093587 | int inc = 0; | |
585 | 8093587 | int x0b = av_mod_uintp2(x0, s->ps.sps->log2_ctb_size); | |
586 | 8093587 | int y0b = av_mod_uintp2(y0, s->ps.sps->log2_ctb_size); | |
587 | |||
588 |
4/4✓ Branch 0 taken 737043 times.
✓ Branch 1 taken 7356544 times.
✓ Branch 2 taken 532233 times.
✓ Branch 3 taken 204810 times.
|
8093587 | if (lc->ctb_left_flag || x0b) |
589 | 7888777 | inc = !!SAMPLE_CTB(s->skip_flag, x_cb - 1, y_cb); | |
590 |
4/4✓ Branch 0 taken 1679754 times.
✓ Branch 1 taken 6413833 times.
✓ Branch 2 taken 1222453 times.
✓ Branch 3 taken 457301 times.
|
8093587 | if (lc->ctb_up_flag || y0b) |
591 | 7636286 | inc += !!SAMPLE_CTB(s->skip_flag, x_cb, y_cb - 1); | |
592 | |||
593 | 8093587 | return GET_CABAC(SKIP_FLAG_OFFSET + inc); | |
594 | } | ||
595 | |||
596 | 610425 | int ff_hevc_cu_qp_delta_abs(HEVCLocalContext *lc) | |
597 | { | ||
598 | 610425 | int prefix_val = 0; | |
599 | 610425 | int suffix_val = 0; | |
600 | 610425 | int inc = 0; | |
601 | |||
602 |
4/4✓ Branch 0 taken 1484333 times.
✓ Branch 1 taken 106178 times.
✓ Branch 3 taken 980086 times.
✓ Branch 4 taken 504247 times.
|
1590511 | while (prefix_val < 5 && GET_CABAC(CU_QP_DELTA_OFFSET + inc)) { |
603 | 980086 | prefix_val++; | |
604 | 980086 | inc = 1; | |
605 | } | ||
606 |
2/2✓ Branch 0 taken 106178 times.
✓ Branch 1 taken 504247 times.
|
610425 | if (prefix_val >= 5) { |
607 | 106178 | int k = 0; | |
608 |
3/4✓ Branch 0 taken 360430 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 254252 times.
✓ Branch 4 taken 106178 times.
|
360430 | while (k < 7 && get_cabac_bypass(&lc->cc)) { |
609 | 254252 | suffix_val += 1 << k; | |
610 | 254252 | k++; | |
611 | } | ||
612 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 106178 times.
|
106178 | if (k == 7) { |
613 | ✗ | av_log(lc->logctx, AV_LOG_ERROR, "CABAC_MAX_BIN : %d\n", k); | |
614 | ✗ | return AVERROR_INVALIDDATA; | |
615 | } | ||
616 | |||
617 |
2/2✓ Branch 0 taken 254252 times.
✓ Branch 1 taken 106178 times.
|
360430 | while (k--) |
618 | 254252 | suffix_val += get_cabac_bypass(&lc->cc) << k; | |
619 | } | ||
620 | 610425 | return prefix_val + suffix_val; | |
621 | } | ||
622 | |||
623 | 370890 | int ff_hevc_cu_qp_delta_sign_flag(HEVCLocalContext *lc) | |
624 | { | ||
625 | 370890 | return get_cabac_bypass(&lc->cc); | |
626 | } | ||
627 | |||
628 | 266275 | int ff_hevc_cu_chroma_qp_offset_flag(HEVCLocalContext *lc) | |
629 | { | ||
630 | 266275 | return GET_CABAC(CU_CHROMA_QP_OFFSET_FLAG_OFFSET); | |
631 | } | ||
632 | |||
633 | ✗ | int ff_hevc_cu_chroma_qp_offset_idx(HEVCLocalContext *lc) | |
634 | { | ||
635 | ✗ | int c_max= FFMAX(5, lc->parent->ps.pps->chroma_qp_offset_list_len_minus1); | |
636 | ✗ | int i = 0; | |
637 | |||
638 | ✗ | while (i < c_max && GET_CABAC(CU_CHROMA_QP_OFFSET_IDX_OFFSET)) | |
639 | ✗ | i++; | |
640 | |||
641 | ✗ | return i; | |
642 | } | ||
643 | |||
644 | 4199694 | int ff_hevc_pred_mode_decode(HEVCLocalContext *lc) | |
645 | { | ||
646 | 4199694 | return GET_CABAC(PRED_MODE_FLAG_OFFSET); | |
647 | } | ||
648 | |||
649 | 7491019 | int ff_hevc_split_coding_unit_flag_decode(HEVCLocalContext *lc, int ct_depth, int x0, int y0) | |
650 | { | ||
651 | 7491019 | const HEVCContext *const s = lc->parent; | |
652 | 7491019 | const HEVCSPS *const sps = s->ps.sps; | |
653 | 7491019 | int inc = 0, depth_left = 0, depth_top = 0; | |
654 | 7491019 | int x0b = av_mod_uintp2(x0, sps->log2_ctb_size); | |
655 | 7491019 | int y0b = av_mod_uintp2(y0, sps->log2_ctb_size); | |
656 | 7491019 | int x_cb = x0 >> sps->log2_min_cb_size; | |
657 | 7491019 | int y_cb = y0 >> sps->log2_min_cb_size; | |
658 | |||
659 |
4/4✓ Branch 0 taken 695203 times.
✓ Branch 1 taken 6795816 times.
✓ Branch 2 taken 396932 times.
✓ Branch 3 taken 298271 times.
|
7491019 | if (lc->ctb_left_flag || x0b) |
660 | 7192748 | depth_left = s->tab_ct_depth[(y_cb) * sps->min_cb_width + x_cb - 1]; | |
661 |
4/4✓ Branch 0 taken 1492001 times.
✓ Branch 1 taken 5999018 times.
✓ Branch 2 taken 839843 times.
✓ Branch 3 taken 652158 times.
|
7491019 | if (lc->ctb_up_flag || y0b) |
662 | 6838861 | depth_top = s->tab_ct_depth[(y_cb - 1) * sps->min_cb_width + x_cb]; | |
663 | |||
664 | 7491019 | inc += (depth_left > ct_depth); | |
665 | 7491019 | inc += (depth_top > ct_depth); | |
666 | |||
667 | 7491019 | return GET_CABAC(SPLIT_CODING_UNIT_FLAG_OFFSET + inc); | |
668 | } | ||
669 | |||
670 | 6171281 | int ff_hevc_part_mode_decode(HEVCLocalContext *lc, int log2_cb_size) | |
671 | { | ||
672 |
2/2✓ Branch 1 taken 3596264 times.
✓ Branch 2 taken 2575017 times.
|
6171281 | if (GET_CABAC(PART_MODE_OFFSET)) // 1 |
673 | 3596264 | return PART_2Nx2N; | |
674 |
2/2✓ Branch 0 taken 1944387 times.
✓ Branch 1 taken 630630 times.
|
2575017 | if (log2_cb_size == lc->parent->ps.sps->log2_min_cb_size) { |
675 |
2/2✓ Branch 0 taken 1195197 times.
✓ Branch 1 taken 749190 times.
|
1944387 | if (lc->cu.pred_mode == MODE_INTRA) // 0 |
676 | 1195197 | return PART_NxN; | |
677 |
2/2✓ Branch 1 taken 308106 times.
✓ Branch 2 taken 441084 times.
|
749190 | if (GET_CABAC(PART_MODE_OFFSET + 1)) // 01 |
678 | 308106 | return PART_2NxN; | |
679 |
2/2✓ Branch 0 taken 223043 times.
✓ Branch 1 taken 218041 times.
|
441084 | if (log2_cb_size == 3) // 00 |
680 | 223043 | return PART_Nx2N; | |
681 |
2/2✓ Branch 1 taken 112405 times.
✓ Branch 2 taken 105636 times.
|
218041 | if (GET_CABAC(PART_MODE_OFFSET + 2)) // 001 |
682 | 112405 | return PART_Nx2N; | |
683 | 105636 | return PART_NxN; // 000 | |
684 | } | ||
685 | |||
686 |
2/2✓ Branch 0 taken 65275 times.
✓ Branch 1 taken 565355 times.
|
630630 | if (!lc->parent->ps.sps->amp_enabled_flag) { |
687 |
2/2✓ Branch 1 taken 29519 times.
✓ Branch 2 taken 35756 times.
|
65275 | if (GET_CABAC(PART_MODE_OFFSET + 1)) // 01 |
688 | 29519 | return PART_2NxN; | |
689 | 35756 | return PART_Nx2N; | |
690 | } | ||
691 | |||
692 |
2/2✓ Branch 1 taken 227440 times.
✓ Branch 2 taken 337915 times.
|
565355 | if (GET_CABAC(PART_MODE_OFFSET + 1)) { // 01X, 01XX |
693 |
2/2✓ Branch 1 taken 108440 times.
✓ Branch 2 taken 119000 times.
|
227440 | if (GET_CABAC(PART_MODE_OFFSET + 3)) // 011 |
694 | 108440 | return PART_2NxN; | |
695 |
2/2✓ Branch 1 taken 55217 times.
✓ Branch 2 taken 63783 times.
|
119000 | if (get_cabac_bypass(&lc->cc)) // 0101 |
696 | 55217 | return PART_2NxnD; | |
697 | 63783 | return PART_2NxnU; // 0100 | |
698 | } | ||
699 | |||
700 |
2/2✓ Branch 1 taken 164578 times.
✓ Branch 2 taken 173337 times.
|
337915 | if (GET_CABAC(PART_MODE_OFFSET + 3)) // 001 |
701 | 164578 | return PART_Nx2N; | |
702 |
2/2✓ Branch 1 taken 80100 times.
✓ Branch 2 taken 93237 times.
|
173337 | if (get_cabac_bypass(&lc->cc)) // 0001 |
703 | 80100 | return PART_nRx2N; | |
704 | 93237 | return PART_nLx2N; // 0000 | |
705 | } | ||
706 | |||
707 | 153183 | int ff_hevc_pcm_flag_decode(HEVCLocalContext *lc) | |
708 | { | ||
709 | 153183 | return get_cabac_terminate(&lc->cc); | |
710 | } | ||
711 | |||
712 | 7548916 | int ff_hevc_prev_intra_luma_pred_flag_decode(HEVCLocalContext *lc) | |
713 | { | ||
714 | 7548916 | return GET_CABAC(PREV_INTRA_LUMA_PRED_FLAG_OFFSET); | |
715 | } | ||
716 | |||
717 | 4526900 | int ff_hevc_mpm_idx_decode(HEVCLocalContext *lc) | |
718 | { | ||
719 | 4526900 | int i = 0; | |
720 |
4/4✓ Branch 0 taken 6743145 times.
✓ Branch 1 taken 939968 times.
✓ Branch 3 taken 3156213 times.
✓ Branch 4 taken 3586932 times.
|
7683113 | while (i < 2 && get_cabac_bypass(&lc->cc)) |
721 | 3156213 | i++; | |
722 | 4526900 | return i; | |
723 | } | ||
724 | |||
725 | 3022016 | int ff_hevc_rem_intra_luma_pred_mode_decode(HEVCLocalContext *lc) | |
726 | { | ||
727 | int i; | ||
728 | 3022016 | int value = get_cabac_bypass(&lc->cc); | |
729 | |||
730 |
2/2✓ Branch 0 taken 12088064 times.
✓ Branch 1 taken 3022016 times.
|
15110080 | for (i = 0; i < 4; i++) |
731 | 12088064 | value = (value << 1) | get_cabac_bypass(&lc->cc); | |
732 | 3022016 | return value; | |
733 | } | ||
734 | |||
735 | 4064686 | int ff_hevc_intra_chroma_pred_mode_decode(HEVCLocalContext *lc) | |
736 | { | ||
737 | int ret; | ||
738 |
2/2✓ Branch 1 taken 3034439 times.
✓ Branch 2 taken 1030247 times.
|
4064686 | if (!GET_CABAC(INTRA_CHROMA_PRED_MODE_OFFSET)) |
739 | 3034439 | return 4; | |
740 | |||
741 | 1030247 | ret = get_cabac_bypass(&lc->cc) << 1; | |
742 | 1030247 | ret |= get_cabac_bypass(&lc->cc); | |
743 | 1030247 | return ret; | |
744 | } | ||
745 | |||
746 | 6152636 | int ff_hevc_merge_idx_decode(HEVCLocalContext *lc) | |
747 | { | ||
748 | 6152636 | int i = GET_CABAC(MERGE_IDX_OFFSET); | |
749 | |||
750 |
2/2✓ Branch 0 taken 2509379 times.
✓ Branch 1 taken 3643257 times.
|
6152636 | if (i != 0) { |
751 |
4/4✓ Branch 0 taken 3862190 times.
✓ Branch 1 taken 298398 times.
✓ Branch 3 taken 1651209 times.
✓ Branch 4 taken 2210981 times.
|
4160588 | while (i < lc->parent->sh.max_num_merge_cand-1 && get_cabac_bypass(&lc->cc)) |
752 | 1651209 | i++; | |
753 | } | ||
754 | 6152636 | return i; | |
755 | } | ||
756 | |||
757 | 4719272 | int ff_hevc_merge_flag_decode(HEVCLocalContext *lc) | |
758 | { | ||
759 | 4719272 | return GET_CABAC(MERGE_FLAG_OFFSET); | |
760 | } | ||
761 | |||
762 | 1811903 | int ff_hevc_inter_pred_idc_decode(HEVCLocalContext *lc, int nPbW, int nPbH) | |
763 | { | ||
764 |
2/2✓ Branch 0 taken 239847 times.
✓ Branch 1 taken 1572056 times.
|
1811903 | if (nPbW + nPbH == 12) |
765 | 239847 | return GET_CABAC(INTER_PRED_IDC_OFFSET + 4); | |
766 |
2/2✓ Branch 1 taken 404163 times.
✓ Branch 2 taken 1167893 times.
|
1572056 | if (GET_CABAC(INTER_PRED_IDC_OFFSET + lc->ct_depth)) |
767 | 404163 | return PRED_BI; | |
768 | |||
769 | 1167893 | return GET_CABAC(INTER_PRED_IDC_OFFSET + 4); | |
770 | } | ||
771 | |||
772 | 2787839 | int ff_hevc_ref_idx_lx_decode(HEVCLocalContext *lc, int num_ref_idx_lx) | |
773 | { | ||
774 | 2787839 | int i = 0; | |
775 | 2787839 | int max = num_ref_idx_lx - 1; | |
776 | 2787839 | int max_ctx = FFMIN(max, 2); | |
777 | |||
778 |
4/4✓ Branch 0 taken 2779159 times.
✓ Branch 1 taken 950948 times.
✓ Branch 3 taken 942268 times.
✓ Branch 4 taken 1836891 times.
|
3730107 | while (i < max_ctx && GET_CABAC(REF_IDX_L0_OFFSET + i)) |
779 | 942268 | i++; | |
780 |
2/2✓ Branch 0 taken 195870 times.
✓ Branch 1 taken 2591969 times.
|
2787839 | if (i == 2) { |
781 |
4/4✓ Branch 0 taken 160433 times.
✓ Branch 1 taken 120846 times.
✓ Branch 3 taken 85409 times.
✓ Branch 4 taken 75024 times.
|
281279 | while (i < max && get_cabac_bypass(&lc->cc)) |
782 | 85409 | i++; | |
783 | } | ||
784 | |||
785 | 2787839 | return i; | |
786 | } | ||
787 | |||
788 | 2787839 | int ff_hevc_mvp_lx_flag_decode(HEVCLocalContext *lc) | |
789 | { | ||
790 | 2787839 | return GET_CABAC(MVP_LX_FLAG_OFFSET); | |
791 | } | ||
792 | |||
793 | 2352059 | int ff_hevc_no_residual_syntax_flag_decode(HEVCLocalContext *lc) | |
794 | { | ||
795 | 2352059 | return GET_CABAC(NO_RESIDUAL_DATA_FLAG_OFFSET); | |
796 | } | ||
797 | |||
798 | 5260090 | static av_always_inline int abs_mvd_greater0_flag_decode(HEVCLocalContext *lc) | |
799 | { | ||
800 | 5260090 | return GET_CABAC(ABS_MVD_GREATER0_FLAG_OFFSET); | |
801 | } | ||
802 | |||
803 | 3599299 | static av_always_inline int abs_mvd_greater1_flag_decode(HEVCLocalContext *lc) | |
804 | { | ||
805 | 3599299 | return GET_CABAC(ABS_MVD_GREATER1_FLAG_OFFSET + 1); | |
806 | } | ||
807 | |||
808 | 2584076 | static av_always_inline int mvd_decode(HEVCLocalContext *lc) | |
809 | { | ||
810 | 2584076 | int ret = 2; | |
811 | 2584076 | int k = 1; | |
812 | |||
813 |
3/4✓ Branch 0 taken 6330044 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 3745968 times.
✓ Branch 4 taken 2584076 times.
|
6330044 | while (k < CABAC_MAX_BIN && get_cabac_bypass(&lc->cc)) { |
814 | 3745968 | ret += 1U << k; | |
815 | 3745968 | k++; | |
816 | } | ||
817 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2584076 times.
|
2584076 | if (k == CABAC_MAX_BIN) { |
818 | ✗ | av_log(lc->logctx, AV_LOG_ERROR, "CABAC_MAX_BIN : %d\n", k); | |
819 | ✗ | return 0; | |
820 | } | ||
821 |
2/2✓ Branch 0 taken 6330044 times.
✓ Branch 1 taken 2584076 times.
|
8914120 | while (k--) |
822 | 6330044 | ret += get_cabac_bypass(&lc->cc) << k; | |
823 | 2584076 | return get_cabac_bypass_sign(&lc->cc, -ret); | |
824 | } | ||
825 | |||
826 | 1015223 | static av_always_inline int mvd_sign_flag_decode(HEVCLocalContext *lc) | |
827 | { | ||
828 | 1015223 | return get_cabac_bypass_sign(&lc->cc, -1); | |
829 | } | ||
830 | |||
831 | 6856824 | int ff_hevc_split_transform_flag_decode(HEVCLocalContext *lc, int log2_trafo_size) | |
832 | { | ||
833 | 6856824 | return GET_CABAC(SPLIT_TRANSFORM_FLAG_OFFSET + 5 - log2_trafo_size); | |
834 | } | ||
835 | |||
836 | 15121987 | int ff_hevc_cbf_cb_cr_decode(HEVCLocalContext *lc, int trafo_depth) | |
837 | { | ||
838 | 15121987 | return GET_CABAC(CBF_CB_CR_OFFSET + trafo_depth); | |
839 | } | ||
840 | |||
841 | 14616568 | int ff_hevc_cbf_luma_decode(HEVCLocalContext *lc, int trafo_depth) | |
842 | { | ||
843 |
2/2✓ Branch 0 taken 2657275 times.
✓ Branch 1 taken 11959293 times.
|
14616568 | return GET_CABAC(CBF_LUMA_OFFSET + !trafo_depth); |
844 | } | ||
845 | |||
846 | 6506260 | static int hevc_transform_skip_flag_decode(HEVCLocalContext *lc, int c_idx) | |
847 | { | ||
848 |
2/2✓ Branch 0 taken 2221826 times.
✓ Branch 1 taken 4284434 times.
|
6506260 | return GET_CABAC(TRANSFORM_SKIP_FLAG_OFFSET + !!c_idx); |
849 | } | ||
850 | |||
851 | 35234 | static int explicit_rdpcm_flag_decode(HEVCLocalContext *lc, int c_idx) | |
852 | { | ||
853 |
2/2✓ Branch 0 taken 29253 times.
✓ Branch 1 taken 5981 times.
|
35234 | return GET_CABAC(EXPLICIT_RDPCM_FLAG_OFFSET + !!c_idx); |
854 | } | ||
855 | |||
856 | 3090 | static int explicit_rdpcm_dir_flag_decode(HEVCLocalContext *lc, int c_idx) | |
857 | { | ||
858 |
2/2✓ Branch 0 taken 1813 times.
✓ Branch 1 taken 1277 times.
|
3090 | return GET_CABAC(EXPLICIT_RDPCM_DIR_FLAG_OFFSET + !!c_idx); |
859 | } | ||
860 | |||
861 | 384850 | int ff_hevc_log2_res_scale_abs(HEVCLocalContext *lc, int idx) | |
862 | { | ||
863 | 384850 | int i =0; | |
864 | |||
865 |
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(LOG2_RES_SCALE_ABS_OFFSET + 4 * idx + i)) |
866 | 837742 | i++; | |
867 | |||
868 | 384850 | return i; | |
869 | } | ||
870 | |||
871 | 235843 | int ff_hevc_res_scale_sign_flag(HEVCLocalContext *lc, int idx) | |
872 | { | ||
873 | 235843 | return GET_CABAC(RES_SCALE_SIGN_FLAG_OFFSET + idx); | |
874 | } | ||
875 | |||
876 | 14151211 | static av_always_inline void last_significant_coeff_xy_prefix_decode(HEVCLocalContext *lc, int c_idx, | |
877 | int log2_size, int *last_scx_prefix, int *last_scy_prefix) | ||
878 | { | ||
879 | 14151211 | int i = 0; | |
880 | 14151211 | int max = (log2_size << 1) - 1; | |
881 | int ctx_offset, ctx_shift; | ||
882 | |||
883 |
2/2✓ Branch 0 taken 9698162 times.
✓ Branch 1 taken 4453049 times.
|
14151211 | if (!c_idx) { |
884 | 9698162 | ctx_offset = 3 * (log2_size - 2) + ((log2_size - 1) >> 2); | |
885 | 9698162 | ctx_shift = (log2_size + 1) >> 2; | |
886 | } else { | ||
887 | 4453049 | ctx_offset = 15; | |
888 | 4453049 | ctx_shift = log2_size - 2; | |
889 | } | ||
890 |
4/4✓ Branch 0 taken 34632989 times.
✓ Branch 1 taken 2099717 times.
✓ Branch 2 taken 22581495 times.
✓ Branch 3 taken 12051494 times.
|
71365695 | while (i < max && |
891 | 34632989 | GET_CABAC(LAST_SIGNIFICANT_COEFF_X_PREFIX_OFFSET + (i >> ctx_shift) + ctx_offset)) | |
892 | 22581495 | i++; | |
893 | 14151211 | *last_scx_prefix = i; | |
894 | |||
895 | 14151211 | i = 0; | |
896 |
4/4✓ Branch 0 taken 30030246 times.
✓ Branch 1 taken 1644167 times.
✓ Branch 2 taken 17523202 times.
✓ Branch 3 taken 12507044 times.
|
61704659 | while (i < max && |
897 | 30030246 | GET_CABAC(LAST_SIGNIFICANT_COEFF_Y_PREFIX_OFFSET + (i >> ctx_shift) + ctx_offset)) | |
898 | 17523202 | i++; | |
899 | 14151211 | *last_scy_prefix = i; | |
900 | 14151211 | } | |
901 | |||
902 | 3079717 | static av_always_inline int last_significant_coeff_suffix_decode(HEVCLocalContext *lc, | |
903 | int last_significant_coeff_prefix) | ||
904 | { | ||
905 | int i; | ||
906 | 3079717 | int length = (last_significant_coeff_prefix >> 1) - 1; | |
907 | 3079717 | int value = get_cabac_bypass(&lc->cc); | |
908 | |||
909 |
2/2✓ Branch 0 taken 862199 times.
✓ Branch 1 taken 3079717 times.
|
3941916 | for (i = 1; i < length; i++) |
910 | 862199 | value = (value << 1) | get_cabac_bypass(&lc->cc); | |
911 | 3079717 | return value; | |
912 | } | ||
913 | |||
914 | 8265512 | static av_always_inline int significant_coeff_group_flag_decode(HEVCLocalContext *lc, int c_idx, int ctx_cg) | |
915 | { | ||
916 | int inc; | ||
917 | |||
918 |
2/2✓ Branch 0 taken 1336741 times.
✓ Branch 1 taken 6928771 times.
|
8265512 | inc = FFMIN(ctx_cg, 1) + (c_idx>0 ? 2 : 0); |
919 | |||
920 | 8265512 | return GET_CABAC(SIGNIFICANT_COEFF_GROUP_FLAG_OFFSET + inc); | |
921 | } | ||
922 | 169371406 | static av_always_inline int significant_coeff_flag_decode(HEVCLocalContext *lc, int x_c, int y_c, | |
923 | int offset, const uint8_t *ctx_idx_map) | ||
924 | { | ||
925 | 169371406 | int inc = ctx_idx_map[(y_c << 2) + x_c] + offset; | |
926 | 169371406 | return GET_CABAC(SIGNIFICANT_COEFF_FLAG_OFFSET + inc); | |
927 | } | ||
928 | |||
929 | 18399017 | static av_always_inline int significant_coeff_flag_decode_0(HEVCLocalContext *lc, int c_idx, int offset) | |
930 | { | ||
931 | 18399017 | return GET_CABAC(SIGNIFICANT_COEFF_FLAG_OFFSET + offset); | |
932 | } | ||
933 | |||
934 | 90462727 | static av_always_inline int coeff_abs_level_greater1_flag_decode(HEVCLocalContext *lc, int c_idx, int inc) | |
935 | { | ||
936 | |||
937 |
2/2✓ Branch 0 taken 21330737 times.
✓ Branch 1 taken 69131990 times.
|
90462727 | if (c_idx > 0) |
938 | 21330737 | inc += 16; | |
939 | |||
940 | 90462727 | return GET_CABAC(COEFF_ABS_LEVEL_GREATER1_FLAG_OFFSET + inc); | |
941 | } | ||
942 | |||
943 | 10071703 | static av_always_inline int coeff_abs_level_greater2_flag_decode(HEVCLocalContext *lc, int c_idx, int inc) | |
944 | { | ||
945 |
2/2✓ Branch 0 taken 2130538 times.
✓ Branch 1 taken 7941165 times.
|
10071703 | if (c_idx > 0) |
946 | 2130538 | inc += 4; | |
947 | |||
948 | 10071703 | return GET_CABAC(COEFF_ABS_LEVEL_GREATER2_FLAG_OFFSET + inc); | |
949 | } | ||
950 | |||
951 | 40712348 | static av_always_inline int coeff_abs_level_remaining_decode(HEVCLocalContext *lc, int rc_rice_param) | |
952 | { | ||
953 | 40712348 | int prefix = 0; | |
954 | 40712348 | int suffix = 0; | |
955 | int last_coeff_abs_level_remaining; | ||
956 | int i; | ||
957 | |||
958 |
3/4✓ Branch 0 taken 89357220 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 48644872 times.
✓ Branch 4 taken 40712348 times.
|
89357220 | while (prefix < CABAC_MAX_BIN && get_cabac_bypass(&lc->cc)) |
959 | 48644872 | prefix++; | |
960 | |||
961 |
2/2✓ Branch 0 taken 34778844 times.
✓ Branch 1 taken 5933504 times.
|
40712348 | if (prefix < 3) { |
962 |
2/2✓ Branch 0 taken 36988478 times.
✓ Branch 1 taken 34778844 times.
|
71767322 | for (i = 0; i < rc_rice_param; i++) |
963 | 36988478 | suffix = (suffix << 1) | get_cabac_bypass(&lc->cc); | |
964 | 34778844 | last_coeff_abs_level_remaining = (prefix << rc_rice_param) + suffix; | |
965 | } else { | ||
966 | 5933504 | int prefix_minus3 = prefix - 3; | |
967 | |||
968 |
2/4✓ Branch 0 taken 5933504 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 5933504 times.
|
5933504 | if (prefix == CABAC_MAX_BIN || prefix_minus3 + rc_rice_param > 16 + 6) { |
969 | ✗ | av_log(lc->logctx, AV_LOG_ERROR, "CABAC_MAX_BIN : %d\n", prefix); | |
970 | ✗ | return 0; | |
971 | } | ||
972 | |||
973 |
2/2✓ Branch 0 taken 19439036 times.
✓ Branch 1 taken 5933504 times.
|
25372540 | for (i = 0; i < prefix_minus3 + rc_rice_param; i++) |
974 | 19439036 | suffix = (suffix << 1) | get_cabac_bypass(&lc->cc); | |
975 | 5933504 | last_coeff_abs_level_remaining = (((1 << prefix_minus3) + 3 - 1) | |
976 | 5933504 | << rc_rice_param) + suffix; | |
977 | } | ||
978 | 40712348 | return last_coeff_abs_level_remaining; | |
979 | } | ||
980 | |||
981 | 21584155 | static av_always_inline int coeff_sign_flag_decode(HEVCLocalContext *lc, uint8_t nb) | |
982 | { | ||
983 | int i; | ||
984 | 21584155 | int ret = 0; | |
985 | |||
986 |
2/2✓ Branch 0 taken 97429015 times.
✓ Branch 1 taken 21584155 times.
|
119013170 | for (i = 0; i < nb; i++) |
987 | 97429015 | ret = (ret << 1) | get_cabac_bypass(&lc->cc); | |
988 | 21584155 | return ret; | |
989 | } | ||
990 | |||
991 | 14151211 | void ff_hevc_hls_residual_coding(HEVCLocalContext *lc, int x0, int y0, | |
992 | int log2_trafo_size, enum ScanType scan_idx, | ||
993 | int c_idx) | ||
994 | { | ||
995 | #define GET_COORD(offset, n) \ | ||
996 | do { \ | ||
997 | x_c = (x_cg << 2) + scan_x_off[n]; \ | ||
998 | y_c = (y_cg << 2) + scan_y_off[n]; \ | ||
999 | } while (0) | ||
1000 | 14151211 | const HEVCContext *const s = lc->parent; | |
1001 | 14151211 | int transform_skip_flag = 0; | |
1002 | |||
1003 | int last_significant_coeff_x, last_significant_coeff_y; | ||
1004 | int last_scan_pos; | ||
1005 | int n_end; | ||
1006 | 14151211 | int num_coeff = 0; | |
1007 | 14151211 | int greater1_ctx = 1; | |
1008 | |||
1009 | int num_last_subset; | ||
1010 | int x_cg_last_sig, y_cg_last_sig; | ||
1011 | |||
1012 | const uint8_t *scan_x_cg, *scan_y_cg, *scan_x_off, *scan_y_off; | ||
1013 | |||
1014 | 14151211 | ptrdiff_t stride = s->frame->linesize[c_idx]; | |
1015 | 14151211 | int hshift = s->ps.sps->hshift[c_idx]; | |
1016 | 14151211 | int vshift = s->ps.sps->vshift[c_idx]; | |
1017 | 14151211 | uint8_t *dst = &s->frame->data[c_idx][(y0 >> vshift) * stride + | |
1018 | 14151211 | ((x0 >> hshift) << s->ps.sps->pixel_shift)]; | |
1019 |
2/2✓ Branch 0 taken 4453049 times.
✓ Branch 1 taken 9698162 times.
|
14151211 | int16_t *coeffs = (int16_t*)(c_idx ? lc->edge_emu_buffer2 : lc->edge_emu_buffer); |
1020 | 14151211 | uint8_t significant_coeff_group_flag[8][8] = {{0}}; | |
1021 | 14151211 | int explicit_rdpcm_flag = 0; | |
1022 | int explicit_rdpcm_dir_flag; | ||
1023 | |||
1024 | 14151211 | int trafo_size = 1 << log2_trafo_size; | |
1025 | int i; | ||
1026 | int qp,shift,add,scale,scale_m; | ||
1027 | static const uint8_t level_scale[] = { 40, 45, 51, 57, 64, 72 }; | ||
1028 | 14151211 | const uint8_t *scale_matrix = NULL; | |
1029 | uint8_t dc_scale; | ||
1030 |
2/2✓ Branch 0 taken 9698162 times.
✓ Branch 1 taken 4453049 times.
|
14151211 | int pred_mode_intra = (c_idx == 0) ? lc->tu.intra_pred_mode : |
1031 | lc->tu.intra_pred_mode_c; | ||
1032 | |||
1033 | 14151211 | memset(coeffs, 0, trafo_size * trafo_size * sizeof(int16_t)); | |
1034 | |||
1035 | // Derive QP for dequant | ||
1036 |
2/2✓ Branch 0 taken 13712845 times.
✓ Branch 1 taken 438366 times.
|
14151211 | if (!lc->cu.cu_transquant_bypass_flag) { |
1037 | static const int qp_c[] = { 29, 30, 31, 32, 33, 33, 34, 34, 35, 35, 36, 36, 37, 37 }; | ||
1038 | static const uint8_t rem6[51 + 4 * 6 + 1] = { | ||
1039 | 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, | ||
1040 | 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, | ||
1041 | 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, | ||
1042 | 4, 5, 0, 1, 2, 3, 4, 5, 0, 1 | ||
1043 | }; | ||
1044 | |||
1045 | static const uint8_t div6[51 + 4 * 6 + 1] = { | ||
1046 | 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, | ||
1047 | 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, | ||
1048 | 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, | ||
1049 | 10, 10, 11, 11, 11, 11, 11, 11, 12, 12 | ||
1050 | }; | ||
1051 | 13712845 | int qp_y = lc->qp_y; | |
1052 | |||
1053 |
2/2✓ Branch 0 taken 11257982 times.
✓ Branch 1 taken 2454863 times.
|
13712845 | if (s->ps.pps->transform_skip_enabled_flag && |
1054 |
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) { |
1055 | 6506260 | transform_skip_flag = hevc_transform_skip_flag_decode(lc, c_idx); | |
1056 | } | ||
1057 | |||
1058 |
2/2✓ Branch 0 taken 9422914 times.
✓ Branch 1 taken 4289931 times.
|
13712845 | if (c_idx == 0) { |
1059 | 9422914 | qp = qp_y + s->ps.sps->qp_bd_offset; | |
1060 | } else { | ||
1061 | int qp_i, offset; | ||
1062 | |||
1063 |
2/2✓ Branch 0 taken 2047560 times.
✓ Branch 1 taken 2242371 times.
|
4289931 | if (c_idx == 1) |
1064 | 2047560 | offset = s->ps.pps->cb_qp_offset + s->sh.slice_cb_qp_offset + | |
1065 | 2047560 | lc->tu.cu_qp_offset_cb; | |
1066 | else | ||
1067 | 2242371 | offset = s->ps.pps->cr_qp_offset + s->sh.slice_cr_qp_offset + | |
1068 | 2242371 | lc->tu.cu_qp_offset_cr; | |
1069 | |||
1070 | 4289931 | qp_i = av_clip(qp_y + offset, - s->ps.sps->qp_bd_offset, 57); | |
1071 |
2/2✓ Branch 0 taken 2423826 times.
✓ Branch 1 taken 1866105 times.
|
4289931 | if (s->ps.sps->chroma_format_idc == 1) { |
1072 |
2/2✓ Branch 0 taken 739689 times.
✓ Branch 1 taken 1684137 times.
|
2423826 | if (qp_i < 30) |
1073 | 739689 | qp = qp_i; | |
1074 |
2/2✓ Branch 0 taken 9279 times.
✓ Branch 1 taken 1674858 times.
|
1684137 | else if (qp_i > 43) |
1075 | 9279 | qp = qp_i - 6; | |
1076 | else | ||
1077 | 1674858 | qp = qp_c[qp_i - 30]; | |
1078 | } else { | ||
1079 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1866105 times.
|
1866105 | if (qp_i > 51) |
1080 | ✗ | qp = 51; | |
1081 | else | ||
1082 | 1866105 | qp = qp_i; | |
1083 | } | ||
1084 | |||
1085 | 4289931 | qp += s->ps.sps->qp_bd_offset; | |
1086 | } | ||
1087 | |||
1088 | 13712845 | shift = s->ps.sps->bit_depth + log2_trafo_size - 5; | |
1089 | 13712845 | add = 1 << (shift-1); | |
1090 | 13712845 | scale = level_scale[rem6[qp]] << (div6[qp]); | |
1091 | 13712845 | scale_m = 16; // default when no custom scaling lists. | |
1092 | 13712845 | dc_scale = 16; | |
1093 | |||
1094 |
6/6✓ Branch 0 taken 484014 times.
✓ Branch 1 taken 13228831 times.
✓ Branch 2 taken 26526 times.
✓ Branch 3 taken 457488 times.
✓ Branch 4 taken 14292 times.
✓ Branch 5 taken 12234 times.
|
13712845 | if (s->ps.sps->scaling_list_enable_flag && !(transform_skip_flag && log2_trafo_size > 2)) { |
1095 | 943560 | const ScalingList *sl = s->ps.pps->scaling_list_data_present_flag ? | |
1096 |
2/2✓ Branch 0 taken 357638 times.
✓ Branch 1 taken 114142 times.
|
471780 | &s->ps.pps->scaling_list : &s->ps.sps->scaling_list; |
1097 | 471780 | int matrix_id = lc->cu.pred_mode != MODE_INTRA; | |
1098 | |||
1099 | 471780 | matrix_id = 3 * matrix_id + c_idx; | |
1100 | |||
1101 | 471780 | scale_matrix = sl->sl[log2_trafo_size - 2][matrix_id]; | |
1102 |
2/2✓ Branch 0 taken 42637 times.
✓ Branch 1 taken 429143 times.
|
471780 | if (log2_trafo_size >= 4) |
1103 | 42637 | dc_scale = sl->sl_dc[log2_trafo_size - 4][matrix_id]; | |
1104 | } | ||
1105 | } else { | ||
1106 | 438366 | shift = 0; | |
1107 | 438366 | add = 0; | |
1108 | 438366 | scale = 0; | |
1109 | 438366 | dc_scale = 0; | |
1110 | } | ||
1111 | |||
1112 |
6/6✓ Branch 0 taken 4620877 times.
✓ Branch 1 taken 9530334 times.
✓ Branch 2 taken 225511 times.
✓ Branch 3 taken 4395366 times.
✓ Branch 4 taken 190277 times.
✓ Branch 5 taken 35234 times.
|
14151211 | if (lc->cu.pred_mode == MODE_INTER && s->ps.sps->explicit_rdpcm_enabled_flag && |
1113 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 190277 times.
|
190277 | (transform_skip_flag || lc->cu.cu_transquant_bypass_flag)) { |
1114 | 35234 | explicit_rdpcm_flag = explicit_rdpcm_flag_decode(lc, c_idx); | |
1115 |
2/2✓ Branch 0 taken 3090 times.
✓ Branch 1 taken 32144 times.
|
35234 | if (explicit_rdpcm_flag) { |
1116 | 3090 | explicit_rdpcm_dir_flag = explicit_rdpcm_dir_flag_decode(lc, c_idx); | |
1117 | } | ||
1118 | } | ||
1119 | |||
1120 | 14151211 | last_significant_coeff_xy_prefix_decode(lc, c_idx, log2_trafo_size, | |
1121 | &last_significant_coeff_x, &last_significant_coeff_y); | ||
1122 | |||
1123 |
2/2✓ Branch 0 taken 1801587 times.
✓ Branch 1 taken 12349624 times.
|
14151211 | if (last_significant_coeff_x > 3) { |
1124 | 1801587 | int suffix = last_significant_coeff_suffix_decode(lc, last_significant_coeff_x); | |
1125 | 1801587 | last_significant_coeff_x = (1 << ((last_significant_coeff_x >> 1) - 1)) * | |
1126 | 1801587 | (2 + (last_significant_coeff_x & 1)) + | |
1127 | suffix; | ||
1128 | } | ||
1129 | |||
1130 |
2/2✓ Branch 0 taken 1278130 times.
✓ Branch 1 taken 12873081 times.
|
14151211 | if (last_significant_coeff_y > 3) { |
1131 | 1278130 | int suffix = last_significant_coeff_suffix_decode(lc, last_significant_coeff_y); | |
1132 | 1278130 | last_significant_coeff_y = (1 << ((last_significant_coeff_y >> 1) - 1)) * | |
1133 | 1278130 | (2 + (last_significant_coeff_y & 1)) + | |
1134 | suffix; | ||
1135 | } | ||
1136 | |||
1137 |
2/2✓ Branch 0 taken 1816895 times.
✓ Branch 1 taken 12334316 times.
|
14151211 | if (scan_idx == SCAN_VERT) |
1138 | 1816895 | FFSWAP(int, last_significant_coeff_x, last_significant_coeff_y); | |
1139 | |||
1140 | 14151211 | x_cg_last_sig = last_significant_coeff_x >> 2; | |
1141 | 14151211 | y_cg_last_sig = last_significant_coeff_y >> 2; | |
1142 | |||
1143 |
3/3✓ Branch 0 taken 10304167 times.
✓ Branch 1 taken 2030149 times.
✓ Branch 2 taken 1816895 times.
|
14151211 | switch (scan_idx) { |
1144 | 10304167 | case SCAN_DIAG: { | |
1145 | 10304167 | int last_x_c = last_significant_coeff_x & 3; | |
1146 | 10304167 | int last_y_c = last_significant_coeff_y & 3; | |
1147 | |||
1148 | 10304167 | scan_x_off = ff_hevc_diag_scan4x4_x; | |
1149 | 10304167 | scan_y_off = ff_hevc_diag_scan4x4_y; | |
1150 | 10304167 | num_coeff = diag_scan4x4_inv[last_y_c][last_x_c]; | |
1151 |
2/2✓ Branch 0 taken 5248769 times.
✓ Branch 1 taken 5055398 times.
|
10304167 | if (trafo_size == 4) { |
1152 | 5248769 | scan_x_cg = scan_1x1; | |
1153 | 5248769 | scan_y_cg = scan_1x1; | |
1154 |
2/2✓ Branch 0 taken 2777241 times.
✓ Branch 1 taken 2278157 times.
|
5055398 | } else if (trafo_size == 8) { |
1155 | 2777241 | num_coeff += diag_scan2x2_inv[y_cg_last_sig][x_cg_last_sig] << 4; | |
1156 | 2777241 | scan_x_cg = diag_scan2x2_x; | |
1157 | 2777241 | scan_y_cg = diag_scan2x2_y; | |
1158 |
2/2✓ Branch 0 taken 1688862 times.
✓ Branch 1 taken 589295 times.
|
2278157 | } else if (trafo_size == 16) { |
1159 | 1688862 | num_coeff += diag_scan4x4_inv[y_cg_last_sig][x_cg_last_sig] << 4; | |
1160 | 1688862 | scan_x_cg = ff_hevc_diag_scan4x4_x; | |
1161 | 1688862 | scan_y_cg = ff_hevc_diag_scan4x4_y; | |
1162 | } else { // trafo_size == 32 | ||
1163 | 589295 | num_coeff += diag_scan8x8_inv[y_cg_last_sig][x_cg_last_sig] << 4; | |
1164 | 589295 | scan_x_cg = ff_hevc_diag_scan8x8_x; | |
1165 | 589295 | scan_y_cg = ff_hevc_diag_scan8x8_y; | |
1166 | } | ||
1167 | 10304167 | break; | |
1168 | } | ||
1169 | 2030149 | case SCAN_HORIZ: | |
1170 | 2030149 | scan_x_cg = horiz_scan2x2_x; | |
1171 | 2030149 | scan_y_cg = horiz_scan2x2_y; | |
1172 | 2030149 | scan_x_off = horiz_scan4x4_x; | |
1173 | 2030149 | scan_y_off = horiz_scan4x4_y; | |
1174 | 2030149 | num_coeff = horiz_scan8x8_inv[last_significant_coeff_y][last_significant_coeff_x]; | |
1175 | 2030149 | break; | |
1176 | 1816895 | default: //SCAN_VERT | |
1177 | 1816895 | scan_x_cg = horiz_scan2x2_y; | |
1178 | 1816895 | scan_y_cg = horiz_scan2x2_x; | |
1179 | 1816895 | scan_x_off = horiz_scan4x4_y; | |
1180 | 1816895 | scan_y_off = horiz_scan4x4_x; | |
1181 | 1816895 | num_coeff = horiz_scan8x8_inv[last_significant_coeff_x][last_significant_coeff_y]; | |
1182 | 1816895 | break; | |
1183 | } | ||
1184 | 14151211 | num_coeff++; | |
1185 | 14151211 | num_last_subset = (num_coeff - 1) >> 4; | |
1186 | |||
1187 |
2/2✓ Branch 0 taken 24785846 times.
✓ Branch 1 taken 14151211 times.
|
38937057 | for (i = num_last_subset; i >= 0; i--) { |
1188 | int n, m; | ||
1189 | int x_cg, y_cg, x_c, y_c, pos; | ||
1190 | 24785846 | int implicit_non_zero_coeff = 0; | |
1191 | int64_t trans_coeff_level; | ||
1192 | 24785846 | int prev_sig = 0; | |
1193 | 24785846 | int offset = i << 4; | |
1194 | 24785846 | int rice_init = 0; | |
1195 | |||
1196 | uint8_t significant_coeff_flag_idx[16]; | ||
1197 | 24785846 | uint8_t nb_significant_coeff_flag = 0; | |
1198 | |||
1199 | 24785846 | x_cg = scan_x_cg[i]; | |
1200 | 24785846 | y_cg = scan_y_cg[i]; | |
1201 | |||
1202 |
4/4✓ Branch 0 taken 10634635 times.
✓ Branch 1 taken 14151211 times.
✓ Branch 2 taken 8265512 times.
✓ Branch 3 taken 2369123 times.
|
24785846 | if ((i < num_last_subset) && (i > 0)) { |
1203 | 8265512 | int ctx_cg = 0; | |
1204 |
2/2✓ Branch 0 taken 7556433 times.
✓ Branch 1 taken 709079 times.
|
8265512 | if (x_cg < (1 << (log2_trafo_size - 2)) - 1) |
1205 | 7556433 | ctx_cg += significant_coeff_group_flag[x_cg + 1][y_cg]; | |
1206 |
2/2✓ Branch 0 taken 6973467 times.
✓ Branch 1 taken 1292045 times.
|
8265512 | if (y_cg < (1 << (log2_trafo_size - 2)) - 1) |
1207 | 6973467 | ctx_cg += significant_coeff_group_flag[x_cg][y_cg + 1]; | |
1208 | |||
1209 | 8265512 | significant_coeff_group_flag[x_cg][y_cg] = | |
1210 | 8265512 | significant_coeff_group_flag_decode(lc, c_idx, ctx_cg); | |
1211 | 8265512 | implicit_non_zero_coeff = 1; | |
1212 | } else { | ||
1213 | 16520334 | significant_coeff_group_flag[x_cg][y_cg] = | |
1214 |
5/6✓ Branch 0 taken 14825816 times.
✓ Branch 1 taken 1694518 times.
✓ Branch 2 taken 674605 times.
✓ Branch 3 taken 14151211 times.
✓ Branch 4 taken 2369123 times.
✗ Branch 5 not taken.
|
18889457 | ((x_cg == x_cg_last_sig && y_cg == y_cg_last_sig) || |
1215 |
1/2✓ Branch 0 taken 2369123 times.
✗ Branch 1 not taken.
|
2369123 | (x_cg == 0 && y_cg == 0)); |
1216 | } | ||
1217 | |||
1218 | 24785846 | last_scan_pos = num_coeff - offset - 1; | |
1219 | |||
1220 |
2/2✓ Branch 0 taken 14151211 times.
✓ Branch 1 taken 10634635 times.
|
24785846 | if (i == num_last_subset) { |
1221 | 14151211 | n_end = last_scan_pos - 1; | |
1222 | 14151211 | significant_coeff_flag_idx[0] = last_scan_pos; | |
1223 | 14151211 | nb_significant_coeff_flag = 1; | |
1224 | } else { | ||
1225 | 10634635 | n_end = 15; | |
1226 | } | ||
1227 | |||
1228 |
2/2✓ Branch 0 taken 14870190 times.
✓ Branch 1 taken 9915656 times.
|
24785846 | if (x_cg < ((1 << log2_trafo_size) - 1) >> 2) |
1229 | 14870190 | prev_sig = !!significant_coeff_group_flag[x_cg + 1][y_cg]; | |
1230 |
2/2✓ Branch 0 taken 14443801 times.
✓ Branch 1 taken 10342045 times.
|
24785846 | if (y_cg < ((1 << log2_trafo_size) - 1) >> 2) |
1231 |
2/2✓ Branch 0 taken 5138069 times.
✓ Branch 1 taken 9305732 times.
|
14443801 | prev_sig += (!!significant_coeff_group_flag[x_cg][y_cg + 1] << 1); |
1232 | |||
1233 |
4/4✓ Branch 0 taken 21669721 times.
✓ Branch 1 taken 3116125 times.
✓ Branch 2 taken 18469556 times.
✓ Branch 3 taken 3200165 times.
|
24785846 | if (significant_coeff_group_flag[x_cg][y_cg] && n_end >= 0) { |
1234 | static const uint8_t ctx_idx_map[] = { | ||
1235 | 0, 1, 4, 5, 2, 3, 4, 5, 6, 6, 8, 8, 7, 7, 8, 8, // log2_trafo_size == 2 | ||
1236 | 1, 1, 1, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, // prev_sig == 0 | ||
1237 | 2, 2, 2, 2, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, // prev_sig == 1 | ||
1238 | 2, 1, 0, 0, 2, 1, 0, 0, 2, 1, 0, 0, 2, 1, 0, 0, // prev_sig == 2 | ||
1239 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 // default | ||
1240 | }; | ||
1241 | const uint8_t *ctx_idx_map_p; | ||
1242 | 18469556 | int scf_offset = 0; | |
1243 |
4/4✓ Branch 0 taken 1017071 times.
✓ Branch 1 taken 17452485 times.
✓ Branch 2 taken 886760 times.
✓ Branch 3 taken 130311 times.
|
18469556 | if (s->ps.sps->transform_skip_context_enabled_flag && |
1244 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 886760 times.
|
886760 | (transform_skip_flag || lc->cu.cu_transquant_bypass_flag)) { |
1245 | 130311 | ctx_idx_map_p = &ctx_idx_map[4 * 16]; | |
1246 |
2/2✓ Branch 0 taken 61311 times.
✓ Branch 1 taken 69000 times.
|
130311 | if (c_idx == 0) { |
1247 | 61311 | scf_offset = 40; | |
1248 | } else { | ||
1249 | 69000 | scf_offset = 14 + 27; | |
1250 | } | ||
1251 | } else { | ||
1252 |
2/2✓ Branch 0 taken 4405520 times.
✓ Branch 1 taken 13933725 times.
|
18339245 | if (c_idx != 0) |
1253 | 4405520 | scf_offset = 27; | |
1254 |
2/2✓ Branch 0 taken 6338730 times.
✓ Branch 1 taken 12000515 times.
|
18339245 | if (log2_trafo_size == 2) { |
1255 | 6338730 | ctx_idx_map_p = &ctx_idx_map[0]; | |
1256 | } else { | ||
1257 | 12000515 | ctx_idx_map_p = &ctx_idx_map[(prev_sig + 1) << 4]; | |
1258 |
2/2✓ Branch 0 taken 9613150 times.
✓ Branch 1 taken 2387365 times.
|
12000515 | if (c_idx == 0) { |
1259 |
4/4✓ Branch 0 taken 5804751 times.
✓ Branch 1 taken 3808399 times.
✓ Branch 2 taken 2015533 times.
✓ Branch 3 taken 3789218 times.
|
9613150 | if ((x_cg > 0 || y_cg > 0)) |
1260 | 5823932 | scf_offset += 3; | |
1261 |
2/2✓ Branch 0 taken 3604431 times.
✓ Branch 1 taken 6008719 times.
|
9613150 | if (log2_trafo_size == 3) { |
1262 |
2/2✓ Branch 0 taken 2502219 times.
✓ Branch 1 taken 1102212 times.
|
3604431 | scf_offset += (scan_idx == SCAN_DIAG) ? 9 : 15; |
1263 | } else { | ||
1264 | 6008719 | scf_offset += 21; | |
1265 | } | ||
1266 | } else { | ||
1267 |
2/2✓ Branch 0 taken 1135141 times.
✓ Branch 1 taken 1252224 times.
|
2387365 | if (log2_trafo_size == 3) |
1268 | 1135141 | scf_offset += 9; | |
1269 | else | ||
1270 | 1252224 | scf_offset += 12; | |
1271 | } | ||
1272 | } | ||
1273 | } | ||
1274 |
2/2✓ Branch 0 taken 169371406 times.
✓ Branch 1 taken 18469556 times.
|
187840962 | for (n = n_end; n > 0; n--) { |
1275 | 169371406 | x_c = scan_x_off[n]; | |
1276 | 169371406 | y_c = scan_y_off[n]; | |
1277 |
2/2✓ Branch 1 taken 81628371 times.
✓ Branch 2 taken 87743035 times.
|
169371406 | if (significant_coeff_flag_decode(lc, x_c, y_c, scf_offset, ctx_idx_map_p)) { |
1278 | 81628371 | significant_coeff_flag_idx[nb_significant_coeff_flag] = n; | |
1279 | 81628371 | nb_significant_coeff_flag++; | |
1280 | 81628371 | implicit_non_zero_coeff = 0; | |
1281 | } | ||
1282 | } | ||
1283 |
2/2✓ Branch 0 taken 18399017 times.
✓ Branch 1 taken 70539 times.
|
18469556 | if (implicit_non_zero_coeff == 0) { |
1284 |
4/4✓ Branch 0 taken 1014653 times.
✓ Branch 1 taken 17384364 times.
✓ Branch 2 taken 884736 times.
✓ Branch 3 taken 129917 times.
|
18399017 | if (s->ps.sps->transform_skip_context_enabled_flag && |
1285 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 884736 times.
|
884736 | (transform_skip_flag || lc->cu.cu_transquant_bypass_flag)) { |
1286 |
2/2✓ Branch 0 taken 61056 times.
✓ Branch 1 taken 68861 times.
|
129917 | if (c_idx == 0) { |
1287 | 61056 | scf_offset = 42; | |
1288 | } else { | ||
1289 | 68861 | scf_offset = 16 + 27; | |
1290 | } | ||
1291 | } else { | ||
1292 |
2/2✓ Branch 0 taken 11194974 times.
✓ Branch 1 taken 7074126 times.
|
18269100 | if (i == 0) { |
1293 |
2/2✓ Branch 0 taken 8109793 times.
✓ Branch 1 taken 3085181 times.
|
11194974 | if (c_idx == 0) |
1294 | 8109793 | scf_offset = 0; | |
1295 | else | ||
1296 | 3085181 | scf_offset = 27; | |
1297 | } else { | ||
1298 | 7074126 | scf_offset = 2 + scf_offset; | |
1299 | } | ||
1300 | } | ||
1301 |
2/2✓ Branch 1 taken 12403751 times.
✓ Branch 2 taken 5995266 times.
|
18399017 | if (significant_coeff_flag_decode_0(lc, c_idx, scf_offset) == 1) { |
1302 | 12403751 | significant_coeff_flag_idx[nb_significant_coeff_flag] = 0; | |
1303 | 12403751 | nb_significant_coeff_flag++; | |
1304 | } | ||
1305 | } else { | ||
1306 | 70539 | significant_coeff_flag_idx[nb_significant_coeff_flag] = 0; | |
1307 | 70539 | nb_significant_coeff_flag++; | |
1308 | } | ||
1309 | } | ||
1310 | |||
1311 | 24785846 | n_end = nb_significant_coeff_flag; | |
1312 | |||
1313 | |||
1314 |
2/2✓ Branch 0 taken 21584155 times.
✓ Branch 1 taken 3201691 times.
|
24785846 | if (n_end) { |
1315 | int first_nz_pos_in_cg; | ||
1316 | int last_nz_pos_in_cg; | ||
1317 | 21584155 | int c_rice_param = 0; | |
1318 | 21584155 | int first_greater1_coeff_idx = -1; | |
1319 | uint8_t coeff_abs_level_greater1_flag[8]; | ||
1320 | uint16_t coeff_sign_flag; | ||
1321 | 21584155 | int sum_abs = 0; | |
1322 | int sign_hidden; | ||
1323 | int sb_type; | ||
1324 | |||
1325 | |||
1326 | // initialize first elem of coeff_bas_level_greater1_flag | ||
1327 |
4/4✓ Branch 0 taken 7518510 times.
✓ Branch 1 taken 14065645 times.
✓ Branch 2 taken 6108421 times.
✓ Branch 3 taken 1410089 times.
|
21584155 | int ctx_set = (i > 0 && c_idx == 0) ? 2 : 0; |
1328 | |||
1329 |
2/2✓ Branch 0 taken 1166629 times.
✓ Branch 1 taken 20417526 times.
|
21584155 | if (s->ps.sps->persistent_rice_adaptation_enabled_flag) { |
1330 |
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) |
1331 |
2/2✓ Branch 0 taken 365016 times.
✓ Branch 1 taken 682024 times.
|
1047040 | sb_type = 2 * (c_idx == 0 ? 1 : 0); |
1332 | else | ||
1333 |
2/2✓ Branch 0 taken 56576 times.
✓ Branch 1 taken 63013 times.
|
119589 | sb_type = 2 * (c_idx == 0 ? 1 : 0) + 1; |
1334 | 1166629 | c_rice_param = lc->stat_coeff[sb_type] / 4; | |
1335 | } | ||
1336 | |||
1337 |
4/4✓ Branch 0 taken 7432944 times.
✓ Branch 1 taken 14151211 times.
✓ Branch 2 taken 3314321 times.
✓ Branch 3 taken 4118623 times.
|
21584155 | if (!(i == num_last_subset) && greater1_ctx == 0) |
1338 | 3314321 | ctx_set++; | |
1339 | 21584155 | greater1_ctx = 1; | |
1340 | 21584155 | last_nz_pos_in_cg = significant_coeff_flag_idx[0]; | |
1341 | |||
1342 |
2/2✓ Branch 0 taken 90462727 times.
✓ Branch 1 taken 21584155 times.
|
112046882 | for (m = 0; m < (n_end > 8 ? 8 : n_end); m++) { |
1343 | 90462727 | int inc = (ctx_set << 2) + greater1_ctx; | |
1344 | 90462727 | coeff_abs_level_greater1_flag[m] = | |
1345 | 90462727 | coeff_abs_level_greater1_flag_decode(lc, c_idx, inc); | |
1346 |
2/2✓ Branch 0 taken 29800254 times.
✓ Branch 1 taken 60662473 times.
|
90462727 | if (coeff_abs_level_greater1_flag[m]) { |
1347 | 29800254 | greater1_ctx = 0; | |
1348 |
2/2✓ Branch 0 taken 10071703 times.
✓ Branch 1 taken 19728551 times.
|
29800254 | if (first_greater1_coeff_idx == -1) |
1349 | 10071703 | first_greater1_coeff_idx = m; | |
1350 |
4/4✓ Branch 0 taken 48104928 times.
✓ Branch 1 taken 12557545 times.
✓ Branch 2 taken 29631618 times.
✓ Branch 3 taken 18473310 times.
|
60662473 | } else if (greater1_ctx > 0 && greater1_ctx < 3) { |
1351 | 29631618 | greater1_ctx++; | |
1352 | } | ||
1353 | } | ||
1354 | 21584155 | first_nz_pos_in_cg = significant_coeff_flag_idx[n_end - 1]; | |
1355 | |||
1356 |
2/2✓ Branch 0 taken 20880668 times.
✓ Branch 1 taken 703487 times.
|
21584155 | if (lc->cu.cu_transquant_bypass_flag || |
1357 |
2/2✓ Branch 0 taken 13474523 times.
✓ Branch 1 taken 7406145 times.
|
20880668 | (lc->cu.pred_mode == MODE_INTRA && |
1358 |
6/6✓ Branch 0 taken 902776 times.
✓ Branch 1 taken 12571747 times.
✓ Branch 2 taken 92431 times.
✓ Branch 3 taken 810345 times.
✓ Branch 4 taken 47376 times.
✓ Branch 5 taken 45055 times.
|
13474523 | s->ps.sps->implicit_rdpcm_enabled_flag && transform_skip_flag && |
1359 |
4/4✓ Branch 0 taken 28377 times.
✓ Branch 1 taken 18999 times.
✓ Branch 2 taken 5999 times.
✓ Branch 3 taken 20810615 times.
|
20835613 | (pred_mode_intra == 10 || pred_mode_intra == 26 )) || |
1360 | explicit_rdpcm_flag) | ||
1361 | 773540 | sign_hidden = 0; | |
1362 | else | ||
1363 | 20810615 | sign_hidden = (last_nz_pos_in_cg - first_nz_pos_in_cg >= 4); | |
1364 | |||
1365 |
2/2✓ Branch 0 taken 10071703 times.
✓ Branch 1 taken 11512452 times.
|
21584155 | if (first_greater1_coeff_idx != -1) { |
1366 | 10071703 | coeff_abs_level_greater1_flag[first_greater1_coeff_idx] += coeff_abs_level_greater2_flag_decode(lc, c_idx, ctx_set); | |
1367 | } | ||
1368 |
4/4✓ Branch 0 taken 19228678 times.
✓ Branch 1 taken 2355477 times.
✓ Branch 2 taken 8403821 times.
✓ Branch 3 taken 10824857 times.
|
21584155 | if (!s->ps.pps->sign_data_hiding_flag || !sign_hidden ) { |
1369 | 10759298 | coeff_sign_flag = coeff_sign_flag_decode(lc, nb_significant_coeff_flag) << (16 - nb_significant_coeff_flag); | |
1370 | } else { | ||
1371 | 10824857 | coeff_sign_flag = coeff_sign_flag_decode(lc, nb_significant_coeff_flag - 1) << (16 - (nb_significant_coeff_flag - 1)); | |
1372 | } | ||
1373 | |||
1374 |
2/2✓ Branch 0 taken 108253872 times.
✓ Branch 1 taken 21584155 times.
|
129838027 | for (m = 0; m < n_end; m++) { |
1375 | 108253872 | n = significant_coeff_flag_idx[m]; | |
1376 | 108253872 | GET_COORD(offset, n); | |
1377 |
2/2✓ Branch 0 taken 90462727 times.
✓ Branch 1 taken 17791145 times.
|
108253872 | if (m < 8) { |
1378 | 90462727 | trans_coeff_level = 1 + coeff_abs_level_greater1_flag[m]; | |
1379 |
4/4✓ Branch 0 taken 10071703 times.
✓ Branch 1 taken 80391024 times.
✓ Branch 2 taken 22921203 times.
✓ Branch 3 taken 67541524 times.
|
90462727 | if (trans_coeff_level == ((m == first_greater1_coeff_idx) ? 3 : 2)) { |
1380 | 22921203 | int last_coeff_abs_level_remaining = coeff_abs_level_remaining_decode(lc, c_rice_param); | |
1381 | |||
1382 | 22921203 | trans_coeff_level += last_coeff_abs_level_remaining; | |
1383 |
2/2✓ Branch 0 taken 5954362 times.
✓ Branch 1 taken 16966841 times.
|
22921203 | if (trans_coeff_level > (3 << c_rice_param)) |
1384 |
2/2✓ Branch 0 taken 197734 times.
✓ Branch 1 taken 5756628 times.
|
5954362 | c_rice_param = s->ps.sps->persistent_rice_adaptation_enabled_flag ? c_rice_param + 1 : FFMIN(c_rice_param + 1, 4); |
1385 |
4/4✓ Branch 0 taken 1114125 times.
✓ Branch 1 taken 21807078 times.
✓ Branch 2 taken 315677 times.
✓ Branch 3 taken 798448 times.
|
22921203 | if (s->ps.sps->persistent_rice_adaptation_enabled_flag && !rice_init) { |
1386 | 315677 | int c_rice_p_init = lc->stat_coeff[sb_type] / 4; | |
1387 |
2/2✓ Branch 0 taken 37785 times.
✓ Branch 1 taken 277892 times.
|
315677 | if (last_coeff_abs_level_remaining >= (3 << c_rice_p_init)) |
1388 | 37785 | lc->stat_coeff[sb_type]++; | |
1389 |
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)) |
1390 |
2/2✓ Branch 0 taken 37744 times.
✓ Branch 1 taken 119323 times.
|
157067 | if (lc->stat_coeff[sb_type] > 0) |
1391 | 37744 | lc->stat_coeff[sb_type]--; | |
1392 | 315677 | rice_init = 1; | |
1393 | } | ||
1394 | } | ||
1395 | } else { | ||
1396 | 17791145 | int last_coeff_abs_level_remaining = coeff_abs_level_remaining_decode(lc, c_rice_param); | |
1397 | |||
1398 | 17791145 | trans_coeff_level = 1 + last_coeff_abs_level_remaining; | |
1399 |
2/2✓ Branch 0 taken 2222431 times.
✓ Branch 1 taken 15568714 times.
|
17791145 | if (trans_coeff_level > (3 << c_rice_param)) |
1400 |
2/2✓ Branch 0 taken 89299 times.
✓ Branch 1 taken 2133132 times.
|
2222431 | c_rice_param = s->ps.sps->persistent_rice_adaptation_enabled_flag ? c_rice_param + 1 : FFMIN(c_rice_param + 1, 4); |
1401 |
4/4✓ Branch 0 taken 938151 times.
✓ Branch 1 taken 16852994 times.
✓ Branch 2 taken 36551 times.
✓ Branch 3 taken 901600 times.
|
17791145 | if (s->ps.sps->persistent_rice_adaptation_enabled_flag && !rice_init) { |
1402 | 36551 | int c_rice_p_init = lc->stat_coeff[sb_type] / 4; | |
1403 |
2/2✓ Branch 0 taken 1344 times.
✓ Branch 1 taken 35207 times.
|
36551 | if (last_coeff_abs_level_remaining >= (3 << c_rice_p_init)) |
1404 | 1344 | lc->stat_coeff[sb_type]++; | |
1405 |
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)) |
1406 |
2/2✓ Branch 0 taken 1307 times.
✓ Branch 1 taken 23297 times.
|
24604 | if (lc->stat_coeff[sb_type] > 0) |
1407 | 1307 | lc->stat_coeff[sb_type]--; | |
1408 | 36551 | rice_init = 1; | |
1409 | } | ||
1410 | } | ||
1411 |
4/4✓ Branch 0 taken 100364643 times.
✓ Branch 1 taken 7889229 times.
✓ Branch 2 taken 78339628 times.
✓ Branch 3 taken 22025015 times.
|
108253872 | if (s->ps.pps->sign_data_hiding_flag && sign_hidden) { |
1412 | 78339628 | sum_abs += trans_coeff_level; | |
1413 |
4/4✓ Branch 0 taken 10824857 times.
✓ Branch 1 taken 67514771 times.
✓ Branch 2 taken 5404745 times.
✓ Branch 3 taken 5420112 times.
|
78339628 | if (n == first_nz_pos_in_cg && (sum_abs&1)) |
1414 | 5404745 | trans_coeff_level = -trans_coeff_level; | |
1415 | } | ||
1416 |
2/2✓ Branch 0 taken 49221531 times.
✓ Branch 1 taken 59032341 times.
|
108253872 | if (coeff_sign_flag >> 15) |
1417 | 49221531 | trans_coeff_level = -trans_coeff_level; | |
1418 | 108253872 | coeff_sign_flag <<= 1; | |
1419 |
2/2✓ Branch 0 taken 99569486 times.
✓ Branch 1 taken 8684386 times.
|
108253872 | if(!lc->cu.cu_transquant_bypass_flag) { |
1420 |
6/6✓ Branch 0 taken 2778647 times.
✓ Branch 1 taken 96790839 times.
✓ Branch 2 taken 190401 times.
✓ Branch 3 taken 2588246 times.
✓ Branch 4 taken 30375 times.
✓ Branch 5 taken 160026 times.
|
99569486 | if (s->ps.sps->scaling_list_enable_flag && !(transform_skip_flag && log2_trafo_size > 2)) { |
1421 |
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) { |
1422 |
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) { |
1423 | 650713 | case 3: pos = (y_c << 3) + x_c; break; | |
1424 | 814838 | case 4: pos = ((y_c >> 1) << 3) + (x_c >> 1); break; | |
1425 | 298445 | case 5: pos = ((y_c >> 2) << 3) + (x_c >> 2); break; | |
1426 | 823368 | default: pos = (y_c << 2) + x_c; break; | |
1427 | } | ||
1428 | 2587364 | scale_m = scale_matrix[pos]; | |
1429 | } else { | ||
1430 | 31257 | scale_m = dc_scale; | |
1431 | } | ||
1432 | } | ||
1433 | 99569486 | trans_coeff_level = (trans_coeff_level * (int64_t)scale * (int64_t)scale_m + add) >> shift; | |
1434 |
2/2✓ Branch 0 taken 50255458 times.
✓ Branch 1 taken 49314028 times.
|
99569486 | if(trans_coeff_level < 0) { |
1435 |
2/2✓ Branch 0 taken 162681 times.
✓ Branch 1 taken 50092777 times.
|
50255458 | if((~trans_coeff_level) & 0xFffffffffff8000) |
1436 | 162681 | trans_coeff_level = -32768; | |
1437 | } else { | ||
1438 |
2/2✓ Branch 0 taken 162295 times.
✓ Branch 1 taken 49151733 times.
|
49314028 | if(trans_coeff_level & 0xffffffffffff8000) |
1439 | 162295 | trans_coeff_level = 32767; | |
1440 | } | ||
1441 | } | ||
1442 | 108253872 | coeffs[y_c * trafo_size + x_c] = trans_coeff_level; | |
1443 | } | ||
1444 | } | ||
1445 | } | ||
1446 | |||
1447 |
2/2✓ Branch 0 taken 438366 times.
✓ Branch 1 taken 13712845 times.
|
14151211 | if (lc->cu.cu_transquant_bypass_flag) { |
1448 |
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 && |
1449 | ✗ | (pred_mode_intra == 10 || pred_mode_intra == 26))) { | |
1450 | ✗ | int mode = s->ps.sps->implicit_rdpcm_enabled_flag ? (pred_mode_intra == 26) : explicit_rdpcm_dir_flag; | |
1451 | |||
1452 | ✗ | s->hevcdsp.transform_rdpcm(coeffs, log2_trafo_size, mode); | |
1453 | } | ||
1454 | } else { | ||
1455 |
2/2✓ Branch 0 taken 432141 times.
✓ Branch 1 taken 13280704 times.
|
13712845 | if (transform_skip_flag) { |
1456 |
2/2✓ Branch 0 taken 54609 times.
✓ Branch 1 taken 21520 times.
|
76129 | int rot = s->ps.sps->transform_skip_rotation_enabled_flag && |
1457 |
2/2✓ Branch 0 taken 76129 times.
✓ Branch 1 taken 356012 times.
|
508270 | log2_trafo_size == 2 && |
1458 |
2/2✓ Branch 0 taken 20826 times.
✓ Branch 1 taken 33783 times.
|
54609 | lc->cu.pred_mode == MODE_INTRA; |
1459 |
2/2✓ Branch 0 taken 20826 times.
✓ Branch 1 taken 411315 times.
|
432141 | if (rot) { |
1460 |
2/2✓ Branch 0 taken 166608 times.
✓ Branch 1 taken 20826 times.
|
187434 | for (i = 0; i < 8; i++) |
1461 | 166608 | FFSWAP(int16_t, coeffs[i], coeffs[16 - i - 1]); | |
1462 | } | ||
1463 | |||
1464 | 432141 | s->hevcdsp.dequant(coeffs, log2_trafo_size); | |
1465 | |||
1466 |
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 && |
1467 |
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 && |
1468 |
2/2✓ Branch 0 taken 8263 times.
✓ Branch 1 taken 16922 times.
|
25185 | (pred_mode_intra == 10 || pred_mode_intra == 26))) { |
1469 |
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); |
1470 | |||
1471 | 27063 | s->hevcdsp.transform_rdpcm(coeffs, log2_trafo_size, mode); | |
1472 | } | ||
1473 |
6/6✓ Branch 0 taken 9026708 times.
✓ Branch 1 taken 4253996 times.
✓ Branch 2 taken 6099140 times.
✓ Branch 3 taken 2927568 times.
✓ Branch 4 taken 3574081 times.
✓ Branch 5 taken 2525059 times.
|
13280704 | } else if (lc->cu.pred_mode == MODE_INTRA && c_idx == 0 && log2_trafo_size == 2) { |
1474 | 3574081 | s->hevcdsp.transform_4x4_luma(coeffs); | |
1475 | } else { | ||
1476 | 9706623 | int max_xy = FFMAX(last_significant_coeff_x, last_significant_coeff_y); | |
1477 |
2/2✓ Branch 0 taken 2180198 times.
✓ Branch 1 taken 7526425 times.
|
9706623 | if (max_xy == 0) |
1478 | 2180198 | s->hevcdsp.idct_dc[log2_trafo_size - 2](coeffs); | |
1479 | else { | ||
1480 | 7526425 | int col_limit = last_significant_coeff_x + last_significant_coeff_y + 4; | |
1481 |
2/2✓ Branch 0 taken 5212842 times.
✓ Branch 1 taken 2313583 times.
|
7526425 | if (max_xy < 4) |
1482 | 5212842 | col_limit = FFMIN(4, col_limit); | |
1483 |
2/2✓ Branch 0 taken 1728036 times.
✓ Branch 1 taken 585547 times.
|
2313583 | else if (max_xy < 8) |
1484 | 1728036 | col_limit = FFMIN(8, col_limit); | |
1485 |
2/2✓ Branch 0 taken 250827 times.
✓ Branch 1 taken 334720 times.
|
585547 | else if (max_xy < 12) |
1486 | 250827 | col_limit = FFMIN(24, col_limit); | |
1487 | 7526425 | s->hevcdsp.idct[log2_trafo_size - 2](coeffs, col_limit); | |
1488 | } | ||
1489 | } | ||
1490 | } | ||
1491 |
2/2✓ Branch 0 taken 269268 times.
✓ Branch 1 taken 13881943 times.
|
14151211 | if (lc->tu.cross_pf) { |
1492 | 269268 | int16_t *coeffs_y = (int16_t*)lc->edge_emu_buffer; | |
1493 | |||
1494 |
2/2✓ Branch 0 taken 20252880 times.
✓ Branch 1 taken 269268 times.
|
20522148 | for (i = 0; i < (trafo_size * trafo_size); i++) { |
1495 | 20252880 | coeffs[i] = coeffs[i] + ((lc->tu.res_scale_val * coeffs_y[i]) >> 3); | |
1496 | } | ||
1497 | } | ||
1498 | 14151211 | s->hevcdsp.add_residual[log2_trafo_size-2](dst, coeffs, stride); | |
1499 | 14151211 | } | |
1500 | |||
1501 | 2630045 | void ff_hevc_hls_mvd_coding(HEVCLocalContext *lc, int x0, int y0, int log2_cb_size) | |
1502 | { | ||
1503 | 2630045 | int x = abs_mvd_greater0_flag_decode(lc); | |
1504 | 2630045 | int y = abs_mvd_greater0_flag_decode(lc); | |
1505 | |||
1506 |
2/2✓ Branch 0 taken 1835917 times.
✓ Branch 1 taken 794128 times.
|
2630045 | if (x) |
1507 | 1835917 | x += abs_mvd_greater1_flag_decode(lc); | |
1508 |
2/2✓ Branch 0 taken 1763382 times.
✓ Branch 1 taken 866663 times.
|
2630045 | if (y) |
1509 | 1763382 | y += abs_mvd_greater1_flag_decode(lc); | |
1510 | |||
1511 |
3/4✓ Branch 0 taken 1333703 times.
✓ Branch 1 taken 502214 times.
✓ Branch 2 taken 794128 times.
✗ Branch 3 not taken.
|
2630045 | switch (x) { |
1512 | 1333703 | case 2: lc->pu.mvd.x = mvd_decode(lc); break; | |
1513 | 502214 | case 1: lc->pu.mvd.x = mvd_sign_flag_decode(lc); break; | |
1514 | 794128 | case 0: lc->pu.mvd.x = 0; break; | |
1515 | } | ||
1516 | |||
1517 |
3/4✓ Branch 0 taken 1250373 times.
✓ Branch 1 taken 513009 times.
✓ Branch 2 taken 866663 times.
✗ Branch 3 not taken.
|
2630045 | switch (y) { |
1518 | 1250373 | case 2: lc->pu.mvd.y = mvd_decode(lc); break; | |
1519 | 513009 | case 1: lc->pu.mvd.y = mvd_sign_flag_decode(lc); break; | |
1520 | 866663 | case 0: lc->pu.mvd.y = 0; break; | |
1521 | } | ||
1522 | 2630045 | } | |
1523 | |||
1524 |