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