FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/h264_direct.c
Date: 2026-05-03 23:58:45
Exec Total Coverage
Lines: 440 446 98.7%
Functions: 8 8 100.0%
Branches: 301 318 94.7%

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 38274 void ff_h264_direct_ref_list_init(const H264Context *const h, H264SliceContext *sl)
121 {
122 38274 H264Ref *const ref1 = &sl->ref_list[1][0];
123 38274 H264Picture *const cur = h->cur_pic_ptr;
124 int list, field;
125 38274 int sidx = (h->picture_structure & 1) ^ 1;
126 38274 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 38274 times.
✗ Branch 1 not taken.
38274 if (!h->setup_finished) {
131
2/2
✓ Branch 0 taken 47253 times.
✓ Branch 1 taken 38274 times.
85527 for (list = 0; list < sl->list_count; list++) {
132 47253 cur->ref_count[sidx][list] = sl->ref_count[list];
133
2/2
✓ Branch 0 taken 142429 times.
✓ Branch 1 taken 47253 times.
189682 for (int j = 0; j < sl->ref_count[list]; j++)
134 142429 cur->ref_poc[sidx][list][j] = 4 * sl->ref_list[list][j].parent->frame_num +
135 142429 (sl->ref_list[list][j].reference & 3);
136 }
137
138
2/2
✓ Branch 0 taken 29114 times.
✓ Branch 1 taken 9160 times.
38274 if (h->picture_structure == PICT_FRAME) {
139 29114 memcpy(cur->ref_count[1], cur->ref_count[0], sizeof(cur->ref_count[0]));
140 29114 memcpy(cur->ref_poc[1], cur->ref_poc[0], sizeof(cur->ref_poc[0]));
141 }
142
143
2/2
✓ Branch 0 taken 29100 times.
✓ Branch 1 taken 9174 times.
38274 if (h->current_slice == 0) {
144 29100 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 38274 sl->col_fieldoff = 0;
151
152
3/4
✓ Branch 0 taken 13537 times.
✓ Branch 1 taken 24737 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 13537 times.
38274 if (sl->list_count != 2 || !sl->ref_count[1])
153 24737 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 4693094 int ref_field = ref->reference - 1;
188 4693094 int ref_field_picture = ref->parent->field_picture;
189 4693094 int ref_height = 16 * h->mb_height >> ref_field_picture;
190
191
2/2
✓ Branch 0 taken 4664211 times.
✓ Branch 1 taken 28883 times.
4693094 if (!HAVE_THREADS || !(h->avctx->active_thread_type & FF_THREAD_FRAME))
192 4664211 return;
193
194 /* FIXME: It can be safe to access mb stuff
195 * even if pixels aren't deblocked yet. */
196
197
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,
198
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 28883 times.
28883 FFMIN(16 * mb_y >> ref_field_picture,
199 ref_height - 1),
200 ref_field_picture && ref_field);
201 }
202
203 3086612 static void pred_spatial_direct_motion(const H264Context *const h, H264SliceContext *sl,
204 int *mb_type)
205 {
206 3086612 int b8_stride = 2;
207 3086612 int b4_stride = h->b_stride;
208 3086612 int mb_xy = sl->mb_xy, mb_y = sl->mb_y;
209 int mb_type_col[2];
210 const int16_t (*l1mv0)[2], (*l1mv1)[2];
211 const int8_t *l1ref0, *l1ref1;
212 3086612 const int is_b8x8 = IS_8X8(*mb_type);
213 3086612 unsigned int sub_mb_type = MB_TYPE_L0L1;
214 int i8, i4;
215 int ref[2];
216 int mv[2];
217 int list;
218
219 assert(sl->ref_list[1][0].reference & 3);
220
221 3086612 await_reference_mb_row(h, &sl->ref_list[1][0],
222 3086612 sl->mb_y + !!IS_INTERLACED(*mb_type));
223
224 #define MB_TYPE_16x16_OR_INTRA (MB_TYPE_16x16 | MB_TYPE_INTRA4x4 | \
225 MB_TYPE_INTRA16x16 | MB_TYPE_INTRA_PCM)
226
227 /* ref = min(neighbors) */
228
2/2
✓ Branch 0 taken 6173224 times.
✓ Branch 1 taken 3086612 times.
9259836 for (list = 0; list < 2; list++) {
229 6173224 int left_ref = sl->ref_cache[list][scan8[0] - 1];
230 6173224 int top_ref = sl->ref_cache[list][scan8[0] - 8];
231 6173224 int refc = sl->ref_cache[list][scan8[0] - 8 + 4];
232 6173224 const int16_t *C = sl->mv_cache[list][scan8[0] - 8 + 4];
233
2/2
✓ Branch 0 taken 757282 times.
✓ Branch 1 taken 5415942 times.
6173224 if (refc == PART_NOT_AVAILABLE) {
234 757282 refc = sl->ref_cache[list][scan8[0] - 8 - 1];
235 757282 C = sl->mv_cache[list][scan8[0] - 8 - 1];
236 }
237 6173224 ref[list] = FFMIN3((unsigned)left_ref,
238 (unsigned)top_ref,
239 (unsigned)refc);
240
2/2
✓ Branch 0 taken 5664621 times.
✓ Branch 1 taken 508603 times.
6173224 if (ref[list] >= 0) {
241 /* This is just pred_motion() but with the cases removed that
242 * cannot happen for direct blocks. */
243 5664621 const int16_t *const A = sl->mv_cache[list][scan8[0] - 1];
244 5664621 const int16_t *const B = sl->mv_cache[list][scan8[0] - 8];
245
246 5664621 int match_count = (left_ref == ref[list]) +
247 5664621 (top_ref == ref[list]) +
248 5664621 (refc == ref[list]);
249
250
2/2
✓ Branch 0 taken 5028526 times.
✓ Branch 1 taken 636095 times.
5664621 if (match_count > 1) { // most common
251 5028526 mv[list] = pack16to32(mid_pred(A[0], B[0], C[0]),
252 5028526 mid_pred(A[1], B[1], C[1]));
253 } else {
254 assert(match_count == 1);
255
2/2
✓ Branch 0 taken 500433 times.
✓ Branch 1 taken 135662 times.
636095 if (left_ref == ref[list])
256 500433 mv[list] = AV_RN32A(A);
257
2/2
✓ Branch 0 taken 63669 times.
✓ Branch 1 taken 71993 times.
135662 else if (top_ref == ref[list])
258 63669 mv[list] = AV_RN32A(B);
259 else
260 71993 mv[list] = AV_RN32A(C);
261 }
262 av_assert2(ref[list] < (sl->ref_count[list] << !!FRAME_MBAFF(h)));
263 } else {
264 508603 int mask = ~(MB_TYPE_L0 << (2 * list));
265 508603 mv[list] = 0;
266 508603 ref[list] = -1;
267
2/2
✓ Branch 0 taken 482573 times.
✓ Branch 1 taken 26030 times.
508603 if (!is_b8x8)
268 482573 *mb_type &= mask;
269 508603 sub_mb_type &= mask;
270 }
271 }
272
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) {
273 6981 ref[0] = ref[1] = 0;
274
2/2
✓ Branch 0 taken 6088 times.
✓ Branch 1 taken 893 times.
6981 if (!is_b8x8)
275 6088 *mb_type |= MB_TYPE_L0L1;
276 6981 sub_mb_type |= MB_TYPE_L0L1;
277 }
278
279
2/2
✓ Branch 0 taken 1985168 times.
✓ Branch 1 taken 1101444 times.
3086612 if (!(is_b8x8 | mv[0] | mv[1])) {
280 1985168 fill_rectangle(&sl->ref_cache[0][scan8[0]], 4, 4, 8, (uint8_t)ref[0], 1);
281 1985168 fill_rectangle(&sl->ref_cache[1][scan8[0]], 4, 4, 8, (uint8_t)ref[1], 1);
282 1985168 fill_rectangle(&sl->mv_cache[0][scan8[0]], 4, 4, 8, 0, 4);
283 1985168 fill_rectangle(&sl->mv_cache[1][scan8[0]], 4, 4, 8, 0, 4);
284 1985168 *mb_type = (*mb_type & ~(MB_TYPE_8x8 | MB_TYPE_16x8 | MB_TYPE_8x16 |
285 MB_TYPE_P1L0 | MB_TYPE_P1L1)) |
286 1985168 MB_TYPE_16x16 | MB_TYPE_DIRECT2;
287 1985168 return;
288 }
289
290
2/2
✓ Branch 0 taken 725700 times.
✓ Branch 1 taken 375744 times.
1101444 if (IS_INTERLACED(sl->ref_list[1][0].parent->mb_type[mb_xy])) { // AFL/AFR/FR/FL -> AFL/FL
291
2/2
✓ Branch 0 taken 43571 times.
✓ Branch 1 taken 682129 times.
725700 if (!IS_INTERLACED(*mb_type)) { // AFR/FR -> AFL/FL
292 43571 mb_y = (sl->mb_y & ~1) + sl->col_parity;
293 43571 mb_xy = sl->mb_x +
294 43571 ((sl->mb_y & ~1) + sl->col_parity) * h->mb_stride;
295 43571 b8_stride = 0;
296 } else {
297 682129 mb_y += sl->col_fieldoff;
298 682129 mb_xy += h->mb_stride * sl->col_fieldoff; // non-zero for FL -> FL & differ parity
299 }
300 725700 goto single_col;
301 } else { // AFL/AFR/FR/FL -> AFR/FR
302
2/2
✓ Branch 0 taken 51346 times.
✓ Branch 1 taken 324398 times.
375744 if (IS_INTERLACED(*mb_type)) { // AFL /FL -> AFR/FR
303 51346 mb_y = sl->mb_y & ~1;
304 51346 mb_xy = (sl->mb_y & ~1) * h->mb_stride + sl->mb_x;
305 51346 mb_type_col[0] = sl->ref_list[1][0].parent->mb_type[mb_xy];
306 51346 mb_type_col[1] = sl->ref_list[1][0].parent->mb_type[mb_xy + h->mb_stride];
307 51346 b8_stride = 2 + 4 * h->mb_stride;
308 51346 b4_stride *= 6;
309 51346 if (IS_INTERLACED(mb_type_col[0]) !=
310
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 51346 times.
51346 IS_INTERLACED(mb_type_col[1])) {
311 mb_type_col[0] &= ~MB_TYPE_INTERLACED;
312 mb_type_col[1] &= ~MB_TYPE_INTERLACED;
313 }
314
315 51346 sub_mb_type |= MB_TYPE_16x16 | MB_TYPE_DIRECT2; /* B_SUB_8x8 */
316
2/2
✓ Branch 0 taken 40827 times.
✓ Branch 1 taken 10519 times.
51346 if ((mb_type_col[0] & MB_TYPE_16x16_OR_INTRA) &&
317
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) &&
318 !is_b8x8) {
319 32330 *mb_type |= MB_TYPE_16x8 | MB_TYPE_DIRECT2; /* B_16x8 */
320 } else {
321 19016 *mb_type |= MB_TYPE_8x8;
322 }
323 } else { // AFR/FR -> AFR/FR
324 324398 single_col:
325 1050098 mb_type_col[0] =
326 1050098 mb_type_col[1] = sl->ref_list[1][0].parent->mb_type[mb_xy];
327
328 1050098 sub_mb_type |= MB_TYPE_16x16 | MB_TYPE_DIRECT2; /* B_SUB_8x8 */
329
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)) {
330 869244 *mb_type |= MB_TYPE_16x16 | MB_TYPE_DIRECT2; /* B_16x16 */
331
2/2
✓ Branch 0 taken 105451 times.
✓ Branch 1 taken 75403 times.
180854 } else if (!is_b8x8 &&
332
2/2
✓ Branch 0 taken 59346 times.
✓ Branch 1 taken 46105 times.
105451 (mb_type_col[0] & (MB_TYPE_16x8 | MB_TYPE_8x16))) {
333 59346 *mb_type |= MB_TYPE_DIRECT2 |
334 59346 (mb_type_col[0] & (MB_TYPE_16x8 | MB_TYPE_8x16));
335 } else {
336
2/2
✓ Branch 0 taken 21562 times.
✓ Branch 1 taken 99946 times.
121508 if (!h->ps.sps->direct_8x8_inference_flag) {
337 /* FIXME: Save sub mb types from previous frames (or derive
338 * from MVs) so we know exactly what block size to use. */
339 21562 sub_mb_type += (MB_TYPE_8x8 - MB_TYPE_16x16); /* B_SUB_4x4 */
340 }
341 121508 *mb_type |= MB_TYPE_8x8;
342 }
343 }
344 }
345
346 1101444 await_reference_mb_row(h, &sl->ref_list[1][0], mb_y);
347
348 1101444 l1mv0 = (void*)&sl->ref_list[1][0].parent->motion_val[0][h->mb2b_xy[mb_xy]];
349 1101444 l1mv1 = (void*)&sl->ref_list[1][0].parent->motion_val[1][h->mb2b_xy[mb_xy]];
350 1101444 l1ref0 = &sl->ref_list[1][0].parent->ref_index[0][4 * mb_xy];
351 1101444 l1ref1 = &sl->ref_list[1][0].parent->ref_index[1][4 * mb_xy];
352
2/2
✓ Branch 0 taken 43571 times.
✓ Branch 1 taken 1057873 times.
1101444 if (!b8_stride) {
353
2/2
✓ Branch 0 taken 22047 times.
✓ Branch 1 taken 21524 times.
43571 if (sl->mb_y & 1) {
354 22047 l1ref0 += 2;
355 22047 l1ref1 += 2;
356 22047 l1mv0 += 2 * b4_stride;
357 22047 l1mv1 += 2 * b4_stride;
358 }
359 }
360
361
2/2
✓ Branch 0 taken 94917 times.
✓ Branch 1 taken 1006527 times.
1101444 if (IS_INTERLACED(*mb_type) != IS_INTERLACED(mb_type_col[0])) {
362 94917 int n = 0;
363
2/2
✓ Branch 0 taken 379668 times.
✓ Branch 1 taken 94917 times.
474585 for (i8 = 0; i8 < 4; i8++) {
364 379668 int x8 = i8 & 1;
365 379668 int y8 = i8 >> 1;
366 379668 int xy8 = x8 + y8 * b8_stride;
367 379668 int xy4 = x8 * 3 + y8 * b4_stride;
368 int a, b;
369
370
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]))
371 27121 continue;
372 352547 sl->sub_mb_type[i8] = sub_mb_type;
373
374 352547 fill_rectangle(&sl->ref_cache[0][scan8[i8 * 4]], 2, 2, 8,
375 352547 (uint8_t)ref[0], 1);
376 352547 fill_rectangle(&sl->ref_cache[1][scan8[i8 * 4]], 2, 2, 8,
377 352547 (uint8_t)ref[1], 1);
378
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 &&
379
2/2
✓ Branch 0 taken 134513 times.
✓ Branch 1 taken 62749 times.
197262 ((l1ref0[xy8] == 0 &&
380
2/2
✓ Branch 0 taken 10493 times.
✓ Branch 1 taken 124020 times.
134513 FFABS(l1mv0[xy4][0]) <= 1 &&
381
2/2
✓ Branch 0 taken 4460 times.
✓ Branch 1 taken 6033 times.
10493 FFABS(l1mv0[xy4][1]) <= 1) ||
382
2/2
✓ Branch 0 taken 12234 times.
✓ Branch 1 taken 178995 times.
191229 (l1ref0[xy8] < 0 &&
383
2/2
✓ Branch 0 taken 9667 times.
✓ Branch 1 taken 2567 times.
12234 l1ref1[xy8] == 0 &&
384
2/2
✓ Branch 0 taken 826 times.
✓ Branch 1 taken 8841 times.
9667 FFABS(l1mv1[xy4][0]) <= 1 &&
385
2/2
✓ Branch 0 taken 502 times.
✓ Branch 1 taken 324 times.
826 FFABS(l1mv1[xy4][1]) <= 1))) {
386 6535 a =
387 6535 b = 0;
388
2/2
✓ Branch 0 taken 515 times.
✓ Branch 1 taken 6020 times.
6535 if (ref[0] > 0)
389 515 a = mv[0];
390
2/2
✓ Branch 0 taken 159 times.
✓ Branch 1 taken 6376 times.
6535 if (ref[1] > 0)
391 159 b = mv[1];
392 6535 n++;
393 } else {
394 346012 a = mv[0];
395 346012 b = mv[1];
396 }
397 352547 fill_rectangle(&sl->mv_cache[0][scan8[i8 * 4]], 2, 2, 8, a, 4);
398 352547 fill_rectangle(&sl->mv_cache[1][scan8[i8 * 4]], 2, 2, 8, b, 4);
399 }
400
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))
401 77034 *mb_type = (*mb_type & ~(MB_TYPE_8x8 | MB_TYPE_16x8 | MB_TYPE_8x16 |
402 MB_TYPE_P1L0 | MB_TYPE_P1L1)) |
403 77034 MB_TYPE_16x16 | MB_TYPE_DIRECT2;
404
2/2
✓ Branch 0 taken 840330 times.
✓ Branch 1 taken 166197 times.
1006527 } else if (IS_16X16(*mb_type)) {
405 int a, b;
406
407 840330 fill_rectangle(&sl->ref_cache[0][scan8[0]], 4, 4, 8, (uint8_t)ref[0], 1);
408 840330 fill_rectangle(&sl->ref_cache[1][scan8[0]], 4, 4, 8, (uint8_t)ref[1], 1);
409
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 &&
410
2/2
✓ Branch 0 taken 351872 times.
✓ Branch 1 taken 274524 times.
626396 ((l1ref0[0] == 0 &&
411
2/2
✓ Branch 0 taken 68362 times.
✓ Branch 1 taken 283510 times.
351872 FFABS(l1mv0[0][0]) <= 1 &&
412
2/2
✓ Branch 0 taken 37757 times.
✓ Branch 1 taken 30605 times.
68362 FFABS(l1mv0[0][1]) <= 1) ||
413
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] &&
414
2/2
✓ Branch 0 taken 4824 times.
✓ Branch 1 taken 12684 times.
17508 FFABS(l1mv1[0][0]) <= 1 &&
415
2/2
✓ Branch 0 taken 3957 times.
✓ Branch 1 taken 867 times.
4824 FFABS(l1mv1[0][1]) <= 1 &&
416
1/2
✓ Branch 0 taken 3957 times.
✗ Branch 1 not taken.
3957 h->x264_build > 33U))) {
417 34562 a = b = 0;
418
2/2
✓ Branch 0 taken 7069 times.
✓ Branch 1 taken 27493 times.
34562 if (ref[0] > 0)
419 7069 a = mv[0];
420
2/2
✓ Branch 0 taken 4735 times.
✓ Branch 1 taken 29827 times.
34562 if (ref[1] > 0)
421 4735 b = mv[1];
422 } else {
423 805768 a = mv[0];
424 805768 b = mv[1];
425 }
426 840330 fill_rectangle(&sl->mv_cache[0][scan8[0]], 4, 4, 8, a, 4);
427 840330 fill_rectangle(&sl->mv_cache[1][scan8[0]], 4, 4, 8, b, 4);
428 } else {
429 166197 int n = 0;
430
2/2
✓ Branch 0 taken 664788 times.
✓ Branch 1 taken 166197 times.
830985 for (i8 = 0; i8 < 4; i8++) {
431 664788 const int x8 = i8 & 1;
432 664788 const int y8 = i8 >> 1;
433
434
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]))
435 123777 continue;
436 541011 sl->sub_mb_type[i8] = sub_mb_type;
437
438 541011 fill_rectangle(&sl->mv_cache[0][scan8[i8 * 4]], 2, 2, 8, mv[0], 4);
439 541011 fill_rectangle(&sl->mv_cache[1][scan8[i8 * 4]], 2, 2, 8, mv[1], 4);
440 541011 fill_rectangle(&sl->ref_cache[0][scan8[i8 * 4]], 2, 2, 8,
441 541011 (uint8_t)ref[0], 1);
442 541011 fill_rectangle(&sl->ref_cache[1][scan8[i8 * 4]], 2, 2, 8,
443 541011 (uint8_t)ref[1], 1);
444
445 assert(b8_stride == 2);
446 /* col_zero_flag */
447
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 &&
448
2/2
✓ Branch 0 taken 170561 times.
✓ Branch 1 taken 330471 times.
501032 (l1ref0[i8] == 0 ||
449
2/2
✓ Branch 0 taken 12407 times.
✓ Branch 1 taken 158154 times.
170561 (l1ref0[i8] < 0 &&
450
2/2
✓ Branch 0 taken 11289 times.
✓ Branch 1 taken 1118 times.
12407 l1ref1[i8] == 0 &&
451
1/2
✓ Branch 0 taken 11289 times.
✗ Branch 1 not taken.
11289 h->x264_build > 33U))) {
452
2/2
✓ Branch 0 taken 330471 times.
✓ Branch 1 taken 11289 times.
341760 const int16_t (*l1mv)[2] = l1ref0[i8] == 0 ? l1mv0 : l1mv1;
453
2/2
✓ Branch 0 taken 311457 times.
✓ Branch 1 taken 30303 times.
341760 if (IS_SUB_8X8(sub_mb_type)) {
454 311457 const int16_t *mv_col = l1mv[x8 * 3 + y8 * 3 * b4_stride];
455
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) {
456
2/2
✓ Branch 0 taken 23004 times.
✓ Branch 1 taken 3960 times.
26964 if (ref[0] == 0)
457 23004 fill_rectangle(&sl->mv_cache[0][scan8[i8 * 4]], 2, 2,
458 8, 0, 4);
459
2/2
✓ Branch 0 taken 24656 times.
✓ Branch 1 taken 2308 times.
26964 if (ref[1] == 0)
460 24656 fill_rectangle(&sl->mv_cache[1][scan8[i8 * 4]], 2, 2,
461 8, 0, 4);
462 26964 n += 4;
463 }
464 } else {
465 30303 int m = 0;
466
2/2
✓ Branch 0 taken 121212 times.
✓ Branch 1 taken 30303 times.
151515 for (i4 = 0; i4 < 4; i4++) {
467 121212 const int16_t *mv_col = l1mv[x8 * 2 + (i4 & 1) +
468 121212 (y8 * 2 + (i4 >> 1)) * b4_stride];
469
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) {
470
2/2
✓ Branch 0 taken 2071 times.
✓ Branch 1 taken 965 times.
3036 if (ref[0] == 0)
471 2071 AV_ZERO32(sl->mv_cache[0][scan8[i8 * 4 + i4]]);
472
2/2
✓ Branch 0 taken 2790 times.
✓ Branch 1 taken 246 times.
3036 if (ref[1] == 0)
473 2790 AV_ZERO32(sl->mv_cache[1][scan8[i8 * 4 + i4]]);
474 3036 m++;
475 }
476 }
477
2/2
✓ Branch 0 taken 29990 times.
✓ Branch 1 taken 313 times.
30303 if (!(m & 3))
478 29990 sl->sub_mb_type[i8] += MB_TYPE_16x16 - MB_TYPE_8x8;
479 30303 n += m;
480 }
481 }
482 }
483
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))
484 89418 *mb_type = (*mb_type & ~(MB_TYPE_8x8 | MB_TYPE_16x8 | MB_TYPE_8x16 |
485 MB_TYPE_P1L0 | MB_TYPE_P1L1)) |
486 89418 MB_TYPE_16x16 | MB_TYPE_DIRECT2;
487 }
488 }
489
490 252519 static void pred_temp_direct_motion(const H264Context *const h, H264SliceContext *sl,
491 int *mb_type)
492 {
493 252519 int b8_stride = 2;
494 252519 int b4_stride = h->b_stride;
495 252519 int mb_xy = sl->mb_xy, mb_y = sl->mb_y;
496 int mb_type_col[2];
497 const int16_t (*l1mv0)[2], (*l1mv1)[2];
498 const int8_t *l1ref0, *l1ref1;
499 252519 const int is_b8x8 = IS_8X8(*mb_type);
500 unsigned int sub_mb_type;
501 int i8, i4;
502
503 assert(sl->ref_list[1][0].reference & 3);
504
505 252519 await_reference_mb_row(h, &sl->ref_list[1][0],
506 252519 sl->mb_y + !!IS_INTERLACED(*mb_type));
507
508
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
509
2/2
✓ Branch 0 taken 15717 times.
✓ Branch 1 taken 73763 times.
89480 if (!IS_INTERLACED(*mb_type)) { // AFR/FR -> AFL/FL
510 15717 mb_y = (sl->mb_y & ~1) + sl->col_parity;
511 15717 mb_xy = sl->mb_x +
512 15717 ((sl->mb_y & ~1) + sl->col_parity) * h->mb_stride;
513 15717 b8_stride = 0;
514 } else {
515 73763 mb_y += sl->col_fieldoff;
516 73763 mb_xy += h->mb_stride * sl->col_fieldoff; // non-zero for FL -> FL & differ parity
517 }
518 89480 goto single_col;
519 } else { // AFL/AFR/FR/FL -> AFR/FR
520
2/2
✓ Branch 0 taken 16549 times.
✓ Branch 1 taken 146490 times.
163039 if (IS_INTERLACED(*mb_type)) { // AFL /FL -> AFR/FR
521 16549 mb_y = sl->mb_y & ~1;
522 16549 mb_xy = sl->mb_x + (sl->mb_y & ~1) * h->mb_stride;
523 16549 mb_type_col[0] = sl->ref_list[1][0].parent->mb_type[mb_xy];
524 16549 mb_type_col[1] = sl->ref_list[1][0].parent->mb_type[mb_xy + h->mb_stride];
525 16549 b8_stride = 2 + 4 * h->mb_stride;
526 16549 b4_stride *= 6;
527 16549 if (IS_INTERLACED(mb_type_col[0]) !=
528
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16549 times.
16549 IS_INTERLACED(mb_type_col[1])) {
529 mb_type_col[0] &= ~MB_TYPE_INTERLACED;
530 mb_type_col[1] &= ~MB_TYPE_INTERLACED;
531 }
532
533 16549 sub_mb_type = MB_TYPE_16x16 | MB_TYPE_P0L0 | MB_TYPE_P0L1 |
534 MB_TYPE_DIRECT2; /* B_SUB_8x8 */
535
536
2/2
✓ Branch 0 taken 9887 times.
✓ Branch 1 taken 6662 times.
16549 if ((mb_type_col[0] & MB_TYPE_16x16_OR_INTRA) &&
537
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) &&
538 !is_b8x8) {
539 5873 *mb_type |= MB_TYPE_16x8 | MB_TYPE_L0L1 |
540 MB_TYPE_DIRECT2; /* B_16x8 */
541 } else {
542 10676 *mb_type |= MB_TYPE_8x8 | MB_TYPE_L0L1;
543 }
544 } else { // AFR/FR -> AFR/FR
545 146490 single_col:
546 235970 mb_type_col[0] =
547 235970 mb_type_col[1] = sl->ref_list[1][0].parent->mb_type[mb_xy];
548
549 235970 sub_mb_type = MB_TYPE_16x16 | MB_TYPE_P0L0 | MB_TYPE_P0L1 |
550 MB_TYPE_DIRECT2; /* B_SUB_8x8 */
551
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)) {
552 135391 *mb_type |= MB_TYPE_16x16 | MB_TYPE_P0L0 | MB_TYPE_P0L1 |
553 MB_TYPE_DIRECT2; /* B_16x16 */
554
2/2
✓ Branch 0 taken 54999 times.
✓ Branch 1 taken 45580 times.
100579 } else if (!is_b8x8 &&
555
2/2
✓ Branch 0 taken 35141 times.
✓ Branch 1 taken 19858 times.
54999 (mb_type_col[0] & (MB_TYPE_16x8 | MB_TYPE_8x16))) {
556 35141 *mb_type |= MB_TYPE_L0L1 | MB_TYPE_DIRECT2 |
557 35141 (mb_type_col[0] & (MB_TYPE_16x8 | MB_TYPE_8x16));
558 } else {
559
2/2
✓ Branch 0 taken 10593 times.
✓ Branch 1 taken 54845 times.
65438 if (!h->ps.sps->direct_8x8_inference_flag) {
560 /* FIXME: save sub mb types from previous frames (or derive
561 * from MVs) so we know exactly what block size to use */
562 10593 sub_mb_type = MB_TYPE_8x8 | MB_TYPE_P0L0 | MB_TYPE_P0L1 |
563 MB_TYPE_DIRECT2; /* B_SUB_4x4 */
564 }
565 65438 *mb_type |= MB_TYPE_8x8 | MB_TYPE_L0L1;
566 }
567 }
568 }
569
570 252519 await_reference_mb_row(h, &sl->ref_list[1][0], mb_y);
571
572 252519 l1mv0 = (void*)&sl->ref_list[1][0].parent->motion_val[0][h->mb2b_xy[mb_xy]];
573 252519 l1mv1 = (void*)&sl->ref_list[1][0].parent->motion_val[1][h->mb2b_xy[mb_xy]];
574 252519 l1ref0 = &sl->ref_list[1][0].parent->ref_index[0][4 * mb_xy];
575 252519 l1ref1 = &sl->ref_list[1][0].parent->ref_index[1][4 * mb_xy];
576
2/2
✓ Branch 0 taken 15717 times.
✓ Branch 1 taken 236802 times.
252519 if (!b8_stride) {
577
2/2
✓ Branch 0 taken 7766 times.
✓ Branch 1 taken 7951 times.
15717 if (sl->mb_y & 1) {
578 7766 l1ref0 += 2;
579 7766 l1ref1 += 2;
580 7766 l1mv0 += 2 * b4_stride;
581 7766 l1mv1 += 2 * b4_stride;
582 }
583 }
584
585 {
586 252519 const int *map_col_to_list0[2] = { sl->map_col_to_list0[0],
587 252519 sl->map_col_to_list0[1] };
588 252519 const int *dist_scale_factor = sl->dist_scale_factor;
589 int ref_offset;
590
591
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)) {
592 20451 map_col_to_list0[0] = sl->map_col_to_list0_field[sl->mb_y & 1][0];
593 20451 map_col_to_list0[1] = sl->map_col_to_list0_field[sl->mb_y & 1][1];
594 20451 dist_scale_factor = sl->dist_scale_factor_field[sl->mb_y & 1];
595 }
596 252519 ref_offset = (sl->ref_list[1][0].parent->mbaff << 4) & (mb_type_col[0] >> 3);
597
598
2/2
✓ Branch 0 taken 32266 times.
✓ Branch 1 taken 220253 times.
252519 if (IS_INTERLACED(*mb_type) != IS_INTERLACED(mb_type_col[0])) {
599
2/2
✓ Branch 0 taken 15717 times.
✓ Branch 1 taken 16549 times.
32266 int y_shift = 2 * !IS_INTERLACED(*mb_type);
600 assert(h->ps.sps->direct_8x8_inference_flag);
601
602
2/2
✓ Branch 0 taken 129064 times.
✓ Branch 1 taken 32266 times.
161330 for (i8 = 0; i8 < 4; i8++) {
603 129064 const int x8 = i8 & 1;
604 129064 const int y8 = i8 >> 1;
605 int ref0, scale;
606 129064 const int16_t (*l1mv)[2] = l1mv0;
607
608
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]))
609 22674 continue;
610 106390 sl->sub_mb_type[i8] = sub_mb_type;
611
612 106390 fill_rectangle(&sl->ref_cache[1][scan8[i8 * 4]], 2, 2, 8, 0, 1);
613
2/2
✓ Branch 0 taken 25592 times.
✓ Branch 1 taken 80798 times.
106390 if (IS_INTRA(mb_type_col[y8])) {
614 25592 fill_rectangle(&sl->ref_cache[0][scan8[i8 * 4]], 2, 2, 8, 0, 1);
615 25592 fill_rectangle(&sl->mv_cache[0][scan8[i8 * 4]], 2, 2, 8, 0, 4);
616 25592 fill_rectangle(&sl->mv_cache[1][scan8[i8 * 4]], 2, 2, 8, 0, 4);
617 25592 continue;
618 }
619
620 80798 ref0 = l1ref0[x8 + y8 * b8_stride];
621
2/2
✓ Branch 0 taken 80605 times.
✓ Branch 1 taken 193 times.
80798 if (ref0 >= 0)
622 80605 ref0 = map_col_to_list0[0][ref0 + ref_offset];
623 else {
624 193 ref0 = map_col_to_list0[1][l1ref1[x8 + y8 * b8_stride] +
625 ref_offset];
626 193 l1mv = l1mv1;
627 }
628 80798 scale = dist_scale_factor[ref0];
629 80798 fill_rectangle(&sl->ref_cache[0][scan8[i8 * 4]], 2, 2, 8,
630 ref0, 1);
631
632 {
633 80798 const int16_t *mv_col = l1mv[x8 * 3 + y8 * b4_stride];
634 80798 int my_col = (mv_col[1] * (1 << y_shift)) / 2;
635 80798 int mx = (scale * mv_col[0] + 128) >> 8;
636 80798 int my = (scale * my_col + 128) >> 8;
637 80798 fill_rectangle(&sl->mv_cache[0][scan8[i8 * 4]], 2, 2, 8,
638 pack16to32(mx, my), 4);
639 80798 fill_rectangle(&sl->mv_cache[1][scan8[i8 * 4]], 2, 2, 8,
640 80798 pack16to32(mx - mv_col[0], my - my_col), 4);
641 }
642 }
643 32266 return;
644 }
645
646 /* one-to-one mv scaling */
647
648
2/2
✓ Branch 0 taken 127730 times.
✓ Branch 1 taken 92523 times.
220253 if (IS_16X16(*mb_type)) {
649 int ref, mv0, mv1;
650
651 127730 fill_rectangle(&sl->ref_cache[1][scan8[0]], 4, 4, 8, 0, 1);
652
2/2
✓ Branch 0 taken 61083 times.
✓ Branch 1 taken 66647 times.
127730 if (IS_INTRA(mb_type_col[0])) {
653 61083 ref = mv0 = mv1 = 0;
654 } else {
655 199890 const int ref0 = l1ref0[0] >= 0 ? map_col_to_list0[0][l1ref0[0] + ref_offset]
656
2/2
✓ Branch 0 taken 66596 times.
✓ Branch 1 taken 51 times.
66647 : map_col_to_list0[1][l1ref1[0] + ref_offset];
657 66647 const int scale = dist_scale_factor[ref0];
658
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];
659 int mv_l0[2];
660 66647 mv_l0[0] = (scale * mv_col[0] + 128) >> 8;
661 66647 mv_l0[1] = (scale * mv_col[1] + 128) >> 8;
662 66647 ref = ref0;
663 66647 mv0 = pack16to32(mv_l0[0], mv_l0[1]);
664 66647 mv1 = pack16to32(mv_l0[0] - mv_col[0], mv_l0[1] - mv_col[1]);
665 }
666 127730 fill_rectangle(&sl->ref_cache[0][scan8[0]], 4, 4, 8, ref, 1);
667 127730 fill_rectangle(&sl->mv_cache[0][scan8[0]], 4, 4, 8, mv0, 4);
668 127730 fill_rectangle(&sl->mv_cache[1][scan8[0]], 4, 4, 8, mv1, 4);
669 } else {
670
2/2
✓ Branch 0 taken 370092 times.
✓ Branch 1 taken 92523 times.
462615 for (i8 = 0; i8 < 4; i8++) {
671 370092 const int x8 = i8 & 1;
672 370092 const int y8 = i8 >> 1;
673 int ref0, scale;
674 370092 const int16_t (*l1mv)[2] = l1mv0;
675
676
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]))
677 92478 continue;
678 277614 sl->sub_mb_type[i8] = sub_mb_type;
679 277614 fill_rectangle(&sl->ref_cache[1][scan8[i8 * 4]], 2, 2, 8, 0, 1);
680
2/2
✓ Branch 0 taken 22294 times.
✓ Branch 1 taken 255320 times.
277614 if (IS_INTRA(mb_type_col[0])) {
681 22294 fill_rectangle(&sl->ref_cache[0][scan8[i8 * 4]], 2, 2, 8, 0, 1);
682 22294 fill_rectangle(&sl->mv_cache[0][scan8[i8 * 4]], 2, 2, 8, 0, 4);
683 22294 fill_rectangle(&sl->mv_cache[1][scan8[i8 * 4]], 2, 2, 8, 0, 4);
684 22294 continue;
685 }
686
687 assert(b8_stride == 2);
688 255320 ref0 = l1ref0[i8];
689
2/2
✓ Branch 0 taken 255300 times.
✓ Branch 1 taken 20 times.
255320 if (ref0 >= 0)
690 255300 ref0 = map_col_to_list0[0][ref0 + ref_offset];
691 else {
692 20 ref0 = map_col_to_list0[1][l1ref1[i8] + ref_offset];
693 20 l1mv = l1mv1;
694 }
695 255320 scale = dist_scale_factor[ref0];
696
697 255320 fill_rectangle(&sl->ref_cache[0][scan8[i8 * 4]], 2, 2, 8,
698 ref0, 1);
699
2/2
✓ Branch 0 taken 230012 times.
✓ Branch 1 taken 25308 times.
255320 if (IS_SUB_8X8(sub_mb_type)) {
700 230012 const int16_t *mv_col = l1mv[x8 * 3 + y8 * 3 * b4_stride];
701 230012 int mx = (scale * mv_col[0] + 128) >> 8;
702 230012 int my = (scale * mv_col[1] + 128) >> 8;
703 230012 fill_rectangle(&sl->mv_cache[0][scan8[i8 * 4]], 2, 2, 8,
704 pack16to32(mx, my), 4);
705 230012 fill_rectangle(&sl->mv_cache[1][scan8[i8 * 4]], 2, 2, 8,
706 230012 pack16to32(mx - mv_col[0], my - mv_col[1]), 4);
707 } else {
708
2/2
✓ Branch 0 taken 101232 times.
✓ Branch 1 taken 25308 times.
126540 for (i4 = 0; i4 < 4; i4++) {
709 101232 const int16_t *mv_col = l1mv[x8 * 2 + (i4 & 1) +
710 101232 (y8 * 2 + (i4 >> 1)) * b4_stride];
711 101232 int16_t *mv_l0 = sl->mv_cache[0][scan8[i8 * 4 + i4]];
712 101232 mv_l0[0] = (scale * mv_col[0] + 128) >> 8;
713 101232 mv_l0[1] = (scale * mv_col[1] + 128) >> 8;
714 101232 AV_WN32A(sl->mv_cache[1][scan8[i8 * 4 + i4]],
715 pack16to32(mv_l0[0] - mv_col[0],
716 mv_l0[1] - mv_col[1]));
717 }
718 }
719 }
720 }
721 }
722 }
723
724 3339131 void ff_h264_pred_direct_motion(const H264Context *const h, H264SliceContext *sl,
725 int *mb_type)
726 {
727
2/2
✓ Branch 0 taken 3086612 times.
✓ Branch 1 taken 252519 times.
3339131 if (sl->direct_spatial_mv_pred)
728 3086612 pred_spatial_direct_motion(h, sl, mb_type);
729 else
730 252519 pred_temp_direct_motion(h, sl, mb_type);
731 3339131 }
732