FFmpeg
cabac.c
Go to the documentation of this file.
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 "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,
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 
403  int ctb_addr_ts)
404 {
405  const HEVCSPS *const sps = pps->sps;
406  if (pps->entropy_coding_sync_enabled_flag &&
407  (ctb_addr_ts % sps->ctb_width == 2 ||
408  (sps->ctb_width == 2 &&
409  ctb_addr_ts % sps->ctb_width == 0))) {
411  if (sps->persistent_rice_adaptation_enabled) {
413  }
414  }
415 }
416 
417 static void load_states(HEVCLocalContext *lc, const HEVCSPS *sps)
418 {
420  if (sps->persistent_rice_adaptation_enabled) {
422  }
423 }
424 
426 {
427  return skip_bytes(&lc->cc, 0) == NULL ? AVERROR_INVALIDDATA : 0;
428 }
429 
431 {
432  int init_type = 2 - s->sh.slice_type;
433  int i;
434 
435  if (s->sh.cabac_init_flag && s->sh.slice_type != HEVC_SLICE_I)
436  init_type ^= 3;
437 
438  for (i = 0; i < HEVC_CONTEXTS; i++) {
439  int init_value = init_values[init_type][i];
440  int m = (init_value >> 4) * 5 - 45;
441  int n = ((init_value & 15) << 3) - 16;
442  int pre = 2 * (((m * av_clip(s->sh.slice_qp, 0, 51)) >> 4) + n) - 127;
443 
444  pre ^= pre >> 31;
445  if (pre > 124)
446  pre = 124 + (pre & 1);
447  lc->cabac_state[i] = pre;
448  }
449 
450  for (i = 0; i < 4; i++)
451  lc->stat_coeff[i] = 0;
452 }
453 
455  int ctb_addr_ts, const uint8_t *data, size_t size,
456  int is_wpp)
457 {
458  const HEVCContext *const s = lc->parent;
459  const HEVCSPS *const sps = pps->sps;
460 
461  if (ctb_addr_ts == pps->ctb_addr_rs_to_ts[s->sh.slice_ctb_addr_rs]) {
462  int ret = ff_init_cabac_decoder(&lc->cc, data, size);
463  if (ret < 0)
464  return ret;
465  if (s->sh.dependent_slice_segment_flag == 0 ||
466  (pps->tiles_enabled_flag &&
467  pps->tile_id[ctb_addr_ts] != pps->tile_id[ctb_addr_ts - 1]))
468  cabac_init_state(lc, s);
469 
470  if (!s->sh.first_slice_in_pic_flag &&
471  pps->entropy_coding_sync_enabled_flag) {
472  if (ctb_addr_ts % sps->ctb_width == 0) {
473  if (sps->ctb_width == 1)
474  cabac_init_state(lc, s);
475  else if (s->sh.dependent_slice_segment_flag == 1)
476  load_states(lc, sps);
477  }
478  }
479  } else {
480  if (pps->tiles_enabled_flag &&
481  pps->tile_id[ctb_addr_ts] != pps->tile_id[ctb_addr_ts - 1]) {
482  int ret;
483  if (!is_wpp)
484  ret = cabac_reinit(lc);
485  else {
487  }
488  if (ret < 0)
489  return ret;
490  cabac_init_state(lc, s);
491  }
492  if (pps->entropy_coding_sync_enabled_flag) {
493  if (ctb_addr_ts % sps->ctb_width == 0) {
494  int ret;
495  get_cabac_terminate(&lc->cc);
496  if (!is_wpp)
497  ret = cabac_reinit(lc);
498  else {
500  }
501  if (ret < 0)
502  return ret;
503 
504  if (sps->ctb_width == 1)
505  cabac_init_state(lc, s);
506  else
507  load_states(lc, sps);
508  }
509  }
510  }
511  return 0;
512 }
513 
514 #define GET_CABAC(ctx) get_cabac(&lc->cc, &lc->cabac_state[ctx])
515 
517 {
518  return GET_CABAC(SAO_MERGE_FLAG_OFFSET);
519 }
520 
522 {
523  if (!GET_CABAC(SAO_TYPE_IDX_OFFSET))
524  return 0;
525 
526  if (!get_cabac_bypass(&lc->cc))
527  return SAO_BAND;
528  return SAO_EDGE;
529 }
530 
532 {
533  int i;
534  int value = get_cabac_bypass(&lc->cc);
535 
536  for (i = 0; i < 4; i++)
537  value = (value << 1) | get_cabac_bypass(&lc->cc);
538  return value;
539 }
540 
542 {
543  int i = 0;
544  int length = (1 << (FFMIN(bit_depth, 10) - 5)) - 1;
545 
546  while (i < length && get_cabac_bypass(&lc->cc))
547  i++;
548  return i;
549 }
550 
552 {
553  return get_cabac_bypass(&lc->cc);
554 }
555 
557 {
558  int ret = get_cabac_bypass(&lc->cc) << 1;
559  ret |= get_cabac_bypass(&lc->cc);
560  return ret;
561 }
562 
564 {
565  return get_cabac_terminate(&lc->cc);
566 }
567 
569 {
570  return GET_CABAC(CU_TRANSQUANT_BYPASS_FLAG_OFFSET);
571 }
572 
574  int x_cb, int y_cb, int min_cb_width)
575 {
576  const HEVCContext *const s = lc->parent;
577  int inc = 0;
578 
579  if (lc->ctb_left_flag || x0)
580  inc = !!SAMPLE_CTB(s->skip_flag, x_cb - 1, y_cb);
581  if (lc->ctb_up_flag || y0)
582  inc += !!SAMPLE_CTB(s->skip_flag, x_cb, y_cb - 1);
583 
584  return GET_CABAC(SKIP_FLAG_OFFSET + inc);
585 }
586 
588 {
589  int prefix_val = 0;
590  int suffix_val = 0;
591  int inc = 0;
592 
593  while (prefix_val < 5 && GET_CABAC(CU_QP_DELTA_OFFSET + inc)) {
594  prefix_val++;
595  inc = 1;
596  }
597  if (prefix_val >= 5) {
598  int k = 0;
599  while (k < 7 && get_cabac_bypass(&lc->cc)) {
600  suffix_val += 1 << k;
601  k++;
602  }
603  if (k == 7) {
604  av_log(lc->logctx, AV_LOG_ERROR, "CABAC_MAX_BIN : %d\n", k);
605  return AVERROR_INVALIDDATA;
606  }
607 
608  while (k--)
609  suffix_val += get_cabac_bypass(&lc->cc) << k;
610  }
611  return prefix_val + suffix_val;
612 }
613 
615 {
616  return get_cabac_bypass(&lc->cc);
617 }
618 
620 {
621  return GET_CABAC(CU_CHROMA_QP_OFFSET_FLAG_OFFSET);
622 }
623 
624 int ff_hevc_cu_chroma_qp_offset_idx(HEVCLocalContext *lc, int chroma_qp_offset_list_len_minus1)
625 {
626  int c_max= FFMAX(5, chroma_qp_offset_list_len_minus1);
627  int i = 0;
628 
629  while (i < c_max && GET_CABAC(CU_CHROMA_QP_OFFSET_IDX_OFFSET))
630  i++;
631 
632  return i;
633 }
634 
636 {
637  return GET_CABAC(PRED_MODE_FLAG_OFFSET);
638 }
639 
641  int ct_depth, int x0, int y0)
642 {
643  const HEVCContext *const s = lc->parent;
644  int inc = 0, depth_left = 0, depth_top = 0;
645  int x0b = av_zero_extend(x0, sps->log2_ctb_size);
646  int y0b = av_zero_extend(y0, sps->log2_ctb_size);
647  int x_cb = x0 >> sps->log2_min_cb_size;
648  int y_cb = y0 >> sps->log2_min_cb_size;
649 
650  if (lc->ctb_left_flag || x0b)
651  depth_left = s->tab_ct_depth[(y_cb) * sps->min_cb_width + x_cb - 1];
652  if (lc->ctb_up_flag || y0b)
653  depth_top = s->tab_ct_depth[(y_cb - 1) * sps->min_cb_width + x_cb];
654 
655  inc += (depth_left > ct_depth);
656  inc += (depth_top > ct_depth);
657 
658  return GET_CABAC(SPLIT_CODING_UNIT_FLAG_OFFSET + inc);
659 }
660 
661 int ff_hevc_part_mode_decode(HEVCLocalContext *lc, const HEVCSPS *sps, int log2_cb_size)
662 {
663  if (GET_CABAC(PART_MODE_OFFSET)) // 1
664  return PART_2Nx2N;
665  if (log2_cb_size == sps->log2_min_cb_size) {
666  if (lc->cu.pred_mode == MODE_INTRA) // 0
667  return PART_NxN;
668  if (GET_CABAC(PART_MODE_OFFSET + 1)) // 01
669  return PART_2NxN;
670  if (log2_cb_size == 3) // 00
671  return PART_Nx2N;
672  if (GET_CABAC(PART_MODE_OFFSET + 2)) // 001
673  return PART_Nx2N;
674  return PART_NxN; // 000
675  }
676 
677  if (!sps->amp_enabled) {
678  if (GET_CABAC(PART_MODE_OFFSET + 1)) // 01
679  return PART_2NxN;
680  return PART_Nx2N;
681  }
682 
683  if (GET_CABAC(PART_MODE_OFFSET + 1)) { // 01X, 01XX
684  if (GET_CABAC(PART_MODE_OFFSET + 3)) // 011
685  return PART_2NxN;
686  if (get_cabac_bypass(&lc->cc)) // 0101
687  return PART_2NxnD;
688  return PART_2NxnU; // 0100
689  }
690 
691  if (GET_CABAC(PART_MODE_OFFSET + 3)) // 001
692  return PART_Nx2N;
693  if (get_cabac_bypass(&lc->cc)) // 0001
694  return PART_nRx2N;
695  return PART_nLx2N; // 0000
696 }
697 
699 {
700  return get_cabac_terminate(&lc->cc);
701 }
702 
704 {
705  return GET_CABAC(PREV_INTRA_LUMA_PRED_FLAG_OFFSET);
706 }
707 
709 {
710  int i = 0;
711  while (i < 2 && get_cabac_bypass(&lc->cc))
712  i++;
713  return i;
714 }
715 
717 {
718  int i;
719  int value = get_cabac_bypass(&lc->cc);
720 
721  for (i = 0; i < 4; i++)
722  value = (value << 1) | get_cabac_bypass(&lc->cc);
723  return value;
724 }
725 
727 {
728  int ret;
729  if (!GET_CABAC(INTRA_CHROMA_PRED_MODE_OFFSET))
730  return 4;
731 
732  ret = get_cabac_bypass(&lc->cc) << 1;
733  ret |= get_cabac_bypass(&lc->cc);
734  return ret;
735 }
736 
738 {
739  int i = GET_CABAC(MERGE_IDX_OFFSET);
740 
741  if (i != 0) {
742  while (i < lc->parent->sh.max_num_merge_cand-1 && get_cabac_bypass(&lc->cc))
743  i++;
744  }
745  return i;
746 }
747 
749 {
750  return GET_CABAC(MERGE_FLAG_OFFSET);
751 }
752 
754 {
755  if (nPbW + nPbH == 12)
756  return GET_CABAC(INTER_PRED_IDC_OFFSET + 4);
757  if (GET_CABAC(INTER_PRED_IDC_OFFSET + lc->ct_depth))
758  return PRED_BI;
759 
760  return GET_CABAC(INTER_PRED_IDC_OFFSET + 4);
761 }
762 
763 int ff_hevc_ref_idx_lx_decode(HEVCLocalContext *lc, int num_ref_idx_lx)
764 {
765  int i = 0;
766  int max = num_ref_idx_lx - 1;
767  int max_ctx = FFMIN(max, 2);
768 
769  while (i < max_ctx && GET_CABAC(REF_IDX_L0_OFFSET + i))
770  i++;
771  if (i == 2) {
772  while (i < max && get_cabac_bypass(&lc->cc))
773  i++;
774  }
775 
776  return i;
777 }
778 
780 {
781  return GET_CABAC(MVP_LX_FLAG_OFFSET);
782 }
783 
785 {
786  return GET_CABAC(NO_RESIDUAL_DATA_FLAG_OFFSET);
787 }
788 
790 {
791  return GET_CABAC(ABS_MVD_GREATER0_FLAG_OFFSET);
792 }
793 
795 {
796  return GET_CABAC(ABS_MVD_GREATER1_FLAG_OFFSET + 1);
797 }
798 
800 {
801  int ret = 2;
802  int k = 1;
803 
804  while (k < CABAC_MAX_BIN && get_cabac_bypass(&lc->cc)) {
805  ret += 1U << k;
806  k++;
807  }
808  if (k == CABAC_MAX_BIN) {
809  av_log(lc->logctx, AV_LOG_ERROR, "CABAC_MAX_BIN : %d\n", k);
810  return 0;
811  }
812  while (k--)
813  ret += get_cabac_bypass(&lc->cc) << k;
814  return get_cabac_bypass_sign(&lc->cc, -ret);
815 }
816 
818 {
819  return get_cabac_bypass_sign(&lc->cc, -1);
820 }
821 
823 {
824  return GET_CABAC(SPLIT_TRANSFORM_FLAG_OFFSET + 5 - log2_trafo_size);
825 }
826 
828 {
829  return GET_CABAC(CBF_CB_CR_OFFSET + trafo_depth);
830 }
831 
832 int ff_hevc_cbf_luma_decode(HEVCLocalContext *lc, int trafo_depth)
833 {
834  return GET_CABAC(CBF_LUMA_OFFSET + !trafo_depth);
835 }
836 
838 {
839  return GET_CABAC(TRANSFORM_SKIP_FLAG_OFFSET + !!c_idx);
840 }
841 
843 {
844  return GET_CABAC(EXPLICIT_RDPCM_FLAG_OFFSET + !!c_idx);
845 }
846 
848 {
849  return GET_CABAC(EXPLICIT_RDPCM_DIR_FLAG_OFFSET + !!c_idx);
850 }
851 
853 {
854  int i =0;
855 
856  while (i < 4 && GET_CABAC(LOG2_RES_SCALE_ABS_OFFSET + 4 * idx + i))
857  i++;
858 
859  return i;
860 }
861 
863 {
864  return GET_CABAC(RES_SCALE_SIGN_FLAG_OFFSET + idx);
865 }
866 
868  int log2_size, int *last_scx_prefix, int *last_scy_prefix)
869 {
870  int i = 0;
871  int max = (log2_size << 1) - 1;
872  int ctx_offset, ctx_shift;
873 
874  if (!c_idx) {
875  ctx_offset = 3 * (log2_size - 2) + ((log2_size - 1) >> 2);
876  ctx_shift = (log2_size + 1) >> 2;
877  } else {
878  ctx_offset = 15;
879  ctx_shift = log2_size - 2;
880  }
881  while (i < max &&
882  GET_CABAC(LAST_SIGNIFICANT_COEFF_X_PREFIX_OFFSET + (i >> ctx_shift) + ctx_offset))
883  i++;
884  *last_scx_prefix = i;
885 
886  i = 0;
887  while (i < max &&
888  GET_CABAC(LAST_SIGNIFICANT_COEFF_Y_PREFIX_OFFSET + (i >> ctx_shift) + ctx_offset))
889  i++;
890  *last_scy_prefix = i;
891 }
892 
894  int last_significant_coeff_prefix)
895 {
896  int i;
897  int length = (last_significant_coeff_prefix >> 1) - 1;
898  int value = get_cabac_bypass(&lc->cc);
899 
900  for (i = 1; i < length; i++)
901  value = (value << 1) | get_cabac_bypass(&lc->cc);
902  return value;
903 }
904 
906 {
907  int inc;
908 
909  inc = FFMIN(ctx_cg, 1) + (c_idx>0 ? 2 : 0);
910 
911  return GET_CABAC(SIGNIFICANT_COEFF_GROUP_FLAG_OFFSET + inc);
912 }
914  int offset, const uint8_t *ctx_idx_map)
915 {
916  int inc = ctx_idx_map[(y_c << 2) + x_c] + offset;
917  return GET_CABAC(SIGNIFICANT_COEFF_FLAG_OFFSET + inc);
918 }
919 
921 {
922  return GET_CABAC(SIGNIFICANT_COEFF_FLAG_OFFSET + offset);
923 }
924 
926 {
927 
928  if (c_idx > 0)
929  inc += 16;
930 
931  return GET_CABAC(COEFF_ABS_LEVEL_GREATER1_FLAG_OFFSET + inc);
932 }
933 
935 {
936  if (c_idx > 0)
937  inc += 4;
938 
939  return GET_CABAC(COEFF_ABS_LEVEL_GREATER2_FLAG_OFFSET + inc);
940 }
941 
943 {
944  int prefix = 0;
945  int suffix = 0;
946  int last_coeff_abs_level_remaining;
947  int i;
948 
949  while (prefix < CABAC_MAX_BIN && get_cabac_bypass(&lc->cc))
950  prefix++;
951 
952  if (prefix < 3) {
953  for (i = 0; i < rc_rice_param; i++)
954  suffix = (suffix << 1) | get_cabac_bypass(&lc->cc);
955  last_coeff_abs_level_remaining = (prefix << rc_rice_param) + suffix;
956  } else {
957  int prefix_minus3 = prefix - 3;
958 
959  if (prefix == CABAC_MAX_BIN || prefix_minus3 + rc_rice_param > 16 + 6) {
960  av_log(lc->logctx, AV_LOG_ERROR, "CABAC_MAX_BIN : %d\n", prefix);
961  return 0;
962  }
963 
964  for (i = 0; i < prefix_minus3 + rc_rice_param; i++)
965  suffix = (suffix << 1) | get_cabac_bypass(&lc->cc);
966  last_coeff_abs_level_remaining = (((1 << prefix_minus3) + 3 - 1)
967  << rc_rice_param) + suffix;
968  }
969  return last_coeff_abs_level_remaining;
970 }
971 
973 {
974  int i;
975  int ret = 0;
976 
977  for (i = 0; i < nb; i++)
978  ret = (ret << 1) | get_cabac_bypass(&lc->cc);
979  return ret;
980 }
981 
983  int x0, int y0,
984  int log2_trafo_size, enum ScanType scan_idx,
985  int c_idx)
986 {
987 #define GET_COORD(offset, n) \
988  do { \
989  x_c = (x_cg << 2) + scan_x_off[n]; \
990  y_c = (y_cg << 2) + scan_y_off[n]; \
991  } while (0)
992  const HEVCContext *const s = lc->parent;
993  const HEVCSPS *const sps = pps->sps;
994  int transform_skip_flag = 0;
995 
996  int last_significant_coeff_x, last_significant_coeff_y;
997  int last_scan_pos;
998  int n_end;
999  int num_coeff = 0;
1000  int greater1_ctx = 1;
1001 
1002  int num_last_subset;
1003  int x_cg_last_sig, y_cg_last_sig;
1004 
1005  const uint8_t *scan_x_cg, *scan_y_cg, *scan_x_off, *scan_y_off;
1006 
1007  ptrdiff_t stride = s->cur_frame->f->linesize[c_idx];
1008  int hshift = sps->hshift[c_idx];
1009  int vshift = sps->vshift[c_idx];
1010  uint8_t *dst = &s->cur_frame->f->data[c_idx][(y0 >> vshift) * stride +
1011  ((x0 >> hshift) << sps->pixel_shift)];
1012  int16_t *coeffs = (int16_t*)(c_idx ? lc->edge_emu_buffer2 : lc->edge_emu_buffer);
1013  uint8_t significant_coeff_group_flag[8][8] = {{0}};
1014  int explicit_rdpcm_flag = 0;
1015  int explicit_rdpcm_dir_flag;
1016 
1017  int trafo_size = 1 << log2_trafo_size;
1018  int i;
1019  int qp,shift,add,scale,scale_m;
1020  static const uint8_t level_scale[] = { 40, 45, 51, 57, 64, 72 };
1021  const uint8_t *scale_matrix = NULL;
1022  uint8_t dc_scale;
1023  int pred_mode_intra = (c_idx == 0) ? lc->tu.intra_pred_mode :
1024  lc->tu.intra_pred_mode_c;
1025 
1026  memset(coeffs, 0, trafo_size * trafo_size * sizeof(int16_t));
1027 
1028  // Derive QP for dequant
1029  if (!lc->cu.cu_transquant_bypass_flag) {
1030  static const int qp_c[] = { 29, 30, 31, 32, 33, 33, 34, 34, 35, 35, 36, 36, 37, 37 };
1031  static const uint8_t rem6[51 + 4 * 6 + 1] = {
1032  0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2,
1033  3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5,
1034  0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3,
1035  4, 5, 0, 1, 2, 3, 4, 5, 0, 1
1036  };
1037 
1038  static const uint8_t div6[51 + 4 * 6 + 1] = {
1039  0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3,
1040  3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6,
1041  7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10,
1042  10, 10, 11, 11, 11, 11, 11, 11, 12, 12
1043  };
1044  int qp_y = lc->qp_y;
1045 
1046  if (pps->transform_skip_enabled_flag &&
1047  log2_trafo_size <= pps->log2_max_transform_skip_block_size) {
1048  transform_skip_flag = hevc_transform_skip_flag_decode(lc, c_idx);
1049  }
1050 
1051  if (c_idx == 0) {
1052  qp = qp_y + sps->qp_bd_offset;
1053  } else {
1054  int qp_i, offset;
1055 
1056  if (c_idx == 1)
1057  offset = pps->cb_qp_offset + s->sh.slice_cb_qp_offset +
1058  lc->tu.cu_qp_offset_cb;
1059  else
1060  offset = pps->cr_qp_offset + s->sh.slice_cr_qp_offset +
1061  lc->tu.cu_qp_offset_cr;
1062 
1063  qp_i = av_clip(qp_y + offset, - sps->qp_bd_offset, 57);
1064  if (sps->chroma_format_idc == 1) {
1065  if (qp_i < 30)
1066  qp = qp_i;
1067  else if (qp_i > 43)
1068  qp = qp_i - 6;
1069  else
1070  qp = qp_c[qp_i - 30];
1071  } else {
1072  if (qp_i > 51)
1073  qp = 51;
1074  else
1075  qp = qp_i;
1076  }
1077 
1078  qp += sps->qp_bd_offset;
1079  }
1080 
1081  shift = sps->bit_depth + log2_trafo_size - 5;
1082  add = 1 << (shift-1);
1083  scale = level_scale[rem6[qp]] << (div6[qp]);
1084  scale_m = 16; // default when no custom scaling lists.
1085  dc_scale = 16;
1086 
1087  if (sps->scaling_list_enabled && !(transform_skip_flag && log2_trafo_size > 2)) {
1088  const ScalingList *sl = pps->scaling_list_data_present_flag ?
1089  &pps->scaling_list : &sps->scaling_list;
1090  int matrix_id = lc->cu.pred_mode != MODE_INTRA;
1091 
1092  matrix_id = 3 * matrix_id + c_idx;
1093 
1094  scale_matrix = sl->sl[log2_trafo_size - 2][matrix_id];
1095  if (log2_trafo_size >= 4)
1096  dc_scale = sl->sl_dc[log2_trafo_size - 4][matrix_id];
1097  }
1098  } else {
1099  shift = 0;
1100  add = 0;
1101  scale = 0;
1102  dc_scale = 0;
1103  }
1104 
1105  if (lc->cu.pred_mode == MODE_INTER && sps->explicit_rdpcm_enabled &&
1106  (transform_skip_flag || lc->cu.cu_transquant_bypass_flag)) {
1107  explicit_rdpcm_flag = explicit_rdpcm_flag_decode(lc, c_idx);
1108  if (explicit_rdpcm_flag) {
1109  explicit_rdpcm_dir_flag = explicit_rdpcm_dir_flag_decode(lc, c_idx);
1110  }
1111  }
1112 
1113  last_significant_coeff_xy_prefix_decode(lc, c_idx, log2_trafo_size,
1114  &last_significant_coeff_x, &last_significant_coeff_y);
1115 
1116  if (last_significant_coeff_x > 3) {
1117  int suffix = last_significant_coeff_suffix_decode(lc, last_significant_coeff_x);
1118  last_significant_coeff_x = (1 << ((last_significant_coeff_x >> 1) - 1)) *
1119  (2 + (last_significant_coeff_x & 1)) +
1120  suffix;
1121  }
1122 
1123  if (last_significant_coeff_y > 3) {
1124  int suffix = last_significant_coeff_suffix_decode(lc, last_significant_coeff_y);
1125  last_significant_coeff_y = (1 << ((last_significant_coeff_y >> 1) - 1)) *
1126  (2 + (last_significant_coeff_y & 1)) +
1127  suffix;
1128  }
1129 
1130  if (scan_idx == SCAN_VERT)
1131  FFSWAP(int, last_significant_coeff_x, last_significant_coeff_y);
1132 
1133  x_cg_last_sig = last_significant_coeff_x >> 2;
1134  y_cg_last_sig = last_significant_coeff_y >> 2;
1135 
1136  switch (scan_idx) {
1137  case SCAN_DIAG: {
1138  int last_x_c = last_significant_coeff_x & 3;
1139  int last_y_c = last_significant_coeff_y & 3;
1140 
1141  scan_x_off = ff_hevc_diag_scan4x4_x;
1142  scan_y_off = ff_hevc_diag_scan4x4_y;
1143  num_coeff = diag_scan4x4_inv[last_y_c][last_x_c];
1144  if (trafo_size == 4) {
1145  scan_x_cg = scan_1x1;
1146  scan_y_cg = scan_1x1;
1147  } else if (trafo_size == 8) {
1148  num_coeff += diag_scan2x2_inv[y_cg_last_sig][x_cg_last_sig] << 4;
1149  scan_x_cg = diag_scan2x2_x;
1150  scan_y_cg = diag_scan2x2_y;
1151  } else if (trafo_size == 16) {
1152  num_coeff += diag_scan4x4_inv[y_cg_last_sig][x_cg_last_sig] << 4;
1153  scan_x_cg = ff_hevc_diag_scan4x4_x;
1154  scan_y_cg = ff_hevc_diag_scan4x4_y;
1155  } else { // trafo_size == 32
1156  num_coeff += diag_scan8x8_inv[y_cg_last_sig][x_cg_last_sig] << 4;
1157  scan_x_cg = ff_hevc_diag_scan8x8_x;
1158  scan_y_cg = ff_hevc_diag_scan8x8_y;
1159  }
1160  break;
1161  }
1162  case SCAN_HORIZ:
1163  scan_x_cg = horiz_scan2x2_x;
1164  scan_y_cg = horiz_scan2x2_y;
1165  scan_x_off = horiz_scan4x4_x;
1166  scan_y_off = horiz_scan4x4_y;
1167  num_coeff = horiz_scan8x8_inv[last_significant_coeff_y][last_significant_coeff_x];
1168  break;
1169  default: //SCAN_VERT
1170  scan_x_cg = horiz_scan2x2_y;
1171  scan_y_cg = horiz_scan2x2_x;
1172  scan_x_off = horiz_scan4x4_y;
1173  scan_y_off = horiz_scan4x4_x;
1174  num_coeff = horiz_scan8x8_inv[last_significant_coeff_x][last_significant_coeff_y];
1175  break;
1176  }
1177  num_coeff++;
1178  num_last_subset = (num_coeff - 1) >> 4;
1179 
1180  for (i = num_last_subset; i >= 0; i--) {
1181  int n, m;
1182  int x_cg, y_cg, x_c, y_c, pos;
1183  int implicit_non_zero_coeff = 0;
1184  int64_t trans_coeff_level;
1185  int prev_sig = 0;
1186  int offset = i << 4;
1187  int rice_init = 0;
1188 
1189  uint8_t significant_coeff_flag_idx[16];
1190  uint8_t nb_significant_coeff_flag = 0;
1191 
1192  x_cg = scan_x_cg[i];
1193  y_cg = scan_y_cg[i];
1194 
1195  if ((i < num_last_subset) && (i > 0)) {
1196  int ctx_cg = 0;
1197  if (x_cg < (1 << (log2_trafo_size - 2)) - 1)
1198  ctx_cg += significant_coeff_group_flag[x_cg + 1][y_cg];
1199  if (y_cg < (1 << (log2_trafo_size - 2)) - 1)
1200  ctx_cg += significant_coeff_group_flag[x_cg][y_cg + 1];
1201 
1202  significant_coeff_group_flag[x_cg][y_cg] =
1203  significant_coeff_group_flag_decode(lc, c_idx, ctx_cg);
1204  implicit_non_zero_coeff = 1;
1205  } else {
1206  significant_coeff_group_flag[x_cg][y_cg] =
1207  ((x_cg == x_cg_last_sig && y_cg == y_cg_last_sig) ||
1208  (x_cg == 0 && y_cg == 0));
1209  }
1210 
1211  last_scan_pos = num_coeff - offset - 1;
1212 
1213  if (i == num_last_subset) {
1214  n_end = last_scan_pos - 1;
1215  significant_coeff_flag_idx[0] = last_scan_pos;
1216  nb_significant_coeff_flag = 1;
1217  } else {
1218  n_end = 15;
1219  }
1220 
1221  if (x_cg < ((1 << log2_trafo_size) - 1) >> 2)
1222  prev_sig = !!significant_coeff_group_flag[x_cg + 1][y_cg];
1223  if (y_cg < ((1 << log2_trafo_size) - 1) >> 2)
1224  prev_sig += (!!significant_coeff_group_flag[x_cg][y_cg + 1] << 1);
1225 
1226  if (significant_coeff_group_flag[x_cg][y_cg] && n_end >= 0) {
1227  static const uint8_t ctx_idx_map[] = {
1228  0, 1, 4, 5, 2, 3, 4, 5, 6, 6, 8, 8, 7, 7, 8, 8, // log2_trafo_size == 2
1229  1, 1, 1, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, // prev_sig == 0
1230  2, 2, 2, 2, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, // prev_sig == 1
1231  2, 1, 0, 0, 2, 1, 0, 0, 2, 1, 0, 0, 2, 1, 0, 0, // prev_sig == 2
1232  2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 // default
1233  };
1234  const uint8_t *ctx_idx_map_p;
1235  int scf_offset = 0;
1236  if (sps->transform_skip_context_enabled &&
1237  (transform_skip_flag || lc->cu.cu_transquant_bypass_flag)) {
1238  ctx_idx_map_p = &ctx_idx_map[4 * 16];
1239  if (c_idx == 0) {
1240  scf_offset = 40;
1241  } else {
1242  scf_offset = 14 + 27;
1243  }
1244  } else {
1245  if (c_idx != 0)
1246  scf_offset = 27;
1247  if (log2_trafo_size == 2) {
1248  ctx_idx_map_p = &ctx_idx_map[0];
1249  } else {
1250  ctx_idx_map_p = &ctx_idx_map[(prev_sig + 1) << 4];
1251  if (c_idx == 0) {
1252  if ((x_cg > 0 || y_cg > 0))
1253  scf_offset += 3;
1254  if (log2_trafo_size == 3) {
1255  scf_offset += (scan_idx == SCAN_DIAG) ? 9 : 15;
1256  } else {
1257  scf_offset += 21;
1258  }
1259  } else {
1260  if (log2_trafo_size == 3)
1261  scf_offset += 9;
1262  else
1263  scf_offset += 12;
1264  }
1265  }
1266  }
1267  for (n = n_end; n > 0; n--) {
1268  x_c = scan_x_off[n];
1269  y_c = scan_y_off[n];
1270  if (significant_coeff_flag_decode(lc, x_c, y_c, scf_offset, ctx_idx_map_p)) {
1271  significant_coeff_flag_idx[nb_significant_coeff_flag] = n;
1272  nb_significant_coeff_flag++;
1273  implicit_non_zero_coeff = 0;
1274  }
1275  }
1276  if (implicit_non_zero_coeff == 0) {
1277  if (sps->transform_skip_context_enabled &&
1278  (transform_skip_flag || lc->cu.cu_transquant_bypass_flag)) {
1279  if (c_idx == 0) {
1280  scf_offset = 42;
1281  } else {
1282  scf_offset = 16 + 27;
1283  }
1284  } else {
1285  if (i == 0) {
1286  if (c_idx == 0)
1287  scf_offset = 0;
1288  else
1289  scf_offset = 27;
1290  } else {
1291  scf_offset = 2 + scf_offset;
1292  }
1293  }
1294  if (significant_coeff_flag_decode_0(lc, c_idx, scf_offset) == 1) {
1295  significant_coeff_flag_idx[nb_significant_coeff_flag] = 0;
1296  nb_significant_coeff_flag++;
1297  }
1298  } else {
1299  significant_coeff_flag_idx[nb_significant_coeff_flag] = 0;
1300  nb_significant_coeff_flag++;
1301  }
1302  }
1303 
1304  n_end = nb_significant_coeff_flag;
1305 
1306 
1307  if (n_end) {
1308  int first_nz_pos_in_cg;
1309  int last_nz_pos_in_cg;
1310  int c_rice_param = 0;
1311  int first_greater1_coeff_idx = -1;
1312  uint8_t coeff_abs_level_greater1_flag[8];
1313  uint16_t coeff_sign_flag;
1314  int sum_abs = 0;
1315  int sign_hidden;
1316  int sb_type;
1317 
1318 
1319  // initialize first elem of coeff_bas_level_greater1_flag
1320  int ctx_set = (i > 0 && c_idx == 0) ? 2 : 0;
1321 
1322  if (sps->persistent_rice_adaptation_enabled) {
1323  if (!transform_skip_flag && !lc->cu.cu_transquant_bypass_flag)
1324  sb_type = 2 * (c_idx == 0 ? 1 : 0);
1325  else
1326  sb_type = 2 * (c_idx == 0 ? 1 : 0) + 1;
1327  c_rice_param = lc->stat_coeff[sb_type] / 4;
1328  }
1329 
1330  if (!(i == num_last_subset) && greater1_ctx == 0)
1331  ctx_set++;
1332  greater1_ctx = 1;
1333  last_nz_pos_in_cg = significant_coeff_flag_idx[0];
1334 
1335  for (m = 0; m < (n_end > 8 ? 8 : n_end); m++) {
1336  int inc = (ctx_set << 2) + greater1_ctx;
1337  coeff_abs_level_greater1_flag[m] =
1339  if (coeff_abs_level_greater1_flag[m]) {
1340  greater1_ctx = 0;
1341  if (first_greater1_coeff_idx == -1)
1342  first_greater1_coeff_idx = m;
1343  } else if (greater1_ctx > 0 && greater1_ctx < 3) {
1344  greater1_ctx++;
1345  }
1346  }
1347  first_nz_pos_in_cg = significant_coeff_flag_idx[n_end - 1];
1348 
1349  if (lc->cu.cu_transquant_bypass_flag ||
1350  (lc->cu.pred_mode == MODE_INTRA &&
1351  sps->implicit_rdpcm_enabled && transform_skip_flag &&
1352  (pred_mode_intra == 10 || pred_mode_intra == 26 )) ||
1353  explicit_rdpcm_flag)
1354  sign_hidden = 0;
1355  else
1356  sign_hidden = (last_nz_pos_in_cg - first_nz_pos_in_cg >= 4);
1357 
1358  if (first_greater1_coeff_idx != -1) {
1359  coeff_abs_level_greater1_flag[first_greater1_coeff_idx] += coeff_abs_level_greater2_flag_decode(lc, c_idx, ctx_set);
1360  }
1361  if (!pps->sign_data_hiding_flag || !sign_hidden ) {
1362  coeff_sign_flag = coeff_sign_flag_decode(lc, nb_significant_coeff_flag) << (16 - nb_significant_coeff_flag);
1363  } else {
1364  coeff_sign_flag = coeff_sign_flag_decode(lc, nb_significant_coeff_flag - 1) << (16 - (nb_significant_coeff_flag - 1));
1365  }
1366 
1367  for (m = 0; m < n_end; m++) {
1368  n = significant_coeff_flag_idx[m];
1369  GET_COORD(offset, n);
1370  if (m < 8) {
1371  trans_coeff_level = 1 + coeff_abs_level_greater1_flag[m];
1372  if (trans_coeff_level == ((m == first_greater1_coeff_idx) ? 3 : 2)) {
1373  int last_coeff_abs_level_remaining = coeff_abs_level_remaining_decode(lc, c_rice_param);
1374 
1375  trans_coeff_level += last_coeff_abs_level_remaining;
1376  if (trans_coeff_level > (3 << c_rice_param))
1377  c_rice_param = sps->persistent_rice_adaptation_enabled ? c_rice_param + 1 : FFMIN(c_rice_param + 1, 4);
1378  if (sps->persistent_rice_adaptation_enabled && !rice_init) {
1379  int c_rice_p_init = lc->stat_coeff[sb_type] / 4;
1380  if (last_coeff_abs_level_remaining >= (3 << c_rice_p_init))
1381  lc->stat_coeff[sb_type]++;
1382  else if (2 * last_coeff_abs_level_remaining < (1 << c_rice_p_init))
1383  if (lc->stat_coeff[sb_type] > 0)
1384  lc->stat_coeff[sb_type]--;
1385  rice_init = 1;
1386  }
1387  }
1388  } else {
1389  int last_coeff_abs_level_remaining = coeff_abs_level_remaining_decode(lc, c_rice_param);
1390 
1391  trans_coeff_level = 1 + last_coeff_abs_level_remaining;
1392  if (trans_coeff_level > (3 << c_rice_param))
1393  c_rice_param = sps->persistent_rice_adaptation_enabled ? c_rice_param + 1 : FFMIN(c_rice_param + 1, 4);
1394  if (sps->persistent_rice_adaptation_enabled && !rice_init) {
1395  int c_rice_p_init = lc->stat_coeff[sb_type] / 4;
1396  if (last_coeff_abs_level_remaining >= (3 << c_rice_p_init))
1397  lc->stat_coeff[sb_type]++;
1398  else if (2 * last_coeff_abs_level_remaining < (1 << c_rice_p_init))
1399  if (lc->stat_coeff[sb_type] > 0)
1400  lc->stat_coeff[sb_type]--;
1401  rice_init = 1;
1402  }
1403  }
1404  if (pps->sign_data_hiding_flag && sign_hidden) {
1405  sum_abs += trans_coeff_level;
1406  if (n == first_nz_pos_in_cg && (sum_abs&1))
1407  trans_coeff_level = -trans_coeff_level;
1408  }
1409  if (coeff_sign_flag >> 15)
1410  trans_coeff_level = -trans_coeff_level;
1411  coeff_sign_flag <<= 1;
1412  if(!lc->cu.cu_transquant_bypass_flag) {
1413  if (sps->scaling_list_enabled && !(transform_skip_flag && log2_trafo_size > 2)) {
1414  if(y_c || x_c || log2_trafo_size < 4) {
1415  switch(log2_trafo_size) {
1416  case 3: pos = (y_c << 3) + x_c; break;
1417  case 4: pos = ((y_c >> 1) << 3) + (x_c >> 1); break;
1418  case 5: pos = ((y_c >> 2) << 3) + (x_c >> 2); break;
1419  default: pos = (y_c << 2) + x_c; break;
1420  }
1421  scale_m = scale_matrix[pos];
1422  } else {
1423  scale_m = dc_scale;
1424  }
1425  }
1426  trans_coeff_level = (trans_coeff_level * (int64_t)scale * (int64_t)scale_m + add) >> shift;
1427  if(trans_coeff_level < 0) {
1428  if((~trans_coeff_level) & 0xFffffffffff8000)
1429  trans_coeff_level = -32768;
1430  } else {
1431  if(trans_coeff_level & 0xffffffffffff8000)
1432  trans_coeff_level = 32767;
1433  }
1434  }
1435  coeffs[y_c * trafo_size + x_c] = trans_coeff_level;
1436  }
1437  }
1438  }
1439 
1440  if (lc->cu.cu_transquant_bypass_flag) {
1441  if (explicit_rdpcm_flag || (sps->implicit_rdpcm_enabled &&
1442  (pred_mode_intra == 10 || pred_mode_intra == 26))) {
1443  int mode = sps->implicit_rdpcm_enabled ? (pred_mode_intra == 26) : explicit_rdpcm_dir_flag;
1444 
1445  s->hevcdsp.transform_rdpcm(coeffs, log2_trafo_size, mode);
1446  }
1447  } else {
1448  if (transform_skip_flag) {
1449  int rot = sps->transform_skip_rotation_enabled &&
1450  log2_trafo_size == 2 &&
1451  lc->cu.pred_mode == MODE_INTRA;
1452  if (rot) {
1453  for (i = 0; i < 8; i++)
1454  FFSWAP(int16_t, coeffs[i], coeffs[16 - i - 1]);
1455  }
1456 
1457  s->hevcdsp.dequant(coeffs, log2_trafo_size);
1458 
1459  if (explicit_rdpcm_flag || (sps->implicit_rdpcm_enabled &&
1460  lc->cu.pred_mode == MODE_INTRA &&
1461  (pred_mode_intra == 10 || pred_mode_intra == 26))) {
1462  int mode = explicit_rdpcm_flag ? explicit_rdpcm_dir_flag : (pred_mode_intra == 26);
1463 
1464  s->hevcdsp.transform_rdpcm(coeffs, log2_trafo_size, mode);
1465  }
1466  } else if (lc->cu.pred_mode == MODE_INTRA && c_idx == 0 && log2_trafo_size == 2) {
1467  s->hevcdsp.transform_4x4_luma(coeffs);
1468  } else {
1469  int max_xy = FFMAX(last_significant_coeff_x, last_significant_coeff_y);
1470  if (max_xy == 0)
1471  s->hevcdsp.idct_dc[log2_trafo_size - 2](coeffs);
1472  else {
1473  int col_limit = last_significant_coeff_x + last_significant_coeff_y + 4;
1474  if (max_xy < 4)
1475  col_limit = FFMIN(4, col_limit);
1476  else if (max_xy < 8)
1477  col_limit = FFMIN(8, col_limit);
1478  else if (max_xy < 12)
1479  col_limit = FFMIN(24, col_limit);
1480  s->hevcdsp.idct[log2_trafo_size - 2](coeffs, col_limit);
1481  }
1482  }
1483  }
1484  if (lc->tu.cross_pf) {
1485  int16_t *coeffs_y = (int16_t*)lc->edge_emu_buffer;
1486 
1487  for (i = 0; i < (trafo_size * trafo_size); i++) {
1488  coeffs[i] = coeffs[i] + ((lc->tu.res_scale_val * coeffs_y[i]) >> 3);
1489  }
1490  }
1491  s->hevcdsp.add_residual[log2_trafo_size-2](dst, coeffs, stride);
1492 }
1493 
1494 void ff_hevc_hls_mvd_coding(HEVCLocalContext *lc, int x0, int y0, int log2_cb_size)
1495 {
1496  int x = abs_mvd_greater0_flag_decode(lc);
1497  int y = abs_mvd_greater0_flag_decode(lc);
1498 
1499  if (x)
1501  if (y)
1503 
1504  switch (x) {
1505  case 2: lc->pu.mvd.x = mvd_decode(lc); break;
1506  case 1: lc->pu.mvd.x = mvd_sign_flag_decode(lc); break;
1507  case 0: lc->pu.mvd.x = 0; break;
1508  }
1509 
1510  switch (y) {
1511  case 2: lc->pu.mvd.y = mvd_decode(lc); break;
1512  case 1: lc->pu.mvd.y = mvd_sign_flag_decode(lc); break;
1513  case 0: lc->pu.mvd.y = 0; break;
1514  }
1515 }
1516 
HEVCLocalContext
Definition: hevcdec.h:389
ff_hevc_merge_flag_decode
int ff_hevc_merge_flag_decode(HEVCLocalContext *lc)
Definition: cabac.c:748
av_clip
#define av_clip
Definition: common.h:100
diag_scan2x2_y
static const uint8_t diag_scan2x2_y[4]
Definition: cabac.c:375
explicit_rdpcm_flag_decode
static int explicit_rdpcm_flag_decode(HEVCLocalContext *lc, int c_idx)
Definition: cabac.c:842
mvd_decode
static av_always_inline int mvd_decode(HEVCLocalContext *lc)
Definition: cabac.c:799
ff_hevc_end_of_slice_flag_decode
int ff_hevc_end_of_slice_flag_decode(HEVCLocalContext *lc)
Definition: cabac.c:563
PART_NxN
@ PART_NxN
Definition: hevcdec.h:94
ff_hevc_cu_qp_delta_sign_flag
int ff_hevc_cu_qp_delta_sign_flag(HEVCLocalContext *lc)
Definition: cabac.c:614
SAO_BAND
@ SAO_BAND
Definition: hevcdec.h:160
HEVCLocalContext::ctb_up_flag
uint8_t ctb_up_flag
Definition: hevcdec.h:421
int64_t
long long int64_t
Definition: coverity.c:34
PART_2NxnU
@ PART_2NxnU
Definition: hevcdec.h:95
abs_mvd_greater1_flag_decode
static av_always_inline int abs_mvd_greater1_flag_decode(HEVCLocalContext *lc)
Definition: cabac.c:794
ScanType
ScanType
Definition: hevcdec.h:172
CNU
#define CNU
Definition: cabac.c:96
ff_hevc_pred_mode_decode
int ff_hevc_pred_mode_decode(HEVCLocalContext *lc)
Definition: cabac.c:635
data
const char data[16]
Definition: mxf.c:148
Mv::y
int16_t y
vertical component of motion vector
Definition: hevcdec.h:300
SAO_EDGE
@ SAO_EDGE
Definition: hevcdec.h:161
ScalingList::sl
uint8_t sl[4][6][64]
Definition: ps.h:186
coeff_abs_level_greater1_flag_decode
static av_always_inline int coeff_abs_level_greater1_flag_decode(HEVCLocalContext *lc, int c_idx, int inc)
Definition: cabac.c:925
get_cabac_bypass_sign
#define get_cabac_bypass_sign
Definition: cabac.h:193
max
#define max(a, b)
Definition: cuda_runtime.h:33
ff_hevc_sao_type_idx_decode
int ff_hevc_sao_type_idx_decode(HEVCLocalContext *lc)
Definition: cabac.c:521
init_values
static const uint8_t init_values[3][HEVC_CONTEXTS]
Indexed by init_type.
Definition: cabac.c:100
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
horiz_scan2x2_x
static const uint8_t horiz_scan2x2_x[4]
Definition: cabac.c:338
bit_depth
static void bit_depth(AudioStatsContext *s, const uint64_t *const mask, uint8_t *depth)
Definition: af_astats.c:246
cabac_init_state
static void cabac_init_state(HEVCLocalContext *lc, const HEVCContext *s)
Definition: cabac.c:430
ff_hevc_prev_intra_luma_pred_flag_decode
int ff_hevc_prev_intra_luma_pred_flag_decode(HEVCLocalContext *lc)
Definition: cabac.c:703
PART_2Nx2N
@ PART_2Nx2N
Definition: hevcdec.h:91
HEVCLocalContext::common_cabac_state
HEVCCABACState * common_cabac_state
This is a pointer to the common CABAC state.
Definition: hevcdec.h:411
PRED_BI
@ PRED_BI
Definition: hevcdec.h:110
ff_hevc_split_transform_flag_decode
int ff_hevc_split_transform_flag_decode(HEVCLocalContext *lc, int log2_trafo_size)
Definition: cabac.c:822
GET_CABAC
#define GET_CABAC(ctx)
Definition: cabac.c:514
MODE_INTER
@ MODE_INTER
Definition: hevcdec.h:102
ff_hevc_hls_mvd_coding
void ff_hevc_hls_mvd_coding(HEVCLocalContext *lc, int x0, int y0, int log2_cb_size)
Definition: cabac.c:1494
HEVCLocalContext::pu
PredictionUnit pu
Definition: hevcdec.h:434
TransformUnit::res_scale_val
int res_scale_val
Definition: hevcdec.h:331
horiz_scan2x2_y
static const uint8_t horiz_scan2x2_y[4]
Definition: cabac.c:342
ff_hevc_diag_scan8x8_y
const uint8_t ff_hevc_diag_scan8x8_y[64]
Definition: data.c:58
ff_hevc_cu_chroma_qp_offset_idx
int ff_hevc_cu_chroma_qp_offset_idx(HEVCLocalContext *lc, int chroma_qp_offset_list_len_minus1)
Definition: cabac.c:624
ff_hevc_sao_offset_abs_decode
int ff_hevc_sao_offset_abs_decode(HEVCLocalContext *lc, int bit_depth)
Definition: cabac.c:541
abs_mvd_greater0_flag_decode
static av_always_inline int abs_mvd_greater0_flag_decode(HEVCLocalContext *lc)
Definition: cabac.c:789
load_states
static void load_states(HEVCLocalContext *lc, const HEVCSPS *sps)
Definition: cabac.c:417
ff_hevc_mvp_lx_flag_decode
int ff_hevc_mvp_lx_flag_decode(HEVCLocalContext *lc)
Definition: cabac.c:779
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
TransformUnit::intra_pred_mode
int intra_pred_mode
Definition: hevcdec.h:334
diag_scan8x8_inv
static const uint8_t diag_scan8x8_inv[8][8]
Definition: cabac.c:391
significant_coeff_group_flag_decode
static av_always_inline int significant_coeff_group_flag_decode(HEVCLocalContext *lc, int c_idx, int ctx_cg)
Definition: cabac.c:905
OFFSET
#define OFFSET(NAME, NUM_BINS)
Definition: cabac.c:90
HEVCLocalContext::parent
const struct HEVCContext * parent
Definition: hevcdec.h:397
s
#define s(width, name)
Definition: cbs_vp9.c:198
explicit_rdpcm_dir_flag_decode
static int explicit_rdpcm_dir_flag_decode(HEVCLocalContext *lc, int c_idx)
Definition: cabac.c:847
ff_hevc_part_mode_decode
int ff_hevc_part_mode_decode(HEVCLocalContext *lc, const HEVCSPS *sps, int log2_cb_size)
Definition: cabac.c:661
ff_hevc_merge_idx_decode
int ff_hevc_merge_idx_decode(HEVCLocalContext *lc)
Definition: cabac.c:737
horiz_scan8x8_inv
static const uint8_t horiz_scan8x8_inv[8][8]
Definition: cabac.c:360
last_significant_coeff_suffix_decode
static av_always_inline int last_significant_coeff_suffix_decode(HEVCLocalContext *lc, int last_significant_coeff_prefix)
Definition: cabac.c:893
ff_hevc_save_states
void ff_hevc_save_states(HEVCLocalContext *lc, const HEVCPPS *pps, int ctb_addr_ts)
Definition: cabac.c:402
ff_hevc_cbf_cb_cr_decode
int ff_hevc_cbf_cb_cr_decode(HEVCLocalContext *lc, int trafo_depth)
Definition: cabac.c:827
hevc.h
ScalingList
Definition: ps.h:183
last_significant_coeff_xy_prefix_decode
static av_always_inline void last_significant_coeff_xy_prefix_decode(HEVCLocalContext *lc, int c_idx, int log2_size, int *last_scx_prefix, int *last_scy_prefix)
Definition: cabac.c:867
ff_hevc_hls_residual_coding
void ff_hevc_hls_residual_coding(HEVCLocalContext *lc, const HEVCPPS *pps, int x0, int y0, int log2_trafo_size, enum ScanType scan_idx, int c_idx)
Definition: cabac.c:982
if
if(ret)
Definition: filter_design.txt:179
ff_hevc_diag_scan4x4_y
const uint8_t ff_hevc_diag_scan4x4_y[16]
Definition: data.c:32
HEVCCABACState::state
uint8_t state[HEVC_CONTEXTS]
Definition: hevcdec.h:179
NULL
#define NULL
Definition: coverity.c:32
significant_coeff_flag_decode
static av_always_inline int significant_coeff_flag_decode(HEVCLocalContext *lc, int x_c, int y_c, int offset, const uint8_t *ctx_idx_map)
Definition: cabac.c:913
ScalingList::sl_dc
uint8_t sl_dc[2][6]
Definition: ps.h:187
horiz_scan4x4_y
static const uint8_t horiz_scan4x4_y[16]
Definition: cabac.c:353
CodingUnit::cu_transquant_bypass_flag
uint8_t cu_transquant_bypass_flag
Definition: hevcdec.h:295
HEVC_SLICE_I
@ HEVC_SLICE_I
Definition: hevc.h:98
diag_scan2x2_x
static const uint8_t diag_scan2x2_x[4]
Definition: cabac.c:371
ff_hevc_res_scale_sign_flag
int ff_hevc_res_scale_sign_flag(HEVCLocalContext *lc, int idx)
Definition: cabac.c:862
PART_Nx2N
@ PART_Nx2N
Definition: hevcdec.h:93
ff_hevc_ref_idx_lx_decode
int ff_hevc_ref_idx_lx_decode(HEVCLocalContext *lc, int num_ref_idx_lx)
Definition: cabac.c:763
data.h
coeff_abs_level_remaining_decode
static av_always_inline int coeff_abs_level_remaining_decode(HEVCLocalContext *lc, int rc_rice_param)
Definition: cabac.c:942
Mv::x
int16_t x
horizontal component of motion vector
Definition: hevcdec.h:299
ff_hevc_sao_eo_class_decode
int ff_hevc_sao_eo_class_decode(HEVCLocalContext *lc)
Definition: cabac.c:556
SAMPLE_CTB
#define SAMPLE_CTB(tab, x, y)
Definition: hevcdec.h:74
inc
static int inc(int num, int period)
Definition: perlin.c:34
SCAN_HORIZ
@ SCAN_HORIZ
Definition: hevcdec.h:174
HEVCLocalContext::edge_emu_buffer
uint8_t edge_emu_buffer[(MAX_PB_SIZE+7) *EDGE_EMU_BUFFER_STRIDE *2]
Definition: hevcdec.h:427
PART_nLx2N
@ PART_nLx2N
Definition: hevcdec.h:97
ff_hevc_cabac_init
int ff_hevc_cabac_init(HEVCLocalContext *lc, const HEVCPPS *pps, int ctb_addr_ts, const uint8_t *data, size_t size, int is_wpp)
Definition: cabac.c:454
diag_scan2x2_inv
static const uint8_t diag_scan2x2_inv[2][2]
Definition: cabac.c:379
HEVCLocalContext::ctb_left_flag
uint8_t ctb_left_flag
Definition: hevcdec.h:420
hevcdec.h
CABAC_MAX_BIN
#define CABAC_MAX_BIN
Definition: cabac.c:32
shift
static int shift(int a, int b)
Definition: bonk.c:261
for
for(k=2;k<=8;++k)
Definition: h264pred_template.c:425
HEVCLocalContext::cabac_state
uint8_t cabac_state[HEVC_CONTEXTS]
Definition: hevcdec.h:390
PART_2NxnD
@ PART_2NxnD
Definition: hevcdec.h:96
size
int size
Definition: twinvq_data.h:10344
SCAN_VERT
@ SCAN_VERT
Definition: hevcdec.h:175
ff_hevc_pcm_flag_decode
int ff_hevc_pcm_flag_decode(HEVCLocalContext *lc)
Definition: cabac.c:698
get_cabac_bypass
#define get_cabac_bypass
Definition: cabac.h:149
diag_scan4x4_inv
static const uint8_t diag_scan4x4_inv[4][4]
Definition: cabac.c:384
horiz_scan4x4_x
static const uint8_t horiz_scan4x4_x[16]
Definition: cabac.c:346
HEVC_STAT_COEFFS
#define HEVC_STAT_COEFFS
Definition: hevcdec.h:54
offset
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf offset
Definition: writing_filters.txt:86
attributes.h
ff_hevc_cbf_luma_decode
int ff_hevc_cbf_luma_decode(HEVCLocalContext *lc, int trafo_depth)
Definition: cabac.c:832
av_zero_extend
#define av_zero_extend
Definition: common.h:151
TransformUnit::cu_qp_offset_cb
int8_t cu_qp_offset_cb
Definition: hevcdec.h:339
ff_hevc_skip_flag_decode
int ff_hevc_skip_flag_decode(HEVCLocalContext *lc, int x0, int y0, int x_cb, int y_cb, int min_cb_width)
Definition: cabac.c:573
HEVCLocalContext::ct_depth
int ct_depth
Definition: hevcdec.h:432
get_cabac_terminate
static int av_unused get_cabac_terminate(CABACContext *c)
Definition: cabac_functions.h:187
ff_init_cabac_decoder
int ff_init_cabac_decoder(CABACContext *c, const uint8_t *buf, int buf_size)
Definition: cabac.c:162
PART_nRx2N
@ PART_nRx2N
Definition: hevcdec.h:98
MODE_INTRA
#define MODE_INTRA
Definition: vp3.c:84
ff_hevc_cu_transquant_bypass_flag_decode
int ff_hevc_cu_transquant_bypass_flag_decode(HEVCLocalContext *lc)
Definition: cabac.c:568
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
HEVCLocalContext::logctx
void * logctx
Definition: hevcdec.h:396
ff_hevc_no_residual_syntax_flag_decode
int ff_hevc_no_residual_syntax_flag_decode(HEVCLocalContext *lc)
Definition: cabac.c:784
common.h
ff_hevc_mpm_idx_decode
int ff_hevc_mpm_idx_decode(HEVCLocalContext *lc)
Definition: cabac.c:708
av_always_inline
#define av_always_inline
Definition: attributes.h:49
value
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default value
Definition: writing_filters.txt:86
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
cabac_functions.h
HEVCLocalContext::qp_y
int8_t qp_y
Definition: hevcdec.h:413
ff_hevc_diag_scan4x4_x
const uint8_t ff_hevc_diag_scan4x4_x[16]
Definition: data.c:25
HEVCLocalContext::stat_coeff
uint8_t stat_coeff[HEVC_STAT_COEFFS]
Definition: hevcdec.h:392
ff_hevc_cu_chroma_qp_offset_flag
int ff_hevc_cu_chroma_qp_offset_flag(HEVCLocalContext *lc)
Definition: cabac.c:619
stride
#define stride
Definition: h264pred_template.c:537
coeff_sign_flag_decode
static av_always_inline int coeff_sign_flag_decode(HEVCLocalContext *lc, uint8_t nb)
Definition: cabac.c:972
ff_hevc_sao_merge_flag_decode
int ff_hevc_sao_merge_flag_decode(HEVCLocalContext *lc)
Definition: cabac.c:516
ret
ret
Definition: filter_design.txt:187
FFSWAP
#define FFSWAP(type, a, b)
Definition: macros.h:52
PredictionUnit::mvd
Mv mvd
Definition: hevcdec.h:322
HEVCLocalContext::edge_emu_buffer2
uint8_t edge_emu_buffer2[(MAX_PB_SIZE+7) *EDGE_EMU_BUFFER_STRIDE *2]
Definition: hevcdec.h:429
sps
static int FUNC() sps(CodedBitstreamContext *ctx, RWContext *rw, H264RawSPS *current)
Definition: cbs_h264_syntax_template.c:260
pos
unsigned int pos
Definition: spdifenc.c:414
mvd_sign_flag_decode
static av_always_inline int mvd_sign_flag_decode(HEVCLocalContext *lc)
Definition: cabac.c:817
GET_COORD
#define GET_COORD(offset, n)
ff_hevc_sao_band_position_decode
int ff_hevc_sao_band_position_decode(HEVCLocalContext *lc)
Definition: cabac.c:531
U
#define U(x)
Definition: vpx_arith.h:37
suffix
const char * suffix
Definition: checkasm.c:271
scan_1x1
static const uint8_t scan_1x1[1]
Definition: cabac.c:334
ff_hevc_split_coding_unit_flag_decode
int ff_hevc_split_coding_unit_flag_decode(HEVCLocalContext *lc, const HEVCSPS *sps, int ct_depth, int x0, int y0)
Definition: cabac.c:640
ff_hevc_inter_pred_idc_decode
int ff_hevc_inter_pred_idc_decode(HEVCLocalContext *lc, int nPbW, int nPbH)
Definition: cabac.c:753
mode
mode
Definition: ebur128.h:83
HEVCContext
Definition: hevcdec.h:450
CodingUnit::pred_mode
enum PredMode pred_mode
PredMode.
Definition: hevcdec.h:289
cabac_reinit
static int cabac_reinit(HEVCLocalContext *lc)
Definition: cabac.c:425
SCAN_DIAG
@ SCAN_DIAG
Definition: hevcdec.h:173
hevc_transform_skip_flag_decode
static int hevc_transform_skip_flag_decode(HEVCLocalContext *lc, int c_idx)
Definition: cabac.c:837
significant_coeff_flag_decode_0
static av_always_inline int significant_coeff_flag_decode_0(HEVCLocalContext *lc, int c_idx, int offset)
Definition: cabac.c:920
CABAC_ELEMS
#define CABAC_ELEMS(ELEM)
Definition: cabac.c:35
pps
uint64_t pps
Definition: dovi_rpuenc.c:35
HEVCLocalContext::tu
TransformUnit tu
Definition: hevcdec.h:418
ff_hevc_diag_scan8x8_x
const uint8_t ff_hevc_diag_scan8x8_x[64]
Definition: data.c:39
ff_hevc_cu_qp_delta_abs
int ff_hevc_cu_qp_delta_abs(HEVCLocalContext *lc)
Definition: cabac.c:587
HEVCCABACState::stat_coeff
uint8_t stat_coeff[HEVC_STAT_COEFFS]
Definition: hevcdec.h:180
HEVCSPS
Definition: ps.h:190
HEVCPPS
Definition: ps.h:309
scale
static void scale(int *out, const int *in, const int w, const int h, const int shift)
Definition: intra.c:291
TransformUnit::cross_pf
uint8_t cross_pf
Definition: hevcdec.h:341
HEVCLocalContext::cu
CodingUnit cu
Definition: hevcdec.h:433
ff_hevc_log2_res_scale_abs
int ff_hevc_log2_res_scale_abs(HEVCLocalContext *lc, int idx)
Definition: cabac.c:852
ff_hevc_sao_offset_sign_decode
int ff_hevc_sao_offset_sign_decode(HEVCLocalContext *lc)
Definition: cabac.c:551
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
skip_bytes
static const av_unused uint8_t * skip_bytes(CABACContext *c, int n)
Skip n bytes and reset the decoder.
Definition: cabac_functions.h:203
TransformUnit::intra_pred_mode_c
int intra_pred_mode_c
Definition: hevcdec.h:335
coeff_abs_level_greater2_flag_decode
static av_always_inline int coeff_abs_level_greater2_flag_decode(HEVCLocalContext *lc, int c_idx, int inc)
Definition: cabac.c:934
ff_hevc_intra_chroma_pred_mode_decode
int ff_hevc_intra_chroma_pred_mode_decode(HEVCLocalContext *lc)
Definition: cabac.c:726
PART_2NxN
@ PART_2NxN
Definition: hevcdec.h:92
HEVCLocalContext::cc
CABACContext cc
Definition: hevcdec.h:399
TransformUnit::cu_qp_offset_cr
int8_t cu_qp_offset_cr
Definition: hevcdec.h:340
HEVC_CONTEXTS
#define HEVC_CONTEXTS
Definition: hevcdec.h:53
ff_hevc_rem_intra_luma_pred_mode_decode
int ff_hevc_rem_intra_luma_pred_mode_decode(HEVCLocalContext *lc)
Definition: cabac.c:716