blob: aed5378e24e720f853064a27b5d9cdd8eb5bb9c8
1 | /* |
2 | * drivers/amvdec_ports/decoder/aml_h264_parser.h |
3 | * |
4 | * Copyright (C) 2015 Amlogic, Inc. All rights reserved. |
5 | * |
6 | * This program is free software; you can redistribute it and/or modify |
7 | * it under the terms of the GNU General Public License as published by |
8 | * the Free Software Foundation; either version 2 of the License, or |
9 | * (at your option) any later version. |
10 | * |
11 | * This program is distributed in the hope that it will be useful, but WITHOUT |
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
14 | * more details. |
15 | * |
16 | */ |
17 | |
18 | #ifndef AML_H264_PARSER_H |
19 | #define AML_H264_PARSER_H |
20 | |
21 | #include "../aml_vcodec_drv.h" |
22 | #include "../utils/pixfmt.h" |
23 | |
24 | #define QP_MAX_NUM (51 + 6 * 6) // The maximum supported qp |
25 | |
26 | /* NAL unit types */ |
27 | enum { |
28 | H264_NAL_SLICE = 1, |
29 | H264_NAL_DPA = 2, |
30 | H264_NAL_DPB = 3, |
31 | H264_NAL_DPC = 4, |
32 | H264_NAL_IDR_SLICE = 5, |
33 | H264_NAL_SEI = 6, |
34 | H264_NAL_SPS = 7, |
35 | H264_NAL_PPS = 8, |
36 | H264_NAL_AUD = 9, |
37 | H264_NAL_END_SEQUENCE = 10, |
38 | H264_NAL_END_STREAM = 11, |
39 | H264_NAL_FILLER_DATA = 12, |
40 | H264_NAL_SPS_EXT = 13, |
41 | H264_NAL_AUXILIARY_SLICE = 19, |
42 | }; |
43 | |
44 | enum { |
45 | // 7.4.2.1.1: seq_parameter_set_id is in [0, 31]. |
46 | H264_MAX_SPS_COUNT = 32, |
47 | // 7.4.2.2: pic_parameter_set_id is in [0, 255]. |
48 | H264_MAX_PPS_COUNT = 256, |
49 | |
50 | // A.3: MaxDpbFrames is bounded above by 16. |
51 | H264_MAX_DPB_FRAMES = 16, |
52 | // 7.4.2.1.1: max_num_ref_frames is in [0, MaxDpbFrames], and |
53 | // each reference frame can have two fields. |
54 | H264_MAX_REFS = 2 * H264_MAX_DPB_FRAMES, |
55 | |
56 | // 7.4.3.1: modification_of_pic_nums_idc is not equal to 3 at most |
57 | // num_ref_idx_lN_active_minus1 + 1 times (that is, once for each |
58 | // possible reference), then equal to 3 once. |
59 | H264_MAX_RPLM_COUNT = H264_MAX_REFS + 1, |
60 | |
61 | // 7.4.3.3: in the worst case, we begin with a full short-term |
62 | // reference picture list. Each picture in turn is moved to the |
63 | // long-term list (type 3) and then discarded from there (type 2). |
64 | // Then, we set the length of the long-term list (type 4), mark |
65 | // the current picture as long-term (type 6) and terminate the |
66 | // process (type 0). |
67 | H264_MAX_MMCO_COUNT = H264_MAX_REFS * 2 + 3, |
68 | |
69 | // A.2.1, A.2.3: profiles supporting FMO constrain |
70 | // num_slice_groups_minus1 to be in [0, 7]. |
71 | H264_MAX_SLICE_GROUPS = 8, |
72 | |
73 | // E.2.2: cpb_cnt_minus1 is in [0, 31]. |
74 | H264_MAX_CPB_CNT = 32, |
75 | |
76 | // A.3: in table A-1 the highest level allows a MaxFS of 139264. |
77 | H264_MAX_MB_PIC_SIZE = 139264, |
78 | // A.3.1, A.3.2: PicWidthInMbs and PicHeightInMbs are constrained |
79 | // to be not greater than sqrt(MaxFS * 8). Hence height/width are |
80 | // bounded above by sqrt(139264 * 8) = 1055.5 macroblocks. |
81 | H264_MAX_MB_WIDTH = 1055, |
82 | H264_MAX_MB_HEIGHT = 1055, |
83 | H264_MAX_WIDTH = H264_MAX_MB_WIDTH * 16, |
84 | H264_MAX_HEIGHT = H264_MAX_MB_HEIGHT * 16, |
85 | }; |
86 | |
87 | /** |
88 | * Rational number (pair of numerator and denominator). |
89 | */ |
90 | struct rational{ |
91 | int num; ///< Numerator |
92 | int den; ///< Denominator |
93 | }; |
94 | |
95 | /** |
96 | * Sequence parameter set |
97 | */ |
98 | struct h264_SPS_t { |
99 | u32 sps_id; |
100 | int profile_idc; |
101 | int level_idc; |
102 | int chroma_format_idc; |
103 | int transform_bypass; ///< qpprime_y_zero_transform_bypass_flag |
104 | int log2_max_frame_num; ///< log2_max_frame_num_minus4 + 4 |
105 | int poc_type; ///< pic_order_cnt_type |
106 | int log2_max_poc_lsb; ///< log2_max_pic_order_cnt_lsb_minus4 |
107 | int delta_pic_order_always_zero_flag; |
108 | int offset_for_non_ref_pic; |
109 | int offset_for_top_to_bottom_field; |
110 | int poc_cycle_length; ///< num_ref_frames_in_pic_order_cnt_cycle |
111 | int ref_frame_count; ///< num_ref_frames |
112 | int gaps_in_frame_num_allowed_flag; |
113 | int mb_width; ///< pic_width_in_mbs_minus1 + 1 |
114 | ///< (pic_height_in_map_units_minus1 + 1) * (2 - frame_mbs_only_flag) |
115 | int mb_height; |
116 | int frame_mbs_only_flag; |
117 | int mb_aff; ///< mb_adaptive_frame_field_flag |
118 | int direct_8x8_inference_flag; |
119 | int crop; ///< frame_cropping_flag |
120 | |
121 | /* those 4 are already in luma samples */ |
122 | u32 crop_left; ///< frame_cropping_rect_left_offset |
123 | u32 crop_right; ///< frame_cropping_rect_right_offset |
124 | u32 crop_top; ///< frame_cropping_rect_top_offset |
125 | u32 crop_bottom; ///< frame_cropping_rect_bottom_offset |
126 | int vui_parameters_present_flag; |
127 | struct rational sar; |
128 | int video_signal_type_present_flag; |
129 | int full_range; |
130 | int colour_description_present_flag; |
131 | enum AVColorPrimaries color_primaries; |
132 | enum AVColorTransferCharacteristic color_trc; |
133 | enum AVColorSpace colorspace; |
134 | int timing_info_present_flag; |
135 | u32 num_units_in_tick; |
136 | u32 time_scale; |
137 | int fixed_frame_rate_flag; |
138 | int32_t offset_for_ref_frame[256]; |
139 | int bitstream_restriction_flag; |
140 | int num_reorder_frames; |
141 | int max_dec_frame_buffering; |
142 | int scaling_matrix_present; |
143 | u8 scaling_matrix4[6][16]; |
144 | u8 scaling_matrix8[6][64]; |
145 | int nal_hrd_parameters_present_flag; |
146 | int vcl_hrd_parameters_present_flag; |
147 | int pic_struct_present_flag; |
148 | int time_offset_length; |
149 | int cpb_cnt; ///< See H.264 E.1.2 |
150 | int initial_cpb_removal_delay_length; ///< initial_cpb_removal_delay_length_minus1 + 1 |
151 | int cpb_removal_delay_length; ///< cpb_removal_delay_length_minus1 + 1 |
152 | int dpb_output_delay_length; ///< dpb_output_delay_length_minus1 + 1 |
153 | int bit_depth_luma; ///< bit_depth_luma_minus8 + 8 |
154 | int bit_depth_chroma; ///< bit_depth_chroma_minus8 + 8 |
155 | int residual_color_transform_flag; ///< residual_colour_transform_flag |
156 | int constraint_set_flags; ///< constraint_set[0-3]_flag |
157 | } ; |
158 | |
159 | /** |
160 | * Picture parameter set |
161 | */ |
162 | struct h264_PPS_t { |
163 | u32 sps_id; |
164 | int cabac; ///< entropy_coding_mode_flag |
165 | int pic_order_present; ///< pic_order_present_flag |
166 | int slice_group_count; ///< num_slice_groups_minus1 + 1 |
167 | int mb_slice_group_map_type; |
168 | u32 ref_count[2]; ///< num_ref_idx_l0/1_active_minus1 + 1 |
169 | int weighted_pred; ///< weighted_pred_flag |
170 | int weighted_bipred_idc; |
171 | int init_qp; ///< pic_init_qp_minus26 + 26 |
172 | int init_qs; ///< pic_init_qs_minus26 + 26 |
173 | int chroma_qp_index_offset[2]; |
174 | int deblocking_filter_parameters_present; ///< deblocking_filter_parameters_present_flag |
175 | int constrained_intra_pred; ///< constrained_intra_pred_flag |
176 | int redundant_pic_cnt_present; ///< redundant_pic_cnt_present_flag |
177 | int transform_8x8_mode; ///< transform_8x8_mode_flag |
178 | u8 scaling_matrix4[6][16]; |
179 | u8 scaling_matrix8[6][64]; |
180 | u8 chroma_qp_table[2][87+1]; ///< pre-scaled (with chroma_qp_index_offset) version of qp_table |
181 | int chroma_qp_diff; |
182 | u8 data[4096]; |
183 | int data_size; |
184 | |
185 | u32 dequant4_buffer[6][87 + 1][16]; |
186 | u32 dequant8_buffer[6][87 + 1][64]; |
187 | u32(*dequant4_coeff[6])[16]; |
188 | u32(*dequant8_coeff[6])[64]; |
189 | } ; |
190 | |
191 | struct h264_param_sets { |
192 | bool sps_parsed; |
193 | bool pps_parsed; |
194 | struct h264_SPS_t sps; |
195 | struct h264_PPS_t pps; |
196 | }; |
197 | |
198 | int h264_decode_extradata_ps(u8 *data, int size, struct h264_param_sets *ps); |
199 | |
200 | #endif /* AML_H264_PARSER_H */ |
201 | |
202 |