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