FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/motion_est.c
Date: 2022-11-28 23:49:43
Exec Total Coverage
Lines: 861 1000 86.1%
Branches: 500 619 80.8%

Line Branch Exec Source
1 /*
2 * Motion estimation
3 * Copyright (c) 2000,2001 Fabrice Bellard
4 * Copyright (c) 2002-2004 Michael Niedermayer
5 *
6 * new motion estimation (X1/EPZS) by Michael Niedermayer <michaelni@gmx.at>
7 *
8 * This file is part of FFmpeg.
9 *
10 * FFmpeg is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
14 *
15 * FFmpeg is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with FFmpeg; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 */
24
25 /**
26 * @file
27 * Motion estimation.
28 */
29
30 #include <stdlib.h>
31 #include <stdio.h>
32 #include <limits.h>
33
34 #include "avcodec.h"
35 #include "mathops.h"
36 #include "motion_est.h"
37 #include "mpegutils.h"
38 #include "mpegvideoenc.h"
39
40 #define P_LEFT P[1]
41 #define P_TOP P[2]
42 #define P_TOPRIGHT P[3]
43 #define P_MEDIAN P[4]
44 #define P_MV1 P[9]
45
46 #define ME_MAP_SHIFT 3
47 #define ME_MAP_MV_BITS 11
48
49 static int sad_hpel_motion_search(MpegEncContext * s,
50 int *mx_ptr, int *my_ptr, int dmin,
51 int src_index, int ref_index,
52 int size, int h);
53
54 5544232 static inline unsigned update_map_generation(MotionEstContext *c)
55 {
56 5544232 c->map_generation+= 1<<(ME_MAP_MV_BITS*2);
57
2/2
✓ Branch 0 taken 5344 times.
✓ Branch 1 taken 5538888 times.
5544232 if(c->map_generation==0){
58 5344 c->map_generation= 1<<(ME_MAP_MV_BITS*2);
59 5344 memset(c->map, 0, sizeof(uint32_t)*ME_MAP_SIZE);
60 }
61 5544232 return c->map_generation;
62 }
63
64 /* shape adaptive search stuff */
65 typedef struct Minima{
66 int height;
67 int x, y;
68 int checked;
69 }Minima;
70
71 static int minima_cmp(const void *a, const void *b){
72 const Minima *da = (const Minima *) a;
73 const Minima *db = (const Minima *) b;
74
75 return da->height - db->height;
76 }
77
78 #define FLAG_QPEL 1 //must be 1
79 #define FLAG_CHROMA 2
80 #define FLAG_DIRECT 4
81
82 2336814 static inline void init_ref(MotionEstContext *c, uint8_t *const src[3],
83 uint8_t *const ref[3], uint8_t *const ref2[3],
84 int x, int y, int ref_index)
85 {
86 2336814 const int offset[3]= {
87 2336814 y*c-> stride + x,
88 2336814 ((y*c->uvstride + x)>>1),
89 2336814 ((y*c->uvstride + x)>>1),
90 };
91 int i;
92
2/2
✓ Branch 0 taken 7010442 times.
✓ Branch 1 taken 2336814 times.
9347256 for(i=0; i<3; i++){
93 7010442 c->src[0][i]= src [i] + offset[i];
94 7010442 c->ref[0][i]= ref [i] + offset[i];
95 }
96
2/2
✓ Branch 0 taken 408312 times.
✓ Branch 1 taken 1928502 times.
2336814 if(ref_index){
97
2/2
✓ Branch 0 taken 1224936 times.
✓ Branch 1 taken 408312 times.
1633248 for(i=0; i<3; i++){
98 1224936 c->ref[ref_index][i]= ref2[i] + offset[i];
99 }
100 }
101 2336814 }
102
103 30252 static int get_flags(MotionEstContext *c, int direct, int chroma){
104 30252 return ((c->avctx->flags&AV_CODEC_FLAG_QPEL) ? FLAG_QPEL : 0)
105
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 30252 times.
30252 + (direct ? FLAG_DIRECT : 0)
106
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 30252 times.
30252 + (chroma ? FLAG_CHROMA : 0);
107 }
108
109 2665836 static av_always_inline int cmp_direct_inline(MpegEncContext *s, const int x, const int y, const int subx, const int suby,
110 const int size, const int h, int ref_index, int src_index,
111 me_cmp_func cmp_func, me_cmp_func chroma_cmp_func, int qpel){
112 2665836 MotionEstContext * const c= &s->me;
113 2665836 const int stride= c->stride;
114 2665836 const int hx = subx + x * (1 << (1 + qpel));
115 2665836 const int hy = suby + y * (1 << (1 + qpel));
116 2665836 const uint8_t * const * const ref = c->ref[ref_index];
117 2665836 const uint8_t * const * const src = c->src[src_index];
118 int d;
119 //FIXME check chroma 4mv, (no crashes ...)
120 av_assert2(x >= c->xmin && hx <= c->xmax<<(qpel+1) && y >= c->ymin && hy <= c->ymax<<(qpel+1));
121
4/8
✓ Branch 0 taken 2665836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2665836 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2665836 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2665836 times.
✗ Branch 7 not taken.
5331672 if(x >= c->xmin && hx <= c->xmax<<(qpel+1) && y >= c->ymin && hy <= c->ymax<<(qpel+1)){
122 2665836 const int time_pp= s->pp_time;
123 2665836 const int time_pb= s->pb_time;
124 2665836 const int mask= 2*qpel+1;
125
2/2
✓ Branch 0 taken 667160 times.
✓ Branch 1 taken 1998676 times.
2665836 if(s->mv_type==MV_TYPE_8X8){
126 int i;
127
2/2
✓ Branch 0 taken 2668640 times.
✓ Branch 1 taken 667160 times.
3335800 for(i=0; i<4; i++){
128 2668640 int fx = c->direct_basis_mv[i][0] + hx;
129 2668640 int fy = c->direct_basis_mv[i][1] + hy;
130
2/2
✓ Branch 0 taken 1689660 times.
✓ Branch 1 taken 978980 times.
2668640 int bx = hx ? fx - c->co_located_mv[i][0] : c->co_located_mv[i][0]*(time_pb - time_pp)/time_pp + ((i &1)<<(qpel+4));
131
2/2
✓ Branch 0 taken 1648144 times.
✓ Branch 1 taken 1020496 times.
2668640 int by = hy ? fy - c->co_located_mv[i][1] : c->co_located_mv[i][1]*(time_pb - time_pp)/time_pp + ((i>>1)<<(qpel+4));
132 2668640 int fxy= (fx&mask) + ((fy&mask)<<(qpel+1));
133 2668640 int bxy= (bx&mask) + ((by&mask)<<(qpel+1));
134
135 2668640 uint8_t *dst= c->temp + 8*(i&1) + 8*stride*(i>>1);
136
2/2
✓ Branch 0 taken 961440 times.
✓ Branch 1 taken 1707200 times.
2668640 if(qpel){
137 961440 c->qpel_put[1][fxy](dst, ref[0] + (fx>>2) + (fy>>2)*stride, stride);
138 961440 c->qpel_avg[1][bxy](dst, ref[8] + (bx>>2) + (by>>2)*stride, stride);
139 }else{
140 1707200 c->hpel_put[1][fxy](dst, ref[0] + (fx>>1) + (fy>>1)*stride, stride, 8);
141 1707200 c->hpel_avg[1][bxy](dst, ref[8] + (bx>>1) + (by>>1)*stride, stride, 8);
142 }
143 }
144 }else{
145 1998676 int fx = c->direct_basis_mv[0][0] + hx;
146 1998676 int fy = c->direct_basis_mv[0][1] + hy;
147
2/2
✓ Branch 0 taken 1513793 times.
✓ Branch 1 taken 484883 times.
1998676 int bx = hx ? fx - c->co_located_mv[0][0] : (c->co_located_mv[0][0]*(time_pb - time_pp)/time_pp);
148
2/2
✓ Branch 0 taken 1470599 times.
✓ Branch 1 taken 528077 times.
1998676 int by = hy ? fy - c->co_located_mv[0][1] : (c->co_located_mv[0][1]*(time_pb - time_pp)/time_pp);
149 1998676 int fxy= (fx&mask) + ((fy&mask)<<(qpel+1));
150 1998676 int bxy= (bx&mask) + ((by&mask)<<(qpel+1));
151
152
2/2
✓ Branch 0 taken 433681 times.
✓ Branch 1 taken 1564995 times.
1998676 if(qpel){
153 433681 c->qpel_put[1][fxy](c->temp , ref[0] + (fx>>2) + (fy>>2)*stride , stride);
154 433681 c->qpel_put[1][fxy](c->temp + 8 , ref[0] + (fx>>2) + (fy>>2)*stride + 8 , stride);
155 433681 c->qpel_put[1][fxy](c->temp + 8*stride, ref[0] + (fx>>2) + (fy>>2)*stride + 8*stride, stride);
156 433681 c->qpel_put[1][fxy](c->temp + 8 + 8*stride, ref[0] + (fx>>2) + (fy>>2)*stride + 8 + 8*stride, stride);
157 433681 c->qpel_avg[1][bxy](c->temp , ref[8] + (bx>>2) + (by>>2)*stride , stride);
158 433681 c->qpel_avg[1][bxy](c->temp + 8 , ref[8] + (bx>>2) + (by>>2)*stride + 8 , stride);
159 433681 c->qpel_avg[1][bxy](c->temp + 8*stride, ref[8] + (bx>>2) + (by>>2)*stride + 8*stride, stride);
160 433681 c->qpel_avg[1][bxy](c->temp + 8 + 8*stride, ref[8] + (bx>>2) + (by>>2)*stride + 8 + 8*stride, stride);
161 }else{
162 av_assert2((fx>>1) + 16*s->mb_x >= -16);
163 av_assert2((fy>>1) + 16*s->mb_y >= -16);
164 av_assert2((fx>>1) + 16*s->mb_x <= s->width);
165 av_assert2((fy>>1) + 16*s->mb_y <= s->height);
166 av_assert2((bx>>1) + 16*s->mb_x >= -16);
167 av_assert2((by>>1) + 16*s->mb_y >= -16);
168 av_assert2((bx>>1) + 16*s->mb_x <= s->width);
169 av_assert2((by>>1) + 16*s->mb_y <= s->height);
170
171 1564995 c->hpel_put[0][fxy](c->temp, ref[0] + (fx>>1) + (fy>>1)*stride, stride, 16);
172 1564995 c->hpel_avg[0][bxy](c->temp, ref[8] + (bx>>1) + (by>>1)*stride, stride, 16);
173 }
174 }
175 2665836 d = cmp_func(s, c->temp, src[0], stride, 16);
176 }else
177 d= 256*256*256*32;
178 2665836 return d;
179 }
180
181 50074225 static av_always_inline int cmp_inline(MpegEncContext *s, const int x, const int y, const int subx, const int suby,
182 const int size, const int h, int ref_index, int src_index,
183 me_cmp_func cmp_func, me_cmp_func chroma_cmp_func, int qpel, int chroma){
184 50074225 MotionEstContext * const c= &s->me;
185 50074225 const int stride= c->stride;
186 50074225 const int uvstride= c->uvstride;
187 50074225 const int dxy= subx + (suby<<(1+qpel)); //FIXME log2_subpel?
188 50074225 const int hx= subx + x*(1<<(1+qpel));
189 50074225 const int hy= suby + y*(1<<(1+qpel));
190 50074225 const uint8_t * const * const ref = c->ref[ref_index];
191 50074225 const uint8_t * const * const src = c->src[src_index];
192 int d;
193 //FIXME check chroma 4mv, (no crashes ...)
194 int uvdxy; /* no, it might not be used uninitialized */
195
2/2
✓ Branch 0 taken 5524153 times.
✓ Branch 1 taken 44550072 times.
50074225 if(dxy){
196
2/2
✓ Branch 0 taken 3605224 times.
✓ Branch 1 taken 1918929 times.
5524153 if(qpel){
197
1/2
✓ Branch 0 taken 3605224 times.
✗ Branch 1 not taken.
3605224 if (h << size == 16) {
198 3605224 c->qpel_put[size][dxy](c->temp, ref[0] + x + y*stride, stride); //FIXME prototype (add h)
199 } else if (size == 0 && h == 8) {
200 c->qpel_put[1][dxy](c->temp , ref[0] + x + y*stride , stride);
201 c->qpel_put[1][dxy](c->temp + 8, ref[0] + x + y*stride + 8, stride);
202 } else
203 av_assert2(0);
204
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3605224 times.
3605224 if(chroma){
205 int cx= hx/2;
206 int cy= hy/2;
207 cx= (cx>>1)|(cx&1);
208 cy= (cy>>1)|(cy&1);
209 uvdxy= (cx&1) + 2*(cy&1);
210 // FIXME x/y wrong, but MPEG-4 qpel is sick anyway, we should drop as much of it as possible in favor for H.264
211 }
212 }else{
213 1918929 c->hpel_put[size][dxy](c->temp, ref[0] + x + y*stride, stride, h);
214
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1918929 times.
1918929 if(chroma)
215 uvdxy= dxy | (x&1) | (2*(y&1));
216 }
217 5524153 d = cmp_func(s, c->temp, src[0], stride, h);
218 }else{
219 44550072 d = cmp_func(s, src[0], ref[0] + x + y*stride, stride, h);
220
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 44550072 times.
44550072 if(chroma)
221 uvdxy= (x&1) + 2*(y&1);
222 }
223
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 50074225 times.
50074225 if(chroma){
224 uint8_t * const uvtemp= c->temp + 16*stride;
225 c->hpel_put[size+1][uvdxy](uvtemp , ref[1] + (x>>1) + (y>>1)*uvstride, uvstride, h>>1);
226 c->hpel_put[size+1][uvdxy](uvtemp+8, ref[2] + (x>>1) + (y>>1)*uvstride, uvstride, h>>1);
227 d += chroma_cmp_func(s, uvtemp , src[1], uvstride, h>>1);
228 d += chroma_cmp_func(s, uvtemp+8, src[2], uvstride, h>>1);
229 }
230 50074225 return d;
231 }
232
233 static int cmp_simple(MpegEncContext *s, const int x, const int y,
234 int ref_index, int src_index,
235 me_cmp_func cmp_func, me_cmp_func chroma_cmp_func){
236 return cmp_inline(s,x,y,0,0,0,16,ref_index,src_index, cmp_func, chroma_cmp_func, 0, 0);
237 }
238
239 static int cmp_fpel_internal(MpegEncContext *s, const int x, const int y,
240 const int size, const int h, int ref_index, int src_index,
241 me_cmp_func cmp_func, me_cmp_func chroma_cmp_func, const int flags){
242 if(flags&FLAG_DIRECT){
243 return cmp_direct_inline(s,x,y,0,0,size,h,ref_index,src_index, cmp_func, chroma_cmp_func, flags&FLAG_QPEL);
244 }else{
245 return cmp_inline(s,x,y,0,0,size,h,ref_index,src_index, cmp_func, chroma_cmp_func, 0, flags&FLAG_CHROMA);
246 }
247 }
248
249 46775881 static int cmp_internal(MpegEncContext *s, const int x, const int y, const int subx, const int suby,
250 const int size, const int h, int ref_index, int src_index,
251 me_cmp_func cmp_func, me_cmp_func chroma_cmp_func, const int flags){
252
2/2
✓ Branch 0 taken 1794244 times.
✓ Branch 1 taken 44981637 times.
46775881 if(flags&FLAG_DIRECT){
253 1794244 return cmp_direct_inline(s,x,y,subx,suby,size,h,ref_index,src_index, cmp_func, chroma_cmp_func, flags&FLAG_QPEL);
254 }else{
255 44981637 return cmp_inline(s,x,y,subx,suby,size,h,ref_index,src_index, cmp_func, chroma_cmp_func, flags&FLAG_QPEL, flags&FLAG_CHROMA);
256 }
257 }
258
259 /** @brief compares a block (either a full macroblock or a partition thereof)
260 against a proposed motion-compensated prediction of that block
261 */
262 46775881 static av_always_inline int cmp(MpegEncContext *s, const int x, const int y, const int subx, const int suby,
263 const int size, const int h, int ref_index, int src_index,
264 me_cmp_func cmp_func, me_cmp_func chroma_cmp_func, const int flags){
265 if(av_builtin_constant_p(flags) && av_builtin_constant_p(h) && av_builtin_constant_p(size)
266 && av_builtin_constant_p(subx) && av_builtin_constant_p(suby)
267 && flags==0 && h==16 && size==0 && subx==0 && suby==0){
268 return cmp_simple(s,x,y,ref_index,src_index, cmp_func, chroma_cmp_func);
269 }else if(av_builtin_constant_p(subx) && av_builtin_constant_p(suby)
270 && subx==0 && suby==0){
271 return cmp_fpel_internal(s,x,y,size,h,ref_index,src_index, cmp_func, chroma_cmp_func,flags);
272 }else{
273 46775881 return cmp_internal(s,x,y,subx,suby,size,h,ref_index,src_index, cmp_func, chroma_cmp_func, flags);
274 }
275 }
276
277 2330660 static int cmp_hpel(MpegEncContext *s, const int x, const int y, const int subx, const int suby,
278 const int size, const int h, int ref_index, int src_index,
279 me_cmp_func cmp_func, me_cmp_func chroma_cmp_func, const int flags){
280
2/2
✓ Branch 0 taken 598184 times.
✓ Branch 1 taken 1732476 times.
2330660 if(flags&FLAG_DIRECT){
281 598184 return cmp_direct_inline(s,x,y,subx,suby,size,h,ref_index,src_index, cmp_func, chroma_cmp_func, 0);
282 }else{
283 1732476 return cmp_inline(s,x,y,subx,suby,size,h,ref_index,src_index, cmp_func, chroma_cmp_func, 0, flags&FLAG_CHROMA);
284 }
285 }
286
287 3633520 static int cmp_qpel(MpegEncContext *s, const int x, const int y, const int subx, const int suby,
288 const int size, const int h, int ref_index, int src_index,
289 me_cmp_func cmp_func, me_cmp_func chroma_cmp_func, const int flags){
290
2/2
✓ Branch 0 taken 273408 times.
✓ Branch 1 taken 3360112 times.
3633520 if(flags&FLAG_DIRECT){
291 273408 return cmp_direct_inline(s,x,y,subx,suby,size,h,ref_index,src_index, cmp_func, chroma_cmp_func, 1);
292 }else{
293 3360112 return cmp_inline(s,x,y,subx,suby,size,h,ref_index,src_index, cmp_func, chroma_cmp_func, 1, flags&FLAG_CHROMA);
294 }
295 }
296
297 #include "motion_est_template.c"
298
299 static int zero_cmp(MpegEncContext *s, const uint8_t *a, const uint8_t *b,
300 ptrdiff_t stride, int h)
301 {
302 return 0;
303 }
304
305 static void zero_hpel(uint8_t *a, const uint8_t *b, ptrdiff_t stride, int h){
306 }
307
308 10084 int ff_init_me(MpegEncContext *s){
309 10084 MotionEstContext * const c= &s->me;
310 10084 int cache_size= FFMIN(ME_MAP_SIZE>>ME_MAP_SHIFT, 1<<ME_MAP_SHIFT);
311 10084 int dia_size= FFMAX(FFABS(s->avctx->dia_size)&255, FFABS(s->avctx->pre_dia_size)&255);
312
313
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10084 times.
10084 if(FFMIN(s->avctx->dia_size, s->avctx->pre_dia_size) < -FFMIN(ME_MAP_SIZE, MAX_SAB_SIZE)){
314 av_log(s->avctx, AV_LOG_ERROR, "ME_MAP size is too small for SAB diamond\n");
315 return -1;
316 }
317
318 10084 c->avctx= s->avctx;
319
320
2/2
✓ Branch 0 taken 300 times.
✓ Branch 1 taken 9784 times.
10084 if(s->codec_id == AV_CODEC_ID_H261)
321 300 c->avctx->me_sub_cmp = c->avctx->me_cmp;
322
323
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 10084 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
10084 if(cache_size < 2*dia_size && !c->stride){
324 av_log(s->avctx, AV_LOG_INFO, "ME_MAP size may be a little small for the selected diamond size\n");
325 }
326
327 10084 ff_set_cmp(&s->mecc, s->mecc.me_pre_cmp, c->avctx->me_pre_cmp);
328 10084 ff_set_cmp(&s->mecc, s->mecc.me_cmp, c->avctx->me_cmp);
329 10084 ff_set_cmp(&s->mecc, s->mecc.me_sub_cmp, c->avctx->me_sub_cmp);
330 10084 ff_set_cmp(&s->mecc, s->mecc.mb_cmp, c->avctx->mb_cmp);
331
332 10084 c->flags = get_flags(c, 0, c->avctx->me_cmp &FF_CMP_CHROMA);
333 10084 c->sub_flags= get_flags(c, 0, c->avctx->me_sub_cmp&FF_CMP_CHROMA);
334 10084 c->mb_flags = get_flags(c, 0, c->avctx->mb_cmp &FF_CMP_CHROMA);
335
336 /*FIXME s->no_rounding b_type*/
337
2/2
✓ Branch 0 taken 470 times.
✓ Branch 1 taken 9614 times.
10084 if (s->avctx->flags & AV_CODEC_FLAG_QPEL) {
338 470 c->sub_motion_search= qpel_motion_search;
339 470 c->qpel_avg = s->qdsp.avg_qpel_pixels_tab;
340
2/2
✓ Branch 0 taken 99 times.
✓ Branch 1 taken 371 times.
470 if (s->no_rounding)
341 99 c->qpel_put = s->qdsp.put_no_rnd_qpel_pixels_tab;
342 else
343 371 c->qpel_put = s->qdsp.put_qpel_pixels_tab;
344 }else{
345
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9614 times.
9614 if(c->avctx->me_sub_cmp&FF_CMP_CHROMA)
346 c->sub_motion_search= hpel_motion_search;
347
2/2
✓ Branch 0 taken 8679 times.
✓ Branch 1 taken 935 times.
9614 else if( c->avctx->me_sub_cmp == FF_CMP_SAD
348
1/2
✓ Branch 0 taken 8679 times.
✗ Branch 1 not taken.
8679 && c->avctx-> me_cmp == FF_CMP_SAD
349
1/2
✓ Branch 0 taken 8679 times.
✗ Branch 1 not taken.
8679 && c->avctx-> mb_cmp == FF_CMP_SAD)
350 8679 c->sub_motion_search= sad_hpel_motion_search; // 2050 vs. 2450 cycles
351 else
352 935 c->sub_motion_search= hpel_motion_search;
353 }
354 10084 c->hpel_avg = s->hdsp.avg_pixels_tab;
355
2/2
✓ Branch 0 taken 1673 times.
✓ Branch 1 taken 8411 times.
10084 if (s->no_rounding)
356 1673 c->hpel_put = s->hdsp.put_no_rnd_pixels_tab;
357 else
358 8411 c->hpel_put = s->hdsp.put_pixels_tab;
359
360
1/2
✓ Branch 0 taken 10084 times.
✗ Branch 1 not taken.
10084 if(s->linesize){
361 10084 c->stride = s->linesize;
362 10084 c->uvstride= s->uvlinesize;
363 }else{
364 c->stride = 16*s->mb_width + 32;
365 c->uvstride= 8*s->mb_width + 16;
366 }
367
368 /* 8x8 fullpel search would need a 4x4 chroma compare, which we do
369 * not have yet, and even if we had, the motion estimation code
370 * does not expect it. */
371
1/2
✓ Branch 0 taken 10084 times.
✗ Branch 1 not taken.
10084 if (s->codec_id != AV_CODEC_ID_SNOW) {
372
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10084 times.
10084 if ((c->avctx->me_cmp & FF_CMP_CHROMA) /* && !s->mecc.me_cmp[2] */)
373 s->mecc.me_cmp[2] = zero_cmp;
374
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 10084 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
10084 if ((c->avctx->me_sub_cmp & FF_CMP_CHROMA) && !s->mecc.me_sub_cmp[2])
375 s->mecc.me_sub_cmp[2] = zero_cmp;
376 10084 c->hpel_put[2][0]= c->hpel_put[2][1]=
377 10084 c->hpel_put[2][2]= c->hpel_put[2][3]= zero_hpel;
378 }
379
380
2/2
✓ Branch 0 taken 300 times.
✓ Branch 1 taken 9784 times.
10084 if(s->codec_id == AV_CODEC_ID_H261){
381 300 c->sub_motion_search= no_sub_motion_search;
382 }
383
384 10084 return 0;
385 }
386
387 #define CHECK_SAD_HALF_MV(suffix, x, y) \
388 {\
389 d = s->mecc.pix_abs[size][(x ? 1 : 0) + (y ? 2 : 0)](NULL, pix, ptr + ((x) >> 1), stride, h); \
390 d += (mv_penalty[pen_x + x] + mv_penalty[pen_y + y])*penalty_factor;\
391 COPY3_IF_LT(dminh, d, dx, x, dy, y)\
392 }
393
394 4379010 static int sad_hpel_motion_search(MpegEncContext * s,
395 int *mx_ptr, int *my_ptr, int dmin,
396 int src_index, int ref_index,
397 int size, int h)
398 {
399 4379010 MotionEstContext * const c= &s->me;
400 4379010 const int penalty_factor= c->sub_penalty_factor;
401 int mx, my, dminh;
402 const uint8_t *pix, *ptr;
403 4379010 int stride= c->stride;
404 4379010 LOAD_COMMON
405
406 av_assert2(c->sub_flags == 0);
407
408
2/2
✓ Branch 0 taken 102283 times.
✓ Branch 1 taken 4276727 times.
4379010 if(c->skip){
409 102283 *mx_ptr = 0;
410 102283 *my_ptr = 0;
411 102283 return dmin;
412 }
413
414 4276727 pix = c->src[src_index][0];
415
416 4276727 mx = *mx_ptr;
417 4276727 my = *my_ptr;
418 4276727 ptr = c->ref[ref_index][0] + (my * stride) + mx;
419
420 4276727 dminh = dmin;
421
422
6/6
✓ Branch 0 taken 4205431 times.
✓ Branch 1 taken 71296 times.
✓ Branch 2 taken 4138431 times.
✓ Branch 3 taken 67000 times.
✓ Branch 4 taken 4053262 times.
✓ Branch 5 taken 85169 times.
4276727 if (mx > xmin && mx < xmax &&
423
2/2
✓ Branch 0 taken 3974090 times.
✓ Branch 1 taken 79172 times.
4053262 my > ymin && my < ymax) {
424 3974090 int dx=0, dy=0;
425 int d, pen_x, pen_y;
426 3974090 const int index= my*(1<<ME_MAP_SHIFT) + mx;
427 3974090 const int t= score_map[(index-(1<<ME_MAP_SHIFT))&(ME_MAP_SIZE-1)];
428 3974090 const int l= score_map[(index- 1 )&(ME_MAP_SIZE-1)];
429 3974090 const int r= score_map[(index+ 1 )&(ME_MAP_SIZE-1)];
430 3974090 const int b= score_map[(index+(1<<ME_MAP_SHIFT))&(ME_MAP_SIZE-1)];
431 3974090 mx += mx;
432 3974090 my += my;
433
434
435 3974090 pen_x= pred_x + mx;
436 3974090 pen_y= pred_y + my;
437
438 3974090 ptr-= stride;
439
2/2
✓ Branch 0 taken 2014779 times.
✓ Branch 1 taken 1959311 times.
3974090 if(t<=b){
440 2014779 CHECK_SAD_HALF_MV(y2 , 0, -1)
441
2/2
✓ Branch 0 taken 1255717 times.
✓ Branch 1 taken 759062 times.
2014779 if(l<=r){
442 1255717 CHECK_SAD_HALF_MV(xy2, -1, -1)
443
2/2
✓ Branch 0 taken 731258 times.
✓ Branch 1 taken 524459 times.
1255717 if(t+r<=b+l){
444 731258 CHECK_SAD_HALF_MV(xy2, +1, -1)
445 731258 ptr+= stride;
446 }else{
447 524459 ptr+= stride;
448 524459 CHECK_SAD_HALF_MV(xy2, -1, +1)
449 }
450 1255717 CHECK_SAD_HALF_MV(x2 , -1, 0)
451 }else{
452 759062 CHECK_SAD_HALF_MV(xy2, +1, -1)
453
2/2
✓ Branch 0 taken 416988 times.
✓ Branch 1 taken 342074 times.
759062 if(t+l<=b+r){
454 416988 CHECK_SAD_HALF_MV(xy2, -1, -1)
455 416988 ptr+= stride;
456 }else{
457 342074 ptr+= stride;
458 342074 CHECK_SAD_HALF_MV(xy2, +1, +1)
459 }
460 759062 CHECK_SAD_HALF_MV(x2 , +1, 0)
461 }
462 }else{
463
2/2
✓ Branch 0 taken 743203 times.
✓ Branch 1 taken 1216108 times.
1959311 if(l<=r){
464
2/2
✓ Branch 0 taken 315030 times.
✓ Branch 1 taken 428173 times.
743203 if(t+l<=b+r){
465 315030 CHECK_SAD_HALF_MV(xy2, -1, -1)
466 315030 ptr+= stride;
467 }else{
468 428173 ptr+= stride;
469 428173 CHECK_SAD_HALF_MV(xy2, +1, +1)
470 }
471 743203 CHECK_SAD_HALF_MV(x2 , -1, 0)
472 743203 CHECK_SAD_HALF_MV(xy2, -1, +1)
473 }else{
474
2/2
✓ Branch 0 taken 541371 times.
✓ Branch 1 taken 674737 times.
1216108 if(t+r<=b+l){
475 541371 CHECK_SAD_HALF_MV(xy2, +1, -1)
476 541371 ptr+= stride;
477 }else{
478 674737 ptr+= stride;
479 674737 CHECK_SAD_HALF_MV(xy2, -1, +1)
480 }
481 1216108 CHECK_SAD_HALF_MV(x2 , +1, 0)
482 1216108 CHECK_SAD_HALF_MV(xy2, +1, +1)
483 }
484 1959311 CHECK_SAD_HALF_MV(y2 , 0, +1)
485 }
486 3974090 mx+=dx;
487 3974090 my+=dy;
488
489 }else{
490 302637 mx += mx;
491 302637 my += my;
492 }
493
494 4276727 *mx_ptr = mx;
495 4276727 *my_ptr = my;
496 4276727 return dminh;
497 }
498
499 1928502 static inline void set_p_mv_tables(MpegEncContext * s, int mx, int my, int mv4)
500 {
501 1928502 const int xy= s->mb_x + s->mb_y*s->mb_stride;
502
503 1928502 s->p_mv_table[xy][0] = mx;
504 1928502 s->p_mv_table[xy][1] = my;
505
506 /* has already been set to the 4 MV if 4MV is done */
507
2/2
✓ Branch 0 taken 1676740 times.
✓ Branch 1 taken 251762 times.
1928502 if(mv4){
508 1676740 int mot_xy= s->block_index[0];
509
510 1676740 s->current_picture.motion_val[0][mot_xy ][0] = mx;
511 1676740 s->current_picture.motion_val[0][mot_xy ][1] = my;
512 1676740 s->current_picture.motion_val[0][mot_xy + 1][0] = mx;
513 1676740 s->current_picture.motion_val[0][mot_xy + 1][1] = my;
514
515 1676740 mot_xy += s->b8_stride;
516 1676740 s->current_picture.motion_val[0][mot_xy ][0] = mx;
517 1676740 s->current_picture.motion_val[0][mot_xy ][1] = my;
518 1676740 s->current_picture.motion_val[0][mot_xy + 1][0] = mx;
519 1676740 s->current_picture.motion_val[0][mot_xy + 1][1] = my;
520 }
521 1928502 }
522
523 /**
524 * get fullpel ME search limits.
525 */
526 3344624 static inline void get_limits(MpegEncContext *s, int x, int y)
527 {
528 3344624 MotionEstContext * const c= &s->me;
529
2/2
✓ Branch 0 taken 168764 times.
✓ Branch 1 taken 3175860 times.
3344624 int range= c->avctx->me_range >> (1 + !!(c->flags&FLAG_QPEL));
530
2/2
✓ Branch 0 taken 168764 times.
✓ Branch 1 taken 3175860 times.
3344624 int max_range = MAX_MV >> (1 + !!(c->flags&FLAG_QPEL));
531 /*
532 if(c->avctx->me_range) c->range= c->avctx->me_range >> 1;
533 else c->range= 16;
534 */
535
2/2
✓ Branch 0 taken 1724561 times.
✓ Branch 1 taken 1620063 times.
3344624 if (s->unrestricted_mv) {
536 1724561 c->xmin = - x - 16;
537 1724561 c->ymin = - y - 16;
538 1724561 c->xmax = - x + s->width;
539 1724561 c->ymax = - y + s->height;
540
2/2
✓ Branch 0 taken 106920 times.
✓ Branch 1 taken 1513143 times.
1620063 } else if (s->out_format == FMT_H261){
541 // Search range of H.261 is different from other codec standards
542
2/2
✓ Branch 0 taken 102060 times.
✓ Branch 1 taken 4860 times.
106920 c->xmin = (x > 15) ? - 15 : 0;
543
2/2
✓ Branch 0 taken 100980 times.
✓ Branch 1 taken 5940 times.
106920 c->ymin = (y > 15) ? - 15 : 0;
544
2/2
✓ Branch 0 taken 102060 times.
✓ Branch 1 taken 4860 times.
106920 c->xmax = (x < s->mb_width * 16 - 16) ? 15 : 0;
545
2/2
✓ Branch 0 taken 100980 times.
✓ Branch 1 taken 5940 times.
106920 c->ymax = (y < s->mb_height * 16 - 16) ? 15 : 0;
546 } else {
547 1513143 c->xmin = - x;
548 1513143 c->ymin = - y;
549 1513143 c->xmax = - x + s->mb_width *16 - 16;
550 1513143 c->ymax = - y + s->mb_height*16 - 16;
551 }
552
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 3344624 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
3344624 if(!range || range > max_range)
553 3344624 range = max_range;
554
1/2
✓ Branch 0 taken 3344624 times.
✗ Branch 1 not taken.
3344624 if(range){
555 3344624 c->xmin = FFMAX(c->xmin,-range);
556 3344624 c->xmax = FFMIN(c->xmax, range);
557 3344624 c->ymin = FFMAX(c->ymin,-range);
558 3344624 c->ymax = FFMIN(c->ymax, range);
559 }
560 3344624 }
561
562 251762 static inline void init_mv4_ref(MotionEstContext *c){
563 251762 const int stride= c->stride;
564
565 251762 c->ref[1][0] = c->ref[0][0] + 8;
566 251762 c->ref[2][0] = c->ref[0][0] + 8*stride;
567 251762 c->ref[3][0] = c->ref[2][0] + 8;
568 251762 c->src[1][0] = c->src[0][0] + 8;
569 251762 c->src[2][0] = c->src[0][0] + 8*stride;
570 251762 c->src[3][0] = c->src[2][0] + 8;
571 251762 }
572
573 251762 static inline int h263_mv4_search(MpegEncContext *s, int mx, int my, int shift)
574 {
575 251762 MotionEstContext * const c= &s->me;
576 251762 const int size= 1;
577 251762 const int h=8;
578 int block;
579 int P[10][2];
580 251762 int dmin_sum=0, mx4_sum=0, my4_sum=0, i;
581 251762 int same=1;
582 251762 const int stride= c->stride;
583 251762 const uint8_t *mv_penalty = c->current_mv_penalty;
584
4/6
✓ Branch 0 taken 251762 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2060 times.
✓ Branch 3 taken 249702 times.
✓ Branch 4 taken 2060 times.
✗ Branch 5 not taken.
251762 int safety_clipping= s->unrestricted_mv && (s->width&15) && (s->height&15);
585
586 251762 init_mv4_ref(c);
587
588
2/2
✓ Branch 0 taken 1007048 times.
✓ Branch 1 taken 251762 times.
1258810 for(block=0; block<4; block++){
589 int mx4, my4;
590 int pred_x4, pred_y4;
591 int dmin4;
592 static const int off[4]= {2, 1, 1, -1};
593 1007048 const int mot_stride = s->b8_stride;
594 1007048 const int mot_xy = s->block_index[block];
595
596
2/2
✓ Branch 0 taken 8240 times.
✓ Branch 1 taken 998808 times.
1007048 if(safety_clipping){
597 8240 c->xmax = - 16*s->mb_x + s->width - 8*(block &1);
598 8240 c->ymax = - 16*s->mb_y + s->height - 8*(block>>1);
599 }
600
601 1007048 P_LEFT[0] = s->current_picture.motion_val[0][mot_xy - 1][0];
602 1007048 P_LEFT[1] = s->current_picture.motion_val[0][mot_xy - 1][1];
603
604
2/2
✓ Branch 0 taken 1484 times.
✓ Branch 1 taken 1005564 times.
1007048 if (P_LEFT[0] > c->xmax * (1 << shift)) P_LEFT[0] = c->xmax * (1 << shift);
605
606 /* special case for first line */
607
4/4
✓ Branch 0 taken 62340 times.
✓ Branch 1 taken 944708 times.
✓ Branch 2 taken 31170 times.
✓ Branch 3 taken 31170 times.
1007048 if (s->first_slice_line && block<2) {
608 31170 c->pred_x= pred_x4= P_LEFT[0];
609 31170 c->pred_y= pred_y4= P_LEFT[1];
610 } else {
611 975878 P_TOP[0] = s->current_picture.motion_val[0][mot_xy - mot_stride ][0];
612 975878 P_TOP[1] = s->current_picture.motion_val[0][mot_xy - mot_stride ][1];
613 975878 P_TOPRIGHT[0] = s->current_picture.motion_val[0][mot_xy - mot_stride + off[block]][0];
614 975878 P_TOPRIGHT[1] = s->current_picture.motion_val[0][mot_xy - mot_stride + off[block]][1];
615
2/2
✓ Branch 0 taken 1450 times.
✓ Branch 1 taken 974428 times.
975878 if (P_TOP[1] > c->ymax * (1 << shift)) P_TOP[1] = c->ymax * (1 << shift);
616
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 975848 times.
975878 if (P_TOPRIGHT[0] < c->xmin * (1 << shift)) P_TOPRIGHT[0] = c->xmin * (1 << shift);
617
2/2
✓ Branch 0 taken 956 times.
✓ Branch 1 taken 974922 times.
975878 if (P_TOPRIGHT[0] > c->xmax * (1 << shift)) P_TOPRIGHT[0] = c->xmax * (1 << shift);
618
2/2
✓ Branch 0 taken 1392 times.
✓ Branch 1 taken 974486 times.
975878 if (P_TOPRIGHT[1] > c->ymax * (1 << shift)) P_TOPRIGHT[1] = c->ymax * (1 << shift);
619
620 975878 P_MEDIAN[0]= mid_pred(P_LEFT[0], P_TOP[0], P_TOPRIGHT[0]);
621 975878 P_MEDIAN[1]= mid_pred(P_LEFT[1], P_TOP[1], P_TOPRIGHT[1]);
622
623 975878 c->pred_x= pred_x4 = P_MEDIAN[0];
624 975878 c->pred_y= pred_y4 = P_MEDIAN[1];
625 }
626 1007048 P_MV1[0]= mx;
627 1007048 P_MV1[1]= my;
628
2/2
✓ Branch 0 taken 8240 times.
✓ Branch 1 taken 998808 times.
1007048 if(safety_clipping)
629
2/2
✓ Branch 0 taken 74160 times.
✓ Branch 1 taken 8240 times.
82400 for(i=1; i<10; i++){
630
8/8
✓ Branch 0 taken 26316 times.
✓ Branch 1 taken 47844 times.
✓ Branch 2 taken 13158 times.
✓ Branch 3 taken 13158 times.
✓ Branch 4 taken 11696 times.
✓ Branch 5 taken 1462 times.
✓ Branch 6 taken 10234 times.
✓ Branch 7 taken 1462 times.
74160 if (s->first_slice_line && block<2 && i>1 && i<9)
631 10234 continue;
632
4/4
✓ Branch 0 taken 35352 times.
✓ Branch 1 taken 28574 times.
✓ Branch 2 taken 27112 times.
✓ Branch 3 taken 8240 times.
63926 if (i>4 && i<9)
633 27112 continue;
634
2/2
✓ Branch 0 taken 1175 times.
✓ Branch 1 taken 35639 times.
36814 if (P[i][0] > c->xmax * (1 << shift)) P[i][0] = c->xmax * (1 << shift);
635
2/2
✓ Branch 0 taken 1434 times.
✓ Branch 1 taken 35380 times.
36814 if (P[i][1] > c->ymax * (1 << shift)) P[i][1] = c->ymax * (1 <<shift );
636 }
637
638 1007048 dmin4 = epzs_motion_search2(s, &mx4, &my4, P, block, block, s->p_mv_table, (1<<16)>>shift, 1);
639
640 1007048 dmin4= c->sub_motion_search(s, &mx4, &my4, dmin4, block, block, size, h);
641
642
2/2
✓ Branch 0 taken 167508 times.
✓ Branch 1 taken 839540 times.
1007048 if (s->mecc.me_sub_cmp[0] != s->mecc.mb_cmp[0]) {
643 int dxy;
644 167508 const int offset= ((block&1) + (block>>1)*stride)*8;
645 167508 uint8_t *dest_y = c->scratchpad + offset;
646
2/2
✓ Branch 0 taken 56744 times.
✓ Branch 1 taken 110764 times.
167508 if(s->quarter_sample){
647 56744 const uint8_t *ref = c->ref[block][0] + (mx4>>2) + (my4>>2)*stride;
648 56744 dxy = ((my4 & 3) << 2) | (mx4 & 3);
649
650
2/2
✓ Branch 0 taken 39304 times.
✓ Branch 1 taken 17440 times.
56744 if(s->no_rounding)
651 39304 s->qdsp.put_no_rnd_qpel_pixels_tab[1][dxy](dest_y, ref, stride);
652 else
653 17440 s->qdsp.put_qpel_pixels_tab[1][dxy](dest_y, ref, stride);
654 }else{
655 110764 const uint8_t *ref = c->ref[block][0] + (mx4>>1) + (my4>>1)*stride;
656 110764 dxy = ((my4 & 1) << 1) | (mx4 & 1);
657
658
2/2
✓ Branch 0 taken 77060 times.
✓ Branch 1 taken 33704 times.
110764 if(s->no_rounding)
659 77060 s->hdsp.put_no_rnd_pixels_tab[1][dxy](dest_y , ref , stride, h);
660 else
661 33704 s->hdsp.put_pixels_tab [1][dxy](dest_y , ref , stride, h);
662 }
663 167508 dmin_sum+= (mv_penalty[mx4-pred_x4] + mv_penalty[my4-pred_y4])*c->mb_penalty_factor;
664 }else
665 839540 dmin_sum+= dmin4;
666
667
2/2
✓ Branch 0 taken 56744 times.
✓ Branch 1 taken 950304 times.
1007048 if(s->quarter_sample){
668 56744 mx4_sum+= mx4/2;
669 56744 my4_sum+= my4/2;
670 }else{
671 950304 mx4_sum+= mx4;
672 950304 my4_sum+= my4;
673 }
674
675 1007048 s->current_picture.motion_val[0][s->block_index[block]][0] = mx4;
676 1007048 s->current_picture.motion_val[0][s->block_index[block]][1] = my4;
677
678
4/4
✓ Branch 0 taken 535638 times.
✓ Branch 1 taken 471410 times.
✓ Branch 2 taken 129952 times.
✓ Branch 3 taken 405686 times.
1007048 if(mx4 != mx || my4 != my) same=0;
679 }
680
681
2/2
✓ Branch 0 taken 41703 times.
✓ Branch 1 taken 210059 times.
251762 if(same)
682 41703 return INT_MAX;
683
684
2/2
✓ Branch 0 taken 41458 times.
✓ Branch 1 taken 168601 times.
210059 if (s->mecc.me_sub_cmp[0] != s->mecc.mb_cmp[0]) {
685 41458 dmin_sum += s->mecc.mb_cmp[0](s,
686 41458 s->new_picture->data[0] +
687 41458 s->mb_x * 16 + s->mb_y * 16 * stride,
688 41458 c->scratchpad, stride, 16);
689 }
690
691
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 210059 times.
210059 if(c->avctx->mb_cmp&FF_CMP_CHROMA){
692 int dxy;
693 int mx, my;
694 int offset;
695
696 mx= ff_h263_round_chroma(mx4_sum);
697 my= ff_h263_round_chroma(my4_sum);
698 dxy = ((my & 1) << 1) | (mx & 1);
699
700 offset= (s->mb_x*8 + (mx>>1)) + (s->mb_y*8 + (my>>1))*s->uvlinesize;
701
702 if(s->no_rounding){
703 s->hdsp.put_no_rnd_pixels_tab[1][dxy](c->scratchpad , s->last_picture.f->data[1] + offset, s->uvlinesize, 8);
704 s->hdsp.put_no_rnd_pixels_tab[1][dxy](c->scratchpad + 8, s->last_picture.f->data[2] + offset, s->uvlinesize, 8);
705 }else{
706 s->hdsp.put_pixels_tab [1][dxy](c->scratchpad , s->last_picture.f->data[1] + offset, s->uvlinesize, 8);
707 s->hdsp.put_pixels_tab [1][dxy](c->scratchpad + 8, s->last_picture.f->data[2] + offset, s->uvlinesize, 8);
708 }
709
710 dmin_sum += s->mecc.mb_cmp[1](s, s->new_picture->data[1] + s->mb_x * 8 + s->mb_y * 8 * s->uvlinesize, c->scratchpad, s->uvlinesize, 8);
711 dmin_sum += s->mecc.mb_cmp[1](s, s->new_picture->data[2] + s->mb_x * 8 + s->mb_y * 8 * s->uvlinesize, c->scratchpad + 8, s->uvlinesize, 8);
712 }
713
714 210059 c->pred_x= mx;
715 210059 c->pred_y= my;
716
717
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 210059 times.
210059 switch(c->avctx->mb_cmp&0xFF){
718 /*case FF_CMP_SSE:
719 return dmin_sum+ 32*s->qscale*s->qscale;*/
720 case FF_CMP_RD:
721 return dmin_sum;
722 210059 default:
723 210059 return dmin_sum+ 11*c->mb_penalty_factor;
724 }
725 }
726
727 331233 static inline void init_interlaced_ref(MpegEncContext *s, int ref_index){
728 331233 MotionEstContext * const c= &s->me;
729
730 331233 c->ref[1+ref_index][0] = c->ref[0+ref_index][0] + s->linesize;
731 331233 c->src[1][0] = c->src[0][0] + s->linesize;
732
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 331233 times.
331233 if(c->flags & FLAG_CHROMA){
733 c->ref[1+ref_index][1] = c->ref[0+ref_index][1] + s->uvlinesize;
734 c->ref[1+ref_index][2] = c->ref[0+ref_index][2] + s->uvlinesize;
735 c->src[1][1] = c->src[0][1] + s->uvlinesize;
736 c->src[1][2] = c->src[0][2] + s->uvlinesize;
737 }
738 331233 }
739
740 331233 static int interlaced_search(MpegEncContext *s, int ref_index,
741 int16_t (*mv_tables[2][2])[2], uint8_t *field_select_tables[2], int mx, int my, int user_field_select)
742 {
743 331233 MotionEstContext * const c= &s->me;
744 331233 const int size=0;
745 331233 const int h=8;
746 int block;
747 int P[10][2];
748 331233 const uint8_t * const mv_penalty = c->current_mv_penalty;
749 331233 int same=1;
750 331233 const int stride= 2*s->linesize;
751 331233 int dmin_sum= 0;
752 331233 const int mot_stride= s->mb_stride;
753 331233 const int xy= s->mb_x + s->mb_y*mot_stride;
754
755 331233 c->ymin>>=1;
756 331233 c->ymax>>=1;
757 331233 c->stride<<=1;
758 331233 c->uvstride<<=1;
759 331233 init_interlaced_ref(s, ref_index);
760
761
2/2
✓ Branch 0 taken 662466 times.
✓ Branch 1 taken 331233 times.
993699 for(block=0; block<2; block++){
762 int field_select;
763 662466 int best_dmin= INT_MAX;
764 662466 int best_field= -1;
765
766
2/2
✓ Branch 0 taken 1324932 times.
✓ Branch 1 taken 662466 times.
1987398 for(field_select=0; field_select<2; field_select++){
767 int dmin, mx_i, my_i;
768 1324932 int16_t (*mv_table)[2]= mv_tables[block][field_select];
769
770
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1324932 times.
1324932 if(user_field_select){
771 av_assert1(field_select==0 || field_select==1);
772 av_assert1(field_select_tables[block][xy]==0 || field_select_tables[block][xy]==1);
773 if(field_select_tables[block][xy] != field_select)
774 continue;
775 }
776
777 1324932 P_LEFT[0] = mv_table[xy - 1][0];
778 1324932 P_LEFT[1] = mv_table[xy - 1][1];
779
2/2
✓ Branch 0 taken 32472 times.
✓ Branch 1 taken 1292460 times.
1324932 if(P_LEFT[0] > (c->xmax<<1)) P_LEFT[0] = (c->xmax<<1);
780
781 1324932 c->pred_x= P_LEFT[0];
782 1324932 c->pred_y= P_LEFT[1];
783
784
2/2
✓ Branch 0 taken 1206192 times.
✓ Branch 1 taken 118740 times.
1324932 if(!s->first_slice_line){
785 1206192 P_TOP[0] = mv_table[xy - mot_stride][0];
786 1206192 P_TOP[1] = mv_table[xy - mot_stride][1];
787 1206192 P_TOPRIGHT[0] = mv_table[xy - mot_stride + 1][0];
788 1206192 P_TOPRIGHT[1] = mv_table[xy - mot_stride + 1][1];
789
2/2
✓ Branch 0 taken 32877 times.
✓ Branch 1 taken 1173315 times.
1206192 if(P_TOP[1] > (c->ymax<<1)) P_TOP[1] = (c->ymax<<1);
790
2/2
✓ Branch 0 taken 26013 times.
✓ Branch 1 taken 1180179 times.
1206192 if (P_TOPRIGHT[0] < c->xmin * (1 << 1)) P_TOPRIGHT[0] = c->xmin * (1 << 1);
791
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1206192 times.
1206192 if(P_TOPRIGHT[0] > (c->xmax<<1)) P_TOPRIGHT[0]= (c->xmax<<1);
792
2/2
✓ Branch 0 taken 30765 times.
✓ Branch 1 taken 1175427 times.
1206192 if(P_TOPRIGHT[1] > (c->ymax<<1)) P_TOPRIGHT[1]= (c->ymax<<1);
793
794 1206192 P_MEDIAN[0]= mid_pred(P_LEFT[0], P_TOP[0], P_TOPRIGHT[0]);
795 1206192 P_MEDIAN[1]= mid_pred(P_LEFT[1], P_TOP[1], P_TOPRIGHT[1]);
796 }
797 1324932 P_MV1[0]= mx; //FIXME not correct if block != field_select
798 1324932 P_MV1[1]= my / 2;
799
800 1324932 dmin = epzs_motion_search2(s, &mx_i, &my_i, P, block, field_select+ref_index, mv_table, (1<<16)>>1, 0);
801
802 1324932 dmin= c->sub_motion_search(s, &mx_i, &my_i, dmin, block, field_select+ref_index, size, h);
803
804 1324932 mv_table[xy][0]= mx_i;
805 1324932 mv_table[xy][1]= my_i;
806
807
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1324932 times.
1324932 if (s->mecc.me_sub_cmp[0] != s->mecc.mb_cmp[0]) {
808 int dxy;
809
810 //FIXME chroma ME
811 const uint8_t *ref = c->ref[field_select+ref_index][0] + (mx_i>>1) + (my_i>>1)*stride;
812 dxy = ((my_i & 1) << 1) | (mx_i & 1);
813
814 if(s->no_rounding){
815 s->hdsp.put_no_rnd_pixels_tab[size][dxy](c->scratchpad, ref , stride, h);
816 }else{
817 s->hdsp.put_pixels_tab [size][dxy](c->scratchpad, ref , stride, h);
818 }
819 dmin = s->mecc.mb_cmp[size](s, c->src[block][0], c->scratchpad, stride, h);
820 dmin+= (mv_penalty[mx_i-c->pred_x] + mv_penalty[my_i-c->pred_y] + 1)*c->mb_penalty_factor;
821 }else
822 1324932 dmin+= c->mb_penalty_factor; //field_select bits
823
824 1324932 dmin += field_select != block; //slightly prefer same field
825
826
2/2
✓ Branch 0 taken 994745 times.
✓ Branch 1 taken 330187 times.
1324932 if(dmin < best_dmin){
827 994745 best_dmin= dmin;
828 994745 best_field= field_select;
829 }
830 }
831 {
832 662466 int16_t (*mv_table)[2]= mv_tables[block][best_field];
833
834
2/2
✓ Branch 0 taken 257294 times.
✓ Branch 1 taken 405172 times.
662466 if(mv_table[xy][0] != mx) same=0; //FIXME check if these checks work and are any good at all
835
2/2
✓ Branch 0 taken 59142 times.
✓ Branch 1 taken 603324 times.
662466 if(mv_table[xy][1]&1) same=0;
836
2/2
✓ Branch 0 taken 444919 times.
✓ Branch 1 taken 217547 times.
662466 if(mv_table[xy][1]*2 != my) same=0;
837
2/2
✓ Branch 0 taken 318666 times.
✓ Branch 1 taken 343800 times.
662466 if(best_field != block) same=0;
838 }
839
840 662466 field_select_tables[block][xy]= best_field;
841 662466 dmin_sum += best_dmin;
842 }
843
844 331233 c->ymin *= 2;
845 331233 c->ymax<<=1;
846 331233 c->stride>>=1;
847 331233 c->uvstride>>=1;
848
849
2/2
✓ Branch 0 taken 55300 times.
✓ Branch 1 taken 275933 times.
331233 if(same)
850 55300 return INT_MAX;
851
852
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 275933 times.
275933 switch(c->avctx->mb_cmp&0xFF){
853 /*case FF_CMP_SSE:
854 return dmin_sum+ 32*s->qscale*s->qscale;*/
855 case FF_CMP_RD:
856 return dmin_sum;
857 275933 default:
858 275933 return dmin_sum+ 11*c->mb_penalty_factor;
859 }
860 }
861
862 8234682 static inline int get_penalty_factor(int lambda, int lambda2, int type){
863
3/7
✓ Branch 0 taken 7335839 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 552909 times.
✓ Branch 5 taken 345934 times.
✗ Branch 6 not taken.
8234682 switch(type&0xFF){
864 7335839 default:
865 case FF_CMP_SAD:
866 7335839 return lambda>>FF_LAMBDA_SHIFT;
867 case FF_CMP_DCT:
868 return (3*lambda)>>(FF_LAMBDA_SHIFT+1);
869 case FF_CMP_W53:
870 return (4*lambda)>>(FF_LAMBDA_SHIFT);
871 case FF_CMP_W97:
872 return (2*lambda)>>(FF_LAMBDA_SHIFT);
873 552909 case FF_CMP_SATD:
874 case FF_CMP_DCT264:
875 552909 return (2*lambda)>>FF_LAMBDA_SHIFT;
876 345934 case FF_CMP_RD:
877 case FF_CMP_PSNR:
878 case FF_CMP_SSE:
879 case FF_CMP_NSSE:
880 345934 return lambda2>>FF_LAMBDA_SHIFT;
881 case FF_CMP_BIT:
882 case FF_CMP_MEDIAN_SAD:
883 return 1;
884 }
885 }
886
887 1928502 void ff_estimate_p_frame_motion(MpegEncContext * s,
888 int mb_x, int mb_y)
889 {
890 1928502 MotionEstContext * const c= &s->me;
891 const uint8_t *pix, *ppix;
892 1928502 int sum, mx = 0, my = 0, dmin = 0;
893 int varc; ///< the variance of the block (sum of squared (p[y][x]-average))
894 int vard; ///< sum of squared differences with the estimated motion vector
895 int P[10][2];
896 1928502 const int shift= 1+s->quarter_sample;
897 1928502 int mb_type=0;
898
899 1928502 init_ref(c, s->new_picture->data, s->last_picture.f->data, NULL, 16*mb_x, 16*mb_y, 0);
900
901
3/4
✓ Branch 0 taken 15570 times.
✓ Branch 1 taken 1912932 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 15570 times.
1928502 av_assert0(s->quarter_sample==0 || s->quarter_sample==1);
902
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1928502 times.
1928502 av_assert0(s->linesize == c->stride);
903
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1928502 times.
1928502 av_assert0(s->uvlinesize == c->uvstride);
904
905 1928502 c->penalty_factor = get_penalty_factor(s->lambda, s->lambda2, c->avctx->me_cmp);
906 1928502 c->sub_penalty_factor= get_penalty_factor(s->lambda, s->lambda2, c->avctx->me_sub_cmp);
907 1928502 c->mb_penalty_factor = get_penalty_factor(s->lambda, s->lambda2, c->avctx->mb_cmp);
908 1928502 c->current_mv_penalty= c->mv_penalty[s->f_code] + MAX_DMV;
909
910 1928502 get_limits(s, 16*mb_x, 16*mb_y);
911 1928502 c->skip=0;
912
913 /* intra / predictive decision */
914 1928502 pix = c->src[0][0];
915 1928502 sum = s->mpvencdsp.pix_sum(pix, s->linesize);
916 1928502 varc = s->mpvencdsp.pix_norm1(pix, s->linesize) -
917 1928502 (((unsigned) sum * sum) >> 8) + 500;
918
919 1928502 s->mb_mean[s->mb_stride * mb_y + mb_x] = (sum+128)>>8;
920 1928502 s->mb_var [s->mb_stride * mb_y + mb_x] = (varc+128)>>8;
921 1928502 c->mb_var_sum_temp += (varc+128)>>8;
922
923
1/2
✓ Branch 0 taken 1928502 times.
✗ Branch 1 not taken.
1928502 if (s->motion_est != FF_ME_ZERO) {
924 1928502 const int mot_stride = s->b8_stride;
925 1928502 const int mot_xy = s->block_index[0];
926
927 1928502 P_LEFT[0] = s->current_picture.motion_val[0][mot_xy - 1][0];
928 1928502 P_LEFT[1] = s->current_picture.motion_val[0][mot_xy - 1][1];
929
930
2/2
✓ Branch 0 taken 19623 times.
✓ Branch 1 taken 1908879 times.
1928502 if (P_LEFT[0] > (c->xmax << shift))
931 19623 P_LEFT[0] = c->xmax << shift;
932
933
2/2
✓ Branch 0 taken 1821011 times.
✓ Branch 1 taken 107491 times.
1928502 if (!s->first_slice_line) {
934 1821011 P_TOP[0] = s->current_picture.motion_val[0][mot_xy - mot_stride ][0];
935 1821011 P_TOP[1] = s->current_picture.motion_val[0][mot_xy - mot_stride ][1];
936 1821011 P_TOPRIGHT[0] = s->current_picture.motion_val[0][mot_xy - mot_stride + 2][0];
937 1821011 P_TOPRIGHT[1] = s->current_picture.motion_val[0][mot_xy - mot_stride + 2][1];
938
2/2
✓ Branch 0 taken 21865 times.
✓ Branch 1 taken 1799146 times.
1821011 if (P_TOP[1] > (c->ymax << shift))
939 21865 P_TOP[1] = c->ymax << shift;
940
2/2
✓ Branch 0 taken 21669 times.
✓ Branch 1 taken 1799342 times.
1821011 if (P_TOPRIGHT[0] < (c->xmin * (1 << shift)))
941 21669 P_TOPRIGHT[0] = c->xmin * (1 << shift);
942
2/2
✓ Branch 0 taken 20081 times.
✓ Branch 1 taken 1800930 times.
1821011 if (P_TOPRIGHT[1] > (c->ymax * (1 << shift)))
943 20081 P_TOPRIGHT[1] = c->ymax * (1 << shift);
944
945 1821011 P_MEDIAN[0] = mid_pred(P_LEFT[0], P_TOP[0], P_TOPRIGHT[0]);
946 1821011 P_MEDIAN[1] = mid_pred(P_LEFT[1], P_TOP[1], P_TOPRIGHT[1]);
947
948
2/2
✓ Branch 0 taken 1112641 times.
✓ Branch 1 taken 708370 times.
1821011 if (s->out_format == FMT_H263) {
949 1112641 c->pred_x = P_MEDIAN[0];
950 1112641 c->pred_y = P_MEDIAN[1];
951 } else { /* MPEG-1 at least */
952 708370 c->pred_x = P_LEFT[0];
953 708370 c->pred_y = P_LEFT[1];
954 }
955 } else {
956 107491 c->pred_x = P_LEFT[0];
957 107491 c->pred_y = P_LEFT[1];
958 }
959 1928502 dmin = ff_epzs_motion_search(s, &mx, &my, P, 0, 0, s->p_mv_table, (1<<16)>>shift, 0, 16);
960 }
961
962 /* At this point (mx,my) are full-pell and the relative displacement */
963 1928502 ppix = c->ref[0][0] + (my * s->linesize) + mx;
964
965 1928502 vard = s->mecc.sse[0](NULL, pix, ppix, s->linesize, 16);
966
967 1928502 s->mc_mb_var[s->mb_stride * mb_y + mb_x] = (vard+128)>>8;
968 1928502 c->mc_mb_var_sum_temp += (vard+128)>>8;
969
970
2/2
✓ Branch 0 taken 362361 times.
✓ Branch 1 taken 1566141 times.
1928502 if (c->avctx->mb_decision > FF_MB_DECISION_SIMPLE) {
971 362361 int p_score= FFMIN(vard, varc-500+(s->lambda2>>FF_LAMBDA_SHIFT)*100);
972 362361 int i_score= varc-500+(s->lambda2>>FF_LAMBDA_SHIFT)*20;
973 362361 c->scene_change_score+= ff_sqrt(p_score) - ff_sqrt(i_score);
974
975
3/4
✓ Branch 0 taken 97659 times.
✓ Branch 1 taken 264702 times.
✓ Branch 2 taken 97659 times.
✗ Branch 3 not taken.
362361 if (vard*2 + 200*256 > varc && !s->intra_penalty)
976 97659 mb_type|= CANDIDATE_MB_TYPE_INTRA;
977
3/4
✓ Branch 0 taken 2107 times.
✓ Branch 1 taken 360254 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2107 times.
362361 if (varc*2 + 200*256 > vard || s->qscale > 24){
978 // if (varc*2 + 200*256 + 50*(s->lambda2>>FF_LAMBDA_SHIFT) > vard){
979 360254 mb_type|= CANDIDATE_MB_TYPE_INTER;
980 360254 c->sub_motion_search(s, &mx, &my, dmin, 0, 0, 0, 16);
981
2/2
✓ Branch 0 taken 61156 times.
✓ Branch 1 taken 299098 times.
360254 if (s->mpv_flags & FF_MPV_FLAG_MV0)
982
4/4
✓ Branch 0 taken 4055 times.
✓ Branch 1 taken 57101 times.
✓ Branch 2 taken 3527 times.
✓ Branch 3 taken 528 times.
61156 if(mx || my)
983 60628 mb_type |= CANDIDATE_MB_TYPE_SKIPPED; //FIXME check difference
984 }else{
985 2107 mx *= 1 << shift;
986 2107 my *= 1 << shift;
987 }
988
2/2
✓ Branch 0 taken 277722 times.
✓ Branch 1 taken 84639 times.
362361 if ((s->avctx->flags & AV_CODEC_FLAG_4MV)
989
6/6
✓ Branch 0 taken 277715 times.
✓ Branch 1 taken 7 times.
✓ Branch 2 taken 260928 times.
✓ Branch 3 taken 16787 times.
✓ Branch 4 taken 251762 times.
✓ Branch 5 taken 9166 times.
277722 && !c->skip && varc>50<<8 && vard>10<<8){
990
2/2
✓ Branch 1 taken 210059 times.
✓ Branch 2 taken 41703 times.
251762 if(h263_mv4_search(s, mx, my, shift) < INT_MAX)
991 210059 mb_type|=CANDIDATE_MB_TYPE_INTER4V;
992
993 251762 set_p_mv_tables(s, mx, my, 0);
994 }else
995 110599 set_p_mv_tables(s, mx, my, 1);
996
2/2
✓ Branch 0 taken 15600 times.
✓ Branch 1 taken 346761 times.
362361 if ((s->avctx->flags & AV_CODEC_FLAG_INTERLACED_ME)
997
1/2
✓ Branch 0 taken 15600 times.
✗ Branch 1 not taken.
15600 && !c->skip){ //FIXME varc/d checks
998
2/2
✓ Branch 1 taken 13535 times.
✓ Branch 2 taken 2065 times.
15600 if(interlaced_search(s, 0, s->p_field_mv_table, s->p_field_select_table, mx, my, 0) < INT_MAX)
999 13535 mb_type |= CANDIDATE_MB_TYPE_INTER_I;
1000 }
1001 }else{
1002 int intra_score, i;
1003 1566141 mb_type= CANDIDATE_MB_TYPE_INTER;
1004
1005 1566141 dmin= c->sub_motion_search(s, &mx, &my, dmin, 0, 0, 0, 16);
1006
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 1566141 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
1566141 if(c->avctx->me_sub_cmp != c->avctx->mb_cmp && !c->skip)
1007 dmin= get_mb_score(s, mx, my, 0, 0, 0, 16, 1);
1008
1009
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1566141 times.
1566141 if ((s->avctx->flags & AV_CODEC_FLAG_4MV)
1010 && !c->skip && varc>50<<8 && vard>10<<8){
1011 int dmin4= h263_mv4_search(s, mx, my, shift);
1012 if(dmin4 < dmin){
1013 mb_type= CANDIDATE_MB_TYPE_INTER4V;
1014 dmin=dmin4;
1015 }
1016 }
1017
2/2
✓ Branch 0 taken 85236 times.
✓ Branch 1 taken 1480905 times.
1566141 if ((s->avctx->flags & AV_CODEC_FLAG_INTERLACED_ME)
1018
2/2
✓ Branch 0 taken 85233 times.
✓ Branch 1 taken 3 times.
85236 && !c->skip){ //FIXME varc/d checks
1019 85233 int dmin_i= interlaced_search(s, 0, s->p_field_mv_table, s->p_field_select_table, mx, my, 0);
1020
2/2
✓ Branch 0 taken 11208 times.
✓ Branch 1 taken 74025 times.
85233 if(dmin_i < dmin){
1021 11208 mb_type = CANDIDATE_MB_TYPE_INTER_I;
1022 11208 dmin= dmin_i;
1023 }
1024 }
1025
1026 1566141 set_p_mv_tables(s, mx, my, mb_type!=CANDIDATE_MB_TYPE_INTER4V);
1027
1028 /* get intra luma score */
1029
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1566141 times.
1566141 if((c->avctx->mb_cmp&0xFF)==FF_CMP_SSE){
1030 intra_score= varc - 500;
1031 }else{
1032 1566141 unsigned mean = (sum+128)>>8;
1033 1566141 mean*= 0x01010101;
1034
1035
2/2
✓ Branch 0 taken 25058256 times.
✓ Branch 1 taken 1566141 times.
26624397 for(i=0; i<16; i++){
1036 25058256 *(uint32_t*)(&c->scratchpad[i*s->linesize+ 0]) = mean;
1037 25058256 *(uint32_t*)(&c->scratchpad[i*s->linesize+ 4]) = mean;
1038 25058256 *(uint32_t*)(&c->scratchpad[i*s->linesize+ 8]) = mean;
1039 25058256 *(uint32_t*)(&c->scratchpad[i*s->linesize+12]) = mean;
1040 }
1041
1042 1566141 intra_score= s->mecc.mb_cmp[0](s, c->scratchpad, pix, s->linesize, 16);
1043 }
1044 1566141 intra_score += c->mb_penalty_factor*16 + s->intra_penalty;
1045
1046
2/2
✓ Branch 0 taken 75644 times.
✓ Branch 1 taken 1490497 times.
1566141 if(intra_score < dmin){
1047 75644 mb_type= CANDIDATE_MB_TYPE_INTRA;
1048 75644 s->current_picture.mb_type[mb_y*s->mb_stride + mb_x] = CANDIDATE_MB_TYPE_INTRA; //FIXME cleanup
1049 }else
1050 1490497 s->current_picture.mb_type[mb_y*s->mb_stride + mb_x] = 0;
1051
1052 {
1053 1566141 int p_score= FFMIN(vard, varc-500+(s->lambda2>>FF_LAMBDA_SHIFT)*100);
1054 1566141 int i_score= varc-500+(s->lambda2>>FF_LAMBDA_SHIFT)*20;
1055 1566141 c->scene_change_score+= ff_sqrt(p_score) - ff_sqrt(i_score);
1056 }
1057 }
1058
1059 1928502 s->mb_type[mb_y*s->mb_stride + mb_x]= mb_type;
1060 1928502 }
1061
1062 int ff_pre_estimate_p_frame_motion(MpegEncContext * s,
1063 int mb_x, int mb_y)
1064 {
1065 MotionEstContext * const c= &s->me;
1066 int mx, my, dmin;
1067 int P[10][2];
1068 const int shift= 1+s->quarter_sample;
1069 const int xy= mb_x + mb_y*s->mb_stride;
1070 init_ref(c, s->new_picture->data, s->last_picture.f->data, NULL, 16*mb_x, 16*mb_y, 0);
1071
1072 av_assert0(s->quarter_sample==0 || s->quarter_sample==1);
1073
1074 c->pre_penalty_factor = get_penalty_factor(s->lambda, s->lambda2, c->avctx->me_pre_cmp);
1075 c->current_mv_penalty= c->mv_penalty[s->f_code] + MAX_DMV;
1076
1077 get_limits(s, 16*mb_x, 16*mb_y);
1078 c->skip=0;
1079
1080 P_LEFT[0] = s->p_mv_table[xy + 1][0];
1081 P_LEFT[1] = s->p_mv_table[xy + 1][1];
1082
1083 if(P_LEFT[0] < (c->xmin<<shift)) P_LEFT[0] = (c->xmin<<shift);
1084
1085 /* special case for first line */
1086 if (s->first_slice_line) {
1087 c->pred_x= P_LEFT[0];
1088 c->pred_y= P_LEFT[1];
1089 P_TOP[0]= P_TOPRIGHT[0]= P_MEDIAN[0]=
1090 P_TOP[1]= P_TOPRIGHT[1]= P_MEDIAN[1]= 0; //FIXME
1091 } else {
1092 P_TOP[0] = s->p_mv_table[xy + s->mb_stride ][0];
1093 P_TOP[1] = s->p_mv_table[xy + s->mb_stride ][1];
1094 P_TOPRIGHT[0] = s->p_mv_table[xy + s->mb_stride - 1][0];
1095 P_TOPRIGHT[1] = s->p_mv_table[xy + s->mb_stride - 1][1];
1096 if(P_TOP[1] < (c->ymin<<shift)) P_TOP[1] = (c->ymin<<shift);
1097 if(P_TOPRIGHT[0] > (c->xmax<<shift)) P_TOPRIGHT[0]= (c->xmax<<shift);
1098 if(P_TOPRIGHT[1] < (c->ymin<<shift)) P_TOPRIGHT[1]= (c->ymin<<shift);
1099
1100 P_MEDIAN[0]= mid_pred(P_LEFT[0], P_TOP[0], P_TOPRIGHT[0]);
1101 P_MEDIAN[1]= mid_pred(P_LEFT[1], P_TOP[1], P_TOPRIGHT[1]);
1102
1103 c->pred_x = P_MEDIAN[0];
1104 c->pred_y = P_MEDIAN[1];
1105 }
1106
1107 dmin = ff_epzs_motion_search(s, &mx, &my, P, 0, 0, s->p_mv_table, (1<<16)>>shift, 0, 16);
1108
1109 s->p_mv_table[xy][0] = mx<<shift;
1110 s->p_mv_table[xy][1] = my<<shift;
1111
1112 return dmin;
1113 }
1114
1115 816392 static int estimate_motion_b(MpegEncContext *s, int mb_x, int mb_y,
1116 int16_t (*mv_table)[2], int ref_index, int f_code)
1117 {
1118 816392 MotionEstContext * const c= &s->me;
1119 816392 int mx = 0, my = 0, dmin = 0;
1120 int P[10][2];
1121 816392 const int shift= 1+s->quarter_sample;
1122 816392 const int mot_stride = s->mb_stride;
1123 816392 const int mot_xy = mb_y*mot_stride + mb_x;
1124 816392 const uint8_t * const mv_penalty = c->mv_penalty[f_code] + MAX_DMV;
1125 int mv_scale;
1126
1127 816392 c->penalty_factor = get_penalty_factor(s->lambda, s->lambda2, c->avctx->me_cmp);
1128 816392 c->sub_penalty_factor= get_penalty_factor(s->lambda, s->lambda2, c->avctx->me_sub_cmp);
1129 816392 c->mb_penalty_factor = get_penalty_factor(s->lambda, s->lambda2, c->avctx->mb_cmp);
1130 816392 c->current_mv_penalty= mv_penalty;
1131
1132 816392 get_limits(s, 16*mb_x, 16*mb_y);
1133
1134
1/2
✓ Branch 0 taken 816392 times.
✗ Branch 1 not taken.
816392 if (s->motion_est != FF_ME_ZERO) {
1135 816392 P_LEFT[0] = mv_table[mot_xy - 1][0];
1136 816392 P_LEFT[1] = mv_table[mot_xy - 1][1];
1137
1138
2/2
✓ Branch 0 taken 10174 times.
✓ Branch 1 taken 806218 times.
816392 if (P_LEFT[0] > (c->xmax << shift)) P_LEFT[0] = (c->xmax << shift);
1139
1140 /* special case for first line */
1141
2/2
✓ Branch 0 taken 756200 times.
✓ Branch 1 taken 60192 times.
816392 if (!s->first_slice_line) {
1142 756200 P_TOP[0] = mv_table[mot_xy - mot_stride ][0];
1143 756200 P_TOP[1] = mv_table[mot_xy - mot_stride ][1];
1144 756200 P_TOPRIGHT[0] = mv_table[mot_xy - mot_stride + 1][0];
1145 756200 P_TOPRIGHT[1] = mv_table[mot_xy - mot_stride + 1][1];
1146
2/2
✓ Branch 0 taken 11736 times.
✓ Branch 1 taken 744464 times.
756200 if (P_TOP[1] > (c->ymax << shift)) P_TOP[1] = (c->ymax << shift);
1147
2/2
✓ Branch 0 taken 8203 times.
✓ Branch 1 taken 747997 times.
756200 if (P_TOPRIGHT[0] < c->xmin * (1 << shift)) P_TOPRIGHT[0] = c->xmin * (1 << shift);
1148
2/2
✓ Branch 0 taken 11073 times.
✓ Branch 1 taken 745127 times.
756200 if (P_TOPRIGHT[1] > (c->ymax << shift)) P_TOPRIGHT[1] = (c->ymax << shift);
1149
1150 756200 P_MEDIAN[0] = mid_pred(P_LEFT[0], P_TOP[0], P_TOPRIGHT[0]);
1151 756200 P_MEDIAN[1] = mid_pred(P_LEFT[1], P_TOP[1], P_TOPRIGHT[1]);
1152 }
1153 816392 c->pred_x = P_LEFT[0];
1154 816392 c->pred_y = P_LEFT[1];
1155
1156
2/2
✓ Branch 0 taken 408196 times.
✓ Branch 1 taken 408196 times.
816392 if(mv_table == s->b_forw_mv_table){
1157 408196 mv_scale= (s->pb_time<<16) / (s->pp_time<<shift);
1158 }else{
1159 408196 mv_scale = ((s->pb_time - s->pp_time) * (1 << 16)) / (s->pp_time<<shift);
1160 }
1161
1162 816392 dmin = ff_epzs_motion_search(s, &mx, &my, P, 0, ref_index, s->p_mv_table, mv_scale, 0, 16);
1163 }
1164
1165 816392 dmin= c->sub_motion_search(s, &mx, &my, dmin, 0, ref_index, 0, 16);
1166
1167
3/4
✓ Branch 0 taken 306344 times.
✓ Branch 1 taken 510048 times.
✓ Branch 2 taken 306344 times.
✗ Branch 3 not taken.
816392 if(c->avctx->me_sub_cmp != c->avctx->mb_cmp && !c->skip)
1168 306344 dmin= get_mb_score(s, mx, my, 0, ref_index, 0, 16, 1);
1169
1170 // s->mb_type[mb_y*s->mb_width + mb_x]= mb_type;
1171 816392 mv_table[mot_xy][0]= mx;
1172 816392 mv_table[mot_xy][1]= my;
1173
1174 816392 return dmin;
1175 }
1176
1177 5436185 static inline int check_bidir_mv(MpegEncContext * s,
1178 int motion_fx, int motion_fy,
1179 int motion_bx, int motion_by,
1180 int pred_fx, int pred_fy,
1181 int pred_bx, int pred_by,
1182 int size, int h)
1183 {
1184 //FIXME optimize?
1185 //FIXME better f_code prediction (max mv & distance)
1186 //FIXME pointers
1187 5436185 MotionEstContext * const c= &s->me;
1188 5436185 const uint8_t * const mv_penalty_f = c->mv_penalty[s->f_code] + MAX_DMV; // f_code of the prev frame
1189 5436185 const uint8_t * const mv_penalty_b = c->mv_penalty[s->b_code] + MAX_DMV; // f_code of the prev frame
1190 5436185 int stride= c->stride;
1191 5436185 uint8_t *dest_y = c->scratchpad;
1192 const uint8_t *ptr;
1193 int dxy;
1194 int src_x, src_y;
1195 int fbmin;
1196 5436185 const uint8_t *const *src_data = c->src[0];
1197 5436185 const uint8_t *const *ref_data = c->ref[0];
1198 5436185 const uint8_t *const *ref2_data = c->ref[2];
1199
1200
2/2
✓ Branch 0 taken 625749 times.
✓ Branch 1 taken 4810436 times.
5436185 if(s->quarter_sample){
1201 625749 dxy = ((motion_fy & 3) << 2) | (motion_fx & 3);
1202 625749 src_x = motion_fx >> 2;
1203 625749 src_y = motion_fy >> 2;
1204
1205 625749 ptr = ref_data[0] + (src_y * stride) + src_x;
1206 625749 s->qdsp.put_qpel_pixels_tab[0][dxy](dest_y, ptr, stride);
1207
1208 625749 dxy = ((motion_by & 3) << 2) | (motion_bx & 3);
1209 625749 src_x = motion_bx >> 2;
1210 625749 src_y = motion_by >> 2;
1211
1212 625749 ptr = ref2_data[0] + (src_y * stride) + src_x;
1213 625749 s->qdsp.avg_qpel_pixels_tab[size][dxy](dest_y, ptr, stride);
1214 }else{
1215 4810436 dxy = ((motion_fy & 1) << 1) | (motion_fx & 1);
1216 4810436 src_x = motion_fx >> 1;
1217 4810436 src_y = motion_fy >> 1;
1218
1219 4810436 ptr = ref_data[0] + (src_y * stride) + src_x;
1220 4810436 s->hdsp.put_pixels_tab[size][dxy](dest_y , ptr , stride, h);
1221
1222 4810436 dxy = ((motion_by & 1) << 1) | (motion_bx & 1);
1223 4810436 src_x = motion_bx >> 1;
1224 4810436 src_y = motion_by >> 1;
1225
1226 4810436 ptr = ref2_data[0] + (src_y * stride) + src_x;
1227 4810436 s->hdsp.avg_pixels_tab[size][dxy](dest_y , ptr , stride, h);
1228 }
1229
1230 10872370 fbmin = (mv_penalty_f[motion_fx-pred_fx] + mv_penalty_f[motion_fy-pred_fy])*c->mb_penalty_factor
1231 5436185 +(mv_penalty_b[motion_bx-pred_bx] + mv_penalty_b[motion_by-pred_by])*c->mb_penalty_factor
1232 5436185 + s->mecc.mb_cmp[size](s, src_data[0], dest_y, stride, h); // FIXME new_pic
1233
1234 5436185 if(c->avctx->mb_cmp&FF_CMP_CHROMA){
1235 }
1236 //FIXME CHROMA !!!
1237
1238 5436185 return fbmin;
1239 }
1240
1241 /* refine the bidir vectors in hq mode and return the score in both lq & hq mode*/
1242 408196 static inline int bidir_refine(MpegEncContext * s, int mb_x, int mb_y)
1243 {
1244 408196 MotionEstContext * const c= &s->me;
1245 408196 const int mot_stride = s->mb_stride;
1246 408196 const int xy = mb_y *mot_stride + mb_x;
1247 int fbmin;
1248 408196 int pred_fx= s->b_bidir_forw_mv_table[xy-1][0];
1249 408196 int pred_fy= s->b_bidir_forw_mv_table[xy-1][1];
1250 408196 int pred_bx= s->b_bidir_back_mv_table[xy-1][0];
1251 408196 int pred_by= s->b_bidir_back_mv_table[xy-1][1];
1252 408196 int motion_fx= s->b_bidir_forw_mv_table[xy][0]= s->b_forw_mv_table[xy][0];
1253 408196 int motion_fy= s->b_bidir_forw_mv_table[xy][1]= s->b_forw_mv_table[xy][1];
1254 408196 int motion_bx= s->b_bidir_back_mv_table[xy][0]= s->b_back_mv_table[xy][0];
1255 408196 int motion_by= s->b_bidir_back_mv_table[xy][1]= s->b_back_mv_table[xy][1];
1256 408196 const int flags= c->sub_flags;
1257 408196 const int qpel= flags&FLAG_QPEL;
1258 408196 const int shift= 1+qpel;
1259 408196 const int xmin= c->xmin * (1 << shift);
1260 408196 const int ymin= c->ymin * (1 << shift);
1261 408196 const int xmax= c->xmax<<shift;
1262 408196 const int ymax= c->ymax<<shift;
1263 #define HASH(fx,fy,bx,by) ((fx)+17*(fy)+63*(bx)+117*(by))
1264 #define HASH8(fx,fy,bx,by) ((uint8_t)HASH(fx,fy,bx,by))
1265 408196 int hashidx= HASH(motion_fx,motion_fy, motion_bx, motion_by);
1266 408196 uint8_t map[256] = { 0 };
1267
1268 408196 map[hashidx&255] = 1;
1269
1270 408196 fbmin= check_bidir_mv(s, motion_fx, motion_fy,
1271 motion_bx, motion_by,
1272 pred_fx, pred_fy,
1273 pred_bx, pred_by,
1274 0, 16);
1275
1276
1/2
✓ Branch 0 taken 408196 times.
✗ Branch 1 not taken.
408196 if(s->avctx->bidir_refine){
1277 int end;
1278 static const uint8_t limittab[5]={0,8,32,64,80};
1279 408196 const int limit= limittab[s->avctx->bidir_refine];
1280 static const int8_t vect[][4]={
1281 { 0, 0, 0, 1}, { 0, 0, 0,-1}, { 0, 0, 1, 0}, { 0, 0,-1, 0}, { 0, 1, 0, 0}, { 0,-1, 0, 0}, { 1, 0, 0, 0}, {-1, 0, 0, 0},
1282
1283 { 0, 0, 1, 1}, { 0, 0,-1,-1}, { 0, 1, 1, 0}, { 0,-1,-1, 0}, { 1, 1, 0, 0}, {-1,-1, 0, 0}, { 1, 0, 0, 1}, {-1, 0, 0,-1},
1284 { 0, 1, 0, 1}, { 0,-1, 0,-1}, { 1, 0, 1, 0}, {-1, 0,-1, 0},
1285 { 0, 0,-1, 1}, { 0, 0, 1,-1}, { 0,-1, 1, 0}, { 0, 1,-1, 0}, {-1, 1, 0, 0}, { 1,-1, 0, 0}, { 1, 0, 0,-1}, {-1, 0, 0, 1},
1286 { 0,-1, 0, 1}, { 0, 1, 0,-1}, {-1, 0, 1, 0}, { 1, 0,-1, 0},
1287
1288 { 0, 1, 1, 1}, { 0,-1,-1,-1}, { 1, 1, 1, 0}, {-1,-1,-1, 0}, { 1, 1, 0, 1}, {-1,-1, 0,-1}, { 1, 0, 1, 1}, {-1, 0,-1,-1},
1289 { 0,-1, 1, 1}, { 0, 1,-1,-1}, {-1, 1, 1, 0}, { 1,-1,-1, 0}, { 1, 1, 0,-1}, {-1,-1, 0, 1}, { 1, 0,-1, 1}, {-1, 0, 1,-1},
1290 { 0, 1,-1, 1}, { 0,-1, 1,-1}, { 1,-1, 1, 0}, {-1, 1,-1, 0}, {-1, 1, 0, 1}, { 1,-1, 0,-1}, { 1, 0, 1,-1}, {-1, 0,-1, 1},
1291 { 0, 1, 1,-1}, { 0,-1,-1, 1}, { 1, 1,-1, 0}, {-1,-1, 1, 0}, { 1,-1, 0, 1}, {-1, 1, 0,-1}, {-1, 0, 1, 1}, { 1, 0,-1,-1},
1292
1293 { 1, 1, 1, 1}, {-1,-1,-1,-1},
1294 { 1, 1, 1,-1}, {-1,-1,-1, 1}, { 1, 1,-1, 1}, {-1,-1, 1,-1}, { 1,-1, 1, 1}, {-1, 1,-1,-1}, {-1, 1, 1, 1}, { 1,-1,-1,-1},
1295 { 1, 1,-1,-1}, {-1,-1, 1, 1}, { 1,-1,-1, 1}, {-1, 1, 1,-1}, { 1,-1, 1,-1}, {-1, 1,-1, 1},
1296 };
1297 static const uint8_t hash[]={
1298 HASH8( 0, 0, 0, 1), HASH8( 0, 0, 0,-1), HASH8( 0, 0, 1, 0), HASH8( 0, 0,-1, 0), HASH8( 0, 1, 0, 0), HASH8( 0,-1, 0, 0), HASH8( 1, 0, 0, 0), HASH8(-1, 0, 0, 0),
1299
1300 HASH8( 0, 0, 1, 1), HASH8( 0, 0,-1,-1), HASH8( 0, 1, 1, 0), HASH8( 0,-1,-1, 0), HASH8( 1, 1, 0, 0), HASH8(-1,-1, 0, 0), HASH8( 1, 0, 0, 1), HASH8(-1, 0, 0,-1),
1301 HASH8( 0, 1, 0, 1), HASH8( 0,-1, 0,-1), HASH8( 1, 0, 1, 0), HASH8(-1, 0,-1, 0),
1302 HASH8( 0, 0,-1, 1), HASH8( 0, 0, 1,-1), HASH8( 0,-1, 1, 0), HASH8( 0, 1,-1, 0), HASH8(-1, 1, 0, 0), HASH8( 1,-1, 0, 0), HASH8( 1, 0, 0,-1), HASH8(-1, 0, 0, 1),
1303 HASH8( 0,-1, 0, 1), HASH8( 0, 1, 0,-1), HASH8(-1, 0, 1, 0), HASH8( 1, 0,-1, 0),
1304
1305 HASH8( 0, 1, 1, 1), HASH8( 0,-1,-1,-1), HASH8( 1, 1, 1, 0), HASH8(-1,-1,-1, 0), HASH8( 1, 1, 0, 1), HASH8(-1,-1, 0,-1), HASH8( 1, 0, 1, 1), HASH8(-1, 0,-1,-1),
1306 HASH8( 0,-1, 1, 1), HASH8( 0, 1,-1,-1), HASH8(-1, 1, 1, 0), HASH8( 1,-1,-1, 0), HASH8( 1, 1, 0,-1), HASH8(-1,-1, 0, 1), HASH8( 1, 0,-1, 1), HASH8(-1, 0, 1,-1),
1307 HASH8( 0, 1,-1, 1), HASH8( 0,-1, 1,-1), HASH8( 1,-1, 1, 0), HASH8(-1, 1,-1, 0), HASH8(-1, 1, 0, 1), HASH8( 1,-1, 0,-1), HASH8( 1, 0, 1,-1), HASH8(-1, 0,-1, 1),
1308 HASH8( 0, 1, 1,-1), HASH8( 0,-1,-1, 1), HASH8( 1, 1,-1, 0), HASH8(-1,-1, 1, 0), HASH8( 1,-1, 0, 1), HASH8(-1, 1, 0,-1), HASH8(-1, 0, 1, 1), HASH8( 1, 0,-1,-1),
1309
1310 HASH8( 1, 1, 1, 1), HASH8(-1,-1,-1,-1),
1311 HASH8( 1, 1, 1,-1), HASH8(-1,-1,-1, 1), HASH8( 1, 1,-1, 1), HASH8(-1,-1, 1,-1), HASH8( 1,-1, 1, 1), HASH8(-1, 1,-1,-1), HASH8(-1, 1, 1, 1), HASH8( 1,-1,-1,-1),
1312 HASH8( 1, 1,-1,-1), HASH8(-1,-1, 1, 1), HASH8( 1,-1,-1, 1), HASH8(-1, 1, 1,-1), HASH8( 1,-1, 1,-1), HASH8(-1, 1,-1, 1),
1313 };
1314
1315 #define CHECK_BIDIR(fx,fy,bx,by)\
1316 if( !map[(hashidx+HASH(fx,fy,bx,by))&255]\
1317 &&(fx<=0 || motion_fx+fx<=xmax) && (fy<=0 || motion_fy+fy<=ymax) && (bx<=0 || motion_bx+bx<=xmax) && (by<=0 || motion_by+by<=ymax)\
1318 &&(fx>=0 || motion_fx+fx>=xmin) && (fy>=0 || motion_fy+fy>=ymin) && (bx>=0 || motion_bx+bx>=xmin) && (by>=0 || motion_by+by>=ymin)){\
1319 int score;\
1320 map[(hashidx+HASH(fx,fy,bx,by))&255] = 1;\
1321 score= check_bidir_mv(s, motion_fx+fx, motion_fy+fy, motion_bx+bx, motion_by+by, pred_fx, pred_fy, pred_bx, pred_by, 0, 16);\
1322 if(score < fbmin){\
1323 hashidx += HASH(fx,fy,bx,by);\
1324 fbmin= score;\
1325 motion_fx+=fx;\
1326 motion_fy+=fy;\
1327 motion_bx+=bx;\
1328 motion_by+=by;\
1329 end=0;\
1330 }\
1331 }
1332 #define CHECK_BIDIR2(a,b,c,d)\
1333 CHECK_BIDIR(a,b,c,d)\
1334 CHECK_BIDIR(-(a),-(b),-(c),-(d))
1335
1336 do{
1337 int i;
1338 827572 int borderdist=0;
1339 827572 end=1;
1340
1341
12/12
✓ Branch 0 taken 774557 times.
✓ Branch 1 taken 53015 times.
✓ Branch 2 taken 762398 times.
✓ Branch 3 taken 12159 times.
✓ Branch 5 taken 95157 times.
✓ Branch 6 taken 667241 times.
✓ Branch 7 taken 695835 times.
✓ Branch 8 taken 131737 times.
✓ Branch 9 taken 683529 times.
✓ Branch 10 taken 12306 times.
✓ Branch 12 taken 113786 times.
✓ Branch 13 taken 569743 times.
827572 CHECK_BIDIR2(0,0,0,1)
1342
12/12
✓ Branch 0 taken 711340 times.
✓ Branch 1 taken 116232 times.
✓ Branch 2 taken 700448 times.
✓ Branch 3 taken 10892 times.
✓ Branch 5 taken 101352 times.
✓ Branch 6 taken 599096 times.
✓ Branch 7 taken 613334 times.
✓ Branch 8 taken 214238 times.
✓ Branch 9 taken 603642 times.
✓ Branch 10 taken 9692 times.
✓ Branch 12 taken 83031 times.
✓ Branch 13 taken 520611 times.
827572 CHECK_BIDIR2(0,0,1,0)
1343
12/12
✓ Branch 0 taken 657865 times.
✓ Branch 1 taken 169707 times.
✓ Branch 2 taken 640842 times.
✓ Branch 3 taken 17023 times.
✓ Branch 5 taken 92574 times.
✓ Branch 6 taken 548268 times.
✓ Branch 7 taken 557531 times.
✓ Branch 8 taken 270041 times.
✓ Branch 9 taken 540393 times.
✓ Branch 10 taken 17138 times.
✓ Branch 12 taken 59872 times.
✓ Branch 13 taken 480521 times.
827572 CHECK_BIDIR2(0,1,0,0)
1344
12/12
✓ Branch 0 taken 590201 times.
✓ Branch 1 taken 237371 times.
✓ Branch 2 taken 574467 times.
✓ Branch 3 taken 15734 times.
✓ Branch 5 taken 66168 times.
✓ Branch 6 taken 508299 times.
✓ Branch 7 taken 538335 times.
✓ Branch 8 taken 289237 times.
✓ Branch 9 taken 522270 times.
✓ Branch 10 taken 16065 times.
✓ Branch 12 taken 72366 times.
✓ Branch 13 taken 449904 times.
827572 CHECK_BIDIR2(1,0,0,0)
1345
1346
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 827572 times.
827572 for(i=8; i<limit; i++){
1347 int fx= motion_fx+vect[i][0];
1348 int fy= motion_fy+vect[i][1];
1349 int bx= motion_bx+vect[i][2];
1350 int by= motion_by+vect[i][3];
1351 if(borderdist<=0){
1352 int a= (xmax - FFMAX(fx,bx))|(FFMIN(fx,bx) - xmin);
1353 int b= (ymax - FFMAX(fy,by))|(FFMIN(fy,by) - ymin);
1354 if((a|b) < 0)
1355 map[(hashidx+hash[i])&255] = 1;
1356 }
1357 if(!map[(hashidx+hash[i])&255]){
1358 int score;
1359 map[(hashidx+hash[i])&255] = 1;
1360 score= check_bidir_mv(s, fx, fy, bx, by, pred_fx, pred_fy, pred_bx, pred_by, 0, 16);
1361 if(score < fbmin){
1362 hashidx += hash[i];
1363 fbmin= score;
1364 motion_fx=fx;
1365 motion_fy=fy;
1366 motion_bx=bx;
1367 motion_by=by;
1368 end=0;
1369 borderdist--;
1370 if(borderdist<=0){
1371 int a= FFMIN(xmax - FFMAX(fx,bx), FFMIN(fx,bx) - xmin);
1372 int b= FFMIN(ymax - FFMAX(fy,by), FFMIN(fy,by) - ymin);
1373 borderdist= FFMIN(a,b);
1374 }
1375 }
1376 }
1377 }
1378
2/2
✓ Branch 0 taken 419376 times.
✓ Branch 1 taken 408196 times.
827572 }while(!end);
1379 }
1380
1381 408196 s->b_bidir_forw_mv_table[xy][0]= motion_fx;
1382 408196 s->b_bidir_forw_mv_table[xy][1]= motion_fy;
1383 408196 s->b_bidir_back_mv_table[xy][0]= motion_bx;
1384 408196 s->b_bidir_back_mv_table[xy][1]= motion_by;
1385
1386 408196 return fbmin;
1387 }
1388
1389 191520 static inline int direct_search(MpegEncContext * s, int mb_x, int mb_y)
1390 {
1391 191520 MotionEstContext * const c= &s->me;
1392 int P[10][2];
1393 191520 const int mot_stride = s->mb_stride;
1394 191520 const int mot_xy = mb_y*mot_stride + mb_x;
1395 191520 const int shift= 1+s->quarter_sample;
1396 int dmin, i;
1397 191520 const int time_pp= s->pp_time;
1398 191520 const int time_pb= s->pb_time;
1399 int mx, my, xmin, xmax, ymin, ymax;
1400 191520 int16_t (*mv_table)[2]= s->b_direct_mv_table;
1401
1402 191520 c->current_mv_penalty= c->mv_penalty[1] + MAX_DMV;
1403 191520 ymin= xmin=(-32)>>shift;
1404 191520 ymax= xmax= 31>>shift;
1405
1406
2/2
✓ Branch 0 taken 54658 times.
✓ Branch 1 taken 136862 times.
191520 if (IS_8X8(s->next_picture.mb_type[mot_xy])) {
1407 54658 s->mv_type= MV_TYPE_8X8;
1408 }else{
1409 136862 s->mv_type= MV_TYPE_16X16;
1410 }
1411
1412
2/2
✓ Branch 0 taken 355494 times.
✓ Branch 1 taken 54658 times.
410152 for(i=0; i<4; i++){
1413 355494 int index= s->block_index[i];
1414 int min, max;
1415
1416 355494 c->co_located_mv[i][0] = s->next_picture.motion_val[0][index][0];
1417 355494 c->co_located_mv[i][1] = s->next_picture.motion_val[0][index][1];
1418 355494 c->direct_basis_mv[i][0]= c->co_located_mv[i][0]*time_pb/time_pp + ((i& 1)<<(shift+3));
1419 355494 c->direct_basis_mv[i][1]= c->co_located_mv[i][1]*time_pb/time_pp + ((i>>1)<<(shift+3));
1420 // c->direct_basis_mv[1][i][0]= c->co_located_mv[i][0]*(time_pb - time_pp)/time_pp + ((i &1)<<(shift+3);
1421 // c->direct_basis_mv[1][i][1]= c->co_located_mv[i][1]*(time_pb - time_pp)/time_pp + ((i>>1)<<(shift+3);
1422
1423
2/2
✓ Branch 0 taken 139772 times.
✓ Branch 1 taken 215722 times.
355494 max= FFMAX(c->direct_basis_mv[i][0], c->direct_basis_mv[i][0] - c->co_located_mv[i][0])>>shift;
1424
2/2
✓ Branch 0 taken 139772 times.
✓ Branch 1 taken 215722 times.
355494 min= FFMIN(c->direct_basis_mv[i][0], c->direct_basis_mv[i][0] - c->co_located_mv[i][0])>>shift;
1425 355494 max+= 16*mb_x + 1; // +-1 is for the simpler rounding
1426 355494 min+= 16*mb_x - 1;
1427 355494 xmax= FFMIN(xmax, s->width - max);
1428 355494 xmin= FFMAX(xmin, - 16 - min);
1429
1430
2/2
✓ Branch 0 taken 141358 times.
✓ Branch 1 taken 214136 times.
355494 max= FFMAX(c->direct_basis_mv[i][1], c->direct_basis_mv[i][1] - c->co_located_mv[i][1])>>shift;
1431
2/2
✓ Branch 0 taken 141358 times.
✓ Branch 1 taken 214136 times.
355494 min= FFMIN(c->direct_basis_mv[i][1], c->direct_basis_mv[i][1] - c->co_located_mv[i][1])>>shift;
1432 355494 max+= 16*mb_y + 1; // +-1 is for the simpler rounding
1433 355494 min+= 16*mb_y - 1;
1434 355494 ymax= FFMIN(ymax, s->height - max);
1435 355494 ymin= FFMAX(ymin, - 16 - min);
1436
1437
2/2
✓ Branch 0 taken 136862 times.
✓ Branch 1 taken 218632 times.
355494 if(s->mv_type == MV_TYPE_16X16) break;
1438 }
1439
1440 av_assert2(xmax <= 15 && ymax <= 15 && xmin >= -16 && ymin >= -16);
1441
1442
7/8
✓ Branch 0 taken 191455 times.
✓ Branch 1 taken 65 times.
✓ Branch 2 taken 191453 times.
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 191418 times.
✓ Branch 5 taken 35 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 191418 times.
191520 if(xmax < 0 || xmin >0 || ymax < 0 || ymin > 0){
1443 102 s->b_direct_mv_table[mot_xy][0]= 0;
1444 102 s->b_direct_mv_table[mot_xy][1]= 0;
1445
1446 102 return 256*256*256*64;
1447 }
1448
1449 191418 c->xmin= xmin;
1450 191418 c->ymin= ymin;
1451 191418 c->xmax= xmax;
1452 191418 c->ymax= ymax;
1453 191418 c->flags |= FLAG_DIRECT;
1454 191418 c->sub_flags |= FLAG_DIRECT;
1455 191418 c->pred_x=0;
1456 191418 c->pred_y=0;
1457
1458 191418 P_LEFT[0] = av_clip(mv_table[mot_xy - 1][0], xmin * (1 << shift), xmax << shift);
1459 191418 P_LEFT[1] = av_clip(mv_table[mot_xy - 1][1], ymin * (1 << shift), ymax << shift);
1460
1461 /* special case for first line */
1462
2/2
✓ Branch 0 taken 178176 times.
✓ Branch 1 taken 13242 times.
191418 if (!s->first_slice_line) { //FIXME maybe allow this over thread boundary as it is clipped
1463 178176 P_TOP[0] = av_clip(mv_table[mot_xy - mot_stride ][0], xmin * (1 << shift), xmax << shift);
1464 178176 P_TOP[1] = av_clip(mv_table[mot_xy - mot_stride ][1], ymin * (1 << shift), ymax << shift);
1465 178176 P_TOPRIGHT[0] = av_clip(mv_table[mot_xy - mot_stride + 1][0], xmin * (1 << shift), xmax << shift);
1466 178176 P_TOPRIGHT[1] = av_clip(mv_table[mot_xy - mot_stride + 1][1], ymin * (1 << shift), ymax << shift);
1467
1468 178176 P_MEDIAN[0]= mid_pred(P_LEFT[0], P_TOP[0], P_TOPRIGHT[0]);
1469 178176 P_MEDIAN[1]= mid_pred(P_LEFT[1], P_TOP[1], P_TOPRIGHT[1]);
1470 }
1471
1472 191418 dmin = ff_epzs_motion_search(s, &mx, &my, P, 0, 0, mv_table, 1<<(16-shift), 0, 16);
1473
2/2
✓ Branch 0 taken 38282 times.
✓ Branch 1 taken 153136 times.
191418 if(c->sub_flags&FLAG_QPEL)
1474 38282 dmin = qpel_motion_search(s, &mx, &my, dmin, 0, 0, 0, 16);
1475 else
1476 153136 dmin = hpel_motion_search(s, &mx, &my, dmin, 0, 0, 0, 16);
1477
1478
4/4
✓ Branch 0 taken 114843 times.
✓ Branch 1 taken 76575 times.
✓ Branch 2 taken 114823 times.
✓ Branch 3 taken 20 times.
191418 if(c->avctx->me_sub_cmp != c->avctx->mb_cmp && !c->skip)
1479 114823 dmin= get_mb_score(s, mx, my, 0, 0, 0, 16, 1);
1480
1481 191418 get_limits(s, 16*mb_x, 16*mb_y); //restore c->?min/max, maybe not needed
1482
1483 191418 mv_table[mot_xy][0]= mx;
1484 191418 mv_table[mot_xy][1]= my;
1485 191418 c->flags &= ~FLAG_DIRECT;
1486 191418 c->sub_flags &= ~FLAG_DIRECT;
1487
1488 191418 return dmin;
1489 }
1490
1491 408312 void ff_estimate_b_frame_motion(MpegEncContext * s,
1492 int mb_x, int mb_y)
1493 {
1494 408312 MotionEstContext * const c= &s->me;
1495 408312 const int penalty_factor= c->mb_penalty_factor;
1496 int fmin, bmin, dmin, fbmin, bimin, fimin;
1497 408312 int type=0;
1498 408312 const int xy = mb_y*s->mb_stride + mb_x;
1499 408312 init_ref(c, s->new_picture->data, s->last_picture.f->data,
1500 408312 s->next_picture.f->data, 16 * mb_x, 16 * mb_y, 2);
1501
1502 408312 get_limits(s, 16*mb_x, 16*mb_y);
1503
1504 408312 c->skip=0;
1505
1506
4/4
✓ Branch 0 taken 191520 times.
✓ Branch 1 taken 216792 times.
✓ Branch 2 taken 116 times.
✓ Branch 3 taken 191404 times.
408312 if (s->codec_id == AV_CODEC_ID_MPEG4 && s->next_picture.mbskip_table[xy]) {
1507 116 int score= direct_search(s, mb_x, mb_y); //FIXME just check 0,0
1508
1509 116 score= ((unsigned)(score*score + 128*256))>>16;
1510 116 c->mc_mb_var_sum_temp += score;
1511 116 s->mc_mb_var[mb_y*s->mb_stride + mb_x] = score; //FIXME use SSE
1512 116 s->mb_type[mb_y*s->mb_stride + mb_x]= CANDIDATE_MB_TYPE_DIRECT0;
1513
1514 116 return;
1515 }
1516
1517
2/2
✓ Branch 0 taken 191404 times.
✓ Branch 1 taken 216792 times.
408196 if (s->codec_id == AV_CODEC_ID_MPEG4)
1518 191404 dmin= direct_search(s, mb_x, mb_y);
1519 else
1520 216792 dmin= INT_MAX;
1521 // FIXME penalty stuff for non-MPEG-4
1522 408196 c->skip=0;
1523 408196 fmin = estimate_motion_b(s, mb_x, mb_y, s->b_forw_mv_table, 0, s->f_code) +
1524 408196 3 * penalty_factor;
1525
1526 408196 c->skip=0;
1527 408196 bmin = estimate_motion_b(s, mb_x, mb_y, s->b_back_mv_table, 2, s->b_code) +
1528 408196 2 * penalty_factor;
1529 ff_dlog(s, " %d %d ", s->b_forw_mv_table[xy][0], s->b_forw_mv_table[xy][1]);
1530
1531 408196 c->skip=0;
1532 408196 fbmin= bidir_refine(s, mb_x, mb_y) + penalty_factor;
1533 ff_dlog(s, "%d %d %d %d\n", dmin, fmin, bmin, fbmin);
1534
1535
2/2
✓ Branch 0 taken 115200 times.
✓ Branch 1 taken 292996 times.
408196 if (s->avctx->flags & AV_CODEC_FLAG_INTERLACED_ME) {
1536 //FIXME mb type penalty
1537 115200 c->skip=0;
1538 115200 c->current_mv_penalty= c->mv_penalty[s->f_code] + MAX_DMV;
1539 115200 fimin= interlaced_search(s, 0,
1540 115200 s->b_field_mv_table[0], s->b_field_select_table[0],
1541 115200 s->b_forw_mv_table[xy][0], s->b_forw_mv_table[xy][1], 0);
1542 115200 c->current_mv_penalty= c->mv_penalty[s->b_code] + MAX_DMV;
1543 115200 bimin= interlaced_search(s, 2,
1544 115200 s->b_field_mv_table[1], s->b_field_select_table[1],
1545 115200 s->b_back_mv_table[xy][0], s->b_back_mv_table[xy][1], 0);
1546 }else
1547 292996 fimin= bimin= INT_MAX;
1548
1549 {
1550 408196 int score= fmin;
1551 408196 type = CANDIDATE_MB_TYPE_FORWARD;
1552
1553
2/2
✓ Branch 0 taken 55256 times.
✓ Branch 1 taken 352940 times.
408196 if (dmin <= score){
1554 55256 score = dmin;
1555 55256 type = CANDIDATE_MB_TYPE_DIRECT;
1556 }
1557
2/2
✓ Branch 0 taken 202888 times.
✓ Branch 1 taken 205308 times.
408196 if(bmin<score){
1558 202888 score=bmin;
1559 202888 type= CANDIDATE_MB_TYPE_BACKWARD;
1560 }
1561
2/2
✓ Branch 0 taken 237825 times.
✓ Branch 1 taken 170371 times.
408196 if(fbmin<score){
1562 237825 score=fbmin;
1563 237825 type= CANDIDATE_MB_TYPE_BIDIR;
1564 }
1565
2/2
✓ Branch 0 taken 3902 times.
✓ Branch 1 taken 404294 times.
408196 if(fimin<score){
1566 3902 score=fimin;
1567 3902 type= CANDIDATE_MB_TYPE_FORWARD_I;
1568 }
1569
2/2
✓ Branch 0 taken 4095 times.
✓ Branch 1 taken 404101 times.
408196 if(bimin<score){
1570 4095 score=bimin;
1571 4095 type= CANDIDATE_MB_TYPE_BACKWARD_I;
1572 }
1573
1574 408196 score= ((unsigned)(score*score + 128*256))>>16;
1575 408196 c->mc_mb_var_sum_temp += score;
1576 408196 s->mc_mb_var[mb_y*s->mb_stride + mb_x] = score; //FIXME use SSE
1577 }
1578
1579
2/2
✓ Branch 0 taken 229852 times.
✓ Branch 1 taken 178344 times.
408196 if(c->avctx->mb_decision > FF_MB_DECISION_SIMPLE){
1580 229852 type= CANDIDATE_MB_TYPE_FORWARD | CANDIDATE_MB_TYPE_BACKWARD | CANDIDATE_MB_TYPE_BIDIR | CANDIDATE_MB_TYPE_DIRECT;
1581
2/2
✓ Branch 0 taken 30990 times.
✓ Branch 1 taken 198862 times.
229852 if(fimin < INT_MAX)
1582 30990 type |= CANDIDATE_MB_TYPE_FORWARD_I;
1583
2/2
✓ Branch 0 taken 31154 times.
✓ Branch 1 taken 198698 times.
229852 if(bimin < INT_MAX)
1584 31154 type |= CANDIDATE_MB_TYPE_BACKWARD_I;
1585
4/4
✓ Branch 0 taken 30990 times.
✓ Branch 1 taken 198862 times.
✓ Branch 2 taken 26027 times.
✓ Branch 3 taken 4963 times.
229852 if(fimin < INT_MAX && bimin < INT_MAX){
1586 26027 type |= CANDIDATE_MB_TYPE_BIDIR_I;
1587 }
1588 //FIXME something smarter
1589
2/2
✓ Branch 0 taken 76801 times.
✓ Branch 1 taken 153051 times.
229852 if(dmin>256*256*16) type&= ~CANDIDATE_MB_TYPE_DIRECT; //do not try direct mode if it is invalid for this MB
1590
4/4
✓ Branch 0 taken 153148 times.
✓ Branch 1 taken 76704 times.
✓ Branch 2 taken 153051 times.
✓ Branch 3 taken 97 times.
229852 if (s->codec_id == AV_CODEC_ID_MPEG4 && type&CANDIDATE_MB_TYPE_DIRECT &&
1591
4/4
✓ Branch 0 taken 76517 times.
✓ Branch 1 taken 76534 times.
✓ Branch 2 taken 47391 times.
✓ Branch 3 taken 29126 times.
153051 s->mpv_flags & FF_MPV_FLAG_MV0 && *(uint32_t*)s->b_direct_mv_table[xy])
1592 47391 type |= CANDIDATE_MB_TYPE_DIRECT0;
1593 }
1594
1595 408196 s->mb_type[mb_y*s->mb_stride + mb_x]= type;
1596 }
1597
1598 /* find best f_code for ME which do unlimited searches */
1599 10926 int ff_get_best_fcode(MpegEncContext * s, const int16_t (*mv_table)[2], int type)
1600 {
1601
1/2
✓ Branch 0 taken 10926 times.
✗ Branch 1 not taken.
10926 if (s->motion_est != FF_ME_ZERO) {
1602 int score[8];
1603
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10926 times.
10926 int i, y, range= s->avctx->me_range ? s->avctx->me_range : (INT_MAX/2);
1604 10926 const uint8_t * fcode_tab = s->fcode_tab;
1605 10926 int best_fcode=-1;
1606 10926 int best_score=-10000000;
1607
1608
2/2
✓ Branch 0 taken 742 times.
✓ Branch 1 taken 10184 times.
10926 if(s->msmpeg4_version)
1609 742 range= FFMIN(range, 16);
1610
3/4
✓ Branch 0 taken 3904 times.
✓ Branch 1 taken 6280 times.
✓ Branch 2 taken 3904 times.
✗ Branch 3 not taken.
10184 else if(s->codec_id == AV_CODEC_ID_MPEG2VIDEO && s->avctx->strict_std_compliance >= FF_COMPLIANCE_NORMAL)
1611 3904 range= FFMIN(range, 256);
1612
1613
2/2
✓ Branch 0 taken 87408 times.
✓ Branch 1 taken 10926 times.
98334 for(i=0; i<8; i++) score[i]= s->mb_num*(8-i);
1614
1615
2/2
✓ Branch 0 taken 166686 times.
✓ Branch 1 taken 10926 times.
177612 for(y=0; y<s->mb_height; y++){
1616 int x;
1617 166686 int xy= y*s->mb_stride;
1618
2/2
✓ Branch 0 taken 3647430 times.
✓ Branch 1 taken 166686 times.
3814116 for(x=0; x<s->mb_width; x++, xy++){
1619
2/2
✓ Branch 0 taken 2955191 times.
✓ Branch 1 taken 692239 times.
3647430 if(s->mb_type[xy] & type){
1620 2955191 int mx= mv_table[xy][0];
1621 2955191 int my= mv_table[xy][1];
1622 2955191 int fcode= FFMAX(fcode_tab[mx + MAX_MV],
1623 fcode_tab[my + MAX_MV]);
1624 int j;
1625
1626
6/6
✓ Branch 0 taken 2954230 times.
✓ Branch 1 taken 961 times.
✓ Branch 2 taken 2953641 times.
✓ Branch 3 taken 589 times.
✓ Branch 4 taken 2953003 times.
✓ Branch 5 taken 638 times.
2955191 if (mx >= range || mx < -range ||
1627
2/2
✓ Branch 0 taken 410 times.
✓ Branch 1 taken 2952593 times.
2953003 my >= range || my < -range)
1628 2598 continue;
1629
1630
3/4
✓ Branch 0 taken 3151516 times.
✓ Branch 1 taken 2952593 times.
✓ Branch 2 taken 3151516 times.
✗ Branch 3 not taken.
6104109 for(j=0; j<fcode && j<8; j++){
1631
2/2
✓ Branch 0 taken 1885759 times.
✓ Branch 1 taken 1265757 times.
3151516 if (s->pict_type == AV_PICTURE_TYPE_B ||
1632
2/2
✓ Branch 0 taken 1785049 times.
✓ Branch 1 taken 100710 times.
1885759 s->mc_mb_var[xy] < s->mb_var[xy])
1633 3050806 score[j]-= 170;
1634 }
1635 }
1636 }
1637 }
1638
1639
2/2
✓ Branch 0 taken 76482 times.
✓ Branch 1 taken 10926 times.
87408 for(i=1; i<8; i++){
1640
2/2
✓ Branch 0 taken 14812 times.
✓ Branch 1 taken 61670 times.
76482 if(score[i] > best_score){
1641 14812 best_score= score[i];
1642 14812 best_fcode= i;
1643 }
1644 }
1645
1646 10926 return best_fcode;
1647 }else{
1648 return 1;
1649 }
1650 }
1651
1652 5414 void ff_fix_long_p_mvs(MpegEncContext * s, int type)
1653 {
1654 5414 MotionEstContext * const c= &s->me;
1655 5414 const int f_code= s->f_code;
1656 int y, range;
1657
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5414 times.
5414 av_assert0(s->pict_type==AV_PICTURE_TYPE_P);
1658
1659
4/4
✓ Branch 0 taken 3603 times.
✓ Branch 1 taken 1811 times.
✓ Branch 2 taken 742 times.
✓ Branch 3 taken 2861 times.
5414 range = (((s->out_format == FMT_MPEG1 || s->msmpeg4_version) ? 8 : 16) << f_code);
1660
1661
3/4
✓ Branch 0 taken 3554 times.
✓ Branch 1 taken 1860 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3554 times.
5414 av_assert0(range <= 16 || !s->msmpeg4_version);
1662
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 5414 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
5414 av_assert0(range <=256 || !(s->codec_id == AV_CODEC_ID_MPEG2VIDEO && s->avctx->strict_std_compliance >= FF_COMPLIANCE_NORMAL));
1663
1664
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 5414 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
5414 if(c->avctx->me_range && range > c->avctx->me_range) range= c->avctx->me_range;
1665
1666
2/2
✓ Branch 0 taken 927 times.
✓ Branch 1 taken 4487 times.
5414 if (s->avctx->flags & AV_CODEC_FLAG_4MV) {
1667 927 const int wrap= s->b8_stride;
1668
1669 /* clip / convert to intra 8x8 type MVs */
1670
2/2
✓ Branch 0 taken 13221 times.
✓ Branch 1 taken 927 times.
14148 for(y=0; y<s->mb_height; y++){
1671 13221 int xy= y*2*wrap;
1672 13221 int i= y*s->mb_stride;
1673 int x;
1674
1675
2/2
✓ Branch 0 taken 277695 times.
✓ Branch 1 taken 13221 times.
290916 for(x=0; x<s->mb_width; x++){
1676
2/2
✓ Branch 0 taken 210033 times.
✓ Branch 1 taken 67662 times.
277695 if(s->mb_type[i]&CANDIDATE_MB_TYPE_INTER4V){
1677 int block;
1678
2/2
✓ Branch 0 taken 840132 times.
✓ Branch 1 taken 210033 times.
1050165 for(block=0; block<4; block++){
1679 840132 int off= (block& 1) + (block>>1)*wrap;
1680 840132 int mx = s->current_picture.motion_val[0][ xy + off ][0];
1681 840132 int my = s->current_picture.motion_val[0][ xy + off ][1];
1682
1683
4/4
✓ Branch 0 taken 839736 times.
✓ Branch 1 taken 396 times.
✓ Branch 2 taken 839117 times.
✓ Branch 3 taken 619 times.
840132 if( mx >=range || mx <-range
1684
4/4
✓ Branch 0 taken 838976 times.
✓ Branch 1 taken 141 times.
✓ Branch 2 taken 234 times.
✓ Branch 3 taken 838742 times.
839117 || my >=range || my <-range){
1685 1390 s->mb_type[i] &= ~CANDIDATE_MB_TYPE_INTER4V;
1686 1390 s->mb_type[i] |= type;
1687 1390 s->current_picture.mb_type[i] = type;
1688 }
1689 }
1690 }
1691 277695 xy+=2;
1692 277695 i++;
1693 }
1694 }
1695 }
1696 5414 }
1697
1698 /**
1699 * @param truncate 1 for truncation, 0 for using intra
1700 */
1701 15202 void ff_fix_long_mvs(MpegEncContext * s, uint8_t *field_select_table, int field_select,
1702 int16_t (*mv_table)[2], int f_code, int type, int truncate)
1703 {
1704 15202 MotionEstContext * const c= &s->me;
1705 int y, h_range, v_range;
1706
1707 // RAL: 8 in MPEG-1, 16 in MPEG-4
1708
4/4
✓ Branch 0 taken 6163 times.
✓ Branch 1 taken 9039 times.
✓ Branch 2 taken 742 times.
✓ Branch 3 taken 5421 times.
15202 int range = (((s->out_format == FMT_MPEG1 || s->msmpeg4_version) ? 8 : 16) << f_code);
1709
1710
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 15202 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
15202 if(c->avctx->me_range && range > c->avctx->me_range) range= c->avctx->me_range;
1711
1712 15202 h_range= range;
1713
2/2
✓ Branch 0 taken 4400 times.
✓ Branch 1 taken 10802 times.
15202 v_range= field_select_table ? range>>1 : range;
1714
1715 /* clip / convert to intra 16x16 type MVs */
1716
2/2
✓ Branch 0 taken 224947 times.
✓ Branch 1 taken 15202 times.
240149 for(y=0; y<s->mb_height; y++){
1717 int x;
1718 224947 int xy= y*s->mb_stride;
1719
2/2
✓ Branch 0 taken 4832589 times.
✓ Branch 1 taken 224947 times.
5057536 for(x=0; x<s->mb_width; x++){
1720
2/2
✓ Branch 0 taken 3327726 times.
✓ Branch 1 taken 1504863 times.
4832589 if (s->mb_type[xy] & type){ // RAL: "type" test added...
1721
4/4
✓ Branch 0 taken 359422 times.
✓ Branch 1 taken 2968304 times.
✓ Branch 2 taken 179813 times.
✓ Branch 3 taken 179609 times.
3327726 if (!field_select_table || field_select_table[xy] == field_select) {
1722
4/4
✓ Branch 0 taken 3145748 times.
✓ Branch 1 taken 2369 times.
✓ Branch 2 taken 3143914 times.
✓ Branch 3 taken 1834 times.
3148117 if( mv_table[xy][0] >=h_range || mv_table[xy][0] <-h_range
1723
4/4
✓ Branch 0 taken 3142467 times.
✓ Branch 1 taken 1447 times.
✓ Branch 2 taken 1133 times.
✓ Branch 3 taken 3141334 times.
3143914 || mv_table[xy][1] >=v_range || mv_table[xy][1] <-v_range){
1724
1725
2/2
✓ Branch 0 taken 1519 times.
✓ Branch 1 taken 5264 times.
6783 if(truncate){
1726
2/2
✓ Branch 0 taken 420 times.
✓ Branch 1 taken 1099 times.
1519 if (mv_table[xy][0] > h_range-1) mv_table[xy][0]= h_range-1;
1727
2/2
✓ Branch 0 taken 477 times.
✓ Branch 1 taken 622 times.
1099 else if(mv_table[xy][0] < -h_range ) mv_table[xy][0]= -h_range;
1728
2/2
✓ Branch 0 taken 342 times.
✓ Branch 1 taken 1177 times.
1519 if (mv_table[xy][1] > v_range-1) mv_table[xy][1]= v_range-1;
1729
2/2
✓ Branch 0 taken 317 times.
✓ Branch 1 taken 860 times.
1177 else if(mv_table[xy][1] < -v_range ) mv_table[xy][1]= -v_range;
1730 }else{
1731 5264 s->mb_type[xy] &= ~type;
1732 5264 s->mb_type[xy] |= CANDIDATE_MB_TYPE_INTRA;
1733 5264 mv_table[xy][0]=
1734 5264 mv_table[xy][1]= 0;
1735 }
1736 }
1737 }
1738 }
1739 4832589 xy++;
1740 }
1741 }
1742 15202 }
1743