FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/motion_est.h
Date: 2024-07-17 14:05:47
Exec Total Coverage
Lines: 2 2 100.0%
Functions: 1 1 100.0%
Branches: 0 0 -%

Line Branch Exec Source
1 /*
2 * Motion estimation
3 *
4 * This file is part of FFmpeg.
5 *
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.
10 *
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.
15 *
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
19 */
20
21 #ifndef AVCODEC_MOTION_EST_H
22 #define AVCODEC_MOTION_EST_H
23
24 #include <stdint.h>
25
26 #include "avcodec.h"
27 #include "hpeldsp.h"
28 #include "me_cmp.h"
29 #include "qpeldsp.h"
30
31 struct MpegEncContext;
32
33 #if ARCH_IA64 // Limit static arrays to avoid gcc failing "short data segment overflowed"
34 #define MAX_MV 1024
35 #else
36 #define MAX_MV 4096
37 #endif
38 #define MAX_DMV (2*MAX_MV)
39 #define ME_MAP_SIZE 64
40
41 #define FF_ME_ZERO 0
42 #define FF_ME_EPZS 1
43 #define FF_ME_XONE 2
44
45 /**
46 * Motion estimation context.
47 */
48 typedef struct MotionEstContext {
49 AVCodecContext *avctx;
50 int skip; ///< set if ME is skipped for the current MB
51 int co_located_mv[4][2]; ///< mv from last P-frame for direct mode ME
52 int direct_basis_mv[4][2];
53 uint8_t *scratchpad; /**< data area for the ME algo, so that
54 * the ME does not need to malloc/free. */
55 uint8_t *temp;
56 uint32_t *map; ///< map to avoid duplicate evaluations
57 uint32_t *score_map; ///< map to store the scores
58 unsigned map_generation;
59 int pre_penalty_factor;
60 int penalty_factor; /**< an estimate of the bits required to
61 * code a given mv value, e.g. (1,0) takes
62 * more bits than (0,0). We have to
63 * estimate whether any reduction in
64 * residual is worth the extra bits. */
65 int sub_penalty_factor;
66 int mb_penalty_factor;
67 int flags;
68 int sub_flags;
69 int mb_flags;
70 int pre_pass; ///< = 1 for the pre pass
71 int dia_size;
72 int xmin;
73 int xmax;
74 int ymin;
75 int ymax;
76 int pred_x;
77 int pred_y;
78 const uint8_t *src[4][4];
79 const uint8_t *ref[4][4];
80 int stride;
81 int uvstride;
82 /* temp variables for picture complexity calculation */
83 int64_t mc_mb_var_sum_temp;
84 int64_t mb_var_sum_temp;
85 int scene_change_score;
86
87 me_cmp_func me_pre_cmp[6];
88 me_cmp_func me_cmp[6];
89 me_cmp_func me_sub_cmp[6];
90 me_cmp_func mb_cmp[6];
91
92 me_cmp_func pix_abs[2][4];
93 me_cmp_func sse;
94
95 op_pixels_func(*hpel_put)[4];
96 op_pixels_func(*hpel_avg)[4];
97 qpel_mc_func(*qpel_put)[16];
98 qpel_mc_func(*qpel_avg)[16];
99 const uint8_t (*mv_penalty)[MAX_DMV * 2 + 1]; ///< bit amount needed to encode a MV
100 const uint8_t *current_mv_penalty;
101 int (*sub_motion_search)(struct MpegEncContext *s,
102 int *mx_ptr, int *my_ptr, int dmin,
103 int src_index, int ref_index,
104 int size, int h);
105 } MotionEstContext;
106
107 1433662 static inline int ff_h263_round_chroma(int x)
108 {
109 //FIXME static or not?
110 static const uint8_t h263_chroma_roundtab[16] = {
111 // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
112 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1,
113 };
114 1433662 return h263_chroma_roundtab[x & 0xf] + (x >> 3);
115 }
116
117 /**
118 * Performs one-time initialization of the MotionEstContext.
119 */
120 int ff_me_init(MotionEstContext *c, struct AVCodecContext *avctx,
121 const struct MECmpContext *mecc, int mpvenc);
122
123 void ff_me_init_pic(struct MpegEncContext *s);
124
125 void ff_estimate_p_frame_motion(struct MpegEncContext *s, int mb_x, int mb_y);
126 void ff_estimate_b_frame_motion(struct MpegEncContext *s, int mb_x, int mb_y);
127
128 int ff_pre_estimate_p_frame_motion(struct MpegEncContext *s,
129 int mb_x, int mb_y);
130
131 int ff_epzs_motion_search(struct MpegEncContext *s, int *mx_ptr, int *my_ptr,
132 int P[10][2], int src_index, int ref_index,
133 const int16_t (*last_mv)[2], int ref_mv_scale,
134 int size, int h);
135
136 int ff_get_mb_score(struct MpegEncContext *s, int mx, int my, int src_index,
137 int ref_index, int size, int h, int add_rate);
138
139 int ff_get_best_fcode(struct MpegEncContext *s,
140 const int16_t (*mv_table)[2], int type);
141
142 void ff_fix_long_p_mvs(struct MpegEncContext *s, int type);
143 void ff_fix_long_mvs(struct MpegEncContext *s, uint8_t *field_select_table,
144 int field_select, int16_t (*mv_table)[2], int f_code,
145 int type, int truncate);
146
147 #endif /* AVCODEC_MOTION_EST_H */
148