yading@10
|
1 /*
|
yading@10
|
2 * Generic DCT based hybrid video encoder
|
yading@10
|
3 * Copyright (c) 2000, 2001, 2002 Fabrice Bellard
|
yading@10
|
4 * Copyright (c) 2002-2004 Michael Niedermayer
|
yading@10
|
5 *
|
yading@10
|
6 * This file is part of FFmpeg.
|
yading@10
|
7 *
|
yading@10
|
8 * FFmpeg is free software; you can redistribute it and/or
|
yading@10
|
9 * modify it under the terms of the GNU Lesser General Public
|
yading@10
|
10 * License as published by the Free Software Foundation; either
|
yading@10
|
11 * version 2.1 of the License, or (at your option) any later version.
|
yading@10
|
12 *
|
yading@10
|
13 * FFmpeg is distributed in the hope that it will be useful,
|
yading@10
|
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
yading@10
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
yading@10
|
16 * Lesser General Public License for more details.
|
yading@10
|
17 *
|
yading@10
|
18 * You should have received a copy of the GNU Lesser General Public
|
yading@10
|
19 * License along with FFmpeg; if not, write to the Free Software
|
yading@10
|
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
yading@10
|
21 */
|
yading@10
|
22
|
yading@10
|
23 /**
|
yading@10
|
24 * @file
|
yading@10
|
25 * mpegvideo header.
|
yading@10
|
26 */
|
yading@10
|
27
|
yading@10
|
28 #ifndef AVCODEC_MPEGVIDEO_H
|
yading@10
|
29 #define AVCODEC_MPEGVIDEO_H
|
yading@10
|
30
|
yading@10
|
31 #include "avcodec.h"
|
yading@10
|
32 #include "dsputil.h"
|
yading@10
|
33 #include "error_resilience.h"
|
yading@10
|
34 #include "get_bits.h"
|
yading@10
|
35 #include "h264chroma.h"
|
yading@10
|
36 #include "hpeldsp.h"
|
yading@10
|
37 #include "put_bits.h"
|
yading@10
|
38 #include "ratecontrol.h"
|
yading@10
|
39 #include "parser.h"
|
yading@10
|
40 #include "mpeg12data.h"
|
yading@10
|
41 #include "rl.h"
|
yading@10
|
42 #include "thread.h"
|
yading@10
|
43 #include "videodsp.h"
|
yading@10
|
44
|
yading@10
|
45 #include "libavutil/opt.h"
|
yading@10
|
46 #include "libavutil/timecode.h"
|
yading@10
|
47
|
yading@10
|
48 #define FRAME_SKIPPED 100 ///< return value for header parsers if frame is not coded
|
yading@10
|
49
|
yading@10
|
50 enum OutputFormat {
|
yading@10
|
51 FMT_MPEG1,
|
yading@10
|
52 FMT_H261,
|
yading@10
|
53 FMT_H263,
|
yading@10
|
54 FMT_MJPEG,
|
yading@10
|
55 };
|
yading@10
|
56
|
yading@10
|
57 #define MPEG_BUF_SIZE (16 * 1024)
|
yading@10
|
58
|
yading@10
|
59 #define QMAT_SHIFT_MMX 16
|
yading@10
|
60 #define QMAT_SHIFT 21
|
yading@10
|
61
|
yading@10
|
62 #define MAX_FCODE 7
|
yading@10
|
63 #define MAX_MV 4096
|
yading@10
|
64
|
yading@10
|
65 #define MAX_THREADS 32
|
yading@10
|
66 #define MAX_PICTURE_COUNT 36
|
yading@10
|
67
|
yading@10
|
68 #define ME_MAP_SIZE 64
|
yading@10
|
69 #define ME_MAP_SHIFT 3
|
yading@10
|
70 #define ME_MAP_MV_BITS 11
|
yading@10
|
71
|
yading@10
|
72 #define MAX_MB_BYTES (30*16*16*3/8 + 120)
|
yading@10
|
73
|
yading@10
|
74 #define INPLACE_OFFSET 16
|
yading@10
|
75
|
yading@10
|
76 /* Start codes. */
|
yading@10
|
77 #define SEQ_END_CODE 0x000001b7
|
yading@10
|
78 #define SEQ_START_CODE 0x000001b3
|
yading@10
|
79 #define GOP_START_CODE 0x000001b8
|
yading@10
|
80 #define PICTURE_START_CODE 0x00000100
|
yading@10
|
81 #define SLICE_MIN_START_CODE 0x00000101
|
yading@10
|
82 #define SLICE_MAX_START_CODE 0x000001af
|
yading@10
|
83 #define EXT_START_CODE 0x000001b5
|
yading@10
|
84 #define USER_START_CODE 0x000001b2
|
yading@10
|
85
|
yading@10
|
86 /**
|
yading@10
|
87 * Value of Picture.reference when Picture is not a reference picture, but
|
yading@10
|
88 * is held for delayed output.
|
yading@10
|
89 */
|
yading@10
|
90 #define DELAYED_PIC_REF 4
|
yading@10
|
91
|
yading@10
|
92 struct MpegEncContext;
|
yading@10
|
93
|
yading@10
|
94 /**
|
yading@10
|
95 * Picture.
|
yading@10
|
96 */
|
yading@10
|
97 typedef struct Picture{
|
yading@10
|
98 struct AVFrame f;
|
yading@10
|
99 ThreadFrame tf;
|
yading@10
|
100
|
yading@10
|
101 AVBufferRef *qscale_table_buf;
|
yading@10
|
102 int8_t *qscale_table;
|
yading@10
|
103
|
yading@10
|
104 AVBufferRef *motion_val_buf[2];
|
yading@10
|
105 int16_t (*motion_val[2])[2];
|
yading@10
|
106
|
yading@10
|
107 AVBufferRef *mb_type_buf;
|
yading@10
|
108 uint32_t *mb_type;
|
yading@10
|
109
|
yading@10
|
110 AVBufferRef *mbskip_table_buf;
|
yading@10
|
111 uint8_t *mbskip_table;
|
yading@10
|
112
|
yading@10
|
113 AVBufferRef *ref_index_buf[2];
|
yading@10
|
114 int8_t *ref_index[2];
|
yading@10
|
115
|
yading@10
|
116 AVBufferRef *mb_var_buf;
|
yading@10
|
117 uint16_t *mb_var; ///< Table for MB variances
|
yading@10
|
118
|
yading@10
|
119 AVBufferRef *mc_mb_var_buf;
|
yading@10
|
120 uint16_t *mc_mb_var; ///< Table for motion compensated MB variances
|
yading@10
|
121
|
yading@10
|
122 int alloc_mb_width; ///< mb_width used to allocate tables
|
yading@10
|
123 int alloc_mb_height; ///< mb_height used to allocate tables
|
yading@10
|
124
|
yading@10
|
125 AVBufferRef *mb_mean_buf;
|
yading@10
|
126 uint8_t *mb_mean; ///< Table for MB luminance
|
yading@10
|
127
|
yading@10
|
128 AVBufferRef *hwaccel_priv_buf;
|
yading@10
|
129 /**
|
yading@10
|
130 * hardware accelerator private data
|
yading@10
|
131 */
|
yading@10
|
132 void *hwaccel_picture_private;
|
yading@10
|
133
|
yading@10
|
134 #define MB_TYPE_INTRA MB_TYPE_INTRA4x4 //default mb_type if there is just one type
|
yading@10
|
135 #define IS_INTRA4x4(a) ((a)&MB_TYPE_INTRA4x4)
|
yading@10
|
136 #define IS_INTRA16x16(a) ((a)&MB_TYPE_INTRA16x16)
|
yading@10
|
137 #define IS_PCM(a) ((a)&MB_TYPE_INTRA_PCM)
|
yading@10
|
138 #define IS_INTRA(a) ((a)&7)
|
yading@10
|
139 #define IS_INTER(a) ((a)&(MB_TYPE_16x16|MB_TYPE_16x8|MB_TYPE_8x16|MB_TYPE_8x8))
|
yading@10
|
140 #define IS_SKIP(a) ((a)&MB_TYPE_SKIP)
|
yading@10
|
141 #define IS_INTRA_PCM(a) ((a)&MB_TYPE_INTRA_PCM)
|
yading@10
|
142 #define IS_INTERLACED(a) ((a)&MB_TYPE_INTERLACED)
|
yading@10
|
143 #define IS_DIRECT(a) ((a)&MB_TYPE_DIRECT2)
|
yading@10
|
144 #define IS_GMC(a) ((a)&MB_TYPE_GMC)
|
yading@10
|
145 #define IS_16X16(a) ((a)&MB_TYPE_16x16)
|
yading@10
|
146 #define IS_16X8(a) ((a)&MB_TYPE_16x8)
|
yading@10
|
147 #define IS_8X16(a) ((a)&MB_TYPE_8x16)
|
yading@10
|
148 #define IS_8X8(a) ((a)&MB_TYPE_8x8)
|
yading@10
|
149 #define IS_SUB_8X8(a) ((a)&MB_TYPE_16x16) //note reused
|
yading@10
|
150 #define IS_SUB_8X4(a) ((a)&MB_TYPE_16x8) //note reused
|
yading@10
|
151 #define IS_SUB_4X8(a) ((a)&MB_TYPE_8x16) //note reused
|
yading@10
|
152 #define IS_SUB_4X4(a) ((a)&MB_TYPE_8x8) //note reused
|
yading@10
|
153 #define IS_ACPRED(a) ((a)&MB_TYPE_ACPRED)
|
yading@10
|
154 #define IS_QUANT(a) ((a)&MB_TYPE_QUANT)
|
yading@10
|
155 #define IS_DIR(a, part, list) ((a) & (MB_TYPE_P0L0<<((part)+2*(list))))
|
yading@10
|
156 #define USES_LIST(a, list) ((a) & ((MB_TYPE_P0L0|MB_TYPE_P1L0)<<(2*(list)))) ///< does this mb use listX, note does not work if subMBs
|
yading@10
|
157 #define HAS_CBP(a) ((a)&MB_TYPE_CBP)
|
yading@10
|
158
|
yading@10
|
159 int field_poc[2]; ///< h264 top/bottom POC
|
yading@10
|
160 int poc; ///< h264 frame POC
|
yading@10
|
161 int frame_num; ///< h264 frame_num (raw frame_num from slice header)
|
yading@10
|
162 int mmco_reset; ///< h264 MMCO_RESET set this 1. Reordering code must not mix pictures before and after MMCO_RESET.
|
yading@10
|
163 int pic_id; /**< h264 pic_num (short -> no wrap version of pic_num,
|
yading@10
|
164 pic_num & max_pic_num; long -> long_pic_num) */
|
yading@10
|
165 int long_ref; ///< 1->long term reference 0->short term reference
|
yading@10
|
166 int ref_poc[2][2][32]; ///< h264 POCs of the frames/fields used as reference (FIXME need per slice)
|
yading@10
|
167 int ref_count[2][2]; ///< number of entries in ref_poc (FIXME need per slice)
|
yading@10
|
168 int mbaff; ///< h264 1 -> MBAFF frame 0-> not MBAFF
|
yading@10
|
169 int field_picture; ///< whether or not the picture was encoded in separate fields
|
yading@10
|
170 int sync; ///< has been decoded after a keyframe
|
yading@10
|
171
|
yading@10
|
172 int mb_var_sum; ///< sum of MB variance for current frame
|
yading@10
|
173 int mc_mb_var_sum; ///< motion compensated MB variance for current frame
|
yading@10
|
174
|
yading@10
|
175 int b_frame_score; /* */
|
yading@10
|
176 int needs_realloc; ///< Picture needs to be reallocated (eg due to a frame size change)
|
yading@10
|
177
|
yading@10
|
178 int reference;
|
yading@10
|
179 int shared;
|
yading@10
|
180 } Picture;
|
yading@10
|
181
|
yading@10
|
182 /**
|
yading@10
|
183 * Motion estimation context.
|
yading@10
|
184 */
|
yading@10
|
185 typedef struct MotionEstContext{
|
yading@10
|
186 AVCodecContext *avctx;
|
yading@10
|
187 int skip; ///< set if ME is skipped for the current MB
|
yading@10
|
188 int co_located_mv[4][2]; ///< mv from last P-frame for direct mode ME
|
yading@10
|
189 int direct_basis_mv[4][2];
|
yading@10
|
190 uint8_t *scratchpad; ///< data area for the ME algo, so that the ME does not need to malloc/free
|
yading@10
|
191 uint8_t *best_mb;
|
yading@10
|
192 uint8_t *temp_mb[2];
|
yading@10
|
193 uint8_t *temp;
|
yading@10
|
194 int best_bits;
|
yading@10
|
195 uint32_t *map; ///< map to avoid duplicate evaluations
|
yading@10
|
196 uint32_t *score_map; ///< map to store the scores
|
yading@10
|
197 unsigned map_generation;
|
yading@10
|
198 int pre_penalty_factor;
|
yading@10
|
199 int penalty_factor; /**< an estimate of the bits required to
|
yading@10
|
200 code a given mv value, e.g. (1,0) takes
|
yading@10
|
201 more bits than (0,0). We have to
|
yading@10
|
202 estimate whether any reduction in
|
yading@10
|
203 residual is worth the extra bits. */
|
yading@10
|
204 int sub_penalty_factor;
|
yading@10
|
205 int mb_penalty_factor;
|
yading@10
|
206 int flags;
|
yading@10
|
207 int sub_flags;
|
yading@10
|
208 int mb_flags;
|
yading@10
|
209 int pre_pass; ///< = 1 for the pre pass
|
yading@10
|
210 int dia_size;
|
yading@10
|
211 int xmin;
|
yading@10
|
212 int xmax;
|
yading@10
|
213 int ymin;
|
yading@10
|
214 int ymax;
|
yading@10
|
215 int pred_x;
|
yading@10
|
216 int pred_y;
|
yading@10
|
217 uint8_t *src[4][4];
|
yading@10
|
218 uint8_t *ref[4][4];
|
yading@10
|
219 int stride;
|
yading@10
|
220 int uvstride;
|
yading@10
|
221 /* temp variables for picture complexity calculation */
|
yading@10
|
222 int mc_mb_var_sum_temp;
|
yading@10
|
223 int mb_var_sum_temp;
|
yading@10
|
224 int scene_change_score;
|
yading@10
|
225 /* cmp, chroma_cmp;*/
|
yading@10
|
226 op_pixels_func (*hpel_put)[4];
|
yading@10
|
227 op_pixels_func (*hpel_avg)[4];
|
yading@10
|
228 qpel_mc_func (*qpel_put)[16];
|
yading@10
|
229 qpel_mc_func (*qpel_avg)[16];
|
yading@10
|
230 uint8_t (*mv_penalty)[MAX_MV*2+1]; ///< amount of bits needed to encode a MV
|
yading@10
|
231 uint8_t *current_mv_penalty;
|
yading@10
|
232 int (*sub_motion_search)(struct MpegEncContext * s,
|
yading@10
|
233 int *mx_ptr, int *my_ptr, int dmin,
|
yading@10
|
234 int src_index, int ref_index,
|
yading@10
|
235 int size, int h);
|
yading@10
|
236 }MotionEstContext;
|
yading@10
|
237
|
yading@10
|
238 /**
|
yading@10
|
239 * MpegEncContext.
|
yading@10
|
240 */
|
yading@10
|
241 typedef struct MpegEncContext {
|
yading@10
|
242 AVClass *class;
|
yading@10
|
243 struct AVCodecContext *avctx;
|
yading@10
|
244 /* the following parameters must be initialized before encoding */
|
yading@10
|
245 int width, height;///< picture size. must be a multiple of 16
|
yading@10
|
246 int gop_size;
|
yading@10
|
247 int intra_only; ///< if true, only intra pictures are generated
|
yading@10
|
248 int bit_rate; ///< wanted bit rate
|
yading@10
|
249 enum OutputFormat out_format; ///< output format
|
yading@10
|
250 int h263_pred; ///< use mpeg4/h263 ac/dc predictions
|
yading@10
|
251 int pb_frame; ///< PB frame mode (0 = none, 1 = base, 2 = improved)
|
yading@10
|
252
|
yading@10
|
253 /* the following codec id fields are deprecated in favor of codec_id */
|
yading@10
|
254 int h263_plus; ///< h263 plus headers
|
yading@10
|
255 int h263_flv; ///< use flv h263 header
|
yading@10
|
256
|
yading@10
|
257 enum AVCodecID codec_id; /* see AV_CODEC_ID_xxx */
|
yading@10
|
258 int fixed_qscale; ///< fixed qscale if non zero
|
yading@10
|
259 int encoding; ///< true if we are encoding (vs decoding)
|
yading@10
|
260 int flags; ///< AVCodecContext.flags (HQ, MV4, ...)
|
yading@10
|
261 int flags2; ///< AVCodecContext.flags2
|
yading@10
|
262 int max_b_frames; ///< max number of b-frames for encoding
|
yading@10
|
263 int luma_elim_threshold;
|
yading@10
|
264 int chroma_elim_threshold;
|
yading@10
|
265 int strict_std_compliance; ///< strictly follow the std (MPEG4, ...)
|
yading@10
|
266 int workaround_bugs; ///< workaround bugs in encoders which cannot be detected automatically
|
yading@10
|
267 int codec_tag; ///< internal codec_tag upper case converted from avctx codec_tag
|
yading@10
|
268 int stream_codec_tag; ///< internal stream_codec_tag upper case converted from avctx stream_codec_tag
|
yading@10
|
269 /* the following fields are managed internally by the encoder */
|
yading@10
|
270
|
yading@10
|
271 /* sequence parameters */
|
yading@10
|
272 int context_initialized;
|
yading@10
|
273 int input_picture_number; ///< used to set pic->display_picture_number, should not be used for/by anything else
|
yading@10
|
274 int coded_picture_number; ///< used to set pic->coded_picture_number, should not be used for/by anything else
|
yading@10
|
275 int picture_number; //FIXME remove, unclear definition
|
yading@10
|
276 int picture_in_gop_number; ///< 0-> first pic in gop, ...
|
yading@10
|
277 int mb_width, mb_height; ///< number of MBs horizontally & vertically
|
yading@10
|
278 int mb_stride; ///< mb_width+1 used for some arrays to allow simple addressing of left & top MBs without sig11
|
yading@10
|
279 int b8_stride; ///< 2*mb_width+1 used for some 8x8 block arrays to allow simple addressing
|
yading@10
|
280 int b4_stride; ///< 4*mb_width+1 used for some 4x4 block arrays to allow simple addressing
|
yading@10
|
281 int h_edge_pos, v_edge_pos;///< horizontal / vertical position of the right/bottom edge (pixel replication)
|
yading@10
|
282 int mb_num; ///< number of MBs of a picture
|
yading@10
|
283 int linesize; ///< line size, in bytes, may be different from width
|
yading@10
|
284 int uvlinesize; ///< line size, for chroma in bytes, may be different from width
|
yading@10
|
285 Picture *picture; ///< main picture buffer
|
yading@10
|
286 Picture **input_picture; ///< next pictures on display order for encoding
|
yading@10
|
287 Picture **reordered_input_picture; ///< pointer to the next pictures in codedorder for encoding
|
yading@10
|
288
|
yading@10
|
289 int y_dc_scale, c_dc_scale;
|
yading@10
|
290 int ac_pred;
|
yading@10
|
291 int block_last_index[12]; ///< last non zero coefficient in block
|
yading@10
|
292 int h263_aic; ///< Advanded INTRA Coding (AIC)
|
yading@10
|
293
|
yading@10
|
294 /* scantables */
|
yading@10
|
295 ScanTable inter_scantable; ///< if inter == intra then intra should be used to reduce tha cache usage
|
yading@10
|
296 ScanTable intra_scantable;
|
yading@10
|
297 ScanTable intra_h_scantable;
|
yading@10
|
298 ScanTable intra_v_scantable;
|
yading@10
|
299
|
yading@10
|
300 /* WARNING: changes above this line require updates to hardcoded
|
yading@10
|
301 * offsets used in asm. */
|
yading@10
|
302
|
yading@10
|
303 int64_t user_specified_pts;///< last non zero pts from AVFrame which was passed into avcodec_encode_video()
|
yading@10
|
304 /**
|
yading@10
|
305 * pts difference between the first and second input frame, used for
|
yading@10
|
306 * calculating dts of the first frame when there's a delay */
|
yading@10
|
307 int64_t dts_delta;
|
yading@10
|
308 /**
|
yading@10
|
309 * reordered pts to be used as dts for the next output frame when there's
|
yading@10
|
310 * a delay */
|
yading@10
|
311 int64_t reordered_pts;
|
yading@10
|
312
|
yading@10
|
313 /** bit output */
|
yading@10
|
314 PutBitContext pb;
|
yading@10
|
315
|
yading@10
|
316 int start_mb_y; ///< start mb_y of this thread (so current thread should process start_mb_y <= row < end_mb_y)
|
yading@10
|
317 int end_mb_y; ///< end mb_y of this thread (so current thread should process start_mb_y <= row < end_mb_y)
|
yading@10
|
318 struct MpegEncContext *thread_context[MAX_THREADS];
|
yading@10
|
319 int slice_context_count; ///< number of used thread_contexts
|
yading@10
|
320
|
yading@10
|
321 /**
|
yading@10
|
322 * copy of the previous picture structure.
|
yading@10
|
323 * note, linesize & data, might not match the previous picture (for field pictures)
|
yading@10
|
324 */
|
yading@10
|
325 Picture last_picture;
|
yading@10
|
326
|
yading@10
|
327 /**
|
yading@10
|
328 * copy of the next picture structure.
|
yading@10
|
329 * note, linesize & data, might not match the next picture (for field pictures)
|
yading@10
|
330 */
|
yading@10
|
331 Picture next_picture;
|
yading@10
|
332
|
yading@10
|
333 /**
|
yading@10
|
334 * copy of the source picture structure for encoding.
|
yading@10
|
335 * note, linesize & data, might not match the source picture (for field pictures)
|
yading@10
|
336 */
|
yading@10
|
337 Picture new_picture;
|
yading@10
|
338
|
yading@10
|
339 /**
|
yading@10
|
340 * copy of the current picture structure.
|
yading@10
|
341 * note, linesize & data, might not match the current picture (for field pictures)
|
yading@10
|
342 */
|
yading@10
|
343 Picture current_picture; ///< buffer to store the decompressed current picture
|
yading@10
|
344
|
yading@10
|
345 Picture *last_picture_ptr; ///< pointer to the previous picture.
|
yading@10
|
346 Picture *next_picture_ptr; ///< pointer to the next picture (for bidir pred)
|
yading@10
|
347 Picture *current_picture_ptr; ///< pointer to the current picture
|
yading@10
|
348 int last_dc[3]; ///< last DC values for MPEG1
|
yading@10
|
349 int16_t *dc_val_base;
|
yading@10
|
350 int16_t *dc_val[3]; ///< used for mpeg4 DC prediction, all 3 arrays must be continuous
|
yading@10
|
351 const uint8_t *y_dc_scale_table; ///< qscale -> y_dc_scale table
|
yading@10
|
352 const uint8_t *c_dc_scale_table; ///< qscale -> c_dc_scale table
|
yading@10
|
353 const uint8_t *chroma_qscale_table; ///< qscale -> chroma_qscale (h263)
|
yading@10
|
354 uint8_t *coded_block_base;
|
yading@10
|
355 uint8_t *coded_block; ///< used for coded block pattern prediction (msmpeg4v3, wmv1)
|
yading@10
|
356 int16_t (*ac_val_base)[16];
|
yading@10
|
357 int16_t (*ac_val[3])[16]; ///< used for for mpeg4 AC prediction, all 3 arrays must be continuous
|
yading@10
|
358 int mb_skipped; ///< MUST BE SET only during DECODING
|
yading@10
|
359 uint8_t *mbskip_table; /**< used to avoid copy if macroblock skipped (for black regions for example)
|
yading@10
|
360 and used for b-frame encoding & decoding (contains skip table of next P Frame) */
|
yading@10
|
361 uint8_t *mbintra_table; ///< used to avoid setting {ac, dc, cbp}-pred stuff to zero on inter MB decoding
|
yading@10
|
362 uint8_t *cbp_table; ///< used to store cbp, ac_pred for partitioned decoding
|
yading@10
|
363 uint8_t *pred_dir_table; ///< used to store pred_dir for partitioned decoding
|
yading@10
|
364 uint8_t *edge_emu_buffer; ///< temporary buffer for if MVs point to out-of-frame data
|
yading@10
|
365 uint8_t *rd_scratchpad; ///< scratchpad for rate distortion mb decision
|
yading@10
|
366 uint8_t *obmc_scratchpad;
|
yading@10
|
367 uint8_t *b_scratchpad; ///< scratchpad used for writing into write only buffers
|
yading@10
|
368
|
yading@10
|
369 int qscale; ///< QP
|
yading@10
|
370 int chroma_qscale; ///< chroma QP
|
yading@10
|
371 unsigned int lambda; ///< lagrange multipler used in rate distortion
|
yading@10
|
372 unsigned int lambda2; ///< (lambda*lambda) >> FF_LAMBDA_SHIFT
|
yading@10
|
373 int *lambda_table;
|
yading@10
|
374 int adaptive_quant; ///< use adaptive quantization
|
yading@10
|
375 int dquant; ///< qscale difference to prev qscale
|
yading@10
|
376 int closed_gop; ///< MPEG1/2 GOP is closed
|
yading@10
|
377 int pict_type; ///< AV_PICTURE_TYPE_I, AV_PICTURE_TYPE_P, AV_PICTURE_TYPE_B, ...
|
yading@10
|
378 int vbv_delay;
|
yading@10
|
379 int last_pict_type; //FIXME removes
|
yading@10
|
380 int last_non_b_pict_type; ///< used for mpeg4 gmc b-frames & ratecontrol
|
yading@10
|
381 int droppable;
|
yading@10
|
382 int frame_rate_index;
|
yading@10
|
383 AVRational mpeg2_frame_rate_ext;
|
yading@10
|
384 int last_lambda_for[5]; ///< last lambda for a specific pict type
|
yading@10
|
385 int skipdct; ///< skip dct and code zero residual
|
yading@10
|
386
|
yading@10
|
387 /* motion compensation */
|
yading@10
|
388 int unrestricted_mv; ///< mv can point outside of the coded picture
|
yading@10
|
389 int h263_long_vectors; ///< use horrible h263v1 long vector mode
|
yading@10
|
390
|
yading@10
|
391 DSPContext dsp; ///< pointers for accelerated dsp functions
|
yading@10
|
392 H264ChromaContext h264chroma;
|
yading@10
|
393 HpelDSPContext hdsp;
|
yading@10
|
394 VideoDSPContext vdsp;
|
yading@10
|
395 int f_code; ///< forward MV resolution
|
yading@10
|
396 int b_code; ///< backward MV resolution for B Frames (mpeg4)
|
yading@10
|
397 int16_t (*p_mv_table_base)[2];
|
yading@10
|
398 int16_t (*b_forw_mv_table_base)[2];
|
yading@10
|
399 int16_t (*b_back_mv_table_base)[2];
|
yading@10
|
400 int16_t (*b_bidir_forw_mv_table_base)[2];
|
yading@10
|
401 int16_t (*b_bidir_back_mv_table_base)[2];
|
yading@10
|
402 int16_t (*b_direct_mv_table_base)[2];
|
yading@10
|
403 int16_t (*p_field_mv_table_base[2][2])[2];
|
yading@10
|
404 int16_t (*b_field_mv_table_base[2][2][2])[2];
|
yading@10
|
405 int16_t (*p_mv_table)[2]; ///< MV table (1MV per MB) p-frame encoding
|
yading@10
|
406 int16_t (*b_forw_mv_table)[2]; ///< MV table (1MV per MB) forward mode b-frame encoding
|
yading@10
|
407 int16_t (*b_back_mv_table)[2]; ///< MV table (1MV per MB) backward mode b-frame encoding
|
yading@10
|
408 int16_t (*b_bidir_forw_mv_table)[2]; ///< MV table (1MV per MB) bidir mode b-frame encoding
|
yading@10
|
409 int16_t (*b_bidir_back_mv_table)[2]; ///< MV table (1MV per MB) bidir mode b-frame encoding
|
yading@10
|
410 int16_t (*b_direct_mv_table)[2]; ///< MV table (1MV per MB) direct mode b-frame encoding
|
yading@10
|
411 int16_t (*p_field_mv_table[2][2])[2]; ///< MV table (2MV per MB) interlaced p-frame encoding
|
yading@10
|
412 int16_t (*b_field_mv_table[2][2][2])[2];///< MV table (4MV per MB) interlaced b-frame encoding
|
yading@10
|
413 uint8_t (*p_field_select_table[2]);
|
yading@10
|
414 uint8_t (*b_field_select_table[2][2]);
|
yading@10
|
415 int me_method; ///< ME algorithm
|
yading@10
|
416 int mv_dir;
|
yading@10
|
417 #define MV_DIR_FORWARD 1
|
yading@10
|
418 #define MV_DIR_BACKWARD 2
|
yading@10
|
419 #define MV_DIRECT 4 ///< bidirectional mode where the difference equals the MV of the last P/S/I-Frame (mpeg4)
|
yading@10
|
420 int mv_type;
|
yading@10
|
421 #define MV_TYPE_16X16 0 ///< 1 vector for the whole mb
|
yading@10
|
422 #define MV_TYPE_8X8 1 ///< 4 vectors (h263, mpeg4 4MV)
|
yading@10
|
423 #define MV_TYPE_16X8 2 ///< 2 vectors, one per 16x8 block
|
yading@10
|
424 #define MV_TYPE_FIELD 3 ///< 2 vectors, one per field
|
yading@10
|
425 #define MV_TYPE_DMV 4 ///< 2 vectors, special mpeg2 Dual Prime Vectors
|
yading@10
|
426 /**motion vectors for a macroblock
|
yading@10
|
427 first coordinate : 0 = forward 1 = backward
|
yading@10
|
428 second " : depend on type
|
yading@10
|
429 third " : 0 = x, 1 = y
|
yading@10
|
430 */
|
yading@10
|
431 int mv[2][4][2];
|
yading@10
|
432 int field_select[2][2];
|
yading@10
|
433 int last_mv[2][2][2]; ///< last MV, used for MV prediction in MPEG1 & B-frame MPEG4
|
yading@10
|
434 uint8_t *fcode_tab; ///< smallest fcode needed for each MV
|
yading@10
|
435 int16_t direct_scale_mv[2][64]; ///< precomputed to avoid divisions in ff_mpeg4_set_direct_mv
|
yading@10
|
436
|
yading@10
|
437 MotionEstContext me;
|
yading@10
|
438
|
yading@10
|
439 int no_rounding; /**< apply no rounding to motion compensation (MPEG4, msmpeg4, ...)
|
yading@10
|
440 for b-frames rounding mode is always 0 */
|
yading@10
|
441
|
yading@10
|
442 /* macroblock layer */
|
yading@10
|
443 int mb_x, mb_y;
|
yading@10
|
444 int mb_skip_run;
|
yading@10
|
445 int mb_intra;
|
yading@10
|
446 uint16_t *mb_type; ///< Table for candidate MB types for encoding
|
yading@10
|
447 #define CANDIDATE_MB_TYPE_INTRA 0x01
|
yading@10
|
448 #define CANDIDATE_MB_TYPE_INTER 0x02
|
yading@10
|
449 #define CANDIDATE_MB_TYPE_INTER4V 0x04
|
yading@10
|
450 #define CANDIDATE_MB_TYPE_SKIPPED 0x08
|
yading@10
|
451 //#define MB_TYPE_GMC 0x10
|
yading@10
|
452
|
yading@10
|
453 #define CANDIDATE_MB_TYPE_DIRECT 0x10
|
yading@10
|
454 #define CANDIDATE_MB_TYPE_FORWARD 0x20
|
yading@10
|
455 #define CANDIDATE_MB_TYPE_BACKWARD 0x40
|
yading@10
|
456 #define CANDIDATE_MB_TYPE_BIDIR 0x80
|
yading@10
|
457
|
yading@10
|
458 #define CANDIDATE_MB_TYPE_INTER_I 0x100
|
yading@10
|
459 #define CANDIDATE_MB_TYPE_FORWARD_I 0x200
|
yading@10
|
460 #define CANDIDATE_MB_TYPE_BACKWARD_I 0x400
|
yading@10
|
461 #define CANDIDATE_MB_TYPE_BIDIR_I 0x800
|
yading@10
|
462
|
yading@10
|
463 #define CANDIDATE_MB_TYPE_DIRECT0 0x1000
|
yading@10
|
464
|
yading@10
|
465 int block_index[6]; ///< index to current MB in block based arrays with edges
|
yading@10
|
466 int block_wrap[6];
|
yading@10
|
467 uint8_t *dest[3];
|
yading@10
|
468
|
yading@10
|
469 int *mb_index2xy; ///< mb_index -> mb_x + mb_y*mb_stride
|
yading@10
|
470
|
yading@10
|
471 /** matrix transmitted in the bitstream */
|
yading@10
|
472 uint16_t intra_matrix[64];
|
yading@10
|
473 uint16_t chroma_intra_matrix[64];
|
yading@10
|
474 uint16_t inter_matrix[64];
|
yading@10
|
475 uint16_t chroma_inter_matrix[64];
|
yading@10
|
476 #define QUANT_BIAS_SHIFT 8
|
yading@10
|
477 int intra_quant_bias; ///< bias for the quantizer
|
yading@10
|
478 int inter_quant_bias; ///< bias for the quantizer
|
yading@10
|
479 int min_qcoeff; ///< minimum encodable coefficient
|
yading@10
|
480 int max_qcoeff; ///< maximum encodable coefficient
|
yading@10
|
481 int ac_esc_length; ///< num of bits needed to encode the longest esc
|
yading@10
|
482 uint8_t *intra_ac_vlc_length;
|
yading@10
|
483 uint8_t *intra_ac_vlc_last_length;
|
yading@10
|
484 uint8_t *inter_ac_vlc_length;
|
yading@10
|
485 uint8_t *inter_ac_vlc_last_length;
|
yading@10
|
486 uint8_t *luma_dc_vlc_length;
|
yading@10
|
487 #define UNI_AC_ENC_INDEX(run,level) ((run)*128 + (level))
|
yading@10
|
488
|
yading@10
|
489 int coded_score[12];
|
yading@10
|
490
|
yading@10
|
491 /** precomputed matrix (combine qscale and DCT renorm) */
|
yading@10
|
492 int (*q_intra_matrix)[64];
|
yading@10
|
493 int (*q_chroma_intra_matrix)[64];
|
yading@10
|
494 int (*q_inter_matrix)[64];
|
yading@10
|
495 /** identical to the above but for MMX & these are not permutated, second 64 entries are bias*/
|
yading@10
|
496 uint16_t (*q_intra_matrix16)[2][64];
|
yading@10
|
497 uint16_t (*q_chroma_intra_matrix16)[2][64];
|
yading@10
|
498 uint16_t (*q_inter_matrix16)[2][64];
|
yading@10
|
499
|
yading@10
|
500 /* noise reduction */
|
yading@10
|
501 int (*dct_error_sum)[64];
|
yading@10
|
502 int dct_count[2];
|
yading@10
|
503 uint16_t (*dct_offset)[64];
|
yading@10
|
504
|
yading@10
|
505 void *opaque; ///< private data for the user
|
yading@10
|
506
|
yading@10
|
507 /* bit rate control */
|
yading@10
|
508 int64_t total_bits;
|
yading@10
|
509 int frame_bits; ///< bits used for the current frame
|
yading@10
|
510 int stuffing_bits; ///< bits used for stuffing
|
yading@10
|
511 int next_lambda; ///< next lambda used for retrying to encode a frame
|
yading@10
|
512 RateControlContext rc_context; ///< contains stuff only accessed in ratecontrol.c
|
yading@10
|
513
|
yading@10
|
514 /* statistics, used for 2-pass encoding */
|
yading@10
|
515 int mv_bits;
|
yading@10
|
516 int header_bits;
|
yading@10
|
517 int i_tex_bits;
|
yading@10
|
518 int p_tex_bits;
|
yading@10
|
519 int i_count;
|
yading@10
|
520 int f_count;
|
yading@10
|
521 int b_count;
|
yading@10
|
522 int skip_count;
|
yading@10
|
523 int misc_bits; ///< cbp, mb_type
|
yading@10
|
524 int last_bits; ///< temp var used for calculating the above vars
|
yading@10
|
525
|
yading@10
|
526 /* error concealment / resync */
|
yading@10
|
527 int resync_mb_x; ///< x position of last resync marker
|
yading@10
|
528 int resync_mb_y; ///< y position of last resync marker
|
yading@10
|
529 GetBitContext last_resync_gb; ///< used to search for the next resync marker
|
yading@10
|
530 int mb_num_left; ///< number of MBs left in this video packet (for partitioned Slices only)
|
yading@10
|
531 int next_p_frame_damaged; ///< set if the next p frame is damaged, to avoid showing trashed b frames
|
yading@10
|
532 int err_recognition;
|
yading@10
|
533
|
yading@10
|
534 ParseContext parse_context;
|
yading@10
|
535
|
yading@10
|
536 /* H.263 specific */
|
yading@10
|
537 int gob_index;
|
yading@10
|
538 int obmc; ///< overlapped block motion compensation
|
yading@10
|
539 int showed_packed_warning; ///< flag for having shown the warning about divxs invalid b frames
|
yading@10
|
540 int mb_info; ///< interval for outputting info about mb offsets as side data
|
yading@10
|
541 int prev_mb_info, last_mb_info;
|
yading@10
|
542 uint8_t *mb_info_ptr;
|
yading@10
|
543 int mb_info_size;
|
yading@10
|
544
|
yading@10
|
545 /* H.263+ specific */
|
yading@10
|
546 int umvplus; ///< == H263+ && unrestricted_mv
|
yading@10
|
547 int h263_aic_dir; ///< AIC direction: 0 = left, 1 = top
|
yading@10
|
548 int h263_slice_structured;
|
yading@10
|
549 int alt_inter_vlc; ///< alternative inter vlc
|
yading@10
|
550 int modified_quant;
|
yading@10
|
551 int loop_filter;
|
yading@10
|
552 int custom_pcf;
|
yading@10
|
553
|
yading@10
|
554 /* mpeg4 specific */
|
yading@10
|
555 int time_increment_bits; ///< number of bits to represent the fractional part of time
|
yading@10
|
556 int last_time_base;
|
yading@10
|
557 int time_base; ///< time in seconds of last I,P,S Frame
|
yading@10
|
558 int64_t time; ///< time of current frame
|
yading@10
|
559 int64_t last_non_b_time;
|
yading@10
|
560 uint16_t pp_time; ///< time distance between the last 2 p,s,i frames
|
yading@10
|
561 uint16_t pb_time; ///< time distance between the last b and p,s,i frame
|
yading@10
|
562 uint16_t pp_field_time;
|
yading@10
|
563 uint16_t pb_field_time; ///< like above, just for interlaced
|
yading@10
|
564 int shape;
|
yading@10
|
565 int vol_sprite_usage;
|
yading@10
|
566 int sprite_width;
|
yading@10
|
567 int sprite_height;
|
yading@10
|
568 int sprite_left;
|
yading@10
|
569 int sprite_top;
|
yading@10
|
570 int sprite_brightness_change;
|
yading@10
|
571 int num_sprite_warping_points;
|
yading@10
|
572 int real_sprite_warping_points;
|
yading@10
|
573 uint16_t sprite_traj[4][2]; ///< sprite trajectory points
|
yading@10
|
574 int sprite_offset[2][2]; ///< sprite offset[isChroma][isMVY]
|
yading@10
|
575 int sprite_delta[2][2]; ///< sprite_delta [isY][isMVY]
|
yading@10
|
576 int sprite_shift[2]; ///< sprite shift [isChroma]
|
yading@10
|
577 int mcsel;
|
yading@10
|
578 int quant_precision;
|
yading@10
|
579 int quarter_sample; ///< 1->qpel, 0->half pel ME/MC
|
yading@10
|
580 int scalability;
|
yading@10
|
581 int hierachy_type;
|
yading@10
|
582 int enhancement_type;
|
yading@10
|
583 int new_pred;
|
yading@10
|
584 int reduced_res_vop;
|
yading@10
|
585 int aspect_ratio_info; //FIXME remove
|
yading@10
|
586 int sprite_warping_accuracy;
|
yading@10
|
587 int low_latency_sprite;
|
yading@10
|
588 int data_partitioning; ///< data partitioning flag from header
|
yading@10
|
589 int partitioned_frame; ///< is current frame partitioned
|
yading@10
|
590 int rvlc; ///< reversible vlc
|
yading@10
|
591 int resync_marker; ///< could this stream contain resync markers
|
yading@10
|
592 int low_delay; ///< no reordering needed / has no b-frames
|
yading@10
|
593 int vo_type;
|
yading@10
|
594 int vol_control_parameters; ///< does the stream contain the low_delay flag, used to workaround buggy encoders
|
yading@10
|
595 int intra_dc_threshold; ///< QP above whch the ac VLC should be used for intra dc
|
yading@10
|
596 int use_intra_dc_vlc;
|
yading@10
|
597 PutBitContext tex_pb; ///< used for data partitioned VOPs
|
yading@10
|
598 PutBitContext pb2; ///< used for data partitioned VOPs
|
yading@10
|
599 int mpeg_quant;
|
yading@10
|
600 int t_frame; ///< time distance of first I -> B, used for interlaced b frames
|
yading@10
|
601 int padding_bug_score; ///< used to detect the VERY common padding bug in MPEG4
|
yading@10
|
602 int cplx_estimation_trash_i;
|
yading@10
|
603 int cplx_estimation_trash_p;
|
yading@10
|
604 int cplx_estimation_trash_b;
|
yading@10
|
605
|
yading@10
|
606 /* divx specific, used to workaround (many) bugs in divx5 */
|
yading@10
|
607 int divx_version;
|
yading@10
|
608 int divx_build;
|
yading@10
|
609 int divx_packed;
|
yading@10
|
610 uint8_t *bitstream_buffer; //Divx 5.01 puts several frames in a single one, this is used to reorder them
|
yading@10
|
611 int bitstream_buffer_size;
|
yading@10
|
612 unsigned int allocated_bitstream_buffer_size;
|
yading@10
|
613
|
yading@10
|
614 int xvid_build;
|
yading@10
|
615
|
yading@10
|
616 /* lavc specific stuff, used to workaround bugs in libavcodec */
|
yading@10
|
617 int lavc_build;
|
yading@10
|
618
|
yading@10
|
619 /* RV10 specific */
|
yading@10
|
620 int rv10_version; ///< RV10 version: 0 or 3
|
yading@10
|
621 int rv10_first_dc_coded[3];
|
yading@10
|
622 int orig_width, orig_height;
|
yading@10
|
623
|
yading@10
|
624 /* MJPEG specific */
|
yading@10
|
625 struct MJpegContext *mjpeg_ctx;
|
yading@10
|
626 int mjpeg_vsample[3]; ///< vertical sampling factors, default = {2, 1, 1}
|
yading@10
|
627 int mjpeg_hsample[3]; ///< horizontal sampling factors, default = {2, 1, 1}
|
yading@10
|
628 int esc_pos;
|
yading@10
|
629
|
yading@10
|
630 /* MSMPEG4 specific */
|
yading@10
|
631 int mv_table_index;
|
yading@10
|
632 int rl_table_index;
|
yading@10
|
633 int rl_chroma_table_index;
|
yading@10
|
634 int dc_table_index;
|
yading@10
|
635 int use_skip_mb_code;
|
yading@10
|
636 int slice_height; ///< in macroblocks
|
yading@10
|
637 int first_slice_line; ///< used in mpeg4 too to handle resync markers
|
yading@10
|
638 int flipflop_rounding;
|
yading@10
|
639 int msmpeg4_version; ///< 0=not msmpeg4, 1=mp41, 2=mp42, 3=mp43/divx3 4=wmv1/7 5=wmv2/8
|
yading@10
|
640 int per_mb_rl_table;
|
yading@10
|
641 int esc3_level_length;
|
yading@10
|
642 int esc3_run_length;
|
yading@10
|
643 /** [mb_intra][isChroma][level][run][last] */
|
yading@10
|
644 int (*ac_stats)[2][MAX_LEVEL+1][MAX_RUN+1][2];
|
yading@10
|
645 int inter_intra_pred;
|
yading@10
|
646 int mspel;
|
yading@10
|
647
|
yading@10
|
648 /* decompression specific */
|
yading@10
|
649 GetBitContext gb;
|
yading@10
|
650
|
yading@10
|
651 /* Mpeg1 specific */
|
yading@10
|
652 int gop_picture_number; ///< index of the first picture of a GOP based on fake_pic_num & mpeg1 specific
|
yading@10
|
653 int last_mv_dir; ///< last mv_dir, used for b frame encoding
|
yading@10
|
654 int broken_link; ///< no_output_of_prior_pics_flag
|
yading@10
|
655 uint8_t *vbv_delay_ptr; ///< pointer to vbv_delay in the bitstream
|
yading@10
|
656
|
yading@10
|
657 /* MPEG-2-specific - I wished not to have to support this mess. */
|
yading@10
|
658 int progressive_sequence;
|
yading@10
|
659 int mpeg_f_code[2][2];
|
yading@10
|
660 int picture_structure;
|
yading@10
|
661 /* picture type */
|
yading@10
|
662 #define PICT_TOP_FIELD 1
|
yading@10
|
663 #define PICT_BOTTOM_FIELD 2
|
yading@10
|
664 #define PICT_FRAME 3
|
yading@10
|
665
|
yading@10
|
666 int intra_dc_precision;
|
yading@10
|
667 int frame_pred_frame_dct;
|
yading@10
|
668 int top_field_first;
|
yading@10
|
669 int concealment_motion_vectors;
|
yading@10
|
670 int q_scale_type;
|
yading@10
|
671 int intra_vlc_format;
|
yading@10
|
672 int alternate_scan;
|
yading@10
|
673 int repeat_first_field;
|
yading@10
|
674 int chroma_420_type;
|
yading@10
|
675 int chroma_format;
|
yading@10
|
676 #define CHROMA_420 1
|
yading@10
|
677 #define CHROMA_422 2
|
yading@10
|
678 #define CHROMA_444 3
|
yading@10
|
679 int chroma_x_shift;//depend on pix_format, that depend on chroma_format
|
yading@10
|
680 int chroma_y_shift;
|
yading@10
|
681
|
yading@10
|
682 int progressive_frame;
|
yading@10
|
683 int full_pel[2];
|
yading@10
|
684 int interlaced_dct;
|
yading@10
|
685 int first_slice;
|
yading@10
|
686 int first_field; ///< is 1 for the first field of a field picture 0 otherwise
|
yading@10
|
687 int drop_frame_timecode; ///< timecode is in drop frame format.
|
yading@10
|
688 int scan_offset; ///< reserve space for SVCD scan offset user data.
|
yading@10
|
689
|
yading@10
|
690 /* RTP specific */
|
yading@10
|
691 int rtp_mode;
|
yading@10
|
692
|
yading@10
|
693 char *tc_opt_str; ///< timecode option string
|
yading@10
|
694 AVTimecode tc; ///< timecode context
|
yading@10
|
695
|
yading@10
|
696 uint8_t *ptr_lastgob;
|
yading@10
|
697 int swap_uv; //vcr2 codec is an MPEG-2 variant with U and V swapped
|
yading@10
|
698 int16_t (*pblocks[12])[64];
|
yading@10
|
699
|
yading@10
|
700 int16_t (*block)[64]; ///< points to one of the following blocks
|
yading@10
|
701 int16_t (*blocks)[12][64]; // for HQ mode we need to keep the best block
|
yading@10
|
702 int (*decode_mb)(struct MpegEncContext *s, int16_t block[6][64]); // used by some codecs to avoid a switch()
|
yading@10
|
703 #define SLICE_OK 0
|
yading@10
|
704 #define SLICE_ERROR -1
|
yading@10
|
705 #define SLICE_END -2 ///<end marker found
|
yading@10
|
706 #define SLICE_NOEND -3 ///<no end marker or error found but mb count exceeded
|
yading@10
|
707
|
yading@10
|
708 void (*dct_unquantize_mpeg1_intra)(struct MpegEncContext *s,
|
yading@10
|
709 int16_t *block/*align 16*/, int n, int qscale);
|
yading@10
|
710 void (*dct_unquantize_mpeg1_inter)(struct MpegEncContext *s,
|
yading@10
|
711 int16_t *block/*align 16*/, int n, int qscale);
|
yading@10
|
712 void (*dct_unquantize_mpeg2_intra)(struct MpegEncContext *s,
|
yading@10
|
713 int16_t *block/*align 16*/, int n, int qscale);
|
yading@10
|
714 void (*dct_unquantize_mpeg2_inter)(struct MpegEncContext *s,
|
yading@10
|
715 int16_t *block/*align 16*/, int n, int qscale);
|
yading@10
|
716 void (*dct_unquantize_h263_intra)(struct MpegEncContext *s,
|
yading@10
|
717 int16_t *block/*align 16*/, int n, int qscale);
|
yading@10
|
718 void (*dct_unquantize_h263_inter)(struct MpegEncContext *s,
|
yading@10
|
719 int16_t *block/*align 16*/, int n, int qscale);
|
yading@10
|
720 void (*dct_unquantize_h261_intra)(struct MpegEncContext *s,
|
yading@10
|
721 int16_t *block/*align 16*/, int n, int qscale);
|
yading@10
|
722 void (*dct_unquantize_h261_inter)(struct MpegEncContext *s,
|
yading@10
|
723 int16_t *block/*align 16*/, int n, int qscale);
|
yading@10
|
724 void (*dct_unquantize_intra)(struct MpegEncContext *s, // unquantizer to use (mpeg4 can use both)
|
yading@10
|
725 int16_t *block/*align 16*/, int n, int qscale);
|
yading@10
|
726 void (*dct_unquantize_inter)(struct MpegEncContext *s, // unquantizer to use (mpeg4 can use both)
|
yading@10
|
727 int16_t *block/*align 16*/, int n, int qscale);
|
yading@10
|
728 int (*dct_quantize)(struct MpegEncContext *s, int16_t *block/*align 16*/, int n, int qscale, int *overflow);
|
yading@10
|
729 int (*fast_dct_quantize)(struct MpegEncContext *s, int16_t *block/*align 16*/, int n, int qscale, int *overflow);
|
yading@10
|
730 void (*denoise_dct)(struct MpegEncContext *s, int16_t *block);
|
yading@10
|
731
|
yading@10
|
732 int mpv_flags; ///< flags set by private options
|
yading@10
|
733 int quantizer_noise_shaping;
|
yading@10
|
734
|
yading@10
|
735 /* temp buffers for rate control */
|
yading@10
|
736 float *cplx_tab, *bits_tab;
|
yading@10
|
737
|
yading@10
|
738 /* flag to indicate a reinitialization is required, e.g. after
|
yading@10
|
739 * a frame size change */
|
yading@10
|
740 int context_reinit;
|
yading@10
|
741
|
yading@10
|
742 ERContext er;
|
yading@10
|
743 } MpegEncContext;
|
yading@10
|
744
|
yading@10
|
745 #define REBASE_PICTURE(pic, new_ctx, old_ctx) \
|
yading@10
|
746 ((pic && pic >= old_ctx->picture && \
|
yading@10
|
747 pic < old_ctx->picture + MAX_PICTURE_COUNT) ? \
|
yading@10
|
748 &new_ctx->picture[pic - old_ctx->picture] : NULL)
|
yading@10
|
749
|
yading@10
|
750 /* mpegvideo_enc common options */
|
yading@10
|
751 #define FF_MPV_FLAG_SKIP_RD 0x0001
|
yading@10
|
752 #define FF_MPV_FLAG_STRICT_GOP 0x0002
|
yading@10
|
753 #define FF_MPV_FLAG_QP_RD 0x0004
|
yading@10
|
754 #define FF_MPV_FLAG_CBP_RD 0x0008
|
yading@10
|
755
|
yading@10
|
756 #define FF_MPV_OFFSET(x) offsetof(MpegEncContext, x)
|
yading@10
|
757 #define FF_MPV_OPT_FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM)
|
yading@10
|
758 #define FF_MPV_COMMON_OPTS \
|
yading@10
|
759 { "mpv_flags", "Flags common for all mpegvideo-based encoders.", FF_MPV_OFFSET(mpv_flags), AV_OPT_TYPE_FLAGS, { .i64 = 0 }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS, "mpv_flags" },\
|
yading@10
|
760 { "skip_rd", "RD optimal MB level residual skipping", 0, AV_OPT_TYPE_CONST, { .i64 = FF_MPV_FLAG_SKIP_RD }, 0, 0, FF_MPV_OPT_FLAGS, "mpv_flags" },\
|
yading@10
|
761 { "strict_gop", "Strictly enforce gop size", 0, AV_OPT_TYPE_CONST, { .i64 = FF_MPV_FLAG_STRICT_GOP }, 0, 0, FF_MPV_OPT_FLAGS, "mpv_flags" },\
|
yading@10
|
762 { "qp_rd", "Use rate distortion optimization for qp selection", 0, AV_OPT_TYPE_CONST, { .i64 = FF_MPV_FLAG_QP_RD }, 0, 0, FF_MPV_OPT_FLAGS, "mpv_flags" },\
|
yading@10
|
763 { "cbp_rd", "use rate distortion optimization for CBP", 0, AV_OPT_TYPE_CONST, { .i64 = FF_MPV_FLAG_CBP_RD }, 0, 0, FF_MPV_OPT_FLAGS, "mpv_flags" },\
|
yading@10
|
764 { "luma_elim_threshold", "single coefficient elimination threshold for luminance (negative values also consider dc coefficient)",\
|
yading@10
|
765 FF_MPV_OFFSET(luma_elim_threshold), AV_OPT_TYPE_INT, { .i64 = 0 }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS },\
|
yading@10
|
766 { "chroma_elim_threshold", "single coefficient elimination threshold for chrominance (negative values also consider dc coefficient)",\
|
yading@10
|
767 FF_MPV_OFFSET(chroma_elim_threshold), AV_OPT_TYPE_INT, { .i64 = 0 }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS },\
|
yading@10
|
768 { "quantizer_noise_shaping", NULL, FF_MPV_OFFSET(quantizer_noise_shaping), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, FF_MPV_OPT_FLAGS },
|
yading@10
|
769
|
yading@10
|
770 extern const AVOption ff_mpv_generic_options[];
|
yading@10
|
771
|
yading@10
|
772 #define FF_MPV_GENERIC_CLASS(name) \
|
yading@10
|
773 static const AVClass name ## _class = {\
|
yading@10
|
774 .class_name = #name " encoder",\
|
yading@10
|
775 .item_name = av_default_item_name,\
|
yading@10
|
776 .option = ff_mpv_generic_options,\
|
yading@10
|
777 .version = LIBAVUTIL_VERSION_INT,\
|
yading@10
|
778 };
|
yading@10
|
779
|
yading@10
|
780 /**
|
yading@10
|
781 * Set the given MpegEncContext to common defaults (same for encoding
|
yading@10
|
782 * and decoding). The changed fields will not depend upon the prior
|
yading@10
|
783 * state of the MpegEncContext.
|
yading@10
|
784 */
|
yading@10
|
785 void ff_MPV_common_defaults(MpegEncContext *s);
|
yading@10
|
786
|
yading@10
|
787 void ff_MPV_decode_defaults(MpegEncContext *s);
|
yading@10
|
788 int ff_MPV_common_init(MpegEncContext *s);
|
yading@10
|
789 int ff_mpv_frame_size_alloc(MpegEncContext *s, int linesize);
|
yading@10
|
790 int ff_MPV_common_frame_size_change(MpegEncContext *s);
|
yading@10
|
791 void ff_MPV_common_end(MpegEncContext *s);
|
yading@10
|
792 void ff_MPV_decode_mb(MpegEncContext *s, int16_t block[12][64]);
|
yading@10
|
793 int ff_MPV_frame_start(MpegEncContext *s, AVCodecContext *avctx);
|
yading@10
|
794 void ff_MPV_frame_end(MpegEncContext *s);
|
yading@10
|
795 int ff_MPV_encode_init(AVCodecContext *avctx);
|
yading@10
|
796 int ff_MPV_encode_end(AVCodecContext *avctx);
|
yading@10
|
797 int ff_MPV_encode_picture(AVCodecContext *avctx, AVPacket *pkt,
|
yading@10
|
798 AVFrame *frame, int *got_packet);
|
yading@10
|
799 void ff_dct_encode_init_x86(MpegEncContext *s);
|
yading@10
|
800 void ff_MPV_common_init_x86(MpegEncContext *s);
|
yading@10
|
801 void ff_MPV_common_init_axp(MpegEncContext *s);
|
yading@10
|
802 void ff_MPV_common_init_arm(MpegEncContext *s);
|
yading@10
|
803 void ff_MPV_common_init_altivec(MpegEncContext *s);
|
yading@10
|
804 void ff_MPV_common_init_bfin(MpegEncContext *s);
|
yading@10
|
805 void ff_clean_intra_table_entries(MpegEncContext *s);
|
yading@10
|
806 void ff_draw_horiz_band(AVCodecContext *avctx, DSPContext *dsp, Picture *cur,
|
yading@10
|
807 Picture *last, int y, int h, int picture_structure,
|
yading@10
|
808 int first_field, int draw_edges, int low_delay,
|
yading@10
|
809 int v_edge_pos, int h_edge_pos);
|
yading@10
|
810 void ff_mpeg_draw_horiz_band(MpegEncContext *s, int y, int h);
|
yading@10
|
811 void ff_mpeg_flush(AVCodecContext *avctx);
|
yading@10
|
812
|
yading@10
|
813 void ff_print_debug_info(MpegEncContext *s, Picture *p, AVFrame *pict);
|
yading@10
|
814 void ff_print_debug_info2(AVCodecContext *avctx, Picture *p, AVFrame *pict, uint8_t *mbskip_table,
|
yading@10
|
815 int *low_delay,
|
yading@10
|
816 int mb_width, int mb_height, int mb_stride, int quarter_sample);
|
yading@10
|
817
|
yading@10
|
818 int ff_mpv_export_qp_table(MpegEncContext *s, AVFrame *f, Picture *p, int qp_type);
|
yading@10
|
819
|
yading@10
|
820 void ff_write_quant_matrix(PutBitContext *pb, uint16_t *matrix);
|
yading@10
|
821 void ff_release_unused_pictures(MpegEncContext *s, int remove_current);
|
yading@10
|
822 int ff_find_unused_picture(MpegEncContext *s, int shared);
|
yading@10
|
823 void ff_denoise_dct(MpegEncContext *s, int16_t *block);
|
yading@10
|
824 int ff_update_duplicate_context(MpegEncContext *dst, MpegEncContext *src);
|
yading@10
|
825 int ff_MPV_lowest_referenced_row(MpegEncContext *s, int dir);
|
yading@10
|
826 void ff_MPV_report_decode_progress(MpegEncContext *s);
|
yading@10
|
827 int ff_mpeg_update_thread_context(AVCodecContext *dst, const AVCodecContext *src);
|
yading@10
|
828 void ff_set_qscale(MpegEncContext * s, int qscale);
|
yading@10
|
829
|
yading@10
|
830 void ff_mpeg_er_frame_start(MpegEncContext *s);
|
yading@10
|
831
|
yading@10
|
832 int ff_dct_common_init(MpegEncContext *s);
|
yading@10
|
833 int ff_dct_encode_init(MpegEncContext *s);
|
yading@10
|
834 void ff_convert_matrix(DSPContext *dsp, int (*qmat)[64], uint16_t (*qmat16)[2][64],
|
yading@10
|
835 const uint16_t *quant_matrix, int bias, int qmin, int qmax, int intra);
|
yading@10
|
836 int ff_dct_quantize_c(MpegEncContext *s, int16_t *block, int n, int qscale, int *overflow);
|
yading@10
|
837
|
yading@10
|
838 void ff_init_block_index(MpegEncContext *s);
|
yading@10
|
839
|
yading@10
|
840 void ff_MPV_motion(MpegEncContext *s,
|
yading@10
|
841 uint8_t *dest_y, uint8_t *dest_cb,
|
yading@10
|
842 uint8_t *dest_cr, int dir,
|
yading@10
|
843 uint8_t **ref_picture,
|
yading@10
|
844 op_pixels_func (*pix_op)[4],
|
yading@10
|
845 qpel_mc_func (*qpix_op)[16]);
|
yading@10
|
846
|
yading@10
|
847 /**
|
yading@10
|
848 * Allocate a Picture.
|
yading@10
|
849 * The pixels are allocated/set by calling get_buffer() if shared = 0.
|
yading@10
|
850 */
|
yading@10
|
851 int ff_alloc_picture(MpegEncContext *s, Picture *pic, int shared);
|
yading@10
|
852
|
yading@10
|
853 extern const enum AVPixelFormat ff_pixfmt_list_420[];
|
yading@10
|
854
|
yading@10
|
855 /**
|
yading@10
|
856 * permute block according to permuatation.
|
yading@10
|
857 * @param last last non zero element in scantable order
|
yading@10
|
858 */
|
yading@10
|
859 void ff_block_permute(int16_t *block, uint8_t *permutation, const uint8_t *scantable, int last);
|
yading@10
|
860
|
yading@10
|
861 static inline void ff_update_block_index(MpegEncContext *s){
|
yading@10
|
862 const int block_size= 8 >> s->avctx->lowres;
|
yading@10
|
863
|
yading@10
|
864 s->block_index[0]+=2;
|
yading@10
|
865 s->block_index[1]+=2;
|
yading@10
|
866 s->block_index[2]+=2;
|
yading@10
|
867 s->block_index[3]+=2;
|
yading@10
|
868 s->block_index[4]++;
|
yading@10
|
869 s->block_index[5]++;
|
yading@10
|
870 s->dest[0]+= 2*block_size;
|
yading@10
|
871 s->dest[1]+= block_size;
|
yading@10
|
872 s->dest[2]+= block_size;
|
yading@10
|
873 }
|
yading@10
|
874
|
yading@10
|
875 static inline int get_bits_diff(MpegEncContext *s){
|
yading@10
|
876 const int bits= put_bits_count(&s->pb);
|
yading@10
|
877 const int last= s->last_bits;
|
yading@10
|
878
|
yading@10
|
879 s->last_bits = bits;
|
yading@10
|
880
|
yading@10
|
881 return bits - last;
|
yading@10
|
882 }
|
yading@10
|
883
|
yading@10
|
884 static inline int ff_h263_round_chroma(int x){
|
yading@10
|
885 static const uint8_t h263_chroma_roundtab[16] = {
|
yading@10
|
886 // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
yading@10
|
887 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1,
|
yading@10
|
888 };
|
yading@10
|
889 return h263_chroma_roundtab[x & 0xf] + (x >> 3);
|
yading@10
|
890 }
|
yading@10
|
891
|
yading@10
|
892 /* motion_est.c */
|
yading@10
|
893 void ff_estimate_p_frame_motion(MpegEncContext * s,
|
yading@10
|
894 int mb_x, int mb_y);
|
yading@10
|
895 void ff_estimate_b_frame_motion(MpegEncContext * s,
|
yading@10
|
896 int mb_x, int mb_y);
|
yading@10
|
897 int ff_get_best_fcode(MpegEncContext * s, int16_t (*mv_table)[2], int type);
|
yading@10
|
898 void ff_fix_long_p_mvs(MpegEncContext * s);
|
yading@10
|
899 void ff_fix_long_mvs(MpegEncContext * s, uint8_t *field_select_table, int field_select,
|
yading@10
|
900 int16_t (*mv_table)[2], int f_code, int type, int truncate);
|
yading@10
|
901 int ff_init_me(MpegEncContext *s);
|
yading@10
|
902 int ff_pre_estimate_p_frame_motion(MpegEncContext * s, int mb_x, int mb_y);
|
yading@10
|
903 int ff_epzs_motion_search(MpegEncContext * s, int *mx_ptr, int *my_ptr,
|
yading@10
|
904 int P[10][2], int src_index, int ref_index, int16_t (*last_mv)[2],
|
yading@10
|
905 int ref_mv_scale, int size, int h);
|
yading@10
|
906 int ff_get_mb_score(MpegEncContext * s, int mx, int my, int src_index,
|
yading@10
|
907 int ref_index, int size, int h, int add_rate);
|
yading@10
|
908
|
yading@10
|
909 /* mpeg12.c */
|
yading@10
|
910 extern const uint8_t ff_mpeg1_dc_scale_table[128];
|
yading@10
|
911 extern const uint8_t * const ff_mpeg2_dc_scale_table[4];
|
yading@10
|
912
|
yading@10
|
913 void ff_mpeg1_encode_picture_header(MpegEncContext *s, int picture_number);
|
yading@10
|
914 void ff_mpeg1_encode_mb(MpegEncContext *s,
|
yading@10
|
915 int16_t block[6][64],
|
yading@10
|
916 int motion_x, int motion_y);
|
yading@10
|
917 void ff_mpeg1_encode_init(MpegEncContext *s);
|
yading@10
|
918 void ff_mpeg1_encode_slice_header(MpegEncContext *s);
|
yading@10
|
919
|
yading@10
|
920 extern const uint8_t ff_aic_dc_scale_table[32];
|
yading@10
|
921 extern const uint8_t ff_h263_chroma_qscale_table[32];
|
yading@10
|
922 extern const uint8_t ff_h263_loop_filter_strength[32];
|
yading@10
|
923
|
yading@10
|
924 /* rv10.c */
|
yading@10
|
925 void ff_rv10_encode_picture_header(MpegEncContext *s, int picture_number);
|
yading@10
|
926 int ff_rv_decode_dc(MpegEncContext *s, int n);
|
yading@10
|
927 void ff_rv20_encode_picture_header(MpegEncContext *s, int picture_number);
|
yading@10
|
928
|
yading@10
|
929
|
yading@10
|
930 /* msmpeg4.c */
|
yading@10
|
931 void ff_msmpeg4_encode_picture_header(MpegEncContext * s, int picture_number);
|
yading@10
|
932 void ff_msmpeg4_encode_ext_header(MpegEncContext * s);
|
yading@10
|
933 void ff_msmpeg4_encode_mb(MpegEncContext * s,
|
yading@10
|
934 int16_t block[6][64],
|
yading@10
|
935 int motion_x, int motion_y);
|
yading@10
|
936 int ff_msmpeg4_decode_picture_header(MpegEncContext * s);
|
yading@10
|
937 int ff_msmpeg4_decode_ext_header(MpegEncContext * s, int buf_size);
|
yading@10
|
938 int ff_msmpeg4_decode_init(AVCodecContext *avctx);
|
yading@10
|
939 void ff_msmpeg4_encode_init(MpegEncContext *s);
|
yading@10
|
940 int ff_wmv2_decode_picture_header(MpegEncContext * s);
|
yading@10
|
941 int ff_wmv2_decode_secondary_picture_header(MpegEncContext * s);
|
yading@10
|
942 void ff_wmv2_add_mb(MpegEncContext *s, int16_t block[6][64], uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr);
|
yading@10
|
943 void ff_mspel_motion(MpegEncContext *s,
|
yading@10
|
944 uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
|
yading@10
|
945 uint8_t **ref_picture, op_pixels_func (*pix_op)[4],
|
yading@10
|
946 int motion_x, int motion_y, int h);
|
yading@10
|
947 int ff_wmv2_encode_picture_header(MpegEncContext * s, int picture_number);
|
yading@10
|
948 void ff_wmv2_encode_mb(MpegEncContext * s,
|
yading@10
|
949 int16_t block[6][64],
|
yading@10
|
950 int motion_x, int motion_y);
|
yading@10
|
951
|
yading@10
|
952 int ff_mpeg_ref_picture(MpegEncContext *s, Picture *dst, Picture *src);
|
yading@10
|
953 void ff_mpeg_unref_picture(MpegEncContext *s, Picture *picture);
|
yading@10
|
954
|
yading@10
|
955
|
yading@10
|
956 #endif /* AVCODEC_MPEGVIDEO_H */
|