| 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 | 27561 | static int get_scale_factor(const H264SliceContext *sl, | |
| 38 | int poc, int poc1, int i) | ||
| 39 | { | ||
| 40 | 27561 | int poc0 = sl->ref_list[0][i].poc; | |
| 41 | 27561 | int64_t pocdiff = poc1 - (int64_t)poc0; | |
| 42 | 27561 | int td = av_clip_int8(pocdiff); | |
| 43 | |||
| 44 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 27561 times.
|
27561 | if (pocdiff != (int)pocdiff) |
| 45 | ✗ | avpriv_request_sample(sl->h264->avctx, "pocdiff overflow"); | |
| 46 | |||
| 47 |
4/4✓ Branch 0 taken 19955 times.
✓ Branch 1 taken 7606 times.
✓ Branch 2 taken 531 times.
✓ Branch 3 taken 19424 times.
|
27561 | if (td == 0 || sl->ref_list[0][i].parent->long_ref) { |
| 48 | 8137 | return 256; | |
| 49 | } else { | ||
| 50 | 19424 | int64_t pocdiff0 = poc - (int64_t)poc0; | |
| 51 | 19424 | int tb = av_clip_int8(pocdiff0); | |
| 52 | 19424 | int tx = (16384 + (FFABS(td) >> 1)) / td; | |
| 53 | |||
| 54 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 19424 times.
|
19424 | if (pocdiff0 != (int)pocdiff0) |
| 55 | ✗ | av_log(sl->h264->avctx, AV_LOG_DEBUG, "pocdiff0 overflow\n"); | |
| 56 | |||
| 57 | 19424 | return av_clip_intp2((tb * tx + 32) >> 6, 10); | |
| 58 | } | ||
| 59 | } | ||
| 60 | |||
| 61 | 7710 | void ff_h264_direct_dist_scale_factor(const H264Context *const h, | |
| 62 | H264SliceContext *sl) | ||
| 63 | { | ||
| 64 | 18808 | const int poc = FIELD_PICTURE(h) ? h->cur_pic_ptr->field_poc[h->picture_structure == PICT_BOTTOM_FIELD] | |
| 65 |
2/2✓ Branch 0 taken 3388 times.
✓ Branch 1 taken 4322 times.
|
7710 | : h->cur_pic_ptr->poc; |
| 66 | 7710 | const int poc1 = sl->ref_list[1][0].poc; | |
| 67 | int i, field; | ||
| 68 | |||
| 69 |
2/2✓ Branch 0 taken 516 times.
✓ Branch 1 taken 7194 times.
|
7710 | if (FRAME_MBAFF(h)) |
| 70 |
2/2✓ Branch 0 taken 1032 times.
✓ Branch 1 taken 516 times.
|
1548 | for (field = 0; field < 2; field++) { |
| 71 | 1032 | const int poc = h->cur_pic_ptr->field_poc[field]; | |
| 72 | 1032 | const int poc1 = sl->ref_list[1][0].parent->field_poc[field]; | |
| 73 |
2/2✓ Branch 0 taken 6604 times.
✓ Branch 1 taken 1032 times.
|
7636 | for (i = 0; i < 2 * sl->ref_count[0]; i++) |
| 74 | 6604 | sl->dist_scale_factor_field[field][i ^ field] = | |
| 75 | 6604 | get_scale_factor(sl, poc, poc1, i + 16); | |
| 76 | } | ||
| 77 | |||
| 78 |
2/2✓ Branch 0 taken 20957 times.
✓ Branch 1 taken 7710 times.
|
28667 | for (i = 0; i < sl->ref_count[0]; i++) |
| 79 | 20957 | sl->dist_scale_factor[i] = get_scale_factor(sl, poc, poc1, i); | |
| 80 | 7710 | } | |
| 81 | |||
| 82 | 17484 | 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 | 17484 | const H264Picture *const ref1 = sl->ref_list[1][0].parent; | |
| 87 | int j, old_ref, rfield; | ||
| 88 |
2/2✓ Branch 0 taken 2064 times.
✓ Branch 1 taken 15420 times.
|
17484 | int start = mbafi ? 16 : 0; |
| 89 |
2/2✓ Branch 0 taken 2064 times.
✓ Branch 1 taken 15420 times.
|
17484 | int end = mbafi ? 16 + 2 * sl->ref_count[0] : sl->ref_count[0]; |
| 90 |
4/4✓ Branch 0 taken 15420 times.
✓ Branch 1 taken 2064 times.
✓ Branch 2 taken 6776 times.
✓ Branch 3 taken 8644 times.
|
17484 | int interl = mbafi || h->picture_structure != PICT_FRAME; |
| 91 | |||
| 92 | /* bogus; fills in for missing frames */ | ||
| 93 | 17484 | memset(map[list], 0, sizeof(map[list])); | |
| 94 | |||
| 95 |
2/2✓ Branch 0 taken 34968 times.
✓ Branch 1 taken 17484 times.
|
52452 | for (rfield = 0; rfield < 2; rfield++) { |
| 96 |
2/2✓ Branch 0 taken 37254 times.
✓ Branch 1 taken 34968 times.
|
72222 | for (old_ref = 0; old_ref < ref1->ref_count[colfield][list]; old_ref++) { |
| 97 | 37254 | int poc = ref1->ref_poc[colfield][list][old_ref]; | |
| 98 | |||
| 99 |
2/2✓ Branch 0 taken 16814 times.
✓ Branch 1 taken 20440 times.
|
37254 | if (!interl) |
| 100 | 16814 | poc |= 3; | |
| 101 | // FIXME: store all MBAFF references so this is not needed | ||
| 102 |
3/4✓ Branch 0 taken 20440 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5408 times.
✓ Branch 3 taken 15032 times.
|
20440 | else if (interl && (poc & 3) == 3) |
| 103 | 5408 | poc = (poc & ~3) + rfield + 1; | |
| 104 | |||
| 105 |
2/2✓ Branch 0 taken 101342 times.
✓ Branch 1 taken 7392 times.
|
108734 | for (j = start; j < end; j++) { |
| 106 | 101342 | if (4 * sl->ref_list[0][j].parent->frame_num + | |
| 107 |
2/2✓ Branch 0 taken 29862 times.
✓ Branch 1 taken 71480 times.
|
101342 | (sl->ref_list[0][j].reference & 3) == poc) { |
| 108 |
2/2✓ Branch 0 taken 4208 times.
✓ Branch 1 taken 25654 times.
|
29862 | int cur_ref = mbafi ? (j - 16) ^ field : j; |
| 109 |
2/2✓ Branch 0 taken 5754 times.
✓ Branch 1 taken 24108 times.
|
29862 | if (ref1->mbaff) |
| 110 | 5754 | map[list][2 * old_ref + (rfield ^ field) + 16] = cur_ref; | |
| 111 |
4/4✓ Branch 0 taken 14931 times.
✓ Branch 1 taken 14931 times.
✓ Branch 2 taken 6583 times.
✓ Branch 3 taken 8348 times.
|
29862 | if (rfield == field || !interl) |
| 112 | 21514 | map[list][old_ref] = cur_ref; | |
| 113 | 29862 | break; | |
| 114 | } | ||
| 115 | } | ||
| 116 | } | ||
| 117 | } | ||
| 118 | 17484 | } | |
| 119 | |||
| 120 | 38041 | void ff_h264_direct_ref_list_init(const H264Context *const h, H264SliceContext *sl) | |
| 121 | { | ||
| 122 | 38041 | H264Ref *const ref1 = &sl->ref_list[1][0]; | |
| 123 | 38041 | H264Picture *const cur = h->cur_pic_ptr; | |
| 124 | int list, j, field; | ||
| 125 | 38041 | int sidx = (h->picture_structure & 1) ^ 1; | |
| 126 | 38041 | int ref1sidx = (ref1->reference & 1) ^ 1; | |
| 127 | |||
| 128 |
2/2✓ Branch 0 taken 47029 times.
✓ Branch 1 taken 38041 times.
|
85070 | for (list = 0; list < sl->list_count; list++) { |
| 129 | 47029 | cur->ref_count[sidx][list] = sl->ref_count[list]; | |
| 130 |
2/2✓ Branch 0 taken 142005 times.
✓ Branch 1 taken 47029 times.
|
189034 | for (j = 0; j < sl->ref_count[list]; j++) |
| 131 | 142005 | cur->ref_poc[sidx][list][j] = 4 * sl->ref_list[list][j].parent->frame_num + | |
| 132 | 142005 | (sl->ref_list[list][j].reference & 3); | |
| 133 | } | ||
| 134 | |||
| 135 |
2/2✓ Branch 0 taken 28881 times.
✓ Branch 1 taken 9160 times.
|
38041 | if (h->picture_structure == PICT_FRAME) { |
| 136 | 28881 | memcpy(cur->ref_count[1], cur->ref_count[0], sizeof(cur->ref_count[0])); | |
| 137 | 28881 | memcpy(cur->ref_poc[1], cur->ref_poc[0], sizeof(cur->ref_poc[0])); | |
| 138 | } | ||
| 139 | |||
| 140 |
2/2✓ Branch 0 taken 28867 times.
✓ Branch 1 taken 9174 times.
|
38041 | if (h->current_slice == 0) { |
| 141 | 28867 | cur->mbaff = FRAME_MBAFF(h); | |
| 142 | } else { | ||
| 143 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9174 times.
|
9174 | av_assert0(cur->mbaff == FRAME_MBAFF(h)); |
| 144 | } | ||
| 145 | |||
| 146 | 38041 | sl->col_fieldoff = 0; | |
| 147 | |||
| 148 |
3/4✓ Branch 0 taken 13472 times.
✓ Branch 1 taken 24569 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 13472 times.
|
38041 | if (sl->list_count != 2 || !sl->ref_count[1]) |
| 149 | 24569 | return; | |
| 150 | |||
| 151 |
2/2✓ Branch 0 taken 8477 times.
✓ Branch 1 taken 4995 times.
|
13472 | if (h->picture_structure == PICT_FRAME) { |
| 152 | 8477 | int cur_poc = h->cur_pic_ptr->poc; | |
| 153 | 8477 | const int *col_poc = sl->ref_list[1][0].parent->field_poc; | |
| 154 |
3/4✓ Branch 0 taken 12 times.
✓ Branch 1 taken 8465 times.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
|
8477 | if (col_poc[0] == INT_MAX && col_poc[1] == INT_MAX) { |
| 155 | 12 | av_log(h->avctx, AV_LOG_ERROR, "co located POCs unavailable\n"); | |
| 156 | 12 | sl->col_parity = 1; | |
| 157 | } else | ||
| 158 | 8465 | sl->col_parity = (FFABS(col_poc[0] - (int64_t)cur_poc) >= | |
| 159 | 8465 | FFABS(col_poc[1] - (int64_t)cur_poc)); | |
| 160 | 8477 | ref1sidx = | |
| 161 | 8477 | sidx = sl->col_parity; | |
| 162 | // FL -> FL & differ parity | ||
| 163 |
2/2✓ Branch 0 taken 1866 times.
✓ Branch 1 taken 3129 times.
|
4995 | } else if (!(h->picture_structure & sl->ref_list[1][0].reference) && |
| 164 |
2/2✓ Branch 0 taken 1728 times.
✓ Branch 1 taken 138 times.
|
1866 | !sl->ref_list[1][0].parent->mbaff) { |
| 165 | 1728 | sl->col_fieldoff = 2 * sl->ref_list[1][0].reference - 3; | |
| 166 | } | ||
| 167 | |||
| 168 |
3/4✓ Branch 0 taken 13472 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5762 times.
✓ Branch 3 taken 7710 times.
|
13472 | if (sl->slice_type_nos != AV_PICTURE_TYPE_B || sl->direct_spatial_mv_pred) |
| 169 | 5762 | return; | |
| 170 | |||
| 171 |
2/2✓ Branch 0 taken 15420 times.
✓ Branch 1 taken 7710 times.
|
23130 | for (list = 0; list < 2; list++) { |
| 172 | 15420 | fill_colmap(h, sl, sl->map_col_to_list0, list, sidx, ref1sidx, 0); | |
| 173 |
2/2✓ Branch 0 taken 1032 times.
✓ Branch 1 taken 14388 times.
|
15420 | if (FRAME_MBAFF(h)) |
| 174 |
2/2✓ Branch 0 taken 2064 times.
✓ Branch 1 taken 1032 times.
|
3096 | for (field = 0; field < 2; field++) |
| 175 | 2064 | fill_colmap(h, sl, sl->map_col_to_list0_field[field], list, field, | |
| 176 | field, 1); | ||
| 177 | } | ||
| 178 | } | ||
| 179 | |||
| 180 | 4643220 | static void await_reference_mb_row(const H264Context *const h, H264Ref *ref, | |
| 181 | int mb_y) | ||
| 182 | { | ||
| 183 | 4643220 | int ref_field = ref->reference - 1; | |
| 184 | 4643220 | int ref_field_picture = ref->parent->field_picture; | |
| 185 | 4643220 | int ref_height = 16 * h->mb_height >> ref_field_picture; | |
| 186 | |||
| 187 |
2/2✓ Branch 0 taken 4614337 times.
✓ Branch 1 taken 28883 times.
|
4643220 | if (!HAVE_THREADS || !(h->avctx->active_thread_type & FF_THREAD_FRAME)) |
| 188 | 4614337 | return; | |
| 189 | |||
| 190 | /* FIXME: It can be safe to access mb stuff | ||
| 191 | * even if pixels aren't deblocked yet. */ | ||
| 192 | |||
| 193 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 28883 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
57766 | ff_thread_await_progress(&ref->parent->tf, |
| 194 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 28883 times.
|
28883 | FFMIN(16 * mb_y >> ref_field_picture, |
| 195 | ref_height - 1), | ||
| 196 | ref_field_picture && ref_field); | ||
| 197 | } | ||
| 198 | |||
| 199 | 3037116 | static void pred_spatial_direct_motion(const H264Context *const h, H264SliceContext *sl, | |
| 200 | int *mb_type) | ||
| 201 | { | ||
| 202 | 3037116 | int b8_stride = 2; | |
| 203 | 3037116 | int b4_stride = h->b_stride; | |
| 204 | 3037116 | int mb_xy = sl->mb_xy, mb_y = sl->mb_y; | |
| 205 | int mb_type_col[2]; | ||
| 206 | const int16_t (*l1mv0)[2], (*l1mv1)[2]; | ||
| 207 | const int8_t *l1ref0, *l1ref1; | ||
| 208 | 3037116 | const int is_b8x8 = IS_8X8(*mb_type); | |
| 209 | 3037116 | unsigned int sub_mb_type = MB_TYPE_L0L1; | |
| 210 | int i8, i4; | ||
| 211 | int ref[2]; | ||
| 212 | int mv[2]; | ||
| 213 | int list; | ||
| 214 | |||
| 215 | assert(sl->ref_list[1][0].reference & 3); | ||
| 216 | |||
| 217 | 3037116 | await_reference_mb_row(h, &sl->ref_list[1][0], | |
| 218 | 3037116 | sl->mb_y + !!IS_INTERLACED(*mb_type)); | |
| 219 | |||
| 220 | #define MB_TYPE_16x16_OR_INTRA (MB_TYPE_16x16 | MB_TYPE_INTRA4x4 | \ | ||
| 221 | MB_TYPE_INTRA16x16 | MB_TYPE_INTRA_PCM) | ||
| 222 | |||
| 223 | /* ref = min(neighbors) */ | ||
| 224 |
2/2✓ Branch 0 taken 6074232 times.
✓ Branch 1 taken 3037116 times.
|
9111348 | for (list = 0; list < 2; list++) { |
| 225 | 6074232 | int left_ref = sl->ref_cache[list][scan8[0] - 1]; | |
| 226 | 6074232 | int top_ref = sl->ref_cache[list][scan8[0] - 8]; | |
| 227 | 6074232 | int refc = sl->ref_cache[list][scan8[0] - 8 + 4]; | |
| 228 | 6074232 | const int16_t *C = sl->mv_cache[list][scan8[0] - 8 + 4]; | |
| 229 |
2/2✓ Branch 0 taken 750278 times.
✓ Branch 1 taken 5323954 times.
|
6074232 | if (refc == PART_NOT_AVAILABLE) { |
| 230 | 750278 | refc = sl->ref_cache[list][scan8[0] - 8 - 1]; | |
| 231 | 750278 | C = sl->mv_cache[list][scan8[0] - 8 - 1]; | |
| 232 | } | ||
| 233 | 6074232 | ref[list] = FFMIN3((unsigned)left_ref, | |
| 234 | (unsigned)top_ref, | ||
| 235 | (unsigned)refc); | ||
| 236 |
2/2✓ Branch 0 taken 5567610 times.
✓ Branch 1 taken 506622 times.
|
6074232 | if (ref[list] >= 0) { |
| 237 | /* This is just pred_motion() but with the cases removed that | ||
| 238 | * cannot happen for direct blocks. */ | ||
| 239 | 5567610 | const int16_t *const A = sl->mv_cache[list][scan8[0] - 1]; | |
| 240 | 5567610 | const int16_t *const B = sl->mv_cache[list][scan8[0] - 8]; | |
| 241 | |||
| 242 | 5567610 | int match_count = (left_ref == ref[list]) + | |
| 243 | 5567610 | (top_ref == ref[list]) + | |
| 244 | 5567610 | (refc == ref[list]); | |
| 245 | |||
| 246 |
2/2✓ Branch 0 taken 4936895 times.
✓ Branch 1 taken 630715 times.
|
5567610 | if (match_count > 1) { // most common |
| 247 | 4936895 | mv[list] = pack16to32(mid_pred(A[0], B[0], C[0]), | |
| 248 | 4936895 | mid_pred(A[1], B[1], C[1])); | |
| 249 | } else { | ||
| 250 | assert(match_count == 1); | ||
| 251 |
2/2✓ Branch 0 taken 495507 times.
✓ Branch 1 taken 135208 times.
|
630715 | if (left_ref == ref[list]) |
| 252 | 495507 | mv[list] = AV_RN32A(A); | |
| 253 |
2/2✓ Branch 0 taken 63507 times.
✓ Branch 1 taken 71701 times.
|
135208 | else if (top_ref == ref[list]) |
| 254 | 63507 | mv[list] = AV_RN32A(B); | |
| 255 | else | ||
| 256 | 71701 | mv[list] = AV_RN32A(C); | |
| 257 | } | ||
| 258 | av_assert2(ref[list] < (sl->ref_count[list] << !!FRAME_MBAFF(h))); | ||
| 259 | } else { | ||
| 260 | 506622 | int mask = ~(MB_TYPE_L0 << (2 * list)); | |
| 261 | 506622 | mv[list] = 0; | |
| 262 | 506622 | ref[list] = -1; | |
| 263 |
2/2✓ Branch 0 taken 480643 times.
✓ Branch 1 taken 25979 times.
|
506622 | if (!is_b8x8) |
| 264 | 480643 | *mb_type &= mask; | |
| 265 | 506622 | sub_mb_type &= mask; | |
| 266 | } | ||
| 267 | } | ||
| 268 |
4/4✓ Branch 0 taken 251709 times.
✓ Branch 1 taken 2785407 times.
✓ Branch 2 taken 6914 times.
✓ Branch 3 taken 244795 times.
|
3037116 | if (ref[0] < 0 && ref[1] < 0) { |
| 269 | 6914 | ref[0] = ref[1] = 0; | |
| 270 |
2/2✓ Branch 0 taken 6022 times.
✓ Branch 1 taken 892 times.
|
6914 | if (!is_b8x8) |
| 271 | 6022 | *mb_type |= MB_TYPE_L0L1; | |
| 272 | 6914 | sub_mb_type |= MB_TYPE_L0L1; | |
| 273 | } | ||
| 274 | |||
| 275 |
2/2✓ Branch 0 taken 1936050 times.
✓ Branch 1 taken 1101066 times.
|
3037116 | if (!(is_b8x8 | mv[0] | mv[1])) { |
| 276 | 1936050 | fill_rectangle(&sl->ref_cache[0][scan8[0]], 4, 4, 8, (uint8_t)ref[0], 1); | |
| 277 | 1936050 | fill_rectangle(&sl->ref_cache[1][scan8[0]], 4, 4, 8, (uint8_t)ref[1], 1); | |
| 278 | 1936050 | fill_rectangle(&sl->mv_cache[0][scan8[0]], 4, 4, 8, 0, 4); | |
| 279 | 1936050 | fill_rectangle(&sl->mv_cache[1][scan8[0]], 4, 4, 8, 0, 4); | |
| 280 | 1936050 | *mb_type = (*mb_type & ~(MB_TYPE_8x8 | MB_TYPE_16x8 | MB_TYPE_8x16 | | |
| 281 | MB_TYPE_P1L0 | MB_TYPE_P1L1)) | | ||
| 282 | 1936050 | MB_TYPE_16x16 | MB_TYPE_DIRECT2; | |
| 283 | 1936050 | return; | |
| 284 | } | ||
| 285 | |||
| 286 |
2/2✓ Branch 0 taken 725700 times.
✓ Branch 1 taken 375366 times.
|
1101066 | if (IS_INTERLACED(sl->ref_list[1][0].parent->mb_type[mb_xy])) { // AFL/AFR/FR/FL -> AFL/FL |
| 287 |
2/2✓ Branch 0 taken 43571 times.
✓ Branch 1 taken 682129 times.
|
725700 | if (!IS_INTERLACED(*mb_type)) { // AFR/FR -> AFL/FL |
| 288 | 43571 | mb_y = (sl->mb_y & ~1) + sl->col_parity; | |
| 289 | 43571 | mb_xy = sl->mb_x + | |
| 290 | 43571 | ((sl->mb_y & ~1) + sl->col_parity) * h->mb_stride; | |
| 291 | 43571 | b8_stride = 0; | |
| 292 | } else { | ||
| 293 | 682129 | mb_y += sl->col_fieldoff; | |
| 294 | 682129 | mb_xy += h->mb_stride * sl->col_fieldoff; // non-zero for FL -> FL & differ parity | |
| 295 | } | ||
| 296 | 725700 | goto single_col; | |
| 297 | } else { // AFL/AFR/FR/FL -> AFR/FR | ||
| 298 |
2/2✓ Branch 0 taken 51346 times.
✓ Branch 1 taken 324020 times.
|
375366 | if (IS_INTERLACED(*mb_type)) { // AFL /FL -> AFR/FR |
| 299 | 51346 | mb_y = sl->mb_y & ~1; | |
| 300 | 51346 | mb_xy = (sl->mb_y & ~1) * h->mb_stride + sl->mb_x; | |
| 301 | 51346 | mb_type_col[0] = sl->ref_list[1][0].parent->mb_type[mb_xy]; | |
| 302 | 51346 | mb_type_col[1] = sl->ref_list[1][0].parent->mb_type[mb_xy + h->mb_stride]; | |
| 303 | 51346 | b8_stride = 2 + 4 * h->mb_stride; | |
| 304 | 51346 | b4_stride *= 6; | |
| 305 | 51346 | if (IS_INTERLACED(mb_type_col[0]) != | |
| 306 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 51346 times.
|
51346 | IS_INTERLACED(mb_type_col[1])) { |
| 307 | ✗ | mb_type_col[0] &= ~MB_TYPE_INTERLACED; | |
| 308 | ✗ | mb_type_col[1] &= ~MB_TYPE_INTERLACED; | |
| 309 | } | ||
| 310 | |||
| 311 | 51346 | sub_mb_type |= MB_TYPE_16x16 | MB_TYPE_DIRECT2; /* B_SUB_8x8 */ | |
| 312 |
2/2✓ Branch 0 taken 40827 times.
✓ Branch 1 taken 10519 times.
|
51346 | if ((mb_type_col[0] & MB_TYPE_16x16_OR_INTRA) && |
| 313 |
4/4✓ Branch 0 taken 35974 times.
✓ Branch 1 taken 4853 times.
✓ Branch 2 taken 32330 times.
✓ Branch 3 taken 3644 times.
|
40827 | (mb_type_col[1] & MB_TYPE_16x16_OR_INTRA) && |
| 314 | !is_b8x8) { | ||
| 315 | 32330 | *mb_type |= MB_TYPE_16x8 | MB_TYPE_DIRECT2; /* B_16x8 */ | |
| 316 | } else { | ||
| 317 | 19016 | *mb_type |= MB_TYPE_8x8; | |
| 318 | } | ||
| 319 | } else { // AFR/FR -> AFR/FR | ||
| 320 | 324020 | single_col: | |
| 321 | 1049720 | mb_type_col[0] = | |
| 322 | 1049720 | mb_type_col[1] = sl->ref_list[1][0].parent->mb_type[mb_xy]; | |
| 323 | |||
| 324 | 1049720 | sub_mb_type |= MB_TYPE_16x16 | MB_TYPE_DIRECT2; /* B_SUB_8x8 */ | |
| 325 |
4/4✓ Branch 0 taken 974415 times.
✓ Branch 1 taken 75305 times.
✓ Branch 2 taken 869032 times.
✓ Branch 3 taken 105383 times.
|
1049720 | if (!is_b8x8 && (mb_type_col[0] & MB_TYPE_16x16_OR_INTRA)) { |
| 326 | 869032 | *mb_type |= MB_TYPE_16x16 | MB_TYPE_DIRECT2; /* B_16x16 */ | |
| 327 |
2/2✓ Branch 0 taken 105383 times.
✓ Branch 1 taken 75305 times.
|
180688 | } else if (!is_b8x8 && |
| 328 |
2/2✓ Branch 0 taken 59302 times.
✓ Branch 1 taken 46081 times.
|
105383 | (mb_type_col[0] & (MB_TYPE_16x8 | MB_TYPE_8x16))) { |
| 329 | 59302 | *mb_type |= MB_TYPE_DIRECT2 | | |
| 330 | 59302 | (mb_type_col[0] & (MB_TYPE_16x8 | MB_TYPE_8x16)); | |
| 331 | } else { | ||
| 332 |
2/2✓ Branch 0 taken 21562 times.
✓ Branch 1 taken 99824 times.
|
121386 | if (!h->ps.sps->direct_8x8_inference_flag) { |
| 333 | /* FIXME: Save sub mb types from previous frames (or derive | ||
| 334 | * from MVs) so we know exactly what block size to use. */ | ||
| 335 | 21562 | sub_mb_type += (MB_TYPE_8x8 - MB_TYPE_16x16); /* B_SUB_4x4 */ | |
| 336 | } | ||
| 337 | 121386 | *mb_type |= MB_TYPE_8x8; | |
| 338 | } | ||
| 339 | } | ||
| 340 | } | ||
| 341 | |||
| 342 | 1101066 | await_reference_mb_row(h, &sl->ref_list[1][0], mb_y); | |
| 343 | |||
| 344 | 1101066 | l1mv0 = (void*)&sl->ref_list[1][0].parent->motion_val[0][h->mb2b_xy[mb_xy]]; | |
| 345 | 1101066 | l1mv1 = (void*)&sl->ref_list[1][0].parent->motion_val[1][h->mb2b_xy[mb_xy]]; | |
| 346 | 1101066 | l1ref0 = &sl->ref_list[1][0].parent->ref_index[0][4 * mb_xy]; | |
| 347 | 1101066 | l1ref1 = &sl->ref_list[1][0].parent->ref_index[1][4 * mb_xy]; | |
| 348 |
2/2✓ Branch 0 taken 43571 times.
✓ Branch 1 taken 1057495 times.
|
1101066 | if (!b8_stride) { |
| 349 |
2/2✓ Branch 0 taken 22047 times.
✓ Branch 1 taken 21524 times.
|
43571 | if (sl->mb_y & 1) { |
| 350 | 22047 | l1ref0 += 2; | |
| 351 | 22047 | l1ref1 += 2; | |
| 352 | 22047 | l1mv0 += 2 * b4_stride; | |
| 353 | 22047 | l1mv1 += 2 * b4_stride; | |
| 354 | } | ||
| 355 | } | ||
| 356 | |||
| 357 |
2/2✓ Branch 0 taken 94917 times.
✓ Branch 1 taken 1006149 times.
|
1101066 | if (IS_INTERLACED(*mb_type) != IS_INTERLACED(mb_type_col[0])) { |
| 358 | 94917 | int n = 0; | |
| 359 |
2/2✓ Branch 0 taken 379668 times.
✓ Branch 1 taken 94917 times.
|
474585 | for (i8 = 0; i8 < 4; i8++) { |
| 360 | 379668 | int x8 = i8 & 1; | |
| 361 | 379668 | int y8 = i8 >> 1; | |
| 362 | 379668 | int xy8 = x8 + y8 * b8_stride; | |
| 363 | 379668 | int xy4 = x8 * 3 + y8 * b4_stride; | |
| 364 | int a, b; | ||
| 365 | |||
| 366 |
4/4✓ Branch 0 taken 66816 times.
✓ Branch 1 taken 312852 times.
✓ Branch 2 taken 27121 times.
✓ Branch 3 taken 39695 times.
|
379668 | if (is_b8x8 && !IS_DIRECT(sl->sub_mb_type[i8])) |
| 367 | 27121 | continue; | |
| 368 | 352547 | sl->sub_mb_type[i8] = sub_mb_type; | |
| 369 | |||
| 370 | 352547 | fill_rectangle(&sl->ref_cache[0][scan8[i8 * 4]], 2, 2, 8, | |
| 371 | 352547 | (uint8_t)ref[0], 1); | |
| 372 | 352547 | fill_rectangle(&sl->ref_cache[1][scan8[i8 * 4]], 2, 2, 8, | |
| 373 | 352547 | (uint8_t)ref[1], 1); | |
| 374 |
3/4✓ Branch 0 taken 197262 times.
✓ Branch 1 taken 155285 times.
✓ Branch 2 taken 197262 times.
✗ Branch 3 not taken.
|
352547 | if (!IS_INTRA(mb_type_col[y8]) && !sl->ref_list[1][0].parent->long_ref && |
| 375 |
2/2✓ Branch 0 taken 134513 times.
✓ Branch 1 taken 62749 times.
|
197262 | ((l1ref0[xy8] == 0 && |
| 376 |
2/2✓ Branch 0 taken 10493 times.
✓ Branch 1 taken 124020 times.
|
134513 | FFABS(l1mv0[xy4][0]) <= 1 && |
| 377 |
2/2✓ Branch 0 taken 4460 times.
✓ Branch 1 taken 6033 times.
|
10493 | FFABS(l1mv0[xy4][1]) <= 1) || |
| 378 |
2/2✓ Branch 0 taken 12234 times.
✓ Branch 1 taken 178995 times.
|
191229 | (l1ref0[xy8] < 0 && |
| 379 |
2/2✓ Branch 0 taken 9667 times.
✓ Branch 1 taken 2567 times.
|
12234 | l1ref1[xy8] == 0 && |
| 380 |
2/2✓ Branch 0 taken 826 times.
✓ Branch 1 taken 8841 times.
|
9667 | FFABS(l1mv1[xy4][0]) <= 1 && |
| 381 |
2/2✓ Branch 0 taken 502 times.
✓ Branch 1 taken 324 times.
|
826 | FFABS(l1mv1[xy4][1]) <= 1))) { |
| 382 | 6535 | a = | |
| 383 | 6535 | b = 0; | |
| 384 |
2/2✓ Branch 0 taken 515 times.
✓ Branch 1 taken 6020 times.
|
6535 | if (ref[0] > 0) |
| 385 | 515 | a = mv[0]; | |
| 386 |
2/2✓ Branch 0 taken 159 times.
✓ Branch 1 taken 6376 times.
|
6535 | if (ref[1] > 0) |
| 387 | 159 | b = mv[1]; | |
| 388 | 6535 | n++; | |
| 389 | } else { | ||
| 390 | 346012 | a = mv[0]; | |
| 391 | 346012 | b = mv[1]; | |
| 392 | } | ||
| 393 | 352547 | fill_rectangle(&sl->mv_cache[0][scan8[i8 * 4]], 2, 2, 8, a, 4); | |
| 394 | 352547 | fill_rectangle(&sl->mv_cache[1][scan8[i8 * 4]], 2, 2, 8, b, 4); | |
| 395 | } | ||
| 396 |
4/4✓ Branch 0 taken 78213 times.
✓ Branch 1 taken 16704 times.
✓ Branch 2 taken 77034 times.
✓ Branch 3 taken 1179 times.
|
94917 | if (!is_b8x8 && !(n & 3)) |
| 397 | 77034 | *mb_type = (*mb_type & ~(MB_TYPE_8x8 | MB_TYPE_16x8 | MB_TYPE_8x16 | | |
| 398 | MB_TYPE_P1L0 | MB_TYPE_P1L1)) | | ||
| 399 | 77034 | MB_TYPE_16x16 | MB_TYPE_DIRECT2; | |
| 400 |
2/2✓ Branch 0 taken 840118 times.
✓ Branch 1 taken 166031 times.
|
1006149 | } else if (IS_16X16(*mb_type)) { |
| 401 | int a, b; | ||
| 402 | |||
| 403 | 840118 | fill_rectangle(&sl->ref_cache[0][scan8[0]], 4, 4, 8, (uint8_t)ref[0], 1); | |
| 404 | 840118 | fill_rectangle(&sl->ref_cache[1][scan8[0]], 4, 4, 8, (uint8_t)ref[1], 1); | |
| 405 |
4/4✓ Branch 0 taken 626232 times.
✓ Branch 1 taken 213886 times.
✓ Branch 2 taken 626221 times.
✓ Branch 3 taken 11 times.
|
840118 | if (!IS_INTRA(mb_type_col[0]) && !sl->ref_list[1][0].parent->long_ref && |
| 406 |
2/2✓ Branch 0 taken 351754 times.
✓ Branch 1 taken 274467 times.
|
626221 | ((l1ref0[0] == 0 && |
| 407 |
2/2✓ Branch 0 taken 68282 times.
✓ Branch 1 taken 283472 times.
|
351754 | FFABS(l1mv0[0][0]) <= 1 && |
| 408 |
2/2✓ Branch 0 taken 37741 times.
✓ Branch 1 taken 30541 times.
|
68282 | FFABS(l1mv0[0][1]) <= 1) || |
| 409 |
4/4✓ Branch 0 taken 18256 times.
✓ Branch 1 taken 577424 times.
✓ Branch 2 taken 17491 times.
✓ Branch 3 taken 765 times.
|
595680 | (l1ref0[0] < 0 && !l1ref1[0] && |
| 410 |
2/2✓ Branch 0 taken 4813 times.
✓ Branch 1 taken 12678 times.
|
17491 | FFABS(l1mv1[0][0]) <= 1 && |
| 411 |
2/2✓ Branch 0 taken 3948 times.
✓ Branch 1 taken 865 times.
|
4813 | FFABS(l1mv1[0][1]) <= 1 && |
| 412 |
1/2✓ Branch 0 taken 3948 times.
✗ Branch 1 not taken.
|
3948 | h->x264_build > 33U))) { |
| 413 | 34489 | a = b = 0; | |
| 414 |
2/2✓ Branch 0 taken 7066 times.
✓ Branch 1 taken 27423 times.
|
34489 | if (ref[0] > 0) |
| 415 | 7066 | a = mv[0]; | |
| 416 |
2/2✓ Branch 0 taken 4725 times.
✓ Branch 1 taken 29764 times.
|
34489 | if (ref[1] > 0) |
| 417 | 4725 | b = mv[1]; | |
| 418 | } else { | ||
| 419 | 805629 | a = mv[0]; | |
| 420 | 805629 | b = mv[1]; | |
| 421 | } | ||
| 422 | 840118 | fill_rectangle(&sl->mv_cache[0][scan8[0]], 4, 4, 8, a, 4); | |
| 423 | 840118 | fill_rectangle(&sl->mv_cache[1][scan8[0]], 4, 4, 8, b, 4); | |
| 424 | } else { | ||
| 425 | 166031 | int n = 0; | |
| 426 |
2/2✓ Branch 0 taken 664124 times.
✓ Branch 1 taken 166031 times.
|
830155 | for (i8 = 0; i8 < 4; i8++) { |
| 427 | 664124 | const int x8 = i8 & 1; | |
| 428 | 664124 | const int y8 = i8 >> 1; | |
| 429 | |||
| 430 |
4/4✓ Branch 0 taken 270932 times.
✓ Branch 1 taken 393192 times.
✓ Branch 2 taken 123571 times.
✓ Branch 3 taken 147361 times.
|
664124 | if (is_b8x8 && !IS_DIRECT(sl->sub_mb_type[i8])) |
| 431 | 123571 | continue; | |
| 432 | 540553 | sl->sub_mb_type[i8] = sub_mb_type; | |
| 433 | |||
| 434 | 540553 | fill_rectangle(&sl->mv_cache[0][scan8[i8 * 4]], 2, 2, 8, mv[0], 4); | |
| 435 | 540553 | fill_rectangle(&sl->mv_cache[1][scan8[i8 * 4]], 2, 2, 8, mv[1], 4); | |
| 436 | 540553 | fill_rectangle(&sl->ref_cache[0][scan8[i8 * 4]], 2, 2, 8, | |
| 437 | 540553 | (uint8_t)ref[0], 1); | |
| 438 | 540553 | fill_rectangle(&sl->ref_cache[1][scan8[i8 * 4]], 2, 2, 8, | |
| 439 | 540553 | (uint8_t)ref[1], 1); | |
| 440 | |||
| 441 | assert(b8_stride == 2); | ||
| 442 | /* col_zero_flag */ | ||
| 443 |
4/4✓ Branch 0 taken 500758 times.
✓ Branch 1 taken 39795 times.
✓ Branch 2 taken 500626 times.
✓ Branch 3 taken 132 times.
|
540553 | if (!IS_INTRA(mb_type_col[0]) && !sl->ref_list[1][0].parent->long_ref && |
| 444 |
2/2✓ Branch 0 taken 170416 times.
✓ Branch 1 taken 330210 times.
|
500626 | (l1ref0[i8] == 0 || |
| 445 |
2/2✓ Branch 0 taken 12367 times.
✓ Branch 1 taken 158049 times.
|
170416 | (l1ref0[i8] < 0 && |
| 446 |
2/2✓ Branch 0 taken 11249 times.
✓ Branch 1 taken 1118 times.
|
12367 | l1ref1[i8] == 0 && |
| 447 |
1/2✓ Branch 0 taken 11249 times.
✗ Branch 1 not taken.
|
11249 | h->x264_build > 33U))) { |
| 448 |
2/2✓ Branch 0 taken 330210 times.
✓ Branch 1 taken 11249 times.
|
341459 | const int16_t (*l1mv)[2] = l1ref0[i8] == 0 ? l1mv0 : l1mv1; |
| 449 |
2/2✓ Branch 0 taken 311156 times.
✓ Branch 1 taken 30303 times.
|
341459 | if (IS_SUB_8X8(sub_mb_type)) { |
| 450 | 311156 | const int16_t *mv_col = l1mv[x8 * 3 + y8 * 3 * b4_stride]; | |
| 451 |
4/4✓ Branch 0 taken 50296 times.
✓ Branch 1 taken 260860 times.
✓ Branch 2 taken 26854 times.
✓ Branch 3 taken 23442 times.
|
311156 | if (FFABS(mv_col[0]) <= 1 && FFABS(mv_col[1]) <= 1) { |
| 452 |
2/2✓ Branch 0 taken 22929 times.
✓ Branch 1 taken 3925 times.
|
26854 | if (ref[0] == 0) |
| 453 | 22929 | fill_rectangle(&sl->mv_cache[0][scan8[i8 * 4]], 2, 2, | |
| 454 | 8, 0, 4); | ||
| 455 |
2/2✓ Branch 0 taken 24572 times.
✓ Branch 1 taken 2282 times.
|
26854 | if (ref[1] == 0) |
| 456 | 24572 | fill_rectangle(&sl->mv_cache[1][scan8[i8 * 4]], 2, 2, | |
| 457 | 8, 0, 4); | ||
| 458 | 26854 | n += 4; | |
| 459 | } | ||
| 460 | } else { | ||
| 461 | 30303 | int m = 0; | |
| 462 |
2/2✓ Branch 0 taken 121212 times.
✓ Branch 1 taken 30303 times.
|
151515 | for (i4 = 0; i4 < 4; i4++) { |
| 463 | 121212 | const int16_t *mv_col = l1mv[x8 * 2 + (i4 & 1) + | |
| 464 | 121212 | (y8 * 2 + (i4 >> 1)) * b4_stride]; | |
| 465 |
4/4✓ Branch 0 taken 8548 times.
✓ Branch 1 taken 112664 times.
✓ Branch 2 taken 3036 times.
✓ Branch 3 taken 5512 times.
|
121212 | if (FFABS(mv_col[0]) <= 1 && FFABS(mv_col[1]) <= 1) { |
| 466 |
2/2✓ Branch 0 taken 2071 times.
✓ Branch 1 taken 965 times.
|
3036 | if (ref[0] == 0) |
| 467 | 2071 | AV_ZERO32(sl->mv_cache[0][scan8[i8 * 4 + i4]]); | |
| 468 |
2/2✓ Branch 0 taken 2790 times.
✓ Branch 1 taken 246 times.
|
3036 | if (ref[1] == 0) |
| 469 | 2790 | AV_ZERO32(sl->mv_cache[1][scan8[i8 * 4 + i4]]); | |
| 470 | 3036 | m++; | |
| 471 | } | ||
| 472 | } | ||
| 473 |
2/2✓ Branch 0 taken 29990 times.
✓ Branch 1 taken 313 times.
|
30303 | if (!(m & 3)) |
| 474 | 29990 | sl->sub_mb_type[i8] += MB_TYPE_16x16 - MB_TYPE_8x8; | |
| 475 | 30303 | n += m; | |
| 476 | } | ||
| 477 | } | ||
| 478 | } | ||
| 479 |
4/4✓ Branch 0 taken 98298 times.
✓ Branch 1 taken 67733 times.
✓ Branch 2 taken 89366 times.
✓ Branch 3 taken 8932 times.
|
166031 | if (!is_b8x8 && !(n & 15)) |
| 480 | 89366 | *mb_type = (*mb_type & ~(MB_TYPE_8x8 | MB_TYPE_16x8 | MB_TYPE_8x16 | | |
| 481 | MB_TYPE_P1L0 | MB_TYPE_P1L1)) | | ||
| 482 | 89366 | MB_TYPE_16x16 | MB_TYPE_DIRECT2; | |
| 483 | } | ||
| 484 | } | ||
| 485 | |||
| 486 | 252519 | static void pred_temp_direct_motion(const H264Context *const h, H264SliceContext *sl, | |
| 487 | int *mb_type) | ||
| 488 | { | ||
| 489 | 252519 | int b8_stride = 2; | |
| 490 | 252519 | int b4_stride = h->b_stride; | |
| 491 | 252519 | int mb_xy = sl->mb_xy, mb_y = sl->mb_y; | |
| 492 | int mb_type_col[2]; | ||
| 493 | const int16_t (*l1mv0)[2], (*l1mv1)[2]; | ||
| 494 | const int8_t *l1ref0, *l1ref1; | ||
| 495 | 252519 | const int is_b8x8 = IS_8X8(*mb_type); | |
| 496 | unsigned int sub_mb_type; | ||
| 497 | int i8, i4; | ||
| 498 | |||
| 499 | assert(sl->ref_list[1][0].reference & 3); | ||
| 500 | |||
| 501 | 252519 | await_reference_mb_row(h, &sl->ref_list[1][0], | |
| 502 | 252519 | sl->mb_y + !!IS_INTERLACED(*mb_type)); | |
| 503 | |||
| 504 |
2/2✓ Branch 0 taken 89480 times.
✓ Branch 1 taken 163039 times.
|
252519 | if (IS_INTERLACED(sl->ref_list[1][0].parent->mb_type[mb_xy])) { // AFL/AFR/FR/FL -> AFL/FL |
| 505 |
2/2✓ Branch 0 taken 15717 times.
✓ Branch 1 taken 73763 times.
|
89480 | if (!IS_INTERLACED(*mb_type)) { // AFR/FR -> AFL/FL |
| 506 | 15717 | mb_y = (sl->mb_y & ~1) + sl->col_parity; | |
| 507 | 15717 | mb_xy = sl->mb_x + | |
| 508 | 15717 | ((sl->mb_y & ~1) + sl->col_parity) * h->mb_stride; | |
| 509 | 15717 | b8_stride = 0; | |
| 510 | } else { | ||
| 511 | 73763 | mb_y += sl->col_fieldoff; | |
| 512 | 73763 | mb_xy += h->mb_stride * sl->col_fieldoff; // non-zero for FL -> FL & differ parity | |
| 513 | } | ||
| 514 | 89480 | goto single_col; | |
| 515 | } else { // AFL/AFR/FR/FL -> AFR/FR | ||
| 516 |
2/2✓ Branch 0 taken 16549 times.
✓ Branch 1 taken 146490 times.
|
163039 | if (IS_INTERLACED(*mb_type)) { // AFL /FL -> AFR/FR |
| 517 | 16549 | mb_y = sl->mb_y & ~1; | |
| 518 | 16549 | mb_xy = sl->mb_x + (sl->mb_y & ~1) * h->mb_stride; | |
| 519 | 16549 | mb_type_col[0] = sl->ref_list[1][0].parent->mb_type[mb_xy]; | |
| 520 | 16549 | mb_type_col[1] = sl->ref_list[1][0].parent->mb_type[mb_xy + h->mb_stride]; | |
| 521 | 16549 | b8_stride = 2 + 4 * h->mb_stride; | |
| 522 | 16549 | b4_stride *= 6; | |
| 523 | 16549 | if (IS_INTERLACED(mb_type_col[0]) != | |
| 524 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 16549 times.
|
16549 | IS_INTERLACED(mb_type_col[1])) { |
| 525 | ✗ | mb_type_col[0] &= ~MB_TYPE_INTERLACED; | |
| 526 | ✗ | mb_type_col[1] &= ~MB_TYPE_INTERLACED; | |
| 527 | } | ||
| 528 | |||
| 529 | 16549 | sub_mb_type = MB_TYPE_16x16 | MB_TYPE_P0L0 | MB_TYPE_P0L1 | | |
| 530 | MB_TYPE_DIRECT2; /* B_SUB_8x8 */ | ||
| 531 | |||
| 532 |
2/2✓ Branch 0 taken 9887 times.
✓ Branch 1 taken 6662 times.
|
16549 | if ((mb_type_col[0] & MB_TYPE_16x16_OR_INTRA) && |
| 533 |
4/4✓ Branch 0 taken 7209 times.
✓ Branch 1 taken 2678 times.
✓ Branch 2 taken 5873 times.
✓ Branch 3 taken 1336 times.
|
9887 | (mb_type_col[1] & MB_TYPE_16x16_OR_INTRA) && |
| 534 | !is_b8x8) { | ||
| 535 | 5873 | *mb_type |= MB_TYPE_16x8 | MB_TYPE_L0L1 | | |
| 536 | MB_TYPE_DIRECT2; /* B_16x8 */ | ||
| 537 | } else { | ||
| 538 | 10676 | *mb_type |= MB_TYPE_8x8 | MB_TYPE_L0L1; | |
| 539 | } | ||
| 540 | } else { // AFR/FR -> AFR/FR | ||
| 541 | 146490 | single_col: | |
| 542 | 235970 | mb_type_col[0] = | |
| 543 | 235970 | mb_type_col[1] = sl->ref_list[1][0].parent->mb_type[mb_xy]; | |
| 544 | |||
| 545 | 235970 | sub_mb_type = MB_TYPE_16x16 | MB_TYPE_P0L0 | MB_TYPE_P0L1 | | |
| 546 | MB_TYPE_DIRECT2; /* B_SUB_8x8 */ | ||
| 547 |
4/4✓ Branch 0 taken 190390 times.
✓ Branch 1 taken 45580 times.
✓ Branch 2 taken 135391 times.
✓ Branch 3 taken 54999 times.
|
235970 | if (!is_b8x8 && (mb_type_col[0] & MB_TYPE_16x16_OR_INTRA)) { |
| 548 | 135391 | *mb_type |= MB_TYPE_16x16 | MB_TYPE_P0L0 | MB_TYPE_P0L1 | | |
| 549 | MB_TYPE_DIRECT2; /* B_16x16 */ | ||
| 550 |
2/2✓ Branch 0 taken 54999 times.
✓ Branch 1 taken 45580 times.
|
100579 | } else if (!is_b8x8 && |
| 551 |
2/2✓ Branch 0 taken 35141 times.
✓ Branch 1 taken 19858 times.
|
54999 | (mb_type_col[0] & (MB_TYPE_16x8 | MB_TYPE_8x16))) { |
| 552 | 35141 | *mb_type |= MB_TYPE_L0L1 | MB_TYPE_DIRECT2 | | |
| 553 | 35141 | (mb_type_col[0] & (MB_TYPE_16x8 | MB_TYPE_8x16)); | |
| 554 | } else { | ||
| 555 |
2/2✓ Branch 0 taken 10593 times.
✓ Branch 1 taken 54845 times.
|
65438 | if (!h->ps.sps->direct_8x8_inference_flag) { |
| 556 | /* FIXME: save sub mb types from previous frames (or derive | ||
| 557 | * from MVs) so we know exactly what block size to use */ | ||
| 558 | 10593 | sub_mb_type = MB_TYPE_8x8 | MB_TYPE_P0L0 | MB_TYPE_P0L1 | | |
| 559 | MB_TYPE_DIRECT2; /* B_SUB_4x4 */ | ||
| 560 | } | ||
| 561 | 65438 | *mb_type |= MB_TYPE_8x8 | MB_TYPE_L0L1; | |
| 562 | } | ||
| 563 | } | ||
| 564 | } | ||
| 565 | |||
| 566 | 252519 | await_reference_mb_row(h, &sl->ref_list[1][0], mb_y); | |
| 567 | |||
| 568 | 252519 | l1mv0 = (void*)&sl->ref_list[1][0].parent->motion_val[0][h->mb2b_xy[mb_xy]]; | |
| 569 | 252519 | l1mv1 = (void*)&sl->ref_list[1][0].parent->motion_val[1][h->mb2b_xy[mb_xy]]; | |
| 570 | 252519 | l1ref0 = &sl->ref_list[1][0].parent->ref_index[0][4 * mb_xy]; | |
| 571 | 252519 | l1ref1 = &sl->ref_list[1][0].parent->ref_index[1][4 * mb_xy]; | |
| 572 |
2/2✓ Branch 0 taken 15717 times.
✓ Branch 1 taken 236802 times.
|
252519 | if (!b8_stride) { |
| 573 |
2/2✓ Branch 0 taken 7766 times.
✓ Branch 1 taken 7951 times.
|
15717 | if (sl->mb_y & 1) { |
| 574 | 7766 | l1ref0 += 2; | |
| 575 | 7766 | l1ref1 += 2; | |
| 576 | 7766 | l1mv0 += 2 * b4_stride; | |
| 577 | 7766 | l1mv1 += 2 * b4_stride; | |
| 578 | } | ||
| 579 | } | ||
| 580 | |||
| 581 | { | ||
| 582 | 252519 | const int *map_col_to_list0[2] = { sl->map_col_to_list0[0], | |
| 583 | 252519 | sl->map_col_to_list0[1] }; | |
| 584 | 252519 | const int *dist_scale_factor = sl->dist_scale_factor; | |
| 585 | int ref_offset; | ||
| 586 | |||
| 587 |
4/4✓ Branch 0 taken 42738 times.
✓ Branch 1 taken 209781 times.
✓ Branch 2 taken 20451 times.
✓ Branch 3 taken 22287 times.
|
252519 | if (FRAME_MBAFF(h) && IS_INTERLACED(*mb_type)) { |
| 588 | 20451 | map_col_to_list0[0] = sl->map_col_to_list0_field[sl->mb_y & 1][0]; | |
| 589 | 20451 | map_col_to_list0[1] = sl->map_col_to_list0_field[sl->mb_y & 1][1]; | |
| 590 | 20451 | dist_scale_factor = sl->dist_scale_factor_field[sl->mb_y & 1]; | |
| 591 | } | ||
| 592 | 252519 | ref_offset = (sl->ref_list[1][0].parent->mbaff << 4) & (mb_type_col[0] >> 3); | |
| 593 | |||
| 594 |
2/2✓ Branch 0 taken 32266 times.
✓ Branch 1 taken 220253 times.
|
252519 | if (IS_INTERLACED(*mb_type) != IS_INTERLACED(mb_type_col[0])) { |
| 595 |
2/2✓ Branch 0 taken 15717 times.
✓ Branch 1 taken 16549 times.
|
32266 | int y_shift = 2 * !IS_INTERLACED(*mb_type); |
| 596 | assert(h->ps.sps->direct_8x8_inference_flag); | ||
| 597 | |||
| 598 |
2/2✓ Branch 0 taken 129064 times.
✓ Branch 1 taken 32266 times.
|
161330 | for (i8 = 0; i8 < 4; i8++) { |
| 599 | 129064 | const int x8 = i8 & 1; | |
| 600 | 129064 | const int y8 = i8 >> 1; | |
| 601 | int ref0, scale; | ||
| 602 | 129064 | const int16_t (*l1mv)[2] = l1mv0; | |
| 603 | |||
| 604 |
4/4✓ Branch 0 taken 43260 times.
✓ Branch 1 taken 85804 times.
✓ Branch 2 taken 22674 times.
✓ Branch 3 taken 20586 times.
|
129064 | if (is_b8x8 && !IS_DIRECT(sl->sub_mb_type[i8])) |
| 605 | 22674 | continue; | |
| 606 | 106390 | sl->sub_mb_type[i8] = sub_mb_type; | |
| 607 | |||
| 608 | 106390 | fill_rectangle(&sl->ref_cache[1][scan8[i8 * 4]], 2, 2, 8, 0, 1); | |
| 609 |
2/2✓ Branch 0 taken 25592 times.
✓ Branch 1 taken 80798 times.
|
106390 | if (IS_INTRA(mb_type_col[y8])) { |
| 610 | 25592 | fill_rectangle(&sl->ref_cache[0][scan8[i8 * 4]], 2, 2, 8, 0, 1); | |
| 611 | 25592 | fill_rectangle(&sl->mv_cache[0][scan8[i8 * 4]], 2, 2, 8, 0, 4); | |
| 612 | 25592 | fill_rectangle(&sl->mv_cache[1][scan8[i8 * 4]], 2, 2, 8, 0, 4); | |
| 613 | 25592 | continue; | |
| 614 | } | ||
| 615 | |||
| 616 | 80798 | ref0 = l1ref0[x8 + y8 * b8_stride]; | |
| 617 |
2/2✓ Branch 0 taken 80605 times.
✓ Branch 1 taken 193 times.
|
80798 | if (ref0 >= 0) |
| 618 | 80605 | ref0 = map_col_to_list0[0][ref0 + ref_offset]; | |
| 619 | else { | ||
| 620 | 193 | ref0 = map_col_to_list0[1][l1ref1[x8 + y8 * b8_stride] + | |
| 621 | ref_offset]; | ||
| 622 | 193 | l1mv = l1mv1; | |
| 623 | } | ||
| 624 | 80798 | scale = dist_scale_factor[ref0]; | |
| 625 | 80798 | fill_rectangle(&sl->ref_cache[0][scan8[i8 * 4]], 2, 2, 8, | |
| 626 | ref0, 1); | ||
| 627 | |||
| 628 | { | ||
| 629 | 80798 | const int16_t *mv_col = l1mv[x8 * 3 + y8 * b4_stride]; | |
| 630 | 80798 | int my_col = (mv_col[1] * (1 << y_shift)) / 2; | |
| 631 | 80798 | int mx = (scale * mv_col[0] + 128) >> 8; | |
| 632 | 80798 | int my = (scale * my_col + 128) >> 8; | |
| 633 | 80798 | fill_rectangle(&sl->mv_cache[0][scan8[i8 * 4]], 2, 2, 8, | |
| 634 | pack16to32(mx, my), 4); | ||
| 635 | 80798 | fill_rectangle(&sl->mv_cache[1][scan8[i8 * 4]], 2, 2, 8, | |
| 636 | 80798 | pack16to32(mx - mv_col[0], my - my_col), 4); | |
| 637 | } | ||
| 638 | } | ||
| 639 | 32266 | return; | |
| 640 | } | ||
| 641 | |||
| 642 | /* one-to-one mv scaling */ | ||
| 643 | |||
| 644 |
2/2✓ Branch 0 taken 127730 times.
✓ Branch 1 taken 92523 times.
|
220253 | if (IS_16X16(*mb_type)) { |
| 645 | int ref, mv0, mv1; | ||
| 646 | |||
| 647 | 127730 | fill_rectangle(&sl->ref_cache[1][scan8[0]], 4, 4, 8, 0, 1); | |
| 648 |
2/2✓ Branch 0 taken 61083 times.
✓ Branch 1 taken 66647 times.
|
127730 | if (IS_INTRA(mb_type_col[0])) { |
| 649 | 61083 | ref = mv0 = mv1 = 0; | |
| 650 | } else { | ||
| 651 | 199890 | const int ref0 = l1ref0[0] >= 0 ? map_col_to_list0[0][l1ref0[0] + ref_offset] | |
| 652 |
2/2✓ Branch 0 taken 66596 times.
✓ Branch 1 taken 51 times.
|
66647 | : map_col_to_list0[1][l1ref1[0] + ref_offset]; |
| 653 | 66647 | const int scale = dist_scale_factor[ref0]; | |
| 654 |
2/2✓ Branch 0 taken 66596 times.
✓ Branch 1 taken 51 times.
|
66647 | const int16_t *mv_col = l1ref0[0] >= 0 ? l1mv0[0] : l1mv1[0]; |
| 655 | int mv_l0[2]; | ||
| 656 | 66647 | mv_l0[0] = (scale * mv_col[0] + 128) >> 8; | |
| 657 | 66647 | mv_l0[1] = (scale * mv_col[1] + 128) >> 8; | |
| 658 | 66647 | ref = ref0; | |
| 659 | 66647 | mv0 = pack16to32(mv_l0[0], mv_l0[1]); | |
| 660 | 66647 | mv1 = pack16to32(mv_l0[0] - mv_col[0], mv_l0[1] - mv_col[1]); | |
| 661 | } | ||
| 662 | 127730 | fill_rectangle(&sl->ref_cache[0][scan8[0]], 4, 4, 8, ref, 1); | |
| 663 | 127730 | fill_rectangle(&sl->mv_cache[0][scan8[0]], 4, 4, 8, mv0, 4); | |
| 664 | 127730 | fill_rectangle(&sl->mv_cache[1][scan8[0]], 4, 4, 8, mv1, 4); | |
| 665 | } else { | ||
| 666 |
2/2✓ Branch 0 taken 370092 times.
✓ Branch 1 taken 92523 times.
|
462615 | for (i8 = 0; i8 < 4; i8++) { |
| 667 | 370092 | const int x8 = i8 & 1; | |
| 668 | 370092 | const int y8 = i8 >> 1; | |
| 669 | int ref0, scale; | ||
| 670 | 370092 | const int16_t (*l1mv)[2] = l1mv0; | |
| 671 | |||
| 672 |
4/4✓ Branch 0 taken 163928 times.
✓ Branch 1 taken 206164 times.
✓ Branch 2 taken 92478 times.
✓ Branch 3 taken 71450 times.
|
370092 | if (is_b8x8 && !IS_DIRECT(sl->sub_mb_type[i8])) |
| 673 | 92478 | continue; | |
| 674 | 277614 | sl->sub_mb_type[i8] = sub_mb_type; | |
| 675 | 277614 | fill_rectangle(&sl->ref_cache[1][scan8[i8 * 4]], 2, 2, 8, 0, 1); | |
| 676 |
2/2✓ Branch 0 taken 22294 times.
✓ Branch 1 taken 255320 times.
|
277614 | if (IS_INTRA(mb_type_col[0])) { |
| 677 | 22294 | fill_rectangle(&sl->ref_cache[0][scan8[i8 * 4]], 2, 2, 8, 0, 1); | |
| 678 | 22294 | fill_rectangle(&sl->mv_cache[0][scan8[i8 * 4]], 2, 2, 8, 0, 4); | |
| 679 | 22294 | fill_rectangle(&sl->mv_cache[1][scan8[i8 * 4]], 2, 2, 8, 0, 4); | |
| 680 | 22294 | continue; | |
| 681 | } | ||
| 682 | |||
| 683 | assert(b8_stride == 2); | ||
| 684 | 255320 | ref0 = l1ref0[i8]; | |
| 685 |
2/2✓ Branch 0 taken 255300 times.
✓ Branch 1 taken 20 times.
|
255320 | if (ref0 >= 0) |
| 686 | 255300 | ref0 = map_col_to_list0[0][ref0 + ref_offset]; | |
| 687 | else { | ||
| 688 | 20 | ref0 = map_col_to_list0[1][l1ref1[i8] + ref_offset]; | |
| 689 | 20 | l1mv = l1mv1; | |
| 690 | } | ||
| 691 | 255320 | scale = dist_scale_factor[ref0]; | |
| 692 | |||
| 693 | 255320 | fill_rectangle(&sl->ref_cache[0][scan8[i8 * 4]], 2, 2, 8, | |
| 694 | ref0, 1); | ||
| 695 |
2/2✓ Branch 0 taken 230012 times.
✓ Branch 1 taken 25308 times.
|
255320 | if (IS_SUB_8X8(sub_mb_type)) { |
| 696 | 230012 | const int16_t *mv_col = l1mv[x8 * 3 + y8 * 3 * b4_stride]; | |
| 697 | 230012 | int mx = (scale * mv_col[0] + 128) >> 8; | |
| 698 | 230012 | int my = (scale * mv_col[1] + 128) >> 8; | |
| 699 | 230012 | fill_rectangle(&sl->mv_cache[0][scan8[i8 * 4]], 2, 2, 8, | |
| 700 | pack16to32(mx, my), 4); | ||
| 701 | 230012 | fill_rectangle(&sl->mv_cache[1][scan8[i8 * 4]], 2, 2, 8, | |
| 702 | 230012 | pack16to32(mx - mv_col[0], my - mv_col[1]), 4); | |
| 703 | } else { | ||
| 704 |
2/2✓ Branch 0 taken 101232 times.
✓ Branch 1 taken 25308 times.
|
126540 | for (i4 = 0; i4 < 4; i4++) { |
| 705 | 101232 | const int16_t *mv_col = l1mv[x8 * 2 + (i4 & 1) + | |
| 706 | 101232 | (y8 * 2 + (i4 >> 1)) * b4_stride]; | |
| 707 | 101232 | int16_t *mv_l0 = sl->mv_cache[0][scan8[i8 * 4 + i4]]; | |
| 708 | 101232 | mv_l0[0] = (scale * mv_col[0] + 128) >> 8; | |
| 709 | 101232 | mv_l0[1] = (scale * mv_col[1] + 128) >> 8; | |
| 710 | 101232 | AV_WN32A(sl->mv_cache[1][scan8[i8 * 4 + i4]], | |
| 711 | pack16to32(mv_l0[0] - mv_col[0], | ||
| 712 | mv_l0[1] - mv_col[1])); | ||
| 713 | } | ||
| 714 | } | ||
| 715 | } | ||
| 716 | } | ||
| 717 | } | ||
| 718 | } | ||
| 719 | |||
| 720 | 3289635 | void ff_h264_pred_direct_motion(const H264Context *const h, H264SliceContext *sl, | |
| 721 | int *mb_type) | ||
| 722 | { | ||
| 723 |
2/2✓ Branch 0 taken 3037116 times.
✓ Branch 1 taken 252519 times.
|
3289635 | if (sl->direct_spatial_mv_pred) |
| 724 | 3037116 | pred_spatial_direct_motion(h, sl, mb_type); | |
| 725 | else | ||
| 726 | 252519 | pred_temp_direct_motion(h, sl, mb_type); | |
| 727 | 3289635 | } | |
| 728 |