../../../ffmpeg/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
447 / 454
98.5%
Branches:
306 / 326
93.9%
Functions:
8 / 8
100.0%

libavcodec/h264_direct.c
Line Branch Exec Source
1 /*
2 * H.26L/H.264/AVC/JVT/14496-10/... direct mb/block decoding
3 * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 /**
23 * @file
24 * H.264 / AVC / MPEG-4 part10 direct mb/block decoding.
25 * @author Michael Niedermayer <michaelni@gmx.at>
26 */
27
28 #include "avcodec.h"
29 #include "h264dec.h"
30 #include "h264_ps.h"
31 #include "mpegutils.h"
32 #include "rectangle.h"
33 #include "threadframe.h"
34
35 #include <assert.h>
36
37 29078 static int get_scale_factor(const H264SliceContext *sl,
38 int poc, int poc1, int i)
39 {
40 29078 int poc0 = sl->ref_list[0][i].poc;
41 29078 int64_t pocdiff = poc1 - (int64_t)poc0;
42 29078 int td = av_clip_int8(pocdiff);
43
44
1/2
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 4 taken 29078 times.
29078 if (pocdiff != (int)pocdiff)
45 ✗ avpriv_request_sample(sl->h264->avctx, "pocdiff overflow");
46
47
4/4
✓ Branch 4 → 5 taken 21321 times.
✓ Branch 4 → 6 taken 7757 times.
✓ Branch 5 → 6 taken 531 times.
✓ Branch 5 → 7 taken 20790 times.
29078 if (td == 0 || sl->ref_list[0][i].parent->long_ref) {
48 8288 return 256;
49 } else {
50 20790 int64_t pocdiff0 = poc - (int64_t)poc0;
51 20790 int tb = av_clip_int8(pocdiff0);
52 20790 int tx = (16384 + (FFABS(td) >> 1)) / td;
53
54
1/2
✗ Branch 7 → 8 not taken.
✓ Branch 7 → 9 taken 20790 times.
20790 if (pocdiff0 != (int)pocdiff0)
55 ✗ av_log(sl->h264->avctx, AV_LOG_DEBUG, "pocdiff0 overflow\n");
56
57 20790 return av_clip_intp2((tb * tx + 32) >> 6, 10);
58 }
59 }
60
61 7959 void ff_h264_direct_dist_scale_factor(const H264Context *const h,
62 H264SliceContext *sl)
63 {
64 3612 const int poc = FIELD_PICTURE(h) ? h->cur_pic_ptr->field_poc[h->picture_structure == PICT_BOTTOM_FIELD]
65
2/2
✓ Branch 2 → 3 taken 3612 times.
✓ Branch 2 → 4 taken 4347 times.
7959 : h->cur_pic_ptr->poc;
66 7959 const int poc1 = sl->ref_list[1][0].poc;
67 int i, field;
68
69
2/2
✓ Branch 5 → 6 taken 522 times.
✓ Branch 5 → 13 taken 7437 times.
7959 if (FRAME_MBAFF(h))
70
2/2
✓ Branch 12 → 7 taken 1044 times.
✓ Branch 12 → 13 taken 522 times.
1566 for (field = 0; field < 2; field++) {
71 1044 const int poc = h->cur_pic_ptr->field_poc[field];
72 1044 const int poc1 = sl->ref_list[1][0].parent->field_poc[field];
73
2/2
✓ Branch 10 → 8 taken 6676 times.
✓ Branch 10 → 11 taken 1044 times.
7720 for (i = 0; i < 2 * sl->ref_count[0]; i++)
74 6676 sl->dist_scale_factor_field[field][i ^ field] =
75 6676 get_scale_factor(sl, poc, poc1, i + 16);
76 }
77
78
2/2
✓ Branch 16 → 14 taken 22402 times.
✓ Branch 16 → 17 taken 7959 times.
30361 for (i = 0; i < sl->ref_count[0]; i++)
79 22402 sl->dist_scale_factor[i] = get_scale_factor(sl, poc, poc1, i);
80 7959 }
81
82 18006 static void fill_colmap(const H264Context *h, H264SliceContext *sl,
83 int map[2][16 + 32], int list,
84 int field, int colfield, int mbafi)
85 {
86 18006 const H264Picture *const ref1 = sl->ref_list[1][0].parent;
87 int j, old_ref, rfield;
88
2/2
✓ Branch 2 → 3 taken 2088 times.
✓ Branch 2 → 4 taken 15918 times.
18006 int start = mbafi ? 16 : 0;
89
2/2
✓ Branch 5 → 6 taken 2088 times.
✓ Branch 5 → 7 taken 15918 times.
18006 int end = mbafi ? 16 + 2 * sl->ref_count[0] : sl->ref_count[0];
90
4/4
✓ Branch 8 → 9 taken 15918 times.
✓ Branch 8 → 10 taken 2088 times.
✓ Branch 9 → 10 taken 7224 times.
✓ Branch 9 → 11 taken 8694 times.
18006 int interl = mbafi || h->picture_structure != PICT_FRAME;
91
92 /* bogus; fills in for missing frames */
93 18006 memset(map[list], 0, sizeof(map[list]));
94
95
2/2
✓ Branch 35 → 13 taken 36012 times.
✓ Branch 35 → 36 taken 18006 times.
54018 for (rfield = 0; rfield < 2; rfield++) {
96
2/2
✓ Branch 33 → 14 taken 39408 times.
✓ Branch 33 → 34 taken 36012 times.
75420 for (old_ref = 0; old_ref < ref1->ref_count[colfield][list]; old_ref++) {
97 39408 int poc = ref1->ref_poc[colfield][list][old_ref];
98
99
2/2
✓ Branch 14 → 15 taken 16960 times.
✓ Branch 14 → 16 taken 22448 times.
39408 if (!interl)
100 16960 poc |= 3;
101 // FIXME: store all MBAFF references so this is not needed
102
3/4
✓ Branch 16 → 17 taken 22448 times.
✗ Branch 16 → 19 not taken.
✓ Branch 17 → 18 taken 5456 times.
✓ Branch 17 → 19 taken 16992 times.
22448 else if (interl && (poc & 3) == 3)
103 5456 poc = (poc & ~3) + rfield + 1;
104
105
2/2
✓ Branch 31 → 20 taken 107980 times.
✓ Branch 31 → 32 taken 7522 times.
115502 for (j = start; j < end; j++) {
106 107980 if (4 * sl->ref_list[0][j].parent->frame_num +
107
2/2
✓ Branch 20 → 21 taken 31886 times.
✓ Branch 20 → 30 taken 76094 times.
107980 (sl->ref_list[0][j].reference & 3) == poc) {
108
2/2
✓ Branch 21 → 22 taken 4256 times.
✓ Branch 21 → 23 taken 27630 times.
31886 int cur_ref = mbafi ? (j - 16) ^ field : j;
109
2/2
✓ Branch 24 → 25 taken 5826 times.
✓ Branch 24 → 26 taken 26060 times.
31886 if (ref1->mbaff)
110 5826 map[list][2 * old_ref + (rfield ^ field) + 16] = cur_ref;
111
4/4
✓ Branch 26 → 27 taken 15943 times.
✓ Branch 26 → 28 taken 15943 times.
✓ Branch 27 → 28 taken 6647 times.
✓ Branch 27 → 29 taken 9296 times.
31886 if (rfield == field || !interl)
112 22590 map[list][old_ref] = cur_ref;
113 31886 break;
114 }
115 }
116 }
117 }
118 18006 }
119
120 39187 void ff_h264_direct_ref_list_init(const H264Context *const h, H264SliceContext *sl)
121 {
122 39187 H264Ref *const ref1 = &sl->ref_list[1][0];
123 39187 H264Picture *const cur = h->cur_pic_ptr;
124 int list, field;
125 39187 int sidx = (h->picture_structure & 1) ^ 1;
126 39187 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 2 → 3 taken 39187 times.
✗ Branch 2 → 16 not taken.
39187 if (!h->setup_finished) {
131
2/2
✓ Branch 8 → 4 taken 48386 times.
✓ Branch 8 → 9 taken 39187 times.
87573 for (list = 0; list < sl->list_count; list++) {
132 48386 cur->ref_count[sidx][list] = sl->ref_count[list];
133
2/2
✓ Branch 6 → 5 taken 146203 times.
✓ Branch 6 → 7 taken 48386 times.
194589 for (int j = 0; j < sl->ref_count[list]; j++)
134 146203 cur->ref_poc[sidx][list][j] = 4 * sl->ref_list[list][j].parent->frame_num +
135 146203 (sl->ref_list[list][j].reference & 3);
136 }
137
138
2/2
✓ Branch 9 → 10 taken 29629 times.
✓ Branch 9 → 11 taken 9558 times.
39187 if (h->picture_structure == PICT_FRAME) {
139 29629 memcpy(cur->ref_count[1], cur->ref_count[0], sizeof(cur->ref_count[0]));
140 29629 memcpy(cur->ref_poc[1], cur->ref_poc[0], sizeof(cur->ref_poc[0]));
141 }
142
143
2/2
✓ Branch 11 → 12 taken 29448 times.
✓ Branch 11 → 13 taken 9739 times.
39187 if (h->current_slice == 0) {
144 29448 cur->mbaff = FRAME_MBAFF(h);
145 } else {
146
1/2
✗ Branch 13 → 14 not taken.
✓ Branch 13 → 16 taken 9739 times.
9739 av_assert0(cur->mbaff == FRAME_MBAFF(h));
147 }
148 }
149
150 39187 sl->col_fieldoff = 0;
151
152
3/4
✓ Branch 16 → 17 taken 13901 times.
✓ Branch 16 → 18 taken 25286 times.
✗ Branch 17 → 18 not taken.
✓ Branch 17 → 19 taken 13901 times.
39187 if (sl->list_count != 2 || !sl->ref_count[1])
153 25286 return;
154
155
2/2
✓ Branch 19 → 20 taken 8682 times.
✓ Branch 19 → 26 taken 5219 times.
13901 if (h->picture_structure == PICT_FRAME) {
156 8682 int cur_poc = h->cur_pic_ptr->poc;
157 8682 const int *col_poc = sl->ref_list[1][0].parent->field_poc;
158
3/4
✓ Branch 20 → 21 taken 12 times.
✓ Branch 20 → 24 taken 8670 times.
✓ Branch 21 → 22 taken 12 times.
✗ Branch 21 → 24 not taken.
8682 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 8670 sl->col_parity = (FFABS(col_poc[0] - (int64_t)cur_poc) >=
163 8670 FFABS(col_poc[1] - (int64_t)cur_poc));
164 8682 ref1sidx =
165 8682 sidx = sl->col_parity;
166 // FL -> FL & differ parity
167
2/2
✓ Branch 26 → 27 taken 1866 times.
✓ Branch 26 → 29 taken 3353 times.
5219 } else if (!(h->picture_structure & sl->ref_list[1][0].reference) &&
168
2/2
✓ Branch 27 → 28 taken 1728 times.
✓ Branch 27 → 29 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 29 → 30 taken 13901 times.
✗ Branch 29 → 31 not taken.
✓ Branch 30 → 31 taken 5942 times.
✓ Branch 30 → 32 taken 7959 times.
13901 if (sl->slice_type_nos != AV_PICTURE_TYPE_B || sl->direct_spatial_mv_pred)
173 5942 return;
174
175
2/2
✓ Branch 40 → 33 taken 15918 times.
✓ Branch 40 → 41 taken 7959 times.
23877 for (list = 0; list < 2; list++) {
176 15918 fill_colmap(h, sl, sl->map_col_to_list0, list, sidx, ref1sidx, 0);
177
2/2
✓ Branch 34 → 35 taken 1044 times.
✓ Branch 34 → 39 taken 14874 times.
15918 if (FRAME_MBAFF(h))
178
2/2
✓ Branch 38 → 36 taken 2088 times.
✓ Branch 38 → 39 taken 1044 times.
3132 for (field = 0; field < 2; field++)
179 2088 fill_colmap(h, sl, sl->map_col_to_list0_field[field], list, field,
180 field, 1);
181 }
182 }
183
184 4759863 static void await_reference_mb_row(const H264Context *const h, H264Ref *ref,
185 int mb_y)
186 {
187
2/2
✓ Branch 2 → 3 taken 4730980 times.
✓ Branch 2 → 4 taken 28883 times.
4759863 if (!HAVE_THREADS || !(h->avctx->active_thread_type & FF_THREAD_FRAME))
188 4730980 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 4 → 5 not taken.
✓ Branch 4 → 6 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 7 → 8 not taken.
✓ Branch 7 → 10 taken 28883 times.
✗ Branch 8 → 9 not taken.
✗ Branch 8 → 10 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 12 → 13 not taken.
✓ Branch 12 → 15 taken 28883 times.
✗ Branch 13 → 14 not taken.
✗ Branch 13 → 15 not taken.
28883 if (ref_field_picture && !FIELD_PICTURE(h))
205 ✗ ff_thread_await_progress(&ref->parent->tf, row, 0);
206 }
207
208 3130301 static void pred_spatial_direct_motion(const H264Context *const h, H264SliceContext *sl,
209 int *mb_type)
210 {
211 3130301 int b8_stride = 2;
212 3130301 int b4_stride = h->b_stride;
213 3130301 int mb_xy = sl->mb_xy, mb_y = sl->mb_y;
214 int mb_type_col[2];
215 3130301 int col_field = 0;
216 const int16_t (*l1mv0)[2], (*l1mv1)[2];
217 const int8_t *l1ref0, *l1ref1;
218 3130301 const int is_b8x8 = IS_8X8(*mb_type);
219 3130301 unsigned int sub_mb_type = MB_TYPE_L0L1;
220 int i8, i4;
221 int ref[2];
222 int mv[2];
223 int list;
224
225 assert(sl->ref_list[1][0].reference & 3);
226
227 3130301 await_reference_mb_row(h, &sl->ref_list[1][0],
228 3130301 sl->mb_y + !!IS_INTERLACED(*mb_type));
229
230 #define MB_TYPE_16x16_OR_INTRA (MB_TYPE_16x16 | MB_TYPE_INTRA4x4 | \
231 MB_TYPE_INTRA16x16 | MB_TYPE_INTRA_PCM)
232
233 /* ref = min(neighbors) */
234
2/2
✓ Branch 19 → 4 taken 6260602 times.
✓ Branch 19 → 20 taken 3130301 times.
9390903 for (list = 0; list < 2; list++) {
235 6260602 int left_ref = sl->ref_cache[list][scan8[0] - 1];
236 6260602 int top_ref = sl->ref_cache[list][scan8[0] - 8];
237 6260602 int refc = sl->ref_cache[list][scan8[0] - 8 + 4];
238 6260602 const int16_t *C = sl->mv_cache[list][scan8[0] - 8 + 4];
239
2/2
✓ Branch 4 → 5 taken 767824 times.
✓ Branch 4 → 6 taken 5492778 times.
6260602 if (refc == PART_NOT_AVAILABLE) {
240 767824 refc = sl->ref_cache[list][scan8[0] - 8 - 1];
241 767824 C = sl->mv_cache[list][scan8[0] - 8 - 1];
242 }
243 6260602 ref[list] = FFMIN3((unsigned)left_ref,
244 (unsigned)top_ref,
245 (unsigned)refc);
246
2/2
✓ Branch 6 → 7 taken 5744391 times.
✓ Branch 6 → 15 taken 516211 times.
6260602 if (ref[list] >= 0) {
247 /* This is just pred_motion() but with the cases removed that
248 * cannot happen for direct blocks. */
249 5744391 const int16_t *const A = sl->mv_cache[list][scan8[0] - 1];
250 5744391 const int16_t *const B = sl->mv_cache[list][scan8[0] - 8];
251
252 5744391 int match_count = (left_ref == ref[list]) +
253 5744391 (top_ref == ref[list]) +
254 5744391 (refc == ref[list]);
255
256
2/2
✓ Branch 7 → 8 taken 5096916 times.
✓ Branch 7 → 10 taken 647475 times.
5744391 if (match_count > 1) { // most common
257 5096916 mv[list] = pack16to32(mid_pred(A[0], B[0], C[0]),
258 5096916 mid_pred(A[1], B[1], C[1]));
259 } else {
260 assert(match_count == 1);
261
2/2
✓ Branch 10 → 11 taken 510037 times.
✓ Branch 10 → 12 taken 137438 times.
647475 if (left_ref == ref[list])
262 510037 mv[list] = AV_RN32A(A);
263
2/2
✓ Branch 12 → 13 taken 64308 times.
✓ Branch 12 → 14 taken 73130 times.
137438 else if (top_ref == ref[list])
264 64308 mv[list] = AV_RN32A(B);
265 else
266 73130 mv[list] = AV_RN32A(C);
267 }
268 av_assert2(ref[list] < (sl->ref_count[list] << !!FRAME_MBAFF(h)));
269 } else {
270 516211 int mask = ~(MB_TYPE_L0 << (2 * list));
271 516211 mv[list] = 0;
272 516211 ref[list] = -1;
273
2/2
✓ Branch 15 → 16 taken 490080 times.
✓ Branch 15 → 17 taken 26131 times.
516211 if (!is_b8x8)
274 490080 *mb_type &= mask;
275 516211 sub_mb_type &= mask;
276 }
277 }
278
4/4
✓ Branch 20 → 21 taken 256207 times.
✓ Branch 20 → 25 taken 2874094 times.
✓ Branch 21 → 22 taken 7118 times.
✓ Branch 21 → 25 taken 249089 times.
3130301 if (ref[0] < 0 && ref[1] < 0) {
279 7118 ref[0] = ref[1] = 0;
280
2/2
✓ Branch 22 → 23 taken 6221 times.
✓ Branch 22 → 24 taken 897 times.
7118 if (!is_b8x8)
281 6221 *mb_type |= MB_TYPE_L0L1;
282 7118 sub_mb_type |= MB_TYPE_L0L1;
283 }
284
285
2/2
✓ Branch 25 → 26 taken 2005875 times.
✓ Branch 25 → 31 taken 1124426 times.
3130301 if (!(is_b8x8 | mv[0] | mv[1])) {
286 2005875 fill_rectangle(&sl->ref_cache[0][scan8[0]], 4, 4, 8, (uint8_t)ref[0], 1);
287 2005875 fill_rectangle(&sl->ref_cache[1][scan8[0]], 4, 4, 8, (uint8_t)ref[1], 1);
288 2005875 fill_rectangle(&sl->mv_cache[0][scan8[0]], 4, 4, 8, 0, 4);
289 2005875 fill_rectangle(&sl->mv_cache[1][scan8[0]], 4, 4, 8, 0, 4);
290 2005875 *mb_type = (*mb_type & ~(MB_TYPE_8x8 | MB_TYPE_16x8 | MB_TYPE_8x16 |
291 MB_TYPE_P1L0 | MB_TYPE_P1L1)) |
292 2005875 MB_TYPE_16x16 | MB_TYPE_DIRECT2;
293 2005875 return;
294 }
295
296
2/2
✓ Branch 31 → 32 taken 466614 times.
✓ Branch 31 → 33 taken 657812 times.
1124426 if (sl->ref_list[1][0].parent->field_picture ||
297
2/2
✓ Branch 32 → 33 taken 67888 times.
✓ Branch 32 → 37 taken 398726 times.
466614 IS_INTERLACED(sl->ref_list[1][0].parent->mb_type[mb_xy])) { // AFL/AFR/FR/FL -> AFL/FL
298
2/2
✓ Branch 33 → 34 taken 43571 times.
✓ Branch 33 → 35 taken 682129 times.
725700 if (!IS_INTERLACED(*mb_type)) { // AFR/FR -> AFL/FL
299 43571 mb_y = (sl->mb_y & ~1) + sl->col_parity;
300 43571 mb_xy = sl->mb_x +
301 43571 ((sl->mb_y & ~1) + sl->col_parity) * h->mb_stride;
302 43571 b8_stride = 0;
303 } else {
304 682129 mb_y += sl->col_fieldoff;
305 682129 mb_xy += h->mb_stride * sl->col_fieldoff; // non-zero for FL -> FL & differ parity
306 }
307 // Undecoded macroblocks of a broken field picture lack the flag, the
308 // colocated type has to agree with the branch taken here.
309 725700 col_field = MB_TYPE_INTERLACED;
310 725700 goto single_col;
311 } else { // AFL/AFR/FR/FL -> AFR/FR
312
2/2
✓ Branch 37 → 38 taken 51346 times.
✓ Branch 37 → 46 taken 347380 times.
398726 if (IS_INTERLACED(*mb_type)) { // AFL /FL -> AFR/FR
313 51346 mb_y = sl->mb_y & ~1;
314 51346 mb_xy = (sl->mb_y & ~1) * h->mb_stride + sl->mb_x;
315 51346 mb_type_col[0] = sl->ref_list[1][0].parent->mb_type[mb_xy];
316 51346 mb_type_col[1] = sl->ref_list[1][0].parent->mb_type[mb_xy + h->mb_stride];
317 51346 b8_stride = 2 + 4 * h->mb_stride;
318 51346 b4_stride *= 6;
319 51346 if (IS_INTERLACED(mb_type_col[0]) !=
320
1/2
✗ Branch 38 → 39 not taken.
✓ Branch 38 → 40 taken 51346 times.
51346 IS_INTERLACED(mb_type_col[1])) {
321 ✗ mb_type_col[0] &= ~MB_TYPE_INTERLACED;
322 ✗ mb_type_col[1] &= ~MB_TYPE_INTERLACED;
323 }
324
325 51346 sub_mb_type |= MB_TYPE_16x16 | MB_TYPE_DIRECT2; /* B_SUB_8x8 */
326
2/2
✓ Branch 40 → 41 taken 40827 times.
✓ Branch 40 → 44 taken 10519 times.
51346 if ((mb_type_col[0] & MB_TYPE_16x16_OR_INTRA) &&
327
4/4
✓ Branch 41 → 42 taken 35974 times.
✓ Branch 41 → 44 taken 4853 times.
✓ Branch 42 → 43 taken 32330 times.
✓ Branch 42 → 44 taken 3644 times.
40827 (mb_type_col[1] & MB_TYPE_16x16_OR_INTRA) &&
328 !is_b8x8) {
329 32330 *mb_type |= MB_TYPE_16x8 | MB_TYPE_DIRECT2; /* B_16x8 */
330 } else {
331 19016 *mb_type |= MB_TYPE_8x8;
332 }
333 } else { // AFR/FR -> AFR/FR
334 347380 single_col:
335 1073080 mb_type_col[0] =
336 1073080 mb_type_col[1] = sl->ref_list[1][0].parent->mb_type[mb_xy] | col_field;
337
338 1073080 sub_mb_type |= MB_TYPE_16x16 | MB_TYPE_DIRECT2; /* B_SUB_8x8 */
339
4/4
✓ Branch 47 → 48 taken 997220 times.
✓ Branch 47 → 50 taken 75860 times.
✓ Branch 48 → 49 taken 884872 times.
✓ Branch 48 → 50 taken 112348 times.
1073080 if (!is_b8x8 && (mb_type_col[0] & MB_TYPE_16x16_OR_INTRA)) {
340 884872 *mb_type |= MB_TYPE_16x16 | MB_TYPE_DIRECT2; /* B_16x16 */
341
2/2
✓ Branch 50 → 51 taken 112348 times.
✓ Branch 50 → 53 taken 75860 times.
188208 } else if (!is_b8x8 &&
342
2/2
✓ Branch 51 → 52 taken 64033 times.
✓ Branch 51 → 53 taken 48315 times.
112348 (mb_type_col[0] & (MB_TYPE_16x8 | MB_TYPE_8x16))) {
343 64033 *mb_type |= MB_TYPE_DIRECT2 |
344 64033 (mb_type_col[0] & (MB_TYPE_16x8 | MB_TYPE_8x16));
345 } else {
346
2/2
✓ Branch 53 → 54 taken 21562 times.
✓ Branch 53 → 55 taken 102613 times.
124175 if (!h->ps.sps->direct_8x8_inference_flag) {
347 /* FIXME: Save sub mb types from previous frames (or derive
348 * from MVs) so we know exactly what block size to use. */
349 21562 sub_mb_type += (MB_TYPE_8x8 - MB_TYPE_16x16); /* B_SUB_4x4 */
350 }
351 124175 *mb_type |= MB_TYPE_8x8;
352 }
353 }
354 }
355
356 1124426 await_reference_mb_row(h, &sl->ref_list[1][0], mb_y);
357
358 1124426 l1mv0 = (void*)&sl->ref_list[1][0].parent->motion_val[0][h->mb2b_xy[mb_xy]];
359 1124426 l1mv1 = (void*)&sl->ref_list[1][0].parent->motion_val[1][h->mb2b_xy[mb_xy]];
360 1124426 l1ref0 = &sl->ref_list[1][0].parent->ref_index[0][4 * mb_xy];
361 1124426 l1ref1 = &sl->ref_list[1][0].parent->ref_index[1][4 * mb_xy];
362
2/2
✓ Branch 57 → 58 taken 43571 times.
✓ Branch 57 → 60 taken 1080855 times.
1124426 if (!b8_stride) {
363
2/2
✓ Branch 58 → 59 taken 22047 times.
✓ Branch 58 → 60 taken 21524 times.
43571 if (sl->mb_y & 1) {
364 22047 l1ref0 += 2;
365 22047 l1ref1 += 2;
366 22047 l1mv0 += 2 * b4_stride;
367 22047 l1mv1 += 2 * b4_stride;
368 }
369 }
370
371
2/2
✓ Branch 60 → 61 taken 94917 times.
✓ Branch 60 → 89 taken 1029509 times.
1124426 if (IS_INTERLACED(*mb_type) != IS_INTERLACED(mb_type_col[0])) {
372 94917 int n = 0;
373
2/2
✓ Branch 85 → 62 taken 379668 times.
✓ Branch 85 → 86 taken 94917 times.
474585 for (i8 = 0; i8 < 4; i8++) {
374 379668 int x8 = i8 & 1;
375 379668 int y8 = i8 >> 1;
376 379668 int xy8 = x8 + y8 * b8_stride;
377 379668 int xy4 = x8 * 3 + y8 * b4_stride;
378 int a, b;
379
380
4/4
✓ Branch 62 → 63 taken 66816 times.
✓ Branch 62 → 65 taken 312852 times.
✓ Branch 63 → 64 taken 27121 times.
✓ Branch 63 → 65 taken 39695 times.
379668 if (is_b8x8 && !IS_DIRECT(sl->sub_mb_type[i8]))
381 27121 continue;
382 352547 sl->sub_mb_type[i8] = sub_mb_type;
383
384 352547 fill_rectangle(&sl->ref_cache[0][scan8[i8 * 4]], 2, 2, 8,
385 352547 (uint8_t)ref[0], 1);
386 352547 fill_rectangle(&sl->ref_cache[1][scan8[i8 * 4]], 2, 2, 8,
387 352547 (uint8_t)ref[1], 1);
388
3/4
✓ Branch 67 → 68 taken 197262 times.
✓ Branch 67 → 81 taken 155285 times.
✓ Branch 68 → 69 taken 197262 times.
✗ Branch 68 → 81 not taken.
352547 if (!IS_INTRA(mb_type_col[y8]) && !sl->ref_list[1][0].parent->long_ref &&
389
2/2
✓ Branch 69 → 70 taken 134513 times.
✓ Branch 69 → 72 taken 62749 times.
197262 ((l1ref0[xy8] == 0 &&
390
2/2
✓ Branch 70 → 71 taken 10493 times.
✓ Branch 70 → 72 taken 124020 times.
134513 FFABS(l1mv0[xy4][0]) <= 1 &&
391
2/2
✓ Branch 71 → 72 taken 4460 times.
✓ Branch 71 → 76 taken 6033 times.
10493 FFABS(l1mv0[xy4][1]) <= 1) ||
392
2/2
✓ Branch 72 → 73 taken 12234 times.
✓ Branch 72 → 81 taken 178995 times.
191229 (l1ref0[xy8] < 0 &&
393
2/2
✓ Branch 73 → 74 taken 9667 times.
✓ Branch 73 → 81 taken 2567 times.
12234 l1ref1[xy8] == 0 &&
394
2/2
✓ Branch 74 → 75 taken 826 times.
✓ Branch 74 → 81 taken 8841 times.
9667 FFABS(l1mv1[xy4][0]) <= 1 &&
395
2/2
✓ Branch 75 → 76 taken 502 times.
✓ Branch 75 → 81 taken 324 times.
826 FFABS(l1mv1[xy4][1]) <= 1))) {
396 6535 a =
397 6535 b = 0;
398
2/2
✓ Branch 76 → 77 taken 515 times.
✓ Branch 76 → 78 taken 6020 times.
6535 if (ref[0] > 0)
399 515 a = mv[0];
400
2/2
✓ Branch 78 → 79 taken 159 times.
✓ Branch 78 → 80 taken 6376 times.
6535 if (ref[1] > 0)
401 159 b = mv[1];
402 6535 n++;
403 } else {
404 346012 a = mv[0];
405 346012 b = mv[1];
406 }
407 352547 fill_rectangle(&sl->mv_cache[0][scan8[i8 * 4]], 2, 2, 8, a, 4);
408 352547 fill_rectangle(&sl->mv_cache[1][scan8[i8 * 4]], 2, 2, 8, b, 4);
409 }
410
4/4
✓ Branch 86 → 87 taken 78213 times.
✓ Branch 86 → 153 taken 16704 times.
✓ Branch 87 → 88 taken 77034 times.
✓ Branch 87 → 153 taken 1179 times.
94917 if (!is_b8x8 && !(n & 3))
411 77034 *mb_type = (*mb_type & ~(MB_TYPE_8x8 | MB_TYPE_16x8 | MB_TYPE_8x16 |
412 MB_TYPE_P1L0 | MB_TYPE_P1L1)) |
413 77034 MB_TYPE_16x16 | MB_TYPE_DIRECT2;
414
2/2
✓ Branch 89 → 90 taken 855958 times.
✓ Branch 89 → 110 taken 173551 times.
1029509 } else if (IS_16X16(*mb_type)) {
415 int a, b;
416
417 855958 fill_rectangle(&sl->ref_cache[0][scan8[0]], 4, 4, 8, (uint8_t)ref[0], 1);
418 855958 fill_rectangle(&sl->ref_cache[1][scan8[0]], 4, 4, 8, (uint8_t)ref[1], 1);
419
4/4
✓ Branch 92 → 93 taken 641795 times.
✓ Branch 92 → 107 taken 214163 times.
✓ Branch 93 → 94 taken 641784 times.
✓ Branch 93 → 107 taken 11 times.
855958 if (!IS_INTRA(mb_type_col[0]) && !sl->ref_list[1][0].parent->long_ref &&
420
2/2
✓ Branch 94 → 95 taken 365778 times.
✓ Branch 94 → 97 taken 276006 times.
641784 ((l1ref0[0] == 0 &&
421
2/2
✓ Branch 95 → 96 taken 72265 times.
✓ Branch 95 → 97 taken 293513 times.
365778 FFABS(l1mv0[0][0]) <= 1 &&
422
2/2
✓ Branch 96 → 97 taken 40745 times.
✓ Branch 96 → 102 taken 31520 times.
72265 FFABS(l1mv0[0][1]) <= 1) ||
423
4/4
✓ Branch 97 → 98 taken 18410 times.
✓ Branch 97 → 107 taken 591854 times.
✓ Branch 98 → 99 taken 17645 times.
✓ Branch 98 → 107 taken 765 times.
610264 (l1ref0[0] < 0 && !l1ref1[0] &&
424
2/2
✓ Branch 99 → 100 taken 4913 times.
✓ Branch 99 → 107 taken 12732 times.
17645 FFABS(l1mv1[0][0]) <= 1 &&
425
2/2
✓ Branch 100 → 101 taken 4046 times.
✓ Branch 100 → 107 taken 867 times.
4913 FFABS(l1mv1[0][1]) <= 1 &&
426
1/2
✓ Branch 101 → 102 taken 4046 times.
✗ Branch 101 → 107 not taken.
4046 h->x264_build > 33U))) {
427 35566 a = b = 0;
428
2/2
✓ Branch 102 → 103 taken 7092 times.
✓ Branch 102 → 104 taken 28474 times.
35566 if (ref[0] > 0)
429 7092 a = mv[0];
430
2/2
✓ Branch 104 → 105 taken 4747 times.
✓ Branch 104 → 106 taken 30819 times.
35566 if (ref[1] > 0)
431 4747 b = mv[1];
432 } else {
433 820392 a = mv[0];
434 820392 b = mv[1];
435 }
436 855958 fill_rectangle(&sl->mv_cache[0][scan8[0]], 4, 4, 8, a, 4);
437 855958 fill_rectangle(&sl->mv_cache[1][scan8[0]], 4, 4, 8, b, 4);
438 } else {
439 173551 int n = 0;
440
2/2
✓ Branch 149 → 111 taken 694204 times.
✓ Branch 149 → 150 taken 173551 times.
867755 for (i8 = 0; i8 < 4; i8++) {
441 694204 const int x8 = i8 & 1;
442 694204 const int y8 = i8 >> 1;
443
444
4/4
✓ Branch 111 → 112 taken 273152 times.
✓ Branch 111 → 114 taken 421052 times.
✓ Branch 112 → 113 taken 124637 times.
✓ Branch 112 → 114 taken 148515 times.
694204 if (is_b8x8 && !IS_DIRECT(sl->sub_mb_type[i8]))
445 124637 continue;
446 569567 sl->sub_mb_type[i8] = sub_mb_type;
447
448 569567 fill_rectangle(&sl->mv_cache[0][scan8[i8 * 4]], 2, 2, 8, mv[0], 4);
449 569567 fill_rectangle(&sl->mv_cache[1][scan8[i8 * 4]], 2, 2, 8, mv[1], 4);
450 569567 fill_rectangle(&sl->ref_cache[0][scan8[i8 * 4]], 2, 2, 8,
451 569567 (uint8_t)ref[0], 1);
452 569567 fill_rectangle(&sl->ref_cache[1][scan8[i8 * 4]], 2, 2, 8,
453 569567 (uint8_t)ref[1], 1);
454
455 assert(b8_stride == 2);
456 /* col_zero_flag */
457
4/4
✓ Branch 118 → 119 taken 529692 times.
✓ Branch 118 → 148 taken 39875 times.
✓ Branch 119 → 120 taken 529560 times.
✓ Branch 119 → 148 taken 132 times.
569567 if (!IS_INTRA(mb_type_col[0]) && !sl->ref_list[1][0].parent->long_ref &&
458
2/2
✓ Branch 120 → 121 taken 174359 times.
✓ Branch 120 → 124 taken 355201 times.
529560 (l1ref0[i8] == 0 ||
459
2/2
✓ Branch 121 → 122 taken 12456 times.
✓ Branch 121 → 148 taken 161903 times.
174359 (l1ref0[i8] < 0 &&
460
2/2
✓ Branch 122 → 123 taken 11338 times.
✓ Branch 122 → 148 taken 1118 times.
12456 l1ref1[i8] == 0 &&
461
1/2
✓ Branch 123 → 124 taken 11338 times.
✗ Branch 123 → 148 not taken.
11338 h->x264_build > 33U))) {
462
2/2
✓ Branch 124 → 125 taken 355201 times.
✓ Branch 124 → 126 taken 11338 times.
366539 const int16_t (*l1mv)[2] = l1ref0[i8] == 0 ? l1mv0 : l1mv1;
463
2/2
✓ Branch 127 → 128 taken 336236 times.
✓ Branch 127 → 135 taken 30303 times.
366539 if (IS_SUB_8X8(sub_mb_type)) {
464 336236 const int16_t *mv_col = l1mv[x8 * 3 + y8 * 3 * b4_stride];
465
4/4
✓ Branch 128 → 129 taken 54278 times.
✓ Branch 128 → 148 taken 281958 times.
✓ Branch 129 → 130 taken 28299 times.
✓ Branch 129 → 148 taken 25979 times.
336236 if (FFABS(mv_col[0]) <= 1 && FFABS(mv_col[1]) <= 1) {
466
2/2
✓ Branch 130 → 131 taken 24172 times.
✓ Branch 130 → 132 taken 4127 times.
28299 if (ref[0] == 0)
467 24172 fill_rectangle(&sl->mv_cache[0][scan8[i8 * 4]], 2, 2,
468 8, 0, 4);
469
2/2
✓ Branch 132 → 133 taken 25827 times.
✓ Branch 132 → 134 taken 2472 times.
28299 if (ref[1] == 0)
470 25827 fill_rectangle(&sl->mv_cache[1][scan8[i8 * 4]], 2, 2,
471 8, 0, 4);
472 28299 n += 4;
473 }
474 } else {
475 30303 int m = 0;
476
2/2
✓ Branch 144 → 136 taken 121212 times.
✓ Branch 144 → 145 taken 30303 times.
151515 for (i4 = 0; i4 < 4; i4++) {
477 121212 const int16_t *mv_col = l1mv[x8 * 2 + (i4 & 1) +
478 121212 (y8 * 2 + (i4 >> 1)) * b4_stride];
479
4/4
✓ Branch 136 → 137 taken 8548 times.
✓ Branch 136 → 143 taken 112664 times.
✓ Branch 137 → 138 taken 3036 times.
✓ Branch 137 → 143 taken 5512 times.
121212 if (FFABS(mv_col[0]) <= 1 && FFABS(mv_col[1]) <= 1) {
480
2/2
✓ Branch 138 → 139 taken 2071 times.
✓ Branch 138 → 140 taken 965 times.
3036 if (ref[0] == 0)
481 2071 AV_ZERO32(sl->mv_cache[0][scan8[i8 * 4 + i4]]);
482
2/2
✓ Branch 140 → 141 taken 2790 times.
✓ Branch 140 → 142 taken 246 times.
3036 if (ref[1] == 0)
483 2790 AV_ZERO32(sl->mv_cache[1][scan8[i8 * 4 + i4]]);
484 3036 m++;
485 }
486 }
487
2/2
✓ Branch 145 → 146 taken 29990 times.
✓ Branch 145 → 147 taken 313 times.
30303 if (!(m & 3))
488 29990 sl->sub_mb_type[i8] += MB_TYPE_16x16 - MB_TYPE_8x8;
489 30303 n += m;
490 }
491 }
492 }
493
4/4
✓ Branch 150 → 151 taken 105263 times.
✓ Branch 150 → 153 taken 68288 times.
✓ Branch 151 → 152 taken 95855 times.
✓ Branch 151 → 153 taken 9408 times.
173551 if (!is_b8x8 && !(n & 15))
494 95855 *mb_type = (*mb_type & ~(MB_TYPE_8x8 | MB_TYPE_16x8 | MB_TYPE_8x16 |
495 MB_TYPE_P1L0 | MB_TYPE_P1L1)) |
496 95855 MB_TYPE_16x16 | MB_TYPE_DIRECT2;
497 }
498 }
499
500 252568 static void pred_temp_direct_motion(const H264Context *const h, H264SliceContext *sl,
501 int *mb_type)
502 {
503 252568 int b8_stride = 2;
504 252568 int b4_stride = h->b_stride;
505 252568 int mb_xy = sl->mb_xy, mb_y = sl->mb_y;
506 int mb_type_col[2];
507 252568 int col_field = 0;
508 const int16_t (*l1mv0)[2], (*l1mv1)[2];
509 const int8_t *l1ref0, *l1ref1;
510 252568 const int is_b8x8 = IS_8X8(*mb_type);
511 unsigned int sub_mb_type;
512 int i8, i4;
513
514 assert(sl->ref_list[1][0].reference & 3);
515
516 252568 await_reference_mb_row(h, &sl->ref_list[1][0],
517 252568 sl->mb_y + !!IS_INTERLACED(*mb_type));
518
519
2/2
✓ Branch 3 → 4 taken 182932 times.
✓ Branch 3 → 5 taken 69636 times.
252568 if (sl->ref_list[1][0].parent->field_picture ||
520
2/2
✓ Branch 4 → 5 taken 19848 times.
✓ Branch 4 → 9 taken 163084 times.
182932 IS_INTERLACED(sl->ref_list[1][0].parent->mb_type[mb_xy])) { // AFL/AFR/FR/FL -> AFL/FL
521
2/2
✓ Branch 5 → 6 taken 15720 times.
✓ Branch 5 → 7 taken 73764 times.
89484 if (!IS_INTERLACED(*mb_type)) { // AFR/FR -> AFL/FL
522 15720 mb_y = (sl->mb_y & ~1) + sl->col_parity;
523 15720 mb_xy = sl->mb_x +
524 15720 ((sl->mb_y & ~1) + sl->col_parity) * h->mb_stride;
525 15720 b8_stride = 0;
526 } else {
527 73764 mb_y += sl->col_fieldoff;
528 73764 mb_xy += h->mb_stride * sl->col_fieldoff; // non-zero for FL -> FL & differ parity
529 }
530 // Undecoded macroblocks of a broken field picture lack the flag, the
531 // colocated type has to agree with the branch taken here.
532 89484 col_field = MB_TYPE_INTERLACED;
533 89484 goto single_col;
534 } else { // AFL/AFR/FR/FL -> AFR/FR
535
2/2
✓ Branch 9 → 10 taken 16565 times.
✓ Branch 9 → 18 taken 146519 times.
163084 if (IS_INTERLACED(*mb_type)) { // AFL /FL -> AFR/FR
536 16565 mb_y = sl->mb_y & ~1;
537 16565 mb_xy = sl->mb_x + (sl->mb_y & ~1) * h->mb_stride;
538 16565 mb_type_col[0] = sl->ref_list[1][0].parent->mb_type[mb_xy];
539 16565 mb_type_col[1] = sl->ref_list[1][0].parent->mb_type[mb_xy + h->mb_stride];
540 16565 b8_stride = 2 + 4 * h->mb_stride;
541 16565 b4_stride *= 6;
542 16565 if (IS_INTERLACED(mb_type_col[0]) !=
543
1/2
✗ Branch 10 → 11 not taken.
✓ Branch 10 → 12 taken 16565 times.
16565 IS_INTERLACED(mb_type_col[1])) {
544 ✗ mb_type_col[0] &= ~MB_TYPE_INTERLACED;
545 ✗ mb_type_col[1] &= ~MB_TYPE_INTERLACED;
546 }
547
548 16565 sub_mb_type = MB_TYPE_16x16 | MB_TYPE_P0L0 | MB_TYPE_P0L1 |
549 MB_TYPE_DIRECT2; /* B_SUB_8x8 */
550
551
2/2
✓ Branch 12 → 13 taken 9903 times.
✓ Branch 12 → 16 taken 6662 times.
16565 if ((mb_type_col[0] & MB_TYPE_16x16_OR_INTRA) &&
552
4/4
✓ Branch 13 → 14 taken 7225 times.
✓ Branch 13 → 16 taken 2678 times.
✓ Branch 14 → 15 taken 5889 times.
✓ Branch 14 → 16 taken 1336 times.
9903 (mb_type_col[1] & MB_TYPE_16x16_OR_INTRA) &&
553 !is_b8x8) {
554 5889 *mb_type |= MB_TYPE_16x8 | MB_TYPE_L0L1 |
555 MB_TYPE_DIRECT2; /* B_16x8 */
556 } else {
557 10676 *mb_type |= MB_TYPE_8x8 | MB_TYPE_L0L1;
558 }
559 } else { // AFR/FR -> AFR/FR
560 146519 single_col:
561 236003 mb_type_col[0] =
562 236003 mb_type_col[1] = sl->ref_list[1][0].parent->mb_type[mb_xy] | col_field;
563
564 236003 sub_mb_type = MB_TYPE_16x16 | MB_TYPE_P0L0 | MB_TYPE_P0L1 |
565 MB_TYPE_DIRECT2; /* B_SUB_8x8 */
566
4/4
✓ Branch 19 → 20 taken 190423 times.
✓ Branch 19 → 22 taken 45580 times.
✓ Branch 20 → 21 taken 135424 times.
✓ Branch 20 → 22 taken 54999 times.
236003 if (!is_b8x8 && (mb_type_col[0] & MB_TYPE_16x16_OR_INTRA)) {
567 135424 *mb_type |= MB_TYPE_16x16 | MB_TYPE_P0L0 | MB_TYPE_P0L1 |
568 MB_TYPE_DIRECT2; /* B_16x16 */
569
2/2
✓ Branch 22 → 23 taken 54999 times.
✓ Branch 22 → 25 taken 45580 times.
100579 } else if (!is_b8x8 &&
570
2/2
✓ Branch 23 → 24 taken 35141 times.
✓ Branch 23 → 25 taken 19858 times.
54999 (mb_type_col[0] & (MB_TYPE_16x8 | MB_TYPE_8x16))) {
571 35141 *mb_type |= MB_TYPE_L0L1 | MB_TYPE_DIRECT2 |
572 35141 (mb_type_col[0] & (MB_TYPE_16x8 | MB_TYPE_8x16));
573 } else {
574
2/2
✓ Branch 25 → 26 taken 10593 times.
✓ Branch 25 → 27 taken 54845 times.
65438 if (!h->ps.sps->direct_8x8_inference_flag) {
575 /* FIXME: save sub mb types from previous frames (or derive
576 * from MVs) so we know exactly what block size to use */
577 10593 sub_mb_type = MB_TYPE_8x8 | MB_TYPE_P0L0 | MB_TYPE_P0L1 |
578 MB_TYPE_DIRECT2; /* B_SUB_4x4 */
579 }
580 65438 *mb_type |= MB_TYPE_8x8 | MB_TYPE_L0L1;
581 }
582 }
583 }
584
585 252568 await_reference_mb_row(h, &sl->ref_list[1][0], mb_y);
586
587 252568 l1mv0 = (void*)&sl->ref_list[1][0].parent->motion_val[0][h->mb2b_xy[mb_xy]];
588 252568 l1mv1 = (void*)&sl->ref_list[1][0].parent->motion_val[1][h->mb2b_xy[mb_xy]];
589 252568 l1ref0 = &sl->ref_list[1][0].parent->ref_index[0][4 * mb_xy];
590 252568 l1ref1 = &sl->ref_list[1][0].parent->ref_index[1][4 * mb_xy];
591
2/2
✓ Branch 29 → 30 taken 15720 times.
✓ Branch 29 → 32 taken 236848 times.
252568 if (!b8_stride) {
592
2/2
✓ Branch 30 → 31 taken 7767 times.
✓ Branch 30 → 32 taken 7953 times.
15720 if (sl->mb_y & 1) {
593 7767 l1ref0 += 2;
594 7767 l1ref1 += 2;
595 7767 l1mv0 += 2 * b4_stride;
596 7767 l1mv1 += 2 * b4_stride;
597 }
598 }
599
600 {
601 252568 const int *map_col_to_list0[2] = { sl->map_col_to_list0[0],
602 252568 sl->map_col_to_list0[1] };
603 252568 const int *dist_scale_factor = sl->dist_scale_factor;
604 int ref_offset;
605
606
4/4
✓ Branch 32 → 33 taken 42787 times.
✓ Branch 32 → 35 taken 209781 times.
✓ Branch 33 → 34 taken 20468 times.
✓ Branch 33 → 35 taken 22319 times.
252568 if (FRAME_MBAFF(h) && IS_INTERLACED(*mb_type)) {
607 20468 map_col_to_list0[0] = sl->map_col_to_list0_field[sl->mb_y & 1][0];
608 20468 map_col_to_list0[1] = sl->map_col_to_list0_field[sl->mb_y & 1][1];
609 20468 dist_scale_factor = sl->dist_scale_factor_field[sl->mb_y & 1];
610 }
611 252568 ref_offset = (sl->ref_list[1][0].parent->mbaff << 4) & (mb_type_col[0] >> 3);
612
613
2/2
✓ Branch 35 → 36 taken 32285 times.
✓ Branch 35 → 60 taken 220283 times.
252568 if (IS_INTERLACED(*mb_type) != IS_INTERLACED(mb_type_col[0])) {
614
2/2
✓ Branch 36 → 37 taken 15720 times.
✓ Branch 36 → 38 taken 16565 times.
32285 int y_shift = 2 * !IS_INTERLACED(*mb_type);
615 assert(h->ps.sps->direct_8x8_inference_flag);
616
617
2/2
✓ Branch 58 → 40 taken 129140 times.
✓ Branch 58 → 59 taken 32285 times.
161425 for (i8 = 0; i8 < 4; i8++) {
618 129140 const int x8 = i8 & 1;
619 129140 const int y8 = i8 >> 1;
620 int ref0, scale;
621 129140 const int16_t (*l1mv)[2] = l1mv0;
622
623
4/4
✓ Branch 40 → 41 taken 43260 times.
✓ Branch 40 → 43 taken 85880 times.
✓ Branch 41 → 42 taken 22674 times.
✓ Branch 41 → 43 taken 20586 times.
129140 if (is_b8x8 && !IS_DIRECT(sl->sub_mb_type[i8]))
624 22674 continue;
625 106466 sl->sub_mb_type[i8] = sub_mb_type;
626
627 106466 fill_rectangle(&sl->ref_cache[1][scan8[i8 * 4]], 2, 2, 8, 0, 1);
628
2/2
✓ Branch 44 → 45 taken 25630 times.
✓ Branch 44 → 49 taken 80836 times.
106466 if (IS_INTRA(mb_type_col[y8])) {
629 25630 fill_rectangle(&sl->ref_cache[0][scan8[i8 * 4]], 2, 2, 8, 0, 1);
630 25630 fill_rectangle(&sl->mv_cache[0][scan8[i8 * 4]], 2, 2, 8, 0, 4);
631 25630 fill_rectangle(&sl->mv_cache[1][scan8[i8 * 4]], 2, 2, 8, 0, 4);
632 25630 continue;
633 }
634
635 80836 ref0 = l1ref0[x8 + y8 * b8_stride];
636
2/2
✓ Branch 49 → 50 taken 80643 times.
✓ Branch 49 → 51 taken 193 times.
80836 if (ref0 >= 0)
637 80643 ref0 = map_col_to_list0[0][ref0 + ref_offset];
638 else {
639 193 ref0 = map_col_to_list0[1][l1ref1[x8 + y8 * b8_stride] +
640 ref_offset];
641 193 l1mv = l1mv1;
642 }
643 80836 scale = dist_scale_factor[ref0];
644 80836 fill_rectangle(&sl->ref_cache[0][scan8[i8 * 4]], 2, 2, 8,
645 ref0, 1);
646
647 {
648 80836 const int16_t *mv_col = l1mv[x8 * 3 + y8 * b4_stride];
649 80836 int my_col = (mv_col[1] * (1 << y_shift)) / 2;
650 80836 int mx = (scale * mv_col[0] + 128) >> 8;
651 80836 int my = (scale * my_col + 128) >> 8;
652 80836 fill_rectangle(&sl->mv_cache[0][scan8[i8 * 4]], 2, 2, 8,
653 pack16to32(mx, my), 4);
654 80836 fill_rectangle(&sl->mv_cache[1][scan8[i8 * 4]], 2, 2, 8,
655 80836 pack16to32(mx - mv_col[0], my - my_col), 4);
656 }
657 }
658 32285 return;
659 }
660
661 /* one-to-one mv scaling */
662
663
2/2
✓ Branch 60 → 61 taken 127760 times.
✓ Branch 60 → 76 taken 92523 times.
220283 if (IS_16X16(*mb_type)) {
664 int ref, mv0, mv1;
665
666 127760 fill_rectangle(&sl->ref_cache[1][scan8[0]], 4, 4, 8, 0, 1);
667
2/2
✓ Branch 62 → 63 taken 61090 times.
✓ Branch 62 → 64 taken 66670 times.
127760 if (IS_INTRA(mb_type_col[0])) {
668 61090 ref = mv0 = mv1 = 0;
669 } else {
670 66619 const int ref0 = l1ref0[0] >= 0 ? map_col_to_list0[0][l1ref0[0] + ref_offset]
671
2/2
✓ Branch 64 → 65 taken 66619 times.
✓ Branch 64 → 66 taken 51 times.
66670 : map_col_to_list0[1][l1ref1[0] + ref_offset];
672 66670 const int scale = dist_scale_factor[ref0];
673
2/2
✓ Branch 67 → 68 taken 66619 times.
✓ Branch 67 → 69 taken 51 times.
66670 const int16_t *mv_col = l1ref0[0] >= 0 ? l1mv0[0] : l1mv1[0];
674 int mv_l0[2];
675 66670 mv_l0[0] = (scale * mv_col[0] + 128) >> 8;
676 66670 mv_l0[1] = (scale * mv_col[1] + 128) >> 8;
677 66670 ref = ref0;
678 66670 mv0 = pack16to32(mv_l0[0], mv_l0[1]);
679 66670 mv1 = pack16to32(mv_l0[0] - mv_col[0], mv_l0[1] - mv_col[1]);
680 }
681 127760 fill_rectangle(&sl->ref_cache[0][scan8[0]], 4, 4, 8, ref, 1);
682 127760 fill_rectangle(&sl->mv_cache[0][scan8[0]], 4, 4, 8, mv0, 4);
683 127760 fill_rectangle(&sl->mv_cache[1][scan8[0]], 4, 4, 8, mv1, 4);
684 } else {
685
2/2
✓ Branch 100 → 77 taken 370092 times.
✓ Branch 100 → 101 taken 92523 times.
462615 for (i8 = 0; i8 < 4; i8++) {
686 370092 const int x8 = i8 & 1;
687 370092 const int y8 = i8 >> 1;
688 int ref0, scale;
689 370092 const int16_t (*l1mv)[2] = l1mv0;
690
691
4/4
✓ Branch 77 → 78 taken 163928 times.
✓ Branch 77 → 80 taken 206164 times.
✓ Branch 78 → 79 taken 92478 times.
✓ Branch 78 → 80 taken 71450 times.
370092 if (is_b8x8 && !IS_DIRECT(sl->sub_mb_type[i8]))
692 92478 continue;
693 277614 sl->sub_mb_type[i8] = sub_mb_type;
694 277614 fill_rectangle(&sl->ref_cache[1][scan8[i8 * 4]], 2, 2, 8, 0, 1);
695
2/2
✓ Branch 81 → 82 taken 22294 times.
✓ Branch 81 → 86 taken 255320 times.
277614 if (IS_INTRA(mb_type_col[0])) {
696 22294 fill_rectangle(&sl->ref_cache[0][scan8[i8 * 4]], 2, 2, 8, 0, 1);
697 22294 fill_rectangle(&sl->mv_cache[0][scan8[i8 * 4]], 2, 2, 8, 0, 4);
698 22294 fill_rectangle(&sl->mv_cache[1][scan8[i8 * 4]], 2, 2, 8, 0, 4);
699 22294 continue;
700 }
701
702 assert(b8_stride == 2);
703 255320 ref0 = l1ref0[i8];
704
2/2
✓ Branch 86 → 87 taken 255300 times.
✓ Branch 86 → 88 taken 20 times.
255320 if (ref0 >= 0)
705 255300 ref0 = map_col_to_list0[0][ref0 + ref_offset];
706 else {
707 20 ref0 = map_col_to_list0[1][l1ref1[i8] + ref_offset];
708 20 l1mv = l1mv1;
709 }
710 255320 scale = dist_scale_factor[ref0];
711
712 255320 fill_rectangle(&sl->ref_cache[0][scan8[i8 * 4]], 2, 2, 8,
713 ref0, 1);
714
2/2
✓ Branch 90 → 91 taken 230012 times.
✓ Branch 90 → 95 taken 25308 times.
255320 if (IS_SUB_8X8(sub_mb_type)) {
715 230012 const int16_t *mv_col = l1mv[x8 * 3 + y8 * 3 * b4_stride];
716 230012 int mx = (scale * mv_col[0] + 128) >> 8;
717 230012 int my = (scale * mv_col[1] + 128) >> 8;
718 230012 fill_rectangle(&sl->mv_cache[0][scan8[i8 * 4]], 2, 2, 8,
719 pack16to32(mx, my), 4);
720 230012 fill_rectangle(&sl->mv_cache[1][scan8[i8 * 4]], 2, 2, 8,
721 230012 pack16to32(mx - mv_col[0], my - mv_col[1]), 4);
722 } else {
723
2/2
✓ Branch 98 → 96 taken 101232 times.
✓ Branch 98 → 99 taken 25308 times.
126540 for (i4 = 0; i4 < 4; i4++) {
724 101232 const int16_t *mv_col = l1mv[x8 * 2 + (i4 & 1) +
725 101232 (y8 * 2 + (i4 >> 1)) * b4_stride];
726 101232 int16_t *mv_l0 = sl->mv_cache[0][scan8[i8 * 4 + i4]];
727 101232 mv_l0[0] = (scale * mv_col[0] + 128) >> 8;
728 101232 mv_l0[1] = (scale * mv_col[1] + 128) >> 8;
729 101232 AV_WN32A(sl->mv_cache[1][scan8[i8 * 4 + i4]],
730 pack16to32(mv_l0[0] - mv_col[0],
731 mv_l0[1] - mv_col[1]));
732 }
733 }
734 }
735 }
736 }
737 }
738
739 3382869 void ff_h264_pred_direct_motion(const H264Context *const h, H264SliceContext *sl,
740 int *mb_type)
741 {
742
2/2
✓ Branch 2 → 3 taken 3130301 times.
✓ Branch 2 → 4 taken 252568 times.
3382869 if (sl->direct_spatial_mv_pred)
743 3130301 pred_spatial_direct_motion(h, sl, mb_type);
744 else
745 252568 pred_temp_direct_motion(h, sl, mb_type);
746 3382869 }
747