| 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 "wmv2dec.h" | ||
| 38 | |||
| 39 | 2661496 | 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 | 2661496 | int dxy = 0; | |
| 46 | 2661496 | int emu = 0; | |
| 47 | |||
| 48 | 2661496 | src_x += motion_x >> 1; | |
| 49 | 2661496 | src_y += motion_y >> 1; | |
| 50 | |||
| 51 | /* WARNING: do no forget half pels */ | ||
| 52 | 2661496 | src_x = av_clip(src_x, -16, s->width); // FIXME unneeded for emu? | |
| 53 |
2/2✓ Branch 0 taken 2659519 times.
✓ Branch 1 taken 1977 times.
|
2661496 | if (src_x != s->width) |
| 54 | 2659519 | dxy |= motion_x & 1; | |
| 55 | 2661496 | src_y = av_clip(src_y, -16, s->height); | |
| 56 |
2/2✓ Branch 0 taken 2659106 times.
✓ Branch 1 taken 2390 times.
|
2661496 | if (src_y != s->height) |
| 57 | 2659106 | dxy |= (motion_y & 1) << 1; | |
| 58 | 2661496 | src += src_y * s->linesize + src_x; | |
| 59 | |||
| 60 |
3/4✓ Branch 0 taken 2661496 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2618572 times.
✓ Branch 3 taken 42924 times.
|
2661496 | if ((unsigned)src_x >= FFMAX(s->h_edge_pos - (motion_x & 1) - 7, 0) || |
| 61 |
3/4✓ Branch 0 taken 2618572 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 46913 times.
✓ Branch 3 taken 2571659 times.
|
2618572 | (unsigned)src_y >= FFMAX(s->v_edge_pos - (motion_y & 1) - 7, 0)) { |
| 62 | 89837 | 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 | 89837 | src = s->sc.edge_emu_buffer; | |
| 68 | 89837 | emu = 1; | |
| 69 | } | ||
| 70 | 2661496 | pix_op[dxy](dest, src, s->linesize, 8); | |
| 71 | 2661496 | return emu; | |
| 72 | } | ||
| 73 | |||
| 74 | static av_always_inline | ||
| 75 | 9760766 | 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 | 9760766 | v_edge_pos = s->v_edge_pos >> field_based; | |
| 97 | 9760766 | linesize = s->cur_pic.linesize[0] << field_based; | |
| 98 | 9760766 | uvlinesize = s->cur_pic.linesize[1] << field_based; | |
| 99 | 9760766 | block_y_half = (field_based | is_16x8); | |
| 100 | |||
| 101 | 9760766 | dxy = ((motion_y & 1) << 1) | (motion_x & 1); | |
| 102 | 9760766 | src_x = s->mb_x * 16 + (motion_x >> 1); | |
| 103 | 9760766 | src_y = (mb_y << (4 - block_y_half)) + (motion_y >> 1); | |
| 104 | |||
| 105 |
4/4✓ Branch 0 taken 3998302 times.
✓ Branch 1 taken 5762464 times.
✓ Branch 2 taken 3791054 times.
✓ Branch 3 taken 207248 times.
|
9760766 | if (!is_mpeg12 && s->out_format == FMT_H263) { |
| 106 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 3791054 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
3791054 | 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 | 3791054 | uvdxy = dxy | (motion_y & 2) | ((motion_x & 2) >> 1); | |
| 114 | 3791054 | uvsrc_x = src_x >> 1; | |
| 115 | 3791054 | 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 5762464 times.
|
5969712 | } 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 5088570 times.
✓ Branch 1 taken 673894 times.
|
5762464 | if (s->chroma_y_shift) { |
| 129 | 5088570 | mx = motion_x / 2; | |
| 130 | 5088570 | my = motion_y / 2; | |
| 131 | 5088570 | uvdxy = ((my & 1) << 1) | (mx & 1); | |
| 132 | 5088570 | uvsrc_x = s->mb_x * 8 + (mx >> 1); | |
| 133 | 5088570 | 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 | 9760766 | ptr_y = ref_picture[0] + src_y * linesize + src_x; | |
| 151 | 9760766 | ptr_cb = ref_picture[1] + uvsrc_y * uvlinesize + uvsrc_x; | |
| 152 | 9760766 | ptr_cr = ref_picture[2] + uvsrc_y * uvlinesize + uvsrc_x; | |
| 153 | |||
| 154 |
3/4✓ Branch 0 taken 9760766 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9625418 times.
✓ Branch 3 taken 135348 times.
|
9760766 | if ((unsigned)src_x >= FFMAX(s->h_edge_pos - (motion_x & 1) - 15 , 0) || |
| 155 |
3/4✓ Branch 0 taken 9625418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 147792 times.
✓ Branch 3 taken 9477626 times.
|
9625418 | (unsigned)src_y >= FFMAX( v_edge_pos - (motion_y & 1) - h + 1, 0)) { |
| 156 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 283140 times.
|
283140 | 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 | 283140 | src_y = (unsigned)src_y << field_based; | |
| 165 | 283140 | 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 | 283140 | ptr_y = s->sc.edge_emu_buffer; | |
| 171 | if (!CONFIG_GRAY || !(s->avctx->flags & AV_CODEC_FLAG_GRAY)) { | ||
| 172 | 283140 | uint8_t *ubuf = s->sc.edge_emu_buffer + 18 * s->linesize; | |
| 173 | 283140 | uint8_t *vbuf = ubuf + 10 * s->uvlinesize; | |
| 174 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 283140 times.
|
283140 | if (s->workaround_bugs & FF_BUG_IEDGE) |
| 175 | ✗ | vbuf -= s->uvlinesize; | |
| 176 | 283140 | uvsrc_y = (unsigned)uvsrc_y << field_based; | |
| 177 | 283140 | s->vdsp.emulated_edge_mc(ubuf, ptr_cb, | |
| 178 | s->uvlinesize, s->uvlinesize, | ||
| 179 | 9, 9 + field_based, | ||
| 180 | uvsrc_x, uvsrc_y, | ||
| 181 | 283140 | s->h_edge_pos >> 1, s->v_edge_pos >> 1); | |
| 182 | 283140 | s->vdsp.emulated_edge_mc(vbuf, ptr_cr, | |
| 183 | s->uvlinesize, s->uvlinesize, | ||
| 184 | 9, 9 + field_based, | ||
| 185 | uvsrc_x, uvsrc_y, | ||
| 186 | 283140 | s->h_edge_pos >> 1, s->v_edge_pos >> 1); | |
| 187 | 283140 | ptr_cb = ubuf; | |
| 188 | 283140 | 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 262409 times.
✓ Branch 1 taken 9498357 times.
|
9760766 | if (bottom_field) { |
| 195 | 262409 | dest_y += s->linesize; | |
| 196 | 262409 | dest_cb += s->uvlinesize; | |
| 197 | 262409 | dest_cr += s->uvlinesize; | |
| 198 | } | ||
| 199 | |||
| 200 |
2/2✓ Branch 0 taken 792644 times.
✓ Branch 1 taken 8968122 times.
|
9760766 | if (field_select) { |
| 201 | 792644 | ptr_y += s->linesize; | |
| 202 | 792644 | ptr_cb += s->uvlinesize; | |
| 203 | 792644 | ptr_cr += s->uvlinesize; | |
| 204 | } | ||
| 205 | |||
| 206 | 9760766 | pix_op[0][dxy](dest_y, ptr_y, linesize, h); | |
| 207 | |||
| 208 | if (!CONFIG_GRAY || !(s->avctx->flags & AV_CODEC_FLAG_GRAY)) { | ||
| 209 | 9760766 | pix_op[s->chroma_x_shift][uvdxy] | |
| 210 | 9760766 | (dest_cb, ptr_cb, uvlinesize, h >> s->chroma_y_shift); | |
| 211 | 9760766 | pix_op[s->chroma_x_shift][uvdxy] | |
| 212 | 9760766 | (dest_cr, ptr_cr, uvlinesize, h >> s->chroma_y_shift); | |
| 213 | } | ||
| 214 |
2/2✓ Branch 0 taken 3998302 times.
✓ Branch 1 taken 5762464 times.
|
9760766 | if (!is_mpeg12 && (CONFIG_H261_ENCODER || CONFIG_H261_DECODER) && |
| 215 |
2/2✓ Branch 0 taken 207248 times.
✓ Branch 1 taken 3791054 times.
|
3998302 | 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 | 9235948 | 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 5237646 times.
✓ Branch 1 taken 3998302 times.
|
9235948 | if (s->out_format == FMT_MPEG1) |
| 228 | 5237646 | 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 | 3998302 | 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 | 9235948 | } | |
| 237 | |||
| 238 | 524818 | 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 524818 times.
✗ Branch 1 not taken.
|
524818 | if (s->out_format == FMT_MPEG1) |
| 247 | 524818 | 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 | 524818 | } | |
| 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 | 689462 | 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 | 689462 | 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 | 689462 | mx = ff_h263_round_chroma(mx); | |
| 457 | 689462 | my = ff_h263_round_chroma(my); | |
| 458 | |||
| 459 | 689462 | dxy = ((my & 1) << 1) | (mx & 1); | |
| 460 | 689462 | mx >>= 1; | |
| 461 | 689462 | my >>= 1; | |
| 462 | |||
| 463 | 689462 | src_x = s->mb_x * 8 + mx; | |
| 464 | 689462 | src_y = s->mb_y * 8 + my; | |
| 465 | 689462 | src_x = av_clip(src_x, -8, (s->width >> 1)); | |
| 466 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 689459 times.
|
689462 | if (src_x == (s->width >> 1)) |
| 467 | 3 | dxy &= ~1; | |
| 468 | 689462 | src_y = av_clip(src_y, -8, (s->height >> 1)); | |
| 469 |
2/2✓ Branch 0 taken 10 times.
✓ Branch 1 taken 689452 times.
|
689462 | if (src_y == (s->height >> 1)) |
| 470 | 10 | dxy &= ~2; | |
| 471 | |||
| 472 | 689462 | offset = src_y * s->uvlinesize + src_x; | |
| 473 | 689462 | ptr = ref_picture[1] + offset; | |
| 474 |
3/4✓ Branch 0 taken 689462 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 662309 times.
✓ Branch 3 taken 27153 times.
|
689462 | if ((unsigned)src_x >= FFMAX((s->h_edge_pos >> 1) - (dxy & 1) - 7, 0) || |
| 475 |
3/4✓ Branch 0 taken 662309 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 29000 times.
✓ Branch 3 taken 633309 times.
|
662309 | (unsigned)src_y >= FFMAX((s->v_edge_pos >> 1) - (dxy >> 1) - 7, 0)) { |
| 476 | 56153 | s->vdsp.emulated_edge_mc(s->sc.edge_emu_buffer, ptr, | |
| 477 | s->uvlinesize, s->uvlinesize, | ||
| 478 | 9, 9, src_x, src_y, | ||
| 479 | 56153 | s->h_edge_pos >> 1, s->v_edge_pos >> 1); | |
| 480 | 56153 | ptr = s->sc.edge_emu_buffer; | |
| 481 | 56153 | emu = 1; | |
| 482 | } | ||
| 483 | 689462 | pix_op[dxy](dest_cb, ptr, s->uvlinesize, 8); | |
| 484 | |||
| 485 | 689462 | ptr = ref_picture[2] + offset; | |
| 486 |
2/2✓ Branch 0 taken 56153 times.
✓ Branch 1 taken 633309 times.
|
689462 | if (emu) { |
| 487 | 56153 | s->vdsp.emulated_edge_mc(s->sc.edge_emu_buffer, ptr, | |
| 488 | s->uvlinesize, s->uvlinesize, | ||
| 489 | 9, 9, src_x, src_y, | ||
| 490 | 56153 | s->h_edge_pos >> 1, s->v_edge_pos >> 1); | |
| 491 | 56153 | ptr = s->sc.edge_emu_buffer; | |
| 492 | } | ||
| 493 | 689462 | pix_op[dxy](dest_cr, ptr, s->uvlinesize, 8); | |
| 494 | 689462 | } | |
| 495 | |||
| 496 | 10145562 | 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 9806266 times.
|
10145562 | const int shift = s->quarter_sample ? 2 : 1; |
| 501 | 10145562 | const int mx = (s->mv[dir][0][0] >> shift) + 16 * s->mb_x + 8; | |
| 502 | 10145562 | const int my = (s->mv[dir][0][1] >> shift) + 16 * s->mb_y; | |
| 503 | 10145562 | int off = mx + (my + (s->mb_x & 3) * 4) * s->linesize + 64; | |
| 504 | |||
| 505 | 10145562 | s->vdsp.prefetch(pix[0] + off, s->linesize, 4); | |
| 506 | 10145562 | off = (mx >> 1) + ((my >> 1) + (s->mb_x & 7)) * s->uvlinesize + 64; | |
| 507 | 10145562 | s->vdsp.prefetch(pix[1] + off, pix[2] - pix[1], 2); | |
| 508 | 10145562 | } | |
| 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 | 586220 | 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 | 586220 | int mb_x = s->mb_x; | |
| 609 | 586220 | int mb_y = s->mb_y; | |
| 610 | uint8_t *dest; | ||
| 611 | const uint8_t *ptr; | ||
| 612 | |||
| 613 | 586220 | mx = 0; | |
| 614 | 586220 | my = 0; | |
| 615 |
2/2✓ Branch 0 taken 126531 times.
✓ Branch 1 taken 459689 times.
|
586220 | 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 1838756 times.
✓ Branch 1 taken 459689 times.
|
2298445 | for (i = 0; i < 4; i++) { |
| 651 | 1838756 | hpel_motion(s, | |
| 652 | 1838756 | dest_y + ((i & 1) * 8) + (i >> 1) * 8 * s->linesize, | |
| 653 | ref_picture[0], | ||
| 654 | 1838756 | mb_x * 16 + (i & 1) * 8, | |
| 655 | 1838756 | mb_y * 16 + (i >> 1) * 8, | |
| 656 | 1838756 | pix_op[1], | |
| 657 | s->mv[dir][i][0], | ||
| 658 | s->mv[dir][i][1]); | ||
| 659 | |||
| 660 | 1838756 | mx += s->mv[dir][i][0]; | |
| 661 | 1838756 | my += s->mv[dir][i][1]; | |
| 662 | } | ||
| 663 | } | ||
| 664 | |||
| 665 | if (!CONFIG_GRAY || !(s->avctx->flags & AV_CODEC_FLAG_GRAY)) | ||
| 666 | 586220 | chroma_4mv_motion(s, dest_cb, dest_cr, | |
| 667 | 586220 | ref_picture, pix_op[1], mx, my); | |
| 668 | 586220 | } | |
| 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 | 10145562 | 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 | 10145562 | int mb_y = s->mb_y; | |
| 694 | |||
| 695 |
5/6✓ Branch 0 taken 4981022 times.
✓ Branch 1 taken 5164540 times.
✓ Branch 2 taken 103242 times.
✓ Branch 3 taken 4877780 times.
✓ Branch 4 taken 103242 times.
✗ Branch 5 not taken.
|
10145562 | 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 8489073 times.
✓ Branch 1 taken 586220 times.
✓ Branch 2 taken 631512 times.
✓ Branch 3 taken 312297 times.
✓ Branch 4 taken 23218 times.
✗ Branch 5 not taken.
|
10042320 | switch (s->mv_type) { |
| 701 | 8489073 | case MV_TYPE_16X16: | |
| 702 |
3/4✓ Branch 0 taken 4291560 times.
✓ Branch 1 taken 4197513 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 4291560 times.
|
8489073 | 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 4291560 times.
✓ Branch 1 taken 4197513 times.
✓ Branch 2 taken 212765 times.
✓ Branch 3 taken 4078795 times.
|
8489073 | } 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 | #if CONFIG_WMV2_DECODER | ||
| 710 |
5/6✓ Branch 0 taken 4078795 times.
✓ Branch 1 taken 4197513 times.
✓ Branch 2 taken 80493 times.
✓ Branch 3 taken 3998302 times.
✓ Branch 4 taken 80493 times.
✗ Branch 5 not taken.
|
8276308 | } else if (!is_mpeg12 && s->mspel && s->codec_id == AV_CODEC_ID_WMV2) { |
| 711 | av_assert2(av_codec_is_decoder(s->avctx->codec)); | ||
| 712 | 80493 | ff_mspel_motion(s, dest_y, dest_cb, dest_cr, | |
| 713 | ref_picture, pix_op, | ||
| 714 | s->mv[dir][0][0], s->mv[dir][0][1], 16); | ||
| 715 | #endif | ||
| 716 | } else { | ||
| 717 | 8195815 | mpeg_motion(s, dest_y, dest_cb, dest_cr, 0, | |
| 718 | ref_picture, pix_op, | ||
| 719 | s->mv[dir][0][0], s->mv[dir][0][1], 16, 0, mb_y); | ||
| 720 | } | ||
| 721 | 8489073 | break; | |
| 722 | 586220 | case MV_TYPE_8X8: | |
| 723 |
1/2✓ Branch 0 taken 586220 times.
✗ Branch 1 not taken.
|
586220 | if (!is_mpeg12) |
| 724 | 586220 | apply_8x8(s, dest_y, dest_cb, dest_cr, | |
| 725 | dir, ref_picture, qpix_op, pix_op); | ||
| 726 | 586220 | break; | |
| 727 | 631512 | case MV_TYPE_FIELD: | |
| 728 | // Only MPEG-1/2 can have a picture_structure != PICT_FRAME here. | ||
| 729 | if (!CONFIG_SMALL) | ||
| 730 | av_assert2(is_mpeg12 || s->picture_structure == PICT_FRAME); | ||
| 731 |
1/2✓ Branch 0 taken 631512 times.
✗ Branch 1 not taken.
|
631512 | if ((!CONFIG_SMALL && !is_mpeg12) || |
| 732 |
2/2✓ Branch 0 taken 262409 times.
✓ Branch 1 taken 369103 times.
|
631512 | s->picture_structure == PICT_FRAME) { |
| 733 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 262409 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
262409 | if (!is_mpeg12 && s->quarter_sample) { |
| 734 | ✗ | for (i = 0; i < 2; i++) | |
| 735 | ✗ | qpel_motion(s, dest_y, dest_cb, dest_cr, | |
| 736 | 1, i, s->field_select[dir][i], | ||
| 737 | ref_picture, pix_op, qpix_op, | ||
| 738 | s->mv[dir][i][0], s->mv[dir][i][1], 8); | ||
| 739 | } else { | ||
| 740 | /* top field */ | ||
| 741 | 262409 | mpeg_motion_field(s, dest_y, dest_cb, dest_cr, | |
| 742 | 0, s->field_select[dir][0], | ||
| 743 | ref_picture, pix_op, | ||
| 744 | s->mv[dir][0][0], s->mv[dir][0][1], mb_y); | ||
| 745 | /* bottom field */ | ||
| 746 | 262409 | mpeg_motion_field(s, dest_y, dest_cb, dest_cr, | |
| 747 | 1, s->field_select[dir][1], | ||
| 748 | ref_picture, pix_op, | ||
| 749 | s->mv[dir][1][0], s->mv[dir][1][1], mb_y); | ||
| 750 | } | ||
| 751 | } else { | ||
| 752 | av_assert2(s->out_format == FMT_MPEG1); | ||
| 753 |
2/2✓ Branch 0 taken 52428 times.
✓ Branch 1 taken 316675 times.
|
369103 | if (s->picture_structure != s->field_select[dir][0] + 1 && |
| 754 |
4/4✓ Branch 0 taken 41420 times.
✓ Branch 1 taken 11008 times.
✓ Branch 2 taken 33491 times.
✓ Branch 3 taken 7929 times.
|
52428 | s->pict_type != AV_PICTURE_TYPE_B && !s->first_field) { |
| 755 | 33491 | ref_picture = s->cur_pic.ptr->f->data; | |
| 756 | } | ||
| 757 | |||
| 758 | 369103 | mpeg_motion(s, dest_y, dest_cb, dest_cr, | |
| 759 | s->field_select[dir][0], | ||
| 760 | ref_picture, pix_op, | ||
| 761 | s->mv[dir][0][0], s->mv[dir][0][1], 16, 0, mb_y >> 1); | ||
| 762 | } | ||
| 763 | 631512 | break; | |
| 764 | 312297 | case MV_TYPE_16X8: | |
| 765 |
1/2✓ Branch 0 taken 312297 times.
✗ Branch 1 not taken.
|
312297 | if (CONFIG_SMALL || is_mpeg12) { |
| 766 |
2/2✓ Branch 0 taken 624594 times.
✓ Branch 1 taken 312297 times.
|
936891 | for (i = 0; i < 2; i++) { |
| 767 | uint8_t *const *ref2picture; | ||
| 768 | |||
| 769 |
2/2✓ Branch 0 taken 83728 times.
✓ Branch 1 taken 540866 times.
|
624594 | if (s->picture_structure == s->field_select[dir][i] + 1 || |
| 770 |
4/4✓ Branch 0 taken 80334 times.
✓ Branch 1 taken 3394 times.
✓ Branch 2 taken 8814 times.
✓ Branch 3 taken 71520 times.
|
83728 | s->pict_type == AV_PICTURE_TYPE_B || s->first_field) { |
| 771 | 553074 | ref2picture = ref_picture; | |
| 772 | } else { | ||
| 773 | 71520 | ref2picture = s->cur_pic.ptr->f->data; | |
| 774 | } | ||
| 775 | |||
| 776 | 624594 | mpeg_motion(s, dest_y, dest_cb, dest_cr, | |
| 777 | s->field_select[dir][i], | ||
| 778 | ref2picture, pix_op, | ||
| 779 | s->mv[dir][i][0], s->mv[dir][i][1], | ||
| 780 | 624594 | 8, 1, (mb_y & ~1) + i); | |
| 781 | |||
| 782 | 624594 | dest_y += 16 * s->linesize; | |
| 783 | 624594 | dest_cb += (16 >> s->chroma_y_shift) * s->uvlinesize; | |
| 784 | 624594 | dest_cr += (16 >> s->chroma_y_shift) * s->uvlinesize; | |
| 785 | } | ||
| 786 | 312297 | break; | |
| 787 | } | ||
| 788 | case MV_TYPE_DMV: | ||
| 789 |
1/2✓ Branch 0 taken 23218 times.
✗ Branch 1 not taken.
|
23218 | if (CONFIG_SMALL || is_mpeg12) { |
| 790 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 23218 times.
|
23218 | if (s->picture_structure == PICT_FRAME) { |
| 791 | ✗ | for (i = 0; i < 2; i++) { | |
| 792 | ✗ | for (int j = 0; j < 2; j++) | |
| 793 | ✗ | mpeg_motion_field(s, dest_y, dest_cb, dest_cr, | |
| 794 | j, j ^ i, ref_picture, pix_op, | ||
| 795 | ✗ | s->mv[dir][2 * i + j][0], | |
| 796 | ✗ | s->mv[dir][2 * i + j][1], mb_y); | |
| 797 | ✗ | pix_op = s->hdsp.avg_pixels_tab; | |
| 798 | } | ||
| 799 | } else { | ||
| 800 |
2/2✓ Branch 0 taken 46436 times.
✓ Branch 1 taken 23218 times.
|
69654 | for (i = 0; i < 2; i++) { |
| 801 | 46436 | mpeg_motion(s, dest_y, dest_cb, dest_cr, | |
| 802 | 46436 | s->picture_structure != i + 1, | |
| 803 | ref_picture, pix_op, | ||
| 804 | 46436 | s->mv[dir][2 * i][0], s->mv[dir][2 * i][1], | |
| 805 | 16, 0, mb_y >> 1); | ||
| 806 | |||
| 807 | // after put we make avg of the same block | ||
| 808 | 46436 | pix_op = s->hdsp.avg_pixels_tab; | |
| 809 | |||
| 810 | /* opposite parity is always in the same frame if this is | ||
| 811 | * second field */ | ||
| 812 |
2/2✓ Branch 0 taken 39748 times.
✓ Branch 1 taken 6688 times.
|
46436 | if (!s->first_field) |
| 813 | 39748 | ref_picture = s->cur_pic.ptr->f->data; | |
| 814 | } | ||
| 815 | } | ||
| 816 | 23218 | break; | |
| 817 | } | ||
| 818 | default: | ||
| 819 | ✗ | av_unreachable("No other mpegvideo MV types exist"); | |
| 820 | } | ||
| 821 | } | ||
| 822 | |||
| 823 | 10145562 | void ff_mpv_motion(MpegEncContext *s, | |
| 824 | uint8_t *dest_y, uint8_t *dest_cb, | ||
| 825 | uint8_t *dest_cr, int dir, | ||
| 826 | uint8_t *const *ref_picture, | ||
| 827 | const op_pixels_func (*pix_op)[4], | ||
| 828 | const qpel_mc_func (*qpix_op)[16]) | ||
| 829 | { | ||
| 830 | av_assert2(s->out_format == FMT_MPEG1 || | ||
| 831 | s->out_format == FMT_H263 || | ||
| 832 | s->out_format == FMT_H261); | ||
| 833 | 10145562 | prefetch_motion(s, ref_picture, dir); | |
| 834 | |||
| 835 | #if !CONFIG_SMALL | ||
| 836 |
2/2✓ Branch 0 taken 5164540 times.
✓ Branch 1 taken 4981022 times.
|
10145562 | if (s->out_format == FMT_MPEG1) |
| 837 | 5164540 | mpv_motion_internal(s, dest_y, dest_cb, dest_cr, dir, | |
| 838 | ref_picture, pix_op, qpix_op, 1); | ||
| 839 | else | ||
| 840 | #endif | ||
| 841 | 4981022 | mpv_motion_internal(s, dest_y, dest_cb, dest_cr, dir, | |
| 842 | ref_picture, pix_op, qpix_op, 0); | ||
| 843 | 10145562 | } | |
| 844 |