FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/h264_mb.c
Date: 2022-07-04 00:18:54
Exec Total Coverage
Lines: 374 396 94.4%
Branches: 264 298 88.6%

Line Branch Exec Source
1 /*
2 * H.26L/H.264/AVC/JVT/14496-10/... decoder
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 macroblock decoding
25 */
26
27 #include <stdint.h>
28
29 #include "config.h"
30
31 #include "libavutil/common.h"
32 #include "libavutil/intreadwrite.h"
33 #include "avcodec.h"
34 #include "h264dec.h"
35 #include "h264_ps.h"
36 #include "qpeldsp.h"
37 #include "threadframe.h"
38
39 67646 static inline int get_lowest_part_list_y(H264SliceContext *sl,
40 int n, int height, int y_offset, int list)
41 {
42 67646 int raw_my = sl->mv_cache[list][scan8[n]][1];
43
2/2
✓ Branch 0 taken 17304 times.
✓ Branch 1 taken 50342 times.
67646 int filter_height_down = (raw_my & 3) ? 3 : 0;
44 67646 int full_my = (raw_my >> 2) + y_offset;
45 67646 int bottom = full_my + filter_height_down + height;
46
47 av_assert2(height >= 0);
48
49 67646 return FFMAX(0, bottom);
50 }
51
52 53762 static inline void get_lowest_part_y(const H264Context *h, H264SliceContext *sl,
53 int16_t refs[2][48], int n,
54 int height, int y_offset, int list0,
55 int list1, int *nrefs)
56 {
57 int my;
58
59 53762 y_offset += 16 * (sl->mb_y >> MB_FIELD(sl));
60
61
2/2
✓ Branch 0 taken 48825 times.
✓ Branch 1 taken 4937 times.
53762 if (list0) {
62 48825 int ref_n = sl->ref_cache[0][scan8[n]];
63 48825 H264Ref *ref = &sl->ref_list[0][ref_n];
64
65 // Error resilience puts the current picture in the ref list.
66 // Don't try to wait on these as it will cause a deadlock.
67 // Fields can wait on each other, though.
68
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 48825 times.
48825 if (ref->parent->tf.progress->data != h->cur_pic.tf.progress->data ||
69 (ref->reference & 3) != h->picture_structure) {
70 48825 my = get_lowest_part_list_y(sl, n, height, y_offset, 0);
71
2/2
✓ Branch 0 taken 39009 times.
✓ Branch 1 taken 9816 times.
48825 if (refs[0][ref_n] < 0)
72 39009 nrefs[0] += 1;
73 48825 refs[0][ref_n] = FFMAX(refs[0][ref_n], my);
74 }
75 }
76
77
2/2
✓ Branch 0 taken 18821 times.
✓ Branch 1 taken 34941 times.
53762 if (list1) {
78 18821 int ref_n = sl->ref_cache[1][scan8[n]];
79 18821 H264Ref *ref = &sl->ref_list[1][ref_n];
80
81
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18821 times.
18821 if (ref->parent->tf.progress->data != h->cur_pic.tf.progress->data ||
82 (ref->reference & 3) != h->picture_structure) {
83 18821 my = get_lowest_part_list_y(sl, n, height, y_offset, 1);
84
2/2
✓ Branch 0 taken 16624 times.
✓ Branch 1 taken 2197 times.
18821 if (refs[1][ref_n] < 0)
85 16624 nrefs[1] += 1;
86 18821 refs[1][ref_n] = FFMAX(refs[1][ref_n], my);
87 }
88 }
89 53762 }
90
91 /**
92 * Wait until all reference frames are available for MC operations.
93 *
94 * @param h the H.264 context
95 */
96 39818 static void await_references(const H264Context *h, H264SliceContext *sl)
97 {
98 39818 const int mb_xy = sl->mb_xy;
99 39818 const int mb_type = h->cur_pic.mb_type[mb_xy];
100 int16_t refs[2][48];
101 39818 int nrefs[2] = { 0 };
102 int ref, list;
103
104 39818 memset(refs, -1, sizeof(refs));
105
106
2/2
✓ Branch 0 taken 31704 times.
✓ Branch 1 taken 8114 times.
39818 if (IS_16X16(mb_type)) {
107 31704 get_lowest_part_y(h, sl, refs, 0, 16, 0,
108 IS_DIR(mb_type, 0, 0), IS_DIR(mb_type, 0, 1), nrefs);
109
2/2
✓ Branch 0 taken 2608 times.
✓ Branch 1 taken 5506 times.
8114 } else if (IS_16X8(mb_type)) {
110 2608 get_lowest_part_y(h, sl, refs, 0, 8, 0,
111 IS_DIR(mb_type, 0, 0), IS_DIR(mb_type, 0, 1), nrefs);
112 2608 get_lowest_part_y(h, sl, refs, 8, 8, 8,
113 IS_DIR(mb_type, 1, 0), IS_DIR(mb_type, 1, 1), nrefs);
114
2/2
✓ Branch 0 taken 2591 times.
✓ Branch 1 taken 2915 times.
5506 } else if (IS_8X16(mb_type)) {
115 2591 get_lowest_part_y(h, sl, refs, 0, 16, 0,
116 IS_DIR(mb_type, 0, 0), IS_DIR(mb_type, 0, 1), nrefs);
117 2591 get_lowest_part_y(h, sl, refs, 4, 16, 0,
118 IS_DIR(mb_type, 1, 0), IS_DIR(mb_type, 1, 1), nrefs);
119 } else {
120 int i;
121
122 av_assert2(IS_8X8(mb_type));
123
124
2/2
✓ Branch 0 taken 11660 times.
✓ Branch 1 taken 2915 times.
14575 for (i = 0; i < 4; i++) {
125 11660 const int sub_mb_type = sl->sub_mb_type[i];
126 11660 const int n = 4 * i;
127 11660 int y_offset = (i & 2) << 2;
128
129
1/2
✓ Branch 0 taken 11660 times.
✗ Branch 1 not taken.
11660 if (IS_SUB_8X8(sub_mb_type)) {
130 11660 get_lowest_part_y(h, sl, refs, n, 8, y_offset,
131 IS_DIR(sub_mb_type, 0, 0),
132 IS_DIR(sub_mb_type, 0, 1),
133 nrefs);
134 } else if (IS_SUB_8X4(sub_mb_type)) {
135 get_lowest_part_y(h, sl, refs, n, 4, y_offset,
136 IS_DIR(sub_mb_type, 0, 0),
137 IS_DIR(sub_mb_type, 0, 1),
138 nrefs);
139 get_lowest_part_y(h, sl, refs, n + 2, 4, y_offset + 4,
140 IS_DIR(sub_mb_type, 0, 0),
141 IS_DIR(sub_mb_type, 0, 1),
142 nrefs);
143 } else if (IS_SUB_4X8(sub_mb_type)) {
144 get_lowest_part_y(h, sl, refs, n, 8, y_offset,
145 IS_DIR(sub_mb_type, 0, 0),
146 IS_DIR(sub_mb_type, 0, 1),
147 nrefs);
148 get_lowest_part_y(h, sl, refs, n + 1, 8, y_offset,
149 IS_DIR(sub_mb_type, 0, 0),
150 IS_DIR(sub_mb_type, 0, 1),
151 nrefs);
152 } else {
153 int j;
154 av_assert2(IS_SUB_4X4(sub_mb_type));
155 for (j = 0; j < 4; j++) {
156 int sub_y_offset = y_offset + 2 * (j & 2);
157 get_lowest_part_y(h, sl, refs, n + j, 4, sub_y_offset,
158 IS_DIR(sub_mb_type, 0, 0),
159 IS_DIR(sub_mb_type, 0, 1),
160 nrefs);
161 }
162 }
163 }
164 }
165
166
2/2
✓ Branch 0 taken 57782 times.
✓ Branch 1 taken 39818 times.
97600 for (list = sl->list_count - 1; list >= 0; list--)
167
3/4
✓ Branch 0 taken 120634 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 62852 times.
✓ Branch 3 taken 57782 times.
120634 for (ref = 0; ref < 48 && nrefs[list]; ref++) {
168 62852 int row = refs[list][ref];
169
2/2
✓ Branch 0 taken 55633 times.
✓ Branch 1 taken 7219 times.
62852 if (row >= 0) {
170 55633 H264Ref *ref_pic = &sl->ref_list[list][ref];
171 55633 int ref_field = ref_pic->reference - 1;
172 55633 int ref_field_picture = ref_pic->parent->field_picture;
173 55633 int pic_height = 16 * h->mb_height >> ref_field_picture;
174
175 55633 row <<= MB_MBAFF(sl);
176 55633 nrefs[list]--;
177
178
2/4
✓ Branch 0 taken 55633 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 55633 times.
55633 if (!FIELD_PICTURE(h) && ref_field_picture) { // frame referencing two fields
179 av_assert2((ref_pic->parent->reference & 3) == 3);
180 ff_thread_await_progress(&ref_pic->parent->tf,
181 FFMIN((row >> 1) - !(row & 1),
182 pic_height - 1),
183 1);
184 ff_thread_await_progress(&ref_pic->parent->tf,
185 FFMIN((row >> 1), pic_height - 1),
186 0);
187
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 55633 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
55633 } else if (FIELD_PICTURE(h) && !ref_field_picture) { // field referencing one field of a frame
188 ff_thread_await_progress(&ref_pic->parent->tf,
189 FFMIN(row * 2 + ref_field,
190 pic_height - 1),
191 0);
192
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 55633 times.
55633 } else if (FIELD_PICTURE(h)) {
193 ff_thread_await_progress(&ref_pic->parent->tf,
194 FFMIN(row, pic_height - 1),
195 ref_field);
196 } else {
197
2/2
✓ Branch 0 taken 1934 times.
✓ Branch 1 taken 53699 times.
55633 ff_thread_await_progress(&ref_pic->parent->tf,
198 FFMIN(row, pic_height - 1),
199 0);
200 }
201 }
202 }
203 39818 }
204
205 26349765 static av_always_inline void mc_dir_part(const H264Context *h, H264SliceContext *sl,
206 H264Ref *pic,
207 int n, int square, int height,
208 int delta, int list,
209 uint8_t *dest_y, uint8_t *dest_cb,
210 uint8_t *dest_cr,
211 int src_x_offset, int src_y_offset,
212 const qpel_mc_func *qpix_op,
213 h264_chroma_mc_func chroma_op,
214 int pixel_shift, int chroma_idc)
215 {
216 26349765 const int mx = sl->mv_cache[list][scan8[n]][0] + src_x_offset * 8;
217 26349765 int my = sl->mv_cache[list][scan8[n]][1] + src_y_offset * 8;
218 26349765 const int luma_xy = (mx & 3) + ((my & 3) << 2);
219 26349765 ptrdiff_t offset = (mx >> 2) * (1 << pixel_shift) + (my >> 2) * sl->mb_linesize;
220 26349765 uint8_t *src_y = pic->data[0] + offset;
221 uint8_t *src_cb, *src_cr;
222 26349765 int extra_width = 0;
223 26349765 int extra_height = 0;
224 26349765 int emu = 0;
225 26349765 const int full_mx = mx >> 2;
226 26349765 const int full_my = my >> 2;
227 26349765 const int pic_width = 16 * h->mb_width;
228 26349765 const int pic_height = 16 * h->mb_height >> MB_FIELD(sl);
229 int ysh;
230
231
2/2
✓ Branch 0 taken 18323960 times.
✓ Branch 1 taken 8025805 times.
26349765 if (mx & 7)
232 18323960 extra_width -= 3;
233
2/2
✓ Branch 0 taken 15918659 times.
✓ Branch 1 taken 10431106 times.
26349765 if (my & 7)
234 15918659 extra_height -= 3;
235
236
2/2
✓ Branch 0 taken 26229656 times.
✓ Branch 1 taken 120109 times.
26349765 if (full_mx < 0 - extra_width ||
237
2/2
✓ Branch 0 taken 25872924 times.
✓ Branch 1 taken 356732 times.
26229656 full_my < 0 - extra_height ||
238
2/2
✓ Branch 0 taken 25295273 times.
✓ Branch 1 taken 577651 times.
25872924 full_mx + 16 /*FIXME*/ > pic_width + extra_width ||
239
2/2
✓ Branch 0 taken 1022186 times.
✓ Branch 1 taken 24273087 times.
25295273 full_my + 16 /*FIXME*/ > pic_height + extra_height) {
240 2076678 h->vdsp.emulated_edge_mc(sl->edge_emu_buffer,
241 2076678 src_y - (2 << pixel_shift) - 2 * sl->mb_linesize,
242 sl->mb_linesize, sl->mb_linesize,
243 16 + 5, 16 + 5 /*FIXME*/, full_mx - 2,
244 full_my - 2, pic_width, pic_height);
245 2076678 src_y = sl->edge_emu_buffer + (2 << pixel_shift) + 2 * sl->mb_linesize;
246 2076678 emu = 1;
247 }
248
249 26349765 qpix_op[luma_xy](dest_y, src_y, sl->mb_linesize); // FIXME try variable height perhaps?
250
2/2
✓ Branch 0 taken 8684604 times.
✓ Branch 1 taken 17665161 times.
26349765 if (!square)
251 8684604 qpix_op[luma_xy](dest_y + delta, src_y + delta, sl->mb_linesize);
252
253 if (CONFIG_GRAY && h->flags & AV_CODEC_FLAG_GRAY)
254 return;
255
256
2/2
✓ Branch 0 taken 157614 times.
✓ Branch 1 taken 26192151 times.
26349765 if (chroma_idc == 3 /* yuv444 */) {
257 157614 src_cb = pic->data[1] + offset;
258
2/2
✓ Branch 0 taken 5488 times.
✓ Branch 1 taken 152126 times.
157614 if (emu) {
259 5488 h->vdsp.emulated_edge_mc(sl->edge_emu_buffer,
260 5488 src_cb - (2 << pixel_shift) - 2 * sl->mb_linesize,
261 sl->mb_linesize, sl->mb_linesize,
262 16 + 5, 16 + 5 /*FIXME*/,
263 full_mx - 2, full_my - 2,
264 pic_width, pic_height);
265 5488 src_cb = sl->edge_emu_buffer + (2 << pixel_shift) + 2 * sl->mb_linesize;
266 }
267 157614 qpix_op[luma_xy](dest_cb, src_cb, sl->mb_linesize); // FIXME try variable height perhaps?
268
2/2
✓ Branch 0 taken 12367 times.
✓ Branch 1 taken 145247 times.
157614 if (!square)
269 12367 qpix_op[luma_xy](dest_cb + delta, src_cb + delta, sl->mb_linesize);
270
271 157614 src_cr = pic->data[2] + offset;
272
2/2
✓ Branch 0 taken 5488 times.
✓ Branch 1 taken 152126 times.
157614 if (emu) {
273 5488 h->vdsp.emulated_edge_mc(sl->edge_emu_buffer,
274 5488 src_cr - (2 << pixel_shift) - 2 * sl->mb_linesize,
275 sl->mb_linesize, sl->mb_linesize,
276 16 + 5, 16 + 5 /*FIXME*/,
277 full_mx - 2, full_my - 2,
278 pic_width, pic_height);
279 5488 src_cr = sl->edge_emu_buffer + (2 << pixel_shift) + 2 * sl->mb_linesize;
280 }
281 157614 qpix_op[luma_xy](dest_cr, src_cr, sl->mb_linesize); // FIXME try variable height perhaps?
282
2/2
✓ Branch 0 taken 12367 times.
✓ Branch 1 taken 145247 times.
157614 if (!square)
283 12367 qpix_op[luma_xy](dest_cr + delta, src_cr + delta, sl->mb_linesize);
284 157614 return;
285 }
286
287
2/2
✓ Branch 0 taken 118650 times.
✓ Branch 1 taken 26073501 times.
26192151 ysh = 3 - (chroma_idc == 2 /* yuv422 */);
288
4/4
✓ Branch 0 taken 26073501 times.
✓ Branch 1 taken 118650 times.
✓ Branch 2 taken 9619572 times.
✓ Branch 3 taken 16453929 times.
26192151 if (chroma_idc == 1 /* yuv420 */ && MB_FIELD(sl)) {
289 // chroma offset when predicting from a field of opposite parity
290 9619572 my += 2 * ((sl->mb_y & 1) - (pic->reference - 1));
291
4/4
✓ Branch 0 taken 9542369 times.
✓ Branch 1 taken 77203 times.
✓ Branch 2 taken 497920 times.
✓ Branch 3 taken 9044449 times.
9619572 emu |= (my >> 3) < 0 || (my >> 3) + 8 >= (pic_height >> 1);
292 }
293
294 26192151 src_cb = pic->data[1] + ((mx >> 3) * (1 << pixel_shift)) +
295 26192151 (my >> ysh) * sl->mb_uvlinesize;
296 26192151 src_cr = pic->data[2] + ((mx >> 3) * (1 << pixel_shift)) +
297 26192151 (my >> ysh) * sl->mb_uvlinesize;
298
299
2/2
✓ Branch 0 taken 2273335 times.
✓ Branch 1 taken 23918816 times.
26192151 if (emu) {
300 2273335 h->vdsp.emulated_edge_mc(sl->edge_emu_buffer, src_cb,
301 sl->mb_uvlinesize, sl->mb_uvlinesize,
302 2273335 9, 8 * chroma_idc + 1, (mx >> 3), (my >> ysh),
303 2273335 pic_width >> 1, pic_height >> (chroma_idc == 1 /* yuv420 */));
304 2273335 src_cb = sl->edge_emu_buffer;
305 }
306 26192151 chroma_op(dest_cb, src_cb, sl->mb_uvlinesize,
307 26192151 height >> (chroma_idc == 1 /* yuv420 */),
308 26192151 mx & 7, ((unsigned)my << (chroma_idc == 2 /* yuv422 */)) & 7);
309
310
2/2
✓ Branch 0 taken 2273335 times.
✓ Branch 1 taken 23918816 times.
26192151 if (emu) {
311 2273335 h->vdsp.emulated_edge_mc(sl->edge_emu_buffer, src_cr,
312 sl->mb_uvlinesize, sl->mb_uvlinesize,
313 2273335 9, 8 * chroma_idc + 1, (mx >> 3), (my >> ysh),
314 2273335 pic_width >> 1, pic_height >> (chroma_idc == 1 /* yuv420 */));
315 2273335 src_cr = sl->edge_emu_buffer;
316 }
317 26192151 chroma_op(dest_cr, src_cr, sl->mb_uvlinesize, height >> (chroma_idc == 1 /* yuv420 */),
318 26192151 mx & 7, ((unsigned)my << (chroma_idc == 2 /* yuv422 */)) & 7);
319 }
320
321 19344240 static av_always_inline void mc_part_std(const H264Context *h, H264SliceContext *sl,
322 int n, int square,
323 int height, int delta,
324 uint8_t *dest_y, uint8_t *dest_cb,
325 uint8_t *dest_cr,
326 int x_offset, int y_offset,
327 const qpel_mc_func *qpix_put,
328 h264_chroma_mc_func chroma_put,
329 const qpel_mc_func *qpix_avg,
330 h264_chroma_mc_func chroma_avg,
331 int list0, int list1,
332 int pixel_shift, int chroma_idc)
333 {
334 19344240 const qpel_mc_func *qpix_op = qpix_put;
335 19344240 h264_chroma_mc_func chroma_op = chroma_put;
336
337 19344240 dest_y += (2 * x_offset << pixel_shift) + 2 * y_offset * sl->mb_linesize;
338
2/2
✓ Branch 0 taken 39229 times.
✓ Branch 1 taken 19305011 times.
19344240 if (chroma_idc == 3 /* yuv444 */) {
339 39229 dest_cb += (2 * x_offset << pixel_shift) + 2 * y_offset * sl->mb_linesize;
340 39229 dest_cr += (2 * x_offset << pixel_shift) + 2 * y_offset * sl->mb_linesize;
341
2/2
✓ Branch 0 taken 98093 times.
✓ Branch 1 taken 19206918 times.
19305011 } else if (chroma_idc == 2 /* yuv422 */) {
342 98093 dest_cb += (x_offset << pixel_shift) + 2 * y_offset * sl->mb_uvlinesize;
343 98093 dest_cr += (x_offset << pixel_shift) + 2 * y_offset * sl->mb_uvlinesize;
344 } else { /* yuv420 */
345 19206918 dest_cb += (x_offset << pixel_shift) + y_offset * sl->mb_uvlinesize;
346 19206918 dest_cr += (x_offset << pixel_shift) + y_offset * sl->mb_uvlinesize;
347 }
348 19344240 x_offset += 8 * sl->mb_x;
349 19344240 y_offset += 8 * (sl->mb_y >> MB_FIELD(sl));
350
351
2/2
✓ Branch 0 taken 17918463 times.
✓ Branch 1 taken 1425777 times.
19344240 if (list0) {
352 17918463 H264Ref *ref = &sl->ref_list[0][sl->ref_cache[0][scan8[n]]];
353 17918463 mc_dir_part(h, sl, ref, n, square, height, delta, 0,
354 dest_y, dest_cb, dest_cr, x_offset, y_offset,
355 qpix_op, chroma_op, pixel_shift, chroma_idc);
356
357 17918463 qpix_op = qpix_avg;
358 17918463 chroma_op = chroma_avg;
359 }
360
361
2/2
✓ Branch 0 taken 6688294 times.
✓ Branch 1 taken 12655946 times.
19344240 if (list1) {
362 6688294 H264Ref *ref = &sl->ref_list[1][sl->ref_cache[1][scan8[n]]];
363 6688294 mc_dir_part(h, sl, ref, n, square, height, delta, 1,
364 dest_y, dest_cb, dest_cr, x_offset, y_offset,
365 qpix_op, chroma_op, pixel_shift, chroma_idc);
366 }
367 19344240 }
368
369 1471331 static av_always_inline void mc_part_weighted(const H264Context *h, H264SliceContext *sl,
370 int n, int square,
371 int height, int delta,
372 uint8_t *dest_y, uint8_t *dest_cb,
373 uint8_t *dest_cr,
374 int x_offset, int y_offset,
375 const qpel_mc_func *qpix_put,
376 h264_chroma_mc_func chroma_put,
377 h264_weight_func luma_weight_op,
378 h264_weight_func chroma_weight_op,
379 h264_biweight_func luma_weight_avg,
380 h264_biweight_func chroma_weight_avg,
381 int list0, int list1,
382 int pixel_shift, int chroma_idc)
383 {
384 int chroma_height;
385
386 1471331 dest_y += (2 * x_offset << pixel_shift) + 2 * y_offset * sl->mb_linesize;
387
2/2
✓ Branch 0 taken 105686 times.
✓ Branch 1 taken 1365645 times.
1471331 if (chroma_idc == 3 /* yuv444 */) {
388 105686 chroma_height = height;
389 105686 chroma_weight_avg = luma_weight_avg;
390 105686 chroma_weight_op = luma_weight_op;
391 105686 dest_cb += (2 * x_offset << pixel_shift) + 2 * y_offset * sl->mb_linesize;
392 105686 dest_cr += (2 * x_offset << pixel_shift) + 2 * y_offset * sl->mb_linesize;
393
2/2
✓ Branch 0 taken 1266 times.
✓ Branch 1 taken 1364379 times.
1365645 } else if (chroma_idc == 2 /* yuv422 */) {
394 1266 chroma_height = height;
395 1266 dest_cb += (x_offset << pixel_shift) + 2 * y_offset * sl->mb_uvlinesize;
396 1266 dest_cr += (x_offset << pixel_shift) + 2 * y_offset * sl->mb_uvlinesize;
397 } else { /* yuv420 */
398 1364379 chroma_height = height >> 1;
399 1364379 dest_cb += (x_offset << pixel_shift) + y_offset * sl->mb_uvlinesize;
400 1364379 dest_cr += (x_offset << pixel_shift) + y_offset * sl->mb_uvlinesize;
401 }
402 1471331 x_offset += 8 * sl->mb_x;
403 1471331 y_offset += 8 * (sl->mb_y >> MB_FIELD(sl));
404
405
4/4
✓ Branch 0 taken 1426543 times.
✓ Branch 1 taken 44788 times.
✓ Branch 2 taken 271677 times.
✓ Branch 3 taken 1154866 times.
1743008 if (list0 && list1) {
406 /* don't optimize for luma-only case, since B-frames usually
407 * use implicit weights => chroma too. */
408 271677 uint8_t *tmp_cb = sl->bipred_scratchpad;
409 271677 uint8_t *tmp_cr = sl->bipred_scratchpad + (16 << pixel_shift);
410 271677 uint8_t *tmp_y = sl->bipred_scratchpad + 16 * sl->mb_uvlinesize;
411 271677 int refn0 = sl->ref_cache[0][scan8[n]];
412 271677 int refn1 = sl->ref_cache[1][scan8[n]];
413
414 271677 mc_dir_part(h, sl, &sl->ref_list[0][refn0], n, square, height, delta, 0,
415 dest_y, dest_cb, dest_cr,
416 x_offset, y_offset, qpix_put, chroma_put,
417 pixel_shift, chroma_idc);
418 271677 mc_dir_part(h, sl, &sl->ref_list[1][refn1], n, square, height, delta, 1,
419 tmp_y, tmp_cb, tmp_cr,
420 x_offset, y_offset, qpix_put, chroma_put,
421 pixel_shift, chroma_idc);
422
423
2/2
✓ Branch 0 taken 221014 times.
✓ Branch 1 taken 50663 times.
271677 if (sl->pwt.use_weight == 2) {
424 221014 int weight0 = sl->pwt.implicit_weight[refn0][refn1][sl->mb_y & 1];
425 221014 int weight1 = 64 - weight0;
426 221014 luma_weight_avg(dest_y, tmp_y, sl->mb_linesize,
427 height, 5, weight0, weight1, 0);
428 if (!CONFIG_GRAY || !(h->flags & AV_CODEC_FLAG_GRAY)) {
429 221014 chroma_weight_avg(dest_cb, tmp_cb, sl->mb_uvlinesize,
430 chroma_height, 5, weight0, weight1, 0);
431 221014 chroma_weight_avg(dest_cr, tmp_cr, sl->mb_uvlinesize,
432 chroma_height, 5, weight0, weight1, 0);
433 }
434 } else {
435 50663 luma_weight_avg(dest_y, tmp_y, sl->mb_linesize, height,
436 sl->pwt.luma_log2_weight_denom,
437 sl->pwt.luma_weight[refn0][0][0],
438 sl->pwt.luma_weight[refn1][1][0],
439 50663 sl->pwt.luma_weight[refn0][0][1] +
440 50663 sl->pwt.luma_weight[refn1][1][1]);
441 if (!CONFIG_GRAY || !(h->flags & AV_CODEC_FLAG_GRAY)) {
442 50663 chroma_weight_avg(dest_cb, tmp_cb, sl->mb_uvlinesize, chroma_height,
443 sl->pwt.chroma_log2_weight_denom,
444 sl->pwt.chroma_weight[refn0][0][0][0],
445 sl->pwt.chroma_weight[refn1][1][0][0],
446 50663 sl->pwt.chroma_weight[refn0][0][0][1] +
447 50663 sl->pwt.chroma_weight[refn1][1][0][1]);
448 50663 chroma_weight_avg(dest_cr, tmp_cr, sl->mb_uvlinesize, chroma_height,
449 sl->pwt.chroma_log2_weight_denom,
450 sl->pwt.chroma_weight[refn0][0][1][0],
451 sl->pwt.chroma_weight[refn1][1][1][0],
452 50663 sl->pwt.chroma_weight[refn0][0][1][1] +
453 50663 sl->pwt.chroma_weight[refn1][1][1][1]);
454 }
455 }
456 } else {
457 1199654 int list = list1 ? 1 : 0;
458 1199654 int refn = sl->ref_cache[list][scan8[n]];
459 1199654 H264Ref *ref = &sl->ref_list[list][refn];
460 1199654 mc_dir_part(h, sl, ref, n, square, height, delta, list,
461 dest_y, dest_cb, dest_cr, x_offset, y_offset,
462 qpix_put, chroma_put, pixel_shift, chroma_idc);
463
464 1199654 luma_weight_op(dest_y, sl->mb_linesize, height,
465 sl->pwt.luma_log2_weight_denom,
466 sl->pwt.luma_weight[refn][list][0],
467 sl->pwt.luma_weight[refn][list][1]);
468 if (!CONFIG_GRAY || !(h->flags & AV_CODEC_FLAG_GRAY)) {
469
2/2
✓ Branch 0 taken 542457 times.
✓ Branch 1 taken 657197 times.
1199654 if (sl->pwt.use_weight_chroma) {
470 542457 chroma_weight_op(dest_cb, sl->mb_uvlinesize, chroma_height,
471 sl->pwt.chroma_log2_weight_denom,
472 sl->pwt.chroma_weight[refn][list][0][0],
473 sl->pwt.chroma_weight[refn][list][0][1]);
474 542457 chroma_weight_op(dest_cr, sl->mb_uvlinesize, chroma_height,
475 sl->pwt.chroma_log2_weight_denom,
476 sl->pwt.chroma_weight[refn][list][1][0],
477 sl->pwt.chroma_weight[refn][list][1][1]);
478 }
479 }
480 }
481 1471331 }
482
483 13397638 static av_always_inline void prefetch_motion(const H264Context *h, H264SliceContext *sl,
484 int list, int pixel_shift,
485 int chroma_idc)
486 {
487 /* fetch pixels for estimated mv 4 macroblocks ahead
488 * optimized for 64byte cache lines */
489 13397638 const int refn = sl->ref_cache[list][scan8[0]];
490
2/2
✓ Branch 0 taken 13028339 times.
✓ Branch 1 taken 369299 times.
13397638 if (refn >= 0) {
491 13028339 const int mx = (sl->mv_cache[list][scan8[0]][0] >> 2) + 16 * sl->mb_x + 8;
492 13028339 const int my = (sl->mv_cache[list][scan8[0]][1] >> 2) + 16 * sl->mb_y;
493 13028339 uint8_t **src = sl->ref_list[list][refn].data;
494 13028339 int off = mx * (1<< pixel_shift) +
495 13028339 (my + (sl->mb_x & 3) * 4) * sl->mb_linesize +
496 13028339 (64 << pixel_shift);
497 13028339 h->vdsp.prefetch(src[0] + off, sl->linesize, 4);
498
2/2
✓ Branch 0 taken 132628 times.
✓ Branch 1 taken 12895711 times.
13028339 if (chroma_idc == 3 /* yuv444 */) {
499 132628 h->vdsp.prefetch(src[1] + off, sl->linesize, 4);
500 132628 h->vdsp.prefetch(src[2] + off, sl->linesize, 4);
501 } else {
502 12895711 off= ((mx>>1)+64) * (1<<pixel_shift) + ((my>>1) + (sl->mb_x&7))*sl->uvlinesize;
503 12895711 h->vdsp.prefetch(src[1] + off, src[2] - src[1], 2);
504 }
505 }
506 13397638 }
507
508 6384944 static av_always_inline void xchg_mb_border(const H264Context *h, H264SliceContext *sl,
509 uint8_t *src_y,
510 uint8_t *src_cb, uint8_t *src_cr,
511 int linesize, int uvlinesize,
512 int xchg, int chroma444,
513 int simple, int pixel_shift)
514 {
515 int deblock_topleft;
516 int deblock_top;
517 6384944 int top_idx = 1;
518 uint8_t *top_border_m1;
519 uint8_t *top_border;
520
521
4/4
✓ Branch 0 taken 2846268 times.
✓ Branch 1 taken 3538676 times.
✓ Branch 2 taken 1785962 times.
✓ Branch 3 taken 1060306 times.
6384944 if (!simple && FRAME_MBAFF(h)) {
522
2/2
✓ Branch 0 taken 897060 times.
✓ Branch 1 taken 888902 times.
1785962 if (sl->mb_y & 1) {
523
2/2
✓ Branch 0 taken 689044 times.
✓ Branch 1 taken 208016 times.
897060 if (!MB_MBAFF(sl))
524 689044 return;
525 } else {
526 888902 top_idx = MB_MBAFF(sl) ? 0 : 1;
527 }
528 }
529
530
2/2
✓ Branch 0 taken 60068 times.
✓ Branch 1 taken 5635832 times.
5695900 if (sl->deblocking_filter == 2) {
531 60068 deblock_topleft = h->slice_table[sl->mb_xy - 1 - h->mb_stride] == sl->slice_num;
532 60068 deblock_top = sl->top_type;
533 } else {
534 5635832 deblock_topleft = (sl->mb_x > 0);
535 5635832 deblock_top = (sl->mb_y > !!MB_FIELD(sl));
536 }
537
538 5695900 src_y -= linesize + 1 + pixel_shift;
539 5695900 src_cb -= uvlinesize + 1 + pixel_shift;
540 5695900 src_cr -= uvlinesize + 1 + pixel_shift;
541
542 5695900 top_border_m1 = sl->top_borders[top_idx][sl->mb_x - 1];
543 5695900 top_border = sl->top_borders[top_idx][sl->mb_x];
544
545 #define XCHG(a, b, xchg) \
546 if (pixel_shift) { \
547 if (xchg) { \
548 AV_SWAP64(b + 0, a + 0); \
549 AV_SWAP64(b + 8, a + 8); \
550 } else { \
551 AV_COPY128(b, a); \
552 } \
553 } else if (xchg) \
554 AV_SWAP64(b, a); \
555 else \
556 AV_COPY64(b, a);
557
558
2/2
✓ Branch 0 taken 5470584 times.
✓ Branch 1 taken 225316 times.
5695900 if (deblock_top) {
559
2/2
✓ Branch 0 taken 5368440 times.
✓ Branch 1 taken 102144 times.
5470584 if (deblock_topleft) {
560
2/2
✓ Branch 0 taken 2261358 times.
✓ Branch 1 taken 3107082 times.
5368440 XCHG(top_border_m1 + (8 << pixel_shift),
561 src_y - (7 << pixel_shift), 1);
562 }
563
6/6
✓ Branch 0 taken 2282586 times.
✓ Branch 1 taken 3187998 times.
✓ Branch 2 taken 1141293 times.
✓ Branch 3 taken 1141293 times.
✓ Branch 5 taken 1593999 times.
✓ Branch 6 taken 1593999 times.
5470584 XCHG(top_border + (0 << pixel_shift), src_y + (1 << pixel_shift), xchg);
564
2/2
✓ Branch 0 taken 2282586 times.
✓ Branch 1 taken 3187998 times.
5470584 XCHG(top_border + (8 << pixel_shift), src_y + (9 << pixel_shift), 1);
565
2/2
✓ Branch 0 taken 5349394 times.
✓ Branch 1 taken 121190 times.
5470584 if (sl->mb_x + 1 < h->mb_width) {
566
2/2
✓ Branch 0 taken 2260120 times.
✓ Branch 1 taken 3089274 times.
5349394 XCHG(sl->top_borders[top_idx][sl->mb_x + 1],
567 src_y + (17 << pixel_shift), 1);
568 }
569 if (simple || !CONFIG_GRAY || !(h->flags & AV_CODEC_FLAG_GRAY)) {
570
2/2
✓ Branch 0 taken 121572 times.
✓ Branch 1 taken 5349012 times.
5470584 if (chroma444) {
571
2/2
✓ Branch 0 taken 120330 times.
✓ Branch 1 taken 1242 times.
121572 if (deblock_topleft) {
572
2/2
✓ Branch 0 taken 2252 times.
✓ Branch 1 taken 118078 times.
120330 XCHG(top_border_m1 + (24 << pixel_shift), src_cb - (7 << pixel_shift), 1);
573
2/2
✓ Branch 0 taken 2252 times.
✓ Branch 1 taken 118078 times.
120330 XCHG(top_border_m1 + (40 << pixel_shift), src_cr - (7 << pixel_shift), 1);
574 }
575
6/6
✓ Branch 0 taken 2392 times.
✓ Branch 1 taken 119180 times.
✓ Branch 2 taken 1196 times.
✓ Branch 3 taken 1196 times.
✓ Branch 5 taken 59590 times.
✓ Branch 6 taken 59590 times.
121572 XCHG(top_border + (16 << pixel_shift), src_cb + (1 << pixel_shift), xchg);
576
2/2
✓ Branch 0 taken 2392 times.
✓ Branch 1 taken 119180 times.
121572 XCHG(top_border + (24 << pixel_shift), src_cb + (9 << pixel_shift), 1);
577
6/6
✓ Branch 0 taken 2392 times.
✓ Branch 1 taken 119180 times.
✓ Branch 2 taken 1196 times.
✓ Branch 3 taken 1196 times.
✓ Branch 5 taken 59590 times.
✓ Branch 6 taken 59590 times.
121572 XCHG(top_border + (32 << pixel_shift), src_cr + (1 << pixel_shift), xchg);
578
2/2
✓ Branch 0 taken 2392 times.
✓ Branch 1 taken 119180 times.
121572 XCHG(top_border + (40 << pixel_shift), src_cr + (9 << pixel_shift), 1);
579
2/2
✓ Branch 0 taken 120314 times.
✓ Branch 1 taken 1258 times.
121572 if (sl->mb_x + 1 < h->mb_width) {
580
2/2
✓ Branch 0 taken 2234 times.
✓ Branch 1 taken 118080 times.
120314 XCHG(sl->top_borders[top_idx][sl->mb_x + 1] + (16 << pixel_shift), src_cb + (17 << pixel_shift), 1);
581
2/2
✓ Branch 0 taken 2234 times.
✓ Branch 1 taken 118080 times.
120314 XCHG(sl->top_borders[top_idx][sl->mb_x + 1] + (32 << pixel_shift), src_cr + (17 << pixel_shift), 1);
582 }
583 } else {
584
2/2
✓ Branch 0 taken 5248110 times.
✓ Branch 1 taken 100902 times.
5349012 if (deblock_topleft) {
585
2/2
✓ Branch 0 taken 2259106 times.
✓ Branch 1 taken 2989004 times.
5248110 XCHG(top_border_m1 + (16 << pixel_shift), src_cb - (7 << pixel_shift), 1);
586
2/2
✓ Branch 0 taken 2259106 times.
✓ Branch 1 taken 2989004 times.
5248110 XCHG(top_border_m1 + (24 << pixel_shift), src_cr - (7 << pixel_shift), 1);
587 }
588
2/2
✓ Branch 0 taken 2280194 times.
✓ Branch 1 taken 3068818 times.
5349012 XCHG(top_border + (16 << pixel_shift), src_cb + 1 + pixel_shift, 1);
589
2/2
✓ Branch 0 taken 2280194 times.
✓ Branch 1 taken 3068818 times.
5349012 XCHG(top_border + (24 << pixel_shift), src_cr + 1 + pixel_shift, 1);
590 }
591 }
592 }
593 }
594
595 4202000 static av_always_inline int dctcoef_get(int16_t *mb, int high_bit_depth,
596 int index)
597 {
598
2/2
✓ Branch 0 taken 1113043 times.
✓ Branch 1 taken 3088957 times.
4202000 if (high_bit_depth) {
599 1113043 return AV_RN32A(((int32_t *)mb) + index);
600 } else
601 3088957 return AV_RN16A(mb + index);
602 }
603
604 9792 static av_always_inline void dctcoef_set(int16_t *mb, int high_bit_depth,
605 int index, int value)
606 {
607
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9792 times.
9792 if (high_bit_depth) {
608 AV_WN32A(((int32_t *)mb) + index, value);
609 } else
610 9792 AV_WN16A(mb + index, value);
611 9792 }
612
613 3950561 static av_always_inline void hl_decode_mb_predict_luma(const H264Context *h,
614 H264SliceContext *sl,
615 int mb_type, int simple,
616 int transform_bypass,
617 int pixel_shift,
618 const int *block_offset,
619 int linesize,
620 uint8_t *dest_y, int p)
621 {
622 void (*idct_add)(uint8_t *dst, int16_t *block, int stride);
623 void (*idct_dc_add)(uint8_t *dst, int16_t *block, int stride);
624 int i;
625
2/2
✓ Branch 0 taken 3817693 times.
✓ Branch 1 taken 132868 times.
3950561 int qscale = p == 0 ? sl->qscale : sl->chroma_qp[p - 1];
626 3950561 block_offset += 16 * p;
627
2/2
✓ Branch 0 taken 3085549 times.
✓ Branch 1 taken 865012 times.
3950561 if (IS_INTRA4x4(mb_type)) {
628
2/2
✓ Branch 0 taken 1615320 times.
✓ Branch 1 taken 1470229 times.
3085549 if (IS_8x8DCT(mb_type)) {
629
2/2
✓ Branch 0 taken 660 times.
✓ Branch 1 taken 1614660 times.
1615320 if (transform_bypass) {
630 660 idct_dc_add =
631 660 idct_add = h->h264dsp.h264_add_pixels8_clear;
632 } else {
633 1614660 idct_dc_add = h->h264dsp.h264_idct8_dc_add;
634 1614660 idct_add = h->h264dsp.h264_idct8_add;
635 }
636
2/2
✓ Branch 0 taken 6461280 times.
✓ Branch 1 taken 1615320 times.
8076600 for (i = 0; i < 16; i += 4) {
637 6461280 uint8_t *const ptr = dest_y + block_offset[i];
638 6461280 const int dir = sl->intra4x4_pred_mode_cache[scan8[i]];
639
5/6
✓ Branch 0 taken 2640 times.
✓ Branch 1 taken 6458640 times.
✓ Branch 2 taken 2640 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2488 times.
✓ Branch 5 taken 152 times.
6461280 if (transform_bypass && h->ps.sps->profile_idc == 244 && dir <= 1) {
640
1/2
✓ Branch 0 taken 2488 times.
✗ Branch 1 not taken.
2488 if (h->x264_build < 151U) {
641 2488 h->hpc.pred8x8l_add[dir](ptr, sl->mb + (i * 16 + p * 256 << pixel_shift), linesize);
642 } else
643 h->hpc.pred8x8l_filter_add[dir](ptr, sl->mb + (i * 16 + p * 256 << pixel_shift),
644 (sl-> topleft_samples_available << i) & 0x8000,
645 (sl->topright_samples_available << i) & 0x4000, linesize);
646 } else {
647 6458792 const int nnz = sl->non_zero_count_cache[scan8[i + p * 16]];
648 6458792 h->hpc.pred8x8l[dir](ptr, (sl->topleft_samples_available << i) & 0x8000,
649 6458792 (sl->topright_samples_available << i) & 0x4000, linesize);
650
2/2
✓ Branch 0 taken 5081028 times.
✓ Branch 1 taken 1377764 times.
6458792 if (nnz) {
651
4/4
✓ Branch 0 taken 554750 times.
✓ Branch 1 taken 4526278 times.
✓ Branch 3 taken 246537 times.
✓ Branch 4 taken 308213 times.
5081028 if (nnz == 1 && dctcoef_get(sl->mb, pixel_shift, i * 16 + p * 256))
652 246537 idct_dc_add(ptr, sl->mb + (i * 16 + p * 256 << pixel_shift), linesize);
653 else
654 4834491 idct_add(ptr, sl->mb + (i * 16 + p * 256 << pixel_shift), linesize);
655 }
656 }
657 }
658 } else {
659
2/2
✓ Branch 0 taken 15230 times.
✓ Branch 1 taken 1454999 times.
1470229 if (transform_bypass) {
660 15230 idct_dc_add =
661 15230 idct_add = h->h264dsp.h264_add_pixels4_clear;
662 } else {
663 1454999 idct_dc_add = h->h264dsp.h264_idct_dc_add;
664 1454999 idct_add = h->h264dsp.h264_idct_add;
665 }
666
2/2
✓ Branch 0 taken 23523664 times.
✓ Branch 1 taken 1470229 times.
24993893 for (i = 0; i < 16; i++) {
667 23523664 uint8_t *const ptr = dest_y + block_offset[i];
668 23523664 const int dir = sl->intra4x4_pred_mode_cache[scan8[i]];
669
670
5/6
✓ Branch 0 taken 243680 times.
✓ Branch 1 taken 23279984 times.
✓ Branch 2 taken 243680 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 180369 times.
✓ Branch 5 taken 63311 times.
23523664 if (transform_bypass && h->ps.sps->profile_idc == 244 && dir <= 1) {
671 180369 h->hpc.pred4x4_add[dir](ptr, sl->mb + (i * 16 + p * 256 << pixel_shift), linesize);
672 } else {
673 uint8_t *topright;
674 int nnz, tr;
675 uint64_t tr_high;
676
4/4
✓ Branch 0 taken 22212973 times.
✓ Branch 1 taken 1130322 times.
✓ Branch 2 taken 1084575 times.
✓ Branch 3 taken 21128398 times.
25558192 if (dir == DIAG_DOWN_LEFT_PRED || dir == VERT_LEFT_PRED) {
677 2214897 const int topright_avail = (sl->topright_samples_available << i) & 0x8000;
678 av_assert2(sl->mb_y || linesize <= block_offset[i]);
679
2/2
✓ Branch 0 taken 615172 times.
✓ Branch 1 taken 1599725 times.
2214897 if (!topright_avail) {
680
2/2
✓ Branch 0 taken 246620 times.
✓ Branch 1 taken 368552 times.
615172 if (pixel_shift) {
681 246620 tr_high = ((uint16_t *)ptr)[3 - linesize / 2] * 0x0001000100010001ULL;
682 246620 topright = (uint8_t *)&tr_high;
683 } else {
684 368552 tr = ptr[3 - linesize] * 0x01010101u;
685 368552 topright = (uint8_t *)&tr;
686 }
687 } else
688 1599725 topright = ptr + (4 << pixel_shift) - linesize;
689 } else
690 21128398 topright = NULL;
691
692 23343295 h->hpc.pred4x4[dir](ptr, topright, linesize);
693 23343295 nnz = sl->non_zero_count_cache[scan8[i + p * 16]];
694
2/2
✓ Branch 0 taken 16147492 times.
✓ Branch 1 taken 7195803 times.
23343295 if (nnz) {
695
4/4
✓ Branch 0 taken 3604013 times.
✓ Branch 1 taken 12543479 times.
✓ Branch 3 taken 2056633 times.
✓ Branch 4 taken 1547380 times.
16147492 if (nnz == 1 && dctcoef_get(sl->mb, pixel_shift, i * 16 + p * 256))
696 2056633 idct_dc_add(ptr, sl->mb + (i * 16 + p * 256 << pixel_shift), linesize);
697 else
698 14090859 idct_add(ptr, sl->mb + (i * 16 + p * 256 << pixel_shift), linesize);
699 }
700 }
701 }
702 }
703 } else {
704 865012 h->hpc.pred16x16[sl->intra16x16_pred_mode](dest_y, linesize);
705
2/2
✓ Branch 0 taken 580046 times.
✓ Branch 1 taken 284966 times.
865012 if (sl->non_zero_count_cache[scan8[LUMA_DC_BLOCK_INDEX + p]]) {
706
2/2
✓ Branch 0 taken 579434 times.
✓ Branch 1 taken 612 times.
580046 if (!transform_bypass)
707 579434 h->h264dsp.h264_luma_dc_dequant_idct(sl->mb + (p * 256 << pixel_shift),
708 579434 sl->mb_luma_dc[p],
709 579434 h->ps.pps->dequant4_coeff[p][qscale][0]);
710 else {
711 static const uint8_t dc_mapping[16] = {
712 0 * 16, 1 * 16, 4 * 16, 5 * 16,
713 2 * 16, 3 * 16, 6 * 16, 7 * 16,
714 8 * 16, 9 * 16, 12 * 16, 13 * 16,
715 10 * 16, 11 * 16, 14 * 16, 15 * 16
716 };
717
2/2
✓ Branch 0 taken 9792 times.
✓ Branch 1 taken 612 times.
10404 for (i = 0; i < 16; i++)
718 19584 dctcoef_set(sl->mb + (p * 256 << pixel_shift),
719 9792 pixel_shift, dc_mapping[i],
720 9792 dctcoef_get(sl->mb_luma_dc[p],
721 pixel_shift, i));
722 }
723 }
724 }
725 3950561 }
726
727 14131642 static av_always_inline void hl_decode_mb_idct_luma(const H264Context *h, H264SliceContext *sl,
728 int mb_type, int simple,
729 int transform_bypass,
730 int pixel_shift,
731 const int *block_offset,
732 int linesize,
733 uint8_t *dest_y, int p)
734 {
735 void (*idct_add)(uint8_t *dst, int16_t *block, int stride);
736 int i;
737 14131642 block_offset += 16 * p;
738
2/2
✓ Branch 0 taken 11046093 times.
✓ Branch 1 taken 3085549 times.
14131642 if (!IS_INTRA4x4(mb_type)) {
739
2/2
✓ Branch 0 taken 865012 times.
✓ Branch 1 taken 10181081 times.
11046093 if (IS_INTRA16x16(mb_type)) {
740
2/2
✓ Branch 0 taken 864 times.
✓ Branch 1 taken 864148 times.
865012 if (transform_bypass) {
741
1/2
✓ Branch 0 taken 864 times.
✗ Branch 1 not taken.
864 if (h->ps.sps->profile_idc == 244 &&
742
2/2
✓ Branch 0 taken 502 times.
✓ Branch 1 taken 362 times.
864 (sl->intra16x16_pred_mode == VERT_PRED8x8 ||
743
2/2
✓ Branch 0 taken 278 times.
✓ Branch 1 taken 224 times.
502 sl->intra16x16_pred_mode == HOR_PRED8x8)) {
744 640 h->hpc.pred16x16_add[sl->intra16x16_pred_mode](dest_y, block_offset,
745 640 sl->mb + (p * 256 << pixel_shift),
746 linesize);
747 } else {
748
2/2
✓ Branch 0 taken 3584 times.
✓ Branch 1 taken 224 times.
3808 for (i = 0; i < 16; i++)
749
3/4
✓ Branch 0 taken 40 times.
✓ Branch 1 taken 3544 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 40 times.
3624 if (sl->non_zero_count_cache[scan8[i + p * 16]] ||
750 40 dctcoef_get(sl->mb, pixel_shift, i * 16 + p * 256))
751 3544 h->h264dsp.h264_add_pixels4_clear(dest_y + block_offset[i],
752 3544 sl->mb + (i * 16 + p * 256 << pixel_shift),
753 linesize);
754 }
755 } else {
756 864148 h->h264dsp.h264_idct_add16intra(dest_y, block_offset,
757 864148 sl->mb + (p * 256 << pixel_shift),
758 linesize,
759 864148 sl->non_zero_count_cache + p * 5 * 8);
760 }
761
2/2
✓ Branch 0 taken 5873133 times.
✓ Branch 1 taken 4307948 times.
10181081 } else if (sl->cbp & 15) {
762
2/2
✓ Branch 0 taken 339104 times.
✓ Branch 1 taken 5534029 times.
5873133 if (transform_bypass) {
763
2/2
✓ Branch 0 taken 17071 times.
✓ Branch 1 taken 322033 times.
339104 const int di = IS_8x8DCT(mb_type) ? 4 : 1;
764 678208 idct_add = IS_8x8DCT(mb_type) ? h->h264dsp.h264_add_pixels8_clear
765
2/2
✓ Branch 0 taken 17071 times.
✓ Branch 1 taken 322033 times.
339104 : h->h264dsp.h264_add_pixels4_clear;
766
2/2
✓ Branch 0 taken 5220812 times.
✓ Branch 1 taken 339104 times.
5559916 for (i = 0; i < 16; i += di)
767
2/2
✓ Branch 0 taken 722104 times.
✓ Branch 1 taken 4498708 times.
5220812 if (sl->non_zero_count_cache[scan8[i + p * 16]])
768 722104 idct_add(dest_y + block_offset[i],
769 722104 sl->mb + (i * 16 + p * 256 << pixel_shift),
770 linesize);
771 } else {
772
2/2
✓ Branch 0 taken 918176 times.
✓ Branch 1 taken 4615853 times.
5534029 if (IS_8x8DCT(mb_type))
773 918176 h->h264dsp.h264_idct8_add4(dest_y, block_offset,
774 918176 sl->mb + (p * 256 << pixel_shift),
775 linesize,
776 918176 sl->non_zero_count_cache + p * 5 * 8);
777 else
778 4615853 h->h264dsp.h264_idct_add16(dest_y, block_offset,
779 4615853 sl->mb + (p * 256 << pixel_shift),
780 linesize,
781 4615853 sl->non_zero_count_cache + p * 5 * 8);
782 }
783 }
784 }
785 14131642 }
786
787 #define BITS 8
788 #define SIMPLE 1
789 #include "h264_mb_template.c"
790
791 #undef BITS
792 #define BITS 16
793 #include "h264_mb_template.c"
794
795 #undef SIMPLE
796 #define SIMPLE 0
797 #include "h264_mb_template.c"
798
799 13769431 void ff_h264_hl_decode_mb(const H264Context *h, H264SliceContext *sl)
800 {
801 13769431 const int mb_xy = sl->mb_xy;
802 13769431 const int mb_type = h->cur_pic.mb_type[mb_xy];
803 34708300 int is_complex = CONFIG_SMALL || sl->is_complex ||
804
6/6
✓ Branch 0 taken 7169438 times.
✓ Branch 1 taken 6599993 times.
✓ Branch 2 taken 7146333 times.
✓ Branch 3 taken 23105 times.
✓ Branch 4 taken 136878 times.
✓ Branch 5 taken 7009455 times.
13769431 IS_INTRA_PCM(mb_type) || sl->qscale == 0;
805
806
2/2
✓ Branch 0 taken 192658 times.
✓ Branch 1 taken 13576773 times.
13769431 if (CHROMA444(h)) {
807
4/4
✓ Branch 0 taken 79866 times.
✓ Branch 1 taken 112792 times.
✓ Branch 2 taken 19800 times.
✓ Branch 3 taken 60066 times.
192658 if (is_complex || h->pixel_shift)
808 132592 hl_decode_mb_444_complex(h, sl);
809 else
810 60066 hl_decode_mb_444_simple_8(h, sl);
811
2/2
✓ Branch 0 taken 6647184 times.
✓ Branch 1 taken 6929589 times.
13576773 } else if (is_complex) {
812 6647184 hl_decode_mb_complex(h, sl);
813
2/2
✓ Branch 0 taken 1065720 times.
✓ Branch 1 taken 5863869 times.
6929589 } else if (h->pixel_shift) {
814 1065720 hl_decode_mb_simple_16(h, sl);
815 } else
816 5863869 hl_decode_mb_simple_8(h, sl);
817 13769431 }
818