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