Line | Branch | Exec | Source |
---|---|---|---|
1 | /* | ||
2 | * Copyright (c) 2000,2001 Fabrice Bellard | ||
3 | * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at> | ||
4 | * | ||
5 | * 4MV & hq & B-frame encoding stuff by Michael Niedermayer <michaelni@gmx.at> | ||
6 | * | ||
7 | * This file is part of FFmpeg. | ||
8 | * | ||
9 | * FFmpeg is free software; you can redistribute it and/or | ||
10 | * modify it under the terms of the GNU Lesser General Public | ||
11 | * License as published by the Free Software Foundation; either | ||
12 | * version 2.1 of the License, or (at your option) any later version. | ||
13 | * | ||
14 | * FFmpeg is distributed in the hope that it will be useful, | ||
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
17 | * Lesser General Public License for more details. | ||
18 | * | ||
19 | * You should have received a copy of the GNU Lesser General Public | ||
20 | * License along with FFmpeg; if not, write to the Free Software | ||
21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
22 | */ | ||
23 | |||
24 | #include "config_components.h" | ||
25 | |||
26 | #include "libavutil/avassert.h" | ||
27 | #include "libavutil/internal.h" | ||
28 | #include "libavutil/mem_internal.h" | ||
29 | |||
30 | #include "avcodec.h" | ||
31 | #include "h261.h" | ||
32 | #include "h263.h" | ||
33 | #include "mpegutils.h" | ||
34 | #include "mpegvideo.h" | ||
35 | #include "mpeg4videodec.h" | ||
36 | #include "qpeldsp.h" | ||
37 | #include "wmv2.h" | ||
38 | |||
39 | 2664060 | static inline int hpel_motion(MpegEncContext *s, | |
40 | uint8_t *dest, uint8_t *src, | ||
41 | int src_x, int src_y, | ||
42 | const op_pixels_func *pix_op, | ||
43 | int motion_x, int motion_y) | ||
44 | { | ||
45 | 2664060 | int dxy = 0; | |
46 | 2664060 | int emu = 0; | |
47 | |||
48 | 2664060 | src_x += motion_x >> 1; | |
49 | 2664060 | src_y += motion_y >> 1; | |
50 | |||
51 | /* WARNING: do no forget half pels */ | ||
52 | 2664060 | src_x = av_clip(src_x, -16, s->width); // FIXME unneeded for emu? | |
53 |
2/2✓ Branch 0 taken 2662083 times.
✓ Branch 1 taken 1977 times.
|
2664060 | if (src_x != s->width) |
54 | 2662083 | dxy |= motion_x & 1; | |
55 | 2664060 | src_y = av_clip(src_y, -16, s->height); | |
56 |
2/2✓ Branch 0 taken 2661670 times.
✓ Branch 1 taken 2390 times.
|
2664060 | if (src_y != s->height) |
57 | 2661670 | dxy |= (motion_y & 1) << 1; | |
58 | 2664060 | src += src_y * s->linesize + src_x; | |
59 | |||
60 |
3/4✓ Branch 0 taken 2664060 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2621072 times.
✓ Branch 3 taken 42988 times.
|
2664060 | if ((unsigned)src_x >= FFMAX(s->h_edge_pos - (motion_x & 1) - 7, 0) || |
61 |
3/4✓ Branch 0 taken 2621072 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 46939 times.
✓ Branch 3 taken 2574133 times.
|
2621072 | (unsigned)src_y >= FFMAX(s->v_edge_pos - (motion_y & 1) - 7, 0)) { |
62 | 89927 | s->vdsp.emulated_edge_mc(s->sc.edge_emu_buffer, src, | |
63 | s->linesize, s->linesize, | ||
64 | 9, 9, | ||
65 | src_x, src_y, | ||
66 | s->h_edge_pos, s->v_edge_pos); | ||
67 | 89927 | src = s->sc.edge_emu_buffer; | |
68 | 89927 | emu = 1; | |
69 | } | ||
70 | 2664060 | pix_op[dxy](dest, src, s->linesize, 8); | |
71 | 2664060 | return emu; | |
72 | } | ||
73 | |||
74 | static av_always_inline | ||
75 | 9004328 | void mpeg_motion_internal(MpegEncContext *s, | |
76 | uint8_t *dest_y, | ||
77 | uint8_t *dest_cb, | ||
78 | uint8_t *dest_cr, | ||
79 | int field_based, | ||
80 | int bottom_field, | ||
81 | int field_select, | ||
82 | uint8_t *const *ref_picture, | ||
83 | const op_pixels_func (*pix_op)[4], | ||
84 | int motion_x, | ||
85 | int motion_y, | ||
86 | int h, | ||
87 | int is_mpeg12, | ||
88 | int is_16x8, | ||
89 | int mb_y) | ||
90 | { | ||
91 | const uint8_t *ptr_y, *ptr_cb, *ptr_cr; | ||
92 | int dxy, uvdxy, mx, my, src_x, src_y, | ||
93 | uvsrc_x, uvsrc_y, v_edge_pos, block_y_half; | ||
94 | ptrdiff_t uvlinesize, linesize; | ||
95 | |||
96 | 9004328 | v_edge_pos = s->v_edge_pos >> field_based; | |
97 | 9004328 | linesize = s->cur_pic.linesize[0] << field_based; | |
98 | 9004328 | uvlinesize = s->cur_pic.linesize[1] << field_based; | |
99 | 9004328 | block_y_half = (field_based | is_16x8); | |
100 | |||
101 | 9004328 | dxy = ((motion_y & 1) << 1) | (motion_x & 1); | |
102 | 9004328 | src_x = s->mb_x * 16 + (motion_x >> 1); | |
103 | 9004328 | src_y = (mb_y << (4 - block_y_half)) + (motion_y >> 1); | |
104 | |||
105 |
4/4✓ Branch 0 taken 4006499 times.
✓ Branch 1 taken 4997829 times.
✓ Branch 2 taken 3799251 times.
✓ Branch 3 taken 207248 times.
|
9004328 | if (!is_mpeg12 && s->out_format == FMT_H263) { |
106 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 3799251 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
3799251 | if ((s->workaround_bugs & FF_BUG_HPEL_CHROMA) && field_based) { |
107 | ✗ | mx = (motion_x >> 1) | (motion_x & 1); | |
108 | ✗ | my = motion_y >> 1; | |
109 | ✗ | uvdxy = ((my & 1) << 1) | (mx & 1); | |
110 | ✗ | uvsrc_x = s->mb_x * 8 + (mx >> 1); | |
111 | ✗ | uvsrc_y = (mb_y << (3 - block_y_half)) + (my >> 1); | |
112 | } else { | ||
113 | 3799251 | uvdxy = dxy | (motion_y & 2) | ((motion_x & 2) >> 1); | |
114 | 3799251 | uvsrc_x = src_x >> 1; | |
115 | 3799251 | uvsrc_y = src_y >> 1; | |
116 | } | ||
117 | // Even chroma mv's are full pel in H261 | ||
118 |
2/2✓ Branch 0 taken 207248 times.
✓ Branch 1 taken 4997829 times.
|
5205077 | } else if (!CONFIG_SMALL && !is_mpeg12 || |
119 | CONFIG_SMALL && s->out_format == FMT_H261) { | ||
120 | av_assert2(s->out_format == FMT_H261); | ||
121 | 207248 | mx = motion_x / 4; | |
122 | 207248 | my = motion_y / 4; | |
123 | 207248 | uvdxy = 0; | |
124 | 207248 | uvsrc_x = s->mb_x * 8 + mx; | |
125 | 207248 | uvsrc_y = mb_y * 8 + my; | |
126 | } else { | ||
127 | av_assert2(s->out_format == FMT_MPEG1); | ||
128 |
2/2✓ Branch 0 taken 4323935 times.
✓ Branch 1 taken 673894 times.
|
4997829 | if (s->chroma_y_shift) { |
129 | 4323935 | mx = motion_x / 2; | |
130 | 4323935 | my = motion_y / 2; | |
131 | 4323935 | uvdxy = ((my & 1) << 1) | (mx & 1); | |
132 | 4323935 | uvsrc_x = s->mb_x * 8 + (mx >> 1); | |
133 | 4323935 | uvsrc_y = (mb_y << (3 - block_y_half)) + (my >> 1); | |
134 | } else { | ||
135 |
1/2✓ Branch 0 taken 673894 times.
✗ Branch 1 not taken.
|
673894 | if (s->chroma_x_shift) { |
136 | // Chroma422 | ||
137 | 673894 | mx = motion_x / 2; | |
138 | 673894 | uvdxy = ((motion_y & 1) << 1) | (mx & 1); | |
139 | 673894 | uvsrc_x = s->mb_x * 8 + (mx >> 1); | |
140 | 673894 | uvsrc_y = src_y; | |
141 | } else { | ||
142 | // Chroma444 | ||
143 | ✗ | uvdxy = dxy; | |
144 | ✗ | uvsrc_x = src_x; | |
145 | ✗ | uvsrc_y = src_y; | |
146 | } | ||
147 | } | ||
148 | } | ||
149 | |||
150 | 9004328 | ptr_y = ref_picture[0] + src_y * linesize + src_x; | |
151 | 9004328 | ptr_cb = ref_picture[1] + uvsrc_y * uvlinesize + uvsrc_x; | |
152 | 9004328 | ptr_cr = ref_picture[2] + uvsrc_y * uvlinesize + uvsrc_x; | |
153 | |||
154 |
3/4✓ Branch 0 taken 9004328 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8868769 times.
✓ Branch 3 taken 135559 times.
|
9004328 | if ((unsigned)src_x >= FFMAX(s->h_edge_pos - (motion_x & 1) - 15 , 0) || |
155 |
3/4✓ Branch 0 taken 8868769 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 148127 times.
✓ Branch 3 taken 8720642 times.
|
8868769 | (unsigned)src_y >= FFMAX( v_edge_pos - (motion_y & 1) - h + 1, 0)) { |
156 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 283686 times.
|
283686 | if (is_mpeg12 || (CONFIG_SMALL && |
157 | (s->codec_id == AV_CODEC_ID_MPEG2VIDEO || | ||
158 | s->codec_id == AV_CODEC_ID_MPEG1VIDEO))) { | ||
159 | ✗ | av_log(s->avctx, AV_LOG_DEBUG, | |
160 | "MPEG motion vector out of boundary (%d %d)\n", src_x, | ||
161 | src_y); | ||
162 | ✗ | return; | |
163 | } | ||
164 | 283686 | src_y = (unsigned)src_y << field_based; | |
165 | 283686 | s->vdsp.emulated_edge_mc(s->sc.edge_emu_buffer, ptr_y, | |
166 | s->linesize, s->linesize, | ||
167 | 17, 17 + field_based, | ||
168 | src_x, src_y, | ||
169 | s->h_edge_pos, s->v_edge_pos); | ||
170 | 283686 | ptr_y = s->sc.edge_emu_buffer; | |
171 | if (!CONFIG_GRAY || !(s->avctx->flags & AV_CODEC_FLAG_GRAY)) { | ||
172 | 283686 | uint8_t *ubuf = s->sc.edge_emu_buffer + 18 * s->linesize; | |
173 | 283686 | uint8_t *vbuf = ubuf + 10 * s->uvlinesize; | |
174 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 283686 times.
|
283686 | if (s->workaround_bugs & FF_BUG_IEDGE) |
175 | ✗ | vbuf -= s->uvlinesize; | |
176 | 283686 | uvsrc_y = (unsigned)uvsrc_y << field_based; | |
177 | 283686 | s->vdsp.emulated_edge_mc(ubuf, ptr_cb, | |
178 | s->uvlinesize, s->uvlinesize, | ||
179 | 9, 9 + field_based, | ||
180 | uvsrc_x, uvsrc_y, | ||
181 | 283686 | s->h_edge_pos >> 1, s->v_edge_pos >> 1); | |
182 | 283686 | s->vdsp.emulated_edge_mc(vbuf, ptr_cr, | |
183 | s->uvlinesize, s->uvlinesize, | ||
184 | 9, 9 + field_based, | ||
185 | uvsrc_x, uvsrc_y, | ||
186 | 283686 | s->h_edge_pos >> 1, s->v_edge_pos >> 1); | |
187 | 283686 | ptr_cb = ubuf; | |
188 | 283686 | ptr_cr = vbuf; | |
189 | } | ||
190 | } | ||
191 | |||
192 | /* FIXME use this for field pix too instead of the obnoxious hack which | ||
193 | * changes picture.data */ | ||
194 |
2/2✓ Branch 0 taken 230415 times.
✓ Branch 1 taken 8773913 times.
|
9004328 | if (bottom_field) { |
195 | 230415 | dest_y += s->linesize; | |
196 | 230415 | dest_cb += s->uvlinesize; | |
197 | 230415 | dest_cr += s->uvlinesize; | |
198 | } | ||
199 | |||
200 |
2/2✓ Branch 0 taken 725145 times.
✓ Branch 1 taken 8279183 times.
|
9004328 | if (field_select) { |
201 | 725145 | ptr_y += s->linesize; | |
202 | 725145 | ptr_cb += s->uvlinesize; | |
203 | 725145 | ptr_cr += s->uvlinesize; | |
204 | } | ||
205 | |||
206 | 9004328 | pix_op[0][dxy](dest_y, ptr_y, linesize, h); | |
207 | |||
208 | if (!CONFIG_GRAY || !(s->avctx->flags & AV_CODEC_FLAG_GRAY)) { | ||
209 | 9004328 | pix_op[s->chroma_x_shift][uvdxy] | |
210 | 9004328 | (dest_cb, ptr_cb, uvlinesize, h >> s->chroma_y_shift); | |
211 | 9004328 | pix_op[s->chroma_x_shift][uvdxy] | |
212 | 9004328 | (dest_cr, ptr_cr, uvlinesize, h >> s->chroma_y_shift); | |
213 | } | ||
214 |
2/2✓ Branch 0 taken 4006499 times.
✓ Branch 1 taken 4997829 times.
|
9004328 | if (!is_mpeg12 && (CONFIG_H261_ENCODER || CONFIG_H261_DECODER) && |
215 |
2/2✓ Branch 0 taken 207248 times.
✓ Branch 1 taken 3799251 times.
|
4006499 | s->out_format == FMT_H261) { |
216 | 207248 | ff_h261_loop_filter(s); | |
217 | } | ||
218 | } | ||
219 | /* apply one mpeg motion vector to the three components */ | ||
220 | 8543498 | static void mpeg_motion(MpegEncContext *s, | |
221 | uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, | ||
222 | int field_select, uint8_t *const *ref_picture, | ||
223 | const op_pixels_func (*pix_op)[4], | ||
224 | int motion_x, int motion_y, int h, int is_16x8, int mb_y) | ||
225 | { | ||
226 | #if !CONFIG_SMALL | ||
227 |
2/2✓ Branch 0 taken 4536999 times.
✓ Branch 1 taken 4006499 times.
|
8543498 | if (s->out_format == FMT_MPEG1) |
228 | 4536999 | mpeg_motion_internal(s, dest_y, dest_cb, dest_cr, 0, 0, | |
229 | field_select, ref_picture, pix_op, | ||
230 | motion_x, motion_y, h, 1, is_16x8, mb_y); | ||
231 | else | ||
232 | #endif | ||
233 | 4006499 | mpeg_motion_internal(s, dest_y, dest_cb, dest_cr, 0, 0, | |
234 | field_select, ref_picture, pix_op, | ||
235 | motion_x, motion_y, h, 0, is_16x8, mb_y); | ||
236 | 8543498 | } | |
237 | |||
238 | 460830 | static void mpeg_motion_field(MpegEncContext *s, uint8_t *dest_y, | |
239 | uint8_t *dest_cb, uint8_t *dest_cr, | ||
240 | int bottom_field, int field_select, | ||
241 | uint8_t *const *ref_picture, | ||
242 | const op_pixels_func (*pix_op)[4], | ||
243 | int motion_x, int motion_y, int mb_y) | ||
244 | { | ||
245 | #if !CONFIG_SMALL | ||
246 |
1/2✓ Branch 0 taken 460830 times.
✗ Branch 1 not taken.
|
460830 | if (s->out_format == FMT_MPEG1) |
247 | 460830 | mpeg_motion_internal(s, dest_y, dest_cb, dest_cr, 1, | |
248 | bottom_field, field_select, ref_picture, pix_op, | ||
249 | motion_x, motion_y, 8, 1, 0, mb_y); | ||
250 | else | ||
251 | #endif | ||
252 | ✗ | mpeg_motion_internal(s, dest_y, dest_cb, dest_cr, 1, | |
253 | bottom_field, field_select, ref_picture, pix_op, | ||
254 | motion_x, motion_y, 8, 0, 0, mb_y); | ||
255 | 460830 | } | |
256 | |||
257 | // FIXME: SIMDify, avg variant, 16x16 version | ||
258 | 412968 | static inline void put_obmc(uint8_t *dst, uint8_t *const src[5], int stride) | |
259 | { | ||
260 | int x; | ||
261 | 412968 | uint8_t *const top = src[1]; | |
262 | 412968 | uint8_t *const left = src[2]; | |
263 | 412968 | uint8_t *const mid = src[0]; | |
264 | 412968 | uint8_t *const right = src[3]; | |
265 | 412968 | uint8_t *const bottom = src[4]; | |
266 | #define OBMC_FILTER(x, t, l, m, r, b)\ | ||
267 | dst[x]= (t*top[x] + l*left[x] + m*mid[x] + r*right[x] + b*bottom[x] + 4)>>3 | ||
268 | #define OBMC_FILTER4(x, t, l, m, r, b)\ | ||
269 | OBMC_FILTER(x , t, l, m, r, b);\ | ||
270 | OBMC_FILTER(x+1 , t, l, m, r, b);\ | ||
271 | OBMC_FILTER(x +stride, t, l, m, r, b);\ | ||
272 | OBMC_FILTER(x+1+stride, t, l, m, r, b); | ||
273 | |||
274 | 412968 | x = 0; | |
275 | 412968 | OBMC_FILTER (x , 2, 2, 4, 0, 0); | |
276 | 412968 | OBMC_FILTER (x + 1, 2, 1, 5, 0, 0); | |
277 | 412968 | OBMC_FILTER4(x + 2, 2, 1, 5, 0, 0); | |
278 | 412968 | OBMC_FILTER4(x + 4, 2, 0, 5, 1, 0); | |
279 | 412968 | OBMC_FILTER (x + 6, 2, 0, 5, 1, 0); | |
280 | 412968 | OBMC_FILTER (x + 7, 2, 0, 4, 2, 0); | |
281 | 412968 | x += stride; | |
282 | 412968 | OBMC_FILTER (x , 1, 2, 5, 0, 0); | |
283 | 412968 | OBMC_FILTER (x + 1, 1, 2, 5, 0, 0); | |
284 | 412968 | OBMC_FILTER (x + 6, 1, 0, 5, 2, 0); | |
285 | 412968 | OBMC_FILTER (x + 7, 1, 0, 5, 2, 0); | |
286 | 412968 | x += stride; | |
287 | 412968 | OBMC_FILTER4(x , 1, 2, 5, 0, 0); | |
288 | 412968 | OBMC_FILTER4(x + 2, 1, 1, 6, 0, 0); | |
289 | 412968 | OBMC_FILTER4(x + 4, 1, 0, 6, 1, 0); | |
290 | 412968 | OBMC_FILTER4(x + 6, 1, 0, 5, 2, 0); | |
291 | 412968 | x += 2 * stride; | |
292 | 412968 | OBMC_FILTER4(x , 0, 2, 5, 0, 1); | |
293 | 412968 | OBMC_FILTER4(x + 2, 0, 1, 6, 0, 1); | |
294 | 412968 | OBMC_FILTER4(x + 4, 0, 0, 6, 1, 1); | |
295 | 412968 | OBMC_FILTER4(x + 6, 0, 0, 5, 2, 1); | |
296 | 412968 | x += 2*stride; | |
297 | 412968 | OBMC_FILTER (x , 0, 2, 5, 0, 1); | |
298 | 412968 | OBMC_FILTER (x + 1, 0, 2, 5, 0, 1); | |
299 | 412968 | OBMC_FILTER4(x + 2, 0, 1, 5, 0, 2); | |
300 | 412968 | OBMC_FILTER4(x + 4, 0, 0, 5, 1, 2); | |
301 | 412968 | OBMC_FILTER (x + 6, 0, 0, 5, 2, 1); | |
302 | 412968 | OBMC_FILTER (x + 7, 0, 0, 5, 2, 1); | |
303 | 412968 | x += stride; | |
304 | 412968 | OBMC_FILTER (x , 0, 2, 4, 0, 2); | |
305 | 412968 | OBMC_FILTER (x + 1, 0, 1, 5, 0, 2); | |
306 | 412968 | OBMC_FILTER (x + 6, 0, 0, 5, 1, 2); | |
307 | 412968 | OBMC_FILTER (x + 7, 0, 0, 4, 2, 2); | |
308 | 412968 | } | |
309 | |||
310 | /* obmc for 1 8x8 luma block */ | ||
311 | 412968 | static inline void obmc_motion(MpegEncContext *s, | |
312 | uint8_t *dest, uint8_t *src, | ||
313 | int src_x, int src_y, | ||
314 | const op_pixels_func *pix_op, | ||
315 | int16_t mv[5][2] /* mid top left right bottom */) | ||
316 | #define MID 0 | ||
317 | { | ||
318 | int i; | ||
319 | uint8_t *ptr[5]; | ||
320 | |||
321 | av_assert2(s->quarter_sample == 0); | ||
322 | |||
323 |
2/2✓ Branch 0 taken 2064840 times.
✓ Branch 1 taken 412968 times.
|
2477808 | for (i = 0; i < 5; i++) { |
324 |
6/6✓ Branch 0 taken 1651872 times.
✓ Branch 1 taken 412968 times.
✓ Branch 2 taken 1342174 times.
✓ Branch 3 taken 309698 times.
✓ Branch 4 taken 1242100 times.
✓ Branch 5 taken 100074 times.
|
2064840 | if (i && mv[i][0] == mv[MID][0] && mv[i][1] == mv[MID][1]) { |
325 | 1242100 | ptr[i] = ptr[MID]; | |
326 | } else { | ||
327 | 822740 | ptr[i] = s->sc.obmc_scratchpad + 8 * (i & 1) + | |
328 | 822740 | s->linesize * 8 * (i >> 1); | |
329 | 822740 | hpel_motion(s, ptr[i], src, src_x, src_y, pix_op, | |
330 | 822740 | mv[i][0], mv[i][1]); | |
331 | } | ||
332 | } | ||
333 | |||
334 | 412968 | put_obmc(dest, ptr, s->linesize); | |
335 | 412968 | } | |
336 | |||
337 | 212765 | static inline void qpel_motion(MpegEncContext *s, | |
338 | uint8_t *dest_y, | ||
339 | uint8_t *dest_cb, | ||
340 | uint8_t *dest_cr, | ||
341 | int field_based, int bottom_field, | ||
342 | int field_select, uint8_t *const *ref_picture, | ||
343 | const op_pixels_func (*pix_op)[4], | ||
344 | const qpel_mc_func (*qpix_op)[16], | ||
345 | int motion_x, int motion_y, int h) | ||
346 | { | ||
347 | const uint8_t *ptr_y, *ptr_cb, *ptr_cr; | ||
348 | int dxy, uvdxy, mx, my, src_x, src_y, uvsrc_x, uvsrc_y, v_edge_pos; | ||
349 | ptrdiff_t linesize, uvlinesize; | ||
350 | |||
351 | 212765 | dxy = ((motion_y & 3) << 2) | (motion_x & 3); | |
352 | |||
353 | 212765 | src_x = s->mb_x * 16 + (motion_x >> 2); | |
354 | 212765 | src_y = s->mb_y * (16 >> field_based) + (motion_y >> 2); | |
355 | |||
356 | 212765 | v_edge_pos = s->v_edge_pos >> field_based; | |
357 | 212765 | linesize = s->linesize << field_based; | |
358 | 212765 | uvlinesize = s->uvlinesize << field_based; | |
359 | |||
360 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 212765 times.
|
212765 | if (field_based) { |
361 | ✗ | mx = motion_x / 2; | |
362 | ✗ | my = motion_y >> 1; | |
363 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 212765 times.
|
212765 | } else if (s->workaround_bugs & FF_BUG_QPEL_CHROMA2) { |
364 | static const int rtab[8] = { 0, 0, 1, 1, 0, 0, 0, 1 }; | ||
365 | ✗ | mx = (motion_x >> 1) + rtab[motion_x & 7]; | |
366 | ✗ | my = (motion_y >> 1) + rtab[motion_y & 7]; | |
367 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 212765 times.
|
212765 | } else if (s->workaround_bugs & FF_BUG_QPEL_CHROMA) { |
368 | ✗ | mx = (motion_x >> 1) | (motion_x & 1); | |
369 | ✗ | my = (motion_y >> 1) | (motion_y & 1); | |
370 | } else { | ||
371 | 212765 | mx = motion_x / 2; | |
372 | 212765 | my = motion_y / 2; | |
373 | } | ||
374 | 212765 | mx = (mx >> 1) | (mx & 1); | |
375 | 212765 | my = (my >> 1) | (my & 1); | |
376 | |||
377 | 212765 | uvdxy = (mx & 1) | ((my & 1) << 1); | |
378 | 212765 | mx >>= 1; | |
379 | 212765 | my >>= 1; | |
380 | |||
381 | 212765 | uvsrc_x = s->mb_x * 8 + mx; | |
382 | 212765 | uvsrc_y = s->mb_y * (8 >> field_based) + my; | |
383 | |||
384 | 212765 | ptr_y = ref_picture[0] + src_y * linesize + src_x; | |
385 | 212765 | ptr_cb = ref_picture[1] + uvsrc_y * uvlinesize + uvsrc_x; | |
386 | 212765 | ptr_cr = ref_picture[2] + uvsrc_y * uvlinesize + uvsrc_x; | |
387 | |||
388 |
3/4✓ Branch 0 taken 212765 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 203216 times.
✓ Branch 3 taken 9549 times.
|
212765 | if ((unsigned)src_x >= FFMAX(s->h_edge_pos - (motion_x & 3) - 15 , 0) || |
389 |
3/4✓ Branch 0 taken 203216 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11156 times.
✓ Branch 3 taken 192060 times.
|
203216 | (unsigned)src_y >= FFMAX( v_edge_pos - (motion_y & 3) - h + 1, 0)) { |
390 | 20705 | s->vdsp.emulated_edge_mc(s->sc.edge_emu_buffer, ptr_y, | |
391 | s->linesize, s->linesize, | ||
392 | 17, 17 + field_based, | ||
393 | src_x, src_y * (1 << field_based), | ||
394 | s->h_edge_pos, s->v_edge_pos); | ||
395 | 20705 | ptr_y = s->sc.edge_emu_buffer; | |
396 | if (!CONFIG_GRAY || !(s->avctx->flags & AV_CODEC_FLAG_GRAY)) { | ||
397 | 20705 | uint8_t *ubuf = s->sc.edge_emu_buffer + 18 * s->linesize; | |
398 | 20705 | uint8_t *vbuf = ubuf + 10 * s->uvlinesize; | |
399 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 20705 times.
|
20705 | if (s->workaround_bugs & FF_BUG_IEDGE) |
400 | ✗ | vbuf -= s->uvlinesize; | |
401 | 20705 | s->vdsp.emulated_edge_mc(ubuf, ptr_cb, | |
402 | s->uvlinesize, s->uvlinesize, | ||
403 | 9, 9 + field_based, | ||
404 | uvsrc_x, uvsrc_y * (1 << field_based), | ||
405 | 20705 | s->h_edge_pos >> 1, s->v_edge_pos >> 1); | |
406 | 20705 | s->vdsp.emulated_edge_mc(vbuf, ptr_cr, | |
407 | s->uvlinesize, s->uvlinesize, | ||
408 | 9, 9 + field_based, | ||
409 | uvsrc_x, uvsrc_y * (1 << field_based), | ||
410 | 20705 | s->h_edge_pos >> 1, s->v_edge_pos >> 1); | |
411 | 20705 | ptr_cb = ubuf; | |
412 | 20705 | ptr_cr = vbuf; | |
413 | } | ||
414 | } | ||
415 | |||
416 |
1/2✓ Branch 0 taken 212765 times.
✗ Branch 1 not taken.
|
212765 | if (!field_based) |
417 | 212765 | qpix_op[0][dxy](dest_y, ptr_y, linesize); | |
418 | else { | ||
419 | ✗ | if (bottom_field) { | |
420 | ✗ | dest_y += s->linesize; | |
421 | ✗ | dest_cb += s->uvlinesize; | |
422 | ✗ | dest_cr += s->uvlinesize; | |
423 | } | ||
424 | |||
425 | ✗ | if (field_select) { | |
426 | ✗ | ptr_y += s->linesize; | |
427 | ✗ | ptr_cb += s->uvlinesize; | |
428 | ✗ | ptr_cr += s->uvlinesize; | |
429 | } | ||
430 | // damn interlaced mode | ||
431 | // FIXME boundary mirroring is not exactly correct here | ||
432 | ✗ | qpix_op[1][dxy](dest_y, ptr_y, linesize); | |
433 | ✗ | qpix_op[1][dxy](dest_y + 8, ptr_y + 8, linesize); | |
434 | } | ||
435 | if (!CONFIG_GRAY || !(s->avctx->flags & AV_CODEC_FLAG_GRAY)) { | ||
436 | 212765 | pix_op[1][uvdxy](dest_cr, ptr_cr, uvlinesize, h >> 1); | |
437 | 212765 | pix_op[1][uvdxy](dest_cb, ptr_cb, uvlinesize, h >> 1); | |
438 | } | ||
439 | 212765 | } | |
440 | |||
441 | /** | ||
442 | * H.263 chroma 4mv motion compensation. | ||
443 | */ | ||
444 | 690103 | static void chroma_4mv_motion(MpegEncContext *s, | |
445 | uint8_t *dest_cb, uint8_t *dest_cr, | ||
446 | uint8_t *const *ref_picture, | ||
447 | const op_pixels_func *pix_op, | ||
448 | int mx, int my) | ||
449 | { | ||
450 | const uint8_t *ptr; | ||
451 | 690103 | int src_x, src_y, dxy, emu = 0; | |
452 | ptrdiff_t offset; | ||
453 | |||
454 | /* In case of 8X8, we construct a single chroma motion vector | ||
455 | * with a special rounding */ | ||
456 | 690103 | mx = ff_h263_round_chroma(mx); | |
457 | 690103 | my = ff_h263_round_chroma(my); | |
458 | |||
459 | 690103 | dxy = ((my & 1) << 1) | (mx & 1); | |
460 | 690103 | mx >>= 1; | |
461 | 690103 | my >>= 1; | |
462 | |||
463 | 690103 | src_x = s->mb_x * 8 + mx; | |
464 | 690103 | src_y = s->mb_y * 8 + my; | |
465 | 690103 | src_x = av_clip(src_x, -8, (s->width >> 1)); | |
466 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 690100 times.
|
690103 | if (src_x == (s->width >> 1)) |
467 | 3 | dxy &= ~1; | |
468 | 690103 | src_y = av_clip(src_y, -8, (s->height >> 1)); | |
469 |
2/2✓ Branch 0 taken 10 times.
✓ Branch 1 taken 690093 times.
|
690103 | if (src_y == (s->height >> 1)) |
470 | 10 | dxy &= ~2; | |
471 | |||
472 | 690103 | offset = src_y * s->uvlinesize + src_x; | |
473 | 690103 | ptr = ref_picture[1] + offset; | |
474 |
3/4✓ Branch 0 taken 690103 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 662917 times.
✓ Branch 3 taken 27186 times.
|
690103 | if ((unsigned)src_x >= FFMAX((s->h_edge_pos >> 1) - (dxy & 1) - 7, 0) || |
475 |
3/4✓ Branch 0 taken 662917 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 29016 times.
✓ Branch 3 taken 633901 times.
|
662917 | (unsigned)src_y >= FFMAX((s->v_edge_pos >> 1) - (dxy >> 1) - 7, 0)) { |
476 | 56202 | s->vdsp.emulated_edge_mc(s->sc.edge_emu_buffer, ptr, | |
477 | s->uvlinesize, s->uvlinesize, | ||
478 | 9, 9, src_x, src_y, | ||
479 | 56202 | s->h_edge_pos >> 1, s->v_edge_pos >> 1); | |
480 | 56202 | ptr = s->sc.edge_emu_buffer; | |
481 | 56202 | emu = 1; | |
482 | } | ||
483 | 690103 | pix_op[dxy](dest_cb, ptr, s->uvlinesize, 8); | |
484 | |||
485 | 690103 | ptr = ref_picture[2] + offset; | |
486 |
2/2✓ Branch 0 taken 56202 times.
✓ Branch 1 taken 633901 times.
|
690103 | if (emu) { |
487 | 56202 | s->vdsp.emulated_edge_mc(s->sc.edge_emu_buffer, ptr, | |
488 | s->uvlinesize, s->uvlinesize, | ||
489 | 9, 9, src_x, src_y, | ||
490 | 56202 | s->h_edge_pos >> 1, s->v_edge_pos >> 1); | |
491 | 56202 | ptr = s->sc.edge_emu_buffer; | |
492 | } | ||
493 | 690103 | pix_op[dxy](dest_cr, ptr, s->uvlinesize, 8); | |
494 | 690103 | } | |
495 | |||
496 | 9447578 | static inline void prefetch_motion(MpegEncContext *s, uint8_t *const *pix, int dir) | |
497 | { | ||
498 | /* fetch pixels for estimated mv 4 macroblocks ahead | ||
499 | * optimized for 64byte cache lines */ | ||
500 |
2/2✓ Branch 0 taken 339296 times.
✓ Branch 1 taken 9108282 times.
|
9447578 | const int shift = s->quarter_sample ? 2 : 1; |
501 | 9447578 | const int mx = (s->mv[dir][0][0] >> shift) + 16 * s->mb_x + 8; | |
502 | 9447578 | const int my = (s->mv[dir][0][1] >> shift) + 16 * s->mb_y; | |
503 | 9447578 | int off = mx + (my + (s->mb_x & 3) * 4) * s->linesize + 64; | |
504 | |||
505 | 9447578 | s->vdsp.prefetch(pix[0] + off, s->linesize, 4); | |
506 | 9447578 | off = (mx >> 1) + ((my >> 1) + (s->mb_x & 7)) * s->uvlinesize + 64; | |
507 | 9447578 | s->vdsp.prefetch(pix[1] + off, pix[2] - pix[1], 2); | |
508 | 9447578 | } | |
509 | |||
510 | 103242 | static inline void apply_obmc(MpegEncContext *s, | |
511 | uint8_t *dest_y, | ||
512 | uint8_t *dest_cb, | ||
513 | uint8_t *dest_cr, | ||
514 | uint8_t *const *ref_picture, | ||
515 | const op_pixels_func (*pix_op)[4]) | ||
516 | { | ||
517 | 103242 | LOCAL_ALIGNED_8(int16_t, mv_cache, [4], [4][2]); | |
518 | 103242 | const MPVWorkPicture *cur_frame = &s->cur_pic; | |
519 | 103242 | int mb_x = s->mb_x; | |
520 | 103242 | int mb_y = s->mb_y; | |
521 | 103242 | const int xy = mb_x + mb_y * s->mb_stride; | |
522 | 103242 | const int mot_stride = s->b8_stride; | |
523 | 103242 | const int mot_xy = mb_x * 2 + mb_y * 2 * mot_stride; | |
524 | int mx, my, i; | ||
525 | |||
526 | av_assert2(!s->mb_skipped); | ||
527 | |||
528 | 103242 | AV_COPY32(mv_cache[1][1], cur_frame->motion_val[0][mot_xy]); | |
529 | 103242 | AV_COPY32(mv_cache[1][2], cur_frame->motion_val[0][mot_xy + 1]); | |
530 | |||
531 | 103242 | AV_COPY32(mv_cache[2][1], | |
532 | cur_frame->motion_val[0][mot_xy + mot_stride]); | ||
533 | 103242 | AV_COPY32(mv_cache[2][2], | |
534 | cur_frame->motion_val[0][mot_xy + mot_stride + 1]); | ||
535 | |||
536 | 103242 | AV_COPY32(mv_cache[3][1], | |
537 | cur_frame->motion_val[0][mot_xy + mot_stride]); | ||
538 | 103242 | AV_COPY32(mv_cache[3][2], | |
539 | cur_frame->motion_val[0][mot_xy + mot_stride + 1]); | ||
540 | |||
541 |
4/4✓ Branch 0 taken 97570 times.
✓ Branch 1 taken 5672 times.
✓ Branch 2 taken 2068 times.
✓ Branch 3 taken 95502 times.
|
103242 | if (mb_y == 0 || IS_INTRA(cur_frame->mb_type[xy - s->mb_stride])) { |
542 | 7740 | AV_COPY32(mv_cache[0][1], mv_cache[1][1]); | |
543 | 7740 | AV_COPY32(mv_cache[0][2], mv_cache[1][2]); | |
544 | } else { | ||
545 | 95502 | AV_COPY32(mv_cache[0][1], | |
546 | cur_frame->motion_val[0][mot_xy - mot_stride]); | ||
547 | 95502 | AV_COPY32(mv_cache[0][2], | |
548 | cur_frame->motion_val[0][mot_xy - mot_stride + 1]); | ||
549 | } | ||
550 | |||
551 |
4/4✓ Branch 0 taken 98604 times.
✓ Branch 1 taken 4638 times.
✓ Branch 2 taken 1848 times.
✓ Branch 3 taken 96756 times.
|
103242 | if (mb_x == 0 || IS_INTRA(cur_frame->mb_type[xy - 1])) { |
552 | 6486 | AV_COPY32(mv_cache[1][0], mv_cache[1][1]); | |
553 | 6486 | AV_COPY32(mv_cache[2][0], mv_cache[2][1]); | |
554 | } else { | ||
555 | 96756 | AV_COPY32(mv_cache[1][0], cur_frame->motion_val[0][mot_xy - 1]); | |
556 | 96756 | AV_COPY32(mv_cache[2][0], | |
557 | cur_frame->motion_val[0][mot_xy - 1 + mot_stride]); | ||
558 | } | ||
559 | |||
560 |
4/4✓ Branch 0 taken 98684 times.
✓ Branch 1 taken 4558 times.
✓ Branch 2 taken 1971 times.
✓ Branch 3 taken 96713 times.
|
103242 | if (mb_x + 1 >= s->mb_width || IS_INTRA(cur_frame->mb_type[xy + 1])) { |
561 | 6529 | AV_COPY32(mv_cache[1][3], mv_cache[1][2]); | |
562 | 6529 | AV_COPY32(mv_cache[2][3], mv_cache[2][2]); | |
563 | } else { | ||
564 | 96713 | AV_COPY32(mv_cache[1][3], cur_frame->motion_val[0][mot_xy + 2]); | |
565 | 96713 | AV_COPY32(mv_cache[2][3], | |
566 | cur_frame->motion_val[0][mot_xy + 2 + mot_stride]); | ||
567 | } | ||
568 | |||
569 | 103242 | mx = 0; | |
570 | 103242 | my = 0; | |
571 |
2/2✓ Branch 0 taken 412968 times.
✓ Branch 1 taken 103242 times.
|
516210 | for (i = 0; i < 4; i++) { |
572 | 412968 | const int x = (i & 1) + 1; | |
573 | 412968 | const int y = (i >> 1) + 1; | |
574 | 412968 | int16_t mv[5][2] = { | |
575 | 412968 | { mv_cache[y][x][0], mv_cache[y][x][1] }, | |
576 | 412968 | { mv_cache[y - 1][x][0], mv_cache[y - 1][x][1] }, | |
577 | 412968 | { mv_cache[y][x - 1][0], mv_cache[y][x - 1][1] }, | |
578 | 412968 | { mv_cache[y][x + 1][0], mv_cache[y][x + 1][1] }, | |
579 | 412968 | { mv_cache[y + 1][x][0], mv_cache[y + 1][x][1] } | |
580 | }; | ||
581 | // FIXME cleanup | ||
582 | 412968 | obmc_motion(s, dest_y + ((i & 1) * 8) + (i >> 1) * 8 * s->linesize, | |
583 | ref_picture[0], | ||
584 | 412968 | mb_x * 16 + (i & 1) * 8, mb_y * 16 + (i >> 1) * 8, | |
585 | 412968 | pix_op[1], | |
586 | mv); | ||
587 | |||
588 | 412968 | mx += mv[0][0]; | |
589 | 412968 | my += mv[0][1]; | |
590 | } | ||
591 | if (!CONFIG_GRAY || !(s->avctx->flags & AV_CODEC_FLAG_GRAY)) | ||
592 | 103242 | chroma_4mv_motion(s, dest_cb, dest_cr, | |
593 | 103242 | ref_picture, pix_op[1], | |
594 | mx, my); | ||
595 | 103242 | } | |
596 | |||
597 | 586861 | static inline void apply_8x8(MpegEncContext *s, | |
598 | uint8_t *dest_y, | ||
599 | uint8_t *dest_cb, | ||
600 | uint8_t *dest_cr, | ||
601 | int dir, | ||
602 | uint8_t *const *ref_picture, | ||
603 | const qpel_mc_func (*qpix_op)[16], | ||
604 | const op_pixels_func (*pix_op)[4]) | ||
605 | { | ||
606 | int dxy, mx, my, src_x, src_y; | ||
607 | int i; | ||
608 | 586861 | int mb_x = s->mb_x; | |
609 | 586861 | int mb_y = s->mb_y; | |
610 | uint8_t *dest; | ||
611 | const uint8_t *ptr; | ||
612 | |||
613 | 586861 | mx = 0; | |
614 | 586861 | my = 0; | |
615 |
2/2✓ Branch 0 taken 126531 times.
✓ Branch 1 taken 460330 times.
|
586861 | if (s->quarter_sample) { |
616 |
2/2✓ Branch 0 taken 506124 times.
✓ Branch 1 taken 126531 times.
|
632655 | for (i = 0; i < 4; i++) { |
617 | 506124 | int motion_x = s->mv[dir][i][0]; | |
618 | 506124 | int motion_y = s->mv[dir][i][1]; | |
619 | |||
620 | 506124 | dxy = ((motion_y & 3) << 2) | (motion_x & 3); | |
621 | 506124 | src_x = mb_x * 16 + (motion_x >> 2) + (i & 1) * 8; | |
622 | 506124 | src_y = mb_y * 16 + (motion_y >> 2) + (i >> 1) * 8; | |
623 | |||
624 | /* WARNING: do no forget half pels */ | ||
625 | 506124 | src_x = av_clip(src_x, -16, s->width); | |
626 |
2/2✓ Branch 0 taken 698 times.
✓ Branch 1 taken 505426 times.
|
506124 | if (src_x == s->width) |
627 | 698 | dxy &= ~3; | |
628 | 506124 | src_y = av_clip(src_y, -16, s->height); | |
629 |
2/2✓ Branch 0 taken 838 times.
✓ Branch 1 taken 505286 times.
|
506124 | if (src_y == s->height) |
630 | 838 | dxy &= ~12; | |
631 | |||
632 | 506124 | ptr = ref_picture[0] + (src_y * s->linesize) + (src_x); | |
633 |
3/4✓ Branch 0 taken 506124 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 494465 times.
✓ Branch 3 taken 11659 times.
|
506124 | if ((unsigned)src_x >= FFMAX(s->h_edge_pos - (motion_x & 3) - 7, 0) || |
634 |
3/4✓ Branch 0 taken 494465 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12714 times.
✓ Branch 3 taken 481751 times.
|
494465 | (unsigned)src_y >= FFMAX(s->v_edge_pos - (motion_y & 3) - 7, 0)) { |
635 | 24373 | s->vdsp.emulated_edge_mc(s->sc.edge_emu_buffer, ptr, | |
636 | s->linesize, s->linesize, | ||
637 | 9, 9, | ||
638 | src_x, src_y, | ||
639 | s->h_edge_pos, | ||
640 | s->v_edge_pos); | ||
641 | 24373 | ptr = s->sc.edge_emu_buffer; | |
642 | } | ||
643 | 506124 | dest = dest_y + ((i & 1) * 8) + (i >> 1) * 8 * s->linesize; | |
644 | 506124 | qpix_op[1][dxy](dest, ptr, s->linesize); | |
645 | |||
646 | 506124 | mx += s->mv[dir][i][0] / 2; | |
647 | 506124 | my += s->mv[dir][i][1] / 2; | |
648 | } | ||
649 | } else { | ||
650 |
2/2✓ Branch 0 taken 1841320 times.
✓ Branch 1 taken 460330 times.
|
2301650 | for (i = 0; i < 4; i++) { |
651 | 1841320 | hpel_motion(s, | |
652 | 1841320 | dest_y + ((i & 1) * 8) + (i >> 1) * 8 * s->linesize, | |
653 | ref_picture[0], | ||
654 | 1841320 | mb_x * 16 + (i & 1) * 8, | |
655 | 1841320 | mb_y * 16 + (i >> 1) * 8, | |
656 | 1841320 | pix_op[1], | |
657 | s->mv[dir][i][0], | ||
658 | s->mv[dir][i][1]); | ||
659 | |||
660 | 1841320 | mx += s->mv[dir][i][0]; | |
661 | 1841320 | my += s->mv[dir][i][1]; | |
662 | } | ||
663 | } | ||
664 | |||
665 | if (!CONFIG_GRAY || !(s->avctx->flags & AV_CODEC_FLAG_GRAY)) | ||
666 | 586861 | chroma_4mv_motion(s, dest_cb, dest_cr, | |
667 | 586861 | ref_picture, pix_op[1], mx, my); | |
668 | 586861 | } | |
669 | |||
670 | /** | ||
671 | * motion compensation of a single macroblock | ||
672 | * @param s context | ||
673 | * @param dest_y luma destination pointer | ||
674 | * @param dest_cb chroma cb/u destination pointer | ||
675 | * @param dest_cr chroma cr/v destination pointer | ||
676 | * @param dir direction (0->forward, 1->backward) | ||
677 | * @param ref_picture array[3] of pointers to the 3 planes of the reference picture | ||
678 | * @param pix_op halfpel motion compensation function (average or put normally) | ||
679 | * @param qpix_op qpel motion compensation function (average or put normally) | ||
680 | * the motion vectors are taken from s->mv and the MV type from s->mv_type | ||
681 | */ | ||
682 | 9447578 | static av_always_inline void mpv_motion_internal(MpegEncContext *s, | |
683 | uint8_t *dest_y, | ||
684 | uint8_t *dest_cb, | ||
685 | uint8_t *dest_cr, | ||
686 | int dir, | ||
687 | uint8_t *const *ref_picture, | ||
688 | const op_pixels_func (*pix_op)[4], | ||
689 | const qpel_mc_func (*qpix_op)[16], | ||
690 | int is_mpeg12) | ||
691 | { | ||
692 | int i; | ||
693 | 9447578 | int mb_y = s->mb_y; | |
694 | |||
695 |
5/6✓ Branch 0 taken 4989860 times.
✓ Branch 1 taken 4457718 times.
✓ Branch 2 taken 103242 times.
✓ Branch 3 taken 4886618 times.
✓ Branch 4 taken 103242 times.
✗ Branch 5 not taken.
|
9447578 | if (!is_mpeg12 && s->obmc && s->pict_type != AV_PICTURE_TYPE_B) { |
696 | 103242 | apply_obmc(s, dest_y, dest_cb, dest_cr, ref_picture, pix_op); | |
697 | 103242 | return; | |
698 | } | ||
699 | |||
700 |
5/6✓ Branch 0 taken 7866745 times.
✓ Branch 1 taken 586861 times.
✓ Branch 2 taken 581034 times.
✓ Branch 3 taken 288277 times.
✓ Branch 4 taken 21419 times.
✗ Branch 5 not taken.
|
9344336 | switch (s->mv_type) { |
701 | 7866745 | case MV_TYPE_16X16: | |
702 |
3/4✓ Branch 0 taken 4299757 times.
✓ Branch 1 taken 3566988 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 4299757 times.
|
7866745 | if (CONFIG_MPEG4_DECODER && !is_mpeg12 && s->mcsel) { |
703 | ✗ | ff_mpeg4_mcsel_motion(s, dest_y, dest_cb, dest_cr, ref_picture); | |
704 |
4/4✓ Branch 0 taken 4299757 times.
✓ Branch 1 taken 3566988 times.
✓ Branch 2 taken 212765 times.
✓ Branch 3 taken 4086992 times.
|
7866745 | } else if (!is_mpeg12 && s->quarter_sample) { |
705 | 212765 | qpel_motion(s, dest_y, dest_cb, dest_cr, | |
706 | 0, 0, 0, | ||
707 | ref_picture, pix_op, qpix_op, | ||
708 | s->mv[dir][0][0], s->mv[dir][0][1], 16); | ||
709 |
2/2✓ Branch 0 taken 4086992 times.
✓ Branch 1 taken 3566988 times.
|
7653980 | } else if (!is_mpeg12 && (CONFIG_WMV2_DECODER || CONFIG_WMV2_ENCODER) && |
710 |
3/4✓ Branch 0 taken 80493 times.
✓ Branch 1 taken 4006499 times.
✓ Branch 2 taken 80493 times.
✗ Branch 3 not taken.
|
4086992 | s->mspel && s->codec_id == AV_CODEC_ID_WMV2) { |
711 | 80493 | ff_mspel_motion(s, dest_y, dest_cb, dest_cr, | |
712 | ref_picture, pix_op, | ||
713 | s->mv[dir][0][0], s->mv[dir][0][1], 16); | ||
714 | } else { | ||
715 | 7573487 | mpeg_motion(s, dest_y, dest_cb, dest_cr, 0, | |
716 | ref_picture, pix_op, | ||
717 | s->mv[dir][0][0], s->mv[dir][0][1], 16, 0, mb_y); | ||
718 | } | ||
719 | 7866745 | break; | |
720 | 586861 | case MV_TYPE_8X8: | |
721 |
1/2✓ Branch 0 taken 586861 times.
✗ Branch 1 not taken.
|
586861 | if (!is_mpeg12) |
722 | 586861 | apply_8x8(s, dest_y, dest_cb, dest_cr, | |
723 | dir, ref_picture, qpix_op, pix_op); | ||
724 | 586861 | break; | |
725 | 581034 | case MV_TYPE_FIELD: | |
726 | // Only MPEG-1/2 can have a picture_structure != PICT_FRAME here. | ||
727 | if (!CONFIG_SMALL) | ||
728 | av_assert2(is_mpeg12 || s->picture_structure == PICT_FRAME); | ||
729 |
1/2✓ Branch 0 taken 581034 times.
✗ Branch 1 not taken.
|
581034 | if ((!CONFIG_SMALL && !is_mpeg12) || |
730 |
2/2✓ Branch 0 taken 230415 times.
✓ Branch 1 taken 350619 times.
|
581034 | s->picture_structure == PICT_FRAME) { |
731 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 230415 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
230415 | if (!is_mpeg12 && s->quarter_sample) { |
732 | ✗ | for (i = 0; i < 2; i++) | |
733 | ✗ | qpel_motion(s, dest_y, dest_cb, dest_cr, | |
734 | 1, i, s->field_select[dir][i], | ||
735 | ref_picture, pix_op, qpix_op, | ||
736 | s->mv[dir][i][0], s->mv[dir][i][1], 8); | ||
737 | } else { | ||
738 | /* top field */ | ||
739 | 230415 | mpeg_motion_field(s, dest_y, dest_cb, dest_cr, | |
740 | 0, s->field_select[dir][0], | ||
741 | ref_picture, pix_op, | ||
742 | s->mv[dir][0][0], s->mv[dir][0][1], mb_y); | ||
743 | /* bottom field */ | ||
744 | 230415 | mpeg_motion_field(s, dest_y, dest_cb, dest_cr, | |
745 | 1, s->field_select[dir][1], | ||
746 | ref_picture, pix_op, | ||
747 | s->mv[dir][1][0], s->mv[dir][1][1], mb_y); | ||
748 | } | ||
749 | } else { | ||
750 | av_assert2(s->out_format == FMT_MPEG1); | ||
751 |
2/2✓ Branch 0 taken 50824 times.
✓ Branch 1 taken 299795 times.
|
350619 | if (s->picture_structure != s->field_select[dir][0] + 1 && |
752 |
4/4✓ Branch 0 taken 39816 times.
✓ Branch 1 taken 11008 times.
✓ Branch 2 taken 32006 times.
✓ Branch 3 taken 7810 times.
|
50824 | s->pict_type != AV_PICTURE_TYPE_B && !s->first_field) { |
753 | 32006 | ref_picture = s->cur_pic.ptr->f->data; | |
754 | } | ||
755 | |||
756 | 350619 | mpeg_motion(s, dest_y, dest_cb, dest_cr, | |
757 | s->field_select[dir][0], | ||
758 | ref_picture, pix_op, | ||
759 | s->mv[dir][0][0], s->mv[dir][0][1], 16, 0, mb_y >> 1); | ||
760 | } | ||
761 | 581034 | break; | |
762 | 288277 | case MV_TYPE_16X8: | |
763 |
1/2✓ Branch 0 taken 288277 times.
✗ Branch 1 not taken.
|
288277 | if (CONFIG_SMALL || is_mpeg12) { |
764 |
2/2✓ Branch 0 taken 576554 times.
✓ Branch 1 taken 288277 times.
|
864831 | for (i = 0; i < 2; i++) { |
765 | uint8_t *const *ref2picture; | ||
766 | |||
767 |
2/2✓ Branch 0 taken 77516 times.
✓ Branch 1 taken 499038 times.
|
576554 | if (s->picture_structure == s->field_select[dir][i] + 1 || |
768 |
4/4✓ Branch 0 taken 74122 times.
✓ Branch 1 taken 3394 times.
✓ Branch 2 taken 8135 times.
✓ Branch 3 taken 65987 times.
|
77516 | s->pict_type == AV_PICTURE_TYPE_B || s->first_field) { |
769 | 510567 | ref2picture = ref_picture; | |
770 | } else { | ||
771 | 65987 | ref2picture = s->cur_pic.ptr->f->data; | |
772 | } | ||
773 | |||
774 | 576554 | mpeg_motion(s, dest_y, dest_cb, dest_cr, | |
775 | s->field_select[dir][i], | ||
776 | ref2picture, pix_op, | ||
777 | s->mv[dir][i][0], s->mv[dir][i][1], | ||
778 | 576554 | 8, 1, (mb_y & ~1) + i); | |
779 | |||
780 | 576554 | dest_y += 16 * s->linesize; | |
781 | 576554 | dest_cb += (16 >> s->chroma_y_shift) * s->uvlinesize; | |
782 | 576554 | dest_cr += (16 >> s->chroma_y_shift) * s->uvlinesize; | |
783 | } | ||
784 | 288277 | break; | |
785 | } | ||
786 | case MV_TYPE_DMV: | ||
787 |
1/2✓ Branch 0 taken 21419 times.
✗ Branch 1 not taken.
|
21419 | if (CONFIG_SMALL || is_mpeg12) { |
788 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 21419 times.
|
21419 | if (s->picture_structure == PICT_FRAME) { |
789 | ✗ | for (i = 0; i < 2; i++) { | |
790 | ✗ | for (int j = 0; j < 2; j++) | |
791 | ✗ | mpeg_motion_field(s, dest_y, dest_cb, dest_cr, | |
792 | j, j ^ i, ref_picture, pix_op, | ||
793 | ✗ | s->mv[dir][2 * i + j][0], | |
794 | ✗ | s->mv[dir][2 * i + j][1], mb_y); | |
795 | ✗ | pix_op = s->hdsp.avg_pixels_tab; | |
796 | } | ||
797 | } else { | ||
798 |
2/2✓ Branch 0 taken 42838 times.
✓ Branch 1 taken 21419 times.
|
64257 | for (i = 0; i < 2; i++) { |
799 | 42838 | mpeg_motion(s, dest_y, dest_cb, dest_cr, | |
800 | 42838 | s->picture_structure != i + 1, | |
801 | ref_picture, pix_op, | ||
802 | 42838 | s->mv[dir][2 * i][0], s->mv[dir][2 * i][1], | |
803 | 16, 0, mb_y >> 1); | ||
804 | |||
805 | // after put we make avg of the same block | ||
806 | 42838 | pix_op = s->hdsp.avg_pixels_tab; | |
807 | |||
808 | /* opposite parity is always in the same frame if this is | ||
809 | * second field */ | ||
810 |
2/2✓ Branch 0 taken 36710 times.
✓ Branch 1 taken 6128 times.
|
42838 | if (!s->first_field) |
811 | 36710 | ref_picture = s->cur_pic.ptr->f->data; | |
812 | } | ||
813 | } | ||
814 | 21419 | break; | |
815 | } | ||
816 | default: av_assert2(0); | ||
817 | } | ||
818 | } | ||
819 | |||
820 | 9447578 | void ff_mpv_motion(MpegEncContext *s, | |
821 | uint8_t *dest_y, uint8_t *dest_cb, | ||
822 | uint8_t *dest_cr, int dir, | ||
823 | uint8_t *const *ref_picture, | ||
824 | const op_pixels_func (*pix_op)[4], | ||
825 | const qpel_mc_func (*qpix_op)[16]) | ||
826 | { | ||
827 | av_assert2(s->out_format == FMT_MPEG1 || | ||
828 | s->out_format == FMT_H263 || | ||
829 | s->out_format == FMT_H261); | ||
830 | 9447578 | prefetch_motion(s, ref_picture, dir); | |
831 | |||
832 | #if !CONFIG_SMALL | ||
833 |
2/2✓ Branch 0 taken 4457718 times.
✓ Branch 1 taken 4989860 times.
|
9447578 | if (s->out_format == FMT_MPEG1) |
834 | 4457718 | mpv_motion_internal(s, dest_y, dest_cb, dest_cr, dir, | |
835 | ref_picture, pix_op, qpix_op, 1); | ||
836 | else | ||
837 | #endif | ||
838 | 4989860 | mpv_motion_internal(s, dest_y, dest_cb, dest_cr, dir, | |
839 | ref_picture, pix_op, qpix_op, 0); | ||
840 | 9447578 | } | |
841 |