FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
hevc_ps.h
Go to the documentation of this file.
1 /*
2  * HEVC parameter set parsing
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg 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  * FFmpeg 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 FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #ifndef AVCODEC_HEVC_PS_H
22 #define AVCODEC_HEVC_PS_H
23 
24 #include <stdint.h>
25 
26 #include "libavutil/buffer.h"
27 #include "libavutil/pixfmt.h"
28 #include "libavutil/rational.h"
29 
30 #include "avcodec.h"
31 #include "get_bits.h"
32 #include "hevc.h"
33 
34 typedef struct ShortTermRPS {
35  unsigned int num_negative_pics;
40 } ShortTermRPS;
41 
42 typedef struct HEVCWindow {
43  unsigned int left_offset;
44  unsigned int right_offset;
45  unsigned int top_offset;
46  unsigned int bottom_offset;
47 } HEVCWindow;
48 
49 typedef struct VUI {
51 
54 
62 
67 
70 
73 
76  uint32_t vui_time_scale;
80 
90 } VUI;
91 
92 typedef struct PTLCommon {
102 } PTLCommon;
103 
104 typedef struct PTL {
107 
110 } PTL;
111 
112 typedef struct HEVCVPS {
115  int vps_max_sub_layers; ///< vps_max_temporal_layers_minus1 + 1
116 
123  int vps_num_layer_sets; ///< vps_num_layer_sets_minus1 + 1
126  uint32_t vps_time_scale;
128  int vps_num_ticks_poc_diff_one; ///< vps_num_ticks_poc_diff_one_minus1 + 1
130 
131  uint8_t data[4096];
133 } HEVCVPS;
134 
135 typedef struct ScalingList {
136  /* This is a little wasteful, since sizeID 0 only needs 8 coeffs,
137  * and size ID 3 only has 2 arrays, not 6. */
138  uint8_t sl[4][6][64];
139  uint8_t sl_dc[2][6];
140 } ScalingList;
141 
142 typedef struct HEVCSPS {
143  unsigned vps_id;
146 
147  ///< output (i.e. cropped) values
150 
152 
156 
157  unsigned int log2_max_poc_lsb;
159 
161  struct {
166 
169 
172 
173  unsigned int nb_st_rps;
175 
178 
183 
184  struct {
187  unsigned int log2_min_pcm_cb_size;
188  unsigned int log2_max_pcm_cb_size;
190  } pcm;
193 
194  unsigned int log2_min_cb_size;
196  unsigned int log2_min_tb_size;
197  unsigned int log2_max_trafo_size;
198  unsigned int log2_ctb_size;
199  unsigned int log2_min_pu_size;
200 
203 
210 
211  ///< coded frame dimension in various units
212  int width;
213  int height;
216  int ctb_size;
223  int tb_mask;
224 
225  int hshift[3];
226  int vshift[3];
227 
229 
230  uint8_t data[4096];
232 } HEVCSPS;
233 
234 typedef struct HEVCPPS {
235  unsigned int sps_id; ///< seq_parameter_set_id
236 
238 
240 
241  int num_ref_idx_l0_default_active; ///< num_ref_idx_l0_default_active_minus1 + 1
242  int num_ref_idx_l1_default_active; ///< num_ref_idx_l1_default_active_minus1 + 1
244 
247 
250 
258 
262 
263  int num_tile_columns; ///< num_tile_columns_minus1 + 1
264  int num_tile_rows; ///< num_tile_rows_minus1 + 1
267 
269 
273  int beta_offset; ///< beta_offset_div2 * 2
274  int tc_offset; ///< tc_offset_div2 * 2
275 
278 
280  int log2_parallel_merge_level; ///< log2_parallel_merge_level_minus2 + 2
288  int8_t cb_qp_offset_list[6];
289  int8_t cr_qp_offset_list[6];
292 
293  // Inferred parameters
294  unsigned int *column_width; ///< ColumnWidth
295  unsigned int *row_height; ///< RowHeight
296  unsigned int *col_bd; ///< ColBd
297  unsigned int *row_bd; ///< RowBd
298  int *col_idxX;
299 
300  int *ctb_addr_rs_to_ts; ///< CtbAddrRSToTS
301  int *ctb_addr_ts_to_rs; ///< CtbAddrTSToRS
302  int *tile_id; ///< TileId
303  int *tile_pos_rs; ///< TilePosRS
304  int *min_tb_addr_zs; ///< MinTbAddrZS
305  int *min_tb_addr_zs_tab;///< MinTbAddrZS
306 
307  uint8_t data[4096];
309 } HEVCPPS;
310 
311 typedef struct HEVCParamSets {
315 
316  /* currently active parameter sets */
317  const HEVCVPS *vps;
318  const HEVCSPS *sps;
319  const HEVCPPS *pps;
320 } HEVCParamSets;
321 
322 /**
323  * Parse the SPS from the bitstream into the provided HEVCSPS struct.
324  *
325  * @param sps_id the SPS id will be written here
326  * @param apply_defdispwin if set 1, the default display window from the VUI
327  * will be applied to the video dimensions
328  * @param vps_list if non-NULL, this function will validate that the SPS refers
329  * to an existing VPS
330  */
331 int ff_hevc_parse_sps(HEVCSPS *sps, GetBitContext *gb, unsigned int *sps_id,
332  int apply_defdispwin, AVBufferRef **vps_list, AVCodecContext *avctx);
333 
335  HEVCParamSets *ps);
337  HEVCParamSets *ps, int apply_defdispwin);
339  HEVCParamSets *ps);
340 
342  ShortTermRPS *rps, const HEVCSPS *sps, int is_slice_header);
343 
344 int ff_hevc_encode_nal_vps(HEVCVPS *vps, unsigned int id,
345  uint8_t *buf, int buf_size);
346 
347 #endif /* AVCODEC_HEVC_PS_H */
PTLCommon sub_layer_ptl[HEVC_MAX_SUB_LAYERS]
Definition: hevc_ps.h:106
const HEVCPPS * pps
Definition: hevc_ps.h:319
unsigned int log2_min_cb_size
Definition: hevc_ps.h:194
uint8_t log2_sao_offset_scale_luma
Definition: hevc_ps.h:290
int min_spatial_segmentation_idc
Definition: hevc_ps.h:85
int ctb_height
Definition: hevc_ps.h:215
AVBufferRef * vps_list[HEVC_MAX_VPS_COUNT]
Definition: hevc_ps.h:312
ptrdiff_t const GLvoid * data
Definition: opengl_enc.c:101
uint8_t diff_cu_chroma_qp_offset_depth
Definition: hevc_ps.h:286
struct HEVCSPS::@68 pcm
int vui_num_ticks_poc_diff_one_minus1
Definition: hevc_ps.h:78
int max_dec_pic_buffering
Definition: hevc_ps.h:162
int transform_skip_rotation_enabled_flag
Definition: hevc_ps.h:204
unsigned int * row_height
RowHeight.
Definition: hevc_ps.h:295
ShortTermRPS st_rps[HEVC_MAX_SHORT_TERM_RPS_COUNT]
Definition: hevc_ps.h:174
int vps_num_ticks_poc_diff_one
vps_num_ticks_poc_diff_one_minus1 + 1
Definition: hevc_ps.h:128
int pic_init_qp_minus26
Definition: hevc_ps.h:243
unsigned int vps_max_latency_increase[HEVC_MAX_SUB_LAYERS]
Definition: hevc_ps.h:121
VUI vui
Definition: hevc_ps.h:167
int vshift[3]
Definition: hevc_ps.h:226
uint32_t vui_time_scale
Definition: hevc_ps.h:76
int ff_hevc_encode_nal_vps(HEVCVPS *vps, unsigned int id, uint8_t *buf, int buf_size)
Definition: hevc_ps_enc.c:66
uint8_t weighted_bipred_flag
Definition: hevc_ps.h:255
unsigned int left_offset
Definition: hevc_ps.h:43
Definition: hevc_ps.h:104
unsigned int vps_max_dec_pic_buffering[HEVC_MAX_SUB_LAYERS]
Definition: hevc_ps.h:119
uint8_t seq_loop_filter_across_slices_enabled_flag
Definition: hevc_ps.h:268
uint8_t cabac_init_present_flag
Definition: hevc_ps.h:239
int chroma_loc_info_present_flag
Definition: hevc_ps.h:63
#define HEVC_MAX_SHORT_TERM_RPS_COUNT
Definition: hevc.h:68
int max_latency_increase
Definition: hevc_ps.h:164
int min_cb_height
Definition: hevc_ps.h:218
int * ctb_addr_ts_to_rs
CtbAddrTSToRS.
Definition: hevc_ps.h:301
int explicit_rdpcm_enabled_flag
Definition: hevc_ps.h:207
int num_ref_idx_l0_default_active
num_ref_idx_l0_default_active_minus1 + 1
Definition: hevc_ps.h:241
uint8_t bit_depth
Definition: hevc_ps.h:185
int8_t cr_qp_offset_list[6]
Definition: hevc_ps.h:289
int chroma_sample_loc_type_top_field
Definition: hevc_ps.h:64
int width
Definition: hevc_ps.h:212
int qp_bd_offset
Definition: hevc_ps.h:228
int pixel_shift
Definition: hevc_ps.h:154
uint8_t entropy_coding_sync_enabled_flag
Definition: hevc_ps.h:261
#define HEVC_MAX_VPS_COUNT
Definition: hevc.h:65
HEVCWindow output_window
Definition: hevc_ps.h:149
int output_width
Definition: hevc_ps.h:148
int log2_parallel_merge_level
log2_parallel_merge_level_minus2 + 2
Definition: hevc_ps.h:280
uint8_t log2_sao_offset_scale_chroma
Definition: hevc_ps.h:291
int restricted_ref_pic_lists_flag
Definition: hevc_ps.h:84
int chroma_format_idc
Definition: hevc_ps.h:144
uint8_t disable_dbf
Definition: hevc_ps.h:272
unsigned int log2_max_trafo_size
Definition: hevc_ps.h:197
AVBufferRef * sps_list[HEVC_MAX_SPS_COUNT]
Definition: hevc_ps.h:313
uint8_t profile_compatibility_flag[32]
Definition: hevc_ps.h:96
Definition: hevc_ps.h:49
unsigned int num_negative_pics
Definition: hevc_ps.h:35
uint8_t
HEVCWindow pic_conf_win
Definition: hevc_ps.h:151
uint8_t log2_max_transform_skip_block_size
Definition: hevc_ps.h:283
int overscan_info_present_flag
Definition: hevc_ps.h:52
uint8_t vps_timing_info_present_flag
Definition: hevc_ps.h:124
uint8_t matrix_coeffs
Definition: hevc_ps.h:61
int min_tb_width
Definition: hevc_ps.h:219
const HEVCVPS * vps
Definition: hevc_ps.h:317
int num_ref_idx_l1_default_active
num_ref_idx_l1_default_active_minus1 + 1
Definition: hevc_ps.h:242
unsigned int log2_min_pcm_cb_size
Definition: hevc_ps.h:187
int min_cb_width
Definition: hevc_ps.h:217
int vps_max_sub_layers
vps_max_temporal_layers_minus1 + 1
Definition: hevc_ps.h:115
int frame_field_info_present_flag
Definition: hevc_ps.h:69
uint8_t tier_flag
Definition: hevc_ps.h:94
uint8_t scaling_list_data_present_flag
Definition: hevc_ps.h:276
uint8_t bit_depth_chroma
Definition: hevc_ps.h:186
bitstream reader API header.
AVBufferRef * pps_list[HEVC_MAX_PPS_COUNT]
Definition: hevc_ps.h:314
uint8_t loop_filter_disable_flag
Definition: hevc_ps.h:189
int8_t cb_qp_offset_list[6]
Definition: hevc_ps.h:288
int bitstream_restriction_flag
Definition: hevc_ps.h:81
uint8_t transquant_bypass_enable_flag
Definition: hevc_ps.h:257
int vps_max_layer_id
Definition: hevc_ps.h:122
uint8_t frame_only_constraint_flag
Definition: hevc_ps.h:101
unsigned int log2_max_poc_lsb
Definition: hevc_ps.h:157
int vps_max_layers
Definition: hevc_ps.h:114
int min_pu_height
Definition: hevc_ps.h:222
int persistent_rice_adaptation_enabled_flag
coded frame dimension in various units
Definition: hevc_ps.h:209
int data_size
Definition: hevc_ps.h:308
int vui_timing_info_present_flag
Definition: hevc_ps.h:74
uint8_t amp_enabled_flag
Definition: hevc_ps.h:176
unsigned int log2_ctb_size
Definition: hevc_ps.h:198
int vui_poc_proportional_to_timing_flag
Definition: hevc_ps.h:77
uint8_t vps_temporal_id_nesting_flag
Definition: hevc_ps.h:113
uint8_t colour_primaries
Definition: hevc_ps.h:59
uint8_t used[32]
Definition: hevc_ps.h:39
int motion_vectors_over_pic_boundaries_flag
Definition: hevc_ps.h:83
uint8_t tiles_enabled_flag
Definition: hevc_ps.h:260
uint32_t vps_num_units_in_tick
Definition: hevc_ps.h:125
int * col_idxX
Definition: hevc_ps.h:298
uint8_t sub_layer_level_present_flag[HEVC_MAX_SUB_LAYERS]
Definition: hevc_ps.h:109
const HEVCSPS * sps
Definition: hevc_ps.h:318
int vps_num_layer_sets
vps_num_layer_sets_minus1 + 1
Definition: hevc_ps.h:123
uint8_t lists_modification_present_flag
Definition: hevc_ps.h:279
int * min_tb_addr_zs_tab
MinTbAddrZS.
Definition: hevc_ps.h:305
uint8_t profile_idc
Definition: hevc_ps.h:95
int max_transform_hierarchy_depth_inter
Definition: hevc_ps.h:201
uint8_t vps_poc_proportional_to_timing_flag
Definition: hevc_ps.h:127
int num_tile_columns
num_tile_columns_minus1 + 1
Definition: hevc_ps.h:263
int output_height
Definition: hevc_ps.h:148
int ff_hevc_decode_nal_vps(GetBitContext *gb, AVCodecContext *avctx, HEVCParamSets *ps)
Definition: hevc_ps.c:416
unsigned int top_offset
Definition: hevc_ps.h:45
int hshift[3]
Definition: hevc_ps.h:225
unsigned int vps_num_reorder_pics[HEVC_MAX_SUB_LAYERS]
Definition: hevc_ps.h:120
struct HEVCSPS::@67 temporal_layer[HEVC_MAX_SUB_LAYERS]
int32_t
int max_bits_per_min_cu_denom
Definition: hevc_ps.h:87
uint8_t cu_qp_delta_enabled_flag
Definition: hevc_ps.h:248
uint8_t used_by_curr_pic_lt_sps_flag[32]
Definition: hevc_ps.h:181
int ctb_width
Definition: hevc_ps.h:214
uint8_t sl_dc[2][6]
Definition: hevc_ps.h:139
int32_t delta_poc[32]
Definition: hevc_ps.h:38
uint8_t sign_data_hiding_flag
Definition: hevc_ps.h:237
int height
Definition: hevc_ps.h:213
uint8_t output_flag_present_flag
Definition: hevc_ps.h:256
int log2_max_mv_length_vertical
Definition: hevc_ps.h:89
int data_size
Definition: hevc_ps.h:132
PTLCommon general_ptl
Definition: hevc_ps.h:105
uint8_t sub_layer_profile_present_flag[HEVC_MAX_SUB_LAYERS]
Definition: hevc_ps.h:108
int max_bytes_per_pic_denom
Definition: hevc_ps.h:86
int overscan_appropriate_flag
Definition: hevc_ps.h:53
int implicit_rdpcm_enabled_flag
Definition: hevc_ps.h:206
unsigned vps_id
Definition: hevc_ps.h:143
uint8_t constrained_intra_pred_flag
Definition: hevc_ps.h:245
int tb_mask
Definition: hevc_ps.h:223
uint8_t sl[4][6][64]
Definition: hevc_ps.h:138
PTL ptl
Definition: hevc_ps.h:117
uint8_t pic_slice_level_chroma_qp_offsets_present_flag
Definition: hevc_ps.h:253
uint32_t vps_time_scale
Definition: hevc_ps.h:126
int colour_description_present_flag
Definition: hevc_ps.h:58
enum AVPixelFormat pix_fmt
Definition: hevc_ps.h:155
uint8_t transform_skip_enabled_flag
Definition: hevc_ps.h:246
Libavcodec external API header.
uint8_t uniform_spacing_flag
Definition: hevc_ps.h:265
int ctb_size
Definition: hevc_ps.h:216
int * ctb_addr_rs_to_ts
CtbAddrRSToTS.
Definition: hevc_ps.h:300
PTL ptl
Definition: hevc_ps.h:168
int max_sub_layers
Definition: hevc_ps.h:160
unsigned int log2_min_pu_size
Definition: hevc_ps.h:199
unsigned int sps_id
seq_parameter_set_id
Definition: hevc_ps.h:235
ScalingList scaling_list
Definition: hevc_ps.h:277
main external API structure.
Definition: avcodec.h:1732
int log2_max_mv_length_horizontal
Definition: hevc_ps.h:88
uint8_t sao_enabled
Definition: hevc_ps.h:177
int num_extra_slice_header_bits
Definition: hevc_ps.h:281
uint8_t loop_filter_across_tiles_enabled_flag
Definition: hevc_ps.h:266
uint8_t num_long_term_ref_pics_sps
Definition: hevc_ps.h:182
uint8_t cross_component_prediction_enabled_flag
Definition: hevc_ps.h:284
void * buf
Definition: avisynth_c.h:690
int ff_hevc_decode_nal_pps(GetBitContext *gb, AVCodecContext *avctx, HEVCParamSets *ps)
Definition: hevc_ps.c:1467
uint32_t vui_num_units_in_tick
Definition: hevc_ps.h:75
int ff_hevc_parse_sps(HEVCSPS *sps, GetBitContext *gb, unsigned int *sps_id, int apply_defdispwin, AVBufferRef **vps_list, AVCodecContext *avctx)
Parse the SPS from the bitstream into the provided HEVCSPS struct.
Definition: hevc_ps.c:865
uint8_t deblocking_filter_control_present_flag
Definition: hevc_ps.h:270
int transform_skip_context_enabled_flag
Definition: hevc_ps.h:205
uint8_t sps_temporal_mvp_enabled_flag
Definition: hevc_ps.h:191
unsigned int nb_st_rps
Definition: hevc_ps.h:173
int chroma_sample_loc_type_bottom_field
Definition: hevc_ps.h:65
int num_tile_rows
num_tile_rows_minus1 + 1
Definition: hevc_ps.h:264
uint8_t chroma_qp_offset_list_enabled_flag
Definition: hevc_ps.h:285
Rational number (pair of numerator and denominator).
Definition: rational.h:58
int vps_num_hrd_parameters
Definition: hevc_ps.h:129
#define HEVC_MAX_SPS_COUNT
Definition: hevc.h:66
int ff_hevc_decode_short_term_rps(GetBitContext *gb, AVCodecContext *avctx, ShortTermRPS *rps, const HEVCSPS *sps, int is_slice_header)
Definition: hevc_ps.c:111
unsigned int log2_min_tb_size
Definition: hevc_ps.h:196
refcounted data buffer API
uint16_t lt_ref_pic_poc_lsb_sps[32]
Definition: hevc_ps.h:180
#define HEVC_MAX_SUB_LAYERS
7.4.2.1
Definition: hevc.h:64
uint8_t scaling_list_enable_flag
Definition: hevc_ps.h:170
int * tile_id
TileId.
Definition: hevc_ps.h:302
int tc_offset
tc_offset_div2 * 2
Definition: hevc_ps.h:274
uint8_t transfer_characteristic
Definition: hevc_ps.h:60
int default_display_window_flag
Definition: hevc_ps.h:71
HEVCWindow def_disp_win
Definition: hevc_ps.h:72
int cr_qp_offset
Definition: hevc_ps.h:252
ScalingList scaling_list
Definition: hevc_ps.h:171
unsigned int log2_diff_max_min_coding_block_size
Definition: hevc_ps.h:195
unsigned int log2_max_pcm_cb_size
Definition: hevc_ps.h:188
uint8_t level_idc
Definition: hevc_ps.h:97
int ff_hevc_decode_nal_sps(GetBitContext *gb, AVCodecContext *avctx, HEVCParamSets *ps, int apply_defdispwin)
Definition: hevc_ps.c:1224
int neutra_chroma_indication_flag
Definition: hevc_ps.h:66
int * tile_pos_rs
TilePosRS.
Definition: hevc_ps.h:303
int data_size
Definition: hevc_ps.h:231
A reference to a data buffer.
Definition: buffer.h:81
int max_transform_hierarchy_depth_intra
Definition: hevc_ps.h:202
uint8_t profile_space
Definition: hevc_ps.h:93
unsigned int * row_bd
RowBd.
Definition: hevc_ps.h:297
int video_format
Definition: hevc_ps.h:56
Utilties for rational number calculation.
uint8_t weighted_pred_flag
Definition: hevc_ps.h:254
unsigned int * col_bd
ColBd.
Definition: hevc_ps.h:296
unsigned int * column_width
ColumnWidth.
Definition: hevc_ps.h:294
uint8_t slice_header_extension_present_flag
Definition: hevc_ps.h:282
#define HEVC_MAX_PPS_COUNT
Definition: hevc.h:67
int video_full_range_flag
Definition: hevc_ps.h:57
AVRational sar
Definition: hevc_ps.h:50
uint8_t chroma_qp_offset_list_len_minus1
Definition: hevc_ps.h:287
int num_delta_pocs
Definition: hevc_ps.h:36
uint8_t sps_strong_intra_smoothing_enable_flag
Definition: hevc_ps.h:192
pixel format definitions
int rps_idx_num_delta_pocs
Definition: hevc_ps.h:37
int min_pu_width
Definition: hevc_ps.h:221
uint8_t long_term_ref_pics_present_flag
Definition: hevc_ps.h:179
int vui_hrd_parameters_present_flag
Definition: hevc_ps.h:79
unsigned int right_offset
Definition: hevc_ps.h:44
int diff_cu_qp_delta_depth
Definition: hevc_ps.h:249
int num_reorder_pics
Definition: hevc_ps.h:163
uint8_t progressive_source_flag
Definition: hevc_ps.h:98
int cb_qp_offset
Definition: hevc_ps.h:251
int video_signal_type_present_flag
Definition: hevc_ps.h:55
uint8_t deblocking_filter_override_enabled_flag
Definition: hevc_ps.h:271
int bit_depth
Definition: hevc_ps.h:153
int beta_offset
beta_offset_div2 * 2
Definition: hevc_ps.h:273
int min_tb_height
Definition: hevc_ps.h:220
int * min_tb_addr_zs
MinTbAddrZS.
Definition: hevc_ps.h:304
uint8_t non_packed_constraint_flag
Definition: hevc_ps.h:100
int intra_smoothing_disabled_flag
Definition: hevc_ps.h:208
int pcm_enabled_flag
Definition: hevc_ps.h:158
AVPixelFormat
Pixel format.
Definition: pixfmt.h:60
int tiles_fixed_structure_flag
Definition: hevc_ps.h:82
uint8_t interlaced_source_flag
Definition: hevc_ps.h:99
int field_seq_flag
Definition: hevc_ps.h:68
uint8_t separate_colour_plane_flag
output (i.e. cropped) values
Definition: hevc_ps.h:145
unsigned int bottom_offset
Definition: hevc_ps.h:46
int vps_sub_layer_ordering_info_present_flag
Definition: hevc_ps.h:118
uint8_t dependent_slice_segments_enabled_flag
Definition: hevc_ps.h:259