libavcodec/h264_direct.c
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * H.26L/H.264/AVC/JVT/14496-10/... direct mb/block decoding | ||
| 3 | * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at> | ||
| 4 | * | ||
| 5 | * This file is part of FFmpeg. | ||
| 6 | * | ||
| 7 | * FFmpeg is free software; you can redistribute it and/or | ||
| 8 | * modify it under the terms of the GNU Lesser General Public | ||
| 9 | * License as published by the Free Software Foundation; either | ||
| 10 | * version 2.1 of the License, or (at your option) any later version. | ||
| 11 | * | ||
| 12 | * FFmpeg is distributed in the hope that it will be useful, | ||
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 15 | * Lesser General Public License for more details. | ||
| 16 | * | ||
| 17 | * You should have received a copy of the GNU Lesser General Public | ||
| 18 | * License along with FFmpeg; if not, write to the Free Software | ||
| 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 20 | */ | ||
| 21 | |||
| 22 | /** | ||
| 23 | * @file | ||
| 24 | * H.264 / AVC / MPEG-4 part10 direct mb/block decoding. | ||
| 25 | * @author Michael Niedermayer <michaelni@gmx.at> | ||
| 26 | */ | ||
| 27 | |||
| 28 | #include "avcodec.h" | ||
| 29 | #include "h264dec.h" | ||
| 30 | #include "h264_ps.h" | ||
| 31 | #include "mpegutils.h" | ||
| 32 | #include "rectangle.h" | ||
| 33 | #include "threadframe.h" | ||
| 34 | |||
| 35 | #include <assert.h> | ||
| 36 | |||
| 37 | 29078 | static int get_scale_factor(const H264SliceContext *sl, | |
| 38 | int poc, int poc1, int i) | ||
| 39 | { | ||
| 40 | 29078 | int poc0 = sl->ref_list[0][i].poc; | |
| 41 | 29078 | int64_t pocdiff = poc1 - (int64_t)poc0; | |
| 42 | 29078 | int td = av_clip_int8(pocdiff); | |
| 43 | |||
| 44 | 29078 | if (pocdiff != (int)pocdiff) | |
| 45 | ✗ | avpriv_request_sample(sl->h264->avctx, "pocdiff overflow"); | |
| 46 | |||
| 47 | 29078 | if (td == 0 || sl->ref_list[0][i].parent->long_ref) { | |
| 48 | 8288 | return 256; | |
| 49 | } else { | ||
| 50 | 20790 | int64_t pocdiff0 = poc - (int64_t)poc0; | |
| 51 | 20790 | int tb = av_clip_int8(pocdiff0); | |
| 52 | 20790 | int tx = (16384 + (FFABS(td) >> 1)) / td; | |
| 53 | |||
| 54 | 20790 | if (pocdiff0 != (int)pocdiff0) | |
| 55 | ✗ | av_log(sl->h264->avctx, AV_LOG_DEBUG, "pocdiff0 overflow\n"); | |
| 56 | |||
| 57 | 20790 | return av_clip_intp2((tb * tx + 32) >> 6, 10); | |
| 58 | } | ||
| 59 | } | ||
| 60 | |||
| 61 | 7959 | void ff_h264_direct_dist_scale_factor(const H264Context *const h, | |
| 62 | H264SliceContext *sl) | ||
| 63 | { | ||
| 64 | 3612 | const int poc = FIELD_PICTURE(h) ? h->cur_pic_ptr->field_poc[h->picture_structure == PICT_BOTTOM_FIELD] | |
| 65 | 7959 | : h->cur_pic_ptr->poc; | |
| 66 | 7959 | const int poc1 = sl->ref_list[1][0].poc; | |
| 67 | int i, field; | ||
| 68 | |||
| 69 | 7959 | if (FRAME_MBAFF(h)) | |
| 70 | 1566 | for (field = 0; field < 2; field++) { | |
| 71 | 1044 | const int poc = h->cur_pic_ptr->field_poc[field]; | |
| 72 | 1044 | const int poc1 = sl->ref_list[1][0].parent->field_poc[field]; | |
| 73 | 7720 | for (i = 0; i < 2 * sl->ref_count[0]; i++) | |
| 74 | 6676 | sl->dist_scale_factor_field[field][i ^ field] = | |
| 75 | 6676 | get_scale_factor(sl, poc, poc1, i + 16); | |
| 76 | } | ||
| 77 | |||
| 78 | 30361 | for (i = 0; i < sl->ref_count[0]; i++) | |
| 79 | 22402 | sl->dist_scale_factor[i] = get_scale_factor(sl, poc, poc1, i); | |
| 80 | 7959 | } | |
| 81 | |||
| 82 | 18006 | static void fill_colmap(const H264Context *h, H264SliceContext *sl, | |
| 83 | int map[2][16 + 32], int list, | ||
| 84 | int field, int colfield, int mbafi) | ||
| 85 | { | ||
| 86 | 18006 | const H264Picture *const ref1 = sl->ref_list[1][0].parent; | |
| 87 | int j, old_ref, rfield; | ||
| 88 | 18006 | int start = mbafi ? 16 : 0; | |
| 89 | 18006 | int end = mbafi ? 16 + 2 * sl->ref_count[0] : sl->ref_count[0]; | |
| 90 | 18006 | int interl = mbafi || h->picture_structure != PICT_FRAME; | |
| 91 | |||
| 92 | /* bogus; fills in for missing frames */ | ||
| 93 | 18006 | memset(map[list], 0, sizeof(map[list])); | |
| 94 | |||
| 95 | 54018 | for (rfield = 0; rfield < 2; rfield++) { | |
| 96 | 75420 | for (old_ref = 0; old_ref < ref1->ref_count[colfield][list]; old_ref++) { | |
| 97 | 39408 | int poc = ref1->ref_poc[colfield][list][old_ref]; | |
| 98 | |||
| 99 | 39408 | if (!interl) | |
| 100 | 16960 | poc |= 3; | |
| 101 | // FIXME: store all MBAFF references so this is not needed | ||
| 102 | 22448 | else if (interl && (poc & 3) == 3) | |
| 103 | 5456 | poc = (poc & ~3) + rfield + 1; | |
| 104 | |||
| 105 | 115502 | for (j = start; j < end; j++) { | |
| 106 | 107980 | if (4 * sl->ref_list[0][j].parent->frame_num + | |
| 107 | 107980 | (sl->ref_list[0][j].reference & 3) == poc) { | |
| 108 | 31886 | int cur_ref = mbafi ? (j - 16) ^ field : j; | |
| 109 | 31886 | if (ref1->mbaff) | |
| 110 | 5826 | map[list][2 * old_ref + (rfield ^ field) + 16] = cur_ref; | |
| 111 | 31886 | if (rfield == field || !interl) | |
| 112 | 22590 | map[list][old_ref] = cur_ref; | |
| 113 | 31886 | break; | |
| 114 | } | ||
| 115 | } | ||
| 116 | } | ||
| 117 | } | ||
| 118 | 18006 | } | |
| 119 | |||
| 120 | 39187 | void ff_h264_direct_ref_list_init(const H264Context *const h, H264SliceContext *sl) | |
| 121 | { | ||
| 122 | 39187 | H264Ref *const ref1 = &sl->ref_list[1][0]; | |
| 123 | 39187 | H264Picture *const cur = h->cur_pic_ptr; | |
| 124 | int list, field; | ||
| 125 | 39187 | int sidx = (h->picture_structure & 1) ^ 1; | |
| 126 | 39187 | int ref1sidx = (ref1->reference & 1) ^ 1; | |
| 127 | |||
| 128 | /* Updates to cur_pic are not safe once ff_thread_finish_setup() has been | ||
| 129 | * called (other threads may already be reading these fields). */ | ||
| 130 | 39187 | if (!h->setup_finished) { | |
| 131 | 87573 | for (list = 0; list < sl->list_count; list++) { | |
| 132 | 48386 | cur->ref_count[sidx][list] = sl->ref_count[list]; | |
| 133 | 194589 | for (int j = 0; j < sl->ref_count[list]; j++) | |
| 134 | 146203 | cur->ref_poc[sidx][list][j] = 4 * sl->ref_list[list][j].parent->frame_num + | |
| 135 | 146203 | (sl->ref_list[list][j].reference & 3); | |
| 136 | } | ||
| 137 | |||
| 138 | 39187 | if (h->picture_structure == PICT_FRAME) { | |
| 139 | 29629 | memcpy(cur->ref_count[1], cur->ref_count[0], sizeof(cur->ref_count[0])); | |
| 140 | 29629 | memcpy(cur->ref_poc[1], cur->ref_poc[0], sizeof(cur->ref_poc[0])); | |
| 141 | } | ||
| 142 | |||
| 143 | 39187 | if (h->current_slice == 0) { | |
| 144 | 29448 | cur->mbaff = FRAME_MBAFF(h); | |
| 145 | } else { | ||
| 146 | 9739 | av_assert0(cur->mbaff == FRAME_MBAFF(h)); | |
| 147 | } | ||
| 148 | } | ||
| 149 | |||
| 150 | 39187 | sl->col_fieldoff = 0; | |
| 151 | |||
| 152 | 39187 | if (sl->list_count != 2 || !sl->ref_count[1]) | |
| 153 | 25286 | return; | |
| 154 | |||
| 155 | 13901 | if (h->picture_structure == PICT_FRAME) { | |
| 156 | 8682 | int cur_poc = h->cur_pic_ptr->poc; | |
| 157 | 8682 | const int *col_poc = sl->ref_list[1][0].parent->field_poc; | |
| 158 | 8682 | if (col_poc[0] == INT_MAX && col_poc[1] == INT_MAX) { | |
| 159 | 12 | av_log(h->avctx, AV_LOG_ERROR, "co located POCs unavailable\n"); | |
| 160 | 12 | sl->col_parity = 1; | |
| 161 | } else | ||
| 162 | 8670 | sl->col_parity = (FFABS(col_poc[0] - (int64_t)cur_poc) >= | |
| 163 | 8670 | FFABS(col_poc[1] - (int64_t)cur_poc)); | |
| 164 | 8682 | ref1sidx = | |
| 165 | 8682 | sidx = sl->col_parity; | |
| 166 | // FL -> FL & differ parity | ||
| 167 | 5219 | } else if (!(h->picture_structure & sl->ref_list[1][0].reference) && | |
| 168 | 1866 | !sl->ref_list[1][0].parent->mbaff) { | |
| 169 | 1728 | sl->col_fieldoff = 2 * sl->ref_list[1][0].reference - 3; | |
| 170 | } | ||
| 171 | |||
| 172 | 13901 | if (sl->slice_type_nos != AV_PICTURE_TYPE_B || sl->direct_spatial_mv_pred) | |
| 173 | 5942 | return; | |
| 174 | |||
| 175 | 23877 | for (list = 0; list < 2; list++) { | |
| 176 | 15918 | fill_colmap(h, sl, sl->map_col_to_list0, list, sidx, ref1sidx, 0); | |
| 177 | 15918 | if (FRAME_MBAFF(h)) | |
| 178 | 3132 | for (field = 0; field < 2; field++) | |
| 179 | 2088 | fill_colmap(h, sl, sl->map_col_to_list0_field[field], list, field, | |
| 180 | field, 1); | ||
| 181 | } | ||
| 182 | } | ||
| 183 | |||
| 184 | 4759863 | static void await_reference_mb_row(const H264Context *const h, H264Ref *ref, | |
| 185 | int mb_y) | ||
| 186 | { | ||
| 187 | 4759863 | if (!HAVE_THREADS || !(h->avctx->active_thread_type & FF_THREAD_FRAME)) | |
| 188 | 4730980 | return; | |
| 189 | |||
| 190 | 28883 | int ref_field = ref->reference - 1; | |
| 191 | 28883 | int ref_field_picture = ref->parent->field_picture; | |
| 192 | 28883 | int ref_height = 16 * h->mb_height >> ref_field_picture; | |
| 193 | 28883 | int row = FFMIN(16 * mb_y >> ref_field_picture, ref_height - 1); | |
| 194 | |||
| 195 | /* FIXME: It can be safe to access mb stuff | ||
| 196 | * even if pixels aren't deblocked yet. */ | ||
| 197 | |||
| 198 | 28883 | ff_thread_await_progress(&ref->parent->tf, row, | |
| 199 | ref_field_picture && ref_field); | ||
| 200 | |||
| 201 | /* A frame references a field pair as a whole, so the wait above covers | ||
| 202 | * its bottom field only, while the colocated data is read from the field | ||
| 203 | * selected by col_parity. The two are decoded by different threads. */ | ||
| 204 | 28883 | if (ref_field_picture && !FIELD_PICTURE(h)) | |
| 205 | ✗ | ff_thread_await_progress(&ref->parent->tf, row, 0); | |
| 206 | } | ||
| 207 | |||
| 208 | 3130301 | static void pred_spatial_direct_motion(const H264Context *const h, H264SliceContext *sl, | |
| 209 | int *mb_type) | ||
| 210 | { | ||
| 211 | 3130301 | int b8_stride = 2; | |
| 212 | 3130301 | int b4_stride = h->b_stride; | |
| 213 | 3130301 | int mb_xy = sl->mb_xy, mb_y = sl->mb_y; | |
| 214 | int mb_type_col[2]; | ||
| 215 | 3130301 | int col_field = 0; | |
| 216 | const int16_t (*l1mv0)[2], (*l1mv1)[2]; | ||
| 217 | const int8_t *l1ref0, *l1ref1; | ||
| 218 | 3130301 | const int is_b8x8 = IS_8X8(*mb_type); | |
| 219 | 3130301 | unsigned int sub_mb_type = MB_TYPE_L0L1; | |
| 220 | int i8, i4; | ||
| 221 | int ref[2]; | ||
| 222 | int mv[2]; | ||
| 223 | int list; | ||
| 224 | |||
| 225 | assert(sl->ref_list[1][0].reference & 3); | ||
| 226 | |||
| 227 | 3130301 | await_reference_mb_row(h, &sl->ref_list[1][0], | |
| 228 | 3130301 | sl->mb_y + !!IS_INTERLACED(*mb_type)); | |
| 229 | |||
| 230 | #define MB_TYPE_16x16_OR_INTRA (MB_TYPE_16x16 | MB_TYPE_INTRA4x4 | \ | ||
| 231 | MB_TYPE_INTRA16x16 | MB_TYPE_INTRA_PCM) | ||
| 232 | |||
| 233 | /* ref = min(neighbors) */ | ||
| 234 | 9390903 | for (list = 0; list < 2; list++) { | |
| 235 | 6260602 | int left_ref = sl->ref_cache[list][scan8[0] - 1]; | |
| 236 | 6260602 | int top_ref = sl->ref_cache[list][scan8[0] - 8]; | |
| 237 | 6260602 | int refc = sl->ref_cache[list][scan8[0] - 8 + 4]; | |
| 238 | 6260602 | const int16_t *C = sl->mv_cache[list][scan8[0] - 8 + 4]; | |
| 239 | 6260602 | if (refc == PART_NOT_AVAILABLE) { | |
| 240 | 767824 | refc = sl->ref_cache[list][scan8[0] - 8 - 1]; | |
| 241 | 767824 | C = sl->mv_cache[list][scan8[0] - 8 - 1]; | |
| 242 | } | ||
| 243 | 6260602 | ref[list] = FFMIN3((unsigned)left_ref, | |
| 244 | (unsigned)top_ref, | ||
| 245 | (unsigned)refc); | ||
| 246 | 6260602 | if (ref[list] >= 0) { | |
| 247 | /* This is just pred_motion() but with the cases removed that | ||
| 248 | * cannot happen for direct blocks. */ | ||
| 249 | 5744391 | const int16_t *const A = sl->mv_cache[list][scan8[0] - 1]; | |
| 250 | 5744391 | const int16_t *const B = sl->mv_cache[list][scan8[0] - 8]; | |
| 251 | |||
| 252 | 5744391 | int match_count = (left_ref == ref[list]) + | |
| 253 | 5744391 | (top_ref == ref[list]) + | |
| 254 | 5744391 | (refc == ref[list]); | |
| 255 | |||
| 256 | 5744391 | if (match_count > 1) { // most common | |
| 257 | 5096916 | mv[list] = pack16to32(mid_pred(A[0], B[0], C[0]), | |
| 258 | 5096916 | mid_pred(A[1], B[1], C[1])); | |
| 259 | } else { | ||
| 260 | assert(match_count == 1); | ||
| 261 | 647475 | if (left_ref == ref[list]) | |
| 262 | 510037 | mv[list] = AV_RN32A(A); | |
| 263 | 137438 | else if (top_ref == ref[list]) | |
| 264 | 64308 | mv[list] = AV_RN32A(B); | |
| 265 | else | ||
| 266 | 73130 | mv[list] = AV_RN32A(C); | |
| 267 | } | ||
| 268 | av_assert2(ref[list] < (sl->ref_count[list] << !!FRAME_MBAFF(h))); | ||
| 269 | } else { | ||
| 270 | 516211 | int mask = ~(MB_TYPE_L0 << (2 * list)); | |
| 271 | 516211 | mv[list] = 0; | |
| 272 | 516211 | ref[list] = -1; | |
| 273 | 516211 | if (!is_b8x8) | |
| 274 | 490080 | *mb_type &= mask; | |
| 275 | 516211 | sub_mb_type &= mask; | |
| 276 | } | ||
| 277 | } | ||
| 278 | 3130301 | if (ref[0] < 0 && ref[1] < 0) { | |
| 279 | 7118 | ref[0] = ref[1] = 0; | |
| 280 | 7118 | if (!is_b8x8) | |
| 281 | 6221 | *mb_type |= MB_TYPE_L0L1; | |
| 282 | 7118 | sub_mb_type |= MB_TYPE_L0L1; | |
| 283 | } | ||
| 284 | |||
| 285 | 3130301 | if (!(is_b8x8 | mv[0] | mv[1])) { | |
| 286 | 2005875 | fill_rectangle(&sl->ref_cache[0][scan8[0]], 4, 4, 8, (uint8_t)ref[0], 1); | |
| 287 | 2005875 | fill_rectangle(&sl->ref_cache[1][scan8[0]], 4, 4, 8, (uint8_t)ref[1], 1); | |
| 288 | 2005875 | fill_rectangle(&sl->mv_cache[0][scan8[0]], 4, 4, 8, 0, 4); | |
| 289 | 2005875 | fill_rectangle(&sl->mv_cache[1][scan8[0]], 4, 4, 8, 0, 4); | |
| 290 | 2005875 | *mb_type = (*mb_type & ~(MB_TYPE_8x8 | MB_TYPE_16x8 | MB_TYPE_8x16 | | |
| 291 | MB_TYPE_P1L0 | MB_TYPE_P1L1)) | | ||
| 292 | 2005875 | MB_TYPE_16x16 | MB_TYPE_DIRECT2; | |
| 293 | 2005875 | return; | |
| 294 | } | ||
| 295 | |||
| 296 | 1124426 | if (sl->ref_list[1][0].parent->field_picture || | |
| 297 | 466614 | IS_INTERLACED(sl->ref_list[1][0].parent->mb_type[mb_xy])) { // AFL/AFR/FR/FL -> AFL/FL | |
| 298 | 725700 | if (!IS_INTERLACED(*mb_type)) { // AFR/FR -> AFL/FL | |
| 299 | 43571 | mb_y = (sl->mb_y & ~1) + sl->col_parity; | |
| 300 | 43571 | mb_xy = sl->mb_x + | |
| 301 | 43571 | ((sl->mb_y & ~1) + sl->col_parity) * h->mb_stride; | |
| 302 | 43571 | b8_stride = 0; | |
| 303 | } else { | ||
| 304 | 682129 | mb_y += sl->col_fieldoff; | |
| 305 | 682129 | mb_xy += h->mb_stride * sl->col_fieldoff; // non-zero for FL -> FL & differ parity | |
| 306 | } | ||
| 307 | // Undecoded macroblocks of a broken field picture lack the flag, the | ||
| 308 | // colocated type has to agree with the branch taken here. | ||
| 309 | 725700 | col_field = MB_TYPE_INTERLACED; | |
| 310 | 725700 | goto single_col; | |
| 311 | } else { // AFL/AFR/FR/FL -> AFR/FR | ||
| 312 | 398726 | if (IS_INTERLACED(*mb_type)) { // AFL /FL -> AFR/FR | |
| 313 | 51346 | mb_y = sl->mb_y & ~1; | |
| 314 | 51346 | mb_xy = (sl->mb_y & ~1) * h->mb_stride + sl->mb_x; | |
| 315 | 51346 | mb_type_col[0] = sl->ref_list[1][0].parent->mb_type[mb_xy]; | |
| 316 | 51346 | mb_type_col[1] = sl->ref_list[1][0].parent->mb_type[mb_xy + h->mb_stride]; | |
| 317 | 51346 | b8_stride = 2 + 4 * h->mb_stride; | |
| 318 | 51346 | b4_stride *= 6; | |
| 319 | 51346 | if (IS_INTERLACED(mb_type_col[0]) != | |
| 320 | 51346 | IS_INTERLACED(mb_type_col[1])) { | |
| 321 | ✗ | mb_type_col[0] &= ~MB_TYPE_INTERLACED; | |
| 322 | ✗ | mb_type_col[1] &= ~MB_TYPE_INTERLACED; | |
| 323 | } | ||
| 324 | |||
| 325 | 51346 | sub_mb_type |= MB_TYPE_16x16 | MB_TYPE_DIRECT2; /* B_SUB_8x8 */ | |
| 326 | 51346 | if ((mb_type_col[0] & MB_TYPE_16x16_OR_INTRA) && | |
| 327 | 40827 | (mb_type_col[1] & MB_TYPE_16x16_OR_INTRA) && | |
| 328 | !is_b8x8) { | ||
| 329 | 32330 | *mb_type |= MB_TYPE_16x8 | MB_TYPE_DIRECT2; /* B_16x8 */ | |
| 330 | } else { | ||
| 331 | 19016 | *mb_type |= MB_TYPE_8x8; | |
| 332 | } | ||
| 333 | } else { // AFR/FR -> AFR/FR | ||
| 334 | 347380 | single_col: | |
| 335 | 1073080 | mb_type_col[0] = | |
| 336 | 1073080 | mb_type_col[1] = sl->ref_list[1][0].parent->mb_type[mb_xy] | col_field; | |
| 337 | |||
| 338 | 1073080 | sub_mb_type |= MB_TYPE_16x16 | MB_TYPE_DIRECT2; /* B_SUB_8x8 */ | |
| 339 | 1073080 | if (!is_b8x8 && (mb_type_col[0] & MB_TYPE_16x16_OR_INTRA)) { | |
| 340 | 884872 | *mb_type |= MB_TYPE_16x16 | MB_TYPE_DIRECT2; /* B_16x16 */ | |
| 341 | 188208 | } else if (!is_b8x8 && | |
| 342 | 112348 | (mb_type_col[0] & (MB_TYPE_16x8 | MB_TYPE_8x16))) { | |
| 343 | 64033 | *mb_type |= MB_TYPE_DIRECT2 | | |
| 344 | 64033 | (mb_type_col[0] & (MB_TYPE_16x8 | MB_TYPE_8x16)); | |
| 345 | } else { | ||
| 346 | 124175 | if (!h->ps.sps->direct_8x8_inference_flag) { | |
| 347 | /* FIXME: Save sub mb types from previous frames (or derive | ||
| 348 | * from MVs) so we know exactly what block size to use. */ | ||
| 349 | 21562 | sub_mb_type += (MB_TYPE_8x8 - MB_TYPE_16x16); /* B_SUB_4x4 */ | |
| 350 | } | ||
| 351 | 124175 | *mb_type |= MB_TYPE_8x8; | |
| 352 | } | ||
| 353 | } | ||
| 354 | } | ||
| 355 | |||
| 356 | 1124426 | await_reference_mb_row(h, &sl->ref_list[1][0], mb_y); | |
| 357 | |||
| 358 | 1124426 | l1mv0 = (void*)&sl->ref_list[1][0].parent->motion_val[0][h->mb2b_xy[mb_xy]]; | |
| 359 | 1124426 | l1mv1 = (void*)&sl->ref_list[1][0].parent->motion_val[1][h->mb2b_xy[mb_xy]]; | |
| 360 | 1124426 | l1ref0 = &sl->ref_list[1][0].parent->ref_index[0][4 * mb_xy]; | |
| 361 | 1124426 | l1ref1 = &sl->ref_list[1][0].parent->ref_index[1][4 * mb_xy]; | |
| 362 | 1124426 | if (!b8_stride) { | |
| 363 | 43571 | if (sl->mb_y & 1) { | |
| 364 | 22047 | l1ref0 += 2; | |
| 365 | 22047 | l1ref1 += 2; | |
| 366 | 22047 | l1mv0 += 2 * b4_stride; | |
| 367 | 22047 | l1mv1 += 2 * b4_stride; | |
| 368 | } | ||
| 369 | } | ||
| 370 | |||
| 371 | 1124426 | if (IS_INTERLACED(*mb_type) != IS_INTERLACED(mb_type_col[0])) { | |
| 372 | 94917 | int n = 0; | |
| 373 | 474585 | for (i8 = 0; i8 < 4; i8++) { | |
| 374 | 379668 | int x8 = i8 & 1; | |
| 375 | 379668 | int y8 = i8 >> 1; | |
| 376 | 379668 | int xy8 = x8 + y8 * b8_stride; | |
| 377 | 379668 | int xy4 = x8 * 3 + y8 * b4_stride; | |
| 378 | int a, b; | ||
| 379 | |||
| 380 | 379668 | if (is_b8x8 && !IS_DIRECT(sl->sub_mb_type[i8])) | |
| 381 | 27121 | continue; | |
| 382 | 352547 | sl->sub_mb_type[i8] = sub_mb_type; | |
| 383 | |||
| 384 | 352547 | fill_rectangle(&sl->ref_cache[0][scan8[i8 * 4]], 2, 2, 8, | |
| 385 | 352547 | (uint8_t)ref[0], 1); | |
| 386 | 352547 | fill_rectangle(&sl->ref_cache[1][scan8[i8 * 4]], 2, 2, 8, | |
| 387 | 352547 | (uint8_t)ref[1], 1); | |
| 388 | 352547 | if (!IS_INTRA(mb_type_col[y8]) && !sl->ref_list[1][0].parent->long_ref && | |
| 389 | 197262 | ((l1ref0[xy8] == 0 && | |
| 390 | 134513 | FFABS(l1mv0[xy4][0]) <= 1 && | |
| 391 | 10493 | FFABS(l1mv0[xy4][1]) <= 1) || | |
| 392 | 191229 | (l1ref0[xy8] < 0 && | |
| 393 | 12234 | l1ref1[xy8] == 0 && | |
| 394 | 9667 | FFABS(l1mv1[xy4][0]) <= 1 && | |
| 395 | 826 | FFABS(l1mv1[xy4][1]) <= 1))) { | |
| 396 | 6535 | a = | |
| 397 | 6535 | b = 0; | |
| 398 | 6535 | if (ref[0] > 0) | |
| 399 | 515 | a = mv[0]; | |
| 400 | 6535 | if (ref[1] > 0) | |
| 401 | 159 | b = mv[1]; | |
| 402 | 6535 | n++; | |
| 403 | } else { | ||
| 404 | 346012 | a = mv[0]; | |
| 405 | 346012 | b = mv[1]; | |
| 406 | } | ||
| 407 | 352547 | fill_rectangle(&sl->mv_cache[0][scan8[i8 * 4]], 2, 2, 8, a, 4); | |
| 408 | 352547 | fill_rectangle(&sl->mv_cache[1][scan8[i8 * 4]], 2, 2, 8, b, 4); | |
| 409 | } | ||
| 410 | 94917 | if (!is_b8x8 && !(n & 3)) | |
| 411 | 77034 | *mb_type = (*mb_type & ~(MB_TYPE_8x8 | MB_TYPE_16x8 | MB_TYPE_8x16 | | |
| 412 | MB_TYPE_P1L0 | MB_TYPE_P1L1)) | | ||
| 413 | 77034 | MB_TYPE_16x16 | MB_TYPE_DIRECT2; | |
| 414 | 1029509 | } else if (IS_16X16(*mb_type)) { | |
| 415 | int a, b; | ||
| 416 | |||
| 417 | 855958 | fill_rectangle(&sl->ref_cache[0][scan8[0]], 4, 4, 8, (uint8_t)ref[0], 1); | |
| 418 | 855958 | fill_rectangle(&sl->ref_cache[1][scan8[0]], 4, 4, 8, (uint8_t)ref[1], 1); | |
| 419 | 855958 | if (!IS_INTRA(mb_type_col[0]) && !sl->ref_list[1][0].parent->long_ref && | |
| 420 | 641784 | ((l1ref0[0] == 0 && | |
| 421 | 365778 | FFABS(l1mv0[0][0]) <= 1 && | |
| 422 | 72265 | FFABS(l1mv0[0][1]) <= 1) || | |
| 423 | 610264 | (l1ref0[0] < 0 && !l1ref1[0] && | |
| 424 | 17645 | FFABS(l1mv1[0][0]) <= 1 && | |
| 425 | 4913 | FFABS(l1mv1[0][1]) <= 1 && | |
| 426 | 4046 | h->x264_build > 33U))) { | |
| 427 | 35566 | a = b = 0; | |
| 428 | 35566 | if (ref[0] > 0) | |
| 429 | 7092 | a = mv[0]; | |
| 430 | 35566 | if (ref[1] > 0) | |
| 431 | 4747 | b = mv[1]; | |
| 432 | } else { | ||
| 433 | 820392 | a = mv[0]; | |
| 434 | 820392 | b = mv[1]; | |
| 435 | } | ||
| 436 | 855958 | fill_rectangle(&sl->mv_cache[0][scan8[0]], 4, 4, 8, a, 4); | |
| 437 | 855958 | fill_rectangle(&sl->mv_cache[1][scan8[0]], 4, 4, 8, b, 4); | |
| 438 | } else { | ||
| 439 | 173551 | int n = 0; | |
| 440 | 867755 | for (i8 = 0; i8 < 4; i8++) { | |
| 441 | 694204 | const int x8 = i8 & 1; | |
| 442 | 694204 | const int y8 = i8 >> 1; | |
| 443 | |||
| 444 | 694204 | if (is_b8x8 && !IS_DIRECT(sl->sub_mb_type[i8])) | |
| 445 | 124637 | continue; | |
| 446 | 569567 | sl->sub_mb_type[i8] = sub_mb_type; | |
| 447 | |||
| 448 | 569567 | fill_rectangle(&sl->mv_cache[0][scan8[i8 * 4]], 2, 2, 8, mv[0], 4); | |
| 449 | 569567 | fill_rectangle(&sl->mv_cache[1][scan8[i8 * 4]], 2, 2, 8, mv[1], 4); | |
| 450 | 569567 | fill_rectangle(&sl->ref_cache[0][scan8[i8 * 4]], 2, 2, 8, | |
| 451 | 569567 | (uint8_t)ref[0], 1); | |
| 452 | 569567 | fill_rectangle(&sl->ref_cache[1][scan8[i8 * 4]], 2, 2, 8, | |
| 453 | 569567 | (uint8_t)ref[1], 1); | |
| 454 | |||
| 455 | assert(b8_stride == 2); | ||
| 456 | /* col_zero_flag */ | ||
| 457 | 569567 | if (!IS_INTRA(mb_type_col[0]) && !sl->ref_list[1][0].parent->long_ref && | |
| 458 | 529560 | (l1ref0[i8] == 0 || | |
| 459 | 174359 | (l1ref0[i8] < 0 && | |
| 460 | 12456 | l1ref1[i8] == 0 && | |
| 461 | 11338 | h->x264_build > 33U))) { | |
| 462 | 366539 | const int16_t (*l1mv)[2] = l1ref0[i8] == 0 ? l1mv0 : l1mv1; | |
| 463 | 366539 | if (IS_SUB_8X8(sub_mb_type)) { | |
| 464 | 336236 | const int16_t *mv_col = l1mv[x8 * 3 + y8 * 3 * b4_stride]; | |
| 465 | 336236 | if (FFABS(mv_col[0]) <= 1 && FFABS(mv_col[1]) <= 1) { | |
| 466 | 28299 | if (ref[0] == 0) | |
| 467 | 24172 | fill_rectangle(&sl->mv_cache[0][scan8[i8 * 4]], 2, 2, | |
| 468 | 8, 0, 4); | ||
| 469 | 28299 | if (ref[1] == 0) | |
| 470 | 25827 | fill_rectangle(&sl->mv_cache[1][scan8[i8 * 4]], 2, 2, | |
| 471 | 8, 0, 4); | ||
| 472 | 28299 | n += 4; | |
| 473 | } | ||
| 474 | } else { | ||
| 475 | 30303 | int m = 0; | |
| 476 | 151515 | for (i4 = 0; i4 < 4; i4++) { | |
| 477 | 121212 | const int16_t *mv_col = l1mv[x8 * 2 + (i4 & 1) + | |
| 478 | 121212 | (y8 * 2 + (i4 >> 1)) * b4_stride]; | |
| 479 | 121212 | if (FFABS(mv_col[0]) <= 1 && FFABS(mv_col[1]) <= 1) { | |
| 480 | 3036 | if (ref[0] == 0) | |
| 481 | 2071 | AV_ZERO32(sl->mv_cache[0][scan8[i8 * 4 + i4]]); | |
| 482 | 3036 | if (ref[1] == 0) | |
| 483 | 2790 | AV_ZERO32(sl->mv_cache[1][scan8[i8 * 4 + i4]]); | |
| 484 | 3036 | m++; | |
| 485 | } | ||
| 486 | } | ||
| 487 | 30303 | if (!(m & 3)) | |
| 488 | 29990 | sl->sub_mb_type[i8] += MB_TYPE_16x16 - MB_TYPE_8x8; | |
| 489 | 30303 | n += m; | |
| 490 | } | ||
| 491 | } | ||
| 492 | } | ||
| 493 | 173551 | if (!is_b8x8 && !(n & 15)) | |
| 494 | 95855 | *mb_type = (*mb_type & ~(MB_TYPE_8x8 | MB_TYPE_16x8 | MB_TYPE_8x16 | | |
| 495 | MB_TYPE_P1L0 | MB_TYPE_P1L1)) | | ||
| 496 | 95855 | MB_TYPE_16x16 | MB_TYPE_DIRECT2; | |
| 497 | } | ||
| 498 | } | ||
| 499 | |||
| 500 | 252568 | static void pred_temp_direct_motion(const H264Context *const h, H264SliceContext *sl, | |
| 501 | int *mb_type) | ||
| 502 | { | ||
| 503 | 252568 | int b8_stride = 2; | |
| 504 | 252568 | int b4_stride = h->b_stride; | |
| 505 | 252568 | int mb_xy = sl->mb_xy, mb_y = sl->mb_y; | |
| 506 | int mb_type_col[2]; | ||
| 507 | 252568 | int col_field = 0; | |
| 508 | const int16_t (*l1mv0)[2], (*l1mv1)[2]; | ||
| 509 | const int8_t *l1ref0, *l1ref1; | ||
| 510 | 252568 | const int is_b8x8 = IS_8X8(*mb_type); | |
| 511 | unsigned int sub_mb_type; | ||
| 512 | int i8, i4; | ||
| 513 | |||
| 514 | assert(sl->ref_list[1][0].reference & 3); | ||
| 515 | |||
| 516 | 252568 | await_reference_mb_row(h, &sl->ref_list[1][0], | |
| 517 | 252568 | sl->mb_y + !!IS_INTERLACED(*mb_type)); | |
| 518 | |||
| 519 | 252568 | if (sl->ref_list[1][0].parent->field_picture || | |
| 520 | 182932 | IS_INTERLACED(sl->ref_list[1][0].parent->mb_type[mb_xy])) { // AFL/AFR/FR/FL -> AFL/FL | |
| 521 | 89484 | if (!IS_INTERLACED(*mb_type)) { // AFR/FR -> AFL/FL | |
| 522 | 15720 | mb_y = (sl->mb_y & ~1) + sl->col_parity; | |
| 523 | 15720 | mb_xy = sl->mb_x + | |
| 524 | 15720 | ((sl->mb_y & ~1) + sl->col_parity) * h->mb_stride; | |
| 525 | 15720 | b8_stride = 0; | |
| 526 | } else { | ||
| 527 | 73764 | mb_y += sl->col_fieldoff; | |
| 528 | 73764 | mb_xy += h->mb_stride * sl->col_fieldoff; // non-zero for FL -> FL & differ parity | |
| 529 | } | ||
| 530 | // Undecoded macroblocks of a broken field picture lack the flag, the | ||
| 531 | // colocated type has to agree with the branch taken here. | ||
| 532 | 89484 | col_field = MB_TYPE_INTERLACED; | |
| 533 | 89484 | goto single_col; | |
| 534 | } else { // AFL/AFR/FR/FL -> AFR/FR | ||
| 535 | 163084 | if (IS_INTERLACED(*mb_type)) { // AFL /FL -> AFR/FR | |
| 536 | 16565 | mb_y = sl->mb_y & ~1; | |
| 537 | 16565 | mb_xy = sl->mb_x + (sl->mb_y & ~1) * h->mb_stride; | |
| 538 | 16565 | mb_type_col[0] = sl->ref_list[1][0].parent->mb_type[mb_xy]; | |
| 539 | 16565 | mb_type_col[1] = sl->ref_list[1][0].parent->mb_type[mb_xy + h->mb_stride]; | |
| 540 | 16565 | b8_stride = 2 + 4 * h->mb_stride; | |
| 541 | 16565 | b4_stride *= 6; | |
| 542 | 16565 | if (IS_INTERLACED(mb_type_col[0]) != | |
| 543 | 16565 | IS_INTERLACED(mb_type_col[1])) { | |
| 544 | ✗ | mb_type_col[0] &= ~MB_TYPE_INTERLACED; | |
| 545 | ✗ | mb_type_col[1] &= ~MB_TYPE_INTERLACED; | |
| 546 | } | ||
| 547 | |||
| 548 | 16565 | sub_mb_type = MB_TYPE_16x16 | MB_TYPE_P0L0 | MB_TYPE_P0L1 | | |
| 549 | MB_TYPE_DIRECT2; /* B_SUB_8x8 */ | ||
| 550 | |||
| 551 | 16565 | if ((mb_type_col[0] & MB_TYPE_16x16_OR_INTRA) && | |
| 552 | 9903 | (mb_type_col[1] & MB_TYPE_16x16_OR_INTRA) && | |
| 553 | !is_b8x8) { | ||
| 554 | 5889 | *mb_type |= MB_TYPE_16x8 | MB_TYPE_L0L1 | | |
| 555 | MB_TYPE_DIRECT2; /* B_16x8 */ | ||
| 556 | } else { | ||
| 557 | 10676 | *mb_type |= MB_TYPE_8x8 | MB_TYPE_L0L1; | |
| 558 | } | ||
| 559 | } else { // AFR/FR -> AFR/FR | ||
| 560 | 146519 | single_col: | |
| 561 | 236003 | mb_type_col[0] = | |
| 562 | 236003 | mb_type_col[1] = sl->ref_list[1][0].parent->mb_type[mb_xy] | col_field; | |
| 563 | |||
| 564 | 236003 | sub_mb_type = MB_TYPE_16x16 | MB_TYPE_P0L0 | MB_TYPE_P0L1 | | |
| 565 | MB_TYPE_DIRECT2; /* B_SUB_8x8 */ | ||
| 566 | 236003 | if (!is_b8x8 && (mb_type_col[0] & MB_TYPE_16x16_OR_INTRA)) { | |
| 567 | 135424 | *mb_type |= MB_TYPE_16x16 | MB_TYPE_P0L0 | MB_TYPE_P0L1 | | |
| 568 | MB_TYPE_DIRECT2; /* B_16x16 */ | ||
| 569 | 100579 | } else if (!is_b8x8 && | |
| 570 | 54999 | (mb_type_col[0] & (MB_TYPE_16x8 | MB_TYPE_8x16))) { | |
| 571 | 35141 | *mb_type |= MB_TYPE_L0L1 | MB_TYPE_DIRECT2 | | |
| 572 | 35141 | (mb_type_col[0] & (MB_TYPE_16x8 | MB_TYPE_8x16)); | |
| 573 | } else { | ||
| 574 | 65438 | if (!h->ps.sps->direct_8x8_inference_flag) { | |
| 575 | /* FIXME: save sub mb types from previous frames (or derive | ||
| 576 | * from MVs) so we know exactly what block size to use */ | ||
| 577 | 10593 | sub_mb_type = MB_TYPE_8x8 | MB_TYPE_P0L0 | MB_TYPE_P0L1 | | |
| 578 | MB_TYPE_DIRECT2; /* B_SUB_4x4 */ | ||
| 579 | } | ||
| 580 | 65438 | *mb_type |= MB_TYPE_8x8 | MB_TYPE_L0L1; | |
| 581 | } | ||
| 582 | } | ||
| 583 | } | ||
| 584 | |||
| 585 | 252568 | await_reference_mb_row(h, &sl->ref_list[1][0], mb_y); | |
| 586 | |||
| 587 | 252568 | l1mv0 = (void*)&sl->ref_list[1][0].parent->motion_val[0][h->mb2b_xy[mb_xy]]; | |
| 588 | 252568 | l1mv1 = (void*)&sl->ref_list[1][0].parent->motion_val[1][h->mb2b_xy[mb_xy]]; | |
| 589 | 252568 | l1ref0 = &sl->ref_list[1][0].parent->ref_index[0][4 * mb_xy]; | |
| 590 | 252568 | l1ref1 = &sl->ref_list[1][0].parent->ref_index[1][4 * mb_xy]; | |
| 591 | 252568 | if (!b8_stride) { | |
| 592 | 15720 | if (sl->mb_y & 1) { | |
| 593 | 7767 | l1ref0 += 2; | |
| 594 | 7767 | l1ref1 += 2; | |
| 595 | 7767 | l1mv0 += 2 * b4_stride; | |
| 596 | 7767 | l1mv1 += 2 * b4_stride; | |
| 597 | } | ||
| 598 | } | ||
| 599 | |||
| 600 | { | ||
| 601 | 252568 | const int *map_col_to_list0[2] = { sl->map_col_to_list0[0], | |
| 602 | 252568 | sl->map_col_to_list0[1] }; | |
| 603 | 252568 | const int *dist_scale_factor = sl->dist_scale_factor; | |
| 604 | int ref_offset; | ||
| 605 | |||
| 606 | 252568 | if (FRAME_MBAFF(h) && IS_INTERLACED(*mb_type)) { | |
| 607 | 20468 | map_col_to_list0[0] = sl->map_col_to_list0_field[sl->mb_y & 1][0]; | |
| 608 | 20468 | map_col_to_list0[1] = sl->map_col_to_list0_field[sl->mb_y & 1][1]; | |
| 609 | 20468 | dist_scale_factor = sl->dist_scale_factor_field[sl->mb_y & 1]; | |
| 610 | } | ||
| 611 | 252568 | ref_offset = (sl->ref_list[1][0].parent->mbaff << 4) & (mb_type_col[0] >> 3); | |
| 612 | |||
| 613 | 252568 | if (IS_INTERLACED(*mb_type) != IS_INTERLACED(mb_type_col[0])) { | |
| 614 | 32285 | int y_shift = 2 * !IS_INTERLACED(*mb_type); | |
| 615 | assert(h->ps.sps->direct_8x8_inference_flag); | ||
| 616 | |||
| 617 | 161425 | for (i8 = 0; i8 < 4; i8++) { | |
| 618 | 129140 | const int x8 = i8 & 1; | |
| 619 | 129140 | const int y8 = i8 >> 1; | |
| 620 | int ref0, scale; | ||
| 621 | 129140 | const int16_t (*l1mv)[2] = l1mv0; | |
| 622 | |||
| 623 | 129140 | if (is_b8x8 && !IS_DIRECT(sl->sub_mb_type[i8])) | |
| 624 | 22674 | continue; | |
| 625 | 106466 | sl->sub_mb_type[i8] = sub_mb_type; | |
| 626 | |||
| 627 | 106466 | fill_rectangle(&sl->ref_cache[1][scan8[i8 * 4]], 2, 2, 8, 0, 1); | |
| 628 | 106466 | if (IS_INTRA(mb_type_col[y8])) { | |
| 629 | 25630 | fill_rectangle(&sl->ref_cache[0][scan8[i8 * 4]], 2, 2, 8, 0, 1); | |
| 630 | 25630 | fill_rectangle(&sl->mv_cache[0][scan8[i8 * 4]], 2, 2, 8, 0, 4); | |
| 631 | 25630 | fill_rectangle(&sl->mv_cache[1][scan8[i8 * 4]], 2, 2, 8, 0, 4); | |
| 632 | 25630 | continue; | |
| 633 | } | ||
| 634 | |||
| 635 | 80836 | ref0 = l1ref0[x8 + y8 * b8_stride]; | |
| 636 | 80836 | if (ref0 >= 0) | |
| 637 | 80643 | ref0 = map_col_to_list0[0][ref0 + ref_offset]; | |
| 638 | else { | ||
| 639 | 193 | ref0 = map_col_to_list0[1][l1ref1[x8 + y8 * b8_stride] + | |
| 640 | ref_offset]; | ||
| 641 | 193 | l1mv = l1mv1; | |
| 642 | } | ||
| 643 | 80836 | scale = dist_scale_factor[ref0]; | |
| 644 | 80836 | fill_rectangle(&sl->ref_cache[0][scan8[i8 * 4]], 2, 2, 8, | |
| 645 | ref0, 1); | ||
| 646 | |||
| 647 | { | ||
| 648 | 80836 | const int16_t *mv_col = l1mv[x8 * 3 + y8 * b4_stride]; | |
| 649 | 80836 | int my_col = (mv_col[1] * (1 << y_shift)) / 2; | |
| 650 | 80836 | int mx = (scale * mv_col[0] + 128) >> 8; | |
| 651 | 80836 | int my = (scale * my_col + 128) >> 8; | |
| 652 | 80836 | fill_rectangle(&sl->mv_cache[0][scan8[i8 * 4]], 2, 2, 8, | |
| 653 | pack16to32(mx, my), 4); | ||
| 654 | 80836 | fill_rectangle(&sl->mv_cache[1][scan8[i8 * 4]], 2, 2, 8, | |
| 655 | 80836 | pack16to32(mx - mv_col[0], my - my_col), 4); | |
| 656 | } | ||
| 657 | } | ||
| 658 | 32285 | return; | |
| 659 | } | ||
| 660 | |||
| 661 | /* one-to-one mv scaling */ | ||
| 662 | |||
| 663 | 220283 | if (IS_16X16(*mb_type)) { | |
| 664 | int ref, mv0, mv1; | ||
| 665 | |||
| 666 | 127760 | fill_rectangle(&sl->ref_cache[1][scan8[0]], 4, 4, 8, 0, 1); | |
| 667 | 127760 | if (IS_INTRA(mb_type_col[0])) { | |
| 668 | 61090 | ref = mv0 = mv1 = 0; | |
| 669 | } else { | ||
| 670 | 66619 | const int ref0 = l1ref0[0] >= 0 ? map_col_to_list0[0][l1ref0[0] + ref_offset] | |
| 671 | 66670 | : map_col_to_list0[1][l1ref1[0] + ref_offset]; | |
| 672 | 66670 | const int scale = dist_scale_factor[ref0]; | |
| 673 | 66670 | const int16_t *mv_col = l1ref0[0] >= 0 ? l1mv0[0] : l1mv1[0]; | |
| 674 | int mv_l0[2]; | ||
| 675 | 66670 | mv_l0[0] = (scale * mv_col[0] + 128) >> 8; | |
| 676 | 66670 | mv_l0[1] = (scale * mv_col[1] + 128) >> 8; | |
| 677 | 66670 | ref = ref0; | |
| 678 | 66670 | mv0 = pack16to32(mv_l0[0], mv_l0[1]); | |
| 679 | 66670 | mv1 = pack16to32(mv_l0[0] - mv_col[0], mv_l0[1] - mv_col[1]); | |
| 680 | } | ||
| 681 | 127760 | fill_rectangle(&sl->ref_cache[0][scan8[0]], 4, 4, 8, ref, 1); | |
| 682 | 127760 | fill_rectangle(&sl->mv_cache[0][scan8[0]], 4, 4, 8, mv0, 4); | |
| 683 | 127760 | fill_rectangle(&sl->mv_cache[1][scan8[0]], 4, 4, 8, mv1, 4); | |
| 684 | } else { | ||
| 685 | 462615 | for (i8 = 0; i8 < 4; i8++) { | |
| 686 | 370092 | const int x8 = i8 & 1; | |
| 687 | 370092 | const int y8 = i8 >> 1; | |
| 688 | int ref0, scale; | ||
| 689 | 370092 | const int16_t (*l1mv)[2] = l1mv0; | |
| 690 | |||
| 691 | 370092 | if (is_b8x8 && !IS_DIRECT(sl->sub_mb_type[i8])) | |
| 692 | 92478 | continue; | |
| 693 | 277614 | sl->sub_mb_type[i8] = sub_mb_type; | |
| 694 | 277614 | fill_rectangle(&sl->ref_cache[1][scan8[i8 * 4]], 2, 2, 8, 0, 1); | |
| 695 | 277614 | if (IS_INTRA(mb_type_col[0])) { | |
| 696 | 22294 | fill_rectangle(&sl->ref_cache[0][scan8[i8 * 4]], 2, 2, 8, 0, 1); | |
| 697 | 22294 | fill_rectangle(&sl->mv_cache[0][scan8[i8 * 4]], 2, 2, 8, 0, 4); | |
| 698 | 22294 | fill_rectangle(&sl->mv_cache[1][scan8[i8 * 4]], 2, 2, 8, 0, 4); | |
| 699 | 22294 | continue; | |
| 700 | } | ||
| 701 | |||
| 702 | assert(b8_stride == 2); | ||
| 703 | 255320 | ref0 = l1ref0[i8]; | |
| 704 | 255320 | if (ref0 >= 0) | |
| 705 | 255300 | ref0 = map_col_to_list0[0][ref0 + ref_offset]; | |
| 706 | else { | ||
| 707 | 20 | ref0 = map_col_to_list0[1][l1ref1[i8] + ref_offset]; | |
| 708 | 20 | l1mv = l1mv1; | |
| 709 | } | ||
| 710 | 255320 | scale = dist_scale_factor[ref0]; | |
| 711 | |||
| 712 | 255320 | fill_rectangle(&sl->ref_cache[0][scan8[i8 * 4]], 2, 2, 8, | |
| 713 | ref0, 1); | ||
| 714 | 255320 | if (IS_SUB_8X8(sub_mb_type)) { | |
| 715 | 230012 | const int16_t *mv_col = l1mv[x8 * 3 + y8 * 3 * b4_stride]; | |
| 716 | 230012 | int mx = (scale * mv_col[0] + 128) >> 8; | |
| 717 | 230012 | int my = (scale * mv_col[1] + 128) >> 8; | |
| 718 | 230012 | fill_rectangle(&sl->mv_cache[0][scan8[i8 * 4]], 2, 2, 8, | |
| 719 | pack16to32(mx, my), 4); | ||
| 720 | 230012 | fill_rectangle(&sl->mv_cache[1][scan8[i8 * 4]], 2, 2, 8, | |
| 721 | 230012 | pack16to32(mx - mv_col[0], my - mv_col[1]), 4); | |
| 722 | } else { | ||
| 723 | 126540 | for (i4 = 0; i4 < 4; i4++) { | |
| 724 | 101232 | const int16_t *mv_col = l1mv[x8 * 2 + (i4 & 1) + | |
| 725 | 101232 | (y8 * 2 + (i4 >> 1)) * b4_stride]; | |
| 726 | 101232 | int16_t *mv_l0 = sl->mv_cache[0][scan8[i8 * 4 + i4]]; | |
| 727 | 101232 | mv_l0[0] = (scale * mv_col[0] + 128) >> 8; | |
| 728 | 101232 | mv_l0[1] = (scale * mv_col[1] + 128) >> 8; | |
| 729 | 101232 | AV_WN32A(sl->mv_cache[1][scan8[i8 * 4 + i4]], | |
| 730 | pack16to32(mv_l0[0] - mv_col[0], | ||
| 731 | mv_l0[1] - mv_col[1])); | ||
| 732 | } | ||
| 733 | } | ||
| 734 | } | ||
| 735 | } | ||
| 736 | } | ||
| 737 | } | ||
| 738 | |||
| 739 | 3382869 | void ff_h264_pred_direct_motion(const H264Context *const h, H264SliceContext *sl, | |
| 740 | int *mb_type) | ||
| 741 | { | ||
| 742 | 3382869 | if (sl->direct_spatial_mv_pred) | |
| 743 | 3130301 | pred_spatial_direct_motion(h, sl, mb_type); | |
| 744 | else | ||
| 745 | 252568 | pred_temp_direct_motion(h, sl, mb_type); | |
| 746 | 3382869 | } | |
| 747 |