h264_ps: export actual height in MBs as SPS.mb_height
[libav.git] / libavcodec / h264_ps.h
1 /*
2 * This file is part of Libav.
3 *
4 * Libav 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 * Libav 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 Libav; 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/buffer.h"
30 #include "libavutil/pixfmt.h"
31 #include "libavutil/rational.h"
32
33 #include "avcodec.h"
34 #include "get_bits.h"
35 #include "h264.h"
36
37 #define MAX_SPS_COUNT 32
38 #define MAX_PPS_COUNT 256
39
40 /**
41 * Sequence parameter set
42 */
43 typedef struct SPS {
44 unsigned int sps_id;
45 int profile_idc;
46 int level_idc;
47 int chroma_format_idc;
48 int transform_bypass; ///< qpprime_y_zero_transform_bypass_flag
49 int log2_max_frame_num; ///< log2_max_frame_num_minus4 + 4
50 int poc_type; ///< pic_order_cnt_type
51 int log2_max_poc_lsb; ///< log2_max_pic_order_cnt_lsb_minus4
52 int delta_pic_order_always_zero_flag;
53 int offset_for_non_ref_pic;
54 int offset_for_top_to_bottom_field;
55 int poc_cycle_length; ///< num_ref_frames_in_pic_order_cnt_cycle
56 int ref_frame_count; ///< num_ref_frames
57 int gaps_in_frame_num_allowed_flag;
58 int mb_width; ///< pic_width_in_mbs_minus1 + 1
59 ///< (pic_height_in_map_units_minus1 + 1) * (2 - frame_mbs_only_flag)
60 int mb_height;
61 int frame_mbs_only_flag;
62 int mb_aff; ///< mb_adaptive_frame_field_flag
63 int direct_8x8_inference_flag;
64 int crop; ///< frame_cropping_flag
65
66 /* those 4 are already in luma samples */
67 unsigned int crop_left; ///< frame_cropping_rect_left_offset
68 unsigned int crop_right; ///< frame_cropping_rect_right_offset
69 unsigned int crop_top; ///< frame_cropping_rect_top_offset
70 unsigned int crop_bottom; ///< frame_cropping_rect_bottom_offset
71 int vui_parameters_present_flag;
72 AVRational sar;
73 int video_signal_type_present_flag;
74 int full_range;
75 int colour_description_present_flag;
76 enum AVColorPrimaries color_primaries;
77 enum AVColorTransferCharacteristic color_trc;
78 enum AVColorSpace colorspace;
79 int timing_info_present_flag;
80 uint32_t num_units_in_tick;
81 uint32_t time_scale;
82 int fixed_frame_rate_flag;
83 short offset_for_ref_frame[256]; // FIXME dyn aloc?
84 int bitstream_restriction_flag;
85 int num_reorder_frames;
86 int scaling_matrix_present;
87 uint8_t scaling_matrix4[6][16];
88 uint8_t scaling_matrix8[6][64];
89 int nal_hrd_parameters_present_flag;
90 int vcl_hrd_parameters_present_flag;
91 int pic_struct_present_flag;
92 int time_offset_length;
93 int cpb_cnt; ///< See H.264 E.1.2
94 int initial_cpb_removal_delay_length; ///< initial_cpb_removal_delay_length_minus1 + 1
95 int cpb_removal_delay_length; ///< cpb_removal_delay_length_minus1 + 1
96 int dpb_output_delay_length; ///< dpb_output_delay_length_minus1 + 1
97 int bit_depth_luma; ///< bit_depth_luma_minus8 + 8
98 int bit_depth_chroma; ///< bit_depth_chroma_minus8 + 8
99 int residual_color_transform_flag; ///< residual_colour_transform_flag
100 int constraint_set_flags; ///< constraint_set[0-3]_flag
101 } SPS;
102
103 /**
104 * Picture parameter set
105 */
106 typedef struct PPS {
107 unsigned int sps_id;
108 int cabac; ///< entropy_coding_mode_flag
109 int pic_order_present; ///< pic_order_present_flag
110 int slice_group_count; ///< num_slice_groups_minus1 + 1
111 int mb_slice_group_map_type;
112 unsigned int ref_count[2]; ///< num_ref_idx_l0/1_active_minus1 + 1
113 int weighted_pred; ///< weighted_pred_flag
114 int weighted_bipred_idc;
115 int init_qp; ///< pic_init_qp_minus26 + 26
116 int init_qs; ///< pic_init_qs_minus26 + 26
117 int chroma_qp_index_offset[2];
118 int deblocking_filter_parameters_present; ///< deblocking_filter_parameters_present_flag
119 int constrained_intra_pred; ///< constrained_intra_pred_flag
120 int redundant_pic_cnt_present; ///< redundant_pic_cnt_present_flag
121 int transform_8x8_mode; ///< transform_8x8_mode_flag
122 uint8_t scaling_matrix4[6][16];
123 uint8_t scaling_matrix8[6][64];
124 uint8_t chroma_qp_table[2][64]; ///< pre-scaled (with chroma_qp_index_offset) version of qp_table
125 int chroma_qp_diff;
126
127 uint32_t dequant4_buffer[6][QP_MAX_NUM + 1][16];
128 uint32_t dequant8_buffer[6][QP_MAX_NUM + 1][64];
129 uint32_t(*dequant4_coeff[6])[16];
130 uint32_t(*dequant8_coeff[6])[64];
131 } PPS;
132
133 typedef struct H264ParamSets {
134 AVBufferRef *sps_list[MAX_SPS_COUNT];
135 AVBufferRef *pps_list[MAX_PPS_COUNT];
136
137 /* currently active parameters sets */
138 const PPS *pps;
139 // FIXME this should properly be const
140 SPS *sps;
141 } H264ParamSets;
142
143 /**
144 * Decode SPS
145 */
146 int ff_h264_decode_seq_parameter_set(GetBitContext *gb, AVCodecContext *avctx,
147 H264ParamSets *ps);
148
149 /**
150 * Decode PPS
151 */
152 int ff_h264_decode_picture_parameter_set(GetBitContext *gb, AVCodecContext *avctx,
153 H264ParamSets *ps, int bit_length);
154
155 #endif /* AVCODEC_H264_PS_H */