ffmpeg / libavcodec / mpegvideo.h @ 2f349de2
History | View | Annotate | Download (10.4 KB)
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 |
#define QMAT_SHIFT_MMX 19 |
34 |
#define QMAT_SHIFT 25 |
35 |
|
36 |
typedef struct MpegEncContext { |
37 |
struct AVCodecContext *avctx;
|
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 */ |
47 |
int h263_pred; /* use mpeg4/h263 ac/dc predictions */ |
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 */ |
51 |
int encoding; /* true if we are encoding (vs decoding) */ |
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 */ |
61 |
int gop_picture_number; /* index of the first picture of a GOP */ |
62 |
int mb_width, mb_height;
|
63 |
int linesize; /* line size, in bytes, may be different from width */ |
64 |
UINT8 *new_picture[3]; /* picture to be compressed */ |
65 |
UINT8 *last_picture[3]; /* previous picture */ |
66 |
UINT8 *last_picture_base[3]; /* real start of the picture */ |
67 |
UINT8 *next_picture[3]; /* previous picture (for bidir pred) */ |
68 |
UINT8 *next_picture_base[3]; /* real start of the picture */ |
69 |
UINT8 *aux_picture[3]; /* aux picture (for B frames only) */ |
70 |
UINT8 *aux_picture_base[3]; /* real start of the picture */ |
71 |
UINT8 *current_picture[3]; /* buffer to store the decompressed current picture */ |
72 |
int last_dc[3]; /* last DC values for MPEG1 */ |
73 |
INT16 *dc_val[3]; /* used for mpeg4 DC prediction */ |
74 |
int y_dc_scale, c_dc_scale;
|
75 |
UINT8 *coded_block; /* used for coded block pattern prediction */
|
76 |
INT16 (*ac_val[3])[16]; /* used for for mpeg4 AC prediction */ |
77 |
int ac_pred;
|
78 |
int mb_skiped; /* MUST BE SET only during DECODING */ |
79 |
UINT8 *mbskip_table; /* used to avoid copy if macroblock
|
80 |
skipped (for black regions for example) */
|
81 |
UINT8 *mbintra_table; /* used to kill a few memsets */
|
82 |
|
83 |
int qscale;
|
84 |
int pict_type;
|
85 |
int frame_rate_index;
|
86 |
/* motion compensation */
|
87 |
int unrestricted_mv;
|
88 |
int h263_long_vectors; /* use horrible h263v1 long vector mode */ |
89 |
|
90 |
int f_code; /* resolution */ |
91 |
INT16 (*motion_val)[2]; /* used for MV prediction */ |
92 |
int full_search;
|
93 |
int mv_dir;
|
94 |
#define MV_DIR_BACKWARD 1 |
95 |
#define MV_DIR_FORWARD 2 |
96 |
int mv_type;
|
97 |
#define MV_TYPE_16X16 0 /* 1 vector for the whole mb */ |
98 |
#define MV_TYPE_8X8 1 /* 4 vectors (h263) */ |
99 |
#define MV_TYPE_16X8 2 /* 2 vectors, one per 16x8 block */ |
100 |
#define MV_TYPE_FIELD 3 /* 2 vectors, one per field */ |
101 |
#define MV_TYPE_DMV 4 /* 2 vectors, special mpeg2 Dual Prime Vectors */ |
102 |
/* motion vectors for a macroblock
|
103 |
first coordinate : 0 = forward 1 = backward
|
104 |
second " : depend on type
|
105 |
third " : 0 = x, 1 = y
|
106 |
*/
|
107 |
int mv[2][4][2]; |
108 |
int field_select[2][2]; |
109 |
int last_mv[2][2][2]; |
110 |
|
111 |
int has_b_frames;
|
112 |
int no_rounding; /* apply no rounding to motion estimation (MPEG4) */ |
113 |
|
114 |
/* macroblock layer */
|
115 |
int mb_x, mb_y;
|
116 |
int mb_incr;
|
117 |
int mb_intra;
|
118 |
/* matrix transmitted in the bitstream */
|
119 |
UINT16 intra_matrix[64];
|
120 |
UINT16 chroma_intra_matrix[64];
|
121 |
UINT16 non_intra_matrix[64];
|
122 |
UINT16 chroma_non_intra_matrix[64];
|
123 |
/* precomputed matrix (combine qscale and DCT renorm) */
|
124 |
int q_intra_matrix[64]; |
125 |
int q_non_intra_matrix[64]; |
126 |
/* identical to the above but for MMX & these are not permutated */
|
127 |
UINT16 __align8 q_intra_matrix16[64] ;
|
128 |
UINT16 __align8 q_non_intra_matrix16[64];
|
129 |
int block_last_index[6]; /* last non zero coefficient in block */ |
130 |
|
131 |
void *opaque; /* private data for the user */ |
132 |
|
133 |
/* bit rate control */
|
134 |
int I_frame_bits; /* wanted number of bits per I frame */ |
135 |
int P_frame_bits; /* same for P frame */ |
136 |
INT64 wanted_bits; |
137 |
INT64 total_bits; |
138 |
|
139 |
/* H.263 specific */
|
140 |
int gob_number;
|
141 |
int gob_index;
|
142 |
int first_gob_line;
|
143 |
|
144 |
/* H.263+ specific */
|
145 |
int umvplus;
|
146 |
int umvplus_dec;
|
147 |
|
148 |
/* mpeg4 specific */
|
149 |
int time_increment_bits;
|
150 |
int shape;
|
151 |
int vol_sprite_usage;
|
152 |
int quant_precision;
|
153 |
|
154 |
/* RV10 specific */
|
155 |
int rv10_version; /* RV10 version: 0 or 3 */ |
156 |
int rv10_first_dc_coded[3]; |
157 |
|
158 |
/* MJPEG specific */
|
159 |
struct MJpegContext *mjpeg_ctx;
|
160 |
|
161 |
/* MSMPEG4 specific */
|
162 |
int mv_table_index;
|
163 |
int rl_table_index;
|
164 |
int rl_chroma_table_index;
|
165 |
int dc_table_index;
|
166 |
int use_skip_mb_code;
|
167 |
int slice_height; /* in macroblocks */ |
168 |
int first_slice_line;
|
169 |
int flipflop_rounding;
|
170 |
int bitrate;
|
171 |
/* decompression specific */
|
172 |
GetBitContext gb; |
173 |
|
174 |
/* MPEG2 specific - I wish I had not to support this mess. */
|
175 |
int progressive_sequence;
|
176 |
int mpeg_f_code[2][2]; |
177 |
int picture_structure;
|
178 |
/* picture type */
|
179 |
#define PICT_TOP_FIELD 1 |
180 |
#define PICT_BOTTOM_FIELD 2 |
181 |
#define PICT_FRAME 3 |
182 |
|
183 |
int intra_dc_precision;
|
184 |
int frame_pred_frame_dct;
|
185 |
int top_field_first;
|
186 |
int concealment_motion_vectors;
|
187 |
int q_scale_type;
|
188 |
int intra_vlc_format;
|
189 |
int alternate_scan;
|
190 |
int repeat_first_field;
|
191 |
int chroma_420_type;
|
192 |
int progressive_frame;
|
193 |
int mpeg2;
|
194 |
int full_pel[2]; |
195 |
int interlaced_dct;
|
196 |
int last_qscale;
|
197 |
int first_slice;
|
198 |
|
199 |
/* RTP specific */
|
200 |
int rtp_mode;
|
201 |
int rtp_payload_size;
|
202 |
UINT8 *ptr_lastgob; |
203 |
UINT8 *ptr_last_mb_line; |
204 |
UINT32 mb_line_avgsize; |
205 |
|
206 |
DCTELEM block[6][64] __align8; |
207 |
void (*dct_unquantize)(struct MpegEncContext *s, |
208 |
DCTELEM *block, int n, int qscale); |
209 |
} MpegEncContext; |
210 |
|
211 |
int MPV_common_init(MpegEncContext *s);
|
212 |
void MPV_common_end(MpegEncContext *s);
|
213 |
void MPV_decode_mb(MpegEncContext *s, DCTELEM block[6][64]); |
214 |
void MPV_frame_start(MpegEncContext *s);
|
215 |
void MPV_frame_end(MpegEncContext *s);
|
216 |
#ifdef HAVE_MMX
|
217 |
void MPV_common_init_mmx(MpegEncContext *s);
|
218 |
#endif
|
219 |
|
220 |
/* motion_est.c */
|
221 |
|
222 |
int estimate_motion(MpegEncContext *s,
|
223 |
int mb_x, int mb_y, |
224 |
int *mx_ptr, int *my_ptr); |
225 |
|
226 |
/* mpeg12.c */
|
227 |
extern INT16 default_intra_matrix[64]; |
228 |
extern INT16 default_non_intra_matrix[64]; |
229 |
|
230 |
void mpeg1_encode_picture_header(MpegEncContext *s, int picture_number); |
231 |
void mpeg1_encode_mb(MpegEncContext *s,
|
232 |
DCTELEM block[6][64], |
233 |
int motion_x, int motion_y); |
234 |
|
235 |
/* h263enc.c */
|
236 |
|
237 |
/* run length table */
|
238 |
#define MAX_RUN 64 |
239 |
#define MAX_LEVEL 64 |
240 |
|
241 |
typedef struct RLTable { |
242 |
int n; /* number of entries of table_vlc minus 1 */ |
243 |
int last; /* number of values for last = 0 */ |
244 |
const UINT16 (*table_vlc)[2]; |
245 |
const INT8 *table_run;
|
246 |
const INT8 *table_level;
|
247 |
UINT8 *index_run[2]; /* encoding only */ |
248 |
INT8 *max_level[2]; /* encoding & decoding */ |
249 |
INT8 *max_run[2]; /* encoding & decoding */ |
250 |
VLC vlc; /* decoding only */
|
251 |
} RLTable; |
252 |
|
253 |
void init_rl(RLTable *rl);
|
254 |
void init_vlc_rl(RLTable *rl);
|
255 |
|
256 |
extern inline int get_rl_index(const RLTable *rl, int last, int run, int level) |
257 |
{ |
258 |
int index;
|
259 |
index = rl->index_run[last][run]; |
260 |
if (index >= rl->n)
|
261 |
return rl->n;
|
262 |
if (level > rl->max_level[last][run])
|
263 |
return rl->n;
|
264 |
return index + level - 1; |
265 |
} |
266 |
|
267 |
void h263_encode_mb(MpegEncContext *s,
|
268 |
DCTELEM block[6][64], |
269 |
int motion_x, int motion_y); |
270 |
void h263_encode_picture_header(MpegEncContext *s, int picture_number); |
271 |
int h263_encode_gob_header(MpegEncContext * s, int mb_line); |
272 |
void h263_dc_scale(MpegEncContext *s);
|
273 |
INT16 *h263_pred_motion(MpegEncContext * s, int block,
|
274 |
int *px, int *py); |
275 |
void mpeg4_pred_ac(MpegEncContext * s, INT16 *block, int n, |
276 |
int dir);
|
277 |
void mpeg4_encode_picture_header(MpegEncContext *s, int picture_number); |
278 |
void h263_encode_init_vlc(MpegEncContext *s);
|
279 |
|
280 |
void h263_decode_init_vlc(MpegEncContext *s);
|
281 |
int h263_decode_picture_header(MpegEncContext *s);
|
282 |
int h263_decode_gob_header(MpegEncContext *s);
|
283 |
int mpeg4_decode_picture_header(MpegEncContext * s);
|
284 |
int intel_h263_decode_picture_header(MpegEncContext *s);
|
285 |
int h263_decode_mb(MpegEncContext *s,
|
286 |
DCTELEM block[6][64]); |
287 |
int h263_get_picture_format(int width, int height); |
288 |
|
289 |
/* rv10.c */
|
290 |
void rv10_encode_picture_header(MpegEncContext *s, int picture_number); |
291 |
int rv_decode_dc(MpegEncContext *s, int n); |
292 |
|
293 |
/* msmpeg4.c */
|
294 |
void msmpeg4_encode_picture_header(MpegEncContext * s, int picture_number); |
295 |
void msmpeg4_encode_ext_header(MpegEncContext * s);
|
296 |
void msmpeg4_encode_mb(MpegEncContext * s,
|
297 |
DCTELEM block[6][64], |
298 |
int motion_x, int motion_y); |
299 |
void msmpeg4_dc_scale(MpegEncContext * s);
|
300 |
int msmpeg4_decode_picture_header(MpegEncContext * s);
|
301 |
int msmpeg4_decode_ext_header(MpegEncContext * s, int buf_size); |
302 |
int msmpeg4_decode_mb(MpegEncContext *s,
|
303 |
DCTELEM block[6][64]); |
304 |
int msmpeg4_decode_init_vlc(MpegEncContext *s);
|
305 |
|
306 |
/* mjpegenc.c */
|
307 |
|
308 |
int mjpeg_init(MpegEncContext *s);
|
309 |
void mjpeg_close(MpegEncContext *s);
|
310 |
void mjpeg_encode_mb(MpegEncContext *s,
|
311 |
DCTELEM block[6][64]); |
312 |
void mjpeg_picture_header(MpegEncContext *s);
|
313 |
void mjpeg_picture_trailer(MpegEncContext *s);
|