Mercurial > libavcodec.hg
annotate mpegvideo.h @ 253:4448dd55d415 libavcodec
parsing more of the mpeg4 header & print some "not supported" stuff
author | michaelni |
---|---|
date | Tue, 05 Mar 2002 13:58:13 +0000 |
parents | 56ee684c48bb |
children | b4fed8b24e3a |
rev | line source |
---|---|
0 | 1 /* |
2 * Generic DCT based hybrid video encoder | |
3 * Copyright (c) 2000,2001 Gerard Lantau. | |
4 * | |
5 * This program is free software; you can redistribute it and/or modify | |
6 * it under the terms of the GNU General Public License as published by | |
7 * the Free Software Foundation; either version 2 of the License, or | |
8 * (at your option) any later version. | |
9 * | |
10 * This program is distributed in the hope that it will be useful, | |
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 * GNU General Public License for more details. | |
14 * | |
15 * You should have received a copy of the GNU General Public License | |
16 * along with this program; if not, write to the Free Software | |
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
18 */ | |
19 | |
20 /* Macros for picture code type. */ | |
21 #define I_TYPE 1 | |
22 #define P_TYPE 2 | |
23 #define B_TYPE 3 | |
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
248
diff
changeset
|
24 #define S_TYPE 4 //S(GMC)-VOP MPEG4 |
0 | 25 |
26 enum OutputFormat { | |
27 FMT_MPEG1, | |
28 FMT_H263, | |
29 FMT_MJPEG, | |
30 }; | |
31 | |
32 #define MPEG_BUF_SIZE (16 * 1024) | |
33 | |
220 | 34 #define QMAT_SHIFT_MMX 19 |
35 #define QMAT_SHIFT 25 | |
36 | |
0 | 37 typedef struct MpegEncContext { |
71 | 38 struct AVCodecContext *avctx; |
0 | 39 /* the following parameters must be initialized before encoding */ |
40 int width, height; /* picture size. must be a multiple of 16 */ | |
41 int gop_size; | |
42 int frame_rate; /* number of frames per second */ | |
43 int intra_only; /* if true, only intra pictures are generated */ | |
44 int bit_rate; /* wanted bit rate */ | |
45 enum OutputFormat out_format; /* output format */ | |
46 int h263_plus; /* h263 plus headers */ | |
47 int h263_rv10; /* use RV10 variation for H263 */ | |
71 | 48 int h263_pred; /* use mpeg4/h263 ac/dc predictions */ |
0 | 49 int h263_msmpeg4; /* generate MSMPEG4 compatible stream */ |
50 int h263_intel; /* use I263 intel h263 header */ | |
51 int fixed_qscale; /* fixed qscale if non zero */ | |
7
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
52 int encoding; /* true if we are encoding (vs decoding) */ |
0 | 53 /* the following fields are managed internally by the encoder */ |
54 | |
55 /* bit output */ | |
56 PutBitContext pb; | |
57 | |
58 /* sequence parameters */ | |
59 int context_initialized; | |
60 int picture_number; | |
61 int fake_picture_number; /* picture number at the bitstream frame rate */ | |
233
3f5b72726118
- More work on preliminary bit rate control, just to be able to get an
pulento
parents:
232
diff
changeset
|
62 int gop_picture_number; /* index of the first picture of a GOP */ |
0 | 63 int mb_width, mb_height; |
233
3f5b72726118
- More work on preliminary bit rate control, just to be able to get an
pulento
parents:
232
diff
changeset
|
64 int mb_num; /* number of MBs of a picture */ |
0 | 65 int linesize; /* line size, in bytes, may be different from width */ |
66 UINT8 *new_picture[3]; /* picture to be compressed */ | |
67 UINT8 *last_picture[3]; /* previous picture */ | |
68 UINT8 *last_picture_base[3]; /* real start of the picture */ | |
69 UINT8 *next_picture[3]; /* previous picture (for bidir pred) */ | |
70 UINT8 *next_picture_base[3]; /* real start of the picture */ | |
71 UINT8 *aux_picture[3]; /* aux picture (for B frames only) */ | |
72 UINT8 *aux_picture_base[3]; /* real start of the picture */ | |
73 UINT8 *current_picture[3]; /* buffer to store the decompressed current picture */ | |
74 int last_dc[3]; /* last DC values for MPEG1 */ | |
75 INT16 *dc_val[3]; /* used for mpeg4 DC prediction */ | |
76 int y_dc_scale, c_dc_scale; | |
77 UINT8 *coded_block; /* used for coded block pattern prediction */ | |
78 INT16 (*ac_val[3])[16]; /* used for for mpeg4 AC prediction */ | |
79 int ac_pred; | |
7
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
80 int mb_skiped; /* MUST BE SET only during DECODING */ |
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
81 UINT8 *mbskip_table; /* used to avoid copy if macroblock |
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
82 skipped (for black regions for example) */ |
191
883f184537e6
AC table reset (memset) optimization - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
162
diff
changeset
|
83 UINT8 *mbintra_table; /* used to kill a few memsets */ |
0 | 84 |
85 int qscale; | |
86 int pict_type; | |
87 int frame_rate_index; | |
88 /* motion compensation */ | |
89 int unrestricted_mv; | |
90 int h263_long_vectors; /* use horrible h263v1 long vector mode */ | |
91 | |
92 int f_code; /* resolution */ | |
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
248
diff
changeset
|
93 int b_code; /* resolution for B Frames*/ |
232
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
94 INT16 *mv_table[2]; /* MV table */ |
0 | 95 INT16 (*motion_val)[2]; /* used for MV prediction */ |
96 int full_search; | |
97 int mv_dir; | |
98 #define MV_DIR_BACKWARD 1 | |
99 #define MV_DIR_FORWARD 2 | |
100 int mv_type; | |
101 #define MV_TYPE_16X16 0 /* 1 vector for the whole mb */ | |
102 #define MV_TYPE_8X8 1 /* 4 vectors (h263) */ | |
103 #define MV_TYPE_16X8 2 /* 2 vectors, one per 16x8 block */ | |
104 #define MV_TYPE_FIELD 3 /* 2 vectors, one per field */ | |
105 #define MV_TYPE_DMV 4 /* 2 vectors, special mpeg2 Dual Prime Vectors */ | |
106 /* motion vectors for a macroblock | |
107 first coordinate : 0 = forward 1 = backward | |
108 second " : depend on type | |
109 third " : 0 = x, 1 = y | |
110 */ | |
111 int mv[2][4][2]; | |
112 int field_select[2][2]; | |
113 int last_mv[2][2][2]; | |
114 | |
115 int has_b_frames; | |
116 int no_rounding; /* apply no rounding to motion estimation (MPEG4) */ | |
117 | |
118 /* macroblock layer */ | |
119 int mb_x, mb_y; | |
120 int mb_incr; | |
121 int mb_intra; | |
239 | 122 INT16 *mb_var; /* Table for MB variances */ |
232
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
123 char *mb_type; /* Table for MB type */ |
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
124 |
0 | 125 /* matrix transmitted in the bitstream */ |
126 UINT16 intra_matrix[64]; | |
127 UINT16 chroma_intra_matrix[64]; | |
128 UINT16 non_intra_matrix[64]; | |
129 UINT16 chroma_non_intra_matrix[64]; | |
130 /* precomputed matrix (combine qscale and DCT renorm) */ | |
131 int q_intra_matrix[64]; | |
132 int q_non_intra_matrix[64]; | |
220 | 133 /* identical to the above but for MMX & these are not permutated */ |
134 UINT16 __align8 q_intra_matrix16[64] ; | |
135 UINT16 __align8 q_non_intra_matrix16[64]; | |
0 | 136 int block_last_index[6]; /* last non zero coefficient in block */ |
137 | |
138 void *opaque; /* private data for the user */ | |
139 | |
140 /* bit rate control */ | |
141 int I_frame_bits; /* wanted number of bits per I frame */ | |
142 int P_frame_bits; /* same for P frame */ | |
233
3f5b72726118
- More work on preliminary bit rate control, just to be able to get an
pulento
parents:
232
diff
changeset
|
143 int avg_mb_var; /* average MB variance for current frame */ |
64 | 144 INT64 wanted_bits; |
145 INT64 total_bits; | |
79
82e579c37bc3
Moved some H.263+ variables to MpegEncContext to be thread-safe.
pulento
parents:
71
diff
changeset
|
146 |
154
f914f710b8d0
- Fixed a bug on H.263 MV prediction for MB on GOBs limits.
pulento
parents:
151
diff
changeset
|
147 /* H.263 specific */ |
f914f710b8d0
- Fixed a bug on H.263 MV prediction for MB on GOBs limits.
pulento
parents:
151
diff
changeset
|
148 int gob_number; |
162 | 149 int gob_index; |
154
f914f710b8d0
- Fixed a bug on H.263 MV prediction for MB on GOBs limits.
pulento
parents:
151
diff
changeset
|
150 int first_gob_line; |
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
243
diff
changeset
|
151 |
79
82e579c37bc3
Moved some H.263+ variables to MpegEncContext to be thread-safe.
pulento
parents:
71
diff
changeset
|
152 /* H.263+ specific */ |
82e579c37bc3
Moved some H.263+ variables to MpegEncContext to be thread-safe.
pulento
parents:
71
diff
changeset
|
153 int umvplus; |
82e579c37bc3
Moved some H.263+ variables to MpegEncContext to be thread-safe.
pulento
parents:
71
diff
changeset
|
154 int umvplus_dec; |
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
243
diff
changeset
|
155 int h263_aic; /* Advanded INTRA Coding (AIC) */ |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
243
diff
changeset
|
156 int h263_aic_dir; /* AIC direction: 0 = left, 1 = top */ |
79
82e579c37bc3
Moved some H.263+ variables to MpegEncContext to be thread-safe.
pulento
parents:
71
diff
changeset
|
157 |
0 | 158 /* mpeg4 specific */ |
159 int time_increment_bits; | |
64 | 160 int shape; |
161 int vol_sprite_usage; | |
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
248
diff
changeset
|
162 int sprite_width; |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
248
diff
changeset
|
163 int sprite_height; |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
248
diff
changeset
|
164 int sprite_left; |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
248
diff
changeset
|
165 int sprite_top; |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
248
diff
changeset
|
166 int sprite_brightness_change; |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
248
diff
changeset
|
167 int no_sprite_wraping_points; |
64 | 168 int quant_precision; |
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
248
diff
changeset
|
169 int quarter_sample; |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
248
diff
changeset
|
170 int scalability; |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
248
diff
changeset
|
171 int new_pred; |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
248
diff
changeset
|
172 int reduced_res_vop; |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
248
diff
changeset
|
173 int aspect_ratio_info; |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
248
diff
changeset
|
174 int sprite_warping_accuracy; |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
248
diff
changeset
|
175 int low_latency_sprite; |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
248
diff
changeset
|
176 int data_partioning; |
0 | 177 |
178 /* RV10 specific */ | |
179 int rv10_version; /* RV10 version: 0 or 3 */ | |
180 int rv10_first_dc_coded[3]; | |
181 | |
182 /* MJPEG specific */ | |
183 struct MJpegContext *mjpeg_ctx; | |
229 | 184 int mjpeg_vsample[3]; /* vertical sampling factors, default = {2, 1, 1} */ |
185 int mjpeg_hsample[3]; /* horizontal sampling factors, default = {2, 1, 1} */ | |
186 int mjpeg_write_tables; /* do we want to have quantisation- and | |
187 huffmantables in the jpeg file ? */ | |
0 | 188 |
189 /* MSMPEG4 specific */ | |
190 int mv_table_index; | |
191 int rl_table_index; | |
192 int rl_chroma_table_index; | |
193 int dc_table_index; | |
194 int use_skip_mb_code; | |
195 int slice_height; /* in macroblocks */ | |
196 int first_slice_line; | |
208 | 197 int flipflop_rounding; |
198 int bitrate; | |
0 | 199 /* decompression specific */ |
200 GetBitContext gb; | |
201 | |
202 /* MPEG2 specific - I wish I had not to support this mess. */ | |
203 int progressive_sequence; | |
204 int mpeg_f_code[2][2]; | |
205 int picture_structure; | |
206 /* picture type */ | |
207 #define PICT_TOP_FIELD 1 | |
208 #define PICT_BOTTOM_FIELD 2 | |
209 #define PICT_FRAME 3 | |
210 | |
211 int intra_dc_precision; | |
212 int frame_pred_frame_dct; | |
213 int top_field_first; | |
214 int concealment_motion_vectors; | |
215 int q_scale_type; | |
216 int intra_vlc_format; | |
217 int alternate_scan; | |
218 int repeat_first_field; | |
219 int chroma_420_type; | |
220 int progressive_frame; | |
221 int mpeg2; | |
222 int full_pel[2]; | |
223 int interlaced_dct; | |
224 int last_qscale; | |
225 int first_slice; | |
162 | 226 |
227 /* RTP specific */ | |
231 | 228 /* These are explained on avcodec.h */ |
162 | 229 int rtp_mode; |
230 int rtp_payload_size; | |
231 | 231 void (*rtp_callback)(void *data, int size, int packet_number); |
162 | 232 UINT8 *ptr_lastgob; |
233 UINT8 *ptr_last_mb_line; | |
234 UINT32 mb_line_avgsize; | |
235 | |
13
174ef88f619a
use block[] in structure to have it aligned on 8 bytes for mmx optimizations - dct_unquantize is always a function pointer - added specialized dct_unquantize_h263
glantau
parents:
7
diff
changeset
|
236 DCTELEM block[6][64] __align8; |
174ef88f619a
use block[] in structure to have it aligned on 8 bytes for mmx optimizations - dct_unquantize is always a function pointer - added specialized dct_unquantize_h263
glantau
parents:
7
diff
changeset
|
237 void (*dct_unquantize)(struct MpegEncContext *s, |
174ef88f619a
use block[] in structure to have it aligned on 8 bytes for mmx optimizations - dct_unquantize is always a function pointer - added specialized dct_unquantize_h263
glantau
parents:
7
diff
changeset
|
238 DCTELEM *block, int n, int qscale); |
0 | 239 } MpegEncContext; |
240 | |
241 int MPV_common_init(MpegEncContext *s); | |
242 void MPV_common_end(MpegEncContext *s); | |
243 void MPV_decode_mb(MpegEncContext *s, DCTELEM block[6][64]); | |
244 void MPV_frame_start(MpegEncContext *s); | |
245 void MPV_frame_end(MpegEncContext *s); | |
13
174ef88f619a
use block[] in structure to have it aligned on 8 bytes for mmx optimizations - dct_unquantize is always a function pointer - added specialized dct_unquantize_h263
glantau
parents:
7
diff
changeset
|
246 #ifdef HAVE_MMX |
174ef88f619a
use block[] in structure to have it aligned on 8 bytes for mmx optimizations - dct_unquantize is always a function pointer - added specialized dct_unquantize_h263
glantau
parents:
7
diff
changeset
|
247 void MPV_common_init_mmx(MpegEncContext *s); |
174ef88f619a
use block[] in structure to have it aligned on 8 bytes for mmx optimizations - dct_unquantize is always a function pointer - added specialized dct_unquantize_h263
glantau
parents:
7
diff
changeset
|
248 #endif |
0 | 249 |
250 /* motion_est.c */ | |
251 | |
252 int estimate_motion(MpegEncContext *s, | |
253 int mb_x, int mb_y, | |
254 int *mx_ptr, int *my_ptr); | |
255 | |
256 /* mpeg12.c */ | |
41 | 257 extern INT16 default_intra_matrix[64]; |
258 extern INT16 default_non_intra_matrix[64]; | |
0 | 259 |
260 void mpeg1_encode_picture_header(MpegEncContext *s, int picture_number); | |
261 void mpeg1_encode_mb(MpegEncContext *s, | |
262 DCTELEM block[6][64], | |
263 int motion_x, int motion_y); | |
264 | |
265 /* h263enc.c */ | |
266 | |
267 /* run length table */ | |
268 #define MAX_RUN 64 | |
269 #define MAX_LEVEL 64 | |
270 | |
271 typedef struct RLTable { | |
272 int n; /* number of entries of table_vlc minus 1 */ | |
273 int last; /* number of values for last = 0 */ | |
274 const UINT16 (*table_vlc)[2]; | |
275 const INT8 *table_run; | |
276 const INT8 *table_level; | |
277 UINT8 *index_run[2]; /* encoding only */ | |
278 INT8 *max_level[2]; /* encoding & decoding */ | |
279 INT8 *max_run[2]; /* encoding & decoding */ | |
280 VLC vlc; /* decoding only */ | |
281 } RLTable; | |
282 | |
283 void init_rl(RLTable *rl); | |
284 void init_vlc_rl(RLTable *rl); | |
285 | |
243 | 286 static inline int get_rl_index(const RLTable *rl, int last, int run, int level) |
0 | 287 { |
288 int index; | |
289 index = rl->index_run[last][run]; | |
290 if (index >= rl->n) | |
291 return rl->n; | |
292 if (level > rl->max_level[last][run]) | |
293 return rl->n; | |
294 return index + level - 1; | |
295 } | |
296 | |
297 void h263_encode_mb(MpegEncContext *s, | |
298 DCTELEM block[6][64], | |
299 int motion_x, int motion_y); | |
300 void h263_encode_picture_header(MpegEncContext *s, int picture_number); | |
162 | 301 int h263_encode_gob_header(MpegEncContext * s, int mb_line); |
0 | 302 void h263_dc_scale(MpegEncContext *s); |
303 INT16 *h263_pred_motion(MpegEncContext * s, int block, | |
304 int *px, int *py); | |
305 void mpeg4_pred_ac(MpegEncContext * s, INT16 *block, int n, | |
306 int dir); | |
307 void mpeg4_encode_picture_header(MpegEncContext *s, int picture_number); | |
308 void h263_encode_init_vlc(MpegEncContext *s); | |
309 | |
310 void h263_decode_init_vlc(MpegEncContext *s); | |
311 int h263_decode_picture_header(MpegEncContext *s); | |
162 | 312 int h263_decode_gob_header(MpegEncContext *s); |
0 | 313 int mpeg4_decode_picture_header(MpegEncContext * s); |
314 int intel_h263_decode_picture_header(MpegEncContext *s); | |
315 int h263_decode_mb(MpegEncContext *s, | |
316 DCTELEM block[6][64]); | |
317 int h263_get_picture_format(int width, int height); | |
318 | |
319 /* rv10.c */ | |
320 void rv10_encode_picture_header(MpegEncContext *s, int picture_number); | |
321 int rv_decode_dc(MpegEncContext *s, int n); | |
322 | |
323 /* msmpeg4.c */ | |
324 void msmpeg4_encode_picture_header(MpegEncContext * s, int picture_number); | |
208 | 325 void msmpeg4_encode_ext_header(MpegEncContext * s); |
0 | 326 void msmpeg4_encode_mb(MpegEncContext * s, |
327 DCTELEM block[6][64], | |
328 int motion_x, int motion_y); | |
329 void msmpeg4_dc_scale(MpegEncContext * s); | |
330 int msmpeg4_decode_picture_header(MpegEncContext * s); | |
208 | 331 int msmpeg4_decode_ext_header(MpegEncContext * s, int buf_size); |
0 | 332 int msmpeg4_decode_mb(MpegEncContext *s, |
333 DCTELEM block[6][64]); | |
334 int msmpeg4_decode_init_vlc(MpegEncContext *s); | |
335 | |
336 /* mjpegenc.c */ | |
337 | |
338 int mjpeg_init(MpegEncContext *s); | |
339 void mjpeg_close(MpegEncContext *s); | |
340 void mjpeg_encode_mb(MpegEncContext *s, | |
341 DCTELEM block[6][64]); | |
342 void mjpeg_picture_header(MpegEncContext *s); | |
343 void mjpeg_picture_trailer(MpegEncContext *s); |