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