| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * HEVC CABAC decoding | ||
| 3 | * | ||
| 4 | * Copyright (C) 2012 - 2013 Guillaume Martres | ||
| 5 | * Copyright (C) 2012 - 2013 Gildas Cocherel | ||
| 6 | * | ||
| 7 | * This file is part of FFmpeg. | ||
| 8 | * | ||
| 9 | * FFmpeg is free software; you can redistribute it and/or | ||
| 10 | * modify it under the terms of the GNU Lesser General Public | ||
| 11 | * License as published by the Free Software Foundation; either | ||
| 12 | * version 2.1 of the License, or (at your option) any later version. | ||
| 13 | * | ||
| 14 | * FFmpeg is distributed in the hope that it will be useful, | ||
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 17 | * Lesser General Public License for more details. | ||
| 18 | * | ||
| 19 | * You should have received a copy of the GNU Lesser General Public | ||
| 20 | * License along with FFmpeg; if not, write to the Free Software | ||
| 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 22 | */ | ||
| 23 | |||
| 24 | #include "libavutil/attributes.h" | ||
| 25 | #include "libavutil/common.h" | ||
| 26 | |||
| 27 | #include "libavcodec/cabac_functions.h" | ||
| 28 | #include "data.h" | ||
| 29 | #include "hevc.h" | ||
| 30 | #include "hevcdec.h" | ||
| 31 | |||
| 32 | #define CABAC_MAX_BIN 31 | ||
| 33 | |||
| 34 | // ELEM(NAME, NUM_BINS) | ||
| 35 | #define CABAC_ELEMS(ELEM) \ | ||
| 36 | ELEM(SAO_MERGE_FLAG, 1) \ | ||
| 37 | ELEM(SAO_TYPE_IDX, 1) \ | ||
| 38 | ELEM(SAO_EO_CLASS, 0) \ | ||
| 39 | ELEM(SAO_BAND_POSITION, 0) \ | ||
| 40 | ELEM(SAO_OFFSET_ABS, 0) \ | ||
| 41 | ELEM(SAO_OFFSET_SIGN, 0) \ | ||
| 42 | ELEM(END_OF_SLICE_FLAG, 0) \ | ||
| 43 | ELEM(SPLIT_CODING_UNIT_FLAG, 3) \ | ||
| 44 | ELEM(CU_TRANSQUANT_BYPASS_FLAG, 1) \ | ||
| 45 | ELEM(SKIP_FLAG, 3) \ | ||
| 46 | ELEM(CU_QP_DELTA, 3) \ | ||
| 47 | ELEM(PRED_MODE_FLAG, 1) \ | ||
| 48 | ELEM(PART_MODE, 4) \ | ||
| 49 | ELEM(PCM_FLAG, 0) \ | ||
| 50 | ELEM(PREV_INTRA_LUMA_PRED_FLAG, 1) \ | ||
| 51 | ELEM(MPM_IDX, 0) \ | ||
| 52 | ELEM(REM_INTRA_LUMA_PRED_MODE, 0) \ | ||
| 53 | ELEM(INTRA_CHROMA_PRED_MODE, 2) \ | ||
| 54 | ELEM(MERGE_FLAG, 1) \ | ||
| 55 | ELEM(MERGE_IDX, 1) \ | ||
| 56 | ELEM(INTER_PRED_IDC, 5) \ | ||
| 57 | ELEM(REF_IDX_L0, 2) \ | ||
| 58 | ELEM(REF_IDX_L1, 2) \ | ||
| 59 | ELEM(ABS_MVD_GREATER0_FLAG, 2) \ | ||
| 60 | ELEM(ABS_MVD_GREATER1_FLAG, 2) \ | ||
| 61 | ELEM(ABS_MVD_MINUS2, 0) \ | ||
| 62 | ELEM(MVD_SIGN_FLAG, 0) \ | ||
| 63 | ELEM(MVP_LX_FLAG, 1) \ | ||
| 64 | ELEM(NO_RESIDUAL_DATA_FLAG, 1) \ | ||
| 65 | ELEM(SPLIT_TRANSFORM_FLAG, 3) \ | ||
| 66 | ELEM(CBF_LUMA, 2) \ | ||
| 67 | ELEM(CBF_CB_CR, 5) \ | ||
| 68 | ELEM(TRANSFORM_SKIP_FLAG, 2) \ | ||
| 69 | ELEM(EXPLICIT_RDPCM_FLAG, 2) \ | ||
| 70 | ELEM(EXPLICIT_RDPCM_DIR_FLAG, 2) \ | ||
| 71 | ELEM(LAST_SIGNIFICANT_COEFF_X_PREFIX, 18) \ | ||
| 72 | ELEM(LAST_SIGNIFICANT_COEFF_Y_PREFIX, 18) \ | ||
| 73 | ELEM(LAST_SIGNIFICANT_COEFF_X_SUFFIX, 0) \ | ||
| 74 | ELEM(LAST_SIGNIFICANT_COEFF_Y_SUFFIX, 0) \ | ||
| 75 | ELEM(SIGNIFICANT_COEFF_GROUP_FLAG, 4) \ | ||
| 76 | ELEM(SIGNIFICANT_COEFF_FLAG, 44) \ | ||
| 77 | ELEM(COEFF_ABS_LEVEL_GREATER1_FLAG, 24) \ | ||
| 78 | ELEM(COEFF_ABS_LEVEL_GREATER2_FLAG, 6) \ | ||
| 79 | ELEM(COEFF_ABS_LEVEL_REMAINING, 0) \ | ||
| 80 | ELEM(COEFF_SIGN_FLAG, 0) \ | ||
| 81 | ELEM(LOG2_RES_SCALE_ABS, 8) \ | ||
| 82 | ELEM(RES_SCALE_SIGN_FLAG, 2) \ | ||
| 83 | ELEM(CU_CHROMA_QP_OFFSET_FLAG, 1) \ | ||
| 84 | ELEM(CU_CHROMA_QP_OFFSET_IDX, 1) \ | ||
| 85 | |||
| 86 | /** | ||
| 87 | * Offset to ctxIdx 0 in init_values and states. | ||
| 88 | */ | ||
| 89 | enum { | ||
| 90 | #define OFFSET(NAME, NUM_BINS) \ | ||
| 91 | NAME ## _OFFSET, \ | ||
| 92 | NAME ## _END = NAME ## _OFFSET + NUM_BINS - 1, | ||
| 93 | CABAC_ELEMS(OFFSET) | ||
| 94 | }; | ||
| 95 | |||
| 96 | #define CNU 154 | ||
| 97 | /** | ||
| 98 | * Indexed by init_type | ||
| 99 | */ | ||
| 100 | static const uint8_t init_values[3][HEVC_CONTEXTS] = { | ||
| 101 | { // sao_merge_flag | ||
| 102 | 153, | ||
| 103 | // sao_type_idx | ||
| 104 | 200, | ||
| 105 | // split_coding_unit_flag | ||
| 106 | 139, 141, 157, | ||
| 107 | // cu_transquant_bypass_flag | ||
| 108 | 154, | ||
| 109 | // skip_flag | ||
| 110 | CNU, CNU, CNU, | ||
| 111 | // cu_qp_delta | ||
| 112 | 154, 154, 154, | ||
| 113 | // pred_mode | ||
| 114 | CNU, | ||
| 115 | // part_mode | ||
| 116 | 184, CNU, CNU, CNU, | ||
| 117 | // prev_intra_luma_pred_mode | ||
| 118 | 184, | ||
| 119 | // intra_chroma_pred_mode | ||
| 120 | 63, 139, | ||
| 121 | // merge_flag | ||
| 122 | CNU, | ||
| 123 | // merge_idx | ||
| 124 | CNU, | ||
| 125 | // inter_pred_idc | ||
| 126 | CNU, CNU, CNU, CNU, CNU, | ||
| 127 | // ref_idx_l0 | ||
| 128 | CNU, CNU, | ||
| 129 | // ref_idx_l1 | ||
| 130 | CNU, CNU, | ||
| 131 | // abs_mvd_greater1_flag | ||
| 132 | CNU, CNU, | ||
| 133 | // abs_mvd_greater1_flag | ||
| 134 | CNU, CNU, | ||
| 135 | // mvp_lx_flag | ||
| 136 | CNU, | ||
| 137 | // no_residual_data_flag | ||
| 138 | CNU, | ||
| 139 | // split_transform_flag | ||
| 140 | 153, 138, 138, | ||
| 141 | // cbf_luma | ||
| 142 | 111, 141, | ||
| 143 | // cbf_cb, cbf_cr | ||
| 144 | 94, 138, 182, 154, 154, | ||
| 145 | // transform_skip_flag | ||
| 146 | 139, 139, | ||
| 147 | // explicit_rdpcm_flag | ||
| 148 | 139, 139, | ||
| 149 | // explicit_rdpcm_dir_flag | ||
| 150 | 139, 139, | ||
| 151 | // last_significant_coeff_x_prefix | ||
| 152 | 110, 110, 124, 125, 140, 153, 125, 127, 140, 109, 111, 143, 127, 111, | ||
| 153 | 79, 108, 123, 63, | ||
| 154 | // last_significant_coeff_y_prefix | ||
| 155 | 110, 110, 124, 125, 140, 153, 125, 127, 140, 109, 111, 143, 127, 111, | ||
| 156 | 79, 108, 123, 63, | ||
| 157 | // significant_coeff_group_flag | ||
| 158 | 91, 171, 134, 141, | ||
| 159 | // significant_coeff_flag | ||
| 160 | 111, 111, 125, 110, 110, 94, 124, 108, 124, 107, 125, 141, 179, 153, | ||
| 161 | 125, 107, 125, 141, 179, 153, 125, 107, 125, 141, 179, 153, 125, 140, | ||
| 162 | 139, 182, 182, 152, 136, 152, 136, 153, 136, 139, 111, 136, 139, 111, | ||
| 163 | 141, 111, | ||
| 164 | // coeff_abs_level_greater1_flag | ||
| 165 | 140, 92, 137, 138, 140, 152, 138, 139, 153, 74, 149, 92, 139, 107, | ||
| 166 | 122, 152, 140, 179, 166, 182, 140, 227, 122, 197, | ||
| 167 | // coeff_abs_level_greater2_flag | ||
| 168 | 138, 153, 136, 167, 152, 152, | ||
| 169 | // log2_res_scale_abs | ||
| 170 | 154, 154, 154, 154, 154, 154, 154, 154, | ||
| 171 | // res_scale_sign_flag | ||
| 172 | 154, 154, | ||
| 173 | // cu_chroma_qp_offset_flag | ||
| 174 | 154, | ||
| 175 | // cu_chroma_qp_offset_idx | ||
| 176 | 154, | ||
| 177 | }, | ||
| 178 | { // sao_merge_flag | ||
| 179 | 153, | ||
| 180 | // sao_type_idx | ||
| 181 | 185, | ||
| 182 | // split_coding_unit_flag | ||
| 183 | 107, 139, 126, | ||
| 184 | // cu_transquant_bypass_flag | ||
| 185 | 154, | ||
| 186 | // skip_flag | ||
| 187 | 197, 185, 201, | ||
| 188 | // cu_qp_delta | ||
| 189 | 154, 154, 154, | ||
| 190 | // pred_mode | ||
| 191 | 149, | ||
| 192 | // part_mode | ||
| 193 | 154, 139, 154, 154, | ||
| 194 | // prev_intra_luma_pred_mode | ||
| 195 | 154, | ||
| 196 | // intra_chroma_pred_mode | ||
| 197 | 152, 139, | ||
| 198 | // merge_flag | ||
| 199 | 110, | ||
| 200 | // merge_idx | ||
| 201 | 122, | ||
| 202 | // inter_pred_idc | ||
| 203 | 95, 79, 63, 31, 31, | ||
| 204 | // ref_idx_l0 | ||
| 205 | 153, 153, | ||
| 206 | // ref_idx_l1 | ||
| 207 | 153, 153, | ||
| 208 | // abs_mvd_greater1_flag | ||
| 209 | 140, 198, | ||
| 210 | // abs_mvd_greater1_flag | ||
| 211 | 140, 198, | ||
| 212 | // mvp_lx_flag | ||
| 213 | 168, | ||
| 214 | // no_residual_data_flag | ||
| 215 | 79, | ||
| 216 | // split_transform_flag | ||
| 217 | 124, 138, 94, | ||
| 218 | // cbf_luma | ||
| 219 | 153, 111, | ||
| 220 | // cbf_cb, cbf_cr | ||
| 221 | 149, 107, 167, 154, 154, | ||
| 222 | // transform_skip_flag | ||
| 223 | 139, 139, | ||
| 224 | // explicit_rdpcm_flag | ||
| 225 | 139, 139, | ||
| 226 | // explicit_rdpcm_dir_flag | ||
| 227 | 139, 139, | ||
| 228 | // last_significant_coeff_x_prefix | ||
| 229 | 125, 110, 94, 110, 95, 79, 125, 111, 110, 78, 110, 111, 111, 95, | ||
| 230 | 94, 108, 123, 108, | ||
| 231 | // last_significant_coeff_y_prefix | ||
| 232 | 125, 110, 94, 110, 95, 79, 125, 111, 110, 78, 110, 111, 111, 95, | ||
| 233 | 94, 108, 123, 108, | ||
| 234 | // significant_coeff_group_flag | ||
| 235 | 121, 140, 61, 154, | ||
| 236 | // significant_coeff_flag | ||
| 237 | 155, 154, 139, 153, 139, 123, 123, 63, 153, 166, 183, 140, 136, 153, | ||
| 238 | 154, 166, 183, 140, 136, 153, 154, 166, 183, 140, 136, 153, 154, 170, | ||
| 239 | 153, 123, 123, 107, 121, 107, 121, 167, 151, 183, 140, 151, 183, 140, | ||
| 240 | 140, 140, | ||
| 241 | // coeff_abs_level_greater1_flag | ||
| 242 | 154, 196, 196, 167, 154, 152, 167, 182, 182, 134, 149, 136, 153, 121, | ||
| 243 | 136, 137, 169, 194, 166, 167, 154, 167, 137, 182, | ||
| 244 | // coeff_abs_level_greater2_flag | ||
| 245 | 107, 167, 91, 122, 107, 167, | ||
| 246 | // log2_res_scale_abs | ||
| 247 | 154, 154, 154, 154, 154, 154, 154, 154, | ||
| 248 | // res_scale_sign_flag | ||
| 249 | 154, 154, | ||
| 250 | // cu_chroma_qp_offset_flag | ||
| 251 | 154, | ||
| 252 | // cu_chroma_qp_offset_idx | ||
| 253 | 154, | ||
| 254 | }, | ||
| 255 | { // sao_merge_flag | ||
| 256 | 153, | ||
| 257 | // sao_type_idx | ||
| 258 | 160, | ||
| 259 | // split_coding_unit_flag | ||
| 260 | 107, 139, 126, | ||
| 261 | // cu_transquant_bypass_flag | ||
| 262 | 154, | ||
| 263 | // skip_flag | ||
| 264 | 197, 185, 201, | ||
| 265 | // cu_qp_delta | ||
| 266 | 154, 154, 154, | ||
| 267 | // pred_mode | ||
| 268 | 134, | ||
| 269 | // part_mode | ||
| 270 | 154, 139, 154, 154, | ||
| 271 | // prev_intra_luma_pred_mode | ||
| 272 | 183, | ||
| 273 | // intra_chroma_pred_mode | ||
| 274 | 152, 139, | ||
| 275 | // merge_flag | ||
| 276 | 154, | ||
| 277 | // merge_idx | ||
| 278 | 137, | ||
| 279 | // inter_pred_idc | ||
| 280 | 95, 79, 63, 31, 31, | ||
| 281 | // ref_idx_l0 | ||
| 282 | 153, 153, | ||
| 283 | // ref_idx_l1 | ||
| 284 | 153, 153, | ||
| 285 | // abs_mvd_greater1_flag | ||
| 286 | 169, 198, | ||
| 287 | // abs_mvd_greater1_flag | ||
| 288 | 169, 198, | ||
| 289 | // mvp_lx_flag | ||
| 290 | 168, | ||
| 291 | // no_residual_data_flag | ||
| 292 | 79, | ||
| 293 | // split_transform_flag | ||
| 294 | 224, 167, 122, | ||
| 295 | // cbf_luma | ||
| 296 | 153, 111, | ||
| 297 | // cbf_cb, cbf_cr | ||
| 298 | 149, 92, 167, 154, 154, | ||
| 299 | // transform_skip_flag | ||
| 300 | 139, 139, | ||
| 301 | // explicit_rdpcm_flag | ||
| 302 | 139, 139, | ||
| 303 | // explicit_rdpcm_dir_flag | ||
| 304 | 139, 139, | ||
| 305 | // last_significant_coeff_x_prefix | ||
| 306 | 125, 110, 124, 110, 95, 94, 125, 111, 111, 79, 125, 126, 111, 111, | ||
| 307 | 79, 108, 123, 93, | ||
| 308 | // last_significant_coeff_y_prefix | ||
| 309 | 125, 110, 124, 110, 95, 94, 125, 111, 111, 79, 125, 126, 111, 111, | ||
| 310 | 79, 108, 123, 93, | ||
| 311 | // significant_coeff_group_flag | ||
| 312 | 121, 140, 61, 154, | ||
| 313 | // significant_coeff_flag | ||
| 314 | 170, 154, 139, 153, 139, 123, 123, 63, 124, 166, 183, 140, 136, 153, | ||
| 315 | 154, 166, 183, 140, 136, 153, 154, 166, 183, 140, 136, 153, 154, 170, | ||
| 316 | 153, 138, 138, 122, 121, 122, 121, 167, 151, 183, 140, 151, 183, 140, | ||
| 317 | 140, 140, | ||
| 318 | // coeff_abs_level_greater1_flag | ||
| 319 | 154, 196, 167, 167, 154, 152, 167, 182, 182, 134, 149, 136, 153, 121, | ||
| 320 | 136, 122, 169, 208, 166, 167, 154, 152, 167, 182, | ||
| 321 | // coeff_abs_level_greater2_flag | ||
| 322 | 107, 167, 91, 107, 107, 167, | ||
| 323 | // log2_res_scale_abs | ||
| 324 | 154, 154, 154, 154, 154, 154, 154, 154, | ||
| 325 | // res_scale_sign_flag | ||
| 326 | 154, 154, | ||
| 327 | // cu_chroma_qp_offset_flag | ||
| 328 | 154, | ||
| 329 | // cu_chroma_qp_offset_idx | ||
| 330 | 154, | ||
| 331 | }, | ||
| 332 | }; | ||
| 333 | |||
| 334 | static const uint8_t scan_1x1[1] = { | ||
| 335 | 0, | ||
| 336 | }; | ||
| 337 | |||
| 338 | static const uint8_t horiz_scan2x2_x[4] = { | ||
| 339 | 0, 1, 0, 1, | ||
| 340 | }; | ||
| 341 | |||
| 342 | static const uint8_t horiz_scan2x2_y[4] = { | ||
| 343 | 0, 0, 1, 1 | ||
| 344 | }; | ||
| 345 | |||
| 346 | static const uint8_t horiz_scan4x4_x[16] = { | ||
| 347 | 0, 1, 2, 3, | ||
| 348 | 0, 1, 2, 3, | ||
| 349 | 0, 1, 2, 3, | ||
| 350 | 0, 1, 2, 3, | ||
| 351 | }; | ||
| 352 | |||
| 353 | static const uint8_t horiz_scan4x4_y[16] = { | ||
| 354 | 0, 0, 0, 0, | ||
| 355 | 1, 1, 1, 1, | ||
| 356 | 2, 2, 2, 2, | ||
| 357 | 3, 3, 3, 3, | ||
| 358 | }; | ||
| 359 | |||
| 360 | static const uint8_t horiz_scan8x8_inv[8][8] = { | ||
| 361 | { 0, 1, 2, 3, 16, 17, 18, 19, }, | ||
| 362 | { 4, 5, 6, 7, 20, 21, 22, 23, }, | ||
| 363 | { 8, 9, 10, 11, 24, 25, 26, 27, }, | ||
| 364 | { 12, 13, 14, 15, 28, 29, 30, 31, }, | ||
| 365 | { 32, 33, 34, 35, 48, 49, 50, 51, }, | ||
| 366 | { 36, 37, 38, 39, 52, 53, 54, 55, }, | ||
| 367 | { 40, 41, 42, 43, 56, 57, 58, 59, }, | ||
| 368 | { 44, 45, 46, 47, 60, 61, 62, 63, }, | ||
| 369 | }; | ||
| 370 | |||
| 371 | static const uint8_t diag_scan2x2_x[4] = { | ||
| 372 | 0, 0, 1, 1, | ||
| 373 | }; | ||
| 374 | |||
| 375 | static const uint8_t diag_scan2x2_y[4] = { | ||
| 376 | 0, 1, 0, 1, | ||
| 377 | }; | ||
| 378 | |||
| 379 | static const uint8_t diag_scan2x2_inv[2][2] = { | ||
| 380 | { 0, 2, }, | ||
| 381 | { 1, 3, }, | ||
| 382 | }; | ||
| 383 | |||
| 384 | static const uint8_t diag_scan4x4_inv[4][4] = { | ||
| 385 | { 0, 2, 5, 9, }, | ||
| 386 | { 1, 4, 8, 12, }, | ||
| 387 | { 3, 7, 11, 14, }, | ||
| 388 | { 6, 10, 13, 15, }, | ||
| 389 | }; | ||
| 390 | |||
| 391 | static const uint8_t diag_scan8x8_inv[8][8] = { | ||
| 392 | { 0, 2, 5, 9, 14, 20, 27, 35, }, | ||
| 393 | { 1, 4, 8, 13, 19, 26, 34, 42, }, | ||
| 394 | { 3, 7, 12, 18, 25, 33, 41, 48, }, | ||
| 395 | { 6, 11, 17, 24, 32, 40, 47, 53, }, | ||
| 396 | { 10, 16, 23, 31, 39, 46, 52, 57, }, | ||
| 397 | { 15, 22, 30, 38, 45, 51, 56, 60, }, | ||
| 398 | { 21, 29, 37, 44, 50, 55, 59, 62, }, | ||
| 399 | { 28, 36, 43, 49, 54, 58, 61, 63, }, | ||
| 400 | }; | ||
| 401 | |||
| 402 | 2044193 | void ff_hevc_save_states(HEVCLocalContext *lc, const HEVCPPS *pps, | |
| 403 | int ctb_addr_ts) | ||
| 404 | { | ||
| 405 | 2044193 | const HEVCSPS *const sps = pps->sps; | |
| 406 |
2/2✓ Branch 0 taken 168556 times.
✓ Branch 1 taken 1875637 times.
|
2044193 | if (pps->entropy_coding_sync_enabled_flag && |
| 407 |
2/2✓ Branch 0 taken 161382 times.
✓ Branch 1 taken 7174 times.
|
168556 | (ctb_addr_ts % sps->ctb_width == 2 || |
| 408 |
2/2✓ Branch 0 taken 768 times.
✓ Branch 1 taken 160614 times.
|
161382 | (sps->ctb_width == 2 && |
| 409 |
2/2✓ Branch 0 taken 384 times.
✓ Branch 1 taken 384 times.
|
768 | ctb_addr_ts % sps->ctb_width == 0))) { |
| 410 | 7558 | memcpy(lc->common_cabac_state->state, lc->sub.cabac_state, HEVC_CONTEXTS); | |
| 411 |
2/2✓ Branch 0 taken 36 times.
✓ Branch 1 taken 7522 times.
|
7558 | if (sps->persistent_rice_adaptation_enabled) { |
| 412 | 36 | memcpy(lc->common_cabac_state->stat_coeff, lc->sub.stat_coeff, HEVC_STAT_COEFFS); | |
| 413 | } | ||
| 414 | } | ||
| 415 | 2044193 | } | |
| 416 | |||
| 417 | 6283 | static void load_states(HEVCLocalContext *lc, const HEVCSPS *sps) | |
| 418 | { | ||
| 419 | 6283 | memcpy(lc->sub.cabac_state, lc->common_cabac_state->state, HEVC_CONTEXTS); | |
| 420 |
2/2✓ Branch 0 taken 33 times.
✓ Branch 1 taken 6250 times.
|
6283 | if (sps->persistent_rice_adaptation_enabled) { |
| 421 | 33 | memcpy(lc->sub.stat_coeff, lc->common_cabac_state->stat_coeff, HEVC_STAT_COEFFS); | |
| 422 | } | ||
| 423 | 6283 | } | |
| 424 | |||
| 425 | 10886 | static int cabac_reinit(HEVCLocalContext *lc) | |
| 426 | { | ||
| 427 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 10886 times.
|
10886 | return skip_bytes(&lc->sub.cc, 0) == NULL ? AVERROR_INVALIDDATA : 0; |
| 428 | } | ||
| 429 | |||
| 430 | 33506 | static void cabac_init_state(HEVCLocalContext *lc, const HEVCContext *s) | |
| 431 | { | ||
| 432 | 33506 | int init_type = 2 - lc->sh->slice_type; | |
| 433 | int i; | ||
| 434 | |||
| 435 |
4/4✓ Branch 0 taken 6681 times.
✓ Branch 1 taken 26825 times.
✓ Branch 2 taken 6503 times.
✓ Branch 3 taken 178 times.
|
33506 | if (lc->sh->cabac_init_flag && lc->sh->slice_type != HEVC_SLICE_I) |
| 436 | 6503 | init_type ^= 3; | |
| 437 | |||
| 438 |
2/2✓ Branch 0 taken 6667694 times.
✓ Branch 1 taken 33506 times.
|
6701200 | for (i = 0; i < HEVC_CONTEXTS; i++) { |
| 439 | 6667694 | int init_value = init_values[init_type][i]; | |
| 440 | 6667694 | int m = (init_value >> 4) * 5 - 45; | |
| 441 | 6667694 | int n = ((init_value & 15) << 3) - 16; | |
| 442 | 6667694 | int pre = 2 * (((m * av_clip(lc->sh->slice_qp, 0, 51)) >> 4) + n) - 127; | |
| 443 | |||
| 444 | 6667694 | pre ^= pre >> 31; | |
| 445 |
2/2✓ Branch 0 taken 681563 times.
✓ Branch 1 taken 5986131 times.
|
6667694 | if (pre > 124) |
| 446 | 681563 | pre = 124 + (pre & 1); | |
| 447 | 6667694 | lc->sub.cabac_state[i] = pre; | |
| 448 | } | ||
| 449 | |||
| 450 |
2/2✓ Branch 0 taken 134024 times.
✓ Branch 1 taken 33506 times.
|
167530 | for (i = 0; i < 4; i++) |
| 451 | 134024 | lc->sub.stat_coeff[i] = 0; | |
| 452 | 33506 | } | |
| 453 | |||
| 454 | /* Open CABAC on this substream's data, or continue byte-aligned in it if it | ||
| 455 | * is already open (one slice read from a single buffer). */ | ||
| 456 | 15974 | static int substream_continue(HEVCLocalContext *lc) | |
| 457 | { | ||
| 458 | 15974 | HEVCSubstream *const sub = &lc->sub; | |
| 459 | int ret; | ||
| 460 | |||
| 461 |
2/2✓ Branch 0 taken 10886 times.
✓ Branch 1 taken 5088 times.
|
15974 | if (sub->opened) |
| 462 | 10886 | return cabac_reinit(lc); | |
| 463 | |||
| 464 | 5088 | ret = ff_init_cabac_decoder(&sub->cc, sub->data, sub->size); | |
| 465 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5088 times.
|
5088 | if (ret < 0) |
| 466 | ✗ | return ret; | |
| 467 | 5088 | sub->opened = 1; | |
| 468 | |||
| 469 | 5088 | return 0; | |
| 470 | } | ||
| 471 | |||
| 472 | 2096754 | int ff_hevc_cabac_init(HEVCLocalContext *lc, const HEVCPPS *pps, | |
| 473 | int ctb_addr_ts) | ||
| 474 | { | ||
| 475 | 2096754 | const HEVCContext *const s = lc->parent; | |
| 476 | 2096754 | const HEVCSPS *const sps = pps->sps; | |
| 477 | 2096754 | HEVCSubstream *const sub = &lc->sub; | |
| 478 | |||
| 479 |
2/2✓ Branch 0 taken 30073 times.
✓ Branch 1 taken 2066681 times.
|
2096754 | if (ctb_addr_ts == pps->ctb_addr_rs_to_ts[lc->sh->slice_ctb_addr_rs]) { |
| 480 | /* First CTB of a slice segment. For a dependent slice segment the | ||
| 481 | * data still belongs to the new segment. */ | ||
| 482 | 30073 | int ret = ff_init_cabac_decoder(&sub->cc, sub->data, sub->size); | |
| 483 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 30073 times.
|
30073 | if (ret < 0) |
| 484 | ✗ | return ret; | |
| 485 | 30073 | sub->opened = 1; | |
| 486 |
2/2✓ Branch 0 taken 7794 times.
✓ Branch 1 taken 22279 times.
|
30073 | if (lc->sh->dependent_slice_segment_flag == 0 || |
| 487 |
2/2✓ Branch 0 taken 844 times.
✓ Branch 1 taken 6950 times.
|
7794 | (pps->tiles_enabled_flag && |
| 488 |
2/2✓ Branch 0 taken 298 times.
✓ Branch 1 taken 546 times.
|
844 | pps->tile_id[ctb_addr_ts] != pps->tile_id[ctb_addr_ts - 1])) |
| 489 | 22577 | cabac_init_state(lc, s); | |
| 490 | |||
| 491 |
2/2✓ Branch 0 taken 19381 times.
✓ Branch 1 taken 10692 times.
|
30073 | if (!lc->sh->first_slice_in_pic_flag && |
| 492 |
2/2✓ Branch 0 taken 3820 times.
✓ Branch 1 taken 15561 times.
|
19381 | pps->entropy_coding_sync_enabled_flag) { |
| 493 |
2/2✓ Branch 0 taken 1620 times.
✓ Branch 1 taken 2200 times.
|
3820 | if (ctb_addr_ts % sps->ctb_width == 0) { |
| 494 |
2/2✓ Branch 0 taken 92 times.
✓ Branch 1 taken 1528 times.
|
1620 | if (sps->ctb_width == 1) |
| 495 | 92 | cabac_init_state(lc, s); | |
| 496 |
2/2✓ Branch 0 taken 1146 times.
✓ Branch 1 taken 382 times.
|
1528 | else if (lc->sh->dependent_slice_segment_flag == 1) |
| 497 | 1146 | load_states(lc, sps); | |
| 498 | } | ||
| 499 | } | ||
| 500 | } else { | ||
| 501 |
2/2✓ Branch 0 taken 805264 times.
✓ Branch 1 taken 1261417 times.
|
2066681 | if (pps->tiles_enabled_flag && |
| 502 |
2/2✓ Branch 0 taken 10641 times.
✓ Branch 1 taken 794623 times.
|
805264 | pps->tile_id[ctb_addr_ts] != pps->tile_id[ctb_addr_ts - 1]) { |
| 503 | 10641 | int ret = substream_continue(lc); | |
| 504 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10641 times.
|
10641 | if (ret < 0) |
| 505 | ✗ | return ret; | |
| 506 | 10641 | cabac_init_state(lc, s); | |
| 507 | } | ||
| 508 |
2/2✓ Branch 0 taken 163747 times.
✓ Branch 1 taken 1902934 times.
|
2066681 | if (pps->entropy_coding_sync_enabled_flag) { |
| 509 |
2/2✓ Branch 0 taken 5333 times.
✓ Branch 1 taken 158414 times.
|
163747 | if (ctb_addr_ts % sps->ctb_width == 0) { |
| 510 | int ret; | ||
| 511 | /* The end of row terminate bit is read only when continuing */ | ||
| 512 |
1/2✓ Branch 0 taken 5333 times.
✗ Branch 1 not taken.
|
5333 | if (sub->opened) |
| 513 | 5333 | get_cabac_terminate(&sub->cc); | |
| 514 | 5333 | ret = substream_continue(lc); | |
| 515 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5333 times.
|
5333 | if (ret < 0) |
| 516 | ✗ | return ret; | |
| 517 | |||
| 518 |
2/2✓ Branch 0 taken 196 times.
✓ Branch 1 taken 5137 times.
|
5333 | if (sps->ctb_width == 1) |
| 519 | 196 | cabac_init_state(lc, s); | |
| 520 | else | ||
| 521 | 5137 | load_states(lc, sps); | |
| 522 | } | ||
| 523 | } | ||
| 524 | } | ||
| 525 | 2096754 | return 0; | |
| 526 | } | ||
| 527 | |||
| 528 | #define GET_CABAC(ctx) get_cabac(&lc->sub.cc, &lc->sub.cabac_state[ctx]) | ||
| 529 | |||
| 530 | 1430230 | int ff_hevc_sao_merge_flag_decode(HEVCLocalContext *lc) | |
| 531 | { | ||
| 532 | 1430230 | return GET_CABAC(SAO_MERGE_FLAG_OFFSET); | |
| 533 | } | ||
| 534 | |||
| 535 | 561217 | int ff_hevc_sao_type_idx_decode(HEVCLocalContext *lc) | |
| 536 | { | ||
| 537 |
2/2✓ Branch 1 taken 390748 times.
✓ Branch 2 taken 170469 times.
|
561217 | if (!GET_CABAC(SAO_TYPE_IDX_OFFSET)) |
| 538 | 390748 | return 0; | |
| 539 | |||
| 540 |
2/2✓ Branch 1 taken 50547 times.
✓ Branch 2 taken 119922 times.
|
170469 | if (!get_cabac_bypass(&lc->sub.cc)) |
| 541 | 50547 | return SAO_BAND; | |
| 542 | 119922 | return SAO_EDGE; | |
| 543 | } | ||
| 544 | |||
| 545 | 72036 | int ff_hevc_sao_band_position_decode(HEVCLocalContext *lc) | |
| 546 | { | ||
| 547 | int i; | ||
| 548 | 72036 | int value = get_cabac_bypass(&lc->sub.cc); | |
| 549 | |||
| 550 |
2/2✓ Branch 0 taken 288144 times.
✓ Branch 1 taken 72036 times.
|
360180 | for (i = 0; i < 4; i++) |
| 551 | 288144 | value = (value << 1) | get_cabac_bypass(&lc->sub.cc); | |
| 552 | 72036 | return value; | |
| 553 | } | ||
| 554 | |||
| 555 | 875640 | int ff_hevc_sao_offset_abs_decode(HEVCLocalContext *lc, int bit_depth) | |
| 556 | { | ||
| 557 | 875640 | int i = 0; | |
| 558 | 875640 | int length = (1 << (FFMIN(bit_depth, 10) - 5)) - 1; | |
| 559 | |||
| 560 |
4/4✓ Branch 0 taken 2409493 times.
✓ Branch 1 taken 118188 times.
✓ Branch 3 taken 1652041 times.
✓ Branch 4 taken 757452 times.
|
2527681 | while (i < length && get_cabac_bypass(&lc->sub.cc)) |
| 561 | 1652041 | i++; | |
| 562 | 875640 | return i; | |
| 563 | } | ||
| 564 | |||
| 565 | 223920 | int ff_hevc_sao_offset_sign_decode(HEVCLocalContext *lc) | |
| 566 | { | ||
| 567 | 223920 | return get_cabac_bypass(&lc->sub.cc); | |
| 568 | } | ||
| 569 | |||
| 570 | 119922 | int ff_hevc_sao_eo_class_decode(HEVCLocalContext *lc) | |
| 571 | { | ||
| 572 | 119922 | int ret = get_cabac_bypass(&lc->sub.cc) << 1; | |
| 573 | 119922 | ret |= get_cabac_bypass(&lc->sub.cc); | |
| 574 | 119922 | return ret; | |
| 575 | } | ||
| 576 | |||
| 577 | 2096753 | int ff_hevc_end_of_slice_flag_decode(HEVCLocalContext *lc) | |
| 578 | { | ||
| 579 | 2096753 | return get_cabac_terminate(&lc->sub.cc); | |
| 580 | } | ||
| 581 | |||
| 582 | 180080 | int ff_hevc_cu_transquant_bypass_flag_decode(HEVCLocalContext *lc) | |
| 583 | { | ||
| 584 | 180080 | return GET_CABAC(CU_TRANSQUANT_BYPASS_FLAG_OFFSET); | |
| 585 | } | ||
| 586 | |||
| 587 | 10722244 | int ff_hevc_skip_flag_decode(HEVCLocalContext *lc, uint8_t *skip_flag, | |
| 588 | int x0, int y0, int x_cb, int y_cb, int min_cb_width) | ||
| 589 | { | ||
| 590 | 10722244 | int inc = 0; | |
| 591 | |||
| 592 |
4/4✓ Branch 0 taken 969759 times.
✓ Branch 1 taken 9752485 times.
✓ Branch 2 taken 677383 times.
✓ Branch 3 taken 292376 times.
|
10722244 | if (lc->ctb_left_flag || x0) |
| 593 | 10429868 | inc = !!SAMPLE_CTB(skip_flag, x_cb - 1, y_cb); | |
| 594 |
4/4✓ Branch 0 taken 2020321 times.
✓ Branch 1 taken 8701923 times.
✓ Branch 2 taken 1452683 times.
✓ Branch 3 taken 567638 times.
|
10722244 | if (lc->ctb_up_flag || y0) |
| 595 | 10154606 | inc += !!SAMPLE_CTB(skip_flag, x_cb, y_cb - 1); | |
| 596 | |||
| 597 | 10722244 | return GET_CABAC(SKIP_FLAG_OFFSET + inc); | |
| 598 | } | ||
| 599 | |||
| 600 | 920252 | int ff_hevc_cu_qp_delta_abs(HEVCLocalContext *lc) | |
| 601 | { | ||
| 602 | 920252 | int prefix_val = 0; | |
| 603 | 920252 | int suffix_val = 0; | |
| 604 | 920252 | int inc = 0; | |
| 605 | |||
| 606 |
4/4✓ Branch 0 taken 2062233 times.
✓ Branch 1 taken 141978 times.
✓ Branch 3 taken 1283959 times.
✓ Branch 4 taken 778274 times.
|
2204211 | while (prefix_val < 5 && GET_CABAC(CU_QP_DELTA_OFFSET + inc)) { |
| 607 | 1283959 | prefix_val++; | |
| 608 | 1283959 | inc = 1; | |
| 609 | } | ||
| 610 |
2/2✓ Branch 0 taken 141978 times.
✓ Branch 1 taken 778274 times.
|
920252 | if (prefix_val >= 5) { |
| 611 | 141978 | int k = 0; | |
| 612 |
3/4✓ Branch 0 taken 438128 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 296150 times.
✓ Branch 4 taken 141978 times.
|
438128 | while (k < 7 && get_cabac_bypass(&lc->sub.cc)) { |
| 613 | 296150 | suffix_val += 1 << k; | |
| 614 | 296150 | k++; | |
| 615 | } | ||
| 616 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 141978 times.
|
141978 | if (k == 7) { |
| 617 | ✗ | av_log(lc->logctx, AV_LOG_ERROR, "CABAC_MAX_BIN : %d\n", k); | |
| 618 | ✗ | return AVERROR_INVALIDDATA; | |
| 619 | } | ||
| 620 | |||
| 621 |
2/2✓ Branch 0 taken 296150 times.
✓ Branch 1 taken 141978 times.
|
438128 | while (k--) |
| 622 | 296150 | suffix_val += get_cabac_bypass(&lc->sub.cc) << k; | |
| 623 | } | ||
| 624 | 920252 | return prefix_val + suffix_val; | |
| 625 | } | ||
| 626 | |||
| 627 | 485048 | int ff_hevc_cu_qp_delta_sign_flag(HEVCLocalContext *lc) | |
| 628 | { | ||
| 629 | 485048 | return get_cabac_bypass(&lc->sub.cc); | |
| 630 | } | ||
| 631 | |||
| 632 | 228078 | int ff_hevc_cu_chroma_qp_offset_flag(HEVCLocalContext *lc) | |
| 633 | { | ||
| 634 | 228078 | return GET_CABAC(CU_CHROMA_QP_OFFSET_FLAG_OFFSET); | |
| 635 | } | ||
| 636 | |||
| 637 | ✗ | int ff_hevc_cu_chroma_qp_offset_idx(HEVCLocalContext *lc, int chroma_qp_offset_list_len_minus1) | |
| 638 | { | ||
| 639 | ✗ | int c_max= FFMAX(5, chroma_qp_offset_list_len_minus1); | |
| 640 | ✗ | int i = 0; | |
| 641 | |||
| 642 | ✗ | while (i < c_max && GET_CABAC(CU_CHROMA_QP_OFFSET_IDX_OFFSET)) | |
| 643 | ✗ | i++; | |
| 644 | |||
| 645 | ✗ | return i; | |
| 646 | } | ||
| 647 | |||
| 648 | 5581758 | int ff_hevc_pred_mode_decode(HEVCLocalContext *lc) | |
| 649 | { | ||
| 650 | 5581758 | return GET_CABAC(PRED_MODE_FLAG_OFFSET); | |
| 651 | } | ||
| 652 | |||
| 653 | 9482637 | int ff_hevc_split_coding_unit_flag_decode(HEVCLocalContext *lc, uint8_t *tab_ct_depth, | |
| 654 | const HEVCSPS *sps, | ||
| 655 | int ct_depth, int x0, int y0) | ||
| 656 | { | ||
| 657 | 9482637 | int inc = 0, depth_left = 0, depth_top = 0; | |
| 658 | 9482637 | int x0b = av_zero_extend(x0, sps->log2_ctb_size); | |
| 659 | 9482637 | int y0b = av_zero_extend(y0, sps->log2_ctb_size); | |
| 660 | 9482637 | int x_cb = x0 >> sps->log2_min_cb_size; | |
| 661 | 9482637 | int y_cb = y0 >> sps->log2_min_cb_size; | |
| 662 | |||
| 663 |
4/4✓ Branch 0 taken 864725 times.
✓ Branch 1 taken 8617912 times.
✓ Branch 2 taken 469094 times.
✓ Branch 3 taken 395631 times.
|
9482637 | if (lc->ctb_left_flag || x0b) |
| 664 | 9087006 | depth_left = tab_ct_depth[(y_cb) * sps->min_cb_width + x_cb - 1]; | |
| 665 |
4/4✓ Branch 0 taken 1733109 times.
✓ Branch 1 taken 7749528 times.
✓ Branch 2 taken 953091 times.
✓ Branch 3 taken 780018 times.
|
9482637 | if (lc->ctb_up_flag || y0b) |
| 666 | 8702619 | depth_top = tab_ct_depth[(y_cb - 1) * sps->min_cb_width + x_cb]; | |
| 667 | |||
| 668 | 9482637 | inc += (depth_left > ct_depth); | |
| 669 | 9482637 | inc += (depth_top > ct_depth); | |
| 670 | |||
| 671 | 9482637 | return GET_CABAC(SPLIT_CODING_UNIT_FLAG_OFFSET + inc); | |
| 672 | } | ||
| 673 | |||
| 674 | 7103409 | int ff_hevc_part_mode_decode(HEVCLocalContext *lc, const HEVCSPS *sps, int log2_cb_size) | |
| 675 | { | ||
| 676 |
2/2✓ Branch 1 taken 4471637 times.
✓ Branch 2 taken 2631772 times.
|
7103409 | if (GET_CABAC(PART_MODE_OFFSET)) // 1 |
| 677 | 4471637 | return PART_2Nx2N; | |
| 678 |
2/2✓ Branch 0 taken 1845562 times.
✓ Branch 1 taken 786210 times.
|
2631772 | if (log2_cb_size == sps->log2_min_cb_size) { |
| 679 |
2/2✓ Branch 0 taken 1070180 times.
✓ Branch 1 taken 775382 times.
|
1845562 | if (lc->cu.pred_mode == MODE_INTRA) // 0 |
| 680 | 1070180 | return PART_NxN; | |
| 681 |
2/2✓ Branch 1 taken 317827 times.
✓ Branch 2 taken 457555 times.
|
775382 | if (GET_CABAC(PART_MODE_OFFSET + 1)) // 01 |
| 682 | 317827 | return PART_2NxN; | |
| 683 |
2/2✓ Branch 0 taken 233413 times.
✓ Branch 1 taken 224142 times.
|
457555 | if (log2_cb_size == 3) // 00 |
| 684 | 233413 | return PART_Nx2N; | |
| 685 |
2/2✓ Branch 1 taken 115987 times.
✓ Branch 2 taken 108155 times.
|
224142 | if (GET_CABAC(PART_MODE_OFFSET + 2)) // 001 |
| 686 | 115987 | return PART_Nx2N; | |
| 687 | 108155 | return PART_NxN; // 000 | |
| 688 | } | ||
| 689 | |||
| 690 |
2/2✓ Branch 0 taken 180593 times.
✓ Branch 1 taken 605617 times.
|
786210 | if (!sps->amp_enabled) { |
| 691 |
2/2✓ Branch 1 taken 88775 times.
✓ Branch 2 taken 91818 times.
|
180593 | if (GET_CABAC(PART_MODE_OFFSET + 1)) // 01 |
| 692 | 88775 | return PART_2NxN; | |
| 693 | 91818 | return PART_Nx2N; | |
| 694 | } | ||
| 695 | |||
| 696 |
2/2✓ Branch 1 taken 241563 times.
✓ Branch 2 taken 364054 times.
|
605617 | if (GET_CABAC(PART_MODE_OFFSET + 1)) { // 01X, 01XX |
| 697 |
2/2✓ Branch 1 taken 115990 times.
✓ Branch 2 taken 125573 times.
|
241563 | if (GET_CABAC(PART_MODE_OFFSET + 3)) // 011 |
| 698 | 115990 | return PART_2NxN; | |
| 699 |
2/2✓ Branch 1 taken 58179 times.
✓ Branch 2 taken 67394 times.
|
125573 | if (get_cabac_bypass(&lc->sub.cc)) // 0101 |
| 700 | 58179 | return PART_2NxnD; | |
| 701 | 67394 | return PART_2NxnU; // 0100 | |
| 702 | } | ||
| 703 | |||
| 704 |
2/2✓ Branch 1 taken 177818 times.
✓ Branch 2 taken 186236 times.
|
364054 | if (GET_CABAC(PART_MODE_OFFSET + 3)) // 001 |
| 705 | 177818 | return PART_Nx2N; | |
| 706 |
2/2✓ Branch 1 taken 85890 times.
✓ Branch 2 taken 100346 times.
|
186236 | if (get_cabac_bypass(&lc->sub.cc)) // 0001 |
| 707 | 85890 | return PART_nRx2N; | |
| 708 | 100346 | return PART_nLx2N; // 0000 | |
| 709 | } | ||
| 710 | |||
| 711 | 126478 | int ff_hevc_pcm_flag_decode(HEVCLocalContext *lc) | |
| 712 | { | ||
| 713 | 126478 | return get_cabac_terminate(&lc->sub.cc); | |
| 714 | } | ||
| 715 | |||
| 716 | 6956058 | int ff_hevc_prev_intra_luma_pred_flag_decode(HEVCLocalContext *lc) | |
| 717 | { | ||
| 718 | 6956058 | return GET_CABAC(PREV_INTRA_LUMA_PRED_FLAG_OFFSET); | |
| 719 | } | ||
| 720 | |||
| 721 | 4139240 | int ff_hevc_mpm_idx_decode(HEVCLocalContext *lc) | |
| 722 | { | ||
| 723 | 4139240 | int i = 0; | |
| 724 |
4/4✓ Branch 0 taken 6179412 times.
✓ Branch 1 taken 867719 times.
✓ Branch 3 taken 2907891 times.
✓ Branch 4 taken 3271521 times.
|
7047131 | while (i < 2 && get_cabac_bypass(&lc->sub.cc)) |
| 725 | 2907891 | i++; | |
| 726 | 4139240 | return i; | |
| 727 | } | ||
| 728 | |||
| 729 | 2816818 | int ff_hevc_rem_intra_luma_pred_mode_decode(HEVCLocalContext *lc) | |
| 730 | { | ||
| 731 | int i; | ||
| 732 | 2816818 | int value = get_cabac_bypass(&lc->sub.cc); | |
| 733 | |||
| 734 |
2/2✓ Branch 0 taken 11267272 times.
✓ Branch 1 taken 2816818 times.
|
14084090 | for (i = 0; i < 4; i++) |
| 735 | 11267272 | value = (value << 1) | get_cabac_bypass(&lc->sub.cc); | |
| 736 | 2816818 | return value; | |
| 737 | } | ||
| 738 | |||
| 739 | 3801791 | int ff_hevc_intra_chroma_pred_mode_decode(HEVCLocalContext *lc) | |
| 740 | { | ||
| 741 | int ret; | ||
| 742 |
2/2✓ Branch 1 taken 2911284 times.
✓ Branch 2 taken 890507 times.
|
3801791 | if (!GET_CABAC(INTRA_CHROMA_PRED_MODE_OFFSET)) |
| 743 | 2911284 | return 4; | |
| 744 | |||
| 745 | 890507 | ret = get_cabac_bypass(&lc->sub.cc) << 1; | |
| 746 | 890507 | ret |= get_cabac_bypass(&lc->sub.cc); | |
| 747 | 890507 | return ret; | |
| 748 | } | ||
| 749 | |||
| 750 | 8001358 | int ff_hevc_merge_idx_decode(HEVCLocalContext *lc) | |
| 751 | { | ||
| 752 | 8001358 | int i = GET_CABAC(MERGE_IDX_OFFSET); | |
| 753 | |||
| 754 |
2/2✓ Branch 0 taken 3166345 times.
✓ Branch 1 taken 4835013 times.
|
8001358 | if (i != 0) { |
| 755 |
4/4✓ Branch 0 taken 4604593 times.
✓ Branch 1 taken 412546 times.
✓ Branch 3 taken 1850794 times.
✓ Branch 4 taken 2753799 times.
|
5017139 | while (i < lc->sh->max_num_merge_cand-1 && get_cabac_bypass(&lc->sub.cc)) |
| 756 | 1850794 | i++; | |
| 757 | } | ||
| 758 | 8001358 | return i; | |
| 759 | } | ||
| 760 | |||
| 761 | 6055465 | int ff_hevc_merge_flag_decode(HEVCLocalContext *lc) | |
| 762 | { | ||
| 763 | 6055465 | return GET_CABAC(MERGE_FLAG_OFFSET); | |
| 764 | } | ||
| 765 | |||
| 766 | 1923691 | int ff_hevc_inter_pred_idc_decode(HEVCLocalContext *lc, int nPbW, int nPbH) | |
| 767 | { | ||
| 768 |
2/2✓ Branch 0 taken 248743 times.
✓ Branch 1 taken 1674948 times.
|
1923691 | if (nPbW + nPbH == 12) |
| 769 | 248743 | return GET_CABAC(INTER_PRED_IDC_OFFSET + 4); | |
| 770 |
2/2✓ Branch 1 taken 425087 times.
✓ Branch 2 taken 1249861 times.
|
1674948 | if (GET_CABAC(INTER_PRED_IDC_OFFSET + lc->ct_depth)) |
| 771 | 425087 | return PRED_BI; | |
| 772 | |||
| 773 | 1249861 | return GET_CABAC(INTER_PRED_IDC_OFFSET + 4); | |
| 774 | } | ||
| 775 | |||
| 776 | 3542827 | int ff_hevc_ref_idx_lx_decode(HEVCLocalContext *lc, int num_ref_idx_lx) | |
| 777 | { | ||
| 778 | 3542827 | int i = 0; | |
| 779 | 3542827 | int max = num_ref_idx_lx - 1; | |
| 780 | 3542827 | int max_ctx = FFMIN(max, 2); | |
| 781 | |||
| 782 |
4/4✓ Branch 0 taken 3331489 times.
✓ Branch 1 taken 1311595 times.
✓ Branch 3 taken 1100257 times.
✓ Branch 4 taken 2231232 times.
|
4643084 | while (i < max_ctx && GET_CABAC(REF_IDX_L0_OFFSET + i)) |
| 783 | 1100257 | i++; | |
| 784 |
2/2✓ Branch 0 taken 203609 times.
✓ Branch 1 taken 3339218 times.
|
3542827 | if (i == 2) { |
| 785 |
4/4✓ Branch 0 taken 162576 times.
✓ Branch 1 taken 127630 times.
✓ Branch 3 taken 86597 times.
✓ Branch 4 taken 75979 times.
|
290206 | while (i < max && get_cabac_bypass(&lc->sub.cc)) |
| 786 | 86597 | i++; | |
| 787 | } | ||
| 788 | |||
| 789 | 3542827 | return i; | |
| 790 | } | ||
| 791 | |||
| 792 | 3542827 | int ff_hevc_mvp_lx_flag_decode(HEVCLocalContext *lc) | |
| 793 | { | ||
| 794 | 3542827 | return GET_CABAC(MVP_LX_FLAG_OFFSET); | |
| 795 | } | ||
| 796 | |||
| 797 | 3069115 | int ff_hevc_no_residual_syntax_flag_decode(HEVCLocalContext *lc) | |
| 798 | { | ||
| 799 | 3069115 | return GET_CABAC(NO_RESIDUAL_DATA_FLAG_OFFSET); | |
| 800 | } | ||
| 801 | |||
| 802 | 6758444 | static av_always_inline int abs_mvd_greater0_flag_decode(HEVCLocalContext *lc) | |
| 803 | { | ||
| 804 | 6758444 | return GET_CABAC(ABS_MVD_GREATER0_FLAG_OFFSET); | |
| 805 | } | ||
| 806 | |||
| 807 | 4542572 | static av_always_inline int abs_mvd_greater1_flag_decode(HEVCLocalContext *lc) | |
| 808 | { | ||
| 809 | 4542572 | return GET_CABAC(ABS_MVD_GREATER1_FLAG_OFFSET + 1); | |
| 810 | } | ||
| 811 | |||
| 812 | 3112692 | static av_always_inline int mvd_decode(HEVCLocalContext *lc) | |
| 813 | { | ||
| 814 | 3112692 | int ret = 2; | |
| 815 | 3112692 | int k = 1; | |
| 816 | |||
| 817 |
3/4✓ Branch 0 taken 7471928 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 4359236 times.
✓ Branch 4 taken 3112692 times.
|
7471928 | while (k < CABAC_MAX_BIN && get_cabac_bypass(&lc->sub.cc)) { |
| 818 | 4359236 | ret += 1U << k; | |
| 819 | 4359236 | k++; | |
| 820 | } | ||
| 821 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3112692 times.
|
3112692 | if (k == CABAC_MAX_BIN) { |
| 822 | ✗ | av_log(lc->logctx, AV_LOG_ERROR, "CABAC_MAX_BIN : %d\n", k); | |
| 823 | ✗ | return 0; | |
| 824 | } | ||
| 825 |
2/2✓ Branch 0 taken 7471928 times.
✓ Branch 1 taken 3112692 times.
|
10584620 | while (k--) |
| 826 | 7471928 | ret += get_cabac_bypass(&lc->sub.cc) << k; | |
| 827 | 3112692 | return get_cabac_bypass_sign(&lc->sub.cc, -ret); | |
| 828 | } | ||
| 829 | |||
| 830 | 1429880 | static av_always_inline int mvd_sign_flag_decode(HEVCLocalContext *lc) | |
| 831 | { | ||
| 832 | 1429880 | return get_cabac_bypass_sign(&lc->sub.cc, -1); | |
| 833 | } | ||
| 834 | |||
| 835 | 7166603 | int ff_hevc_split_transform_flag_decode(HEVCLocalContext *lc, int log2_trafo_size) | |
| 836 | { | ||
| 837 | 7166603 | return GET_CABAC(SPLIT_TRANSFORM_FLAG_OFFSET + 5 - log2_trafo_size); | |
| 838 | } | ||
| 839 | |||
| 840 | 15959986 | int ff_hevc_cbf_cb_cr_decode(HEVCLocalContext *lc, int trafo_depth) | |
| 841 | { | ||
| 842 | 15959986 | return GET_CABAC(CBF_CB_CR_OFFSET + trafo_depth); | |
| 843 | } | ||
| 844 | |||
| 845 | 14965982 | int ff_hevc_cbf_luma_decode(HEVCLocalContext *lc, int trafo_depth) | |
| 846 | { | ||
| 847 |
2/2✓ Branch 0 taken 2811022 times.
✓ Branch 1 taken 12154960 times.
|
14965982 | return GET_CABAC(CBF_LUMA_OFFSET + !trafo_depth); |
| 848 | } | ||
| 849 | |||
| 850 | 5701370 | static int hevc_transform_skip_flag_decode(HEVCLocalContext *lc, int c_idx) | |
| 851 | { | ||
| 852 |
2/2✓ Branch 0 taken 1848777 times.
✓ Branch 1 taken 3852593 times.
|
5701370 | return GET_CABAC(TRANSFORM_SKIP_FLAG_OFFSET + !!c_idx); |
| 853 | } | ||
| 854 | |||
| 855 | 35234 | static int explicit_rdpcm_flag_decode(HEVCLocalContext *lc, int c_idx) | |
| 856 | { | ||
| 857 |
2/2✓ Branch 0 taken 29253 times.
✓ Branch 1 taken 5981 times.
|
35234 | return GET_CABAC(EXPLICIT_RDPCM_FLAG_OFFSET + !!c_idx); |
| 858 | } | ||
| 859 | |||
| 860 | 3090 | static int explicit_rdpcm_dir_flag_decode(HEVCLocalContext *lc, int c_idx) | |
| 861 | { | ||
| 862 |
2/2✓ Branch 0 taken 1813 times.
✓ Branch 1 taken 1277 times.
|
3090 | return GET_CABAC(EXPLICIT_RDPCM_DIR_FLAG_OFFSET + !!c_idx); |
| 863 | } | ||
| 864 | |||
| 865 | 251428 | int ff_hevc_log2_res_scale_abs(HEVCLocalContext *lc, int idx) | |
| 866 | { | ||
| 867 | 251428 | int i =0; | |
| 868 | |||
| 869 |
4/4✓ Branch 0 taken 668172 times.
✓ Branch 1 taken 84789 times.
✓ Branch 3 taken 501533 times.
✓ Branch 4 taken 166639 times.
|
752961 | while (i < 4 && GET_CABAC(LOG2_RES_SCALE_ABS_OFFSET + 4 * idx + i)) |
| 870 | 501533 | i++; | |
| 871 | |||
| 872 | 251428 | return i; | |
| 873 | } | ||
| 874 | |||
| 875 | 142161 | int ff_hevc_res_scale_sign_flag(HEVCLocalContext *lc, int idx) | |
| 876 | { | ||
| 877 | 142161 | return GET_CABAC(RES_SCALE_SIGN_FLAG_OFFSET + idx); | |
| 878 | } | ||
| 879 | |||
| 880 | 14292077 | static av_always_inline void last_significant_coeff_xy_prefix_decode(HEVCLocalContext *lc, int c_idx, | |
| 881 | int log2_size, int *last_scx_prefix, int *last_scy_prefix) | ||
| 882 | { | ||
| 883 | 14292077 | int i = 0; | |
| 884 | 14292077 | int max = (log2_size << 1) - 1; | |
| 885 | int ctx_offset, ctx_shift; | ||
| 886 | |||
| 887 |
2/2✓ Branch 0 taken 10136106 times.
✓ Branch 1 taken 4155971 times.
|
14292077 | if (!c_idx) { |
| 888 | 10136106 | ctx_offset = 3 * (log2_size - 2) + ((log2_size - 1) >> 2); | |
| 889 | 10136106 | ctx_shift = (log2_size + 1) >> 2; | |
| 890 | } else { | ||
| 891 | 4155971 | ctx_offset = 15; | |
| 892 | 4155971 | ctx_shift = log2_size - 2; | |
| 893 | } | ||
| 894 |
4/4✓ Branch 0 taken 34755241 times.
✓ Branch 1 taken 1881938 times.
✓ Branch 2 taken 22345102 times.
✓ Branch 3 taken 12410139 times.
|
71392420 | while (i < max && |
| 895 | 34755241 | GET_CABAC(LAST_SIGNIFICANT_COEFF_X_PREFIX_OFFSET + (i >> ctx_shift) + ctx_offset)) | |
| 896 | 22345102 | i++; | |
| 897 | 14292077 | *last_scx_prefix = i; | |
| 898 | |||
| 899 | 14292077 | i = 0; | |
| 900 |
4/4✓ Branch 0 taken 30556780 times.
✓ Branch 1 taken 1526943 times.
✓ Branch 2 taken 17791646 times.
✓ Branch 3 taken 12765134 times.
|
62640503 | while (i < max && |
| 901 | 30556780 | GET_CABAC(LAST_SIGNIFICANT_COEFF_Y_PREFIX_OFFSET + (i >> ctx_shift) + ctx_offset)) | |
| 902 | 17791646 | i++; | |
| 903 | 14292077 | *last_scy_prefix = i; | |
| 904 | 14292077 | } | |
| 905 | |||
| 906 | 3263919 | static av_always_inline int last_significant_coeff_suffix_decode(HEVCLocalContext *lc, | |
| 907 | int last_significant_coeff_prefix) | ||
| 908 | { | ||
| 909 | int i; | ||
| 910 | 3263919 | int length = (last_significant_coeff_prefix >> 1) - 1; | |
| 911 | 3263919 | int value = get_cabac_bypass(&lc->sub.cc); | |
| 912 | |||
| 913 |
2/2✓ Branch 0 taken 878265 times.
✓ Branch 1 taken 3263919 times.
|
4142184 | for (i = 1; i < length; i++) |
| 914 | 878265 | value = (value << 1) | get_cabac_bypass(&lc->sub.cc); | |
| 915 | 3263919 | return value; | |
| 916 | } | ||
| 917 | |||
| 918 | 8388041 | static av_always_inline int significant_coeff_group_flag_decode(HEVCLocalContext *lc, int c_idx, int ctx_cg) | |
| 919 | { | ||
| 920 | int inc; | ||
| 921 | |||
| 922 |
2/2✓ Branch 0 taken 1179753 times.
✓ Branch 1 taken 7208288 times.
|
8388041 | inc = FFMIN(ctx_cg, 1) + (c_idx>0 ? 2 : 0); |
| 923 | |||
| 924 | 8388041 | return GET_CABAC(SIGNIFICANT_COEFF_GROUP_FLAG_OFFSET + inc); | |
| 925 | } | ||
| 926 | 170100122 | static av_always_inline int significant_coeff_flag_decode(HEVCLocalContext *lc, int n, | |
| 927 | int offset, const uint8_t *ctx_idx_map) | ||
| 928 | { | ||
| 929 | 170100122 | int inc = ctx_idx_map[n] + offset; | |
| 930 | 170100122 | return GET_CABAC(SIGNIFICANT_COEFF_FLAG_OFFSET + inc); | |
| 931 | } | ||
| 932 | |||
| 933 | 18388123 | static av_always_inline int significant_coeff_flag_decode_0(HEVCLocalContext *lc, int c_idx, int offset) | |
| 934 | { | ||
| 935 | 18388123 | return GET_CABAC(SIGNIFICANT_COEFF_FLAG_OFFSET + offset); | |
| 936 | } | ||
| 937 | |||
| 938 | 86527310 | static av_always_inline int coeff_abs_level_greater1_flag_decode(HEVCLocalContext *lc, int c_idx, int inc) | |
| 939 | { | ||
| 940 | |||
| 941 |
2/2✓ Branch 0 taken 18369553 times.
✓ Branch 1 taken 68157757 times.
|
86527310 | if (c_idx > 0) |
| 942 | 18369553 | inc += 16; | |
| 943 | |||
| 944 | 86527310 | return GET_CABAC(COEFF_ABS_LEVEL_GREATER1_FLAG_OFFSET + inc); | |
| 945 | } | ||
| 946 | |||
| 947 | 9392252 | static av_always_inline int coeff_abs_level_greater2_flag_decode(HEVCLocalContext *lc, int c_idx, int inc) | |
| 948 | { | ||
| 949 |
2/2✓ Branch 0 taken 1797939 times.
✓ Branch 1 taken 7594313 times.
|
9392252 | if (c_idx > 0) |
| 950 | 1797939 | inc += 4; | |
| 951 | |||
| 952 | 9392252 | return GET_CABAC(COEFF_ABS_LEVEL_GREATER2_FLAG_OFFSET + inc); | |
| 953 | } | ||
| 954 | |||
| 955 | /* a run of bypass bins is the quotient of the offset by range << 17 */ | ||
| 956 | 17296445 | static int cabac_bypass_bits(CABACContext *c, int n) | |
| 957 | { | ||
| 958 | 17296445 | int avail = CABAC_BITS - ff_ctz(c->low); | |
| 959 | 17296445 | uint64_t x, r = (uint64_t)c->range << (CABAC_BITS + 1); | |
| 960 | 17296445 | const uint8_t *bytestream = c->bytestream; | |
| 961 | |||
| 962 |
2/2✓ Branch 0 taken 10800097 times.
✓ Branch 1 taken 6496348 times.
|
17296445 | if (n < avail) { |
| 963 | 10800097 | x = (uint64_t)c->low << n; | |
| 964 | } else { | ||
| 965 | 6496348 | int fill = (bytestream[0] << 9) + (bytestream[1] << 1) - CABAC_MASK; | |
| 966 | |||
| 967 | 6496348 | x = (uint64_t)((((int64_t)c->low << avail) + fill)) << (n - avail); | |
| 968 | #if !UNCHECKED_BITSTREAM_READER | ||
| 969 |
2/2✓ Branch 0 taken 6496148 times.
✓ Branch 1 taken 200 times.
|
6496348 | if (bytestream < c->bytestream_end) |
| 970 | #endif | ||
| 971 | 6496148 | bytestream += CABAC_BITS / 8; | |
| 972 | } | ||
| 973 | |||
| 974 |
1/2✓ Branch 0 taken 17296445 times.
✗ Branch 1 not taken.
|
17296445 | if (x < r << n) { |
| 975 | 17296445 | c->low = x % r; | |
| 976 | 17296445 | c->bytestream = bytestream; | |
| 977 | 17296445 | return x / r; | |
| 978 | } else { | ||
| 979 | ✗ | int ret = 0; | |
| 980 | |||
| 981 | ✗ | for (int i = 0; i < n; i++) | |
| 982 | ✗ | ret = (ret << 1) | get_cabac_bypass(c); | |
| 983 | ✗ | return ret; | |
| 984 | } | ||
| 985 | } | ||
| 986 | |||
| 987 | /* leading ones of the quotient, consumed only up to the first zero */ | ||
| 988 | 36906236 | static int cabac_unary_prefix(CABACContext *c, int max) | |
| 989 | { | ||
| 990 | 36906236 | int prefix = 0; | |
| 991 | |||
| 992 |
1/2✓ Branch 0 taken 42227664 times.
✗ Branch 1 not taken.
|
42227664 | while (prefix < max) { |
| 993 | 42227664 | int avail = CABAC_BITS - ff_ctz(c->low); | |
| 994 | 42227664 | int n = FFMIN(avail - 1, max - prefix); | |
| 995 | 42227664 | uint64_t r = (uint64_t)c->range << (CABAC_BITS + 1); | |
| 996 | 42227664 | uint64_t x = (uint64_t)c->low << n; | |
| 997 | int q, t; | ||
| 998 | |||
| 999 |
3/4✓ Branch 0 taken 37259099 times.
✓ Branch 1 taken 4968565 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 37259099 times.
|
42227664 | if (n < 1 || x >= r << n) { |
| 1000 |
2/2✓ Branch 1 taken 2307222 times.
✓ Branch 2 taken 2661343 times.
|
4968565 | if (!get_cabac_bypass(c)) |
| 1001 | 2307222 | return prefix; | |
| 1002 | 2661343 | prefix++; | |
| 1003 | 2661343 | continue; | |
| 1004 | } | ||
| 1005 | |||
| 1006 | 37259099 | q = x / r; | |
| 1007 | 37259099 | t = ~q & ((1 << n) - 1); | |
| 1008 |
2/2✓ Branch 0 taken 34599014 times.
✓ Branch 1 taken 2660085 times.
|
37259099 | if (t) { |
| 1009 | 34599014 | int p = n - 1 - av_log2(t); | |
| 1010 | 34599014 | int k = n - (p + 1); | |
| 1011 | |||
| 1012 | 34599014 | c->low = (x >> k) - ((uint64_t)(q >> k) * r); | |
| 1013 | 34599014 | return prefix + p; | |
| 1014 | } | ||
| 1015 | 2660085 | c->low = x - (uint64_t)q * r; | |
| 1016 | 2660085 | prefix += n; | |
| 1017 | } | ||
| 1018 | ✗ | return prefix; | |
| 1019 | } | ||
| 1020 | |||
| 1021 | 36906236 | static av_always_inline int coeff_abs_level_remaining_decode(HEVCLocalContext *lc, int rc_rice_param) | |
| 1022 | { | ||
| 1023 | int prefix; | ||
| 1024 | 36906236 | int suffix = 0; | |
| 1025 | int last_coeff_abs_level_remaining; | ||
| 1026 | int i; | ||
| 1027 | |||
| 1028 | 36906236 | prefix = cabac_unary_prefix(&lc->sub.cc, CABAC_MAX_BIN); | |
| 1029 | |||
| 1030 |
2/2✓ Branch 0 taken 31863750 times.
✓ Branch 1 taken 5042486 times.
|
36906236 | if (prefix < 3) { |
| 1031 |
2/2✓ Branch 0 taken 3411491 times.
✓ Branch 1 taken 28452259 times.
|
31863750 | if (rc_rice_param > 2) |
| 1032 | 3411491 | suffix = cabac_bypass_bits(&lc->sub.cc, rc_rice_param); | |
| 1033 | else | ||
| 1034 |
2/2✓ Branch 0 taken 19495607 times.
✓ Branch 1 taken 28452259 times.
|
47947866 | for (i = 0; i < rc_rice_param; i++) |
| 1035 | 19495607 | suffix = (suffix << 1) | get_cabac_bypass(&lc->sub.cc); | |
| 1036 | 31863750 | last_coeff_abs_level_remaining = (prefix << rc_rice_param) + suffix; | |
| 1037 | } else { | ||
| 1038 | 5042486 | int prefix_minus3 = prefix - 3; | |
| 1039 | int k; | ||
| 1040 | |||
| 1041 |
2/4✓ Branch 0 taken 5042486 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 5042486 times.
|
5042486 | if (prefix == CABAC_MAX_BIN || prefix_minus3 + rc_rice_param > 16 + 6) { |
| 1042 | ✗ | av_log(lc->logctx, AV_LOG_ERROR, "CABAC_MAX_BIN : %d\n", prefix); | |
| 1043 | ✗ | return 0; | |
| 1044 | } | ||
| 1045 | |||
| 1046 | 5042486 | k = prefix_minus3 + rc_rice_param; | |
| 1047 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5042486 times.
|
5042486 | if (k > 16) { |
| 1048 | ✗ | suffix = cabac_bypass_bits(&lc->sub.cc, 16) << (k - 16); | |
| 1049 | ✗ | suffix |= cabac_bypass_bits(&lc->sub.cc, k - 16); | |
| 1050 |
2/2✓ Branch 0 taken 2177876 times.
✓ Branch 1 taken 2864610 times.
|
5042486 | } else if (k > 2) { |
| 1051 | 2177876 | suffix = cabac_bypass_bits(&lc->sub.cc, k); | |
| 1052 | } else { | ||
| 1053 |
2/2✓ Branch 0 taken 2805317 times.
✓ Branch 1 taken 2864610 times.
|
5669927 | for (i = 0; i < k; i++) |
| 1054 | 2805317 | suffix = (suffix << 1) | get_cabac_bypass(&lc->sub.cc); | |
| 1055 | } | ||
| 1056 | 5042486 | last_coeff_abs_level_remaining = (((1 << prefix_minus3) + 3 - 1) | |
| 1057 | 5042486 | << rc_rice_param) + suffix; | |
| 1058 | } | ||
| 1059 | 36906236 | return last_coeff_abs_level_remaining; | |
| 1060 | } | ||
| 1061 | |||
| 1062 | 21795729 | static av_always_inline int coeff_sign_flag_decode(HEVCLocalContext *lc, uint8_t nb) | |
| 1063 | { | ||
| 1064 | int i; | ||
| 1065 | 21795729 | int ret = 0; | |
| 1066 | |||
| 1067 |
2/2✓ Branch 0 taken 11707078 times.
✓ Branch 1 taken 10088651 times.
|
21795729 | if (nb > 2) |
| 1068 | 11707078 | return cabac_bypass_bits(&lc->sub.cc, nb); | |
| 1069 | |||
| 1070 |
2/2✓ Branch 0 taken 14193732 times.
✓ Branch 1 taken 10088651 times.
|
24282383 | for (i = 0; i < nb; i++) |
| 1071 | 14193732 | ret = (ret << 1) | get_cabac_bypass(&lc->sub.cc); | |
| 1072 | 10088651 | return ret; | |
| 1073 | } | ||
| 1074 | |||
| 1075 | 14292077 | void ff_hevc_hls_residual_coding(HEVCLocalContext *lc, const HEVCPPS *pps, | |
| 1076 | int x0, int y0, | ||
| 1077 | int log2_trafo_size, enum ScanType scan_idx, | ||
| 1078 | int c_idx) | ||
| 1079 | { | ||
| 1080 | #define GET_COORD(offset, n) \ | ||
| 1081 | do { \ | ||
| 1082 | x_c = (x_cg << 2) + scan_x_off[n]; \ | ||
| 1083 | y_c = (y_cg << 2) + scan_y_off[n]; \ | ||
| 1084 | } while (0) | ||
| 1085 | 14292077 | const HEVCContext *const s = lc->parent; | |
| 1086 | 14292077 | const HEVCSPS *const sps = pps->sps; | |
| 1087 | 14292077 | int transform_skip_flag = 0; | |
| 1088 | |||
| 1089 | int last_significant_coeff_x, last_significant_coeff_y; | ||
| 1090 | int last_scan_pos; | ||
| 1091 | int n_end; | ||
| 1092 | 14292077 | int num_coeff = 0; | |
| 1093 | 14292077 | int greater1_ctx = 1; | |
| 1094 | |||
| 1095 | int num_last_subset; | ||
| 1096 | int max_xy, col_limit, clear_rows; | ||
| 1097 | int x_cg_last_sig, y_cg_last_sig; | ||
| 1098 | |||
| 1099 | const uint8_t *scan_x_cg, *scan_y_cg, *scan_x_off, *scan_y_off; | ||
| 1100 | |||
| 1101 | 14292077 | ptrdiff_t stride = s->cur_frame->f->linesize[c_idx]; | |
| 1102 | 14292077 | int hshift = sps->hshift[c_idx]; | |
| 1103 | 14292077 | int vshift = sps->vshift[c_idx]; | |
| 1104 | 14292077 | uint8_t *dst = &s->cur_frame->f->data[c_idx][(y0 >> vshift) * stride + | |
| 1105 | 14292077 | ((x0 >> hshift) << sps->pixel_shift)]; | |
| 1106 |
2/2✓ Branch 0 taken 4155971 times.
✓ Branch 1 taken 10136106 times.
|
14292077 | int16_t *coeffs = (int16_t*)(c_idx ? lc->edge_emu_buffer2 : lc->edge_emu_buffer); |
| 1107 | 14292077 | uint8_t significant_coeff_group_flag[8][8] = {{0}}; | |
| 1108 | 14292077 | int explicit_rdpcm_flag = 0; | |
| 1109 | int explicit_rdpcm_dir_flag; | ||
| 1110 | |||
| 1111 | 14292077 | int trafo_size = 1 << log2_trafo_size; | |
| 1112 | int i; | ||
| 1113 | int qp,shift,add,scale,scale_m; | ||
| 1114 | static const uint8_t level_scale[] = { 40, 45, 51, 57, 64, 72 }; | ||
| 1115 | 14292077 | const uint8_t *scale_matrix = NULL; | |
| 1116 | uint8_t dc_scale; | ||
| 1117 |
2/2✓ Branch 0 taken 10136106 times.
✓ Branch 1 taken 4155971 times.
|
14292077 | int pred_mode_intra = (c_idx == 0) ? lc->tu.intra_pred_mode : |
| 1118 | lc->tu.intra_pred_mode_c; | ||
| 1119 | |||
| 1120 | // Derive QP for dequant | ||
| 1121 |
2/2✓ Branch 0 taken 13867879 times.
✓ Branch 1 taken 424198 times.
|
14292077 | if (!lc->cu.cu_transquant_bypass_flag) { |
| 1122 | static const int qp_c[] = { 29, 30, 31, 32, 33, 33, 34, 34, 35, 35, 36, 36, 37, 37 }; | ||
| 1123 | static const uint8_t rem6[51 + 4 * 6 + 1] = { | ||
| 1124 | 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, | ||
| 1125 | 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, | ||
| 1126 | 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, | ||
| 1127 | 4, 5, 0, 1, 2, 3, 4, 5, 0, 1 | ||
| 1128 | }; | ||
| 1129 | |||
| 1130 | static const uint8_t div6[51 + 4 * 6 + 1] = { | ||
| 1131 | 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, | ||
| 1132 | 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, | ||
| 1133 | 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, | ||
| 1134 | 10, 10, 11, 11, 11, 11, 11, 11, 12, 12 | ||
| 1135 | }; | ||
| 1136 | 13867879 | int qp_y = lc->sub.qp_y; | |
| 1137 | |||
| 1138 |
2/2✓ Branch 0 taken 10307969 times.
✓ Branch 1 taken 3559910 times.
|
13867879 | if (pps->transform_skip_enabled_flag && |
| 1139 |
2/2✓ Branch 0 taken 5701370 times.
✓ Branch 1 taken 4606599 times.
|
10307969 | log2_trafo_size <= pps->log2_max_transform_skip_block_size) { |
| 1140 | 5701370 | transform_skip_flag = hevc_transform_skip_flag_decode(lc, c_idx); | |
| 1141 | } | ||
| 1142 | |||
| 1143 |
2/2✓ Branch 0 taken 9875311 times.
✓ Branch 1 taken 3992568 times.
|
13867879 | if (c_idx == 0) { |
| 1144 | 9875311 | qp = qp_y + sps->qp_bd_offset; | |
| 1145 | } else { | ||
| 1146 | int qp_i, offset; | ||
| 1147 | |||
| 1148 |
2/2✓ Branch 0 taken 1919420 times.
✓ Branch 1 taken 2073148 times.
|
3992568 | if (c_idx == 1) |
| 1149 | 1919420 | offset = pps->cb_qp_offset + lc->sh->slice_cb_qp_offset + | |
| 1150 | 1919420 | lc->sub.cu_qp_offset_cb; | |
| 1151 | else | ||
| 1152 | 2073148 | offset = pps->cr_qp_offset + lc->sh->slice_cr_qp_offset + | |
| 1153 | 2073148 | lc->sub.cu_qp_offset_cr; | |
| 1154 | |||
| 1155 | 3992568 | qp_i = av_clip(qp_y + offset, - sps->qp_bd_offset, 57); | |
| 1156 |
2/2✓ Branch 0 taken 2596256 times.
✓ Branch 1 taken 1396312 times.
|
3992568 | if (sps->chroma_format_idc == 1) { |
| 1157 |
2/2✓ Branch 0 taken 953564 times.
✓ Branch 1 taken 1642692 times.
|
2596256 | if (qp_i < 30) |
| 1158 | 953564 | qp = qp_i; | |
| 1159 |
2/2✓ Branch 0 taken 11213 times.
✓ Branch 1 taken 1631479 times.
|
1642692 | else if (qp_i > 43) |
| 1160 | 11213 | qp = qp_i - 6; | |
| 1161 | else | ||
| 1162 | 1631479 | qp = qp_c[qp_i - 30]; | |
| 1163 | } else { | ||
| 1164 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1396312 times.
|
1396312 | if (qp_i > 51) |
| 1165 | ✗ | qp = 51; | |
| 1166 | else | ||
| 1167 | 1396312 | qp = qp_i; | |
| 1168 | } | ||
| 1169 | |||
| 1170 | 3992568 | qp += sps->qp_bd_offset; | |
| 1171 | } | ||
| 1172 | |||
| 1173 | 13867879 | shift = sps->bit_depth + log2_trafo_size - 5; | |
| 1174 | 13867879 | add = 1 << (shift-1); | |
| 1175 | 13867879 | scale = level_scale[rem6[qp]] << (div6[qp]); | |
| 1176 | 13867879 | scale_m = 16; // default when no custom scaling lists. | |
| 1177 | 13867879 | dc_scale = 16; | |
| 1178 | |||
| 1179 |
6/6✓ Branch 0 taken 613107 times.
✓ Branch 1 taken 13254772 times.
✓ Branch 2 taken 19500 times.
✓ Branch 3 taken 593607 times.
✓ Branch 4 taken 11407 times.
✓ Branch 5 taken 8093 times.
|
13867879 | if (sps->scaling_list_enabled && !(transform_skip_flag && log2_trafo_size > 2)) { |
| 1180 | 1210028 | const ScalingList *sl = pps->scaling_list_data_present_flag ? | |
| 1181 |
2/2✓ Branch 0 taken 347752 times.
✓ Branch 1 taken 257262 times.
|
605014 | &pps->scaling_list : &sps->scaling_list; |
| 1182 | 605014 | int matrix_id = lc->cu.pred_mode != MODE_INTRA; | |
| 1183 | |||
| 1184 | 605014 | matrix_id = 3 * matrix_id + c_idx; | |
| 1185 | |||
| 1186 | 605014 | scale_matrix = sl->sl[log2_trafo_size - 2][matrix_id]; | |
| 1187 |
2/2✓ Branch 0 taken 112450 times.
✓ Branch 1 taken 492564 times.
|
605014 | if (log2_trafo_size >= 4) |
| 1188 | 112450 | dc_scale = sl->sl_dc[log2_trafo_size - 4][matrix_id]; | |
| 1189 | } | ||
| 1190 | } else { | ||
| 1191 | 424198 | shift = 0; | |
| 1192 | 424198 | add = 0; | |
| 1193 | 424198 | scale = 0; | |
| 1194 | 424198 | dc_scale = 0; | |
| 1195 | } | ||
| 1196 | |||
| 1197 |
6/6✓ Branch 0 taken 5995166 times.
✓ Branch 1 taken 8296911 times.
✓ Branch 2 taken 225511 times.
✓ Branch 3 taken 5769655 times.
✓ Branch 4 taken 190277 times.
✓ Branch 5 taken 35234 times.
|
14292077 | if (lc->cu.pred_mode == MODE_INTER && sps->explicit_rdpcm_enabled && |
| 1198 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 190277 times.
|
190277 | (transform_skip_flag || lc->cu.cu_transquant_bypass_flag)) { |
| 1199 | 35234 | explicit_rdpcm_flag = explicit_rdpcm_flag_decode(lc, c_idx); | |
| 1200 |
2/2✓ Branch 0 taken 3090 times.
✓ Branch 1 taken 32144 times.
|
35234 | if (explicit_rdpcm_flag) { |
| 1201 | 3090 | explicit_rdpcm_dir_flag = explicit_rdpcm_dir_flag_decode(lc, c_idx); | |
| 1202 | } | ||
| 1203 | } | ||
| 1204 | |||
| 1205 | 14292077 | last_significant_coeff_xy_prefix_decode(lc, c_idx, log2_trafo_size, | |
| 1206 | &last_significant_coeff_x, &last_significant_coeff_y); | ||
| 1207 | |||
| 1208 |
2/2✓ Branch 0 taken 1874672 times.
✓ Branch 1 taken 12417405 times.
|
14292077 | if (last_significant_coeff_x > 3) { |
| 1209 | 1874672 | int suffix = last_significant_coeff_suffix_decode(lc, last_significant_coeff_x); | |
| 1210 | 1874672 | last_significant_coeff_x = (1 << ((last_significant_coeff_x >> 1) - 1)) * | |
| 1211 | 1874672 | (2 + (last_significant_coeff_x & 1)) + | |
| 1212 | suffix; | ||
| 1213 | } | ||
| 1214 | |||
| 1215 |
2/2✓ Branch 0 taken 1389247 times.
✓ Branch 1 taken 12902830 times.
|
14292077 | if (last_significant_coeff_y > 3) { |
| 1216 | 1389247 | int suffix = last_significant_coeff_suffix_decode(lc, last_significant_coeff_y); | |
| 1217 | 1389247 | last_significant_coeff_y = (1 << ((last_significant_coeff_y >> 1) - 1)) * | |
| 1218 | 1389247 | (2 + (last_significant_coeff_y & 1)) + | |
| 1219 | suffix; | ||
| 1220 | } | ||
| 1221 | |||
| 1222 |
2/2✓ Branch 0 taken 1518530 times.
✓ Branch 1 taken 12773547 times.
|
14292077 | if (scan_idx == SCAN_VERT) |
| 1223 | 1518530 | FFSWAP(int, last_significant_coeff_x, last_significant_coeff_y); | |
| 1224 | |||
| 1225 | 14292077 | x_cg_last_sig = last_significant_coeff_x >> 2; | |
| 1226 | 14292077 | y_cg_last_sig = last_significant_coeff_y >> 2; | |
| 1227 | |||
| 1228 |
3/3✓ Branch 0 taken 10951954 times.
✓ Branch 1 taken 1821593 times.
✓ Branch 2 taken 1518530 times.
|
14292077 | switch (scan_idx) { |
| 1229 | 10951954 | case SCAN_DIAG: { | |
| 1230 | 10951954 | int last_x_c = last_significant_coeff_x & 3; | |
| 1231 | 10951954 | int last_y_c = last_significant_coeff_y & 3; | |
| 1232 | |||
| 1233 | 10951954 | scan_x_off = ff_hevc_diag_scan4x4_x; | |
| 1234 | 10951954 | scan_y_off = ff_hevc_diag_scan4x4_y; | |
| 1235 | 10951954 | num_coeff = diag_scan4x4_inv[last_y_c][last_x_c]; | |
| 1236 |
2/2✓ Branch 0 taken 4912954 times.
✓ Branch 1 taken 6039000 times.
|
10951954 | if (trafo_size == 4) { |
| 1237 | 4912954 | scan_x_cg = scan_1x1; | |
| 1238 | 4912954 | scan_y_cg = scan_1x1; | |
| 1239 |
2/2✓ Branch 0 taken 3115300 times.
✓ Branch 1 taken 2923700 times.
|
6039000 | } else if (trafo_size == 8) { |
| 1240 | 3115300 | num_coeff += diag_scan2x2_inv[y_cg_last_sig][x_cg_last_sig] << 4; | |
| 1241 | 3115300 | scan_x_cg = diag_scan2x2_x; | |
| 1242 | 3115300 | scan_y_cg = diag_scan2x2_y; | |
| 1243 |
2/2✓ Branch 0 taken 2119144 times.
✓ Branch 1 taken 804556 times.
|
2923700 | } else if (trafo_size == 16) { |
| 1244 | 2119144 | num_coeff += diag_scan4x4_inv[y_cg_last_sig][x_cg_last_sig] << 4; | |
| 1245 | 2119144 | scan_x_cg = ff_hevc_diag_scan4x4_x; | |
| 1246 | 2119144 | scan_y_cg = ff_hevc_diag_scan4x4_y; | |
| 1247 | } else { // trafo_size == 32 | ||
| 1248 | 804556 | num_coeff += diag_scan8x8_inv[y_cg_last_sig][x_cg_last_sig] << 4; | |
| 1249 | 804556 | scan_x_cg = ff_hevc_diag_scan8x8_x; | |
| 1250 | 804556 | scan_y_cg = ff_hevc_diag_scan8x8_y; | |
| 1251 | } | ||
| 1252 | 10951954 | break; | |
| 1253 | } | ||
| 1254 | 1821593 | case SCAN_HORIZ: | |
| 1255 | 1821593 | scan_x_cg = horiz_scan2x2_x; | |
| 1256 | 1821593 | scan_y_cg = horiz_scan2x2_y; | |
| 1257 | 1821593 | scan_x_off = horiz_scan4x4_x; | |
| 1258 | 1821593 | scan_y_off = horiz_scan4x4_y; | |
| 1259 | 1821593 | num_coeff = horiz_scan8x8_inv[last_significant_coeff_y][last_significant_coeff_x]; | |
| 1260 | 1821593 | break; | |
| 1261 | 1518530 | default: //SCAN_VERT | |
| 1262 | 1518530 | scan_x_cg = horiz_scan2x2_y; | |
| 1263 | 1518530 | scan_y_cg = horiz_scan2x2_x; | |
| 1264 | 1518530 | scan_x_off = horiz_scan4x4_y; | |
| 1265 | 1518530 | scan_y_off = horiz_scan4x4_x; | |
| 1266 | 1518530 | num_coeff = horiz_scan8x8_inv[last_significant_coeff_x][last_significant_coeff_y]; | |
| 1267 | 1518530 | break; | |
| 1268 | } | ||
| 1269 | 14292077 | num_coeff++; | |
| 1270 | 14292077 | num_last_subset = (num_coeff - 1) >> 4; | |
| 1271 | |||
| 1272 | 14292077 | max_xy = FFMAX(last_significant_coeff_x, last_significant_coeff_y); | |
| 1273 | 14292077 | col_limit = last_significant_coeff_x + last_significant_coeff_y + 4; | |
| 1274 |
2/2✓ Branch 0 taken 11758663 times.
✓ Branch 1 taken 2533414 times.
|
14292077 | if (max_xy < 4) |
| 1275 | 11758663 | col_limit = FFMIN(4, col_limit); | |
| 1276 |
2/2✓ Branch 0 taken 1906746 times.
✓ Branch 1 taken 626668 times.
|
2533414 | else if (max_xy < 8) |
| 1277 | 1906746 | col_limit = FFMIN(8, col_limit); | |
| 1278 |
2/2✓ Branch 0 taken 286498 times.
✓ Branch 1 taken 340170 times.
|
626668 | else if (max_xy < 12) |
| 1279 | 286498 | col_limit = FFMIN(24, col_limit); | |
| 1280 | |||
| 1281 | // idct_dc reads coeffs[0] only and writes the whole block: no clear needed | ||
| 1282 | 14292077 | clear_rows = trafo_size; | |
| 1283 |
4/4✓ Branch 0 taken 13867879 times.
✓ Branch 1 taken 424198 times.
✓ Branch 2 taken 13473170 times.
✓ Branch 3 taken 394709 times.
|
14292077 | if (!lc->cu.cu_transquant_bypass_flag && !transform_skip_flag && |
| 1284 |
6/6✓ Branch 0 taken 7874331 times.
✓ Branch 1 taken 5598839 times.
✓ Branch 2 taken 5547621 times.
✓ Branch 3 taken 2326710 times.
✓ Branch 4 taken 2375004 times.
✓ Branch 5 taken 3172617 times.
|
13473170 | !(lc->cu.pred_mode == MODE_INTRA && c_idx == 0 && log2_trafo_size == 2)) { |
| 1285 |
2/2✓ Branch 0 taken 2494503 times.
✓ Branch 1 taken 7806050 times.
|
10300553 | if (max_xy == 0) |
| 1286 | 2494503 | clear_rows = 0; | |
| 1287 | } | ||
| 1288 |
2/2✓ Branch 0 taken 11797574 times.
✓ Branch 1 taken 2494503 times.
|
14292077 | if (clear_rows) |
| 1289 | 11797574 | memset(coeffs, 0, clear_rows * trafo_size * sizeof(int16_t)); | |
| 1290 | |||
| 1291 |
2/2✓ Branch 0 taken 25213532 times.
✓ Branch 1 taken 14292077 times.
|
39505609 | for (i = num_last_subset; i >= 0; i--) { |
| 1292 | int n, m; | ||
| 1293 | int x_cg, y_cg, x_c, y_c, pos; | ||
| 1294 | 25213532 | int implicit_non_zero_coeff = 0; | |
| 1295 | int64_t trans_coeff_level; | ||
| 1296 | 25213532 | int prev_sig = 0; | |
| 1297 | 25213532 | int offset = i << 4; | |
| 1298 | 25213532 | int rice_init = 0; | |
| 1299 | |||
| 1300 | uint8_t significant_coeff_flag_idx[16]; | ||
| 1301 | 25213532 | uint8_t nb_significant_coeff_flag = 0; | |
| 1302 | |||
| 1303 | 25213532 | x_cg = scan_x_cg[i]; | |
| 1304 | 25213532 | y_cg = scan_y_cg[i]; | |
| 1305 | |||
| 1306 |
4/4✓ Branch 0 taken 10921455 times.
✓ Branch 1 taken 14292077 times.
✓ Branch 2 taken 8388041 times.
✓ Branch 3 taken 2533414 times.
|
25213532 | if ((i < num_last_subset) && (i > 0)) { |
| 1307 | 8388041 | int ctx_cg = 0; | |
| 1308 |
2/2✓ Branch 0 taken 7715312 times.
✓ Branch 1 taken 672729 times.
|
8388041 | if (x_cg < (1 << (log2_trafo_size - 2)) - 1) |
| 1309 | 7715312 | ctx_cg += significant_coeff_group_flag[x_cg + 1][y_cg]; | |
| 1310 |
2/2✓ Branch 0 taken 7091738 times.
✓ Branch 1 taken 1296303 times.
|
8388041 | if (y_cg < (1 << (log2_trafo_size - 2)) - 1) |
| 1311 | 7091738 | ctx_cg += significant_coeff_group_flag[x_cg][y_cg + 1]; | |
| 1312 | |||
| 1313 | 8388041 | significant_coeff_group_flag[x_cg][y_cg] = | |
| 1314 | 8388041 | significant_coeff_group_flag_decode(lc, c_idx, ctx_cg); | |
| 1315 | 8388041 | implicit_non_zero_coeff = 1; | |
| 1316 | } else { | ||
| 1317 | 16825491 | significant_coeff_group_flag[x_cg][y_cg] = | |
| 1318 |
5/6✓ Branch 0 taken 15034414 times.
✓ Branch 1 taken 1791077 times.
✓ Branch 2 taken 742337 times.
✓ Branch 3 taken 14292077 times.
✓ Branch 4 taken 2533414 times.
✗ Branch 5 not taken.
|
19358905 | ((x_cg == x_cg_last_sig && y_cg == y_cg_last_sig) || |
| 1319 |
1/2✓ Branch 0 taken 2533414 times.
✗ Branch 1 not taken.
|
2533414 | (x_cg == 0 && y_cg == 0)); |
| 1320 | } | ||
| 1321 | |||
| 1322 | 25213532 | last_scan_pos = num_coeff - offset - 1; | |
| 1323 | |||
| 1324 |
2/2✓ Branch 0 taken 14292077 times.
✓ Branch 1 taken 10921455 times.
|
25213532 | if (i == num_last_subset) { |
| 1325 | 14292077 | n_end = last_scan_pos - 1; | |
| 1326 | 14292077 | significant_coeff_flag_idx[0] = last_scan_pos; | |
| 1327 | 14292077 | nb_significant_coeff_flag = 1; | |
| 1328 | } else { | ||
| 1329 | 10921455 | n_end = 15; | |
| 1330 | } | ||
| 1331 | |||
| 1332 |
2/2✓ Branch 0 taken 16109157 times.
✓ Branch 1 taken 9104375 times.
|
25213532 | if (x_cg < ((1 << log2_trafo_size) - 1) >> 2) |
| 1333 | 16109157 | prev_sig = !!significant_coeff_group_flag[x_cg + 1][y_cg]; | |
| 1334 |
2/2✓ Branch 0 taken 15622754 times.
✓ Branch 1 taken 9590778 times.
|
25213532 | if (y_cg < ((1 << log2_trafo_size) - 1) >> 2) |
| 1335 |
2/2✓ Branch 0 taken 5192854 times.
✓ Branch 1 taken 10429900 times.
|
15622754 | prev_sig += (!!significant_coeff_group_flag[x_cg][y_cg + 1] << 1); |
| 1336 | |||
| 1337 |
4/4✓ Branch 0 taken 21949094 times.
✓ Branch 1 taken 3264438 times.
✓ Branch 2 taken 18469860 times.
✓ Branch 3 taken 3479234 times.
|
25213532 | if (significant_coeff_group_flag[x_cg][y_cg] && n_end >= 0) { |
| 1338 | // ctx_idx_map composed with the intra-CG scan, indexed by scan position | ||
| 1339 | static const uint8_t ctx_idx_map[3][5 * 16] = { | ||
| 1340 | { // SCAN_DIAG | ||
| 1341 | 0, 2, 1, 6, 3, 4, 7, 6, 4, 5, 7, 8, 5, 8, 8, 8, // log2_trafo_size == 2 | ||
| 1342 | 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // prev_sig == 0 | ||
| 1343 | 2, 1, 2, 0, 1, 2, 0, 0, 1, 2, 0, 0, 1, 0, 0, 0, // prev_sig == 1 | ||
| 1344 | 2, 2, 1, 2, 1, 0, 2, 1, 0, 0, 1, 0, 0, 0, 0, 0, // prev_sig == 2 | ||
| 1345 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, // default | ||
| 1346 | }, | ||
| 1347 | { // SCAN_HORIZ | ||
| 1348 | 0, 1, 4, 5, 2, 3, 4, 5, 6, 6, 8, 8, 7, 7, 8, 8, | ||
| 1349 | 1, 1, 1, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, | ||
| 1350 | 2, 2, 2, 2, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 1351 | 2, 1, 0, 0, 2, 1, 0, 0, 2, 1, 0, 0, 2, 1, 0, 0, | ||
| 1352 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | ||
| 1353 | }, | ||
| 1354 | { // SCAN_VERT | ||
| 1355 | 0, 2, 6, 7, 1, 3, 6, 7, 4, 4, 8, 8, 5, 5, 8, 8, | ||
| 1356 | 1, 1, 1, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, | ||
| 1357 | 2, 1, 0, 0, 2, 1, 0, 0, 2, 1, 0, 0, 2, 1, 0, 0, | ||
| 1358 | 2, 2, 2, 2, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 1359 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | ||
| 1360 | }, | ||
| 1361 | }; | ||
| 1362 | const uint8_t *ctx_idx_map_p; | ||
| 1363 | 18469860 | int scf_offset = 0; | |
| 1364 | int nb0; | ||
| 1365 |
4/4✓ Branch 0 taken 687068 times.
✓ Branch 1 taken 17782792 times.
✓ Branch 2 taken 592618 times.
✓ Branch 3 taken 94450 times.
|
18469860 | if (sps->transform_skip_context_enabled && |
| 1366 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 592618 times.
|
592618 | (transform_skip_flag || lc->cu.cu_transquant_bypass_flag)) { |
| 1367 | 94450 | ctx_idx_map_p = &ctx_idx_map[scan_idx][4 * 16]; | |
| 1368 |
2/2✓ Branch 0 taken 41170 times.
✓ Branch 1 taken 53280 times.
|
94450 | if (c_idx == 0) { |
| 1369 | 41170 | scf_offset = 40; | |
| 1370 | } else { | ||
| 1371 | 53280 | scf_offset = 14 + 27; | |
| 1372 | } | ||
| 1373 | } else { | ||
| 1374 |
2/2✓ Branch 0 taken 3811984 times.
✓ Branch 1 taken 14563426 times.
|
18375410 | if (c_idx != 0) |
| 1375 | 3811984 | scf_offset = 27; | |
| 1376 |
2/2✓ Branch 0 taken 5707195 times.
✓ Branch 1 taken 12668215 times.
|
18375410 | if (log2_trafo_size == 2) { |
| 1377 | 5707195 | ctx_idx_map_p = &ctx_idx_map[scan_idx][0]; | |
| 1378 | } else { | ||
| 1379 | 12668215 | ctx_idx_map_p = &ctx_idx_map[scan_idx][(prev_sig + 1) << 4]; | |
| 1380 |
2/2✓ Branch 0 taken 10519355 times.
✓ Branch 1 taken 2148860 times.
|
12668215 | if (c_idx == 0) { |
| 1381 |
4/4✓ Branch 0 taken 6535529 times.
✓ Branch 1 taken 3983826 times.
✓ Branch 2 taken 2124909 times.
✓ Branch 3 taken 4410620 times.
|
10519355 | if ((x_cg > 0 || y_cg > 0)) |
| 1382 | 6108735 | scf_offset += 3; | |
| 1383 |
2/2✓ Branch 0 taken 3841846 times.
✓ Branch 1 taken 6677509 times.
|
10519355 | if (log2_trafo_size == 3) { |
| 1384 |
2/2✓ Branch 0 taken 2838456 times.
✓ Branch 1 taken 1003390 times.
|
3841846 | scf_offset += (scan_idx == SCAN_DIAG) ? 9 : 15; |
| 1385 | } else { | ||
| 1386 | 6677509 | scf_offset += 21; | |
| 1387 | } | ||
| 1388 | } else { | ||
| 1389 |
2/2✓ Branch 0 taken 997654 times.
✓ Branch 1 taken 1151206 times.
|
2148860 | if (log2_trafo_size == 3) |
| 1390 | 997654 | scf_offset += 9; | |
| 1391 | else | ||
| 1392 | 1151206 | scf_offset += 12; | |
| 1393 | } | ||
| 1394 | } | ||
| 1395 | } | ||
| 1396 | // the flag is a fresh bin: store always, advance conditionally | ||
| 1397 | 18469860 | nb0 = nb_significant_coeff_flag; | |
| 1398 |
2/2✓ Branch 0 taken 170100122 times.
✓ Branch 1 taken 18469860 times.
|
188569982 | for (n = n_end; n > 0; n--) { |
| 1399 | 170100122 | int sig = significant_coeff_flag_decode(lc, n, scf_offset, ctx_idx_map_p); | |
| 1400 | 170100122 | significant_coeff_flag_idx[nb_significant_coeff_flag] = n; | |
| 1401 | 170100122 | nb_significant_coeff_flag += sig; | |
| 1402 | } | ||
| 1403 |
2/2✓ Branch 0 taken 14775787 times.
✓ Branch 1 taken 3694073 times.
|
18469860 | if (nb_significant_coeff_flag != nb0) |
| 1404 | 14775787 | implicit_non_zero_coeff = 0; | |
| 1405 |
2/2✓ Branch 0 taken 18388123 times.
✓ Branch 1 taken 81737 times.
|
18469860 | if (implicit_non_zero_coeff == 0) { |
| 1406 |
4/4✓ Branch 0 taken 685361 times.
✓ Branch 1 taken 17702762 times.
✓ Branch 2 taken 591196 times.
✓ Branch 3 taken 94165 times.
|
18388123 | if (sps->transform_skip_context_enabled && |
| 1407 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 591196 times.
|
591196 | (transform_skip_flag || lc->cu.cu_transquant_bypass_flag)) { |
| 1408 |
2/2✓ Branch 0 taken 40977 times.
✓ Branch 1 taken 53188 times.
|
94165 | if (c_idx == 0) { |
| 1409 | 40977 | scf_offset = 42; | |
| 1410 | } else { | ||
| 1411 | 53188 | scf_offset = 16 + 27; | |
| 1412 | } | ||
| 1413 | } else { | ||
| 1414 |
2/2✓ Branch 0 taken 11112348 times.
✓ Branch 1 taken 7181610 times.
|
18293958 | if (i == 0) { |
| 1415 |
2/2✓ Branch 0 taken 8454691 times.
✓ Branch 1 taken 2657657 times.
|
11112348 | if (c_idx == 0) |
| 1416 | 8454691 | scf_offset = 0; | |
| 1417 | else | ||
| 1418 | 2657657 | scf_offset = 27; | |
| 1419 | } else { | ||
| 1420 | 7181610 | scf_offset = 2 + scf_offset; | |
| 1421 | } | ||
| 1422 | } | ||
| 1423 | 18388123 | significant_coeff_flag_idx[nb_significant_coeff_flag] = 0; | |
| 1424 | 18388123 | nb_significant_coeff_flag += | |
| 1425 | 18388123 | significant_coeff_flag_decode_0(lc, c_idx, scf_offset); | |
| 1426 | } else { | ||
| 1427 | 81737 | significant_coeff_flag_idx[nb_significant_coeff_flag] = 0; | |
| 1428 | 81737 | nb_significant_coeff_flag++; | |
| 1429 | } | ||
| 1430 | } | ||
| 1431 | |||
| 1432 | 25213532 | n_end = nb_significant_coeff_flag; | |
| 1433 | |||
| 1434 | |||
| 1435 |
2/2✓ Branch 0 taken 21795729 times.
✓ Branch 1 taken 3417803 times.
|
25213532 | if (n_end) { |
| 1436 | int first_nz_pos_in_cg; | ||
| 1437 | int last_nz_pos_in_cg; | ||
| 1438 | 21795729 | int c_rice_param = 0; | |
| 1439 | 21795729 | int first_greater1_coeff_idx = -1; | |
| 1440 | uint8_t coeff_abs_level_greater1_flag[8]; | ||
| 1441 | uint16_t coeff_sign_flag; | ||
| 1442 | 21795729 | int sum_abs = 0; | |
| 1443 | int sign_hidden; | ||
| 1444 | int sb_type; | ||
| 1445 | 21795729 | int gt1_mask = 0; | |
| 1446 | |||
| 1447 | |||
| 1448 | // initialize first elem of coeff_bas_level_greater1_flag | ||
| 1449 |
4/4✓ Branch 0 taken 7657017 times.
✓ Branch 1 taken 14138712 times.
✓ Branch 2 taken 6434212 times.
✓ Branch 3 taken 1222805 times.
|
21795729 | int ctx_set = (i > 0 && c_idx == 0) ? 2 : 0; |
| 1450 | |||
| 1451 |
2/2✓ Branch 0 taken 769625 times.
✓ Branch 1 taken 21026104 times.
|
21795729 | if (sps->persistent_rice_adaptation_enabled) { |
| 1452 |
3/4✓ Branch 0 taken 685062 times.
✓ Branch 1 taken 84563 times.
✓ Branch 2 taken 685062 times.
✗ Branch 3 not taken.
|
769625 | if (!transform_skip_flag && !lc->cu.cu_transquant_bypass_flag) |
| 1453 |
2/2✓ Branch 0 taken 224053 times.
✓ Branch 1 taken 461009 times.
|
685062 | sb_type = 2 * (c_idx == 0 ? 1 : 0); |
| 1454 | else | ||
| 1455 |
2/2✓ Branch 0 taken 36677 times.
✓ Branch 1 taken 47886 times.
|
84563 | sb_type = 2 * (c_idx == 0 ? 1 : 0) + 1; |
| 1456 | 769625 | c_rice_param = lc->sub.stat_coeff[sb_type] / 4; | |
| 1457 | } | ||
| 1458 | |||
| 1459 |
4/4✓ Branch 0 taken 7503652 times.
✓ Branch 1 taken 14292077 times.
✓ Branch 2 taken 3068573 times.
✓ Branch 3 taken 4435079 times.
|
21795729 | if (!(i == num_last_subset) && greater1_ctx == 0) |
| 1460 | 3068573 | ctx_set++; | |
| 1461 | 21795729 | greater1_ctx = 1; | |
| 1462 | 21795729 | last_nz_pos_in_cg = significant_coeff_flag_idx[0]; | |
| 1463 | |||
| 1464 | // fresh bins: branchless context update, first set index from the mask | ||
| 1465 |
2/2✓ Branch 0 taken 86527310 times.
✓ Branch 1 taken 21795729 times.
|
108323039 | for (m = 0; m < (n_end > 8 ? 8 : n_end); m++) { |
| 1466 | 86527310 | int inc = (ctx_set << 2) + greater1_ctx; | |
| 1467 | 86527310 | int flag = coeff_abs_level_greater1_flag_decode(lc, c_idx, inc); | |
| 1468 | 86527310 | coeff_abs_level_greater1_flag[m] = flag; | |
| 1469 | 86527310 | gt1_mask |= flag << m; | |
| 1470 | 86527310 | greater1_ctx = (greater1_ctx + (greater1_ctx - 1U < 2)) & (flag - 1); | |
| 1471 | } | ||
| 1472 |
2/2✓ Branch 0 taken 9392252 times.
✓ Branch 1 taken 12403477 times.
|
21795729 | if (gt1_mask) |
| 1473 | 9392252 | first_greater1_coeff_idx = ff_ctz(gt1_mask); | |
| 1474 | 21795729 | first_nz_pos_in_cg = significant_coeff_flag_idx[n_end - 1]; | |
| 1475 | |||
| 1476 |
2/2✓ Branch 0 taken 21076787 times.
✓ Branch 1 taken 718942 times.
|
21795729 | if (lc->cu.cu_transquant_bypass_flag || |
| 1477 |
2/2✓ Branch 0 taken 11508246 times.
✓ Branch 1 taken 9568541 times.
|
21076787 | (lc->cu.pred_mode == MODE_INTRA && |
| 1478 |
6/6✓ Branch 0 taken 505772 times.
✓ Branch 1 taken 11002474 times.
✓ Branch 2 taken 57405 times.
✓ Branch 3 taken 448367 times.
✓ Branch 4 taken 29611 times.
✓ Branch 5 taken 27794 times.
|
11508246 | sps->implicit_rdpcm_enabled && transform_skip_flag && |
| 1479 |
4/4✓ Branch 0 taken 16913 times.
✓ Branch 1 taken 12698 times.
✓ Branch 2 taken 5999 times.
✓ Branch 3 taken 21030296 times.
|
21048993 | (pred_mode_intra == 10 || pred_mode_intra == 26 )) || |
| 1480 | explicit_rdpcm_flag) | ||
| 1481 | 765433 | sign_hidden = 0; | |
| 1482 | else | ||
| 1483 | 21030296 | sign_hidden = (last_nz_pos_in_cg - first_nz_pos_in_cg >= 4); | |
| 1484 | |||
| 1485 |
2/2✓ Branch 0 taken 9392252 times.
✓ Branch 1 taken 12403477 times.
|
21795729 | if (first_greater1_coeff_idx != -1) { |
| 1486 | 9392252 | coeff_abs_level_greater1_flag[first_greater1_coeff_idx] += coeff_abs_level_greater2_flag_decode(lc, c_idx, ctx_set); | |
| 1487 | } | ||
| 1488 |
4/4✓ Branch 0 taken 17530408 times.
✓ Branch 1 taken 4265321 times.
✓ Branch 2 taken 7807211 times.
✓ Branch 3 taken 9723197 times.
|
21795729 | if (!pps->sign_data_hiding_flag || !sign_hidden ) { |
| 1489 | 12072532 | coeff_sign_flag = coeff_sign_flag_decode(lc, nb_significant_coeff_flag) << (16 - nb_significant_coeff_flag); | |
| 1490 | } else { | ||
| 1491 | 9723197 | coeff_sign_flag = coeff_sign_flag_decode(lc, nb_significant_coeff_flag - 1) << (16 - (nb_significant_coeff_flag - 1)); | |
| 1492 | } | ||
| 1493 | |||
| 1494 |
2/2✓ Branch 0 taken 102555549 times.
✓ Branch 1 taken 21795729 times.
|
124351278 | for (m = 0; m < n_end; m++) { |
| 1495 | int64_t sign; | ||
| 1496 | |||
| 1497 | 102555549 | n = significant_coeff_flag_idx[m]; | |
| 1498 | 102555549 | GET_COORD(offset, n); | |
| 1499 |
2/2✓ Branch 0 taken 86527310 times.
✓ Branch 1 taken 16028239 times.
|
102555549 | if (m < 8) { |
| 1500 | 86527310 | trans_coeff_level = 1 + coeff_abs_level_greater1_flag[m]; | |
| 1501 |
4/4✓ Branch 0 taken 9392252 times.
✓ Branch 1 taken 77135058 times.
✓ Branch 2 taken 20877997 times.
✓ Branch 3 taken 65649313 times.
|
86527310 | if (trans_coeff_level == ((m == first_greater1_coeff_idx) ? 3 : 2)) { |
| 1502 | 20877997 | int last_coeff_abs_level_remaining = coeff_abs_level_remaining_decode(lc, c_rice_param); | |
| 1503 | |||
| 1504 | 20877997 | trans_coeff_level += last_coeff_abs_level_remaining; | |
| 1505 |
2/2✓ Branch 0 taken 5279936 times.
✓ Branch 1 taken 15598061 times.
|
20877997 | if (trans_coeff_level > (3 << c_rice_param)) |
| 1506 |
2/2✓ Branch 0 taken 107884 times.
✓ Branch 1 taken 5172052 times.
|
5279936 | c_rice_param = sps->persistent_rice_adaptation_enabled ? c_rice_param + 1 : FFMIN(c_rice_param + 1, 4); |
| 1507 |
4/4✓ Branch 0 taken 601790 times.
✓ Branch 1 taken 20276207 times.
✓ Branch 2 taken 182004 times.
✓ Branch 3 taken 419786 times.
|
20877997 | if (sps->persistent_rice_adaptation_enabled && !rice_init) { |
| 1508 | 182004 | int c_rice_p_init = lc->sub.stat_coeff[sb_type] / 4; | |
| 1509 |
2/2✓ Branch 0 taken 20309 times.
✓ Branch 1 taken 161695 times.
|
182004 | if (last_coeff_abs_level_remaining >= (3 << c_rice_p_init)) |
| 1510 | 20309 | lc->sub.stat_coeff[sb_type]++; | |
| 1511 |
2/2✓ Branch 0 taken 93774 times.
✓ Branch 1 taken 67921 times.
|
161695 | else if (2 * last_coeff_abs_level_remaining < (1 << c_rice_p_init)) |
| 1512 |
2/2✓ Branch 0 taken 20285 times.
✓ Branch 1 taken 73489 times.
|
93774 | if (lc->sub.stat_coeff[sb_type] > 0) |
| 1513 | 20285 | lc->sub.stat_coeff[sb_type]--; | |
| 1514 | 182004 | rice_init = 1; | |
| 1515 | } | ||
| 1516 | } | ||
| 1517 | } else { | ||
| 1518 | 16028239 | int last_coeff_abs_level_remaining = coeff_abs_level_remaining_decode(lc, c_rice_param); | |
| 1519 | |||
| 1520 | 16028239 | trans_coeff_level = 1 + last_coeff_abs_level_remaining; | |
| 1521 |
2/2✓ Branch 0 taken 1830306 times.
✓ Branch 1 taken 14197933 times.
|
16028239 | if (trans_coeff_level > (3 << c_rice_param)) |
| 1522 |
2/2✓ Branch 0 taken 47948 times.
✓ Branch 1 taken 1782358 times.
|
1830306 | c_rice_param = sps->persistent_rice_adaptation_enabled ? c_rice_param + 1 : FFMIN(c_rice_param + 1, 4); |
| 1523 |
4/4✓ Branch 0 taken 495525 times.
✓ Branch 1 taken 15532714 times.
✓ Branch 2 taken 22670 times.
✓ Branch 3 taken 472855 times.
|
16028239 | if (sps->persistent_rice_adaptation_enabled && !rice_init) { |
| 1524 | 22670 | int c_rice_p_init = lc->sub.stat_coeff[sb_type] / 4; | |
| 1525 |
2/2✓ Branch 0 taken 785 times.
✓ Branch 1 taken 21885 times.
|
22670 | if (last_coeff_abs_level_remaining >= (3 << c_rice_p_init)) |
| 1526 | 785 | lc->sub.stat_coeff[sb_type]++; | |
| 1527 |
2/2✓ Branch 0 taken 15387 times.
✓ Branch 1 taken 6498 times.
|
21885 | else if (2 * last_coeff_abs_level_remaining < (1 << c_rice_p_init)) |
| 1528 |
2/2✓ Branch 0 taken 744 times.
✓ Branch 1 taken 14643 times.
|
15387 | if (lc->sub.stat_coeff[sb_type] > 0) |
| 1529 | 744 | lc->sub.stat_coeff[sb_type]--; | |
| 1530 | 22670 | rice_init = 1; | |
| 1531 | } | ||
| 1532 | } | ||
| 1533 |
4/4✓ Branch 0 taken 90778824 times.
✓ Branch 1 taken 11776725 times.
✓ Branch 2 taken 69870578 times.
✓ Branch 3 taken 20908246 times.
|
102555549 | if (pps->sign_data_hiding_flag && sign_hidden) { |
| 1534 | 69870578 | sum_abs += trans_coeff_level; | |
| 1535 |
4/4✓ Branch 0 taken 9723197 times.
✓ Branch 1 taken 60147381 times.
✓ Branch 2 taken 4844031 times.
✓ Branch 3 taken 4879166 times.
|
69870578 | if (n == first_nz_pos_in_cg && (sum_abs&1)) |
| 1536 | 4844031 | trans_coeff_level = -trans_coeff_level; | |
| 1537 | } | ||
| 1538 | // equiprobable sign: apply it branchless | ||
| 1539 | 102555549 | sign = -(int64_t)(coeff_sign_flag >> 15); | |
| 1540 | 102555549 | trans_coeff_level = (trans_coeff_level ^ sign) - sign; | |
| 1541 | 102555549 | coeff_sign_flag <<= 1; | |
| 1542 |
2/2✓ Branch 0 taken 93728166 times.
✓ Branch 1 taken 8827383 times.
|
102555549 | if(!lc->cu.cu_transquant_bypass_flag) { |
| 1543 |
6/6✓ Branch 0 taken 3256495 times.
✓ Branch 1 taken 90471671 times.
✓ Branch 2 taken 124715 times.
✓ Branch 3 taken 3131780 times.
✓ Branch 4 taken 25373 times.
✓ Branch 5 taken 99342 times.
|
93728166 | if (sps->scaling_list_enabled && !(transform_skip_flag && log2_trafo_size > 2)) { |
| 1544 |
6/6✓ Branch 0 taken 1014069 times.
✓ Branch 1 taken 2143084 times.
✓ Branch 2 taken 456467 times.
✓ Branch 3 taken 557602 times.
✓ Branch 4 taken 372832 times.
✓ Branch 5 taken 83635 times.
|
3157153 | if(y_c || x_c || log2_trafo_size < 4) { |
| 1545 |
4/4✓ Branch 0 taken 731538 times.
✓ Branch 1 taken 926236 times.
✓ Branch 2 taken 413079 times.
✓ Branch 3 taken 1002665 times.
|
3073518 | switch(log2_trafo_size) { |
| 1546 | 731538 | case 3: pos = (y_c << 3) + x_c; break; | |
| 1547 | 926236 | case 4: pos = ((y_c >> 1) << 3) + (x_c >> 1); break; | |
| 1548 | 413079 | case 5: pos = ((y_c >> 2) << 3) + (x_c >> 2); break; | |
| 1549 | 1002665 | default: pos = (y_c << 2) + x_c; break; | |
| 1550 | } | ||
| 1551 | 3073518 | scale_m = scale_matrix[pos]; | |
| 1552 | } else { | ||
| 1553 | 83635 | scale_m = dc_scale; | |
| 1554 | } | ||
| 1555 | } | ||
| 1556 | 93728166 | trans_coeff_level = (trans_coeff_level * (int64_t)scale * (int64_t)scale_m + add) >> shift; | |
| 1557 | 93728166 | trans_coeff_level = FFMAX(FFMIN(trans_coeff_level, 32767), -32768); | |
| 1558 | } | ||
| 1559 | 102555549 | coeffs[y_c * trafo_size + x_c] = trans_coeff_level; | |
| 1560 | } | ||
| 1561 | } | ||
| 1562 | } | ||
| 1563 | |||
| 1564 |
2/2✓ Branch 0 taken 424198 times.
✓ Branch 1 taken 13867879 times.
|
14292077 | if (lc->cu.cu_transquant_bypass_flag) { |
| 1565 |
2/6✓ Branch 0 taken 424198 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 424198 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
424198 | if (explicit_rdpcm_flag || (sps->implicit_rdpcm_enabled && |
| 1566 | ✗ | (pred_mode_intra == 10 || pred_mode_intra == 26))) { | |
| 1567 | ✗ | int mode = sps->implicit_rdpcm_enabled ? (pred_mode_intra == 26) : explicit_rdpcm_dir_flag; | |
| 1568 | |||
| 1569 | ✗ | s->hevcdsp.transform_rdpcm(coeffs, log2_trafo_size, mode); | |
| 1570 | } | ||
| 1571 | } else { | ||
| 1572 |
2/2✓ Branch 0 taken 394709 times.
✓ Branch 1 taken 13473170 times.
|
13867879 | if (transform_skip_flag) { |
| 1573 |
2/2✓ Branch 0 taken 45633 times.
✓ Branch 1 taken 14213 times.
|
59846 | int rot = sps->transform_skip_rotation_enabled && |
| 1574 |
2/2✓ Branch 0 taken 59846 times.
✓ Branch 1 taken 334863 times.
|
454555 | log2_trafo_size == 2 && |
| 1575 |
2/2✓ Branch 0 taken 11850 times.
✓ Branch 1 taken 33783 times.
|
45633 | lc->cu.pred_mode == MODE_INTRA; |
| 1576 |
2/2✓ Branch 0 taken 11850 times.
✓ Branch 1 taken 382859 times.
|
394709 | if (rot) { |
| 1577 |
2/2✓ Branch 0 taken 94800 times.
✓ Branch 1 taken 11850 times.
|
106650 | for (i = 0; i < 8; i++) |
| 1578 | 94800 | FFSWAP(int16_t, coeffs[i], coeffs[16 - i - 1]); | |
| 1579 | } | ||
| 1580 | |||
| 1581 | 394709 | s->hevcdsp.dequant(coeffs, log2_trafo_size); | |
| 1582 | |||
| 1583 |
4/4✓ Branch 0 taken 391619 times.
✓ Branch 1 taken 3090 times.
✓ Branch 2 taken 56756 times.
✓ Branch 3 taken 334863 times.
|
394709 | if (explicit_rdpcm_flag || (sps->implicit_rdpcm_enabled && |
| 1584 |
4/4✓ Branch 0 taken 24612 times.
✓ Branch 1 taken 32144 times.
✓ Branch 2 taken 15060 times.
✓ Branch 3 taken 9552 times.
|
56756 | lc->cu.pred_mode == MODE_INTRA && |
| 1585 |
2/2✓ Branch 0 taken 5302 times.
✓ Branch 1 taken 9758 times.
|
15060 | (pred_mode_intra == 10 || pred_mode_intra == 26))) { |
| 1586 |
2/2✓ Branch 0 taken 14854 times.
✓ Branch 1 taken 3090 times.
|
17944 | int mode = explicit_rdpcm_flag ? explicit_rdpcm_dir_flag : (pred_mode_intra == 26); |
| 1587 | |||
| 1588 | 17944 | s->hevcdsp.transform_rdpcm(coeffs, log2_trafo_size, mode); | |
| 1589 | } | ||
| 1590 |
6/6✓ Branch 0 taken 7874331 times.
✓ Branch 1 taken 5598839 times.
✓ Branch 2 taken 5547621 times.
✓ Branch 3 taken 2326710 times.
✓ Branch 4 taken 3172617 times.
✓ Branch 5 taken 2375004 times.
|
13473170 | } else if (lc->cu.pred_mode == MODE_INTRA && c_idx == 0 && log2_trafo_size == 2) { |
| 1591 | 3172617 | s->hevcdsp.transform_4x4_luma(coeffs); | |
| 1592 | } else { | ||
| 1593 |
2/2✓ Branch 0 taken 2494503 times.
✓ Branch 1 taken 7806050 times.
|
10300553 | if (max_xy == 0) |
| 1594 | 2494503 | s->hevcdsp.idct_dc[log2_trafo_size - 2](coeffs); | |
| 1595 | else | ||
| 1596 | 7806050 | s->hevcdsp.idct[log2_trafo_size - 2](coeffs, col_limit); | |
| 1597 | } | ||
| 1598 | } | ||
| 1599 |
2/2✓ Branch 0 taken 171429 times.
✓ Branch 1 taken 14120648 times.
|
14292077 | if (lc->tu.cross_pf) { |
| 1600 | 171429 | int16_t *coeffs_y = (int16_t*)lc->edge_emu_buffer; | |
| 1601 | |||
| 1602 |
2/2✓ Branch 0 taken 13540080 times.
✓ Branch 1 taken 171429 times.
|
13711509 | for (i = 0; i < (trafo_size * trafo_size); i++) { |
| 1603 | 13540080 | coeffs[i] = coeffs[i] + ((lc->tu.res_scale_val * coeffs_y[i]) >> 3); | |
| 1604 | } | ||
| 1605 | } | ||
| 1606 | 14292077 | s->hevcdsp.add_residual[log2_trafo_size-2](dst, coeffs, stride); | |
| 1607 | 14292077 | } | |
| 1608 | |||
| 1609 | 3379222 | void ff_hevc_hls_mvd_coding(HEVCLocalContext *lc, int x0, int y0, int log2_cb_size) | |
| 1610 | { | ||
| 1611 | 3379222 | int x = abs_mvd_greater0_flag_decode(lc); | |
| 1612 | 3379222 | int y = abs_mvd_greater0_flag_decode(lc); | |
| 1613 | |||
| 1614 |
2/2✓ Branch 0 taken 2318663 times.
✓ Branch 1 taken 1060559 times.
|
3379222 | if (x) |
| 1615 | 2318663 | x += abs_mvd_greater1_flag_decode(lc); | |
| 1616 |
2/2✓ Branch 0 taken 2223909 times.
✓ Branch 1 taken 1155313 times.
|
3379222 | if (y) |
| 1617 | 2223909 | y += abs_mvd_greater1_flag_decode(lc); | |
| 1618 | |||
| 1619 |
3/4✓ Branch 0 taken 1611612 times.
✓ Branch 1 taken 707051 times.
✓ Branch 2 taken 1060559 times.
✗ Branch 3 not taken.
|
3379222 | switch (x) { |
| 1620 | 1611612 | case 2: lc->pu.mvd.x = mvd_decode(lc); break; | |
| 1621 | 707051 | case 1: lc->pu.mvd.x = mvd_sign_flag_decode(lc); break; | |
| 1622 | 1060559 | case 0: lc->pu.mvd.x = 0; break; | |
| 1623 | } | ||
| 1624 | |||
| 1625 |
3/4✓ Branch 0 taken 1501080 times.
✓ Branch 1 taken 722829 times.
✓ Branch 2 taken 1155313 times.
✗ Branch 3 not taken.
|
3379222 | switch (y) { |
| 1626 | 1501080 | case 2: lc->pu.mvd.y = mvd_decode(lc); break; | |
| 1627 | 722829 | case 1: lc->pu.mvd.y = mvd_sign_flag_decode(lc); break; | |
| 1628 | 1155313 | case 0: lc->pu.mvd.y = 0; break; | |
| 1629 | } | ||
| 1630 | 3379222 | } | |
| 1631 |