hevcdec.h 21 KB

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