Mercurial > libavcodec.hg
annotate mpegvideo.h @ 59:efd3c19f6d62 libavcodec
fixed mpeg2 non intra dequant - fixed MPEG1 and 2 matrix parsing
| author | glantau |
|---|---|
| date | Sun, 12 Aug 2001 00:52:01 +0000 |
| parents | d99e8a2351f4 |
| children | 5aa6292a1660 |
| 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 | |
| 33 typedef struct MpegEncContext { | |
| 34 /* the following parameters must be initialized before encoding */ | |
| 35 int width, height; /* picture size. must be a multiple of 16 */ | |
| 36 int gop_size; | |
| 37 int frame_rate; /* number of frames per second */ | |
| 38 int intra_only; /* if true, only intra pictures are generated */ | |
| 39 int bit_rate; /* wanted bit rate */ | |
| 40 enum OutputFormat out_format; /* output format */ | |
| 41 int h263_plus; /* h263 plus headers */ | |
| 42 int h263_rv10; /* use RV10 variation for H263 */ | |
| 43 int h263_pred; /* use OpenDIVX (aka mpeg4) ac/dc predictions */ | |
| 44 int h263_msmpeg4; /* generate MSMPEG4 compatible stream */ | |
| 45 int h263_intel; /* use I263 intel h263 header */ | |
| 46 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
|
47 int encoding; /* true if we are encoding (vs decoding) */ |
| 0 | 48 /* the following fields are managed internally by the encoder */ |
| 49 | |
| 50 /* bit output */ | |
| 51 PutBitContext pb; | |
| 52 | |
| 53 /* sequence parameters */ | |
| 54 int context_initialized; | |
| 55 int picture_number; | |
| 56 int fake_picture_number; /* picture number at the bitstream frame rate */ | |
| 57 int gop_picture_number; /* index of the first picture of a GOP */ | |
| 58 int mb_width, mb_height; | |
| 59 int linesize; /* line size, in bytes, may be different from width */ | |
| 60 UINT8 *new_picture[3]; /* picture to be compressed */ | |
| 61 UINT8 *last_picture[3]; /* previous picture */ | |
| 62 UINT8 *last_picture_base[3]; /* real start of the picture */ | |
| 63 UINT8 *next_picture[3]; /* previous picture (for bidir pred) */ | |
| 64 UINT8 *next_picture_base[3]; /* real start of the picture */ | |
| 65 UINT8 *aux_picture[3]; /* aux picture (for B frames only) */ | |
| 66 UINT8 *aux_picture_base[3]; /* real start of the picture */ | |
| 67 UINT8 *current_picture[3]; /* buffer to store the decompressed current picture */ | |
| 68 int last_dc[3]; /* last DC values for MPEG1 */ | |
| 69 INT16 *dc_val[3]; /* used for mpeg4 DC prediction */ | |
| 70 int y_dc_scale, c_dc_scale; | |
| 71 UINT8 *coded_block; /* used for coded block pattern prediction */ | |
| 72 INT16 (*ac_val[3])[16]; /* used for for mpeg4 AC prediction */ | |
| 73 int ac_pred; | |
|
7
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
74 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
|
75 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
|
76 skipped (for black regions for example) */ |
| 0 | 77 |
| 78 int qscale; | |
| 79 int pict_type; | |
| 80 int frame_rate_index; | |
| 81 /* motion compensation */ | |
| 82 int unrestricted_mv; | |
| 83 int h263_long_vectors; /* use horrible h263v1 long vector mode */ | |
| 84 | |
| 85 int f_code; /* resolution */ | |
| 86 INT16 (*motion_val)[2]; /* used for MV prediction */ | |
| 87 int full_search; | |
| 88 int mv_dir; | |
| 89 #define MV_DIR_BACKWARD 1 | |
| 90 #define MV_DIR_FORWARD 2 | |
| 91 int mv_type; | |
| 92 #define MV_TYPE_16X16 0 /* 1 vector for the whole mb */ | |
| 93 #define MV_TYPE_8X8 1 /* 4 vectors (h263) */ | |
| 94 #define MV_TYPE_16X8 2 /* 2 vectors, one per 16x8 block */ | |
| 95 #define MV_TYPE_FIELD 3 /* 2 vectors, one per field */ | |
| 96 #define MV_TYPE_DMV 4 /* 2 vectors, special mpeg2 Dual Prime Vectors */ | |
| 97 /* motion vectors for a macroblock | |
| 98 first coordinate : 0 = forward 1 = backward | |
| 99 second " : depend on type | |
| 100 third " : 0 = x, 1 = y | |
| 101 */ | |
| 102 int mv[2][4][2]; | |
| 103 int field_select[2][2]; | |
| 104 int last_mv[2][2][2]; | |
| 105 | |
| 106 int has_b_frames; | |
| 107 int no_rounding; /* apply no rounding to motion estimation (MPEG4) */ | |
| 108 | |
| 109 /* macroblock layer */ | |
| 110 int mb_x, mb_y; | |
| 111 int mb_incr; | |
| 112 int mb_intra; | |
| 113 /* matrix transmitted in the bitstream */ | |
| 114 UINT16 intra_matrix[64]; | |
| 115 UINT16 chroma_intra_matrix[64]; | |
| 116 UINT16 non_intra_matrix[64]; | |
| 117 UINT16 chroma_non_intra_matrix[64]; | |
| 118 /* precomputed matrix (combine qscale and DCT renorm) */ | |
| 119 int q_intra_matrix[64]; | |
| 120 int q_non_intra_matrix[64]; | |
| 121 int block_last_index[6]; /* last non zero coefficient in block */ | |
| 122 | |
| 123 void *opaque; /* private data for the user */ | |
| 124 | |
| 125 /* bit rate control */ | |
| 126 int I_frame_bits; /* wanted number of bits per I frame */ | |
| 127 int P_frame_bits; /* same for P frame */ | |
| 128 long long wanted_bits; | |
| 129 long long total_bits; | |
| 130 | |
| 131 /* mpeg4 specific */ | |
| 132 int time_increment_bits; | |
| 133 | |
| 134 /* RV10 specific */ | |
| 135 int rv10_version; /* RV10 version: 0 or 3 */ | |
| 136 int rv10_first_dc_coded[3]; | |
| 137 | |
| 138 /* MJPEG specific */ | |
| 139 struct MJpegContext *mjpeg_ctx; | |
| 140 | |
| 141 /* MSMPEG4 specific */ | |
| 142 int mv_table_index; | |
| 143 int rl_table_index; | |
| 144 int rl_chroma_table_index; | |
| 145 int dc_table_index; | |
| 146 int use_skip_mb_code; | |
| 147 int slice_height; /* in macroblocks */ | |
| 148 int first_slice_line; | |
| 149 /* decompression specific */ | |
| 150 GetBitContext gb; | |
| 151 | |
| 152 /* MPEG2 specific - I wish I had not to support this mess. */ | |
| 153 int progressive_sequence; | |
| 154 int mpeg_f_code[2][2]; | |
| 155 int picture_structure; | |
| 156 /* picture type */ | |
| 157 #define PICT_TOP_FIELD 1 | |
| 158 #define PICT_BOTTOM_FIELD 2 | |
| 159 #define PICT_FRAME 3 | |
| 160 | |
| 161 int intra_dc_precision; | |
| 162 int frame_pred_frame_dct; | |
| 163 int top_field_first; | |
| 164 int concealment_motion_vectors; | |
| 165 int q_scale_type; | |
| 166 int intra_vlc_format; | |
| 167 int alternate_scan; | |
| 168 int repeat_first_field; | |
| 169 int chroma_420_type; | |
| 170 int progressive_frame; | |
| 171 int mpeg2; | |
| 172 int full_pel[2]; | |
| 173 int interlaced_dct; | |
| 174 int last_qscale; | |
| 175 int first_slice; | |
|
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
|
176 |
|
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
|
177 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
|
178 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
|
179 DCTELEM *block, int n, int qscale); |
| 0 | 180 } MpegEncContext; |
| 181 | |
| 182 int MPV_common_init(MpegEncContext *s); | |
| 183 void MPV_common_end(MpegEncContext *s); | |
| 184 void MPV_decode_mb(MpegEncContext *s, DCTELEM block[6][64]); | |
| 185 void MPV_frame_start(MpegEncContext *s); | |
| 186 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
|
187 #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
|
188 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
|
189 #endif |
| 0 | 190 |
| 191 /* motion_est.c */ | |
| 192 | |
| 193 int estimate_motion(MpegEncContext *s, | |
| 194 int mb_x, int mb_y, | |
| 195 int *mx_ptr, int *my_ptr); | |
| 196 | |
| 197 /* mpeg12.c */ | |
| 41 | 198 extern INT16 default_intra_matrix[64]; |
| 199 extern INT16 default_non_intra_matrix[64]; | |
| 0 | 200 |
| 201 void mpeg1_encode_picture_header(MpegEncContext *s, int picture_number); | |
| 202 void mpeg1_encode_mb(MpegEncContext *s, | |
| 203 DCTELEM block[6][64], | |
| 204 int motion_x, int motion_y); | |
| 205 | |
| 206 /* h263enc.c */ | |
| 207 | |
| 208 /* run length table */ | |
| 209 #define MAX_RUN 64 | |
| 210 #define MAX_LEVEL 64 | |
| 211 | |
| 212 typedef struct RLTable { | |
| 213 int n; /* number of entries of table_vlc minus 1 */ | |
| 214 int last; /* number of values for last = 0 */ | |
| 215 const UINT16 (*table_vlc)[2]; | |
| 216 const INT8 *table_run; | |
| 217 const INT8 *table_level; | |
| 218 UINT8 *index_run[2]; /* encoding only */ | |
| 219 INT8 *max_level[2]; /* encoding & decoding */ | |
| 220 INT8 *max_run[2]; /* encoding & decoding */ | |
| 221 VLC vlc; /* decoding only */ | |
| 222 } RLTable; | |
| 223 | |
| 224 void init_rl(RLTable *rl); | |
| 225 void init_vlc_rl(RLTable *rl); | |
| 226 | |
| 227 extern inline int get_rl_index(const RLTable *rl, int last, int run, int level) | |
| 228 { | |
| 229 int index; | |
| 230 index = rl->index_run[last][run]; | |
| 231 if (index >= rl->n) | |
| 232 return rl->n; | |
| 233 if (level > rl->max_level[last][run]) | |
| 234 return rl->n; | |
| 235 return index + level - 1; | |
| 236 } | |
| 237 | |
| 238 void h263_encode_mb(MpegEncContext *s, | |
| 239 DCTELEM block[6][64], | |
| 240 int motion_x, int motion_y); | |
| 241 void h263_encode_picture_header(MpegEncContext *s, int picture_number); | |
| 242 void h263_dc_scale(MpegEncContext *s); | |
| 243 INT16 *h263_pred_motion(MpegEncContext * s, int block, | |
| 244 int *px, int *py); | |
| 245 void mpeg4_pred_ac(MpegEncContext * s, INT16 *block, int n, | |
| 246 int dir); | |
| 247 void mpeg4_encode_picture_header(MpegEncContext *s, int picture_number); | |
| 248 void h263_encode_init_vlc(MpegEncContext *s); | |
| 249 | |
| 250 void h263_decode_init_vlc(MpegEncContext *s); | |
| 251 int h263_decode_picture_header(MpegEncContext *s); | |
| 252 int mpeg4_decode_picture_header(MpegEncContext * s); | |
| 253 int intel_h263_decode_picture_header(MpegEncContext *s); | |
| 254 int h263_decode_mb(MpegEncContext *s, | |
| 255 DCTELEM block[6][64]); | |
| 256 int h263_get_picture_format(int width, int height); | |
| 257 | |
| 258 /* rv10.c */ | |
| 259 void rv10_encode_picture_header(MpegEncContext *s, int picture_number); | |
| 260 int rv_decode_dc(MpegEncContext *s, int n); | |
| 261 | |
| 262 /* msmpeg4.c */ | |
| 263 void msmpeg4_encode_picture_header(MpegEncContext * s, int picture_number); | |
| 264 void msmpeg4_encode_mb(MpegEncContext * s, | |
| 265 DCTELEM block[6][64], | |
| 266 int motion_x, int motion_y); | |
| 267 void msmpeg4_dc_scale(MpegEncContext * s); | |
| 268 int msmpeg4_decode_picture_header(MpegEncContext * s); | |
| 269 int msmpeg4_decode_mb(MpegEncContext *s, | |
| 270 DCTELEM block[6][64]); | |
| 271 int msmpeg4_decode_init_vlc(MpegEncContext *s); | |
| 272 | |
| 273 /* mjpegenc.c */ | |
| 274 | |
| 275 int mjpeg_init(MpegEncContext *s); | |
| 276 void mjpeg_close(MpegEncContext *s); | |
| 277 void mjpeg_encode_mb(MpegEncContext *s, | |
| 278 DCTELEM block[6][64]); | |
| 279 void mjpeg_picture_header(MpegEncContext *s); | |
| 280 void mjpeg_picture_trailer(MpegEncContext *s); |
