hevcdec.h 18 KB

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