]> git.sesse.net Git - ffmpeg/blob - libavcodec/motion_est.h
lavu: Remove bit packing from AVComponentDescriptor
[ffmpeg] / libavcodec / motion_est.h
1 /*
2  * Motion estimation
3  *
4  * This file is part of Libav.
5  *
6  * Libav 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.
10  *
11  * Libav 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.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with Libav; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20
21 #ifndef AVCODEC_MOTIONEST_H
22 #define AVCODEC_MOTIONEST_H
23
24 #include <stdint.h>
25
26 #include "avcodec.h"
27 #include "hpeldsp.h"
28 #include "qpeldsp.h"
29
30 struct MpegEncContext;
31
32 #define MAX_MV 2048
33
34 #define FF_ME_ZERO 0
35 #define FF_ME_EPZS 1
36 #define FF_ME_XONE 2
37
38 /**
39  * Motion estimation context.
40  */
41 typedef struct MotionEstContext {
42     AVCodecContext *avctx;
43     int skip;                       ///< set if ME is skipped for the current MB
44     int co_located_mv[4][2];        ///< mv from last P-frame for direct mode ME
45     int direct_basis_mv[4][2];
46     uint8_t *scratchpad;            /**< data area for the ME algo, so that
47                                      * the ME does not need to malloc/free. */
48     uint8_t *best_mb;
49     uint8_t *temp_mb[2];
50     uint8_t *temp;
51     int best_bits;
52     uint32_t *map;                  ///< map to avoid duplicate evaluations
53     uint32_t *score_map;            ///< map to store the scores
54     unsigned map_generation;
55     int pre_penalty_factor;
56     int penalty_factor;             /**< an estimate of the bits required to
57                                      * code a given mv value, e.g. (1,0) takes
58                                      * more bits than (0,0). We have to
59                                      * estimate whether any reduction in
60                                      * residual is worth the extra bits. */
61     int sub_penalty_factor;
62     int mb_penalty_factor;
63     int flags;
64     int sub_flags;
65     int mb_flags;
66     int pre_pass;                   ///< = 1 for the pre pass
67     int dia_size;
68     int xmin;
69     int xmax;
70     int ymin;
71     int ymax;
72     int pred_x;
73     int pred_y;
74     uint8_t *src[4][4];
75     uint8_t *ref[4][4];
76     int stride;
77     int uvstride;
78     /* temp variables for picture complexity calculation */
79     int mc_mb_var_sum_temp;
80     int mb_var_sum_temp;
81     int scene_change_score;
82
83     op_pixels_func(*hpel_put)[4];
84     op_pixels_func(*hpel_avg)[4];
85     qpel_mc_func(*qpel_put)[16];
86     qpel_mc_func(*qpel_avg)[16];
87     uint8_t (*mv_penalty)[MAX_MV * 2 + 1]; ///< bit amount needed to encode a MV
88     uint8_t *current_mv_penalty;
89     int (*sub_motion_search)(struct MpegEncContext *s,
90                              int *mx_ptr, int *my_ptr, int dmin,
91                              int src_index, int ref_index,
92                              int size, int h);
93 } MotionEstContext;
94
95 static inline int ff_h263_round_chroma(int x)
96 {
97     //FIXME static or not?
98     static const uint8_t h263_chroma_roundtab[16] = {
99     //  0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15
100         0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1,
101     };
102     return h263_chroma_roundtab[x & 0xf] + (x >> 3);
103 }
104
105 int ff_init_me(struct MpegEncContext *s);
106
107 void ff_estimate_p_frame_motion(struct MpegEncContext *s, int mb_x, int mb_y);
108 void ff_estimate_b_frame_motion(struct MpegEncContext *s, int mb_x, int mb_y);
109
110 int ff_pre_estimate_p_frame_motion(struct MpegEncContext *s,
111                                    int mb_x, int mb_y);
112
113 int ff_epzs_motion_search(struct MpegEncContext *s, int *mx_ptr, int *my_ptr,
114                           int P[10][2], int src_index, int ref_index,
115                           int16_t (*last_mv)[2], int ref_mv_scale, int size,
116                           int h);
117
118 int ff_get_mb_score(struct MpegEncContext *s, int mx, int my, int src_index,
119                     int ref_index, int size, int h, int add_rate);
120
121 int ff_get_best_fcode(struct MpegEncContext *s,
122                       int16_t (*mv_table)[2], int type);
123
124 void ff_fix_long_p_mvs(struct MpegEncContext *s);
125 void ff_fix_long_mvs(struct MpegEncContext *s, uint8_t *field_select_table,
126                      int field_select, int16_t (*mv_table)[2], int f_code,
127                      int type, int truncate);
128
129 #endif /* AVCODEC_MOTIONEST_H */