You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

319 lines
9.5KB

  1. /*
  2. * HEVC parameter set parsing
  3. *
  4. * This file is part of Libav.
  5. *
  6. * Libav is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * Libav is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with Libav; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #ifndef AVCODEC_HEVC_PS_H
  21. #define AVCODEC_HEVC_PS_H
  22. #include <stdint.h>
  23. #include "libavutil/buffer.h"
  24. #include "libavutil/pixfmt.h"
  25. #include "libavutil/rational.h"
  26. #include "avcodec.h"
  27. #include "get_bits.h"
  28. #include "hevc.h"
  29. typedef struct ShortTermRPS {
  30. unsigned int num_negative_pics;
  31. int num_delta_pocs;
  32. int rps_idx_num_delta_pocs;
  33. int32_t delta_poc[32];
  34. uint8_t used[32];
  35. } ShortTermRPS;
  36. typedef struct HEVCWindow {
  37. unsigned int left_offset;
  38. unsigned int right_offset;
  39. unsigned int top_offset;
  40. unsigned int bottom_offset;
  41. } HEVCWindow;
  42. typedef struct VUI {
  43. AVRational sar;
  44. int overscan_info_present_flag;
  45. int overscan_appropriate_flag;
  46. int video_signal_type_present_flag;
  47. int video_format;
  48. int video_full_range_flag;
  49. int colour_description_present_flag;
  50. uint8_t colour_primaries;
  51. uint8_t transfer_characteristic;
  52. uint8_t matrix_coeffs;
  53. int chroma_loc_info_present_flag;
  54. int chroma_sample_loc_type_top_field;
  55. int chroma_sample_loc_type_bottom_field;
  56. int neutra_chroma_indication_flag;
  57. int field_seq_flag;
  58. int frame_field_info_present_flag;
  59. int default_display_window_flag;
  60. HEVCWindow def_disp_win;
  61. int vui_timing_info_present_flag;
  62. uint32_t vui_num_units_in_tick;
  63. uint32_t vui_time_scale;
  64. int vui_poc_proportional_to_timing_flag;
  65. int vui_num_ticks_poc_diff_one_minus1;
  66. int vui_hrd_parameters_present_flag;
  67. int bitstream_restriction_flag;
  68. int tiles_fixed_structure_flag;
  69. int motion_vectors_over_pic_boundaries_flag;
  70. int restricted_ref_pic_lists_flag;
  71. int min_spatial_segmentation_idc;
  72. int max_bytes_per_pic_denom;
  73. int max_bits_per_min_cu_denom;
  74. int log2_max_mv_length_horizontal;
  75. int log2_max_mv_length_vertical;
  76. } VUI;
  77. typedef struct PTLCommon {
  78. uint8_t profile_space;
  79. uint8_t tier_flag;
  80. uint8_t profile_idc;
  81. uint8_t profile_compatibility_flag[32];
  82. uint8_t level_idc;
  83. uint8_t progressive_source_flag;
  84. uint8_t interlaced_source_flag;
  85. uint8_t non_packed_constraint_flag;
  86. uint8_t frame_only_constraint_flag;
  87. } PTLCommon;
  88. typedef struct PTL {
  89. PTLCommon general_ptl;
  90. PTLCommon sub_layer_ptl[HEVC_MAX_SUB_LAYERS];
  91. uint8_t sub_layer_profile_present_flag[HEVC_MAX_SUB_LAYERS];
  92. uint8_t sub_layer_level_present_flag[HEVC_MAX_SUB_LAYERS];
  93. } PTL;
  94. typedef struct HEVCVPS {
  95. uint8_t vps_temporal_id_nesting_flag;
  96. int vps_max_layers;
  97. int vps_max_sub_layers; ///< vps_max_temporal_layers_minus1 + 1
  98. PTL ptl;
  99. int vps_sub_layer_ordering_info_present_flag;
  100. unsigned int vps_max_dec_pic_buffering[HEVC_MAX_SUB_LAYERS];
  101. unsigned int vps_num_reorder_pics[HEVC_MAX_SUB_LAYERS];
  102. unsigned int vps_max_latency_increase[HEVC_MAX_SUB_LAYERS];
  103. int vps_max_layer_id;
  104. int vps_num_layer_sets; ///< vps_num_layer_sets_minus1 + 1
  105. uint8_t vps_timing_info_present_flag;
  106. uint32_t vps_num_units_in_tick;
  107. uint32_t vps_time_scale;
  108. uint8_t vps_poc_proportional_to_timing_flag;
  109. int vps_num_ticks_poc_diff_one; ///< vps_num_ticks_poc_diff_one_minus1 + 1
  110. int vps_num_hrd_parameters;
  111. } HEVCVPS;
  112. typedef struct ScalingList {
  113. /* This is a little wasteful, since sizeID 0 only needs 8 coeffs,
  114. * and size ID 3 only has 2 arrays, not 6. */
  115. uint8_t sl[4][6][64];
  116. uint8_t sl_dc[2][6];
  117. } ScalingList;
  118. typedef struct HEVCSPS {
  119. int vps_id;
  120. int chroma_format_idc;
  121. uint8_t separate_colour_plane_flag;
  122. HEVCWindow output_window;
  123. HEVCWindow pic_conf_win;
  124. int bit_depth;
  125. int pixel_shift;
  126. enum AVPixelFormat pix_fmt;
  127. unsigned int log2_max_poc_lsb;
  128. int pcm_enabled_flag;
  129. int max_sub_layers;
  130. struct {
  131. int max_dec_pic_buffering;
  132. int num_reorder_pics;
  133. int max_latency_increase;
  134. } temporal_layer[HEVC_MAX_SUB_LAYERS];
  135. VUI vui;
  136. PTL ptl;
  137. uint8_t scaling_list_enable_flag;
  138. ScalingList scaling_list;
  139. unsigned int nb_st_rps;
  140. ShortTermRPS st_rps[HEVC_MAX_SHORT_TERM_RPS_COUNT];
  141. uint8_t amp_enabled_flag;
  142. uint8_t sao_enabled;
  143. uint8_t long_term_ref_pics_present_flag;
  144. uint16_t lt_ref_pic_poc_lsb_sps[32];
  145. uint8_t used_by_curr_pic_lt_sps_flag[32];
  146. uint8_t num_long_term_ref_pics_sps;
  147. struct {
  148. uint8_t bit_depth;
  149. uint8_t bit_depth_chroma;
  150. unsigned int log2_min_pcm_cb_size;
  151. unsigned int log2_max_pcm_cb_size;
  152. uint8_t loop_filter_disable_flag;
  153. } pcm;
  154. uint8_t sps_temporal_mvp_enabled_flag;
  155. uint8_t sps_strong_intra_smoothing_enable_flag;
  156. unsigned int log2_min_cb_size;
  157. unsigned int log2_diff_max_min_coding_block_size;
  158. unsigned int log2_min_tb_size;
  159. unsigned int log2_max_trafo_size;
  160. unsigned int log2_ctb_size;
  161. unsigned int log2_min_pu_size;
  162. int max_transform_hierarchy_depth_inter;
  163. int max_transform_hierarchy_depth_intra;
  164. ///< coded frame dimension in various units
  165. int width;
  166. int height;
  167. int ctb_width;
  168. int ctb_height;
  169. int ctb_size;
  170. int min_cb_width;
  171. int min_cb_height;
  172. int min_tb_width;
  173. int min_tb_height;
  174. int min_pu_width;
  175. int min_pu_height;
  176. int hshift[3];
  177. int vshift[3];
  178. int qp_bd_offset;
  179. } HEVCSPS;
  180. typedef struct HEVCPPS {
  181. unsigned int sps_id; ///< seq_parameter_set_id
  182. uint8_t sign_data_hiding_flag;
  183. uint8_t cabac_init_present_flag;
  184. int num_ref_idx_l0_default_active; ///< num_ref_idx_l0_default_active_minus1 + 1
  185. int num_ref_idx_l1_default_active; ///< num_ref_idx_l1_default_active_minus1 + 1
  186. int pic_init_qp_minus26;
  187. uint8_t constrained_intra_pred_flag;
  188. uint8_t transform_skip_enabled_flag;
  189. uint8_t cu_qp_delta_enabled_flag;
  190. int diff_cu_qp_delta_depth;
  191. int cb_qp_offset;
  192. int cr_qp_offset;
  193. uint8_t pic_slice_level_chroma_qp_offsets_present_flag;
  194. uint8_t weighted_pred_flag;
  195. uint8_t weighted_bipred_flag;
  196. uint8_t output_flag_present_flag;
  197. uint8_t transquant_bypass_enable_flag;
  198. uint8_t dependent_slice_segments_enabled_flag;
  199. uint8_t tiles_enabled_flag;
  200. uint8_t entropy_coding_sync_enabled_flag;
  201. int num_tile_columns; ///< num_tile_columns_minus1 + 1
  202. int num_tile_rows; ///< num_tile_rows_minus1 + 1
  203. uint8_t uniform_spacing_flag;
  204. uint8_t loop_filter_across_tiles_enabled_flag;
  205. uint8_t seq_loop_filter_across_slices_enabled_flag;
  206. uint8_t deblocking_filter_control_present_flag;
  207. uint8_t deblocking_filter_override_enabled_flag;
  208. uint8_t disable_dbf;
  209. int beta_offset; ///< beta_offset_div2 * 2
  210. int tc_offset; ///< tc_offset_div2 * 2
  211. uint8_t scaling_list_data_present_flag;
  212. ScalingList scaling_list;
  213. uint8_t lists_modification_present_flag;
  214. int log2_parallel_merge_level; ///< log2_parallel_merge_level_minus2 + 2
  215. int num_extra_slice_header_bits;
  216. uint8_t slice_header_extension_present_flag;
  217. // Inferred parameters
  218. unsigned int *column_width; ///< ColumnWidth
  219. unsigned int *row_height; ///< RowHeight
  220. unsigned int *col_bd; ///< ColBd
  221. unsigned int *row_bd; ///< RowBd
  222. int *col_idxX;
  223. int *ctb_addr_rs_to_ts; ///< CtbAddrRSToTS
  224. int *ctb_addr_ts_to_rs; ///< CtbAddrTSToRS
  225. int *tile_id; ///< TileId
  226. int *tile_pos_rs; ///< TilePosRS
  227. int *min_tb_addr_zs; ///< MinTbAddrZS
  228. } HEVCPPS;
  229. typedef struct HEVCParamSets {
  230. AVBufferRef *vps_list[HEVC_MAX_VPS_COUNT];
  231. AVBufferRef *sps_list[HEVC_MAX_SPS_COUNT];
  232. AVBufferRef *pps_list[HEVC_MAX_PPS_COUNT];
  233. /* currently active parameter sets */
  234. const HEVCVPS *vps;
  235. const HEVCSPS *sps;
  236. const HEVCPPS *pps;
  237. } HEVCParamSets;
  238. /**
  239. * Parse the SPS from the bitstream into the provided HEVCSPS struct.
  240. *
  241. * @param sps_id the SPS id will be written here
  242. * @param apply_defdispwin if set 1, the default display window from the VUI
  243. * will be applied to the video dimensions
  244. * @param vps_list if non-NULL, this function will validate that the SPS refers
  245. * to an existing VPS
  246. */
  247. int ff_hevc_parse_sps(HEVCSPS *sps, GetBitContext *gb, unsigned int *sps_id,
  248. int apply_defdispwin, AVBufferRef **vps_list, AVCodecContext *avctx);
  249. int ff_hevc_decode_nal_vps(GetBitContext *gb, AVCodecContext *avctx,
  250. HEVCParamSets *ps);
  251. int ff_hevc_decode_nal_sps(GetBitContext *gb, AVCodecContext *avctx,
  252. HEVCParamSets *ps, int apply_defdispwin);
  253. int ff_hevc_decode_nal_pps(GetBitContext *gb, AVCodecContext *avctx,
  254. HEVCParamSets *ps);
  255. int ff_hevc_decode_short_term_rps(GetBitContext *gb, AVCodecContext *avctx,
  256. ShortTermRPS *rps, const HEVCSPS *sps, int is_slice_header);
  257. int ff_hevc_encode_nal_vps(HEVCVPS *vps, unsigned int id,
  258. uint8_t *buf, int buf_size);
  259. #endif /* AVCODEC_HEVC_PS_H */