Line | Branch | Exec | Source |
---|---|---|---|
1 | /* | ||
2 | * HEVC video decoder | ||
3 | * | ||
4 | * Copyright (C) 2012 - 2013 Guillaume Martres | ||
5 | * | ||
6 | * This file is part of FFmpeg. | ||
7 | * | ||
8 | * FFmpeg is free software; you can redistribute it and/or | ||
9 | * modify it under the terms of the GNU Lesser General Public | ||
10 | * License as published by the Free Software Foundation; either | ||
11 | * version 2.1 of the License, or (at your option) any later version. | ||
12 | * | ||
13 | * FFmpeg is distributed in the hope that it will be useful, | ||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
16 | * Lesser General Public License for more details. | ||
17 | * | ||
18 | * You should have received a copy of the GNU Lesser General Public | ||
19 | * License along with FFmpeg; if not, write to the Free Software | ||
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
21 | */ | ||
22 | |||
23 | #ifndef AVCODEC_HEVC_HEVCDEC_H | ||
24 | #define AVCODEC_HEVC_HEVCDEC_H | ||
25 | |||
26 | #include <stdatomic.h> | ||
27 | |||
28 | #include "libavutil/buffer.h" | ||
29 | #include "libavutil/mem_internal.h" | ||
30 | |||
31 | #include "libavcodec/avcodec.h" | ||
32 | #include "libavcodec/bswapdsp.h" | ||
33 | #include "libavcodec/cabac.h" | ||
34 | #include "libavcodec/dovi_rpu.h" | ||
35 | #include "libavcodec/get_bits.h" | ||
36 | #include "libavcodec/h2645_parse.h" | ||
37 | #include "libavcodec/h274.h" | ||
38 | #include "libavcodec/progressframe.h" | ||
39 | #include "libavcodec/videodsp.h" | ||
40 | |||
41 | #include "dsp.h" | ||
42 | #include "hevc.h" | ||
43 | #include "pred.h" | ||
44 | #include "ps.h" | ||
45 | #include "sei.h" | ||
46 | |||
47 | #define SHIFT_CTB_WPP 2 | ||
48 | |||
49 | #define MAX_TB_SIZE 32 | ||
50 | #define MAX_QP 51 | ||
51 | #define DEFAULT_INTRA_TC_OFFSET 2 | ||
52 | |||
53 | #define HEVC_CONTEXTS 199 | ||
54 | #define HEVC_STAT_COEFFS 4 | ||
55 | |||
56 | #define MRG_MAX_NUM_CANDS 5 | ||
57 | |||
58 | #define L0 0 | ||
59 | #define L1 1 | ||
60 | |||
61 | #define EPEL_EXTRA_BEFORE 1 | ||
62 | #define EPEL_EXTRA_AFTER 2 | ||
63 | #define EPEL_EXTRA 3 | ||
64 | #define QPEL_EXTRA_BEFORE 3 | ||
65 | #define QPEL_EXTRA_AFTER 4 | ||
66 | #define QPEL_EXTRA 7 | ||
67 | |||
68 | #define EDGE_EMU_BUFFER_STRIDE 80 | ||
69 | |||
70 | /** | ||
71 | * Value of the luma sample at position (x, y) in the 2D array tab. | ||
72 | */ | ||
73 | #define SAMPLE(tab, x, y) ((tab)[(y) * s->sps->width + (x)]) | ||
74 | #define SAMPLE_CTB(tab, x, y) ((tab)[(y) * min_cb_width + (x)]) | ||
75 | |||
76 | #define IS_IDR(s) ((s)->nal_unit_type == HEVC_NAL_IDR_W_RADL || (s)->nal_unit_type == HEVC_NAL_IDR_N_LP) | ||
77 | #define IS_BLA(s) ((s)->nal_unit_type == HEVC_NAL_BLA_W_RADL || (s)->nal_unit_type == HEVC_NAL_BLA_W_LP || \ | ||
78 | (s)->nal_unit_type == HEVC_NAL_BLA_N_LP) | ||
79 | #define IS_IRAP(s) ((s)->nal_unit_type >= HEVC_NAL_BLA_W_LP && (s)->nal_unit_type <= HEVC_NAL_RSV_IRAP_VCL23) | ||
80 | |||
81 | #define HEVC_RECOVERY_UNSPECIFIED INT_MAX | ||
82 | #define HEVC_RECOVERY_END INT_MIN | ||
83 | #define HEVC_IS_RECOVERING(s) ((s)->recovery_poc != HEVC_RECOVERY_UNSPECIFIED && (s)->recovery_poc != HEVC_RECOVERY_END) | ||
84 | |||
85 | enum RPSType { | ||
86 | ST_CURR_BEF = 0, | ||
87 | ST_CURR_AFT, | ||
88 | ST_FOLL, | ||
89 | LT_CURR, | ||
90 | LT_FOLL, | ||
91 | INTER_LAYER0, | ||
92 | INTER_LAYER1, | ||
93 | NB_RPS_TYPE, | ||
94 | }; | ||
95 | |||
96 | enum PartMode { | ||
97 | PART_2Nx2N = 0, | ||
98 | PART_2NxN = 1, | ||
99 | PART_Nx2N = 2, | ||
100 | PART_NxN = 3, | ||
101 | PART_2NxnU = 4, | ||
102 | PART_2NxnD = 5, | ||
103 | PART_nLx2N = 6, | ||
104 | PART_nRx2N = 7, | ||
105 | }; | ||
106 | |||
107 | enum PredMode { | ||
108 | MODE_INTER = 0, | ||
109 | MODE_INTRA, | ||
110 | MODE_SKIP, | ||
111 | }; | ||
112 | |||
113 | enum InterPredIdc { | ||
114 | PRED_L0 = 0, | ||
115 | PRED_L1, | ||
116 | PRED_BI, | ||
117 | }; | ||
118 | |||
119 | enum PredFlag { | ||
120 | PF_INTRA = 0, | ||
121 | PF_L0, | ||
122 | PF_L1, | ||
123 | PF_BI, | ||
124 | }; | ||
125 | |||
126 | enum IntraPredMode { | ||
127 | INTRA_PLANAR = 0, | ||
128 | INTRA_DC, | ||
129 | INTRA_ANGULAR_2, | ||
130 | INTRA_ANGULAR_3, | ||
131 | INTRA_ANGULAR_4, | ||
132 | INTRA_ANGULAR_5, | ||
133 | INTRA_ANGULAR_6, | ||
134 | INTRA_ANGULAR_7, | ||
135 | INTRA_ANGULAR_8, | ||
136 | INTRA_ANGULAR_9, | ||
137 | INTRA_ANGULAR_10, | ||
138 | INTRA_ANGULAR_11, | ||
139 | INTRA_ANGULAR_12, | ||
140 | INTRA_ANGULAR_13, | ||
141 | INTRA_ANGULAR_14, | ||
142 | INTRA_ANGULAR_15, | ||
143 | INTRA_ANGULAR_16, | ||
144 | INTRA_ANGULAR_17, | ||
145 | INTRA_ANGULAR_18, | ||
146 | INTRA_ANGULAR_19, | ||
147 | INTRA_ANGULAR_20, | ||
148 | INTRA_ANGULAR_21, | ||
149 | INTRA_ANGULAR_22, | ||
150 | INTRA_ANGULAR_23, | ||
151 | INTRA_ANGULAR_24, | ||
152 | INTRA_ANGULAR_25, | ||
153 | INTRA_ANGULAR_26, | ||
154 | INTRA_ANGULAR_27, | ||
155 | INTRA_ANGULAR_28, | ||
156 | INTRA_ANGULAR_29, | ||
157 | INTRA_ANGULAR_30, | ||
158 | INTRA_ANGULAR_31, | ||
159 | INTRA_ANGULAR_32, | ||
160 | INTRA_ANGULAR_33, | ||
161 | INTRA_ANGULAR_34, | ||
162 | }; | ||
163 | |||
164 | enum SAOType { | ||
165 | SAO_NOT_APPLIED = 0, | ||
166 | SAO_BAND, | ||
167 | SAO_EDGE, | ||
168 | SAO_APPLIED | ||
169 | }; | ||
170 | |||
171 | enum SAOEOClass { | ||
172 | SAO_EO_HORIZ = 0, | ||
173 | SAO_EO_VERT, | ||
174 | SAO_EO_135D, | ||
175 | SAO_EO_45D, | ||
176 | }; | ||
177 | |||
178 | enum ScanType { | ||
179 | SCAN_DIAG = 0, | ||
180 | SCAN_HORIZ, | ||
181 | SCAN_VERT, | ||
182 | }; | ||
183 | |||
184 | typedef struct HEVCCABACState { | ||
185 | uint8_t state[HEVC_CONTEXTS]; | ||
186 | uint8_t stat_coeff[HEVC_STAT_COEFFS]; | ||
187 | } HEVCCABACState; | ||
188 | |||
189 | typedef struct LongTermRPS { | ||
190 | int poc[32]; | ||
191 | uint8_t poc_msb_present[32]; | ||
192 | uint8_t used[32]; | ||
193 | uint8_t nb_refs; | ||
194 | } LongTermRPS; | ||
195 | |||
196 | typedef struct RefPicList { | ||
197 | struct HEVCFrame *ref[HEVC_MAX_REFS]; | ||
198 | int list[HEVC_MAX_REFS]; | ||
199 | int isLongTerm[HEVC_MAX_REFS]; | ||
200 | int nb_refs; | ||
201 | } RefPicList; | ||
202 | |||
203 | typedef struct RefPicListTab { | ||
204 | RefPicList refPicList[2]; | ||
205 | } RefPicListTab; | ||
206 | |||
207 | typedef struct SliceHeader { | ||
208 | unsigned int pps_id; | ||
209 | |||
210 | ///< address (in raster order) of the first block in the current slice segment | ||
211 | unsigned int slice_segment_addr; | ||
212 | ///< address (in raster order) of the first block in the current slice | ||
213 | unsigned int slice_addr; | ||
214 | |||
215 | enum HEVCSliceType slice_type; | ||
216 | |||
217 | int pic_order_cnt_lsb; | ||
218 | int poc; | ||
219 | |||
220 | uint8_t first_slice_in_pic_flag; | ||
221 | uint8_t dependent_slice_segment_flag; | ||
222 | uint8_t pic_output_flag; | ||
223 | uint8_t colour_plane_id; | ||
224 | uint8_t inter_layer_pred; | ||
225 | |||
226 | ///< RPS coded in the slice header itself is stored here | ||
227 | int short_term_ref_pic_set_sps_flag; | ||
228 | int short_term_ref_pic_set_size; | ||
229 | ShortTermRPS slice_rps; | ||
230 | const ShortTermRPS *short_term_rps; | ||
231 | int long_term_ref_pic_set_size; | ||
232 | LongTermRPS long_term_rps; | ||
233 | unsigned int list_entry_lx[2][32]; | ||
234 | |||
235 | uint8_t rpl_modification_flag[2]; | ||
236 | uint8_t no_output_of_prior_pics_flag; | ||
237 | uint8_t slice_temporal_mvp_enabled_flag; | ||
238 | |||
239 | unsigned int nb_refs[2]; | ||
240 | |||
241 | uint8_t slice_sample_adaptive_offset_flag[3]; | ||
242 | uint8_t mvd_l1_zero_flag; | ||
243 | |||
244 | uint8_t cabac_init_flag; | ||
245 | uint8_t disable_deblocking_filter_flag; ///< slice_header_disable_deblocking_filter_flag | ||
246 | uint8_t slice_loop_filter_across_slices_enabled_flag; | ||
247 | uint8_t collocated_list; | ||
248 | |||
249 | unsigned int collocated_ref_idx; | ||
250 | |||
251 | int slice_qp_delta; | ||
252 | int slice_cb_qp_offset; | ||
253 | int slice_cr_qp_offset; | ||
254 | |||
255 | int slice_act_y_qp_offset; | ||
256 | int slice_act_cb_qp_offset; | ||
257 | int slice_act_cr_qp_offset; | ||
258 | |||
259 | uint8_t cu_chroma_qp_offset_enabled_flag; | ||
260 | |||
261 | int beta_offset; ///< beta_offset_div2 * 2 | ||
262 | int tc_offset; ///< tc_offset_div2 * 2 | ||
263 | |||
264 | uint8_t max_num_merge_cand; ///< 5 - 5_minus_max_num_merge_cand | ||
265 | uint8_t use_integer_mv_flag; | ||
266 | |||
267 | unsigned *entry_point_offset; | ||
268 | int * offset; | ||
269 | int * size; | ||
270 | int num_entry_point_offsets; | ||
271 | |||
272 | int8_t slice_qp; | ||
273 | |||
274 | uint8_t luma_log2_weight_denom; | ||
275 | int16_t chroma_log2_weight_denom; | ||
276 | |||
277 | int16_t luma_weight_l0[16]; | ||
278 | int16_t chroma_weight_l0[16][2]; | ||
279 | int16_t chroma_weight_l1[16][2]; | ||
280 | int16_t luma_weight_l1[16]; | ||
281 | |||
282 | int16_t luma_offset_l0[16]; | ||
283 | int16_t chroma_offset_l0[16][2]; | ||
284 | |||
285 | int16_t luma_offset_l1[16]; | ||
286 | int16_t chroma_offset_l1[16][2]; | ||
287 | |||
288 | int slice_ctb_addr_rs; | ||
289 | unsigned data_offset; | ||
290 | } SliceHeader; | ||
291 | |||
292 | typedef struct CodingUnit { | ||
293 | int x; | ||
294 | int y; | ||
295 | |||
296 | enum PredMode pred_mode; ///< PredMode | ||
297 | enum PartMode part_mode; ///< PartMode | ||
298 | |||
299 | // Inferred parameters | ||
300 | uint8_t intra_split_flag; ///< IntraSplitFlag | ||
301 | uint8_t max_trafo_depth; ///< MaxTrafoDepth | ||
302 | uint8_t cu_transquant_bypass_flag; | ||
303 | } CodingUnit; | ||
304 | |||
305 | typedef struct Mv { | ||
306 | int16_t x; ///< horizontal component of motion vector | ||
307 | int16_t y; ///< vertical component of motion vector | ||
308 | } Mv; | ||
309 | |||
310 | typedef struct MvField { | ||
311 | DECLARE_ALIGNED(4, Mv, mv)[2]; | ||
312 | int8_t ref_idx[2]; | ||
313 | int8_t pred_flag; | ||
314 | } MvField; | ||
315 | |||
316 | typedef struct NeighbourAvailable { | ||
317 | int cand_bottom_left; | ||
318 | int cand_left; | ||
319 | int cand_up; | ||
320 | int cand_up_left; | ||
321 | int cand_up_right; | ||
322 | int cand_up_right_sap; | ||
323 | } NeighbourAvailable; | ||
324 | |||
325 | typedef struct PredictionUnit { | ||
326 | int mpm_idx; | ||
327 | int rem_intra_luma_pred_mode; | ||
328 | uint8_t intra_pred_mode[4]; | ||
329 | Mv mvd; | ||
330 | uint8_t merge_flag; | ||
331 | uint8_t intra_pred_mode_c[4]; | ||
332 | uint8_t chroma_mode_c[4]; | ||
333 | } PredictionUnit; | ||
334 | |||
335 | typedef struct TransformUnit { | ||
336 | int cu_qp_delta; | ||
337 | |||
338 | int res_scale_val; | ||
339 | |||
340 | // Inferred parameters; | ||
341 | int intra_pred_mode; | ||
342 | int intra_pred_mode_c; | ||
343 | int chroma_mode_c; | ||
344 | uint8_t is_cu_qp_delta_coded; | ||
345 | uint8_t is_cu_chroma_qp_offset_coded; | ||
346 | int8_t cu_qp_offset_cb; | ||
347 | int8_t cu_qp_offset_cr; | ||
348 | uint8_t cross_pf; | ||
349 | } TransformUnit; | ||
350 | |||
351 | typedef struct DBParams { | ||
352 | int beta_offset; | ||
353 | int tc_offset; | ||
354 | } DBParams; | ||
355 | |||
356 | #define HEVC_FRAME_FLAG_OUTPUT (1 << 0) | ||
357 | #define HEVC_FRAME_FLAG_SHORT_REF (1 << 1) | ||
358 | #define HEVC_FRAME_FLAG_LONG_REF (1 << 2) | ||
359 | #define HEVC_FRAME_FLAG_UNAVAILABLE (1 << 3) | ||
360 | #define HEVC_FRAME_FLAG_CORRUPT (1 << 4) | ||
361 | |||
362 | typedef struct HEVCFrame { | ||
363 | union { | ||
364 | struct { | ||
365 | AVFrame *f; | ||
366 | }; | ||
367 | ProgressFrame tf; | ||
368 | }; | ||
369 | AVFrame *frame_grain; | ||
370 | int needs_fg; /* 1 if grain needs to be applied by the decoder */ | ||
371 | MvField *tab_mvf; ///< RefStruct reference | ||
372 | RefPicList *refPicList; | ||
373 | RefPicListTab **rpl_tab; ///< RefStruct reference | ||
374 | int ctb_count; | ||
375 | int poc; | ||
376 | |||
377 | const HEVCPPS *pps; ///< RefStruct reference | ||
378 | RefPicListTab *rpl; ///< RefStruct reference | ||
379 | int nb_rpl_elems; | ||
380 | |||
381 | void *hwaccel_picture_private; ///< RefStruct reference | ||
382 | |||
383 | // for secondary-layer frames, this is the DPB index of the base-layer frame | ||
384 | // from the same AU, if it exists, otherwise -1 | ||
385 | int base_layer_frame; | ||
386 | |||
387 | /** | ||
388 | * A combination of HEVC_FRAME_FLAG_* | ||
389 | */ | ||
390 | uint8_t flags; | ||
391 | } HEVCFrame; | ||
392 | |||
393 | typedef struct HEVCLocalContext { | ||
394 | uint8_t cabac_state[HEVC_CONTEXTS]; | ||
395 | |||
396 | uint8_t stat_coeff[HEVC_STAT_COEFFS]; | ||
397 | |||
398 | uint8_t first_qp_group; | ||
399 | |||
400 | void *logctx; | ||
401 | const struct HEVCContext *parent; | ||
402 | |||
403 | CABACContext cc; | ||
404 | |||
405 | /** | ||
406 | * This is a pointer to the common CABAC state. | ||
407 | * In case entropy_coding_sync_enabled_flag is set, | ||
408 | * the CABAC state after decoding the second CTU in a row is | ||
409 | * stored here and used to initialize the CABAC state before | ||
410 | * decoding the first CTU in the next row. | ||
411 | * This is the basis for WPP and in case slice-threading is used, | ||
412 | * the next row is decoded by another thread making this state | ||
413 | * shared between threads. | ||
414 | */ | ||
415 | HEVCCABACState *common_cabac_state; | ||
416 | |||
417 | int8_t qp_y; | ||
418 | int8_t curr_qp_y; | ||
419 | |||
420 | int qPy_pred; | ||
421 | |||
422 | TransformUnit tu; | ||
423 | |||
424 | uint8_t ctb_left_flag; | ||
425 | uint8_t ctb_up_flag; | ||
426 | uint8_t ctb_up_right_flag; | ||
427 | uint8_t ctb_up_left_flag; | ||
428 | int end_of_tiles_x; | ||
429 | int end_of_tiles_y; | ||
430 | /* +7 is for subpixel interpolation, *2 for high bit depths */ | ||
431 | DECLARE_ALIGNED(32, uint8_t, edge_emu_buffer)[(MAX_PB_SIZE + 7) * EDGE_EMU_BUFFER_STRIDE * 2]; | ||
432 | /* The extended size between the new edge emu buffer is abused by SAO */ | ||
433 | DECLARE_ALIGNED(32, uint8_t, edge_emu_buffer2)[(MAX_PB_SIZE + 7) * EDGE_EMU_BUFFER_STRIDE * 2]; | ||
434 | DECLARE_ALIGNED(32, int16_t, tmp)[MAX_PB_SIZE * MAX_PB_SIZE]; | ||
435 | |||
436 | int ct_depth; | ||
437 | CodingUnit cu; | ||
438 | PredictionUnit pu; | ||
439 | NeighbourAvailable na; | ||
440 | |||
441 | #define BOUNDARY_LEFT_SLICE (1 << 0) | ||
442 | #define BOUNDARY_LEFT_TILE (1 << 1) | ||
443 | #define BOUNDARY_UPPER_SLICE (1 << 2) | ||
444 | #define BOUNDARY_UPPER_TILE (1 << 3) | ||
445 | /* properties of the boundary of the current CTB for the purposes | ||
446 | * of the deblocking filter */ | ||
447 | int boundary_flags; | ||
448 | |||
449 | // an array of these structs is used for per-thread state - pad its size | ||
450 | // to avoid false sharing | ||
451 | char padding[128]; | ||
452 | } HEVCLocalContext; | ||
453 | |||
454 | typedef struct HEVCLayerContext { | ||
455 | HEVCFrame DPB[32]; | ||
456 | HEVCFrame *cur_frame; | ||
457 | |||
458 | const HEVCSPS *sps; // RefStruct reference | ||
459 | |||
460 | int bs_width; | ||
461 | int bs_height; | ||
462 | |||
463 | SAOParams *sao; | ||
464 | DBParams *deblock; | ||
465 | |||
466 | // CU | ||
467 | uint8_t *skip_flag; | ||
468 | uint8_t *tab_ct_depth; | ||
469 | |||
470 | // PU | ||
471 | uint8_t *cbf_luma; // cbf_luma of colocated TU | ||
472 | uint8_t *tab_ipm; | ||
473 | uint8_t *is_pcm; | ||
474 | |||
475 | // CTB-level flags affecting loop filter operation | ||
476 | uint8_t *filter_slice_edges; | ||
477 | |||
478 | int32_t *tab_slice_address; | ||
479 | |||
480 | int8_t *qp_y_tab; | ||
481 | |||
482 | uint8_t *horizontal_bs; | ||
483 | uint8_t *vertical_bs; | ||
484 | |||
485 | uint8_t *sao_pixel_buffer_h[3]; | ||
486 | uint8_t *sao_pixel_buffer_v[3]; | ||
487 | |||
488 | struct AVRefStructPool *tab_mvf_pool; | ||
489 | struct AVRefStructPool *rpl_tab_pool; | ||
490 | } HEVCLayerContext; | ||
491 | |||
492 | typedef struct HEVCContext { | ||
493 | const AVClass *c; // needed by private avoptions | ||
494 | AVCodecContext *avctx; | ||
495 | |||
496 | HEVCLocalContext *local_ctx; | ||
497 | unsigned nb_local_ctx; | ||
498 | |||
499 | // per-layer decoding state, addressed by VPS layer indices | ||
500 | HEVCLayerContext layers[HEVC_VPS_MAX_LAYERS]; | ||
501 | // VPS index of the layer currently being decoded | ||
502 | unsigned cur_layer; | ||
503 | // bitmask of layer indices that are active for decoding/output | ||
504 | unsigned layers_active_decode; | ||
505 | unsigned layers_active_output; | ||
506 | |||
507 | /** 1 if the independent slice segment header was successfully parsed */ | ||
508 | uint8_t slice_initialized; | ||
509 | |||
510 | struct AVContainerFifo *output_fifo; | ||
511 | |||
512 | HEVCParamSets ps; | ||
513 | HEVCSEI sei; | ||
514 | struct AVMD5 *md5_ctx; | ||
515 | |||
516 | ///< candidate references for the current frame | ||
517 | RefPicList rps[NB_RPS_TYPE]; | ||
518 | |||
519 | const HEVCVPS *vps; ///< RefStruct reference | ||
520 | const HEVCPPS *pps; ///< RefStruct reference | ||
521 | SliceHeader sh; | ||
522 | enum HEVCNALUnitType nal_unit_type; | ||
523 | int temporal_id; ///< temporal_id_plus1 - 1 | ||
524 | HEVCFrame *cur_frame; | ||
525 | HEVCFrame *collocated_ref; | ||
526 | int poc; | ||
527 | int poc_tid0; | ||
528 | int slice_idx; ///< number of the slice being currently decoded | ||
529 | int eos; ///< current packet contains an EOS/EOB NAL | ||
530 | int last_eos; ///< last packet contains an EOS/EOB NAL | ||
531 | int recovery_poc; | ||
532 | |||
533 | // NoRaslOutputFlag associated with the last IRAP frame | ||
534 | int no_rasl_output_flag; | ||
535 | |||
536 | HEVCPredContext hpc; | ||
537 | HEVCDSPContext hevcdsp; | ||
538 | VideoDSPContext vdsp; | ||
539 | BswapDSPContext bdsp; | ||
540 | H274FilmGrainDatabase h274db; | ||
541 | |||
542 | /** used on BE to byteswap the lines for checksumming */ | ||
543 | uint8_t *checksum_buf; | ||
544 | int checksum_buf_size; | ||
545 | |||
546 | /** The target for the common_cabac_state of the local contexts. */ | ||
547 | HEVCCABACState cabac; | ||
548 | |||
549 | struct ThreadProgress *wpp_progress; | ||
550 | unsigned nb_wpp_progress; | ||
551 | |||
552 | atomic_int wpp_err; | ||
553 | |||
554 | const uint8_t *data; | ||
555 | |||
556 | H2645Packet pkt; | ||
557 | // type of the first VCL NAL of the current frame | ||
558 | enum HEVCNALUnitType first_nal_type; | ||
559 | // index in pkt.nals of the NAL unit after which we can call | ||
560 | // ff_thread_finish_setup() | ||
561 | unsigned finish_setup_nal_idx; | ||
562 | |||
563 | int is_nalff; ///< this flag is != 0 if bitstream is encapsulated | ||
564 | ///< as a format defined in 14496-15 | ||
565 | int apply_defdispwin; | ||
566 | |||
567 | // multi-layer AVOptions | ||
568 | int *view_ids; | ||
569 | unsigned nb_view_ids; | ||
570 | |||
571 | unsigned *view_ids_available; | ||
572 | unsigned nb_view_ids_available; | ||
573 | |||
574 | unsigned *view_pos_available; | ||
575 | unsigned nb_view_pos_available; | ||
576 | |||
577 | int nal_length_size; ///< Number of bytes used for nal length (1, 2 or 4) | ||
578 | int nuh_layer_id; | ||
579 | |||
580 | int film_grain_warning_shown; | ||
581 | |||
582 | // dts of the packet currently being decoded | ||
583 | int64_t pkt_dts; | ||
584 | |||
585 | AVBufferRef *rpu_buf; ///< 0 or 1 Dolby Vision RPUs. | ||
586 | DOVIContext dovi_ctx; ///< Dolby Vision decoding context | ||
587 | } HEVCContext; | ||
588 | |||
589 | /** | ||
590 | * Mark all frames in DPB as unused for reference. | ||
591 | */ | ||
592 | void ff_hevc_clear_refs(HEVCLayerContext *l); | ||
593 | |||
594 | /** | ||
595 | * Drop all frames currently in DPB. | ||
596 | */ | ||
597 | void ff_hevc_flush_dpb(HEVCContext *s); | ||
598 | |||
599 | const RefPicList *ff_hevc_get_ref_list(const HEVCFrame *frame, int x0, int y0); | ||
600 | |||
601 | /** | ||
602 | * Construct the reference picture sets for the current frame. | ||
603 | */ | ||
604 | int ff_hevc_frame_rps(HEVCContext *s, HEVCLayerContext *l); | ||
605 | |||
606 | /** | ||
607 | * Construct the reference picture list(s) for the current slice. | ||
608 | */ | ||
609 | int ff_hevc_slice_rpl(HEVCContext *s); | ||
610 | |||
611 | void ff_hevc_save_states(HEVCLocalContext *lc, const HEVCPPS *pps, | ||
612 | int ctb_addr_ts); | ||
613 | int ff_hevc_cabac_init(HEVCLocalContext *lc, const HEVCPPS *pps, | ||
614 | int ctb_addr_ts, const uint8_t *data, size_t size, | ||
615 | int is_wpp); | ||
616 | int ff_hevc_sao_merge_flag_decode(HEVCLocalContext *lc); | ||
617 | int ff_hevc_sao_type_idx_decode(HEVCLocalContext *lc); | ||
618 | int ff_hevc_sao_band_position_decode(HEVCLocalContext *lc); | ||
619 | int ff_hevc_sao_offset_abs_decode(HEVCLocalContext *lc, int bit_depth); | ||
620 | int ff_hevc_sao_offset_sign_decode(HEVCLocalContext *lc); | ||
621 | int ff_hevc_sao_eo_class_decode(HEVCLocalContext *lc); | ||
622 | int ff_hevc_end_of_slice_flag_decode(HEVCLocalContext *lc); | ||
623 | int ff_hevc_cu_transquant_bypass_flag_decode(HEVCLocalContext *lc); | ||
624 | int ff_hevc_skip_flag_decode(HEVCLocalContext *lc, uint8_t *skip_flag, | ||
625 | int x0, int y0, int x_cb, int y_cb, int min_cb_width); | ||
626 | int ff_hevc_pred_mode_decode(HEVCLocalContext *lc); | ||
627 | int ff_hevc_split_coding_unit_flag_decode(HEVCLocalContext *lc, uint8_t *tab_ct_depth, | ||
628 | const HEVCSPS *sps, | ||
629 | int ct_depth, int x0, int y0); | ||
630 | int ff_hevc_part_mode_decode(HEVCLocalContext *lc, const HEVCSPS *sps, int log2_cb_size); | ||
631 | int ff_hevc_pcm_flag_decode(HEVCLocalContext *lc); | ||
632 | int ff_hevc_prev_intra_luma_pred_flag_decode(HEVCLocalContext *lc); | ||
633 | int ff_hevc_mpm_idx_decode(HEVCLocalContext *lc); | ||
634 | int ff_hevc_rem_intra_luma_pred_mode_decode(HEVCLocalContext *lc); | ||
635 | int ff_hevc_intra_chroma_pred_mode_decode(HEVCLocalContext *lc); | ||
636 | int ff_hevc_merge_idx_decode(HEVCLocalContext *lc); | ||
637 | int ff_hevc_merge_flag_decode(HEVCLocalContext *lc); | ||
638 | int ff_hevc_inter_pred_idc_decode(HEVCLocalContext *lc, int nPbW, int nPbH); | ||
639 | int ff_hevc_ref_idx_lx_decode(HEVCLocalContext *lc, int num_ref_idx_lx); | ||
640 | int ff_hevc_mvp_lx_flag_decode(HEVCLocalContext *lc); | ||
641 | int ff_hevc_no_residual_syntax_flag_decode(HEVCLocalContext *lc); | ||
642 | int ff_hevc_split_transform_flag_decode(HEVCLocalContext *lc, int log2_trafo_size); | ||
643 | int ff_hevc_cbf_cb_cr_decode(HEVCLocalContext *lc, int trafo_depth); | ||
644 | int ff_hevc_cbf_luma_decode(HEVCLocalContext *lc, int trafo_depth); | ||
645 | int ff_hevc_log2_res_scale_abs(HEVCLocalContext *lc, int idx); | ||
646 | int ff_hevc_res_scale_sign_flag(HEVCLocalContext *lc, int idx); | ||
647 | |||
648 | /** | ||
649 | * Get the number of candidate references for the current frame. | ||
650 | */ | ||
651 | int ff_hevc_frame_nb_refs(const SliceHeader *sh, const HEVCPPS *pps, | ||
652 | unsigned layer_idx); | ||
653 | |||
654 | int ff_hevc_set_new_ref(HEVCContext *s, HEVCLayerContext *l, int poc); | ||
655 | |||
656 | 1020 | static av_always_inline int ff_hevc_nal_is_nonref(enum HEVCNALUnitType type) | |
657 | { | ||
658 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1020 times.
|
1020 | switch (type) { |
659 | ✗ | case HEVC_NAL_TRAIL_N: | |
660 | case HEVC_NAL_TSA_N: | ||
661 | case HEVC_NAL_STSA_N: | ||
662 | case HEVC_NAL_RADL_N: | ||
663 | case HEVC_NAL_RASL_N: | ||
664 | case HEVC_NAL_VCL_N10: | ||
665 | case HEVC_NAL_VCL_N12: | ||
666 | case HEVC_NAL_VCL_N14: | ||
667 | ✗ | return 1; | |
668 | 1020 | default: break; | |
669 | } | ||
670 | 1020 | return 0; | |
671 | } | ||
672 | |||
673 | /** | ||
674 | * Find frames in the DPB that are ready for output and either write them to the | ||
675 | * output FIFO or drop their output flag, depending on the value of discard. | ||
676 | * | ||
677 | * @param max_output maximum number of AUs with an output-pending frame in at | ||
678 | * least one layer that can be present in the DPB before output | ||
679 | * is triggered | ||
680 | * @param max_dpb maximum number of any frames that can be present in the DPB | ||
681 | * for any layer before output is triggered | ||
682 | */ | ||
683 | int ff_hevc_output_frames(HEVCContext *s, | ||
684 | unsigned layers_active_decode, unsigned layers_active_output, | ||
685 | unsigned max_output, unsigned max_dpb, int discard); | ||
686 | |||
687 | void ff_hevc_unref_frame(HEVCFrame *frame, int flags); | ||
688 | |||
689 | void ff_hevc_set_neighbour_available(HEVCLocalContext *lc, int x0, int y0, | ||
690 | int nPbW, int nPbH, int log2_ctb_size); | ||
691 | void ff_hevc_luma_mv_merge_mode(HEVCLocalContext *lc, const HEVCPPS *pps, | ||
692 | int x0, int y0, | ||
693 | int nPbW, int nPbH, int log2_cb_size, | ||
694 | int part_idx, int merge_idx, MvField *mv); | ||
695 | void ff_hevc_luma_mv_mvp_mode(HEVCLocalContext *lc, const HEVCPPS *pps, | ||
696 | int x0, int y0, | ||
697 | int nPbW, int nPbH, int log2_cb_size, | ||
698 | int part_idx, int merge_idx, | ||
699 | MvField *mv, int mvp_lx_flag, int LX); | ||
700 | void ff_hevc_hls_filter(HEVCLocalContext *lc, const HEVCLayerContext *l, | ||
701 | const HEVCPPS *pps, | ||
702 | int x, int y, int ctb_size); | ||
703 | void ff_hevc_hls_filters(HEVCLocalContext *lc, const HEVCLayerContext *l, | ||
704 | const HEVCPPS *pps, | ||
705 | int x_ctb, int y_ctb, int ctb_size); | ||
706 | void ff_hevc_set_qPy(HEVCLocalContext *lc, | ||
707 | const HEVCLayerContext *l, const HEVCPPS *pps, | ||
708 | int xBase, int yBase, int log2_cb_size); | ||
709 | void ff_hevc_deblocking_boundary_strengths(HEVCLocalContext *lc, const HEVCLayerContext *l, | ||
710 | const HEVCPPS *pps, | ||
711 | int x0, int y0, int log2_trafo_size); | ||
712 | int ff_hevc_cu_qp_delta_sign_flag(HEVCLocalContext *lc); | ||
713 | int ff_hevc_cu_qp_delta_abs(HEVCLocalContext *lc); | ||
714 | int ff_hevc_cu_chroma_qp_offset_flag(HEVCLocalContext *lc); | ||
715 | int ff_hevc_cu_chroma_qp_offset_idx(HEVCLocalContext *lc, int chroma_qp_offset_list_len_minus1); | ||
716 | void ff_hevc_hls_residual_coding(HEVCLocalContext *lc, const HEVCPPS *pps, | ||
717 | int x0, int y0, | ||
718 | int log2_trafo_size, enum ScanType scan_idx, | ||
719 | int c_idx); | ||
720 | |||
721 | void ff_hevc_hls_mvd_coding(HEVCLocalContext *lc, int x0, int y0, int log2_cb_size); | ||
722 | |||
723 | int ff_hevc_is_alpha_video(const HEVCContext *s); | ||
724 | |||
725 | extern const uint8_t ff_hevc_qpel_extra_before[4]; | ||
726 | extern const uint8_t ff_hevc_qpel_extra_after[4]; | ||
727 | extern const uint8_t ff_hevc_qpel_extra[4]; | ||
728 | |||
729 | #endif /* AVCODEC_HEVC_HEVCDEC_H */ | ||
730 |