You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

630 lines
26KB

  1. /*
  2. * Generic DCT based hybrid video encoder
  3. * Copyright (c) 2000, 2001, 2002 Fabrice Bellard.
  4. *
  5. * This library is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU Lesser General Public
  7. * License as published by the Free Software Foundation; either
  8. * version 2 of the License, or (at your option) any later version.
  9. *
  10. * This library is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * Lesser General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Lesser General Public
  16. * License along with this library; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. */
  19. #ifndef AVCODEC_MPEGVIDEO_H
  20. #define AVCODEC_MPEGVIDEO_H
  21. #define FRAME_SKIPED 100 // return value for header parsers if frame is not coded
  22. enum OutputFormat {
  23. FMT_MPEG1,
  24. FMT_H263,
  25. FMT_MJPEG,
  26. };
  27. #define MPEG_BUF_SIZE (16 * 1024)
  28. #define QMAT_SHIFT_MMX 16
  29. #define QMAT_SHIFT 22
  30. #define MAX_FCODE 7
  31. #define MAX_MV 2048
  32. #define REORDER_BUFFER_SIZE (FF_MAX_B_FRAMES+2)
  33. #define ME_MAP_SIZE 64
  34. #define ME_MAP_SHIFT 3
  35. #define ME_MAP_MV_BITS 11
  36. /* run length table */
  37. #define MAX_RUN 64
  38. #define MAX_LEVEL 64
  39. typedef struct Predictor{
  40. double coeff;
  41. double count;
  42. double decay;
  43. } Predictor;
  44. typedef struct RateControlEntry{
  45. int pict_type;
  46. float qscale;
  47. int mv_bits;
  48. int i_tex_bits;
  49. int p_tex_bits;
  50. int misc_bits;
  51. UINT64 expected_bits;
  52. int new_pict_type;
  53. float new_qscale;
  54. int mc_mb_var_sum;
  55. int mb_var_sum;
  56. int i_count;
  57. int f_code;
  58. int b_code;
  59. }RateControlEntry;
  60. typedef struct RateControlContext{
  61. FILE *stats_file;
  62. int num_entries; /* number of RateControlEntries */
  63. RateControlEntry *entry;
  64. int buffer_index; /* amount of bits in the video/audio buffer */
  65. Predictor pred[5];
  66. double short_term_qsum; /* sum of recent qscales */
  67. double short_term_qcount; /* count of recent qscales */
  68. double pass1_bits; /* bits outputted by the pass1 code (including complexity init) */
  69. double pass1_wanted_bits; /* bits which should have been outputed by the pass1 code (including complexity init) */
  70. double last_qscale;
  71. double last_qscale_for[5]; /* last qscale for a specific pict type, used for max_diff & ipb factor stuff */
  72. int last_mc_mb_var_sum;
  73. int last_mb_var_sum;
  74. UINT64 i_cplx_sum[5];
  75. UINT64 p_cplx_sum[5];
  76. UINT64 mv_bits_sum[5];
  77. UINT64 qscale_sum[5];
  78. int frame_count[5];
  79. int last_non_b_pict_type;
  80. }RateControlContext;
  81. typedef struct ReorderBuffer{
  82. UINT8 *picture[3];
  83. int pict_type;
  84. int qscale;
  85. int force_type;
  86. int picture_number;
  87. int picture_in_gop_number;
  88. } ReorderBuffer;
  89. typedef struct MpegEncContext {
  90. struct AVCodecContext *avctx;
  91. /* the following parameters must be initialized before encoding */
  92. int width, height; /* picture size. must be a multiple of 16 */
  93. int gop_size;
  94. int frame_rate; /* number of frames per second */
  95. int intra_only; /* if true, only intra pictures are generated */
  96. int bit_rate; /* wanted bit rate */
  97. int bit_rate_tolerance; /* amount of +- bits (>0)*/
  98. enum OutputFormat out_format; /* output format */
  99. int h263_pred; /* use mpeg4/h263 ac/dc predictions */
  100. /* the following codec id fields are deprecated in favor of codec_id */
  101. int h263_plus; /* h263 plus headers */
  102. int h263_rv10; /* use RV10 variation for H263 */
  103. int h263_msmpeg4; /* generate MSMPEG4 compatible stream (deprecated, use msmpeg4_version instead)*/
  104. int h263_intel; /* use I263 intel h263 header */
  105. int codec_id; /* see CODEC_ID_xxx */
  106. int fixed_qscale; /* fixed qscale if non zero */
  107. float qcompress; /* amount of qscale change between easy & hard scenes (0.0-1.0) */
  108. float qblur; /* amount of qscale smoothing over time (0.0-1.0) */
  109. int qmin; /* min qscale */
  110. int qmax; /* max qscale */
  111. int max_qdiff; /* max qscale difference between frames */
  112. int encoding; /* true if we are encoding (vs decoding) */
  113. int flags; /* AVCodecContext.flags (HQ, MV4, ...) */
  114. int force_input_type;/* 0= no force, otherwise I_TYPE, P_TYPE, ... */
  115. int max_b_frames; /* max number of b-frames for encoding */
  116. int b_frame_strategy;
  117. int luma_elim_threshold;
  118. int chroma_elim_threshold;
  119. int strict_std_compliance; /* strictly follow the std (MPEG4, ...) */
  120. int workaround_bugs; /* workaround bugs in encoders which cannot be detected automatically */
  121. /* the following fields are managed internally by the encoder */
  122. /* bit output */
  123. PutBitContext pb;
  124. /* sequence parameters */
  125. int context_initialized;
  126. int input_picture_number;
  127. int input_picture_in_gop_number; /* 0-> first pic in gop, ... */
  128. int picture_number;
  129. int fake_picture_number; /* picture number at the bitstream frame rate */
  130. int gop_picture_number; /* index of the first picture of a GOP based on fake_pic_num & mpeg1 specific */
  131. int picture_in_gop_number; /* 0-> first pic in gop, ... */
  132. int b_frames_since_non_b; /* used for encoding, relative to not yet reordered input */
  133. int mb_width, mb_height; /* number of MBs horizontally & vertically */
  134. int h_edge_pos, v_edge_pos;/* horizontal / vertical position of the right/bottom edge (pixel replicateion)*/
  135. int mb_num; /* number of MBs of a picture */
  136. int linesize; /* line size, in bytes, may be different from width */
  137. int uvlinesize; /* line size, for chroma in bytes, may be different from width */
  138. UINT8 *new_picture[3]; /* picture to be compressed */
  139. UINT8 *picture_buffer[REORDER_BUFFER_SIZE][3]; /* internal buffers used for reordering of input pictures */
  140. int picture_buffer_index;
  141. ReorderBuffer coded_order[REORDER_BUFFER_SIZE];
  142. UINT8 *last_picture[3]; /* previous picture */
  143. UINT8 *last_picture_base[3]; /* real start of the picture */
  144. UINT8 *next_picture[3]; /* previous picture (for bidir pred) */
  145. UINT8 *next_picture_base[3]; /* real start of the picture */
  146. UINT8 *aux_picture[3]; /* aux picture (for B frames only) */
  147. UINT8 *aux_picture_base[3]; /* real start of the picture */
  148. UINT8 *current_picture[3]; /* buffer to store the decompressed current picture */
  149. void *last_dr_opaque;
  150. void *next_dr_opaque;
  151. int ip_buffer_count; /* number of buffers, currently only >2 if dr1 is used */
  152. int num_available_buffers; /* is 0 at the start & after seeking, after the first I frame its 1 after next I/P 2 */
  153. int last_dc[3]; /* last DC values for MPEG1 */
  154. INT16 *dc_val[3]; /* used for mpeg4 DC prediction, all 3 arrays must be continuous */
  155. int y_dc_scale, c_dc_scale;
  156. UINT8 *y_dc_scale_table; /* qscale -> y_dc_scale table */
  157. UINT8 *c_dc_scale_table; /* qscale -> c_dc_scale table */
  158. UINT8 *coded_block; /* used for coded block pattern prediction (msmpeg4v3, wmv1)*/
  159. INT16 (*ac_val[3])[16]; /* used for for mpeg4 AC prediction, all 3 arrays must be continuous */
  160. int ac_pred;
  161. int mb_skiped; /* MUST BE SET only during DECODING */
  162. UINT8 *mbskip_table; /* used to avoid copy if macroblock skipped (for black regions for example)
  163. and used for b-frame encoding & decoding (contains skip table of next P Frame) */
  164. UINT8 *mbintra_table; /* used to avoid setting {ac, dc, cbp}-pred stuff to zero on inter MB decoding */
  165. UINT8 *cbp_table; /* used to store cbp, ac_pred for partitioned decoding */
  166. UINT8 *pred_dir_table; /* used to store pred_dir for partitioned decoding */
  167. INT8 *qscale_table; /* used to store qscale for partitioned decoding (& postprocessing FIXME export) */
  168. UINT8 *edge_emu_buffer;
  169. int input_qscale; /* qscale prior to reordering of frames */
  170. int input_pict_type; /* pict_type prior to reordering of frames */
  171. int force_type; /* 0= no force, otherwise I_TYPE, P_TYPE, ... */
  172. int qscale; /* QP */
  173. float frame_qscale; /* qscale from the frame level rc */
  174. int adaptive_quant; /* use adaptive quantization */
  175. int dquant; /* qscale difference to prev qscale */
  176. int pict_type; /* I_TYPE, P_TYPE, B_TYPE, ... */
  177. int last_pict_type;
  178. int last_non_b_pict_type; /* used for mpeg4 gmc b-frames & ratecontrol */
  179. int frame_rate_index;
  180. /* motion compensation */
  181. int unrestricted_mv;
  182. int h263_long_vectors; /* use horrible h263v1 long vector mode */
  183. int f_code; /* forward MV resolution */
  184. int b_code; /* backward MV resolution for B Frames (mpeg4) */
  185. INT16 (*motion_val)[2]; /* used for MV prediction (4MV per MB) */
  186. INT16 (*p_mv_table)[2]; /* MV table (1MV per MB) p-frame encoding */
  187. INT16 (*b_forw_mv_table)[2]; /* MV table (1MV per MB) forward mode b-frame encoding */
  188. INT16 (*b_back_mv_table)[2]; /* MV table (1MV per MB) backward mode b-frame encoding */
  189. INT16 (*b_bidir_forw_mv_table)[2]; /* MV table (1MV per MB) bidir mode b-frame encoding */
  190. INT16 (*b_bidir_back_mv_table)[2]; /* MV table (1MV per MB) bidir mode b-frame encoding */
  191. INT16 (*b_direct_forw_mv_table)[2];/* MV table (1MV per MB) direct mode b-frame encoding */
  192. INT16 (*b_direct_back_mv_table)[2];/* MV table (1MV per MB) direct mode b-frame encoding */
  193. INT16 (*b_direct_mv_table)[2]; /* MV table (1MV per MB) direct mode b-frame encoding */
  194. int me_method; /* ME algorithm */
  195. uint8_t *me_scratchpad; /* data area for the me algo, so that the ME doesnt need to malloc/free */
  196. uint32_t *me_map; /* map to avoid duplicate evaluations */
  197. uint16_t *me_score_map; /* map to store the SADs */
  198. int me_map_generation;
  199. int skip_me; /* set if ME is skiped for the current MB */
  200. int scene_change_score;
  201. int mv_dir;
  202. #define MV_DIR_BACKWARD 1
  203. #define MV_DIR_FORWARD 2
  204. #define MV_DIRECT 4 // bidirectional mode where the difference equals the MV of the last P/S/I-Frame (mpeg4)
  205. int mv_type;
  206. #define MV_TYPE_16X16 0 /* 1 vector for the whole mb */
  207. #define MV_TYPE_8X8 1 /* 4 vectors (h263, mpeg4 4MV) */
  208. #define MV_TYPE_16X8 2 /* 2 vectors, one per 16x8 block */
  209. #define MV_TYPE_FIELD 3 /* 2 vectors, one per field */
  210. #define MV_TYPE_DMV 4 /* 2 vectors, special mpeg2 Dual Prime Vectors */
  211. /* motion vectors for a macroblock
  212. first coordinate : 0 = forward 1 = backward
  213. second " : depend on type
  214. third " : 0 = x, 1 = y
  215. */
  216. int mv[2][4][2];
  217. int field_select[2][2];
  218. int last_mv[2][2][2]; /* last MV, used for MV prediction in MPEG1 & B-frame MPEG4 */
  219. UINT16 (*mv_penalty)[MAX_MV*2+1]; /* amount of bits needed to encode a MV, used for ME */
  220. UINT8 *fcode_tab; /* smallest fcode needed for each MV */
  221. int has_b_frames;
  222. int no_rounding; /* apply no rounding to motion compensation (MPEG4, msmpeg4, ...)
  223. for b-frames rounding mode is allways 0 */
  224. int hurry_up; /* when set to 1 during decoding, b frames will be skiped
  225. when set to 2 idct/dequant will be skipped too */
  226. /* macroblock layer */
  227. int mb_x, mb_y;
  228. int mb_incr;
  229. int mb_intra;
  230. UINT16 *mb_var; /* Table for MB variances */
  231. UINT16 *mc_mb_var; /* Table for motion compensated MB variances */
  232. UINT8 *mb_mean; /* Table for MB luminance */
  233. UINT8 *mb_type; /* Table for MB type */
  234. #define MB_TYPE_INTRA 0x01
  235. #define MB_TYPE_INTER 0x02
  236. #define MB_TYPE_INTER4V 0x04
  237. #define MB_TYPE_SKIPED 0x08
  238. #define MB_TYPE_GMC 0x10
  239. #define MB_TYPE_DIRECT 0x10
  240. #define MB_TYPE_FORWARD 0x20
  241. #define MB_TYPE_BACKWARD 0x40
  242. #define MB_TYPE_BIDIR 0x80
  243. int block_index[6]; /* index to current MB in block based arrays with edges*/
  244. int block_wrap[6];
  245. /* matrix transmitted in the bitstream */
  246. UINT16 intra_matrix[64];
  247. UINT16 chroma_intra_matrix[64];
  248. UINT16 inter_matrix[64];
  249. UINT16 chroma_inter_matrix[64];
  250. #define QUANT_BIAS_SHIFT 4
  251. int intra_quant_bias; /* bias for the quantizer */
  252. int inter_quant_bias; /* bias for the quantizer */
  253. int min_qcoeff; /* minimum encodable coefficient */
  254. int max_qcoeff; /* maximum encodable coefficient */
  255. /* precomputed matrix (combine qscale and DCT renorm) */
  256. int q_intra_matrix[32][64];
  257. int q_inter_matrix[32][64];
  258. /* identical to the above but for MMX & these are not permutated */
  259. UINT16 __align8 q_intra_matrix16[32][64];
  260. UINT16 __align8 q_inter_matrix16[32][64];
  261. UINT16 __align8 q_intra_matrix16_bias[32][64];
  262. UINT16 __align8 q_inter_matrix16_bias[32][64];
  263. int block_last_index[6]; /* last non zero coefficient in block */
  264. void *opaque; /* private data for the user */
  265. /* bit rate control */
  266. int I_frame_bits; //FIXME used in mpeg12 ...
  267. int mb_var_sum; /* sum of MB variance for current frame */
  268. int mc_mb_var_sum; /* motion compensated MB variance for current frame */
  269. INT64 wanted_bits;
  270. INT64 total_bits;
  271. int frame_bits; /* bits used for the current frame */
  272. RateControlContext rc_context; // contains stuff only accessed in ratecontrol.c
  273. /* statistics, used for 2-pass encoding */
  274. int mv_bits;
  275. int header_bits;
  276. int i_tex_bits;
  277. int p_tex_bits;
  278. int i_count;
  279. int f_count;
  280. int b_count;
  281. int skip_count;
  282. int misc_bits; // cbp, mb_type
  283. int last_bits; //temp var used for calculating the above vars
  284. /* error concealment / resync */
  285. int resync_mb_x; /* x position of last resync marker */
  286. int resync_mb_y; /* y position of last resync marker */
  287. int mb_num_left; /* number of MBs left in this video packet */
  288. GetBitContext next_resync_gb; /* starts at the next resync marker */
  289. int next_resync_qscale; /* qscale of next resync marker */
  290. int next_resync_pos; /* bitstream position of next resync marker */
  291. #define DECODING_AC_LOST -1
  292. #define DECODING_ACDC_LOST -2
  293. #define DECODING_DESYNC -3
  294. int decoding_error;
  295. int next_p_frame_damaged; /* set if the next p frame is damaged, to avoid showing trashed b frames */
  296. int error_resilience;
  297. /* H.263 specific */
  298. int gob_number;
  299. int gob_index;
  300. /* H.263+ specific */
  301. int umvplus;
  302. int umvplus_dec;
  303. int h263_aic; /* Advanded INTRA Coding (AIC) */
  304. int h263_aic_dir; /* AIC direction: 0 = left, 1 = top */
  305. /* mpeg4 specific */
  306. int time_increment_resolution;
  307. int time_increment_bits; /* number of bits to represent the fractional part of time */
  308. int last_time_base;
  309. int time_base; /* time in seconds of last I,P,S Frame */
  310. INT64 time; /* time of current frame */
  311. INT64 last_non_b_time;
  312. UINT16 pp_time; /* time distance between the last 2 p,s,i frames */
  313. UINT16 pb_time; /* time distance between the last b and p,s,i frame */
  314. UINT16 pp_field_time;
  315. UINT16 pb_field_time; /* like above, just for interlaced */
  316. int shape;
  317. int vol_sprite_usage;
  318. int sprite_width;
  319. int sprite_height;
  320. int sprite_left;
  321. int sprite_top;
  322. int sprite_brightness_change;
  323. int num_sprite_warping_points;
  324. int real_sprite_warping_points;
  325. int sprite_offset[2][2];
  326. int sprite_delta[2][2][2];
  327. int sprite_shift[2][2];
  328. int mcsel;
  329. int quant_precision;
  330. int quarter_sample; /* 1->qpel, 0->half pel ME/MC */
  331. int scalability;
  332. int hierachy_type;
  333. int enhancement_type;
  334. int new_pred;
  335. int reduced_res_vop;
  336. int aspect_ratio_info;
  337. int aspected_width;
  338. int aspected_height;
  339. int sprite_warping_accuracy;
  340. int low_latency_sprite;
  341. int data_partitioning;
  342. int rvlc; /* reversible vlc */
  343. int resync_marker; /* could this stream contain resync markers*/
  344. int low_delay; /* no reordering needed / has no b-frames */
  345. int vo_type;
  346. int vol_control_parameters; /* does the stream contain the low_delay flag, used to workaround buggy encoders */
  347. PutBitContext tex_pb; /* used for data partitioned VOPs */
  348. PutBitContext pb2; /* used for data partitioned VOPs */
  349. #define PB_BUFFER_SIZE 1024*256
  350. uint8_t *tex_pb_buffer;
  351. uint8_t *pb2_buffer;
  352. int mpeg_quant;
  353. #define CO_LOCATED_TYPE_4MV 1
  354. #define CO_LOCATED_TYPE_FIELDMV 2
  355. INT8 *co_located_type_table; /* 4mv & field_mv info for next b frame */
  356. INT16 (*field_mv_table)[2][2]; /* used for interlaced b frame decoding */
  357. INT8 (*field_select_table)[2]; /* wtf, no really another table for interlaced b frames */
  358. int t_frame; /* time distance of first I -> B, used for interlaced b frames */
  359. /* divx specific, used to workaround (many) bugs in divx5 */
  360. int divx_version;
  361. int divx_build;
  362. #define BITSTREAM_BUFFER_SIZE 1024*256
  363. UINT8 *bitstream_buffer; //Divx 5.01 puts several frames in a single one, this is used to reorder them
  364. int bitstream_buffer_size;
  365. /* RV10 specific */
  366. int rv10_version; /* RV10 version: 0 or 3 */
  367. int rv10_first_dc_coded[3];
  368. /* MJPEG specific */
  369. struct MJpegContext *mjpeg_ctx;
  370. int mjpeg_vsample[3]; /* vertical sampling factors, default = {2, 1, 1} */
  371. int mjpeg_hsample[3]; /* horizontal sampling factors, default = {2, 1, 1} */
  372. int mjpeg_write_tables; /* do we want to have quantisation- and
  373. huffmantables in the jpeg file ? */
  374. int mjpeg_data_only_frames; /* frames only with SOI, SOS and EOI markers */
  375. /* MSMPEG4 specific */
  376. int mv_table_index;
  377. int rl_table_index;
  378. int rl_chroma_table_index;
  379. int dc_table_index;
  380. int use_skip_mb_code;
  381. int slice_height; /* in macroblocks */
  382. int first_slice_line; /* used in mpeg4 too to handle resync markers */
  383. int flipflop_rounding;
  384. int msmpeg4_version; /* 0=not msmpeg4, 1=mp41, 2=mp42, 3=mp43/divx3 4=wmv1/7 5=wmv2/8*/
  385. int per_mb_rl_table;
  386. int esc3_level_length;
  387. int esc3_run_length;
  388. UINT8 *inter_scantable;
  389. UINT8 *intra_scantable;
  390. UINT8 *intra_v_scantable;
  391. UINT8 *intra_h_scantable;
  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. /* decompression specific */
  396. GetBitContext gb;
  397. /* MPEG2 specific - I wish I had not to support this mess. */
  398. int progressive_sequence;
  399. int mpeg_f_code[2][2];
  400. int picture_structure;
  401. /* picture type */
  402. #define PICT_TOP_FIELD 1
  403. #define PICT_BOTTOM_FIELD 2
  404. #define PICT_FRAME 3
  405. int intra_dc_precision;
  406. int frame_pred_frame_dct;
  407. int top_field_first;
  408. int concealment_motion_vectors;
  409. int q_scale_type;
  410. int intra_vlc_format;
  411. int alternate_scan;
  412. int repeat_first_field;
  413. int chroma_420_type;
  414. int progressive_frame;
  415. int mpeg2;
  416. int full_pel[2];
  417. int interlaced_dct;
  418. int last_qscale;
  419. int first_slice;
  420. /* RTP specific */
  421. /* These are explained on avcodec.h */
  422. int rtp_mode;
  423. int rtp_payload_size;
  424. void (*rtp_callback)(void *data, int size, int packet_number);
  425. UINT8 *ptr_lastgob;
  426. UINT8 *ptr_last_mb_line;
  427. UINT32 mb_line_avgsize;
  428. DCTELEM (*block)[64]; /* points to one of the following blocks */
  429. DCTELEM blocks[2][6][64] __align8; // for HQ mode we need to keep the best block
  430. void (*dct_unquantize_mpeg1)(struct MpegEncContext *s,
  431. DCTELEM *block, int n, int qscale);
  432. void (*dct_unquantize_mpeg2)(struct MpegEncContext *s,
  433. DCTELEM *block, int n, int qscale);
  434. void (*dct_unquantize_h263)(struct MpegEncContext *s,
  435. DCTELEM *block, int n, int qscale);
  436. void (*dct_unquantize)(struct MpegEncContext *s, // unquantizer to use (mpeg4 can use both)
  437. DCTELEM *block, int n, int qscale);
  438. int (*dct_quantize)(struct MpegEncContext *s, DCTELEM *block, int n, int qscale, int *overflow);
  439. void (*fdct)(DCTELEM *block);
  440. } MpegEncContext;
  441. int MPV_common_init(MpegEncContext *s);
  442. void MPV_common_end(MpegEncContext *s);
  443. void MPV_decode_mb(MpegEncContext *s, DCTELEM block[6][64]);
  444. void MPV_frame_start(MpegEncContext *s, AVCodecContext *avctx);
  445. void MPV_frame_end(MpegEncContext *s);
  446. #ifdef HAVE_MMX
  447. void MPV_common_init_mmx(MpegEncContext *s);
  448. #endif
  449. #ifdef ARCH_ALPHA
  450. void MPV_common_init_axp(MpegEncContext *s);
  451. #endif
  452. #ifdef HAVE_MLIB
  453. void MPV_common_init_mlib(MpegEncContext *s);
  454. #endif
  455. extern void (*draw_edges)(UINT8 *buf, int wrap, int width, int height, int w);
  456. void ff_conceal_past_errors(MpegEncContext *s, int conceal_all);
  457. void ff_copy_bits(PutBitContext *pb, UINT8 *src, int length);
  458. void ff_clean_intra_table_entries(MpegEncContext *s);
  459. extern int ff_bit_exact;
  460. /* motion_est.c */
  461. void ff_estimate_p_frame_motion(MpegEncContext * s,
  462. int mb_x, int mb_y);
  463. void ff_estimate_b_frame_motion(MpegEncContext * s,
  464. int mb_x, int mb_y);
  465. int ff_get_best_fcode(MpegEncContext * s, int16_t (*mv_table)[2], int type);
  466. void ff_fix_long_p_mvs(MpegEncContext * s);
  467. void ff_fix_long_b_mvs(MpegEncContext * s, int16_t (*mv_table)[2], int f_code, int type);
  468. /* mpeg12.c */
  469. extern INT16 ff_mpeg1_default_intra_matrix[64];
  470. extern INT16 ff_mpeg1_default_non_intra_matrix[64];
  471. extern UINT8 ff_mpeg1_dc_scale_table[128];
  472. void mpeg1_encode_picture_header(MpegEncContext *s, int picture_number);
  473. void mpeg1_encode_mb(MpegEncContext *s,
  474. DCTELEM block[6][64],
  475. int motion_x, int motion_y);
  476. void ff_mpeg1_encode_init(MpegEncContext *s);
  477. /* h263enc.c */
  478. typedef struct RLTable {
  479. int n; /* number of entries of table_vlc minus 1 */
  480. int last; /* number of values for last = 0 */
  481. const UINT16 (*table_vlc)[2];
  482. const INT8 *table_run;
  483. const INT8 *table_level;
  484. UINT8 *index_run[2]; /* encoding only */
  485. INT8 *max_level[2]; /* encoding & decoding */
  486. INT8 *max_run[2]; /* encoding & decoding */
  487. VLC vlc; /* decoding only deprected FIXME remove*/
  488. RL_VLC_ELEM *rl_vlc[32]; /* decoding only */
  489. } RLTable;
  490. void init_rl(RLTable *rl);
  491. void init_vlc_rl(RLTable *rl);
  492. static inline int get_rl_index(const RLTable *rl, int last, int run, int level)
  493. {
  494. int index;
  495. index = rl->index_run[last][run];
  496. if (index >= rl->n)
  497. return rl->n;
  498. if (level > rl->max_level[last][run])
  499. return rl->n;
  500. return index + level - 1;
  501. }
  502. extern UINT8 ff_mpeg4_y_dc_scale_table[32];
  503. extern UINT8 ff_mpeg4_c_dc_scale_table[32];
  504. extern INT16 ff_mpeg4_default_intra_matrix[64];
  505. extern INT16 ff_mpeg4_default_non_intra_matrix[64];
  506. void h263_encode_mb(MpegEncContext *s,
  507. DCTELEM block[6][64],
  508. int motion_x, int motion_y);
  509. void mpeg4_encode_mb(MpegEncContext *s,
  510. DCTELEM block[6][64],
  511. int motion_x, int motion_y);
  512. void h263_encode_picture_header(MpegEncContext *s, int picture_number);
  513. int h263_encode_gob_header(MpegEncContext * s, int mb_line);
  514. INT16 *h263_pred_motion(MpegEncContext * s, int block,
  515. int *px, int *py);
  516. void mpeg4_pred_ac(MpegEncContext * s, INT16 *block, int n,
  517. int dir);
  518. void ff_set_mpeg4_time(MpegEncContext * s, int picture_number);
  519. void mpeg4_encode_picture_header(MpegEncContext *s, int picture_number);
  520. void h263_encode_init(MpegEncContext *s);
  521. void h263_decode_init_vlc(MpegEncContext *s);
  522. int h263_decode_picture_header(MpegEncContext *s);
  523. int h263_decode_gob_header(MpegEncContext *s);
  524. int mpeg4_decode_picture_header(MpegEncContext * s);
  525. int intel_h263_decode_picture_header(MpegEncContext *s);
  526. int h263_decode_mb(MpegEncContext *s,
  527. DCTELEM block[6][64]);
  528. int h263_get_picture_format(int width, int height);
  529. int ff_mpeg4_decode_video_packet_header(MpegEncContext *s);
  530. int ff_mpeg4_resync(MpegEncContext *s);
  531. void ff_mpeg4_encode_video_packet_header(MpegEncContext *s);
  532. void ff_mpeg4_clean_buffers(MpegEncContext *s);
  533. void ff_mpeg4_stuffing(PutBitContext * pbc);
  534. void ff_mpeg4_init_partitions(MpegEncContext *s);
  535. void ff_mpeg4_merge_partitions(MpegEncContext *s);
  536. extern inline int ff_mpeg4_pred_dc(MpegEncContext * s, int n, UINT16 **dc_val_ptr, int *dir_ptr);
  537. void ff_clean_mpeg4_qscales(MpegEncContext *s);
  538. void ff_clean_h263_qscales(MpegEncContext *s);
  539. /* rv10.c */
  540. void rv10_encode_picture_header(MpegEncContext *s, int picture_number);
  541. int rv_decode_dc(MpegEncContext *s, int n);
  542. /* msmpeg4.c */
  543. void msmpeg4_encode_picture_header(MpegEncContext * s, int picture_number);
  544. void msmpeg4_encode_ext_header(MpegEncContext * s);
  545. void msmpeg4_encode_mb(MpegEncContext * s,
  546. DCTELEM block[6][64],
  547. int motion_x, int motion_y);
  548. int msmpeg4_decode_picture_header(MpegEncContext * s);
  549. int msmpeg4_decode_ext_header(MpegEncContext * s, int buf_size);
  550. int msmpeg4_decode_mb(MpegEncContext *s,
  551. DCTELEM block[6][64]);
  552. int ff_msmpeg4_decode_init(MpegEncContext *s);
  553. void ff_msmpeg4_encode_init(MpegEncContext *s);
  554. /* mjpegenc.c */
  555. int mjpeg_init(MpegEncContext *s);
  556. void mjpeg_close(MpegEncContext *s);
  557. void mjpeg_encode_mb(MpegEncContext *s,
  558. DCTELEM block[6][64]);
  559. void mjpeg_picture_header(MpegEncContext *s);
  560. void mjpeg_picture_trailer(MpegEncContext *s);
  561. /* rate control */
  562. int ff_rate_control_init(MpegEncContext *s);
  563. float ff_rate_estimate_qscale(MpegEncContext *s);
  564. void ff_write_pass1_stats(MpegEncContext *s);
  565. void ff_rate_control_uninit(MpegEncContext *s);
  566. double ff_eval(char *s, double *const_value, char **const_name,
  567. double (**func1)(void *, double), char **func1_name,
  568. double (**func2)(void *, double, double), char **func2_name,
  569. void *opaque);
  570. #endif /* AVCODEC_MPEGVIDEO_H */