FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/h264_cavlc.c
Date: 2021-09-22 05:58:22
Exec Total Coverage
Lines: 457 507 90.1%
Branches: 347 384 90.4%

Line Branch Exec Source
1 /*
2 * H.26L/H.264/AVC/JVT/14496-10/... cavlc bitstream decoding
3 * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 /**
23 * @file
24 * H.264 / AVC / MPEG-4 part10 cavlc bitstream decoding.
25 * @author Michael Niedermayer <michaelni@gmx.at>
26 */
27
28 #define CABAC(h) 0
29 #define UNCHECKED_BITSTREAM_READER 1
30
31 #include "internal.h"
32 #include "h264dec.h"
33 #include "h264_mvpred.h"
34 #include "h264data.h"
35 #include "golomb.h"
36 #include "mpegutils.h"
37 #include "libavutil/avassert.h"
38
39
40 static const uint8_t golomb_to_inter_cbp_gray[16]={
41 0, 1, 2, 4, 8, 3, 5,10,12,15, 7,11,13,14, 6, 9,
42 };
43
44 static const uint8_t golomb_to_intra4x4_cbp_gray[16]={
45 15, 0, 7,11,13,14, 3, 5,10,12, 1, 2, 4, 8, 6, 9,
46 };
47
48 static const uint8_t chroma_dc_coeff_token_len[4*5]={
49 2, 0, 0, 0,
50 6, 1, 0, 0,
51 6, 6, 3, 0,
52 6, 7, 7, 6,
53 6, 8, 8, 7,
54 };
55
56 static const uint8_t chroma_dc_coeff_token_bits[4*5]={
57 1, 0, 0, 0,
58 7, 1, 0, 0,
59 4, 6, 1, 0,
60 3, 3, 2, 5,
61 2, 3, 2, 0,
62 };
63
64 static const uint8_t chroma422_dc_coeff_token_len[4*9]={
65 1, 0, 0, 0,
66 7, 2, 0, 0,
67 7, 7, 3, 0,
68 9, 7, 7, 5,
69 9, 9, 7, 6,
70 10, 10, 9, 7,
71 11, 11, 10, 7,
72 12, 12, 11, 10,
73 13, 12, 12, 11,
74 };
75
76 static const uint8_t chroma422_dc_coeff_token_bits[4*9]={
77 1, 0, 0, 0,
78 15, 1, 0, 0,
79 14, 13, 1, 0,
80 7, 12, 11, 1,
81 6, 5, 10, 1,
82 7, 6, 4, 9,
83 7, 6, 5, 8,
84 7, 6, 5, 4,
85 7, 5, 4, 4,
86 };
87
88 static const uint8_t coeff_token_len[4][4*17]={
89 {
90 1, 0, 0, 0,
91 6, 2, 0, 0, 8, 6, 3, 0, 9, 8, 7, 5, 10, 9, 8, 6,
92 11,10, 9, 7, 13,11,10, 8, 13,13,11, 9, 13,13,13,10,
93 14,14,13,11, 14,14,14,13, 15,15,14,14, 15,15,15,14,
94 16,15,15,15, 16,16,16,15, 16,16,16,16, 16,16,16,16,
95 },
96 {
97 2, 0, 0, 0,
98 6, 2, 0, 0, 6, 5, 3, 0, 7, 6, 6, 4, 8, 6, 6, 4,
99 8, 7, 7, 5, 9, 8, 8, 6, 11, 9, 9, 6, 11,11,11, 7,
100 12,11,11, 9, 12,12,12,11, 12,12,12,11, 13,13,13,12,
101 13,13,13,13, 13,14,13,13, 14,14,14,13, 14,14,14,14,
102 },
103 {
104 4, 0, 0, 0,
105 6, 4, 0, 0, 6, 5, 4, 0, 6, 5, 5, 4, 7, 5, 5, 4,
106 7, 5, 5, 4, 7, 6, 6, 4, 7, 6, 6, 4, 8, 7, 7, 5,
107 8, 8, 7, 6, 9, 8, 8, 7, 9, 9, 8, 8, 9, 9, 9, 8,
108 10, 9, 9, 9, 10,10,10,10, 10,10,10,10, 10,10,10,10,
109 },
110 {
111 6, 0, 0, 0,
112 6, 6, 0, 0, 6, 6, 6, 0, 6, 6, 6, 6, 6, 6, 6, 6,
113 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
114 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
115 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
116 }
117 };
118
119 static const uint8_t coeff_token_bits[4][4*17]={
120 {
121 1, 0, 0, 0,
122 5, 1, 0, 0, 7, 4, 1, 0, 7, 6, 5, 3, 7, 6, 5, 3,
123 7, 6, 5, 4, 15, 6, 5, 4, 11,14, 5, 4, 8,10,13, 4,
124 15,14, 9, 4, 11,10,13,12, 15,14, 9,12, 11,10,13, 8,
125 15, 1, 9,12, 11,14,13, 8, 7,10, 9,12, 4, 6, 5, 8,
126 },
127 {
128 3, 0, 0, 0,
129 11, 2, 0, 0, 7, 7, 3, 0, 7,10, 9, 5, 7, 6, 5, 4,
130 4, 6, 5, 6, 7, 6, 5, 8, 15, 6, 5, 4, 11,14,13, 4,
131 15,10, 9, 4, 11,14,13,12, 8,10, 9, 8, 15,14,13,12,
132 11,10, 9,12, 7,11, 6, 8, 9, 8,10, 1, 7, 6, 5, 4,
133 },
134 {
135 15, 0, 0, 0,
136 15,14, 0, 0, 11,15,13, 0, 8,12,14,12, 15,10,11,11,
137 11, 8, 9,10, 9,14,13, 9, 8,10, 9, 8, 15,14,13,13,
138 11,14,10,12, 15,10,13,12, 11,14, 9,12, 8,10,13, 8,
139 13, 7, 9,12, 9,12,11,10, 5, 8, 7, 6, 1, 4, 3, 2,
140 },
141 {
142 3, 0, 0, 0,
143 0, 1, 0, 0, 4, 5, 6, 0, 8, 9,10,11, 12,13,14,15,
144 16,17,18,19, 20,21,22,23, 24,25,26,27, 28,29,30,31,
145 32,33,34,35, 36,37,38,39, 40,41,42,43, 44,45,46,47,
146 48,49,50,51, 52,53,54,55, 56,57,58,59, 60,61,62,63,
147 }
148 };
149
150 static const uint8_t total_zeros_len[16][16]= {
151 {1,3,3,4,4,5,5,6,6,7,7,8,8,9,9,9},
152 {3,3,3,3,3,4,4,4,4,5,5,6,6,6,6},
153 {4,3,3,3,4,4,3,3,4,5,5,6,5,6},
154 {5,3,4,4,3,3,3,4,3,4,5,5,5},
155 {4,4,4,3,3,3,3,3,4,5,4,5},
156 {6,5,3,3,3,3,3,3,4,3,6},
157 {6,5,3,3,3,2,3,4,3,6},
158 {6,4,5,3,2,2,3,3,6},
159 {6,6,4,2,2,3,2,5},
160 {5,5,3,2,2,2,4},
161 {4,4,3,3,1,3},
162 {4,4,2,1,3},
163 {3,3,1,2},
164 {2,2,1},
165 {1,1},
166 };
167
168 static const uint8_t total_zeros_bits[16][16]= {
169 {1,3,2,3,2,3,2,3,2,3,2,3,2,3,2,1},
170 {7,6,5,4,3,5,4,3,2,3,2,3,2,1,0},
171 {5,7,6,5,4,3,4,3,2,3,2,1,1,0},
172 {3,7,5,4,6,5,4,3,3,2,2,1,0},
173 {5,4,3,7,6,5,4,3,2,1,1,0},
174 {1,1,7,6,5,4,3,2,1,1,0},
175 {1,1,5,4,3,3,2,1,1,0},
176 {1,1,1,3,3,2,2,1,0},
177 {1,0,1,3,2,1,1,1},
178 {1,0,1,3,2,1,1},
179 {0,1,1,2,1,3},
180 {0,1,1,1,1},
181 {0,1,1,1},
182 {0,1,1},
183 {0,1},
184 };
185
186 static const uint8_t chroma_dc_total_zeros_len[3][4]= {
187 { 1, 2, 3, 3,},
188 { 1, 2, 2, 0,},
189 { 1, 1, 0, 0,},
190 };
191
192 static const uint8_t chroma_dc_total_zeros_bits[3][4]= {
193 { 1, 1, 1, 0,},
194 { 1, 1, 0, 0,},
195 { 1, 0, 0, 0,},
196 };
197
198 static const uint8_t chroma422_dc_total_zeros_len[7][8]= {
199 { 1, 3, 3, 4, 4, 4, 5, 5 },
200 { 3, 2, 3, 3, 3, 3, 3 },
201 { 3, 3, 2, 2, 3, 3 },
202 { 3, 2, 2, 2, 3 },
203 { 2, 2, 2, 2 },
204 { 2, 2, 1 },
205 { 1, 1 },
206 };
207
208 static const uint8_t chroma422_dc_total_zeros_bits[7][8]= {
209 { 1, 2, 3, 2, 3, 1, 1, 0 },
210 { 0, 1, 1, 4, 5, 6, 7 },
211 { 0, 1, 1, 2, 6, 7 },
212 { 6, 0, 1, 2, 7 },
213 { 0, 1, 2, 3 },
214 { 0, 1, 1 },
215 { 0, 1 },
216 };
217
218 static const uint8_t run_len[7][16]={
219 {1,1},
220 {1,2,2},
221 {2,2,2,2},
222 {2,2,2,3,3},
223 {2,2,3,3,3,3},
224 {2,3,3,3,3,3,3},
225 {3,3,3,3,3,3,3,4,5,6,7,8,9,10,11},
226 };
227
228 static const uint8_t run_bits[7][16]={
229 {1,0},
230 {1,1,0},
231 {3,2,1,0},
232 {3,2,1,1,0},
233 {3,2,3,2,1,0},
234 {3,0,1,3,2,5,4},
235 {7,6,5,4,3,2,1,1,1,1,1,1,1,1,1},
236 };
237
238 static VLC coeff_token_vlc[4];
239 static VLC_TYPE coeff_token_vlc_tables[520+332+280+256][2];
240 static const int coeff_token_vlc_tables_size[4]={520,332,280,256};
241
242 static VLC chroma_dc_coeff_token_vlc;
243 static VLC_TYPE chroma_dc_coeff_token_vlc_table[256][2];
244 static const int chroma_dc_coeff_token_vlc_table_size = 256;
245
246 static VLC chroma422_dc_coeff_token_vlc;
247 static VLC_TYPE chroma422_dc_coeff_token_vlc_table[8192][2];
248 static const int chroma422_dc_coeff_token_vlc_table_size = 8192;
249
250 static VLC total_zeros_vlc[15+1];
251 static VLC_TYPE total_zeros_vlc_tables[15][512][2];
252 static const int total_zeros_vlc_tables_size = 512;
253
254 static VLC chroma_dc_total_zeros_vlc[3+1];
255 static VLC_TYPE chroma_dc_total_zeros_vlc_tables[3][8][2];
256 static const int chroma_dc_total_zeros_vlc_tables_size = 8;
257
258 static VLC chroma422_dc_total_zeros_vlc[7+1];
259 static VLC_TYPE chroma422_dc_total_zeros_vlc_tables[7][32][2];
260 static const int chroma422_dc_total_zeros_vlc_tables_size = 32;
261
262 static VLC run_vlc[6+1];
263 static VLC_TYPE run_vlc_tables[6][8][2];
264 static const int run_vlc_tables_size = 8;
265
266 static VLC run7_vlc;
267 static VLC_TYPE run7_vlc_table[96][2];
268 static const int run7_vlc_table_size = 96;
269
270 #define LEVEL_TAB_BITS 8
271 static int8_t cavlc_level_tab[7][1<<LEVEL_TAB_BITS][2];
272
273 #define CHROMA_DC_COEFF_TOKEN_VLC_BITS 8
274 #define CHROMA422_DC_COEFF_TOKEN_VLC_BITS 13
275 #define COEFF_TOKEN_VLC_BITS 8
276 #define TOTAL_ZEROS_VLC_BITS 9
277 #define CHROMA_DC_TOTAL_ZEROS_VLC_BITS 3
278 #define CHROMA422_DC_TOTAL_ZEROS_VLC_BITS 5
279 #define RUN_VLC_BITS 3
280 #define RUN7_VLC_BITS 6
281
282 /**
283 * Get the predicted number of non-zero coefficients.
284 * @param n block index
285 */
286 41953051 static inline int pred_non_zero_count(const H264Context *h, H264SliceContext *sl, int n)
287 {
288 41953051 const int index8= scan8[n];
289 41953051 const int left = sl->non_zero_count_cache[index8 - 1];
290 41953051 const int top = sl->non_zero_count_cache[index8 - 8];
291 41953051 int i= left + top;
292
293
2/2
✓ Branch 0 taken 40335791 times.
✓ Branch 1 taken 1617260 times.
41953051 if(i<64) i= (i+1)>>1;
294
295 ff_tlog(h->avctx, "pred_nnz L%X T%X n%d s%d P%X\n", left, top, n, scan8[n], i&31);
296
297 41953051 return i&31;
298 }
299
300 293 static av_cold void init_cavlc_level_tab(void){
301 int suffix_length;
302 unsigned int i;
303
304
2/2
✓ Branch 0 taken 2051 times.
✓ Branch 1 taken 293 times.
2344 for(suffix_length=0; suffix_length<7; suffix_length++){
305
2/2
✓ Branch 0 taken 525056 times.
✓ Branch 1 taken 2051 times.
527107 for(i=0; i<(1<<LEVEL_TAB_BITS); i++){
306 525056 int prefix= LEVEL_TAB_BITS - av_log2(2*i);
307
308
2/2
✓ Branch 0 taken 487845 times.
✓ Branch 1 taken 37211 times.
525056 if(prefix + 1 + suffix_length <= LEVEL_TAB_BITS){
309 487845 int level_code = (prefix << suffix_length) +
310 487845 (i >> (av_log2(i) - suffix_length)) - (1 << suffix_length);
311 487845 int mask = -(level_code&1);
312 487845 level_code = (((2 + level_code) >> 1) ^ mask) - mask;
313 487845 cavlc_level_tab[suffix_length][i][0]= level_code;
314 487845 cavlc_level_tab[suffix_length][i][1]= prefix + 1 + suffix_length;
315
2/2
✓ Branch 0 taken 35160 times.
✓ Branch 1 taken 2051 times.
37211 }else if(prefix + 1 <= LEVEL_TAB_BITS){
316 35160 cavlc_level_tab[suffix_length][i][0]= prefix+100;
317 35160 cavlc_level_tab[suffix_length][i][1]= prefix + 1;
318 }else{
319 2051 cavlc_level_tab[suffix_length][i][0]= LEVEL_TAB_BITS+100;
320 2051 cavlc_level_tab[suffix_length][i][1]= LEVEL_TAB_BITS;
321 }
322 }
323 }
324 293 }
325
326 293 av_cold void ff_h264_decode_init_vlc(void)
327 {
328 int offset;
329
330 293 chroma_dc_coeff_token_vlc.table = chroma_dc_coeff_token_vlc_table;
331 293 chroma_dc_coeff_token_vlc.table_allocated = chroma_dc_coeff_token_vlc_table_size;
332 293 init_vlc(&chroma_dc_coeff_token_vlc, CHROMA_DC_COEFF_TOKEN_VLC_BITS, 4*5,
333 &chroma_dc_coeff_token_len [0], 1, 1,
334 &chroma_dc_coeff_token_bits[0], 1, 1,
335 INIT_VLC_USE_NEW_STATIC);
336
337 293 chroma422_dc_coeff_token_vlc.table = chroma422_dc_coeff_token_vlc_table;
338 293 chroma422_dc_coeff_token_vlc.table_allocated = chroma422_dc_coeff_token_vlc_table_size;
339 293 init_vlc(&chroma422_dc_coeff_token_vlc, CHROMA422_DC_COEFF_TOKEN_VLC_BITS, 4*9,
340 &chroma422_dc_coeff_token_len [0], 1, 1,
341 &chroma422_dc_coeff_token_bits[0], 1, 1,
342 INIT_VLC_USE_NEW_STATIC);
343
344 293 offset = 0;
345
2/2
✓ Branch 0 taken 1172 times.
✓ Branch 1 taken 293 times.
1465 for (int i = 0; i < 4; i++) {
346 1172 coeff_token_vlc[i].table = coeff_token_vlc_tables + offset;
347 1172 coeff_token_vlc[i].table_allocated = coeff_token_vlc_tables_size[i];
348 1172 init_vlc(&coeff_token_vlc[i], COEFF_TOKEN_VLC_BITS, 4*17,
349 &coeff_token_len [i][0], 1, 1,
350 &coeff_token_bits[i][0], 1, 1,
351 INIT_VLC_USE_NEW_STATIC);
352 1172 offset += coeff_token_vlc_tables_size[i];
353 }
354 /*
355 * This is a one time safety check to make sure that
356 * the packed static coeff_token_vlc table sizes
357 * were initialized correctly.
358 */
359
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 293 times.
293 av_assert0(offset == FF_ARRAY_ELEMS(coeff_token_vlc_tables));
360
361
2/2
✓ Branch 0 taken 879 times.
✓ Branch 1 taken 293 times.
1172 for (int i = 0; i < 3; i++) {
362 879 chroma_dc_total_zeros_vlc[i + 1].table = chroma_dc_total_zeros_vlc_tables[i];
363 879 chroma_dc_total_zeros_vlc[i + 1].table_allocated = chroma_dc_total_zeros_vlc_tables_size;
364 879 init_vlc(&chroma_dc_total_zeros_vlc[i + 1],
365 CHROMA_DC_TOTAL_ZEROS_VLC_BITS, 4,
366 &chroma_dc_total_zeros_len [i][0], 1, 1,
367 &chroma_dc_total_zeros_bits[i][0], 1, 1,
368 INIT_VLC_USE_NEW_STATIC);
369 }
370
371
2/2
✓ Branch 0 taken 2051 times.
✓ Branch 1 taken 293 times.
2344 for (int i = 0; i < 7; i++) {
372 2051 chroma422_dc_total_zeros_vlc[i + 1].table = chroma422_dc_total_zeros_vlc_tables[i];
373 2051 chroma422_dc_total_zeros_vlc[i + 1].table_allocated = chroma422_dc_total_zeros_vlc_tables_size;
374 2051 init_vlc(&chroma422_dc_total_zeros_vlc[i + 1],
375 CHROMA422_DC_TOTAL_ZEROS_VLC_BITS, 8,
376 &chroma422_dc_total_zeros_len [i][0], 1, 1,
377 &chroma422_dc_total_zeros_bits[i][0], 1, 1,
378 INIT_VLC_USE_NEW_STATIC);
379 }
380
381
2/2
✓ Branch 0 taken 4395 times.
✓ Branch 1 taken 293 times.
4688 for (int i = 0; i < 15; i++) {
382 4395 total_zeros_vlc[i + 1].table = total_zeros_vlc_tables[i];
383 4395 total_zeros_vlc[i + 1].table_allocated = total_zeros_vlc_tables_size;
384 4395 init_vlc(&total_zeros_vlc[i + 1],
385 TOTAL_ZEROS_VLC_BITS, 16,
386 &total_zeros_len [i][0], 1, 1,
387 &total_zeros_bits[i][0], 1, 1,
388 INIT_VLC_USE_NEW_STATIC);
389 }
390
391
2/2
✓ Branch 0 taken 1758 times.
✓ Branch 1 taken 293 times.
2051 for (int i = 0; i < 6; i++) {
392 1758 run_vlc[i + 1].table = run_vlc_tables[i];
393 1758 run_vlc[i + 1].table_allocated = run_vlc_tables_size;
394 1758 init_vlc(&run_vlc[i + 1],
395 RUN_VLC_BITS, 7,
396 &run_len [i][0], 1, 1,
397 &run_bits[i][0], 1, 1,
398 INIT_VLC_USE_NEW_STATIC);
399 }
400 293 run7_vlc.table = run7_vlc_table;
401 293 run7_vlc.table_allocated = run7_vlc_table_size;
402 293 init_vlc(&run7_vlc, RUN7_VLC_BITS, 16,
403 &run_len [6][0], 1, 1,
404 &run_bits[6][0], 1, 1,
405 INIT_VLC_USE_NEW_STATIC);
406
407 293 init_cavlc_level_tab();
408 293 }
409
410 683047 static inline int get_level_prefix(GetBitContext *gb){
411 unsigned int buf;
412 int log;
413
414 683047 OPEN_READER(re, gb);
415 683047 UPDATE_CACHE(re, gb);
416 683047 buf=GET_CACHE(re, gb);
417
418 683047 log= 32 - av_log2(buf);
419
420 683047 LAST_SKIP_BITS(re, gb, log);
421 683047 CLOSE_READER(re, gb);
422
423 683047 return log-1;
424 }
425
426 /**
427 * Decode a residual block.
428 * @param n block index
429 * @param scantable scantable
430 * @param max_coeff number of coefficients in the block
431 * @return <0 if an error occurred
432 */
433 45088163 static int decode_residual(const H264Context *h, H264SliceContext *sl,
434 GetBitContext *gb, int16_t *block, int n,
435 const uint8_t *scantable, const uint32_t *qmul,
436 int max_coeff)
437 {
438 static const int coeff_token_table_index[17]= {0, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3};
439 int level[16];
440 int zeros_left, coeff_token, total_coeff, i, trailing_ones, run_before;
441
442 //FIXME put trailing_onex into the context
443
444
2/2
✓ Branch 0 taken 3135112 times.
✓ Branch 1 taken 41953051 times.
45088163 if(max_coeff <= 8){
445
2/2
✓ Branch 0 taken 2556054 times.
✓ Branch 1 taken 579058 times.
3135112 if (max_coeff == 4)
446 2556054 coeff_token = get_vlc2(gb, chroma_dc_coeff_token_vlc.table, CHROMA_DC_COEFF_TOKEN_VLC_BITS, 1);
447 else
448 579058 coeff_token = get_vlc2(gb, chroma422_dc_coeff_token_vlc.table, CHROMA422_DC_COEFF_TOKEN_VLC_BITS, 1);
449 3135112 total_coeff= coeff_token>>2;
450 }else{
451
2/2
✓ Branch 0 taken 210603 times.
✓ Branch 1 taken 41742448 times.
41953051 if(n >= LUMA_DC_BLOCK_INDEX){
452 210603 total_coeff= pred_non_zero_count(h, sl, (n - LUMA_DC_BLOCK_INDEX)*16);
453 210603 coeff_token= get_vlc2(gb, coeff_token_vlc[ coeff_token_table_index[total_coeff] ].table, COEFF_TOKEN_VLC_BITS, 2);
454 210603 total_coeff= coeff_token>>2;
455 }else{
456 41742448 total_coeff= pred_non_zero_count(h, sl, n);
457 41742448 coeff_token= get_vlc2(gb, coeff_token_vlc[ coeff_token_table_index[total_coeff] ].table, COEFF_TOKEN_VLC_BITS, 2);
458 41742448 total_coeff= coeff_token>>2;
459 }
460 }
461 45088163 sl->non_zero_count_cache[scan8[n]] = total_coeff;
462
463 //FIXME set last_non_zero?
464
465
2/2
✓ Branch 0 taken 15668411 times.
✓ Branch 1 taken 29419752 times.
45088163 if(total_coeff==0)
466 15668411 return 0;
467
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 29419752 times.
29419752 if(total_coeff > (unsigned)max_coeff) {
468 av_log(h->avctx, AV_LOG_ERROR, "corrupted macroblock %d %d (total_coeff=%d)\n", sl->mb_x, sl->mb_y, total_coeff);
469 return -1;
470 }
471
472 29419752 trailing_ones= coeff_token&3;
473 ff_tlog(h->avctx, "trailing:%d, total:%d\n", trailing_ones, total_coeff);
474 av_assert2(total_coeff<=16);
475
476 29419752 i = show_bits(gb, 3);
477 29419752 skip_bits(gb, trailing_ones);
478 29419752 level[0] = 1-((i&4)>>1);
479 29419752 level[1] = 1-((i&2) );
480 29419752 level[2] = 1-((i&1)<<1);
481
482
2/2
✓ Branch 0 taken 13389894 times.
✓ Branch 1 taken 16029858 times.
29419752 if(trailing_ones<total_coeff) {
483 int mask, prefix;
484 13389894 int suffix_length = total_coeff > 10 & trailing_ones < 3;
485 13389894 int bitsi= show_bits(gb, LEVEL_TAB_BITS);
486 13389894 int level_code= cavlc_level_tab[suffix_length][bitsi][0];
487
488 13389894 skip_bits(gb, cavlc_level_tab[suffix_length][bitsi][1]);
489
2/2
✓ Branch 0 taken 305379 times.
✓ Branch 1 taken 13084515 times.
13389894 if(level_code >= 100){
490 305379 prefix= level_code - 100;
491
2/2
✓ Branch 0 taken 301644 times.
✓ Branch 1 taken 3735 times.
305379 if(prefix == LEVEL_TAB_BITS)
492 301644 prefix += get_level_prefix(gb);
493
494 //first coefficient has suffix_length equal to 0 or 1
495
2/2
✓ Branch 0 taken 184421 times.
✓ Branch 1 taken 120958 times.
305379 if(prefix<14){ //FIXME try to build a large unified VLC table for all this
496
2/2
✓ Branch 0 taken 12209 times.
✓ Branch 1 taken 172212 times.
184421 if(suffix_length)
497 12209 level_code= (prefix<<1) + get_bits1(gb); //part
498 else
499 172212 level_code= prefix; //part
500
2/2
✓ Branch 0 taken 55311 times.
✓ Branch 1 taken 65647 times.
120958 }else if(prefix==14){
501
2/2
✓ Branch 0 taken 536 times.
✓ Branch 1 taken 54775 times.
55311 if(suffix_length)
502 536 level_code= (prefix<<1) + get_bits1(gb); //part
503 else
504 54775 level_code= prefix + get_bits(gb, 4); //part
505 }else{
506 65647 level_code= 30;
507
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 65623 times.
65647 if(prefix>=16){
508
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
24 if(prefix > 25+3){
509 av_log(h->avctx, AV_LOG_ERROR, "Invalid level prefix\n");
510 return -1;
511 }
512 24 level_code += (1<<(prefix-3))-4096;
513 }
514 65647 level_code += get_bits(gb, prefix-3); //part
515 }
516
517
2/2
✓ Branch 0 taken 234592 times.
✓ Branch 1 taken 70787 times.
305379 if(trailing_ones < 3) level_code += 2;
518
519 305379 suffix_length = 2;
520 305379 mask= -(level_code&1);
521 305379 level[trailing_ones]= (((2+level_code)>>1) ^ mask) - mask;
522 }else{
523 13084515 level_code += ((level_code>>31)|1) & -(trailing_ones < 3);
524
525
2/2
✓ Branch 0 taken 727583 times.
✓ Branch 1 taken 12356932 times.
13084515 suffix_length = 1 + (level_code + 3U > 6U);
526 13084515 level[trailing_ones]= level_code;
527 }
528
529 //remaining coefficients have suffix_length > 0
530
2/2
✓ Branch 0 taken 38179212 times.
✓ Branch 1 taken 13389894 times.
51569106 for(i=trailing_ones+1;i<total_coeff;i++) {
531 static const unsigned int suffix_limit[7] = {0,3,6,12,24,48,INT_MAX };
532 38179212 int bitsi= show_bits(gb, LEVEL_TAB_BITS);
533 38179212 level_code= cavlc_level_tab[suffix_length][bitsi][0];
534
535 38179212 skip_bits(gb, cavlc_level_tab[suffix_length][bitsi][1]);
536
2/2
✓ Branch 0 taken 765472 times.
✓ Branch 1 taken 37413740 times.
38179212 if(level_code >= 100){
537 765472 prefix= level_code - 100;
538
2/2
✓ Branch 0 taken 381403 times.
✓ Branch 1 taken 384069 times.
765472 if(prefix == LEVEL_TAB_BITS){
539 381403 prefix += get_level_prefix(gb);
540 }
541
2/2
✓ Branch 0 taken 702286 times.
✓ Branch 1 taken 63186 times.
765472 if(prefix<15){
542 702286 level_code = (prefix<<suffix_length) + get_bits(gb, suffix_length);
543 }else{
544 63186 level_code = 15<<suffix_length;
545
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 63182 times.
63186 if (prefix>=16) {
546
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if(prefix > 25+3){
547 av_log(h->avctx, AV_LOG_ERROR, "Invalid level prefix\n");
548 return AVERROR_INVALIDDATA;
549 }
550 4 level_code += (1<<(prefix-3))-4096;
551 }
552 63186 level_code += get_bits(gb, prefix-3);
553 }
554 765472 mask= -(level_code&1);
555 765472 level_code= (((2+level_code)>>1) ^ mask) - mask;
556 }
557 38179212 level[i]= level_code;
558 38179212 suffix_length+= suffix_limit[suffix_length] + level_code > 2U*suffix_limit[suffix_length];
559 }
560 }
561
562
2/2
✓ Branch 0 taken 291828 times.
✓ Branch 1 taken 29127924 times.
29419752 if(total_coeff == max_coeff)
563 291828 zeros_left=0;
564 else{
565
2/2
✓ Branch 0 taken 1867388 times.
✓ Branch 1 taken 27260536 times.
29127924 if (max_coeff <= 8) {
566
2/2
✓ Branch 0 taken 1410006 times.
✓ Branch 1 taken 457382 times.
1867388 if (max_coeff == 4)
567 1410006 zeros_left = get_vlc2(gb, chroma_dc_total_zeros_vlc[total_coeff].table,
568 CHROMA_DC_TOTAL_ZEROS_VLC_BITS, 1);
569 else
570 457382 zeros_left = get_vlc2(gb, chroma422_dc_total_zeros_vlc[total_coeff].table,
571 CHROMA422_DC_TOTAL_ZEROS_VLC_BITS, 1);
572 } else {
573 27260536 zeros_left= get_vlc2(gb, total_zeros_vlc[ total_coeff ].table, TOTAL_ZEROS_VLC_BITS, 1);
574 }
575 }
576
577 #define STORE_BLOCK(type) \
578 scantable += zeros_left + total_coeff - 1; \
579 if(n >= LUMA_DC_BLOCK_INDEX){ \
580 ((type*)block)[*scantable] = level[0]; \
581 for(i=1;i<total_coeff && zeros_left > 0;i++) { \
582 if(zeros_left < 7) \
583 run_before= get_vlc2(gb, run_vlc[zeros_left].table, RUN_VLC_BITS, 1); \
584 else \
585 run_before= get_vlc2(gb, run7_vlc.table, RUN7_VLC_BITS, 2); \
586 zeros_left -= run_before; \
587 scantable -= 1 + run_before; \
588 ((type*)block)[*scantable]= level[i]; \
589 } \
590 for(;i<total_coeff;i++) { \
591 scantable--; \
592 ((type*)block)[*scantable]= level[i]; \
593 } \
594 }else{ \
595 ((type*)block)[*scantable] = ((int)(level[0] * qmul[*scantable] + 32))>>6; \
596 for(i=1;i<total_coeff && zeros_left > 0;i++) { \
597 if(zeros_left < 7) \
598 run_before= get_vlc2(gb, run_vlc[zeros_left].table, RUN_VLC_BITS, 1); \
599 else \
600 run_before= get_vlc2(gb, run7_vlc.table, RUN7_VLC_BITS, 2); \
601 zeros_left -= run_before; \
602 scantable -= 1 + run_before; \
603 ((type*)block)[*scantable]= ((int)(level[i] * qmul[*scantable] + 32))>>6; \
604 } \
605 for(;i<total_coeff;i++) { \
606 scantable--; \
607 ((type*)block)[*scantable]= ((int)(level[i] * qmul[*scantable] + 32))>>6; \
608 } \
609 }
610
611
2/2
✓ Branch 0 taken 10462176 times.
✓ Branch 1 taken 18957576 times.
29419752 if (h->pixel_shift) {
612
18/18
✓ Branch 0 taken 839279 times.
✓ Branch 1 taken 9622897 times.
✓ Branch 2 taken 775402 times.
✓ Branch 3 taken 16974 times.
✓ Branch 6 taken 1075317 times.
✓ Branch 7 taken 556338 times.
✓ Branch 8 taken 792376 times.
✓ Branch 9 taken 282941 times.
✓ Branch 10 taken 675595 times.
✓ Branch 11 taken 839279 times.
✓ Branch 12 taken 13892379 times.
✓ Branch 13 taken 2124206 times.
✓ Branch 16 taken 19265710 times.
✓ Branch 17 taken 6373772 times.
✓ Branch 18 taken 16016585 times.
✓ Branch 19 taken 3249125 times.
✓ Branch 20 taken 9617414 times.
✓ Branch 21 taken 9622897 times.
37564146 STORE_BLOCK(int32_t)
613 } else {
614
18/18
✓ Branch 0 taken 1387513 times.
✓ Branch 1 taken 17570063 times.
✓ Branch 2 taken 590547 times.
✓ Branch 3 taken 16821 times.
✓ Branch 6 taken 1012584 times.
✓ Branch 7 taken 982297 times.
✓ Branch 8 taken 607368 times.
✓ Branch 9 taken 405216 times.
✓ Branch 10 taken 1017834 times.
✓ Branch 11 taken 1387513 times.
✓ Branch 12 taken 26392145 times.
✓ Branch 13 taken 4056396 times.
✓ Branch 16 taken 34522288 times.
✓ Branch 17 taken 13496316 times.
✓ Branch 18 taken 30448541 times.
✓ Branch 19 taken 4073747 times.
✓ Branch 20 taken 11384363 times.
✓ Branch 21 taken 17570063 times.
62415682 STORE_BLOCK(int16_t)
615 }
616
617
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 29419752 times.
29419752 if(zeros_left<0){
618 av_log(h->avctx, AV_LOG_ERROR, "negative number of zero coeffs at %d %d\n", sl->mb_x, sl->mb_y);
619 return -1;
620 }
621
622 29419752 return 0;
623 }
624
625 static av_always_inline
626 2806644 int decode_luma_residual(const H264Context *h, H264SliceContext *sl,
627 GetBitContext *gb, const uint8_t *scan,
628 const uint8_t *scan8x8, int pixel_shift,
629 int mb_type, int cbp, int p)
630 {
631 int i4x4, i8x8;
632
1/2
✓ Branch 0 taken 2806644 times.
✗ Branch 1 not taken.
2806644 int qscale = p == 0 ? sl->qscale : sl->chroma_qp[p - 1];
633
2/2
✓ Branch 0 taken 210603 times.
✓ Branch 1 taken 2596041 times.
2806644 if(IS_INTRA16x16(mb_type)){
634 210603 AV_ZERO128(sl->mb_luma_dc[p]+0);
635 210603 AV_ZERO128(sl->mb_luma_dc[p]+8);
636 210603 AV_ZERO128(sl->mb_luma_dc[p]+16);
637 210603 AV_ZERO128(sl->mb_luma_dc[p]+24);
638
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 210603 times.
210603 if (decode_residual(h, sl, gb, sl->mb_luma_dc[p], LUMA_DC_BLOCK_INDEX + p, scan, NULL, 16) < 0) {
639 return -1; //FIXME continue if partitioned and other return -1 too
640 }
641
642 av_assert2((cbp&15) == 0 || (cbp&15) == 15);
643
644
2/2
✓ Branch 0 taken 94606 times.
✓ Branch 1 taken 115997 times.
210603 if(cbp&15){
645
2/2
✓ Branch 0 taken 378424 times.
✓ Branch 1 taken 94606 times.
473030 for(i8x8=0; i8x8<4; i8x8++){
646
2/2
✓ Branch 0 taken 1513696 times.
✓ Branch 1 taken 378424 times.
1892120 for(i4x4=0; i4x4<4; i4x4++){
647 1513696 const int index= i4x4 + 4*i8x8 + p*16;
648
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1513696 times.
1513696 if( decode_residual(h, sl, gb, sl->mb + (16*index << pixel_shift),
649 1513696 index, scan + 1, h->ps.pps->dequant4_coeff[p][qscale], 15) < 0 ){
650 return -1;
651 }
652 }
653 }
654 94606 return 0xf;
655 }else{
656 115997 fill_rectangle(&sl->non_zero_count_cache[scan8[p*16]], 4, 4, 8, 0, 1);
657 115997 return 0;
658 }
659 }else{
660
2/2
✓ Branch 0 taken 1133043 times.
✓ Branch 1 taken 1462998 times.
2596041 int cqm = (IS_INTRA( mb_type ) ? 0:3)+p;
661 /* For CAVLC 4:4:4, we need to keep track of the luma 8x8 CBP for deblocking nnz purposes. */
662 2596041 int new_cbp = 0;
663
2/2
✓ Branch 0 taken 10384164 times.
✓ Branch 1 taken 2596041 times.
12980205 for(i8x8=0; i8x8<4; i8x8++){
664
2/2
✓ Branch 0 taken 7657176 times.
✓ Branch 1 taken 2726988 times.
10384164 if(cbp & (1<<i8x8)){
665
2/2
✓ Branch 0 taken 2320357 times.
✓ Branch 1 taken 5336819 times.
7657176 if(IS_8x8DCT(mb_type)){
666 2320357 int16_t *buf = &sl->mb[64*i8x8+256*p << pixel_shift];
667 uint8_t *nnz;
668
2/2
✓ Branch 0 taken 9281428 times.
✓ Branch 1 taken 2320357 times.
11601785 for(i4x4=0; i4x4<4; i4x4++){
669 9281428 const int index= i4x4 + 4*i8x8 + p*16;
670
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9281428 times.
9281428 if( decode_residual(h, sl, gb, buf, index, scan8x8+16*i4x4,
671 9281428 h->ps.pps->dequant8_coeff[cqm][qscale], 16) < 0 )
672 return -1;
673 }
674 2320357 nnz = &sl->non_zero_count_cache[scan8[4 * i8x8 + p * 16]];
675 2320357 nnz[0] += nnz[1] + nnz[8] + nnz[9];
676 2320357 new_cbp |= !!nnz[0] << i8x8;
677 }else{
678
2/2
✓ Branch 0 taken 21347276 times.
✓ Branch 1 taken 5336819 times.
26684095 for(i4x4=0; i4x4<4; i4x4++){
679 21347276 const int index= i4x4 + 4*i8x8 + p*16;
680
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21347276 times.
21347276 if( decode_residual(h, sl, gb, sl->mb + (16*index << pixel_shift), index,
681 21347276 scan, h->ps.pps->dequant4_coeff[cqm][qscale], 16) < 0 ){
682 return -1;
683 }
684 21347276 new_cbp |= sl->non_zero_count_cache[scan8[index]] << i8x8;
685 }
686 }
687 }else{
688 2726988 uint8_t * const nnz = &sl->non_zero_count_cache[scan8[4 * i8x8 + p * 16]];
689 2726988 nnz[0] = nnz[1] = nnz[8] = nnz[9] = 0;
690 }
691 }
692 2596041 return new_cbp;
693 }
694 }
695
696 4346943 int ff_h264_decode_mb_cavlc(const H264Context *h, H264SliceContext *sl)
697 {
698 int mb_xy;
699 int partition_count;
700 unsigned int mb_type, cbp;
701 4346943 int dct8x8_allowed = h->ps.pps->transform_8x8_mode;
702
4/4
✓ Branch 0 taken 389328 times.
✓ Branch 1 taken 3957615 times.
✓ Branch 2 taken 346560 times.
✓ Branch 3 taken 42768 times.
4346943 const int decode_chroma = h->ps.sps->chroma_format_idc == 1 || h->ps.sps->chroma_format_idc == 2;
703 4346943 const int pixel_shift = h->pixel_shift;
704
705 4346943 mb_xy = sl->mb_xy = sl->mb_x + sl->mb_y*h->mb_stride;
706
707 ff_tlog(h->avctx, "pic:%d mb:%d/%d\n", h->poc.frame_num, sl->mb_x, sl->mb_y);
708 4346943 cbp = 0; /* avoid warning. FIXME: find a solution without slowing
709 down the code */
710
2/2
✓ Branch 0 taken 3338086 times.
✓ Branch 1 taken 1008857 times.
4346943 if (sl->slice_type_nos != AV_PICTURE_TYPE_I) {
711
2/2
✓ Branch 0 taken 2485391 times.
✓ Branch 1 taken 852695 times.
3338086 if (sl->mb_skip_run == -1) {
712 2485391 unsigned mb_skip_run = get_ue_golomb_long(&sl->gb);
713
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2485391 times.
2485391 if (mb_skip_run > h->mb_num) {
714 av_log(h->avctx, AV_LOG_ERROR, "mb_skip_run %d is invalid\n", mb_skip_run);
715 return AVERROR_INVALIDDATA;
716 }
717 2485391 sl->mb_skip_run = mb_skip_run;
718 }
719
720
2/2
✓ Branch 0 taken 855807 times.
✓ Branch 1 taken 2482279 times.
3338086 if (sl->mb_skip_run--) {
721
4/4
✓ Branch 0 taken 11109 times.
✓ Branch 1 taken 844698 times.
✓ Branch 2 taken 5515 times.
✓ Branch 3 taken 5594 times.
855807 if (FRAME_MBAFF(h) && (sl->mb_y & 1) == 0) {
722
2/2
✓ Branch 0 taken 2894 times.
✓ Branch 1 taken 2621 times.
5515 if (sl->mb_skip_run == 0)
723 2894 sl->mb_mbaff = sl->mb_field_decoding_flag = get_bits1(&sl->gb);
724 }
725 855807 decode_mb_skip(h, sl);
726 855807 return 0;
727 }
728 }
729
2/2
✓ Branch 0 taken 497835 times.
✓ Branch 1 taken 2993301 times.
3491136 if (FRAME_MBAFF(h)) {
730
2/2
✓ Branch 0 taken 248957 times.
✓ Branch 1 taken 248878 times.
497835 if ((sl->mb_y & 1) == 0)
731 248957 sl->mb_mbaff = sl->mb_field_decoding_flag = get_bits1(&sl->gb);
732 }
733
734 3491136 sl->prev_mb_skipped = 0;
735
736 3491136 mb_type= get_ue_golomb(&sl->gb);
737
2/2
✓ Branch 0 taken 877411 times.
✓ Branch 1 taken 2613725 times.
3491136 if (sl->slice_type_nos == AV_PICTURE_TYPE_B) {
738
2/2
✓ Branch 0 taken 736512 times.
✓ Branch 1 taken 140899 times.
877411 if(mb_type < 23){
739 736512 partition_count = ff_h264_b_mb_type_info[mb_type].partition_count;
740 736512 mb_type = ff_h264_b_mb_type_info[mb_type].type;
741 }else{
742 140899 mb_type -= 23;
743 140899 goto decode_intra_mb;
744 }
745
2/2
✓ Branch 0 taken 1604868 times.
✓ Branch 1 taken 1008857 times.
2613725 } else if (sl->slice_type_nos == AV_PICTURE_TYPE_P) {
746
2/2
✓ Branch 0 taken 1367646 times.
✓ Branch 1 taken 237222 times.
1604868 if(mb_type < 5){
747 1367646 partition_count = ff_h264_p_mb_type_info[mb_type].partition_count;
748 1367646 mb_type = ff_h264_p_mb_type_info[mb_type].type;
749 }else{
750 237222 mb_type -= 5;
751 237222 goto decode_intra_mb;
752 }
753 }else{
754 av_assert2(sl->slice_type_nos == AV_PICTURE_TYPE_I);
755
1/4
✓ Branch 0 taken 1008857 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
1008857 if (sl->slice_type == AV_PICTURE_TYPE_SI && mb_type)
756 mb_type--;
757 1008857 decode_intra_mb:
758
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1386978 times.
1386978 if(mb_type > 25){
759 av_log(h->avctx, AV_LOG_ERROR, "mb_type %d in %c slice too large at %d %d\n", mb_type, av_get_picture_type_char(sl->slice_type), sl->mb_x, sl->mb_y);
760 return -1;
761 }
762 1386978 partition_count=0;
763 1386978 cbp = ff_h264_i_mb_type_info[mb_type].cbp;
764 1386978 sl->intra16x16_pred_mode = ff_h264_i_mb_type_info[mb_type].pred_mode;
765 1386978 mb_type = ff_h264_i_mb_type_info[mb_type].type;
766 }
767
768
2/2
✓ Branch 0 taken 981328 times.
✓ Branch 1 taken 2509808 times.
3491136 if (MB_FIELD(sl))
769 981328 mb_type |= MB_TYPE_INTERLACED;
770
771 3491136 h->slice_table[mb_xy] = sl->slice_num;
772
773
2/2
✓ Branch 0 taken 17446 times.
✓ Branch 1 taken 3473690 times.
3491136 if(IS_INTRA_PCM(mb_type)){
774 17446 const int mb_size = ff_h264_mb_sizes[h->ps.sps->chroma_format_idc] *
775 17446 h->ps.sps->bit_depth_luma;
776
777 // We assume these blocks are very rare so we do not optimize it.
778 17446 sl->intra_pcm_ptr = align_get_bits(&sl->gb);
779
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 17446 times.
17446 if (get_bits_left(&sl->gb) < mb_size) {
780 av_log(h->avctx, AV_LOG_ERROR, "Not enough data for an intra PCM block.\n");
781 return AVERROR_INVALIDDATA;
782 }
783 17446 skip_bits_long(&sl->gb, mb_size);
784
785 // In deblocking, the quantizer is 0
786 17446 h->cur_pic.qscale_table[mb_xy] = 0;
787 // All coeffs are present
788 17446 memset(h->non_zero_count[mb_xy], 16, 48);
789
790 17446 h->cur_pic.mb_type[mb_xy] = mb_type;
791 17446 return 0;
792 }
793
794 3473690 fill_decode_neighbors(h, sl, mb_type);
795 3473690 fill_decode_caches(h, sl, mb_type);
796
797 //mb_pred
798
2/2
✓ Branch 0 taken 1369532 times.
✓ Branch 1 taken 2104158 times.
3473690 if(IS_INTRA(mb_type)){
799 int pred_mode;
800 // init_top_left_availability(h);
801
2/2
✓ Branch 0 taken 1158929 times.
✓ Branch 1 taken 210603 times.
1369532 if(IS_INTRA4x4(mb_type)){
802 int i;
803 1158929 int di = 1;
804
4/4
✓ Branch 0 taken 849962 times.
✓ Branch 1 taken 308967 times.
✓ Branch 3 taken 541655 times.
✓ Branch 4 taken 308307 times.
1158929 if(dct8x8_allowed && get_bits1(&sl->gb)){
805 541655 mb_type |= MB_TYPE_8x8DCT;
806 541655 di = 4;
807 }
808
809 // fill_intra4x4_pred_table(h);
810
2/2
✓ Branch 0 taken 12043004 times.
✓ Branch 1 taken 1158929 times.
13201933 for(i=0; i<16; i+=di){
811 12043004 int mode = pred_intra_mode(h, sl, i);
812
813
2/2
✓ Branch 1 taken 6502141 times.
✓ Branch 2 taken 5540863 times.
12043004 if(!get_bits1(&sl->gb)){
814 6502141 const int rem_mode= get_bits(&sl->gb, 3);
815 6502141 mode = rem_mode + (rem_mode >= mode);
816 }
817
818
2/2
✓ Branch 0 taken 2166620 times.
✓ Branch 1 taken 9876384 times.
12043004 if(di==4)
819 2166620 fill_rectangle(&sl->intra4x4_pred_mode_cache[ scan8[i] ], 2, 2, 8, mode, 1);
820 else
821 9876384 sl->intra4x4_pred_mode_cache[scan8[i]] = mode;
822 }
823 1158929 write_back_intra_pred_mode(h, sl);
824
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1158929 times.
1158929 if (ff_h264_check_intra4x4_pred_mode(sl->intra4x4_pred_mode_cache, h->avctx,
825 1158929 sl->top_samples_available, sl->left_samples_available) < 0)
826 return -1;
827 }else{
828 421206 sl->intra16x16_pred_mode = ff_h264_check_intra_pred_mode(h->avctx, sl->top_samples_available,
829 210603 sl->left_samples_available, sl->intra16x16_pred_mode, 0);
830
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 210603 times.
210603 if (sl->intra16x16_pred_mode < 0)
831 return -1;
832 }
833
2/2
✓ Branch 0 taken 1342403 times.
✓ Branch 1 taken 27129 times.
1369532 if(decode_chroma){
834 1342403 pred_mode= ff_h264_check_intra_pred_mode(h->avctx, sl->top_samples_available,
835 1342403 sl->left_samples_available, get_ue_golomb_31(&sl->gb), 1);
836
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1342403 times.
1342403 if(pred_mode < 0)
837 return -1;
838 1342403 sl->chroma_pred_mode = pred_mode;
839 } else {
840 27129 sl->chroma_pred_mode = DC_128_PRED8x8;
841 }
842
2/2
✓ Branch 0 taken 511482 times.
✓ Branch 1 taken 1592676 times.
2104158 }else if(partition_count==4){
843 int i, j, sub_partition_count[4], list, ref[2][4];
844
845
2/2
✓ Branch 0 taken 177999 times.
✓ Branch 1 taken 333483 times.
511482 if (sl->slice_type_nos == AV_PICTURE_TYPE_B) {
846
2/2
✓ Branch 0 taken 711996 times.
✓ Branch 1 taken 177999 times.
889995 for(i=0; i<4; i++){
847 711996 sl->sub_mb_type[i]= get_ue_golomb_31(&sl->gb);
848
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 711996 times.
711996 if(sl->sub_mb_type[i] >=13){
849 av_log(h->avctx, AV_LOG_ERROR, "B sub_mb_type %u out of range at %d %d\n", sl->sub_mb_type[i], sl->mb_x, sl->mb_y);
850 return -1;
851 }
852 711996 sub_partition_count[i] = ff_h264_b_sub_mb_type_info[sl->sub_mb_type[i]].partition_count;
853 711996 sl->sub_mb_type[i] = ff_h264_b_sub_mb_type_info[sl->sub_mb_type[i]].type;
854 }
855
2/2
✓ Branch 0 taken 55683 times.
✓ Branch 1 taken 122316 times.
177999 if( IS_DIRECT(sl->sub_mb_type[0]|sl->sub_mb_type[1]|sl->sub_mb_type[2]|sl->sub_mb_type[3])) {
856 55683 ff_h264_pred_direct_motion(h, sl, &mb_type);
857 55683 sl->ref_cache[0][scan8[4]] =
858 55683 sl->ref_cache[1][scan8[4]] =
859 55683 sl->ref_cache[0][scan8[12]] =
860 55683 sl->ref_cache[1][scan8[12]] = PART_NOT_AVAILABLE;
861 }
862 }else{
863 av_assert2(sl->slice_type_nos == AV_PICTURE_TYPE_P); //FIXME SP correct ?
864
2/2
✓ Branch 0 taken 1333932 times.
✓ Branch 1 taken 333483 times.
1667415 for(i=0; i<4; i++){
865 1333932 sl->sub_mb_type[i]= get_ue_golomb_31(&sl->gb);
866
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1333932 times.
1333932 if(sl->sub_mb_type[i] >=4){
867 av_log(h->avctx, AV_LOG_ERROR, "P sub_mb_type %u out of range at %d %d\n", sl->sub_mb_type[i], sl->mb_x, sl->mb_y);
868 return -1;
869 }
870 1333932 sub_partition_count[i] = ff_h264_p_sub_mb_type_info[sl->sub_mb_type[i]].partition_count;
871 1333932 sl->sub_mb_type[i] = ff_h264_p_sub_mb_type_info[sl->sub_mb_type[i]].type;
872 }
873 }
874
875
2/2
✓ Branch 0 taken 689481 times.
✓ Branch 1 taken 511482 times.
1200963 for (list = 0; list < sl->list_count; list++) {
876
2/2
✓ Branch 0 taken 567881 times.
✓ Branch 1 taken 121600 times.
689481 int ref_count = IS_REF0(mb_type) ? 1 : sl->ref_count[list] << MB_MBAFF(sl);
877
2/2
✓ Branch 0 taken 2757924 times.
✓ Branch 1 taken 689481 times.
3447405 for(i=0; i<4; i++){
878
2/2
✓ Branch 0 taken 230658 times.
✓ Branch 1 taken 2527266 times.
2757924 if(IS_DIRECT(sl->sub_mb_type[i])) continue;
879
2/2
✓ Branch 0 taken 2200238 times.
✓ Branch 1 taken 327028 times.
2527266 if(IS_DIR(sl->sub_mb_type[i], 0, list)){
880 unsigned int tmp;
881
2/2
✓ Branch 0 taken 756033 times.
✓ Branch 1 taken 1444205 times.
2200238 if(ref_count == 1){
882 756033 tmp= 0;
883
2/2
✓ Branch 0 taken 454436 times.
✓ Branch 1 taken 989769 times.
1444205 }else if(ref_count == 2){
884 454436 tmp= get_bits1(&sl->gb)^1;
885 }else{
886 989769 tmp= get_ue_golomb_31(&sl->gb);
887
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 989769 times.
989769 if(tmp>=ref_count){
888 av_log(h->avctx, AV_LOG_ERROR, "ref %u overflow\n", tmp);
889 return -1;
890 }
891 }
892 2200238 ref[list][i]= tmp;
893 }else{
894 //FIXME
895 327028 ref[list][i] = -1;
896 }
897 }
898 }
899
900
2/2
✓ Branch 0 taken 51527 times.
✓ Branch 1 taken 459955 times.
511482 if(dct8x8_allowed)
901 51527 dct8x8_allowed = get_dct8x8_allowed(h, sl);
902
903
2/2
✓ Branch 0 taken 689481 times.
✓ Branch 1 taken 511482 times.
1200963 for (list = 0; list < sl->list_count; list++) {
904
2/2
✓ Branch 0 taken 2757924 times.
✓ Branch 1 taken 689481 times.
3447405 for(i=0; i<4; i++){
905
2/2
✓ Branch 0 taken 230658 times.
✓ Branch 1 taken 2527266 times.
2757924 if(IS_DIRECT(sl->sub_mb_type[i])) {
906 230658 sl->ref_cache[list][ scan8[4*i] ] = sl->ref_cache[list][ scan8[4*i]+1 ];
907 230658 continue;
908 }
909 2527266 sl->ref_cache[list][ scan8[4*i] ]=sl->ref_cache[list][ scan8[4*i]+1 ]=
910 2527266 sl->ref_cache[list][ scan8[4*i]+8 ]=sl->ref_cache[list][ scan8[4*i]+9 ]= ref[list][i];
911
912
2/2
✓ Branch 0 taken 2200238 times.
✓ Branch 1 taken 327028 times.
2527266 if(IS_DIR(sl->sub_mb_type[i], 0, list)){
913 2200238 const int sub_mb_type= sl->sub_mb_type[i];
914
2/2
✓ Branch 0 taken 1653695 times.
✓ Branch 1 taken 546543 times.
2200238 const int block_width= (sub_mb_type & (MB_TYPE_16x16|MB_TYPE_16x8)) ? 2 : 1;
915
2/2
✓ Branch 0 taken 3663426 times.
✓ Branch 1 taken 2200238 times.
5863664 for(j=0; j<sub_partition_count[i]; j++){
916 int mx, my;
917 3663426 const int index= 4*i + block_width*j;
918 3663426 int16_t (* mv_cache)[2]= &sl->mv_cache[list][ scan8[index] ];
919 3663426 pred_motion(h, sl, index, block_width, list, sl->ref_cache[list][ scan8[index] ], &mx, &my);
920 3663426 mx += (unsigned)get_se_golomb(&sl->gb);
921 3663426 my += (unsigned)get_se_golomb(&sl->gb);
922 ff_tlog(h->avctx, "final mv:%d %d\n", mx, my);
923
924
2/2
✓ Branch 0 taken 1141536 times.
✓ Branch 1 taken 2521890 times.
3663426 if(IS_SUB_8X8(sub_mb_type)){
925 1141536 mv_cache[ 1 ][0]=
926 1141536 mv_cache[ 8 ][0]= mv_cache[ 9 ][0]= mx;
927 1141536 mv_cache[ 1 ][1]=
928 1141536 mv_cache[ 8 ][1]= mv_cache[ 9 ][1]= my;
929
2/2
✓ Branch 0 taken 1024318 times.
✓ Branch 1 taken 1497572 times.
2521890 }else if(IS_SUB_8X4(sub_mb_type)){
930 1024318 mv_cache[ 1 ][0]= mx;
931 1024318 mv_cache[ 1 ][1]= my;
932
2/2
✓ Branch 0 taken 688600 times.
✓ Branch 1 taken 808972 times.
1497572 }else if(IS_SUB_4X8(sub_mb_type)){
933 688600 mv_cache[ 8 ][0]= mx;
934 688600 mv_cache[ 8 ][1]= my;
935 }
936 3663426 mv_cache[ 0 ][0]= mx;
937 3663426 mv_cache[ 0 ][1]= my;
938 }
939 }else{
940 327028 uint32_t *p= (uint32_t *)&sl->mv_cache[list][ scan8[4*i] ][0];
941 327028 p[0] = p[1]=
942 327028 p[8] = p[9]= 0;
943 }
944 }
945 }
946
2/2
✓ Branch 0 taken 120891 times.
✓ Branch 1 taken 1471785 times.
1592676 }else if(IS_DIRECT(mb_type)){
947 120891 ff_h264_pred_direct_motion(h, sl, &mb_type);
948 120891 dct8x8_allowed &= h->ps.sps->direct_8x8_inference_flag;
949 }else{
950 int list, mx, my, i;
951 //FIXME we should set ref_idx_l? to 0 if we use that later ...
952
2/2
✓ Branch 0 taken 994792 times.
✓ Branch 1 taken 476993 times.
1471785 if(IS_16X16(mb_type)){
953
2/2
✓ Branch 0 taken 1254114 times.
✓ Branch 1 taken 994792 times.
2248906 for (list = 0; list < sl->list_count; list++) {
954 unsigned int val;
955
2/2
✓ Branch 0 taken 1050560 times.
✓ Branch 1 taken 203554 times.
1254114 if(IS_DIR(mb_type, 0, list)){
956 1050560 unsigned rc = sl->ref_count[list] << MB_MBAFF(sl);
957
2/2
✓ Branch 0 taken 550783 times.
✓ Branch 1 taken 499777 times.
1050560 if (rc == 1) {
958 550783 val= 0;
959
2/2
✓ Branch 0 taken 135504 times.
✓ Branch 1 taken 364273 times.
499777 } else if (rc == 2) {
960 135504 val= get_bits1(&sl->gb)^1;
961 }else{
962 364273 val= get_ue_golomb_31(&sl->gb);
963
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 364273 times.
364273 if (val >= rc) {
964 av_log(h->avctx, AV_LOG_ERROR, "ref %u overflow\n", val);
965 return -1;
966 }
967 }
968 1050560 fill_rectangle(&sl->ref_cache[list][ scan8[0] ], 4, 4, 8, val, 1);
969 }
970 }
971
2/2
✓ Branch 0 taken 1254114 times.
✓ Branch 1 taken 994792 times.
2248906 for (list = 0; list < sl->list_count; list++) {
972
2/2
✓ Branch 0 taken 1050560 times.
✓ Branch 1 taken 203554 times.
1254114 if(IS_DIR(mb_type, 0, list)){
973 1050560 pred_motion(h, sl, 0, 4, list, sl->ref_cache[list][ scan8[0] ], &mx, &my);
974 1050560 mx += (unsigned)get_se_golomb(&sl->gb);
975 1050560 my += (unsigned)get_se_golomb(&sl->gb);
976 ff_tlog(h->avctx, "final mv:%d %d\n", mx, my);
977
978 1050560 fill_rectangle(sl->mv_cache[list][ scan8[0] ], 4, 4, 8, pack16to32(mx,my), 4);
979 }
980 }
981 }
982
2/2
✓ Branch 0 taken 252561 times.
✓ Branch 1 taken 224432 times.
476993 else if(IS_16X8(mb_type)){
983
2/2
✓ Branch 0 taken 350968 times.
✓ Branch 1 taken 252561 times.
603529 for (list = 0; list < sl->list_count; list++) {
984
2/2
✓ Branch 0 taken 701936 times.
✓ Branch 1 taken 350968 times.
1052904 for(i=0; i<2; i++){
985 unsigned int val;
986
2/2
✓ Branch 0 taken 547878 times.
✓ Branch 1 taken 154058 times.
701936 if(IS_DIR(mb_type, i, list)){
987 547878 unsigned rc = sl->ref_count[list] << MB_MBAFF(sl);
988
2/2
✓ Branch 0 taken 204911 times.
✓ Branch 1 taken 342967 times.
547878 if (rc == 1) {
989 204911 val= 0;
990
2/2
✓ Branch 0 taken 80255 times.
✓ Branch 1 taken 262712 times.
342967 } else if (rc == 2) {
991 80255 val= get_bits1(&sl->gb)^1;
992 }else{
993 262712 val= get_ue_golomb_31(&sl->gb);
994
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 262712 times.
262712 if (val >= rc) {
995 av_log(h->avctx, AV_LOG_ERROR, "ref %u overflow\n", val);
996 return -1;
997 }
998 }
999 }else
1000 154058 val= LIST_NOT_USED&0xFF;
1001 701936 fill_rectangle(&sl->ref_cache[list][ scan8[0] + 16*i ], 4, 2, 8, val, 1);
1002 }
1003 }
1004
2/2
✓ Branch 0 taken 350968 times.
✓ Branch 1 taken 252561 times.
603529 for (list = 0; list < sl->list_count; list++) {
1005
2/2
✓ Branch 0 taken 701936 times.
✓ Branch 1 taken 350968 times.
1052904 for(i=0; i<2; i++){
1006 unsigned int val;
1007
2/2
✓ Branch 0 taken 547878 times.
✓ Branch 1 taken 154058 times.
701936 if(IS_DIR(mb_type, i, list)){
1008 547878 pred_16x8_motion(h, sl, 8*i, list, sl->ref_cache[list][scan8[0] + 16*i], &mx, &my);
1009 547878 mx += (unsigned)get_se_golomb(&sl->gb);
1010 547878 my += (unsigned)get_se_golomb(&sl->gb);
1011 ff_tlog(h->avctx, "final mv:%d %d\n", mx, my);
1012
1013 547878 val= pack16to32(mx,my);
1014 }else
1015 154058 val=0;
1016 701936 fill_rectangle(sl->mv_cache[list][ scan8[0] + 16*i ], 4, 2, 8, val, 4);
1017 }
1018 }
1019 }else{
1020 av_assert2(IS_8X16(mb_type));
1021
2/2
✓ Branch 0 taken 304325 times.
✓ Branch 1 taken 224432 times.
528757 for (list = 0; list < sl->list_count; list++) {
1022
2/2
✓ Branch 0 taken 608650 times.
✓ Branch 1 taken 304325 times.
912975 for(i=0; i<2; i++){
1023 unsigned int val;
1024
2/2
✓ Branch 0 taken 482052 times.
✓ Branch 1 taken 126598 times.
608650 if(IS_DIR(mb_type, i, list)){ //FIXME optimize
1025 482052 unsigned rc = sl->ref_count[list] << MB_MBAFF(sl);
1026
2/2
✓ Branch 0 taken 180611 times.
✓ Branch 1 taken 301441 times.
482052 if (rc == 1) {
1027 180611 val= 0;
1028
2/2
✓ Branch 0 taken 82740 times.
✓ Branch 1 taken 218701 times.
301441 } else if (rc == 2) {
1029 82740 val= get_bits1(&sl->gb)^1;
1030 }else{
1031 218701 val= get_ue_golomb_31(&sl->gb);
1032
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 218701 times.
218701 if (val >= rc) {
1033 av_log(h->avctx, AV_LOG_ERROR, "ref %u overflow\n", val);
1034 return -1;
1035 }
1036 }
1037 }else
1038 126598 val= LIST_NOT_USED&0xFF;
1039 608650 fill_rectangle(&sl->ref_cache[list][ scan8[0] + 2*i ], 2, 4, 8, val, 1);
1040 }
1041 }
1042
2/2
✓ Branch 0 taken 304325 times.
✓ Branch 1 taken 224432 times.
528757 for (list = 0; list < sl->list_count; list++) {
1043
2/2
✓ Branch 0 taken 608650 times.
✓ Branch 1 taken 304325 times.
912975 for(i=0; i<2; i++){
1044 unsigned int val;
1045
2/2
✓ Branch 0 taken 482052 times.
✓ Branch 1 taken 126598 times.
608650 if(IS_DIR(mb_type, i, list)){
1046 482052 pred_8x16_motion(h, sl, i*4, list, sl->ref_cache[list][ scan8[0] + 2*i ], &mx, &my);
1047 482052 mx += (unsigned)get_se_golomb(&sl->gb);
1048 482052 my += (unsigned)get_se_golomb(&sl->gb);
1049 ff_tlog(h->avctx, "final mv:%d %d\n", mx, my);
1050
1051 482052 val= pack16to32(mx,my);
1052 }else
1053 126598 val=0;
1054 608650 fill_rectangle(sl->mv_cache[list][ scan8[0] + 2*i ], 2, 4, 8, val, 4);
1055 }
1056 }
1057 }
1058 }
1059
1060
2/2
✓ Branch 0 taken 2104158 times.
✓ Branch 1 taken 1369532 times.
3473690 if(IS_INTER(mb_type))
1061 2104158 write_back_motion(h, sl, mb_type);
1062
1063
2/2
✓ Branch 0 taken 3263087 times.
✓ Branch 1 taken 210603 times.
3473690 if(!IS_INTRA16x16(mb_type)){
1064 3263087 cbp= get_ue_golomb(&sl->gb);
1065
1066
2/2
✓ Branch 0 taken 3223737 times.
✓ Branch 1 taken 39350 times.
3263087 if(decode_chroma){
1067
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3223737 times.
3223737 if(cbp > 47){
1068 av_log(h->avctx, AV_LOG_ERROR, "cbp too large (%u) at %d %d\n", cbp, sl->mb_x, sl->mb_y);
1069 return -1;
1070 }
1071
2/2
✓ Branch 0 taken 1134780 times.
✓ Branch 1 taken 2088957 times.
3223737 if (IS_INTRA4x4(mb_type))
1072 1134780 cbp = ff_h264_golomb_to_intra4x4_cbp[cbp];
1073 else
1074 2088957 cbp = ff_h264_golomb_to_inter_cbp[cbp];
1075 }else{
1076
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 39350 times.
39350 if(cbp > 15){
1077 av_log(h->avctx, AV_LOG_ERROR, "cbp too large (%u) at %d %d\n", cbp, sl->mb_x, sl->mb_y);
1078 return -1;
1079 }
1080
2/2
✓ Branch 0 taken 24149 times.
✓ Branch 1 taken 15201 times.
39350 if(IS_INTRA4x4(mb_type)) cbp= golomb_to_intra4x4_cbp_gray[cbp];
1081 15201 else cbp= golomb_to_inter_cbp_gray[cbp];
1082 }
1083 } else {
1084
3/4
✓ Branch 0 taken 2980 times.
✓ Branch 1 taken 207623 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2980 times.
210603 if (!decode_chroma && cbp>15) {
1085 av_log(h->avctx, AV_LOG_ERROR, "gray chroma\n");
1086 return AVERROR_INVALIDDATA;
1087 }
1088 }
1089
1090
6/6
✓ Branch 0 taken 1273759 times.
✓ Branch 1 taken 2199931 times.
✓ Branch 2 taken 1146561 times.
✓ Branch 3 taken 127198 times.
✓ Branch 4 taken 272479 times.
✓ Branch 5 taken 874082 times.
3473690 if(dct8x8_allowed && (cbp&15) && !IS_INTRA(mb_type)){
1091 272479 mb_type |= MB_TYPE_8x8DCT*get_bits1(&sl->gb);
1092 }
1093 3473690 sl->cbp=
1094 3473690 h->cbp_table[mb_xy]= cbp;
1095 3473690 h->cur_pic.mb_type[mb_xy] = mb_type;
1096
1097
4/4
✓ Branch 0 taken 764554 times.
✓ Branch 1 taken 2709136 times.
✓ Branch 2 taken 97508 times.
✓ Branch 3 taken 667046 times.
6280334 if(cbp || IS_INTRA16x16(mb_type)){
1098 int i4x4, i8x8, chroma_idx;
1099 int dquant;
1100 int ret;
1101 2806644 GetBitContext *gb = &sl->gb;
1102 const uint8_t *scan, *scan8x8;
1103 2806644 const int max_qp = 51 + 6 * (h->ps.sps->bit_depth_luma - 8);
1104
1105 2806644 dquant= get_se_golomb(&sl->gb);
1106
1107 2806644 sl->qscale += (unsigned)dquant;
1108
1109
2/2
✓ Branch 0 taken 8070 times.
✓ Branch 1 taken 2798574 times.
2806644 if (((unsigned)sl->qscale) > max_qp){
1110
2/2
✓ Branch 0 taken 3860 times.
✓ Branch 1 taken 4210 times.
8070 if (sl->qscale < 0) sl->qscale += max_qp + 1;
1111 4210 else sl->qscale -= max_qp+1;
1112
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8070 times.
8070 if (((unsigned)sl->qscale) > max_qp){
1113 av_log(h->avctx, AV_LOG_ERROR, "dquant out of range (%d) at %d %d\n", dquant, sl->mb_x, sl->mb_y);
1114 sl->qscale = max_qp;
1115 return -1;
1116 }
1117 }
1118
1119 2806644 sl->chroma_qp[0] = get_chroma_qp(h->ps.pps, 0, sl->qscale);
1120 2806644 sl->chroma_qp[1] = get_chroma_qp(h->ps.pps, 1, sl->qscale);
1121
1122
2/2
✓ Branch 0 taken 824163 times.
✓ Branch 1 taken 1982481 times.
2806644 if(IS_INTERLACED(mb_type)){
1123
2/2
✓ Branch 0 taken 824002 times.
✓ Branch 1 taken 161 times.
824163 scan8x8 = sl->qscale ? h->field_scan8x8_cavlc : h->field_scan8x8_cavlc_q0;
1124
2/2
✓ Branch 0 taken 824002 times.
✓ Branch 1 taken 161 times.
824163 scan = sl->qscale ? h->field_scan : h->field_scan_q0;
1125 }else{
1126
2/2
✓ Branch 0 taken 1981592 times.
✓ Branch 1 taken 889 times.
1982481 scan8x8 = sl->qscale ? h->zigzag_scan8x8_cavlc : h->zigzag_scan8x8_cavlc_q0;
1127
2/2
✓ Branch 0 taken 1981592 times.
✓ Branch 1 taken 889 times.
1982481 scan = sl->qscale ? h->zigzag_scan : h->zigzag_scan_q0;
1128 }
1129
1130
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2806644 times.
2806644 if ((ret = decode_luma_residual(h, sl, gb, scan, scan8x8, pixel_shift, mb_type, cbp, 0)) < 0 ) {
1131 return -1;
1132 }
1133 2806644 h->cbp_table[mb_xy] |= ret << 12;
1134
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2806644 times.
2806644 if (CHROMA444(h)) {
1135 if (decode_luma_residual(h, sl, gb, scan, scan8x8, pixel_shift, mb_type, cbp, 1) < 0 ) {
1136 return -1;
1137 }
1138 if (decode_luma_residual(h, sl, gb, scan, scan8x8, pixel_shift, mb_type, cbp, 2) < 0 ) {
1139 return -1;
1140 }
1141 } else {
1142 2806644 const int num_c8x8 = h->ps.sps->chroma_format_idc;
1143
1144
2/2
✓ Branch 0 taken 1567556 times.
✓ Branch 1 taken 1239088 times.
2806644 if(cbp&0x30){
1145
2/2
✓ Branch 0 taken 3135112 times.
✓ Branch 1 taken 1567556 times.
4702668 for(chroma_idx=0; chroma_idx<2; chroma_idx++)
1146
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 3135112 times.
3135112 if (decode_residual(h, sl, gb, sl->mb + ((256 + 16*16*chroma_idx) << pixel_shift),
1147 CHROMA_DC_BLOCK_INDEX + chroma_idx,
1148
2/2
✓ Branch 0 taken 579058 times.
✓ Branch 1 taken 2556054 times.
3135112 CHROMA422(h) ? ff_h264_chroma422_dc_scan : ff_h264_chroma_dc_scan,
1149 NULL, 4 * num_c8x8) < 0) {
1150 return -1;
1151 }
1152 }
1153
1154
2/2
✓ Branch 0 taken 1006434 times.
✓ Branch 1 taken 1800210 times.
2806644 if(cbp&0x20){
1155
2/2
✓ Branch 0 taken 2012868 times.
✓ Branch 1 taken 1006434 times.
3019302 for(chroma_idx=0; chroma_idx<2; chroma_idx++){
1156
2/2
✓ Branch 0 taken 1164378 times.
✓ Branch 1 taken 848490 times.
2012868 const uint32_t *qmul = h->ps.pps->dequant4_coeff[chroma_idx+1+(IS_INTRA( mb_type ) ? 0:3)][sl->chroma_qp[chroma_idx]];
1157 2012868 int16_t *mb = sl->mb + (16*(16 + 16*chroma_idx) << pixel_shift);
1158
2/2
✓ Branch 0 taken 2400012 times.
✓ Branch 1 taken 2012868 times.
4412880 for (i8x8 = 0; i8x8<num_c8x8; i8x8++) {
1159
2/2
✓ Branch 0 taken 9600048 times.
✓ Branch 1 taken 2400012 times.
12000060 for (i4x4 = 0; i4x4 < 4; i4x4++) {
1160 9600048 const int index = 16 + 16*chroma_idx + 8*i8x8 + i4x4;
1161
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 9600048 times.
9600048 if (decode_residual(h, sl, gb, mb, index, scan + 1, qmul, 15) < 0)
1162 return -1;
1163 9600048 mb += 16 << pixel_shift;
1164 }
1165 }
1166 }
1167 }else{
1168 1800210 fill_rectangle(&sl->non_zero_count_cache[scan8[16]], 4, 4, 8, 0, 1);
1169 1800210 fill_rectangle(&sl->non_zero_count_cache[scan8[32]], 4, 4, 8, 0, 1);
1170 }
1171 }
1172 }else{
1173 667046 fill_rectangle(&sl->non_zero_count_cache[scan8[ 0]], 4, 4, 8, 0, 1);
1174 667046 fill_rectangle(&sl->non_zero_count_cache[scan8[16]], 4, 4, 8, 0, 1);
1175 667046 fill_rectangle(&sl->non_zero_count_cache[scan8[32]], 4, 4, 8, 0, 1);
1176 }
1177 3473690 h->cur_pic.qscale_table[mb_xy] = sl->qscale;
1178 3473690 write_back_non_zero_count(h, sl);
1179
1180 3473690 return 0;
1181 }
1182