FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/h264_mvpred.h
Date: 2026-10-30 17:37:53
Exec Total Coverage
Lines: 500 502 99.6%
Functions: 14 14 100.0%
Branches: 374 376 99.5%

Line Branch Exec Source
1 /*
2 * H.26L/H.264/AVC/JVT/14496-10/... motion vector prediction
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 motion vector prediction.
25 * @author Michael Niedermayer <michaelni@gmx.at>
26 */
27
28 #ifndef AVCODEC_H264_MVPRED_H
29 #define AVCODEC_H264_MVPRED_H
30
31 #include "h264dec.h"
32 #include "mpegutils.h"
33 #include "rectangle.h"
34
35 #include "libavutil/avassert.h"
36 #include "libavutil/mem_internal.h"
37
38
39 /**
40 * Get the predicted intra4x4 prediction mode.
41 */
42 31210472 static av_always_inline int pred_intra_mode(const H264Context *h,
43 H264SliceContext *sl, int n)
44 {
45 31210472 const int index8 = scan8[n];
46 31210472 const int left = sl->intra4x4_pred_mode_cache[index8 - 1];
47 31210472 const int top = sl->intra4x4_pred_mode_cache[index8 - 8];
48 31210472 const int min = FFMIN(left, top);
49
50 ff_tlog(h->avctx, "mode:%d %d min:%d\n", left, top, min);
51
52
2/2
✓ Branch 0 taken 883262 times.
✓ Branch 1 taken 30327210 times.
31210472 if (min < 0)
53 883262 return DC_PRED;
54 else
55 30327210 return min;
56 }
57
58 3115343 static av_always_inline void write_back_intra_pred_mode(const H264Context *h,
59 H264SliceContext *sl)
60 {
61 3115343 int8_t *i4x4 = sl->intra4x4_pred_mode + h->mb2br_xy[sl->mb_xy];
62 3115343 int8_t *i4x4_cache = sl->intra4x4_pred_mode_cache;
63
64 3115343 AV_COPY32(i4x4, i4x4_cache + 4 + 8 * 4);
65 3115343 i4x4[4] = i4x4_cache[7 + 8 * 3];
66 3115343 i4x4[5] = i4x4_cache[7 + 8 * 2];
67 3115343 i4x4[6] = i4x4_cache[7 + 8 * 1];
68 3115343 }
69
70 11187352 static av_always_inline void write_back_non_zero_count(const H264Context *h,
71 H264SliceContext *sl)
72 {
73 11187352 const int mb_xy = sl->mb_xy;
74 11187352 uint8_t *nnz = h->non_zero_count[mb_xy];
75 11187352 uint8_t *nnz_cache = sl->non_zero_count_cache;
76
77 11187352 AV_COPY32(&nnz[ 0], &nnz_cache[4 + 8 * 1]);
78 11187352 AV_COPY32(&nnz[ 4], &nnz_cache[4 + 8 * 2]);
79 11187352 AV_COPY32(&nnz[ 8], &nnz_cache[4 + 8 * 3]);
80 11187352 AV_COPY32(&nnz[12], &nnz_cache[4 + 8 * 4]);
81 11187352 AV_COPY32(&nnz[16], &nnz_cache[4 + 8 * 6]);
82 11187352 AV_COPY32(&nnz[20], &nnz_cache[4 + 8 * 7]);
83 11187352 AV_COPY32(&nnz[32], &nnz_cache[4 + 8 * 11]);
84 11187352 AV_COPY32(&nnz[36], &nnz_cache[4 + 8 * 12]);
85
86
2/2
✓ Branch 0 taken 979699 times.
✓ Branch 1 taken 10207653 times.
11187352 if (!h->chroma_y_shift) {
87 979699 AV_COPY32(&nnz[24], &nnz_cache[4 + 8 * 8]);
88 979699 AV_COPY32(&nnz[28], &nnz_cache[4 + 8 * 9]);
89 979699 AV_COPY32(&nnz[40], &nnz_cache[4 + 8 * 13]);
90 979699 AV_COPY32(&nnz[44], &nnz_cache[4 + 8 * 14]);
91 }
92 11187352 }
93
94 15426506 static av_always_inline void write_back_motion_list(const H264Context *h,
95 H264SliceContext *sl,
96 int b_stride,
97 int b_xy, int b8_xy,
98 int mb_type, int list)
99 {
100 15426506 int16_t(*mv_dst)[2] = &h->cur_pic.motion_val[list][b_xy];
101 15426506 int16_t(*mv_src)[2] = &sl->mv_cache[list][scan8[0]];
102 15426506 AV_COPY128(mv_dst + 0 * b_stride, mv_src + 8 * 0);
103 15426506 AV_COPY128(mv_dst + 1 * b_stride, mv_src + 8 * 1);
104 15426506 AV_COPY128(mv_dst + 2 * b_stride, mv_src + 8 * 2);
105 15426506 AV_COPY128(mv_dst + 3 * b_stride, mv_src + 8 * 3);
106 if (CABAC(h)) {
107 11307375 uint8_t (*mvd_dst)[2] = &sl->mvd_table[list][FMO ? 8 * sl->mb_xy
108 11307375 : h->mb2br_xy[sl->mb_xy]];
109 11307375 uint8_t(*mvd_src)[2] = &sl->mvd_cache[list][scan8[0]];
110
2/2
✓ Branch 0 taken 5393531 times.
✓ Branch 1 taken 5913844 times.
11307375 if (IS_SKIP(mb_type)) {
111 5393531 AV_ZERO128(mvd_dst);
112 } else {
113 5913844 AV_COPY64(mvd_dst, mvd_src + 8 * 3);
114 5913844 AV_COPY16(mvd_dst + 3 + 3, mvd_src + 3 + 8 * 0);
115 5913844 AV_COPY16(mvd_dst + 3 + 2, mvd_src + 3 + 8 * 1);
116 5913844 AV_COPY16(mvd_dst + 3 + 1, mvd_src + 3 + 8 * 2);
117 }
118 }
119
120 {
121 15426506 int8_t *ref_index = &h->cur_pic.ref_index[list][b8_xy];
122 15426506 int8_t *ref_cache = sl->ref_cache[list];
123 15426506 ref_index[0 + 0 * 2] = ref_cache[scan8[0]];
124 15426506 ref_index[1 + 0 * 2] = ref_cache[scan8[4]];
125 15426506 ref_index[0 + 1 * 2] = ref_cache[scan8[8]];
126 15426506 ref_index[1 + 1 * 2] = ref_cache[scan8[12]];
127 }
128 15426506 }
129
130 11500940 static av_always_inline void write_back_motion(const H264Context *h,
131 H264SliceContext *sl,
132 int mb_type)
133 {
134 11500940 const int b_stride = h->b_stride;
135 11500940 const int b_xy = 4 * sl->mb_x + 4 * sl->mb_y * h->b_stride; // try mb2b(8)_xy
136 11500940 const int b8_xy = 4 * sl->mb_xy;
137
138
2/2
✓ Branch 0 taken 10664451 times.
✓ Branch 1 taken 836489 times.
11500940 if (USES_LIST(mb_type, 0)) {
139 10664451 write_back_motion_list(h, sl, b_stride, b_xy, b8_xy, mb_type, 0);
140 } else {
141 836489 fill_rectangle(&h->cur_pic.ref_index[0][b8_xy],
142 2, 2, 2, (uint8_t)LIST_NOT_USED, 1);
143 }
144
2/2
✓ Branch 0 taken 4762055 times.
✓ Branch 1 taken 6738885 times.
11500940 if (USES_LIST(mb_type, 1))
145 4762055 write_back_motion_list(h, sl, b_stride, b_xy, b8_xy, mb_type, 1);
146
147
2/2
✓ Branch 0 taken 4706759 times.
✓ Branch 1 taken 3374890 times.
8081649 if (sl->slice_type_nos == AV_PICTURE_TYPE_B && CABAC(h)) {
148
2/2
✓ Branch 0 taken 424966 times.
✓ Branch 1 taken 4281793 times.
4706759 if (IS_8X8(mb_type)) {
149 424966 uint8_t *direct_table = &h->direct_table[4 * sl->mb_xy];
150 424966 direct_table[1] = sl->sub_mb_type[1] >> 1;
151 424966 direct_table[2] = sl->sub_mb_type[2] >> 1;
152 424966 direct_table[3] = sl->sub_mb_type[3] >> 1;
153 }
154 }
155 11500940 }
156
157 308362 static av_always_inline int get_dct8x8_allowed(const H264Context *h, H264SliceContext *sl)
158 {
159
2/2
✓ Branch 0 taken 303485 times.
✓ Branch 1 taken 4877 times.
308362 if (h->ps.sps->direct_8x8_inference_flag)
160 303485 return !(AV_RN64A(sl->sub_mb_type) &
161 ((MB_TYPE_16x8 | MB_TYPE_8x16 | MB_TYPE_8x8) *
162 0x0001000100010001ULL));
163 else
164 4877 return !(AV_RN64A(sl->sub_mb_type) &
165 ((MB_TYPE_16x8 | MB_TYPE_8x16 | MB_TYPE_8x8 | MB_TYPE_DIRECT2) *
166 0x0001000100010001ULL));
167 }
168
169 18562893 static av_always_inline int fetch_diagonal_mv(const H264Context *h, H264SliceContext *sl,
170 const int16_t **C,
171 int i, int list, int part_width)
172 {
173 18562893 const int topright_ref = sl->ref_cache[list][i - 8 + part_width];
174
175 /* there is no consistent mapping of mvs to neighboring locations that will
176 * make mbaff happy, so we can't move all this logic to fill_caches */
177
2/2
✓ Branch 0 taken 2973597 times.
✓ Branch 1 taken 15589296 times.
18562893 if (FRAME_MBAFF(h)) {
178 #define SET_DIAG_MV(MV_OP, REF_OP, XY, Y4) \
179 const int xy = XY, y4 = Y4; \
180 const int mb_type = mb_types[xy + (y4 >> 2) * h->mb_stride]; \
181 if (!USES_LIST(mb_type, list)) \
182 return LIST_NOT_USED; \
183 mv = h->cur_pic_ptr->motion_val[list][h->mb2b_xy[xy] + 3 + y4 * h->b_stride]; \
184 sl->mv_cache[list][scan8[0] - 2][0] = mv[0]; \
185 sl->mv_cache[list][scan8[0] - 2][1] = mv[1] MV_OP; \
186 return h->cur_pic_ptr->ref_index[list][4 * xy + 1 + (y4 & ~1)] REF_OP;
187
188
2/2
✓ Branch 0 taken 1303181 times.
✓ Branch 1 taken 1670416 times.
2973597 if (topright_ref == PART_NOT_AVAILABLE
189
4/4
✓ Branch 0 taken 807286 times.
✓ Branch 1 taken 495895 times.
✓ Branch 2 taken 199073 times.
✓ Branch 3 taken 608213 times.
1303181 && i >= scan8[0] + 8 && (i & 7) == 4
190
2/2
✓ Branch 0 taken 190896 times.
✓ Branch 1 taken 8177 times.
199073 && sl->ref_cache[list][scan8[0] - 1] != PART_NOT_AVAILABLE) {
191 190896 const uint32_t *mb_types = h->cur_pic_ptr->mb_type;
192 const int16_t *mv;
193 190896 AV_ZERO32(sl->mv_cache[list][scan8[0] - 2]);
194 190896 *C = sl->mv_cache[list][scan8[0] - 2];
195
196
4/4
✓ Branch 0 taken 94068 times.
✓ Branch 1 taken 96828 times.
✓ Branch 2 taken 26751 times.
✓ Branch 3 taken 67317 times.
190896 if (!MB_FIELD(sl) && IS_INTERLACED(sl->left_type[0])) {
197
2/2
✓ Branch 0 taken 2849 times.
✓ Branch 1 taken 23902 times.
26751 SET_DIAG_MV(* 2, >> 1, sl->left_mb_xy[0] + h->mb_stride,
198 (sl->mb_y & 1) * 2 + (i >> 5));
199 }
200
4/4
✓ Branch 0 taken 96828 times.
✓ Branch 1 taken 67317 times.
✓ Branch 2 taken 36130 times.
✓ Branch 3 taken 60698 times.
164145 if (MB_FIELD(sl) && !IS_INTERLACED(sl->left_type[0])) {
201 // left shift will turn LIST_NOT_USED into PART_NOT_AVAILABLE, but that's OK.
202
2/2
✓ Branch 0 taken 5750 times.
✓ Branch 1 taken 30380 times.
36130 SET_DIAG_MV(/ 2, *2, sl->left_mb_xy[i >= 36], ((i >> 2)) & 3);
203 }
204 }
205 #undef SET_DIAG_MV
206 }
207
208
2/2
✓ Branch 0 taken 11815154 times.
✓ Branch 1 taken 6684858 times.
18500012 if (topright_ref != PART_NOT_AVAILABLE) {
209 11815154 *C = sl->mv_cache[list][i - 8 + part_width];
210 11815154 return topright_ref;
211 } else {
212 ff_tlog(h->avctx, "topright MV not available\n");
213
214 6684858 *C = sl->mv_cache[list][i - 8 - 1];
215 6684858 return sl->ref_cache[list][i - 8 - 1];
216 }
217 }
218
219 /**
220 * Get the predicted MV.
221 * @param n the block index
222 * @param part_width the width of the partition (4, 8,16) -> (1, 2, 4)
223 * @param mx the x component of the predicted motion vector
224 * @param my the y component of the predicted motion vector
225 */
226 17903664 static av_always_inline void pred_motion(const H264Context *const h,
227 H264SliceContext *sl,
228 int n,
229 int part_width, int list, int ref,
230 int *const mx, int *const my)
231 {
232 17903664 const int index8 = scan8[n];
233 17903664 const int top_ref = sl->ref_cache[list][index8 - 8];
234 17903664 const int left_ref = sl->ref_cache[list][index8 - 1];
235 17903664 const int16_t *const A = sl->mv_cache[list][index8 - 1];
236 17903664 const int16_t *const B = sl->mv_cache[list][index8 - 8];
237 const int16_t *C;
238 int diagonal_ref, match_count;
239
240 av_assert2(part_width == 1 || part_width == 2 || part_width == 4);
241
242 /* mv_cache
243 * B . . A T T T T
244 * U . . L . . , .
245 * U . . L . . . .
246 * U . . L . . , .
247 * . . . L . . . .
248 */
249
250 17903664 diagonal_ref = fetch_diagonal_mv(h, sl, &C, index8, list, part_width);
251 17903664 match_count = (diagonal_ref == ref) + (top_ref == ref) + (left_ref == ref);
252 ff_tlog(h->avctx, "pred_motion match_count=%d\n", match_count);
253
2/2
✓ Branch 0 taken 13272294 times.
✓ Branch 1 taken 4631370 times.
17903664 if (match_count > 1) { //most common
254 13272294 *mx = mid_pred(A[0], B[0], C[0]);
255 13272294 *my = mid_pred(A[1], B[1], C[1]);
256
2/2
✓ Branch 0 taken 3139450 times.
✓ Branch 1 taken 1491920 times.
4631370 } else if (match_count == 1) {
257
2/2
✓ Branch 0 taken 1982334 times.
✓ Branch 1 taken 1157116 times.
3139450 if (left_ref == ref) {
258 1982334 *mx = A[0];
259 1982334 *my = A[1];
260
2/2
✓ Branch 0 taken 827691 times.
✓ Branch 1 taken 329425 times.
1157116 } else if (top_ref == ref) {
261 827691 *mx = B[0];
262 827691 *my = B[1];
263 } else {
264 329425 *mx = C[0];
265 329425 *my = C[1];
266 }
267 } else {
268
4/4
✓ Branch 0 taken 246386 times.
✓ Branch 1 taken 1245534 times.
✓ Branch 2 taken 245969 times.
✓ Branch 3 taken 417 times.
1491920 if (top_ref == PART_NOT_AVAILABLE &&
269
2/2
✓ Branch 0 taken 220157 times.
✓ Branch 1 taken 25812 times.
245969 diagonal_ref == PART_NOT_AVAILABLE &&
270 left_ref != PART_NOT_AVAILABLE) {
271 220157 *mx = A[0];
272 220157 *my = A[1];
273 } else {
274 1271763 *mx = mid_pred(A[0], B[0], C[0]);
275 1271763 *my = mid_pred(A[1], B[1], C[1]);
276 }
277 }
278
279 ff_tlog(h->avctx,
280 "pred_motion (%2d %2d %2d) (%2d %2d %2d) (%2d %2d %2d) -> (%2d %2d %2d) at %2d %2d %d list %d\n",
281 top_ref, B[0], B[1], diagonal_ref, C[0], C[1], left_ref,
282 A[0], A[1], ref, *mx, *my, sl->mb_x, sl->mb_y, n, list);
283 17903664 }
284
285 /**
286 * Get the directionally predicted 16x8 MV.
287 * @param n the block index
288 * @param mx the x component of the predicted motion vector
289 * @param my the y component of the predicted motion vector
290 */
291 1472567 static av_always_inline void pred_16x8_motion(const H264Context *const h,
292 H264SliceContext *sl,
293 int n, int list, int ref,
294 int *const mx, int *const my)
295 {
296
2/2
✓ Branch 0 taken 735371 times.
✓ Branch 1 taken 737196 times.
1472567 if (n == 0) {
297 735371 const int top_ref = sl->ref_cache[list][scan8[0] - 8];
298 735371 const int16_t *const B = sl->mv_cache[list][scan8[0] - 8];
299
300 ff_tlog(h->avctx, "pred_16x8: (%2d %2d %2d) at %2d %2d %d list %d\n",
301 top_ref, B[0], B[1], sl->mb_x, sl->mb_y, n, list);
302
303
2/2
✓ Branch 0 taken 429244 times.
✓ Branch 1 taken 306127 times.
735371 if (top_ref == ref) {
304 429244 *mx = B[0];
305 429244 *my = B[1];
306 429244 return;
307 }
308 } else {
309 737196 const int left_ref = sl->ref_cache[list][scan8[8] - 1];
310 737196 const int16_t *const A = sl->mv_cache[list][scan8[8] - 1];
311
312 ff_tlog(h->avctx, "pred_16x8: (%2d %2d %2d) at %2d %2d %d list %d\n",
313 left_ref, A[0], A[1], sl->mb_x, sl->mb_y, n, list);
314
315
2/2
✓ Branch 0 taken 503080 times.
✓ Branch 1 taken 234116 times.
737196 if (left_ref == ref) {
316 503080 *mx = A[0];
317 503080 *my = A[1];
318 503080 return;
319 }
320 }
321
322 //RARE
323 540243 pred_motion(h, sl, n, 4, list, ref, mx, my);
324 }
325
326 /**
327 * Get the directionally predicted 8x16 MV.
328 * @param n the block index
329 * @param mx the x component of the predicted motion vector
330 * @param my the y component of the predicted motion vector
331 */
332 1319722 static av_always_inline void pred_8x16_motion(const H264Context *const h,
333 H264SliceContext *sl,
334 int n, int list, int ref,
335 int *const mx, int *const my)
336 {
337
2/2
✓ Branch 0 taken 660493 times.
✓ Branch 1 taken 659229 times.
1319722 if (n == 0) {
338 660493 const int left_ref = sl->ref_cache[list][scan8[0] - 1];
339 660493 const int16_t *const A = sl->mv_cache[list][scan8[0] - 1];
340
341 ff_tlog(h->avctx, "pred_8x16: (%2d %2d %2d) at %2d %2d %d list %d\n",
342 left_ref, A[0], A[1], sl->mb_x, sl->mb_y, n, list);
343
344
2/2
✓ Branch 0 taken 426299 times.
✓ Branch 1 taken 234194 times.
660493 if (left_ref == ref) {
345 426299 *mx = A[0];
346 426299 *my = A[1];
347 426299 return;
348 }
349 } else {
350 const int16_t *C;
351 int diagonal_ref;
352
353 659229 diagonal_ref = fetch_diagonal_mv(h, sl, &C, scan8[4], list, 2);
354
355 ff_tlog(h->avctx, "pred_8x16: (%2d %2d %2d) at %2d %2d %d list %d\n",
356 diagonal_ref, C[0], C[1], sl->mb_x, sl->mb_y, n, list);
357
358
2/2
✓ Branch 0 taken 392234 times.
✓ Branch 1 taken 266995 times.
659229 if (diagonal_ref == ref) {
359 392234 *mx = C[0];
360 392234 *my = C[1];
361 392234 return;
362 }
363 }
364
365 //RARE
366 501189 pred_motion(h, sl, n, 2, list, ref, mx, my);
367 }
368
369 #define FIX_MV_MBAFF(type, refn, mvn, idx) \
370 if (FRAME_MBAFF(h)) { \
371 if (MB_FIELD(sl)) { \
372 if (!IS_INTERLACED(type)) { \
373 refn <<= 1; \
374 AV_COPY32(mvbuf[idx], mvn); \
375 mvbuf[idx][1] /= 2; \
376 mvn = mvbuf[idx]; \
377 } \
378 } else { \
379 if (IS_INTERLACED(type)) { \
380 refn >>= 1; \
381 AV_COPY32(mvbuf[idx], mvn); \
382 mvbuf[idx][1] *= 2; \
383 mvn = mvbuf[idx]; \
384 } \
385 } \
386 }
387
388 1954215 static av_always_inline void pred_pskip_motion(const H264Context *const h,
389 H264SliceContext *sl)
390 {
391 DECLARE_ALIGNED(4, static const int16_t, zeromv)[2] = { 0 };
392 DECLARE_ALIGNED(4, int16_t, mvbuf)[3][2];
393 1954215 int8_t *ref = h->cur_pic.ref_index[0];
394 1954215 int16_t(*mv)[2] = h->cur_pic.motion_val[0];
395 int top_ref, left_ref, diagonal_ref, match_count, mx, my;
396 const int16_t *A, *B, *C;
397 1954215 int b_stride = h->b_stride;
398
399 1954215 fill_rectangle(&sl->ref_cache[0][scan8[0]], 4, 4, 8, 0, 1);
400
401 /* To avoid doing an entire fill_decode_caches, we inline the relevant
402 * parts here.
403 * FIXME: this is a partial duplicate of the logic in fill_decode_caches,
404 * but it's faster this way. Is there a way to avoid this duplication?
405 */
406
2/2
✓ Branch 0 taken 1850653 times.
✓ Branch 1 taken 103562 times.
1954215 if (USES_LIST(sl->left_type[LTOP], 0)) {
407 1850653 left_ref = ref[4 * sl->left_mb_xy[LTOP] + 1 + (sl->left_block[0] & ~1)];
408 1850653 A = mv[h->mb2b_xy[sl->left_mb_xy[LTOP]] + 3 + b_stride * sl->left_block[0]];
409
8/8
✓ Branch 0 taken 45630 times.
✓ Branch 1 taken 1805023 times.
✓ Branch 2 taken 7113 times.
✓ Branch 3 taken 38517 times.
✓ Branch 4 taken 1136 times.
✓ Branch 5 taken 5977 times.
✓ Branch 6 taken 1812 times.
✓ Branch 7 taken 36705 times.
1850653 FIX_MV_MBAFF(sl->left_type[LTOP], left_ref, A, 0);
410
2/2
✓ Branch 0 taken 1478607 times.
✓ Branch 1 taken 372046 times.
1850653 if (!(left_ref | AV_RN32A(A)))
411 1478607 goto zeromv;
412
2/2
✓ Branch 0 taken 41594 times.
✓ Branch 1 taken 61968 times.
103562 } else if (sl->left_type[LTOP]) {
413 41594 left_ref = LIST_NOT_USED;
414 41594 A = zeromv;
415 } else {
416 61968 goto zeromv;
417 }
418
419
2/2
✓ Branch 0 taken 380002 times.
✓ Branch 1 taken 33638 times.
413640 if (USES_LIST(sl->top_type, 0)) {
420 380002 top_ref = ref[4 * sl->top_mb_xy + 2];
421 380002 B = mv[h->mb2b_xy[sl->top_mb_xy] + 3 * b_stride];
422
8/8
✓ Branch 0 taken 20121 times.
✓ Branch 1 taken 359881 times.
✓ Branch 2 taken 2277 times.
✓ Branch 3 taken 17844 times.
✓ Branch 4 taken 1243 times.
✓ Branch 5 taken 1034 times.
✓ Branch 6 taken 1009 times.
✓ Branch 7 taken 16835 times.
380002 FIX_MV_MBAFF(sl->top_type, top_ref, B, 1);
423
2/2
✓ Branch 0 taken 68745 times.
✓ Branch 1 taken 311257 times.
380002 if (!(top_ref | AV_RN32A(B)))
424 68745 goto zeromv;
425
2/2
✓ Branch 0 taken 22271 times.
✓ Branch 1 taken 11367 times.
33638 } else if (sl->top_type) {
426 22271 top_ref = LIST_NOT_USED;
427 22271 B = zeromv;
428 } else {
429 11367 goto zeromv;
430 }
431
432 ff_tlog(h->avctx, "pred_pskip: (%d) (%d) at %2d %2d\n",
433 top_ref, left_ref, sl->mb_x, sl->mb_y);
434
435
2/2
✓ Branch 0 taken 287938 times.
✓ Branch 1 taken 45590 times.
333528 if (USES_LIST(sl->topright_type, 0)) {
436 287938 diagonal_ref = ref[4 * sl->topright_mb_xy + 2];
437 287938 C = mv[h->mb2b_xy[sl->topright_mb_xy] + 3 * b_stride];
438
8/8
✓ Branch 0 taken 8116 times.
✓ Branch 1 taken 279822 times.
✓ Branch 2 taken 1882 times.
✓ Branch 3 taken 6234 times.
✓ Branch 4 taken 908 times.
✓ Branch 5 taken 974 times.
✓ Branch 6 taken 835 times.
✓ Branch 7 taken 5399 times.
287938 FIX_MV_MBAFF(sl->topright_type, diagonal_ref, C, 2);
439
2/2
✓ Branch 0 taken 21885 times.
✓ Branch 1 taken 23705 times.
45590 } else if (sl->topright_type) {
440 21885 diagonal_ref = LIST_NOT_USED;
441 21885 C = zeromv;
442 } else {
443
2/2
✓ Branch 0 taken 22519 times.
✓ Branch 1 taken 1186 times.
23705 if (USES_LIST(sl->topleft_type, 0)) {
444 22519 diagonal_ref = ref[4 * sl->topleft_mb_xy + 1 +
445 22519 (sl->topleft_partition & 2)];
446 22519 C = mv[h->mb2b_xy[sl->topleft_mb_xy] + 3 + b_stride +
447 22519 (sl->topleft_partition & 2 * b_stride)];
448
8/8
✓ Branch 0 taken 9102 times.
✓ Branch 1 taken 13417 times.
✓ Branch 2 taken 53 times.
✓ Branch 3 taken 9049 times.
✓ Branch 4 taken 9 times.
✓ Branch 5 taken 44 times.
✓ Branch 6 taken 478 times.
✓ Branch 7 taken 8571 times.
22519 FIX_MV_MBAFF(sl->topleft_type, diagonal_ref, C, 2);
449
1/2
✓ Branch 0 taken 1186 times.
✗ Branch 1 not taken.
1186 } else if (sl->topleft_type) {
450 1186 diagonal_ref = LIST_NOT_USED;
451 1186 C = zeromv;
452 } else {
453 ✗ diagonal_ref = PART_NOT_AVAILABLE;
454 ✗ C = zeromv;
455 }
456 }
457
458 333528 match_count = !diagonal_ref + !top_ref + !left_ref;
459 ff_tlog(h->avctx, "pred_pskip_motion match_count=%d\n", match_count);
460
2/2
✓ Branch 0 taken 288327 times.
✓ Branch 1 taken 45201 times.
333528 if (match_count > 1) {
461 288327 mx = mid_pred(A[0], B[0], C[0]);
462 288327 my = mid_pred(A[1], B[1], C[1]);
463
2/2
✓ Branch 0 taken 38567 times.
✓ Branch 1 taken 6634 times.
45201 } else if (match_count == 1) {
464
2/2
✓ Branch 0 taken 18612 times.
✓ Branch 1 taken 19955 times.
38567 if (!left_ref) {
465 18612 mx = A[0];
466 18612 my = A[1];
467
2/2
✓ Branch 0 taken 8573 times.
✓ Branch 1 taken 11382 times.
19955 } else if (!top_ref) {
468 8573 mx = B[0];
469 8573 my = B[1];
470 } else {
471 11382 mx = C[0];
472 11382 my = C[1];
473 }
474 } else {
475 6634 mx = mid_pred(A[0], B[0], C[0]);
476 6634 my = mid_pred(A[1], B[1], C[1]);
477 }
478
479 333528 fill_rectangle(sl->mv_cache[0][scan8[0]], 4, 4, 8, pack16to32(mx, my), 4);
480 333528 return;
481
482 1620687 zeromv:
483 1620687 fill_rectangle(sl->mv_cache[0][scan8[0]], 4, 4, 8, 0, 4);
484 1620687 return;
485 }
486
487 15604309 static void fill_decode_neighbors(const H264Context *h, H264SliceContext *sl, int mb_type)
488 {
489 15604309 const int mb_xy = sl->mb_xy;
490 int topleft_xy, top_xy, topright_xy, left_xy[LEFT_MBS];
491 static const uint8_t left_block_options[4][32] = {
492 { 0, 1, 2, 3, 7, 10, 8, 11, 3 + 0 * 4, 3 + 1 * 4, 3 + 2 * 4, 3 + 3 * 4, 1 + 4 * 4, 1 + 8 * 4, 1 + 5 * 4, 1 + 9 * 4 },
493 { 2, 2, 3, 3, 8, 11, 8, 11, 3 + 2 * 4, 3 + 2 * 4, 3 + 3 * 4, 3 + 3 * 4, 1 + 5 * 4, 1 + 9 * 4, 1 + 5 * 4, 1 + 9 * 4 },
494 { 0, 0, 1, 1, 7, 10, 7, 10, 3 + 0 * 4, 3 + 0 * 4, 3 + 1 * 4, 3 + 1 * 4, 1 + 4 * 4, 1 + 8 * 4, 1 + 4 * 4, 1 + 8 * 4 },
495 { 0, 2, 0, 2, 7, 10, 7, 10, 3 + 0 * 4, 3 + 2 * 4, 3 + 0 * 4, 3 + 2 * 4, 1 + 4 * 4, 1 + 8 * 4, 1 + 4 * 4, 1 + 8 * 4 }
496 };
497
498 15604309 sl->topleft_partition = -1;
499
500 15604309 top_xy = mb_xy - (h->mb_stride << MB_FIELD(sl));
501
502 /* Wow, what a mess, why didn't they simplify the interlacing & intra
503 * stuff, I can't imagine that these complex rules are worth it. */
504
505 15604309 topleft_xy = top_xy - 1;
506 15604309 topright_xy = top_xy + 1;
507 15604309 left_xy[LBOT] = left_xy[LTOP] = mb_xy - 1;
508 15604309 sl->left_block = left_block_options[0];
509
2/2
✓ Branch 0 taken 2306671 times.
✓ Branch 1 taken 13297638 times.
15604309 if (FRAME_MBAFF(h)) {
510 2306671 const int left_mb_field_flag = IS_INTERLACED(h->cur_pic.mb_type[mb_xy - 1]);
511 2306671 const int curr_mb_field_flag = IS_INTERLACED(mb_type);
512
2/2
✓ Branch 0 taken 1153229 times.
✓ Branch 1 taken 1153442 times.
2306671 if (sl->mb_y & 1) {
513
2/2
✓ Branch 0 taken 263872 times.
✓ Branch 1 taken 889357 times.
1153229 if (left_mb_field_flag != curr_mb_field_flag) {
514 263872 left_xy[LBOT] = left_xy[LTOP] = mb_xy - h->mb_stride - 1;
515
2/2
✓ Branch 0 taken 136062 times.
✓ Branch 1 taken 127810 times.
263872 if (curr_mb_field_flag) {
516 136062 left_xy[LBOT] += h->mb_stride;
517 136062 sl->left_block = left_block_options[3];
518 } else {
519 127810 topleft_xy += h->mb_stride;
520 /* take top left mv from the middle of the mb, as opposed
521 * to all other modes which use the bottom right partition */
522 127810 sl->topleft_partition = 0;
523 127810 sl->left_block = left_block_options[1];
524 }
525 }
526 } else {
527
2/2
✓ Branch 0 taken 327608 times.
✓ Branch 1 taken 825834 times.
1153442 if (curr_mb_field_flag) {
528 327608 topleft_xy += h->mb_stride & (((h->cur_pic.mb_type[top_xy - 1] >> 7) & 1) - 1);
529 327608 topright_xy += h->mb_stride & (((h->cur_pic.mb_type[top_xy + 1] >> 7) & 1) - 1);
530 327608 top_xy += h->mb_stride & (((h->cur_pic.mb_type[top_xy] >> 7) & 1) - 1);
531 }
532
2/2
✓ Branch 0 taken 264042 times.
✓ Branch 1 taken 889400 times.
1153442 if (left_mb_field_flag != curr_mb_field_flag) {
533
2/2
✓ Branch 0 taken 136032 times.
✓ Branch 1 taken 128010 times.
264042 if (curr_mb_field_flag) {
534 136032 left_xy[LBOT] += h->mb_stride;
535 136032 sl->left_block = left_block_options[3];
536 } else {
537 128010 sl->left_block = left_block_options[2];
538 }
539 }
540 }
541 }
542
543 15604309 sl->topleft_mb_xy = topleft_xy;
544 15604309 sl->top_mb_xy = top_xy;
545 15604309 sl->topright_mb_xy = topright_xy;
546 15604309 sl->left_mb_xy[LTOP] = left_xy[LTOP];
547 15604309 sl->left_mb_xy[LBOT] = left_xy[LBOT];
548 //FIXME do we need all in the context?
549
550 15604309 sl->topleft_type = h->cur_pic.mb_type[topleft_xy];
551 15604309 sl->top_type = h->cur_pic.mb_type[top_xy];
552 15604309 sl->topright_type = h->cur_pic.mb_type[topright_xy];
553 15604309 sl->left_type[LTOP] = h->cur_pic.mb_type[left_xy[LTOP]];
554 15604309 sl->left_type[LBOT] = h->cur_pic.mb_type[left_xy[LBOT]];
555
556 if (FMO) {
557 if (h->slice_table[topleft_xy] != sl->slice_num)
558 sl->topleft_type = 0;
559 if (h->slice_table[top_xy] != sl->slice_num)
560 sl->top_type = 0;
561 if (h->slice_table[left_xy[LTOP]] != sl->slice_num)
562 sl->left_type[LTOP] = sl->left_type[LBOT] = 0;
563 } else {
564
2/2
✓ Branch 0 taken 1591591 times.
✓ Branch 1 taken 14012718 times.
15604309 if (h->slice_table[topleft_xy] != sl->slice_num) {
565 1591591 sl->topleft_type = 0;
566
2/2
✓ Branch 0 taken 1194224 times.
✓ Branch 1 taken 397367 times.
1591591 if (h->slice_table[top_xy] != sl->slice_num)
567 1194224 sl->top_type = 0;
568
2/2
✓ Branch 0 taken 435853 times.
✓ Branch 1 taken 1155738 times.
1591591 if (h->slice_table[left_xy[LTOP]] != sl->slice_num)
569 435853 sl->left_type[LTOP] = sl->left_type[LBOT] = 0;
570 }
571 }
572
2/2
✓ Branch 0 taken 2393999 times.
✓ Branch 1 taken 13210310 times.
15604309 if (h->slice_table[topright_xy] != sl->slice_num)
573 2393999 sl->topright_type = 0;
574 15604309 }
575
576 13644435 static void fill_decode_caches(const H264Context *h, H264SliceContext *sl, int mb_type)
577 {
578 int topleft_xy, top_xy, topright_xy, left_xy[LEFT_MBS];
579 int topleft_type, top_type, topright_type, left_type[LEFT_MBS];
580 13644435 const uint8_t *left_block = sl->left_block;
581 int i;
582 uint8_t *nnz;
583 uint8_t *nnz_cache;
584
585 13644435 topleft_xy = sl->topleft_mb_xy;
586 13644435 top_xy = sl->top_mb_xy;
587 13644435 topright_xy = sl->topright_mb_xy;
588 13644435 left_xy[LTOP] = sl->left_mb_xy[LTOP];
589 13644435 left_xy[LBOT] = sl->left_mb_xy[LBOT];
590 13644435 topleft_type = sl->topleft_type;
591 13644435 top_type = sl->top_type;
592 13644435 topright_type = sl->topright_type;
593 13644435 left_type[LTOP] = sl->left_type[LTOP];
594 13644435 left_type[LBOT] = sl->left_type[LBOT];
595
596
2/2
✓ Branch 0 taken 11187368 times.
✓ Branch 1 taken 2457067 times.
13644435 if (!IS_SKIP(mb_type)) {
597
2/2
✓ Branch 0 taken 4234229 times.
✓ Branch 1 taken 6953139 times.
11187368 if (IS_INTRA(mb_type)) {
598
2/2
✓ Branch 0 taken 10368 times.
✓ Branch 1 taken 4223861 times.
4234229 int type_mask = h->ps.pps->constrained_intra_pred ? IS_INTRA(-1) : -1;
599 4234229 sl->topleft_samples_available =
600 4234229 sl->top_samples_available =
601 4234229 sl->left_samples_available = 0xFFFF;
602 4234229 sl->topright_samples_available = 0xEEEA;
603
604
2/2
✓ Branch 0 taken 309936 times.
✓ Branch 1 taken 3924293 times.
4234229 if (!(top_type & type_mask)) {
605 309936 sl->topleft_samples_available = 0xB3FF;
606 309936 sl->top_samples_available = 0x33FF;
607 309936 sl->topright_samples_available = 0x26EA;
608 }
609
2/2
✓ Branch 0 taken 219817 times.
✓ Branch 1 taken 4014412 times.
4234229 if (IS_INTERLACED(mb_type) != IS_INTERLACED(left_type[LTOP])) {
610
2/2
✓ Branch 0 taken 114372 times.
✓ Branch 1 taken 105445 times.
219817 if (IS_INTERLACED(mb_type)) {
611
2/2
✓ Branch 0 taken 16799 times.
✓ Branch 1 taken 97573 times.
114372 if (!(left_type[LTOP] & type_mask)) {
612 16799 sl->topleft_samples_available &= 0xDFFF;
613 16799 sl->left_samples_available &= 0x5FFF;
614 }
615
2/2
✓ Branch 0 taken 16807 times.
✓ Branch 1 taken 97565 times.
114372 if (!(left_type[LBOT] & type_mask)) {
616 16807 sl->topleft_samples_available &= 0xFF5F;
617 16807 sl->left_samples_available &= 0xFF5F;
618 }
619 } else {
620 105445 int left_typei = h->cur_pic.mb_type[left_xy[LTOP] + h->mb_stride];
621
622 av_assert2(left_xy[LTOP] == left_xy[LBOT]);
623
4/4
✓ Branch 0 taken 105384 times.
✓ Branch 1 taken 61 times.
✓ Branch 2 taken 11 times.
✓ Branch 3 taken 105373 times.
105445 if (!((left_typei & type_mask) && (left_type[LTOP] & type_mask))) {
624 72 sl->topleft_samples_available &= 0xDF5F;
625 72 sl->left_samples_available &= 0x5F5F;
626 }
627 }
628 } else {
629
2/2
✓ Branch 0 taken 70906 times.
✓ Branch 1 taken 3943506 times.
4014412 if (!(left_type[LTOP] & type_mask)) {
630 70906 sl->topleft_samples_available &= 0xDF5F;
631 70906 sl->left_samples_available &= 0x5F5F;
632 }
633 }
634
635
2/2
✓ Branch 0 taken 387654 times.
✓ Branch 1 taken 3846575 times.
4234229 if (!(topleft_type & type_mask))
636 387654 sl->topleft_samples_available &= 0x7FFF;
637
638
2/2
✓ Branch 0 taken 784643 times.
✓ Branch 1 taken 3449586 times.
4234229 if (!(topright_type & type_mask))
639 784643 sl->topright_samples_available &= 0xFBFF;
640
641
2/2
✓ Branch 0 taken 3115343 times.
✓ Branch 1 taken 1118886 times.
4234229 if (IS_INTRA4x4(mb_type)) {
642
2/2
✓ Branch 0 taken 2333651 times.
✓ Branch 1 taken 781692 times.
3115343 if (IS_INTRA4x4(top_type)) {
643 2333651 AV_COPY32(sl->intra4x4_pred_mode_cache + 4 + 8 * 0, sl->intra4x4_pred_mode + h->mb2br_xy[top_xy]);
644 } else {
645 781692 sl->intra4x4_pred_mode_cache[4 + 8 * 0] =
646 781692 sl->intra4x4_pred_mode_cache[5 + 8 * 0] =
647 781692 sl->intra4x4_pred_mode_cache[6 + 8 * 0] =
648
2/2
✓ Branch 0 taken 217388 times.
✓ Branch 1 taken 564304 times.
781692 sl->intra4x4_pred_mode_cache[7 + 8 * 0] = 2 - 3 * !(top_type & type_mask);
649 }
650
2/2
✓ Branch 0 taken 6230686 times.
✓ Branch 1 taken 3115343 times.
9346029 for (i = 0; i < 2; i++) {
651
2/2
✓ Branch 0 taken 5002992 times.
✓ Branch 1 taken 1227694 times.
6230686 if (IS_INTRA4x4(left_type[LEFT(i)])) {
652 5002992 int8_t *mode = sl->intra4x4_pred_mode + h->mb2br_xy[left_xy[LEFT(i)]];
653 5002992 sl->intra4x4_pred_mode_cache[3 + 8 * 1 + 2 * 8 * i] = mode[6 - left_block[0 + 2 * i]];
654 5002992 sl->intra4x4_pred_mode_cache[3 + 8 * 2 + 2 * 8 * i] = mode[6 - left_block[1 + 2 * i]];
655 } else {
656 1227694 sl->intra4x4_pred_mode_cache[3 + 8 * 1 + 2 * 8 * i] =
657
2/2
✓ Branch 0 taken 131730 times.
✓ Branch 1 taken 1095964 times.
1227694 sl->intra4x4_pred_mode_cache[3 + 8 * 2 + 2 * 8 * i] = 2 - 3 * !(left_type[LEFT(i)] & type_mask);
658 }
659 }
660 }
661 }
662
663 /*
664 * 0 . T T. T T T T
665 * 1 L . .L . . . .
666 * 2 L . .L . . . .
667 * 3 . T TL . . . .
668 * 4 L . .L . . . .
669 * 5 L . .. . . . .
670 */
671 /* 9.2.1: with data partitioning and constrained intra prediction, an
672 * inter neighbour must not contribute to nC for an intra macroblock.
673 * Step 7 would drop it from the (nA + nB + 1) >> 1 average entirely,
674 * but JM's predict_nnz() counts it as present with zero coefficients.
675 * FF_BUG_H264_DP_NNZ picks JM, and is autodetected in h264dec.c. */
676 11187368 int nnz_mask = -1;
677 11187368 int nnz_excluded = 64; // 64: unavailable, 0: present but empty
678
679
4/4
✓ Branch 0 taken 4798 times.
✓ Branch 1 taken 11182570 times.
✓ Branch 2 taken 1828 times.
✓ Branch 3 taken 2970 times.
11187368 if (sl->data_partitioning && h->ps.pps->constrained_intra_pred &&
680
2/2
✓ Branch 0 taken 380 times.
✓ Branch 1 taken 1448 times.
1828 IS_INTRA(mb_type)) {
681 380 nnz_mask = IS_INTRA(-1);
682
2/2
✓ Branch 0 taken 298 times.
✓ Branch 1 taken 82 times.
380 if (h->workaround_bugs & FF_BUG_H264_DP_NNZ)
683 298 nnz_excluded = 0;
684 }
685
686 11187368 nnz_cache = sl->non_zero_count_cache;
687
2/2
✓ Branch 0 taken 10288935 times.
✓ Branch 1 taken 898433 times.
11187368 if (top_type & nnz_mask) {
688 10288935 nnz = h->non_zero_count[top_xy];
689 10288935 AV_COPY32(&nnz_cache[4 + 8 * 0], &nnz[4 * 3]);
690
2/2
✓ Branch 0 taken 914779 times.
✓ Branch 1 taken 9374156 times.
10288935 if (!h->chroma_y_shift) {
691 914779 AV_COPY32(&nnz_cache[4 + 8 * 5], &nnz[4 * 7]);
692 914779 AV_COPY32(&nnz_cache[4 + 8 * 10], &nnz[4 * 11]);
693 } else {
694 9374156 AV_COPY32(&nnz_cache[4 + 8 * 5], &nnz[4 * 5]);
695 9374156 AV_COPY32(&nnz_cache[4 + 8 * 10], &nnz[4 * 9]);
696 }
697 } else {
698
2/2
✓ Branch 0 taken 180296 times.
✓ Branch 1 taken 718137 times.
1078546 uint32_t top_empty = CABAC(h) && !IS_INTRA(mb_type) ? 0 :
699
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 180113 times.
180296 top_type ? nnz_excluded * 0x01010101u : 0x40404040;
700 898433 AV_WN32A(&nnz_cache[4 + 8 * 0], top_empty);
701 898433 AV_WN32A(&nnz_cache[4 + 8 * 5], top_empty);
702 898433 AV_WN32A(&nnz_cache[4 + 8 * 10], top_empty);
703 }
704
705
2/2
✓ Branch 0 taken 22374736 times.
✓ Branch 1 taken 11187368 times.
33562104 for (i = 0; i < 2; i++) {
706
2/2
✓ Branch 0 taken 21732214 times.
✓ Branch 1 taken 642522 times.
22374736 if (left_type[LEFT(i)] & nnz_mask) {
707 21732214 nnz = h->non_zero_count[left_xy[LEFT(i)]];
708 21732214 nnz_cache[3 + 8 * 1 + 2 * 8 * i] = nnz[left_block[8 + 0 + 2 * i]];
709 21732214 nnz_cache[3 + 8 * 2 + 2 * 8 * i] = nnz[left_block[8 + 1 + 2 * i]];
710
2/2
✓ Branch 0 taken 295798 times.
✓ Branch 1 taken 21436416 times.
21732214 if (CHROMA444(h)) {
711 295798 nnz_cache[3 + 8 * 6 + 2 * 8 * i] = nnz[left_block[8 + 0 + 2 * i] + 4 * 4];
712 295798 nnz_cache[3 + 8 * 7 + 2 * 8 * i] = nnz[left_block[8 + 1 + 2 * i] + 4 * 4];
713 295798 nnz_cache[3 + 8 * 11 + 2 * 8 * i] = nnz[left_block[8 + 0 + 2 * i] + 8 * 4];
714 295798 nnz_cache[3 + 8 * 12 + 2 * 8 * i] = nnz[left_block[8 + 1 + 2 * i] + 8 * 4];
715
2/2
✓ Branch 0 taken 1635372 times.
✓ Branch 1 taken 19801044 times.
21436416 } else if (CHROMA422(h)) {
716 1635372 nnz_cache[3 + 8 * 6 + 2 * 8 * i] = nnz[left_block[8 + 0 + 2 * i] - 2 + 4 * 4];
717 1635372 nnz_cache[3 + 8 * 7 + 2 * 8 * i] = nnz[left_block[8 + 1 + 2 * i] - 2 + 4 * 4];
718 1635372 nnz_cache[3 + 8 * 11 + 2 * 8 * i] = nnz[left_block[8 + 0 + 2 * i] - 2 + 8 * 4];
719 1635372 nnz_cache[3 + 8 * 12 + 2 * 8 * i] = nnz[left_block[8 + 1 + 2 * i] - 2 + 8 * 4];
720 } else {
721 19801044 nnz_cache[3 + 8 * 6 + 8 * i] = nnz[left_block[8 + 4 + 2 * i]];
722 19801044 nnz_cache[3 + 8 * 11 + 8 * i] = nnz[left_block[8 + 5 + 2 * i]];
723 }
724 } else {
725
2/2
✓ Branch 0 taken 106540 times.
✓ Branch 1 taken 272194 times.
749062 int empty = CABAC(h) && !IS_INTRA(mb_type) ? 0 :
726
2/2
✓ Branch 0 taken 420 times.
✓ Branch 1 taken 369908 times.
370328 left_type[LEFT(i)] ? nnz_excluded : 64;
727 642522 nnz_cache[3 + 8 * 1 + 2 * 8 * i] =
728 642522 nnz_cache[3 + 8 * 2 + 2 * 8 * i] =
729 642522 nnz_cache[3 + 8 * 6 + 2 * 8 * i] =
730 642522 nnz_cache[3 + 8 * 7 + 2 * 8 * i] =
731 642522 nnz_cache[3 + 8 * 11 + 2 * 8 * i] =
732 642522 nnz_cache[3 + 8 * 12 + 2 * 8 * i] = empty;
733 }
734 }
735
736 if (CABAC(h)) {
737 // top_cbp
738
2/2
✓ Branch 0 taken 6912807 times.
✓ Branch 1 taken 516528 times.
7429335 if (top_type)
739 6912807 sl->top_cbp = h->cbp_table[top_xy];
740 else
741
2/2
✓ Branch 0 taken 180113 times.
✓ Branch 1 taken 336415 times.
516528 sl->top_cbp = IS_INTRA(mb_type) ? 0x7CF : 0x00F;
742 // left_cbp
743
2/2
✓ Branch 0 taken 7239968 times.
✓ Branch 1 taken 189367 times.
7429335 if (left_type[LTOP]) {
744 7239968 sl->left_cbp = (h->cbp_table[left_xy[LTOP]] & 0x7F0) |
745 7239968 ((h->cbp_table[left_xy[LTOP]] >> (left_block[0] & (~1))) & 2) |
746 7239968 (((h->cbp_table[left_xy[LBOT]] >> (left_block[2] & (~1))) & 2) << 2);
747 } else {
748
2/2
✓ Branch 0 taken 53270 times.
✓ Branch 1 taken 136097 times.
189367 sl->left_cbp = IS_INTRA(mb_type) ? 0x7CF : 0x00F;
749 }
750 }
751 }
752
753
6/6
✓ Branch 0 taken 7343790 times.
✓ Branch 1 taken 6300645 times.
✓ Branch 2 taken 3109561 times.
✓ Branch 3 taken 4234229 times.
✓ Branch 4 taken 3045309 times.
✓ Branch 5 taken 64252 times.
13644435 if (IS_INTER(mb_type) || (IS_DIRECT(mb_type) && sl->direct_spatial_mv_pred)) {
754 int list;
755 9345954 int b_stride = h->b_stride;
756
2/2
✓ Branch 0 taken 14943051 times.
✓ Branch 1 taken 9345954 times.
24289005 for (list = 0; list < sl->list_count; list++) {
757 14943051 int8_t *ref_cache = &sl->ref_cache[list][scan8[0]];
758 14943051 int8_t *ref = h->cur_pic.ref_index[list];
759 14943051 int16_t(*mv_cache)[2] = &sl->mv_cache[list][scan8[0]];
760 14943051 int16_t(*mv)[2] = h->cur_pic.motion_val[list];
761
2/2
✓ Branch 0 taken 1394664 times.
✓ Branch 1 taken 13548387 times.
14943051 if (!USES_LIST(mb_type, list))
762 1394664 continue;
763 av_assert2(!(IS_DIRECT(mb_type) && !sl->direct_spatial_mv_pred));
764
765
2/2
✓ Branch 0 taken 10934574 times.
✓ Branch 1 taken 2613813 times.
13548387 if (USES_LIST(top_type, list)) {
766 10934574 const int b_xy = h->mb2b_xy[top_xy] + 3 * b_stride;
767 10934574 AV_COPY128(mv_cache[0 - 1 * 8], mv[b_xy + 0]);
768 10934574 ref_cache[0 - 1 * 8] =
769 10934574 ref_cache[1 - 1 * 8] = ref[4 * top_xy + 2];
770 10934574 ref_cache[2 - 1 * 8] =
771 10934574 ref_cache[3 - 1 * 8] = ref[4 * top_xy + 3];
772 } else {
773 2613813 AV_ZERO128(mv_cache[0 - 1 * 8]);
774
2/2
✓ Branch 0 taken 1561353 times.
✓ Branch 1 taken 1052460 times.
2613813 AV_WN32A(&ref_cache[0 - 1 * 8],
775 ((top_type ? LIST_NOT_USED : PART_NOT_AVAILABLE) & 0xFF) * 0x01010101u);
776 }
777
778
2/2
✓ Branch 0 taken 2852674 times.
✓ Branch 1 taken 10695713 times.
13548387 if (mb_type & (MB_TYPE_16x8 | MB_TYPE_8x8)) {
779
2/2
✓ Branch 0 taken 5705348 times.
✓ Branch 1 taken 2852674 times.
8558022 for (i = 0; i < 2; i++) {
780 5705348 int cache_idx = -1 + i * 2 * 8;
781
2/2
✓ Branch 0 taken 4883117 times.
✓ Branch 1 taken 822231 times.
5705348 if (USES_LIST(left_type[LEFT(i)], list)) {
782 4883117 const int b_xy = h->mb2b_xy[left_xy[LEFT(i)]] + 3;
783 4883117 const int b8_xy = 4 * left_xy[LEFT(i)] + 1;
784 4883117 AV_COPY32(mv_cache[cache_idx],
785 mv[b_xy + b_stride * left_block[0 + i * 2]]);
786 4883117 AV_COPY32(mv_cache[cache_idx + 8],
787 mv[b_xy + b_stride * left_block[1 + i * 2]]);
788 4883117 ref_cache[cache_idx] = ref[b8_xy + (left_block[0 + i * 2] & ~1)];
789 4883117 ref_cache[cache_idx + 8] = ref[b8_xy + (left_block[1 + i * 2] & ~1)];
790 } else {
791 822231 AV_ZERO32(mv_cache[cache_idx]);
792 822231 AV_ZERO32(mv_cache[cache_idx + 8]);
793 822231 ref_cache[cache_idx] =
794
2/2
✓ Branch 0 taken 586515 times.
✓ Branch 1 taken 235716 times.
822231 ref_cache[cache_idx + 8] = (left_type[LEFT(i)]) ? LIST_NOT_USED
795 : PART_NOT_AVAILABLE;
796 }
797 }
798 } else {
799
2/2
✓ Branch 0 taken 9180514 times.
✓ Branch 1 taken 1515199 times.
10695713 if (USES_LIST(left_type[LTOP], list)) {
800 9180514 const int b_xy = h->mb2b_xy[left_xy[LTOP]] + 3;
801 9180514 const int b8_xy = 4 * left_xy[LTOP] + 1;
802 9180514 AV_COPY32(mv_cache[-1], mv[b_xy + b_stride * left_block[0]]);
803 9180514 ref_cache[-1] = ref[b8_xy + (left_block[0] & ~1)];
804 } else {
805 1515199 AV_ZERO32(mv_cache[-1]);
806
2/2
✓ Branch 0 taken 1238778 times.
✓ Branch 1 taken 276421 times.
1515199 ref_cache[-1] = left_type[LTOP] ? LIST_NOT_USED
807 : PART_NOT_AVAILABLE;
808 }
809 }
810
811
2/2
✓ Branch 0 taken 10066690 times.
✓ Branch 1 taken 3481697 times.
13548387 if (USES_LIST(topright_type, list)) {
812 10066690 const int b_xy = h->mb2b_xy[topright_xy] + 3 * b_stride;
813 10066690 AV_COPY32(mv_cache[4 - 1 * 8], mv[b_xy]);
814 10066690 ref_cache[4 - 1 * 8] = ref[4 * topright_xy + 2];
815 } else {
816 3481697 AV_ZERO32(mv_cache[4 - 1 * 8]);
817
2/2
✓ Branch 0 taken 1511096 times.
✓ Branch 1 taken 1970601 times.
3481697 ref_cache[4 - 1 * 8] = topright_type ? LIST_NOT_USED
818 : PART_NOT_AVAILABLE;
819 }
820
4/4
✓ Branch 0 taken 10732231 times.
✓ Branch 1 taken 2816156 times.
✓ Branch 2 taken 1395750 times.
✓ Branch 3 taken 9336481 times.
13548387 if(ref_cache[2 - 1*8] < 0 || ref_cache[4 - 1 * 8] < 0) {
821
2/2
✓ Branch 0 taken 1888697 times.
✓ Branch 1 taken 2323209 times.
4211906 if (USES_LIST(topleft_type, list)) {
822 1888697 const int b_xy = h->mb2b_xy[topleft_xy] + 3 + b_stride +
823 1888697 (sl->topleft_partition & 2 * b_stride);
824 1888697 const int b8_xy = 4 * topleft_xy + 1 + (sl->topleft_partition & 2);
825 1888697 AV_COPY32(mv_cache[-1 - 1 * 8], mv[b_xy]);
826 1888697 ref_cache[-1 - 1 * 8] = ref[b8_xy];
827 } else {
828 2323209 AV_ZERO32(mv_cache[-1 - 1 * 8]);
829
2/2
✓ Branch 0 taken 1175408 times.
✓ Branch 1 taken 1147801 times.
2323209 ref_cache[-1 - 1 * 8] = topleft_type ? LIST_NOT_USED
830 : PART_NOT_AVAILABLE;
831 }
832 }
833
834
4/4
✓ Branch 0 taken 6090618 times.
✓ Branch 1 taken 7457769 times.
✓ Branch 2 taken 5449434 times.
✓ Branch 3 taken 641184 times.
13548387 if ((mb_type & (MB_TYPE_SKIP | MB_TYPE_DIRECT2)) && !FRAME_MBAFF(h))
835 5449434 continue;
836
837
2/2
✓ Branch 0 taken 7457769 times.
✓ Branch 1 taken 641184 times.
8098953 if (!(mb_type & (MB_TYPE_SKIP | MB_TYPE_DIRECT2))) {
838 7457769 uint8_t(*mvd_cache)[2] = &sl->mvd_cache[list][scan8[0]];
839 7457769 uint8_t(*mvd)[2] = sl->mvd_table[list];
840 7457769 ref_cache[2 + 8 * 0] =
841 7457769 ref_cache[2 + 8 * 2] = PART_NOT_AVAILABLE;
842 7457769 AV_ZERO32(mv_cache[2 + 8 * 0]);
843 7457769 AV_ZERO32(mv_cache[2 + 8 * 2]);
844
845 if (CABAC(h)) {
846
2/2
✓ Branch 0 taken 4017405 times.
✓ Branch 1 taken 991431 times.
5008836 if (USES_LIST(top_type, list)) {
847 4017405 const int b_xy = h->mb2br_xy[top_xy];
848 4017405 AV_COPY64(mvd_cache[0 - 1 * 8], mvd[b_xy + 0]);
849 } else {
850 991431 AV_ZERO64(mvd_cache[0 - 1 * 8]);
851 }
852
2/2
✓ Branch 0 taken 4242595 times.
✓ Branch 1 taken 766241 times.
5008836 if (USES_LIST(left_type[LTOP], list)) {
853 4242595 const int b_xy = h->mb2br_xy[left_xy[LTOP]] + 6;
854 4242595 AV_COPY16(mvd_cache[-1 + 0 * 8], mvd[b_xy - left_block[0]]);
855 4242595 AV_COPY16(mvd_cache[-1 + 1 * 8], mvd[b_xy - left_block[1]]);
856 } else {
857 766241 AV_ZERO16(mvd_cache[-1 + 0 * 8]);
858 766241 AV_ZERO16(mvd_cache[-1 + 1 * 8]);
859 }
860
2/2
✓ Branch 0 taken 4242070 times.
✓ Branch 1 taken 766766 times.
5008836 if (USES_LIST(left_type[LBOT], list)) {
861 4242070 const int b_xy = h->mb2br_xy[left_xy[LBOT]] + 6;
862 4242070 AV_COPY16(mvd_cache[-1 + 2 * 8], mvd[b_xy - left_block[2]]);
863 4242070 AV_COPY16(mvd_cache[-1 + 3 * 8], mvd[b_xy - left_block[3]]);
864 } else {
865 766766 AV_ZERO16(mvd_cache[-1 + 2 * 8]);
866 766766 AV_ZERO16(mvd_cache[-1 + 3 * 8]);
867 }
868 5008836 AV_ZERO16(mvd_cache[2 + 8 * 0]);
869 5008836 AV_ZERO16(mvd_cache[2 + 8 * 2]);
870
2/2
✓ Branch 0 taken 2749568 times.
✓ Branch 1 taken 2259268 times.
5008836 if (sl->slice_type_nos == AV_PICTURE_TYPE_B) {
871 2749568 uint8_t *direct_cache = &sl->direct_cache[scan8[0]];
872 2749568 uint8_t *direct_table = h->direct_table;
873 2749568 fill_rectangle(direct_cache, 4, 4, 8, MB_TYPE_16x16 >> 1, 1);
874
875
2/2
✓ Branch 0 taken 468928 times.
✓ Branch 1 taken 2280640 times.
2749568 if (IS_DIRECT(top_type)) {
876 468928 AV_WN32A(&direct_cache[-1 * 8],
877 0x01010101u * (MB_TYPE_DIRECT2 >> 1));
878
2/2
✓ Branch 0 taken 617657 times.
✓ Branch 1 taken 1662983 times.
2280640 } else if (IS_8X8(top_type)) {
879 617657 int b8_xy = 4 * top_xy;
880 617657 direct_cache[0 - 1 * 8] = direct_table[b8_xy + 2];
881 617657 direct_cache[2 - 1 * 8] = direct_table[b8_xy + 3];
882 } else {
883 1662983 AV_WN32A(&direct_cache[-1 * 8],
884 0x01010101 * (MB_TYPE_16x16 >> 1));
885 }
886
887
2/2
✓ Branch 0 taken 459333 times.
✓ Branch 1 taken 2290235 times.
2749568 if (IS_DIRECT(left_type[LTOP]))
888 459333 direct_cache[-1 + 0 * 8] = MB_TYPE_DIRECT2 >> 1;
889
2/2
✓ Branch 0 taken 654022 times.
✓ Branch 1 taken 1636213 times.
2290235 else if (IS_8X8(left_type[LTOP]))
890 654022 direct_cache[-1 + 0 * 8] = direct_table[4 * left_xy[LTOP] + 1 + (left_block[0] & ~1)];
891 else
892 1636213 direct_cache[-1 + 0 * 8] = MB_TYPE_16x16 >> 1;
893
894
2/2
✓ Branch 0 taken 458355 times.
✓ Branch 1 taken 2291213 times.
2749568 if (IS_DIRECT(left_type[LBOT]))
895 458355 direct_cache[-1 + 2 * 8] = MB_TYPE_DIRECT2 >> 1;
896
2/2
✓ Branch 0 taken 656190 times.
✓ Branch 1 taken 1635023 times.
2291213 else if (IS_8X8(left_type[LBOT]))
897 656190 direct_cache[-1 + 2 * 8] = direct_table[4 * left_xy[LBOT] + 1 + (left_block[2] & ~1)];
898 else
899 1635023 direct_cache[-1 + 2 * 8] = MB_TYPE_16x16 >> 1;
900 }
901 }
902 }
903
904 #define MAP_MVS \
905 MAP_F2F(scan8[0] - 1 - 1 * 8, topleft_type) \
906 MAP_F2F(scan8[0] + 0 - 1 * 8, top_type) \
907 MAP_F2F(scan8[0] + 1 - 1 * 8, top_type) \
908 MAP_F2F(scan8[0] + 2 - 1 * 8, top_type) \
909 MAP_F2F(scan8[0] + 3 - 1 * 8, top_type) \
910 MAP_F2F(scan8[0] + 4 - 1 * 8, topright_type) \
911 MAP_F2F(scan8[0] - 1 + 0 * 8, left_type[LTOP]) \
912 MAP_F2F(scan8[0] - 1 + 1 * 8, left_type[LTOP]) \
913 MAP_F2F(scan8[0] - 1 + 2 * 8, left_type[LBOT]) \
914 MAP_F2F(scan8[0] - 1 + 3 * 8, left_type[LBOT])
915
916
2/2
✓ Branch 0 taken 1797798 times.
✓ Branch 1 taken 6301155 times.
8098953 if (FRAME_MBAFF(h)) {
917
2/2
✓ Branch 0 taken 593355 times.
✓ Branch 1 taken 1204443 times.
1797798 if (MB_FIELD(sl)) {
918
919 #define MAP_F2F(idx, mb_type) \
920 if (!IS_INTERLACED(mb_type) && sl->ref_cache[list][idx] >= 0) { \
921 sl->ref_cache[list][idx] *= 2; \
922 sl->mv_cache[list][idx][1] /= 2; \
923 sl->mvd_cache[list][idx][1] >>= 1; \
924 }
925
926
40/40
✓ Branch 0 taken 332670 times.
✓ Branch 1 taken 260685 times.
✓ Branch 2 taken 173128 times.
✓ Branch 3 taken 159542 times.
✓ Branch 4 taken 308069 times.
✓ Branch 5 taken 285286 times.
✓ Branch 6 taken 170899 times.
✓ Branch 7 taken 137170 times.
✓ Branch 8 taken 308069 times.
✓ Branch 9 taken 285286 times.
✓ Branch 10 taken 170899 times.
✓ Branch 11 taken 137170 times.
✓ Branch 12 taken 308069 times.
✓ Branch 13 taken 285286 times.
✓ Branch 14 taken 170932 times.
✓ Branch 15 taken 137137 times.
✓ Branch 16 taken 308069 times.
✓ Branch 17 taken 285286 times.
✓ Branch 18 taken 170932 times.
✓ Branch 19 taken 137137 times.
✓ Branch 20 taken 332601 times.
✓ Branch 21 taken 260754 times.
✓ Branch 22 taken 178849 times.
✓ Branch 23 taken 153752 times.
✓ Branch 24 taken 248011 times.
✓ Branch 25 taken 345344 times.
✓ Branch 26 taken 169958 times.
✓ Branch 27 taken 78053 times.
✓ Branch 28 taken 248011 times.
✓ Branch 29 taken 345344 times.
✓ Branch 30 taken 159851 times.
✓ Branch 31 taken 88160 times.
✓ Branch 32 taken 248011 times.
✓ Branch 33 taken 345344 times.
✓ Branch 34 taken 159632 times.
✓ Branch 35 taken 88379 times.
✓ Branch 36 taken 248011 times.
✓ Branch 37 taken 345344 times.
✓ Branch 38 taken 159638 times.
✓ Branch 39 taken 88373 times.
593355 MAP_MVS
927 } else {
928
929 #undef MAP_F2F
930 #define MAP_F2F(idx, mb_type) \
931 if (IS_INTERLACED(mb_type) && sl->ref_cache[list][idx] >= 0) { \
932 sl->ref_cache[list][idx] >>= 1; \
933 sl->mv_cache[list][idx][1] *= 2; \
934 sl->mvd_cache[list][idx][1] <<= 1; \
935 }
936
937
40/40
✓ Branch 0 taken 211670 times.
✓ Branch 1 taken 992773 times.
✓ Branch 2 taken 157172 times.
✓ Branch 3 taken 54498 times.
✓ Branch 4 taken 100047 times.
✓ Branch 5 taken 1104396 times.
✓ Branch 6 taken 77264 times.
✓ Branch 7 taken 22783 times.
✓ Branch 8 taken 100047 times.
✓ Branch 9 taken 1104396 times.
✓ Branch 10 taken 77264 times.
✓ Branch 11 taken 22783 times.
✓ Branch 12 taken 100047 times.
✓ Branch 13 taken 1104396 times.
✓ Branch 14 taken 77329 times.
✓ Branch 15 taken 22718 times.
✓ Branch 16 taken 100047 times.
✓ Branch 17 taken 1104396 times.
✓ Branch 18 taken 77329 times.
✓ Branch 19 taken 22718 times.
✓ Branch 20 taken 104691 times.
✓ Branch 21 taken 1099752 times.
✓ Branch 22 taken 81676 times.
✓ Branch 23 taken 23015 times.
✓ Branch 24 taken 213148 times.
✓ Branch 25 taken 991295 times.
✓ Branch 26 taken 165497 times.
✓ Branch 27 taken 47651 times.
✓ Branch 28 taken 213148 times.
✓ Branch 29 taken 991295 times.
✓ Branch 30 taken 146044 times.
✓ Branch 31 taken 67104 times.
✓ Branch 32 taken 213148 times.
✓ Branch 33 taken 991295 times.
✓ Branch 34 taken 146010 times.
✓ Branch 35 taken 67138 times.
✓ Branch 36 taken 213148 times.
✓ Branch 37 taken 991295 times.
✓ Branch 38 taken 145879 times.
✓ Branch 39 taken 67269 times.
1204443 MAP_MVS
938 #undef MAP_F2F
939 }
940 }
941 }
942 }
943
944 13644435 sl->neighbor_transform_size = !!IS_8x8DCT(top_type) + !!IS_8x8DCT(left_type[LTOP]);
945 13644435 }
946
947 /**
948 * decodes a P_SKIP or B_SKIP macroblock
949 */
950 4547801 av_unused static void decode_mb_skip(const H264Context *h, H264SliceContext *sl)
951 {
952 4547801 const int mb_xy = sl->mb_xy;
953 4547801 int mb_type = 0;
954
955 4547801 memset(h->non_zero_count[mb_xy], 0, 48);
956
957
2/2
✓ Branch 0 taken 1561190 times.
✓ Branch 1 taken 2986611 times.
4547801 if (MB_FIELD(sl))
958 1561190 mb_type |= MB_TYPE_INTERLACED;
959
960
2/2
✓ Branch 0 taken 2593586 times.
✓ Branch 1 taken 1954215 times.
4547801 if (sl->slice_type_nos == AV_PICTURE_TYPE_B) {
961 // just for fill_caches. pred_direct_motion will set the real mb_type
962 2593586 mb_type |= MB_TYPE_L0L1 | MB_TYPE_DIRECT2 | MB_TYPE_SKIP;
963
2/2
✓ Branch 0 taken 2457067 times.
✓ Branch 1 taken 136519 times.
2593586 if (sl->direct_spatial_mv_pred) {
964 2457067 fill_decode_neighbors(h, sl, mb_type);
965 2457067 fill_decode_caches(h, sl, mb_type); //FIXME check what is needed and what not ...
966 }
967 2593586 ff_h264_pred_direct_motion(h, sl, &mb_type);
968 2593586 mb_type |= MB_TYPE_SKIP;
969 } else {
970 1954215 mb_type |= MB_TYPE_16x16 | MB_TYPE_P0L0 | MB_TYPE_P1L0 | MB_TYPE_SKIP;
971
972 1954215 fill_decode_neighbors(h, sl, mb_type);
973 1954215 pred_pskip_motion(h, sl);
974 }
975
976 4547801 write_back_motion(h, sl, mb_type);
977 4547801 h->cur_pic.mb_type[mb_xy] = mb_type;
978 4547801 h->cur_pic.qscale_table[mb_xy] = sl->qscale;
979 4547801 h->slice_table[mb_xy] = sl->slice_num;
980 4547801 sl->prev_mb_skipped = 1;
981 4547801 }
982
983 #endif /* AVCODEC_H264_MVPRED_H */
984