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