FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/mpegvideo.h
Date: 2024-04-26 14:42:52
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 Picture *picture; ///< main picture buffer
132 Picture **input_picture; ///< next pictures on display order for encoding
133 Picture **reordered_input_picture; ///< pointer to the next pictures in coded order for encoding
134
135 int64_t user_specified_pts; ///< last non-zero pts from AVFrame which was passed into avcodec_send_frame()
136 /**
137 * pts difference between the first and second input frame, used for
138 * calculating dts of the first frame when there's a delay */
139 int64_t dts_delta;
140 /**
141 * reordered pts to be used as dts for the next output frame when there's
142 * a delay */
143 int64_t reordered_pts;
144
145 /** bit output */
146 PutBitContext pb;
147
148 int start_mb_y; ///< start mb_y of this thread (so current thread should process start_mb_y <= row < end_mb_y)
149 int end_mb_y; ///< end mb_y of this thread (so current thread should process start_mb_y <= row < end_mb_y)
150 struct MpegEncContext *thread_context[MAX_THREADS];
151 int slice_context_count; ///< number of used thread_contexts
152
153 /**
154 * copy of the previous picture structure.
155 * note, linesize & data, might not match the previous picture (for field pictures)
156 */
157 Picture last_picture;
158
159 /**
160 * copy of the next picture structure.
161 * note, linesize & data, might not match the next picture (for field pictures)
162 */
163 Picture next_picture;
164
165 /**
166 * Reference to the source picture for encoding.
167 * note, linesize & data, might not match the source picture (for field pictures)
168 */
169 AVFrame *new_picture;
170
171 /**
172 * copy of the current picture structure.
173 * note, linesize & data, might not match the current picture (for field pictures)
174 */
175 Picture current_picture; ///< buffer to store the decompressed current picture
176
177 Picture *last_picture_ptr; ///< pointer to the previous picture.
178 Picture *next_picture_ptr; ///< pointer to the next picture (for bidir pred)
179 Picture *current_picture_ptr; ///< pointer to the current picture
180 int skipped_last_frame;
181 int last_dc[3]; ///< last DC values for MPEG-1
182 int16_t *dc_val_base;
183 int16_t *dc_val[3]; ///< used for MPEG-4 DC prediction, all 3 arrays must be continuous
184 const uint8_t *y_dc_scale_table; ///< qscale -> y_dc_scale table
185 const uint8_t *c_dc_scale_table; ///< qscale -> c_dc_scale table
186 const uint8_t *chroma_qscale_table; ///< qscale -> chroma_qscale (H.263)
187 uint8_t *coded_block_base;
188 uint8_t *coded_block; ///< used for coded block pattern prediction (msmpeg4v3, wmv1)
189 int16_t (*ac_val_base)[16];
190 int16_t (*ac_val[3])[16]; ///< used for MPEG-4 AC prediction, all 3 arrays must be continuous
191 int mb_skipped; ///< MUST BE SET only during DECODING
192 uint8_t *mbskip_table; /**< used to avoid copy if macroblock skipped (for black regions for example)
193 and used for B-frame encoding & decoding (contains skip table of next P-frame) */
194 uint8_t *mbintra_table; ///< used to avoid setting {ac, dc, cbp}-pred stuff to zero on inter MB decoding
195 uint8_t *cbp_table; ///< used to store cbp, ac_pred for partitioned decoding
196 uint8_t *pred_dir_table; ///< used to store pred_dir for partitioned decoding
197
198 ScratchpadContext sc;
199
200 int qscale; ///< QP
201 int chroma_qscale; ///< chroma QP
202 unsigned int lambda; ///< Lagrange multiplier used in rate distortion
203 unsigned int lambda2; ///< (lambda*lambda) >> FF_LAMBDA_SHIFT
204 int *lambda_table;
205 int adaptive_quant; ///< use adaptive quantization
206 int dquant; ///< qscale difference to prev qscale
207 int pict_type; ///< AV_PICTURE_TYPE_I, AV_PICTURE_TYPE_P, AV_PICTURE_TYPE_B, ...
208 int vbv_delay;
209 int last_pict_type; //FIXME removes
210 int last_non_b_pict_type; ///< used for MPEG-4 gmc B-frames & ratecontrol
211 int droppable;
212 int last_lambda_for[5]; ///< last lambda for a specific pict type
213 int skipdct; ///< skip dct and code zero residual
214
215 /* motion compensation */
216 int unrestricted_mv; ///< mv can point outside of the coded picture
217 int h263_long_vectors; ///< use horrible H.263v1 long vector mode
218
219 BlockDSPContext bdsp;
220 FDCTDSPContext fdsp;
221 H264ChromaContext h264chroma;
222 HpelDSPContext hdsp;
223 IDCTDSPContext idsp;
224 MECmpContext mecc;
225 MpegvideoEncDSPContext mpvencdsp;
226 PixblockDSPContext pdsp;
227 QpelDSPContext qdsp;
228 VideoDSPContext vdsp;
229 H263DSPContext h263dsp;
230 int f_code; ///< forward MV resolution
231 int b_code; ///< backward MV resolution for B-frames (MPEG-4)
232 int16_t (*p_mv_table_base)[2];
233 int16_t (*b_forw_mv_table_base)[2];
234 int16_t (*b_back_mv_table_base)[2];
235 int16_t (*b_bidir_forw_mv_table_base)[2];
236 int16_t (*b_bidir_back_mv_table_base)[2];
237 int16_t (*b_direct_mv_table_base)[2];
238 int16_t (*p_field_mv_table_base)[2];
239 int16_t (*b_field_mv_table_base)[2];
240 int16_t (*p_mv_table)[2]; ///< MV table (1MV per MB) P-frame encoding
241 int16_t (*b_forw_mv_table)[2]; ///< MV table (1MV per MB) forward mode B-frame encoding
242 int16_t (*b_back_mv_table)[2]; ///< MV table (1MV per MB) backward mode B-frame encoding
243 int16_t (*b_bidir_forw_mv_table)[2]; ///< MV table (1MV per MB) bidir mode B-frame encoding
244 int16_t (*b_bidir_back_mv_table)[2]; ///< MV table (1MV per MB) bidir mode B-frame encoding
245 int16_t (*b_direct_mv_table)[2]; ///< MV table (1MV per MB) direct mode B-frame encoding
246 int16_t (*p_field_mv_table[2][2])[2]; ///< MV table (2MV per MB) interlaced P-frame encoding
247 int16_t (*b_field_mv_table[2][2][2])[2];///< MV table (4MV per MB) interlaced B-frame encoding
248 uint8_t (*p_field_select_table[2]); ///< Only the first element is allocated
249 uint8_t (*b_field_select_table[2][2]); ///< Only the first element is allocated
250
251 /* The following fields are encoder-only */
252 uint16_t *mb_var; ///< Table for MB variances
253 uint16_t *mc_mb_var; ///< Table for motion compensated MB variances
254 uint8_t *mb_mean; ///< Table for MB luminance
255 int64_t mb_var_sum; ///< sum of MB variance for current frame
256 int64_t mc_mb_var_sum; ///< motion compensated MB variance for current frame
257 uint64_t encoding_error[MPEGVIDEO_MAX_PLANES];
258
259 int motion_est; ///< ME algorithm
260 int me_penalty_compensation;
261 int me_pre; ///< prepass for motion estimation
262 int mv_dir;
263 #define MV_DIR_FORWARD 1
264 #define MV_DIR_BACKWARD 2
265 #define MV_DIRECT 4 ///< bidirectional mode where the difference equals the MV of the last P/S/I-Frame (MPEG-4)
266 int mv_type;
267 #define MV_TYPE_16X16 0 ///< 1 vector for the whole mb
268 #define MV_TYPE_8X8 1 ///< 4 vectors (H.263, MPEG-4 4MV)
269 #define MV_TYPE_16X8 2 ///< 2 vectors, one per 16x8 block
270 #define MV_TYPE_FIELD 3 ///< 2 vectors, one per field
271 #define MV_TYPE_DMV 4 ///< 2 vectors, special mpeg2 Dual Prime Vectors
272 /**motion vectors for a macroblock
273 first coordinate : 0 = forward 1 = backward
274 second " : depend on type
275 third " : 0 = x, 1 = y
276 */
277 int mv[2][4][2];
278 int field_select[2][2];
279 int last_mv[2][2][2]; ///< last MV, used for MV prediction in MPEG-1 & B-frame MPEG-4
280 const uint8_t *fcode_tab; ///< smallest fcode needed for each MV
281 int16_t direct_scale_mv[2][64]; ///< precomputed to avoid divisions in ff_mpeg4_set_direct_mv
282
283 MotionEstContext me;
284
285 int no_rounding; /**< apply no rounding to motion compensation (MPEG-4, msmpeg4, ...)
286 for B-frames rounding mode is always 0 */
287
288 /* macroblock layer */
289 int mb_x, mb_y;
290 int mb_skip_run;
291 int mb_intra;
292 uint16_t *mb_type; ///< Table for candidate MB types for encoding (defines in mpegvideoenc.h)
293
294 int block_index[6]; ///< index to current MB in block based arrays with edges
295 int block_wrap[6];
296 uint8_t *dest[3];
297
298 int *mb_index2xy; ///< mb_index -> mb_x + mb_y*mb_stride
299
300 /** matrix transmitted in the bitstream */
301 uint16_t intra_matrix[64];
302 uint16_t chroma_intra_matrix[64];
303 uint16_t inter_matrix[64];
304 uint16_t chroma_inter_matrix[64];
305
306 int intra_quant_bias; ///< bias for the quantizer
307 int inter_quant_bias; ///< bias for the quantizer
308 int min_qcoeff; ///< minimum encodable coefficient
309 int max_qcoeff; ///< maximum encodable coefficient
310 int ac_esc_length; ///< num of bits needed to encode the longest esc
311 uint8_t *intra_ac_vlc_length;
312 uint8_t *intra_ac_vlc_last_length;
313 uint8_t *intra_chroma_ac_vlc_length;
314 uint8_t *intra_chroma_ac_vlc_last_length;
315 uint8_t *inter_ac_vlc_length;
316 uint8_t *inter_ac_vlc_last_length;
317 uint8_t *luma_dc_vlc_length;
318
319 int coded_score[12];
320
321 /** precomputed matrix (combine qscale and DCT renorm) */
322 int (*q_intra_matrix)[64];
323 int (*q_chroma_intra_matrix)[64];
324 int (*q_inter_matrix)[64];
325 /** identical to the above but for MMX & these are not permutated, second 64 entries are bias*/
326 uint16_t (*q_intra_matrix16)[2][64];
327 uint16_t (*q_chroma_intra_matrix16)[2][64];
328 uint16_t (*q_inter_matrix16)[2][64];
329
330 /* noise reduction */
331 int (*dct_error_sum)[64];
332 int dct_count[2];
333 uint16_t (*dct_offset)[64];
334
335 /* bit rate control */
336 int64_t total_bits;
337 int frame_bits; ///< bits used for the current frame
338 int stuffing_bits; ///< bits used for stuffing
339 int next_lambda; ///< next lambda used for retrying to encode a frame
340 RateControlContext rc_context; ///< contains stuff only accessed in ratecontrol.c
341
342 /* statistics, used for 2-pass encoding */
343 int mv_bits;
344 int header_bits;
345 int i_tex_bits;
346 int p_tex_bits;
347 int i_count;
348 int skip_count;
349 int misc_bits; ///< cbp, mb_type
350 int last_bits; ///< temp var used for calculating the above vars
351
352 /* error concealment / resync */
353 int resync_mb_x; ///< x position of last resync marker
354 int resync_mb_y; ///< y position of last resync marker
355 GetBitContext last_resync_gb; ///< used to search for the next resync marker
356 int mb_num_left; ///< number of MBs left in this video packet (for partitioned Slices only)
357
358 /* H.263 specific */
359 int gob_index;
360 int obmc; ///< overlapped block motion compensation
361 int mb_info; ///< interval for outputting info about mb offsets as side data
362 int prev_mb_info, last_mb_info;
363 uint8_t *mb_info_ptr;
364 int mb_info_size;
365 int ehc_mode;
366
367 /* H.263+ specific */
368 int umvplus; ///< == H.263+ && unrestricted_mv
369 int h263_aic_dir; ///< AIC direction: 0 = left, 1 = top
370 int h263_slice_structured;
371 int alt_inter_vlc; ///< alternative inter vlc
372 int modified_quant;
373 int loop_filter;
374 int custom_pcf;
375
376 /* MPEG-4 specific */
377 int studio_profile;
378 int dct_precision;
379 ///< number of bits to represent the fractional part of time (encoder only)
380 int time_increment_bits;
381 int last_time_base;
382 int time_base; ///< time in seconds of last I,P,S Frame
383 int64_t time; ///< time of current frame
384 int64_t last_non_b_time;
385 uint16_t pp_time; ///< time distance between the last 2 p,s,i frames
386 uint16_t pb_time; ///< time distance between the last b and p,s,i frame
387 uint16_t pp_field_time;
388 uint16_t pb_field_time; ///< like above, just for interlaced
389 int mcsel;
390 int quant_precision;
391 int quarter_sample; ///< 1->qpel, 0->half pel ME/MC
392 int data_partitioning; ///< data partitioning flag from header
393 int partitioned_frame; ///< is current frame partitioned
394 int low_delay; ///< no reordering needed / has no B-frames
395 PutBitContext tex_pb; ///< used for data partitioned VOPs
396 PutBitContext pb2; ///< used for data partitioned VOPs
397 int mpeg_quant;
398 int padding_bug_score; ///< used to detect the VERY common padding bug in MPEG-4
399
400 /* divx specific, used to workaround (many) bugs in divx5 */
401 int divx_packed;
402 uint8_t *bitstream_buffer; //Divx 5.01 puts several frames in a single one, this is used to reorder them
403 int bitstream_buffer_size;
404 unsigned int allocated_bitstream_buffer_size;
405
406 /* RV10 specific */
407 int rv10_version; ///< RV10 version: 0 or 3
408 int rv10_first_dc_coded[3];
409
410 /* MJPEG specific */
411 struct MJpegContext *mjpeg_ctx;
412 int esc_pos;
413
414 /* MSMPEG4 specific */
415 int mv_table_index;
416 int rl_table_index;
417 int rl_chroma_table_index;
418 int dc_table_index;
419 int use_skip_mb_code;
420 int slice_height; ///< in macroblocks
421 int first_slice_line; ///< used in MPEG-4 too to handle resync markers
422 int flipflop_rounding;
423 int msmpeg4_version; ///< 0=not msmpeg4, 1=mp41, 2=mp42, 3=mp43/divx3 4=wmv1/7 5=wmv2/8
424 int per_mb_rl_table;
425 int esc3_level_length;
426 int esc3_run_length;
427 int inter_intra_pred;
428 int mspel;
429
430 /* decompression specific */
431 GetBitContext gb;
432
433 /* MPEG-1 specific */
434 int last_mv_dir; ///< last mv_dir, used for B-frame encoding
435 int vbv_delay_pos; ///< offset of vbv_delay in the bitstream
436
437 /* MPEG-2-specific - I wished not to have to support this mess. */
438 int progressive_sequence;
439 int mpeg_f_code[2][2];
440
441 // picture structure defines are loaded from mpegutils.h
442 int picture_structure;
443
444 int intra_dc_precision;
445 int frame_pred_frame_dct;
446 int top_field_first;
447 int concealment_motion_vectors;
448 int q_scale_type;
449 int brd_scale;
450 int intra_vlc_format;
451 int alternate_scan;
452 int repeat_first_field;
453 int chroma_420_type;
454 int chroma_format;
455 #define CHROMA_420 1
456 #define CHROMA_422 2
457 #define CHROMA_444 3
458 int chroma_x_shift;//depend on pix_format, that depend on chroma_format
459 int chroma_y_shift;
460
461 int progressive_frame;
462 int full_pel[2];
463 int interlaced_dct;
464 int first_field; ///< is 1 for the first field of a field picture 0 otherwise
465
466 /* RTP specific */
467 int rtp_mode;
468 int rtp_payload_size;
469
470 uint8_t *ptr_lastgob;
471 int16_t (*pblocks[12])[64];
472
473 int16_t (*block)[64]; ///< points to one of the following blocks
474 int16_t (*blocks)[12][64]; // for HQ mode we need to keep the best block
475 int (*decode_mb)(struct MpegEncContext *s, int16_t block[12][64]); // used by some codecs to avoid a switch()
476
477 #define SLICE_OK 0
478 #define SLICE_ERROR -1
479 #define SLICE_END -2 ///<end marker found
480 #define SLICE_NOEND -3 ///<no end marker or error found but mb count exceeded
481
482 void (*dct_unquantize_mpeg1_intra)(struct MpegEncContext *s,
483 int16_t *block/*align 16*/, int n, int qscale);
484 void (*dct_unquantize_mpeg1_inter)(struct MpegEncContext *s,
485 int16_t *block/*align 16*/, int n, int qscale);
486 void (*dct_unquantize_mpeg2_intra)(struct MpegEncContext *s,
487 int16_t *block/*align 16*/, int n, int qscale);
488 void (*dct_unquantize_mpeg2_inter)(struct MpegEncContext *s,
489 int16_t *block/*align 16*/, int n, int qscale);
490 void (*dct_unquantize_h263_intra)(struct MpegEncContext *s,
491 int16_t *block/*align 16*/, int n, int qscale);
492 void (*dct_unquantize_h263_inter)(struct MpegEncContext *s,
493 int16_t *block/*align 16*/, int n, int qscale);
494 void (*dct_unquantize_intra)(struct MpegEncContext *s, // unquantizer to use (MPEG-4 can use both)
495 int16_t *block/*align 16*/, int n, int qscale);
496 void (*dct_unquantize_inter)(struct MpegEncContext *s, // unquantizer to use (MPEG-4 can use both)
497 int16_t *block/*align 16*/, int n, int qscale);
498 int (*dct_quantize)(struct MpegEncContext *s, int16_t *block/*align 16*/, int n, int qscale, int *overflow);
499 int (*fast_dct_quantize)(struct MpegEncContext *s, int16_t *block/*align 16*/, int n, int qscale, int *overflow);
500 void (*denoise_dct)(struct MpegEncContext *s, int16_t *block);
501
502 int mpv_flags; ///< flags set by private options
503 int quantizer_noise_shaping;
504
505 /**
506 * ratecontrol qmin qmax limiting method
507 * 0-> clipping, 1-> use a nice continuous function to limit qscale within qmin/qmax.
508 */
509 float rc_qsquish;
510 float rc_qmod_amp;
511 int rc_qmod_freq;
512 float rc_initial_cplx;
513 float rc_buffer_aggressivity;
514 float border_masking;
515 int lmin, lmax;
516 int vbv_ignore_qmax;
517
518 char *rc_eq;
519
520 /* temp buffers for rate control */
521 float *cplx_tab, *bits_tab;
522
523 /* flag to indicate a reinitialization is required, e.g. after
524 * a frame size change */
525 int context_reinit;
526
527 ERContext er;
528
529 int error_rate;
530
531 /* temporary frames used by b_frame_strategy = 2 */
532 AVFrame *tmp_frames[MAX_B_FRAMES + 2];
533 int b_frame_strategy;
534 int b_sensitivity;
535
536 /* frame skip options for encoding */
537 int frame_skip_threshold;
538 int frame_skip_factor;
539 int frame_skip_exp;
540 int frame_skip_cmp;
541
542 int scenechange_threshold;
543 int noise_reduction;
544
545 int intra_penalty;
546 } MpegEncContext;
547
548
549 /**
550 * Set the given MpegEncContext to common defaults (same for encoding
551 * and decoding). The changed fields will not depend upon the prior
552 * state of the MpegEncContext.
553 */
554 void ff_mpv_common_defaults(MpegEncContext *s);
555
556 int ff_mpv_common_init(MpegEncContext *s);
557 void ff_mpv_common_init_arm(MpegEncContext *s);
558 void ff_mpv_common_init_axp(MpegEncContext *s);
559 void ff_mpv_common_init_neon(MpegEncContext *s);
560 void ff_mpv_common_init_ppc(MpegEncContext *s);
561 void ff_mpv_common_init_x86(MpegEncContext *s);
562 void ff_mpv_common_init_mips(MpegEncContext *s);
563 /**
564 * Initialize an MpegEncContext's thread contexts. Presumes that
565 * slice_context_count is already set and that all the fields
566 * that are freed/reset in free_duplicate_context() are NULL.
567 */
568 int ff_mpv_init_duplicate_contexts(MpegEncContext *s);
569 /**
570 * Initialize and allocates MpegEncContext fields dependent on the resolution.
571 */
572 int ff_mpv_init_context_frame(MpegEncContext *s);
573 /**
574 * Frees and resets MpegEncContext fields depending on the resolution
575 * as well as the slice thread contexts.
576 * Is used during resolution changes to avoid a full reinitialization of the
577 * codec.
578 */
579 void ff_mpv_free_context_frame(MpegEncContext *s);
580
581 void ff_mpv_common_end(MpegEncContext *s);
582
583 void ff_clean_intra_table_entries(MpegEncContext *s);
584
585 int ff_update_duplicate_context(MpegEncContext *dst, const MpegEncContext *src);
586 void ff_set_qscale(MpegEncContext * s, int qscale);
587
588 void ff_mpv_idct_init(MpegEncContext *s);
589 void ff_init_scantable(const uint8_t *permutation, ScanTable *st,
590 const uint8_t *src_scantable);
591 void ff_init_block_index(MpegEncContext *s);
592
593 void ff_mpv_motion(MpegEncContext *s,
594 uint8_t *dest_y, uint8_t *dest_cb,
595 uint8_t *dest_cr, int dir,
596 uint8_t *const *ref_picture,
597 op_pixels_func (*pix_op)[4],
598 qpel_mc_func (*qpix_op)[16]);
599
600 7065657 static inline void ff_update_block_index(MpegEncContext *s, int bits_per_raw_sample,
601 int lowres, int chroma_x_shift)
602 {
603
2/2
✓ Branch 0 taken 1350 times.
✓ Branch 1 taken 7064307 times.
7065657 const int bytes_per_pixel = 1 + (bits_per_raw_sample > 8);
604 7065657 const int block_size = (8 * bytes_per_pixel) >> lowres;
605
606 7065657 s->block_index[0]+=2;
607 7065657 s->block_index[1]+=2;
608 7065657 s->block_index[2]+=2;
609 7065657 s->block_index[3]+=2;
610 7065657 s->block_index[4]++;
611 7065657 s->block_index[5]++;
612 7065657 s->dest[0]+= 2*block_size;
613 7065657 s->dest[1] += (2 >> chroma_x_shift) * block_size;
614 7065657 s->dest[2] += (2 >> chroma_x_shift) * block_size;
615 7065657 }
616
617 #endif /* AVCODEC_MPEGVIDEO_H */
618