| 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 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 29078 times.
|
29078 | if (pocdiff != (int)pocdiff) |
| 45 | ✗ | avpriv_request_sample(sl->h264->avctx, "pocdiff overflow"); | |
| 46 | |||
| 47 |
4/4✓ Branch 0 taken 21321 times.
✓ Branch 1 taken 7757 times.
✓ Branch 2 taken 531 times.
✓ Branch 3 taken 20790 times.
|
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 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 20790 times.
|
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 | 19530 | const int poc = FIELD_PICTURE(h) ? h->cur_pic_ptr->field_poc[h->picture_structure == PICT_BOTTOM_FIELD] | |
| 65 |
2/2✓ Branch 0 taken 3612 times.
✓ Branch 1 taken 4347 times.
|
7959 | : h->cur_pic_ptr->poc; |
| 66 | 7959 | const int poc1 = sl->ref_list[1][0].poc; | |
| 67 | int i, field; | ||
| 68 | |||
| 69 |
2/2✓ Branch 0 taken 522 times.
✓ Branch 1 taken 7437 times.
|
7959 | if (FRAME_MBAFF(h)) |
| 70 |
2/2✓ Branch 0 taken 1044 times.
✓ Branch 1 taken 522 times.
|
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 |
2/2✓ Branch 0 taken 6676 times.
✓ Branch 1 taken 1044 times.
|
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 |
2/2✓ Branch 0 taken 22402 times.
✓ Branch 1 taken 7959 times.
|
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 |
2/2✓ Branch 0 taken 2088 times.
✓ Branch 1 taken 15918 times.
|
18006 | int start = mbafi ? 16 : 0; |
| 89 |
2/2✓ Branch 0 taken 2088 times.
✓ Branch 1 taken 15918 times.
|
18006 | int end = mbafi ? 16 + 2 * sl->ref_count[0] : sl->ref_count[0]; |
| 90 |
4/4✓ Branch 0 taken 15918 times.
✓ Branch 1 taken 2088 times.
✓ Branch 2 taken 7224 times.
✓ Branch 3 taken 8694 times.
|
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 |
2/2✓ Branch 0 taken 36012 times.
✓ Branch 1 taken 18006 times.
|
54018 | for (rfield = 0; rfield < 2; rfield++) { |
| 96 |
2/2✓ Branch 0 taken 39408 times.
✓ Branch 1 taken 36012 times.
|
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 |
2/2✓ Branch 0 taken 16960 times.
✓ Branch 1 taken 22448 times.
|
39408 | if (!interl) |
| 100 | 16960 | poc |= 3; | |
| 101 | // FIXME: store all MBAFF references so this is not needed | ||
| 102 |
3/4✓ Branch 0 taken 22448 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5456 times.
✓ Branch 3 taken 16992 times.
|
22448 | else if (interl && (poc & 3) == 3) |
| 103 | 5456 | poc = (poc & ~3) + rfield + 1; | |
| 104 | |||
| 105 |
2/2✓ Branch 0 taken 107980 times.
✓ Branch 1 taken 7522 times.
|
115502 | for (j = start; j < end; j++) { |
| 106 | 107980 | if (4 * sl->ref_list[0][j].parent->frame_num + | |
| 107 |
2/2✓ Branch 0 taken 31886 times.
✓ Branch 1 taken 76094 times.
|
107980 | (sl->ref_list[0][j].reference & 3) == poc) { |
| 108 |
2/2✓ Branch 0 taken 4256 times.
✓ Branch 1 taken 27630 times.
|
31886 | int cur_ref = mbafi ? (j - 16) ^ field : j; |
| 109 |
2/2✓ Branch 0 taken 5826 times.
✓ Branch 1 taken 26060 times.
|
31886 | if (ref1->mbaff) |
| 110 | 5826 | map[list][2 * old_ref + (rfield ^ field) + 16] = cur_ref; | |
| 111 |
4/4✓ Branch 0 taken 15943 times.
✓ Branch 1 taken 15943 times.
✓ Branch 2 taken 6647 times.
✓ Branch 3 taken 9296 times.
|
31886 | if (rfield == field || !interl) |
| 112 | 22590 | map[list][old_ref] = cur_ref; | |
| 113 | 31886 | break; | |
| 114 | } | ||
| 115 | } | ||
| 116 | } | ||
| 117 | } | ||
| 118 | 18006 | } | |
| 119 | |||
| 120 | 38838 | void ff_h264_direct_ref_list_init(const H264Context *const h, H264SliceContext *sl) | |
| 121 | { | ||
| 122 | 38838 | H264Ref *const ref1 = &sl->ref_list[1][0]; | |
| 123 | 38838 | H264Picture *const cur = h->cur_pic_ptr; | |
| 124 | int list, field; | ||
| 125 | 38838 | int sidx = (h->picture_structure & 1) ^ 1; | |
| 126 | 38838 | 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 |
1/2✓ Branch 0 taken 38838 times.
✗ Branch 1 not taken.
|
38838 | if (!h->setup_finished) { |
| 131 |
2/2✓ Branch 0 taken 48016 times.
✓ Branch 1 taken 38838 times.
|
86854 | for (list = 0; list < sl->list_count; list++) { |
| 132 | 48016 | cur->ref_count[sidx][list] = sl->ref_count[list]; | |
| 133 |
2/2✓ Branch 0 taken 145673 times.
✓ Branch 1 taken 48016 times.
|
193689 | for (int j = 0; j < sl->ref_count[list]; j++) |
| 134 | 145673 | cur->ref_poc[sidx][list][j] = 4 * sl->ref_list[list][j].parent->frame_num + | |
| 135 | 145673 | (sl->ref_list[list][j].reference & 3); | |
| 136 | } | ||
| 137 | |||
| 138 |
2/2✓ Branch 0 taken 29286 times.
✓ Branch 1 taken 9552 times.
|
38838 | if (h->picture_structure == PICT_FRAME) { |
| 139 | 29286 | memcpy(cur->ref_count[1], cur->ref_count[0], sizeof(cur->ref_count[0])); | |
| 140 | 29286 | memcpy(cur->ref_poc[1], cur->ref_poc[0], sizeof(cur->ref_poc[0])); | |
| 141 | } | ||
| 142 | |||
| 143 |
2/2✓ Branch 0 taken 29328 times.
✓ Branch 1 taken 9510 times.
|
38838 | if (h->current_slice == 0) { |
| 144 | 29328 | cur->mbaff = FRAME_MBAFF(h); | |
| 145 | } else { | ||
| 146 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9510 times.
|
9510 | av_assert0(cur->mbaff == FRAME_MBAFF(h)); |
| 147 | } | ||
| 148 | } | ||
| 149 | |||
| 150 | 38838 | sl->col_fieldoff = 0; | |
| 151 | |||
| 152 |
3/4✓ Branch 0 taken 13804 times.
✓ Branch 1 taken 25034 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 13804 times.
|
38838 | if (sl->list_count != 2 || !sl->ref_count[1]) |
| 153 | 25034 | return; | |
| 154 | |||
| 155 |
2/2✓ Branch 0 taken 8585 times.
✓ Branch 1 taken 5219 times.
|
13804 | if (h->picture_structure == PICT_FRAME) { |
| 156 | 8585 | int cur_poc = h->cur_pic_ptr->poc; | |
| 157 | 8585 | const int *col_poc = sl->ref_list[1][0].parent->field_poc; | |
| 158 |
3/4✓ Branch 0 taken 12 times.
✓ Branch 1 taken 8573 times.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
|
8585 | 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 | 8573 | sl->col_parity = (FFABS(col_poc[0] - (int64_t)cur_poc) >= | |
| 163 | 8573 | FFABS(col_poc[1] - (int64_t)cur_poc)); | |
| 164 | 8585 | ref1sidx = | |
| 165 | 8585 | sidx = sl->col_parity; | |
| 166 | // FL -> FL & differ parity | ||
| 167 |
2/2✓ Branch 0 taken 1866 times.
✓ Branch 1 taken 3353 times.
|
5219 | } else if (!(h->picture_structure & sl->ref_list[1][0].reference) && |
| 168 |
2/2✓ Branch 0 taken 1728 times.
✓ Branch 1 taken 138 times.
|
1866 | !sl->ref_list[1][0].parent->mbaff) { |
| 169 | 1728 | sl->col_fieldoff = 2 * sl->ref_list[1][0].reference - 3; | |
| 170 | } | ||
| 171 | |||
| 172 |
3/4✓ Branch 0 taken 13804 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5845 times.
✓ Branch 3 taken 7959 times.
|
13804 | if (sl->slice_type_nos != AV_PICTURE_TYPE_B || sl->direct_spatial_mv_pred) |
| 173 | 5845 | return; | |
| 174 | |||
| 175 |
2/2✓ Branch 0 taken 15918 times.
✓ Branch 1 taken 7959 times.
|
23877 | for (list = 0; list < 2; list++) { |
| 176 | 15918 | fill_colmap(h, sl, sl->map_col_to_list0, list, sidx, ref1sidx, 0); | |
| 177 |
2/2✓ Branch 0 taken 1044 times.
✓ Branch 1 taken 14874 times.
|
15918 | if (FRAME_MBAFF(h)) |
| 178 |
2/2✓ Branch 0 taken 2088 times.
✓ Branch 1 taken 1044 times.
|
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 | 4698061 | static void await_reference_mb_row(const H264Context *const h, H264Ref *ref, | |
| 185 | int mb_y) | ||
| 186 | { | ||
| 187 |
2/2✓ Branch 0 taken 4669178 times.
✓ Branch 1 taken 28883 times.
|
4698061 | if (!HAVE_THREADS || !(h->avctx->active_thread_type & FF_THREAD_FRAME)) |
| 188 | 4669178 | 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 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 28883 times.
|
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 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 28883 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
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 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 28883 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
28883 | if (ref_field_picture && !FIELD_PICTURE(h)) |
| 205 | ✗ | ff_thread_await_progress(&ref->parent->tf, row, 0); | |
| 206 | } | ||
| 207 | |||
| 208 | 3090333 | static void pred_spatial_direct_motion(const H264Context *const h, H264SliceContext *sl, | |
| 209 | int *mb_type) | ||
| 210 | { | ||
| 211 | 3090333 | int b8_stride = 2; | |
| 212 | 3090333 | int b4_stride = h->b_stride; | |
| 213 | 3090333 | int mb_xy = sl->mb_xy, mb_y = sl->mb_y; | |
| 214 | int mb_type_col[2]; | ||
| 215 | const int16_t (*l1mv0)[2], (*l1mv1)[2]; | ||
| 216 | const int8_t *l1ref0, *l1ref1; | ||
| 217 | 3090333 | const int is_b8x8 = IS_8X8(*mb_type); | |
| 218 | 3090333 | unsigned int sub_mb_type = MB_TYPE_L0L1; | |
| 219 | int i8, i4; | ||
| 220 | int ref[2]; | ||
| 221 | int mv[2]; | ||
| 222 | int list; | ||
| 223 | |||
| 224 | assert(sl->ref_list[1][0].reference & 3); | ||
| 225 | |||
| 226 | 3090333 | await_reference_mb_row(h, &sl->ref_list[1][0], | |
| 227 | 3090333 | sl->mb_y + !!IS_INTERLACED(*mb_type)); | |
| 228 | |||
| 229 | #define MB_TYPE_16x16_OR_INTRA (MB_TYPE_16x16 | MB_TYPE_INTRA4x4 | \ | ||
| 230 | MB_TYPE_INTRA16x16 | MB_TYPE_INTRA_PCM) | ||
| 231 | |||
| 232 | /* ref = min(neighbors) */ | ||
| 233 |
2/2✓ Branch 0 taken 6180666 times.
✓ Branch 1 taken 3090333 times.
|
9270999 | for (list = 0; list < 2; list++) { |
| 234 | 6180666 | int left_ref = sl->ref_cache[list][scan8[0] - 1]; | |
| 235 | 6180666 | int top_ref = sl->ref_cache[list][scan8[0] - 8]; | |
| 236 | 6180666 | int refc = sl->ref_cache[list][scan8[0] - 8 + 4]; | |
| 237 | 6180666 | const int16_t *C = sl->mv_cache[list][scan8[0] - 8 + 4]; | |
| 238 |
2/2✓ Branch 0 taken 758222 times.
✓ Branch 1 taken 5422444 times.
|
6180666 | if (refc == PART_NOT_AVAILABLE) { |
| 239 | 758222 | refc = sl->ref_cache[list][scan8[0] - 8 - 1]; | |
| 240 | 758222 | C = sl->mv_cache[list][scan8[0] - 8 - 1]; | |
| 241 | } | ||
| 242 | 6180666 | ref[list] = FFMIN3((unsigned)left_ref, | |
| 243 | (unsigned)top_ref, | ||
| 244 | (unsigned)refc); | ||
| 245 |
2/2✓ Branch 0 taken 5671471 times.
✓ Branch 1 taken 509195 times.
|
6180666 | if (ref[list] >= 0) { |
| 246 | /* This is just pred_motion() but with the cases removed that | ||
| 247 | * cannot happen for direct blocks. */ | ||
| 248 | 5671471 | const int16_t *const A = sl->mv_cache[list][scan8[0] - 1]; | |
| 249 | 5671471 | const int16_t *const B = sl->mv_cache[list][scan8[0] - 8]; | |
| 250 | |||
| 251 | 5671471 | int match_count = (left_ref == ref[list]) + | |
| 252 | 5671471 | (top_ref == ref[list]) + | |
| 253 | 5671471 | (refc == ref[list]); | |
| 254 | |||
| 255 |
2/2✓ Branch 0 taken 5034388 times.
✓ Branch 1 taken 637083 times.
|
5671471 | if (match_count > 1) { // most common |
| 256 | 5034388 | mv[list] = pack16to32(mid_pred(A[0], B[0], C[0]), | |
| 257 | 5034388 | mid_pred(A[1], B[1], C[1])); | |
| 258 | } else { | ||
| 259 | assert(match_count == 1); | ||
| 260 |
2/2✓ Branch 0 taken 501203 times.
✓ Branch 1 taken 135880 times.
|
637083 | if (left_ref == ref[list]) |
| 261 | 501203 | mv[list] = AV_RN32A(A); | |
| 262 |
2/2✓ Branch 0 taken 63751 times.
✓ Branch 1 taken 72129 times.
|
135880 | else if (top_ref == ref[list]) |
| 263 | 63751 | mv[list] = AV_RN32A(B); | |
| 264 | else | ||
| 265 | 72129 | mv[list] = AV_RN32A(C); | |
| 266 | } | ||
| 267 | av_assert2(ref[list] < (sl->ref_count[list] << !!FRAME_MBAFF(h))); | ||
| 268 | } else { | ||
| 269 | 509195 | int mask = ~(MB_TYPE_L0 << (2 * list)); | |
| 270 | 509195 | mv[list] = 0; | |
| 271 | 509195 | ref[list] = -1; | |
| 272 |
2/2✓ Branch 0 taken 483123 times.
✓ Branch 1 taken 26072 times.
|
509195 | if (!is_b8x8) |
| 273 | 483123 | *mb_type &= mask; | |
| 274 | 509195 | sub_mb_type &= mask; | |
| 275 | } | ||
| 276 | } | ||
| 277 |
4/4✓ Branch 0 taken 253189 times.
✓ Branch 1 taken 2837144 times.
✓ Branch 2 taken 6995 times.
✓ Branch 3 taken 246194 times.
|
3090333 | if (ref[0] < 0 && ref[1] < 0) { |
| 278 | 6995 | ref[0] = ref[1] = 0; | |
| 279 |
2/2✓ Branch 0 taken 6102 times.
✓ Branch 1 taken 893 times.
|
6995 | if (!is_b8x8) |
| 280 | 6102 | *mb_type |= MB_TYPE_L0L1; | |
| 281 | 6995 | sub_mb_type |= MB_TYPE_L0L1; | |
| 282 | } | ||
| 283 | |||
| 284 |
2/2✓ Branch 0 taken 1987741 times.
✓ Branch 1 taken 1102592 times.
|
3090333 | if (!(is_b8x8 | mv[0] | mv[1])) { |
| 285 | 1987741 | fill_rectangle(&sl->ref_cache[0][scan8[0]], 4, 4, 8, (uint8_t)ref[0], 1); | |
| 286 | 1987741 | fill_rectangle(&sl->ref_cache[1][scan8[0]], 4, 4, 8, (uint8_t)ref[1], 1); | |
| 287 | 1987741 | fill_rectangle(&sl->mv_cache[0][scan8[0]], 4, 4, 8, 0, 4); | |
| 288 | 1987741 | fill_rectangle(&sl->mv_cache[1][scan8[0]], 4, 4, 8, 0, 4); | |
| 289 | 1987741 | *mb_type = (*mb_type & ~(MB_TYPE_8x8 | MB_TYPE_16x8 | MB_TYPE_8x16 | | |
| 290 | MB_TYPE_P1L0 | MB_TYPE_P1L1)) | | ||
| 291 | 1987741 | MB_TYPE_16x16 | MB_TYPE_DIRECT2; | |
| 292 | 1987741 | return; | |
| 293 | } | ||
| 294 | |||
| 295 |
2/2✓ Branch 0 taken 444780 times.
✓ Branch 1 taken 657812 times.
|
1102592 | if (sl->ref_list[1][0].parent->field_picture || |
| 296 |
2/2✓ Branch 0 taken 67888 times.
✓ Branch 1 taken 376892 times.
|
444780 | IS_INTERLACED(sl->ref_list[1][0].parent->mb_type[mb_xy])) { // AFL/AFR/FR/FL -> AFL/FL |
| 297 |
2/2✓ Branch 0 taken 43571 times.
✓ Branch 1 taken 682129 times.
|
725700 | if (!IS_INTERLACED(*mb_type)) { // AFR/FR -> AFL/FL |
| 298 | 43571 | mb_y = (sl->mb_y & ~1) + sl->col_parity; | |
| 299 | 43571 | mb_xy = sl->mb_x + | |
| 300 | 43571 | ((sl->mb_y & ~1) + sl->col_parity) * h->mb_stride; | |
| 301 | 43571 | b8_stride = 0; | |
| 302 | } else { | ||
| 303 | 682129 | mb_y += sl->col_fieldoff; | |
| 304 | 682129 | mb_xy += h->mb_stride * sl->col_fieldoff; // non-zero for FL -> FL & differ parity | |
| 305 | } | ||
| 306 | 725700 | goto single_col; | |
| 307 | } else { // AFL/AFR/FR/FL -> AFR/FR | ||
| 308 |
2/2✓ Branch 0 taken 51346 times.
✓ Branch 1 taken 325546 times.
|
376892 | if (IS_INTERLACED(*mb_type)) { // AFL /FL -> AFR/FR |
| 309 | 51346 | mb_y = sl->mb_y & ~1; | |
| 310 | 51346 | mb_xy = (sl->mb_y & ~1) * h->mb_stride + sl->mb_x; | |
| 311 | 51346 | mb_type_col[0] = sl->ref_list[1][0].parent->mb_type[mb_xy]; | |
| 312 | 51346 | mb_type_col[1] = sl->ref_list[1][0].parent->mb_type[mb_xy + h->mb_stride]; | |
| 313 | 51346 | b8_stride = 2 + 4 * h->mb_stride; | |
| 314 | 51346 | b4_stride *= 6; | |
| 315 | 51346 | if (IS_INTERLACED(mb_type_col[0]) != | |
| 316 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 51346 times.
|
51346 | IS_INTERLACED(mb_type_col[1])) { |
| 317 | ✗ | mb_type_col[0] &= ~MB_TYPE_INTERLACED; | |
| 318 | ✗ | mb_type_col[1] &= ~MB_TYPE_INTERLACED; | |
| 319 | } | ||
| 320 | |||
| 321 | 51346 | sub_mb_type |= MB_TYPE_16x16 | MB_TYPE_DIRECT2; /* B_SUB_8x8 */ | |
| 322 |
2/2✓ Branch 0 taken 40827 times.
✓ Branch 1 taken 10519 times.
|
51346 | if ((mb_type_col[0] & MB_TYPE_16x16_OR_INTRA) && |
| 323 |
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) && |
| 324 | !is_b8x8) { | ||
| 325 | 32330 | *mb_type |= MB_TYPE_16x8 | MB_TYPE_DIRECT2; /* B_16x8 */ | |
| 326 | } else { | ||
| 327 | 19016 | *mb_type |= MB_TYPE_8x8; | |
| 328 | } | ||
| 329 | } else { // AFR/FR -> AFR/FR | ||
| 330 | 325546 | single_col: | |
| 331 | 1051246 | mb_type_col[0] = | |
| 332 | 1051246 | mb_type_col[1] = sl->ref_list[1][0].parent->mb_type[mb_xy]; | |
| 333 | |||
| 334 | 1051246 | sub_mb_type |= MB_TYPE_16x16 | MB_TYPE_DIRECT2; /* B_SUB_8x8 */ | |
| 335 |
4/4✓ Branch 0 taken 975701 times.
✓ Branch 1 taken 75545 times.
✓ Branch 2 taken 870114 times.
✓ Branch 3 taken 105587 times.
|
1051246 | if (!is_b8x8 && (mb_type_col[0] & MB_TYPE_16x16_OR_INTRA)) { |
| 336 | 870114 | *mb_type |= MB_TYPE_16x16 | MB_TYPE_DIRECT2; /* B_16x16 */ | |
| 337 |
2/2✓ Branch 0 taken 105587 times.
✓ Branch 1 taken 75545 times.
|
181132 | } else if (!is_b8x8 && |
| 338 |
2/2✓ Branch 0 taken 59412 times.
✓ Branch 1 taken 46175 times.
|
105587 | (mb_type_col[0] & (MB_TYPE_16x8 | MB_TYPE_8x16))) { |
| 339 | 59412 | *mb_type |= MB_TYPE_DIRECT2 | | |
| 340 | 59412 | (mb_type_col[0] & (MB_TYPE_16x8 | MB_TYPE_8x16)); | |
| 341 | } else { | ||
| 342 |
2/2✓ Branch 0 taken 21562 times.
✓ Branch 1 taken 100158 times.
|
121720 | if (!h->ps.sps->direct_8x8_inference_flag) { |
| 343 | /* FIXME: Save sub mb types from previous frames (or derive | ||
| 344 | * from MVs) so we know exactly what block size to use. */ | ||
| 345 | 21562 | sub_mb_type += (MB_TYPE_8x8 - MB_TYPE_16x16); /* B_SUB_4x4 */ | |
| 346 | } | ||
| 347 | 121720 | *mb_type |= MB_TYPE_8x8; | |
| 348 | } | ||
| 349 | } | ||
| 350 | } | ||
| 351 | |||
| 352 | 1102592 | await_reference_mb_row(h, &sl->ref_list[1][0], mb_y); | |
| 353 | |||
| 354 | 1102592 | l1mv0 = (void*)&sl->ref_list[1][0].parent->motion_val[0][h->mb2b_xy[mb_xy]]; | |
| 355 | 1102592 | l1mv1 = (void*)&sl->ref_list[1][0].parent->motion_val[1][h->mb2b_xy[mb_xy]]; | |
| 356 | 1102592 | l1ref0 = &sl->ref_list[1][0].parent->ref_index[0][4 * mb_xy]; | |
| 357 | 1102592 | l1ref1 = &sl->ref_list[1][0].parent->ref_index[1][4 * mb_xy]; | |
| 358 |
2/2✓ Branch 0 taken 43571 times.
✓ Branch 1 taken 1059021 times.
|
1102592 | if (!b8_stride) { |
| 359 |
2/2✓ Branch 0 taken 22047 times.
✓ Branch 1 taken 21524 times.
|
43571 | if (sl->mb_y & 1) { |
| 360 | 22047 | l1ref0 += 2; | |
| 361 | 22047 | l1ref1 += 2; | |
| 362 | 22047 | l1mv0 += 2 * b4_stride; | |
| 363 | 22047 | l1mv1 += 2 * b4_stride; | |
| 364 | } | ||
| 365 | } | ||
| 366 | |||
| 367 |
2/2✓ Branch 0 taken 94917 times.
✓ Branch 1 taken 1007675 times.
|
1102592 | if (IS_INTERLACED(*mb_type) != IS_INTERLACED(mb_type_col[0])) { |
| 368 | 94917 | int n = 0; | |
| 369 |
2/2✓ Branch 0 taken 379668 times.
✓ Branch 1 taken 94917 times.
|
474585 | for (i8 = 0; i8 < 4; i8++) { |
| 370 | 379668 | int x8 = i8 & 1; | |
| 371 | 379668 | int y8 = i8 >> 1; | |
| 372 | 379668 | int xy8 = x8 + y8 * b8_stride; | |
| 373 | 379668 | int xy4 = x8 * 3 + y8 * b4_stride; | |
| 374 | int a, b; | ||
| 375 | |||
| 376 |
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])) |
| 377 | 27121 | continue; | |
| 378 | 352547 | sl->sub_mb_type[i8] = sub_mb_type; | |
| 379 | |||
| 380 | 352547 | fill_rectangle(&sl->ref_cache[0][scan8[i8 * 4]], 2, 2, 8, | |
| 381 | 352547 | (uint8_t)ref[0], 1); | |
| 382 | 352547 | fill_rectangle(&sl->ref_cache[1][scan8[i8 * 4]], 2, 2, 8, | |
| 383 | 352547 | (uint8_t)ref[1], 1); | |
| 384 |
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 && |
| 385 |
2/2✓ Branch 0 taken 134513 times.
✓ Branch 1 taken 62749 times.
|
197262 | ((l1ref0[xy8] == 0 && |
| 386 |
2/2✓ Branch 0 taken 10493 times.
✓ Branch 1 taken 124020 times.
|
134513 | FFABS(l1mv0[xy4][0]) <= 1 && |
| 387 |
2/2✓ Branch 0 taken 4460 times.
✓ Branch 1 taken 6033 times.
|
10493 | FFABS(l1mv0[xy4][1]) <= 1) || |
| 388 |
2/2✓ Branch 0 taken 12234 times.
✓ Branch 1 taken 178995 times.
|
191229 | (l1ref0[xy8] < 0 && |
| 389 |
2/2✓ Branch 0 taken 9667 times.
✓ Branch 1 taken 2567 times.
|
12234 | l1ref1[xy8] == 0 && |
| 390 |
2/2✓ Branch 0 taken 826 times.
✓ Branch 1 taken 8841 times.
|
9667 | FFABS(l1mv1[xy4][0]) <= 1 && |
| 391 |
2/2✓ Branch 0 taken 502 times.
✓ Branch 1 taken 324 times.
|
826 | FFABS(l1mv1[xy4][1]) <= 1))) { |
| 392 | 6535 | a = | |
| 393 | 6535 | b = 0; | |
| 394 |
2/2✓ Branch 0 taken 515 times.
✓ Branch 1 taken 6020 times.
|
6535 | if (ref[0] > 0) |
| 395 | 515 | a = mv[0]; | |
| 396 |
2/2✓ Branch 0 taken 159 times.
✓ Branch 1 taken 6376 times.
|
6535 | if (ref[1] > 0) |
| 397 | 159 | b = mv[1]; | |
| 398 | 6535 | n++; | |
| 399 | } else { | ||
| 400 | 346012 | a = mv[0]; | |
| 401 | 346012 | b = mv[1]; | |
| 402 | } | ||
| 403 | 352547 | fill_rectangle(&sl->mv_cache[0][scan8[i8 * 4]], 2, 2, 8, a, 4); | |
| 404 | 352547 | fill_rectangle(&sl->mv_cache[1][scan8[i8 * 4]], 2, 2, 8, b, 4); | |
| 405 | } | ||
| 406 |
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)) |
| 407 | 77034 | *mb_type = (*mb_type & ~(MB_TYPE_8x8 | MB_TYPE_16x8 | MB_TYPE_8x16 | | |
| 408 | MB_TYPE_P1L0 | MB_TYPE_P1L1)) | | ||
| 409 | 77034 | MB_TYPE_16x16 | MB_TYPE_DIRECT2; | |
| 410 |
2/2✓ Branch 0 taken 841200 times.
✓ Branch 1 taken 166475 times.
|
1007675 | } else if (IS_16X16(*mb_type)) { |
| 411 | int a, b; | ||
| 412 | |||
| 413 | 841200 | fill_rectangle(&sl->ref_cache[0][scan8[0]], 4, 4, 8, (uint8_t)ref[0], 1); | |
| 414 | 841200 | fill_rectangle(&sl->ref_cache[1][scan8[0]], 4, 4, 8, (uint8_t)ref[1], 1); | |
| 415 |
4/4✓ Branch 0 taken 627227 times.
✓ Branch 1 taken 213973 times.
✓ Branch 2 taken 627216 times.
✓ Branch 3 taken 11 times.
|
841200 | if (!IS_INTRA(mb_type_col[0]) && !sl->ref_list[1][0].parent->long_ref && |
| 416 |
2/2✓ Branch 0 taken 352630 times.
✓ Branch 1 taken 274586 times.
|
627216 | ((l1ref0[0] == 0 && |
| 417 |
2/2✓ Branch 0 taken 68883 times.
✓ Branch 1 taken 283747 times.
|
352630 | FFABS(l1mv0[0][0]) <= 1 && |
| 418 |
2/2✓ Branch 0 taken 38146 times.
✓ Branch 1 taken 30737 times.
|
68883 | FFABS(l1mv0[0][1]) <= 1) || |
| 419 |
4/4✓ Branch 0 taken 18273 times.
✓ Branch 1 taken 578206 times.
✓ Branch 2 taken 17508 times.
✓ Branch 3 taken 765 times.
|
596479 | (l1ref0[0] < 0 && !l1ref1[0] && |
| 420 |
2/2✓ Branch 0 taken 4824 times.
✓ Branch 1 taken 12684 times.
|
17508 | FFABS(l1mv1[0][0]) <= 1 && |
| 421 |
2/2✓ Branch 0 taken 3957 times.
✓ Branch 1 taken 867 times.
|
4824 | FFABS(l1mv1[0][1]) <= 1 && |
| 422 |
1/2✓ Branch 0 taken 3957 times.
✗ Branch 1 not taken.
|
3957 | h->x264_build > 33U))) { |
| 423 | 34694 | a = b = 0; | |
| 424 |
2/2✓ Branch 0 taken 7079 times.
✓ Branch 1 taken 27615 times.
|
34694 | if (ref[0] > 0) |
| 425 | 7079 | a = mv[0]; | |
| 426 |
2/2✓ Branch 0 taken 4735 times.
✓ Branch 1 taken 29959 times.
|
34694 | if (ref[1] > 0) |
| 427 | 4735 | b = mv[1]; | |
| 428 | } else { | ||
| 429 | 806506 | a = mv[0]; | |
| 430 | 806506 | b = mv[1]; | |
| 431 | } | ||
| 432 | 841200 | fill_rectangle(&sl->mv_cache[0][scan8[0]], 4, 4, 8, a, 4); | |
| 433 | 841200 | fill_rectangle(&sl->mv_cache[1][scan8[0]], 4, 4, 8, b, 4); | |
| 434 | } else { | ||
| 435 | 166475 | int n = 0; | |
| 436 |
2/2✓ Branch 0 taken 665900 times.
✓ Branch 1 taken 166475 times.
|
832375 | for (i8 = 0; i8 < 4; i8++) { |
| 437 | 665900 | const int x8 = i8 & 1; | |
| 438 | 665900 | const int y8 = i8 >> 1; | |
| 439 | |||
| 440 |
4/4✓ Branch 0 taken 271892 times.
✓ Branch 1 taken 394008 times.
✓ Branch 2 taken 124087 times.
✓ Branch 3 taken 147805 times.
|
665900 | if (is_b8x8 && !IS_DIRECT(sl->sub_mb_type[i8])) |
| 441 | 124087 | continue; | |
| 442 | 541813 | sl->sub_mb_type[i8] = sub_mb_type; | |
| 443 | |||
| 444 | 541813 | fill_rectangle(&sl->mv_cache[0][scan8[i8 * 4]], 2, 2, 8, mv[0], 4); | |
| 445 | 541813 | fill_rectangle(&sl->mv_cache[1][scan8[i8 * 4]], 2, 2, 8, mv[1], 4); | |
| 446 | 541813 | fill_rectangle(&sl->ref_cache[0][scan8[i8 * 4]], 2, 2, 8, | |
| 447 | 541813 | (uint8_t)ref[0], 1); | |
| 448 | 541813 | fill_rectangle(&sl->ref_cache[1][scan8[i8 * 4]], 2, 2, 8, | |
| 449 | 541813 | (uint8_t)ref[1], 1); | |
| 450 | |||
| 451 | assert(b8_stride == 2); | ||
| 452 | /* col_zero_flag */ | ||
| 453 |
4/4✓ Branch 0 taken 501951 times.
✓ Branch 1 taken 39862 times.
✓ Branch 2 taken 501819 times.
✓ Branch 3 taken 132 times.
|
541813 | if (!IS_INTRA(mb_type_col[0]) && !sl->ref_list[1][0].parent->long_ref && |
| 454 |
2/2✓ Branch 0 taken 170912 times.
✓ Branch 1 taken 330907 times.
|
501819 | (l1ref0[i8] == 0 || |
| 455 |
2/2✓ Branch 0 taken 12407 times.
✓ Branch 1 taken 158505 times.
|
170912 | (l1ref0[i8] < 0 && |
| 456 |
2/2✓ Branch 0 taken 11289 times.
✓ Branch 1 taken 1118 times.
|
12407 | l1ref1[i8] == 0 && |
| 457 |
1/2✓ Branch 0 taken 11289 times.
✗ Branch 1 not taken.
|
11289 | h->x264_build > 33U))) { |
| 458 |
2/2✓ Branch 0 taken 330907 times.
✓ Branch 1 taken 11289 times.
|
342196 | const int16_t (*l1mv)[2] = l1ref0[i8] == 0 ? l1mv0 : l1mv1; |
| 459 |
2/2✓ Branch 0 taken 311893 times.
✓ Branch 1 taken 30303 times.
|
342196 | if (IS_SUB_8X8(sub_mb_type)) { |
| 460 | 311893 | const int16_t *mv_col = l1mv[x8 * 3 + y8 * 3 * b4_stride]; | |
| 461 |
4/4✓ Branch 0 taken 50641 times.
✓ Branch 1 taken 261252 times.
✓ Branch 2 taken 27047 times.
✓ Branch 3 taken 23594 times.
|
311893 | if (FFABS(mv_col[0]) <= 1 && FFABS(mv_col[1]) <= 1) { |
| 462 |
2/2✓ Branch 0 taken 23080 times.
✓ Branch 1 taken 3967 times.
|
27047 | if (ref[0] == 0) |
| 463 | 23080 | fill_rectangle(&sl->mv_cache[0][scan8[i8 * 4]], 2, 2, | |
| 464 | 8, 0, 4); | ||
| 465 |
2/2✓ Branch 0 taken 24722 times.
✓ Branch 1 taken 2325 times.
|
27047 | if (ref[1] == 0) |
| 466 | 24722 | fill_rectangle(&sl->mv_cache[1][scan8[i8 * 4]], 2, 2, | |
| 467 | 8, 0, 4); | ||
| 468 | 27047 | n += 4; | |
| 469 | } | ||
| 470 | } else { | ||
| 471 | 30303 | int m = 0; | |
| 472 |
2/2✓ Branch 0 taken 121212 times.
✓ Branch 1 taken 30303 times.
|
151515 | for (i4 = 0; i4 < 4; i4++) { |
| 473 | 121212 | const int16_t *mv_col = l1mv[x8 * 2 + (i4 & 1) + | |
| 474 | 121212 | (y8 * 2 + (i4 >> 1)) * b4_stride]; | |
| 475 |
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) { |
| 476 |
2/2✓ Branch 0 taken 2071 times.
✓ Branch 1 taken 965 times.
|
3036 | if (ref[0] == 0) |
| 477 | 2071 | AV_ZERO32(sl->mv_cache[0][scan8[i8 * 4 + i4]]); | |
| 478 |
2/2✓ Branch 0 taken 2790 times.
✓ Branch 1 taken 246 times.
|
3036 | if (ref[1] == 0) |
| 479 | 2790 | AV_ZERO32(sl->mv_cache[1][scan8[i8 * 4 + i4]]); | |
| 480 | 3036 | m++; | |
| 481 | } | ||
| 482 | } | ||
| 483 |
2/2✓ Branch 0 taken 29990 times.
✓ Branch 1 taken 313 times.
|
30303 | if (!(m & 3)) |
| 484 | 29990 | sl->sub_mb_type[i8] += MB_TYPE_16x16 - MB_TYPE_8x8; | |
| 485 | 30303 | n += m; | |
| 486 | } | ||
| 487 | } | ||
| 488 | } | ||
| 489 |
4/4✓ Branch 0 taken 98502 times.
✓ Branch 1 taken 67973 times.
✓ Branch 2 taken 89537 times.
✓ Branch 3 taken 8965 times.
|
166475 | if (!is_b8x8 && !(n & 15)) |
| 490 | 89537 | *mb_type = (*mb_type & ~(MB_TYPE_8x8 | MB_TYPE_16x8 | MB_TYPE_8x16 | | |
| 491 | MB_TYPE_P1L0 | MB_TYPE_P1L1)) | | ||
| 492 | 89537 | MB_TYPE_16x16 | MB_TYPE_DIRECT2; | |
| 493 | } | ||
| 494 | } | ||
| 495 | |||
| 496 | 252568 | static void pred_temp_direct_motion(const H264Context *const h, H264SliceContext *sl, | |
| 497 | int *mb_type) | ||
| 498 | { | ||
| 499 | 252568 | int b8_stride = 2; | |
| 500 | 252568 | int b4_stride = h->b_stride; | |
| 501 | 252568 | int mb_xy = sl->mb_xy, mb_y = sl->mb_y; | |
| 502 | int mb_type_col[2]; | ||
| 503 | const int16_t (*l1mv0)[2], (*l1mv1)[2]; | ||
| 504 | const int8_t *l1ref0, *l1ref1; | ||
| 505 | 252568 | const int is_b8x8 = IS_8X8(*mb_type); | |
| 506 | unsigned int sub_mb_type; | ||
| 507 | int i8, i4; | ||
| 508 | |||
| 509 | assert(sl->ref_list[1][0].reference & 3); | ||
| 510 | |||
| 511 | 252568 | await_reference_mb_row(h, &sl->ref_list[1][0], | |
| 512 | 252568 | sl->mb_y + !!IS_INTERLACED(*mb_type)); | |
| 513 | |||
| 514 |
2/2✓ Branch 0 taken 182932 times.
✓ Branch 1 taken 69636 times.
|
252568 | if (sl->ref_list[1][0].parent->field_picture || |
| 515 |
2/2✓ Branch 0 taken 19848 times.
✓ Branch 1 taken 163084 times.
|
182932 | IS_INTERLACED(sl->ref_list[1][0].parent->mb_type[mb_xy])) { // AFL/AFR/FR/FL -> AFL/FL |
| 516 |
2/2✓ Branch 0 taken 15720 times.
✓ Branch 1 taken 73764 times.
|
89484 | if (!IS_INTERLACED(*mb_type)) { // AFR/FR -> AFL/FL |
| 517 | 15720 | mb_y = (sl->mb_y & ~1) + sl->col_parity; | |
| 518 | 15720 | mb_xy = sl->mb_x + | |
| 519 | 15720 | ((sl->mb_y & ~1) + sl->col_parity) * h->mb_stride; | |
| 520 | 15720 | b8_stride = 0; | |
| 521 | } else { | ||
| 522 | 73764 | mb_y += sl->col_fieldoff; | |
| 523 | 73764 | mb_xy += h->mb_stride * sl->col_fieldoff; // non-zero for FL -> FL & differ parity | |
| 524 | } | ||
| 525 | 89484 | goto single_col; | |
| 526 | } else { // AFL/AFR/FR/FL -> AFR/FR | ||
| 527 |
2/2✓ Branch 0 taken 16565 times.
✓ Branch 1 taken 146519 times.
|
163084 | if (IS_INTERLACED(*mb_type)) { // AFL /FL -> AFR/FR |
| 528 | 16565 | mb_y = sl->mb_y & ~1; | |
| 529 | 16565 | mb_xy = sl->mb_x + (sl->mb_y & ~1) * h->mb_stride; | |
| 530 | 16565 | mb_type_col[0] = sl->ref_list[1][0].parent->mb_type[mb_xy]; | |
| 531 | 16565 | mb_type_col[1] = sl->ref_list[1][0].parent->mb_type[mb_xy + h->mb_stride]; | |
| 532 | 16565 | b8_stride = 2 + 4 * h->mb_stride; | |
| 533 | 16565 | b4_stride *= 6; | |
| 534 | 16565 | if (IS_INTERLACED(mb_type_col[0]) != | |
| 535 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 16565 times.
|
16565 | IS_INTERLACED(mb_type_col[1])) { |
| 536 | ✗ | mb_type_col[0] &= ~MB_TYPE_INTERLACED; | |
| 537 | ✗ | mb_type_col[1] &= ~MB_TYPE_INTERLACED; | |
| 538 | } | ||
| 539 | |||
| 540 | 16565 | sub_mb_type = MB_TYPE_16x16 | MB_TYPE_P0L0 | MB_TYPE_P0L1 | | |
| 541 | MB_TYPE_DIRECT2; /* B_SUB_8x8 */ | ||
| 542 | |||
| 543 |
2/2✓ Branch 0 taken 9903 times.
✓ Branch 1 taken 6662 times.
|
16565 | if ((mb_type_col[0] & MB_TYPE_16x16_OR_INTRA) && |
| 544 |
4/4✓ Branch 0 taken 7225 times.
✓ Branch 1 taken 2678 times.
✓ Branch 2 taken 5889 times.
✓ Branch 3 taken 1336 times.
|
9903 | (mb_type_col[1] & MB_TYPE_16x16_OR_INTRA) && |
| 545 | !is_b8x8) { | ||
| 546 | 5889 | *mb_type |= MB_TYPE_16x8 | MB_TYPE_L0L1 | | |
| 547 | MB_TYPE_DIRECT2; /* B_16x8 */ | ||
| 548 | } else { | ||
| 549 | 10676 | *mb_type |= MB_TYPE_8x8 | MB_TYPE_L0L1; | |
| 550 | } | ||
| 551 | } else { // AFR/FR -> AFR/FR | ||
| 552 | 146519 | single_col: | |
| 553 | 236003 | mb_type_col[0] = | |
| 554 | 236003 | mb_type_col[1] = sl->ref_list[1][0].parent->mb_type[mb_xy]; | |
| 555 | |||
| 556 | 236003 | sub_mb_type = MB_TYPE_16x16 | MB_TYPE_P0L0 | MB_TYPE_P0L1 | | |
| 557 | MB_TYPE_DIRECT2; /* B_SUB_8x8 */ | ||
| 558 |
4/4✓ Branch 0 taken 190423 times.
✓ Branch 1 taken 45580 times.
✓ Branch 2 taken 135424 times.
✓ Branch 3 taken 54999 times.
|
236003 | if (!is_b8x8 && (mb_type_col[0] & MB_TYPE_16x16_OR_INTRA)) { |
| 559 | 135424 | *mb_type |= MB_TYPE_16x16 | MB_TYPE_P0L0 | MB_TYPE_P0L1 | | |
| 560 | MB_TYPE_DIRECT2; /* B_16x16 */ | ||
| 561 |
2/2✓ Branch 0 taken 54999 times.
✓ Branch 1 taken 45580 times.
|
100579 | } else if (!is_b8x8 && |
| 562 |
2/2✓ Branch 0 taken 35141 times.
✓ Branch 1 taken 19858 times.
|
54999 | (mb_type_col[0] & (MB_TYPE_16x8 | MB_TYPE_8x16))) { |
| 563 | 35141 | *mb_type |= MB_TYPE_L0L1 | MB_TYPE_DIRECT2 | | |
| 564 | 35141 | (mb_type_col[0] & (MB_TYPE_16x8 | MB_TYPE_8x16)); | |
| 565 | } else { | ||
| 566 |
2/2✓ Branch 0 taken 10593 times.
✓ Branch 1 taken 54845 times.
|
65438 | if (!h->ps.sps->direct_8x8_inference_flag) { |
| 567 | /* FIXME: save sub mb types from previous frames (or derive | ||
| 568 | * from MVs) so we know exactly what block size to use */ | ||
| 569 | 10593 | sub_mb_type = MB_TYPE_8x8 | MB_TYPE_P0L0 | MB_TYPE_P0L1 | | |
| 570 | MB_TYPE_DIRECT2; /* B_SUB_4x4 */ | ||
| 571 | } | ||
| 572 | 65438 | *mb_type |= MB_TYPE_8x8 | MB_TYPE_L0L1; | |
| 573 | } | ||
| 574 | } | ||
| 575 | } | ||
| 576 | |||
| 577 | 252568 | await_reference_mb_row(h, &sl->ref_list[1][0], mb_y); | |
| 578 | |||
| 579 | 252568 | l1mv0 = (void*)&sl->ref_list[1][0].parent->motion_val[0][h->mb2b_xy[mb_xy]]; | |
| 580 | 252568 | l1mv1 = (void*)&sl->ref_list[1][0].parent->motion_val[1][h->mb2b_xy[mb_xy]]; | |
| 581 | 252568 | l1ref0 = &sl->ref_list[1][0].parent->ref_index[0][4 * mb_xy]; | |
| 582 | 252568 | l1ref1 = &sl->ref_list[1][0].parent->ref_index[1][4 * mb_xy]; | |
| 583 |
2/2✓ Branch 0 taken 15720 times.
✓ Branch 1 taken 236848 times.
|
252568 | if (!b8_stride) { |
| 584 |
2/2✓ Branch 0 taken 7767 times.
✓ Branch 1 taken 7953 times.
|
15720 | if (sl->mb_y & 1) { |
| 585 | 7767 | l1ref0 += 2; | |
| 586 | 7767 | l1ref1 += 2; | |
| 587 | 7767 | l1mv0 += 2 * b4_stride; | |
| 588 | 7767 | l1mv1 += 2 * b4_stride; | |
| 589 | } | ||
| 590 | } | ||
| 591 | |||
| 592 | { | ||
| 593 | 252568 | const int *map_col_to_list0[2] = { sl->map_col_to_list0[0], | |
| 594 | 252568 | sl->map_col_to_list0[1] }; | |
| 595 | 252568 | const int *dist_scale_factor = sl->dist_scale_factor; | |
| 596 | int ref_offset; | ||
| 597 | |||
| 598 |
4/4✓ Branch 0 taken 42787 times.
✓ Branch 1 taken 209781 times.
✓ Branch 2 taken 20468 times.
✓ Branch 3 taken 22319 times.
|
252568 | if (FRAME_MBAFF(h) && IS_INTERLACED(*mb_type)) { |
| 599 | 20468 | map_col_to_list0[0] = sl->map_col_to_list0_field[sl->mb_y & 1][0]; | |
| 600 | 20468 | map_col_to_list0[1] = sl->map_col_to_list0_field[sl->mb_y & 1][1]; | |
| 601 | 20468 | dist_scale_factor = sl->dist_scale_factor_field[sl->mb_y & 1]; | |
| 602 | } | ||
| 603 | 252568 | ref_offset = (sl->ref_list[1][0].parent->mbaff << 4) & (mb_type_col[0] >> 3); | |
| 604 | |||
| 605 |
2/2✓ Branch 0 taken 32285 times.
✓ Branch 1 taken 220283 times.
|
252568 | if (IS_INTERLACED(*mb_type) != IS_INTERLACED(mb_type_col[0])) { |
| 606 |
2/2✓ Branch 0 taken 15720 times.
✓ Branch 1 taken 16565 times.
|
32285 | int y_shift = 2 * !IS_INTERLACED(*mb_type); |
| 607 | assert(h->ps.sps->direct_8x8_inference_flag); | ||
| 608 | |||
| 609 |
2/2✓ Branch 0 taken 129140 times.
✓ Branch 1 taken 32285 times.
|
161425 | for (i8 = 0; i8 < 4; i8++) { |
| 610 | 129140 | const int x8 = i8 & 1; | |
| 611 | 129140 | const int y8 = i8 >> 1; | |
| 612 | int ref0, scale; | ||
| 613 | 129140 | const int16_t (*l1mv)[2] = l1mv0; | |
| 614 | |||
| 615 |
4/4✓ Branch 0 taken 43260 times.
✓ Branch 1 taken 85880 times.
✓ Branch 2 taken 22674 times.
✓ Branch 3 taken 20586 times.
|
129140 | if (is_b8x8 && !IS_DIRECT(sl->sub_mb_type[i8])) |
| 616 | 22674 | continue; | |
| 617 | 106466 | sl->sub_mb_type[i8] = sub_mb_type; | |
| 618 | |||
| 619 | 106466 | fill_rectangle(&sl->ref_cache[1][scan8[i8 * 4]], 2, 2, 8, 0, 1); | |
| 620 |
2/2✓ Branch 0 taken 25630 times.
✓ Branch 1 taken 80836 times.
|
106466 | if (IS_INTRA(mb_type_col[y8])) { |
| 621 | 25630 | fill_rectangle(&sl->ref_cache[0][scan8[i8 * 4]], 2, 2, 8, 0, 1); | |
| 622 | 25630 | fill_rectangle(&sl->mv_cache[0][scan8[i8 * 4]], 2, 2, 8, 0, 4); | |
| 623 | 25630 | fill_rectangle(&sl->mv_cache[1][scan8[i8 * 4]], 2, 2, 8, 0, 4); | |
| 624 | 25630 | continue; | |
| 625 | } | ||
| 626 | |||
| 627 | 80836 | ref0 = l1ref0[x8 + y8 * b8_stride]; | |
| 628 |
2/2✓ Branch 0 taken 80643 times.
✓ Branch 1 taken 193 times.
|
80836 | if (ref0 >= 0) |
| 629 | 80643 | ref0 = map_col_to_list0[0][ref0 + ref_offset]; | |
| 630 | else { | ||
| 631 | 193 | ref0 = map_col_to_list0[1][l1ref1[x8 + y8 * b8_stride] + | |
| 632 | ref_offset]; | ||
| 633 | 193 | l1mv = l1mv1; | |
| 634 | } | ||
| 635 | 80836 | scale = dist_scale_factor[ref0]; | |
| 636 | 80836 | fill_rectangle(&sl->ref_cache[0][scan8[i8 * 4]], 2, 2, 8, | |
| 637 | ref0, 1); | ||
| 638 | |||
| 639 | { | ||
| 640 | 80836 | const int16_t *mv_col = l1mv[x8 * 3 + y8 * b4_stride]; | |
| 641 | 80836 | int my_col = (mv_col[1] * (1 << y_shift)) / 2; | |
| 642 | 80836 | int mx = (scale * mv_col[0] + 128) >> 8; | |
| 643 | 80836 | int my = (scale * my_col + 128) >> 8; | |
| 644 | 80836 | fill_rectangle(&sl->mv_cache[0][scan8[i8 * 4]], 2, 2, 8, | |
| 645 | pack16to32(mx, my), 4); | ||
| 646 | 80836 | fill_rectangle(&sl->mv_cache[1][scan8[i8 * 4]], 2, 2, 8, | |
| 647 | 80836 | pack16to32(mx - mv_col[0], my - my_col), 4); | |
| 648 | } | ||
| 649 | } | ||
| 650 | 32285 | return; | |
| 651 | } | ||
| 652 | |||
| 653 | /* one-to-one mv scaling */ | ||
| 654 | |||
| 655 |
2/2✓ Branch 0 taken 127760 times.
✓ Branch 1 taken 92523 times.
|
220283 | if (IS_16X16(*mb_type)) { |
| 656 | int ref, mv0, mv1; | ||
| 657 | |||
| 658 | 127760 | fill_rectangle(&sl->ref_cache[1][scan8[0]], 4, 4, 8, 0, 1); | |
| 659 |
2/2✓ Branch 0 taken 61090 times.
✓ Branch 1 taken 66670 times.
|
127760 | if (IS_INTRA(mb_type_col[0])) { |
| 660 | 61090 | ref = mv0 = mv1 = 0; | |
| 661 | } else { | ||
| 662 | 199959 | const int ref0 = l1ref0[0] >= 0 ? map_col_to_list0[0][l1ref0[0] + ref_offset] | |
| 663 |
2/2✓ Branch 0 taken 66619 times.
✓ Branch 1 taken 51 times.
|
66670 | : map_col_to_list0[1][l1ref1[0] + ref_offset]; |
| 664 | 66670 | const int scale = dist_scale_factor[ref0]; | |
| 665 |
2/2✓ Branch 0 taken 66619 times.
✓ Branch 1 taken 51 times.
|
66670 | const int16_t *mv_col = l1ref0[0] >= 0 ? l1mv0[0] : l1mv1[0]; |
| 666 | int mv_l0[2]; | ||
| 667 | 66670 | mv_l0[0] = (scale * mv_col[0] + 128) >> 8; | |
| 668 | 66670 | mv_l0[1] = (scale * mv_col[1] + 128) >> 8; | |
| 669 | 66670 | ref = ref0; | |
| 670 | 66670 | mv0 = pack16to32(mv_l0[0], mv_l0[1]); | |
| 671 | 66670 | mv1 = pack16to32(mv_l0[0] - mv_col[0], mv_l0[1] - mv_col[1]); | |
| 672 | } | ||
| 673 | 127760 | fill_rectangle(&sl->ref_cache[0][scan8[0]], 4, 4, 8, ref, 1); | |
| 674 | 127760 | fill_rectangle(&sl->mv_cache[0][scan8[0]], 4, 4, 8, mv0, 4); | |
| 675 | 127760 | fill_rectangle(&sl->mv_cache[1][scan8[0]], 4, 4, 8, mv1, 4); | |
| 676 | } else { | ||
| 677 |
2/2✓ Branch 0 taken 370092 times.
✓ Branch 1 taken 92523 times.
|
462615 | for (i8 = 0; i8 < 4; i8++) { |
| 678 | 370092 | const int x8 = i8 & 1; | |
| 679 | 370092 | const int y8 = i8 >> 1; | |
| 680 | int ref0, scale; | ||
| 681 | 370092 | const int16_t (*l1mv)[2] = l1mv0; | |
| 682 | |||
| 683 |
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])) |
| 684 | 92478 | continue; | |
| 685 | 277614 | sl->sub_mb_type[i8] = sub_mb_type; | |
| 686 | 277614 | fill_rectangle(&sl->ref_cache[1][scan8[i8 * 4]], 2, 2, 8, 0, 1); | |
| 687 |
2/2✓ Branch 0 taken 22294 times.
✓ Branch 1 taken 255320 times.
|
277614 | if (IS_INTRA(mb_type_col[0])) { |
| 688 | 22294 | fill_rectangle(&sl->ref_cache[0][scan8[i8 * 4]], 2, 2, 8, 0, 1); | |
| 689 | 22294 | fill_rectangle(&sl->mv_cache[0][scan8[i8 * 4]], 2, 2, 8, 0, 4); | |
| 690 | 22294 | fill_rectangle(&sl->mv_cache[1][scan8[i8 * 4]], 2, 2, 8, 0, 4); | |
| 691 | 22294 | continue; | |
| 692 | } | ||
| 693 | |||
| 694 | assert(b8_stride == 2); | ||
| 695 | 255320 | ref0 = l1ref0[i8]; | |
| 696 |
2/2✓ Branch 0 taken 255300 times.
✓ Branch 1 taken 20 times.
|
255320 | if (ref0 >= 0) |
| 697 | 255300 | ref0 = map_col_to_list0[0][ref0 + ref_offset]; | |
| 698 | else { | ||
| 699 | 20 | ref0 = map_col_to_list0[1][l1ref1[i8] + ref_offset]; | |
| 700 | 20 | l1mv = l1mv1; | |
| 701 | } | ||
| 702 | 255320 | scale = dist_scale_factor[ref0]; | |
| 703 | |||
| 704 | 255320 | fill_rectangle(&sl->ref_cache[0][scan8[i8 * 4]], 2, 2, 8, | |
| 705 | ref0, 1); | ||
| 706 |
2/2✓ Branch 0 taken 230012 times.
✓ Branch 1 taken 25308 times.
|
255320 | if (IS_SUB_8X8(sub_mb_type)) { |
| 707 | 230012 | const int16_t *mv_col = l1mv[x8 * 3 + y8 * 3 * b4_stride]; | |
| 708 | 230012 | int mx = (scale * mv_col[0] + 128) >> 8; | |
| 709 | 230012 | int my = (scale * mv_col[1] + 128) >> 8; | |
| 710 | 230012 | fill_rectangle(&sl->mv_cache[0][scan8[i8 * 4]], 2, 2, 8, | |
| 711 | pack16to32(mx, my), 4); | ||
| 712 | 230012 | fill_rectangle(&sl->mv_cache[1][scan8[i8 * 4]], 2, 2, 8, | |
| 713 | 230012 | pack16to32(mx - mv_col[0], my - mv_col[1]), 4); | |
| 714 | } else { | ||
| 715 |
2/2✓ Branch 0 taken 101232 times.
✓ Branch 1 taken 25308 times.
|
126540 | for (i4 = 0; i4 < 4; i4++) { |
| 716 | 101232 | const int16_t *mv_col = l1mv[x8 * 2 + (i4 & 1) + | |
| 717 | 101232 | (y8 * 2 + (i4 >> 1)) * b4_stride]; | |
| 718 | 101232 | int16_t *mv_l0 = sl->mv_cache[0][scan8[i8 * 4 + i4]]; | |
| 719 | 101232 | mv_l0[0] = (scale * mv_col[0] + 128) >> 8; | |
| 720 | 101232 | mv_l0[1] = (scale * mv_col[1] + 128) >> 8; | |
| 721 | 101232 | AV_WN32A(sl->mv_cache[1][scan8[i8 * 4 + i4]], | |
| 722 | pack16to32(mv_l0[0] - mv_col[0], | ||
| 723 | mv_l0[1] - mv_col[1])); | ||
| 724 | } | ||
| 725 | } | ||
| 726 | } | ||
| 727 | } | ||
| 728 | } | ||
| 729 | } | ||
| 730 | |||
| 731 | 3342901 | void ff_h264_pred_direct_motion(const H264Context *const h, H264SliceContext *sl, | |
| 732 | int *mb_type) | ||
| 733 | { | ||
| 734 |
2/2✓ Branch 0 taken 3090333 times.
✓ Branch 1 taken 252568 times.
|
3342901 | if (sl->direct_spatial_mv_pred) |
| 735 | 3090333 | pred_spatial_direct_motion(h, sl, mb_type); | |
| 736 | else | ||
| 737 | 252568 | pred_temp_direct_motion(h, sl, mb_type); | |
| 738 | 3342901 | } | |
| 739 |