FFmpeg
h264_ps.h
Go to the documentation of this file.
1 /*
2  * This file is part of FFmpeg.
3  *
4  * FFmpeg is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * FFmpeg is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with FFmpeg; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
19 /**
20  * @file
21  * H.264 parameter set handling
22  */
23 
24 #ifndef AVCODEC_H264_PS_H
25 #define AVCODEC_H264_PS_H
26 
27 #include <stdint.h>
28 
29 #include "libavutil/pixfmt.h"
30 #include "libavutil/rational.h"
31 
32 #include "avcodec.h"
33 #include "get_bits.h"
34 #include "h264.h"
35 #include "h2645_vui.h"
36 
37 #define MAX_SPS_COUNT 32
38 #define MAX_PPS_COUNT 256
39 #define MAX_LOG2_MAX_FRAME_NUM (12 + 4)
40 
41 /**
42  * Sequence parameter set
43  */
44 typedef struct SPS {
45  unsigned int sps_id;
47  int level_idc;
49  int transform_bypass; ///< qpprime_y_zero_transform_bypass_flag
50  int log2_max_frame_num; ///< log2_max_frame_num_minus4 + 4
51  int poc_type; ///< pic_order_cnt_type
52  int log2_max_poc_lsb; ///< log2_max_pic_order_cnt_lsb_minus4
56  int poc_cycle_length; ///< num_ref_frames_in_pic_order_cnt_cycle
57  int ref_frame_count; ///< num_ref_frames
59  int mb_width; ///< pic_width_in_mbs_minus1 + 1
60  ///< (pic_height_in_map_units_minus1 + 1) * (2 - frame_mbs_only_flag)
61  int mb_height;
63  int mb_aff; ///< mb_adaptive_frame_field_flag
65  int crop; ///< frame_cropping_flag
66 
67  /* those 4 are already in luma samples */
68  unsigned int crop_left; ///< frame_cropping_rect_left_offset
69  unsigned int crop_right; ///< frame_cropping_rect_right_offset
70  unsigned int crop_top; ///< frame_cropping_rect_top_offset
71  unsigned int crop_bottom; ///< frame_cropping_rect_bottom_offset
74 
77  uint32_t time_scale;
85  uint8_t scaling_matrix4[6][16];
86  uint8_t scaling_matrix8[6][64];
91  int cpb_cnt; ///< See H.264 E.1.2
93  uint32_t bit_rate_value[32]; ///< bit_rate_value_minus1 + 1
94  uint32_t cpb_size_value[32]; ///< cpb_size_value_minus1 + 1
95  uint32_t cpr_flag;
96  int initial_cpb_removal_delay_length; ///< initial_cpb_removal_delay_length_minus1 + 1
97  int cpb_removal_delay_length; ///< cpb_removal_delay_length_minus1 + 1
98  int dpb_output_delay_length; ///< dpb_output_delay_length_minus1 + 1
99  int bit_depth_luma; ///< bit_depth_luma_minus8 + 8
100  int bit_depth_chroma; ///< bit_depth_chroma_minus8 + 8
101  int residual_color_transform_flag; ///< residual_colour_transform_flag
102  int constraint_set_flags; ///< constraint_set[0-3]_flag
103  uint8_t data[4096];
104  size_t data_size;
105 } SPS;
106 
107 /**
108  * Picture parameter set
109  */
110 typedef struct PPS {
111  unsigned int pps_id;
112  unsigned int sps_id;
113  int cabac; ///< entropy_coding_mode_flag
114  int pic_order_present; ///< bottom_field_pic_order_in_frame_present_flag
115  int slice_group_count; ///< num_slice_groups_minus1 + 1
117  unsigned int ref_count[2]; ///< num_ref_idx_l0/1_active_minus1 + 1
118  int weighted_pred; ///< weighted_pred_flag
120  int init_qp; ///< pic_init_qp_minus26 + 26
121  int init_qs; ///< pic_init_qs_minus26 + 26
123  int deblocking_filter_parameters_present; ///< deblocking_filter_parameters_present_flag
124  int constrained_intra_pred; ///< constrained_intra_pred_flag
125  int redundant_pic_cnt_present; ///< redundant_pic_cnt_present_flag
126  int transform_8x8_mode; ///< transform_8x8_mode_flag
129  uint8_t scaling_matrix4[6][16];
130  uint8_t scaling_matrix8[6][64];
131  uint8_t chroma_qp_table[2][QP_MAX_NUM+1]; ///< pre-scaled (with chroma_qp_index_offset) version of qp_table
133  uint8_t data[4096];
134  size_t data_size;
135 
136  uint32_t dequant4_buffer[6][QP_MAX_NUM + 1][16];
137  uint32_t dequant8_buffer[6][QP_MAX_NUM + 1][64];
138  uint32_t(*dequant4_coeff[6])[16];
139  uint32_t(*dequant8_coeff[6])[64];
140 
141  const SPS *sps; ///< RefStruct reference
142 } PPS;
143 
144 typedef struct H264ParamSets {
145  const SPS *sps_list[MAX_SPS_COUNT]; ///< RefStruct references
146  const PPS *pps_list[MAX_PPS_COUNT]; ///< RefStruct references
147 
148  /* currently active parameters sets */
149  const PPS *pps; ///< RefStruct reference
150  const SPS *sps; ///< ordinary pointer, no RefStruct reference
151 
153 } H264ParamSets;
154 
155 /**
156  * compute profile from sps
157  */
158 int ff_h264_get_profile(const SPS *sps);
159 
160 /**
161  * Decode SPS
162  */
164  H264ParamSets *ps, int ignore_truncation);
165 
166 /**
167  * Decode PPS
168  */
170  H264ParamSets *ps, int bit_length);
171 
172 /**
173  * Uninit H264 param sets structure.
174  */
176 
177 #endif /* AVCODEC_H264_PS_H */
H264ParamSets::sps_list
const SPS * sps_list[MAX_SPS_COUNT]
RefStruct references.
Definition: h264_ps.h:145
SPS::offset_for_ref_frame
int32_t offset_for_ref_frame[256]
Definition: h264_ps.h:79
SPS::cpb_removal_delay_length
int cpb_removal_delay_length
cpb_removal_delay_length_minus1 + 1
Definition: h264_ps.h:97
SPS::scaling_matrix_present
int scaling_matrix_present
Definition: h264_ps.h:83
SPS::crop_bottom
unsigned int crop_bottom
frame_cropping_rect_bottom_offset
Definition: h264_ps.h:71
H264ParamSets::sps
const SPS * sps
ordinary pointer, no RefStruct reference
Definition: h264_ps.h:150
PPS::scaling_matrix4
uint8_t scaling_matrix4[6][16]
Definition: h264_ps.h:129
SPS::mb_width
int mb_width
pic_width_in_mbs_minus1 + 1
Definition: h264_ps.h:59
SPS::offset_for_non_ref_pic
int offset_for_non_ref_pic
Definition: h264_ps.h:54
rational.h
H264ParamSets::pps_list
const PPS * pps_list[MAX_PPS_COUNT]
RefStruct references.
Definition: h264_ps.h:146
SPS::crop_right
unsigned int crop_right
frame_cropping_rect_right_offset
Definition: h264_ps.h:69
PPS::chroma_qp_index_offset
int chroma_qp_index_offset[2]
Definition: h264_ps.h:122
SPS::crop_top
unsigned int crop_top
frame_cropping_rect_top_offset
Definition: h264_ps.h:70
SPS::cpr_flag
uint32_t cpr_flag
Definition: h264_ps.h:95
SPS::fixed_frame_rate_flag
int fixed_frame_rate_flag
Definition: h264_ps.h:78
SPS::scaling_matrix_present_mask
uint16_t scaling_matrix_present_mask
Definition: h264_ps.h:84
SPS::frame_mbs_only_flag
int frame_mbs_only_flag
Definition: h264_ps.h:62
SPS::bit_rate_value
uint32_t bit_rate_value[32]
bit_rate_value_minus1 + 1
Definition: h264_ps.h:93
SPS::poc_type
int poc_type
pic_order_cnt_type
Definition: h264_ps.h:51
SPS::num_reorder_frames
int num_reorder_frames
Definition: h264_ps.h:81
PPS::constrained_intra_pred
int constrained_intra_pred
constrained_intra_pred_flag
Definition: h264_ps.h:124
PPS::redundant_pic_cnt_present
int redundant_pic_cnt_present
redundant_pic_cnt_present_flag
Definition: h264_ps.h:125
PPS::weighted_bipred_idc
int weighted_bipred_idc
Definition: h264_ps.h:119
GetBitContext
Definition: get_bits.h:108
ff_h264_decode_seq_parameter_set
int ff_h264_decode_seq_parameter_set(GetBitContext *gb, AVCodecContext *avctx, H264ParamSets *ps, int ignore_truncation)
Decode SPS.
Definition: h264_ps.c:284
SPS::residual_color_transform_flag
int residual_color_transform_flag
residual_colour_transform_flag
Definition: h264_ps.h:101
PPS::ref_count
unsigned int ref_count[2]
num_ref_idx_l0/1_active_minus1 + 1
Definition: h264_ps.h:117
PPS::scaling_matrix8
uint8_t scaling_matrix8[6][64]
Definition: h264_ps.h:130
PPS::pic_scaling_matrix_present_flag
int pic_scaling_matrix_present_flag
Definition: h264_ps.h:127
SPS::num_units_in_tick
uint32_t num_units_in_tick
Definition: h264_ps.h:76
SPS::bit_depth_chroma
int bit_depth_chroma
bit_depth_chroma_minus8 + 8
Definition: h264_ps.h:100
SPS::profile_idc
int profile_idc
Definition: h264_ps.h:46
PPS::pps_id
unsigned int pps_id
Definition: h264_ps.h:111
H264ParamSets::overread_warning_printed
int overread_warning_printed[2]
Definition: h264_ps.h:152
PPS::pic_scaling_matrix_present_mask
uint16_t pic_scaling_matrix_present_mask
Definition: h264_ps.h:128
QP_MAX_NUM
#define QP_MAX_NUM
Definition: h264.h:27
SPS::transform_bypass
int transform_bypass
qpprime_y_zero_transform_bypass_flag
Definition: h264_ps.h:49
PPS::deblocking_filter_parameters_present
int deblocking_filter_parameters_present
deblocking_filter_parameters_present_flag
Definition: h264_ps.h:123
get_bits.h
SPS::direct_8x8_inference_flag
int direct_8x8_inference_flag
Definition: h264_ps.h:64
SPS::crop_left
unsigned int crop_left
frame_cropping_rect_left_offset
Definition: h264_ps.h:68
SPS::gaps_in_frame_num_allowed_flag
int gaps_in_frame_num_allowed_flag
Definition: h264_ps.h:58
SPS::scaling_matrix8
uint8_t scaling_matrix8[6][64]
Definition: h264_ps.h:86
SPS::ref_frame_count
int ref_frame_count
num_ref_frames
Definition: h264_ps.h:57
SPS::sps_id
unsigned int sps_id
Definition: h264_ps.h:45
ff_h264_decode_picture_parameter_set
int ff_h264_decode_picture_parameter_set(GetBitContext *gb, AVCodecContext *avctx, H264ParamSets *ps, int bit_length)
Decode PPS.
Definition: h264_ps.c:696
SPS::mb_aff
int mb_aff
mb_adaptive_frame_field_flag
Definition: h264_ps.h:63
PPS::cabac
int cabac
entropy_coding_mode_flag
Definition: h264_ps.h:113
PPS::pic_order_present
int pic_order_present
bottom_field_pic_order_in_frame_present_flag
Definition: h264_ps.h:114
PPS::dequant4_coeff
uint32_t(*[6] dequant4_coeff)[16]
Definition: h264_ps.h:138
PPS::dequant8_coeff
uint32_t(*[6] dequant8_coeff)[64]
Definition: h264_ps.h:139
ff_h264_ps_uninit
void ff_h264_ps_uninit(H264ParamSets *ps)
Uninit H264 param sets structure.
Definition: h264_ps.c:270
SPS::time_offset_length
int time_offset_length
Definition: h264_ps.h:90
SPS
Sequence parameter set.
Definition: h264_ps.h:44
PPS
Picture parameter set.
Definition: h264_ps.h:110
PPS::init_qp
int init_qp
pic_init_qp_minus26 + 26
Definition: h264_ps.h:120
H2645VUI
Definition: h2645_vui.h:27
MAX_PPS_COUNT
#define MAX_PPS_COUNT
Definition: h264_ps.h:38
SPS::cpb_size_value
uint32_t cpb_size_value[32]
cpb_size_value_minus1 + 1
Definition: h264_ps.h:94
SPS::vcl_hrd_parameters_present_flag
int vcl_hrd_parameters_present_flag
Definition: h264_ps.h:88
SPS::timing_info_present_flag
int timing_info_present_flag
Definition: h264_ps.h:75
SPS::poc_cycle_length
int poc_cycle_length
num_ref_frames_in_pic_order_cnt_cycle
Definition: h264_ps.h:56
PPS::weighted_pred
int weighted_pred
weighted_pred_flag
Definition: h264_ps.h:118
SPS::vui
H2645VUI vui
Definition: h264_ps.h:73
SPS::delta_pic_order_always_zero_flag
int delta_pic_order_always_zero_flag
Definition: h264_ps.h:53
SPS::offset_for_top_to_bottom_field
int offset_for_top_to_bottom_field
Definition: h264_ps.h:55
SPS::crop
int crop
frame_cropping_flag
Definition: h264_ps.h:65
SPS::data_size
size_t data_size
Definition: h264_ps.h:104
PPS::data_size
size_t data_size
Definition: h264_ps.h:134
PPS::init_qs
int init_qs
pic_init_qs_minus26 + 26
Definition: h264_ps.h:121
SPS::initial_cpb_removal_delay_length
int initial_cpb_removal_delay_length
initial_cpb_removal_delay_length_minus1 + 1
Definition: h264_ps.h:96
SPS::data
uint8_t data[4096]
Definition: h264_ps.h:103
PPS::data
uint8_t data[4096]
Definition: h264_ps.h:133
SPS::log2_max_poc_lsb
int log2_max_poc_lsb
log2_max_pic_order_cnt_lsb_minus4
Definition: h264_ps.h:52
PPS::transform_8x8_mode
int transform_8x8_mode
transform_8x8_mode_flag
Definition: h264_ps.h:126
PPS::chroma_qp_table
uint8_t chroma_qp_table[2][QP_MAX_NUM+1]
pre-scaled (with chroma_qp_index_offset) version of qp_table
Definition: h264_ps.h:131
SPS::dpb_output_delay_length
int dpb_output_delay_length
dpb_output_delay_length_minus1 + 1
Definition: h264_ps.h:98
PPS::slice_group_count
int slice_group_count
num_slice_groups_minus1 + 1
Definition: h264_ps.h:115
avcodec.h
SPS::constraint_set_flags
int constraint_set_flags
constraint_set[0-3]_flag
Definition: h264_ps.h:102
SPS::nal_hrd_parameters_present_flag
int nal_hrd_parameters_present_flag
Definition: h264_ps.h:87
SPS::bit_rate_scale
int bit_rate_scale
Definition: h264_ps.h:92
PPS::sps
const SPS * sps
RefStruct reference.
Definition: h264_ps.h:141
pixfmt.h
h2645_vui.h
sps
static int FUNC() sps(CodedBitstreamContext *ctx, RWContext *rw, H264RawSPS *current)
Definition: cbs_h264_syntax_template.c:260
SPS::max_dec_frame_buffering
int max_dec_frame_buffering
Definition: h264_ps.h:82
PPS::sps_id
unsigned int sps_id
Definition: h264_ps.h:112
AVCodecContext
main external API structure.
Definition: avcodec.h:445
SPS::vui_parameters_present_flag
int vui_parameters_present_flag
Definition: h264_ps.h:72
H264ParamSets
Definition: h264_ps.h:144
SPS::chroma_format_idc
int chroma_format_idc
Definition: h264_ps.h:48
MAX_SPS_COUNT
#define MAX_SPS_COUNT
Definition: h264_ps.h:37
ff_h264_get_profile
int ff_h264_get_profile(const SPS *sps)
compute profile from sps
Definition: h264_parse.c:531
SPS::mb_height
int mb_height
Definition: h264_ps.h:61
PPS::dequant8_buffer
uint32_t dequant8_buffer[6][QP_MAX_NUM+1][64]
Definition: h264_ps.h:137
SPS::level_idc
int level_idc
Definition: h264_ps.h:47
SPS::bit_depth_luma
int bit_depth_luma
bit_depth_luma_minus8 + 8
Definition: h264_ps.h:99
SPS::time_scale
uint32_t time_scale
Definition: h264_ps.h:77
int32_t
int32_t
Definition: audioconvert.c:56
h264.h
PPS::mb_slice_group_map_type
int mb_slice_group_map_type
Definition: h264_ps.h:116
SPS::pic_struct_present_flag
int pic_struct_present_flag
Definition: h264_ps.h:89
H264ParamSets::pps
const PPS * pps
RefStruct reference.
Definition: h264_ps.h:149
SPS::bitstream_restriction_flag
int bitstream_restriction_flag
Definition: h264_ps.h:80
SPS::scaling_matrix4
uint8_t scaling_matrix4[6][16]
Definition: h264_ps.h:85
SPS::cpb_cnt
int cpb_cnt
See H.264 E.1.2.
Definition: h264_ps.h:91
SPS::log2_max_frame_num
int log2_max_frame_num
log2_max_frame_num_minus4 + 4
Definition: h264_ps.h:50
PPS::chroma_qp_diff
int chroma_qp_diff
Definition: h264_ps.h:132
PPS::dequant4_buffer
uint32_t dequant4_buffer[6][QP_MAX_NUM+1][16]
Definition: h264_ps.h:136