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