FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/h264_direct.c
Date: 2021-09-16 08:47:15
Exec Total Coverage
Lines: 439 445 98.7%
Branches: 300 316 94.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 "internal.h"
29 #include "avcodec.h"
30 #include "h264dec.h"
31 #include "h264_ps.h"
32 #include "mpegutils.h"
33 #include "rectangle.h"
34 #include "thread.h"
35
36 #include <assert.h>
37
38 27501 static int get_scale_factor(H264SliceContext *sl,
39 int poc, int poc1, int i)
40 {
41 27501 int poc0 = sl->ref_list[0][i].poc;
42 27501 int64_t pocdiff = poc1 - (int64_t)poc0;
43 27501 int td = av_clip_int8(pocdiff);
44
45
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 27501 times.
27501 if (pocdiff != (int)pocdiff)
46 avpriv_request_sample(sl->h264->avctx, "pocdiff overflow");
47
48
4/4
✓ Branch 0 taken 19905 times.
✓ Branch 1 taken 7596 times.
✓ Branch 2 taken 531 times.
✓ Branch 3 taken 19374 times.
27501 if (td == 0 || sl->ref_list[0][i].parent->long_ref) {
49 8127 return 256;
50 } else {
51 19374 int64_t pocdiff0 = poc - (int64_t)poc0;
52 19374 int tb = av_clip_int8(pocdiff0);
53 19374 int tx = (16384 + (FFABS(td) >> 1)) / td;
54
55
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 19374 times.
19374 if (pocdiff0 != (int)pocdiff0)
56 av_log(sl->h264->avctx, AV_LOG_DEBUG, "pocdiff0 overflow\n");
57
58 19374 return av_clip_intp2((tb * tx + 32) >> 6, 10);
59 }
60 }
61
62 7703 void ff_h264_direct_dist_scale_factor(const H264Context *const h,
63 H264SliceContext *sl)
64 {
65 18790 const int poc = FIELD_PICTURE(h) ? h->cur_pic_ptr->field_poc[h->picture_structure == PICT_BOTTOM_FIELD]
66
2/2
✓ Branch 0 taken 3384 times.
✓ Branch 1 taken 4319 times.
7703 : h->cur_pic_ptr->poc;
67 7703 const int poc1 = sl->ref_list[1][0].poc;
68 int i, field;
69
70
2/2
✓ Branch 0 taken 513 times.
✓ Branch 1 taken 7190 times.
7703 if (FRAME_MBAFF(h))
71
2/2
✓ Branch 0 taken 1026 times.
✓ Branch 1 taken 513 times.
1539 for (field = 0; field < 2; field++) {
72 1026 const int poc = h->cur_pic_ptr->field_poc[field];
73 1026 const int poc1 = sl->ref_list[1][0].parent->field_poc[field];
74
2/2
✓ Branch 0 taken 6572 times.
✓ Branch 1 taken 1026 times.
7598 for (i = 0; i < 2 * sl->ref_count[0]; i++)
75 6572 sl->dist_scale_factor_field[field][i ^ field] =
76 6572 get_scale_factor(sl, poc, poc1, i + 16);
77 }
78
79
2/2
✓ Branch 0 taken 20929 times.
✓ Branch 1 taken 7703 times.
28632 for (i = 0; i < sl->ref_count[0]; i++)
80 20929 sl->dist_scale_factor[i] = get_scale_factor(sl, poc, poc1, i);
81 7703 }
82
83 17458 static void fill_colmap(const H264Context *h, H264SliceContext *sl,
84 int map[2][16 + 32], int list,
85 int field, int colfield, int mbafi)
86 {
87 17458 H264Picture *const ref1 = sl->ref_list[1][0].parent;
88 int j, old_ref, rfield;
89
2/2
✓ Branch 0 taken 2052 times.
✓ Branch 1 taken 15406 times.
17458 int start = mbafi ? 16 : 0;
90
2/2
✓ Branch 0 taken 2052 times.
✓ Branch 1 taken 15406 times.
17458 int end = mbafi ? 16 + 2 * sl->ref_count[0] : sl->ref_count[0];
91
4/4
✓ Branch 0 taken 15406 times.
✓ Branch 1 taken 2052 times.
✓ Branch 2 taken 6768 times.
✓ Branch 3 taken 8638 times.
17458 int interl = mbafi || h->picture_structure != PICT_FRAME;
92
93 /* bogus; fills in for missing frames */
94 17458 memset(map[list], 0, sizeof(map[list]));
95
96
2/2
✓ Branch 0 taken 34916 times.
✓ Branch 1 taken 17458 times.
52374 for (rfield = 0; rfield < 2; rfield++) {
97
2/2
✓ Branch 0 taken 37168 times.
✓ Branch 1 taken 34916 times.
72084 for (old_ref = 0; old_ref < ref1->ref_count[colfield][list]; old_ref++) {
98 37168 int poc = ref1->ref_poc[colfield][list][old_ref];
99
100
2/2
✓ Branch 0 taken 16796 times.
✓ Branch 1 taken 20372 times.
37168 if (!interl)
101 16796 poc |= 3;
102 // FIXME: store all MBAFF references so this is not needed
103
3/4
✓ Branch 0 taken 20372 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5396 times.
✓ Branch 3 taken 14976 times.
20372 else if (interl && (poc & 3) == 3)
104 5396 poc = (poc & ~3) + rfield + 1;
105
106
2/2
✓ Branch 0 taken 101132 times.
✓ Branch 1 taken 7392 times.
108524 for (j = start; j < end; j++) {
107 101132 if (4 * sl->ref_list[0][j].parent->frame_num +
108
2/2
✓ Branch 0 taken 29776 times.
✓ Branch 1 taken 71356 times.
101132 (sl->ref_list[0][j].reference & 3) == poc) {
109
2/2
✓ Branch 0 taken 4168 times.
✓ Branch 1 taken 25608 times.
29776 int cur_ref = mbafi ? (j - 16) ^ field : j;
110
2/2
✓ Branch 0 taken 5736 times.
✓ Branch 1 taken 24040 times.
29776 if (ref1->mbaff)
111 5736 map[list][2 * old_ref + (rfield ^ field) + 16] = cur_ref;
112
4/4
✓ Branch 0 taken 14888 times.
✓ Branch 1 taken 14888 times.
✓ Branch 2 taken 6574 times.
✓ Branch 3 taken 8314 times.
29776 if (rfield == field || !interl)
113 21462 map[list][old_ref] = cur_ref;
114 29776 break;
115 }
116 }
117 }
118 }
119 17458 }
120
121 34216 void ff_h264_direct_ref_list_init(const H264Context *const h, H264SliceContext *sl)
122 {
123 34216 H264Ref *const ref1 = &sl->ref_list[1][0];
124 34216 H264Picture *const cur = h->cur_pic_ptr;
125 int list, j, field;
126 34216 int sidx = (h->picture_structure & 1) ^ 1;
127 34216 int ref1sidx = (ref1->reference & 1) ^ 1;
128
129
2/2
✓ Branch 0 taken 42016 times.
✓ Branch 1 taken 34216 times.
76232 for (list = 0; list < sl->list_count; list++) {
130 42016 cur->ref_count[sidx][list] = sl->ref_count[list];
131
2/2
✓ Branch 0 taken 134229 times.
✓ Branch 1 taken 42016 times.
176245 for (j = 0; j < sl->ref_count[list]; j++)
132 134229 cur->ref_poc[sidx][list][j] = 4 * sl->ref_list[list][j].parent->frame_num +
133 134229 (sl->ref_list[list][j].reference & 3);
134 }
135
136
2/2
✓ Branch 0 taken 25620 times.
✓ Branch 1 taken 8596 times.
34216 if (h->picture_structure == PICT_FRAME) {
137 25620 memcpy(cur->ref_count[1], cur->ref_count[0], sizeof(cur->ref_count[0]));
138 25620 memcpy(cur->ref_poc[1], cur->ref_poc[0], sizeof(cur->ref_poc[0]));
139 }
140
141
2/2
✓ Branch 0 taken 26111 times.
✓ Branch 1 taken 8105 times.
34216 if (h->current_slice == 0) {
142 26111 cur->mbaff = FRAME_MBAFF(h);
143 } else {
144
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8105 times.
8105 av_assert0(cur->mbaff == FRAME_MBAFF(h));
145 }
146
147 34216 sl->col_fieldoff = 0;
148
149
3/4
✓ Branch 0 taken 12032 times.
✓ Branch 1 taken 22184 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 12032 times.
34216 if (sl->list_count != 2 || !sl->ref_count[1])
150 22184 return;
151
152
2/2
✓ Branch 0 taken 7453 times.
✓ Branch 1 taken 4579 times.
12032 if (h->picture_structure == PICT_FRAME) {
153 7453 int cur_poc = h->cur_pic_ptr->poc;
154 7453 int *col_poc = sl->ref_list[1][0].parent->field_poc;
155
3/4
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 7449 times.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
7453 if (col_poc[0] == INT_MAX && col_poc[1] == INT_MAX) {
156 4 av_log(h->avctx, AV_LOG_ERROR, "co located POCs unavailable\n");
157 4 sl->col_parity = 1;
158 } else
159 7449 sl->col_parity = (FFABS(col_poc[0] - (int64_t)cur_poc) >=
160 7449 FFABS(col_poc[1] - (int64_t)cur_poc));
161 7453 ref1sidx =
162 7453 sidx = sl->col_parity;
163 // FL -> FL & differ parity
164
2/2
✓ Branch 0 taken 1866 times.
✓ Branch 1 taken 2713 times.
4579 } else if (!(h->picture_structure & sl->ref_list[1][0].reference) &&
165
2/2
✓ Branch 0 taken 1728 times.
✓ Branch 1 taken 138 times.
1866 !sl->ref_list[1][0].parent->mbaff) {
166 1728 sl->col_fieldoff = 2 * sl->ref_list[1][0].reference - 3;
167 }
168
169
3/4
✓ Branch 0 taken 12032 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4329 times.
✓ Branch 3 taken 7703 times.
12032 if (sl->slice_type_nos != AV_PICTURE_TYPE_B || sl->direct_spatial_mv_pred)
170 4329 return;
171
172
2/2
✓ Branch 0 taken 15406 times.
✓ Branch 1 taken 7703 times.
23109 for (list = 0; list < 2; list++) {
173 15406 fill_colmap(h, sl, sl->map_col_to_list0, list, sidx, ref1sidx, 0);
174
2/2
✓ Branch 0 taken 1026 times.
✓ Branch 1 taken 14380 times.
15406 if (FRAME_MBAFF(h))
175
2/2
✓ Branch 0 taken 2052 times.
✓ Branch 1 taken 1026 times.
3078 for (field = 0; field < 2; field++)
176 2052 fill_colmap(h, sl, sl->map_col_to_list0_field[field], list, field,
177 field, 1);
178 }
179 }
180
181 4096924 static void await_reference_mb_row(const H264Context *const h, H264Ref *ref,
182 int mb_y)
183 {
184 4096924 int ref_field = ref->reference - 1;
185 4096924 int ref_field_picture = ref->parent->field_picture;
186 4096924 int ref_height = 16 * h->mb_height >> ref_field_picture;
187
188
2/2
✓ Branch 0 taken 4080106 times.
✓ Branch 1 taken 16818 times.
4096924 if (!HAVE_THREADS || !(h->avctx->active_thread_type & FF_THREAD_FRAME))
189 4080106 return;
190
191 /* FIXME: It can be safe to access mb stuff
192 * even if pixels aren't deblocked yet. */
193
194
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 16818 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
33636 ff_thread_await_progress(&ref->parent->tf,
195
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16818 times.
16818 FFMIN(16 * mb_y >> ref_field_picture,
196 ref_height - 1),
197 ref_field_picture && ref_field);
198 }
199
200 2608161 static void pred_spatial_direct_motion(const H264Context *const h, H264SliceContext *sl,
201 int *mb_type)
202 {
203 2608161 int b8_stride = 2;
204 2608161 int b4_stride = h->b_stride;
205 2608161 int mb_xy = sl->mb_xy, mb_y = sl->mb_y;
206 int mb_type_col[2];
207 const int16_t (*l1mv0)[2], (*l1mv1)[2];
208 const int8_t *l1ref0, *l1ref1;
209 2608161 const int is_b8x8 = IS_8X8(*mb_type);
210 2608161 unsigned int sub_mb_type = MB_TYPE_L0L1;
211 int i8, i4;
212 int ref[2];
213 int mv[2];
214 int list;
215
216 assert(sl->ref_list[1][0].reference & 3);
217
218 2608161 await_reference_mb_row(h, &sl->ref_list[1][0],
219 2608161 sl->mb_y + !!IS_INTERLACED(*mb_type));
220
221 #define MB_TYPE_16x16_OR_INTRA (MB_TYPE_16x16 | MB_TYPE_INTRA4x4 | \
222 MB_TYPE_INTRA16x16 | MB_TYPE_INTRA_PCM)
223
224 /* ref = min(neighbors) */
225
2/2
✓ Branch 0 taken 5216322 times.
✓ Branch 1 taken 2608161 times.
7824483 for (list = 0; list < 2; list++) {
226 5216322 int left_ref = sl->ref_cache[list][scan8[0] - 1];
227 5216322 int top_ref = sl->ref_cache[list][scan8[0] - 8];
228 5216322 int refc = sl->ref_cache[list][scan8[0] - 8 + 4];
229 5216322 const int16_t *C = sl->mv_cache[list][scan8[0] - 8 + 4];
230
2/2
✓ Branch 0 taken 567052 times.
✓ Branch 1 taken 4649270 times.
5216322 if (refc == PART_NOT_AVAILABLE) {
231 567052 refc = sl->ref_cache[list][scan8[0] - 8 - 1];
232 567052 C = sl->mv_cache[list][scan8[0] - 8 - 1];
233 }
234 5216322 ref[list] = FFMIN3((unsigned)left_ref,
235 (unsigned)top_ref,
236 (unsigned)refc);
237
2/2
✓ Branch 0 taken 4806933 times.
✓ Branch 1 taken 409389 times.
5216322 if (ref[list] >= 0) {
238 /* This is just pred_motion() but with the cases removed that
239 * cannot happen for direct blocks. */
240 4806933 const int16_t *const A = sl->mv_cache[list][scan8[0] - 1];
241 4806933 const int16_t *const B = sl->mv_cache[list][scan8[0] - 8];
242
243 4806933 int match_count = (left_ref == ref[list]) +
244 4806933 (top_ref == ref[list]) +
245 4806933 (refc == ref[list]);
246
247
2/2
✓ Branch 0 taken 4315513 times.
✓ Branch 1 taken 491420 times.
4806933 if (match_count > 1) { // most common
248 4315513 mv[list] = pack16to32(mid_pred(A[0], B[0], C[0]),
249 4315513 mid_pred(A[1], B[1], C[1]));
250 } else {
251 assert(match_count == 1);
252
2/2
✓ Branch 0 taken 375187 times.
✓ Branch 1 taken 116233 times.
491420 if (left_ref == ref[list])
253 375187 mv[list] = AV_RN32A(A);
254
2/2
✓ Branch 0 taken 54407 times.
✓ Branch 1 taken 61826 times.
116233 else if (top_ref == ref[list])
255 54407 mv[list] = AV_RN32A(B);
256 else
257 61826 mv[list] = AV_RN32A(C);
258 }
259 av_assert2(ref[list] < (sl->ref_count[list] << !!FRAME_MBAFF(h)));
260 } else {
261 409389 int mask = ~(MB_TYPE_L0 << (2 * list));
262 409389 mv[list] = 0;
263 409389 ref[list] = -1;
264
2/2
✓ Branch 0 taken 384940 times.
✓ Branch 1 taken 24449 times.
409389 if (!is_b8x8)
265 384940 *mb_type &= mask;
266 409389 sub_mb_type &= mask;
267 }
268 }
269
4/4
✓ Branch 0 taken 212687 times.
✓ Branch 1 taken 2395474 times.
✓ Branch 2 taken 5180 times.
✓ Branch 3 taken 207507 times.
2608161 if (ref[0] < 0 && ref[1] < 0) {
270 5180 ref[0] = ref[1] = 0;
271
2/2
✓ Branch 0 taken 4350 times.
✓ Branch 1 taken 830 times.
5180 if (!is_b8x8)
272 4350 *mb_type |= MB_TYPE_L0L1;
273 5180 sub_mb_type |= MB_TYPE_L0L1;
274 }
275
276
2/2
✓ Branch 0 taken 1623030 times.
✓ Branch 1 taken 985131 times.
2608161 if (!(is_b8x8 | mv[0] | mv[1])) {
277 1623030 fill_rectangle(&sl->ref_cache[0][scan8[0]], 4, 4, 8, (uint8_t)ref[0], 1);
278 1623030 fill_rectangle(&sl->ref_cache[1][scan8[0]], 4, 4, 8, (uint8_t)ref[1], 1);
279 1623030 fill_rectangle(&sl->mv_cache[0][scan8[0]], 4, 4, 8, 0, 4);
280 1623030 fill_rectangle(&sl->mv_cache[1][scan8[0]], 4, 4, 8, 0, 4);
281 1623030 *mb_type = (*mb_type & ~(MB_TYPE_8x8 | MB_TYPE_16x8 | MB_TYPE_8x16 |
282 MB_TYPE_P1L0 | MB_TYPE_P1L1)) |
283 1623030 MB_TYPE_16x16 | MB_TYPE_DIRECT2;
284 1623030 return;
285 }
286
287
2/2
✓ Branch 0 taken 678812 times.
✓ Branch 1 taken 306319 times.
985131 if (IS_INTERLACED(sl->ref_list[1][0].parent->mb_type[mb_xy])) { // AFL/AFR/FR/FL -> AFL/FL
288
2/2
✓ Branch 0 taken 39366 times.
✓ Branch 1 taken 639446 times.
678812 if (!IS_INTERLACED(*mb_type)) { // AFR/FR -> AFL/FL
289 39366 mb_y = (sl->mb_y & ~1) + sl->col_parity;
290 39366 mb_xy = sl->mb_x +
291 39366 ((sl->mb_y & ~1) + sl->col_parity) * h->mb_stride;
292 39366 b8_stride = 0;
293 } else {
294 639446 mb_y += sl->col_fieldoff;
295 639446 mb_xy += h->mb_stride * sl->col_fieldoff; // non-zero for FL -> FL & differ parity
296 }
297 678812 goto single_col;
298 } else { // AFL/AFR/FR/FL -> AFR/FR
299
2/2
✓ Branch 0 taken 43711 times.
✓ Branch 1 taken 262608 times.
306319 if (IS_INTERLACED(*mb_type)) { // AFL /FL -> AFR/FR
300 43711 mb_y = sl->mb_y & ~1;
301 43711 mb_xy = (sl->mb_y & ~1) * h->mb_stride + sl->mb_x;
302 43711 mb_type_col[0] = sl->ref_list[1][0].parent->mb_type[mb_xy];
303 43711 mb_type_col[1] = sl->ref_list[1][0].parent->mb_type[mb_xy + h->mb_stride];
304 43711 b8_stride = 2 + 4 * h->mb_stride;
305 43711 b4_stride *= 6;
306 43711 if (IS_INTERLACED(mb_type_col[0]) !=
307
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 43711 times.
43711 IS_INTERLACED(mb_type_col[1])) {
308 mb_type_col[0] &= ~MB_TYPE_INTERLACED;
309 mb_type_col[1] &= ~MB_TYPE_INTERLACED;
310 }
311
312 43711 sub_mb_type |= MB_TYPE_16x16 | MB_TYPE_DIRECT2; /* B_SUB_8x8 */
313
2/2
✓ Branch 0 taken 33897 times.
✓ Branch 1 taken 9814 times.
43711 if ((mb_type_col[0] & MB_TYPE_16x16_OR_INTRA) &&
314
4/4
✓ Branch 0 taken 29403 times.
✓ Branch 1 taken 4494 times.
✓ Branch 2 taken 26172 times.
✓ Branch 3 taken 3231 times.
33897 (mb_type_col[1] & MB_TYPE_16x16_OR_INTRA) &&
315 !is_b8x8) {
316 26172 *mb_type |= MB_TYPE_16x8 | MB_TYPE_DIRECT2; /* B_16x8 */
317 } else {
318 17539 *mb_type |= MB_TYPE_8x8;
319 }
320 } else { // AFR/FR -> AFR/FR
321 262608 single_col:
322 941420 mb_type_col[0] =
323 941420 mb_type_col[1] = sl->ref_list[1][0].parent->mb_type[mb_xy];
324
325 941420 sub_mb_type |= MB_TYPE_16x16 | MB_TYPE_DIRECT2; /* B_SUB_8x8 */
326
4/4
✓ Branch 0 taken 872466 times.
✓ Branch 1 taken 68954 times.
✓ Branch 2 taken 784150 times.
✓ Branch 3 taken 88316 times.
941420 if (!is_b8x8 && (mb_type_col[0] & MB_TYPE_16x16_OR_INTRA)) {
327 784150 *mb_type |= MB_TYPE_16x16 | MB_TYPE_DIRECT2; /* B_16x16 */
328
2/2
✓ Branch 0 taken 88316 times.
✓ Branch 1 taken 68954 times.
157270 } else if (!is_b8x8 &&
329
2/2
✓ Branch 0 taken 47987 times.
✓ Branch 1 taken 40329 times.
88316 (mb_type_col[0] & (MB_TYPE_16x8 | MB_TYPE_8x16))) {
330 47987 *mb_type |= MB_TYPE_DIRECT2 |
331 47987 (mb_type_col[0] & (MB_TYPE_16x8 | MB_TYPE_8x16));
332 } else {
333
2/2
✓ Branch 0 taken 21546 times.
✓ Branch 1 taken 87737 times.
109283 if (!h->ps.sps->direct_8x8_inference_flag) {
334 /* FIXME: Save sub mb types from previous frames (or derive
335 * from MVs) so we know exactly what block size to use. */
336 21546 sub_mb_type += (MB_TYPE_8x8 - MB_TYPE_16x16); /* B_SUB_4x4 */
337 }
338 109283 *mb_type |= MB_TYPE_8x8;
339 }
340 }
341 }
342
343 985131 await_reference_mb_row(h, &sl->ref_list[1][0], mb_y);
344
345 985131 l1mv0 = (void*)&sl->ref_list[1][0].parent->motion_val[0][h->mb2b_xy[mb_xy]];
346 985131 l1mv1 = (void*)&sl->ref_list[1][0].parent->motion_val[1][h->mb2b_xy[mb_xy]];
347 985131 l1ref0 = &sl->ref_list[1][0].parent->ref_index[0][4 * mb_xy];
348 985131 l1ref1 = &sl->ref_list[1][0].parent->ref_index[1][4 * mb_xy];
349
2/2
✓ Branch 0 taken 39366 times.
✓ Branch 1 taken 945765 times.
985131 if (!b8_stride) {
350
2/2
✓ Branch 0 taken 19982 times.
✓ Branch 1 taken 19384 times.
39366 if (sl->mb_y & 1) {
351 19982 l1ref0 += 2;
352 19982 l1ref1 += 2;
353 19982 l1mv0 += 2 * b4_stride;
354 19982 l1mv1 += 2 * b4_stride;
355 }
356 }
357
358
2/2
✓ Branch 0 taken 83077 times.
✓ Branch 1 taken 902054 times.
985131 if (IS_INTERLACED(*mb_type) != IS_INTERLACED(mb_type_col[0])) {
359 83077 int n = 0;
360
2/2
✓ Branch 0 taken 332308 times.
✓ Branch 1 taken 83077 times.
415385 for (i8 = 0; i8 < 4; i8++) {
361 332308 int x8 = i8 & 1;
362 332308 int y8 = i8 >> 1;
363 332308 int xy8 = x8 + y8 * b8_stride;
364 332308 int xy4 = x8 * 3 + y8 * b4_stride;
365 int a, b;
366
367
4/4
✓ Branch 0 taken 63764 times.
✓ Branch 1 taken 268544 times.
✓ Branch 2 taken 25993 times.
✓ Branch 3 taken 37771 times.
332308 if (is_b8x8 && !IS_DIRECT(sl->sub_mb_type[i8]))
368 25993 continue;
369 306315 sl->sub_mb_type[i8] = sub_mb_type;
370
371 306315 fill_rectangle(&sl->ref_cache[0][scan8[i8 * 4]], 2, 2, 8,
372 306315 (uint8_t)ref[0], 1);
373 306315 fill_rectangle(&sl->ref_cache[1][scan8[i8 * 4]], 2, 2, 8,
374 306315 (uint8_t)ref[1], 1);
375
3/4
✓ Branch 0 taken 173012 times.
✓ Branch 1 taken 133303 times.
✓ Branch 2 taken 173012 times.
✗ Branch 3 not taken.
306315 if (!IS_INTRA(mb_type_col[y8]) && !sl->ref_list[1][0].parent->long_ref &&
376
2/2
✓ Branch 0 taken 118708 times.
✓ Branch 1 taken 54304 times.
173012 ((l1ref0[xy8] == 0 &&
377
2/2
✓ Branch 0 taken 8884 times.
✓ Branch 1 taken 109824 times.
118708 FFABS(l1mv0[xy4][0]) <= 1 &&
378
2/2
✓ Branch 0 taken 3955 times.
✓ Branch 1 taken 4929 times.
8884 FFABS(l1mv0[xy4][1]) <= 1) ||
379
2/2
✓ Branch 0 taken 8526 times.
✓ Branch 1 taken 159557 times.
168083 (l1ref0[xy8] < 0 &&
380
2/2
✓ Branch 0 taken 6741 times.
✓ Branch 1 taken 1785 times.
8526 l1ref1[xy8] == 0 &&
381
2/2
✓ Branch 0 taken 574 times.
✓ Branch 1 taken 6167 times.
6741 FFABS(l1mv1[xy4][0]) <= 1 &&
382
2/2
✓ Branch 0 taken 354 times.
✓ Branch 1 taken 220 times.
574 FFABS(l1mv1[xy4][1]) <= 1))) {
383 5283 a =
384 5283 b = 0;
385
2/2
✓ Branch 0 taken 459 times.
✓ Branch 1 taken 4824 times.
5283 if (ref[0] > 0)
386 459 a = mv[0];
387
2/2
✓ Branch 0 taken 149 times.
✓ Branch 1 taken 5134 times.
5283 if (ref[1] > 0)
388 149 b = mv[1];
389 5283 n++;
390 } else {
391 301032 a = mv[0];
392 301032 b = mv[1];
393 }
394 306315 fill_rectangle(&sl->mv_cache[0][scan8[i8 * 4]], 2, 2, 8, a, 4);
395 306315 fill_rectangle(&sl->mv_cache[1][scan8[i8 * 4]], 2, 2, 8, b, 4);
396 }
397
4/4
✓ Branch 0 taken 67136 times.
✓ Branch 1 taken 15941 times.
✓ Branch 2 taken 66179 times.
✓ Branch 3 taken 957 times.
83077 if (!is_b8x8 && !(n & 3))
398 66179 *mb_type = (*mb_type & ~(MB_TYPE_8x8 | MB_TYPE_16x8 | MB_TYPE_8x16 |
399 MB_TYPE_P1L0 | MB_TYPE_P1L1)) |
400 66179 MB_TYPE_16x16 | MB_TYPE_DIRECT2;
401
2/2
✓ Branch 0 taken 759078 times.
✓ Branch 1 taken 142976 times.
902054 } else if (IS_16X16(*mb_type)) {
402 int a, b;
403
404 759078 fill_rectangle(&sl->ref_cache[0][scan8[0]], 4, 4, 8, (uint8_t)ref[0], 1);
405 759078 fill_rectangle(&sl->ref_cache[1][scan8[0]], 4, 4, 8, (uint8_t)ref[1], 1);
406
4/4
✓ Branch 0 taken 571727 times.
✓ Branch 1 taken 187351 times.
✓ Branch 2 taken 571716 times.
✓ Branch 3 taken 11 times.
759078 if (!IS_INTRA(mb_type_col[0]) && !sl->ref_list[1][0].parent->long_ref &&
407
2/2
✓ Branch 0 taken 307858 times.
✓ Branch 1 taken 263858 times.
571716 ((l1ref0[0] == 0 &&
408
2/2
✓ Branch 0 taken 57913 times.
✓ Branch 1 taken 249945 times.
307858 FFABS(l1mv0[0][0]) <= 1 &&
409
2/2
✓ Branch 0 taken 33754 times.
✓ Branch 1 taken 24159 times.
57913 FFABS(l1mv0[0][1]) <= 1) ||
410
4/4
✓ Branch 0 taken 15800 times.
✓ Branch 1 taken 531757 times.
✓ Branch 2 taken 15337 times.
✓ Branch 3 taken 463 times.
547557 (l1ref0[0] < 0 && !l1ref1[0] &&
411
2/2
✓ Branch 0 taken 4335 times.
✓ Branch 1 taken 11002 times.
15337 FFABS(l1mv1[0][0]) <= 1 &&
412
2/2
✓ Branch 0 taken 3598 times.
✓ Branch 1 taken 737 times.
4335 FFABS(l1mv1[0][1]) <= 1 &&
413
1/2
✓ Branch 0 taken 3598 times.
✗ Branch 1 not taken.
3598 h->x264_build > 33U))) {
414 27757 a = b = 0;
415
2/2
✓ Branch 0 taken 5010 times.
✓ Branch 1 taken 22747 times.
27757 if (ref[0] > 0)
416 5010 a = mv[0];
417
2/2
✓ Branch 0 taken 3330 times.
✓ Branch 1 taken 24427 times.
27757 if (ref[1] > 0)
418 3330 b = mv[1];
419 } else {
420 731321 a = mv[0];
421 731321 b = mv[1];
422 }
423 759078 fill_rectangle(&sl->mv_cache[0][scan8[0]], 4, 4, 8, a, 4);
424 759078 fill_rectangle(&sl->mv_cache[1][scan8[0]], 4, 4, 8, b, 4);
425 } else {
426 142976 int n = 0;
427
2/2
✓ Branch 0 taken 571904 times.
✓ Branch 1 taken 142976 times.
714880 for (i8 = 0; i8 < 4; i8++) {
428 571904 const int x8 = i8 & 1;
429 571904 const int y8 = i8 >> 1;
430
431
4/4
✓ Branch 0 taken 246176 times.
✓ Branch 1 taken 325728 times.
✓ Branch 2 taken 112794 times.
✓ Branch 3 taken 133382 times.
571904 if (is_b8x8 && !IS_DIRECT(sl->sub_mb_type[i8]))
432 112794 continue;
433 459110 sl->sub_mb_type[i8] = sub_mb_type;
434
435 459110 fill_rectangle(&sl->mv_cache[0][scan8[i8 * 4]], 2, 2, 8, mv[0], 4);
436 459110 fill_rectangle(&sl->mv_cache[1][scan8[i8 * 4]], 2, 2, 8, mv[1], 4);
437 459110 fill_rectangle(&sl->ref_cache[0][scan8[i8 * 4]], 2, 2, 8,
438 459110 (uint8_t)ref[0], 1);
439 459110 fill_rectangle(&sl->ref_cache[1][scan8[i8 * 4]], 2, 2, 8,
440 459110 (uint8_t)ref[1], 1);
441
442 assert(b8_stride == 2);
443 /* col_zero_flag */
444
4/4
✓ Branch 0 taken 424093 times.
✓ Branch 1 taken 35017 times.
✓ Branch 2 taken 423961 times.
✓ Branch 3 taken 132 times.
459110 if (!IS_INTRA(mb_type_col[0]) && !sl->ref_list[1][0].parent->long_ref &&
445
2/2
✓ Branch 0 taken 161723 times.
✓ Branch 1 taken 262238 times.
423961 (l1ref0[i8] == 0 ||
446
2/2
✓ Branch 0 taken 10931 times.
✓ Branch 1 taken 150792 times.
161723 (l1ref0[i8] < 0 &&
447
2/2
✓ Branch 0 taken 10185 times.
✓ Branch 1 taken 746 times.
10931 l1ref1[i8] == 0 &&
448
1/2
✓ Branch 0 taken 10185 times.
✗ Branch 1 not taken.
10185 h->x264_build > 33U))) {
449
2/2
✓ Branch 0 taken 262238 times.
✓ Branch 1 taken 10185 times.
272423 const int16_t (*l1mv)[2] = l1ref0[i8] == 0 ? l1mv0 : l1mv1;
450
2/2
✓ Branch 0 taken 242184 times.
✓ Branch 1 taken 30239 times.
272423 if (IS_SUB_8X8(sub_mb_type)) {
451 242184 const int16_t *mv_col = l1mv[x8 * 3 + y8 * 3 * b4_stride];
452
4/4
✓ Branch 0 taken 36551 times.
✓ Branch 1 taken 205633 times.
✓ Branch 2 taken 18805 times.
✓ Branch 3 taken 17746 times.
242184 if (FFABS(mv_col[0]) <= 1 && FFABS(mv_col[1]) <= 1) {
453
2/2
✓ Branch 0 taken 15715 times.
✓ Branch 1 taken 3090 times.
18805 if (ref[0] == 0)
454 15715 fill_rectangle(&sl->mv_cache[0][scan8[i8 * 4]], 2, 2,
455 8, 0, 4);
456
2/2
✓ Branch 0 taken 16796 times.
✓ Branch 1 taken 2009 times.
18805 if (ref[1] == 0)
457 16796 fill_rectangle(&sl->mv_cache[1][scan8[i8 * 4]], 2, 2,
458 8, 0, 4);
459 18805 n += 4;
460 }
461 } else {
462 30239 int m = 0;
463
2/2
✓ Branch 0 taken 120956 times.
✓ Branch 1 taken 30239 times.
151195 for (i4 = 0; i4 < 4; i4++) {
464 120956 const int16_t *mv_col = l1mv[x8 * 2 + (i4 & 1) +
465 120956 (y8 * 2 + (i4 >> 1)) * b4_stride];
466
4/4
✓ Branch 0 taken 8348 times.
✓ Branch 1 taken 112608 times.
✓ Branch 2 taken 2956 times.
✓ Branch 3 taken 5392 times.
120956 if (FFABS(mv_col[0]) <= 1 && FFABS(mv_col[1]) <= 1) {
467
2/2
✓ Branch 0 taken 1991 times.
✓ Branch 1 taken 965 times.
2956 if (ref[0] == 0)
468 1991 AV_ZERO32(sl->mv_cache[0][scan8[i8 * 4 + i4]]);
469
2/2
✓ Branch 0 taken 2710 times.
✓ Branch 1 taken 246 times.
2956 if (ref[1] == 0)
470 2710 AV_ZERO32(sl->mv_cache[1][scan8[i8 * 4 + i4]]);
471 2956 m++;
472 }
473 }
474
2/2
✓ Branch 0 taken 29926 times.
✓ Branch 1 taken 313 times.
30239 if (!(m & 3))
475 29926 sl->sub_mb_type[i8] += MB_TYPE_16x16 - MB_TYPE_8x8;
476 30239 n += m;
477 }
478 }
479 }
480
4/4
✓ Branch 0 taken 81432 times.
✓ Branch 1 taken 61544 times.
✓ Branch 2 taken 75301 times.
✓ Branch 3 taken 6131 times.
142976 if (!is_b8x8 && !(n & 15))
481 75301 *mb_type = (*mb_type & ~(MB_TYPE_8x8 | MB_TYPE_16x8 | MB_TYPE_8x16 |
482 MB_TYPE_P1L0 | MB_TYPE_P1L1)) |
483 75301 MB_TYPE_16x16 | MB_TYPE_DIRECT2;
484 }
485 }
486
487 251816 static void pred_temp_direct_motion(const H264Context *const h, H264SliceContext *sl,
488 int *mb_type)
489 {
490 251816 int b8_stride = 2;
491 251816 int b4_stride = h->b_stride;
492 251816 int mb_xy = sl->mb_xy, mb_y = sl->mb_y;
493 int mb_type_col[2];
494 const int16_t (*l1mv0)[2], (*l1mv1)[2];
495 const int8_t *l1ref0, *l1ref1;
496 251816 const int is_b8x8 = IS_8X8(*mb_type);
497 unsigned int sub_mb_type;
498 int i8, i4;
499
500 assert(sl->ref_list[1][0].reference & 3);
501
502 251816 await_reference_mb_row(h, &sl->ref_list[1][0],
503 251816 sl->mb_y + !!IS_INTERLACED(*mb_type));
504
505
2/2
✓ Branch 0 taken 88777 times.
✓ Branch 1 taken 163039 times.
251816 if (IS_INTERLACED(sl->ref_list[1][0].parent->mb_type[mb_xy])) { // AFL/AFR/FR/FL -> AFL/FL
506
2/2
✓ Branch 0 taken 15611 times.
✓ Branch 1 taken 73166 times.
88777 if (!IS_INTERLACED(*mb_type)) { // AFR/FR -> AFL/FL
507 15611 mb_y = (sl->mb_y & ~1) + sl->col_parity;
508 15611 mb_xy = sl->mb_x +
509 15611 ((sl->mb_y & ~1) + sl->col_parity) * h->mb_stride;
510 15611 b8_stride = 0;
511 } else {
512 73166 mb_y += sl->col_fieldoff;
513 73166 mb_xy += h->mb_stride * sl->col_fieldoff; // non-zero for FL -> FL & differ parity
514 }
515 88777 goto single_col;
516 } else { // AFL/AFR/FR/FL -> AFR/FR
517
2/2
✓ Branch 0 taken 16549 times.
✓ Branch 1 taken 146490 times.
163039 if (IS_INTERLACED(*mb_type)) { // AFL /FL -> AFR/FR
518 16549 mb_y = sl->mb_y & ~1;
519 16549 mb_xy = sl->mb_x + (sl->mb_y & ~1) * h->mb_stride;
520 16549 mb_type_col[0] = sl->ref_list[1][0].parent->mb_type[mb_xy];
521 16549 mb_type_col[1] = sl->ref_list[1][0].parent->mb_type[mb_xy + h->mb_stride];
522 16549 b8_stride = 2 + 4 * h->mb_stride;
523 16549 b4_stride *= 6;
524 16549 if (IS_INTERLACED(mb_type_col[0]) !=
525
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16549 times.
16549 IS_INTERLACED(mb_type_col[1])) {
526 mb_type_col[0] &= ~MB_TYPE_INTERLACED;
527 mb_type_col[1] &= ~MB_TYPE_INTERLACED;
528 }
529
530 16549 sub_mb_type = MB_TYPE_16x16 | MB_TYPE_P0L0 | MB_TYPE_P0L1 |
531 MB_TYPE_DIRECT2; /* B_SUB_8x8 */
532
533
2/2
✓ Branch 0 taken 9887 times.
✓ Branch 1 taken 6662 times.
16549 if ((mb_type_col[0] & MB_TYPE_16x16_OR_INTRA) &&
534
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) &&
535 !is_b8x8) {
536 5873 *mb_type |= MB_TYPE_16x8 | MB_TYPE_L0L1 |
537 MB_TYPE_DIRECT2; /* B_16x8 */
538 } else {
539 10676 *mb_type |= MB_TYPE_8x8 | MB_TYPE_L0L1;
540 }
541 } else { // AFR/FR -> AFR/FR
542 146490 single_col:
543 235267 mb_type_col[0] =
544 235267 mb_type_col[1] = sl->ref_list[1][0].parent->mb_type[mb_xy];
545
546 235267 sub_mb_type = MB_TYPE_16x16 | MB_TYPE_P0L0 | MB_TYPE_P0L1 |
547 MB_TYPE_DIRECT2; /* B_SUB_8x8 */
548
4/4
✓ Branch 0 taken 189694 times.
✓ Branch 1 taken 45573 times.
✓ Branch 2 taken 134937 times.
✓ Branch 3 taken 54757 times.
235267 if (!is_b8x8 && (mb_type_col[0] & MB_TYPE_16x16_OR_INTRA)) {
549 134937 *mb_type |= MB_TYPE_16x16 | MB_TYPE_P0L0 | MB_TYPE_P0L1 |
550 MB_TYPE_DIRECT2; /* B_16x16 */
551
2/2
✓ Branch 0 taken 54757 times.
✓ Branch 1 taken 45573 times.
100330 } else if (!is_b8x8 &&
552
2/2
✓ Branch 0 taken 34983 times.
✓ Branch 1 taken 19774 times.
54757 (mb_type_col[0] & (MB_TYPE_16x8 | MB_TYPE_8x16))) {
553 34983 *mb_type |= MB_TYPE_L0L1 | MB_TYPE_DIRECT2 |
554 34983 (mb_type_col[0] & (MB_TYPE_16x8 | MB_TYPE_8x16));
555 } else {
556
2/2
✓ Branch 0 taken 10593 times.
✓ Branch 1 taken 54754 times.
65347 if (!h->ps.sps->direct_8x8_inference_flag) {
557 /* FIXME: save sub mb types from previous frames (or derive
558 * from MVs) so we know exactly what block size to use */
559 10593 sub_mb_type = MB_TYPE_8x8 | MB_TYPE_P0L0 | MB_TYPE_P0L1 |
560 MB_TYPE_DIRECT2; /* B_SUB_4x4 */
561 }
562 65347 *mb_type |= MB_TYPE_8x8 | MB_TYPE_L0L1;
563 }
564 }
565 }
566
567 251816 await_reference_mb_row(h, &sl->ref_list[1][0], mb_y);
568
569 251816 l1mv0 = (void*)&sl->ref_list[1][0].parent->motion_val[0][h->mb2b_xy[mb_xy]];
570 251816 l1mv1 = (void*)&sl->ref_list[1][0].parent->motion_val[1][h->mb2b_xy[mb_xy]];
571 251816 l1ref0 = &sl->ref_list[1][0].parent->ref_index[0][4 * mb_xy];
572 251816 l1ref1 = &sl->ref_list[1][0].parent->ref_index[1][4 * mb_xy];
573
2/2
✓ Branch 0 taken 15611 times.
✓ Branch 1 taken 236205 times.
251816 if (!b8_stride) {
574
2/2
✓ Branch 0 taken 7720 times.
✓ Branch 1 taken 7891 times.
15611 if (sl->mb_y & 1) {
575 7720 l1ref0 += 2;
576 7720 l1ref1 += 2;
577 7720 l1mv0 += 2 * b4_stride;
578 7720 l1mv1 += 2 * b4_stride;
579 }
580 }
581
582 {
583 251816 const int *map_col_to_list0[2] = { sl->map_col_to_list0[0],
584 251816 sl->map_col_to_list0[1] };
585 251816 const int *dist_scale_factor = sl->dist_scale_factor;
586 int ref_offset;
587
588
4/4
✓ Branch 0 taken 42213 times.
✓ Branch 1 taken 209603 times.
✓ Branch 2 taken 20032 times.
✓ Branch 3 taken 22181 times.
251816 if (FRAME_MBAFF(h) && IS_INTERLACED(*mb_type)) {
589 20032 map_col_to_list0[0] = sl->map_col_to_list0_field[sl->mb_y & 1][0];
590 20032 map_col_to_list0[1] = sl->map_col_to_list0_field[sl->mb_y & 1][1];
591 20032 dist_scale_factor = sl->dist_scale_factor_field[sl->mb_y & 1];
592 }
593 251816 ref_offset = (sl->ref_list[1][0].parent->mbaff << 4) & (mb_type_col[0] >> 3);
594
595
2/2
✓ Branch 0 taken 32160 times.
✓ Branch 1 taken 219656 times.
251816 if (IS_INTERLACED(*mb_type) != IS_INTERLACED(mb_type_col[0])) {
596
2/2
✓ Branch 0 taken 15611 times.
✓ Branch 1 taken 16549 times.
32160 int y_shift = 2 * !IS_INTERLACED(*mb_type);
597 assert(h->ps.sps->direct_8x8_inference_flag);
598
599
2/2
✓ Branch 0 taken 128640 times.
✓ Branch 1 taken 32160 times.
160800 for (i8 = 0; i8 < 4; i8++) {
600 128640 const int x8 = i8 & 1;
601 128640 const int y8 = i8 >> 1;
602 int ref0, scale;
603 128640 const int16_t (*l1mv)[2] = l1mv0;
604
605
4/4
✓ Branch 0 taken 43260 times.
✓ Branch 1 taken 85380 times.
✓ Branch 2 taken 22674 times.
✓ Branch 3 taken 20586 times.
128640 if (is_b8x8 && !IS_DIRECT(sl->sub_mb_type[i8]))
606 22674 continue;
607 105966 sl->sub_mb_type[i8] = sub_mb_type;
608
609 105966 fill_rectangle(&sl->ref_cache[1][scan8[i8 * 4]], 2, 2, 8, 0, 1);
610
2/2
✓ Branch 0 taken 25496 times.
✓ Branch 1 taken 80470 times.
105966 if (IS_INTRA(mb_type_col[y8])) {
611 25496 fill_rectangle(&sl->ref_cache[0][scan8[i8 * 4]], 2, 2, 8, 0, 1);
612 25496 fill_rectangle(&sl->mv_cache[0][scan8[i8 * 4]], 2, 2, 8, 0, 4);
613 25496 fill_rectangle(&sl->mv_cache[1][scan8[i8 * 4]], 2, 2, 8, 0, 4);
614 25496 continue;
615 }
616
617 80470 ref0 = l1ref0[x8 + y8 * b8_stride];
618
2/2
✓ Branch 0 taken 80277 times.
✓ Branch 1 taken 193 times.
80470 if (ref0 >= 0)
619 80277 ref0 = map_col_to_list0[0][ref0 + ref_offset];
620 else {
621 193 ref0 = map_col_to_list0[1][l1ref1[x8 + y8 * b8_stride] +
622 ref_offset];
623 193 l1mv = l1mv1;
624 }
625 80470 scale = dist_scale_factor[ref0];
626 80470 fill_rectangle(&sl->ref_cache[0][scan8[i8 * 4]], 2, 2, 8,
627 ref0, 1);
628
629 {
630 80470 const int16_t *mv_col = l1mv[x8 * 3 + y8 * b4_stride];
631 80470 int my_col = (mv_col[1] * (1 << y_shift)) / 2;
632 80470 int mx = (scale * mv_col[0] + 128) >> 8;
633 80470 int my = (scale * my_col + 128) >> 8;
634 80470 fill_rectangle(&sl->mv_cache[0][scan8[i8 * 4]], 2, 2, 8,
635 pack16to32(mx, my), 4);
636 80470 fill_rectangle(&sl->mv_cache[1][scan8[i8 * 4]], 2, 2, 8,
637 80470 pack16to32(mx - mv_col[0], my - my_col), 4);
638 }
639 }
640 32160 return;
641 }
642
643 /* one-to-one mv scaling */
644
645
2/2
✓ Branch 0 taken 127333 times.
✓ Branch 1 taken 92323 times.
219656 if (IS_16X16(*mb_type)) {
646 int ref, mv0, mv1;
647
648 127333 fill_rectangle(&sl->ref_cache[1][scan8[0]], 4, 4, 8, 0, 1);
649
2/2
✓ Branch 0 taken 60991 times.
✓ Branch 1 taken 66342 times.
127333 if (IS_INTRA(mb_type_col[0])) {
650 60991 ref = mv0 = mv1 = 0;
651 } else {
652 198975 const int ref0 = l1ref0[0] >= 0 ? map_col_to_list0[0][l1ref0[0] + ref_offset]
653
2/2
✓ Branch 0 taken 66291 times.
✓ Branch 1 taken 51 times.
66342 : map_col_to_list0[1][l1ref1[0] + ref_offset];
654 66342 const int scale = dist_scale_factor[ref0];
655
2/2
✓ Branch 0 taken 66291 times.
✓ Branch 1 taken 51 times.
66342 const int16_t *mv_col = l1ref0[0] >= 0 ? l1mv0[0] : l1mv1[0];
656 int mv_l0[2];
657 66342 mv_l0[0] = (scale * mv_col[0] + 128) >> 8;
658 66342 mv_l0[1] = (scale * mv_col[1] + 128) >> 8;
659 66342 ref = ref0;
660 66342 mv0 = pack16to32(mv_l0[0], mv_l0[1]);
661 66342 mv1 = pack16to32(mv_l0[0] - mv_col[0], mv_l0[1] - mv_col[1]);
662 }
663 127333 fill_rectangle(&sl->ref_cache[0][scan8[0]], 4, 4, 8, ref, 1);
664 127333 fill_rectangle(&sl->mv_cache[0][scan8[0]], 4, 4, 8, mv0, 4);
665 127333 fill_rectangle(&sl->mv_cache[1][scan8[0]], 4, 4, 8, mv1, 4);
666 } else {
667
2/2
✓ Branch 0 taken 369292 times.
✓ Branch 1 taken 92323 times.
461615 for (i8 = 0; i8 < 4; i8++) {
668 369292 const int x8 = i8 & 1;
669 369292 const int y8 = i8 >> 1;
670 int ref0, scale;
671 369292 const int16_t (*l1mv)[2] = l1mv0;
672
673
4/4
✓ Branch 0 taken 163900 times.
✓ Branch 1 taken 205392 times.
✓ Branch 2 taken 92460 times.
✓ Branch 3 taken 71440 times.
369292 if (is_b8x8 && !IS_DIRECT(sl->sub_mb_type[i8]))
674 92460 continue;
675 276832 sl->sub_mb_type[i8] = sub_mb_type;
676 276832 fill_rectangle(&sl->ref_cache[1][scan8[i8 * 4]], 2, 2, 8, 0, 1);
677
2/2
✓ Branch 0 taken 22293 times.
✓ Branch 1 taken 254539 times.
276832 if (IS_INTRA(mb_type_col[0])) {
678 22293 fill_rectangle(&sl->ref_cache[0][scan8[i8 * 4]], 2, 2, 8, 0, 1);
679 22293 fill_rectangle(&sl->mv_cache[0][scan8[i8 * 4]], 2, 2, 8, 0, 4);
680 22293 fill_rectangle(&sl->mv_cache[1][scan8[i8 * 4]], 2, 2, 8, 0, 4);
681 22293 continue;
682 }
683
684 assert(b8_stride == 2);
685 254539 ref0 = l1ref0[i8];
686
2/2
✓ Branch 0 taken 254519 times.
✓ Branch 1 taken 20 times.
254539 if (ref0 >= 0)
687 254519 ref0 = map_col_to_list0[0][ref0 + ref_offset];
688 else {
689 20 ref0 = map_col_to_list0[1][l1ref1[i8] + ref_offset];
690 20 l1mv = l1mv1;
691 }
692 254539 scale = dist_scale_factor[ref0];
693
694 254539 fill_rectangle(&sl->ref_cache[0][scan8[i8 * 4]], 2, 2, 8,
695 ref0, 1);
696
2/2
✓ Branch 0 taken 229231 times.
✓ Branch 1 taken 25308 times.
254539 if (IS_SUB_8X8(sub_mb_type)) {
697 229231 const int16_t *mv_col = l1mv[x8 * 3 + y8 * 3 * b4_stride];
698 229231 int mx = (scale * mv_col[0] + 128) >> 8;
699 229231 int my = (scale * mv_col[1] + 128) >> 8;
700 229231 fill_rectangle(&sl->mv_cache[0][scan8[i8 * 4]], 2, 2, 8,
701 pack16to32(mx, my), 4);
702 229231 fill_rectangle(&sl->mv_cache[1][scan8[i8 * 4]], 2, 2, 8,
703 229231 pack16to32(mx - mv_col[0], my - mv_col[1]), 4);
704 } else {
705
2/2
✓ Branch 0 taken 101232 times.
✓ Branch 1 taken 25308 times.
126540 for (i4 = 0; i4 < 4; i4++) {
706 101232 const int16_t *mv_col = l1mv[x8 * 2 + (i4 & 1) +
707 101232 (y8 * 2 + (i4 >> 1)) * b4_stride];
708 101232 int16_t *mv_l0 = sl->mv_cache[0][scan8[i8 * 4 + i4]];
709 101232 mv_l0[0] = (scale * mv_col[0] + 128) >> 8;
710 101232 mv_l0[1] = (scale * mv_col[1] + 128) >> 8;
711 101232 AV_WN32A(sl->mv_cache[1][scan8[i8 * 4 + i4]],
712 pack16to32(mv_l0[0] - mv_col[0],
713 mv_l0[1] - mv_col[1]));
714 }
715 }
716 }
717 }
718 }
719 }
720
721 2859977 void ff_h264_pred_direct_motion(const H264Context *const h, H264SliceContext *sl,
722 int *mb_type)
723 {
724
2/2
✓ Branch 0 taken 2608161 times.
✓ Branch 1 taken 251816 times.
2859977 if (sl->direct_spatial_mv_pred)
725 2608161 pred_spatial_direct_motion(h, sl, mb_type);
726 else
727 251816 pred_temp_direct_motion(h, sl, mb_type);
728 2859977 }
729