mpegvideo.h 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773
  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. * @file
  24. * mpegvideo header.
  25. */
  26. #ifndef AVCODEC_MPEGVIDEO_H
  27. #define AVCODEC_MPEGVIDEO_H
  28. #include <float.h>
  29. #include "avcodec.h"
  30. #include "blockdsp.h"
  31. #include "error_resilience.h"
  32. #include "fdctdsp.h"
  33. #include "get_bits.h"
  34. #include "h264chroma.h"
  35. #include "h263dsp.h"
  36. #include "hpeldsp.h"
  37. #include "idctdsp.h"
  38. #include "internal.h"
  39. #include "me_cmp.h"
  40. #include "motion_est.h"
  41. #include "mpegpicture.h"
  42. #include "mpegvideodsp.h"
  43. #include "mpegvideoencdsp.h"
  44. #include "mpegvideodata.h"
  45. #include "pixblockdsp.h"
  46. #include "put_bits.h"
  47. #include "ratecontrol.h"
  48. #include "parser.h"
  49. #include "mpegutils.h"
  50. #include "mpeg12data.h"
  51. #include "qpeldsp.h"
  52. #include "thread.h"
  53. #include "videodsp.h"
  54. #include "libavutil/opt.h"
  55. #include "libavutil/timecode.h"
  56. #define MAX_THREADS 32
  57. #define MAX_B_FRAMES 16
  58. /* Start codes. */
  59. #define SEQ_END_CODE 0x000001b7
  60. #define SEQ_START_CODE 0x000001b3
  61. #define GOP_START_CODE 0x000001b8
  62. #define PICTURE_START_CODE 0x00000100
  63. #define SLICE_MIN_START_CODE 0x00000101
  64. #define SLICE_MAX_START_CODE 0x000001af
  65. #define EXT_START_CODE 0x000001b5
  66. #define USER_START_CODE 0x000001b2
  67. #define SLICE_START_CODE 0x000001b7
  68. /**
  69. * MpegEncContext.
  70. */
  71. typedef struct MpegEncContext {
  72. AVClass *class;
  73. int y_dc_scale, c_dc_scale;
  74. int ac_pred;
  75. int block_last_index[12]; ///< last non zero coefficient in block
  76. int h263_aic; ///< Advanced INTRA Coding (AIC)
  77. /* scantables */
  78. ScanTable inter_scantable; ///< if inter == intra then intra should be used to reduce the cache usage
  79. ScanTable intra_scantable;
  80. ScanTable intra_h_scantable;
  81. ScanTable intra_v_scantable;
  82. /* WARNING: changes above this line require updates to hardcoded
  83. * offsets used in ASM. */
  84. struct AVCodecContext *avctx;
  85. /* the following parameters must be initialized before encoding */
  86. int width, height;///< picture size. must be a multiple of 16
  87. int gop_size;
  88. int intra_only; ///< if true, only intra pictures are generated
  89. int64_t bit_rate; ///< wanted bit rate
  90. enum OutputFormat out_format; ///< output format
  91. int h263_pred; ///< use MPEG-4/H.263 ac/dc predictions
  92. int pb_frame; ///< PB-frame mode (0 = none, 1 = base, 2 = improved)
  93. /* the following codec id fields are deprecated in favor of codec_id */
  94. int h263_plus; ///< H.263+ headers
  95. int h263_flv; ///< use flv H.263 header
  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 strict_std_compliance; ///< strictly follow the std (MPEG-4, ...)
  103. int workaround_bugs; ///< workaround bugs in encoders which cannot be detected automatically
  104. int codec_tag; ///< internal codec_tag upper case converted from avctx codec_tag
  105. /* the following fields are managed internally by the encoder */
  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. int64_t user_specified_pts; ///< last non-zero pts from AVFrame which was passed into avcodec_encode_video2()
  123. /**
  124. * pts difference between the first and second input frame, used for
  125. * calculating dts of the first frame when there's a delay */
  126. int64_t dts_delta;
  127. /**
  128. * reordered pts to be used as dts for the next output frame when there's
  129. * a delay */
  130. int64_t reordered_pts;
  131. /** bit output */
  132. PutBitContext pb;
  133. int start_mb_y; ///< start mb_y of this thread (so current thread should process start_mb_y <= row < end_mb_y)
  134. int end_mb_y; ///< end mb_y of this thread (so current thread should process start_mb_y <= row < end_mb_y)
  135. struct MpegEncContext *thread_context[MAX_THREADS];
  136. int slice_context_count; ///< number of used thread_contexts
  137. /**
  138. * copy of the previous picture structure.
  139. * note, linesize & data, might not match the previous picture (for field pictures)
  140. */
  141. Picture last_picture;
  142. /**
  143. * copy of the next picture structure.
  144. * note, linesize & data, might not match the next picture (for field pictures)
  145. */
  146. Picture next_picture;
  147. /**
  148. * copy of the source picture structure for encoding.
  149. * note, linesize & data, might not match the source picture (for field pictures)
  150. */
  151. Picture new_picture;
  152. /**
  153. * copy of the current picture structure.
  154. * note, linesize & data, might not match the current picture (for field pictures)
  155. */
  156. Picture current_picture; ///< buffer to store the decompressed current picture
  157. Picture *last_picture_ptr; ///< pointer to the previous picture.
  158. Picture *next_picture_ptr; ///< pointer to the next picture (for bidir pred)
  159. Picture *current_picture_ptr; ///< pointer to the current picture
  160. int last_dc[3]; ///< last DC values for MPEG-1
  161. int16_t *dc_val_base;
  162. int16_t *dc_val[3]; ///< used for MPEG-4 DC prediction, all 3 arrays must be continuous
  163. const uint8_t *y_dc_scale_table; ///< qscale -> y_dc_scale table
  164. const uint8_t *c_dc_scale_table; ///< qscale -> c_dc_scale table
  165. const uint8_t *chroma_qscale_table; ///< qscale -> chroma_qscale (H.263)
  166. uint8_t *coded_block_base;
  167. uint8_t *coded_block; ///< used for coded block pattern prediction (msmpeg4v3, wmv1)
  168. int16_t (*ac_val_base)[16];
  169. int16_t (*ac_val[3])[16]; ///< used for MPEG-4 AC prediction, all 3 arrays must be continuous
  170. int mb_skipped; ///< MUST BE SET only during DECODING
  171. uint8_t *mbskip_table; /**< used to avoid copy if macroblock skipped (for black regions for example)
  172. and used for B-frame encoding & decoding (contains skip table of next P-frame) */
  173. uint8_t *mbintra_table; ///< used to avoid setting {ac, dc, cbp}-pred stuff to zero on inter MB decoding
  174. uint8_t *cbp_table; ///< used to store cbp, ac_pred for partitioned decoding
  175. uint8_t *pred_dir_table; ///< used to store pred_dir for partitioned decoding
  176. ScratchpadContext sc;
  177. int qscale; ///< QP
  178. int chroma_qscale; ///< chroma QP
  179. unsigned int lambda; ///< Lagrange multiplier used in rate distortion
  180. unsigned int lambda2; ///< (lambda*lambda) >> FF_LAMBDA_SHIFT
  181. int *lambda_table;
  182. int adaptive_quant; ///< use adaptive quantization
  183. int dquant; ///< qscale difference to prev qscale
  184. int closed_gop; ///< MPEG1/2 GOP is closed
  185. int pict_type; ///< AV_PICTURE_TYPE_I, AV_PICTURE_TYPE_P, AV_PICTURE_TYPE_B, ...
  186. int vbv_delay;
  187. int last_pict_type; //FIXME removes
  188. int last_non_b_pict_type; ///< used for MPEG-4 gmc B-frames & ratecontrol
  189. int droppable;
  190. int frame_rate_index;
  191. AVRational mpeg2_frame_rate_ext;
  192. int last_lambda_for[5]; ///< last lambda for a specific pict type
  193. int skipdct; ///< skip dct and code zero residual
  194. /* motion compensation */
  195. int unrestricted_mv; ///< mv can point outside of the coded picture
  196. int h263_long_vectors; ///< use horrible H.263v1 long vector mode
  197. BlockDSPContext bdsp;
  198. FDCTDSPContext fdsp;
  199. H264ChromaContext h264chroma;
  200. HpelDSPContext hdsp;
  201. IDCTDSPContext idsp;
  202. MECmpContext mecc;
  203. MpegVideoDSPContext mdsp;
  204. MpegvideoEncDSPContext mpvencdsp;
  205. PixblockDSPContext pdsp;
  206. QpelDSPContext qdsp;
  207. VideoDSPContext vdsp;
  208. H263DSPContext h263dsp;
  209. int f_code; ///< forward MV resolution
  210. int b_code; ///< backward MV resolution for B-frames (MPEG-4)
  211. int16_t (*p_mv_table_base)[2];
  212. int16_t (*b_forw_mv_table_base)[2];
  213. int16_t (*b_back_mv_table_base)[2];
  214. int16_t (*b_bidir_forw_mv_table_base)[2];
  215. int16_t (*b_bidir_back_mv_table_base)[2];
  216. int16_t (*b_direct_mv_table_base)[2];
  217. int16_t (*p_field_mv_table_base[2][2])[2];
  218. int16_t (*b_field_mv_table_base[2][2][2])[2];
  219. int16_t (*p_mv_table)[2]; ///< MV table (1MV per MB) P-frame encoding
  220. int16_t (*b_forw_mv_table)[2]; ///< MV table (1MV per MB) forward mode B-frame encoding
  221. int16_t (*b_back_mv_table)[2]; ///< MV table (1MV per MB) backward mode B-frame encoding
  222. int16_t (*b_bidir_forw_mv_table)[2]; ///< MV table (1MV per MB) bidir mode B-frame encoding
  223. int16_t (*b_bidir_back_mv_table)[2]; ///< MV table (1MV per MB) bidir mode B-frame encoding
  224. int16_t (*b_direct_mv_table)[2]; ///< MV table (1MV per MB) direct mode B-frame encoding
  225. int16_t (*p_field_mv_table[2][2])[2]; ///< MV table (2MV per MB) interlaced P-frame encoding
  226. int16_t (*b_field_mv_table[2][2][2])[2];///< MV table (4MV per MB) interlaced B-frame encoding
  227. uint8_t (*p_field_select_table[2]);
  228. uint8_t (*b_field_select_table[2][2]);
  229. int motion_est; ///< ME algorithm
  230. int me_penalty_compensation;
  231. int me_pre; ///< prepass for motion estimation
  232. int mv_dir;
  233. #define MV_DIR_FORWARD 1
  234. #define MV_DIR_BACKWARD 2
  235. #define MV_DIRECT 4 ///< bidirectional mode where the difference equals the MV of the last P/S/I-Frame (MPEG-4)
  236. int mv_type;
  237. #define MV_TYPE_16X16 0 ///< 1 vector for the whole mb
  238. #define MV_TYPE_8X8 1 ///< 4 vectors (H.263, MPEG-4 4MV)
  239. #define MV_TYPE_16X8 2 ///< 2 vectors, one per 16x8 block
  240. #define MV_TYPE_FIELD 3 ///< 2 vectors, one per field
  241. #define MV_TYPE_DMV 4 ///< 2 vectors, special mpeg2 Dual Prime Vectors
  242. /**motion vectors for a macroblock
  243. first coordinate : 0 = forward 1 = backward
  244. second " : depend on type
  245. third " : 0 = x, 1 = y
  246. */
  247. int mv[2][4][2];
  248. int field_select[2][2];
  249. int last_mv[2][2][2]; ///< last MV, used for MV prediction in MPEG-1 & B-frame MPEG-4
  250. uint8_t *fcode_tab; ///< smallest fcode needed for each MV
  251. int16_t direct_scale_mv[2][64]; ///< precomputed to avoid divisions in ff_mpeg4_set_direct_mv
  252. MotionEstContext me;
  253. int no_rounding; /**< apply no rounding to motion compensation (MPEG-4, msmpeg4, ...)
  254. for B-frames rounding mode is always 0 */
  255. /* macroblock layer */
  256. int mb_x, mb_y;
  257. int mb_skip_run;
  258. int mb_intra;
  259. uint16_t *mb_type; ///< Table for candidate MB types for encoding (defines in mpegutils.h)
  260. int block_index[6]; ///< index to current MB in block based arrays with edges
  261. int block_wrap[6];
  262. uint8_t *dest[3];
  263. int *mb_index2xy; ///< mb_index -> mb_x + mb_y*mb_stride
  264. /** matrix transmitted in the bitstream */
  265. uint16_t intra_matrix[64];
  266. uint16_t chroma_intra_matrix[64];
  267. uint16_t inter_matrix[64];
  268. uint16_t chroma_inter_matrix[64];
  269. int force_duplicated_matrix; ///< Force duplication of mjpeg matrices, useful for rtp streaming
  270. int intra_quant_bias; ///< bias for the quantizer
  271. int inter_quant_bias; ///< bias for the quantizer
  272. int min_qcoeff; ///< minimum encodable coefficient
  273. int max_qcoeff; ///< maximum encodable coefficient
  274. int ac_esc_length; ///< num of bits needed to encode the longest esc
  275. uint8_t *intra_ac_vlc_length;
  276. uint8_t *intra_ac_vlc_last_length;
  277. uint8_t *intra_chroma_ac_vlc_length;
  278. uint8_t *intra_chroma_ac_vlc_last_length;
  279. uint8_t *inter_ac_vlc_length;
  280. uint8_t *inter_ac_vlc_last_length;
  281. uint8_t *luma_dc_vlc_length;
  282. #define UNI_AC_ENC_INDEX(run,level) ((run)*128 + (level))
  283. int coded_score[12];
  284. /** precomputed matrix (combine qscale and DCT renorm) */
  285. int (*q_intra_matrix)[64];
  286. int (*q_chroma_intra_matrix)[64];
  287. int (*q_inter_matrix)[64];
  288. /** identical to the above but for MMX & these are not permutated, second 64 entries are bias*/
  289. uint16_t (*q_intra_matrix16)[2][64];
  290. uint16_t (*q_chroma_intra_matrix16)[2][64];
  291. uint16_t (*q_inter_matrix16)[2][64];
  292. /* noise reduction */
  293. int (*dct_error_sum)[64];
  294. int dct_count[2];
  295. uint16_t (*dct_offset)[64];
  296. /* bit rate control */
  297. int64_t total_bits;
  298. int frame_bits; ///< bits used for the current frame
  299. int stuffing_bits; ///< bits used for stuffing
  300. int next_lambda; ///< next lambda used for retrying to encode a frame
  301. RateControlContext rc_context; ///< contains stuff only accessed in ratecontrol.c
  302. /* statistics, used for 2-pass encoding */
  303. int mv_bits;
  304. int header_bits;
  305. int i_tex_bits;
  306. int p_tex_bits;
  307. int i_count;
  308. int f_count;
  309. int b_count;
  310. int skip_count;
  311. int misc_bits; ///< cbp, mb_type
  312. int last_bits; ///< temp var used for calculating the above vars
  313. /* error concealment / resync */
  314. int resync_mb_x; ///< x position of last resync marker
  315. int resync_mb_y; ///< y position of last resync marker
  316. GetBitContext last_resync_gb; ///< used to search for the next resync marker
  317. int mb_num_left; ///< number of MBs left in this video packet (for partitioned Slices only)
  318. int next_p_frame_damaged; ///< set if the next p frame is damaged, to avoid showing trashed B-frames
  319. ParseContext parse_context;
  320. /* H.263 specific */
  321. int gob_index;
  322. int obmc; ///< overlapped block motion compensation
  323. int mb_info; ///< interval for outputting info about mb offsets as side data
  324. int prev_mb_info, last_mb_info;
  325. uint8_t *mb_info_ptr;
  326. int mb_info_size;
  327. int ehc_mode;
  328. int rc_strategy; ///< deprecated
  329. /* H.263+ specific */
  330. int umvplus; ///< == H.263+ && unrestricted_mv
  331. int h263_aic_dir; ///< AIC direction: 0 = left, 1 = top
  332. int h263_slice_structured;
  333. int alt_inter_vlc; ///< alternative inter vlc
  334. int modified_quant;
  335. int loop_filter;
  336. int custom_pcf;
  337. /* MPEG-4 specific */
  338. int studio_profile;
  339. int dct_precision;
  340. ///< number of bits to represent the fractional part of time (encoder only)
  341. int time_increment_bits;
  342. int last_time_base;
  343. int time_base; ///< time in seconds of last I,P,S Frame
  344. int64_t time; ///< time of current frame
  345. int64_t last_non_b_time;
  346. uint16_t pp_time; ///< time distance between the last 2 p,s,i frames
  347. uint16_t pb_time; ///< time distance between the last b and p,s,i frame
  348. uint16_t pp_field_time;
  349. uint16_t pb_field_time; ///< like above, just for interlaced
  350. int real_sprite_warping_points;
  351. int sprite_offset[2][2]; ///< sprite offset[isChroma][isMVY]
  352. int sprite_delta[2][2]; ///< sprite_delta [isY][isMVY]
  353. int mcsel;
  354. int quant_precision;
  355. int quarter_sample; ///< 1->qpel, 0->half pel ME/MC
  356. int aspect_ratio_info; //FIXME remove
  357. int sprite_warping_accuracy;
  358. int data_partitioning; ///< data partitioning flag from header
  359. int partitioned_frame; ///< is current frame partitioned
  360. int low_delay; ///< no reordering needed / has no B-frames
  361. int vo_type;
  362. PutBitContext tex_pb; ///< used for data partitioned VOPs
  363. PutBitContext pb2; ///< used for data partitioned VOPs
  364. int mpeg_quant;
  365. int padding_bug_score; ///< used to detect the VERY common padding bug in MPEG-4
  366. /* divx specific, used to workaround (many) bugs in divx5 */
  367. int divx_packed;
  368. uint8_t *bitstream_buffer; //Divx 5.01 puts several frames in a single one, this is used to reorder them
  369. int bitstream_buffer_size;
  370. unsigned int allocated_bitstream_buffer_size;
  371. /* RV10 specific */
  372. int rv10_version; ///< RV10 version: 0 or 3
  373. int rv10_first_dc_coded[3];
  374. /* MJPEG specific */
  375. struct MJpegContext *mjpeg_ctx;
  376. int esc_pos;
  377. int pred;
  378. int huffman;
  379. /* MSMPEG4 specific */
  380. int mv_table_index;
  381. int rl_table_index;
  382. int rl_chroma_table_index;
  383. int dc_table_index;
  384. int use_skip_mb_code;
  385. int slice_height; ///< in macroblocks
  386. int first_slice_line; ///< used in MPEG-4 too to handle resync markers
  387. int flipflop_rounding;
  388. int msmpeg4_version; ///< 0=not msmpeg4, 1=mp41, 2=mp42, 3=mp43/divx3 4=wmv1/7 5=wmv2/8
  389. int per_mb_rl_table;
  390. int esc3_level_length;
  391. int esc3_run_length;
  392. /** [mb_intra][isChroma][level][run][last] */
  393. int (*ac_stats)[2][MAX_LEVEL+1][MAX_RUN+1][2];
  394. int inter_intra_pred;
  395. int mspel;
  396. /* decompression specific */
  397. GetBitContext gb;
  398. /* MPEG-1 specific */
  399. int gop_picture_number; ///< index of the first picture of a GOP based on fake_pic_num & MPEG-1 specific
  400. int last_mv_dir; ///< last mv_dir, used for B-frame encoding
  401. uint8_t *vbv_delay_ptr; ///< pointer to vbv_delay in the bitstream
  402. /* MPEG-2-specific - I wished not to have to support this mess. */
  403. int progressive_sequence;
  404. int mpeg_f_code[2][2];
  405. int a53_cc;
  406. // picture structure defines are loaded from mpegutils.h
  407. int picture_structure;
  408. int64_t timecode_frame_start; ///< GOP timecode frame start number, in non drop frame format
  409. int intra_dc_precision;
  410. int frame_pred_frame_dct;
  411. int top_field_first;
  412. int concealment_motion_vectors;
  413. int q_scale_type;
  414. int brd_scale;
  415. int intra_vlc_format;
  416. int alternate_scan;
  417. int seq_disp_ext;
  418. int video_format;
  419. #define VIDEO_FORMAT_COMPONENT 0
  420. #define VIDEO_FORMAT_PAL 1
  421. #define VIDEO_FORMAT_NTSC 2
  422. #define VIDEO_FORMAT_SECAM 3
  423. #define VIDEO_FORMAT_MAC 4
  424. #define VIDEO_FORMAT_UNSPECIFIED 5
  425. int repeat_first_field;
  426. int chroma_420_type;
  427. int chroma_format;
  428. #define CHROMA_420 1
  429. #define CHROMA_422 2
  430. #define CHROMA_444 3
  431. int chroma_x_shift;//depend on pix_format, that depend on chroma_format
  432. int chroma_y_shift;
  433. int progressive_frame;
  434. int full_pel[2];
  435. int interlaced_dct;
  436. int first_field; ///< is 1 for the first field of a field picture 0 otherwise
  437. int drop_frame_timecode; ///< timecode is in drop frame format.
  438. int scan_offset; ///< reserve space for SVCD scan offset user data.
  439. /* RTP specific */
  440. int rtp_mode;
  441. int rtp_payload_size;
  442. char *tc_opt_str; ///< timecode option string
  443. AVTimecode tc; ///< timecode context
  444. uint8_t *ptr_lastgob;
  445. int swap_uv; //vcr2 codec is an MPEG-2 variant with U and V swapped
  446. int pack_pblocks; //xvmc needs to keep blocks without gaps.
  447. int16_t (*pblocks[12])[64];
  448. int16_t (*block)[64]; ///< points to one of the following blocks
  449. int16_t (*blocks)[12][64]; // for HQ mode we need to keep the best block
  450. int (*decode_mb)(struct MpegEncContext *s, int16_t block[12][64]); // used by some codecs to avoid a switch()
  451. int32_t (*block32)[12][64];
  452. int dpcm_direction; // 0 = DCT, 1 = DPCM top to bottom scan, -1 = DPCM bottom to top scan
  453. int16_t (*dpcm_macroblock)[3][256];
  454. #define SLICE_OK 0
  455. #define SLICE_ERROR -1
  456. #define SLICE_END -2 ///<end marker found
  457. #define SLICE_NOEND -3 ///<no end marker or error found but mb count exceeded
  458. void (*dct_unquantize_mpeg1_intra)(struct MpegEncContext *s,
  459. int16_t *block/*align 16*/, int n, int qscale);
  460. void (*dct_unquantize_mpeg1_inter)(struct MpegEncContext *s,
  461. int16_t *block/*align 16*/, int n, int qscale);
  462. void (*dct_unquantize_mpeg2_intra)(struct MpegEncContext *s,
  463. int16_t *block/*align 16*/, int n, int qscale);
  464. void (*dct_unquantize_mpeg2_inter)(struct MpegEncContext *s,
  465. int16_t *block/*align 16*/, int n, int qscale);
  466. void (*dct_unquantize_h263_intra)(struct MpegEncContext *s,
  467. int16_t *block/*align 16*/, int n, int qscale);
  468. void (*dct_unquantize_h263_inter)(struct MpegEncContext *s,
  469. int16_t *block/*align 16*/, int n, int qscale);
  470. void (*dct_unquantize_intra)(struct MpegEncContext *s, // unquantizer to use (MPEG-4 can use both)
  471. int16_t *block/*align 16*/, int n, int qscale);
  472. void (*dct_unquantize_inter)(struct MpegEncContext *s, // unquantizer to use (MPEG-4 can use both)
  473. int16_t *block/*align 16*/, int n, int qscale);
  474. int (*dct_quantize)(struct MpegEncContext *s, int16_t *block/*align 16*/, int n, int qscale, int *overflow);
  475. int (*fast_dct_quantize)(struct MpegEncContext *s, int16_t *block/*align 16*/, int n, int qscale, int *overflow);
  476. void (*denoise_dct)(struct MpegEncContext *s, int16_t *block);
  477. int mpv_flags; ///< flags set by private options
  478. int quantizer_noise_shaping;
  479. /**
  480. * ratecontrol qmin qmax limiting method
  481. * 0-> clipping, 1-> use a nice continuous function to limit qscale within qmin/qmax.
  482. */
  483. float rc_qsquish;
  484. float rc_qmod_amp;
  485. int rc_qmod_freq;
  486. float rc_initial_cplx;
  487. float rc_buffer_aggressivity;
  488. float border_masking;
  489. int lmin, lmax;
  490. int vbv_ignore_qmax;
  491. char *rc_eq;
  492. /* temp buffers for rate control */
  493. float *cplx_tab, *bits_tab;
  494. /* flag to indicate a reinitialization is required, e.g. after
  495. * a frame size change */
  496. int context_reinit;
  497. ERContext er;
  498. int error_rate;
  499. /* temporary frames used by b_frame_strategy = 2 */
  500. AVFrame *tmp_frames[MAX_B_FRAMES + 2];
  501. int b_frame_strategy;
  502. int b_sensitivity;
  503. /* frame skip options for encoding */
  504. int frame_skip_threshold;
  505. int frame_skip_factor;
  506. int frame_skip_exp;
  507. int frame_skip_cmp;
  508. int scenechange_threshold;
  509. int noise_reduction;
  510. int intra_penalty;
  511. } MpegEncContext;
  512. /* mpegvideo_enc common options */
  513. #define FF_MPV_FLAG_SKIP_RD 0x0001
  514. #define FF_MPV_FLAG_STRICT_GOP 0x0002
  515. #define FF_MPV_FLAG_QP_RD 0x0004
  516. #define FF_MPV_FLAG_CBP_RD 0x0008
  517. #define FF_MPV_FLAG_NAQ 0x0010
  518. #define FF_MPV_FLAG_MV0 0x0020
  519. #define FF_MPV_OPT_CMP_FUNC \
  520. { "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" }, \
  521. { "sse", "Sum of squared errors", 0, AV_OPT_TYPE_CONST, {.i64 = FF_CMP_SSE }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS, "cmp_func" }, \
  522. { "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" }, \
  523. { "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" }, \
  524. { "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" }, \
  525. { "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" }, \
  526. { "rd", "Rate distortion optimal, slow", 0, AV_OPT_TYPE_CONST, {.i64 = FF_CMP_RD }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS, "cmp_func" }, \
  527. { "zero", "Zero", 0, AV_OPT_TYPE_CONST, {.i64 = FF_CMP_ZERO }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS, "cmp_func" }, \
  528. { "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" }, \
  529. { "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" }, \
  530. { "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" }, \
  531. { "dct264", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = FF_CMP_DCT264 }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS, "cmp_func" }, \
  532. { "dctmax", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = FF_CMP_DCTMAX }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS, "cmp_func" }, \
  533. { "chroma", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = FF_CMP_CHROMA }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS, "cmp_func" }, \
  534. { "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" }
  535. #ifndef FF_MPV_OFFSET
  536. #define FF_MPV_OFFSET(x) offsetof(MpegEncContext, x)
  537. #endif
  538. #define FF_MPV_OPT_FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM)
  539. #define FF_MPV_COMMON_OPTS \
  540. FF_MPV_OPT_CMP_FUNC, \
  541. { "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" },\
  542. { "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" },\
  543. { "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" },\
  544. { "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" },\
  545. { "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" },\
  546. { "naq", "normalize adaptive quantization", 0, AV_OPT_TYPE_CONST, { .i64 = FF_MPV_FLAG_NAQ }, 0, 0, FF_MPV_OPT_FLAGS, "mpv_flags" },\
  547. { "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" },\
  548. { "luma_elim_threshold", "single coefficient elimination threshold for luminance (negative values also consider dc coefficient)",\
  549. FF_MPV_OFFSET(luma_elim_threshold), AV_OPT_TYPE_INT, { .i64 = 0 }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS },\
  550. { "chroma_elim_threshold", "single coefficient elimination threshold for chrominance (negative values also consider dc coefficient)",\
  551. FF_MPV_OFFSET(chroma_elim_threshold), AV_OPT_TYPE_INT, { .i64 = 0 }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS },\
  552. { "quantizer_noise_shaping", NULL, FF_MPV_OFFSET(quantizer_noise_shaping), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, FF_MPV_OPT_FLAGS },\
  553. { "error_rate", "Simulate errors in the bitstream to test error concealment.", \
  554. FF_MPV_OFFSET(error_rate), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, FF_MPV_OPT_FLAGS },\
  555. {"qsquish", "how to keep quantizer between qmin and qmax (0 = clip, 1 = use differentiable function)", \
  556. FF_MPV_OFFSET(rc_qsquish), AV_OPT_TYPE_FLOAT, {.dbl = 0 }, 0, 99, FF_MPV_OPT_FLAGS}, \
  557. {"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}, \
  558. {"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}, \
  559. {"rc_eq", "Set rate control equation. When computing the expression, besides the standard functions " \
  560. "defined in the section 'Expression Evaluation', the following functions are available: " \
  561. "bits2qp(bits), qp2bits(qp). Also the following constants are available: iTex pTex tex mv " \
  562. "fCode iCount mcVar var isI isP isB avgQP qComp avgIITex avgPITex avgPPTex avgBPTex avgTex.", \
  563. FF_MPV_OFFSET(rc_eq), AV_OPT_TYPE_STRING, .flags = FF_MPV_OPT_FLAGS }, \
  564. {"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}, \
  565. {"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}, \
  566. {"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}, \
  567. {"lmin", "minimum Lagrange factor (VBR)", FF_MPV_OFFSET(lmin), AV_OPT_TYPE_INT, {.i64 = 2*FF_QP2LAMBDA }, 0, INT_MAX, FF_MPV_OPT_FLAGS }, \
  568. {"lmax", "maximum Lagrange factor (VBR)", FF_MPV_OFFSET(lmax), AV_OPT_TYPE_INT, {.i64 = 31*FF_QP2LAMBDA }, 0, INT_MAX, FF_MPV_OPT_FLAGS }, \
  569. {"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 }, \
  570. {"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 }, \
  571. {"rc_strategy", "ratecontrol method", FF_MPV_OFFSET(rc_strategy), AV_OPT_TYPE_INT, {.i64 = 0 }, 0, 1, FF_MPV_OPT_FLAGS | AV_OPT_FLAG_DEPRECATED, "rc_strategy" }, \
  572. { "ffmpeg", "deprecated, does nothing", 0, AV_OPT_TYPE_CONST, { .i64 = 0 }, 0, 0, FF_MPV_OPT_FLAGS | AV_OPT_FLAG_DEPRECATED, "rc_strategy" }, \
  573. { "xvid", "deprecated, does nothing", 0, AV_OPT_TYPE_CONST, { .i64 = 0 }, 0, 0, FF_MPV_OPT_FLAGS | AV_OPT_FLAG_DEPRECATED, "rc_strategy" }, \
  574. {"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" }, \
  575. { "zero", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = FF_ME_ZERO }, 0, 0, FF_MPV_OPT_FLAGS, "motion_est" }, \
  576. { "epzs", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = FF_ME_EPZS }, 0, 0, FF_MPV_OPT_FLAGS, "motion_est" }, \
  577. { "xone", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = FF_ME_XONE }, 0, 0, FF_MPV_OPT_FLAGS, "motion_est" }, \
  578. { "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 }, \
  579. {"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 }, \
  580. {"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 }, \
  581. {"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 }, \
  582. {"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 }, \
  583. {"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 }, \
  584. {"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 }, \
  585. {"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" }, \
  586. {"sc_threshold", "Scene change threshold", FF_MPV_OFFSET(scenechange_threshold), AV_OPT_TYPE_INT, {.i64 = 0 }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS }, \
  587. {"noise_reduction", "Noise reduction", FF_MPV_OFFSET(noise_reduction), AV_OPT_TYPE_INT, {.i64 = 0 }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS }, \
  588. {"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 }, \
  589. {"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 }, \
  590. {"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 }, \
  591. {"mepre", "pre motion estimation", FF_MPV_OFFSET(me_pre), AV_OPT_TYPE_INT, {.i64 = 0 }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS }, \
  592. {"intra_penalty", "Penalty for intra blocks in block decision", FF_MPV_OFFSET(intra_penalty), AV_OPT_TYPE_INT, {.i64 = 0 }, 0, INT_MAX/2, FF_MPV_OPT_FLAGS }, \
  593. {"a53cc", "Use A53 Closed Captions (if available)", FF_MPV_OFFSET(a53_cc), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, FF_MPV_OPT_FLAGS }, \
  594. extern const AVOption ff_mpv_generic_options[];
  595. /**
  596. * Set the given MpegEncContext to common defaults (same for encoding
  597. * and decoding). The changed fields will not depend upon the prior
  598. * state of the MpegEncContext.
  599. */
  600. void ff_mpv_common_defaults(MpegEncContext *s);
  601. void ff_dct_encode_init_x86(MpegEncContext *s);
  602. int ff_mpv_common_init(MpegEncContext *s);
  603. void ff_mpv_common_init_arm(MpegEncContext *s);
  604. void ff_mpv_common_init_axp(MpegEncContext *s);
  605. void ff_mpv_common_init_neon(MpegEncContext *s);
  606. void ff_mpv_common_init_ppc(MpegEncContext *s);
  607. void ff_mpv_common_init_x86(MpegEncContext *s);
  608. void ff_mpv_common_init_mips(MpegEncContext *s);
  609. int ff_mpv_common_frame_size_change(MpegEncContext *s);
  610. void ff_mpv_common_end(MpegEncContext *s);
  611. void ff_mpv_decode_defaults(MpegEncContext *s);
  612. void ff_mpv_decode_init(MpegEncContext *s, AVCodecContext *avctx);
  613. void ff_mpv_reconstruct_mb(MpegEncContext *s, int16_t block[12][64]);
  614. void ff_mpv_report_decode_progress(MpegEncContext *s);
  615. int ff_mpv_frame_start(MpegEncContext *s, AVCodecContext *avctx);
  616. void ff_mpv_frame_end(MpegEncContext *s);
  617. int ff_mpv_encode_init(AVCodecContext *avctx);
  618. void ff_mpv_encode_init_x86(MpegEncContext *s);
  619. int ff_mpv_encode_end(AVCodecContext *avctx);
  620. int ff_mpv_encode_picture(AVCodecContext *avctx, AVPacket *pkt,
  621. const AVFrame *frame, int *got_packet);
  622. int ff_mpv_reallocate_putbitbuffer(MpegEncContext *s, size_t threshold, size_t size_increase);
  623. void ff_clean_intra_table_entries(MpegEncContext *s);
  624. void ff_mpeg_draw_horiz_band(MpegEncContext *s, int y, int h);
  625. void ff_mpeg_flush(AVCodecContext *avctx);
  626. void ff_print_debug_info(MpegEncContext *s, Picture *p, AVFrame *pict);
  627. int ff_mpv_export_qp_table(MpegEncContext *s, AVFrame *f, Picture *p, int qp_type);
  628. void ff_write_quant_matrix(PutBitContext *pb, uint16_t *matrix);
  629. int ff_update_duplicate_context(MpegEncContext *dst, MpegEncContext *src);
  630. int ff_mpeg_update_thread_context(AVCodecContext *dst, const AVCodecContext *src);
  631. void ff_set_qscale(MpegEncContext * s, int qscale);
  632. void ff_mpv_idct_init(MpegEncContext *s);
  633. int ff_dct_encode_init(MpegEncContext *s);
  634. void ff_convert_matrix(MpegEncContext *s, int (*qmat)[64], uint16_t (*qmat16)[2][64],
  635. const uint16_t *quant_matrix, int bias, int qmin, int qmax, int intra);
  636. int ff_dct_quantize_c(MpegEncContext *s, int16_t *block, int n, int qscale, int *overflow);
  637. void ff_block_permute(int16_t *block, uint8_t *permutation,
  638. const uint8_t *scantable, int last);
  639. void ff_init_block_index(MpegEncContext *s);
  640. void ff_mpv_motion(MpegEncContext *s,
  641. uint8_t *dest_y, uint8_t *dest_cb,
  642. uint8_t *dest_cr, int dir,
  643. uint8_t **ref_picture,
  644. op_pixels_func (*pix_op)[4],
  645. qpel_mc_func (*qpix_op)[16]);
  646. static inline void ff_update_block_index(MpegEncContext *s){
  647. const int bytes_per_pixel = 1 + (s->avctx->bits_per_raw_sample > 8);
  648. const int block_size= (8*bytes_per_pixel) >> s->avctx->lowres;
  649. s->block_index[0]+=2;
  650. s->block_index[1]+=2;
  651. s->block_index[2]+=2;
  652. s->block_index[3]+=2;
  653. s->block_index[4]++;
  654. s->block_index[5]++;
  655. s->dest[0]+= 2*block_size;
  656. s->dest[1]+= (2 >> s->chroma_x_shift) * block_size;
  657. s->dest[2]+= (2 >> s->chroma_x_shift) * block_size;
  658. }
  659. static inline int get_bits_diff(MpegEncContext *s){
  660. const int bits= put_bits_count(&s->pb);
  661. const int last= s->last_bits;
  662. s->last_bits = bits;
  663. return bits - last;
  664. }
  665. static inline int mpeg_get_qscale(MpegEncContext *s)
  666. {
  667. int qscale = get_bits(&s->gb, 5);
  668. if (s->q_scale_type)
  669. return ff_mpeg2_non_linear_qscale[qscale];
  670. else
  671. return qscale << 1;
  672. }
  673. #endif /* AVCODEC_MPEGVIDEO_H */