FFmpeg
Loading...
Searching...
No Matches
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
25#include "libavutil/common.h"
26
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 */
89enum {
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 */
100static 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
334static const uint8_t scan_1x1[1] = {
335 0,
336};
337
338static const uint8_t horiz_scan2x2_x[4] = {
339 0, 1, 0, 1,
340};
341
342static const uint8_t horiz_scan2x2_y[4] = {
343 0, 0, 1, 1
344};
345
346static 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
353static 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
360static 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
371static const uint8_t diag_scan2x2_x[4] = {
372 0, 0, 1, 1,
373};
374
375static const uint8_t diag_scan2x2_y[4] = {
376 0, 1, 0, 1,
377};
378
379static const uint8_t diag_scan2x2_inv[2][2] = {
380 { 0, 2, },
381 { 1, 3, },
382};
383
384static 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
391static 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
417static 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->sub.cc, 0) == NULL ? AVERROR_INVALIDDATA : 0;
428}
429
431{
432 int init_type = 2 - lc->sh->slice_type;
433 int i;
434
435 if (lc->sh->cabac_init_flag && lc->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(lc->sh->slice_qp, 0, 51)) >> 4) + n) - 127;
443
444 pre ^= pre >> 31;
445 if (pre > 124)
446 pre = 124 + (pre & 1);
447 lc->sub.cabac_state[i] = pre;
448 }
449
450 for (i = 0; i < 4; i++)
451 lc->sub.stat_coeff[i] = 0;
452}
453
454/* Open CABAC on this substream's data, or continue byte-aligned in it if it
455 * is already open (one slice read from a single buffer). */
457{
458 HEVCSubstream *const sub = &lc->sub;
459 int ret;
460
461 if (sub->opened)
462 return cabac_reinit(lc);
463
464 ret = ff_init_cabac_decoder(&sub->cc, sub->data, sub->size);
465 if (ret < 0)
466 return ret;
467 sub->opened = 1;
468
469 return 0;
470}
471
473 int ctb_addr_ts)
474{
475 const HEVCContext *const s = lc->parent;
476 const HEVCSPS *const sps = pps->sps;
477 HEVCSubstream *const sub = &lc->sub;
478
479 if (ctb_addr_ts == pps->ctb_addr_rs_to_ts[lc->sh->slice_ctb_addr_rs]) {
480 /* First CTB of a slice segment. For a dependent slice segment the
481 * data still belongs to the new segment. */
482 int ret = ff_init_cabac_decoder(&sub->cc, sub->data, sub->size);
483 if (ret < 0)
484 return ret;
485 sub->opened = 1;
486 if (lc->sh->dependent_slice_segment_flag == 0 ||
487 (pps->tiles_enabled_flag &&
488 pps->tile_id[ctb_addr_ts] != pps->tile_id[ctb_addr_ts - 1]))
489 cabac_init_state(lc, s);
490
491 if (!lc->sh->first_slice_in_pic_flag &&
492 pps->entropy_coding_sync_enabled_flag) {
493 if (ctb_addr_ts % sps->ctb_width == 0) {
494 if (sps->ctb_width == 1)
495 cabac_init_state(lc, s);
496 else if (lc->sh->dependent_slice_segment_flag == 1)
497 load_states(lc, sps);
498 }
499 }
500 } else {
501 if (pps->tiles_enabled_flag &&
502 pps->tile_id[ctb_addr_ts] != pps->tile_id[ctb_addr_ts - 1]) {
503 int ret = substream_continue(lc);
504 if (ret < 0)
505 return ret;
506 cabac_init_state(lc, s);
507 }
508 if (pps->entropy_coding_sync_enabled_flag) {
509 if (ctb_addr_ts % sps->ctb_width == 0) {
510 int ret;
511 /* The end of row terminate bit is read only when continuing */
512 if (sub->opened)
513 get_cabac_terminate(&sub->cc);
515 if (ret < 0)
516 return ret;
517
518 if (sps->ctb_width == 1)
519 cabac_init_state(lc, s);
520 else
521 load_states(lc, sps);
522 }
523 }
524 }
525 return 0;
526}
527
528#define GET_CABAC(ctx) get_cabac(&lc->sub.cc, &lc->sub.cabac_state[ctx])
529
531{
532 return GET_CABAC(SAO_MERGE_FLAG_OFFSET);
533}
534
536{
537 if (!GET_CABAC(SAO_TYPE_IDX_OFFSET))
538 return 0;
539
540 if (!get_cabac_bypass(&lc->sub.cc))
541 return SAO_BAND;
542 return SAO_EDGE;
543}
544
546{
547 int i;
548 int value = get_cabac_bypass(&lc->sub.cc);
549
550 for (i = 0; i < 4; i++)
551 value = (value << 1) | get_cabac_bypass(&lc->sub.cc);
552 return value;
553}
554
556{
557 int i = 0;
558 int length = (1 << (FFMIN(bit_depth, 10) - 5)) - 1;
559
560 while (i < length && get_cabac_bypass(&lc->sub.cc))
561 i++;
562 return i;
563}
564
569
571{
572 int ret = get_cabac_bypass(&lc->sub.cc) << 1;
573 ret |= get_cabac_bypass(&lc->sub.cc);
574 return ret;
575}
576
581
583{
584 return GET_CABAC(CU_TRANSQUANT_BYPASS_FLAG_OFFSET);
585}
586
587int ff_hevc_skip_flag_decode(HEVCLocalContext *lc, uint8_t *skip_flag,
588 int x0, int y0, int x_cb, int y_cb, int min_cb_width)
589{
590 int inc = 0;
591
592 if (lc->ctb_left_flag || x0)
593 inc = !!SAMPLE_CTB(skip_flag, x_cb - 1, y_cb);
594 if (lc->ctb_up_flag || y0)
595 inc += !!SAMPLE_CTB(skip_flag, x_cb, y_cb - 1);
596
597 return GET_CABAC(SKIP_FLAG_OFFSET + inc);
598}
599
601{
602 int prefix_val = 0;
603 int suffix_val = 0;
604 int inc = 0;
605
606 while (prefix_val < 5 && GET_CABAC(CU_QP_DELTA_OFFSET + inc)) {
607 prefix_val++;
608 inc = 1;
609 }
610 if (prefix_val >= 5) {
611 int k = 0;
612 while (k < 7 && get_cabac_bypass(&lc->sub.cc)) {
613 suffix_val += 1 << k;
614 k++;
615 }
616 if (k == 7) {
617 av_log(lc->logctx, AV_LOG_ERROR, "CABAC_MAX_BIN : %d\n", k);
618 return AVERROR_INVALIDDATA;
619 }
620
621 while (k--)
622 suffix_val += get_cabac_bypass(&lc->sub.cc) << k;
623 }
624 return prefix_val + suffix_val;
625}
626
631
633{
634 return GET_CABAC(CU_CHROMA_QP_OFFSET_FLAG_OFFSET);
635}
636
637int ff_hevc_cu_chroma_qp_offset_idx(HEVCLocalContext *lc, int chroma_qp_offset_list_len_minus1)
638{
639 int c_max= FFMAX(5, chroma_qp_offset_list_len_minus1);
640 int i = 0;
641
642 while (i < c_max && GET_CABAC(CU_CHROMA_QP_OFFSET_IDX_OFFSET))
643 i++;
644
645 return i;
646}
647
649{
650 return GET_CABAC(PRED_MODE_FLAG_OFFSET);
651}
652
654 const HEVCSPS *sps,
655 int ct_depth, int x0, int y0)
656{
657 int inc = 0, depth_left = 0, depth_top = 0;
658 int x0b = av_zero_extend(x0, sps->log2_ctb_size);
659 int y0b = av_zero_extend(y0, sps->log2_ctb_size);
660 int x_cb = x0 >> sps->log2_min_cb_size;
661 int y_cb = y0 >> sps->log2_min_cb_size;
662
663 if (lc->ctb_left_flag || x0b)
664 depth_left = tab_ct_depth[(y_cb) * sps->min_cb_width + x_cb - 1];
665 if (lc->ctb_up_flag || y0b)
666 depth_top = tab_ct_depth[(y_cb - 1) * sps->min_cb_width + x_cb];
667
668 inc += (depth_left > ct_depth);
669 inc += (depth_top > ct_depth);
670
671 return GET_CABAC(SPLIT_CODING_UNIT_FLAG_OFFSET + inc);
672}
673
674int ff_hevc_part_mode_decode(HEVCLocalContext *lc, const HEVCSPS *sps, int log2_cb_size)
675{
676 if (GET_CABAC(PART_MODE_OFFSET)) // 1
677 return PART_2Nx2N;
678 if (log2_cb_size == sps->log2_min_cb_size) {
679 if (lc->cu.pred_mode == MODE_INTRA) // 0
680 return PART_NxN;
681 if (GET_CABAC(PART_MODE_OFFSET + 1)) // 01
682 return PART_2NxN;
683 if (log2_cb_size == 3) // 00
684 return PART_Nx2N;
685 if (GET_CABAC(PART_MODE_OFFSET + 2)) // 001
686 return PART_Nx2N;
687 return PART_NxN; // 000
688 }
689
690 if (!sps->amp_enabled) {
691 if (GET_CABAC(PART_MODE_OFFSET + 1)) // 01
692 return PART_2NxN;
693 return PART_Nx2N;
694 }
695
696 if (GET_CABAC(PART_MODE_OFFSET + 1)) { // 01X, 01XX
697 if (GET_CABAC(PART_MODE_OFFSET + 3)) // 011
698 return PART_2NxN;
699 if (get_cabac_bypass(&lc->sub.cc)) // 0101
700 return PART_2NxnD;
701 return PART_2NxnU; // 0100
702 }
703
704 if (GET_CABAC(PART_MODE_OFFSET + 3)) // 001
705 return PART_Nx2N;
706 if (get_cabac_bypass(&lc->sub.cc)) // 0001
707 return PART_nRx2N;
708 return PART_nLx2N; // 0000
709}
710
715
717{
718 return GET_CABAC(PREV_INTRA_LUMA_PRED_FLAG_OFFSET);
719}
720
722{
723 int i = 0;
724 while (i < 2 && get_cabac_bypass(&lc->sub.cc))
725 i++;
726 return i;
727}
728
730{
731 int i;
732 int value = get_cabac_bypass(&lc->sub.cc);
733
734 for (i = 0; i < 4; i++)
735 value = (value << 1) | get_cabac_bypass(&lc->sub.cc);
736 return value;
737}
738
740{
741 int ret;
742 if (!GET_CABAC(INTRA_CHROMA_PRED_MODE_OFFSET))
743 return 4;
744
745 ret = get_cabac_bypass(&lc->sub.cc) << 1;
746 ret |= get_cabac_bypass(&lc->sub.cc);
747 return ret;
748}
749
751{
752 int i = GET_CABAC(MERGE_IDX_OFFSET);
753
754 if (i != 0) {
755 while (i < lc->sh->max_num_merge_cand-1 && get_cabac_bypass(&lc->sub.cc))
756 i++;
757 }
758 return i;
759}
760
762{
763 return GET_CABAC(MERGE_FLAG_OFFSET);
764}
765
767{
768 if (nPbW + nPbH == 12)
769 return GET_CABAC(INTER_PRED_IDC_OFFSET + 4);
770 if (GET_CABAC(INTER_PRED_IDC_OFFSET + lc->ct_depth))
771 return PRED_BI;
772
773 return GET_CABAC(INTER_PRED_IDC_OFFSET + 4);
774}
775
776int ff_hevc_ref_idx_lx_decode(HEVCLocalContext *lc, int num_ref_idx_lx)
777{
778 int i = 0;
779 int max = num_ref_idx_lx - 1;
780 int max_ctx = FFMIN(max, 2);
781
782 while (i < max_ctx && GET_CABAC(REF_IDX_L0_OFFSET + i))
783 i++;
784 if (i == 2) {
785 while (i < max && get_cabac_bypass(&lc->sub.cc))
786 i++;
787 }
788
789 return i;
790}
791
793{
794 return GET_CABAC(MVP_LX_FLAG_OFFSET);
795}
796
798{
799 return GET_CABAC(NO_RESIDUAL_DATA_FLAG_OFFSET);
800}
801
803{
804 return GET_CABAC(ABS_MVD_GREATER0_FLAG_OFFSET);
805}
806
808{
809 return GET_CABAC(ABS_MVD_GREATER1_FLAG_OFFSET + 1);
810}
811
813{
814 int ret = 2;
815 int k = 1;
816
817 while (k < CABAC_MAX_BIN && get_cabac_bypass(&lc->sub.cc)) {
818 ret += 1U << k;
819 k++;
820 }
821 if (k == CABAC_MAX_BIN) {
822 av_log(lc->logctx, AV_LOG_ERROR, "CABAC_MAX_BIN : %d\n", k);
823 return 0;
824 }
825 while (k--)
826 ret += get_cabac_bypass(&lc->sub.cc) << k;
827 return get_cabac_bypass_sign(&lc->sub.cc, -ret);
828}
829
834
836{
837 return GET_CABAC(SPLIT_TRANSFORM_FLAG_OFFSET + 5 - log2_trafo_size);
838}
839
841{
842 return GET_CABAC(CBF_CB_CR_OFFSET + trafo_depth);
843}
844
846{
847 return GET_CABAC(CBF_LUMA_OFFSET + !trafo_depth);
848}
849
851{
852 return GET_CABAC(TRANSFORM_SKIP_FLAG_OFFSET + !!c_idx);
853}
854
856{
857 return GET_CABAC(EXPLICIT_RDPCM_FLAG_OFFSET + !!c_idx);
858}
859
861{
862 return GET_CABAC(EXPLICIT_RDPCM_DIR_FLAG_OFFSET + !!c_idx);
863}
864
866{
867 int i =0;
868
869 while (i < 4 && GET_CABAC(LOG2_RES_SCALE_ABS_OFFSET + 4 * idx + i))
870 i++;
871
872 return i;
873}
874
876{
877 return GET_CABAC(RES_SCALE_SIGN_FLAG_OFFSET + idx);
878}
879
881 int log2_size, int *last_scx_prefix, int *last_scy_prefix)
882{
883 int i = 0;
884 int max = (log2_size << 1) - 1;
885 int ctx_offset, ctx_shift;
886
887 if (!c_idx) {
888 ctx_offset = 3 * (log2_size - 2) + ((log2_size - 1) >> 2);
889 ctx_shift = (log2_size + 1) >> 2;
890 } else {
891 ctx_offset = 15;
892 ctx_shift = log2_size - 2;
893 }
894 while (i < max &&
895 GET_CABAC(LAST_SIGNIFICANT_COEFF_X_PREFIX_OFFSET + (i >> ctx_shift) + ctx_offset))
896 i++;
897 *last_scx_prefix = i;
898
899 i = 0;
900 while (i < max &&
901 GET_CABAC(LAST_SIGNIFICANT_COEFF_Y_PREFIX_OFFSET + (i >> ctx_shift) + ctx_offset))
902 i++;
903 *last_scy_prefix = i;
904}
905
907 int last_significant_coeff_prefix)
908{
909 int i;
910 int length = (last_significant_coeff_prefix >> 1) - 1;
911 int value = get_cabac_bypass(&lc->sub.cc);
912
913 for (i = 1; i < length; i++)
914 value = (value << 1) | get_cabac_bypass(&lc->sub.cc);
915 return value;
916}
917
919{
920 int inc;
921
922 inc = FFMIN(ctx_cg, 1) + (c_idx>0 ? 2 : 0);
923
924 return GET_CABAC(SIGNIFICANT_COEFF_GROUP_FLAG_OFFSET + inc);
925}
927 int offset, const uint8_t *ctx_idx_map)
928{
929 int inc = ctx_idx_map[n] + offset;
930 return GET_CABAC(SIGNIFICANT_COEFF_FLAG_OFFSET + inc);
931}
932
934{
935 return GET_CABAC(SIGNIFICANT_COEFF_FLAG_OFFSET + offset);
936}
937
939{
940
941 if (c_idx > 0)
942 inc += 16;
943
944 return GET_CABAC(COEFF_ABS_LEVEL_GREATER1_FLAG_OFFSET + inc);
945}
946
948{
949 if (c_idx > 0)
950 inc += 4;
951
952 return GET_CABAC(COEFF_ABS_LEVEL_GREATER2_FLAG_OFFSET + inc);
953}
954
955/* a run of bypass bins is the quotient of the offset by range << 17 */
957{
958 int avail = CABAC_BITS - ff_ctz(c->low);
959 uint64_t x, r = (uint64_t)c->range << (CABAC_BITS + 1);
960 const uint8_t *bytestream = c->bytestream;
961
962 if (n < avail) {
963 x = (uint64_t)c->low << n;
964 } else {
965 int fill = (bytestream[0] << 9) + (bytestream[1] << 1) - CABAC_MASK;
966
967 x = (uint64_t)((((int64_t)c->low << avail) + fill)) << (n - avail);
968#if !UNCHECKED_BITSTREAM_READER
969 if (bytestream < c->bytestream_end)
970#endif
971 bytestream += CABAC_BITS / 8;
972 }
973
974 if (x < r << n) {
975 c->low = x % r;
976 c->bytestream = bytestream;
977 return x / r;
978 } else {
979 int ret = 0;
980
981 for (int i = 0; i < n; i++)
982 ret = (ret << 1) | get_cabac_bypass(c);
983 return ret;
984 }
985}
986
987/* leading ones of the quotient, consumed only up to the first zero */
989{
990 int prefix = 0;
991
992 while (prefix < max) {
993 int avail = CABAC_BITS - ff_ctz(c->low);
994 int n = FFMIN(avail - 1, max - prefix);
995 uint64_t r = (uint64_t)c->range << (CABAC_BITS + 1);
996 uint64_t x = (uint64_t)c->low << n;
997 int q, t;
998
999 if (n < 1 || x >= r << n) {
1000 if (!get_cabac_bypass(c))
1001 return prefix;
1002 prefix++;
1003 continue;
1004 }
1005
1006 q = x / r;
1007 t = ~q & ((1 << n) - 1);
1008 if (t) {
1009 int p = n - 1 - av_log2(t);
1010 int k = n - (p + 1);
1011
1012 c->low = (x >> k) - ((uint64_t)(q >> k) * r);
1013 return prefix + p;
1014 }
1015 c->low = x - (uint64_t)q * r;
1016 prefix += n;
1017 }
1018 return prefix;
1019}
1020
1022{
1023 int prefix;
1024 int suffix = 0;
1025 int last_coeff_abs_level_remaining;
1026 int i;
1027
1029
1030 if (prefix < 3) {
1031 if (rc_rice_param > 2)
1032 suffix = cabac_bypass_bits(&lc->sub.cc, rc_rice_param);
1033 else
1034 for (i = 0; i < rc_rice_param; i++)
1035 suffix = (suffix << 1) | get_cabac_bypass(&lc->sub.cc);
1036 last_coeff_abs_level_remaining = (prefix << rc_rice_param) + suffix;
1037 } else {
1038 int prefix_minus3 = prefix - 3;
1039 int k;
1040
1041 if (prefix == CABAC_MAX_BIN || prefix_minus3 + rc_rice_param > 16 + 6) {
1042 av_log(lc->logctx, AV_LOG_ERROR, "CABAC_MAX_BIN : %d\n", prefix);
1043 return 0;
1044 }
1045
1046 k = prefix_minus3 + rc_rice_param;
1047 if (k > 16) {
1048 suffix = cabac_bypass_bits(&lc->sub.cc, 16) << (k - 16);
1049 suffix |= cabac_bypass_bits(&lc->sub.cc, k - 16);
1050 } else if (k > 2) {
1051 suffix = cabac_bypass_bits(&lc->sub.cc, k);
1052 } else {
1053 for (i = 0; i < k; i++)
1054 suffix = (suffix << 1) | get_cabac_bypass(&lc->sub.cc);
1055 }
1056 last_coeff_abs_level_remaining = (((1 << prefix_minus3) + 3 - 1)
1057 << rc_rice_param) + suffix;
1058 }
1059 return last_coeff_abs_level_remaining;
1060}
1061
1063{
1064 int i;
1065 int ret = 0;
1066
1067 if (nb > 2)
1068 return cabac_bypass_bits(&lc->sub.cc, nb);
1069
1070 for (i = 0; i < nb; i++)
1071 ret = (ret << 1) | get_cabac_bypass(&lc->sub.cc);
1072 return ret;
1073}
1074
1076 int x0, int y0,
1077 int log2_trafo_size, enum ScanType scan_idx,
1078 int c_idx)
1079{
1080#define GET_COORD(offset, n) \
1081 do { \
1082 x_c = (x_cg << 2) + scan_x_off[n]; \
1083 y_c = (y_cg << 2) + scan_y_off[n]; \
1084 } while (0)
1085 const HEVCContext *const s = lc->parent;
1086 const HEVCSPS *const sps = pps->sps;
1087 int transform_skip_flag = 0;
1088
1089 int last_significant_coeff_x, last_significant_coeff_y;
1090 int last_scan_pos;
1091 int n_end;
1092 int num_coeff = 0;
1093 int greater1_ctx = 1;
1094
1095 int num_last_subset;
1096 int max_xy, col_limit, clear_rows;
1097 int x_cg_last_sig, y_cg_last_sig;
1098
1099 const uint8_t *scan_x_cg, *scan_y_cg, *scan_x_off, *scan_y_off;
1100
1101 ptrdiff_t stride = s->cur_frame->f->linesize[c_idx];
1102 int hshift = sps->hshift[c_idx];
1103 int vshift = sps->vshift[c_idx];
1104 uint8_t *dst = &s->cur_frame->f->data[c_idx][(y0 >> vshift) * stride +
1105 ((x0 >> hshift) << sps->pixel_shift)];
1106 int16_t *coeffs = (int16_t*)(c_idx ? lc->edge_emu_buffer2 : lc->edge_emu_buffer);
1107 uint8_t significant_coeff_group_flag[8][8] = {{0}};
1108 int explicit_rdpcm_flag = 0;
1109 int explicit_rdpcm_dir_flag;
1110
1111 int trafo_size = 1 << log2_trafo_size;
1112 int i;
1113 int qp,shift,add,scale,scale_m;
1114 static const uint8_t level_scale[] = { 40, 45, 51, 57, 64, 72 };
1115 const uint8_t *scale_matrix = NULL;
1116 uint8_t dc_scale;
1117 int pred_mode_intra = (c_idx == 0) ? lc->tu.intra_pred_mode :
1119
1120 // Derive QP for dequant
1121 if (!lc->cu.cu_transquant_bypass_flag) {
1122 static const int qp_c[] = { 29, 30, 31, 32, 33, 33, 34, 34, 35, 35, 36, 36, 37, 37 };
1123 static const uint8_t rem6[51 + 4 * 6 + 1] = {
1124 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2,
1125 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5,
1126 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3,
1127 4, 5, 0, 1, 2, 3, 4, 5, 0, 1
1128 };
1129
1130 static const uint8_t div6[51 + 4 * 6 + 1] = {
1131 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3,
1132 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6,
1133 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10,
1134 10, 10, 11, 11, 11, 11, 11, 11, 12, 12
1135 };
1136 int qp_y = lc->sub.qp_y;
1137
1138 if (pps->transform_skip_enabled_flag &&
1139 log2_trafo_size <= pps->log2_max_transform_skip_block_size) {
1140 transform_skip_flag = hevc_transform_skip_flag_decode(lc, c_idx);
1141 }
1142
1143 if (c_idx == 0) {
1144 qp = qp_y + sps->qp_bd_offset;
1145 } else {
1146 int qp_i, offset;
1147
1148 if (c_idx == 1)
1149 offset = pps->cb_qp_offset + lc->sh->slice_cb_qp_offset +
1150 lc->sub.cu_qp_offset_cb;
1151 else
1152 offset = pps->cr_qp_offset + lc->sh->slice_cr_qp_offset +
1153 lc->sub.cu_qp_offset_cr;
1154
1155 qp_i = av_clip(qp_y + offset, - sps->qp_bd_offset, 57);
1156 if (sps->chroma_format_idc == 1) {
1157 if (qp_i < 30)
1158 qp = qp_i;
1159 else if (qp_i > 43)
1160 qp = qp_i - 6;
1161 else
1162 qp = qp_c[qp_i - 30];
1163 } else {
1164 if (qp_i > 51)
1165 qp = 51;
1166 else
1167 qp = qp_i;
1168 }
1169
1170 qp += sps->qp_bd_offset;
1171 }
1172
1173 shift = sps->bit_depth + log2_trafo_size - 5;
1174 add = 1 << (shift-1);
1175 scale = level_scale[rem6[qp]] << (div6[qp]);
1176 scale_m = 16; // default when no custom scaling lists.
1177 dc_scale = 16;
1178
1179 if (sps->scaling_list_enabled && !(transform_skip_flag && log2_trafo_size > 2)) {
1180 const ScalingList *sl = pps->scaling_list_data_present_flag ?
1181 &pps->scaling_list : &sps->scaling_list;
1182 int matrix_id = lc->cu.pred_mode != MODE_INTRA;
1183
1184 matrix_id = 3 * matrix_id + c_idx;
1185
1186 scale_matrix = sl->sl[log2_trafo_size - 2][matrix_id];
1187 if (log2_trafo_size >= 4)
1188 dc_scale = sl->sl_dc[log2_trafo_size - 4][matrix_id];
1189 }
1190 } else {
1191 shift = 0;
1192 add = 0;
1193 scale = 0;
1194 dc_scale = 0;
1195 }
1196
1197 if (lc->cu.pred_mode == MODE_INTER && sps->explicit_rdpcm_enabled &&
1198 (transform_skip_flag || lc->cu.cu_transquant_bypass_flag)) {
1199 explicit_rdpcm_flag = explicit_rdpcm_flag_decode(lc, c_idx);
1200 if (explicit_rdpcm_flag) {
1201 explicit_rdpcm_dir_flag = explicit_rdpcm_dir_flag_decode(lc, c_idx);
1202 }
1203 }
1204
1205 last_significant_coeff_xy_prefix_decode(lc, c_idx, log2_trafo_size,
1206 &last_significant_coeff_x, &last_significant_coeff_y);
1207
1208 if (last_significant_coeff_x > 3) {
1209 int suffix = last_significant_coeff_suffix_decode(lc, last_significant_coeff_x);
1210 last_significant_coeff_x = (1 << ((last_significant_coeff_x >> 1) - 1)) *
1211 (2 + (last_significant_coeff_x & 1)) +
1212 suffix;
1213 }
1214
1215 if (last_significant_coeff_y > 3) {
1216 int suffix = last_significant_coeff_suffix_decode(lc, last_significant_coeff_y);
1217 last_significant_coeff_y = (1 << ((last_significant_coeff_y >> 1) - 1)) *
1218 (2 + (last_significant_coeff_y & 1)) +
1219 suffix;
1220 }
1221
1222 if (scan_idx == SCAN_VERT)
1223 FFSWAP(int, last_significant_coeff_x, last_significant_coeff_y);
1224
1225 x_cg_last_sig = last_significant_coeff_x >> 2;
1226 y_cg_last_sig = last_significant_coeff_y >> 2;
1227
1228 switch (scan_idx) {
1229 case SCAN_DIAG: {
1230 int last_x_c = last_significant_coeff_x & 3;
1231 int last_y_c = last_significant_coeff_y & 3;
1232
1233 scan_x_off = ff_hevc_diag_scan4x4_x;
1234 scan_y_off = ff_hevc_diag_scan4x4_y;
1235 num_coeff = diag_scan4x4_inv[last_y_c][last_x_c];
1236 if (trafo_size == 4) {
1237 scan_x_cg = scan_1x1;
1238 scan_y_cg = scan_1x1;
1239 } else if (trafo_size == 8) {
1240 num_coeff += diag_scan2x2_inv[y_cg_last_sig][x_cg_last_sig] << 4;
1241 scan_x_cg = diag_scan2x2_x;
1242 scan_y_cg = diag_scan2x2_y;
1243 } else if (trafo_size == 16) {
1244 num_coeff += diag_scan4x4_inv[y_cg_last_sig][x_cg_last_sig] << 4;
1245 scan_x_cg = ff_hevc_diag_scan4x4_x;
1246 scan_y_cg = ff_hevc_diag_scan4x4_y;
1247 } else { // trafo_size == 32
1248 num_coeff += diag_scan8x8_inv[y_cg_last_sig][x_cg_last_sig] << 4;
1249 scan_x_cg = ff_hevc_diag_scan8x8_x;
1250 scan_y_cg = ff_hevc_diag_scan8x8_y;
1251 }
1252 break;
1253 }
1254 case SCAN_HORIZ:
1255 scan_x_cg = horiz_scan2x2_x;
1256 scan_y_cg = horiz_scan2x2_y;
1257 scan_x_off = horiz_scan4x4_x;
1258 scan_y_off = horiz_scan4x4_y;
1259 num_coeff = horiz_scan8x8_inv[last_significant_coeff_y][last_significant_coeff_x];
1260 break;
1261 default: //SCAN_VERT
1262 scan_x_cg = horiz_scan2x2_y;
1263 scan_y_cg = horiz_scan2x2_x;
1264 scan_x_off = horiz_scan4x4_y;
1265 scan_y_off = horiz_scan4x4_x;
1266 num_coeff = horiz_scan8x8_inv[last_significant_coeff_x][last_significant_coeff_y];
1267 break;
1268 }
1269 num_coeff++;
1270 num_last_subset = (num_coeff - 1) >> 4;
1271
1272 max_xy = FFMAX(last_significant_coeff_x, last_significant_coeff_y);
1273 col_limit = last_significant_coeff_x + last_significant_coeff_y + 4;
1274 if (max_xy < 4)
1275 col_limit = FFMIN(4, col_limit);
1276 else if (max_xy < 8)
1277 col_limit = FFMIN(8, col_limit);
1278 else if (max_xy < 12)
1279 col_limit = FFMIN(24, col_limit);
1280
1281 // idct_dc reads coeffs[0] only and writes the whole block: no clear needed
1282 clear_rows = trafo_size;
1283 if (!lc->cu.cu_transquant_bypass_flag && !transform_skip_flag &&
1284 !(lc->cu.pred_mode == MODE_INTRA && c_idx == 0 && log2_trafo_size == 2)) {
1285 if (max_xy == 0)
1286 clear_rows = 0;
1287 }
1288 if (clear_rows)
1289 memset(coeffs, 0, clear_rows * trafo_size * sizeof(int16_t));
1290
1291 for (i = num_last_subset; i >= 0; i--) {
1292 int n, m;
1293 int x_cg, y_cg, x_c, y_c, pos;
1294 int implicit_non_zero_coeff = 0;
1295 int64_t trans_coeff_level;
1296 int prev_sig = 0;
1297 int offset = i << 4;
1298 int rice_init = 0;
1299
1300 uint8_t significant_coeff_flag_idx[16];
1301 uint8_t nb_significant_coeff_flag = 0;
1302
1303 x_cg = scan_x_cg[i];
1304 y_cg = scan_y_cg[i];
1305
1306 if ((i < num_last_subset) && (i > 0)) {
1307 int ctx_cg = 0;
1308 if (x_cg < (1 << (log2_trafo_size - 2)) - 1)
1309 ctx_cg += significant_coeff_group_flag[x_cg + 1][y_cg];
1310 if (y_cg < (1 << (log2_trafo_size - 2)) - 1)
1311 ctx_cg += significant_coeff_group_flag[x_cg][y_cg + 1];
1312
1313 significant_coeff_group_flag[x_cg][y_cg] =
1314 significant_coeff_group_flag_decode(lc, c_idx, ctx_cg);
1315 implicit_non_zero_coeff = 1;
1316 } else {
1317 significant_coeff_group_flag[x_cg][y_cg] =
1318 ((x_cg == x_cg_last_sig && y_cg == y_cg_last_sig) ||
1319 (x_cg == 0 && y_cg == 0));
1320 }
1321
1322 last_scan_pos = num_coeff - offset - 1;
1323
1324 if (i == num_last_subset) {
1325 n_end = last_scan_pos - 1;
1326 significant_coeff_flag_idx[0] = last_scan_pos;
1327 nb_significant_coeff_flag = 1;
1328 } else {
1329 n_end = 15;
1330 }
1331
1332 if (x_cg < ((1 << log2_trafo_size) - 1) >> 2)
1333 prev_sig = !!significant_coeff_group_flag[x_cg + 1][y_cg];
1334 if (y_cg < ((1 << log2_trafo_size) - 1) >> 2)
1335 prev_sig += (!!significant_coeff_group_flag[x_cg][y_cg + 1] << 1);
1336
1337 if (significant_coeff_group_flag[x_cg][y_cg] && n_end >= 0) {
1338 // ctx_idx_map composed with the intra-CG scan, indexed by scan position
1339 static const uint8_t ctx_idx_map[3][5 * 16] = {
1340 { // SCAN_DIAG
1341 0, 2, 1, 6, 3, 4, 7, 6, 4, 5, 7, 8, 5, 8, 8, 8, // log2_trafo_size == 2
1342 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // prev_sig == 0
1343 2, 1, 2, 0, 1, 2, 0, 0, 1, 2, 0, 0, 1, 0, 0, 0, // prev_sig == 1
1344 2, 2, 1, 2, 1, 0, 2, 1, 0, 0, 1, 0, 0, 0, 0, 0, // prev_sig == 2
1345 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, // default
1346 },
1347 { // SCAN_HORIZ
1348 0, 1, 4, 5, 2, 3, 4, 5, 6, 6, 8, 8, 7, 7, 8, 8,
1349 1, 1, 1, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0,
1350 2, 2, 2, 2, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0,
1351 2, 1, 0, 0, 2, 1, 0, 0, 2, 1, 0, 0, 2, 1, 0, 0,
1352 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1353 },
1354 { // SCAN_VERT
1355 0, 2, 6, 7, 1, 3, 6, 7, 4, 4, 8, 8, 5, 5, 8, 8,
1356 1, 1, 1, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0,
1357 2, 1, 0, 0, 2, 1, 0, 0, 2, 1, 0, 0, 2, 1, 0, 0,
1358 2, 2, 2, 2, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0,
1359 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1360 },
1361 };
1362 const uint8_t *ctx_idx_map_p;
1363 int scf_offset = 0;
1364 int nb0;
1365 if (sps->transform_skip_context_enabled &&
1366 (transform_skip_flag || lc->cu.cu_transquant_bypass_flag)) {
1367 ctx_idx_map_p = &ctx_idx_map[scan_idx][4 * 16];
1368 if (c_idx == 0) {
1369 scf_offset = 40;
1370 } else {
1371 scf_offset = 14 + 27;
1372 }
1373 } else {
1374 if (c_idx != 0)
1375 scf_offset = 27;
1376 if (log2_trafo_size == 2) {
1377 ctx_idx_map_p = &ctx_idx_map[scan_idx][0];
1378 } else {
1379 ctx_idx_map_p = &ctx_idx_map[scan_idx][(prev_sig + 1) << 4];
1380 if (c_idx == 0) {
1381 if ((x_cg > 0 || y_cg > 0))
1382 scf_offset += 3;
1383 if (log2_trafo_size == 3) {
1384 scf_offset += (scan_idx == SCAN_DIAG) ? 9 : 15;
1385 } else {
1386 scf_offset += 21;
1387 }
1388 } else {
1389 if (log2_trafo_size == 3)
1390 scf_offset += 9;
1391 else
1392 scf_offset += 12;
1393 }
1394 }
1395 }
1396 // the flag is a fresh bin: store always, advance conditionally
1397 nb0 = nb_significant_coeff_flag;
1398 for (n = n_end; n > 0; n--) {
1399 int sig = significant_coeff_flag_decode(lc, n, scf_offset, ctx_idx_map_p);
1400 significant_coeff_flag_idx[nb_significant_coeff_flag] = n;
1401 nb_significant_coeff_flag += sig;
1402 }
1403 if (nb_significant_coeff_flag != nb0)
1404 implicit_non_zero_coeff = 0;
1405 if (implicit_non_zero_coeff == 0) {
1406 if (sps->transform_skip_context_enabled &&
1407 (transform_skip_flag || lc->cu.cu_transquant_bypass_flag)) {
1408 if (c_idx == 0) {
1409 scf_offset = 42;
1410 } else {
1411 scf_offset = 16 + 27;
1412 }
1413 } else {
1414 if (i == 0) {
1415 if (c_idx == 0)
1416 scf_offset = 0;
1417 else
1418 scf_offset = 27;
1419 } else {
1420 scf_offset = 2 + scf_offset;
1421 }
1422 }
1423 significant_coeff_flag_idx[nb_significant_coeff_flag] = 0;
1424 nb_significant_coeff_flag +=
1425 significant_coeff_flag_decode_0(lc, c_idx, scf_offset);
1426 } else {
1427 significant_coeff_flag_idx[nb_significant_coeff_flag] = 0;
1428 nb_significant_coeff_flag++;
1429 }
1430 }
1431
1432 n_end = nb_significant_coeff_flag;
1433
1434
1435 if (n_end) {
1436 int first_nz_pos_in_cg;
1437 int last_nz_pos_in_cg;
1438 int c_rice_param = 0;
1439 int first_greater1_coeff_idx = -1;
1440 uint8_t coeff_abs_level_greater1_flag[8];
1441 uint16_t coeff_sign_flag;
1442 int sum_abs = 0;
1443 int sign_hidden;
1444 int sb_type;
1445 int gt1_mask = 0;
1446
1447
1448 // initialize first elem of coeff_bas_level_greater1_flag
1449 int ctx_set = (i > 0 && c_idx == 0) ? 2 : 0;
1450
1451 if (sps->persistent_rice_adaptation_enabled) {
1452 if (!transform_skip_flag && !lc->cu.cu_transquant_bypass_flag)
1453 sb_type = 2 * (c_idx == 0 ? 1 : 0);
1454 else
1455 sb_type = 2 * (c_idx == 0 ? 1 : 0) + 1;
1456 c_rice_param = lc->sub.stat_coeff[sb_type] / 4;
1457 }
1458
1459 if (!(i == num_last_subset) && greater1_ctx == 0)
1460 ctx_set++;
1461 greater1_ctx = 1;
1462 last_nz_pos_in_cg = significant_coeff_flag_idx[0];
1463
1464 // fresh bins: branchless context update, first set index from the mask
1465 for (m = 0; m < (n_end > 8 ? 8 : n_end); m++) {
1466 int inc = (ctx_set << 2) + greater1_ctx;
1468 coeff_abs_level_greater1_flag[m] = flag;
1469 gt1_mask |= flag << m;
1470 greater1_ctx = (greater1_ctx + (greater1_ctx - 1U < 2)) & (flag - 1);
1471 }
1472 if (gt1_mask)
1473 first_greater1_coeff_idx = ff_ctz(gt1_mask);
1474 first_nz_pos_in_cg = significant_coeff_flag_idx[n_end - 1];
1475
1476 if (lc->cu.cu_transquant_bypass_flag ||
1477 (lc->cu.pred_mode == MODE_INTRA &&
1478 sps->implicit_rdpcm_enabled && transform_skip_flag &&
1479 (pred_mode_intra == 10 || pred_mode_intra == 26 )) ||
1480 explicit_rdpcm_flag)
1481 sign_hidden = 0;
1482 else
1483 sign_hidden = (last_nz_pos_in_cg - first_nz_pos_in_cg >= 4);
1484
1485 if (first_greater1_coeff_idx != -1) {
1486 coeff_abs_level_greater1_flag[first_greater1_coeff_idx] += coeff_abs_level_greater2_flag_decode(lc, c_idx, ctx_set);
1487 }
1488 if (!pps->sign_data_hiding_flag || !sign_hidden ) {
1489 coeff_sign_flag = coeff_sign_flag_decode(lc, nb_significant_coeff_flag) << (16 - nb_significant_coeff_flag);
1490 } else {
1491 coeff_sign_flag = coeff_sign_flag_decode(lc, nb_significant_coeff_flag - 1) << (16 - (nb_significant_coeff_flag - 1));
1492 }
1493
1494 for (m = 0; m < n_end; m++) {
1495 int64_t sign;
1496
1497 n = significant_coeff_flag_idx[m];
1498 GET_COORD(offset, n);
1499 if (m < 8) {
1500 trans_coeff_level = 1 + coeff_abs_level_greater1_flag[m];
1501 if (trans_coeff_level == ((m == first_greater1_coeff_idx) ? 3 : 2)) {
1502 int last_coeff_abs_level_remaining = coeff_abs_level_remaining_decode(lc, c_rice_param);
1503
1504 trans_coeff_level += last_coeff_abs_level_remaining;
1505 if (trans_coeff_level > (3 << c_rice_param))
1506 c_rice_param = sps->persistent_rice_adaptation_enabled ? c_rice_param + 1 : FFMIN(c_rice_param + 1, 4);
1507 if (sps->persistent_rice_adaptation_enabled && !rice_init) {
1508 int c_rice_p_init = lc->sub.stat_coeff[sb_type] / 4;
1509 if (last_coeff_abs_level_remaining >= (3 << c_rice_p_init))
1510 lc->sub.stat_coeff[sb_type]++;
1511 else if (2 * last_coeff_abs_level_remaining < (1 << c_rice_p_init))
1512 if (lc->sub.stat_coeff[sb_type] > 0)
1513 lc->sub.stat_coeff[sb_type]--;
1514 rice_init = 1;
1515 }
1516 }
1517 } else {
1518 int last_coeff_abs_level_remaining = coeff_abs_level_remaining_decode(lc, c_rice_param);
1519
1520 trans_coeff_level = 1 + last_coeff_abs_level_remaining;
1521 if (trans_coeff_level > (3 << c_rice_param))
1522 c_rice_param = sps->persistent_rice_adaptation_enabled ? c_rice_param + 1 : FFMIN(c_rice_param + 1, 4);
1523 if (sps->persistent_rice_adaptation_enabled && !rice_init) {
1524 int c_rice_p_init = lc->sub.stat_coeff[sb_type] / 4;
1525 if (last_coeff_abs_level_remaining >= (3 << c_rice_p_init))
1526 lc->sub.stat_coeff[sb_type]++;
1527 else if (2 * last_coeff_abs_level_remaining < (1 << c_rice_p_init))
1528 if (lc->sub.stat_coeff[sb_type] > 0)
1529 lc->sub.stat_coeff[sb_type]--;
1530 rice_init = 1;
1531 }
1532 }
1533 if (pps->sign_data_hiding_flag && sign_hidden) {
1534 sum_abs += trans_coeff_level;
1535 if (n == first_nz_pos_in_cg && (sum_abs&1))
1536 trans_coeff_level = -trans_coeff_level;
1537 }
1538 // equiprobable sign: apply it branchless
1539 sign = -(int64_t)(coeff_sign_flag >> 15);
1540 trans_coeff_level = (trans_coeff_level ^ sign) - sign;
1541 coeff_sign_flag <<= 1;
1542 if(!lc->cu.cu_transquant_bypass_flag) {
1543 if (sps->scaling_list_enabled && !(transform_skip_flag && log2_trafo_size > 2)) {
1544 if(y_c || x_c || log2_trafo_size < 4) {
1545 switch(log2_trafo_size) {
1546 case 3: pos = (y_c << 3) + x_c; break;
1547 case 4: pos = ((y_c >> 1) << 3) + (x_c >> 1); break;
1548 case 5: pos = ((y_c >> 2) << 3) + (x_c >> 2); break;
1549 default: pos = (y_c << 2) + x_c; break;
1550 }
1551 scale_m = scale_matrix[pos];
1552 } else {
1553 scale_m = dc_scale;
1554 }
1555 }
1556 trans_coeff_level = (trans_coeff_level * (int64_t)scale * (int64_t)scale_m + add) >> shift;
1557 trans_coeff_level = FFMAX(FFMIN(trans_coeff_level, 32767), -32768);
1558 }
1559 coeffs[y_c * trafo_size + x_c] = trans_coeff_level;
1560 }
1561 }
1562 }
1563
1564 if (lc->cu.cu_transquant_bypass_flag) {
1565 if (explicit_rdpcm_flag || (sps->implicit_rdpcm_enabled &&
1566 (pred_mode_intra == 10 || pred_mode_intra == 26))) {
1567 int mode = sps->implicit_rdpcm_enabled ? (pred_mode_intra == 26) : explicit_rdpcm_dir_flag;
1568
1569 s->hevcdsp.transform_rdpcm(coeffs, log2_trafo_size, mode);
1570 }
1571 } else {
1572 if (transform_skip_flag) {
1573 int rot = sps->transform_skip_rotation_enabled &&
1574 log2_trafo_size == 2 &&
1575 lc->cu.pred_mode == MODE_INTRA;
1576 if (rot) {
1577 for (i = 0; i < 8; i++)
1578 FFSWAP(int16_t, coeffs[i], coeffs[16 - i - 1]);
1579 }
1580
1581 s->hevcdsp.dequant(coeffs, log2_trafo_size);
1582
1583 if (explicit_rdpcm_flag || (sps->implicit_rdpcm_enabled &&
1584 lc->cu.pred_mode == MODE_INTRA &&
1585 (pred_mode_intra == 10 || pred_mode_intra == 26))) {
1586 int mode = explicit_rdpcm_flag ? explicit_rdpcm_dir_flag : (pred_mode_intra == 26);
1587
1588 s->hevcdsp.transform_rdpcm(coeffs, log2_trafo_size, mode);
1589 }
1590 } else if (lc->cu.pred_mode == MODE_INTRA && c_idx == 0 && log2_trafo_size == 2) {
1591 s->hevcdsp.transform_4x4_luma(coeffs);
1592 } else {
1593 if (max_xy == 0)
1594 s->hevcdsp.idct_dc[log2_trafo_size - 2](coeffs);
1595 else
1596 s->hevcdsp.idct[log2_trafo_size - 2](coeffs, col_limit);
1597 }
1598 }
1599 if (lc->tu.cross_pf) {
1600 int16_t *coeffs_y = (int16_t*)lc->edge_emu_buffer;
1601
1602 for (i = 0; i < (trafo_size * trafo_size); i++) {
1603 coeffs[i] = coeffs[i] + ((lc->tu.res_scale_val * coeffs_y[i]) >> 3);
1604 }
1605 }
1606 s->hevcdsp.add_residual[log2_trafo_size-2](dst, coeffs, stride);
1607}
1608
1609void ff_hevc_hls_mvd_coding(HEVCLocalContext *lc, int x0, int y0, int log2_cb_size)
1610{
1611 int x = abs_mvd_greater0_flag_decode(lc);
1612 int y = abs_mvd_greater0_flag_decode(lc);
1613
1614 if (x)
1616 if (y)
1618
1619 switch (x) {
1620 case 2: lc->pu.mvd.x = mvd_decode(lc); break;
1621 case 1: lc->pu.mvd.x = mvd_sign_flag_decode(lc); break;
1622 case 0: lc->pu.mvd.x = 0; break;
1623 }
1624
1625 switch (y) {
1626 case 2: lc->pu.mvd.y = mvd_decode(lc); break;
1627 case 1: lc->pu.mvd.y = mvd_sign_flag_decode(lc); break;
1628 case 0: lc->pu.mvd.y = 0; break;
1629 }
1630}
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition dsp.h:97
static void bit_depth(AudioStatsContext *s, const uint64_t *const mask, uint8_t *depth)
Definition af_astats.c:246
int ff_init_cabac_decoder(CABACContext *c, const uint8_t *buf, int buf_size)
Definition cabac.c:162
#define CABAC_BITS
Definition cabac.h:38
#define CABAC_MASK
Definition cabac.h:39
Context Adaptive Binary Arithmetic Coder inline functions.
static av_unused int get_cabac_terminate(CABACContext *c)
static av_unused const uint8_t * skip_bytes(CABACContext *c, int n)
Skip n bytes and reset the decoder.
#define flag(name)
Definition cbs_h264.c:60
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
static int FUNC sps(CodedBitstreamContext *ctx, RWContext *rw, H264RawSPS *current)
#define s(width, name)
Definition cbs_vp9.c:198
common internal and external API header
#define av_clip
Definition common.h:100
#define av_zero_extend
Definition common.h:151
#define NULL
Definition coverity.c:32
long long int64_t
Definition coverity.c:34
#define max(a, b)
uint64_t pps
Definition dovi_rpuenc.c:36
double value
Definition eval.c:102
#define OFFSET(x)
int ret
Definition ffplay.c:391
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition error.h:61
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
#define ff_ctz
Definition intmath.h:105
int ff_hevc_end_of_slice_flag_decode(HEVCLocalContext *lc)
Definition cabac.c:577
static int cabac_reinit(HEVCLocalContext *lc)
Definition cabac.c:425
int ff_hevc_cu_transquant_bypass_flag_decode(HEVCLocalContext *lc)
Definition cabac.c:582
int ff_hevc_sao_type_idx_decode(HEVCLocalContext *lc)
Definition cabac.c:535
static int substream_continue(HEVCLocalContext *lc)
Definition cabac.c:456
static const uint8_t diag_scan2x2_inv[2][2]
Definition cabac.c:379
#define GET_CABAC(ctx)
Definition cabac.c:528
static av_always_inline int coeff_abs_level_greater1_flag_decode(HEVCLocalContext *lc, int c_idx, int inc)
Definition cabac.c:938
static av_always_inline int last_significant_coeff_suffix_decode(HEVCLocalContext *lc, int last_significant_coeff_prefix)
Definition cabac.c:906
static av_always_inline int significant_coeff_flag_decode(HEVCLocalContext *lc, int n, int offset, const uint8_t *ctx_idx_map)
Definition cabac.c:926
static const uint8_t horiz_scan4x4_y[16]
Definition cabac.c:353
int ff_hevc_no_residual_syntax_flag_decode(HEVCLocalContext *lc)
Definition cabac.c:797
int ff_hevc_sao_merge_flag_decode(HEVCLocalContext *lc)
Definition cabac.c:530
static av_always_inline int abs_mvd_greater0_flag_decode(HEVCLocalContext *lc)
Definition cabac.c:802
static const uint8_t horiz_scan2x2_y[4]
Definition cabac.c:342
int ff_hevc_merge_flag_decode(HEVCLocalContext *lc)
Definition cabac.c:761
int ff_hevc_cu_chroma_qp_offset_flag(HEVCLocalContext *lc)
Definition cabac.c:632
static const uint8_t scan_1x1[1]
Definition cabac.c:334
#define CNU
Definition cabac.c:96
int ff_hevc_cu_chroma_qp_offset_idx(HEVCLocalContext *lc, int chroma_qp_offset_list_len_minus1)
Definition cabac.c:637
int ff_hevc_sao_offset_abs_decode(HEVCLocalContext *lc, int bit_depth)
Definition cabac.c:555
#define GET_COORD(offset, n)
static int explicit_rdpcm_dir_flag_decode(HEVCLocalContext *lc, int c_idx)
Definition cabac.c:860
int ff_hevc_res_scale_sign_flag(HEVCLocalContext *lc, int idx)
Definition cabac.c:875
static void cabac_init_state(HEVCLocalContext *lc, const HEVCContext *s)
Definition cabac.c:430
static const uint8_t diag_scan8x8_inv[8][8]
Definition cabac.c:391
int ff_hevc_cu_qp_delta_abs(HEVCLocalContext *lc)
Definition cabac.c:600
static const uint8_t diag_scan4x4_inv[4][4]
Definition cabac.c:384
static int cabac_unary_prefix(CABACContext *c, int max)
Definition cabac.c:988
int ff_hevc_mvp_lx_flag_decode(HEVCLocalContext *lc)
Definition cabac.c:792
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:880
static av_always_inline int significant_coeff_group_flag_decode(HEVCLocalContext *lc, int c_idx, int ctx_cg)
Definition cabac.c:918
static const uint8_t horiz_scan4x4_x[16]
Definition cabac.c:346
void ff_hevc_save_states(HEVCLocalContext *lc, const HEVCPPS *pps, int ctb_addr_ts)
Definition cabac.c:402
int ff_hevc_cabac_init(HEVCLocalContext *lc, const HEVCPPS *pps, int ctb_addr_ts)
Definition cabac.c:472
int ff_hevc_split_transform_flag_decode(HEVCLocalContext *lc, int log2_trafo_size)
Definition cabac.c:835
int ff_hevc_log2_res_scale_abs(HEVCLocalContext *lc, int idx)
Definition cabac.c:865
static av_always_inline int coeff_sign_flag_decode(HEVCLocalContext *lc, uint8_t nb)
Definition cabac.c:1062
int ff_hevc_sao_eo_class_decode(HEVCLocalContext *lc)
Definition cabac.c:570
void ff_hevc_hls_mvd_coding(HEVCLocalContext *lc, int x0, int y0, int log2_cb_size)
Definition cabac.c:1609
int ff_hevc_mpm_idx_decode(HEVCLocalContext *lc)
Definition cabac.c:721
static const uint8_t horiz_scan2x2_x[4]
Definition cabac.c:338
static av_always_inline int coeff_abs_level_greater2_flag_decode(HEVCLocalContext *lc, int c_idx, int inc)
Definition cabac.c:947
static av_always_inline int abs_mvd_greater1_flag_decode(HEVCLocalContext *lc)
Definition cabac.c:807
static av_always_inline int mvd_decode(HEVCLocalContext *lc)
Definition cabac.c:812
static int cabac_bypass_bits(CABACContext *c, int n)
Definition cabac.c:956
int ff_hevc_sao_band_position_decode(HEVCLocalContext *lc)
Definition cabac.c:545
static av_always_inline int mvd_sign_flag_decode(HEVCLocalContext *lc)
Definition cabac.c:830
int ff_hevc_inter_pred_idc_decode(HEVCLocalContext *lc, int nPbW, int nPbH)
Definition cabac.c:766
int ff_hevc_cbf_cb_cr_decode(HEVCLocalContext *lc, int trafo_depth)
Definition cabac.c:840
static int explicit_rdpcm_flag_decode(HEVCLocalContext *lc, int c_idx)
Definition cabac.c:855
int ff_hevc_rem_intra_luma_pred_mode_decode(HEVCLocalContext *lc)
Definition cabac.c:729
int ff_hevc_sao_offset_sign_decode(HEVCLocalContext *lc)
Definition cabac.c:565
static av_always_inline int coeff_abs_level_remaining_decode(HEVCLocalContext *lc, int rc_rice_param)
Definition cabac.c:1021
static const uint8_t init_values[3][HEVC_CONTEXTS]
Indexed by init_type.
Definition cabac.c:100
int ff_hevc_intra_chroma_pred_mode_decode(HEVCLocalContext *lc)
Definition cabac.c:739
int ff_hevc_cbf_luma_decode(HEVCLocalContext *lc, int trafo_depth)
Definition cabac.c:845
int ff_hevc_merge_idx_decode(HEVCLocalContext *lc)
Definition cabac.c:750
#define CABAC_MAX_BIN
Definition cabac.c:32
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:1075
static const uint8_t diag_scan2x2_x[4]
Definition cabac.c:371
int ff_hevc_split_coding_unit_flag_decode(HEVCLocalContext *lc, uint8_t *tab_ct_depth, const HEVCSPS *sps, int ct_depth, int x0, int y0)
Definition cabac.c:653
int ff_hevc_pcm_flag_decode(HEVCLocalContext *lc)
Definition cabac.c:711
int ff_hevc_part_mode_decode(HEVCLocalContext *lc, const HEVCSPS *sps, int log2_cb_size)
Definition cabac.c:674
#define CABAC_ELEMS(ELEM)
Definition cabac.c:35
int ff_hevc_skip_flag_decode(HEVCLocalContext *lc, uint8_t *skip_flag, int x0, int y0, int x_cb, int y_cb, int min_cb_width)
Definition cabac.c:587
static const uint8_t diag_scan2x2_y[4]
Definition cabac.c:375
static void load_states(HEVCLocalContext *lc, const HEVCSPS *sps)
Definition cabac.c:417
int ff_hevc_cu_qp_delta_sign_flag(HEVCLocalContext *lc)
Definition cabac.c:627
int ff_hevc_prev_intra_luma_pred_flag_decode(HEVCLocalContext *lc)
Definition cabac.c:716
int ff_hevc_pred_mode_decode(HEVCLocalContext *lc)
Definition cabac.c:648
static int hevc_transform_skip_flag_decode(HEVCLocalContext *lc, int c_idx)
Definition cabac.c:850
static const uint8_t horiz_scan8x8_inv[8][8]
Definition cabac.c:360
int ff_hevc_ref_idx_lx_decode(HEVCLocalContext *lc, int num_ref_idx_lx)
Definition cabac.c:776
static av_always_inline int significant_coeff_flag_decode_0(HEVCLocalContext *lc, int c_idx, int offset)
Definition cabac.c:933
const uint8_t ff_hevc_diag_scan8x8_x[64]
Definition data.c:39
const uint8_t ff_hevc_diag_scan4x4_x[16]
Definition data.c:25
const uint8_t ff_hevc_diag_scan8x8_y[64]
Definition data.c:58
const uint8_t ff_hevc_diag_scan4x4_y[16]
Definition data.c:32
#define HEVC_STAT_COEFFS
Definition hevcdec.h:52
@ MODE_INTER
Definition hevcdec.h:107
@ PART_2Nx2N
Definition hevcdec.h:96
@ PART_Nx2N
Definition hevcdec.h:98
@ PART_NxN
Definition hevcdec.h:99
@ PART_2NxnD
Definition hevcdec.h:101
@ PART_nLx2N
Definition hevcdec.h:102
@ PART_2NxN
Definition hevcdec.h:97
@ PART_2NxnU
Definition hevcdec.h:100
@ PART_nRx2N
Definition hevcdec.h:103
@ PRED_BI
Definition hevcdec.h:115
@ SAO_BAND
Definition hevcdec.h:165
@ SAO_EDGE
Definition hevcdec.h:166
#define HEVC_CONTEXTS
Definition hevcdec.h:51
#define SAMPLE_CTB(tab, x, y)
Definition hevcdec.h:72
ScanType
Definition hevcdec.h:177
@ SCAN_HORIZ
Definition hevcdec.h:179
@ SCAN_DIAG
Definition hevcdec.h:178
@ SCAN_VERT
Definition hevcdec.h:180
static av_always_inline void scale(vec_s32 res[4], vec_s16 res_packed[2], const int shift)
#define r
Definition input.c:42
#define av_log2
Definition intmath.h:84
static const uint8_t div6[63+8 *6+1]
Definition intra.c:328
static const uint8_t rem6[63+8 *6+1]
Definition intra.c:320
static const int level_scale[2][6]
Definition intra.c:336
unsigned offset
Definition libaomenc.c:763
static int shift(int a, int b)
Definition bonk.c:261
@ HEVC_SLICE_I
Definition hevc.h:98
Macro definitions for various function/variable attributes.
#define av_always_inline
Definition attributes.h:72
#define get_cabac_bypass
Definition cabac.h:149
#define get_cabac_bypass_sign
Definition cabac.h:193
#define FFSWAP(type, a, b)
Definition macros.h:52
#define FFMIN(a, b)
Definition macros.h:49
#define FFMAX(a, b)
Definition macros.h:47
static int inc(int num, int period)
Definition perlin.c:34
static volatile sig_atomic_t sig
Definition signal.c:48
unsigned int pos
Definition spdifenc.c:431
enum PredMode pred_mode
PredMode.
Definition hevcdec.h:295
uint8_t cu_transquant_bypass_flag
Definition hevcdec.h:301
uint8_t state[HEVC_CONTEXTS]
Definition hevcdec.h:184
uint8_t stat_coeff[HEVC_STAT_COEFFS]
Definition hevcdec.h:185
uint8_t ctb_left_flag
Definition hevcdec.h:435
PredictionUnit pu
Definition hevcdec.h:449
HEVCSubstream sub
Definition hevcdec.h:410
uint8_t edge_emu_buffer[(MAX_PB_SIZE+7) *EDGE_EMU_BUFFER_STRIDE *2]
Definition hevcdec.h:442
TransformUnit tu
Definition hevcdec.h:433
const struct HEVCContext * parent
Definition hevcdec.h:413
HEVCCABACState * common_cabac_state
This is a pointer to the common CABAC state.
Definition hevcdec.h:431
uint8_t ctb_up_flag
Definition hevcdec.h:436
CodingUnit cu
Definition hevcdec.h:448
uint8_t edge_emu_buffer2[(MAX_PB_SIZE+7) *EDGE_EMU_BUFFER_STRIDE *2]
Definition hevcdec.h:444
const SliceHeader * sh
Definition hevcdec.h:417
Definition ps.h:371
Definition ps.h:252
int8_t cu_qp_offset_cr
Definition hevcdec.h:406
int8_t qp_y
Definition hevcdec.h:402
uint8_t opened
Definition hevcdec.h:396
CABACContext cc
Definition hevcdec.h:398
uint8_t stat_coeff[HEVC_STAT_COEFFS]
Definition hevcdec.h:400
int8_t cu_qp_offset_cb
Definition hevcdec.h:405
uint8_t cabac_state[HEVC_CONTEXTS]
Definition hevcdec.h:399
size_t size
Definition hevcdec.h:394
const uint8_t * data
CABAC bytes of this substream.
Definition hevcdec.h:393
int16_t x
horizontal component of motion vector
Definition hevcdec.h:305
int16_t y
vertical component of motion vector
Definition hevcdec.h:306
uint8_t sl_dc[2][6]
Definition ps.h:249
uint8_t sl[4][6][64]
Definition ps.h:248
int8_t slice_qp
Definition hevcdec.h:271
int slice_cb_qp_offset
Definition hevcdec.h:251
enum HEVCSliceType slice_type
Definition hevcdec.h:214
int slice_ctb_addr_rs
Definition hevcdec.h:287
uint8_t cabac_init_flag
Definition hevcdec.h:243
uint8_t dependent_slice_segment_flag
Definition hevcdec.h:220
uint8_t first_slice_in_pic_flag
Definition hevcdec.h:219
int slice_cr_qp_offset
Definition hevcdec.h:252
uint8_t cross_pf
Definition hevcdec.h:345
int intra_pred_mode_c
Definition hevcdec.h:341
int res_scale_val
Definition hevcdec.h:337
int intra_pred_mode
Definition hevcdec.h:340
Definition swscale.c:85
#define stride
#define av_log(a,...)
char prefix[8]
#define MODE_INTRA
Definition vp3.c:83
static double c[64]