4 * This file is part of FFmpeg.
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 #ifndef AVCODEC_MOTIONEST_H
22 #define AVCODEC_MOTIONEST_H
30 struct MpegEncContext;
33 #define ME_MAP_SIZE 64
40 * Motion estimation context.
42 typedef struct MotionEstContext {
43 AVCodecContext *avctx;
44 int skip; ///< set if ME is skipped for the current MB
45 int co_located_mv[4][2]; ///< mv from last P-frame for direct mode ME
46 int direct_basis_mv[4][2];
47 uint8_t *scratchpad; /**< data area for the ME algo, so that
48 * the ME does not need to malloc/free. */
53 uint32_t *map; ///< map to avoid duplicate evaluations
54 uint32_t *score_map; ///< map to store the scores
55 unsigned map_generation;
56 int pre_penalty_factor;
57 int penalty_factor; /**< an estimate of the bits required to
58 * code a given mv value, e.g. (1,0) takes
59 * more bits than (0,0). We have to
60 * estimate whether any reduction in
61 * residual is worth the extra bits. */
62 int sub_penalty_factor;
63 int mb_penalty_factor;
67 int pre_pass; ///< = 1 for the pre pass
79 /* temp variables for picture complexity calculation */
80 int64_t mc_mb_var_sum_temp;
81 int64_t mb_var_sum_temp;
82 int scene_change_score;
84 op_pixels_func(*hpel_put)[4];
85 op_pixels_func(*hpel_avg)[4];
86 qpel_mc_func(*qpel_put)[16];
87 qpel_mc_func(*qpel_avg)[16];
88 uint8_t (*mv_penalty)[MAX_MV * 2 + 1]; ///< bit amount needed to encode a MV
89 uint8_t *current_mv_penalty;
90 int (*sub_motion_search)(struct MpegEncContext *s,
91 int *mx_ptr, int *my_ptr, int dmin,
92 int src_index, int ref_index,
96 static inline int ff_h263_round_chroma(int x)
98 //FIXME static or not?
99 static const uint8_t h263_chroma_roundtab[16] = {
100 // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
101 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1,
103 return h263_chroma_roundtab[x & 0xf] + (x >> 3);
106 int ff_init_me(struct MpegEncContext *s);
108 void ff_estimate_p_frame_motion(struct MpegEncContext *s, int mb_x, int mb_y);
109 void ff_estimate_b_frame_motion(struct MpegEncContext *s, int mb_x, int mb_y);
111 int ff_pre_estimate_p_frame_motion(struct MpegEncContext *s,
114 int ff_epzs_motion_search(struct MpegEncContext *s, int *mx_ptr, int *my_ptr,
115 int P[10][2], int src_index, int ref_index,
116 int16_t (*last_mv)[2], int ref_mv_scale, int size,
119 int ff_get_mb_score(struct MpegEncContext *s, int mx, int my, int src_index,
120 int ref_index, int size, int h, int add_rate);
122 int ff_get_best_fcode(struct MpegEncContext *s,
123 int16_t (*mv_table)[2], int type);
125 void ff_fix_long_p_mvs(struct MpegEncContext *s);
126 void ff_fix_long_mvs(struct MpegEncContext *s, uint8_t *field_select_table,
127 int field_select, int16_t (*mv_table)[2], int f_code,
128 int type, int truncate);
130 #endif /* AVCODEC_MOTIONEST_H */