Directory: | ../../../ffmpeg/ |
---|---|
File: | src/libavcodec/h264_mvpred.h |
Date: | 2022-07-05 19:52:29 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 413 | 415 | 99.5% |
Branches: | 347 | 348 | 99.7% |
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 "libavutil/avassert.h" | ||
34 | #include "libavutil/mem_internal.h" | ||
35 | |||
36 | |||
37 | 17894377 | static av_always_inline int fetch_diagonal_mv(const H264Context *h, H264SliceContext *sl, | |
38 | const int16_t **C, | ||
39 | int i, int list, int part_width) | ||
40 | { | ||
41 | 17894377 | const int topright_ref = sl->ref_cache[list][i - 8 + part_width]; | |
42 | |||
43 | /* there is no consistent mapping of mvs to neighboring locations that will | ||
44 | * make mbaff happy, so we can't move all this logic to fill_caches */ | ||
45 |
2/2✓ Branch 0 taken 2891570 times.
✓ Branch 1 taken 15002807 times.
|
17894377 | if (FRAME_MBAFF(h)) { |
46 | #define SET_DIAG_MV(MV_OP, REF_OP, XY, Y4) \ | ||
47 | const int xy = XY, y4 = Y4; \ | ||
48 | const int mb_type = mb_types[xy + (y4 >> 2) * h->mb_stride]; \ | ||
49 | if (!USES_LIST(mb_type, list)) \ | ||
50 | return LIST_NOT_USED; \ | ||
51 | mv = h->cur_pic_ptr->motion_val[list][h->mb2b_xy[xy] + 3 + y4 * h->b_stride]; \ | ||
52 | sl->mv_cache[list][scan8[0] - 2][0] = mv[0]; \ | ||
53 | sl->mv_cache[list][scan8[0] - 2][1] = mv[1] MV_OP; \ | ||
54 | return h->cur_pic_ptr->ref_index[list][4 * xy + 1 + (y4 & ~1)] REF_OP; | ||
55 | |||
56 |
2/2✓ Branch 0 taken 1265392 times.
✓ Branch 1 taken 1626178 times.
|
2891570 | if (topright_ref == PART_NOT_AVAILABLE |
57 |
4/4✓ Branch 0 taken 802677 times.
✓ Branch 1 taken 462715 times.
✓ Branch 2 taken 196840 times.
✓ Branch 3 taken 605837 times.
|
1265392 | && i >= scan8[0] + 8 && (i & 7) == 4 |
58 |
2/2✓ Branch 0 taken 188678 times.
✓ Branch 1 taken 8162 times.
|
196840 | && sl->ref_cache[list][scan8[0] - 1] != PART_NOT_AVAILABLE) { |
59 | 188678 | const uint32_t *mb_types = h->cur_pic_ptr->mb_type; | |
60 | const int16_t *mv; | ||
61 | 188678 | AV_ZERO32(sl->mv_cache[list][scan8[0] - 2]); | |
62 | 188678 | *C = sl->mv_cache[list][scan8[0] - 2]; | |
63 | |||
64 |
4/4✓ Branch 0 taken 92913 times.
✓ Branch 1 taken 95765 times.
✓ Branch 2 taken 26640 times.
✓ Branch 3 taken 66273 times.
|
188678 | if (!MB_FIELD(sl) && IS_INTERLACED(sl->left_type[0])) { |
65 |
2/2✓ Branch 0 taken 2807 times.
✓ Branch 1 taken 23833 times.
|
26640 | SET_DIAG_MV(* 2, >> 1, sl->left_mb_xy[0] + h->mb_stride, |
66 | (sl->mb_y & 1) * 2 + (i >> 5)); | ||
67 | } | ||
68 |
4/4✓ Branch 0 taken 95765 times.
✓ Branch 1 taken 66273 times.
✓ Branch 2 taken 35582 times.
✓ Branch 3 taken 60183 times.
|
162038 | if (MB_FIELD(sl) && !IS_INTERLACED(sl->left_type[0])) { |
69 | // left shift will turn LIST_NOT_USED into PART_NOT_AVAILABLE, but that's OK. | ||
70 |
2/2✓ Branch 0 taken 5558 times.
✓ Branch 1 taken 30024 times.
|
35582 | SET_DIAG_MV(/ 2, *2, sl->left_mb_xy[i >= 36], ((i >> 2)) & 3); |
71 | } | ||
72 | } | ||
73 | #undef SET_DIAG_MV | ||
74 | } | ||
75 | |||
76 |
2/2✓ Branch 0 taken 11286005 times.
✓ Branch 1 taken 6546150 times.
|
17832155 | if (topright_ref != PART_NOT_AVAILABLE) { |
77 | 11286005 | *C = sl->mv_cache[list][i - 8 + part_width]; | |
78 | 11286005 | return topright_ref; | |
79 | } else { | ||
80 | ff_tlog(h->avctx, "topright MV not available\n"); | ||
81 | |||
82 | 6546150 | *C = sl->mv_cache[list][i - 8 - 1]; | |
83 | 6546150 | return sl->ref_cache[list][i - 8 - 1]; | |
84 | } | ||
85 | } | ||
86 | |||
87 | /** | ||
88 | * Get the predicted MV. | ||
89 | * @param n the block index | ||
90 | * @param part_width the width of the partition (4, 8,16) -> (1, 2, 4) | ||
91 | * @param mx the x component of the predicted motion vector | ||
92 | * @param my the y component of the predicted motion vector | ||
93 | */ | ||
94 | 17295192 | static av_always_inline void pred_motion(const H264Context *const h, | |
95 | H264SliceContext *sl, | ||
96 | int n, | ||
97 | int part_width, int list, int ref, | ||
98 | int *const mx, int *const my) | ||
99 | { | ||
100 | 17295192 | const int index8 = scan8[n]; | |
101 | 17295192 | const int top_ref = sl->ref_cache[list][index8 - 8]; | |
102 | 17295192 | const int left_ref = sl->ref_cache[list][index8 - 1]; | |
103 | 17295192 | const int16_t *const A = sl->mv_cache[list][index8 - 1]; | |
104 | 17295192 | const int16_t *const B = sl->mv_cache[list][index8 - 8]; | |
105 | const int16_t *C; | ||
106 | int diagonal_ref, match_count; | ||
107 | |||
108 | av_assert2(part_width == 1 || part_width == 2 || part_width == 4); | ||
109 | |||
110 | /* mv_cache | ||
111 | * B . . A T T T T | ||
112 | * U . . L . . , . | ||
113 | * U . . L . . . . | ||
114 | * U . . L . . , . | ||
115 | * . . . L . . . . | ||
116 | */ | ||
117 | |||
118 | 17295192 | diagonal_ref = fetch_diagonal_mv(h, sl, &C, index8, list, part_width); | |
119 | 17295192 | match_count = (diagonal_ref == ref) + (top_ref == ref) + (left_ref == ref); | |
120 | ff_tlog(h->avctx, "pred_motion match_count=%d\n", match_count); | ||
121 |
2/2✓ Branch 0 taken 12814394 times.
✓ Branch 1 taken 4480798 times.
|
17295192 | if (match_count > 1) { //most common |
122 | 12814394 | *mx = mid_pred(A[0], B[0], C[0]); | |
123 | 12814394 | *my = mid_pred(A[1], B[1], C[1]); | |
124 |
2/2✓ Branch 0 taken 3046707 times.
✓ Branch 1 taken 1434091 times.
|
4480798 | } else if (match_count == 1) { |
125 |
2/2✓ Branch 0 taken 1919942 times.
✓ Branch 1 taken 1126765 times.
|
3046707 | if (left_ref == ref) { |
126 | 1919942 | *mx = A[0]; | |
127 | 1919942 | *my = A[1]; | |
128 |
2/2✓ Branch 0 taken 809888 times.
✓ Branch 1 taken 316877 times.
|
1126765 | } else if (top_ref == ref) { |
129 | 809888 | *mx = B[0]; | |
130 | 809888 | *my = B[1]; | |
131 | } else { | ||
132 | 316877 | *mx = C[0]; | |
133 | 316877 | *my = C[1]; | |
134 | } | ||
135 | } else { | ||
136 |
4/4✓ Branch 0 taken 233708 times.
✓ Branch 1 taken 1200383 times.
✓ Branch 2 taken 233295 times.
✓ Branch 3 taken 413 times.
|
1434091 | if (top_ref == PART_NOT_AVAILABLE && |
137 |
2/2✓ Branch 0 taken 208180 times.
✓ Branch 1 taken 25115 times.
|
233295 | diagonal_ref == PART_NOT_AVAILABLE && |
138 | left_ref != PART_NOT_AVAILABLE) { | ||
139 | 208180 | *mx = A[0]; | |
140 | 208180 | *my = A[1]; | |
141 | } else { | ||
142 | 1225911 | *mx = mid_pred(A[0], B[0], C[0]); | |
143 | 1225911 | *my = mid_pred(A[1], B[1], C[1]); | |
144 | } | ||
145 | } | ||
146 | |||
147 | ff_tlog(h->avctx, | ||
148 | "pred_motion (%2d %2d %2d) (%2d %2d %2d) (%2d %2d %2d) -> (%2d %2d %2d) at %2d %2d %d list %d\n", | ||
149 | top_ref, B[0], B[1], diagonal_ref, C[0], C[1], left_ref, | ||
150 | A[0], A[1], ref, *mx, *my, sl->mb_x, sl->mb_y, n, list); | ||
151 | 17295192 | } | |
152 | |||
153 | /** | ||
154 | * Get the directionally predicted 16x8 MV. | ||
155 | * @param n the block index | ||
156 | * @param mx the x component of the predicted motion vector | ||
157 | * @param my the y component of the predicted motion vector | ||
158 | */ | ||
159 | 1354863 | static av_always_inline void pred_16x8_motion(const H264Context *const h, | |
160 | H264SliceContext *sl, | ||
161 | int n, int list, int ref, | ||
162 | int *const mx, int *const my) | ||
163 | { | ||
164 |
2/2✓ Branch 0 taken 676591 times.
✓ Branch 1 taken 678272 times.
|
1354863 | if (n == 0) { |
165 | 676591 | const int top_ref = sl->ref_cache[list][scan8[0] - 8]; | |
166 | 676591 | const int16_t *const B = sl->mv_cache[list][scan8[0] - 8]; | |
167 | |||
168 | ff_tlog(h->avctx, "pred_16x8: (%2d %2d %2d) at %2d %2d %d list %d\n", | ||
169 | top_ref, B[0], B[1], sl->mb_x, sl->mb_y, n, list); | ||
170 | |||
171 |
2/2✓ Branch 0 taken 385094 times.
✓ Branch 1 taken 291497 times.
|
676591 | if (top_ref == ref) { |
172 | 385094 | *mx = B[0]; | |
173 | 385094 | *my = B[1]; | |
174 | 385094 | return; | |
175 | } | ||
176 | } else { | ||
177 | 678272 | const int left_ref = sl->ref_cache[list][scan8[8] - 1]; | |
178 | 678272 | const int16_t *const A = sl->mv_cache[list][scan8[8] - 1]; | |
179 | |||
180 | ff_tlog(h->avctx, "pred_16x8: (%2d %2d %2d) at %2d %2d %d list %d\n", | ||
181 | left_ref, A[0], A[1], sl->mb_x, sl->mb_y, n, list); | ||
182 | |||
183 |
2/2✓ Branch 0 taken 455794 times.
✓ Branch 1 taken 222478 times.
|
678272 | if (left_ref == ref) { |
184 | 455794 | *mx = A[0]; | |
185 | 455794 | *my = A[1]; | |
186 | 455794 | return; | |
187 | } | ||
188 | } | ||
189 | |||
190 | //RARE | ||
191 | 513975 | pred_motion(h, sl, n, 4, list, ref, mx, my); | |
192 | } | ||
193 | |||
194 | /** | ||
195 | * Get the directionally predicted 8x16 MV. | ||
196 | * @param n the block index | ||
197 | * @param mx the x component of the predicted motion vector | ||
198 | * @param my the y component of the predicted motion vector | ||
199 | */ | ||
200 | 1199687 | static av_always_inline void pred_8x16_motion(const H264Context *const h, | |
201 | H264SliceContext *sl, | ||
202 | int n, int list, int ref, | ||
203 | int *const mx, int *const my) | ||
204 | { | ||
205 |
2/2✓ Branch 0 taken 600502 times.
✓ Branch 1 taken 599185 times.
|
1199687 | if (n == 0) { |
206 | 600502 | const int left_ref = sl->ref_cache[list][scan8[0] - 1]; | |
207 | 600502 | const int16_t *const A = sl->mv_cache[list][scan8[0] - 1]; | |
208 | |||
209 | ff_tlog(h->avctx, "pred_8x16: (%2d %2d %2d) at %2d %2d %d list %d\n", | ||
210 | left_ref, A[0], A[1], sl->mb_x, sl->mb_y, n, list); | ||
211 | |||
212 |
2/2✓ Branch 0 taken 376346 times.
✓ Branch 1 taken 224156 times.
|
600502 | if (left_ref == ref) { |
213 | 376346 | *mx = A[0]; | |
214 | 376346 | *my = A[1]; | |
215 | 376346 | return; | |
216 | } | ||
217 | } else { | ||
218 | const int16_t *C; | ||
219 | int diagonal_ref; | ||
220 | |||
221 | 599185 | diagonal_ref = fetch_diagonal_mv(h, sl, &C, scan8[4], list, 2); | |
222 | |||
223 | ff_tlog(h->avctx, "pred_8x16: (%2d %2d %2d) at %2d %2d %d list %d\n", | ||
224 | diagonal_ref, C[0], C[1], sl->mb_x, sl->mb_y, n, list); | ||
225 | |||
226 |
2/2✓ Branch 0 taken 343555 times.
✓ Branch 1 taken 255630 times.
|
599185 | if (diagonal_ref == ref) { |
227 | 343555 | *mx = C[0]; | |
228 | 343555 | *my = C[1]; | |
229 | 343555 | return; | |
230 | } | ||
231 | } | ||
232 | |||
233 | //RARE | ||
234 | 479786 | pred_motion(h, sl, n, 2, list, ref, mx, my); | |
235 | } | ||
236 | |||
237 | #define FIX_MV_MBAFF(type, refn, mvn, idx) \ | ||
238 | if (FRAME_MBAFF(h)) { \ | ||
239 | if (MB_FIELD(sl)) { \ | ||
240 | if (!IS_INTERLACED(type)) { \ | ||
241 | refn <<= 1; \ | ||
242 | AV_COPY32(mvbuf[idx], mvn); \ | ||
243 | mvbuf[idx][1] /= 2; \ | ||
244 | mvn = mvbuf[idx]; \ | ||
245 | } \ | ||
246 | } else { \ | ||
247 | if (IS_INTERLACED(type)) { \ | ||
248 | refn >>= 1; \ | ||
249 | AV_COPY32(mvbuf[idx], mvn); \ | ||
250 | mvbuf[idx][1] *= 2; \ | ||
251 | mvn = mvbuf[idx]; \ | ||
252 | } \ | ||
253 | } \ | ||
254 | } | ||
255 | |||
256 | 1418210 | static av_always_inline void pred_pskip_motion(const H264Context *const h, | |
257 | H264SliceContext *sl) | ||
258 | { | ||
259 | DECLARE_ALIGNED(4, static const int16_t, zeromv)[2] = { 0 }; | ||
260 | DECLARE_ALIGNED(4, int16_t, mvbuf)[3][2]; | ||
261 | 1418210 | int8_t *ref = h->cur_pic.ref_index[0]; | |
262 | 1418210 | int16_t(*mv)[2] = h->cur_pic.motion_val[0]; | |
263 | int top_ref, left_ref, diagonal_ref, match_count, mx, my; | ||
264 | const int16_t *A, *B, *C; | ||
265 | 1418210 | int b_stride = h->b_stride; | |
266 | |||
267 | 1418210 | fill_rectangle(&sl->ref_cache[0][scan8[0]], 4, 4, 8, 0, 1); | |
268 | |||
269 | /* To avoid doing an entire fill_decode_caches, we inline the relevant | ||
270 | * parts here. | ||
271 | * FIXME: this is a partial duplicate of the logic in fill_decode_caches, | ||
272 | * but it's faster this way. Is there a way to avoid this duplication? | ||
273 | */ | ||
274 |
2/2✓ Branch 0 taken 1339837 times.
✓ Branch 1 taken 78373 times.
|
1418210 | if (USES_LIST(sl->left_type[LTOP], 0)) { |
275 | 1339837 | left_ref = ref[4 * sl->left_mb_xy[LTOP] + 1 + (sl->left_block[0] & ~1)]; | |
276 | 1339837 | A = mv[h->mb2b_xy[sl->left_mb_xy[LTOP]] + 3 + b_stride * sl->left_block[0]]; | |
277 |
8/8✓ Branch 0 taken 39358 times.
✓ Branch 1 taken 1300479 times.
✓ Branch 2 taken 5593 times.
✓ Branch 3 taken 33765 times.
✓ Branch 4 taken 1073 times.
✓ Branch 5 taken 4520 times.
✓ Branch 6 taken 1740 times.
✓ Branch 7 taken 32025 times.
|
1339837 | FIX_MV_MBAFF(sl->left_type[LTOP], left_ref, A, 0); |
278 |
2/2✓ Branch 0 taken 1056766 times.
✓ Branch 1 taken 283071 times.
|
1339837 | if (!(left_ref | AV_RN32A(A))) |
279 | 1056766 | goto zeromv; | |
280 |
2/2✓ Branch 0 taken 31610 times.
✓ Branch 1 taken 46763 times.
|
78373 | } else if (sl->left_type[LTOP]) { |
281 | 31610 | left_ref = LIST_NOT_USED; | |
282 | 31610 | A = zeromv; | |
283 | } else { | ||
284 | 46763 | goto zeromv; | |
285 | } | ||
286 | |||
287 |
2/2✓ Branch 0 taken 285670 times.
✓ Branch 1 taken 29011 times.
|
314681 | if (USES_LIST(sl->top_type, 0)) { |
288 | 285670 | top_ref = ref[4 * sl->top_mb_xy + 2]; | |
289 | 285670 | B = mv[h->mb2b_xy[sl->top_mb_xy] + 3 * b_stride]; | |
290 |
8/8✓ Branch 0 taken 19406 times.
✓ Branch 1 taken 266264 times.
✓ Branch 2 taken 2004 times.
✓ Branch 3 taken 17402 times.
✓ Branch 4 taken 1160 times.
✓ Branch 5 taken 844 times.
✓ Branch 6 taken 951 times.
✓ Branch 7 taken 16451 times.
|
285670 | FIX_MV_MBAFF(sl->top_type, top_ref, B, 1); |
291 |
2/2✓ Branch 0 taken 47154 times.
✓ Branch 1 taken 238516 times.
|
285670 | if (!(top_ref | AV_RN32A(B))) |
292 | 47154 | goto zeromv; | |
293 |
2/2✓ Branch 0 taken 19108 times.
✓ Branch 1 taken 9903 times.
|
29011 | } else if (sl->top_type) { |
294 | 19108 | top_ref = LIST_NOT_USED; | |
295 | 19108 | B = zeromv; | |
296 | } else { | ||
297 | 9903 | goto zeromv; | |
298 | } | ||
299 | |||
300 | ff_tlog(h->avctx, "pred_pskip: (%d) (%d) at %2d %2d\n", | ||
301 | top_ref, left_ref, sl->mb_x, sl->mb_y); | ||
302 | |||
303 |
2/2✓ Branch 0 taken 218828 times.
✓ Branch 1 taken 38796 times.
|
257624 | if (USES_LIST(sl->topright_type, 0)) { |
304 | 218828 | diagonal_ref = ref[4 * sl->topright_mb_xy + 2]; | |
305 | 218828 | C = mv[h->mb2b_xy[sl->topright_mb_xy] + 3 * b_stride]; | |
306 |
8/8✓ Branch 0 taken 7797 times.
✓ Branch 1 taken 211031 times.
✓ Branch 2 taken 1655 times.
✓ Branch 3 taken 6142 times.
✓ Branch 4 taken 836 times.
✓ Branch 5 taken 819 times.
✓ Branch 6 taken 810 times.
✓ Branch 7 taken 5332 times.
|
218828 | FIX_MV_MBAFF(sl->topright_type, diagonal_ref, C, 2); |
307 |
2/2✓ Branch 0 taken 18827 times.
✓ Branch 1 taken 19969 times.
|
38796 | } else if (sl->topright_type) { |
308 | 18827 | diagonal_ref = LIST_NOT_USED; | |
309 | 18827 | C = zeromv; | |
310 | } else { | ||
311 |
2/2✓ Branch 0 taken 18982 times.
✓ Branch 1 taken 987 times.
|
19969 | if (USES_LIST(sl->topleft_type, 0)) { |
312 | 18982 | diagonal_ref = ref[4 * sl->topleft_mb_xy + 1 + | |
313 | 18982 | (sl->topleft_partition & 2)]; | |
314 | 18982 | C = mv[h->mb2b_xy[sl->topleft_mb_xy] + 3 + b_stride + | |
315 | 18982 | (sl->topleft_partition & 2 * b_stride)]; | |
316 |
8/8✓ Branch 0 taken 8927 times.
✓ Branch 1 taken 10055 times.
✓ Branch 2 taken 49 times.
✓ Branch 3 taken 8878 times.
✓ Branch 4 taken 9 times.
✓ Branch 5 taken 40 times.
✓ Branch 6 taken 457 times.
✓ Branch 7 taken 8421 times.
|
18982 | FIX_MV_MBAFF(sl->topleft_type, diagonal_ref, C, 2); |
317 |
1/2✓ Branch 0 taken 987 times.
✗ Branch 1 not taken.
|
987 | } else if (sl->topleft_type) { |
318 | 987 | diagonal_ref = LIST_NOT_USED; | |
319 | 987 | C = zeromv; | |
320 | } else { | ||
321 | ✗ | diagonal_ref = PART_NOT_AVAILABLE; | |
322 | ✗ | C = zeromv; | |
323 | } | ||
324 | } | ||
325 | |||
326 | 257624 | match_count = !diagonal_ref + !top_ref + !left_ref; | |
327 | ff_tlog(h->avctx, "pred_pskip_motion match_count=%d\n", match_count); | ||
328 |
2/2✓ Branch 0 taken 215323 times.
✓ Branch 1 taken 42301 times.
|
257624 | if (match_count > 1) { |
329 | 215323 | mx = mid_pred(A[0], B[0], C[0]); | |
330 | 215323 | my = mid_pred(A[1], B[1], C[1]); | |
331 |
2/2✓ Branch 0 taken 36205 times.
✓ Branch 1 taken 6096 times.
|
42301 | } else if (match_count == 1) { |
332 |
2/2✓ Branch 0 taken 17583 times.
✓ Branch 1 taken 18622 times.
|
36205 | if (!left_ref) { |
333 | 17583 | mx = A[0]; | |
334 | 17583 | my = A[1]; | |
335 |
2/2✓ Branch 0 taken 8129 times.
✓ Branch 1 taken 10493 times.
|
18622 | } else if (!top_ref) { |
336 | 8129 | mx = B[0]; | |
337 | 8129 | my = B[1]; | |
338 | } else { | ||
339 | 10493 | mx = C[0]; | |
340 | 10493 | my = C[1]; | |
341 | } | ||
342 | } else { | ||
343 | 6096 | mx = mid_pred(A[0], B[0], C[0]); | |
344 | 6096 | my = mid_pred(A[1], B[1], C[1]); | |
345 | } | ||
346 | |||
347 | 257624 | fill_rectangle(sl->mv_cache[0][scan8[0]], 4, 4, 8, pack16to32(mx, my), 4); | |
348 | 257624 | return; | |
349 | |||
350 | 1160586 | zeromv: | |
351 | 1160586 | fill_rectangle(sl->mv_cache[0][scan8[0]], 4, 4, 8, 0, 4); | |
352 | 1160586 | return; | |
353 | } | ||
354 | |||
355 | 13615920 | static void fill_decode_neighbors(const H264Context *h, H264SliceContext *sl, int mb_type) | |
356 | { | ||
357 | 13615920 | const int mb_xy = sl->mb_xy; | |
358 | int topleft_xy, top_xy, topright_xy, left_xy[LEFT_MBS]; | ||
359 | static const uint8_t left_block_options[4][32] = { | ||
360 | { 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 }, | ||
361 | { 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 }, | ||
362 | { 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 }, | ||
363 | { 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 } | ||
364 | }; | ||
365 | |||
366 | 13615920 | sl->topleft_partition = -1; | |
367 | |||
368 | 13615920 | top_xy = mb_xy - (h->mb_stride << MB_FIELD(sl)); | |
369 | |||
370 | /* Wow, what a mess, why didn't they simplify the interlacing & intra | ||
371 | * stuff, I can't imagine that these complex rules are worth it. */ | ||
372 | |||
373 | 13615920 | topleft_xy = top_xy - 1; | |
374 | 13615920 | topright_xy = top_xy + 1; | |
375 | 13615920 | left_xy[LBOT] = left_xy[LTOP] = mb_xy - 1; | |
376 | 13615920 | sl->left_block = left_block_options[0]; | |
377 |
2/2✓ Branch 0 taken 2095408 times.
✓ Branch 1 taken 11520512 times.
|
13615920 | if (FRAME_MBAFF(h)) { |
378 | 2095408 | const int left_mb_field_flag = IS_INTERLACED(h->cur_pic.mb_type[mb_xy - 1]); | |
379 | 2095408 | const int curr_mb_field_flag = IS_INTERLACED(mb_type); | |
380 |
2/2✓ Branch 0 taken 1047592 times.
✓ Branch 1 taken 1047816 times.
|
2095408 | if (sl->mb_y & 1) { |
381 |
2/2✓ Branch 0 taken 247902 times.
✓ Branch 1 taken 799690 times.
|
1047592 | if (left_mb_field_flag != curr_mb_field_flag) { |
382 | 247902 | left_xy[LBOT] = left_xy[LTOP] = mb_xy - h->mb_stride - 1; | |
383 |
2/2✓ Branch 0 taken 127965 times.
✓ Branch 1 taken 119937 times.
|
247902 | if (curr_mb_field_flag) { |
384 | 127965 | left_xy[LBOT] += h->mb_stride; | |
385 | 127965 | sl->left_block = left_block_options[3]; | |
386 | } else { | ||
387 | 119937 | topleft_xy += h->mb_stride; | |
388 | /* take top left mv from the middle of the mb, as opposed | ||
389 | * to all other modes which use the bottom right partition */ | ||
390 | 119937 | sl->topleft_partition = 0; | |
391 | 119937 | sl->left_block = left_block_options[1]; | |
392 | } | ||
393 | } | ||
394 | } else { | ||
395 |
2/2✓ Branch 0 taken 305129 times.
✓ Branch 1 taken 742687 times.
|
1047816 | if (curr_mb_field_flag) { |
396 | 305129 | topleft_xy += h->mb_stride & (((h->cur_pic.mb_type[top_xy - 1] >> 7) & 1) - 1); | |
397 | 305129 | topright_xy += h->mb_stride & (((h->cur_pic.mb_type[top_xy + 1] >> 7) & 1) - 1); | |
398 | 305129 | top_xy += h->mb_stride & (((h->cur_pic.mb_type[top_xy] >> 7) & 1) - 1); | |
399 | } | ||
400 |
2/2✓ Branch 0 taken 248076 times.
✓ Branch 1 taken 799740 times.
|
1047816 | if (left_mb_field_flag != curr_mb_field_flag) { |
401 |
2/2✓ Branch 0 taken 127938 times.
✓ Branch 1 taken 120138 times.
|
248076 | if (curr_mb_field_flag) { |
402 | 127938 | left_xy[LBOT] += h->mb_stride; | |
403 | 127938 | sl->left_block = left_block_options[3]; | |
404 | } else { | ||
405 | 120138 | sl->left_block = left_block_options[2]; | |
406 | } | ||
407 | } | ||
408 | } | ||
409 | } | ||
410 | |||
411 | 13615920 | sl->topleft_mb_xy = topleft_xy; | |
412 | 13615920 | sl->top_mb_xy = top_xy; | |
413 | 13615920 | sl->topright_mb_xy = topright_xy; | |
414 | 13615920 | sl->left_mb_xy[LTOP] = left_xy[LTOP]; | |
415 | 13615920 | sl->left_mb_xy[LBOT] = left_xy[LBOT]; | |
416 | //FIXME do we need all in the context? | ||
417 | |||
418 | 13615920 | sl->topleft_type = h->cur_pic.mb_type[topleft_xy]; | |
419 | 13615920 | sl->top_type = h->cur_pic.mb_type[top_xy]; | |
420 | 13615920 | sl->topright_type = h->cur_pic.mb_type[topright_xy]; | |
421 | 13615920 | sl->left_type[LTOP] = h->cur_pic.mb_type[left_xy[LTOP]]; | |
422 | 13615920 | sl->left_type[LBOT] = h->cur_pic.mb_type[left_xy[LBOT]]; | |
423 | |||
424 | if (FMO) { | ||
425 | if (h->slice_table[topleft_xy] != sl->slice_num) | ||
426 | sl->topleft_type = 0; | ||
427 | if (h->slice_table[top_xy] != sl->slice_num) | ||
428 | sl->top_type = 0; | ||
429 | if (h->slice_table[left_xy[LTOP]] != sl->slice_num) | ||
430 | sl->left_type[LTOP] = sl->left_type[LBOT] = 0; | ||
431 | } else { | ||
432 |
2/2✓ Branch 0 taken 1358253 times.
✓ Branch 1 taken 12257667 times.
|
13615920 | if (h->slice_table[topleft_xy] != sl->slice_num) { |
433 | 1358253 | sl->topleft_type = 0; | |
434 |
2/2✓ Branch 0 taken 1009437 times.
✓ Branch 1 taken 348816 times.
|
1358253 | if (h->slice_table[top_xy] != sl->slice_num) |
435 | 1009437 | sl->top_type = 0; | |
436 |
2/2✓ Branch 0 taken 382946 times.
✓ Branch 1 taken 975307 times.
|
1358253 | if (h->slice_table[left_xy[LTOP]] != sl->slice_num) |
437 | 382946 | sl->left_type[LTOP] = sl->left_type[LBOT] = 0; | |
438 | } | ||
439 | } | ||
440 |
2/2✓ Branch 0 taken 2079921 times.
✓ Branch 1 taken 11535999 times.
|
13615920 | if (h->slice_table[topright_xy] != sl->slice_num) |
441 | 2079921 | sl->topright_type = 0; | |
442 | 13615920 | } | |
443 | |||
444 | 12192051 | static void fill_decode_caches(const H264Context *h, H264SliceContext *sl, int mb_type) | |
445 | { | ||
446 | int topleft_xy, top_xy, topright_xy, left_xy[LEFT_MBS]; | ||
447 | int topleft_type, top_type, topright_type, left_type[LEFT_MBS]; | ||
448 | 12192051 | const uint8_t *left_block = sl->left_block; | |
449 | int i; | ||
450 | uint8_t *nnz; | ||
451 | uint8_t *nnz_cache; | ||
452 | |||
453 | 12192051 | topleft_xy = sl->topleft_mb_xy; | |
454 | 12192051 | top_xy = sl->top_mb_xy; | |
455 | 12192051 | topright_xy = sl->topright_mb_xy; | |
456 | 12192051 | left_xy[LTOP] = sl->left_mb_xy[LTOP]; | |
457 | 12192051 | left_xy[LBOT] = sl->left_mb_xy[LBOT]; | |
458 | 12192051 | topleft_type = sl->topleft_type; | |
459 | 12192051 | top_type = sl->top_type; | |
460 | 12192051 | topright_type = sl->topright_type; | |
461 | 12192051 | left_type[LTOP] = sl->left_type[LTOP]; | |
462 | 12192051 | left_type[LBOT] = sl->left_type[LBOT]; | |
463 | |||
464 |
2/2✓ Branch 0 taken 10194612 times.
✓ Branch 1 taken 1997439 times.
|
12192051 | if (!IS_SKIP(mb_type)) { |
465 |
2/2✓ Branch 0 taken 3817694 times.
✓ Branch 1 taken 6376918 times.
|
10194612 | if (IS_INTRA(mb_type)) { |
466 |
2/2✓ Branch 0 taken 9021 times.
✓ Branch 1 taken 3808673 times.
|
3817694 | int type_mask = h->ps.pps->constrained_intra_pred ? IS_INTRA(-1) : -1; |
467 | 3817694 | sl->topleft_samples_available = | |
468 | 3817694 | sl->top_samples_available = | |
469 | 3817694 | sl->left_samples_available = 0xFFFF; | |
470 | 3817694 | sl->topright_samples_available = 0xEEEA; | |
471 | |||
472 |
2/2✓ Branch 0 taken 270650 times.
✓ Branch 1 taken 3547044 times.
|
3817694 | if (!(top_type & type_mask)) { |
473 | 270650 | sl->topleft_samples_available = 0xB3FF; | |
474 | 270650 | sl->top_samples_available = 0x33FF; | |
475 | 270650 | sl->topright_samples_available = 0x26EA; | |
476 | } | ||
477 |
2/2✓ Branch 0 taken 212225 times.
✓ Branch 1 taken 3605469 times.
|
3817694 | if (IS_INTERLACED(mb_type) != IS_INTERLACED(left_type[LTOP])) { |
478 |
2/2✓ Branch 0 taken 110678 times.
✓ Branch 1 taken 101547 times.
|
212225 | if (IS_INTERLACED(mb_type)) { |
479 |
2/2✓ Branch 0 taken 15866 times.
✓ Branch 1 taken 94812 times.
|
110678 | if (!(left_type[LTOP] & type_mask)) { |
480 | 15866 | sl->topleft_samples_available &= 0xDFFF; | |
481 | 15866 | sl->left_samples_available &= 0x5FFF; | |
482 | } | ||
483 |
2/2✓ Branch 0 taken 15871 times.
✓ Branch 1 taken 94807 times.
|
110678 | if (!(left_type[LBOT] & type_mask)) { |
484 | 15871 | sl->topleft_samples_available &= 0xFF5F; | |
485 | 15871 | sl->left_samples_available &= 0xFF5F; | |
486 | } | ||
487 | } else { | ||
488 | 101547 | int left_typei = h->cur_pic.mb_type[left_xy[LTOP] + h->mb_stride]; | |
489 | |||
490 | av_assert2(left_xy[LTOP] == left_xy[LBOT]); | ||
491 |
4/4✓ Branch 0 taken 101502 times.
✓ Branch 1 taken 45 times.
✓ Branch 2 taken 8 times.
✓ Branch 3 taken 101494 times.
|
101547 | if (!((left_typei & type_mask) && (left_type[LTOP] & type_mask))) { |
492 | 53 | sl->topleft_samples_available &= 0xDF5F; | |
493 | 53 | sl->left_samples_available &= 0x5F5F; | |
494 | } | ||
495 | } | ||
496 | } else { | ||
497 |
2/2✓ Branch 0 taken 64985 times.
✓ Branch 1 taken 3540484 times.
|
3605469 | if (!(left_type[LTOP] & type_mask)) { |
498 | 64985 | sl->topleft_samples_available &= 0xDF5F; | |
499 | 64985 | sl->left_samples_available &= 0x5F5F; | |
500 | } | ||
501 | } | ||
502 | |||
503 |
2/2✓ Branch 0 taken 342816 times.
✓ Branch 1 taken 3474878 times.
|
3817694 | if (!(topleft_type & type_mask)) |
504 | 342816 | sl->topleft_samples_available &= 0x7FFF; | |
505 | |||
506 |
2/2✓ Branch 0 taken 709168 times.
✓ Branch 1 taken 3108526 times.
|
3817694 | if (!(topright_type & type_mask)) |
507 | 709168 | sl->topright_samples_available &= 0xFBFF; | |
508 | |||
509 |
2/2✓ Branch 0 taken 2959439 times.
✓ Branch 1 taken 858255 times.
|
3817694 | if (IS_INTRA4x4(mb_type)) { |
510 |
2/2✓ Branch 0 taken 2225928 times.
✓ Branch 1 taken 733511 times.
|
2959439 | if (IS_INTRA4x4(top_type)) { |
511 | 2225928 | AV_COPY32(sl->intra4x4_pred_mode_cache + 4 + 8 * 0, sl->intra4x4_pred_mode + h->mb2br_xy[top_xy]); | |
512 | } else { | ||
513 | 733511 | sl->intra4x4_pred_mode_cache[4 + 8 * 0] = | |
514 | 733511 | sl->intra4x4_pred_mode_cache[5 + 8 * 0] = | |
515 | 733511 | sl->intra4x4_pred_mode_cache[6 + 8 * 0] = | |
516 |
2/2✓ Branch 0 taken 202642 times.
✓ Branch 1 taken 530869 times.
|
733511 | sl->intra4x4_pred_mode_cache[7 + 8 * 0] = 2 - 3 * !(top_type & type_mask); |
517 | } | ||
518 |
2/2✓ Branch 0 taken 5918878 times.
✓ Branch 1 taken 2959439 times.
|
8878317 | for (i = 0; i < 2; i++) { |
519 |
2/2✓ Branch 0 taken 4764684 times.
✓ Branch 1 taken 1154194 times.
|
5918878 | if (IS_INTRA4x4(left_type[LEFT(i)])) { |
520 | 4764684 | int8_t *mode = sl->intra4x4_pred_mode + h->mb2br_xy[left_xy[LEFT(i)]]; | |
521 | 4764684 | sl->intra4x4_pred_mode_cache[3 + 8 * 1 + 2 * 8 * i] = mode[6 - left_block[0 + 2 * i]]; | |
522 | 4764684 | sl->intra4x4_pred_mode_cache[3 + 8 * 2 + 2 * 8 * i] = mode[6 - left_block[1 + 2 * i]]; | |
523 | } else { | ||
524 | 1154194 | sl->intra4x4_pred_mode_cache[3 + 8 * 1 + 2 * 8 * i] = | |
525 |
2/2✓ Branch 0 taken 125481 times.
✓ Branch 1 taken 1028713 times.
|
1154194 | sl->intra4x4_pred_mode_cache[3 + 8 * 2 + 2 * 8 * i] = 2 - 3 * !(left_type[LEFT(i)] & type_mask); |
526 | } | ||
527 | } | ||
528 | } | ||
529 | } | ||
530 | |||
531 | /* | ||
532 | * 0 . T T. T T T T | ||
533 | * 1 L . .L . . . . | ||
534 | * 2 L . .L . . . . | ||
535 | * 3 . T TL . . . . | ||
536 | * 4 L . .L . . . . | ||
537 | * 5 L . .. . . . . | ||
538 | */ | ||
539 | /* FIXME: constraint_intra_pred & partitioning & nnz | ||
540 | * (let us hope this is just a typo in the spec) */ | ||
541 | 10194612 | nnz_cache = sl->non_zero_count_cache; | |
542 |
2/2✓ Branch 0 taken 9378709 times.
✓ Branch 1 taken 815903 times.
|
10194612 | if (top_type) { |
543 | 9378709 | nnz = h->non_zero_count[top_xy]; | |
544 | 9378709 | AV_COPY32(&nnz_cache[4 + 8 * 0], &nnz[4 * 3]); | |
545 |
2/2✓ Branch 0 taken 907099 times.
✓ Branch 1 taken 8471610 times.
|
9378709 | if (!h->chroma_y_shift) { |
546 | 907099 | AV_COPY32(&nnz_cache[4 + 8 * 5], &nnz[4 * 7]); | |
547 | 907099 | AV_COPY32(&nnz_cache[4 + 8 * 10], &nnz[4 * 11]); | |
548 | } else { | ||
549 | 8471610 | AV_COPY32(&nnz_cache[4 + 8 * 5], &nnz[4 * 5]); | |
550 | 8471610 | AV_COPY32(&nnz_cache[4 + 8 * 10], &nnz[4 * 9]); | |
551 | } | ||
552 | } else { | ||
553 |
2/2✓ Branch 0 taken 309783 times.
✓ Branch 1 taken 160659 times.
|
815903 | uint32_t top_empty = CABAC(h) && !IS_INTRA(mb_type) ? 0 : 0x40404040; |
554 | 815903 | AV_WN32A(&nnz_cache[4 + 8 * 0], top_empty); | |
555 | 815903 | AV_WN32A(&nnz_cache[4 + 8 * 5], top_empty); | |
556 | 815903 | AV_WN32A(&nnz_cache[4 + 8 * 10], top_empty); | |
557 | } | ||
558 | |||
559 |
2/2✓ Branch 0 taken 20389224 times.
✓ Branch 1 taken 10194612 times.
|
30583836 | for (i = 0; i < 2; i++) { |
560 |
2/2✓ Branch 0 taken 19792008 times.
✓ Branch 1 taken 597216 times.
|
20389224 | if (left_type[LEFT(i)]) { |
561 | 19792008 | nnz = h->non_zero_count[left_xy[LEFT(i)]]; | |
562 | 19792008 | nnz_cache[3 + 8 * 1 + 2 * 8 * i] = nnz[left_block[8 + 0 + 2 * i]]; | |
563 | 19792008 | nnz_cache[3 + 8 * 2 + 2 * 8 * i] = nnz[left_block[8 + 1 + 2 * i]]; | |
564 |
2/2✓ Branch 0 taken 295798 times.
✓ Branch 1 taken 19496210 times.
|
19792008 | if (CHROMA444(h)) { |
565 | 295798 | nnz_cache[3 + 8 * 6 + 2 * 8 * i] = nnz[left_block[8 + 0 + 2 * i] + 4 * 4]; | |
566 | 295798 | nnz_cache[3 + 8 * 7 + 2 * 8 * i] = nnz[left_block[8 + 1 + 2 * i] + 4 * 4]; | |
567 | 295798 | nnz_cache[3 + 8 * 11 + 2 * 8 * i] = nnz[left_block[8 + 0 + 2 * i] + 8 * 4]; | |
568 | 295798 | nnz_cache[3 + 8 * 12 + 2 * 8 * i] = nnz[left_block[8 + 1 + 2 * i] + 8 * 4]; | |
569 |
2/2✓ Branch 0 taken 1619188 times.
✓ Branch 1 taken 17877022 times.
|
19496210 | } else if (CHROMA422(h)) { |
570 | 1619188 | nnz_cache[3 + 8 * 6 + 2 * 8 * i] = nnz[left_block[8 + 0 + 2 * i] - 2 + 4 * 4]; | |
571 | 1619188 | nnz_cache[3 + 8 * 7 + 2 * 8 * i] = nnz[left_block[8 + 1 + 2 * i] - 2 + 4 * 4]; | |
572 | 1619188 | nnz_cache[3 + 8 * 11 + 2 * 8 * i] = nnz[left_block[8 + 0 + 2 * i] - 2 + 8 * 4]; | |
573 | 1619188 | nnz_cache[3 + 8 * 12 + 2 * 8 * i] = nnz[left_block[8 + 1 + 2 * i] - 2 + 8 * 4]; | |
574 | } else { | ||
575 | 17877022 | nnz_cache[3 + 8 * 6 + 8 * i] = nnz[left_block[8 + 4 + 2 * i]]; | |
576 | 17877022 | nnz_cache[3 + 8 * 11 + 8 * i] = nnz[left_block[8 + 5 + 2 * i]]; | |
577 | } | ||
578 | } else { | ||
579 | 597216 | nnz_cache[3 + 8 * 1 + 2 * 8 * i] = | |
580 | 597216 | nnz_cache[3 + 8 * 2 + 2 * 8 * i] = | |
581 | 597216 | nnz_cache[3 + 8 * 6 + 2 * 8 * i] = | |
582 | 597216 | nnz_cache[3 + 8 * 7 + 2 * 8 * i] = | |
583 | 597216 | nnz_cache[3 + 8 * 11 + 2 * 8 * i] = | |
584 |
2/2✓ Branch 0 taken 243304 times.
✓ Branch 1 taken 97292 times.
|
597216 | nnz_cache[3 + 8 * 12 + 2 * 8 * i] = CABAC(h) && !IS_INTRA(mb_type) ? 0 : 64; |
585 | } | ||
586 | } | ||
587 | |||
588 | if (CABAC(h)) { | ||
589 | // top_cbp | ||
590 |
2/2✓ Branch 0 taken 6205830 times.
✓ Branch 1 taken 470442 times.
|
6676272 | if (top_type) |
591 | 6205830 | sl->top_cbp = h->cbp_table[top_xy]; | |
592 | else | ||
593 |
2/2✓ Branch 0 taken 160659 times.
✓ Branch 1 taken 309783 times.
|
470442 | sl->top_cbp = IS_INTRA(mb_type) ? 0x7CF : 0x00F; |
594 | // left_cbp | ||
595 |
2/2✓ Branch 0 taken 6505974 times.
✓ Branch 1 taken 170298 times.
|
6676272 | if (left_type[LTOP]) { |
596 | 6505974 | sl->left_cbp = (h->cbp_table[left_xy[LTOP]] & 0x7F0) | | |
597 | 6505974 | ((h->cbp_table[left_xy[LTOP]] >> (left_block[0] & (~1))) & 2) | | |
598 | 6505974 | (((h->cbp_table[left_xy[LBOT]] >> (left_block[2] & (~1))) & 2) << 2); | |
599 | } else { | ||
600 |
2/2✓ Branch 0 taken 48646 times.
✓ Branch 1 taken 121652 times.
|
170298 | sl->left_cbp = IS_INTRA(mb_type) ? 0x7CF : 0x00F; |
601 | } | ||
602 | } | ||
603 | } | ||
604 | |||
605 |
6/6✓ Branch 0 taken 6412330 times.
✓ Branch 1 taken 5779721 times.
✓ Branch 2 taken 2594636 times.
✓ Branch 3 taken 3817694 times.
✓ Branch 4 taken 2530676 times.
✓ Branch 5 taken 63960 times.
|
12192051 | if (IS_INTER(mb_type) || (IS_DIRECT(mb_type) && sl->direct_spatial_mv_pred)) { |
606 | int list; | ||
607 | 8310397 | int b_stride = h->b_stride; | |
608 |
2/2✓ Branch 0 taken 13207477 times.
✓ Branch 1 taken 8310397 times.
|
21517874 | for (list = 0; list < sl->list_count; list++) { |
609 | 13207477 | int8_t *ref_cache = &sl->ref_cache[list][scan8[0]]; | |
610 | 13207477 | int8_t *ref = h->cur_pic.ref_index[list]; | |
611 | 13207477 | int16_t(*mv_cache)[2] = &sl->mv_cache[list][scan8[0]]; | |
612 | 13207477 | int16_t(*mv)[2] = h->cur_pic.motion_val[list]; | |
613 |
2/2✓ Branch 0 taken 1251861 times.
✓ Branch 1 taken 11955616 times.
|
13207477 | if (!USES_LIST(mb_type, list)) |
614 | 1251861 | continue; | |
615 | av_assert2(!(IS_DIRECT(mb_type) && !sl->direct_spatial_mv_pred)); | ||
616 | |||
617 |
2/2✓ Branch 0 taken 9706398 times.
✓ Branch 1 taken 2249218 times.
|
11955616 | if (USES_LIST(top_type, list)) { |
618 | 9706398 | const int b_xy = h->mb2b_xy[top_xy] + 3 * b_stride; | |
619 | 9706398 | AV_COPY128(mv_cache[0 - 1 * 8], mv[b_xy + 0]); | |
620 | 9706398 | ref_cache[0 - 1 * 8] = | |
621 | 9706398 | ref_cache[1 - 1 * 8] = ref[4 * top_xy + 2]; | |
622 | 9706398 | ref_cache[2 - 1 * 8] = | |
623 | 9706398 | ref_cache[3 - 1 * 8] = ref[4 * top_xy + 3]; | |
624 | } else { | ||
625 | 2249218 | AV_ZERO128(mv_cache[0 - 1 * 8]); | |
626 |
2/2✓ Branch 0 taken 1354818 times.
✓ Branch 1 taken 894400 times.
|
2249218 | AV_WN32A(&ref_cache[0 - 1 * 8], |
627 | ((top_type ? LIST_NOT_USED : PART_NOT_AVAILABLE) & 0xFF) * 0x01010101u); | ||
628 | } | ||
629 | |||
630 |
2/2✓ Branch 0 taken 2730117 times.
✓ Branch 1 taken 9225499 times.
|
11955616 | if (mb_type & (MB_TYPE_16x8 | MB_TYPE_8x8)) { |
631 |
2/2✓ Branch 0 taken 5460234 times.
✓ Branch 1 taken 2730117 times.
|
8190351 | for (i = 0; i < 2; i++) { |
632 | 5460234 | int cache_idx = -1 + i * 2 * 8; | |
633 |
2/2✓ Branch 0 taken 4670240 times.
✓ Branch 1 taken 789994 times.
|
5460234 | if (USES_LIST(left_type[LEFT(i)], list)) { |
634 | 4670240 | const int b_xy = h->mb2b_xy[left_xy[LEFT(i)]] + 3; | |
635 | 4670240 | const int b8_xy = 4 * left_xy[LEFT(i)] + 1; | |
636 | 4670240 | AV_COPY32(mv_cache[cache_idx], | |
637 | mv[b_xy + b_stride * left_block[0 + i * 2]]); | ||
638 | 4670240 | AV_COPY32(mv_cache[cache_idx + 8], | |
639 | mv[b_xy + b_stride * left_block[1 + i * 2]]); | ||
640 | 4670240 | ref_cache[cache_idx] = ref[b8_xy + (left_block[0 + i * 2] & ~1)]; | |
641 | 4670240 | ref_cache[cache_idx + 8] = ref[b8_xy + (left_block[1 + i * 2] & ~1)]; | |
642 | } else { | ||
643 | 789994 | AV_ZERO32(mv_cache[cache_idx]); | |
644 | 789994 | AV_ZERO32(mv_cache[cache_idx + 8]); | |
645 | 789994 | ref_cache[cache_idx] = | |
646 |
2/2✓ Branch 0 taken 560006 times.
✓ Branch 1 taken 229988 times.
|
789994 | ref_cache[cache_idx + 8] = (left_type[LEFT(i)]) ? LIST_NOT_USED |
647 | : PART_NOT_AVAILABLE; | ||
648 | } | ||
649 | } | ||
650 | } else { | ||
651 |
2/2✓ Branch 0 taken 7947889 times.
✓ Branch 1 taken 1277610 times.
|
9225499 | if (USES_LIST(left_type[LTOP], list)) { |
652 | 7947889 | const int b_xy = h->mb2b_xy[left_xy[LTOP]] + 3; | |
653 | 7947889 | const int b8_xy = 4 * left_xy[LTOP] + 1; | |
654 | 7947889 | AV_COPY32(mv_cache[-1], mv[b_xy + b_stride * left_block[0]]); | |
655 | 7947889 | ref_cache[-1] = ref[b8_xy + (left_block[0] & ~1)]; | |
656 | } else { | ||
657 | 1277610 | AV_ZERO32(mv_cache[-1]); | |
658 |
2/2✓ Branch 0 taken 1045211 times.
✓ Branch 1 taken 232399 times.
|
1277610 | ref_cache[-1] = left_type[LTOP] ? LIST_NOT_USED |
659 | : PART_NOT_AVAILABLE; | ||
660 | } | ||
661 | } | ||
662 | |||
663 |
2/2✓ Branch 0 taken 8945815 times.
✓ Branch 1 taken 3009801 times.
|
11955616 | if (USES_LIST(topright_type, list)) { |
664 | 8945815 | const int b_xy = h->mb2b_xy[topright_xy] + 3 * b_stride; | |
665 | 8945815 | AV_COPY32(mv_cache[4 - 1 * 8], mv[b_xy]); | |
666 | 8945815 | ref_cache[4 - 1 * 8] = ref[4 * topright_xy + 2]; | |
667 | } else { | ||
668 | 3009801 | AV_ZERO32(mv_cache[4 - 1 * 8]); | |
669 |
2/2✓ Branch 0 taken 1318319 times.
✓ Branch 1 taken 1691482 times.
|
3009801 | ref_cache[4 - 1 * 8] = topright_type ? LIST_NOT_USED |
670 | : PART_NOT_AVAILABLE; | ||
671 | } | ||
672 |
4/4✓ Branch 0 taken 9512065 times.
✓ Branch 1 taken 2443551 times.
✓ Branch 2 taken 1231685 times.
✓ Branch 3 taken 8280380 times.
|
11955616 | if(ref_cache[2 - 1*8] < 0 || ref_cache[4 - 1 * 8] < 0) { |
673 |
2/2✓ Branch 0 taken 1678114 times.
✓ Branch 1 taken 1997122 times.
|
3675236 | if (USES_LIST(topleft_type, list)) { |
674 | 1678114 | const int b_xy = h->mb2b_xy[topleft_xy] + 3 + b_stride + | |
675 | 1678114 | (sl->topleft_partition & 2 * b_stride); | |
676 | 1678114 | const int b8_xy = 4 * topleft_xy + 1 + (sl->topleft_partition & 2); | |
677 | 1678114 | AV_COPY32(mv_cache[-1 - 1 * 8], mv[b_xy]); | |
678 | 1678114 | ref_cache[-1 - 1 * 8] = ref[b8_xy]; | |
679 | } else { | ||
680 | 1997122 | AV_ZERO32(mv_cache[-1 - 1 * 8]); | |
681 |
2/2✓ Branch 0 taken 1014143 times.
✓ Branch 1 taken 982979 times.
|
1997122 | ref_cache[-1 - 1 * 8] = topleft_type ? LIST_NOT_USED |
682 | : PART_NOT_AVAILABLE; | ||
683 | } | ||
684 | } | ||
685 | |||
686 |
4/4✓ Branch 0 taken 5061352 times.
✓ Branch 1 taken 6894264 times.
✓ Branch 2 taken 4556736 times.
✓ Branch 3 taken 504616 times.
|
11955616 | if ((mb_type & (MB_TYPE_SKIP | MB_TYPE_DIRECT2)) && !FRAME_MBAFF(h)) |
687 | 4556736 | continue; | |
688 | |||
689 |
2/2✓ Branch 0 taken 6894264 times.
✓ Branch 1 taken 504616 times.
|
7398880 | if (!(mb_type & (MB_TYPE_SKIP | MB_TYPE_DIRECT2))) { |
690 | 6894264 | uint8_t(*mvd_cache)[2] = &sl->mvd_cache[list][scan8[0]]; | |
691 | 6894264 | uint8_t(*mvd)[2] = sl->mvd_table[list]; | |
692 | 6894264 | ref_cache[2 + 8 * 0] = | |
693 | 6894264 | ref_cache[2 + 8 * 2] = PART_NOT_AVAILABLE; | |
694 | 6894264 | AV_ZERO32(mv_cache[2 + 8 * 0]); | |
695 | 6894264 | AV_ZERO32(mv_cache[2 + 8 * 2]); | |
696 | |||
697 | if (CABAC(h)) { | ||
698 |
2/2✓ Branch 0 taken 3632253 times.
✓ Branch 1 taken 910754 times.
|
4543007 | if (USES_LIST(top_type, list)) { |
699 | 3632253 | const int b_xy = h->mb2br_xy[top_xy]; | |
700 | 3632253 | AV_COPY64(mvd_cache[0 - 1 * 8], mvd[b_xy + 0]); | |
701 | } else { | ||
702 | 910754 | AV_ZERO64(mvd_cache[0 - 1 * 8]); | |
703 | } | ||
704 |
2/2✓ Branch 0 taken 3848791 times.
✓ Branch 1 taken 694216 times.
|
4543007 | if (USES_LIST(left_type[LTOP], list)) { |
705 | 3848791 | const int b_xy = h->mb2br_xy[left_xy[LTOP]] + 6; | |
706 | 3848791 | AV_COPY16(mvd_cache[-1 + 0 * 8], mvd[b_xy - left_block[0]]); | |
707 | 3848791 | AV_COPY16(mvd_cache[-1 + 1 * 8], mvd[b_xy - left_block[1]]); | |
708 | } else { | ||
709 | 694216 | AV_ZERO16(mvd_cache[-1 + 0 * 8]); | |
710 | 694216 | AV_ZERO16(mvd_cache[-1 + 1 * 8]); | |
711 | } | ||
712 |
2/2✓ Branch 0 taken 3848591 times.
✓ Branch 1 taken 694416 times.
|
4543007 | if (USES_LIST(left_type[LBOT], list)) { |
713 | 3848591 | const int b_xy = h->mb2br_xy[left_xy[LBOT]] + 6; | |
714 | 3848591 | AV_COPY16(mvd_cache[-1 + 2 * 8], mvd[b_xy - left_block[2]]); | |
715 | 3848591 | AV_COPY16(mvd_cache[-1 + 3 * 8], mvd[b_xy - left_block[3]]); | |
716 | } else { | ||
717 | 694416 | AV_ZERO16(mvd_cache[-1 + 2 * 8]); | |
718 | 694416 | AV_ZERO16(mvd_cache[-1 + 3 * 8]); | |
719 | } | ||
720 | 4543007 | AV_ZERO16(mvd_cache[2 + 8 * 0]); | |
721 | 4543007 | AV_ZERO16(mvd_cache[2 + 8 * 2]); | |
722 |
2/2✓ Branch 0 taken 2536394 times.
✓ Branch 1 taken 2006613 times.
|
4543007 | if (sl->slice_type_nos == AV_PICTURE_TYPE_B) { |
723 | 2536394 | uint8_t *direct_cache = &sl->direct_cache[scan8[0]]; | |
724 | 2536394 | uint8_t *direct_table = h->direct_table; | |
725 | 2536394 | fill_rectangle(direct_cache, 4, 4, 8, MB_TYPE_16x16 >> 1, 1); | |
726 | |||
727 |
2/2✓ Branch 0 taken 395572 times.
✓ Branch 1 taken 2140822 times.
|
2536394 | if (IS_DIRECT(top_type)) { |
728 | 395572 | AV_WN32A(&direct_cache[-1 * 8], | |
729 | 0x01010101u * (MB_TYPE_DIRECT2 >> 1)); | ||
730 |
2/2✓ Branch 0 taken 610350 times.
✓ Branch 1 taken 1530472 times.
|
2140822 | } else if (IS_8X8(top_type)) { |
731 | 610350 | int b8_xy = 4 * top_xy; | |
732 | 610350 | direct_cache[0 - 1 * 8] = direct_table[b8_xy + 2]; | |
733 | 610350 | direct_cache[2 - 1 * 8] = direct_table[b8_xy + 3]; | |
734 | } else { | ||
735 | 1530472 | AV_WN32A(&direct_cache[-1 * 8], | |
736 | 0x01010101 * (MB_TYPE_16x16 >> 1)); | ||
737 | } | ||
738 | |||
739 |
2/2✓ Branch 0 taken 390852 times.
✓ Branch 1 taken 2145542 times.
|
2536394 | if (IS_DIRECT(left_type[LTOP])) |
740 | 390852 | direct_cache[-1 + 0 * 8] = MB_TYPE_DIRECT2 >> 1; | |
741 |
2/2✓ Branch 0 taken 645309 times.
✓ Branch 1 taken 1500233 times.
|
2145542 | else if (IS_8X8(left_type[LTOP])) |
742 | 645309 | direct_cache[-1 + 0 * 8] = direct_table[4 * left_xy[LTOP] + 1 + (left_block[0] & ~1)]; | |
743 | else | ||
744 | 1500233 | direct_cache[-1 + 0 * 8] = MB_TYPE_16x16 >> 1; | |
745 | |||
746 |
2/2✓ Branch 0 taken 389967 times.
✓ Branch 1 taken 2146427 times.
|
2536394 | if (IS_DIRECT(left_type[LBOT])) |
747 | 389967 | direct_cache[-1 + 2 * 8] = MB_TYPE_DIRECT2 >> 1; | |
748 |
2/2✓ Branch 0 taken 647398 times.
✓ Branch 1 taken 1499029 times.
|
2146427 | else if (IS_8X8(left_type[LBOT])) |
749 | 647398 | direct_cache[-1 + 2 * 8] = direct_table[4 * left_xy[LBOT] + 1 + (left_block[2] & ~1)]; | |
750 | else | ||
751 | 1499029 | direct_cache[-1 + 2 * 8] = MB_TYPE_16x16 >> 1; | |
752 | } | ||
753 | } | ||
754 | } | ||
755 | |||
756 | #define MAP_MVS \ | ||
757 | MAP_F2F(scan8[0] - 1 - 1 * 8, topleft_type) \ | ||
758 | MAP_F2F(scan8[0] + 0 - 1 * 8, top_type) \ | ||
759 | MAP_F2F(scan8[0] + 1 - 1 * 8, top_type) \ | ||
760 | MAP_F2F(scan8[0] + 2 - 1 * 8, top_type) \ | ||
761 | MAP_F2F(scan8[0] + 3 - 1 * 8, top_type) \ | ||
762 | MAP_F2F(scan8[0] + 4 - 1 * 8, topright_type) \ | ||
763 | MAP_F2F(scan8[0] - 1 + 0 * 8, left_type[LTOP]) \ | ||
764 | MAP_F2F(scan8[0] - 1 + 1 * 8, left_type[LTOP]) \ | ||
765 | MAP_F2F(scan8[0] - 1 + 2 * 8, left_type[LBOT]) \ | ||
766 | MAP_F2F(scan8[0] - 1 + 3 * 8, left_type[LBOT]) | ||
767 | |||
768 |
2/2✓ Branch 0 taken 1583802 times.
✓ Branch 1 taken 5815078 times.
|
7398880 | if (FRAME_MBAFF(h)) { |
769 |
2/2✓ Branch 0 taken 543998 times.
✓ Branch 1 taken 1039804 times.
|
1583802 | if (MB_FIELD(sl)) { |
770 | |||
771 | #define MAP_F2F(idx, mb_type) \ | ||
772 | if (!IS_INTERLACED(mb_type) && sl->ref_cache[list][idx] >= 0) { \ | ||
773 | sl->ref_cache[list][idx] *= 2; \ | ||
774 | sl->mv_cache[list][idx][1] /= 2; \ | ||
775 | sl->mvd_cache[list][idx][1] >>= 1; \ | ||
776 | } | ||
777 | |||
778 |
40/40✓ Branch 0 taken 299275 times.
✓ Branch 1 taken 244723 times.
✓ Branch 2 taken 157885 times.
✓ Branch 3 taken 141390 times.
✓ Branch 4 taken 275785 times.
✓ Branch 5 taken 268213 times.
✓ Branch 6 taken 154644 times.
✓ Branch 7 taken 121141 times.
✓ Branch 8 taken 275785 times.
✓ Branch 9 taken 268213 times.
✓ Branch 10 taken 154644 times.
✓ Branch 11 taken 121141 times.
✓ Branch 12 taken 275785 times.
✓ Branch 13 taken 268213 times.
✓ Branch 14 taken 154677 times.
✓ Branch 15 taken 121108 times.
✓ Branch 16 taken 275785 times.
✓ Branch 17 taken 268213 times.
✓ Branch 18 taken 154677 times.
✓ Branch 19 taken 121108 times.
✓ Branch 20 taken 299232 times.
✓ Branch 21 taken 244766 times.
✓ Branch 22 taken 162514 times.
✓ Branch 23 taken 136718 times.
✓ Branch 24 taken 227363 times.
✓ Branch 25 taken 316635 times.
✓ Branch 26 taken 155807 times.
✓ Branch 27 taken 71556 times.
✓ Branch 28 taken 227363 times.
✓ Branch 29 taken 316635 times.
✓ Branch 30 taken 145281 times.
✓ Branch 31 taken 82082 times.
✓ Branch 32 taken 227363 times.
✓ Branch 33 taken 316635 times.
✓ Branch 34 taken 145154 times.
✓ Branch 35 taken 82209 times.
✓ Branch 36 taken 227363 times.
✓ Branch 37 taken 316635 times.
✓ Branch 38 taken 145201 times.
✓ Branch 39 taken 82162 times.
|
543998 | MAP_MVS |
779 | } else { | ||
780 | |||
781 | #undef MAP_F2F | ||
782 | #define MAP_F2F(idx, mb_type) \ | ||
783 | if (IS_INTERLACED(mb_type) && sl->ref_cache[list][idx] >= 0) { \ | ||
784 | sl->ref_cache[list][idx] >>= 1; \ | ||
785 | sl->mv_cache[list][idx][1] *= 2; \ | ||
786 | sl->mvd_cache[list][idx][1] <<= 1; \ | ||
787 | } | ||
788 | |||
789 |
40/40✓ Branch 0 taken 193812 times.
✓ Branch 1 taken 845992 times.
✓ Branch 2 taken 144457 times.
✓ Branch 3 taken 49355 times.
✓ Branch 4 taken 91546 times.
✓ Branch 5 taken 948258 times.
✓ Branch 6 taken 70710 times.
✓ Branch 7 taken 20836 times.
✓ Branch 8 taken 91546 times.
✓ Branch 9 taken 948258 times.
✓ Branch 10 taken 70710 times.
✓ Branch 11 taken 20836 times.
✓ Branch 12 taken 91546 times.
✓ Branch 13 taken 948258 times.
✓ Branch 14 taken 70779 times.
✓ Branch 15 taken 20767 times.
✓ Branch 16 taken 91546 times.
✓ Branch 17 taken 948258 times.
✓ Branch 18 taken 70779 times.
✓ Branch 19 taken 20767 times.
✓ Branch 20 taken 96000 times.
✓ Branch 21 taken 943804 times.
✓ Branch 22 taken 75095 times.
✓ Branch 23 taken 20905 times.
✓ Branch 24 taken 194949 times.
✓ Branch 25 taken 844855 times.
✓ Branch 26 taken 151645 times.
✓ Branch 27 taken 43304 times.
✓ Branch 28 taken 194949 times.
✓ Branch 29 taken 844855 times.
✓ Branch 30 taken 132794 times.
✓ Branch 31 taken 62155 times.
✓ Branch 32 taken 194949 times.
✓ Branch 33 taken 844855 times.
✓ Branch 34 taken 132794 times.
✓ Branch 35 taken 62155 times.
✓ Branch 36 taken 194949 times.
✓ Branch 37 taken 844855 times.
✓ Branch 38 taken 132680 times.
✓ Branch 39 taken 62269 times.
|
1039804 | MAP_MVS |
790 | #undef MAP_F2F | ||
791 | } | ||
792 | } | ||
793 | } | ||
794 | } | ||
795 | |||
796 | 12192051 | sl->neighbor_transform_size = !!IS_8x8DCT(top_type) + !!IS_8x8DCT(left_type[LTOP]); | |
797 | 12192051 | } | |
798 | |||
799 | /** | ||
800 | * decodes a P_SKIP or B_SKIP macroblock | ||
801 | */ | ||
802 | 3551715 | static void av_unused decode_mb_skip(const H264Context *h, H264SliceContext *sl) | |
803 | { | ||
804 | 3551715 | const int mb_xy = sl->mb_xy; | |
805 | 3551715 | int mb_type = 0; | |
806 | |||
807 | 3551715 | memset(h->non_zero_count[mb_xy], 0, 48); | |
808 | |||
809 |
2/2✓ Branch 0 taken 1460599 times.
✓ Branch 1 taken 2091116 times.
|
3551715 | if (MB_FIELD(sl)) |
810 | 1460599 | mb_type |= MB_TYPE_INTERLACED; | |
811 | |||
812 |
2/2✓ Branch 0 taken 2133505 times.
✓ Branch 1 taken 1418210 times.
|
3551715 | if (sl->slice_type_nos == AV_PICTURE_TYPE_B) { |
813 | // just for fill_caches. pred_direct_motion will set the real mb_type | ||
814 | 2133505 | mb_type |= MB_TYPE_L0L1 | MB_TYPE_DIRECT2 | MB_TYPE_SKIP; | |
815 |
2/2✓ Branch 0 taken 1997439 times.
✓ Branch 1 taken 136066 times.
|
2133505 | if (sl->direct_spatial_mv_pred) { |
816 | 1997439 | fill_decode_neighbors(h, sl, mb_type); | |
817 | 1997439 | fill_decode_caches(h, sl, mb_type); //FIXME check what is needed and what not ... | |
818 | } | ||
819 | 2133505 | ff_h264_pred_direct_motion(h, sl, &mb_type); | |
820 | 2133505 | mb_type |= MB_TYPE_SKIP; | |
821 | } else { | ||
822 | 1418210 | mb_type |= MB_TYPE_16x16 | MB_TYPE_P0L0 | MB_TYPE_P1L0 | MB_TYPE_SKIP; | |
823 | |||
824 | 1418210 | fill_decode_neighbors(h, sl, mb_type); | |
825 | 1418210 | pred_pskip_motion(h, sl); | |
826 | } | ||
827 | |||
828 | 3551715 | write_back_motion(h, sl, mb_type); | |
829 | 3551715 | h->cur_pic.mb_type[mb_xy] = mb_type; | |
830 | 3551715 | h->cur_pic.qscale_table[mb_xy] = sl->qscale; | |
831 | 3551715 | h->slice_table[mb_xy] = sl->slice_num; | |
832 | 3551715 | sl->prev_mb_skipped = 1; | |
833 | 3551715 | } | |
834 | |||
835 | #endif /* AVCODEC_H264_MVPRED_H */ | ||
836 |