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 | 6042877 | static inline unsigned update_map_generation(MotionEstContext *c) | |
55 | { | ||
56 | 6042877 | c->map_generation+= 1<<(ME_MAP_MV_BITS*2); | |
57 |
2/2✓ Branch 0 taken 5821 times.
✓ Branch 1 taken 6037056 times.
|
6042877 | if(c->map_generation==0){ |
58 | 5821 | c->map_generation= 1<<(ME_MAP_MV_BITS*2); | |
59 | 5821 | memset(c->map, 0, sizeof(uint32_t)*ME_MAP_SIZE); | |
60 | } | ||
61 | 6042877 | 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 | 2553517 | 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 | 2553517 | const int offset[3]= { | |
87 | 2553517 | y*c-> stride + x, | |
88 | 2553517 | ((y*c->uvstride + x)>>1), | |
89 | 2553517 | ((y*c->uvstride + x)>>1), | |
90 | }; | ||
91 | int i; | ||
92 |
2/2✓ Branch 0 taken 7660551 times.
✓ Branch 1 taken 2553517 times.
|
10214068 | for(i=0; i<3; i++){ |
93 | 7660551 | c->src[0][i]= src [i] + offset[i]; | |
94 | 7660551 | c->ref[0][i]= ref [i] + offset[i]; | |
95 | } | ||
96 |
2/2✓ Branch 0 taken 408312 times.
✓ Branch 1 taken 2145205 times.
|
2553517 | 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 | 2553517 | } | |
102 | |||
103 | 657 | static int get_flags(MotionEstContext *c, int direct, int chroma){ | |
104 | 657 | return ((c->avctx->flags&AV_CODEC_FLAG_QPEL) ? FLAG_QPEL : 0) | |
105 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 657 times.
|
657 | + (direct ? FLAG_DIRECT : 0) |
106 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 657 times.
|
657 | + (chroma ? FLAG_CHROMA : 0); |
107 | } | ||
108 | |||
109 | 2664973 | 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 | 2664973 | MotionEstContext * const c= &s->me; | |
113 | 2664973 | const int stride= c->stride; | |
114 | 2664973 | const int hx = subx + x * (1 << (1 + qpel)); | |
115 | 2664973 | const int hy = suby + y * (1 << (1 + qpel)); | |
116 | 2664973 | const uint8_t * const * const ref = c->ref[ref_index]; | |
117 | 2664973 | 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 2664973 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2664973 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2664973 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2664973 times.
✗ Branch 7 not taken.
|
5329946 | if(x >= c->xmin && hx <= c->xmax<<(qpel+1) && y >= c->ymin && hy <= c->ymax<<(qpel+1)){ |
122 | 2664973 | const int time_pp= s->pp_time; | |
123 | 2664973 | const int time_pb= s->pb_time; | |
124 | 2664973 | const int mask= 2*qpel+1; | |
125 |
2/2✓ Branch 0 taken 666289 times.
✓ Branch 1 taken 1998684 times.
|
2664973 | if(s->mv_type==MV_TYPE_8X8){ |
126 | int i; | ||
127 |
2/2✓ Branch 0 taken 2665156 times.
✓ Branch 1 taken 666289 times.
|
3331445 | for(i=0; i<4; i++){ |
128 | 2665156 | int fx = c->direct_basis_mv[i][0] + hx; | |
129 | 2665156 | int fy = c->direct_basis_mv[i][1] + hy; | |
130 |
2/2✓ Branch 0 taken 1686252 times.
✓ Branch 1 taken 978904 times.
|
2665156 | 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 1645424 times.
✓ Branch 1 taken 1019732 times.
|
2665156 | 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 | 2665156 | int fxy= (fx&mask) + ((fy&mask)<<(qpel+1)); | |
133 | 2665156 | int bxy= (bx&mask) + ((by&mask)<<(qpel+1)); | |
134 | |||
135 | 2665156 | uint8_t *dst= c->temp + 8*(i&1) + 8*stride*(i>>1); | |
136 |
2/2✓ Branch 0 taken 961440 times.
✓ Branch 1 taken 1703716 times.
|
2665156 | 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 | 1703716 | c->hpel_put[1][fxy](dst, ref[0] + (fx>>1) + (fy>>1)*stride, stride, 8); | |
141 | 1703716 | c->hpel_avg[1][bxy](dst, ref[8] + (bx>>1) + (by>>1)*stride, stride, 8); | |
142 | } | ||
143 | } | ||
144 | }else{ | ||
145 | 1998684 | int fx = c->direct_basis_mv[0][0] + hx; | |
146 | 1998684 | int fy = c->direct_basis_mv[0][1] + hy; | |
147 |
2/2✓ Branch 0 taken 1513294 times.
✓ Branch 1 taken 485390 times.
|
1998684 | 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 1471631 times.
✓ Branch 1 taken 527053 times.
|
1998684 | int by = hy ? fy - c->co_located_mv[0][1] : (c->co_located_mv[0][1]*(time_pb - time_pp)/time_pp); |
149 | 1998684 | int fxy= (fx&mask) + ((fy&mask)<<(qpel+1)); | |
150 | 1998684 | int bxy= (bx&mask) + ((by&mask)<<(qpel+1)); | |
151 | |||
152 |
2/2✓ Branch 0 taken 433681 times.
✓ Branch 1 taken 1565003 times.
|
1998684 | 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 | 1565003 | c->hpel_put[0][fxy](c->temp, ref[0] + (fx>>1) + (fy>>1)*stride, stride, 16); | |
172 | 1565003 | c->hpel_avg[0][bxy](c->temp, ref[8] + (bx>>1) + (by>>1)*stride, stride, 16); | |
173 | } | ||
174 | } | ||
175 | 2664973 | d = cmp_func(s, c->temp, src[0], stride, 16); | |
176 | }else | ||
177 | ✗ | d= 256*256*256*32; | |
178 | 2664973 | return d; | |
179 | } | ||
180 | |||
181 | 60028696 | 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 | 60028696 | MotionEstContext * const c= &s->me; | |
185 | 60028696 | const int stride= c->stride; | |
186 | 60028696 | const int uvstride= c->uvstride; | |
187 | 60028696 | const int dxy= subx + (suby<<(1+qpel)); //FIXME log2_subpel? | |
188 | 60028696 | const int hx= subx + x*(1<<(1+qpel)); | |
189 | 60028696 | const int hy= suby + y*(1<<(1+qpel)); | |
190 | 60028696 | const uint8_t * const * const ref = c->ref[ref_index]; | |
191 | 60028696 | 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 7984726 times.
✓ Branch 1 taken 52043970 times.
|
60028696 | if(dxy){ |
196 |
2/2✓ Branch 0 taken 6065785 times.
✓ Branch 1 taken 1918941 times.
|
7984726 | if(qpel){ |
197 |
1/2✓ Branch 0 taken 6065785 times.
✗ Branch 1 not taken.
|
6065785 | if (h << size == 16) { |
198 | 6065785 | 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 6065785 times.
|
6065785 | 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 | 1918941 | c->hpel_put[size][dxy](c->temp, ref[0] + x + y*stride, stride, h); | |
214 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1918941 times.
|
1918941 | if(chroma) |
215 | ✗ | uvdxy= dxy | (x&1) | (2*(y&1)); | |
216 | } | ||
217 | 7984726 | d = cmp_func(s, c->temp, src[0], stride, h); | |
218 | }else{ | ||
219 | 52043970 | d = cmp_func(s, src[0], ref[0] + x + y*stride, stride, h); | |
220 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 52043970 times.
|
52043970 | if(chroma) |
221 | ✗ | uvdxy= (x&1) + 2*(y&1); | |
222 | } | ||
223 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 60028696 times.
|
60028696 | 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 | 60028696 | 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 | 54486197 | 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 1794701 times.
✓ Branch 1 taken 52691496 times.
|
54486197 | if(flags&FLAG_DIRECT){ |
253 | 1794701 | 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 | 52691496 | 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 | 54486197 | 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 | 54486197 | return cmp_internal(s,x,y,subx,suby,size,h,ref_index,src_index, cmp_func, chroma_cmp_func, flags); | |
274 | } | ||
275 | } | ||
276 | |||
277 | 2329440 | 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 596864 times.
✓ Branch 1 taken 1732576 times.
|
2329440 | if(flags&FLAG_DIRECT){ |
281 | 596864 | return cmp_direct_inline(s,x,y,subx,suby,size,h,ref_index,src_index, cmp_func, chroma_cmp_func, 0); | |
282 | }else{ | ||
283 | 1732576 | 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 | 5878032 | 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 5604624 times.
|
5878032 | 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 | 5604624 | 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 | 219 | av_cold int ff_me_init(MotionEstContext *c, AVCodecContext *avctx, | |
309 | const MECmpContext *mecc, int mpvenc) | ||
310 | { | ||
311 | 219 | int cache_size = FFMIN(ME_MAP_SIZE>>ME_MAP_SHIFT, 1<<ME_MAP_SHIFT); | |
312 | 219 | int dia_size = FFMAX(FFABS(avctx->dia_size) & 255, FFABS(avctx->pre_dia_size) & 255); | |
313 | int ret; | ||
314 | |||
315 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 219 times.
|
219 | if (FFMIN(avctx->dia_size, avctx->pre_dia_size) < -FFMIN(ME_MAP_SIZE, MAX_SAB_SIZE)) { |
316 | ✗ | av_log(avctx, AV_LOG_ERROR, "ME_MAP size is too small for SAB diamond\n"); | |
317 | ✗ | return AVERROR(EINVAL); | |
318 | } | ||
319 | |||
320 | 219 | c->avctx = avctx; | |
321 | |||
322 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 213 times.
|
219 | if (avctx->codec_id == AV_CODEC_ID_H261) |
323 | 6 | avctx->me_sub_cmp = avctx->me_cmp; | |
324 | |||
325 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 219 times.
|
219 | if (cache_size < 2 * dia_size) |
326 | ✗ | av_log(avctx, AV_LOG_INFO, "ME_MAP size may be a little small for the selected diamond size\n"); | |
327 | |||
328 | 219 | ret = ff_set_cmp(mecc, c->me_pre_cmp, avctx->me_pre_cmp, mpvenc); | |
329 | 219 | ret |= ff_set_cmp(mecc, c->me_cmp, avctx->me_cmp, mpvenc); | |
330 | 219 | ret |= ff_set_cmp(mecc, c->me_sub_cmp, avctx->me_sub_cmp, mpvenc); | |
331 | 219 | ret |= ff_set_cmp(mecc, c->mb_cmp, avctx->mb_cmp, mpvenc); | |
332 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 219 times.
|
219 | if (ret < 0) |
333 | ✗ | return ret; | |
334 | |||
335 | 219 | c->sse = mecc->sse[0]; | |
336 | 219 | memcpy(c->pix_abs, mecc->pix_abs, sizeof(c->pix_abs)); | |
337 | |||
338 | 219 | c->flags = get_flags(c, 0, avctx->me_cmp & FF_CMP_CHROMA); | |
339 | 219 | c->sub_flags = get_flags(c, 0, avctx->me_sub_cmp & FF_CMP_CHROMA); | |
340 | 219 | c->mb_flags = get_flags(c, 0, avctx->mb_cmp & FF_CMP_CHROMA); | |
341 | |||
342 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 213 times.
|
219 | if (avctx->codec_id == AV_CODEC_ID_H261) { |
343 | 6 | c->sub_motion_search = no_sub_motion_search; | |
344 |
2/2✓ Branch 0 taken 12 times.
✓ Branch 1 taken 201 times.
|
213 | } else if (avctx->flags & AV_CODEC_FLAG_QPEL) { |
345 | 12 | c->sub_motion_search= qpel_motion_search; | |
346 | }else{ | ||
347 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 201 times.
|
201 | if(c->avctx->me_sub_cmp&FF_CMP_CHROMA) |
348 | ✗ | c->sub_motion_search= hpel_motion_search; | |
349 |
2/2✓ Branch 0 taken 182 times.
✓ Branch 1 taken 19 times.
|
201 | else if( c->avctx->me_sub_cmp == FF_CMP_SAD |
350 |
1/2✓ Branch 0 taken 182 times.
✗ Branch 1 not taken.
|
182 | && c->avctx-> me_cmp == FF_CMP_SAD |
351 |
1/2✓ Branch 0 taken 182 times.
✗ Branch 1 not taken.
|
182 | && c->avctx-> mb_cmp == FF_CMP_SAD) |
352 | 182 | c->sub_motion_search= sad_hpel_motion_search; // 2050 vs. 2450 cycles | |
353 | else | ||
354 | 19 | c->sub_motion_search= hpel_motion_search; | |
355 | } | ||
356 | |||
357 | /* 8x8 fullpel search would need a 4x4 chroma compare, which we do | ||
358 | * not have yet, and even if we had, the motion estimation code | ||
359 | * does not expect it. */ | ||
360 |
2/2✓ Branch 0 taken 208 times.
✓ Branch 1 taken 11 times.
|
219 | if (avctx->codec_id != AV_CODEC_ID_SNOW) { |
361 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 208 times.
|
208 | if ((avctx->me_cmp & FF_CMP_CHROMA) /* && !c->me_cmp[2] */) |
362 | ✗ | c->me_cmp[2] = zero_cmp; | |
363 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 208 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
208 | if ((avctx->me_sub_cmp & FF_CMP_CHROMA) && !c->me_sub_cmp[2]) |
364 | ✗ | c->me_sub_cmp[2] = zero_cmp; | |
365 | } | ||
366 | |||
367 | 219 | return 0; | |
368 | } | ||
369 | |||
370 | 11423 | void ff_me_init_pic(MpegEncContext *s) | |
371 | { | ||
372 | 11423 | MotionEstContext * const c= &s->me; | |
373 | |||
374 | /*FIXME s->no_rounding b_type*/ | ||
375 |
2/2✓ Branch 0 taken 528 times.
✓ Branch 1 taken 10895 times.
|
11423 | if (s->avctx->flags & AV_CODEC_FLAG_QPEL) { |
376 | 528 | c->qpel_avg = s->qdsp.avg_qpel_pixels_tab; | |
377 |
2/2✓ Branch 0 taken 99 times.
✓ Branch 1 taken 429 times.
|
528 | if (s->no_rounding) |
378 | 99 | c->qpel_put = s->qdsp.put_no_rnd_qpel_pixels_tab; | |
379 | else | ||
380 | 429 | c->qpel_put = s->qdsp.put_qpel_pixels_tab; | |
381 | } | ||
382 | 11423 | c->hpel_avg = s->hdsp.avg_pixels_tab; | |
383 |
2/2✓ Branch 0 taken 1709 times.
✓ Branch 1 taken 9714 times.
|
11423 | if (s->no_rounding) |
384 | 1709 | c->hpel_put = s->hdsp.put_no_rnd_pixels_tab; | |
385 | else | ||
386 | 9714 | c->hpel_put = s->hdsp.put_pixels_tab; | |
387 | |||
388 |
1/2✓ Branch 0 taken 11423 times.
✗ Branch 1 not taken.
|
11423 | if(s->linesize){ |
389 | 11423 | c->stride = s->linesize; | |
390 | 11423 | c->uvstride= s->uvlinesize; | |
391 | }else{ | ||
392 | ✗ | c->stride = 16*s->mb_width + 32; | |
393 | ✗ | c->uvstride= 8*s->mb_width + 16; | |
394 | } | ||
395 |
1/2✓ Branch 0 taken 11423 times.
✗ Branch 1 not taken.
|
11423 | if (s->codec_id != AV_CODEC_ID_SNOW) { |
396 | 11423 | c->hpel_put[2][0]= c->hpel_put[2][1]= | |
397 | 11423 | c->hpel_put[2][2]= c->hpel_put[2][3]= zero_hpel; | |
398 | } | ||
399 | 11423 | } | |
400 | |||
401 | #define CHECK_SAD_HALF_MV(suffix, x, y) \ | ||
402 | {\ | ||
403 | d = c->pix_abs[size][(x ? 1 : 0) + (y ? 2 : 0)](NULL, pix, ptr + ((x) >> 1), stride, h); \ | ||
404 | d += (mv_penalty[pen_x + x] + mv_penalty[pen_y + y])*penalty_factor;\ | ||
405 | COPY3_IF_LT(dminh, d, dx, x, dy, y)\ | ||
406 | } | ||
407 | |||
408 | 4595765 | static int sad_hpel_motion_search(MpegEncContext * s, | |
409 | int *mx_ptr, int *my_ptr, int dmin, | ||
410 | int src_index, int ref_index, | ||
411 | int size, int h) | ||
412 | { | ||
413 | 4595765 | MotionEstContext * const c= &s->me; | |
414 | 4595765 | const int penalty_factor= c->sub_penalty_factor; | |
415 | int mx, my, dminh; | ||
416 | const uint8_t *pix, *ptr; | ||
417 | 4595765 | int stride= c->stride; | |
418 | 4595765 | LOAD_COMMON | |
419 | |||
420 | av_assert2(c->sub_flags == 0); | ||
421 | |||
422 |
2/2✓ Branch 0 taken 117086 times.
✓ Branch 1 taken 4478679 times.
|
4595765 | if(c->skip){ |
423 | 117086 | *mx_ptr = 0; | |
424 | 117086 | *my_ptr = 0; | |
425 | 117086 | return dmin; | |
426 | } | ||
427 | |||
428 | 4478679 | pix = c->src[src_index][0]; | |
429 | |||
430 | 4478679 | mx = *mx_ptr; | |
431 | 4478679 | my = *my_ptr; | |
432 | 4478679 | ptr = c->ref[ref_index][0] + (my * stride) + mx; | |
433 | |||
434 | 4478679 | dminh = dmin; | |
435 | |||
436 |
6/6✓ Branch 0 taken 4403142 times.
✓ Branch 1 taken 75537 times.
✓ Branch 2 taken 4333298 times.
✓ Branch 3 taken 69844 times.
✓ Branch 4 taken 4242776 times.
✓ Branch 5 taken 90522 times.
|
4478679 | if (mx > xmin && mx < xmax && |
437 |
2/2✓ Branch 0 taken 4159879 times.
✓ Branch 1 taken 82897 times.
|
4242776 | my > ymin && my < ymax) { |
438 | 4159879 | int dx=0, dy=0; | |
439 | int d, pen_x, pen_y; | ||
440 | 4159879 | const int index= my*(1<<ME_MAP_SHIFT) + mx; | |
441 | 4159879 | const int t= score_map[(index-(1<<ME_MAP_SHIFT))&(ME_MAP_SIZE-1)]; | |
442 | 4159879 | const int l= score_map[(index- 1 )&(ME_MAP_SIZE-1)]; | |
443 | 4159879 | const int r= score_map[(index+ 1 )&(ME_MAP_SIZE-1)]; | |
444 | 4159879 | const int b= score_map[(index+(1<<ME_MAP_SHIFT))&(ME_MAP_SIZE-1)]; | |
445 | 4159879 | mx += mx; | |
446 | 4159879 | my += my; | |
447 | |||
448 | |||
449 | 4159879 | pen_x= pred_x + mx; | |
450 | 4159879 | pen_y= pred_y + my; | |
451 | |||
452 | 4159879 | ptr-= stride; | |
453 |
2/2✓ Branch 0 taken 2113074 times.
✓ Branch 1 taken 2046805 times.
|
4159879 | if(t<=b){ |
454 | 2113074 | CHECK_SAD_HALF_MV(y2 , 0, -1) | |
455 |
2/2✓ Branch 0 taken 1315848 times.
✓ Branch 1 taken 797226 times.
|
2113074 | if(l<=r){ |
456 | 1315848 | CHECK_SAD_HALF_MV(xy2, -1, -1) | |
457 |
2/2✓ Branch 0 taken 768847 times.
✓ Branch 1 taken 547001 times.
|
1315848 | if(t+r<=b+l){ |
458 | 768847 | CHECK_SAD_HALF_MV(xy2, +1, -1) | |
459 | 768847 | ptr+= stride; | |
460 | }else{ | ||
461 | 547001 | ptr+= stride; | |
462 | 547001 | CHECK_SAD_HALF_MV(xy2, -1, +1) | |
463 | } | ||
464 | 1315848 | CHECK_SAD_HALF_MV(x2 , -1, 0) | |
465 | }else{ | ||
466 | 797226 | CHECK_SAD_HALF_MV(xy2, +1, -1) | |
467 |
2/2✓ Branch 0 taken 439239 times.
✓ Branch 1 taken 357987 times.
|
797226 | if(t+l<=b+r){ |
468 | 439239 | CHECK_SAD_HALF_MV(xy2, -1, -1) | |
469 | 439239 | ptr+= stride; | |
470 | }else{ | ||
471 | 357987 | ptr+= stride; | |
472 | 357987 | CHECK_SAD_HALF_MV(xy2, +1, +1) | |
473 | } | ||
474 | 797226 | CHECK_SAD_HALF_MV(x2 , +1, 0) | |
475 | } | ||
476 | }else{ | ||
477 |
2/2✓ Branch 0 taken 780734 times.
✓ Branch 1 taken 1266071 times.
|
2046805 | if(l<=r){ |
478 |
2/2✓ Branch 0 taken 329989 times.
✓ Branch 1 taken 450745 times.
|
780734 | if(t+l<=b+r){ |
479 | 329989 | CHECK_SAD_HALF_MV(xy2, -1, -1) | |
480 | 329989 | ptr+= stride; | |
481 | }else{ | ||
482 | 450745 | ptr+= stride; | |
483 | 450745 | CHECK_SAD_HALF_MV(xy2, +1, +1) | |
484 | } | ||
485 | 780734 | CHECK_SAD_HALF_MV(x2 , -1, 0) | |
486 | 780734 | CHECK_SAD_HALF_MV(xy2, -1, +1) | |
487 | }else{ | ||
488 |
2/2✓ Branch 0 taken 561007 times.
✓ Branch 1 taken 705064 times.
|
1266071 | if(t+r<=b+l){ |
489 | 561007 | CHECK_SAD_HALF_MV(xy2, +1, -1) | |
490 | 561007 | ptr+= stride; | |
491 | }else{ | ||
492 | 705064 | ptr+= stride; | |
493 | 705064 | CHECK_SAD_HALF_MV(xy2, -1, +1) | |
494 | } | ||
495 | 1266071 | CHECK_SAD_HALF_MV(x2 , +1, 0) | |
496 | 1266071 | CHECK_SAD_HALF_MV(xy2, +1, +1) | |
497 | } | ||
498 | 2046805 | CHECK_SAD_HALF_MV(y2 , 0, +1) | |
499 | } | ||
500 | 4159879 | mx+=dx; | |
501 | 4159879 | my+=dy; | |
502 | |||
503 | }else{ | ||
504 | 318800 | mx += mx; | |
505 | 318800 | my += my; | |
506 | } | ||
507 | |||
508 | 4478679 | *mx_ptr = mx; | |
509 | 4478679 | *my_ptr = my; | |
510 | 4478679 | return dminh; | |
511 | } | ||
512 | |||
513 | 2145205 | static inline void set_p_mv_tables(MpegEncContext * s, int mx, int my, int mv4) | |
514 | { | ||
515 | 2145205 | const int xy= s->mb_x + s->mb_y*s->mb_stride; | |
516 | |||
517 | 2145205 | s->p_mv_table[xy][0] = mx; | |
518 | 2145205 | s->p_mv_table[xy][1] = my; | |
519 | |||
520 | /* has already been set to the 4 MV if 4MV is done */ | ||
521 |
2/2✓ Branch 0 taken 1893441 times.
✓ Branch 1 taken 251764 times.
|
2145205 | if(mv4){ |
522 | 1893441 | int mot_xy= s->block_index[0]; | |
523 | |||
524 | 1893441 | s->cur_pic.motion_val[0][mot_xy ][0] = mx; | |
525 | 1893441 | s->cur_pic.motion_val[0][mot_xy ][1] = my; | |
526 | 1893441 | s->cur_pic.motion_val[0][mot_xy + 1][0] = mx; | |
527 | 1893441 | s->cur_pic.motion_val[0][mot_xy + 1][1] = my; | |
528 | |||
529 | 1893441 | mot_xy += s->b8_stride; | |
530 | 1893441 | s->cur_pic.motion_val[0][mot_xy ][0] = mx; | |
531 | 1893441 | s->cur_pic.motion_val[0][mot_xy ][1] = my; | |
532 | 1893441 | s->cur_pic.motion_val[0][mot_xy + 1][0] = mx; | |
533 | 1893441 | s->cur_pic.motion_val[0][mot_xy + 1][1] = my; | |
534 | } | ||
535 | 2145205 | } | |
536 | |||
537 | /** | ||
538 | * get fullpel ME search limits. | ||
539 | */ | ||
540 | 3561381 | static inline void get_limits(MpegEncContext *s, int x, int y, int bframe) | |
541 | { | ||
542 | 3561381 | MotionEstContext * const c= &s->me; | |
543 |
2/2✓ Branch 0 taken 168764 times.
✓ Branch 1 taken 3392617 times.
|
3561381 | int range= c->avctx->me_range >> (1 + !!(c->flags&FLAG_QPEL)); |
544 |
2/2✓ Branch 0 taken 168764 times.
✓ Branch 1 taken 3392617 times.
|
3561381 | int max_range = MAX_MV >> (1 + !!(c->flags&FLAG_QPEL)); |
545 | /* | ||
546 | if(c->avctx->me_range) c->range= c->avctx->me_range >> 1; | ||
547 | else c->range= 16; | ||
548 | */ | ||
549 |
2/2✓ Branch 0 taken 1750751 times.
✓ Branch 1 taken 1810630 times.
|
3561381 | if (s->unrestricted_mv) { |
550 | 1750751 | c->xmin = - x - 16; | |
551 | 1750751 | c->ymin = - y - 16; | |
552 | 1750751 | c->xmax = - x + s->width; | |
553 | 1750751 | c->ymax = - y + s->height; | |
554 |
2/2✓ Branch 0 taken 106920 times.
✓ Branch 1 taken 1703710 times.
|
1810630 | } else if (!(av_builtin_constant_p(bframe) && bframe) && s->out_format == FMT_H261){ |
555 | // Search range of H.261 is different from other codec standards | ||
556 |
2/2✓ Branch 0 taken 102060 times.
✓ Branch 1 taken 4860 times.
|
106920 | c->xmin = (x > 15) ? - 15 : 0; |
557 |
2/2✓ Branch 0 taken 100980 times.
✓ Branch 1 taken 5940 times.
|
106920 | c->ymin = (y > 15) ? - 15 : 0; |
558 |
2/2✓ Branch 0 taken 102060 times.
✓ Branch 1 taken 4860 times.
|
106920 | c->xmax = (x < s->mb_width * 16 - 16) ? 15 : 0; |
559 |
2/2✓ Branch 0 taken 100980 times.
✓ Branch 1 taken 5940 times.
|
106920 | c->ymax = (y < s->mb_height * 16 - 16) ? 15 : 0; |
560 | } else { | ||
561 | 1703710 | c->xmin = - x; | |
562 | 1703710 | c->ymin = - y; | |
563 | 1703710 | c->xmax = - x + s->mb_width *16 - 16; | |
564 | 1703710 | c->ymax = - y + s->mb_height*16 - 16; | |
565 | } | ||
566 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 3561381 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
3561381 | if(!range || range > max_range) |
567 | 3561381 | range = max_range; | |
568 |
1/2✓ Branch 0 taken 3561381 times.
✗ Branch 1 not taken.
|
3561381 | if(range){ |
569 | 3561381 | c->xmin = FFMAX(c->xmin,-range); | |
570 | 3561381 | c->xmax = FFMIN(c->xmax, range); | |
571 | 3561381 | c->ymin = FFMAX(c->ymin,-range); | |
572 | 3561381 | c->ymax = FFMIN(c->ymax, range); | |
573 | } | ||
574 | 3561381 | } | |
575 | |||
576 | 251764 | static inline void init_mv4_ref(MotionEstContext *c){ | |
577 | 251764 | const int stride= c->stride; | |
578 | |||
579 | 251764 | c->ref[1][0] = c->ref[0][0] + 8; | |
580 | 251764 | c->ref[2][0] = c->ref[0][0] + 8*stride; | |
581 | 251764 | c->ref[3][0] = c->ref[2][0] + 8; | |
582 | 251764 | c->src[1][0] = c->src[0][0] + 8; | |
583 | 251764 | c->src[2][0] = c->src[0][0] + 8*stride; | |
584 | 251764 | c->src[3][0] = c->src[2][0] + 8; | |
585 | 251764 | } | |
586 | |||
587 | 251764 | static inline int h263_mv4_search(MpegEncContext *s, int mx, int my, int shift) | |
588 | { | ||
589 | 251764 | MotionEstContext * const c= &s->me; | |
590 | 251764 | const int size= 1; | |
591 | 251764 | const int h=8; | |
592 | int block; | ||
593 | int P[10][2]; | ||
594 | 251764 | int dmin_sum=0, mx4_sum=0, my4_sum=0, i; | |
595 | 251764 | int same=1; | |
596 | 251764 | const int stride= c->stride; | |
597 | 251764 | const uint8_t *mv_penalty = c->current_mv_penalty; | |
598 |
4/6✓ Branch 0 taken 251764 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2060 times.
✓ Branch 3 taken 249704 times.
✓ Branch 4 taken 2060 times.
✗ Branch 5 not taken.
|
251764 | int safety_clipping= s->unrestricted_mv && (s->width&15) && (s->height&15); |
599 | |||
600 | 251764 | init_mv4_ref(c); | |
601 | |||
602 |
2/2✓ Branch 0 taken 1007056 times.
✓ Branch 1 taken 251764 times.
|
1258820 | for(block=0; block<4; block++){ |
603 | int mx4, my4; | ||
604 | int pred_x4, pred_y4; | ||
605 | int dmin4; | ||
606 | static const int off[4]= {2, 1, 1, -1}; | ||
607 | 1007056 | const int mot_stride = s->b8_stride; | |
608 | 1007056 | const int mot_xy = s->block_index[block]; | |
609 | |||
610 |
2/2✓ Branch 0 taken 8240 times.
✓ Branch 1 taken 998816 times.
|
1007056 | if(safety_clipping){ |
611 | 8240 | c->xmax = - 16*s->mb_x + s->width - 8*(block &1); | |
612 | 8240 | c->ymax = - 16*s->mb_y + s->height - 8*(block>>1); | |
613 | } | ||
614 | |||
615 | 1007056 | P_LEFT[0] = s->cur_pic.motion_val[0][mot_xy - 1][0]; | |
616 | 1007056 | P_LEFT[1] = s->cur_pic.motion_val[0][mot_xy - 1][1]; | |
617 | |||
618 |
2/2✓ Branch 0 taken 1479 times.
✓ Branch 1 taken 1005577 times.
|
1007056 | if (P_LEFT[0] > c->xmax * (1 << shift)) P_LEFT[0] = c->xmax * (1 << shift); |
619 | |||
620 | /* special case for first line */ | ||
621 |
4/4✓ Branch 0 taken 62340 times.
✓ Branch 1 taken 944716 times.
✓ Branch 2 taken 31170 times.
✓ Branch 3 taken 31170 times.
|
1007056 | if (s->first_slice_line && block<2) { |
622 | 31170 | c->pred_x= pred_x4= P_LEFT[0]; | |
623 | 31170 | c->pred_y= pred_y4= P_LEFT[1]; | |
624 | } else { | ||
625 | 975886 | P_TOP[0] = s->cur_pic.motion_val[0][mot_xy - mot_stride ][0]; | |
626 | 975886 | P_TOP[1] = s->cur_pic.motion_val[0][mot_xy - mot_stride ][1]; | |
627 | 975886 | P_TOPRIGHT[0] = s->cur_pic.motion_val[0][mot_xy - mot_stride + off[block]][0]; | |
628 | 975886 | P_TOPRIGHT[1] = s->cur_pic.motion_val[0][mot_xy - mot_stride + off[block]][1]; | |
629 |
2/2✓ Branch 0 taken 1447 times.
✓ Branch 1 taken 974439 times.
|
975886 | if (P_TOP[1] > c->ymax * (1 << shift)) P_TOP[1] = c->ymax * (1 << shift); |
630 |
2/2✓ Branch 0 taken 28 times.
✓ Branch 1 taken 975858 times.
|
975886 | if (P_TOPRIGHT[0] < c->xmin * (1 << shift)) P_TOPRIGHT[0] = c->xmin * (1 << shift); |
631 |
2/2✓ Branch 0 taken 954 times.
✓ Branch 1 taken 974932 times.
|
975886 | if (P_TOPRIGHT[0] > c->xmax * (1 << shift)) P_TOPRIGHT[0] = c->xmax * (1 << shift); |
632 |
2/2✓ Branch 0 taken 1389 times.
✓ Branch 1 taken 974497 times.
|
975886 | if (P_TOPRIGHT[1] > c->ymax * (1 << shift)) P_TOPRIGHT[1] = c->ymax * (1 << shift); |
633 | |||
634 | 975886 | P_MEDIAN[0]= mid_pred(P_LEFT[0], P_TOP[0], P_TOPRIGHT[0]); | |
635 | 975886 | P_MEDIAN[1]= mid_pred(P_LEFT[1], P_TOP[1], P_TOPRIGHT[1]); | |
636 | |||
637 | 975886 | c->pred_x= pred_x4 = P_MEDIAN[0]; | |
638 | 975886 | c->pred_y= pred_y4 = P_MEDIAN[1]; | |
639 | } | ||
640 | 1007056 | P_MV1[0]= mx; | |
641 | 1007056 | P_MV1[1]= my; | |
642 |
2/2✓ Branch 0 taken 8240 times.
✓ Branch 1 taken 998816 times.
|
1007056 | if(safety_clipping) |
643 |
2/2✓ Branch 0 taken 74160 times.
✓ Branch 1 taken 8240 times.
|
82400 | for(i=1; i<10; i++){ |
644 |
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) |
645 | 10234 | continue; | |
646 |
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) |
647 | 27112 | continue; | |
648 |
2/2✓ Branch 0 taken 1173 times.
✓ Branch 1 taken 35641 times.
|
36814 | if (P[i][0] > c->xmax * (1 << shift)) P[i][0] = c->xmax * (1 << shift); |
649 |
2/2✓ Branch 0 taken 1432 times.
✓ Branch 1 taken 35382 times.
|
36814 | if (P[i][1] > c->ymax * (1 << shift)) P[i][1] = c->ymax * (1 <<shift ); |
650 | } | ||
651 | |||
652 | 1007056 | dmin4 = epzs_motion_search2(s, &mx4, &my4, P, block, block, s->p_mv_table, (1<<16)>>shift, 1); | |
653 | |||
654 | 1007056 | dmin4= c->sub_motion_search(s, &mx4, &my4, dmin4, block, block, size, h); | |
655 | |||
656 |
2/2✓ Branch 0 taken 167516 times.
✓ Branch 1 taken 839540 times.
|
1007056 | if (c->me_sub_cmp[0] != c->mb_cmp[0]) { |
657 | int dxy; | ||
658 | 167516 | const int offset= ((block&1) + (block>>1)*stride)*8; | |
659 | 167516 | uint8_t *dest_y = c->scratchpad + offset; | |
660 |
2/2✓ Branch 0 taken 56744 times.
✓ Branch 1 taken 110772 times.
|
167516 | if(s->quarter_sample){ |
661 | 56744 | const uint8_t *ref = c->ref[block][0] + (mx4>>2) + (my4>>2)*stride; | |
662 | 56744 | dxy = ((my4 & 3) << 2) | (mx4 & 3); | |
663 | |||
664 | 56744 | c->qpel_put[1][dxy](dest_y, ref, stride); | |
665 | }else{ | ||
666 | 110772 | const uint8_t *ref = c->ref[block][0] + (mx4>>1) + (my4>>1)*stride; | |
667 | 110772 | dxy = ((my4 & 1) << 1) | (mx4 & 1); | |
668 | |||
669 | 110772 | c->hpel_put[1][dxy](dest_y, ref, stride, h); | |
670 | } | ||
671 | 167516 | dmin_sum+= (mv_penalty[mx4-pred_x4] + mv_penalty[my4-pred_y4])*c->mb_penalty_factor; | |
672 | }else | ||
673 | 839540 | dmin_sum+= dmin4; | |
674 | |||
675 |
2/2✓ Branch 0 taken 56744 times.
✓ Branch 1 taken 950312 times.
|
1007056 | if(s->quarter_sample){ |
676 | 56744 | mx4_sum+= mx4/2; | |
677 | 56744 | my4_sum+= my4/2; | |
678 | }else{ | ||
679 | 950312 | mx4_sum+= mx4; | |
680 | 950312 | my4_sum+= my4; | |
681 | } | ||
682 | |||
683 | 1007056 | s->cur_pic.motion_val[0][s->block_index[block]][0] = mx4; | |
684 | 1007056 | s->cur_pic.motion_val[0][s->block_index[block]][1] = my4; | |
685 | |||
686 |
4/4✓ Branch 0 taken 535656 times.
✓ Branch 1 taken 471400 times.
✓ Branch 2 taken 129983 times.
✓ Branch 3 taken 405673 times.
|
1007056 | if(mx4 != mx || my4 != my) same=0; |
687 | } | ||
688 | |||
689 |
2/2✓ Branch 0 taken 41709 times.
✓ Branch 1 taken 210055 times.
|
251764 | if(same) |
690 | 41709 | return INT_MAX; | |
691 | |||
692 |
2/2✓ Branch 0 taken 41454 times.
✓ Branch 1 taken 168601 times.
|
210055 | if (c->me_sub_cmp[0] != c->mb_cmp[0]) { |
693 | 41454 | dmin_sum += c->mb_cmp[0](s, | |
694 | 41454 | s->new_pic->data[0] + | |
695 | 41454 | s->mb_x * 16 + s->mb_y * 16 * stride, | |
696 | 41454 | c->scratchpad, stride, 16); | |
697 | } | ||
698 | |||
699 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 210055 times.
|
210055 | if(c->avctx->mb_cmp&FF_CMP_CHROMA){ |
700 | int dxy; | ||
701 | int mx, my; | ||
702 | int offset; | ||
703 | |||
704 | ✗ | mx= ff_h263_round_chroma(mx4_sum); | |
705 | ✗ | my= ff_h263_round_chroma(my4_sum); | |
706 | ✗ | dxy = ((my & 1) << 1) | (mx & 1); | |
707 | |||
708 | ✗ | offset= (s->mb_x*8 + (mx>>1)) + (s->mb_y*8 + (my>>1))*s->uvlinesize; | |
709 | |||
710 | ✗ | c->hpel_put[1][dxy](c->scratchpad , s->last_pic.data[1] + offset, s->uvlinesize, 8); | |
711 | ✗ | c->hpel_put[1][dxy](c->scratchpad + 8, s->last_pic.data[2] + offset, s->uvlinesize, 8); | |
712 | |||
713 | ✗ | dmin_sum += c->mb_cmp[1](s, s->new_pic->data[1] + s->mb_x * 8 + s->mb_y * 8 * s->uvlinesize, c->scratchpad, s->uvlinesize, 8); | |
714 | ✗ | dmin_sum += c->mb_cmp[1](s, s->new_pic->data[2] + s->mb_x * 8 + s->mb_y * 8 * s->uvlinesize, c->scratchpad + 8, s->uvlinesize, 8); | |
715 | } | ||
716 | |||
717 | 210055 | c->pred_x= mx; | |
718 | 210055 | c->pred_y= my; | |
719 | |||
720 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 210055 times.
|
210055 | switch(c->avctx->mb_cmp&0xFF){ |
721 | /*case FF_CMP_SSE: | ||
722 | return dmin_sum+ 32*s->qscale*s->qscale;*/ | ||
723 | ✗ | case FF_CMP_RD: | |
724 | ✗ | return dmin_sum; | |
725 | 210055 | default: | |
726 | 210055 | return dmin_sum+ 11*c->mb_penalty_factor; | |
727 | } | ||
728 | } | ||
729 | |||
730 | 331233 | static inline void init_interlaced_ref(MpegEncContext *s, int ref_index){ | |
731 | 331233 | MotionEstContext * const c= &s->me; | |
732 | |||
733 | 331233 | c->ref[1+ref_index][0] = c->ref[0+ref_index][0] + s->linesize; | |
734 | 331233 | c->src[1][0] = c->src[0][0] + s->linesize; | |
735 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 331233 times.
|
331233 | if(c->flags & FLAG_CHROMA){ |
736 | ✗ | c->ref[1+ref_index][1] = c->ref[0+ref_index][1] + s->uvlinesize; | |
737 | ✗ | c->ref[1+ref_index][2] = c->ref[0+ref_index][2] + s->uvlinesize; | |
738 | ✗ | c->src[1][1] = c->src[0][1] + s->uvlinesize; | |
739 | ✗ | c->src[1][2] = c->src[0][2] + s->uvlinesize; | |
740 | } | ||
741 | 331233 | } | |
742 | |||
743 | 331233 | static int interlaced_search(MpegEncContext *s, int ref_index, | |
744 | int16_t (*mv_tables[2][2])[2], uint8_t *field_select_tables[2], int mx, int my, int user_field_select) | ||
745 | { | ||
746 | 331233 | MotionEstContext * const c= &s->me; | |
747 | 331233 | const int size=0; | |
748 | 331233 | const int h=8; | |
749 | int block; | ||
750 | int P[10][2]; | ||
751 | 331233 | const uint8_t * const mv_penalty = c->current_mv_penalty; | |
752 | 331233 | int same=1; | |
753 | 331233 | const int stride= 2*s->linesize; | |
754 | 331233 | int dmin_sum= 0; | |
755 | 331233 | const int mot_stride= s->mb_stride; | |
756 | 331233 | const int xy= s->mb_x + s->mb_y*mot_stride; | |
757 | |||
758 | 331233 | c->ymin>>=1; | |
759 | 331233 | c->ymax>>=1; | |
760 | 331233 | c->stride<<=1; | |
761 | 331233 | c->uvstride<<=1; | |
762 | 331233 | init_interlaced_ref(s, ref_index); | |
763 | |||
764 |
2/2✓ Branch 0 taken 662466 times.
✓ Branch 1 taken 331233 times.
|
993699 | for(block=0; block<2; block++){ |
765 | int field_select; | ||
766 | 662466 | int best_dmin= INT_MAX; | |
767 | 662466 | int best_field= -1; | |
768 | |||
769 |
2/2✓ Branch 0 taken 1324932 times.
✓ Branch 1 taken 662466 times.
|
1987398 | for(field_select=0; field_select<2; field_select++){ |
770 | int dmin, mx_i, my_i; | ||
771 | 1324932 | int16_t (*mv_table)[2]= mv_tables[block][field_select]; | |
772 | |||
773 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1324932 times.
|
1324932 | if(user_field_select){ |
774 | av_assert1(field_select==0 || field_select==1); | ||
775 | av_assert1(field_select_tables[block][xy]==0 || field_select_tables[block][xy]==1); | ||
776 | ✗ | if(field_select_tables[block][xy] != field_select) | |
777 | ✗ | continue; | |
778 | } | ||
779 | |||
780 | 1324932 | P_LEFT[0] = mv_table[xy - 1][0]; | |
781 | 1324932 | P_LEFT[1] = mv_table[xy - 1][1]; | |
782 |
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); |
783 | |||
784 | 1324932 | c->pred_x= P_LEFT[0]; | |
785 | 1324932 | c->pred_y= P_LEFT[1]; | |
786 | |||
787 |
2/2✓ Branch 0 taken 1206192 times.
✓ Branch 1 taken 118740 times.
|
1324932 | if(!s->first_slice_line){ |
788 | 1206192 | P_TOP[0] = mv_table[xy - mot_stride][0]; | |
789 | 1206192 | P_TOP[1] = mv_table[xy - mot_stride][1]; | |
790 | 1206192 | P_TOPRIGHT[0] = mv_table[xy - mot_stride + 1][0]; | |
791 | 1206192 | P_TOPRIGHT[1] = mv_table[xy - mot_stride + 1][1]; | |
792 |
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); |
793 |
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); |
794 |
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); |
795 |
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); |
796 | |||
797 | 1206192 | P_MEDIAN[0]= mid_pred(P_LEFT[0], P_TOP[0], P_TOPRIGHT[0]); | |
798 | 1206192 | P_MEDIAN[1]= mid_pred(P_LEFT[1], P_TOP[1], P_TOPRIGHT[1]); | |
799 | } | ||
800 | 1324932 | P_MV1[0]= mx; //FIXME not correct if block != field_select | |
801 | 1324932 | P_MV1[1]= my / 2; | |
802 | |||
803 | 1324932 | dmin = epzs_motion_search2(s, &mx_i, &my_i, P, block, field_select+ref_index, mv_table, (1<<16)>>1, 0); | |
804 | |||
805 | 1324932 | dmin= c->sub_motion_search(s, &mx_i, &my_i, dmin, block, field_select+ref_index, size, h); | |
806 | |||
807 | 1324932 | mv_table[xy][0]= mx_i; | |
808 | 1324932 | mv_table[xy][1]= my_i; | |
809 | |||
810 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1324932 times.
|
1324932 | if (c->me_sub_cmp[0] != c->mb_cmp[0]) { |
811 | int dxy; | ||
812 | |||
813 | //FIXME chroma ME | ||
814 | ✗ | const uint8_t *ref = c->ref[field_select+ref_index][0] + (mx_i>>1) + (my_i>>1)*stride; | |
815 | ✗ | dxy = ((my_i & 1) << 1) | (mx_i & 1); | |
816 | |||
817 | ✗ | c->hpel_put[size][dxy](c->scratchpad, ref, stride, h); | |
818 | ✗ | dmin = c->mb_cmp[size](s, c->src[block][0], c->scratchpad, stride, h); | |
819 | ✗ | dmin+= (mv_penalty[mx_i-c->pred_x] + mv_penalty[my_i-c->pred_y] + 1)*c->mb_penalty_factor; | |
820 | }else | ||
821 | 1324932 | dmin+= c->mb_penalty_factor; //field_select bits | |
822 | |||
823 | 1324932 | dmin += field_select != block; //slightly prefer same field | |
824 | |||
825 |
2/2✓ Branch 0 taken 994745 times.
✓ Branch 1 taken 330187 times.
|
1324932 | if(dmin < best_dmin){ |
826 | 994745 | best_dmin= dmin; | |
827 | 994745 | best_field= field_select; | |
828 | } | ||
829 | } | ||
830 | { | ||
831 | 662466 | int16_t (*mv_table)[2]= mv_tables[block][best_field]; | |
832 | |||
833 |
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 |
834 |
2/2✓ Branch 0 taken 59142 times.
✓ Branch 1 taken 603324 times.
|
662466 | if(mv_table[xy][1]&1) same=0; |
835 |
2/2✓ Branch 0 taken 444919 times.
✓ Branch 1 taken 217547 times.
|
662466 | if(mv_table[xy][1]*2 != my) same=0; |
836 |
2/2✓ Branch 0 taken 318666 times.
✓ Branch 1 taken 343800 times.
|
662466 | if(best_field != block) same=0; |
837 | } | ||
838 | |||
839 | 662466 | field_select_tables[block][xy]= best_field; | |
840 | 662466 | dmin_sum += best_dmin; | |
841 | } | ||
842 | |||
843 | 331233 | c->ymin *= 2; | |
844 | 331233 | c->ymax<<=1; | |
845 | 331233 | c->stride>>=1; | |
846 | 331233 | c->uvstride>>=1; | |
847 | |||
848 |
2/2✓ Branch 0 taken 55300 times.
✓ Branch 1 taken 275933 times.
|
331233 | if(same) |
849 | 55300 | return INT_MAX; | |
850 | |||
851 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 275933 times.
|
275933 | switch(c->avctx->mb_cmp&0xFF){ |
852 | /*case FF_CMP_SSE: | ||
853 | return dmin_sum+ 32*s->qscale*s->qscale;*/ | ||
854 | ✗ | case FF_CMP_RD: | |
855 | ✗ | return dmin_sum; | |
856 | 275933 | default: | |
857 | 275933 | return dmin_sum+ 11*c->mb_penalty_factor; | |
858 | } | ||
859 | } | ||
860 | |||
861 | 7660281 | static inline int get_penalty_factor(int lambda, int lambda2, int type){ | |
862 |
3/7✓ Branch 0 taken 7067782 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 323169 times.
✓ Branch 5 taken 269330 times.
✗ Branch 6 not taken.
|
7660281 | switch(type&0xFF){ |
863 | 7067782 | default: | |
864 | case FF_CMP_SAD: | ||
865 | 7067782 | return lambda>>FF_LAMBDA_SHIFT; | |
866 | ✗ | case FF_CMP_DCT: | |
867 | ✗ | return (3*lambda)>>(FF_LAMBDA_SHIFT+1); | |
868 | ✗ | case FF_CMP_W53: | |
869 | ✗ | return (4*lambda)>>(FF_LAMBDA_SHIFT); | |
870 | ✗ | case FF_CMP_W97: | |
871 | ✗ | return (2*lambda)>>(FF_LAMBDA_SHIFT); | |
872 | 323169 | case FF_CMP_SATD: | |
873 | case FF_CMP_DCT264: | ||
874 | 323169 | return (2*lambda)>>FF_LAMBDA_SHIFT; | |
875 | 269330 | case FF_CMP_RD: | |
876 | case FF_CMP_PSNR: | ||
877 | case FF_CMP_SSE: | ||
878 | case FF_CMP_NSSE: | ||
879 | 269330 | return lambda2>>FF_LAMBDA_SHIFT; | |
880 | ✗ | case FF_CMP_BIT: | |
881 | case FF_CMP_MEDIAN_SAD: | ||
882 | ✗ | return 1; | |
883 | } | ||
884 | } | ||
885 | |||
886 | 2145205 | void ff_estimate_p_frame_motion(MpegEncContext * s, | |
887 | int mb_x, int mb_y) | ||
888 | { | ||
889 | 2145205 | MotionEstContext * const c= &s->me; | |
890 | const uint8_t *pix, *ppix; | ||
891 | 2145205 | int sum, mx = 0, my = 0, dmin = 0; | |
892 | int varc; ///< the variance of the block (sum of squared (p[y][x]-average)) | ||
893 | int vard; ///< sum of squared differences with the estimated motion vector | ||
894 | int P[10][2]; | ||
895 | 2145205 | const int shift= 1+s->quarter_sample; | |
896 | 2145205 | int mb_type=0; | |
897 | |||
898 | 2145205 | init_ref(c, s->new_pic->data, s->last_pic.data, NULL, 16*mb_x, 16*mb_y, 0); | |
899 | |||
900 |
3/4✓ Branch 0 taken 15570 times.
✓ Branch 1 taken 2129635 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 15570 times.
|
2145205 | av_assert0(s->quarter_sample==0 || s->quarter_sample==1); |
901 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2145205 times.
|
2145205 | av_assert0(s->linesize == c->stride); |
902 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2145205 times.
|
2145205 | av_assert0(s->uvlinesize == c->uvstride); |
903 | |||
904 | 2145205 | c->penalty_factor = get_penalty_factor(s->lambda, s->lambda2, c->avctx->me_cmp); | |
905 | 2145205 | c->sub_penalty_factor= get_penalty_factor(s->lambda, s->lambda2, c->avctx->me_sub_cmp); | |
906 | 2145205 | c->mb_penalty_factor = get_penalty_factor(s->lambda, s->lambda2, c->avctx->mb_cmp); | |
907 | 2145205 | c->current_mv_penalty= c->mv_penalty[s->f_code] + MAX_DMV; | |
908 | |||
909 | 2145205 | get_limits(s, 16*mb_x, 16*mb_y, 0); | |
910 | 2145205 | c->skip=0; | |
911 | |||
912 | /* intra / predictive decision */ | ||
913 | 2145205 | pix = c->src[0][0]; | |
914 | 2145205 | sum = s->mpvencdsp.pix_sum(pix, s->linesize); | |
915 | 2145205 | varc = s->mpvencdsp.pix_norm1(pix, s->linesize) - | |
916 | 2145205 | (((unsigned) sum * sum) >> 8) + 500; | |
917 | |||
918 | 2145205 | s->mb_mean[s->mb_stride * mb_y + mb_x] = (sum+128)>>8; | |
919 | 2145205 | s->mb_var [s->mb_stride * mb_y + mb_x] = (varc+128)>>8; | |
920 | 2145205 | c->mb_var_sum_temp += (varc+128)>>8; | |
921 | |||
922 |
1/2✓ Branch 0 taken 2145205 times.
✗ Branch 1 not taken.
|
2145205 | if (s->motion_est != FF_ME_ZERO) { |
923 | 2145205 | const int mot_stride = s->b8_stride; | |
924 | 2145205 | const int mot_xy = s->block_index[0]; | |
925 | |||
926 | 2145205 | P_LEFT[0] = s->cur_pic.motion_val[0][mot_xy - 1][0]; | |
927 | 2145205 | P_LEFT[1] = s->cur_pic.motion_val[0][mot_xy - 1][1]; | |
928 | |||
929 |
2/2✓ Branch 0 taken 21293 times.
✓ Branch 1 taken 2123912 times.
|
2145205 | if (P_LEFT[0] > (c->xmax << shift)) |
930 | 21293 | P_LEFT[0] = c->xmax << shift; | |
931 | |||
932 |
2/2✓ Branch 0 taken 1982783 times.
✓ Branch 1 taken 162422 times.
|
2145205 | if (!s->first_slice_line) { |
933 | 1982783 | P_TOP[0] = s->cur_pic.motion_val[0][mot_xy - mot_stride ][0]; | |
934 | 1982783 | P_TOP[1] = s->cur_pic.motion_val[0][mot_xy - mot_stride ][1]; | |
935 | 1982783 | P_TOPRIGHT[0] = s->cur_pic.motion_val[0][mot_xy - mot_stride + 2][0]; | |
936 | 1982783 | P_TOPRIGHT[1] = s->cur_pic.motion_val[0][mot_xy - mot_stride + 2][1]; | |
937 |
2/2✓ Branch 0 taken 23770 times.
✓ Branch 1 taken 1959013 times.
|
1982783 | if (P_TOP[1] > (c->ymax << shift)) |
938 | 23770 | P_TOP[1] = c->ymax << shift; | |
939 |
2/2✓ Branch 0 taken 22739 times.
✓ Branch 1 taken 1960044 times.
|
1982783 | if (P_TOPRIGHT[0] < (c->xmin * (1 << shift))) |
940 | 22739 | P_TOPRIGHT[0] = c->xmin * (1 << shift); | |
941 |
2/2✓ Branch 0 taken 21952 times.
✓ Branch 1 taken 1960831 times.
|
1982783 | if (P_TOPRIGHT[1] > (c->ymax * (1 << shift))) |
942 | 21952 | P_TOPRIGHT[1] = c->ymax * (1 << shift); | |
943 | |||
944 | 1982783 | P_MEDIAN[0] = mid_pred(P_LEFT[0], P_TOP[0], P_TOPRIGHT[0]); | |
945 | 1982783 | P_MEDIAN[1] = mid_pred(P_LEFT[1], P_TOP[1], P_TOPRIGHT[1]); | |
946 | |||
947 |
2/2✓ Branch 0 taken 1137325 times.
✓ Branch 1 taken 845458 times.
|
1982783 | if (s->out_format == FMT_H263) { |
948 | 1137325 | c->pred_x = P_MEDIAN[0]; | |
949 | 1137325 | c->pred_y = P_MEDIAN[1]; | |
950 | } else { /* MPEG-1 at least */ | ||
951 | 845458 | c->pred_x = P_LEFT[0]; | |
952 | 845458 | c->pred_y = P_LEFT[1]; | |
953 | } | ||
954 | } else { | ||
955 | 162422 | c->pred_x = P_LEFT[0]; | |
956 | 162422 | c->pred_y = P_LEFT[1]; | |
957 | } | ||
958 | 2145205 | dmin = ff_epzs_motion_search(s, &mx, &my, P, 0, 0, s->p_mv_table, (1<<16)>>shift, 0, 16); | |
959 | } | ||
960 | |||
961 | /* At this point (mx,my) are full-pell and the relative displacement */ | ||
962 | 2145205 | ppix = c->ref[0][0] + (my * s->linesize) + mx; | |
963 | |||
964 | 2145205 | vard = c->sse(NULL, pix, ppix, s->linesize, 16); | |
965 | |||
966 | 2145205 | s->mc_mb_var[s->mb_stride * mb_y + mb_x] = (vard+128)>>8; | |
967 | 2145205 | c->mc_mb_var_sum_temp += (vard+128)>>8; | |
968 | |||
969 |
2/2✓ Branch 0 taken 362361 times.
✓ Branch 1 taken 1782844 times.
|
2145205 | if (c->avctx->mb_decision > FF_MB_DECISION_SIMPLE) { |
970 | 362361 | int p_score= FFMIN(vard, varc-500+(s->lambda2>>FF_LAMBDA_SHIFT)*100); | |
971 | 362361 | int i_score= varc-500+(s->lambda2>>FF_LAMBDA_SHIFT)*20; | |
972 | 362361 | c->scene_change_score+= ff_sqrt(p_score) - ff_sqrt(i_score); | |
973 | |||
974 |
3/4✓ Branch 0 taken 97636 times.
✓ Branch 1 taken 264725 times.
✓ Branch 2 taken 97636 times.
✗ Branch 3 not taken.
|
362361 | if (vard*2 + 200*256 > varc && !s->intra_penalty) |
975 | 97636 | mb_type|= CANDIDATE_MB_TYPE_INTRA; | |
976 |
3/4✓ Branch 0 taken 2078 times.
✓ Branch 1 taken 360283 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2078 times.
|
362361 | if (varc*2 + 200*256 > vard || s->qscale > 24){ |
977 | // if (varc*2 + 200*256 + 50*(s->lambda2>>FF_LAMBDA_SHIFT) > vard){ | ||
978 | 360283 | mb_type|= CANDIDATE_MB_TYPE_INTER; | |
979 | 360283 | c->sub_motion_search(s, &mx, &my, dmin, 0, 0, 0, 16); | |
980 |
2/2✓ Branch 0 taken 61162 times.
✓ Branch 1 taken 299121 times.
|
360283 | if (s->mpv_flags & FF_MPV_FLAG_MV0) |
981 |
4/4✓ Branch 0 taken 4046 times.
✓ Branch 1 taken 57116 times.
✓ Branch 2 taken 3521 times.
✓ Branch 3 taken 525 times.
|
61162 | if(mx || my) |
982 | 60637 | mb_type |= CANDIDATE_MB_TYPE_SKIPPED; //FIXME check difference | |
983 | }else{ | ||
984 | 2078 | mx *= 1 << shift; | |
985 | 2078 | my *= 1 << shift; | |
986 | } | ||
987 |
2/2✓ Branch 0 taken 277722 times.
✓ Branch 1 taken 84639 times.
|
362361 | if ((s->avctx->flags & AV_CODEC_FLAG_4MV) |
988 |
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 251764 times.
✓ Branch 5 taken 9164 times.
|
277722 | && !c->skip && varc>50<<8 && vard>10<<8){ |
989 |
2/2✓ Branch 1 taken 210055 times.
✓ Branch 2 taken 41709 times.
|
251764 | if(h263_mv4_search(s, mx, my, shift) < INT_MAX) |
990 | 210055 | mb_type|=CANDIDATE_MB_TYPE_INTER4V; | |
991 | |||
992 | 251764 | set_p_mv_tables(s, mx, my, 0); | |
993 | }else | ||
994 | 110597 | set_p_mv_tables(s, mx, my, 1); | |
995 |
2/2✓ Branch 0 taken 15600 times.
✓ Branch 1 taken 346761 times.
|
362361 | if ((s->avctx->flags & AV_CODEC_FLAG_INTERLACED_ME) |
996 |
1/2✓ Branch 0 taken 15600 times.
✗ Branch 1 not taken.
|
15600 | && !c->skip){ //FIXME varc/d checks |
997 |
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) |
998 | 13535 | mb_type |= CANDIDATE_MB_TYPE_INTER_I; | |
999 | } | ||
1000 | }else{ | ||
1001 | int intra_score, i; | ||
1002 | 1782844 | mb_type= CANDIDATE_MB_TYPE_INTER; | |
1003 | |||
1004 | 1782844 | dmin= c->sub_motion_search(s, &mx, &my, dmin, 0, 0, 0, 16); | |
1005 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 1782844 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
1782844 | if(c->avctx->me_sub_cmp != c->avctx->mb_cmp && !c->skip) |
1006 | ✗ | dmin= get_mb_score(s, mx, my, 0, 0, 0, 16, 1); | |
1007 | |||
1008 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1782844 times.
|
1782844 | if ((s->avctx->flags & AV_CODEC_FLAG_4MV) |
1009 | ✗ | && !c->skip && varc>50<<8 && vard>10<<8){ | |
1010 | ✗ | int dmin4= h263_mv4_search(s, mx, my, shift); | |
1011 | ✗ | if(dmin4 < dmin){ | |
1012 | ✗ | mb_type= CANDIDATE_MB_TYPE_INTER4V; | |
1013 | ✗ | dmin=dmin4; | |
1014 | } | ||
1015 | } | ||
1016 |
2/2✓ Branch 0 taken 85236 times.
✓ Branch 1 taken 1697608 times.
|
1782844 | if ((s->avctx->flags & AV_CODEC_FLAG_INTERLACED_ME) |
1017 |
2/2✓ Branch 0 taken 85233 times.
✓ Branch 1 taken 3 times.
|
85236 | && !c->skip){ //FIXME varc/d checks |
1018 | 85233 | int dmin_i= interlaced_search(s, 0, s->p_field_mv_table, s->p_field_select_table, mx, my, 0); | |
1019 |
2/2✓ Branch 0 taken 11208 times.
✓ Branch 1 taken 74025 times.
|
85233 | if(dmin_i < dmin){ |
1020 | 11208 | mb_type = CANDIDATE_MB_TYPE_INTER_I; | |
1021 | 11208 | dmin= dmin_i; | |
1022 | } | ||
1023 | } | ||
1024 | |||
1025 | 1782844 | set_p_mv_tables(s, mx, my, mb_type!=CANDIDATE_MB_TYPE_INTER4V); | |
1026 | |||
1027 | /* get intra luma score */ | ||
1028 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1782844 times.
|
1782844 | if((c->avctx->mb_cmp&0xFF)==FF_CMP_SSE){ |
1029 | ✗ | intra_score= varc - 500; | |
1030 | }else{ | ||
1031 | 1782844 | unsigned mean = (sum+128)>>8; | |
1032 | 1782844 | mean*= 0x01010101; | |
1033 | |||
1034 |
2/2✓ Branch 0 taken 28525504 times.
✓ Branch 1 taken 1782844 times.
|
30308348 | for(i=0; i<16; i++){ |
1035 | 28525504 | *(uint32_t*)(&c->scratchpad[i*s->linesize+ 0]) = mean; | |
1036 | 28525504 | *(uint32_t*)(&c->scratchpad[i*s->linesize+ 4]) = mean; | |
1037 | 28525504 | *(uint32_t*)(&c->scratchpad[i*s->linesize+ 8]) = mean; | |
1038 | 28525504 | *(uint32_t*)(&c->scratchpad[i*s->linesize+12]) = mean; | |
1039 | } | ||
1040 | |||
1041 | 1782844 | intra_score= c->mb_cmp[0](s, c->scratchpad, pix, s->linesize, 16); | |
1042 | } | ||
1043 | 1782844 | intra_score += c->mb_penalty_factor*16 + s->intra_penalty; | |
1044 | |||
1045 |
2/2✓ Branch 0 taken 95473 times.
✓ Branch 1 taken 1687371 times.
|
1782844 | if(intra_score < dmin){ |
1046 | 95473 | mb_type= CANDIDATE_MB_TYPE_INTRA; | |
1047 | 95473 | s->cur_pic.mb_type[mb_y*s->mb_stride + mb_x] = CANDIDATE_MB_TYPE_INTRA; //FIXME cleanup | |
1048 | }else | ||
1049 | 1687371 | s->cur_pic.mb_type[mb_y*s->mb_stride + mb_x] = 0; | |
1050 | |||
1051 | { | ||
1052 | 1782844 | int p_score= FFMIN(vard, varc-500+(s->lambda2>>FF_LAMBDA_SHIFT)*100); | |
1053 | 1782844 | int i_score= varc-500+(s->lambda2>>FF_LAMBDA_SHIFT)*20; | |
1054 | 1782844 | c->scene_change_score+= ff_sqrt(p_score) - ff_sqrt(i_score); | |
1055 | } | ||
1056 | } | ||
1057 | |||
1058 | 2145205 | s->mb_type[mb_y*s->mb_stride + mb_x]= mb_type; | |
1059 | 2145205 | } | |
1060 | |||
1061 | ✗ | int ff_pre_estimate_p_frame_motion(MpegEncContext * s, | |
1062 | int mb_x, int mb_y) | ||
1063 | { | ||
1064 | ✗ | MotionEstContext * const c= &s->me; | |
1065 | int mx, my, dmin; | ||
1066 | int P[10][2]; | ||
1067 | ✗ | const int shift= 1+s->quarter_sample; | |
1068 | ✗ | const int xy= mb_x + mb_y*s->mb_stride; | |
1069 | ✗ | init_ref(c, s->new_pic->data, s->last_pic.data, NULL, 16*mb_x, 16*mb_y, 0); | |
1070 | |||
1071 | ✗ | av_assert0(s->quarter_sample==0 || s->quarter_sample==1); | |
1072 | |||
1073 | ✗ | c->pre_penalty_factor = get_penalty_factor(s->lambda, s->lambda2, c->avctx->me_pre_cmp); | |
1074 | ✗ | c->current_mv_penalty= c->mv_penalty[s->f_code] + MAX_DMV; | |
1075 | |||
1076 | ✗ | get_limits(s, 16*mb_x, 16*mb_y, 0); | |
1077 | ✗ | c->skip=0; | |
1078 | |||
1079 | ✗ | P_LEFT[0] = s->p_mv_table[xy + 1][0]; | |
1080 | ✗ | P_LEFT[1] = s->p_mv_table[xy + 1][1]; | |
1081 | |||
1082 | ✗ | if(P_LEFT[0] < (c->xmin<<shift)) P_LEFT[0] = (c->xmin<<shift); | |
1083 | |||
1084 | /* special case for first line */ | ||
1085 | ✗ | if (s->first_slice_line) { | |
1086 | ✗ | c->pred_x= P_LEFT[0]; | |
1087 | ✗ | c->pred_y= P_LEFT[1]; | |
1088 | ✗ | P_TOP[0]= P_TOPRIGHT[0]= P_MEDIAN[0]= | |
1089 | ✗ | P_TOP[1]= P_TOPRIGHT[1]= P_MEDIAN[1]= 0; //FIXME | |
1090 | } else { | ||
1091 | ✗ | P_TOP[0] = s->p_mv_table[xy + s->mb_stride ][0]; | |
1092 | ✗ | P_TOP[1] = s->p_mv_table[xy + s->mb_stride ][1]; | |
1093 | ✗ | P_TOPRIGHT[0] = s->p_mv_table[xy + s->mb_stride - 1][0]; | |
1094 | ✗ | P_TOPRIGHT[1] = s->p_mv_table[xy + s->mb_stride - 1][1]; | |
1095 | ✗ | if(P_TOP[1] < (c->ymin<<shift)) P_TOP[1] = (c->ymin<<shift); | |
1096 | ✗ | if(P_TOPRIGHT[0] > (c->xmax<<shift)) P_TOPRIGHT[0]= (c->xmax<<shift); | |
1097 | ✗ | if(P_TOPRIGHT[1] < (c->ymin<<shift)) P_TOPRIGHT[1]= (c->ymin<<shift); | |
1098 | |||
1099 | ✗ | P_MEDIAN[0]= mid_pred(P_LEFT[0], P_TOP[0], P_TOPRIGHT[0]); | |
1100 | ✗ | P_MEDIAN[1]= mid_pred(P_LEFT[1], P_TOP[1], P_TOPRIGHT[1]); | |
1101 | |||
1102 | ✗ | c->pred_x = P_MEDIAN[0]; | |
1103 | ✗ | c->pred_y = P_MEDIAN[1]; | |
1104 | } | ||
1105 | |||
1106 | ✗ | dmin = ff_epzs_motion_search(s, &mx, &my, P, 0, 0, s->p_mv_table, (1<<16)>>shift, 0, 16); | |
1107 | |||
1108 | ✗ | s->p_mv_table[xy][0] = mx<<shift; | |
1109 | ✗ | s->p_mv_table[xy][1] = my<<shift; | |
1110 | |||
1111 | ✗ | return dmin; | |
1112 | } | ||
1113 | |||
1114 | 816444 | static int estimate_motion_b(MpegEncContext *s, int mb_x, int mb_y, | |
1115 | int16_t (*mv_table)[2], int ref_index, int f_code) | ||
1116 | { | ||
1117 | 816444 | MotionEstContext * const c= &s->me; | |
1118 | 816444 | int mx = 0, my = 0, dmin = 0; | |
1119 | int P[10][2]; | ||
1120 | 816444 | const int shift= 1+s->quarter_sample; | |
1121 | 816444 | const int mot_stride = s->mb_stride; | |
1122 | 816444 | const int mot_xy = mb_y*mot_stride + mb_x; | |
1123 | 816444 | const uint8_t * const mv_penalty = c->mv_penalty[f_code] + MAX_DMV; | |
1124 | int mv_scale; | ||
1125 | |||
1126 | 816444 | c->current_mv_penalty= mv_penalty; | |
1127 | |||
1128 | 816444 | get_limits(s, 16*mb_x, 16*mb_y, 1); | |
1129 | |||
1130 |
1/2✓ Branch 0 taken 816444 times.
✗ Branch 1 not taken.
|
816444 | if (s->motion_est != FF_ME_ZERO) { |
1131 | 816444 | P_LEFT[0] = mv_table[mot_xy - 1][0]; | |
1132 | 816444 | P_LEFT[1] = mv_table[mot_xy - 1][1]; | |
1133 | |||
1134 |
2/2✓ Branch 0 taken 10171 times.
✓ Branch 1 taken 806273 times.
|
816444 | if (P_LEFT[0] > (c->xmax << shift)) P_LEFT[0] = (c->xmax << shift); |
1135 | |||
1136 | /* special case for first line */ | ||
1137 |
2/2✓ Branch 0 taken 756252 times.
✓ Branch 1 taken 60192 times.
|
816444 | if (!s->first_slice_line) { |
1138 | 756252 | P_TOP[0] = mv_table[mot_xy - mot_stride ][0]; | |
1139 | 756252 | P_TOP[1] = mv_table[mot_xy - mot_stride ][1]; | |
1140 | 756252 | P_TOPRIGHT[0] = mv_table[mot_xy - mot_stride + 1][0]; | |
1141 | 756252 | P_TOPRIGHT[1] = mv_table[mot_xy - mot_stride + 1][1]; | |
1142 |
2/2✓ Branch 0 taken 11692 times.
✓ Branch 1 taken 744560 times.
|
756252 | if (P_TOP[1] > (c->ymax << shift)) P_TOP[1] = (c->ymax << shift); |
1143 |
2/2✓ Branch 0 taken 8202 times.
✓ Branch 1 taken 748050 times.
|
756252 | if (P_TOPRIGHT[0] < c->xmin * (1 << shift)) P_TOPRIGHT[0] = c->xmin * (1 << shift); |
1144 |
2/2✓ Branch 0 taken 11033 times.
✓ Branch 1 taken 745219 times.
|
756252 | if (P_TOPRIGHT[1] > (c->ymax << shift)) P_TOPRIGHT[1] = (c->ymax << shift); |
1145 | |||
1146 | 756252 | P_MEDIAN[0] = mid_pred(P_LEFT[0], P_TOP[0], P_TOPRIGHT[0]); | |
1147 | 756252 | P_MEDIAN[1] = mid_pred(P_LEFT[1], P_TOP[1], P_TOPRIGHT[1]); | |
1148 | } | ||
1149 | 816444 | c->pred_x = P_LEFT[0]; | |
1150 | 816444 | c->pred_y = P_LEFT[1]; | |
1151 | |||
1152 |
2/2✓ Branch 0 taken 408222 times.
✓ Branch 1 taken 408222 times.
|
816444 | if(mv_table == s->b_forw_mv_table){ |
1153 | 408222 | mv_scale= (s->pb_time<<16) / (s->pp_time<<shift); | |
1154 | }else{ | ||
1155 | 408222 | mv_scale = ((s->pb_time - s->pp_time) * (1 << 16)) / (s->pp_time<<shift); | |
1156 | } | ||
1157 | |||
1158 | 816444 | dmin = ff_epzs_motion_search(s, &mx, &my, P, 0, ref_index, s->p_mv_table, mv_scale, 0, 16); | |
1159 | } | ||
1160 | |||
1161 | 816444 | dmin= c->sub_motion_search(s, &mx, &my, dmin, 0, ref_index, 0, 16); | |
1162 | |||
1163 |
3/4✓ Branch 0 taken 306344 times.
✓ Branch 1 taken 510100 times.
✓ Branch 2 taken 306344 times.
✗ Branch 3 not taken.
|
816444 | if(c->avctx->me_sub_cmp != c->avctx->mb_cmp && !c->skip) |
1164 | 306344 | dmin= get_mb_score(s, mx, my, 0, ref_index, 0, 16, 1); | |
1165 | |||
1166 | // s->mb_type[mb_y*s->mb_width + mb_x]= mb_type; | ||
1167 | 816444 | mv_table[mot_xy][0]= mx; | |
1168 | 816444 | mv_table[mot_xy][1]= my; | |
1169 | |||
1170 | 816444 | return dmin; | |
1171 | } | ||
1172 | |||
1173 | 5438052 | static inline int check_bidir_mv(MpegEncContext * s, | |
1174 | int motion_fx, int motion_fy, | ||
1175 | int motion_bx, int motion_by, | ||
1176 | int pred_fx, int pred_fy, | ||
1177 | int pred_bx, int pred_by, | ||
1178 | int size, int h) | ||
1179 | { | ||
1180 | //FIXME optimize? | ||
1181 | //FIXME better f_code prediction (max mv & distance) | ||
1182 | //FIXME pointers | ||
1183 | 5438052 | MotionEstContext * const c= &s->me; | |
1184 | 5438052 | const uint8_t * const mv_penalty_f = c->mv_penalty[s->f_code] + MAX_DMV; // f_code of the prev frame | |
1185 | 5438052 | const uint8_t * const mv_penalty_b = c->mv_penalty[s->b_code] + MAX_DMV; // f_code of the prev frame | |
1186 | 5438052 | int stride= c->stride; | |
1187 | 5438052 | uint8_t *dest_y = c->scratchpad; | |
1188 | const uint8_t *ptr; | ||
1189 | int dxy; | ||
1190 | int src_x, src_y; | ||
1191 | int fbmin; | ||
1192 | 5438052 | const uint8_t *const *src_data = c->src[0]; | |
1193 | 5438052 | const uint8_t *const *ref_data = c->ref[0]; | |
1194 | 5438052 | const uint8_t *const *ref2_data = c->ref[2]; | |
1195 | |||
1196 |
2/2✓ Branch 0 taken 625749 times.
✓ Branch 1 taken 4812303 times.
|
5438052 | if(s->quarter_sample){ |
1197 | 625749 | dxy = ((motion_fy & 3) << 2) | (motion_fx & 3); | |
1198 | 625749 | src_x = motion_fx >> 2; | |
1199 | 625749 | src_y = motion_fy >> 2; | |
1200 | |||
1201 | 625749 | ptr = ref_data[0] + (src_y * stride) + src_x; | |
1202 | 625749 | s->qdsp.put_qpel_pixels_tab[0][dxy](dest_y, ptr, stride); | |
1203 | |||
1204 | 625749 | dxy = ((motion_by & 3) << 2) | (motion_bx & 3); | |
1205 | 625749 | src_x = motion_bx >> 2; | |
1206 | 625749 | src_y = motion_by >> 2; | |
1207 | |||
1208 | 625749 | ptr = ref2_data[0] + (src_y * stride) + src_x; | |
1209 | 625749 | s->qdsp.avg_qpel_pixels_tab[size][dxy](dest_y, ptr, stride); | |
1210 | }else{ | ||
1211 | 4812303 | dxy = ((motion_fy & 1) << 1) | (motion_fx & 1); | |
1212 | 4812303 | src_x = motion_fx >> 1; | |
1213 | 4812303 | src_y = motion_fy >> 1; | |
1214 | |||
1215 | 4812303 | ptr = ref_data[0] + (src_y * stride) + src_x; | |
1216 | 4812303 | s->hdsp.put_pixels_tab[size][dxy](dest_y , ptr , stride, h); | |
1217 | |||
1218 | 4812303 | dxy = ((motion_by & 1) << 1) | (motion_bx & 1); | |
1219 | 4812303 | src_x = motion_bx >> 1; | |
1220 | 4812303 | src_y = motion_by >> 1; | |
1221 | |||
1222 | 4812303 | ptr = ref2_data[0] + (src_y * stride) + src_x; | |
1223 | 4812303 | s->hdsp.avg_pixels_tab[size][dxy](dest_y , ptr , stride, h); | |
1224 | } | ||
1225 | |||
1226 | 10876104 | fbmin = (mv_penalty_f[motion_fx-pred_fx] + mv_penalty_f[motion_fy-pred_fy])*c->mb_penalty_factor | |
1227 | 5438052 | +(mv_penalty_b[motion_bx-pred_bx] + mv_penalty_b[motion_by-pred_by])*c->mb_penalty_factor | |
1228 | 5438052 | + c->mb_cmp[size](s, src_data[0], dest_y, stride, h); // FIXME new_pic | |
1229 | |||
1230 | 5438052 | if(c->avctx->mb_cmp&FF_CMP_CHROMA){ | |
1231 | } | ||
1232 | //FIXME CHROMA !!! | ||
1233 | |||
1234 | 5438052 | return fbmin; | |
1235 | } | ||
1236 | |||
1237 | /* refine the bidir vectors in hq mode and return the score in both lq & hq mode*/ | ||
1238 | 408222 | static inline int bidir_refine(MpegEncContext * s, int mb_x, int mb_y) | |
1239 | { | ||
1240 | 408222 | MotionEstContext * const c= &s->me; | |
1241 | 408222 | const int mot_stride = s->mb_stride; | |
1242 | 408222 | const int xy = mb_y *mot_stride + mb_x; | |
1243 | int fbmin; | ||
1244 | 408222 | int pred_fx= s->b_bidir_forw_mv_table[xy-1][0]; | |
1245 | 408222 | int pred_fy= s->b_bidir_forw_mv_table[xy-1][1]; | |
1246 | 408222 | int pred_bx= s->b_bidir_back_mv_table[xy-1][0]; | |
1247 | 408222 | int pred_by= s->b_bidir_back_mv_table[xy-1][1]; | |
1248 | 408222 | int motion_fx= s->b_bidir_forw_mv_table[xy][0]= s->b_forw_mv_table[xy][0]; | |
1249 | 408222 | int motion_fy= s->b_bidir_forw_mv_table[xy][1]= s->b_forw_mv_table[xy][1]; | |
1250 | 408222 | int motion_bx= s->b_bidir_back_mv_table[xy][0]= s->b_back_mv_table[xy][0]; | |
1251 | 408222 | int motion_by= s->b_bidir_back_mv_table[xy][1]= s->b_back_mv_table[xy][1]; | |
1252 | 408222 | const int flags= c->sub_flags; | |
1253 | 408222 | const int qpel= flags&FLAG_QPEL; | |
1254 | 408222 | const int shift= 1+qpel; | |
1255 | 408222 | const int xmin= c->xmin * (1 << shift); | |
1256 | 408222 | const int ymin= c->ymin * (1 << shift); | |
1257 | 408222 | const int xmax= c->xmax<<shift; | |
1258 | 408222 | const int ymax= c->ymax<<shift; | |
1259 | #define HASH(fx,fy,bx,by) ((fx)+17*(fy)+63*(bx)+117*(by)) | ||
1260 | #define HASH8(fx,fy,bx,by) ((uint8_t)HASH(fx,fy,bx,by)) | ||
1261 | 408222 | int hashidx= HASH(motion_fx,motion_fy, motion_bx, motion_by); | |
1262 | 408222 | uint8_t map[256] = { 0 }; | |
1263 | |||
1264 | 408222 | map[hashidx&255] = 1; | |
1265 | |||
1266 | 408222 | fbmin= check_bidir_mv(s, motion_fx, motion_fy, | |
1267 | motion_bx, motion_by, | ||
1268 | pred_fx, pred_fy, | ||
1269 | pred_bx, pred_by, | ||
1270 | 0, 16); | ||
1271 | |||
1272 |
1/2✓ Branch 0 taken 408222 times.
✗ Branch 1 not taken.
|
408222 | if(s->avctx->bidir_refine){ |
1273 | int end; | ||
1274 | static const uint8_t limittab[5]={0,8,32,64,80}; | ||
1275 | 408222 | const int limit= limittab[s->avctx->bidir_refine]; | |
1276 | static const int8_t vect[][4]={ | ||
1277 | { 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}, | ||
1278 | |||
1279 | { 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}, | ||
1280 | { 0, 1, 0, 1}, { 0,-1, 0,-1}, { 1, 0, 1, 0}, {-1, 0,-1, 0}, | ||
1281 | { 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}, | ||
1282 | { 0,-1, 0, 1}, { 0, 1, 0,-1}, {-1, 0, 1, 0}, { 1, 0,-1, 0}, | ||
1283 | |||
1284 | { 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}, | ||
1285 | { 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}, | ||
1286 | { 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}, | ||
1287 | { 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}, | ||
1288 | |||
1289 | { 1, 1, 1, 1}, {-1,-1,-1,-1}, | ||
1290 | { 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}, | ||
1291 | { 1, 1,-1,-1}, {-1,-1, 1, 1}, { 1,-1,-1, 1}, {-1, 1, 1,-1}, { 1,-1, 1,-1}, {-1, 1,-1, 1}, | ||
1292 | }; | ||
1293 | static const uint8_t hash[]={ | ||
1294 | 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), | ||
1295 | |||
1296 | 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), | ||
1297 | HASH8( 0, 1, 0, 1), HASH8( 0,-1, 0,-1), HASH8( 1, 0, 1, 0), HASH8(-1, 0,-1, 0), | ||
1298 | 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), | ||
1299 | HASH8( 0,-1, 0, 1), HASH8( 0, 1, 0,-1), HASH8(-1, 0, 1, 0), HASH8( 1, 0,-1, 0), | ||
1300 | |||
1301 | 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), | ||
1302 | 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), | ||
1303 | 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), | ||
1304 | 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), | ||
1305 | |||
1306 | HASH8( 1, 1, 1, 1), HASH8(-1,-1,-1,-1), | ||
1307 | 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), | ||
1308 | 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), | ||
1309 | }; | ||
1310 | |||
1311 | #define CHECK_BIDIR(fx,fy,bx,by)\ | ||
1312 | if( !map[(hashidx+HASH(fx,fy,bx,by))&255]\ | ||
1313 | &&(fx<=0 || motion_fx+fx<=xmax) && (fy<=0 || motion_fy+fy<=ymax) && (bx<=0 || motion_bx+bx<=xmax) && (by<=0 || motion_by+by<=ymax)\ | ||
1314 | &&(fx>=0 || motion_fx+fx>=xmin) && (fy>=0 || motion_fy+fy>=ymin) && (bx>=0 || motion_bx+bx>=xmin) && (by>=0 || motion_by+by>=ymin)){\ | ||
1315 | int score;\ | ||
1316 | map[(hashidx+HASH(fx,fy,bx,by))&255] = 1;\ | ||
1317 | 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);\ | ||
1318 | if(score < fbmin){\ | ||
1319 | hashidx += HASH(fx,fy,bx,by);\ | ||
1320 | fbmin= score;\ | ||
1321 | motion_fx+=fx;\ | ||
1322 | motion_fy+=fy;\ | ||
1323 | motion_bx+=bx;\ | ||
1324 | motion_by+=by;\ | ||
1325 | end=0;\ | ||
1326 | }\ | ||
1327 | } | ||
1328 | #define CHECK_BIDIR2(a,b,c,d)\ | ||
1329 | CHECK_BIDIR(a,b,c,d)\ | ||
1330 | CHECK_BIDIR(-(a),-(b),-(c),-(d)) | ||
1331 | |||
1332 | do{ | ||
1333 | int i; | ||
1334 | 827717 | int borderdist=0; | |
1335 | 827717 | end=1; | |
1336 | |||
1337 |
12/12✓ Branch 0 taken 774970 times.
✓ Branch 1 taken 52747 times.
✓ Branch 2 taken 762716 times.
✓ Branch 3 taken 12254 times.
✓ Branch 5 taken 95040 times.
✓ Branch 6 taken 667676 times.
✓ Branch 7 taken 696061 times.
✓ Branch 8 taken 131656 times.
✓ Branch 9 taken 683635 times.
✓ Branch 10 taken 12426 times.
✓ Branch 12 taken 113388 times.
✓ Branch 13 taken 570247 times.
|
827717 | CHECK_BIDIR2(0,0,0,1) |
1338 |
12/12✓ Branch 0 taken 711361 times.
✓ Branch 1 taken 116356 times.
✓ Branch 2 taken 700401 times.
✓ Branch 3 taken 10960 times.
✓ Branch 5 taken 101115 times.
✓ Branch 6 taken 599286 times.
✓ Branch 7 taken 613905 times.
✓ Branch 8 taken 213812 times.
✓ Branch 9 taken 604097 times.
✓ Branch 10 taken 9808 times.
✓ Branch 12 taken 83230 times.
✓ Branch 13 taken 520867 times.
|
827717 | CHECK_BIDIR2(0,0,1,0) |
1339 |
12/12✓ Branch 0 taken 657915 times.
✓ Branch 1 taken 169802 times.
✓ Branch 2 taken 641000 times.
✓ Branch 3 taken 16915 times.
✓ Branch 5 taken 92357 times.
✓ Branch 6 taken 548643 times.
✓ Branch 7 taken 558073 times.
✓ Branch 8 taken 269644 times.
✓ Branch 9 taken 540958 times.
✓ Branch 10 taken 17115 times.
✓ Branch 12 taken 60209 times.
✓ Branch 13 taken 480749 times.
|
827717 | CHECK_BIDIR2(0,1,0,0) |
1340 |
12/12✓ Branch 0 taken 590036 times.
✓ Branch 1 taken 237681 times.
✓ Branch 2 taken 574421 times.
✓ Branch 3 taken 15615 times.
✓ Branch 5 taken 66178 times.
✓ Branch 6 taken 508243 times.
✓ Branch 7 taken 538563 times.
✓ Branch 8 taken 289154 times.
✓ Branch 9 taken 522602 times.
✓ Branch 10 taken 15961 times.
✓ Branch 12 taken 72902 times.
✓ Branch 13 taken 449700 times.
|
827717 | CHECK_BIDIR2(1,0,0,0) |
1341 | |||
1342 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 827717 times.
|
827717 | for(i=8; i<limit; i++){ |
1343 | ✗ | int fx= motion_fx+vect[i][0]; | |
1344 | ✗ | int fy= motion_fy+vect[i][1]; | |
1345 | ✗ | int bx= motion_bx+vect[i][2]; | |
1346 | ✗ | int by= motion_by+vect[i][3]; | |
1347 | ✗ | if(borderdist<=0){ | |
1348 | ✗ | int a= (xmax - FFMAX(fx,bx))|(FFMIN(fx,bx) - xmin); | |
1349 | ✗ | int b= (ymax - FFMAX(fy,by))|(FFMIN(fy,by) - ymin); | |
1350 | ✗ | if((a|b) < 0) | |
1351 | ✗ | map[(hashidx+hash[i])&255] = 1; | |
1352 | } | ||
1353 | ✗ | if(!map[(hashidx+hash[i])&255]){ | |
1354 | int score; | ||
1355 | ✗ | map[(hashidx+hash[i])&255] = 1; | |
1356 | ✗ | score= check_bidir_mv(s, fx, fy, bx, by, pred_fx, pred_fy, pred_bx, pred_by, 0, 16); | |
1357 | ✗ | if(score < fbmin){ | |
1358 | ✗ | hashidx += hash[i]; | |
1359 | ✗ | fbmin= score; | |
1360 | ✗ | motion_fx=fx; | |
1361 | ✗ | motion_fy=fy; | |
1362 | ✗ | motion_bx=bx; | |
1363 | ✗ | motion_by=by; | |
1364 | ✗ | end=0; | |
1365 | ✗ | borderdist--; | |
1366 | ✗ | if(borderdist<=0){ | |
1367 | ✗ | int a= FFMIN(xmax - FFMAX(fx,bx), FFMIN(fx,bx) - xmin); | |
1368 | ✗ | int b= FFMIN(ymax - FFMAX(fy,by), FFMIN(fy,by) - ymin); | |
1369 | ✗ | borderdist= FFMIN(a,b); | |
1370 | } | ||
1371 | } | ||
1372 | } | ||
1373 | } | ||
1374 |
2/2✓ Branch 0 taken 419495 times.
✓ Branch 1 taken 408222 times.
|
827717 | }while(!end); |
1375 | } | ||
1376 | |||
1377 | 408222 | s->b_bidir_forw_mv_table[xy][0]= motion_fx; | |
1378 | 408222 | s->b_bidir_forw_mv_table[xy][1]= motion_fy; | |
1379 | 408222 | s->b_bidir_back_mv_table[xy][0]= motion_bx; | |
1380 | 408222 | s->b_bidir_back_mv_table[xy][1]= motion_by; | |
1381 | |||
1382 | 408222 | return fbmin; | |
1383 | } | ||
1384 | |||
1385 | 191520 | static inline int direct_search(MpegEncContext * s, int mb_x, int mb_y) | |
1386 | { | ||
1387 | 191520 | MotionEstContext * const c= &s->me; | |
1388 | int P[10][2]; | ||
1389 | 191520 | const int mot_stride = s->mb_stride; | |
1390 | 191520 | const int mot_xy = mb_y*mot_stride + mb_x; | |
1391 | 191520 | const int shift= 1+s->quarter_sample; | |
1392 | int dmin, i; | ||
1393 | 191520 | const int time_pp= s->pp_time; | |
1394 | 191520 | const int time_pb= s->pb_time; | |
1395 | int mx, my, xmin, xmax, ymin, ymax; | ||
1396 | 191520 | int16_t (*mv_table)[2]= s->b_direct_mv_table; | |
1397 | |||
1398 | 191520 | c->current_mv_penalty= c->mv_penalty[1] + MAX_DMV; | |
1399 | 191520 | ymin= xmin=(-32)>>shift; | |
1400 | 191520 | ymax= xmax= 31>>shift; | |
1401 | |||
1402 |
2/2✓ Branch 0 taken 54618 times.
✓ Branch 1 taken 136902 times.
|
191520 | if (IS_8X8(s->next_pic.mb_type[mot_xy])) { |
1403 | 54618 | s->mv_type= MV_TYPE_8X8; | |
1404 | }else{ | ||
1405 | 136902 | s->mv_type= MV_TYPE_16X16; | |
1406 | } | ||
1407 | |||
1408 |
2/2✓ Branch 0 taken 355374 times.
✓ Branch 1 taken 54618 times.
|
409992 | for(i=0; i<4; i++){ |
1409 | 355374 | int index= s->block_index[i]; | |
1410 | int min, max; | ||
1411 | |||
1412 | 355374 | c->co_located_mv[i][0] = s->next_pic.motion_val[0][index][0]; | |
1413 | 355374 | c->co_located_mv[i][1] = s->next_pic.motion_val[0][index][1]; | |
1414 | 355374 | c->direct_basis_mv[i][0]= c->co_located_mv[i][0]*time_pb/time_pp + ((i& 1)<<(shift+3)); | |
1415 | 355374 | c->direct_basis_mv[i][1]= c->co_located_mv[i][1]*time_pb/time_pp + ((i>>1)<<(shift+3)); | |
1416 | // c->direct_basis_mv[1][i][0]= c->co_located_mv[i][0]*(time_pb - time_pp)/time_pp + ((i &1)<<(shift+3); | ||
1417 | // c->direct_basis_mv[1][i][1]= c->co_located_mv[i][1]*(time_pb - time_pp)/time_pp + ((i>>1)<<(shift+3); | ||
1418 | |||
1419 |
2/2✓ Branch 0 taken 139676 times.
✓ Branch 1 taken 215698 times.
|
355374 | max= FFMAX(c->direct_basis_mv[i][0], c->direct_basis_mv[i][0] - c->co_located_mv[i][0])>>shift; |
1420 |
2/2✓ Branch 0 taken 139676 times.
✓ Branch 1 taken 215698 times.
|
355374 | min= FFMIN(c->direct_basis_mv[i][0], c->direct_basis_mv[i][0] - c->co_located_mv[i][0])>>shift; |
1421 | 355374 | max+= 16*mb_x + 1; // +-1 is for the simpler rounding | |
1422 | 355374 | min+= 16*mb_x - 1; | |
1423 | 355374 | xmax= FFMIN(xmax, s->width - max); | |
1424 | 355374 | xmin= FFMAX(xmin, - 16 - min); | |
1425 | |||
1426 |
2/2✓ Branch 0 taken 141386 times.
✓ Branch 1 taken 213988 times.
|
355374 | max= FFMAX(c->direct_basis_mv[i][1], c->direct_basis_mv[i][1] - c->co_located_mv[i][1])>>shift; |
1427 |
2/2✓ Branch 0 taken 141386 times.
✓ Branch 1 taken 213988 times.
|
355374 | min= FFMIN(c->direct_basis_mv[i][1], c->direct_basis_mv[i][1] - c->co_located_mv[i][1])>>shift; |
1428 | 355374 | max+= 16*mb_y + 1; // +-1 is for the simpler rounding | |
1429 | 355374 | min+= 16*mb_y - 1; | |
1430 | 355374 | ymax= FFMIN(ymax, s->height - max); | |
1431 | 355374 | ymin= FFMAX(ymin, - 16 - min); | |
1432 | |||
1433 |
2/2✓ Branch 0 taken 136902 times.
✓ Branch 1 taken 218472 times.
|
355374 | if(s->mv_type == MV_TYPE_16X16) break; |
1434 | } | ||
1435 | |||
1436 | av_assert2(xmax <= 15 && ymax <= 15 && xmin >= -16 && ymin >= -16); | ||
1437 | |||
1438 |
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 191420 times.
✓ Branch 5 taken 33 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 191420 times.
|
191520 | if(xmax < 0 || xmin >0 || ymax < 0 || ymin > 0){ |
1439 | 100 | s->b_direct_mv_table[mot_xy][0]= 0; | |
1440 | 100 | s->b_direct_mv_table[mot_xy][1]= 0; | |
1441 | |||
1442 | 100 | return 256*256*256*64-1; | |
1443 | } | ||
1444 | |||
1445 | 191420 | c->xmin= xmin; | |
1446 | 191420 | c->ymin= ymin; | |
1447 | 191420 | c->xmax= xmax; | |
1448 | 191420 | c->ymax= ymax; | |
1449 | 191420 | c->flags |= FLAG_DIRECT; | |
1450 | 191420 | c->sub_flags |= FLAG_DIRECT; | |
1451 | 191420 | c->pred_x=0; | |
1452 | 191420 | c->pred_y=0; | |
1453 | |||
1454 | 191420 | P_LEFT[0] = av_clip(mv_table[mot_xy - 1][0], xmin * (1 << shift), xmax << shift); | |
1455 | 191420 | P_LEFT[1] = av_clip(mv_table[mot_xy - 1][1], ymin * (1 << shift), ymax << shift); | |
1456 | |||
1457 | /* special case for first line */ | ||
1458 |
2/2✓ Branch 0 taken 178178 times.
✓ Branch 1 taken 13242 times.
|
191420 | if (!s->first_slice_line) { //FIXME maybe allow this over thread boundary as it is clipped |
1459 | 178178 | P_TOP[0] = av_clip(mv_table[mot_xy - mot_stride ][0], xmin * (1 << shift), xmax << shift); | |
1460 | 178178 | P_TOP[1] = av_clip(mv_table[mot_xy - mot_stride ][1], ymin * (1 << shift), ymax << shift); | |
1461 | 178178 | P_TOPRIGHT[0] = av_clip(mv_table[mot_xy - mot_stride + 1][0], xmin * (1 << shift), xmax << shift); | |
1462 | 178178 | P_TOPRIGHT[1] = av_clip(mv_table[mot_xy - mot_stride + 1][1], ymin * (1 << shift), ymax << shift); | |
1463 | |||
1464 | 178178 | P_MEDIAN[0]= mid_pred(P_LEFT[0], P_TOP[0], P_TOPRIGHT[0]); | |
1465 | 178178 | P_MEDIAN[1]= mid_pred(P_LEFT[1], P_TOP[1], P_TOPRIGHT[1]); | |
1466 | } | ||
1467 | |||
1468 | 191420 | dmin = ff_epzs_motion_search(s, &mx, &my, P, 0, 0, mv_table, 1<<(16-shift), 0, 16); | |
1469 |
2/2✓ Branch 0 taken 38282 times.
✓ Branch 1 taken 153138 times.
|
191420 | if(c->sub_flags&FLAG_QPEL) |
1470 | 38282 | dmin = qpel_motion_search(s, &mx, &my, dmin, 0, 0, 0, 16); | |
1471 | else | ||
1472 | 153138 | dmin = hpel_motion_search(s, &mx, &my, dmin, 0, 0, 0, 16); | |
1473 | |||
1474 |
4/4✓ Branch 0 taken 114845 times.
✓ Branch 1 taken 76575 times.
✓ Branch 2 taken 114824 times.
✓ Branch 3 taken 21 times.
|
191420 | if(c->avctx->me_sub_cmp != c->avctx->mb_cmp && !c->skip) |
1475 | 114824 | dmin= get_mb_score(s, mx, my, 0, 0, 0, 16, 1); | |
1476 | |||
1477 | 191420 | get_limits(s, 16*mb_x, 16*mb_y, 1); //restore c->?min/max, maybe not needed | |
1478 | |||
1479 | 191420 | mv_table[mot_xy][0]= mx; | |
1480 | 191420 | mv_table[mot_xy][1]= my; | |
1481 | 191420 | c->flags &= ~FLAG_DIRECT; | |
1482 | 191420 | c->sub_flags &= ~FLAG_DIRECT; | |
1483 | |||
1484 | 191420 | return dmin; | |
1485 | } | ||
1486 | |||
1487 | 408312 | void ff_estimate_b_frame_motion(MpegEncContext * s, | |
1488 | int mb_x, int mb_y) | ||
1489 | { | ||
1490 | 408312 | MotionEstContext * const c= &s->me; | |
1491 | int fmin, bmin, dmin, fbmin, bimin, fimin; | ||
1492 | 408312 | int type=0; | |
1493 | 408312 | const int xy = mb_y*s->mb_stride + mb_x; | |
1494 | 408312 | init_ref(c, s->new_pic->data, s->last_pic.data, | |
1495 | 408312 | s->next_pic.data, 16 * mb_x, 16 * mb_y, 2); | |
1496 | |||
1497 | 408312 | get_limits(s, 16*mb_x, 16*mb_y, 1); | |
1498 | |||
1499 | 408312 | c->skip=0; | |
1500 | |||
1501 |
4/4✓ Branch 0 taken 191520 times.
✓ Branch 1 taken 216792 times.
✓ Branch 2 taken 90 times.
✓ Branch 3 taken 191430 times.
|
408312 | if (s->codec_id == AV_CODEC_ID_MPEG4 && s->next_pic.mbskip_table[xy]) { |
1502 | 90 | int score= direct_search(s, mb_x, mb_y); //FIXME just check 0,0 | |
1503 | |||
1504 | 90 | score= ((unsigned)(score*score + 128*256))>>16; | |
1505 | 90 | c->mc_mb_var_sum_temp += score; | |
1506 | 90 | s->mc_mb_var[mb_y*s->mb_stride + mb_x] = score; //FIXME use SSE | |
1507 | 90 | s->mb_type[mb_y*s->mb_stride + mb_x]= CANDIDATE_MB_TYPE_DIRECT0; | |
1508 | |||
1509 | 90 | return; | |
1510 | } | ||
1511 | |||
1512 | 408222 | c->penalty_factor = get_penalty_factor(s->lambda, s->lambda2, c->avctx->me_cmp); | |
1513 | 408222 | c->sub_penalty_factor= get_penalty_factor(s->lambda, s->lambda2, c->avctx->me_sub_cmp); | |
1514 | 408222 | c->mb_penalty_factor = get_penalty_factor(s->lambda, s->lambda2, c->avctx->mb_cmp); | |
1515 | |||
1516 |
2/2✓ Branch 0 taken 191430 times.
✓ Branch 1 taken 216792 times.
|
408222 | if (s->codec_id == AV_CODEC_ID_MPEG4) |
1517 | 191430 | dmin= direct_search(s, mb_x, mb_y); | |
1518 | else | ||
1519 | 216792 | dmin= INT_MAX; | |
1520 | |||
1521 | // FIXME penalty stuff for non-MPEG-4 | ||
1522 | 408222 | c->skip=0; | |
1523 | 408222 | fmin = estimate_motion_b(s, mb_x, mb_y, s->b_forw_mv_table, 0, s->f_code) + | |
1524 | 408222 | 3 * c->mb_penalty_factor; | |
1525 | |||
1526 | 408222 | c->skip=0; | |
1527 | 408222 | bmin = estimate_motion_b(s, mb_x, mb_y, s->b_back_mv_table, 2, s->b_code) + | |
1528 | 408222 | 2 * c->mb_penalty_factor; | |
1529 | ff_dlog(s->avctx, " %d %d ", s->b_forw_mv_table[xy][0], s->b_forw_mv_table[xy][1]); | ||
1530 | |||
1531 | 408222 | c->skip=0; | |
1532 | 408222 | fbmin= bidir_refine(s, mb_x, mb_y) + c->mb_penalty_factor; | |
1533 | ff_dlog(s->avctx, "%d %d %d %d\n", dmin, fmin, bmin, fbmin); | ||
1534 | |||
1535 |
2/2✓ Branch 0 taken 115200 times.
✓ Branch 1 taken 293022 times.
|
408222 | 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 | 293022 | fimin= bimin= INT_MAX; | |
1548 | |||
1549 | { | ||
1550 | 408222 | int score= fmin; | |
1551 | 408222 | type = CANDIDATE_MB_TYPE_FORWARD; | |
1552 | |||
1553 |
2/2✓ Branch 0 taken 55338 times.
✓ Branch 1 taken 352884 times.
|
408222 | if (dmin <= score){ |
1554 | 55338 | score = dmin; | |
1555 | 55338 | type = CANDIDATE_MB_TYPE_DIRECT; | |
1556 | } | ||
1557 |
2/2✓ Branch 0 taken 204255 times.
✓ Branch 1 taken 203967 times.
|
408222 | if(bmin<score){ |
1558 | 204255 | score=bmin; | |
1559 | 204255 | type= CANDIDATE_MB_TYPE_BACKWARD; | |
1560 | } | ||
1561 |
2/2✓ Branch 0 taken 237582 times.
✓ Branch 1 taken 170640 times.
|
408222 | if(fbmin<score){ |
1562 | 237582 | score=fbmin; | |
1563 | 237582 | type= CANDIDATE_MB_TYPE_BIDIR; | |
1564 | } | ||
1565 |
2/2✓ Branch 0 taken 3902 times.
✓ Branch 1 taken 404320 times.
|
408222 | 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 404127 times.
|
408222 | if(bimin<score){ |
1570 | 4095 | score=bimin; | |
1571 | 4095 | type= CANDIDATE_MB_TYPE_BACKWARD_I; | |
1572 | } | ||
1573 | |||
1574 | 408222 | score= ((unsigned)(score*score + 128*256))>>16; | |
1575 | 408222 | c->mc_mb_var_sum_temp += score; | |
1576 | 408222 | 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 178370 times.
|
408222 | 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 76799 times.
✓ Branch 1 taken 153053 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 153053 times.
✓ Branch 3 taken 95 times.
|
229852 | if (s->codec_id == AV_CODEC_ID_MPEG4 && type&CANDIDATE_MB_TYPE_DIRECT && |
1591 |
4/4✓ Branch 0 taken 76519 times.
✓ Branch 1 taken 76534 times.
✓ Branch 2 taken 47416 times.
✓ Branch 3 taken 29103 times.
|
153053 | s->mpv_flags & FF_MPV_FLAG_MV0 && *(uint32_t*)s->b_direct_mv_table[xy]) |
1592 | 47416 | type |= CANDIDATE_MB_TYPE_DIRECT0; | |
1593 | } | ||
1594 | |||
1595 | 408222 | 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 | 12177 | int ff_get_best_fcode(MpegEncContext * s, const int16_t (*mv_table)[2], int type) | |
1600 | { | ||
1601 |
1/2✓ Branch 0 taken 12177 times.
✗ Branch 1 not taken.
|
12177 | if (s->motion_est != FF_ME_ZERO) { |
1602 | int score[8]; | ||
1603 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 12177 times.
|
12177 | int i, y, range= s->avctx->me_range ? s->avctx->me_range : (INT_MAX/2); |
1604 | 12177 | const uint8_t * fcode_tab = s->fcode_tab; | |
1605 | 12177 | int best_fcode=-1; | |
1606 | 12177 | int best_score=-10000000; | |
1607 | |||
1608 |
2/2✓ Branch 0 taken 742 times.
✓ Branch 1 taken 11435 times.
|
12177 | if (s->msmpeg4_version != MSMP4_UNUSED) |
1609 | 742 | range= FFMIN(range, 16); | |
1610 |
4/4✓ Branch 0 taken 5089 times.
✓ Branch 1 taken 6346 times.
✓ Branch 2 taken 4481 times.
✓ Branch 3 taken 608 times.
|
11435 | else if(s->codec_id == AV_CODEC_ID_MPEG2VIDEO && s->avctx->strict_std_compliance >= FF_COMPLIANCE_NORMAL) |
1611 | 4481 | range= FFMIN(range, 256); | |
1612 | |||
1613 |
2/2✓ Branch 0 taken 97416 times.
✓ Branch 1 taken 12177 times.
|
109593 | for(i=0; i<8; i++) score[i]= s->mb_num*(8-i); |
1614 | |||
1615 |
2/2✓ Branch 0 taken 173637 times.
✓ Branch 1 taken 12177 times.
|
185814 | for(y=0; y<s->mb_height; y++){ |
1616 | int x; | ||
1617 | 173637 | int xy= y*s->mb_stride; | |
1618 |
2/2✓ Branch 0 taken 3864127 times.
✓ Branch 1 taken 173637 times.
|
4037764 | for(x=0; x<s->mb_width; x++, xy++){ |
1619 |
2/2✓ Branch 0 taken 3151449 times.
✓ Branch 1 taken 712678 times.
|
3864127 | if(s->mb_type[xy] & type){ |
1620 | 3151449 | int mx= mv_table[xy][0]; | |
1621 | 3151449 | int my= mv_table[xy][1]; | |
1622 | 3151449 | int fcode = FFMAX(fcode_tab[mx], fcode_tab[my]); | |
1623 | int j; | ||
1624 | |||
1625 |
6/6✓ Branch 0 taken 3150488 times.
✓ Branch 1 taken 961 times.
✓ Branch 2 taken 3149683 times.
✓ Branch 3 taken 805 times.
✓ Branch 4 taken 3149025 times.
✓ Branch 5 taken 658 times.
|
3151449 | if (mx >= range || mx < -range || |
1626 |
2/2✓ Branch 0 taken 459 times.
✓ Branch 1 taken 3148566 times.
|
3149025 | my >= range || my < -range) |
1627 | 2883 | continue; | |
1628 | |||
1629 |
3/4✓ Branch 0 taken 3368640 times.
✓ Branch 1 taken 3148566 times.
✓ Branch 2 taken 3368640 times.
✗ Branch 3 not taken.
|
6517206 | for(j=0; j<fcode && j<8; j++){ |
1630 |
2/2✓ Branch 0 taken 2104116 times.
✓ Branch 1 taken 1264524 times.
|
3368640 | if (s->pict_type == AV_PICTURE_TYPE_B || |
1631 |
2/2✓ Branch 0 taken 1993767 times.
✓ Branch 1 taken 110349 times.
|
2104116 | s->mc_mb_var[xy] < s->mb_var[xy]) |
1632 | 3258291 | score[j]-= 170; | |
1633 | } | ||
1634 | } | ||
1635 | } | ||
1636 | } | ||
1637 | |||
1638 |
2/2✓ Branch 0 taken 85239 times.
✓ Branch 1 taken 12177 times.
|
97416 | for(i=1; i<8; i++){ |
1639 |
2/2✓ Branch 0 taken 16293 times.
✓ Branch 1 taken 68946 times.
|
85239 | if(score[i] > best_score){ |
1640 | 16293 | best_score= score[i]; | |
1641 | 16293 | best_fcode= i; | |
1642 | } | ||
1643 | } | ||
1644 | |||
1645 | 12177 | return best_fcode; | |
1646 | }else{ | ||
1647 | ✗ | return 1; | |
1648 | } | ||
1649 | } | ||
1650 | |||
1651 | 6665 | void ff_fix_long_p_mvs(MpegEncContext * s, int type) | |
1652 | { | ||
1653 | 6665 | MotionEstContext * const c= &s->me; | |
1654 | 6665 | const int f_code= s->f_code; | |
1655 | int y, range; | ||
1656 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6665 times.
|
6665 | av_assert0(s->pict_type==AV_PICTURE_TYPE_P); |
1657 | |||
1658 |
4/4✓ Branch 0 taken 3669 times.
✓ Branch 1 taken 2996 times.
✓ Branch 2 taken 742 times.
✓ Branch 3 taken 2927 times.
|
6665 | range = (((s->out_format == FMT_MPEG1 || s->msmpeg4_version != MSMP4_UNUSED) ? 8 : 16) << f_code); |
1659 | |||
1660 |
3/4✓ Branch 0 taken 3791 times.
✓ Branch 1 taken 2874 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3791 times.
|
6665 | av_assert0(range <= 16 || s->msmpeg4_version == MSMP4_UNUSED); |
1661 |
1/6✗ Branch 0 not taken.
✓ Branch 1 taken 6665 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
6665 | av_assert0(range <=256 || !(s->codec_id == AV_CODEC_ID_MPEG2VIDEO && s->avctx->strict_std_compliance >= FF_COMPLIANCE_NORMAL)); |
1662 | |||
1663 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 6665 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
6665 | if(c->avctx->me_range && range > c->avctx->me_range) range= c->avctx->me_range; |
1664 | |||
1665 |
2/2✓ Branch 0 taken 927 times.
✓ Branch 1 taken 5738 times.
|
6665 | if (s->avctx->flags & AV_CODEC_FLAG_4MV) { |
1666 | 927 | const int wrap= s->b8_stride; | |
1667 | |||
1668 | /* clip / convert to intra 8x8 type MVs */ | ||
1669 |
2/2✓ Branch 0 taken 13221 times.
✓ Branch 1 taken 927 times.
|
14148 | for(y=0; y<s->mb_height; y++){ |
1670 | 13221 | int xy= y*2*wrap; | |
1671 | 13221 | int i= y*s->mb_stride; | |
1672 | int x; | ||
1673 | |||
1674 |
2/2✓ Branch 0 taken 277695 times.
✓ Branch 1 taken 13221 times.
|
290916 | for(x=0; x<s->mb_width; x++){ |
1675 |
2/2✓ Branch 0 taken 210029 times.
✓ Branch 1 taken 67666 times.
|
277695 | if(s->mb_type[i]&CANDIDATE_MB_TYPE_INTER4V){ |
1676 | int block; | ||
1677 |
2/2✓ Branch 0 taken 840116 times.
✓ Branch 1 taken 210029 times.
|
1050145 | for(block=0; block<4; block++){ |
1678 | 840116 | int off= (block& 1) + (block>>1)*wrap; | |
1679 | 840116 | int mx = s->cur_pic.motion_val[0][ xy + off ][0]; | |
1680 | 840116 | int my = s->cur_pic.motion_val[0][ xy + off ][1]; | |
1681 | |||
1682 |
4/4✓ Branch 0 taken 839720 times.
✓ Branch 1 taken 396 times.
✓ Branch 2 taken 839113 times.
✓ Branch 3 taken 607 times.
|
840116 | if( mx >=range || mx <-range |
1683 |
4/4✓ Branch 0 taken 838970 times.
✓ Branch 1 taken 143 times.
✓ Branch 2 taken 235 times.
✓ Branch 3 taken 838735 times.
|
839113 | || my >=range || my <-range){ |
1684 | 1381 | s->mb_type[i] &= ~CANDIDATE_MB_TYPE_INTER4V; | |
1685 | 1381 | s->mb_type[i] |= type; | |
1686 | 1381 | s->cur_pic.mb_type[i] = type; | |
1687 | } | ||
1688 | } | ||
1689 | } | ||
1690 | 277695 | xy+=2; | |
1691 | 277695 | i++; | |
1692 | } | ||
1693 | } | ||
1694 | } | ||
1695 | 6665 | } | |
1696 | |||
1697 | /** | ||
1698 | * @param truncate 1 for truncation, 0 for using intra | ||
1699 | */ | ||
1700 | 16453 | void ff_fix_long_mvs(MpegEncContext * s, uint8_t *field_select_table, int field_select, | |
1701 | int16_t (*mv_table)[2], int f_code, int type, int truncate) | ||
1702 | { | ||
1703 | 16453 | MotionEstContext * const c= &s->me; | |
1704 | int y, h_range, v_range; | ||
1705 | |||
1706 | // RAL: 8 in MPEG-1, 16 in MPEG-4 | ||
1707 |
4/4✓ Branch 0 taken 6229 times.
✓ Branch 1 taken 10224 times.
✓ Branch 2 taken 742 times.
✓ Branch 3 taken 5487 times.
|
16453 | int range = (((s->out_format == FMT_MPEG1 || s->msmpeg4_version != MSMP4_UNUSED) ? 8 : 16) << f_code); |
1708 | |||
1709 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 16453 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
16453 | if(c->avctx->me_range && range > c->avctx->me_range) range= c->avctx->me_range; |
1710 | |||
1711 | 16453 | h_range= range; | |
1712 |
2/2✓ Branch 0 taken 4400 times.
✓ Branch 1 taken 12053 times.
|
16453 | v_range= field_select_table ? range>>1 : range; |
1713 | |||
1714 | /* clip / convert to intra 16x16 type MVs */ | ||
1715 |
2/2✓ Branch 0 taken 231898 times.
✓ Branch 1 taken 16453 times.
|
248351 | for(y=0; y<s->mb_height; y++){ |
1716 | int x; | ||
1717 | 231898 | int xy= y*s->mb_stride; | |
1718 |
2/2✓ Branch 0 taken 5049286 times.
✓ Branch 1 taken 231898 times.
|
5281184 | for(x=0; x<s->mb_width; x++){ |
1719 |
2/2✓ Branch 0 taken 3523984 times.
✓ Branch 1 taken 1525302 times.
|
5049286 | if (s->mb_type[xy] & type){ // RAL: "type" test added... |
1720 |
4/4✓ Branch 0 taken 359422 times.
✓ Branch 1 taken 3164562 times.
✓ Branch 2 taken 179813 times.
✓ Branch 3 taken 179609 times.
|
3523984 | if (!field_select_table || field_select_table[xy] == field_select) { |
1721 |
4/4✓ Branch 0 taken 3341878 times.
✓ Branch 1 taken 2497 times.
✓ Branch 2 taken 3339668 times.
✓ Branch 3 taken 2210 times.
|
3344375 | if( mv_table[xy][0] >=h_range || mv_table[xy][0] <-h_range |
1722 |
4/4✓ Branch 0 taken 3338135 times.
✓ Branch 1 taken 1533 times.
✓ Branch 2 taken 1231 times.
✓ Branch 3 taken 3336904 times.
|
3339668 | || mv_table[xy][1] >=v_range || mv_table[xy][1] <-v_range){ |
1723 | |||
1724 |
2/2✓ Branch 0 taken 1544 times.
✓ Branch 1 taken 5927 times.
|
7471 | if(truncate){ |
1725 |
2/2✓ Branch 0 taken 436 times.
✓ Branch 1 taken 1108 times.
|
1544 | if (mv_table[xy][0] > h_range-1) mv_table[xy][0]= h_range-1; |
1726 |
2/2✓ Branch 0 taken 486 times.
✓ Branch 1 taken 622 times.
|
1108 | else if(mv_table[xy][0] < -h_range ) mv_table[xy][0]= -h_range; |
1727 |
2/2✓ Branch 0 taken 341 times.
✓ Branch 1 taken 1203 times.
|
1544 | if (mv_table[xy][1] > v_range-1) mv_table[xy][1]= v_range-1; |
1728 |
2/2✓ Branch 0 taken 321 times.
✓ Branch 1 taken 882 times.
|
1203 | else if(mv_table[xy][1] < -v_range ) mv_table[xy][1]= -v_range; |
1729 | }else{ | ||
1730 | 5927 | s->mb_type[xy] &= ~type; | |
1731 | 5927 | s->mb_type[xy] |= CANDIDATE_MB_TYPE_INTRA; | |
1732 | 5927 | mv_table[xy][0]= | |
1733 | 5927 | mv_table[xy][1]= 0; | |
1734 | } | ||
1735 | } | ||
1736 | } | ||
1737 | } | ||
1738 | 5049286 | xy++; | |
1739 | } | ||
1740 | } | ||
1741 | 16453 | } | |
1742 |