FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/mpegvideo.h
Date: 2025-03-08 20:38:41
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 AVRefStructPool *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 last_pict_type; //FIXME removes
208 int last_non_b_pict_type; ///< used for MPEG-4 gmc B-frames & ratecontrol
209 int droppable;
210 int last_lambda_for[5]; ///< last lambda for a specific pict type
211 int skipdct; ///< skip dct and code zero residual
212
213 /* motion compensation */
214 int unrestricted_mv; ///< mv can point outside of the coded picture
215 int h263_long_vectors; ///< use horrible H.263v1 long vector mode
216
217 BlockDSPContext bdsp;
218 FDCTDSPContext fdsp;
219 H264ChromaContext h264chroma;
220 HpelDSPContext hdsp;
221 IDCTDSPContext idsp;
222 MpegvideoEncDSPContext mpvencdsp;
223 PixblockDSPContext pdsp;
224 QpelDSPContext qdsp;
225 VideoDSPContext vdsp;
226 H263DSPContext h263dsp;
227 int f_code; ///< forward MV resolution
228 int b_code; ///< backward MV resolution for B-frames (MPEG-4)
229 int16_t (*p_mv_table_base)[2];
230 int16_t (*b_forw_mv_table_base)[2];
231 int16_t (*b_back_mv_table_base)[2];
232 int16_t (*b_bidir_forw_mv_table_base)[2];
233 int16_t (*b_bidir_back_mv_table_base)[2];
234 int16_t (*b_direct_mv_table_base)[2];
235 int16_t (*p_field_mv_table_base)[2];
236 int16_t (*b_field_mv_table_base)[2];
237 int16_t (*p_mv_table)[2]; ///< MV table (1MV per MB) P-frame encoding
238 int16_t (*b_forw_mv_table)[2]; ///< MV table (1MV per MB) forward mode B-frame encoding
239 int16_t (*b_back_mv_table)[2]; ///< MV table (1MV per MB) backward mode B-frame encoding
240 int16_t (*b_bidir_forw_mv_table)[2]; ///< MV table (1MV per MB) bidir mode B-frame encoding
241 int16_t (*b_bidir_back_mv_table)[2]; ///< MV table (1MV per MB) bidir mode B-frame encoding
242 int16_t (*b_direct_mv_table)[2]; ///< MV table (1MV per MB) direct mode B-frame encoding
243 int16_t (*p_field_mv_table[2][2])[2]; ///< MV table (2MV per MB) interlaced P-frame encoding
244 int16_t (*b_field_mv_table[2][2][2])[2];///< MV table (4MV per MB) interlaced B-frame encoding
245 uint8_t (*p_field_select_table[2]); ///< Only the first element is allocated
246 uint8_t (*b_field_select_table[2][2]); ///< Only the first element is allocated
247
248 /* The following fields are encoder-only */
249 uint16_t *mb_var; ///< Table for MB variances
250 uint16_t *mc_mb_var; ///< Table for motion compensated MB variances
251 uint8_t *mb_mean; ///< Table for MB luminance
252 int64_t mb_var_sum; ///< sum of MB variance for current frame
253 int64_t mc_mb_var_sum; ///< motion compensated MB variance for current frame
254 uint64_t encoding_error[MPV_MAX_PLANES];
255
256 int motion_est; ///< ME algorithm
257 int me_penalty_compensation;
258 int me_pre; ///< prepass for motion estimation
259 int mv_dir;
260 #define MV_DIR_FORWARD 1
261 #define MV_DIR_BACKWARD 2
262 #define MV_DIRECT 4 ///< bidirectional mode where the difference equals the MV of the last P/S/I-Frame (MPEG-4)
263 int mv_type;
264 #define MV_TYPE_16X16 0 ///< 1 vector for the whole mb
265 #define MV_TYPE_8X8 1 ///< 4 vectors (H.263, MPEG-4 4MV)
266 #define MV_TYPE_16X8 2 ///< 2 vectors, one per 16x8 block
267 #define MV_TYPE_FIELD 3 ///< 2 vectors, one per field
268 #define MV_TYPE_DMV 4 ///< 2 vectors, special mpeg2 Dual Prime Vectors
269 /**motion vectors for a macroblock
270 first coordinate : 0 = forward 1 = backward
271 second " : depend on type
272 third " : 0 = x, 1 = y
273 */
274 int mv[2][4][2];
275 int field_select[2][2];
276 int last_mv[2][2][2]; ///< last MV, used for MV prediction in MPEG-1 & B-frame MPEG-4
277 const uint8_t *fcode_tab; ///< smallest fcode needed for each MV
278 int16_t direct_scale_mv[2][64]; ///< precomputed to avoid divisions in ff_mpeg4_set_direct_mv
279
280 MotionEstContext me;
281
282 int no_rounding; /**< apply no rounding to motion compensation (MPEG-4, msmpeg4, ...)
283 for B-frames rounding mode is always 0 */
284
285 /* macroblock layer */
286 int mb_x, mb_y;
287 int mb_skip_run;
288 int mb_intra;
289 uint16_t *mb_type; ///< Table for candidate MB types for encoding (defines in mpegvideoenc.h)
290
291 int block_index[6]; ///< index to current MB in block based arrays with edges
292 int block_wrap[6];
293 uint8_t *dest[3];
294
295 int *mb_index2xy; ///< mb_index -> mb_x + mb_y*mb_stride
296
297 /** matrix transmitted in the bitstream */
298 uint16_t intra_matrix[64];
299 uint16_t chroma_intra_matrix[64];
300 uint16_t inter_matrix[64];
301 uint16_t chroma_inter_matrix[64];
302
303 int intra_quant_bias; ///< bias for the quantizer
304 int inter_quant_bias; ///< bias for the quantizer
305 int min_qcoeff; ///< minimum encodable coefficient
306 int max_qcoeff; ///< maximum encodable coefficient
307 int ac_esc_length; ///< num of bits needed to encode the longest esc
308 uint8_t *intra_ac_vlc_length;
309 uint8_t *intra_ac_vlc_last_length;
310 uint8_t *intra_chroma_ac_vlc_length;
311 uint8_t *intra_chroma_ac_vlc_last_length;
312 uint8_t *inter_ac_vlc_length;
313 uint8_t *inter_ac_vlc_last_length;
314 uint8_t *luma_dc_vlc_length;
315
316 int coded_score[12];
317
318 /** precomputed matrix (combine qscale and DCT renorm) */
319 int (*q_intra_matrix)[64];
320 int (*q_chroma_intra_matrix)[64];
321 int (*q_inter_matrix)[64];
322 /** identical to the above but for MMX & these are not permutated, second 64 entries are bias*/
323 uint16_t (*q_intra_matrix16)[2][64];
324 uint16_t (*q_chroma_intra_matrix16)[2][64];
325 uint16_t (*q_inter_matrix16)[2][64];
326
327 /* noise reduction */
328 int (*dct_error_sum)[64];
329 int dct_count[2];
330 uint16_t (*dct_offset)[64];
331
332 /* bit rate control */
333 int64_t total_bits;
334 int frame_bits; ///< bits used for the current frame
335 int stuffing_bits; ///< bits used for stuffing
336 int next_lambda; ///< next lambda used for retrying to encode a frame
337 RateControlContext rc_context; ///< contains stuff only accessed in ratecontrol.c
338
339 /* statistics, used for 2-pass encoding */
340 int mv_bits;
341 int header_bits;
342 int i_tex_bits;
343 int p_tex_bits;
344 int i_count;
345 int misc_bits; ///< cbp, mb_type
346 int last_bits; ///< temp var used for calculating the above vars
347
348 /* error concealment / resync */
349 int resync_mb_x; ///< x position of last resync marker
350 int resync_mb_y; ///< y position of last resync marker
351 GetBitContext last_resync_gb; ///< used to search for the next resync marker
352 int mb_num_left; ///< number of MBs left in this video packet (for partitioned Slices only)
353
354 /* H.263 specific */
355 int gob_index;
356 int obmc; ///< overlapped block motion compensation
357 int mb_info; ///< interval for outputting info about mb offsets as side data
358 int prev_mb_info, last_mb_info;
359 uint8_t *mb_info_ptr;
360 int mb_info_size;
361 int ehc_mode;
362
363 /* H.263+ specific */
364 int umvplus; ///< == H.263+ && unrestricted_mv
365 int h263_aic_dir; ///< AIC direction: 0 = left, 1 = top
366 int h263_slice_structured;
367 int alt_inter_vlc; ///< alternative inter vlc
368 int modified_quant;
369 int loop_filter;
370 int custom_pcf;
371
372 /* MPEG-4 specific */
373 int studio_profile;
374 int dct_precision;
375 ///< number of bits to represent the fractional part of time (encoder only)
376 int time_increment_bits;
377 int last_time_base;
378 int time_base; ///< time in seconds of last I,P,S Frame
379 int64_t time; ///< time of current frame
380 int64_t last_non_b_time;
381 uint16_t pp_time; ///< time distance between the last 2 p,s,i frames
382 uint16_t pb_time; ///< time distance between the last b and p,s,i frame
383 uint16_t pp_field_time;
384 uint16_t pb_field_time; ///< like above, just for interlaced
385 int mcsel;
386 int quarter_sample; ///< 1->qpel, 0->half pel ME/MC
387 int data_partitioning; ///< data partitioning flag from header
388 int partitioned_frame; ///< is current frame partitioned
389 int low_delay; ///< no reordering needed / has no B-frames
390 PutBitContext tex_pb; ///< used for data partitioned VOPs
391 PutBitContext pb2; ///< used for data partitioned VOPs
392 int mpeg_quant;
393 int padding_bug_score; ///< used to detect the VERY common padding bug in MPEG-4
394
395 /* divx specific, used to workaround (many) bugs in divx5 */
396 int divx_packed;
397
398 /* RV10 specific */
399 int rv10_version; ///< RV10 version: 0 or 3
400 int rv10_first_dc_coded[3];
401
402 /* MJPEG specific */
403 struct MJpegContext *mjpeg_ctx;
404 int esc_pos;
405
406 /* MSMPEG4 specific */
407 int mv_table_index;
408 int rl_table_index;
409 int rl_chroma_table_index;
410 int dc_table_index;
411 int use_skip_mb_code;
412 int slice_height; ///< in macroblocks
413 int first_slice_line; ///< used in MPEG-4 too to handle resync markers
414 int flipflop_rounding;
415 enum {
416 MSMP4_UNUSED,
417 MSMP4_V1,
418 MSMP4_V2,
419 MSMP4_V3,
420 MSMP4_WMV1,
421 MSMP4_WMV2,
422 MSMP4_VC1, ///< for VC1 (image), WMV3 (image) and MSS2.
423 } msmpeg4_version;
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
472 int16_t (*block)[64]; ///< points to one of the following blocks
473 int16_t (*blocks)[12][64]; // for HQ mode we need to keep the best block
474 int (*decode_mb)(struct MpegEncContext *s, int16_t block[12][64]); // used by some codecs to avoid a switch()
475
476 #define SLICE_OK 0
477 #define SLICE_ERROR -1
478 #define SLICE_END -2 ///<end marker found
479 #define SLICE_NOEND -3 ///<no end marker or error found but mb count exceeded
480
481 void (*dct_unquantize_mpeg1_intra)(struct MpegEncContext *s,
482 int16_t *block/*align 16*/, int n, int qscale);
483 void (*dct_unquantize_mpeg1_inter)(struct MpegEncContext *s,
484 int16_t *block/*align 16*/, int n, int qscale);
485 void (*dct_unquantize_mpeg2_intra)(struct MpegEncContext *s,
486 int16_t *block/*align 16*/, int n, int qscale);
487 void (*dct_unquantize_mpeg2_inter)(struct MpegEncContext *s,
488 int16_t *block/*align 16*/, int n, int qscale);
489 void (*dct_unquantize_h263_intra)(struct MpegEncContext *s,
490 int16_t *block/*align 16*/, int n, int qscale);
491 void (*dct_unquantize_h263_inter)(struct MpegEncContext *s,
492 int16_t *block/*align 16*/, int n, int qscale);
493 void (*dct_unquantize_intra)(struct MpegEncContext *s, // unquantizer to use (MPEG-4 can use both)
494 int16_t *block/*align 16*/, int n, int qscale);
495 void (*dct_unquantize_inter)(struct MpegEncContext *s, // unquantizer to use (MPEG-4 can use both)
496 int16_t *block/*align 16*/, int n, int qscale);
497 int (*dct_quantize)(struct MpegEncContext *s, int16_t *block/*align 16*/, int n, int qscale, int *overflow);
498 void (*denoise_dct)(struct MpegEncContext *s, int16_t *block);
499
500 int mpv_flags; ///< flags set by private options
501 int quantizer_noise_shaping;
502
503 me_cmp_func ildct_cmp[2]; ///< 0 = intra, 1 = non-intra
504 me_cmp_func n_sse_cmp[2]; ///< either SSE or NSSE cmp func
505 me_cmp_func sad_cmp[2];
506 me_cmp_func sse_cmp[2];
507 int (*sum_abs_dctelem)(const int16_t *block);
508
509 float border_masking;
510 int lmin, lmax;
511 int vbv_ignore_qmax;
512
513 /* flag to indicate a reinitialization is required, e.g. after
514 * a frame size change */
515 int context_reinit;
516
517 ERContext er;
518
519 int error_rate;
520
521 /* temporary frames used by b_frame_strategy = 2 */
522 AVFrame *tmp_frames[MAX_B_FRAMES + 2];
523 int b_frame_strategy;
524 int b_sensitivity;
525
526 /* frame skip options for encoding */
527 int frame_skip_threshold;
528 int frame_skip_factor;
529 int frame_skip_exp;
530 int frame_skip_cmp;
531 me_cmp_func frame_skip_cmp_fn;
532
533 int scenechange_threshold;
534 int noise_reduction;
535
536 int intra_penalty;
537 } MpegEncContext;
538
539
540 /**
541 * Set the given MpegEncContext to common defaults (same for encoding
542 * and decoding). The changed fields will not depend upon the prior
543 * state of the MpegEncContext.
544 */
545 void ff_mpv_common_defaults(MpegEncContext *s);
546
547 int ff_mpv_common_init(MpegEncContext *s);
548 void ff_mpv_common_init_arm(MpegEncContext *s);
549 void ff_mpv_common_init_neon(MpegEncContext *s);
550 void ff_mpv_common_init_ppc(MpegEncContext *s);
551 void ff_mpv_common_init_x86(MpegEncContext *s);
552 void ff_mpv_common_init_mips(MpegEncContext *s);
553 /**
554 * Initialize an MpegEncContext's thread contexts. Presumes that
555 * slice_context_count is already set and that all the fields
556 * that are freed/reset in free_duplicate_context() are NULL.
557 */
558 int ff_mpv_init_duplicate_contexts(MpegEncContext *s);
559 /**
560 * Initialize and allocates MpegEncContext fields dependent on the resolution.
561 */
562 int ff_mpv_init_context_frame(MpegEncContext *s);
563 /**
564 * Frees and resets MpegEncContext fields depending on the resolution
565 * as well as the slice thread contexts.
566 * Is used during resolution changes to avoid a full reinitialization of the
567 * codec.
568 */
569 void ff_mpv_free_context_frame(MpegEncContext *s);
570
571 void ff_mpv_common_end(MpegEncContext *s);
572
573 void ff_clean_intra_table_entries(MpegEncContext *s);
574
575 int ff_update_duplicate_context(MpegEncContext *dst, const MpegEncContext *src);
576 void ff_set_qscale(MpegEncContext * s, int qscale);
577
578 void ff_mpv_idct_init(MpegEncContext *s);
579 void ff_init_scantable(const uint8_t *permutation, ScanTable *st,
580 const uint8_t *src_scantable);
581 void ff_init_block_index(MpegEncContext *s);
582
583 void ff_mpv_motion(MpegEncContext *s,
584 uint8_t *dest_y, uint8_t *dest_cb,
585 uint8_t *dest_cr, int dir,
586 uint8_t *const *ref_picture,
587 const op_pixels_func (*pix_op)[4],
588 const qpel_mc_func (*qpix_op)[16]);
589
590 6752801 static inline void ff_update_block_index(MpegEncContext *s, int bits_per_raw_sample,
591 int lowres, int chroma_x_shift)
592 {
593
2/2
✓ Branch 0 taken 1350 times.
✓ Branch 1 taken 6751451 times.
6752801 const int bytes_per_pixel = 1 + (bits_per_raw_sample > 8);
594 6752801 const int block_size = (8 * bytes_per_pixel) >> lowres;
595
596 6752801 s->block_index[0]+=2;
597 6752801 s->block_index[1]+=2;
598 6752801 s->block_index[2]+=2;
599 6752801 s->block_index[3]+=2;
600 6752801 s->block_index[4]++;
601 6752801 s->block_index[5]++;
602 6752801 s->dest[0]+= 2*block_size;
603 6752801 s->dest[1] += (2 >> chroma_x_shift) * block_size;
604 6752801 s->dest[2] += (2 >> chroma_x_shift) * block_size;
605 6752801 }
606
607 #endif /* AVCODEC_MPEGVIDEO_H */
608