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