summaryrefslogtreecommitdiff
path: root/drivers/amvdec_ports/decoder/aml_mpeg4_parser.h (plain)
blob: 09f392d0ffa404edbbc42337b91e3cbe1848d926
1#ifndef AVCODEC_MPEG4VIDEO_H
2#define AVCODEC_MPEG4VIDEO_H
3
4#include "../aml_vcodec_drv.h"
5#include "../utils/pixfmt.h"
6#include "../utils/common.h"
7
8//mpeg4 profile
9#define FF_PROFILE_MPEG4_SIMPLE 0
10#define FF_PROFILE_MPEG4_SIMPLE_SCALABLE 1
11#define FF_PROFILE_MPEG4_CORE 2
12#define FF_PROFILE_MPEG4_MAIN 3
13#define FF_PROFILE_MPEG4_N_BIT 4
14#define FF_PROFILE_MPEG4_SCALABLE_TEXTURE 5
15#define FF_PROFILE_MPEG4_SIMPLE_FACE_ANIMATION 6
16#define FF_PROFILE_MPEG4_BASIC_ANIMATED_TEXTURE 7
17#define FF_PROFILE_MPEG4_HYBRID 8
18#define FF_PROFILE_MPEG4_ADVANCED_REAL_TIME 9
19#define FF_PROFILE_MPEG4_CORE_SCALABLE 10
20#define FF_PROFILE_MPEG4_ADVANCED_CODING 11
21#define FF_PROFILE_MPEG4_ADVANCED_CORE 12
22#define FF_PROFILE_MPEG4_ADVANCED_SCALABLE_TEXTURE 13
23#define FF_PROFILE_MPEG4_SIMPLE_STUDIO 14
24#define FF_PROFILE_MPEG4_ADVANCED_SIMPLE 15
25
26// shapes
27#define RECT_SHAPE 0
28#define BIN_SHAPE 1
29#define BIN_ONLY_SHAPE 2
30#define GRAY_SHAPE 3
31
32#define SIMPLE_VO_TYPE 1
33#define CORE_VO_TYPE 3
34#define MAIN_VO_TYPE 4
35#define NBIT_VO_TYPE 5
36#define ARTS_VO_TYPE 10
37#define ACE_VO_TYPE 12
38#define SIMPLE_STUDIO_VO_TYPE 14
39#define CORE_STUDIO_VO_TYPE 15
40#define ADV_SIMPLE_VO_TYPE 17
41
42#define VOT_VIDEO_ID 1
43#define VOT_STILL_TEXTURE_ID 2
44
45#define FF_PROFILE_UNKNOWN -99
46#define FF_PROFILE_RESERVED -100
47
48// aspect_ratio_info
49#define EXTENDED_PAR 15
50
51//vol_sprite_usage / sprite_enable
52#define STATIC_SPRITE 1
53#define GMC_SPRITE 2
54
55#define MOTION_MARKER 0x1F001
56#define DC_MARKER 0x6B001
57
58#define VOS_STARTCODE 0x1B0
59#define USER_DATA_STARTCODE 0x1B2
60#define GOP_STARTCODE 0x1B3
61#define VISUAL_OBJ_STARTCODE 0x1B5
62#define VOP_STARTCODE 0x1B6
63#define SLICE_STARTCODE 0x1B7
64#define EXT_STARTCODE 0x1B8
65
66#define QUANT_MATRIX_EXT_ID 0x3
67
68/* smaller packets likely don't contain a real frame */
69#define MAX_NVOP_SIZE 19
70
71#define IS_3IV1 0
72
73#define CHROMA_420 1
74#define CHROMA_422 2
75#define CHROMA_444 3
76
77#define FF_ASPECT_EXTENDED 15
78
79#define AV_NOPTS_VALUE (LONG_MIN)
80
81/**
82 * Return value for header parsers if frame is not coded.
83 * */
84#define FRAME_SKIPPED 100
85
86enum AVPictureType {
87 AV_PICTURE_TYPE_NONE = 0, ///< Undefined
88 AV_PICTURE_TYPE_I, ///< Intra
89 AV_PICTURE_TYPE_P, ///< Predicted
90 AV_PICTURE_TYPE_B, ///< Bi-dir predicted
91 AV_PICTURE_TYPE_S, ///< S(GMC)-VOP MPEG-4
92 AV_PICTURE_TYPE_SI, ///< Switching Intra
93 AV_PICTURE_TYPE_SP, ///< Switching Predicted
94 AV_PICTURE_TYPE_BI, ///< BI type
95};
96
97struct VLC {
98 int bits;
99 short (*table)[2]; ///< code, bits
100 int table_size, table_allocated;
101};
102
103/**
104 * MpegEncContext.
105 */
106struct MpegEncContext {
107 struct mpeg4_dec_param *ctx;
108
109 /* the following parameters must be initialized before encoding */
110 int width, height;///< picture size. must be a multiple of 16
111 int codec_tag; ///< internal codec_tag upper case converted from avctx codec_tag
112 int picture_number; //FIXME remove, unclear definition
113
114 /** matrix transmitted in the bitstream */
115 u16 intra_matrix[64];
116 u16 chroma_intra_matrix[64];
117 u16 inter_matrix[64];
118 u16 chroma_inter_matrix[64];
119
120 /* MPEG-4 specific */
121 int studio_profile;
122 int time_base; ///< time in seconds of last I,P,S Frame
123 int quant_precision;
124 int quarter_sample; ///< 1->qpel, 0->half pel ME/MC
125 int aspect_ratio_info; //FIXME remove
126 int sprite_warping_accuracy;
127 int data_partitioning; ///< data partitioning flag from header
128 int low_delay; ///< no reordering needed / has no B-frames
129 int vo_type;
130 int mpeg_quant;
131
132 /* divx specific, used to workaround (many) bugs in divx5 */
133 int divx_packed;
134
135 /* MPEG-2-specific - I wished not to have to support this mess. */
136 int progressive_sequence;
137
138 int progressive_frame;
139 int interlaced_dct;
140
141 int h_edge_pos, v_edge_pos;///< horizontal / vertical position of the right/bottom edge (pixel replication)
142 const u8 *y_dc_scale_table; ///< qscale -> y_dc_scale table
143 const u8 *c_dc_scale_table; ///< qscale -> c_dc_scale table
144 int qscale; ///< QP
145 int chroma_qscale; ///< chroma QP
146 int pict_type; ///< AV_PICTURE_TYPE_I, AV_PICTURE_TYPE_P, AV_PICTURE_TYPE_B, ...
147 int f_code; ///< forward MV resolution
148 int b_code; ///< backward MV resolution for B-frames (MPEG-4)
149 int no_rounding; /**< apply no rounding to motion compensation (MPEG-4, msmpeg4, ...)
150 for B-frames rounding mode is always 0 */
151 int last_time_base;
152 long time; ///< time of current frame
153 long last_non_b_time;
154 u16 pp_time; ///< time distance between the last 2 p,s,i frames
155 u16 pb_time; ///< time distance between the last b and p,s,i frame
156 u16 pp_field_time;
157 u16 pb_field_time; ///< like above, just for interlaced
158 int real_sprite_warping_points;
159 int sprite_offset[2][2]; ///< sprite offset[isChroma][isMVY]
160 int sprite_delta[2][2]; ///< sprite_delta [isY][isMVY]
161 int mcsel;
162 int partitioned_frame; ///< is current frame partitioned
163 int top_field_first;
164 int alternate_scan;
165 int last_dc[3]; ///< last DC values for MPEG-1
166 int dct_precision;
167 int intra_dc_precision;
168 int frame_pred_frame_dct;
169 int q_scale_type;
170 int context_reinit;
171 int chroma_format;
172};
173
174struct mpeg4_dec_param {
175 struct MpegEncContext m;
176
177 /// number of bits to represent the fractional part of time
178 int time_increment_bits;
179 int shape;
180 int vol_sprite_usage;
181 int sprite_brightness_change;
182 int num_sprite_warping_points;
183 /// sprite trajectory points
184 u16 sprite_traj[4][2];
185 /// sprite shift [isChroma]
186 int sprite_shift[2];
187
188 // reversible vlc
189 int rvlc;
190 /// could this stream contain resync markers
191 int resync_marker;
192 /// time distance of first I -> B, used for interlaced B-frames
193 int t_frame;
194
195 int new_pred;
196 int enhancement_type;
197 int scalability;
198 int use_intra_dc_vlc;
199
200 /// QP above which the ac VLC should be used for intra dc
201 int intra_dc_threshold;
202
203 /* bug workarounds */
204 int divx_version;
205 int divx_build;
206 int xvid_build;
207 int lavc_build;
208
209 /// flag for having shown the warning about invalid Divx B-frames
210 int showed_packed_warning;
211 /** does the stream contain the low_delay flag,
212 * used to work around buggy encoders. */
213 int vol_control_parameters;
214 int cplx_estimation_trash_i;
215 int cplx_estimation_trash_p;
216 int cplx_estimation_trash_b;
217
218 struct VLC studio_intra_tab[12];
219 struct VLC studio_luma_dc;
220 struct VLC studio_chroma_dc;
221
222 int rgb;
223
224 struct AVRational time_base;
225 int ticks_per_frame;
226 enum AVPixelFormat pix_fmt;
227 struct AVRational sample_aspect_ratio;
228 enum AVColorPrimaries color_primaries;
229 enum AVColorTransferCharacteristic color_trc;
230 enum AVColorSpace colorspace;
231 enum AVColorRange color_range;
232 enum AVChromaLocation chroma_sample_location;
233 int err_recognition;
234 int idct_algo;
235 int bits_per_raw_sample;
236 int profile;
237 int level;
238 struct AVRational framerate;
239 int flags;
240};
241
242struct mpeg4_param_sets {
243 bool head_parsed;
244 /* currently active parameter sets */
245 struct mpeg4_dec_param dec_ps;
246};
247
248int mpeg4_decode_extradata_ps(u8 *buf, int size, struct mpeg4_param_sets *ps);
249
250#endif
251
252