FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/mpegvideo.h
Date: 2024-11-20 23:03:26
Exec Total Coverage
Lines: 13 13 100.0%
Functions: 1 1 100.0%
Branches: 2 2 100.0%

Line Branch Exec Source
1 /*
2 * Generic DCT based hybrid video encoder
3 * Copyright (c) 2000, 2001, 2002 Fabrice Bellard
4 * Copyright (c) 2002-2004 Michael Niedermayer
5 *
6 * This file is part of FFmpeg.
7 *
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23 /**
24 * @file
25 * mpegvideo header.
26 */
27
28 #ifndef AVCODEC_MPEGVIDEO_H
29 #define AVCODEC_MPEGVIDEO_H
30
31 #include "blockdsp.h"
32 #include "error_resilience.h"
33 #include "fdctdsp.h"
34 #include "get_bits.h"
35 #include "h264chroma.h"
36 #include "h263dsp.h"
37 #include "hpeldsp.h"
38 #include "idctdsp.h"
39 #include "me_cmp.h"
40 #include "motion_est.h"
41 #include "mpegpicture.h"
42 #include "mpegvideoencdsp.h"
43 #include "pixblockdsp.h"
44 #include "put_bits.h"
45 #include "ratecontrol.h"
46 #include "qpeldsp.h"
47 #include "videodsp.h"
48
49 #define MAX_THREADS 32
50
51 #define MAX_B_FRAMES 16
52
53 /**
54 * Scantable.
55 */
56 typedef struct ScanTable {
57 const uint8_t *scantable;
58 uint8_t permutated[64];
59 uint8_t raster_end[64];
60 } ScanTable;
61
62 enum OutputFormat {
63 FMT_MPEG1,
64 FMT_H261,
65 FMT_H263,
66 FMT_MJPEG,
67 FMT_SPEEDHQ,
68 };
69
70 /**
71 * MpegEncContext.
72 */
73 typedef struct MpegEncContext {
74 AVClass *class;
75
76 int y_dc_scale, c_dc_scale;
77 int ac_pred;
78 int block_last_index[12]; ///< last non zero coefficient in block
79 int h263_aic; ///< Advanced INTRA Coding (AIC)
80
81 /* scantables */
82 ScanTable inter_scantable; ///< if inter == intra then intra should be used to reduce the cache usage
83
84 /* WARNING: changes above this line require updates to hardcoded
85 * offsets used in ASM. */
86
87 ScanTable intra_scantable;
88 uint8_t permutated_intra_h_scantable[64];
89 uint8_t permutated_intra_v_scantable[64];
90
91 struct AVCodecContext *avctx;
92 /* The following pointer is intended for codecs sharing code
93 * between decoder and encoder and in need of a common context to do so. */
94 void *private_ctx;
95 /* the following parameters must be initialized before encoding */
96 int width, height;///< picture size. must be a multiple of 16
97 int gop_size;
98 int intra_only; ///< if true, only intra pictures are generated
99 int64_t bit_rate; ///< wanted bit rate
100 enum OutputFormat out_format; ///< output format
101 int h263_pred; ///< use MPEG-4/H.263 ac/dc predictions
102 int pb_frame; ///< PB-frame mode (0 = none, 1 = base, 2 = improved)
103
104 /* the following codec id fields are deprecated in favor of codec_id */
105 int h263_plus; ///< H.263+ headers
106 int h263_flv; ///< use flv H.263 header
107
108 enum AVCodecID codec_id; /* see AV_CODEC_ID_xxx */
109 int fixed_qscale; ///< fixed qscale if non zero
110 int encoding; ///< true if we are encoding (vs decoding)
111 int max_b_frames; ///< max number of B-frames for encoding
112 int luma_elim_threshold;
113 int chroma_elim_threshold;
114 int workaround_bugs; ///< workaround bugs in encoders which cannot be detected automatically
115 int codec_tag; ///< internal codec_tag upper case converted from avctx codec_tag
116 /* the following fields are managed internally by the encoder */
117
118 /* sequence parameters */
119 int context_initialized;
120 int input_picture_number; ///< used to set pic->display_picture_number, should not be used for/by anything else
121 int coded_picture_number; ///< used to set pic->coded_picture_number, should not be used for/by anything else
122 int picture_number; //FIXME remove, unclear definition
123 int picture_in_gop_number; ///< 0-> first pic in gop, ...
124 int mb_width, mb_height; ///< number of MBs horizontally & vertically
125 int mb_stride; ///< mb_width+1 used for some arrays to allow simple addressing of left & top MBs without sig11
126 int b8_stride; ///< 2*mb_width+1 used for some 8x8 block arrays to allow simple addressing
127 int h_edge_pos, v_edge_pos;///< horizontal / vertical position of the right/bottom edge (pixel replication)
128 int mb_num; ///< number of MBs of a picture
129 ptrdiff_t linesize; ///< line size, in bytes, may be different from width
130 ptrdiff_t uvlinesize; ///< line size, for chroma in bytes, may be different from width
131 struct FFRefStructPool *picture_pool; ///< Pool for MPVPictures
132 MPVPicture **input_picture;///< next pictures on display order for encoding
133 MPVPicture **reordered_input_picture; ///< pointer to the next pictures in coded order for encoding
134
135 BufferPoolContext buffer_pools;
136
137 int64_t user_specified_pts; ///< last non-zero pts from AVFrame which was passed into avcodec_send_frame()
138 /**
139 * pts difference between the first and second input frame, used for
140 * calculating dts of the first frame when there's a delay */
141 int64_t dts_delta;
142 /**
143 * reordered pts to be used as dts for the next output frame when there's
144 * a delay */
145 int64_t reordered_pts;
146
147 /** bit output */
148 PutBitContext pb;
149
150 int start_mb_y; ///< start mb_y of this thread (so current thread should process start_mb_y <= row < end_mb_y)
151 int end_mb_y; ///< end mb_y of this thread (so current thread should process start_mb_y <= row < end_mb_y)
152 struct MpegEncContext *thread_context[MAX_THREADS];
153 int slice_context_count; ///< number of used thread_contexts
154
155 /**
156 * copy of the previous picture structure.
157 * note, linesize & data, might not match the previous picture (for field pictures)
158 */
159 MPVWorkPicture last_pic;
160
161 /**
162 * copy of the next picture structure.
163 * note, linesize & data, might not match the next picture (for field pictures)
164 */
165 MPVWorkPicture next_pic;
166
167 /**
168 * Reference to the source picture for encoding.
169 * note, linesize & data, might not match the source picture (for field pictures)
170 */
171 AVFrame *new_pic;
172
173 /**
174 * copy of the current picture structure.
175 * note, linesize & data, might not match the current picture (for field pictures)
176 */
177 MPVWorkPicture cur_pic;
178
179 int skipped_last_frame;
180 int last_dc[3]; ///< last DC values for MPEG-1
181 int16_t *dc_val_base;
182 int16_t *dc_val[3]; ///< used for MPEG-4 DC prediction, all 3 arrays must be continuous
183 const uint8_t *y_dc_scale_table; ///< qscale -> y_dc_scale table
184 const uint8_t *c_dc_scale_table; ///< qscale -> c_dc_scale table
185 const uint8_t *chroma_qscale_table; ///< qscale -> chroma_qscale (H.263)
186 uint8_t *coded_block_base;
187 uint8_t *coded_block; ///< used for coded block pattern prediction (msmpeg4v3, wmv1)
188 int16_t (*ac_val_base)[16];
189 int16_t (*ac_val[3])[16]; ///< used for MPEG-4 AC prediction, all 3 arrays must be continuous
190 int mb_skipped; ///< MUST BE SET only during DECODING
191 uint8_t *mbskip_table; /**< used to avoid copy if macroblock skipped (for black regions for example)
192 and used for B-frame encoding & decoding (contains skip table of next P-frame) */
193 uint8_t *mbintra_table; ///< used to avoid setting {ac, dc, cbp}-pred stuff to zero on inter MB decoding
194 uint8_t *cbp_table; ///< used to store cbp, ac_pred for partitioned decoding
195 uint8_t *pred_dir_table; ///< used to store pred_dir for partitioned decoding
196
197 ScratchpadContext sc;
198
199 int qscale; ///< QP
200 int chroma_qscale; ///< chroma QP
201 unsigned int lambda; ///< Lagrange multiplier used in rate distortion
202 unsigned int lambda2; ///< (lambda*lambda) >> FF_LAMBDA_SHIFT
203 int *lambda_table;
204 int adaptive_quant; ///< use adaptive quantization
205 int dquant; ///< qscale difference to prev qscale
206 int pict_type; ///< AV_PICTURE_TYPE_I, AV_PICTURE_TYPE_P, AV_PICTURE_TYPE_B, ...
207 int vbv_delay;
208 int last_pict_type; //FIXME removes
209 int last_non_b_pict_type; ///< used for MPEG-4 gmc B-frames & ratecontrol
210 int droppable;
211 int last_lambda_for[5]; ///< last lambda for a specific pict type
212 int skipdct; ///< skip dct and code zero residual
213
214 /* motion compensation */
215 int unrestricted_mv; ///< mv can point outside of the coded picture
216 int h263_long_vectors; ///< use horrible H.263v1 long vector mode
217
218 BlockDSPContext bdsp;
219 FDCTDSPContext fdsp;
220 H264ChromaContext h264chroma;
221 HpelDSPContext hdsp;
222 IDCTDSPContext idsp;
223 MpegvideoEncDSPContext mpvencdsp;
224 PixblockDSPContext pdsp;
225 QpelDSPContext qdsp;
226 VideoDSPContext vdsp;
227 H263DSPContext h263dsp;
228 int f_code; ///< forward MV resolution
229 int b_code; ///< backward MV resolution for B-frames (MPEG-4)
230 int16_t (*p_mv_table_base)[2];
231 int16_t (*b_forw_mv_table_base)[2];
232 int16_t (*b_back_mv_table_base)[2];
233 int16_t (*b_bidir_forw_mv_table_base)[2];
234 int16_t (*b_bidir_back_mv_table_base)[2];
235 int16_t (*b_direct_mv_table_base)[2];
236 int16_t (*p_field_mv_table_base)[2];
237 int16_t (*b_field_mv_table_base)[2];
238 int16_t (*p_mv_table)[2]; ///< MV table (1MV per MB) P-frame encoding
239 int16_t (*b_forw_mv_table)[2]; ///< MV table (1MV per MB) forward mode B-frame encoding
240 int16_t (*b_back_mv_table)[2]; ///< MV table (1MV per MB) backward mode B-frame encoding
241 int16_t (*b_bidir_forw_mv_table)[2]; ///< MV table (1MV per MB) bidir mode B-frame encoding
242 int16_t (*b_bidir_back_mv_table)[2]; ///< MV table (1MV per MB) bidir mode B-frame encoding
243 int16_t (*b_direct_mv_table)[2]; ///< MV table (1MV per MB) direct mode B-frame encoding
244 int16_t (*p_field_mv_table[2][2])[2]; ///< MV table (2MV per MB) interlaced P-frame encoding
245 int16_t (*b_field_mv_table[2][2][2])[2];///< MV table (4MV per MB) interlaced B-frame encoding
246 uint8_t (*p_field_select_table[2]); ///< Only the first element is allocated
247 uint8_t (*b_field_select_table[2][2]); ///< Only the first element is allocated
248
249 /* The following fields are encoder-only */
250 uint16_t *mb_var; ///< Table for MB variances
251 uint16_t *mc_mb_var; ///< Table for motion compensated MB variances
252 uint8_t *mb_mean; ///< Table for MB luminance
253 int64_t mb_var_sum; ///< sum of MB variance for current frame
254 int64_t mc_mb_var_sum; ///< motion compensated MB variance for current frame
255 uint64_t encoding_error[MPV_MAX_PLANES];
256
257 int motion_est; ///< ME algorithm
258 int me_penalty_compensation;
259 int me_pre; ///< prepass for motion estimation
260 int mv_dir;
261 #define MV_DIR_FORWARD 1
262 #define MV_DIR_BACKWARD 2
263 #define MV_DIRECT 4 ///< bidirectional mode where the difference equals the MV of the last P/S/I-Frame (MPEG-4)
264 int mv_type;
265 #define MV_TYPE_16X16 0 ///< 1 vector for the whole mb
266 #define MV_TYPE_8X8 1 ///< 4 vectors (H.263, MPEG-4 4MV)
267 #define MV_TYPE_16X8 2 ///< 2 vectors, one per 16x8 block
268 #define MV_TYPE_FIELD 3 ///< 2 vectors, one per field
269 #define MV_TYPE_DMV 4 ///< 2 vectors, special mpeg2 Dual Prime Vectors
270 /**motion vectors for a macroblock
271 first coordinate : 0 = forward 1 = backward
272 second " : depend on type
273 third " : 0 = x, 1 = y
274 */
275 int mv[2][4][2];
276 int field_select[2][2];
277 int last_mv[2][2][2]; ///< last MV, used for MV prediction in MPEG-1 & B-frame MPEG-4
278 const uint8_t *fcode_tab; ///< smallest fcode needed for each MV
279 int16_t direct_scale_mv[2][64]; ///< precomputed to avoid divisions in ff_mpeg4_set_direct_mv
280
281 MotionEstContext me;
282
283 int no_rounding; /**< apply no rounding to motion compensation (MPEG-4, msmpeg4, ...)
284 for B-frames rounding mode is always 0 */
285
286 /* macroblock layer */
287 int mb_x, mb_y;
288 int mb_skip_run;
289 int mb_intra;
290 uint16_t *mb_type; ///< Table for candidate MB types for encoding (defines in mpegvideoenc.h)
291
292 int block_index[6]; ///< index to current MB in block based arrays with edges
293 int block_wrap[6];
294 uint8_t *dest[3];
295
296 int *mb_index2xy; ///< mb_index -> mb_x + mb_y*mb_stride
297
298 /** matrix transmitted in the bitstream */
299 uint16_t intra_matrix[64];
300 uint16_t chroma_intra_matrix[64];
301 uint16_t inter_matrix[64];
302 uint16_t chroma_inter_matrix[64];
303
304 int intra_quant_bias; ///< bias for the quantizer
305 int inter_quant_bias; ///< bias for the quantizer
306 int min_qcoeff; ///< minimum encodable coefficient
307 int max_qcoeff; ///< maximum encodable coefficient
308 int ac_esc_length; ///< num of bits needed to encode the longest esc
309 uint8_t *intra_ac_vlc_length;
310 uint8_t *intra_ac_vlc_last_length;
311 uint8_t *intra_chroma_ac_vlc_length;
312 uint8_t *intra_chroma_ac_vlc_last_length;
313 uint8_t *inter_ac_vlc_length;
314 uint8_t *inter_ac_vlc_last_length;
315 uint8_t *luma_dc_vlc_length;
316
317 int coded_score[12];
318
319 /** precomputed matrix (combine qscale and DCT renorm) */
320 int (*q_intra_matrix)[64];
321 int (*q_chroma_intra_matrix)[64];
322 int (*q_inter_matrix)[64];
323 /** identical to the above but for MMX & these are not permutated, second 64 entries are bias*/
324 uint16_t (*q_intra_matrix16)[2][64];
325 uint16_t (*q_chroma_intra_matrix16)[2][64];
326 uint16_t (*q_inter_matrix16)[2][64];
327
328 /* noise reduction */
329 int (*dct_error_sum)[64];
330 int dct_count[2];
331 uint16_t (*dct_offset)[64];
332
333 /* bit rate control */
334 int64_t total_bits;
335 int frame_bits; ///< bits used for the current frame
336 int stuffing_bits; ///< bits used for stuffing
337 int next_lambda; ///< next lambda used for retrying to encode a frame
338 RateControlContext rc_context; ///< contains stuff only accessed in ratecontrol.c
339
340 /* statistics, used for 2-pass encoding */
341 int mv_bits;
342 int header_bits;
343 int i_tex_bits;
344 int p_tex_bits;
345 int i_count;
346 int misc_bits; ///< cbp, mb_type
347 int last_bits; ///< temp var used for calculating the above vars
348
349 /* error concealment / resync */
350 int resync_mb_x; ///< x position of last resync marker
351 int resync_mb_y; ///< y position of last resync marker
352 GetBitContext last_resync_gb; ///< used to search for the next resync marker
353 int mb_num_left; ///< number of MBs left in this video packet (for partitioned Slices only)
354
355 /* H.263 specific */
356 int gob_index;
357 int obmc; ///< overlapped block motion compensation
358 int mb_info; ///< interval for outputting info about mb offsets as side data
359 int prev_mb_info, last_mb_info;
360 uint8_t *mb_info_ptr;
361 int mb_info_size;
362 int ehc_mode;
363
364 /* H.263+ specific */
365 int umvplus; ///< == H.263+ && unrestricted_mv
366 int h263_aic_dir; ///< AIC direction: 0 = left, 1 = top
367 int h263_slice_structured;
368 int alt_inter_vlc; ///< alternative inter vlc
369 int modified_quant;
370 int loop_filter;
371 int custom_pcf;
372
373 /* MPEG-4 specific */
374 int studio_profile;
375 int dct_precision;
376 ///< number of bits to represent the fractional part of time (encoder only)
377 int time_increment_bits;
378 int last_time_base;
379 int time_base; ///< time in seconds of last I,P,S Frame
380 int64_t time; ///< time of current frame
381 int64_t last_non_b_time;
382 uint16_t pp_time; ///< time distance between the last 2 p,s,i frames
383 uint16_t pb_time; ///< time distance between the last b and p,s,i frame
384 uint16_t pp_field_time;
385 uint16_t pb_field_time; ///< like above, just for interlaced
386 int mcsel;
387 int quarter_sample; ///< 1->qpel, 0->half pel ME/MC
388 int data_partitioning; ///< data partitioning flag from header
389 int partitioned_frame; ///< is current frame partitioned
390 int low_delay; ///< no reordering needed / has no B-frames
391 PutBitContext tex_pb; ///< used for data partitioned VOPs
392 PutBitContext pb2; ///< used for data partitioned VOPs
393 int mpeg_quant;
394 int padding_bug_score; ///< used to detect the VERY common padding bug in MPEG-4
395
396 /* divx specific, used to workaround (many) bugs in divx5 */
397 int divx_packed;
398 uint8_t *bitstream_buffer; //Divx 5.01 puts several frames in a single one, this is used to reorder them
399 int bitstream_buffer_size;
400 unsigned int allocated_bitstream_buffer_size;
401
402 /* RV10 specific */
403 int rv10_version; ///< RV10 version: 0 or 3
404 int rv10_first_dc_coded[3];
405
406 /* MJPEG specific */
407 struct MJpegContext *mjpeg_ctx;
408 int esc_pos;
409
410 /* MSMPEG4 specific */
411 int mv_table_index;
412 int rl_table_index;
413 int rl_chroma_table_index;
414 int dc_table_index;
415 int use_skip_mb_code;
416 int slice_height; ///< in macroblocks
417 int first_slice_line; ///< used in MPEG-4 too to handle resync markers
418 int flipflop_rounding;
419 enum {
420 MSMP4_UNUSED,
421 MSMP4_V1,
422 MSMP4_V2,
423 MSMP4_V3,
424 MSMP4_WMV1,
425 MSMP4_WMV2,
426 MSMP4_VC1, ///< for VC1 (image), WMV3 (image) and MSS2.
427 } msmpeg4_version;
428 int per_mb_rl_table;
429 int esc3_level_length;
430 int esc3_run_length;
431 int inter_intra_pred;
432 int mspel;
433
434 /* decompression specific */
435 GetBitContext gb;
436
437 /* MPEG-1 specific */
438 int last_mv_dir; ///< last mv_dir, used for B-frame encoding
439 int vbv_delay_pos; ///< offset of vbv_delay in the bitstream
440
441 /* MPEG-2-specific - I wished not to have to support this mess. */
442 int progressive_sequence;
443 int mpeg_f_code[2][2];
444
445 // picture structure defines are loaded from mpegutils.h
446 int picture_structure;
447
448 int intra_dc_precision;
449 int frame_pred_frame_dct;
450 int top_field_first;
451 int concealment_motion_vectors;
452 int q_scale_type;
453 int brd_scale;
454 int intra_vlc_format;
455 int alternate_scan;
456 int repeat_first_field;
457 int chroma_420_type;
458 int chroma_format;
459 #define CHROMA_420 1
460 #define CHROMA_422 2
461 #define CHROMA_444 3
462 int chroma_x_shift;//depend on pix_format, that depend on chroma_format
463 int chroma_y_shift;
464
465 int progressive_frame;
466 int full_pel[2];
467 int interlaced_dct;
468 int first_field; ///< is 1 for the first field of a field picture 0 otherwise
469
470 /* RTP specific */
471 int rtp_mode;
472 int rtp_payload_size;
473
474 uint8_t *ptr_lastgob;
475
476 int16_t (*block)[64]; ///< points to one of the following blocks
477 int16_t (*blocks)[12][64]; // for HQ mode we need to keep the best block
478 int (*decode_mb)(struct MpegEncContext *s, int16_t block[12][64]); // used by some codecs to avoid a switch()
479
480 #define SLICE_OK 0
481 #define SLICE_ERROR -1
482 #define SLICE_END -2 ///<end marker found
483 #define SLICE_NOEND -3 ///<no end marker or error found but mb count exceeded
484
485 void (*dct_unquantize_mpeg1_intra)(struct MpegEncContext *s,
486 int16_t *block/*align 16*/, int n, int qscale);
487 void (*dct_unquantize_mpeg1_inter)(struct MpegEncContext *s,
488 int16_t *block/*align 16*/, int n, int qscale);
489 void (*dct_unquantize_mpeg2_intra)(struct MpegEncContext *s,
490 int16_t *block/*align 16*/, int n, int qscale);
491 void (*dct_unquantize_mpeg2_inter)(struct MpegEncContext *s,
492 int16_t *block/*align 16*/, int n, int qscale);
493 void (*dct_unquantize_h263_intra)(struct MpegEncContext *s,
494 int16_t *block/*align 16*/, int n, int qscale);
495 void (*dct_unquantize_h263_inter)(struct MpegEncContext *s,
496 int16_t *block/*align 16*/, int n, int qscale);
497 void (*dct_unquantize_intra)(struct MpegEncContext *s, // unquantizer to use (MPEG-4 can use both)
498 int16_t *block/*align 16*/, int n, int qscale);
499 void (*dct_unquantize_inter)(struct MpegEncContext *s, // unquantizer to use (MPEG-4 can use both)
500 int16_t *block/*align 16*/, int n, int qscale);
501 int (*dct_quantize)(struct MpegEncContext *s, int16_t *block/*align 16*/, int n, int qscale, int *overflow);
502 void (*denoise_dct)(struct MpegEncContext *s, int16_t *block);
503
504 int mpv_flags; ///< flags set by private options
505 int quantizer_noise_shaping;
506
507 me_cmp_func ildct_cmp[2]; ///< 0 = intra, 1 = non-intra
508 me_cmp_func n_sse_cmp[2]; ///< either SSE or NSSE cmp func
509 me_cmp_func sad_cmp[2];
510 me_cmp_func sse_cmp[2];
511 int (*sum_abs_dctelem)(const int16_t *block);
512
513 /**
514 * ratecontrol qmin qmax limiting method
515 * 0-> clipping, 1-> use a nice continuous function to limit qscale within qmin/qmax.
516 */
517 float rc_qsquish;
518 float rc_qmod_amp;
519 int rc_qmod_freq;
520 float rc_initial_cplx;
521 float rc_buffer_aggressivity;
522 float border_masking;
523 int lmin, lmax;
524 int vbv_ignore_qmax;
525
526 char *rc_eq;
527
528 /* temp buffers for rate control */
529 float *cplx_tab, *bits_tab;
530
531 /* flag to indicate a reinitialization is required, e.g. after
532 * a frame size change */
533 int context_reinit;
534
535 ERContext er;
536
537 int error_rate;
538
539 /* temporary frames used by b_frame_strategy = 2 */
540 AVFrame *tmp_frames[MAX_B_FRAMES + 2];
541 int b_frame_strategy;
542 int b_sensitivity;
543
544 /* frame skip options for encoding */
545 int frame_skip_threshold;
546 int frame_skip_factor;
547 int frame_skip_exp;
548 int frame_skip_cmp;
549 me_cmp_func frame_skip_cmp_fn;
550
551 int scenechange_threshold;
552 int noise_reduction;
553
554 int intra_penalty;
555 } MpegEncContext;
556
557
558 /**
559 * Set the given MpegEncContext to common defaults (same for encoding
560 * and decoding). The changed fields will not depend upon the prior
561 * state of the MpegEncContext.
562 */
563 void ff_mpv_common_defaults(MpegEncContext *s);
564
565 int ff_mpv_common_init(MpegEncContext *s);
566 void ff_mpv_common_init_arm(MpegEncContext *s);
567 void ff_mpv_common_init_axp(MpegEncContext *s);
568 void ff_mpv_common_init_neon(MpegEncContext *s);
569 void ff_mpv_common_init_ppc(MpegEncContext *s);
570 void ff_mpv_common_init_x86(MpegEncContext *s);
571 void ff_mpv_common_init_mips(MpegEncContext *s);
572 /**
573 * Initialize an MpegEncContext's thread contexts. Presumes that
574 * slice_context_count is already set and that all the fields
575 * that are freed/reset in free_duplicate_context() are NULL.
576 */
577 int ff_mpv_init_duplicate_contexts(MpegEncContext *s);
578 /**
579 * Initialize and allocates MpegEncContext fields dependent on the resolution.
580 */
581 int ff_mpv_init_context_frame(MpegEncContext *s);
582 /**
583 * Frees and resets MpegEncContext fields depending on the resolution
584 * as well as the slice thread contexts.
585 * Is used during resolution changes to avoid a full reinitialization of the
586 * codec.
587 */
588 void ff_mpv_free_context_frame(MpegEncContext *s);
589
590 void ff_mpv_common_end(MpegEncContext *s);
591
592 void ff_clean_intra_table_entries(MpegEncContext *s);
593
594 int ff_update_duplicate_context(MpegEncContext *dst, const MpegEncContext *src);
595 void ff_set_qscale(MpegEncContext * s, int qscale);
596
597 void ff_mpv_idct_init(MpegEncContext *s);
598 void ff_init_scantable(const uint8_t *permutation, ScanTable *st,
599 const uint8_t *src_scantable);
600 void ff_init_block_index(MpegEncContext *s);
601
602 void ff_mpv_motion(MpegEncContext *s,
603 uint8_t *dest_y, uint8_t *dest_cb,
604 uint8_t *dest_cr, int dir,
605 uint8_t *const *ref_picture,
606 const op_pixels_func (*pix_op)[4],
607 const qpel_mc_func (*qpix_op)[16]);
608
609 7043995 static inline void ff_update_block_index(MpegEncContext *s, int bits_per_raw_sample,
610 int lowres, int chroma_x_shift)
611 {
612
2/2
✓ Branch 0 taken 1350 times.
✓ Branch 1 taken 7042645 times.
7043995 const int bytes_per_pixel = 1 + (bits_per_raw_sample > 8);
613 7043995 const int block_size = (8 * bytes_per_pixel) >> lowres;
614
615 7043995 s->block_index[0]+=2;
616 7043995 s->block_index[1]+=2;
617 7043995 s->block_index[2]+=2;
618 7043995 s->block_index[3]+=2;
619 7043995 s->block_index[4]++;
620 7043995 s->block_index[5]++;
621 7043995 s->dest[0]+= 2*block_size;
622 7043995 s->dest[1] += (2 >> chroma_x_shift) * block_size;
623 7043995 s->dest[2] += (2 >> chroma_x_shift) * block_size;
624 7043995 }
625
626 #endif /* AVCODEC_MPEGVIDEO_H */
627