FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/h264_direct.c
Date: 2026-08-28 05:02:41
Exec Total Coverage
Lines: 443 450 98.4%
Functions: 8 8 100.0%
Branches: 306 326 93.9%

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 38278 void ff_h264_direct_ref_list_init(const H264Context *const h, H264SliceContext *sl)
121 {
122 38278 H264Ref *const ref1 = &sl->ref_list[1][0];
123 38278 H264Picture *const cur = h->cur_pic_ptr;
124 int list, field;
125 38278 int sidx = (h->picture_structure & 1) ^ 1;
126 38278 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 38278 times.
✗ Branch 1 not taken.
38278 if (!h->setup_finished) {
131
2/2
✓ Branch 0 taken 47251 times.
✓ Branch 1 taken 38278 times.
85529 for (list = 0; list < sl->list_count; list++) {
132 47251 cur->ref_count[sidx][list] = sl->ref_count[list];
133
2/2
✓ Branch 0 taken 142427 times.
✓ Branch 1 taken 47251 times.
189678 for (int j = 0; j < sl->ref_count[list]; j++)
134 142427 cur->ref_poc[sidx][list][j] = 4 * sl->ref_list[list][j].parent->frame_num +
135 142427 (sl->ref_list[list][j].reference & 3);
136 }
137
138
2/2
✓ Branch 0 taken 29118 times.
✓ Branch 1 taken 9160 times.
38278 if (h->picture_structure == PICT_FRAME) {
139 29118 memcpy(cur->ref_count[1], cur->ref_count[0], sizeof(cur->ref_count[0]));
140 29118 memcpy(cur->ref_poc[1], cur->ref_poc[0], sizeof(cur->ref_poc[0]));
141 }
142
143
2/2
✓ Branch 0 taken 29104 times.
✓ Branch 1 taken 9174 times.
38278 if (h->current_slice == 0) {
144 29104 cur->mbaff = FRAME_MBAFF(h);
145 } else {
146
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9174 times.
9174 av_assert0(cur->mbaff == FRAME_MBAFF(h));
147 }
148 }
149
150 38278 sl->col_fieldoff = 0;
151
152
3/4
✓ Branch 0 taken 13537 times.
✓ Branch 1 taken 24741 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 13537 times.
38278 if (sl->list_count != 2 || !sl->ref_count[1])
153 24741 return;
154
155
2/2
✓ Branch 0 taken 8542 times.
✓ Branch 1 taken 4995 times.
13537 if (h->picture_structure == PICT_FRAME) {
156 8542 int cur_poc = h->cur_pic_ptr->poc;
157 8542 const int *col_poc = sl->ref_list[1][0].parent->field_poc;
158
3/4
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 8530 times.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
8542 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 8530 sl->col_parity = (FFABS(col_poc[0] - (int64_t)cur_poc) >=
163 8530 FFABS(col_poc[1] - (int64_t)cur_poc));
164 8542 ref1sidx =
165 8542 sidx = sl->col_parity;
166 // FL -> FL & differ parity
167
2/2
✓ Branch 0 taken 1866 times.
✓ Branch 1 taken 3129 times.
4995 } 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 13537 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5827 times.
✓ Branch 3 taken 7710 times.
13537 if (sl->slice_type_nos != AV_PICTURE_TYPE_B || sl->direct_spatial_mv_pred)
173 5827 return;
174
175
2/2
✓ Branch 0 taken 15420 times.
✓ Branch 1 taken 7710 times.
23130 for (list = 0; list < 2; list++) {
176 15420 fill_colmap(h, sl, sl->map_col_to_list0, list, sidx, ref1sidx, 0);
177
2/2
✓ Branch 0 taken 1032 times.
✓ Branch 1 taken 14388 times.
15420 if (FRAME_MBAFF(h))
178
2/2
✓ Branch 0 taken 2064 times.
✓ Branch 1 taken 1032 times.
3096 for (field = 0; field < 2; field++)
179 2064 fill_colmap(h, sl, sl->map_col_to_list0_field[field], list, field,
180 field, 1);
181 }
182 }
183
184 4693094 static void await_reference_mb_row(const H264Context *const h, H264Ref *ref,
185 int mb_y)
186 {
187
2/2
✓ Branch 0 taken 4664211 times.
✓ Branch 1 taken 28883 times.
4693094 if (!HAVE_THREADS || !(h->avctx->active_thread_type & FF_THREAD_FRAME))
188 4664211 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 3086612 static void pred_spatial_direct_motion(const H264Context *const h, H264SliceContext *sl,
209 int *mb_type)
210 {
211 3086612 int b8_stride = 2;
212 3086612 int b4_stride = h->b_stride;
213 3086612 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 3086612 const int is_b8x8 = IS_8X8(*mb_type);
218 3086612 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 3086612 await_reference_mb_row(h, &sl->ref_list[1][0],
227 3086612 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 6173224 times.
✓ Branch 1 taken 3086612 times.
9259836 for (list = 0; list < 2; list++) {
234 6173224 int left_ref = sl->ref_cache[list][scan8[0] - 1];
235 6173224 int top_ref = sl->ref_cache[list][scan8[0] - 8];
236 6173224 int refc = sl->ref_cache[list][scan8[0] - 8 + 4];
237 6173224 const int16_t *C = sl->mv_cache[list][scan8[0] - 8 + 4];
238
2/2
✓ Branch 0 taken 757282 times.
✓ Branch 1 taken 5415942 times.
6173224 if (refc == PART_NOT_AVAILABLE) {
239 757282 refc = sl->ref_cache[list][scan8[0] - 8 - 1];
240 757282 C = sl->mv_cache[list][scan8[0] - 8 - 1];
241 }
242 6173224 ref[list] = FFMIN3((unsigned)left_ref,
243 (unsigned)top_ref,
244 (unsigned)refc);
245
2/2
✓ Branch 0 taken 5664621 times.
✓ Branch 1 taken 508603 times.
6173224 if (ref[list] >= 0) {
246 /* This is just pred_motion() but with the cases removed that
247 * cannot happen for direct blocks. */
248 5664621 const int16_t *const A = sl->mv_cache[list][scan8[0] - 1];
249 5664621 const int16_t *const B = sl->mv_cache[list][scan8[0] - 8];
250
251 5664621 int match_count = (left_ref == ref[list]) +
252 5664621 (top_ref == ref[list]) +
253 5664621 (refc == ref[list]);
254
255
2/2
✓ Branch 0 taken 5028526 times.
✓ Branch 1 taken 636095 times.
5664621 if (match_count > 1) { // most common
256 5028526 mv[list] = pack16to32(mid_pred(A[0], B[0], C[0]),
257 5028526 mid_pred(A[1], B[1], C[1]));
258 } else {
259 assert(match_count == 1);
260
2/2
✓ Branch 0 taken 500433 times.
✓ Branch 1 taken 135662 times.
636095 if (left_ref == ref[list])
261 500433 mv[list] = AV_RN32A(A);
262
2/2
✓ Branch 0 taken 63669 times.
✓ Branch 1 taken 71993 times.
135662 else if (top_ref == ref[list])
263 63669 mv[list] = AV_RN32A(B);
264 else
265 71993 mv[list] = AV_RN32A(C);
266 }
267 av_assert2(ref[list] < (sl->ref_count[list] << !!FRAME_MBAFF(h)));
268 } else {
269 508603 int mask = ~(MB_TYPE_L0 << (2 * list));
270 508603 mv[list] = 0;
271 508603 ref[list] = -1;
272
2/2
✓ Branch 0 taken 482573 times.
✓ Branch 1 taken 26030 times.
508603 if (!is_b8x8)
273 482573 *mb_type &= mask;
274 508603 sub_mb_type &= mask;
275 }
276 }
277
4/4
✓ Branch 0 taken 253022 times.
✓ Branch 1 taken 2833590 times.
✓ Branch 2 taken 6981 times.
✓ Branch 3 taken 246041 times.
3086612 if (ref[0] < 0 && ref[1] < 0) {
278 6981 ref[0] = ref[1] = 0;
279
2/2
✓ Branch 0 taken 6088 times.
✓ Branch 1 taken 893 times.
6981 if (!is_b8x8)
280 6088 *mb_type |= MB_TYPE_L0L1;
281 6981 sub_mb_type |= MB_TYPE_L0L1;
282 }
283
284
2/2
✓ Branch 0 taken 1985168 times.
✓ Branch 1 taken 1101444 times.
3086612 if (!(is_b8x8 | mv[0] | mv[1])) {
285 1985168 fill_rectangle(&sl->ref_cache[0][scan8[0]], 4, 4, 8, (uint8_t)ref[0], 1);
286 1985168 fill_rectangle(&sl->ref_cache[1][scan8[0]], 4, 4, 8, (uint8_t)ref[1], 1);
287 1985168 fill_rectangle(&sl->mv_cache[0][scan8[0]], 4, 4, 8, 0, 4);
288 1985168 fill_rectangle(&sl->mv_cache[1][scan8[0]], 4, 4, 8, 0, 4);
289 1985168 *mb_type = (*mb_type & ~(MB_TYPE_8x8 | MB_TYPE_16x8 | MB_TYPE_8x16 |
290 MB_TYPE_P1L0 | MB_TYPE_P1L1)) |
291 1985168 MB_TYPE_16x16 | MB_TYPE_DIRECT2;
292 1985168 return;
293 }
294
295
2/2
✓ Branch 0 taken 443632 times.
✓ Branch 1 taken 657812 times.
1101444 if (sl->ref_list[1][0].parent->field_picture ||
296
2/2
✓ Branch 0 taken 67888 times.
✓ Branch 1 taken 375744 times.
443632 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 324398 times.
375744 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 324398 single_col:
331 1050098 mb_type_col[0] =
332 1050098 mb_type_col[1] = sl->ref_list[1][0].parent->mb_type[mb_xy];
333
334 1050098 sub_mb_type |= MB_TYPE_16x16 | MB_TYPE_DIRECT2; /* B_SUB_8x8 */
335
4/4
✓ Branch 0 taken 974695 times.
✓ Branch 1 taken 75403 times.
✓ Branch 2 taken 869244 times.
✓ Branch 3 taken 105451 times.
1050098 if (!is_b8x8 && (mb_type_col[0] & MB_TYPE_16x16_OR_INTRA)) {
336 869244 *mb_type |= MB_TYPE_16x16 | MB_TYPE_DIRECT2; /* B_16x16 */
337
2/2
✓ Branch 0 taken 105451 times.
✓ Branch 1 taken 75403 times.
180854 } else if (!is_b8x8 &&
338
2/2
✓ Branch 0 taken 59346 times.
✓ Branch 1 taken 46105 times.
105451 (mb_type_col[0] & (MB_TYPE_16x8 | MB_TYPE_8x16))) {
339 59346 *mb_type |= MB_TYPE_DIRECT2 |
340 59346 (mb_type_col[0] & (MB_TYPE_16x8 | MB_TYPE_8x16));
341 } else {
342
2/2
✓ Branch 0 taken 21562 times.
✓ Branch 1 taken 99946 times.
121508 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 121508 *mb_type |= MB_TYPE_8x8;
348 }
349 }
350 }
351
352 1101444 await_reference_mb_row(h, &sl->ref_list[1][0], mb_y);
353
354 1101444 l1mv0 = (void*)&sl->ref_list[1][0].parent->motion_val[0][h->mb2b_xy[mb_xy]];
355 1101444 l1mv1 = (void*)&sl->ref_list[1][0].parent->motion_val[1][h->mb2b_xy[mb_xy]];
356 1101444 l1ref0 = &sl->ref_list[1][0].parent->ref_index[0][4 * mb_xy];
357 1101444 l1ref1 = &sl->ref_list[1][0].parent->ref_index[1][4 * mb_xy];
358
2/2
✓ Branch 0 taken 43571 times.
✓ Branch 1 taken 1057873 times.
1101444 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 1006527 times.
1101444 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 840330 times.
✓ Branch 1 taken 166197 times.
1006527 } else if (IS_16X16(*mb_type)) {
411 int a, b;
412
413 840330 fill_rectangle(&sl->ref_cache[0][scan8[0]], 4, 4, 8, (uint8_t)ref[0], 1);
414 840330 fill_rectangle(&sl->ref_cache[1][scan8[0]], 4, 4, 8, (uint8_t)ref[1], 1);
415
4/4
✓ Branch 0 taken 626407 times.
✓ Branch 1 taken 213923 times.
✓ Branch 2 taken 626396 times.
✓ Branch 3 taken 11 times.
840330 if (!IS_INTRA(mb_type_col[0]) && !sl->ref_list[1][0].parent->long_ref &&
416
2/2
✓ Branch 0 taken 351872 times.
✓ Branch 1 taken 274524 times.
626396 ((l1ref0[0] == 0 &&
417
2/2
✓ Branch 0 taken 68362 times.
✓ Branch 1 taken 283510 times.
351872 FFABS(l1mv0[0][0]) <= 1 &&
418
2/2
✓ Branch 0 taken 37757 times.
✓ Branch 1 taken 30605 times.
68362 FFABS(l1mv0[0][1]) <= 1) ||
419
4/4
✓ Branch 0 taken 18273 times.
✓ Branch 1 taken 577518 times.
✓ Branch 2 taken 17508 times.
✓ Branch 3 taken 765 times.
595791 (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 34562 a = b = 0;
424
2/2
✓ Branch 0 taken 7069 times.
✓ Branch 1 taken 27493 times.
34562 if (ref[0] > 0)
425 7069 a = mv[0];
426
2/2
✓ Branch 0 taken 4735 times.
✓ Branch 1 taken 29827 times.
34562 if (ref[1] > 0)
427 4735 b = mv[1];
428 } else {
429 805768 a = mv[0];
430 805768 b = mv[1];
431 }
432 840330 fill_rectangle(&sl->mv_cache[0][scan8[0]], 4, 4, 8, a, 4);
433 840330 fill_rectangle(&sl->mv_cache[1][scan8[0]], 4, 4, 8, b, 4);
434 } else {
435 166197 int n = 0;
436
2/2
✓ Branch 0 taken 664788 times.
✓ Branch 1 taken 166197 times.
830985 for (i8 = 0; i8 < 4; i8++) {
437 664788 const int x8 = i8 & 1;
438 664788 const int y8 = i8 >> 1;
439
440
4/4
✓ Branch 0 taken 271324 times.
✓ Branch 1 taken 393464 times.
✓ Branch 2 taken 123777 times.
✓ Branch 3 taken 147547 times.
664788 if (is_b8x8 && !IS_DIRECT(sl->sub_mb_type[i8]))
441 123777 continue;
442 541011 sl->sub_mb_type[i8] = sub_mb_type;
443
444 541011 fill_rectangle(&sl->mv_cache[0][scan8[i8 * 4]], 2, 2, 8, mv[0], 4);
445 541011 fill_rectangle(&sl->mv_cache[1][scan8[i8 * 4]], 2, 2, 8, mv[1], 4);
446 541011 fill_rectangle(&sl->ref_cache[0][scan8[i8 * 4]], 2, 2, 8,
447 541011 (uint8_t)ref[0], 1);
448 541011 fill_rectangle(&sl->ref_cache[1][scan8[i8 * 4]], 2, 2, 8,
449 541011 (uint8_t)ref[1], 1);
450
451 assert(b8_stride == 2);
452 /* col_zero_flag */
453
4/4
✓ Branch 0 taken 501164 times.
✓ Branch 1 taken 39847 times.
✓ Branch 2 taken 501032 times.
✓ Branch 3 taken 132 times.
541011 if (!IS_INTRA(mb_type_col[0]) && !sl->ref_list[1][0].parent->long_ref &&
454
2/2
✓ Branch 0 taken 170561 times.
✓ Branch 1 taken 330471 times.
501032 (l1ref0[i8] == 0 ||
455
2/2
✓ Branch 0 taken 12407 times.
✓ Branch 1 taken 158154 times.
170561 (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 330471 times.
✓ Branch 1 taken 11289 times.
341760 const int16_t (*l1mv)[2] = l1ref0[i8] == 0 ? l1mv0 : l1mv1;
459
2/2
✓ Branch 0 taken 311457 times.
✓ Branch 1 taken 30303 times.
341760 if (IS_SUB_8X8(sub_mb_type)) {
460 311457 const int16_t *mv_col = l1mv[x8 * 3 + y8 * 3 * b4_stride];
461
4/4
✓ Branch 0 taken 50440 times.
✓ Branch 1 taken 261017 times.
✓ Branch 2 taken 26964 times.
✓ Branch 3 taken 23476 times.
311457 if (FFABS(mv_col[0]) <= 1 && FFABS(mv_col[1]) <= 1) {
462
2/2
✓ Branch 0 taken 23004 times.
✓ Branch 1 taken 3960 times.
26964 if (ref[0] == 0)
463 23004 fill_rectangle(&sl->mv_cache[0][scan8[i8 * 4]], 2, 2,
464 8, 0, 4);
465
2/2
✓ Branch 0 taken 24656 times.
✓ Branch 1 taken 2308 times.
26964 if (ref[1] == 0)
466 24656 fill_rectangle(&sl->mv_cache[1][scan8[i8 * 4]], 2, 2,
467 8, 0, 4);
468 26964 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 98366 times.
✓ Branch 1 taken 67831 times.
✓ Branch 2 taken 89418 times.
✓ Branch 3 taken 8948 times.
166197 if (!is_b8x8 && !(n & 15))
490 89418 *mb_type = (*mb_type & ~(MB_TYPE_8x8 | MB_TYPE_16x8 | MB_TYPE_8x16 |
491 MB_TYPE_P1L0 | MB_TYPE_P1L1)) |
492 89418 MB_TYPE_16x16 | MB_TYPE_DIRECT2;
493 }
494 }
495
496 252519 static void pred_temp_direct_motion(const H264Context *const h, H264SliceContext *sl,
497 int *mb_type)
498 {
499 252519 int b8_stride = 2;
500 252519 int b4_stride = h->b_stride;
501 252519 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 252519 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 252519 await_reference_mb_row(h, &sl->ref_list[1][0],
512 252519 sl->mb_y + !!IS_INTERLACED(*mb_type));
513
514
2/2
✓ Branch 0 taken 182883 times.
✓ Branch 1 taken 69636 times.
252519 if (sl->ref_list[1][0].parent->field_picture ||
515
2/2
✓ Branch 0 taken 19844 times.
✓ Branch 1 taken 163039 times.
182883 IS_INTERLACED(sl->ref_list[1][0].parent->mb_type[mb_xy])) { // AFL/AFR/FR/FL -> AFL/FL
516
2/2
✓ Branch 0 taken 15717 times.
✓ Branch 1 taken 73763 times.
89480 if (!IS_INTERLACED(*mb_type)) { // AFR/FR -> AFL/FL
517 15717 mb_y = (sl->mb_y & ~1) + sl->col_parity;
518 15717 mb_xy = sl->mb_x +
519 15717 ((sl->mb_y & ~1) + sl->col_parity) * h->mb_stride;
520 15717 b8_stride = 0;
521 } else {
522 73763 mb_y += sl->col_fieldoff;
523 73763 mb_xy += h->mb_stride * sl->col_fieldoff; // non-zero for FL -> FL & differ parity
524 }
525 89480 goto single_col;
526 } else { // AFL/AFR/FR/FL -> AFR/FR
527
2/2
✓ Branch 0 taken 16549 times.
✓ Branch 1 taken 146490 times.
163039 if (IS_INTERLACED(*mb_type)) { // AFL /FL -> AFR/FR
528 16549 mb_y = sl->mb_y & ~1;
529 16549 mb_xy = sl->mb_x + (sl->mb_y & ~1) * h->mb_stride;
530 16549 mb_type_col[0] = sl->ref_list[1][0].parent->mb_type[mb_xy];
531 16549 mb_type_col[1] = sl->ref_list[1][0].parent->mb_type[mb_xy + h->mb_stride];
532 16549 b8_stride = 2 + 4 * h->mb_stride;
533 16549 b4_stride *= 6;
534 16549 if (IS_INTERLACED(mb_type_col[0]) !=
535
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16549 times.
16549 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 16549 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 9887 times.
✓ Branch 1 taken 6662 times.
16549 if ((mb_type_col[0] & MB_TYPE_16x16_OR_INTRA) &&
544
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) &&
545 !is_b8x8) {
546 5873 *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 146490 single_col:
553 235970 mb_type_col[0] =
554 235970 mb_type_col[1] = sl->ref_list[1][0].parent->mb_type[mb_xy];
555
556 235970 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 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)) {
559 135391 *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 252519 await_reference_mb_row(h, &sl->ref_list[1][0], mb_y);
578
579 252519 l1mv0 = (void*)&sl->ref_list[1][0].parent->motion_val[0][h->mb2b_xy[mb_xy]];
580 252519 l1mv1 = (void*)&sl->ref_list[1][0].parent->motion_val[1][h->mb2b_xy[mb_xy]];
581 252519 l1ref0 = &sl->ref_list[1][0].parent->ref_index[0][4 * mb_xy];
582 252519 l1ref1 = &sl->ref_list[1][0].parent->ref_index[1][4 * mb_xy];
583
2/2
✓ Branch 0 taken 15717 times.
✓ Branch 1 taken 236802 times.
252519 if (!b8_stride) {
584
2/2
✓ Branch 0 taken 7766 times.
✓ Branch 1 taken 7951 times.
15717 if (sl->mb_y & 1) {
585 7766 l1ref0 += 2;
586 7766 l1ref1 += 2;
587 7766 l1mv0 += 2 * b4_stride;
588 7766 l1mv1 += 2 * b4_stride;
589 }
590 }
591
592 {
593 252519 const int *map_col_to_list0[2] = { sl->map_col_to_list0[0],
594 252519 sl->map_col_to_list0[1] };
595 252519 const int *dist_scale_factor = sl->dist_scale_factor;
596 int ref_offset;
597
598
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)) {
599 20451 map_col_to_list0[0] = sl->map_col_to_list0_field[sl->mb_y & 1][0];
600 20451 map_col_to_list0[1] = sl->map_col_to_list0_field[sl->mb_y & 1][1];
601 20451 dist_scale_factor = sl->dist_scale_factor_field[sl->mb_y & 1];
602 }
603 252519 ref_offset = (sl->ref_list[1][0].parent->mbaff << 4) & (mb_type_col[0] >> 3);
604
605
2/2
✓ Branch 0 taken 32266 times.
✓ Branch 1 taken 220253 times.
252519 if (IS_INTERLACED(*mb_type) != IS_INTERLACED(mb_type_col[0])) {
606
2/2
✓ Branch 0 taken 15717 times.
✓ Branch 1 taken 16549 times.
32266 int y_shift = 2 * !IS_INTERLACED(*mb_type);
607 assert(h->ps.sps->direct_8x8_inference_flag);
608
609
2/2
✓ Branch 0 taken 129064 times.
✓ Branch 1 taken 32266 times.
161330 for (i8 = 0; i8 < 4; i8++) {
610 129064 const int x8 = i8 & 1;
611 129064 const int y8 = i8 >> 1;
612 int ref0, scale;
613 129064 const int16_t (*l1mv)[2] = l1mv0;
614
615
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]))
616 22674 continue;
617 106390 sl->sub_mb_type[i8] = sub_mb_type;
618
619 106390 fill_rectangle(&sl->ref_cache[1][scan8[i8 * 4]], 2, 2, 8, 0, 1);
620
2/2
✓ Branch 0 taken 25592 times.
✓ Branch 1 taken 80798 times.
106390 if (IS_INTRA(mb_type_col[y8])) {
621 25592 fill_rectangle(&sl->ref_cache[0][scan8[i8 * 4]], 2, 2, 8, 0, 1);
622 25592 fill_rectangle(&sl->mv_cache[0][scan8[i8 * 4]], 2, 2, 8, 0, 4);
623 25592 fill_rectangle(&sl->mv_cache[1][scan8[i8 * 4]], 2, 2, 8, 0, 4);
624 25592 continue;
625 }
626
627 80798 ref0 = l1ref0[x8 + y8 * b8_stride];
628
2/2
✓ Branch 0 taken 80605 times.
✓ Branch 1 taken 193 times.
80798 if (ref0 >= 0)
629 80605 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 80798 scale = dist_scale_factor[ref0];
636 80798 fill_rectangle(&sl->ref_cache[0][scan8[i8 * 4]], 2, 2, 8,
637 ref0, 1);
638
639 {
640 80798 const int16_t *mv_col = l1mv[x8 * 3 + y8 * b4_stride];
641 80798 int my_col = (mv_col[1] * (1 << y_shift)) / 2;
642 80798 int mx = (scale * mv_col[0] + 128) >> 8;
643 80798 int my = (scale * my_col + 128) >> 8;
644 80798 fill_rectangle(&sl->mv_cache[0][scan8[i8 * 4]], 2, 2, 8,
645 pack16to32(mx, my), 4);
646 80798 fill_rectangle(&sl->mv_cache[1][scan8[i8 * 4]], 2, 2, 8,
647 80798 pack16to32(mx - mv_col[0], my - my_col), 4);
648 }
649 }
650 32266 return;
651 }
652
653 /* one-to-one mv scaling */
654
655
2/2
✓ Branch 0 taken 127730 times.
✓ Branch 1 taken 92523 times.
220253 if (IS_16X16(*mb_type)) {
656 int ref, mv0, mv1;
657
658 127730 fill_rectangle(&sl->ref_cache[1][scan8[0]], 4, 4, 8, 0, 1);
659
2/2
✓ Branch 0 taken 61083 times.
✓ Branch 1 taken 66647 times.
127730 if (IS_INTRA(mb_type_col[0])) {
660 61083 ref = mv0 = mv1 = 0;
661 } else {
662 199890 const int ref0 = l1ref0[0] >= 0 ? map_col_to_list0[0][l1ref0[0] + ref_offset]
663
2/2
✓ Branch 0 taken 66596 times.
✓ Branch 1 taken 51 times.
66647 : map_col_to_list0[1][l1ref1[0] + ref_offset];
664 66647 const int scale = dist_scale_factor[ref0];
665
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];
666 int mv_l0[2];
667 66647 mv_l0[0] = (scale * mv_col[0] + 128) >> 8;
668 66647 mv_l0[1] = (scale * mv_col[1] + 128) >> 8;
669 66647 ref = ref0;
670 66647 mv0 = pack16to32(mv_l0[0], mv_l0[1]);
671 66647 mv1 = pack16to32(mv_l0[0] - mv_col[0], mv_l0[1] - mv_col[1]);
672 }
673 127730 fill_rectangle(&sl->ref_cache[0][scan8[0]], 4, 4, 8, ref, 1);
674 127730 fill_rectangle(&sl->mv_cache[0][scan8[0]], 4, 4, 8, mv0, 4);
675 127730 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 3339131 void ff_h264_pred_direct_motion(const H264Context *const h, H264SliceContext *sl,
732 int *mb_type)
733 {
734
2/2
✓ Branch 0 taken 3086612 times.
✓ Branch 1 taken 252519 times.
3339131 if (sl->direct_spatial_mv_pred)
735 3086612 pred_spatial_direct_motion(h, sl, mb_type);
736 else
737 252519 pred_temp_direct_motion(h, sl, mb_type);
738 3339131 }
739