FFmpeg
hevc_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 "hevc_data.h"
29 #include "hevc.h"
30 #include "hevcdec.h"
31 
32 #define CABAC_MAX_BIN 31
33 
34 /**
35  * number of bin by SyntaxElement.
36  */
37 static const int8_t num_bins_in_se[] = {
38  1, // sao_merge_flag
39  1, // sao_type_idx
40  0, // sao_eo_class
41  0, // sao_band_position
42  0, // sao_offset_abs
43  0, // sao_offset_sign
44  0, // end_of_slice_flag
45  3, // split_coding_unit_flag
46  1, // cu_transquant_bypass_flag
47  3, // skip_flag
48  3, // cu_qp_delta
49  1, // pred_mode
50  4, // part_mode
51  0, // pcm_flag
52  1, // prev_intra_luma_pred_mode
53  0, // mpm_idx
54  0, // rem_intra_luma_pred_mode
55  2, // intra_chroma_pred_mode
56  1, // merge_flag
57  1, // merge_idx
58  5, // inter_pred_idc
59  2, // ref_idx_l0
60  2, // ref_idx_l1
61  2, // abs_mvd_greater0_flag
62  2, // abs_mvd_greater1_flag
63  0, // abs_mvd_minus2
64  0, // mvd_sign_flag
65  1, // mvp_lx_flag
66  1, // no_residual_data_flag
67  3, // split_transform_flag
68  2, // cbf_luma
69  5, // cbf_cb, cbf_cr
70  2, // transform_skip_flag[][]
71  2, // explicit_rdpcm_flag[][]
72  2, // explicit_rdpcm_dir_flag[][]
73  18, // last_significant_coeff_x_prefix
74  18, // last_significant_coeff_y_prefix
75  0, // last_significant_coeff_x_suffix
76  0, // last_significant_coeff_y_suffix
77  4, // significant_coeff_group_flag
78  44, // significant_coeff_flag
79  24, // coeff_abs_level_greater1_flag
80  6, // coeff_abs_level_greater2_flag
81  0, // coeff_abs_level_remaining
82  0, // coeff_sign_flag
83  8, // log2_res_scale_abs
84  2, // res_scale_sign_flag
85  1, // cu_chroma_qp_offset_flag
86  1, // cu_chroma_qp_offset_idx
87 };
88 
89 /**
90  * Offset to ctxIdx 0 in init_values and states, indexed by SyntaxElement.
91  */
92 static const int elem_offset[sizeof(num_bins_in_se)] = {
93  0, // sao_merge_flag
94  1, // sao_type_idx
95  2, // sao_eo_class
96  2, // sao_band_position
97  2, // sao_offset_abs
98  2, // sao_offset_sign
99  2, // end_of_slice_flag
100  2, // split_coding_unit_flag
101  5, // cu_transquant_bypass_flag
102  6, // skip_flag
103  9, // cu_qp_delta
104  12, // pred_mode
105  13, // part_mode
106  17, // pcm_flag
107  17, // prev_intra_luma_pred_mode
108  18, // mpm_idx
109  18, // rem_intra_luma_pred_mode
110  18, // intra_chroma_pred_mode
111  20, // merge_flag
112  21, // merge_idx
113  22, // inter_pred_idc
114  27, // ref_idx_l0
115  29, // ref_idx_l1
116  31, // abs_mvd_greater0_flag
117  33, // abs_mvd_greater1_flag
118  35, // abs_mvd_minus2
119  35, // mvd_sign_flag
120  35, // mvp_lx_flag
121  36, // no_residual_data_flag
122  37, // split_transform_flag
123  40, // cbf_luma
124  42, // cbf_cb, cbf_cr
125  47, // transform_skip_flag[][]
126  49, // explicit_rdpcm_flag[][]
127  51, // explicit_rdpcm_dir_flag[][]
128  53, // last_significant_coeff_x_prefix
129  71, // last_significant_coeff_y_prefix
130  89, // last_significant_coeff_x_suffix
131  89, // last_significant_coeff_y_suffix
132  89, // significant_coeff_group_flag
133  93, // significant_coeff_flag
134  137, // coeff_abs_level_greater1_flag
135  161, // coeff_abs_level_greater2_flag
136  167, // coeff_abs_level_remaining
137  167, // coeff_sign_flag
138  167, // log2_res_scale_abs
139  175, // res_scale_sign_flag
140  177, // cu_chroma_qp_offset_flag
141  178, // cu_chroma_qp_offset_idx
142 };
143 
144 #define CNU 154
145 /**
146  * Indexed by init_type
147  */
148 static const uint8_t init_values[3][HEVC_CONTEXTS] = {
149  { // sao_merge_flag
150  153,
151  // sao_type_idx
152  200,
153  // split_coding_unit_flag
154  139, 141, 157,
155  // cu_transquant_bypass_flag
156  154,
157  // skip_flag
158  CNU, CNU, CNU,
159  // cu_qp_delta
160  154, 154, 154,
161  // pred_mode
162  CNU,
163  // part_mode
164  184, CNU, CNU, CNU,
165  // prev_intra_luma_pred_mode
166  184,
167  // intra_chroma_pred_mode
168  63, 139,
169  // merge_flag
170  CNU,
171  // merge_idx
172  CNU,
173  // inter_pred_idc
174  CNU, CNU, CNU, CNU, CNU,
175  // ref_idx_l0
176  CNU, CNU,
177  // ref_idx_l1
178  CNU, CNU,
179  // abs_mvd_greater1_flag
180  CNU, CNU,
181  // abs_mvd_greater1_flag
182  CNU, CNU,
183  // mvp_lx_flag
184  CNU,
185  // no_residual_data_flag
186  CNU,
187  // split_transform_flag
188  153, 138, 138,
189  // cbf_luma
190  111, 141,
191  // cbf_cb, cbf_cr
192  94, 138, 182, 154, 154,
193  // transform_skip_flag
194  139, 139,
195  // explicit_rdpcm_flag
196  139, 139,
197  // explicit_rdpcm_dir_flag
198  139, 139,
199  // last_significant_coeff_x_prefix
200  110, 110, 124, 125, 140, 153, 125, 127, 140, 109, 111, 143, 127, 111,
201  79, 108, 123, 63,
202  // last_significant_coeff_y_prefix
203  110, 110, 124, 125, 140, 153, 125, 127, 140, 109, 111, 143, 127, 111,
204  79, 108, 123, 63,
205  // significant_coeff_group_flag
206  91, 171, 134, 141,
207  // significant_coeff_flag
208  111, 111, 125, 110, 110, 94, 124, 108, 124, 107, 125, 141, 179, 153,
209  125, 107, 125, 141, 179, 153, 125, 107, 125, 141, 179, 153, 125, 140,
210  139, 182, 182, 152, 136, 152, 136, 153, 136, 139, 111, 136, 139, 111,
211  141, 111,
212  // coeff_abs_level_greater1_flag
213  140, 92, 137, 138, 140, 152, 138, 139, 153, 74, 149, 92, 139, 107,
214  122, 152, 140, 179, 166, 182, 140, 227, 122, 197,
215  // coeff_abs_level_greater2_flag
216  138, 153, 136, 167, 152, 152,
217  // log2_res_scale_abs
218  154, 154, 154, 154, 154, 154, 154, 154,
219  // res_scale_sign_flag
220  154, 154,
221  // cu_chroma_qp_offset_flag
222  154,
223  // cu_chroma_qp_offset_idx
224  154,
225  },
226  { // sao_merge_flag
227  153,
228  // sao_type_idx
229  185,
230  // split_coding_unit_flag
231  107, 139, 126,
232  // cu_transquant_bypass_flag
233  154,
234  // skip_flag
235  197, 185, 201,
236  // cu_qp_delta
237  154, 154, 154,
238  // pred_mode
239  149,
240  // part_mode
241  154, 139, 154, 154,
242  // prev_intra_luma_pred_mode
243  154,
244  // intra_chroma_pred_mode
245  152, 139,
246  // merge_flag
247  110,
248  // merge_idx
249  122,
250  // inter_pred_idc
251  95, 79, 63, 31, 31,
252  // ref_idx_l0
253  153, 153,
254  // ref_idx_l1
255  153, 153,
256  // abs_mvd_greater1_flag
257  140, 198,
258  // abs_mvd_greater1_flag
259  140, 198,
260  // mvp_lx_flag
261  168,
262  // no_residual_data_flag
263  79,
264  // split_transform_flag
265  124, 138, 94,
266  // cbf_luma
267  153, 111,
268  // cbf_cb, cbf_cr
269  149, 107, 167, 154, 154,
270  // transform_skip_flag
271  139, 139,
272  // explicit_rdpcm_flag
273  139, 139,
274  // explicit_rdpcm_dir_flag
275  139, 139,
276  // last_significant_coeff_x_prefix
277  125, 110, 94, 110, 95, 79, 125, 111, 110, 78, 110, 111, 111, 95,
278  94, 108, 123, 108,
279  // last_significant_coeff_y_prefix
280  125, 110, 94, 110, 95, 79, 125, 111, 110, 78, 110, 111, 111, 95,
281  94, 108, 123, 108,
282  // significant_coeff_group_flag
283  121, 140, 61, 154,
284  // significant_coeff_flag
285  155, 154, 139, 153, 139, 123, 123, 63, 153, 166, 183, 140, 136, 153,
286  154, 166, 183, 140, 136, 153, 154, 166, 183, 140, 136, 153, 154, 170,
287  153, 123, 123, 107, 121, 107, 121, 167, 151, 183, 140, 151, 183, 140,
288  140, 140,
289  // coeff_abs_level_greater1_flag
290  154, 196, 196, 167, 154, 152, 167, 182, 182, 134, 149, 136, 153, 121,
291  136, 137, 169, 194, 166, 167, 154, 167, 137, 182,
292  // coeff_abs_level_greater2_flag
293  107, 167, 91, 122, 107, 167,
294  // log2_res_scale_abs
295  154, 154, 154, 154, 154, 154, 154, 154,
296  // res_scale_sign_flag
297  154, 154,
298  // cu_chroma_qp_offset_flag
299  154,
300  // cu_chroma_qp_offset_idx
301  154,
302  },
303  { // sao_merge_flag
304  153,
305  // sao_type_idx
306  160,
307  // split_coding_unit_flag
308  107, 139, 126,
309  // cu_transquant_bypass_flag
310  154,
311  // skip_flag
312  197, 185, 201,
313  // cu_qp_delta
314  154, 154, 154,
315  // pred_mode
316  134,
317  // part_mode
318  154, 139, 154, 154,
319  // prev_intra_luma_pred_mode
320  183,
321  // intra_chroma_pred_mode
322  152, 139,
323  // merge_flag
324  154,
325  // merge_idx
326  137,
327  // inter_pred_idc
328  95, 79, 63, 31, 31,
329  // ref_idx_l0
330  153, 153,
331  // ref_idx_l1
332  153, 153,
333  // abs_mvd_greater1_flag
334  169, 198,
335  // abs_mvd_greater1_flag
336  169, 198,
337  // mvp_lx_flag
338  168,
339  // no_residual_data_flag
340  79,
341  // split_transform_flag
342  224, 167, 122,
343  // cbf_luma
344  153, 111,
345  // cbf_cb, cbf_cr
346  149, 92, 167, 154, 154,
347  // transform_skip_flag
348  139, 139,
349  // explicit_rdpcm_flag
350  139, 139,
351  // explicit_rdpcm_dir_flag
352  139, 139,
353  // last_significant_coeff_x_prefix
354  125, 110, 124, 110, 95, 94, 125, 111, 111, 79, 125, 126, 111, 111,
355  79, 108, 123, 93,
356  // last_significant_coeff_y_prefix
357  125, 110, 124, 110, 95, 94, 125, 111, 111, 79, 125, 126, 111, 111,
358  79, 108, 123, 93,
359  // significant_coeff_group_flag
360  121, 140, 61, 154,
361  // significant_coeff_flag
362  170, 154, 139, 153, 139, 123, 123, 63, 124, 166, 183, 140, 136, 153,
363  154, 166, 183, 140, 136, 153, 154, 166, 183, 140, 136, 153, 154, 170,
364  153, 138, 138, 122, 121, 122, 121, 167, 151, 183, 140, 151, 183, 140,
365  140, 140,
366  // coeff_abs_level_greater1_flag
367  154, 196, 167, 167, 154, 152, 167, 182, 182, 134, 149, 136, 153, 121,
368  136, 122, 169, 208, 166, 167, 154, 152, 167, 182,
369  // coeff_abs_level_greater2_flag
370  107, 167, 91, 107, 107, 167,
371  // log2_res_scale_abs
372  154, 154, 154, 154, 154, 154, 154, 154,
373  // res_scale_sign_flag
374  154, 154,
375  // cu_chroma_qp_offset_flag
376  154,
377  // cu_chroma_qp_offset_idx
378  154,
379  },
380 };
381 
382 static const uint8_t scan_1x1[1] = {
383  0,
384 };
385 
386 static const uint8_t horiz_scan2x2_x[4] = {
387  0, 1, 0, 1,
388 };
389 
390 static const uint8_t horiz_scan2x2_y[4] = {
391  0, 0, 1, 1
392 };
393 
394 static const uint8_t horiz_scan4x4_x[16] = {
395  0, 1, 2, 3,
396  0, 1, 2, 3,
397  0, 1, 2, 3,
398  0, 1, 2, 3,
399 };
400 
401 static const uint8_t horiz_scan4x4_y[16] = {
402  0, 0, 0, 0,
403  1, 1, 1, 1,
404  2, 2, 2, 2,
405  3, 3, 3, 3,
406 };
407 
408 static const uint8_t horiz_scan8x8_inv[8][8] = {
409  { 0, 1, 2, 3, 16, 17, 18, 19, },
410  { 4, 5, 6, 7, 20, 21, 22, 23, },
411  { 8, 9, 10, 11, 24, 25, 26, 27, },
412  { 12, 13, 14, 15, 28, 29, 30, 31, },
413  { 32, 33, 34, 35, 48, 49, 50, 51, },
414  { 36, 37, 38, 39, 52, 53, 54, 55, },
415  { 40, 41, 42, 43, 56, 57, 58, 59, },
416  { 44, 45, 46, 47, 60, 61, 62, 63, },
417 };
418 
419 static const uint8_t diag_scan2x2_x[4] = {
420  0, 0, 1, 1,
421 };
422 
423 static const uint8_t diag_scan2x2_y[4] = {
424  0, 1, 0, 1,
425 };
426 
427 static const uint8_t diag_scan2x2_inv[2][2] = {
428  { 0, 2, },
429  { 1, 3, },
430 };
431 
432 static const uint8_t diag_scan4x4_inv[4][4] = {
433  { 0, 2, 5, 9, },
434  { 1, 4, 8, 12, },
435  { 3, 7, 11, 14, },
436  { 6, 10, 13, 15, },
437 };
438 
439 static const uint8_t diag_scan8x8_inv[8][8] = {
440  { 0, 2, 5, 9, 14, 20, 27, 35, },
441  { 1, 4, 8, 13, 19, 26, 34, 42, },
442  { 3, 7, 12, 18, 25, 33, 41, 48, },
443  { 6, 11, 17, 24, 32, 40, 47, 53, },
444  { 10, 16, 23, 31, 39, 46, 52, 57, },
445  { 15, 22, 30, 38, 45, 51, 56, 60, },
446  { 21, 29, 37, 44, 50, 55, 59, 62, },
447  { 28, 36, 43, 49, 54, 58, 61, 63, },
448 };
449 
450 void ff_hevc_save_states(HEVCLocalContext *lc, int ctb_addr_ts)
451 {
452  const HEVCContext *const s = lc->parent;
453 
454  if (s->ps.pps->entropy_coding_sync_enabled_flag &&
455  (ctb_addr_ts % s->ps.sps->ctb_width == 2 ||
456  (s->ps.sps->ctb_width == 2 &&
457  ctb_addr_ts % s->ps.sps->ctb_width == 0))) {
459  if (s->ps.sps->persistent_rice_adaptation_enabled_flag) {
461  }
462  }
463 }
464 
465 static void load_states(HEVCLocalContext *lc, const HEVCContext *s)
466 {
468  if (s->ps.sps->persistent_rice_adaptation_enabled_flag) {
470  }
471 }
472 
474 {
475  return skip_bytes(&lc->cc, 0) == NULL ? AVERROR_INVALIDDATA : 0;
476 }
477 
479 {
480  GetBitContext *gb = &lc->gb;
481  skip_bits(gb, 1);
482  align_get_bits(gb);
483  return ff_init_cabac_decoder(&lc->cc,
484  gb->buffer + get_bits_count(gb) / 8,
485  (get_bits_left(gb) + 7) / 8);
486 }
487 
489 {
490  int init_type = 2 - s->sh.slice_type;
491  int i;
492 
493  if (s->sh.cabac_init_flag && s->sh.slice_type != HEVC_SLICE_I)
494  init_type ^= 3;
495 
496  for (i = 0; i < HEVC_CONTEXTS; i++) {
497  int init_value = init_values[init_type][i];
498  int m = (init_value >> 4) * 5 - 45;
499  int n = ((init_value & 15) << 3) - 16;
500  int pre = 2 * (((m * av_clip(s->sh.slice_qp, 0, 51)) >> 4) + n) - 127;
501 
502  pre ^= pre >> 31;
503  if (pre > 124)
504  pre = 124 + (pre & 1);
505  lc->cabac_state[i] = pre;
506  }
507 
508  for (i = 0; i < 4; i++)
509  lc->stat_coeff[i] = 0;
510 }
511 
512 int ff_hevc_cabac_init(HEVCLocalContext *lc, int ctb_addr_ts)
513 {
514  const HEVCContext *const s = lc->parent;
515 
516  if (ctb_addr_ts == s->ps.pps->ctb_addr_rs_to_ts[s->sh.slice_ctb_addr_rs]) {
517  int ret = cabac_init_decoder(lc);
518  if (ret < 0)
519  return ret;
520  if (s->sh.dependent_slice_segment_flag == 0 ||
521  (s->ps.pps->tiles_enabled_flag &&
522  s->ps.pps->tile_id[ctb_addr_ts] != s->ps.pps->tile_id[ctb_addr_ts - 1]))
523  cabac_init_state(lc, s);
524 
525  if (!s->sh.first_slice_in_pic_flag &&
526  s->ps.pps->entropy_coding_sync_enabled_flag) {
527  if (ctb_addr_ts % s->ps.sps->ctb_width == 0) {
528  if (s->ps.sps->ctb_width == 1)
529  cabac_init_state(lc, s);
530  else if (s->sh.dependent_slice_segment_flag == 1)
531  load_states(lc, s);
532  }
533  }
534  } else {
535  if (s->ps.pps->tiles_enabled_flag &&
536  s->ps.pps->tile_id[ctb_addr_ts] != s->ps.pps->tile_id[ctb_addr_ts - 1]) {
537  int ret;
538  if (s->threads_number == 1)
539  ret = cabac_reinit(lc);
540  else {
541  ret = cabac_init_decoder(lc);
542  }
543  if (ret < 0)
544  return ret;
545  cabac_init_state(lc, s);
546  }
547  if (s->ps.pps->entropy_coding_sync_enabled_flag) {
548  if (ctb_addr_ts % s->ps.sps->ctb_width == 0) {
549  int ret;
550  get_cabac_terminate(&lc->cc);
551  if (s->threads_number == 1)
552  ret = cabac_reinit(lc);
553  else {
554  ret = cabac_init_decoder(lc);
555  }
556  if (ret < 0)
557  return ret;
558 
559  if (s->ps.sps->ctb_width == 1)
560  cabac_init_state(lc, s);
561  else
562  load_states(lc, s);
563  }
564  }
565  }
566  return 0;
567 }
568 
569 #define GET_CABAC(ctx) get_cabac(&lc->cc, &lc->cabac_state[ctx])
570 
572 {
574 }
575 
577 {
579  return 0;
580 
581  if (!get_cabac_bypass(&lc->cc))
582  return SAO_BAND;
583  return SAO_EDGE;
584 }
585 
587 {
588  int i;
589  int value = get_cabac_bypass(&lc->cc);
590 
591  for (i = 0; i < 4; i++)
592  value = (value << 1) | get_cabac_bypass(&lc->cc);
593  return value;
594 }
595 
597 {
598  int i = 0;
599  int length = (1 << (FFMIN(lc->parent->ps.sps->bit_depth, 10) - 5)) - 1;
600 
601  while (i < length && get_cabac_bypass(&lc->cc))
602  i++;
603  return i;
604 }
605 
607 {
608  return get_cabac_bypass(&lc->cc);
609 }
610 
612 {
613  int ret = get_cabac_bypass(&lc->cc) << 1;
614  ret |= get_cabac_bypass(&lc->cc);
615  return ret;
616 }
617 
619 {
620  return get_cabac_terminate(&lc->cc);
621 }
622 
624 {
626 }
627 
628 int ff_hevc_skip_flag_decode(HEVCLocalContext *lc, int x0, int y0, int x_cb, int y_cb)
629 {
630  const HEVCContext *const s = lc->parent;
631  int min_cb_width = s->ps.sps->min_cb_width;
632  int inc = 0;
633  int x0b = av_mod_uintp2(x0, s->ps.sps->log2_ctb_size);
634  int y0b = av_mod_uintp2(y0, s->ps.sps->log2_ctb_size);
635 
636  if (lc->ctb_left_flag || x0b)
637  inc = !!SAMPLE_CTB(s->skip_flag, x_cb - 1, y_cb);
638  if (lc->ctb_up_flag || y0b)
639  inc += !!SAMPLE_CTB(s->skip_flag, x_cb, y_cb - 1);
640 
641  return GET_CABAC(elem_offset[SKIP_FLAG] + inc);
642 }
643 
645 {
646  int prefix_val = 0;
647  int suffix_val = 0;
648  int inc = 0;
649 
650  while (prefix_val < 5 && GET_CABAC(elem_offset[CU_QP_DELTA] + inc)) {
651  prefix_val++;
652  inc = 1;
653  }
654  if (prefix_val >= 5) {
655  int k = 0;
656  while (k < 7 && get_cabac_bypass(&lc->cc)) {
657  suffix_val += 1 << k;
658  k++;
659  }
660  if (k == 7) {
661  av_log(lc->logctx, AV_LOG_ERROR, "CABAC_MAX_BIN : %d\n", k);
662  return AVERROR_INVALIDDATA;
663  }
664 
665  while (k--)
666  suffix_val += get_cabac_bypass(&lc->cc) << k;
667  }
668  return prefix_val + suffix_val;
669 }
670 
672 {
673  return get_cabac_bypass(&lc->cc);
674 }
675 
677 {
679 }
680 
682 {
683  int c_max= FFMAX(5, lc->parent->ps.pps->chroma_qp_offset_list_len_minus1);
684  int i = 0;
685 
686  while (i < c_max && GET_CABAC(elem_offset[CU_CHROMA_QP_OFFSET_IDX]))
687  i++;
688 
689  return i;
690 }
691 
693 {
695 }
696 
697 int ff_hevc_split_coding_unit_flag_decode(HEVCLocalContext *lc, int ct_depth, int x0, int y0)
698 {
699  const HEVCContext *const s = lc->parent;
700  const HEVCSPS *const sps = s->ps.sps;
701  int inc = 0, depth_left = 0, depth_top = 0;
702  int x0b = av_mod_uintp2(x0, sps->log2_ctb_size);
703  int y0b = av_mod_uintp2(y0, sps->log2_ctb_size);
704  int x_cb = x0 >> sps->log2_min_cb_size;
705  int y_cb = y0 >> sps->log2_min_cb_size;
706 
707  if (lc->ctb_left_flag || x0b)
708  depth_left = s->tab_ct_depth[(y_cb) * sps->min_cb_width + x_cb - 1];
709  if (lc->ctb_up_flag || y0b)
710  depth_top = s->tab_ct_depth[(y_cb - 1) * sps->min_cb_width + x_cb];
711 
712  inc += (depth_left > ct_depth);
713  inc += (depth_top > ct_depth);
714 
716 }
717 
718 int ff_hevc_part_mode_decode(HEVCLocalContext *lc, int log2_cb_size)
719 {
720  if (GET_CABAC(elem_offset[PART_MODE])) // 1
721  return PART_2Nx2N;
722  if (log2_cb_size == lc->parent->ps.sps->log2_min_cb_size) {
723  if (lc->cu.pred_mode == MODE_INTRA) // 0
724  return PART_NxN;
725  if (GET_CABAC(elem_offset[PART_MODE] + 1)) // 01
726  return PART_2NxN;
727  if (log2_cb_size == 3) // 00
728  return PART_Nx2N;
729  if (GET_CABAC(elem_offset[PART_MODE] + 2)) // 001
730  return PART_Nx2N;
731  return PART_NxN; // 000
732  }
733 
734  if (!lc->parent->ps.sps->amp_enabled_flag) {
735  if (GET_CABAC(elem_offset[PART_MODE] + 1)) // 01
736  return PART_2NxN;
737  return PART_Nx2N;
738  }
739 
740  if (GET_CABAC(elem_offset[PART_MODE] + 1)) { // 01X, 01XX
741  if (GET_CABAC(elem_offset[PART_MODE] + 3)) // 011
742  return PART_2NxN;
743  if (get_cabac_bypass(&lc->cc)) // 0101
744  return PART_2NxnD;
745  return PART_2NxnU; // 0100
746  }
747 
748  if (GET_CABAC(elem_offset[PART_MODE] + 3)) // 001
749  return PART_Nx2N;
750  if (get_cabac_bypass(&lc->cc)) // 0001
751  return PART_nRx2N;
752  return PART_nLx2N; // 0000
753 }
754 
756 {
757  return get_cabac_terminate(&lc->cc);
758 }
759 
761 {
763 }
764 
766 {
767  int i = 0;
768  while (i < 2 && get_cabac_bypass(&lc->cc))
769  i++;
770  return i;
771 }
772 
774 {
775  int i;
776  int value = get_cabac_bypass(&lc->cc);
777 
778  for (i = 0; i < 4; i++)
779  value = (value << 1) | get_cabac_bypass(&lc->cc);
780  return value;
781 }
782 
784 {
785  int ret;
787  return 4;
788 
789  ret = get_cabac_bypass(&lc->cc) << 1;
790  ret |= get_cabac_bypass(&lc->cc);
791  return ret;
792 }
793 
795 {
797 
798  if (i != 0) {
799  while (i < lc->parent->sh.max_num_merge_cand-1 && get_cabac_bypass(&lc->cc))
800  i++;
801  }
802  return i;
803 }
804 
806 {
808 }
809 
811 {
812  if (nPbW + nPbH == 12)
813  return GET_CABAC(elem_offset[INTER_PRED_IDC] + 4);
815  return PRED_BI;
816 
817  return GET_CABAC(elem_offset[INTER_PRED_IDC] + 4);
818 }
819 
820 int ff_hevc_ref_idx_lx_decode(HEVCLocalContext *lc, int num_ref_idx_lx)
821 {
822  int i = 0;
823  int max = num_ref_idx_lx - 1;
824  int max_ctx = FFMIN(max, 2);
825 
826  while (i < max_ctx && GET_CABAC(elem_offset[REF_IDX_L0] + i))
827  i++;
828  if (i == 2) {
829  while (i < max && get_cabac_bypass(&lc->cc))
830  i++;
831  }
832 
833  return i;
834 }
835 
837 {
839 }
840 
842 {
844 }
845 
847 {
849 }
850 
852 {
854 }
855 
857 {
858  int ret = 2;
859  int k = 1;
860 
861  while (k < CABAC_MAX_BIN && get_cabac_bypass(&lc->cc)) {
862  ret += 1U << k;
863  k++;
864  }
865  if (k == CABAC_MAX_BIN) {
866  av_log(lc->logctx, AV_LOG_ERROR, "CABAC_MAX_BIN : %d\n", k);
867  return 0;
868  }
869  while (k--)
870  ret += get_cabac_bypass(&lc->cc) << k;
871  return get_cabac_bypass_sign(&lc->cc, -ret);
872 }
873 
875 {
876  return get_cabac_bypass_sign(&lc->cc, -1);
877 }
878 
880 {
881  return GET_CABAC(elem_offset[SPLIT_TRANSFORM_FLAG] + 5 - log2_trafo_size);
882 }
883 
885 {
886  return GET_CABAC(elem_offset[CBF_CB_CR] + trafo_depth);
887 }
888 
889 int ff_hevc_cbf_luma_decode(HEVCLocalContext *lc, int trafo_depth)
890 {
891  return GET_CABAC(elem_offset[CBF_LUMA] + !trafo_depth);
892 }
893 
895 {
896  return GET_CABAC(elem_offset[TRANSFORM_SKIP_FLAG] + !!c_idx);
897 }
898 
900 {
901  return GET_CABAC(elem_offset[EXPLICIT_RDPCM_FLAG] + !!c_idx);
902 }
903 
905 {
906  return GET_CABAC(elem_offset[EXPLICIT_RDPCM_DIR_FLAG] + !!c_idx);
907 }
908 
910 {
911  int i =0;
912 
913  while (i < 4 && GET_CABAC(elem_offset[LOG2_RES_SCALE_ABS] + 4 * idx + i))
914  i++;
915 
916  return i;
917 }
918 
920 {
922 }
923 
925  int log2_size, int *last_scx_prefix, int *last_scy_prefix)
926 {
927  int i = 0;
928  int max = (log2_size << 1) - 1;
929  int ctx_offset, ctx_shift;
930 
931  if (!c_idx) {
932  ctx_offset = 3 * (log2_size - 2) + ((log2_size - 1) >> 2);
933  ctx_shift = (log2_size + 1) >> 2;
934  } else {
935  ctx_offset = 15;
936  ctx_shift = log2_size - 2;
937  }
938  while (i < max &&
939  GET_CABAC(elem_offset[LAST_SIGNIFICANT_COEFF_X_PREFIX] + (i >> ctx_shift) + ctx_offset))
940  i++;
941  *last_scx_prefix = i;
942 
943  i = 0;
944  while (i < max &&
945  GET_CABAC(elem_offset[LAST_SIGNIFICANT_COEFF_Y_PREFIX] + (i >> ctx_shift) + ctx_offset))
946  i++;
947  *last_scy_prefix = i;
948 }
949 
951  int last_significant_coeff_prefix)
952 {
953  int i;
954  int length = (last_significant_coeff_prefix >> 1) - 1;
955  int value = get_cabac_bypass(&lc->cc);
956 
957  for (i = 1; i < length; i++)
958  value = (value << 1) | get_cabac_bypass(&lc->cc);
959  return value;
960 }
961 
963 {
964  int inc;
965 
966  inc = FFMIN(ctx_cg, 1) + (c_idx>0 ? 2 : 0);
967 
969 }
971  int offset, const uint8_t *ctx_idx_map)
972 {
973  int inc = ctx_idx_map[(y_c << 2) + x_c] + offset;
975 }
976 
978 {
980 }
981 
983 {
984 
985  if (c_idx > 0)
986  inc += 16;
987 
989 }
990 
992 {
993  if (c_idx > 0)
994  inc += 4;
995 
997 }
998 
1000 {
1001  int prefix = 0;
1002  int suffix = 0;
1003  int last_coeff_abs_level_remaining;
1004  int i;
1005 
1006  while (prefix < CABAC_MAX_BIN && get_cabac_bypass(&lc->cc))
1007  prefix++;
1008 
1009  if (prefix < 3) {
1010  for (i = 0; i < rc_rice_param; i++)
1011  suffix = (suffix << 1) | get_cabac_bypass(&lc->cc);
1012  last_coeff_abs_level_remaining = (prefix << rc_rice_param) + suffix;
1013  } else {
1014  int prefix_minus3 = prefix - 3;
1015 
1016  if (prefix == CABAC_MAX_BIN || prefix_minus3 + rc_rice_param > 16 + 6) {
1017  av_log(lc->logctx, AV_LOG_ERROR, "CABAC_MAX_BIN : %d\n", prefix);
1018  return 0;
1019  }
1020 
1021  for (i = 0; i < prefix_minus3 + rc_rice_param; i++)
1022  suffix = (suffix << 1) | get_cabac_bypass(&lc->cc);
1023  last_coeff_abs_level_remaining = (((1 << prefix_minus3) + 3 - 1)
1024  << rc_rice_param) + suffix;
1025  }
1026  return last_coeff_abs_level_remaining;
1027 }
1028 
1030 {
1031  int i;
1032  int ret = 0;
1033 
1034  for (i = 0; i < nb; i++)
1035  ret = (ret << 1) | get_cabac_bypass(&lc->cc);
1036  return ret;
1037 }
1038 
1040  int log2_trafo_size, enum ScanType scan_idx,
1041  int c_idx)
1042 {
1043 #define GET_COORD(offset, n) \
1044  do { \
1045  x_c = (x_cg << 2) + scan_x_off[n]; \
1046  y_c = (y_cg << 2) + scan_y_off[n]; \
1047  } while (0)
1048  const HEVCContext *const s = lc->parent;
1049  int transform_skip_flag = 0;
1050 
1051  int last_significant_coeff_x, last_significant_coeff_y;
1052  int last_scan_pos;
1053  int n_end;
1054  int num_coeff = 0;
1055  int greater1_ctx = 1;
1056 
1057  int num_last_subset;
1058  int x_cg_last_sig, y_cg_last_sig;
1059 
1060  const uint8_t *scan_x_cg, *scan_y_cg, *scan_x_off, *scan_y_off;
1061 
1062  ptrdiff_t stride = s->frame->linesize[c_idx];
1063  int hshift = s->ps.sps->hshift[c_idx];
1064  int vshift = s->ps.sps->vshift[c_idx];
1065  uint8_t *dst = &s->frame->data[c_idx][(y0 >> vshift) * stride +
1066  ((x0 >> hshift) << s->ps.sps->pixel_shift)];
1067  int16_t *coeffs = (int16_t*)(c_idx ? lc->edge_emu_buffer2 : lc->edge_emu_buffer);
1068  uint8_t significant_coeff_group_flag[8][8] = {{0}};
1069  int explicit_rdpcm_flag = 0;
1070  int explicit_rdpcm_dir_flag;
1071 
1072  int trafo_size = 1 << log2_trafo_size;
1073  int i;
1074  int qp,shift,add,scale,scale_m;
1075  static const uint8_t level_scale[] = { 40, 45, 51, 57, 64, 72 };
1076  const uint8_t *scale_matrix = NULL;
1077  uint8_t dc_scale;
1078  int pred_mode_intra = (c_idx == 0) ? lc->tu.intra_pred_mode :
1079  lc->tu.intra_pred_mode_c;
1080 
1081  memset(coeffs, 0, trafo_size * trafo_size * sizeof(int16_t));
1082 
1083  // Derive QP for dequant
1084  if (!lc->cu.cu_transquant_bypass_flag) {
1085  static const int qp_c[] = { 29, 30, 31, 32, 33, 33, 34, 34, 35, 35, 36, 36, 37, 37 };
1086  static const uint8_t rem6[51 + 4 * 6 + 1] = {
1087  0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2,
1088  3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5,
1089  0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3,
1090  4, 5, 0, 1, 2, 3, 4, 5, 0, 1
1091  };
1092 
1093  static const uint8_t div6[51 + 4 * 6 + 1] = {
1094  0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3,
1095  3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6,
1096  7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10,
1097  10, 10, 11, 11, 11, 11, 11, 11, 12, 12
1098  };
1099  int qp_y = lc->qp_y;
1100 
1101  if (s->ps.pps->transform_skip_enabled_flag &&
1102  log2_trafo_size <= s->ps.pps->log2_max_transform_skip_block_size) {
1103  transform_skip_flag = hevc_transform_skip_flag_decode(lc, c_idx);
1104  }
1105 
1106  if (c_idx == 0) {
1107  qp = qp_y + s->ps.sps->qp_bd_offset;
1108  } else {
1109  int qp_i, offset;
1110 
1111  if (c_idx == 1)
1112  offset = s->ps.pps->cb_qp_offset + s->sh.slice_cb_qp_offset +
1113  lc->tu.cu_qp_offset_cb;
1114  else
1115  offset = s->ps.pps->cr_qp_offset + s->sh.slice_cr_qp_offset +
1116  lc->tu.cu_qp_offset_cr;
1117 
1118  qp_i = av_clip(qp_y + offset, - s->ps.sps->qp_bd_offset, 57);
1119  if (s->ps.sps->chroma_format_idc == 1) {
1120  if (qp_i < 30)
1121  qp = qp_i;
1122  else if (qp_i > 43)
1123  qp = qp_i - 6;
1124  else
1125  qp = qp_c[qp_i - 30];
1126  } else {
1127  if (qp_i > 51)
1128  qp = 51;
1129  else
1130  qp = qp_i;
1131  }
1132 
1133  qp += s->ps.sps->qp_bd_offset;
1134  }
1135 
1136  shift = s->ps.sps->bit_depth + log2_trafo_size - 5;
1137  add = 1 << (shift-1);
1138  scale = level_scale[rem6[qp]] << (div6[qp]);
1139  scale_m = 16; // default when no custom scaling lists.
1140  dc_scale = 16;
1141 
1142  if (s->ps.sps->scaling_list_enable_flag && !(transform_skip_flag && log2_trafo_size > 2)) {
1143  const ScalingList *sl = s->ps.pps->scaling_list_data_present_flag ?
1144  &s->ps.pps->scaling_list : &s->ps.sps->scaling_list;
1145  int matrix_id = lc->cu.pred_mode != MODE_INTRA;
1146 
1147  matrix_id = 3 * matrix_id + c_idx;
1148 
1149  scale_matrix = sl->sl[log2_trafo_size - 2][matrix_id];
1150  if (log2_trafo_size >= 4)
1151  dc_scale = sl->sl_dc[log2_trafo_size - 4][matrix_id];
1152  }
1153  } else {
1154  shift = 0;
1155  add = 0;
1156  scale = 0;
1157  dc_scale = 0;
1158  }
1159 
1160  if (lc->cu.pred_mode == MODE_INTER && s->ps.sps->explicit_rdpcm_enabled_flag &&
1161  (transform_skip_flag || lc->cu.cu_transquant_bypass_flag)) {
1162  explicit_rdpcm_flag = explicit_rdpcm_flag_decode(lc, c_idx);
1163  if (explicit_rdpcm_flag) {
1164  explicit_rdpcm_dir_flag = explicit_rdpcm_dir_flag_decode(lc, c_idx);
1165  }
1166  }
1167 
1168  last_significant_coeff_xy_prefix_decode(lc, c_idx, log2_trafo_size,
1169  &last_significant_coeff_x, &last_significant_coeff_y);
1170 
1171  if (last_significant_coeff_x > 3) {
1172  int suffix = last_significant_coeff_suffix_decode(lc, last_significant_coeff_x);
1173  last_significant_coeff_x = (1 << ((last_significant_coeff_x >> 1) - 1)) *
1174  (2 + (last_significant_coeff_x & 1)) +
1175  suffix;
1176  }
1177 
1178  if (last_significant_coeff_y > 3) {
1179  int suffix = last_significant_coeff_suffix_decode(lc, last_significant_coeff_y);
1180  last_significant_coeff_y = (1 << ((last_significant_coeff_y >> 1) - 1)) *
1181  (2 + (last_significant_coeff_y & 1)) +
1182  suffix;
1183  }
1184 
1185  if (scan_idx == SCAN_VERT)
1186  FFSWAP(int, last_significant_coeff_x, last_significant_coeff_y);
1187 
1188  x_cg_last_sig = last_significant_coeff_x >> 2;
1189  y_cg_last_sig = last_significant_coeff_y >> 2;
1190 
1191  switch (scan_idx) {
1192  case SCAN_DIAG: {
1193  int last_x_c = last_significant_coeff_x & 3;
1194  int last_y_c = last_significant_coeff_y & 3;
1195 
1196  scan_x_off = ff_hevc_diag_scan4x4_x;
1197  scan_y_off = ff_hevc_diag_scan4x4_y;
1198  num_coeff = diag_scan4x4_inv[last_y_c][last_x_c];
1199  if (trafo_size == 4) {
1200  scan_x_cg = scan_1x1;
1201  scan_y_cg = scan_1x1;
1202  } else if (trafo_size == 8) {
1203  num_coeff += diag_scan2x2_inv[y_cg_last_sig][x_cg_last_sig] << 4;
1204  scan_x_cg = diag_scan2x2_x;
1205  scan_y_cg = diag_scan2x2_y;
1206  } else if (trafo_size == 16) {
1207  num_coeff += diag_scan4x4_inv[y_cg_last_sig][x_cg_last_sig] << 4;
1208  scan_x_cg = ff_hevc_diag_scan4x4_x;
1209  scan_y_cg = ff_hevc_diag_scan4x4_y;
1210  } else { // trafo_size == 32
1211  num_coeff += diag_scan8x8_inv[y_cg_last_sig][x_cg_last_sig] << 4;
1212  scan_x_cg = ff_hevc_diag_scan8x8_x;
1213  scan_y_cg = ff_hevc_diag_scan8x8_y;
1214  }
1215  break;
1216  }
1217  case SCAN_HORIZ:
1218  scan_x_cg = horiz_scan2x2_x;
1219  scan_y_cg = horiz_scan2x2_y;
1220  scan_x_off = horiz_scan4x4_x;
1221  scan_y_off = horiz_scan4x4_y;
1222  num_coeff = horiz_scan8x8_inv[last_significant_coeff_y][last_significant_coeff_x];
1223  break;
1224  default: //SCAN_VERT
1225  scan_x_cg = horiz_scan2x2_y;
1226  scan_y_cg = horiz_scan2x2_x;
1227  scan_x_off = horiz_scan4x4_y;
1228  scan_y_off = horiz_scan4x4_x;
1229  num_coeff = horiz_scan8x8_inv[last_significant_coeff_x][last_significant_coeff_y];
1230  break;
1231  }
1232  num_coeff++;
1233  num_last_subset = (num_coeff - 1) >> 4;
1234 
1235  for (i = num_last_subset; i >= 0; i--) {
1236  int n, m;
1237  int x_cg, y_cg, x_c, y_c, pos;
1238  int implicit_non_zero_coeff = 0;
1239  int64_t trans_coeff_level;
1240  int prev_sig = 0;
1241  int offset = i << 4;
1242  int rice_init = 0;
1243 
1244  uint8_t significant_coeff_flag_idx[16];
1245  uint8_t nb_significant_coeff_flag = 0;
1246 
1247  x_cg = scan_x_cg[i];
1248  y_cg = scan_y_cg[i];
1249 
1250  if ((i < num_last_subset) && (i > 0)) {
1251  int ctx_cg = 0;
1252  if (x_cg < (1 << (log2_trafo_size - 2)) - 1)
1253  ctx_cg += significant_coeff_group_flag[x_cg + 1][y_cg];
1254  if (y_cg < (1 << (log2_trafo_size - 2)) - 1)
1255  ctx_cg += significant_coeff_group_flag[x_cg][y_cg + 1];
1256 
1257  significant_coeff_group_flag[x_cg][y_cg] =
1258  significant_coeff_group_flag_decode(lc, c_idx, ctx_cg);
1259  implicit_non_zero_coeff = 1;
1260  } else {
1261  significant_coeff_group_flag[x_cg][y_cg] =
1262  ((x_cg == x_cg_last_sig && y_cg == y_cg_last_sig) ||
1263  (x_cg == 0 && y_cg == 0));
1264  }
1265 
1266  last_scan_pos = num_coeff - offset - 1;
1267 
1268  if (i == num_last_subset) {
1269  n_end = last_scan_pos - 1;
1270  significant_coeff_flag_idx[0] = last_scan_pos;
1271  nb_significant_coeff_flag = 1;
1272  } else {
1273  n_end = 15;
1274  }
1275 
1276  if (x_cg < ((1 << log2_trafo_size) - 1) >> 2)
1277  prev_sig = !!significant_coeff_group_flag[x_cg + 1][y_cg];
1278  if (y_cg < ((1 << log2_trafo_size) - 1) >> 2)
1279  prev_sig += (!!significant_coeff_group_flag[x_cg][y_cg + 1] << 1);
1280 
1281  if (significant_coeff_group_flag[x_cg][y_cg] && n_end >= 0) {
1282  static const uint8_t ctx_idx_map[] = {
1283  0, 1, 4, 5, 2, 3, 4, 5, 6, 6, 8, 8, 7, 7, 8, 8, // log2_trafo_size == 2
1284  1, 1, 1, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, // prev_sig == 0
1285  2, 2, 2, 2, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, // prev_sig == 1
1286  2, 1, 0, 0, 2, 1, 0, 0, 2, 1, 0, 0, 2, 1, 0, 0, // prev_sig == 2
1287  2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 // default
1288  };
1289  const uint8_t *ctx_idx_map_p;
1290  int scf_offset = 0;
1291  if (s->ps.sps->transform_skip_context_enabled_flag &&
1292  (transform_skip_flag || lc->cu.cu_transquant_bypass_flag)) {
1293  ctx_idx_map_p = &ctx_idx_map[4 * 16];
1294  if (c_idx == 0) {
1295  scf_offset = 40;
1296  } else {
1297  scf_offset = 14 + 27;
1298  }
1299  } else {
1300  if (c_idx != 0)
1301  scf_offset = 27;
1302  if (log2_trafo_size == 2) {
1303  ctx_idx_map_p = &ctx_idx_map[0];
1304  } else {
1305  ctx_idx_map_p = &ctx_idx_map[(prev_sig + 1) << 4];
1306  if (c_idx == 0) {
1307  if ((x_cg > 0 || y_cg > 0))
1308  scf_offset += 3;
1309  if (log2_trafo_size == 3) {
1310  scf_offset += (scan_idx == SCAN_DIAG) ? 9 : 15;
1311  } else {
1312  scf_offset += 21;
1313  }
1314  } else {
1315  if (log2_trafo_size == 3)
1316  scf_offset += 9;
1317  else
1318  scf_offset += 12;
1319  }
1320  }
1321  }
1322  for (n = n_end; n > 0; n--) {
1323  x_c = scan_x_off[n];
1324  y_c = scan_y_off[n];
1325  if (significant_coeff_flag_decode(lc, x_c, y_c, scf_offset, ctx_idx_map_p)) {
1326  significant_coeff_flag_idx[nb_significant_coeff_flag] = n;
1327  nb_significant_coeff_flag++;
1328  implicit_non_zero_coeff = 0;
1329  }
1330  }
1331  if (implicit_non_zero_coeff == 0) {
1332  if (s->ps.sps->transform_skip_context_enabled_flag &&
1333  (transform_skip_flag || lc->cu.cu_transquant_bypass_flag)) {
1334  if (c_idx == 0) {
1335  scf_offset = 42;
1336  } else {
1337  scf_offset = 16 + 27;
1338  }
1339  } else {
1340  if (i == 0) {
1341  if (c_idx == 0)
1342  scf_offset = 0;
1343  else
1344  scf_offset = 27;
1345  } else {
1346  scf_offset = 2 + scf_offset;
1347  }
1348  }
1349  if (significant_coeff_flag_decode_0(lc, c_idx, scf_offset) == 1) {
1350  significant_coeff_flag_idx[nb_significant_coeff_flag] = 0;
1351  nb_significant_coeff_flag++;
1352  }
1353  } else {
1354  significant_coeff_flag_idx[nb_significant_coeff_flag] = 0;
1355  nb_significant_coeff_flag++;
1356  }
1357  }
1358 
1359  n_end = nb_significant_coeff_flag;
1360 
1361 
1362  if (n_end) {
1363  int first_nz_pos_in_cg;
1364  int last_nz_pos_in_cg;
1365  int c_rice_param = 0;
1366  int first_greater1_coeff_idx = -1;
1367  uint8_t coeff_abs_level_greater1_flag[8];
1368  uint16_t coeff_sign_flag;
1369  int sum_abs = 0;
1370  int sign_hidden;
1371  int sb_type;
1372 
1373 
1374  // initialize first elem of coeff_bas_level_greater1_flag
1375  int ctx_set = (i > 0 && c_idx == 0) ? 2 : 0;
1376 
1377  if (s->ps.sps->persistent_rice_adaptation_enabled_flag) {
1378  if (!transform_skip_flag && !lc->cu.cu_transquant_bypass_flag)
1379  sb_type = 2 * (c_idx == 0 ? 1 : 0);
1380  else
1381  sb_type = 2 * (c_idx == 0 ? 1 : 0) + 1;
1382  c_rice_param = lc->stat_coeff[sb_type] / 4;
1383  }
1384 
1385  if (!(i == num_last_subset) && greater1_ctx == 0)
1386  ctx_set++;
1387  greater1_ctx = 1;
1388  last_nz_pos_in_cg = significant_coeff_flag_idx[0];
1389 
1390  for (m = 0; m < (n_end > 8 ? 8 : n_end); m++) {
1391  int inc = (ctx_set << 2) + greater1_ctx;
1392  coeff_abs_level_greater1_flag[m] =
1393  coeff_abs_level_greater1_flag_decode(lc, c_idx, inc);
1394  if (coeff_abs_level_greater1_flag[m]) {
1395  greater1_ctx = 0;
1396  if (first_greater1_coeff_idx == -1)
1397  first_greater1_coeff_idx = m;
1398  } else if (greater1_ctx > 0 && greater1_ctx < 3) {
1399  greater1_ctx++;
1400  }
1401  }
1402  first_nz_pos_in_cg = significant_coeff_flag_idx[n_end - 1];
1403 
1404  if (lc->cu.cu_transquant_bypass_flag ||
1405  (lc->cu.pred_mode == MODE_INTRA &&
1406  s->ps.sps->implicit_rdpcm_enabled_flag && transform_skip_flag &&
1407  (pred_mode_intra == 10 || pred_mode_intra == 26 )) ||
1408  explicit_rdpcm_flag)
1409  sign_hidden = 0;
1410  else
1411  sign_hidden = (last_nz_pos_in_cg - first_nz_pos_in_cg >= 4);
1412 
1413  if (first_greater1_coeff_idx != -1) {
1414  coeff_abs_level_greater1_flag[first_greater1_coeff_idx] += coeff_abs_level_greater2_flag_decode(lc, c_idx, ctx_set);
1415  }
1416  if (!s->ps.pps->sign_data_hiding_flag || !sign_hidden ) {
1417  coeff_sign_flag = coeff_sign_flag_decode(lc, nb_significant_coeff_flag) << (16 - nb_significant_coeff_flag);
1418  } else {
1419  coeff_sign_flag = coeff_sign_flag_decode(lc, nb_significant_coeff_flag - 1) << (16 - (nb_significant_coeff_flag - 1));
1420  }
1421 
1422  for (m = 0; m < n_end; m++) {
1423  n = significant_coeff_flag_idx[m];
1424  GET_COORD(offset, n);
1425  if (m < 8) {
1426  trans_coeff_level = 1 + coeff_abs_level_greater1_flag[m];
1427  if (trans_coeff_level == ((m == first_greater1_coeff_idx) ? 3 : 2)) {
1428  int last_coeff_abs_level_remaining = coeff_abs_level_remaining_decode(lc, c_rice_param);
1429 
1430  trans_coeff_level += last_coeff_abs_level_remaining;
1431  if (trans_coeff_level > (3 << c_rice_param))
1432  c_rice_param = s->ps.sps->persistent_rice_adaptation_enabled_flag ? c_rice_param + 1 : FFMIN(c_rice_param + 1, 4);
1433  if (s->ps.sps->persistent_rice_adaptation_enabled_flag && !rice_init) {
1434  int c_rice_p_init = lc->stat_coeff[sb_type] / 4;
1435  if (last_coeff_abs_level_remaining >= (3 << c_rice_p_init))
1436  lc->stat_coeff[sb_type]++;
1437  else if (2 * last_coeff_abs_level_remaining < (1 << c_rice_p_init))
1438  if (lc->stat_coeff[sb_type] > 0)
1439  lc->stat_coeff[sb_type]--;
1440  rice_init = 1;
1441  }
1442  }
1443  } else {
1444  int last_coeff_abs_level_remaining = coeff_abs_level_remaining_decode(lc, c_rice_param);
1445 
1446  trans_coeff_level = 1 + last_coeff_abs_level_remaining;
1447  if (trans_coeff_level > (3 << c_rice_param))
1448  c_rice_param = s->ps.sps->persistent_rice_adaptation_enabled_flag ? c_rice_param + 1 : FFMIN(c_rice_param + 1, 4);
1449  if (s->ps.sps->persistent_rice_adaptation_enabled_flag && !rice_init) {
1450  int c_rice_p_init = lc->stat_coeff[sb_type] / 4;
1451  if (last_coeff_abs_level_remaining >= (3 << c_rice_p_init))
1452  lc->stat_coeff[sb_type]++;
1453  else if (2 * last_coeff_abs_level_remaining < (1 << c_rice_p_init))
1454  if (lc->stat_coeff[sb_type] > 0)
1455  lc->stat_coeff[sb_type]--;
1456  rice_init = 1;
1457  }
1458  }
1459  if (s->ps.pps->sign_data_hiding_flag && sign_hidden) {
1460  sum_abs += trans_coeff_level;
1461  if (n == first_nz_pos_in_cg && (sum_abs&1))
1462  trans_coeff_level = -trans_coeff_level;
1463  }
1464  if (coeff_sign_flag >> 15)
1465  trans_coeff_level = -trans_coeff_level;
1466  coeff_sign_flag <<= 1;
1467  if(!lc->cu.cu_transquant_bypass_flag) {
1468  if (s->ps.sps->scaling_list_enable_flag && !(transform_skip_flag && log2_trafo_size > 2)) {
1469  if(y_c || x_c || log2_trafo_size < 4) {
1470  switch(log2_trafo_size) {
1471  case 3: pos = (y_c << 3) + x_c; break;
1472  case 4: pos = ((y_c >> 1) << 3) + (x_c >> 1); break;
1473  case 5: pos = ((y_c >> 2) << 3) + (x_c >> 2); break;
1474  default: pos = (y_c << 2) + x_c; break;
1475  }
1476  scale_m = scale_matrix[pos];
1477  } else {
1478  scale_m = dc_scale;
1479  }
1480  }
1481  trans_coeff_level = (trans_coeff_level * (int64_t)scale * (int64_t)scale_m + add) >> shift;
1482  if(trans_coeff_level < 0) {
1483  if((~trans_coeff_level) & 0xFffffffffff8000)
1484  trans_coeff_level = -32768;
1485  } else {
1486  if(trans_coeff_level & 0xffffffffffff8000)
1487  trans_coeff_level = 32767;
1488  }
1489  }
1490  coeffs[y_c * trafo_size + x_c] = trans_coeff_level;
1491  }
1492  }
1493  }
1494 
1495  if (lc->cu.cu_transquant_bypass_flag) {
1496  if (explicit_rdpcm_flag || (s->ps.sps->implicit_rdpcm_enabled_flag &&
1497  (pred_mode_intra == 10 || pred_mode_intra == 26))) {
1498  int mode = s->ps.sps->implicit_rdpcm_enabled_flag ? (pred_mode_intra == 26) : explicit_rdpcm_dir_flag;
1499 
1500  s->hevcdsp.transform_rdpcm(coeffs, log2_trafo_size, mode);
1501  }
1502  } else {
1503  if (transform_skip_flag) {
1504  int rot = s->ps.sps->transform_skip_rotation_enabled_flag &&
1505  log2_trafo_size == 2 &&
1506  lc->cu.pred_mode == MODE_INTRA;
1507  if (rot) {
1508  for (i = 0; i < 8; i++)
1509  FFSWAP(int16_t, coeffs[i], coeffs[16 - i - 1]);
1510  }
1511 
1512  s->hevcdsp.dequant(coeffs, log2_trafo_size);
1513 
1514  if (explicit_rdpcm_flag || (s->ps.sps->implicit_rdpcm_enabled_flag &&
1515  lc->cu.pred_mode == MODE_INTRA &&
1516  (pred_mode_intra == 10 || pred_mode_intra == 26))) {
1517  int mode = explicit_rdpcm_flag ? explicit_rdpcm_dir_flag : (pred_mode_intra == 26);
1518 
1519  s->hevcdsp.transform_rdpcm(coeffs, log2_trafo_size, mode);
1520  }
1521  } else if (lc->cu.pred_mode == MODE_INTRA && c_idx == 0 && log2_trafo_size == 2) {
1522  s->hevcdsp.transform_4x4_luma(coeffs);
1523  } else {
1524  int max_xy = FFMAX(last_significant_coeff_x, last_significant_coeff_y);
1525  if (max_xy == 0)
1526  s->hevcdsp.idct_dc[log2_trafo_size - 2](coeffs);
1527  else {
1528  int col_limit = last_significant_coeff_x + last_significant_coeff_y + 4;
1529  if (max_xy < 4)
1530  col_limit = FFMIN(4, col_limit);
1531  else if (max_xy < 8)
1532  col_limit = FFMIN(8, col_limit);
1533  else if (max_xy < 12)
1534  col_limit = FFMIN(24, col_limit);
1535  s->hevcdsp.idct[log2_trafo_size - 2](coeffs, col_limit);
1536  }
1537  }
1538  }
1539  if (lc->tu.cross_pf) {
1540  int16_t *coeffs_y = (int16_t*)lc->edge_emu_buffer;
1541 
1542  for (i = 0; i < (trafo_size * trafo_size); i++) {
1543  coeffs[i] = coeffs[i] + ((lc->tu.res_scale_val * coeffs_y[i]) >> 3);
1544  }
1545  }
1546  s->hevcdsp.add_residual[log2_trafo_size-2](dst, coeffs, stride);
1547 }
1548 
1549 void ff_hevc_hls_mvd_coding(HEVCLocalContext *lc, int x0, int y0, int log2_cb_size)
1550 {
1551  int x = abs_mvd_greater0_flag_decode(lc);
1552  int y = abs_mvd_greater0_flag_decode(lc);
1553 
1554  if (x)
1556  if (y)
1558 
1559  switch (x) {
1560  case 2: lc->pu.mvd.x = mvd_decode(lc); break;
1561  case 1: lc->pu.mvd.x = mvd_sign_flag_decode(lc); break;
1562  case 0: lc->pu.mvd.x = 0; break;
1563  }
1564 
1565  switch (y) {
1566  case 2: lc->pu.mvd.y = mvd_decode(lc); break;
1567  case 1: lc->pu.mvd.y = mvd_sign_flag_decode(lc); break;
1568  case 0: lc->pu.mvd.y = 0; break;
1569  }
1570 }
1571 
ff_hevc_sao_offset_sign_decode
int ff_hevc_sao_offset_sign_decode(HEVCLocalContext *lc)
Definition: hevc_cabac.c:606
CNU
#define CNU
Definition: hevc_cabac.c:144
HEVCSPS::log2_min_cb_size
unsigned int log2_min_cb_size
Definition: hevc_ps.h:192
SAO_TYPE_IDX
@ SAO_TYPE_IDX
Definition: hevcdec.h:91
HEVCLocalContext
Definition: hevcdec.h:432
ff_hevc_hls_residual_coding
void ff_hevc_hls_residual_coding(HEVCLocalContext *lc, int x0, int y0, int log2_trafo_size, enum ScanType scan_idx, int c_idx)
Definition: hevc_cabac.c:1039
ff_hevc_skip_flag_decode
int ff_hevc_skip_flag_decode(HEVCLocalContext *lc, int x0, int y0, int x_cb, int y_cb)
Definition: hevc_cabac.c:628
diag_scan2x2_x
static const uint8_t diag_scan2x2_x[4]
Definition: hevc_cabac.c:419
ff_hevc_cu_chroma_qp_offset_idx
int ff_hevc_cu_chroma_qp_offset_idx(HEVCLocalContext *lc)
Definition: hevc_cabac.c:681
mvd_sign_flag_decode
static av_always_inline int mvd_sign_flag_decode(HEVCLocalContext *lc)
Definition: hevc_cabac.c:874
av_clip
#define av_clip
Definition: common.h:95
ff_hevc_pcm_flag_decode
int ff_hevc_pcm_flag_decode(HEVCLocalContext *lc)
Definition: hevc_cabac.c:755
SPLIT_CODING_UNIT_FLAG
@ SPLIT_CODING_UNIT_FLAG
Definition: hevcdec.h:97
get_bits_left
static int get_bits_left(GetBitContext *gb)
Definition: get_bits.h:664
PART_NxN
@ PART_NxN
Definition: hevcdec.h:145
SAO_BAND
@ SAO_BAND
Definition: hevcdec.h:211
ff_hevc_pred_mode_decode
int ff_hevc_pred_mode_decode(HEVCLocalContext *lc)
Definition: hevc_cabac.c:692
ff_hevc_diag_scan8x8_y
const uint8_t ff_hevc_diag_scan8x8_y[64]
Definition: hevc_data.c:58
HEVCSPS::bit_depth
int bit_depth
Definition: hevc_ps.h:149
HEVCLocalContext::ctb_up_flag
uint8_t ctb_up_flag
Definition: hevcdec.h:465
get_bits_count
static int get_bits_count(const GetBitContext *s)
Definition: get_bits.h:256
PART_2NxnU
@ PART_2NxnU
Definition: hevcdec.h:146
av_mod_uintp2
#define av_mod_uintp2
Definition: common.h:122
ScanType
ScanType
Definition: hevcdec.h:223
ff_hevc_cu_transquant_bypass_flag_decode
int ff_hevc_cu_transquant_bypass_flag_decode(HEVCLocalContext *lc)
Definition: hevc_cabac.c:623
significant_coeff_group_flag_decode
static av_always_inline int significant_coeff_group_flag_decode(HEVCLocalContext *lc, int c_idx, int ctx_cg)
Definition: hevc_cabac.c:962
num_bins_in_se
static const int8_t num_bins_in_se[]
number of bin by SyntaxElement.
Definition: hevc_cabac.c:37
LAST_SIGNIFICANT_COEFF_X_PREFIX
@ LAST_SIGNIFICANT_COEFF_X_PREFIX
Definition: hevcdec.h:125
Mv::y
int16_t y
vertical component of motion vector
Definition: hevcdec.h:344
CU_CHROMA_QP_OFFSET_FLAG
@ CU_CHROMA_QP_OFFSET_FLAG
Definition: hevcdec.h:137
SAO_EDGE
@ SAO_EDGE
Definition: hevcdec.h:212
ScalingList::sl
uint8_t sl[4][6][64]
Definition: hevc_ps.h:136
ff_hevc_intra_chroma_pred_mode_decode
int ff_hevc_intra_chroma_pred_mode_decode(HEVCLocalContext *lc)
Definition: hevc_cabac.c:783
MODE_INTRA
@ MODE_INTRA
Definition: hevcdec.h:154
get_cabac_bypass_sign
#define get_cabac_bypass_sign
Definition: cabac.h:193
max
#define max(a, b)
Definition: cuda_runtime.h:33
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
INTER_PRED_IDC
@ INTER_PRED_IDC
Definition: hevcdec.h:110
CBF_CB_CR
@ CBF_CB_CR
Definition: hevcdec.h:121
init_values
static const uint8_t init_values[3][HEVC_CONTEXTS]
Indexed by init_type.
Definition: hevc_cabac.c:148
ff_hevc_cu_qp_delta_sign_flag
int ff_hevc_cu_qp_delta_sign_flag(HEVCLocalContext *lc)
Definition: hevc_cabac.c:671
COEFF_ABS_LEVEL_GREATER2_FLAG
@ COEFF_ABS_LEVEL_GREATER2_FLAG
Definition: hevcdec.h:132
skip_bits
static void skip_bits(GetBitContext *s, int n)
Definition: get_bits.h:371
CBF_LUMA
@ CBF_LUMA
Definition: hevcdec.h:120
PART_2Nx2N
@ PART_2Nx2N
Definition: hevcdec.h:142
HEVCLocalContext::common_cabac_state
HEVCCABACState * common_cabac_state
This is a pointer to the common CABAC state.
Definition: hevcdec.h:455
PRED_BI
@ PRED_BI
Definition: hevcdec.h:161
ff_hevc_log2_res_scale_abs
int ff_hevc_log2_res_scale_abs(HEVCLocalContext *lc, int idx)
Definition: hevc_cabac.c:909
ff_hevc_hls_mvd_coding
void ff_hevc_hls_mvd_coding(HEVCLocalContext *lc, int x0, int y0, int log2_cb_size)
Definition: hevc_cabac.c:1549
MVP_LX_FLAG
@ MVP_LX_FLAG
Definition: hevcdec.h:117
explicit_rdpcm_flag_decode
static int explicit_rdpcm_flag_decode(HEVCLocalContext *lc, int c_idx)
Definition: hevc_cabac.c:899
MODE_INTER
@ MODE_INTER
Definition: hevcdec.h:153
GetBitContext
Definition: get_bits.h:107
HEVCLocalContext::pu
PredictionUnit pu
Definition: hevcdec.h:478
ff_hevc_cu_chroma_qp_offset_flag
int ff_hevc_cu_chroma_qp_offset_flag(HEVCLocalContext *lc)
Definition: hevc_cabac.c:676
TransformUnit::res_scale_val
int res_scale_val
Definition: hevcdec.h:375
LOG2_RES_SCALE_ABS
@ LOG2_RES_SCALE_ABS
Definition: hevcdec.h:135
scale
static av_always_inline float scale(float x, float s)
Definition: vf_v360.c:1389
MERGE_IDX
@ MERGE_IDX
Definition: hevcdec.h:109
cabac_init_decoder
static int cabac_init_decoder(HEVCLocalContext *lc)
Definition: hevc_cabac.c:478
last_significant_coeff_suffix_decode
static av_always_inline int last_significant_coeff_suffix_decode(HEVCLocalContext *lc, int last_significant_coeff_prefix)
Definition: hevc_cabac.c:950
SKIP_FLAG
@ SKIP_FLAG
Definition: hevcdec.h:99
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:378
hevc_transform_skip_flag_decode
static int hevc_transform_skip_flag_decode(HEVCLocalContext *lc, int c_idx)
Definition: hevc_cabac.c:894
ff_hevc_rem_intra_luma_pred_mode_decode
int ff_hevc_rem_intra_luma_pred_mode_decode(HEVCLocalContext *lc)
Definition: hevc_cabac.c:773
ff_hevc_sao_merge_flag_decode
int ff_hevc_sao_merge_flag_decode(HEVCLocalContext *lc)
Definition: hevc_cabac.c:571
HEVCLocalContext::parent
const struct HEVCContext * parent
Definition: hevcdec.h:440
s
#define s(width, name)
Definition: cbs_vp9.c:256
MERGE_FLAG
@ MERGE_FLAG
Definition: hevcdec.h:108
load_states
static void load_states(HEVCLocalContext *lc, const HEVCContext *s)
Definition: hevc_cabac.c:465
ff_hevc_diag_scan8x8_x
const uint8_t ff_hevc_diag_scan8x8_x[64]
Definition: hevc_data.c:39
PREV_INTRA_LUMA_PRED_FLAG
@ PREV_INTRA_LUMA_PRED_FLAG
Definition: hevcdec.h:104
diag_scan2x2_inv
static const uint8_t diag_scan2x2_inv[2][2]
Definition: hevc_cabac.c:427
abs_mvd_greater1_flag_decode
static av_always_inline int abs_mvd_greater1_flag_decode(HEVCLocalContext *lc)
Definition: hevc_cabac.c:851
HEVC_SLICE_I
@ HEVC_SLICE_I
Definition: hevc.h:98
ff_hevc_cabac_init
int ff_hevc_cabac_init(HEVCLocalContext *lc, int ctb_addr_ts)
Definition: hevc_cabac.c:512
ScalingList
Definition: hevc_ps.h:133
if
if(ret)
Definition: filter_design.txt:179
ff_hevc_cbf_cb_cr_decode
int ff_hevc_cbf_cb_cr_decode(HEVCLocalContext *lc, int trafo_depth)
Definition: hevc_cabac.c:884
ff_hevc_diag_scan4x4_y
const uint8_t ff_hevc_diag_scan4x4_y[16]
Definition: hevc_data.c:32
PART_MODE
@ PART_MODE
Definition: hevcdec.h:102
elem_offset
static const int elem_offset[sizeof(num_bins_in_se)]
Offset to ctxIdx 0 in init_values and states, indexed by SyntaxElement.
Definition: hevc_cabac.c:92
GetBitContext::buffer
const uint8_t * buffer
Definition: get_bits.h:108
PRED_MODE_FLAG
@ PRED_MODE_FLAG
Definition: hevcdec.h:101
HEVCCABACState::state
uint8_t state[HEVC_CONTEXTS]
Definition: hevcdec.h:230
NULL
#define NULL
Definition: coverity.c:32
ScalingList::sl_dc
uint8_t sl_dc[2][6]
Definition: hevc_ps.h:137
EXPLICIT_RDPCM_FLAG
@ EXPLICIT_RDPCM_FLAG
Definition: hevcdec.h:123
CodingUnit::cu_transquant_bypass_flag
uint8_t cu_transquant_bypass_flag
Definition: hevcdec.h:339
cabac_init_state
static void cabac_init_state(HEVCLocalContext *lc, const HEVCContext *s)
Definition: hevc_cabac.c:488
COEFF_ABS_LEVEL_GREATER1_FLAG
@ COEFF_ABS_LEVEL_GREATER1_FLAG
Definition: hevcdec.h:131
ff_hevc_sao_band_position_decode
int ff_hevc_sao_band_position_decode(HEVCLocalContext *lc)
Definition: hevc_cabac.c:586
CABAC_MAX_BIN
#define CABAC_MAX_BIN
Definition: hevc_cabac.c:32
PART_Nx2N
@ PART_Nx2N
Definition: hevcdec.h:144
ff_hevc_split_coding_unit_flag_decode
int ff_hevc_split_coding_unit_flag_decode(HEVCLocalContext *lc, int ct_depth, int x0, int y0)
Definition: hevc_cabac.c:697
Mv::x
int16_t x
horizontal component of motion vector
Definition: hevcdec.h:343
ff_hevc_no_residual_syntax_flag_decode
int ff_hevc_no_residual_syntax_flag_decode(HEVCLocalContext *lc)
Definition: hevc_cabac.c:841
SAMPLE_CTB
#define SAMPLE_CTB(tab, x, y)
Definition: hevcdec.h:73
coeff_abs_level_remaining_decode
static av_always_inline int coeff_abs_level_remaining_decode(HEVCLocalContext *lc, int rc_rice_param)
Definition: hevc_cabac.c:999
SCAN_HORIZ
@ SCAN_HORIZ
Definition: hevcdec.h:225
hevc_data.h
HEVCLocalContext::edge_emu_buffer
uint8_t edge_emu_buffer[(MAX_PB_SIZE+7) *EDGE_EMU_BUFFER_STRIDE *2]
Definition: hevcdec.h:471
PART_nLx2N
@ PART_nLx2N
Definition: hevcdec.h:148
NO_RESIDUAL_DATA_FLAG
@ NO_RESIDUAL_DATA_FLAG
Definition: hevcdec.h:118
cabac_reinit
static int cabac_reinit(HEVCLocalContext *lc)
Definition: hevc_cabac.c:473
HEVCLocalContext::ctb_left_flag
uint8_t ctb_left_flag
Definition: hevcdec.h:464
ff_hevc_res_scale_sign_flag
int ff_hevc_res_scale_sign_flag(HEVCLocalContext *lc, int idx)
Definition: hevc_cabac.c:919
ff_hevc_merge_idx_decode
int ff_hevc_merge_idx_decode(HEVCLocalContext *lc)
Definition: hevc_cabac.c:794
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: hevc_cabac.c:924
hevcdec.h
shift
static int shift(int a, int b)
Definition: bonk.c:257
diag_scan2x2_y
static const uint8_t diag_scan2x2_y[4]
Definition: hevc_cabac.c:423
SIGNIFICANT_COEFF_FLAG
@ SIGNIFICANT_COEFF_FLAG
Definition: hevcdec.h:130
SPLIT_TRANSFORM_FLAG
@ SPLIT_TRANSFORM_FLAG
Definition: hevcdec.h:119
for
for(k=2;k<=8;++k)
Definition: h264pred_template.c:425
HEVCLocalContext::cabac_state
uint8_t cabac_state[HEVC_CONTEXTS]
Definition: hevcdec.h:433
PART_2NxnD
@ PART_2NxnD
Definition: hevcdec.h:147
SCAN_VERT
@ SCAN_VERT
Definition: hevcdec.h:226
get_cabac_bypass
#define get_cabac_bypass
Definition: cabac.h:149
ff_hevc_cbf_luma_decode
int ff_hevc_cbf_luma_decode(HEVCLocalContext *lc, int trafo_depth)
Definition: hevc_cabac.c:889
ff_hevc_prev_intra_luma_pred_flag_decode
int ff_hevc_prev_intra_luma_pred_flag_decode(HEVCLocalContext *lc)
Definition: hevc_cabac.c:760
CU_QP_DELTA
@ CU_QP_DELTA
Definition: hevcdec.h:100
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: hevc_cabac.c:970
horiz_scan2x2_y
static const uint8_t horiz_scan2x2_y[4]
Definition: hevc_cabac.c:390
ff_hevc_end_of_slice_flag_decode
int ff_hevc_end_of_slice_flag_decode(HEVCLocalContext *lc)
Definition: hevc_cabac.c:618
HEVCPPS::chroma_qp_offset_list_len_minus1
uint8_t chroma_qp_offset_list_len_minus1
Definition: hevc_ps.h:290
ABS_MVD_GREATER0_FLAG
@ ABS_MVD_GREATER0_FLAG
Definition: hevcdec.h:113
HEVC_STAT_COEFFS
#define HEVC_STAT_COEFFS
Definition: hevcdec.h:53
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
SIGNIFICANT_COEFF_GROUP_FLAG
@ SIGNIFICANT_COEFF_GROUP_FLAG
Definition: hevcdec.h:129
HEVCContext::ps
HEVCParamSets ps
Definition: hevcdec.h:511
TransformUnit::cu_qp_offset_cb
int8_t cu_qp_offset_cb
Definition: hevcdec.h:383
TRANSFORM_SKIP_FLAG
@ TRANSFORM_SKIP_FLAG
Definition: hevcdec.h:122
CU_TRANSQUANT_BYPASS_FLAG
@ CU_TRANSQUANT_BYPASS_FLAG
Definition: hevcdec.h:98
HEVCLocalContext::ct_depth
int ct_depth
Definition: hevcdec.h:476
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
scan_1x1
static const uint8_t scan_1x1[1]
Definition: hevc_cabac.c:382
PART_nRx2N
@ PART_nRx2N
Definition: hevcdec.h:149
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:269
HEVCLocalContext::gb
GetBitContext gb
Definition: hevcdec.h:442
HEVCParamSets::sps
const HEVCSPS * sps
Definition: hevc_ps.h:321
HEVCLocalContext::logctx
void * logctx
Definition: hevcdec.h:439
common.h
horiz_scan4x4_y
static const uint8_t horiz_scan4x4_y[16]
Definition: hevc_cabac.c:401
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
REF_IDX_L0
@ REF_IDX_L0
Definition: hevcdec.h:111
HEVCSPS::amp_enabled_flag
uint8_t amp_enabled_flag
Definition: hevc_ps.h:174
cabac_functions.h
ff_hevc_sao_eo_class_decode
int ff_hevc_sao_eo_class_decode(HEVCLocalContext *lc)
Definition: hevc_cabac.c:611
HEVCLocalContext::qp_y
int8_t qp_y
Definition: hevcdec.h:457
ff_hevc_cu_qp_delta_abs
int ff_hevc_cu_qp_delta_abs(HEVCLocalContext *lc)
Definition: hevc_cabac.c:644
HEVCLocalContext::stat_coeff
uint8_t stat_coeff[HEVC_STAT_COEFFS]
Definition: hevcdec.h:435
hevc.h
stride
#define stride
Definition: h264pred_template.c:537
ret
ret
Definition: filter_design.txt:187
FFSWAP
#define FFSWAP(type, a, b)
Definition: macros.h:52
PredictionUnit::mvd
Mv mvd
Definition: hevcdec.h:366
RES_SCALE_SIGN_FLAG
@ RES_SCALE_SIGN_FLAG
Definition: hevcdec.h:136
HEVCLocalContext::edge_emu_buffer2
uint8_t edge_emu_buffer2[(MAX_PB_SIZE+7) *EDGE_EMU_BUFFER_STRIDE *2]
Definition: hevcdec.h:473
sps
static int FUNC() sps(CodedBitstreamContext *ctx, RWContext *rw, H264RawSPS *current)
Definition: cbs_h264_syntax_template.c:260
align_get_bits
static const uint8_t * align_get_bits(GetBitContext *s)
Definition: get_bits.h:540
ff_hevc_save_states
void ff_hevc_save_states(HEVCLocalContext *lc, int ctb_addr_ts)
Definition: hevc_cabac.c:450
pos
unsigned int pos
Definition: spdifenc.c:413
GET_CABAC
#define GET_CABAC(ctx)
Definition: hevc_cabac.c:569
U
#define U(x)
Definition: vpx_arith.h:37
suffix
const char * suffix
Definition: checkasm.c:220
ff_hevc_mvp_lx_flag_decode
int ff_hevc_mvp_lx_flag_decode(HEVCLocalContext *lc)
Definition: hevc_cabac.c:836
horiz_scan2x2_x
static const uint8_t horiz_scan2x2_x[4]
Definition: hevc_cabac.c:386
explicit_rdpcm_dir_flag_decode
static int explicit_rdpcm_dir_flag_decode(HEVCLocalContext *lc, int c_idx)
Definition: hevc_cabac.c:904
GET_COORD
#define GET_COORD(offset, n)
mode
mode
Definition: ebur128.h:83
HEVCContext
Definition: hevcdec.h:490
mvd_decode
static av_always_inline int mvd_decode(HEVCLocalContext *lc)
Definition: hevc_cabac.c:856
CodingUnit::pred_mode
enum PredMode pred_mode
PredMode.
Definition: hevcdec.h:333
significant_coeff_flag_decode_0
static av_always_inline int significant_coeff_flag_decode_0(HEVCLocalContext *lc, int c_idx, int offset)
Definition: hevc_cabac.c:977
horiz_scan8x8_inv
static const uint8_t horiz_scan8x8_inv[8][8]
Definition: hevc_cabac.c:408
SCAN_DIAG
@ SCAN_DIAG
Definition: hevcdec.h:224
ff_hevc_mpm_idx_decode
int ff_hevc_mpm_idx_decode(HEVCLocalContext *lc)
Definition: hevc_cabac.c:765
HEVCParamSets::pps
const HEVCPPS * pps
Definition: hevc_ps.h:322
ABS_MVD_GREATER1_FLAG
@ ABS_MVD_GREATER1_FLAG
Definition: hevcdec.h:114
ff_hevc_diag_scan4x4_x
const uint8_t ff_hevc_diag_scan4x4_x[16]
Definition: hevc_data.c:25
ff_hevc_inter_pred_idc_decode
int ff_hevc_inter_pred_idc_decode(HEVCLocalContext *lc, int nPbW, int nPbH)
Definition: hevc_cabac.c:810
HEVCLocalContext::tu
TransformUnit tu
Definition: hevcdec.h:462
ff_hevc_part_mode_decode
int ff_hevc_part_mode_decode(HEVCLocalContext *lc, int log2_cb_size)
Definition: hevc_cabac.c:718
coeff_sign_flag_decode
static av_always_inline int coeff_sign_flag_decode(HEVCLocalContext *lc, uint8_t nb)
Definition: hevc_cabac.c:1029
add
static float add(float src0, float src1)
Definition: dnn_backend_native_layer_mathbinary.c:35
ff_hevc_split_transform_flag_decode
int ff_hevc_split_transform_flag_decode(HEVCLocalContext *lc, int log2_trafo_size)
Definition: hevc_cabac.c:879
HEVCCABACState::stat_coeff
uint8_t stat_coeff[HEVC_STAT_COEFFS]
Definition: hevcdec.h:231
HEVCSPS
Definition: hevc_ps.h:140
ff_hevc_sao_offset_abs_decode
int ff_hevc_sao_offset_abs_decode(HEVCLocalContext *lc)
Definition: hevc_cabac.c:596
diag_scan8x8_inv
static const uint8_t diag_scan8x8_inv[8][8]
Definition: hevc_cabac.c:439
TransformUnit::cross_pf
uint8_t cross_pf
Definition: hevcdec.h:385
HEVCLocalContext::cu
CodingUnit cu
Definition: hevcdec.h:477
abs_mvd_greater0_flag_decode
static av_always_inline int abs_mvd_greater0_flag_decode(HEVCLocalContext *lc)
Definition: hevc_cabac.c:846
horiz_scan4x4_x
static const uint8_t horiz_scan4x4_x[16]
Definition: hevc_cabac.c:394
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: hevc_cabac.c:991
LAST_SIGNIFICANT_COEFF_Y_PREFIX
@ LAST_SIGNIFICANT_COEFF_Y_PREFIX
Definition: hevcdec.h:126
CU_CHROMA_QP_OFFSET_IDX
@ CU_CHROMA_QP_OFFSET_IDX
Definition: hevcdec.h:138
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
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: hevc_cabac.c:982
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
ff_hevc_merge_flag_decode
int ff_hevc_merge_flag_decode(HEVCLocalContext *lc)
Definition: hevc_cabac.c:805
TransformUnit::intra_pred_mode_c
int intra_pred_mode_c
Definition: hevcdec.h:379
INTRA_CHROMA_PRED_MODE
@ INTRA_CHROMA_PRED_MODE
Definition: hevcdec.h:107
diag_scan4x4_inv
static const uint8_t diag_scan4x4_inv[4][4]
Definition: hevc_cabac.c:432
ff_hevc_ref_idx_lx_decode
int ff_hevc_ref_idx_lx_decode(HEVCLocalContext *lc, int num_ref_idx_lx)
Definition: hevc_cabac.c:820
PART_2NxN
@ PART_2NxN
Definition: hevcdec.h:143
EXPLICIT_RDPCM_DIR_FLAG
@ EXPLICIT_RDPCM_DIR_FLAG
Definition: hevcdec.h:124
HEVCLocalContext::cc
CABACContext cc
Definition: hevcdec.h:443
TransformUnit::cu_qp_offset_cr
int8_t cu_qp_offset_cr
Definition: hevcdec.h:384
ff_hevc_sao_type_idx_decode
int ff_hevc_sao_type_idx_decode(HEVCLocalContext *lc)
Definition: hevc_cabac.c:576
HEVC_CONTEXTS
#define HEVC_CONTEXTS
Definition: hevcdec.h:52
SAO_MERGE_FLAG
@ SAO_MERGE_FLAG
Definition: hevcdec.h:90