libavcodec/mpegvideo.h
de6d9b64
 /*
  * Generic DCT based hybrid video encoder
406792e7
  * Copyright (c) 2000, 2001, 2002 Fabrice Bellard
8f2ab833
  * Copyright (c) 2002-2004 Michael Niedermayer
de6d9b64
  *
b78e7197
  * This file is part of FFmpeg.
  *
  * FFmpeg is free software; you can redistribute it and/or
ff4ec49e
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation; either
b78e7197
  * version 2.1 of the License, or (at your option) any later version.
de6d9b64
  *
b78e7197
  * FFmpeg is distributed in the hope that it will be useful,
de6d9b64
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
ff4ec49e
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
de6d9b64
  *
ff4ec49e
  * You should have received a copy of the GNU Lesser General Public
b78e7197
  * License along with FFmpeg; if not, write to the Free Software
5509bffa
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
de6d9b64
  */
 
983e3246
 /**
ba87f080
  * @file
983e3246
  * mpegvideo header.
  */
115329f1
 
98790382
 #ifndef AVCODEC_MPEGVIDEO_H
 #define AVCODEC_MPEGVIDEO_H
cd4af68a
 
946f9535
 #include <float.h>
 
657ccb5a
 #include "avcodec.h"
e74433a8
 #include "blockdsp.h"
54974c62
 #include "error_resilience.h"
a9aee08d
 #include "fdctdsp.h"
9106a698
 #include "get_bits.h"
c4e394e4
 #include "h264chroma.h"
0338c396
 #include "h263dsp.h"
4ba5dbc0
 #include "hpeldsp.h"
e3fcb143
 #include "idctdsp.h"
21c90d86
 #include "internal.h"
2d604443
 #include "me_cmp.h"
149fa0b7
 #include "motion_est.h"
7061bf09
 #include "mpegpicture.h"
fab9df63
 #include "mpegvideodsp.h"
8d686ca5
 #include "mpegvideoencdsp.h"
f9d3841a
 #include "mpegvideodata.h"
f46bb608
 #include "pixblockdsp.h"
b2755007
 #include "put_bits.h"
0de9926f
 #include "ratecontrol.h"
4067d81b
 #include "parser.h"
925b80d6
 #include "mpegutils.h"
3bfe9260
 #include "mpeg12data.h"
368f5035
 #include "qpeldsp.h"
759001c5
 #include "thread.h"
8c53d39e
 #include "videodsp.h"
5c91a675
 
ed019b8e
 #include "libavutil/opt.h"
a41bf09d
 #include "libavutil/timecode.h"
ed019b8e
 
cb982739
 #define MAX_THREADS 32
45870f57
 
aa241229
 #define MAX_B_FRAMES 16
 
7f50d4ac
 /* Start codes. */
 #define SEQ_END_CODE            0x000001b7
 #define SEQ_START_CODE          0x000001b3
 #define GOP_START_CODE          0x000001b8
 #define PICTURE_START_CODE      0x00000100
 #define SLICE_MIN_START_CODE    0x00000101
 #define SLICE_MAX_START_CODE    0x000001af
 #define EXT_START_CODE          0x000001b5
 #define USER_START_CODE         0x000001b2
f9d3841a
 #define SLICE_START_CODE        0x000001b7
 
7f50d4ac
 
277f4827
 /**
  * MpegEncContext.
  */
de6d9b64
 typedef struct MpegEncContext {
297d9cb3
     AVClass *class;
6a13505c
 
     int y_dc_scale, c_dc_scale;
     int ac_pred;
     int block_last_index[12];  ///< last non zero coefficient in block
41ed7ab4
     int h263_aic;              ///< Advanced INTRA Coding (AIC)
6a13505c
 
     /* scantables */
41ed7ab4
     ScanTable inter_scantable; ///< if inter == intra then intra should be used to reduce the cache usage
6a13505c
     ScanTable intra_scantable;
     ScanTable intra_h_scantable;
     ScanTable intra_v_scantable;
 
     /* WARNING: changes above this line require updates to hardcoded
41ed7ab4
      *          offsets used in ASM. */
6a13505c
 
58f26ba9
     struct AVCodecContext *avctx;
de6d9b64
     /* the following parameters must be initialized before encoding */
115329f1
     int width, height;///< picture size. must be a multiple of 16
de6d9b64
     int gop_size;
115329f1
     int intra_only;   ///< if true, only intra pictures are generated
d9b56895
     int64_t bit_rate; ///< wanted bit rate
115329f1
     enum OutputFormat out_format; ///< output format
41ed7ab4
     int h263_pred;    ///< use MPEG-4/H.263 ac/dc predictions
     int pb_frame;     ///< PB-frame mode (0 = none, 1 = base, 2 = improved)
d7e9533a
 
 /* the following codec id fields are deprecated in favor of codec_id */
41ed7ab4
     int h263_plus;    ///< H.263+ headers
     int h263_flv;     ///< use flv H.263 header
115329f1
 
36ef5369
     enum AVCodecID codec_id;     /* see AV_CODEC_ID_xxx */
115329f1
     int fixed_qscale; ///< fixed qscale if non zero
     int encoding;     ///< true if we are encoding (vs decoding)
41ed7ab4
     int max_b_frames; ///< max number of B-frames for encoding
7f2fe444
     int luma_elim_threshold;
     int chroma_elim_threshold;
41ed7ab4
     int strict_std_compliance; ///< strictly follow the std (MPEG-4, ...)
115329f1
     int workaround_bugs;       ///< workaround bugs in encoders which cannot be detected automatically
17662955
     int codec_tag;             ///< internal codec_tag upper case converted from avctx codec_tag
de6d9b64
     /* the following fields are managed internally by the encoder */
 
     /* sequence parameters */
     int context_initialized;
755bfeab
     int input_picture_number;  ///< used to set pic->display_picture_number, should not be used for/by anything else
     int coded_picture_number;  ///< used to set pic->coded_picture_number, should not be used for/by anything else
1031fabd
     int picture_number;       //FIXME remove, unclear definition
115329f1
     int picture_in_gop_number; ///< 0-> first pic in gop, ...
     int mb_width, mb_height;   ///< number of MBs horizontally & vertically
bb628dae
     int mb_stride;             ///< mb_width+1 used for some arrays to allow simple addressing of left & top MBs without sig11
     int b8_stride;             ///< 2*mb_width+1 used for some 8x8 block arrays to allow simple addressing
     int h_edge_pos, v_edge_pos;///< horizontal / vertical position of the right/bottom edge (pixel replication)
115329f1
     int mb_num;                ///< number of MBs of a picture
c341f734
     ptrdiff_t linesize;        ///< line size, in bytes, may be different from width
     ptrdiff_t uvlinesize;      ///< line size, for chroma in bytes, may be different from width
115329f1
     Picture *picture;          ///< main picture buffer
9d9e3172
     Picture **input_picture;   ///< next pictures on display order for encoding
41ed7ab4
     Picture **reordered_input_picture; ///< pointer to the next pictures in coded order for encoding
115329f1
 
187105ff
     int64_t user_specified_pts; ///< last non-zero pts from AVFrame which was passed into avcodec_encode_video2()
445a7d48
     /**
      * pts difference between the first and second input frame, used for
      * calculating dts of the first frame when there's a delay */
     int64_t dts_delta;
     /**
      * reordered pts to be used as dts for the next output frame when there's
      * a delay */
     int64_t reordered_pts;
d0a2f0af
 
451b4b86
     /** bit output */
     PutBitContext pb;
 
9c3d33d6
     int start_mb_y;            ///< start mb_y of this thread (so current thread should process start_mb_y <= row < end_mb_y)
     int end_mb_y;              ///< end   mb_y of this thread (so current thread should process start_mb_y <= row < end_mb_y)
     struct MpegEncContext *thread_context[MAX_THREADS];
881a5e04
     int slice_context_count;   ///< number of used thread_contexts
115329f1
 
     /**
b536d0aa
      * copy of the previous picture structure.
      * note, linesize & data, might not match the previous picture (for field pictures)
      */
115329f1
     Picture last_picture;
 
     /**
b536d0aa
      * copy of the next picture structure.
      * note, linesize & data, might not match the next picture (for field pictures)
      */
     Picture next_picture;
115329f1
 
     /**
b536d0aa
      * copy of the source picture structure for encoding.
      * note, linesize & data, might not match the source picture (for field pictures)
      */
     Picture new_picture;
115329f1
 
     /**
b536d0aa
      * copy of the current picture structure.
      * note, linesize & data, might not match the current picture (for field pictures)
      */
115329f1
     Picture current_picture;    ///< buffer to store the decompressed current picture
 
b536d0aa
     Picture *last_picture_ptr;     ///< pointer to the previous picture.
115329f1
     Picture *next_picture_ptr;     ///< pointer to the next picture (for bidir pred)
b536d0aa
     Picture *current_picture_ptr;  ///< pointer to the current picture
41ed7ab4
     int last_dc[3];                ///< last DC values for MPEG-1
b86216de
     int16_t *dc_val_base;
41ed7ab4
     int16_t *dc_val[3];            ///< used for MPEG-4 DC prediction, all 3 arrays must be continuous
115329f1
     const uint8_t *y_dc_scale_table;     ///< qscale -> y_dc_scale table
     const uint8_t *c_dc_scale_table;     ///< qscale -> c_dc_scale table
41ed7ab4
     const uint8_t *chroma_qscale_table;  ///< qscale -> chroma_qscale (H.263)
137c8468
     uint8_t *coded_block_base;
277f4827
     uint8_t *coded_block;          ///< used for coded block pattern prediction (msmpeg4v3, wmv1)
137c8468
     int16_t (*ac_val_base)[16];
8ef57a0d
     int16_t (*ac_val[3])[16];      ///< used for MPEG-4 AC prediction, all 3 arrays must be continuous
115329f1
     int mb_skipped;                ///< MUST BE SET only during DECODING
     uint8_t *mbskip_table;        /**< used to avoid copy if macroblock skipped (for black regions for example)
41ed7ab4
                                    and used for B-frame encoding & decoding (contains skip table of next P-frame) */
115329f1
     uint8_t *mbintra_table;       ///< used to avoid setting {ac, dc, cbp}-pred stuff to zero on inter MB decoding
     uint8_t *cbp_table;           ///< used to store cbp, ac_pred for partitioned decoding
     uint8_t *pred_dir_table;      ///< used to store pred_dir for partitioned decoding
da0c8664
 
     ScratchpadContext sc;
de6d9b64
 
115329f1
     int qscale;                 ///< QP
     int chroma_qscale;          ///< chroma QP
41ed7ab4
     unsigned int lambda;        ///< Lagrange multiplier used in rate distortion
973cbc2a
     unsigned int lambda2;       ///< (lambda*lambda) >> FF_LAMBDA_SHIFT
158c7f05
     int *lambda_table;
115329f1
     int adaptive_quant;         ///< use adaptive quantization
     int dquant;                 ///< qscale difference to prev qscale
fe906830
     int closed_gop;             ///< MPEG1/2 GOP is closed
ce5e49b0
     int pict_type;              ///< AV_PICTURE_TYPE_I, AV_PICTURE_TYPE_P, AV_PICTURE_TYPE_B, ...
25b7aa98
     int vbv_delay;
14e2a940
     int last_pict_type; //FIXME removes
41ed7ab4
     int last_non_b_pict_type;   ///< used for MPEG-4 gmc B-frames & ratecontrol
ba0c8981
     int droppable;
de6d9b64
     int frame_rate_index;
e2143067
     AVRational mpeg2_frame_rate_ext;
88e51e1f
     int last_lambda_for[5];     ///< last lambda for a specific pict type
c52f5d66
     int skipdct;                ///< skip dct and code zero residual
5e5c247a
 
de6d9b64
     /* motion compensation */
115329f1
     int unrestricted_mv;        ///< mv can point outside of the coded picture
41ed7ab4
     int h263_long_vectors;      ///< use horrible H.263v1 long vector mode
277f4827
 
e74433a8
     BlockDSPContext bdsp;
a9aee08d
     FDCTDSPContext fdsp;
c4e394e4
     H264ChromaContext h264chroma;
4ba5dbc0
     HpelDSPContext hdsp;
e3fcb143
     IDCTDSPContext idsp;
2d604443
     MECmpContext mecc;
fab9df63
     MpegVideoDSPContext mdsp;
8d686ca5
     MpegvideoEncDSPContext mpvencdsp;
f46bb608
     PixblockDSPContext pdsp;
368f5035
     QpelDSPContext qdsp;
8c53d39e
     VideoDSPContext vdsp;
0338c396
     H263DSPContext h263dsp;
115329f1
     int f_code;                 ///< forward MV resolution
41ed7ab4
     int b_code;                 ///< backward MV resolution for B-frames (MPEG-4)
7bc9090a
     int16_t (*p_mv_table_base)[2];
     int16_t (*b_forw_mv_table_base)[2];
     int16_t (*b_back_mv_table_base)[2];
115329f1
     int16_t (*b_bidir_forw_mv_table_base)[2];
     int16_t (*b_bidir_back_mv_table_base)[2];
7bc9090a
     int16_t (*b_direct_mv_table_base)[2];
bb198e19
     int16_t (*p_field_mv_table_base[2][2])[2];
     int16_t (*b_field_mv_table_base[2][2][2])[2];
41ed7ab4
     int16_t (*p_mv_table)[2];            ///< MV table (1MV per MB) P-frame encoding
     int16_t (*b_forw_mv_table)[2];       ///< MV table (1MV per MB) forward mode B-frame encoding
     int16_t (*b_back_mv_table)[2];       ///< MV table (1MV per MB) backward mode B-frame encoding
     int16_t (*b_bidir_forw_mv_table)[2]; ///< MV table (1MV per MB) bidir mode B-frame encoding
     int16_t (*b_bidir_back_mv_table)[2]; ///< MV table (1MV per MB) bidir mode B-frame encoding
     int16_t (*b_direct_mv_table)[2];     ///< MV table (1MV per MB) direct mode B-frame encoding
     int16_t (*p_field_mv_table[2][2])[2];   ///< MV table (2MV per MB) interlaced P-frame encoding
     int16_t (*b_field_mv_table[2][2][2])[2];///< MV table (4MV per MB) interlaced B-frame encoding
bb198e19
     uint8_t (*p_field_select_table[2]);
     uint8_t (*b_field_select_table[2][2]);
4b6b1082
     int motion_est;                      ///< ME algorithm
5b6f42da
     int me_penalty_compensation;
0e9c4fe2
     int me_pre;                          ///< prepass for motion estimation
de6d9b64
     int mv_dir;
653f7387
 #define MV_DIR_FORWARD   1
 #define MV_DIR_BACKWARD  2
41ed7ab4
 #define MV_DIRECT        4 ///< bidirectional mode where the difference equals the MV of the last P/S/I-Frame (MPEG-4)
de6d9b64
     int mv_type;
115329f1
 #define MV_TYPE_16X16       0   ///< 1 vector for the whole mb
41ed7ab4
 #define MV_TYPE_8X8         1   ///< 4 vectors (H.263, MPEG-4 4MV)
115329f1
 #define MV_TYPE_16X8        2   ///< 2 vectors, one per 16x8 block
 #define MV_TYPE_FIELD       3   ///< 2 vectors, one per field
 #define MV_TYPE_DMV         4   ///< 2 vectors, special mpeg2 Dual Prime Vectors
     /**motion vectors for a macroblock
de6d9b64
        first coordinate : 0 = forward 1 = backward
        second "         : depend on type
        third  "         : 0 = x, 1 = y
     */
     int mv[2][4][2];
     int field_select[2][2];
41ed7ab4
     int last_mv[2][2][2];             ///< last MV, used for MV prediction in MPEG-1 & B-frame MPEG-4
115329f1
     uint8_t *fcode_tab;               ///< smallest fcode needed for each MV
841f65f2
     int16_t direct_scale_mv[2][64];   ///< precomputed to avoid divisions in ff_mpeg4_set_direct_mv
115329f1
 
1457ab52
     MotionEstContext me;
de6d9b64
 
41ed7ab4
     int no_rounding;  /**< apply no rounding to motion compensation (MPEG-4, msmpeg4, ...)
                         for B-frames rounding mode is always 0 */
de6d9b64
 
     /* macroblock layer */
     int mb_x, mb_y;
9b8709d1
     int mb_skip_run;
de6d9b64
     int mb_intra;
e0c16e4e
     uint16_t *mb_type;  ///< Table for candidate MB types for encoding (defines in mpegutils.h)
2f16af06
 
277f4827
     int block_index[6]; ///< index to current MB in block based arrays with edges
4278e7a6
     int block_wrap[6];
7d1c3fc1
     uint8_t *dest[3];
115329f1
 
7bc9090a
     int *mb_index2xy;        ///< mb_index -> mb_x + mb_y*mb_stride
4278e7a6
 
277f4827
     /** matrix transmitted in the bitstream */
0c1a9eda
     uint16_t intra_matrix[64];
     uint16_t chroma_intra_matrix[64];
     uint16_t inter_matrix[64];
     uint16_t chroma_inter_matrix[64];
d6cfbcd6
     int force_duplicated_matrix; ///< Force duplication of mjpeg matrices, useful for rtp streaming
2b6ab3a2
 
115329f1
     int intra_quant_bias;    ///< bias for the quantizer
     int inter_quant_bias;    ///< bias for the quantizer
     int min_qcoeff;          ///< minimum encodable coefficient
     int max_qcoeff;          ///< maximum encodable coefficient
     int ac_esc_length;       ///< num of bits needed to encode the longest esc
477ab036
     uint8_t *intra_ac_vlc_length;
     uint8_t *intra_ac_vlc_last_length;
7366bb38
     uint8_t *intra_chroma_ac_vlc_length;
     uint8_t *intra_chroma_ac_vlc_last_length;
477ab036
     uint8_t *inter_ac_vlc_length;
     uint8_t *inter_ac_vlc_last_length;
67725183
     uint8_t *luma_dc_vlc_length;
c442d75c
 #define UNI_AC_ENC_INDEX(run,level) ((run)*128 + (level))
477ab036
 
9f02d4ed
     int coded_score[12];
f2f6134b
 
277f4827
     /** precomputed matrix (combine qscale and DCT renorm) */
7e4995c3
     int (*q_intra_matrix)[64];
2aaf32f5
     int (*q_chroma_intra_matrix)[64];
7e4995c3
     int (*q_inter_matrix)[64];
642ccefb
     /** identical to the above but for MMX & these are not permutated, second 64 entries are bias*/
     uint16_t (*q_intra_matrix16)[2][64];
2aaf32f5
     uint16_t (*q_chroma_intra_matrix16)[2][64];
642ccefb
     uint16_t (*q_inter_matrix16)[2][64];
115329f1
 
821cb11f
     /* noise reduction */
     int (*dct_error_sum)[64];
     int dct_count[2];
     uint16_t (*dct_offset)[64];
de6d9b64
 
     /* bit rate control */
0c1a9eda
     int64_t total_bits;
115329f1
     int frame_bits;                ///< bits used for the current frame
a990a308
     int stuffing_bits;             ///< bits used for stuffing
07506002
     int next_lambda;               ///< next lambda used for retrying to encode a frame
277f4827
     RateControlContext rc_context; ///< contains stuff only accessed in ratecontrol.c
9cdd6a24
 
098eefe1
     /* statistics, used for 2-pass encoding */
     int mv_bits;
     int header_bits;
     int i_tex_bits;
     int p_tex_bits;
     int i_count;
66370d3f
     int f_count;
     int b_count;
098eefe1
     int skip_count;
277f4827
     int misc_bits; ///< cbp, mb_type
     int last_bits; ///< temp var used for calculating the above vars
115329f1
 
7f2fe444
     /* error concealment / resync */
115329f1
     int resync_mb_x;                 ///< x position of last resync marker
     int resync_mb_y;                 ///< y position of last resync marker
     GetBitContext last_resync_gb;    ///< used to search for the next resync marker
277f4827
     int mb_num_left;                 ///< number of MBs left in this video packet (for partitioned Slices only)
41ed7ab4
     int next_p_frame_damaged;        ///< set if the next p frame is damaged, to avoid showing trashed B-frames
115329f1
 
d7425f59
     ParseContext parse_context;
098eefe1
 
102d3908
     /* H.263 specific */
644d98a4
     int gob_index;
dba019da
     int obmc;                       ///< overlapped block motion compensation
bdc1220e
     int mb_info;                    ///< interval for outputting info about mb offsets as side data
     int prev_mb_info, last_mb_info;
     uint8_t *mb_info_ptr;
     int mb_info_size;
7495186f
     int ehc_mode;
1761ab83
     int rc_strategy;
115329f1
 
544286b3
     /* H.263+ specific */
41ed7ab4
     int umvplus;                    ///< == H.263+ && unrestricted_mv
ba58dabc
     int h263_aic_dir;               ///< AIC direction: 0 = left, 1 = top
     int h263_slice_structured;
dba019da
     int alt_inter_vlc;              ///< alternative inter vlc
68b94c35
     int modified_quant;
115329f1
     int loop_filter;
b056e73c
     int custom_pcf;
115329f1
 
41ed7ab4
     /* MPEG-4 specific */
f9d3841a
     int studio_profile;
     int dct_precision;
e62a43f6
     ///< number of bits to represent the fractional part of time (encoder only)
     int time_increment_bits;
9dbcbd92
     int last_time_base;
115329f1
     int time_base;                  ///< time in seconds of last I,P,S Frame
     int64_t time;                   ///< time of current frame
0c1a9eda
     int64_t last_non_b_time;
115329f1
     uint16_t pp_time;               ///< time distance between the last 2 p,s,i frames
     uint16_t pb_time;               ///< time distance between the last b and p,s,i frame
0c1a9eda
     uint16_t pp_field_time;
115329f1
     uint16_t pb_field_time;         ///< like above, just for interlaced
44eb4951
     int real_sprite_warping_points;
115329f1
     int sprite_offset[2][2];         ///< sprite offset[isChroma][isMVY]
     int sprite_delta[2][2];          ///< sprite_delta [isY][isMVY]
73c8e514
     int mcsel;
1a565432
     int quant_precision;
115329f1
     int quarter_sample;              ///< 1->qpel, 0->half pel ME/MC
0da71265
     int aspect_ratio_info; //FIXME remove
cc9ba006
     int sprite_warping_accuracy;
115329f1
     int data_partitioning;           ///< data partitioning flag from header
     int partitioned_frame;           ///< is current frame partitioned
41ed7ab4
     int low_delay;                   ///< no reordering needed / has no B-frames
1ff662cc
     int vo_type;
115329f1
     PutBitContext tex_pb;            ///< used for data partitioned VOPs
     PutBitContext pb2;               ///< used for data partitioned VOPs
d930ef19
     int mpeg_quant;
41ed7ab4
     int padding_bug_score;             ///< used to detect the VERY common padding bug in MPEG-4
44eb4951
 
     /* divx specific, used to workaround (many) bugs in divx5 */
d5a21172
     int divx_packed;
0c1a9eda
     uint8_t *bitstream_buffer; //Divx 5.01 puts several frames in a single one, this is used to reorder them
eec1c6b9
     int bitstream_buffer_size;
f038fe8b
     unsigned int allocated_bitstream_buffer_size;
115329f1
 
de6d9b64
     /* RV10 specific */
115329f1
     int rv10_version; ///< RV10 version: 0 or 3
de6d9b64
     int rv10_first_dc_coded[3];
115329f1
 
de6d9b64
     /* MJPEG specific */
     struct MJpegContext *mjpeg_ctx;
bb850480
     int esc_pos;
2862b637
     int pred;
884506df
     int huffman;
de6d9b64
 
     /* MSMPEG4 specific */
     int mv_table_index;
     int rl_table_index;
     int rl_chroma_table_index;
     int dc_table_index;
     int use_skip_mb_code;
115329f1
     int slice_height;      ///< in macroblocks
41ed7ab4
     int first_slice_line;  ///< used in MPEG-4 too to handle resync markers
ae40484c
     int flipflop_rounding;
277f4827
     int msmpeg4_version;   ///< 0=not msmpeg4, 1=mp41, 2=mp42, 3=mp43/divx3 4=wmv1/7 5=wmv2/8
0151a6f5
     int per_mb_rl_table;
     int esc3_level_length;
     int esc3_run_length;
277f4827
     /** [mb_intra][isChroma][level][run][last] */
6b460aa3
     int (*ac_stats)[2][MAX_LEVEL+1][MAX_RUN+1][2];
de0f2f4c
     int inter_intra_pred;
1457ab52
     int mspel;
0151a6f5
 
de6d9b64
     /* decompression specific */
     GetBitContext gb;
 
41ed7ab4
     /* MPEG-1 specific */
     int gop_picture_number;  ///< index of the first picture of a GOP based on fake_pic_num & MPEG-1 specific
     int last_mv_dir;         ///< last mv_dir, used for B-frame encoding
115329f1
     uint8_t *vbv_delay_ptr;  ///< pointer to vbv_delay in the bitstream
 
7eb2d654
     /* MPEG-2-specific - I wished not to have to support this mess. */
de6d9b64
     int progressive_sequence;
     int mpeg_f_code[2][2];
e0c16e4e
 
     // picture structure defines are loaded from mpegutils.h
de6d9b64
     int picture_structure;
 
d7496153
     int64_t timecode_frame_start; ///< GOP timecode frame start number, in non drop frame format
de6d9b64
     int intra_dc_precision;
     int frame_pred_frame_dct;
     int top_field_first;
     int concealment_motion_vectors;
     int q_scale_type;
84c4714f
     int brd_scale;
de6d9b64
     int intra_vlc_format;
     int alternate_scan;
9236f7b5
     int seq_disp_ext;
ce6ce595
     int video_format;
 #define VIDEO_FORMAT_COMPONENT   0
 #define VIDEO_FORMAT_PAL         1
 #define VIDEO_FORMAT_NTSC        2
 #define VIDEO_FORMAT_SECAM       3
 #define VIDEO_FORMAT_MAC         4
 #define VIDEO_FORMAT_UNSPECIFIED 5
de6d9b64
     int repeat_first_field;
     int chroma_420_type;
5e5c247a
     int chroma_format;
 #define CHROMA_420 1
 #define CHROMA_422 2
 #define CHROMA_444 3
ffdff4d7
     int chroma_x_shift;//depend on pix_format, that depend on chroma_format
     int chroma_y_shift;
5e5c247a
 
de6d9b64
     int progressive_frame;
9c020810
     int full_pel[2];
de6d9b64
     int interlaced_dct;
c3bf0288
     int first_field;         ///< is 1 for the first field of a field picture 0 otherwise
2c5e1efc
     int drop_frame_timecode; ///< timecode is in drop frame format.
aed79007
     int scan_offset;         ///< reserve space for SVCD scan offset user data.
ba58dabc
 
644d98a4
     /* RTP specific */
e4eadb4b
     int rtp_mode;
936f0d98
     int rtp_payload_size;
115329f1
 
d8804905
     char *tc_opt_str;        ///< timecode option string
     AVTimecode tc;           ///< timecode context
52314545
 
0c1a9eda
     uint8_t *ptr_lastgob;
7eb2d654
     int swap_uv;             //vcr2 codec is an MPEG-2 variant with U and V swapped
1c63aed2
     int pack_pblocks;        //xvmc needs to keep blocks without gaps.
88bd7fdc
     int16_t (*pblocks[12])[64];
115329f1
 
88bd7fdc
     int16_t (*block)[64]; ///< points to one of the following blocks
ac898759
     int16_t (*blocks)[12][64]; // for HQ mode we need to keep the best block
f9d3841a
     int (*decode_mb)(struct MpegEncContext *s, int16_t block[12][64]); // used by some codecs to avoid a switch()
 
     int32_t (*block32)[12][64];
 
4d2858de
 #define SLICE_OK         0
 #define SLICE_ERROR     -1
c3bf0288
 #define SLICE_END       -2 ///<end marker found
 #define SLICE_NOEND     -3 ///<no end marker or error found but mb count exceeded
115329f1
 
     void (*dct_unquantize_mpeg1_intra)(struct MpegEncContext *s,
88bd7fdc
                            int16_t *block/*align 16*/, int n, int qscale);
115329f1
     void (*dct_unquantize_mpeg1_inter)(struct MpegEncContext *s,
88bd7fdc
                            int16_t *block/*align 16*/, int n, int qscale);
115329f1
     void (*dct_unquantize_mpeg2_intra)(struct MpegEncContext *s,
88bd7fdc
                            int16_t *block/*align 16*/, int n, int qscale);
115329f1
     void (*dct_unquantize_mpeg2_inter)(struct MpegEncContext *s,
88bd7fdc
                            int16_t *block/*align 16*/, int n, int qscale);
115329f1
     void (*dct_unquantize_h263_intra)(struct MpegEncContext *s,
88bd7fdc
                            int16_t *block/*align 16*/, int n, int qscale);
115329f1
     void (*dct_unquantize_h263_inter)(struct MpegEncContext *s,
88bd7fdc
                            int16_t *block/*align 16*/, int n, int qscale);
41ed7ab4
     void (*dct_unquantize_intra)(struct MpegEncContext *s, // unquantizer to use (MPEG-4 can use both)
88bd7fdc
                            int16_t *block/*align 16*/, int n, int qscale);
41ed7ab4
     void (*dct_unquantize_inter)(struct MpegEncContext *s, // unquantizer to use (MPEG-4 can use both)
88bd7fdc
                            int16_t *block/*align 16*/, int n, int qscale);
     int (*dct_quantize)(struct MpegEncContext *s, int16_t *block/*align 16*/, int n, int qscale, int *overflow);
     int (*fast_dct_quantize)(struct MpegEncContext *s, int16_t *block/*align 16*/, int n, int qscale, int *overflow);
     void (*denoise_dct)(struct MpegEncContext *s, int16_t *block);
ed019b8e
 
     int mpv_flags;      ///< flags set by private options
23bfcc06
     int quantizer_noise_shaping;
89b81a1c
 
a6e4ce9f
     /**
      * ratecontrol qmin qmax limiting method
74128352
      * 0-> clipping, 1-> use a nice continuous function to limit qscale within qmin/qmax.
a6e4ce9f
      */
     float rc_qsquish;
946f9535
     float rc_qmod_amp;
     int   rc_qmod_freq;
66a68ddd
     float rc_initial_cplx;
     float rc_buffer_aggressivity;
15ec053c
     float border_masking;
530c1441
     int lmin, lmax;
f977e69d
     int vbv_ignore_qmax;
a6e4ce9f
 
a75c2eb2
     char *rc_eq;
 
89b81a1c
     /* temp buffers for rate control */
     float *cplx_tab, *bits_tab;
8701f4f8
 
     /* flag to indicate a reinitialization is required, e.g. after
      * a frame size change */
     int context_reinit;
54974c62
 
     ERContext er;
8941971a
 
     int error_rate;
1c01b025
 
     /* temporary frames used by b_frame_strategy = 2 */
     AVFrame *tmp_frames[MAX_B_FRAMES + 2];
0e6c8532
     int b_frame_strategy;
     int b_sensitivity;
0ac9f33a
 
     /* frame skip options for encoding */
     int frame_skip_threshold;
     int frame_skip_factor;
     int frame_skip_exp;
     int frame_skip_cmp;
7c79587d
 
     int scenechange_threshold;
1482aff2
     int noise_reduction;
de6d9b64
 } MpegEncContext;
 
ed019b8e
 /* mpegvideo_enc common options */
 #define FF_MPV_FLAG_SKIP_RD      0x0001
a249f0cc
 #define FF_MPV_FLAG_STRICT_GOP   0x0002
ff71a383
 #define FF_MPV_FLAG_QP_RD        0x0004
af3d804f
 #define FF_MPV_FLAG_CBP_RD       0x0008
b2c31710
 #define FF_MPV_FLAG_NAQ          0x0010
a2941c8c
 #define FF_MPV_FLAG_MV0          0x0020
ed019b8e
 
60532348
 enum rc_strategy {
     MPV_RC_STRATEGY_FFMPEG,
     MPV_RC_STRATEGY_XVID,
     NB_MPV_RC_STRATEGY
 };
 
0ac9f33a
 #define FF_MPV_OPT_CMP_FUNC \
 { "sad",    "Sum of absolute differences, fast", 0, AV_OPT_TYPE_CONST, {.i64 = FF_CMP_SAD }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS, "cmp_func" }, \
 { "sse",    "Sum of squared errors", 0, AV_OPT_TYPE_CONST, {.i64 = FF_CMP_SSE }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS, "cmp_func" }, \
 { "satd",   "Sum of absolute Hadamard transformed differences", 0, AV_OPT_TYPE_CONST, {.i64 = FF_CMP_SATD }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS, "cmp_func" }, \
 { "dct",    "Sum of absolute DCT transformed differences", 0, AV_OPT_TYPE_CONST, {.i64 = FF_CMP_DCT }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS, "cmp_func" }, \
 { "psnr",   "Sum of squared quantization errors, low quality", 0, AV_OPT_TYPE_CONST, {.i64 = FF_CMP_PSNR }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS, "cmp_func" }, \
 { "bit",    "Number of bits needed for the block", 0, AV_OPT_TYPE_CONST, {.i64 = FF_CMP_BIT }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS, "cmp_func" }, \
 { "rd",     "Rate distortion optimal, slow", 0, AV_OPT_TYPE_CONST, {.i64 = FF_CMP_RD }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS, "cmp_func" }, \
 { "zero",   "Zero", 0, AV_OPT_TYPE_CONST, {.i64 = FF_CMP_ZERO }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS, "cmp_func" }, \
 { "vsad",   "Sum of absolute vertical differences", 0, AV_OPT_TYPE_CONST, {.i64 = FF_CMP_VSAD }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS, "cmp_func" }, \
 { "vsse",   "Sum of squared vertical differences", 0, AV_OPT_TYPE_CONST, {.i64 = FF_CMP_VSSE }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS, "cmp_func" }, \
 { "nsse",   "Noise preserving sum of squared differences", 0, AV_OPT_TYPE_CONST, {.i64 = FF_CMP_NSSE }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS, "cmp_func" }, \
 { "dct264", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = FF_CMP_DCT264 }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS, "cmp_func" }, \
 { "dctmax", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = FF_CMP_DCTMAX }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS, "cmp_func" }, \
4edd74bd
 { "chroma", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = FF_CMP_CHROMA }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS, "cmp_func" }, \
 { "msad",   "Sum of absolute differences, median predicted", 0, AV_OPT_TYPE_CONST, {.i64 = FF_CMP_MEDIAN_SAD }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS, "cmp_func" }
0ac9f33a
 
bf301258
 #ifndef FF_MPV_OFFSET
ed019b8e
 #define FF_MPV_OFFSET(x) offsetof(MpegEncContext, x)
bf301258
 #endif
ed019b8e
 #define FF_MPV_OPT_FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM)
 #define FF_MPV_COMMON_OPTS \
0ac9f33a
 FF_MPV_OPT_CMP_FUNC, \
d58dd4b5
 { "mpv_flags",      "Flags common for all mpegvideo-based encoders.", FF_MPV_OFFSET(mpv_flags), AV_OPT_TYPE_FLAGS, { .i64 = 0 }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS, "mpv_flags" },\
124134e4
 { "skip_rd",        "RD optimal MB level residual skipping", 0, AV_OPT_TYPE_CONST, { .i64 = FF_MPV_FLAG_SKIP_RD },    0, 0, FF_MPV_OPT_FLAGS, "mpv_flags" },\
 { "strict_gop",     "Strictly enforce gop size",             0, AV_OPT_TYPE_CONST, { .i64 = FF_MPV_FLAG_STRICT_GOP }, 0, 0, FF_MPV_OPT_FLAGS, "mpv_flags" },\
 { "qp_rd",          "Use rate distortion optimization for qp selection", 0, AV_OPT_TYPE_CONST, { .i64 = FF_MPV_FLAG_QP_RD },  0, 0, FF_MPV_OPT_FLAGS, "mpv_flags" },\
 { "cbp_rd",         "use rate distortion optimization for CBP",          0, AV_OPT_TYPE_CONST, { .i64 = FF_MPV_FLAG_CBP_RD }, 0, 0, FF_MPV_OPT_FLAGS, "mpv_flags" },\
b2c31710
 { "naq",            "normalize adaptive quantization",                   0, AV_OPT_TYPE_CONST, { .i64 = FF_MPV_FLAG_NAQ },    0, 0, FF_MPV_OPT_FLAGS, "mpv_flags" },\
a2941c8c
 { "mv0",            "always try a mb with mv=<0,0>",                     0, AV_OPT_TYPE_CONST, { .i64 = FF_MPV_FLAG_MV0 },    0, 0, FF_MPV_OPT_FLAGS, "mpv_flags" },\
63efd83a
 { "luma_elim_threshold",   "single coefficient elimination threshold for luminance (negative values also consider dc coefficient)",\
e6153f17
                                                                       FF_MPV_OFFSET(luma_elim_threshold), AV_OPT_TYPE_INT, { .i64 = 0 }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS },\
63efd83a
 { "chroma_elim_threshold", "single coefficient elimination threshold for chrominance (negative values also consider dc coefficient)",\
e6153f17
                                                                       FF_MPV_OFFSET(chroma_elim_threshold), AV_OPT_TYPE_INT, { .i64 = 0 }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS },\
8941971a
 { "quantizer_noise_shaping", NULL,                                  FF_MPV_OFFSET(quantizer_noise_shaping), AV_OPT_TYPE_INT, { .i64 = 0 },       0, INT_MAX, FF_MPV_OPT_FLAGS },\
 { "error_rate", "Simulate errors in the bitstream to test error concealment.",                                                                                                  \
a6e4ce9f
                                                                     FF_MPV_OFFSET(error_rate),              AV_OPT_TYPE_INT, { .i64 = 0 },       0, INT_MAX, FF_MPV_OPT_FLAGS },\
 {"qsquish", "how to keep quantizer between qmin and qmax (0 = clip, 1 = use differentiable function)",                                                                          \
946f9535
                                                                     FF_MPV_OFFSET(rc_qsquish), AV_OPT_TYPE_FLOAT, {.dbl = 0 }, 0, 99, FF_MPV_OPT_FLAGS},                        \
 {"rc_qmod_amp", "experimental quantizer modulation",                FF_MPV_OFFSET(rc_qmod_amp), AV_OPT_TYPE_FLOAT, {.dbl = 0 }, -FLT_MAX, FLT_MAX, FF_MPV_OPT_FLAGS},           \
a75c2eb2
 {"rc_qmod_freq", "experimental quantizer modulation",               FF_MPV_OFFSET(rc_qmod_freq), AV_OPT_TYPE_INT, {.i64 = 0 }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS},             \
 {"rc_eq", "Set rate control equation. When computing the expression, besides the standard functions "                                                                           \
           "defined in the section 'Expression Evaluation', the following functions are available: "                                                                             \
           "bits2qp(bits), qp2bits(qp). Also the following constants are available: iTex pTex tex mv "                                                                           \
           "fCode iCount mcVar var isI isP isB avgQP qComp avgIITex avgPITex avgPPTex avgBPTex avgTex.",                                                                         \
66a68ddd
                                                                     FF_MPV_OFFSET(rc_eq), AV_OPT_TYPE_STRING,                           .flags = FF_MPV_OPT_FLAGS },            \
 {"rc_init_cplx", "initial complexity for 1-pass encoding",          FF_MPV_OFFSET(rc_initial_cplx), AV_OPT_TYPE_FLOAT, {.dbl = 0 }, -FLT_MAX, FLT_MAX, FF_MPV_OPT_FLAGS},       \
 {"rc_buf_aggressivity", "currently useless",                        FF_MPV_OFFSET(rc_buffer_aggressivity), AV_OPT_TYPE_FLOAT, {.dbl = 1.0 }, -FLT_MAX, FLT_MAX, FF_MPV_OPT_FLAGS}, \
15ec053c
 {"border_mask", "increase the quantizer for macroblocks close to borders", FF_MPV_OFFSET(border_masking), AV_OPT_TYPE_FLOAT, {.dbl = 0 }, -FLT_MAX, FLT_MAX, FF_MPV_OPT_FLAGS},    \
530c1441
 {"lmin", "minimum Lagrange factor (VBR)",                           FF_MPV_OFFSET(lmin), AV_OPT_TYPE_INT, {.i64 =  2*FF_QP2LAMBDA }, 0, INT_MAX, FF_MPV_OPT_FLAGS },            \
 {"lmax", "maximum Lagrange factor (VBR)",                           FF_MPV_OFFSET(lmax), AV_OPT_TYPE_INT, {.i64 = 31*FF_QP2LAMBDA }, 0, INT_MAX, FF_MPV_OPT_FLAGS },            \
910247f1
 {"ibias", "intra quant bias",                                       FF_MPV_OFFSET(intra_quant_bias), AV_OPT_TYPE_INT, {.i64 = FF_DEFAULT_QUANT_BIAS }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS },   \
 {"pbias", "inter quant bias",                                       FF_MPV_OFFSET(inter_quant_bias), AV_OPT_TYPE_INT, {.i64 = FF_DEFAULT_QUANT_BIAS }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS },   \
60532348
 {"rc_strategy", "ratecontrol method",                               FF_MPV_OFFSET(rc_strategy), AV_OPT_TYPE_INT, {.i64 = MPV_RC_STRATEGY_FFMPEG }, 0, NB_MPV_RC_STRATEGY-1, FF_MPV_OPT_FLAGS, "rc_strategy" },   \
     { "ffmpeg", "default native rate control", 0, AV_OPT_TYPE_CONST, { .i64 = MPV_RC_STRATEGY_FFMPEG }, 0, 0, FF_MPV_OPT_FLAGS, "rc_strategy" }, \
     { "xvid",   "libxvid (2 pass only)",       0, AV_OPT_TYPE_CONST, { .i64 = MPV_RC_STRATEGY_XVID },   0, 0, FF_MPV_OPT_FLAGS, "rc_strategy" }, \
4b6b1082
 {"motion_est", "motion estimation algorithm",                       FF_MPV_OFFSET(motion_est), AV_OPT_TYPE_INT, {.i64 = FF_ME_EPZS }, FF_ME_ZERO, FF_ME_XONE, FF_MPV_OPT_FLAGS, "motion_est" },   \
 { "zero", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = FF_ME_ZERO }, 0, 0, FF_MPV_OPT_FLAGS, "motion_est" }, \
 { "epzs", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = FF_ME_EPZS }, 0, 0, FF_MPV_OPT_FLAGS, "motion_est" }, \
 { "xone", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = FF_ME_XONE }, 0, 0, FF_MPV_OPT_FLAGS, "motion_est" }, \
d6cfbcd6
 { "force_duplicated_matrix", "Always write luma and chroma matrix for mjpeg, useful for rtp streaming.", FF_MPV_OFFSET(force_duplicated_matrix), AV_OPT_TYPE_BOOL, {.i64 = 0 }, 0, 1, FF_MPV_OPT_FLAGS },   \
0e6c8532
 {"b_strategy", "Strategy to choose between I/P/B-frames",           FF_MPV_OFFSET(b_frame_strategy), AV_OPT_TYPE_INT, {.i64 = 0 }, 0, 2, FF_MPV_OPT_FLAGS }, \
 {"b_sensitivity", "Adjust sensitivity of b_frame_strategy 1",       FF_MPV_OFFSET(b_sensitivity), AV_OPT_TYPE_INT, {.i64 = 40 }, 1, INT_MAX, FF_MPV_OPT_FLAGS }, \
84c4714f
 {"brd_scale", "Downscale frames for dynamic B-frame decision",      FF_MPV_OFFSET(brd_scale), AV_OPT_TYPE_INT, {.i64 = 0 }, 0, 3, FF_MPV_OPT_FLAGS }, \
0ac9f33a
 {"skip_threshold", "Frame skip threshold",                          FF_MPV_OFFSET(frame_skip_threshold), AV_OPT_TYPE_INT, {.i64 = 0 }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS }, \
 {"skip_factor", "Frame skip factor",                                FF_MPV_OFFSET(frame_skip_factor), AV_OPT_TYPE_INT, {.i64 = 0 }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS }, \
 {"skip_exp", "Frame skip exponent",                                 FF_MPV_OFFSET(frame_skip_exp), AV_OPT_TYPE_INT, {.i64 = 0 }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS }, \
 {"skip_cmp", "Frame skip compare function",                         FF_MPV_OFFSET(frame_skip_cmp), AV_OPT_TYPE_INT, {.i64 = FF_CMP_DCTMAX }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS, "cmp_func" }, \
7c79587d
 {"sc_threshold", "Scene change threshold",                          FF_MPV_OFFSET(scenechange_threshold), AV_OPT_TYPE_INT, {.i64 = 0 }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS }, \
1482aff2
 {"noise_reduction", "Noise reduction",                              FF_MPV_OFFSET(noise_reduction), AV_OPT_TYPE_INT, {.i64 = 0 }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS }, \
12b49769
 {"mpeg_quant", "Use MPEG quantizers instead of H.263",              FF_MPV_OFFSET(mpeg_quant), AV_OPT_TYPE_INT, {.i64 = 0 }, 0, 1, FF_MPV_OPT_FLAGS }, \
936f0d98
 {"ps", "RTP payload size in bytes",                             FF_MPV_OFFSET(rtp_payload_size), AV_OPT_TYPE_INT, {.i64 = 0 }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS }, \
5b6f42da
 {"mepc", "Motion estimation bitrate penalty compensation (1.0 = 256)", FF_MPV_OFFSET(me_penalty_compensation), AV_OPT_TYPE_INT, {.i64 = 256 }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS }, \
0e9c4fe2
 {"mepre", "pre motion estimation", FF_MPV_OFFSET(me_pre), AV_OPT_TYPE_INT, {.i64 = 0 }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS }, \
ed019b8e
 
 extern const AVOption ff_mpv_generic_options[];
 
7a851153
 /**
  * Set the given MpegEncContext to common defaults (same for encoding
  * and decoding).  The changed fields will not depend upon the prior
  * state of the MpegEncContext.
  */
835f798c
 void ff_mpv_common_defaults(MpegEncContext *s);
 
6b33e918
 void ff_dct_encode_init_x86(MpegEncContext *s);
c1df467d
 
835f798c
 int ff_mpv_common_init(MpegEncContext *s);
 void ff_mpv_common_init_arm(MpegEncContext *s);
c1df467d
 void ff_mpv_common_init_axp(MpegEncContext *s);
835f798c
 void ff_mpv_common_init_neon(MpegEncContext *s);
 void ff_mpv_common_init_ppc(MpegEncContext *s);
 void ff_mpv_common_init_x86(MpegEncContext *s);
2eb28e88
 void ff_mpv_common_init_mips(MpegEncContext *s);
835f798c
 
 int ff_mpv_common_frame_size_change(MpegEncContext *s);
 void ff_mpv_common_end(MpegEncContext *s);
 
 void ff_mpv_decode_defaults(MpegEncContext *s);
4dee4a44
 void ff_mpv_decode_init(MpegEncContext *s, AVCodecContext *avctx);
f670c13f
 void ff_mpv_reconstruct_mb(MpegEncContext *s, int16_t block[12][64]);
835f798c
 void ff_mpv_report_decode_progress(MpegEncContext *s);
 
 int ff_mpv_frame_start(MpegEncContext *s, AVCodecContext *avctx);
 void ff_mpv_frame_end(MpegEncContext *s);
 
 int ff_mpv_encode_init(AVCodecContext *avctx);
 void ff_mpv_encode_init_x86(MpegEncContext *s);
 
 int ff_mpv_encode_end(AVCodecContext *avctx);
 int ff_mpv_encode_picture(AVCodecContext *avctx, AVPacket *pkt,
445a7d48
                           const AVFrame *frame, int *got_packet);
00f3bb2e
 int ff_mpv_reallocate_putbitbuffer(MpegEncContext *s, size_t threshold, size_t size_increase);
835f798c
 
7f2fe444
 void ff_clean_intra_table_entries(MpegEncContext *s);
1d0feb5d
 void ff_mpeg_draw_horiz_band(MpegEncContext *s, int y, int h);
7a06ff14
 void ff_mpeg_flush(AVCodecContext *avctx);
a76ef998
 
53fd4f55
 void ff_print_debug_info(MpegEncContext *s, Picture *p, AVFrame *pict);
a76ef998
 
64308941
 int ff_mpv_export_qp_table(MpegEncContext *s, AVFrame *f, Picture *p, int qp_type);
 
191e8ca7
 void ff_write_quant_matrix(PutBitContext *pb, uint16_t *matrix);
4e17946f
 
f1d8763a
 int ff_update_duplicate_context(MpegEncContext *dst, MpegEncContext *src);
d375c104
 int ff_mpeg_update_thread_context(AVCodecContext *dst, const AVCodecContext *src);
bb174ff1
 void ff_set_qscale(MpegEncContext * s, int qscale);
59b571c1
 
998c9f15
 void ff_mpv_idct_init(MpegEncContext *s);
6b33e918
 int ff_dct_encode_init(MpegEncContext *s);
5dd8c08f
 void ff_convert_matrix(MpegEncContext *s, int (*qmat)[64], uint16_t (*qmat16)[2][64],
69cea75f
                        const uint16_t *quant_matrix, int bias, int qmin, int qmax, int intra);
88bd7fdc
 int ff_dct_quantize_c(MpegEncContext *s, int16_t *block, int n, int qscale, int *overflow);
9f3bfe30
 void ff_block_permute(int16_t *block, uint8_t *permutation,
                       const uint8_t *scantable, int last);
7d1c3fc1
 void ff_init_block_index(MpegEncContext *s);
4d2858de
 
835f798c
 void ff_mpv_motion(MpegEncContext *s,
7a851153
                    uint8_t *dest_y, uint8_t *dest_cb,
                    uint8_t *dest_cr, int dir,
                    uint8_t **ref_picture,
                    op_pixels_func (*pix_op)[4],
                    qpel_mc_func (*qpix_op)[16]);
 
4d2858de
 static inline void ff_update_block_index(MpegEncContext *s){
f9d3841a
     const int bytes_per_pixel = 1 + (s->avctx->bits_per_raw_sample > 8);
     const int block_size= (8*bytes_per_pixel) >> s->avctx->lowres;
178fcca8
 
4d2858de
     s->block_index[0]+=2;
     s->block_index[1]+=2;
     s->block_index[2]+=2;
     s->block_index[3]+=2;
     s->block_index[4]++;
     s->block_index[5]++;
178fcca8
     s->dest[0]+= 2*block_size;
f9d3841a
     s->dest[1]+= (2 >> s->chroma_x_shift) * block_size;
     s->dest[2]+= (2 >> s->chroma_x_shift) * block_size;
4d2858de
 }
 
4d2a4834
 static inline int get_bits_diff(MpegEncContext *s){
fe455f33
     const int bits= put_bits_count(&s->pb);
4d2a4834
     const int last= s->last_bits;
 
     s->last_bits = bits;
 
     return bits - last;
 }
4d2858de
 
f9d3841a
 static inline int mpeg_get_qscale(MpegEncContext *s)
 {
     int qscale = get_bits(&s->gb, 5);
     if (s->q_scale_type)
         return ff_mpeg2_non_linear_qscale[qscale];
     else
         return qscale << 1;
 }
 
98790382
 #endif /* AVCODEC_MPEGVIDEO_H */