FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/h264_cavlc.c
Date: 2026-04-30 23:37:26
Exec Total Coverage
Lines: 451 501 90.0%
Functions: 7 7 100.0%
Branches: 348 384 90.6%

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 "h264dec.h"
32 #include "h264_mvpred.h"
33 #include "h264data.h"
34 #include "golomb.h"
35 #include "mpegutils.h"
36 #include "libavutil/avassert.h"
37
38
39 static const uint8_t golomb_to_inter_cbp_gray[16]={
40 0, 1, 2, 4, 8, 3, 5,10,12,15, 7,11,13,14, 6, 9,
41 };
42
43 static const uint8_t golomb_to_intra4x4_cbp_gray[16]={
44 15, 0, 7,11,13,14, 3, 5,10,12, 1, 2, 4, 8, 6, 9,
45 };
46
47 static const uint8_t chroma_dc_coeff_token_len[4*5]={
48 2, 0, 0, 0,
49 6, 1, 0, 0,
50 6, 6, 3, 0,
51 6, 7, 7, 6,
52 6, 8, 8, 7,
53 };
54
55 static const uint8_t chroma_dc_coeff_token_bits[4*5]={
56 1, 0, 0, 0,
57 7, 1, 0, 0,
58 4, 6, 1, 0,
59 3, 3, 2, 5,
60 2, 3, 2, 0,
61 };
62
63 static const uint8_t chroma422_dc_coeff_token_len[4*9]={
64 1, 0, 0, 0,
65 7, 2, 0, 0,
66 7, 7, 3, 0,
67 9, 7, 7, 5,
68 9, 9, 7, 6,
69 10, 10, 9, 7,
70 11, 11, 10, 7,
71 12, 12, 11, 10,
72 13, 12, 12, 11,
73 };
74
75 static const uint8_t chroma422_dc_coeff_token_bits[4*9]={
76 1, 0, 0, 0,
77 15, 1, 0, 0,
78 14, 13, 1, 0,
79 7, 12, 11, 1,
80 6, 5, 10, 1,
81 7, 6, 4, 9,
82 7, 6, 5, 8,
83 7, 6, 5, 4,
84 7, 5, 4, 4,
85 };
86
87 static const uint8_t coeff_token_len[4][4*17]={
88 {
89 1, 0, 0, 0,
90 6, 2, 0, 0, 8, 6, 3, 0, 9, 8, 7, 5, 10, 9, 8, 6,
91 11,10, 9, 7, 13,11,10, 8, 13,13,11, 9, 13,13,13,10,
92 14,14,13,11, 14,14,14,13, 15,15,14,14, 15,15,15,14,
93 16,15,15,15, 16,16,16,15, 16,16,16,16, 16,16,16,16,
94 },
95 {
96 2, 0, 0, 0,
97 6, 2, 0, 0, 6, 5, 3, 0, 7, 6, 6, 4, 8, 6, 6, 4,
98 8, 7, 7, 5, 9, 8, 8, 6, 11, 9, 9, 6, 11,11,11, 7,
99 12,11,11, 9, 12,12,12,11, 12,12,12,11, 13,13,13,12,
100 13,13,13,13, 13,14,13,13, 14,14,14,13, 14,14,14,14,
101 },
102 {
103 4, 0, 0, 0,
104 6, 4, 0, 0, 6, 5, 4, 0, 6, 5, 5, 4, 7, 5, 5, 4,
105 7, 5, 5, 4, 7, 6, 6, 4, 7, 6, 6, 4, 8, 7, 7, 5,
106 8, 8, 7, 6, 9, 8, 8, 7, 9, 9, 8, 8, 9, 9, 9, 8,
107 10, 9, 9, 9, 10,10,10,10, 10,10,10,10, 10,10,10,10,
108 },
109 {
110 6, 0, 0, 0,
111 6, 6, 0, 0, 6, 6, 6, 0, 6, 6, 6, 6, 6, 6, 6, 6,
112 6, 6, 6, 6, 6, 6, 6, 6, 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 }
116 };
117
118 static const uint8_t coeff_token_bits[4][4*17]={
119 {
120 1, 0, 0, 0,
121 5, 1, 0, 0, 7, 4, 1, 0, 7, 6, 5, 3, 7, 6, 5, 3,
122 7, 6, 5, 4, 15, 6, 5, 4, 11,14, 5, 4, 8,10,13, 4,
123 15,14, 9, 4, 11,10,13,12, 15,14, 9,12, 11,10,13, 8,
124 15, 1, 9,12, 11,14,13, 8, 7,10, 9,12, 4, 6, 5, 8,
125 },
126 {
127 3, 0, 0, 0,
128 11, 2, 0, 0, 7, 7, 3, 0, 7,10, 9, 5, 7, 6, 5, 4,
129 4, 6, 5, 6, 7, 6, 5, 8, 15, 6, 5, 4, 11,14,13, 4,
130 15,10, 9, 4, 11,14,13,12, 8,10, 9, 8, 15,14,13,12,
131 11,10, 9,12, 7,11, 6, 8, 9, 8,10, 1, 7, 6, 5, 4,
132 },
133 {
134 15, 0, 0, 0,
135 15,14, 0, 0, 11,15,13, 0, 8,12,14,12, 15,10,11,11,
136 11, 8, 9,10, 9,14,13, 9, 8,10, 9, 8, 15,14,13,13,
137 11,14,10,12, 15,10,13,12, 11,14, 9,12, 8,10,13, 8,
138 13, 7, 9,12, 9,12,11,10, 5, 8, 7, 6, 1, 4, 3, 2,
139 },
140 {
141 3, 0, 0, 0,
142 0, 1, 0, 0, 4, 5, 6, 0, 8, 9,10,11, 12,13,14,15,
143 16,17,18,19, 20,21,22,23, 24,25,26,27, 28,29,30,31,
144 32,33,34,35, 36,37,38,39, 40,41,42,43, 44,45,46,47,
145 48,49,50,51, 52,53,54,55, 56,57,58,59, 60,61,62,63,
146 }
147 };
148
149 static const uint8_t total_zeros_len[16][16]= {
150 {1,3,3,4,4,5,5,6,6,7,7,8,8,9,9,9},
151 {3,3,3,3,3,4,4,4,4,5,5,6,6,6,6},
152 {4,3,3,3,4,4,3,3,4,5,5,6,5,6},
153 {5,3,4,4,3,3,3,4,3,4,5,5,5},
154 {4,4,4,3,3,3,3,3,4,5,4,5},
155 {6,5,3,3,3,3,3,3,4,3,6},
156 {6,5,3,3,3,2,3,4,3,6},
157 {6,4,5,3,2,2,3,3,6},
158 {6,6,4,2,2,3,2,5},
159 {5,5,3,2,2,2,4},
160 {4,4,3,3,1,3},
161 {4,4,2,1,3},
162 {3,3,1,2},
163 {2,2,1},
164 {1,1},
165 };
166
167 static const uint8_t total_zeros_bits[16][16]= {
168 {1,3,2,3,2,3,2,3,2,3,2,3,2,3,2,1},
169 {7,6,5,4,3,5,4,3,2,3,2,3,2,1,0},
170 {5,7,6,5,4,3,4,3,2,3,2,1,1,0},
171 {3,7,5,4,6,5,4,3,3,2,2,1,0},
172 {5,4,3,7,6,5,4,3,2,1,1,0},
173 {1,1,7,6,5,4,3,2,1,1,0},
174 {1,1,5,4,3,3,2,1,1,0},
175 {1,1,1,3,3,2,2,1,0},
176 {1,0,1,3,2,1,1,1},
177 {1,0,1,3,2,1,1},
178 {0,1,1,2,1,3},
179 {0,1,1,1,1},
180 {0,1,1,1},
181 {0,1,1},
182 {0,1},
183 };
184
185 static const uint8_t chroma_dc_total_zeros_len[3][4]= {
186 { 1, 2, 3, 3,},
187 { 1, 2, 2, 0,},
188 { 1, 1, 0, 0,},
189 };
190
191 static const uint8_t chroma_dc_total_zeros_bits[3][4]= {
192 { 1, 1, 1, 0,},
193 { 1, 1, 0, 0,},
194 { 1, 0, 0, 0,},
195 };
196
197 static const uint8_t chroma422_dc_total_zeros_len[7][8]= {
198 { 1, 3, 3, 4, 4, 4, 5, 5 },
199 { 3, 2, 3, 3, 3, 3, 3 },
200 { 3, 3, 2, 2, 3, 3 },
201 { 3, 2, 2, 2, 3 },
202 { 2, 2, 2, 2 },
203 { 2, 2, 1 },
204 { 1, 1 },
205 };
206
207 static const uint8_t chroma422_dc_total_zeros_bits[7][8]= {
208 { 1, 2, 3, 2, 3, 1, 1, 0 },
209 { 0, 1, 1, 4, 5, 6, 7 },
210 { 0, 1, 1, 2, 6, 7 },
211 { 6, 0, 1, 2, 7 },
212 { 0, 1, 2, 3 },
213 { 0, 1, 1 },
214 { 0, 1 },
215 };
216
217 static const uint8_t run_len[7][16]={
218 {1,1},
219 {1,2,2},
220 {2,2,2,2},
221 {2,2,2,3,3},
222 {2,2,3,3,3,3},
223 {2,3,3,3,3,3,3},
224 {3,3,3,3,3,3,3,4,5,6,7,8,9,10,11},
225 };
226
227 static const uint8_t run_bits[7][16]={
228 {1,0},
229 {1,1,0},
230 {3,2,1,0},
231 {3,2,1,1,0},
232 {3,2,3,2,1,0},
233 {3,0,1,3,2,5,4},
234 {7,6,5,4,3,2,1,1,1,1,1,1,1,1,1},
235 };
236
237 #define LEVEL_TAB_BITS 8
238 static int8_t cavlc_level_tab[7][1<<LEVEL_TAB_BITS][2];
239
240 #define CHROMA_DC_COEFF_TOKEN_VLC_BITS 8
241 #define CHROMA422_DC_COEFF_TOKEN_VLC_BITS 13
242 #define COEFF_TOKEN_VLC_BITS 8
243 #define TOTAL_ZEROS_VLC_BITS 9
244 #define CHROMA_DC_TOTAL_ZEROS_VLC_BITS 3
245 #define CHROMA422_DC_TOTAL_ZEROS_VLC_BITS 5
246 #define RUN_VLC_BITS 3
247 #define RUN7_VLC_BITS 6
248
249 /// 17 pointers to only four different VLCs
250 static const VLCElem *coeff_token_vlc[17];
251
252 static VLCElem chroma_dc_coeff_token_vlc_table[256];
253
254 static VLCElem chroma422_dc_coeff_token_vlc_table[1 << CHROMA422_DC_COEFF_TOKEN_VLC_BITS];
255
256 static const VLCElem *total_zeros_vlc[15+1];
257
258 static const VLCElem *chroma_dc_total_zeros_vlc[3+1];
259
260 static const VLCElem *chroma422_dc_total_zeros_vlc[7+1];
261
262 static const VLCElem *run_vlc[6+1];
263
264 // The other pointers to VLCElem point into this array.
265 static VLCElem run7_vlc_table[96 + (6 << RUN_VLC_BITS)
266 + (15 << TOTAL_ZEROS_VLC_BITS)
267 + (3 << CHROMA_DC_TOTAL_ZEROS_VLC_BITS)
268 + (7 << CHROMA422_DC_TOTAL_ZEROS_VLC_BITS)
269 + (520 + 332 + 280 + 256) /* coeff token */];
270
271 /**
272 * Get the predicted number of non-zero coefficients.
273 * @param n block index
274 */
275 43061423 static inline int pred_non_zero_count(const H264Context *h, const H264SliceContext *sl, int n)
276 {
277 43061423 const int index8= scan8[n];
278 43061423 const int left = sl->non_zero_count_cache[index8 - 1];
279 43061423 const int top = sl->non_zero_count_cache[index8 - 8];
280 43061423 int i= left + top;
281
282
2/2
✓ Branch 0 taken 41398194 times.
✓ Branch 1 taken 1663229 times.
43061423 if(i<64) i= (i+1)>>1;
283
284 ff_tlog(h->avctx, "pred_nnz L%X T%X n%d s%d P%X\n", left, top, n, scan8[n], i&31);
285
286 43061423 return i&31;
287 }
288
289 341 static av_cold void init_cavlc_level_tab(void){
290 int suffix_length;
291 unsigned int i;
292
293
2/2
✓ Branch 0 taken 2387 times.
✓ Branch 1 taken 341 times.
2728 for(suffix_length=0; suffix_length<7; suffix_length++){
294
2/2
✓ Branch 0 taken 611072 times.
✓ Branch 1 taken 2387 times.
613459 for(i=0; i<(1<<LEVEL_TAB_BITS); i++){
295 611072 int prefix= LEVEL_TAB_BITS - av_log2(2*i);
296
297
2/2
✓ Branch 0 taken 567765 times.
✓ Branch 1 taken 43307 times.
611072 if(prefix + 1 + suffix_length <= LEVEL_TAB_BITS){
298 567765 int level_code = (prefix << suffix_length) +
299 567765 (i >> (av_log2(i) - suffix_length)) - (1 << suffix_length);
300 567765 int mask = -(level_code&1);
301 567765 level_code = (((2 + level_code) >> 1) ^ mask) - mask;
302 567765 cavlc_level_tab[suffix_length][i][0]= level_code;
303 567765 cavlc_level_tab[suffix_length][i][1]= prefix + 1 + suffix_length;
304
2/2
✓ Branch 0 taken 40920 times.
✓ Branch 1 taken 2387 times.
43307 }else if(prefix + 1 <= LEVEL_TAB_BITS){
305 40920 cavlc_level_tab[suffix_length][i][0]= prefix+100;
306 40920 cavlc_level_tab[suffix_length][i][1]= prefix + 1;
307 }else{
308 2387 cavlc_level_tab[suffix_length][i][0]= LEVEL_TAB_BITS+100;
309 2387 cavlc_level_tab[suffix_length][i][1]= LEVEL_TAB_BITS;
310 }
311 }
312 }
313 341 }
314
315 341 av_cold void ff_h264_decode_init_vlc(void)
316 {
317 const VLCElem *coeff_token_vlc_original[4];
318 341 VLCInitState state = VLC_INIT_STATE(run7_vlc_table);
319
320 341 VLC_INIT_STATIC_TABLE(chroma_dc_coeff_token_vlc_table,
321 CHROMA_DC_COEFF_TOKEN_VLC_BITS, 4 * 5,
322 &chroma_dc_coeff_token_len [0], 1, 1,
323 &chroma_dc_coeff_token_bits[0], 1, 1, 0);
324
325 341 VLC_INIT_STATIC_TABLE(chroma422_dc_coeff_token_vlc_table,
326 CHROMA422_DC_COEFF_TOKEN_VLC_BITS, 4 * 9,
327 &chroma422_dc_coeff_token_len [0], 1, 1,
328 &chroma422_dc_coeff_token_bits[0], 1, 1, 0);
329
330 341 ff_vlc_init_tables(&state, RUN7_VLC_BITS, 16,
331 &run_len [6][0], 1, 1,
332 &run_bits[6][0], 1, 1, 0);
333
334
2/2
✓ Branch 0 taken 2046 times.
✓ Branch 1 taken 341 times.
2387 for (int i = 0; i < 6; i++) {
335 2046 run_vlc[i + 1] = ff_vlc_init_tables(&state, RUN_VLC_BITS, 7,
336 2046 &run_len [i][0], 1, 1,
337 2046 &run_bits[i][0], 1, 1, 0);
338 }
339
340
2/2
✓ Branch 0 taken 1364 times.
✓ Branch 1 taken 341 times.
1705 for (int i = 0; i < 4; i++) {
341 1364 coeff_token_vlc_original[i] =
342 1364 ff_vlc_init_tables(&state, COEFF_TOKEN_VLC_BITS, 4*17,
343 1364 &coeff_token_len [i][0], 1, 1,
344 1364 &coeff_token_bits[i][0], 1, 1, 0);
345 }
346
2/2
✓ Branch 0 taken 5797 times.
✓ Branch 1 taken 341 times.
6138 for (int i = 0; i < FF_ARRAY_ELEMS(coeff_token_vlc); i++) {
347 static const uint8_t coeff_token_table_index[17] = {
348 0, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3
349 };
350 5797 coeff_token_vlc[i] = coeff_token_vlc_original[coeff_token_table_index[i]];
351 }
352
353
2/2
✓ Branch 0 taken 1023 times.
✓ Branch 1 taken 341 times.
1364 for (int i = 0; i < 3; i++) {
354 1023 chroma_dc_total_zeros_vlc[i + 1] =
355 1023 ff_vlc_init_tables(&state, CHROMA_DC_TOTAL_ZEROS_VLC_BITS, 4,
356 1023 &chroma_dc_total_zeros_len [i][0], 1, 1,
357 1023 &chroma_dc_total_zeros_bits[i][0], 1, 1, 0);
358 }
359
360
2/2
✓ Branch 0 taken 2387 times.
✓ Branch 1 taken 341 times.
2728 for (int i = 0; i < 7; i++) {
361 2387 chroma422_dc_total_zeros_vlc[i + 1] =
362 2387 ff_vlc_init_tables(&state, CHROMA422_DC_TOTAL_ZEROS_VLC_BITS, 8,
363 2387 &chroma422_dc_total_zeros_len [i][0], 1, 1,
364 2387 &chroma422_dc_total_zeros_bits[i][0], 1, 1, 0);
365 }
366
367
2/2
✓ Branch 0 taken 5115 times.
✓ Branch 1 taken 341 times.
5456 for (int i = 0; i < 15; i++) {
368 5115 total_zeros_vlc[i + 1] =
369 5115 ff_vlc_init_tables(&state, TOTAL_ZEROS_VLC_BITS, 16,
370 5115 &total_zeros_len [i][0], 1, 1,
371 5115 &total_zeros_bits[i][0], 1, 1, 0);
372 }
373 /*
374 * This is a one time safety check to make sure that
375 * the vlc table sizes were initialized correctly.
376 */
377 av_assert1(state.size == 0);
378
379 341 init_cavlc_level_tab();
380 341 }
381
382 707163 static inline int get_level_prefix(GetBitContext *gb){
383 unsigned int buf;
384 int log;
385
386 707163 OPEN_READER(re, gb);
387 707163 UPDATE_CACHE(re, gb);
388 707163 buf=GET_CACHE(re, gb);
389
390 707163 log= 32 - av_log2(buf);
391
392 707163 LAST_SKIP_BITS(re, gb, log);
393 707163 CLOSE_READER(re, gb);
394
395 707163 return log-1;
396 }
397
398 /**
399 * Decode a residual block.
400 * @param n block index
401 * @param scantable scantable
402 * @param max_coeff number of coefficients in the block
403 * @return <0 if an error occurred
404 */
405 46353561 static int decode_residual(const H264Context *h, H264SliceContext *sl,
406 GetBitContext *gb, int16_t *block, int n,
407 const uint8_t *scantable, const uint32_t *qmul,
408 int max_coeff)
409 {
410 int level[16];
411 int zeros_left, coeff_token, total_coeff, i, trailing_ones, run_before;
412
413 //FIXME put trailing_onex into the context
414
415
2/2
✓ Branch 0 taken 3292138 times.
✓ Branch 1 taken 43061423 times.
46353561 if(max_coeff <= 8){
416
2/2
✓ Branch 0 taken 2713080 times.
✓ Branch 1 taken 579058 times.
3292138 if (max_coeff == 4)
417 2713080 coeff_token = get_vlc2(gb, chroma_dc_coeff_token_vlc_table,
418 CHROMA_DC_COEFF_TOKEN_VLC_BITS, 1);
419 else
420 579058 coeff_token = get_vlc2(gb, chroma422_dc_coeff_token_vlc_table,
421 CHROMA422_DC_COEFF_TOKEN_VLC_BITS, 1);
422 }else{
423
2/2
✓ Branch 0 taken 298287 times.
✓ Branch 1 taken 42763136 times.
43359710 total_coeff = pred_non_zero_count(h, sl, n >= LUMA_DC_BLOCK_INDEX ?
424 298287 (n - LUMA_DC_BLOCK_INDEX) * 16 : n);
425 43061423 coeff_token = get_vlc2(gb, coeff_token_vlc[total_coeff],
426 COEFF_TOKEN_VLC_BITS, 2);
427 }
428 46353561 total_coeff = coeff_token >> 2;
429 46353561 sl->non_zero_count_cache[scan8[n]] = total_coeff;
430
431 //FIXME set last_non_zero?
432
433
2/2
✓ Branch 0 taken 16176079 times.
✓ Branch 1 taken 30177482 times.
46353561 if(total_coeff==0)
434 16176079 return 0;
435
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 30177482 times.
30177482 if(total_coeff > (unsigned)max_coeff) {
436 av_log(h->avctx, AV_LOG_ERROR, "corrupted macroblock %d %d (total_coeff=%d)\n", sl->mb_x, sl->mb_y, total_coeff);
437 return -1;
438 }
439
440 30177482 trailing_ones= coeff_token&3;
441 ff_tlog(h->avctx, "trailing:%d, total:%d\n", trailing_ones, total_coeff);
442 av_assert2(total_coeff<=16);
443
444 30177482 i = show_bits(gb, 3);
445 30177482 skip_bits(gb, trailing_ones);
446 30177482 level[0] = 1-((i&4)>>1);
447 30177482 level[1] = 1-((i&2) );
448 30177482 level[2] = 1-((i&1)<<1);
449
450
2/2
✓ Branch 0 taken 13669290 times.
✓ Branch 1 taken 16508192 times.
30177482 if(trailing_ones<total_coeff) {
451 int mask, prefix;
452 13669290 int suffix_length = total_coeff > 10 & trailing_ones < 3;
453 13669290 int bitsi= show_bits(gb, LEVEL_TAB_BITS);
454 13669290 int level_code= cavlc_level_tab[suffix_length][bitsi][0];
455
456 13669290 skip_bits(gb, cavlc_level_tab[suffix_length][bitsi][1]);
457
2/2
✓ Branch 0 taken 314171 times.
✓ Branch 1 taken 13355119 times.
13669290 if(level_code >= 100){
458 314171 prefix= level_code - 100;
459
2/2
✓ Branch 0 taken 310269 times.
✓ Branch 1 taken 3902 times.
314171 if(prefix == LEVEL_TAB_BITS)
460 310269 prefix += get_level_prefix(gb);
461
462 //first coefficient has suffix_length equal to 0 or 1
463
2/2
✓ Branch 0 taken 190579 times.
✓ Branch 1 taken 123592 times.
314171 if(prefix<14){ //FIXME try to build a large unified VLC table for all this
464
2/2
✓ Branch 0 taken 12605 times.
✓ Branch 1 taken 177974 times.
190579 if(suffix_length)
465 12605 level_code= (prefix<<1) + get_bits1(gb); //part
466 else
467 177974 level_code= prefix; //part
468
2/2
✓ Branch 0 taken 57147 times.
✓ Branch 1 taken 66445 times.
123592 }else if(prefix==14){
469
2/2
✓ Branch 0 taken 536 times.
✓ Branch 1 taken 56611 times.
57147 if(suffix_length)
470 536 level_code= (prefix<<1) + get_bits1(gb); //part
471 else
472 56611 level_code= prefix + get_bits(gb, 4); //part
473 }else{
474 66445 level_code= 30;
475
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 66421 times.
66445 if(prefix>=16){
476
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
24 if(prefix > 25+3){
477 av_log(h->avctx, AV_LOG_ERROR, "Invalid level prefix\n");
478 return -1;
479 }
480 24 level_code += (1<<(prefix-3))-4096;
481 }
482 66445 level_code += get_bits(gb, prefix-3); //part
483 }
484
485
2/2
✓ Branch 0 taken 241341 times.
✓ Branch 1 taken 72830 times.
314171 if(trailing_ones < 3) level_code += 2;
486
487 314171 suffix_length = 2;
488 314171 mask= -(level_code&1);
489 314171 level[trailing_ones]= (((2+level_code)>>1) ^ mask) - mask;
490 }else{
491 13355119 level_code += ((level_code>>31)|1) & -(trailing_ones < 3);
492
493
2/2
✓ Branch 0 taken 750387 times.
✓ Branch 1 taken 12604732 times.
13355119 suffix_length = 1 + (level_code + 3U > 6U);
494 13355119 level[trailing_ones]= level_code;
495 }
496
497 //remaining coefficients have suffix_length > 0
498
2/2
✓ Branch 0 taken 39004455 times.
✓ Branch 1 taken 13669290 times.
52673745 for(i=trailing_ones+1;i<total_coeff;i++) {
499 static const unsigned int suffix_limit[7] = {0,3,6,12,24,48,INT_MAX };
500 39004455 int bitsi= show_bits(gb, LEVEL_TAB_BITS);
501 39004455 level_code= cavlc_level_tab[suffix_length][bitsi][0];
502
503 39004455 skip_bits(gb, cavlc_level_tab[suffix_length][bitsi][1]);
504
2/2
✓ Branch 0 taken 803046 times.
✓ Branch 1 taken 38201409 times.
39004455 if(level_code >= 100){
505 803046 prefix= level_code - 100;
506
2/2
✓ Branch 0 taken 396894 times.
✓ Branch 1 taken 406152 times.
803046 if(prefix == LEVEL_TAB_BITS){
507 396894 prefix += get_level_prefix(gb);
508 }
509
2/2
✓ Branch 0 taken 737640 times.
✓ Branch 1 taken 65406 times.
803046 if(prefix<15){
510 737640 level_code = (prefix<<suffix_length) + get_bits(gb, suffix_length);
511 }else{
512 65406 level_code = 15<<suffix_length;
513
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 65402 times.
65406 if (prefix>=16) {
514
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if(prefix > 25+3){
515 av_log(h->avctx, AV_LOG_ERROR, "Invalid level prefix\n");
516 return AVERROR_INVALIDDATA;
517 }
518 4 level_code += (1<<(prefix-3))-4096;
519 }
520 65406 level_code += get_bits(gb, prefix-3);
521 }
522 803046 mask= -(level_code&1);
523 803046 level_code= (((2+level_code)>>1) ^ mask) - mask;
524 }
525 39004455 level[i]= level_code;
526 39004455 suffix_length+= suffix_limit[suffix_length] + level_code > 2U*suffix_limit[suffix_length];
527 }
528 }
529
530
2/2
✓ Branch 0 taken 302444 times.
✓ Branch 1 taken 29875038 times.
30177482 if(total_coeff == max_coeff)
531 302444 zeros_left=0;
532 else{
533
2/2
✓ Branch 0 taken 1964377 times.
✓ Branch 1 taken 27910661 times.
29875038 if (max_coeff <= 8) {
534
2/2
✓ Branch 0 taken 1506995 times.
✓ Branch 1 taken 457382 times.
1964377 if (max_coeff == 4)
535 1506995 zeros_left = get_vlc2(gb, chroma_dc_total_zeros_vlc[total_coeff],
536 CHROMA_DC_TOTAL_ZEROS_VLC_BITS, 1);
537 else
538 457382 zeros_left = get_vlc2(gb, chroma422_dc_total_zeros_vlc[total_coeff],
539 CHROMA422_DC_TOTAL_ZEROS_VLC_BITS, 1);
540 } else {
541 27910661 zeros_left = get_vlc2(gb, total_zeros_vlc[total_coeff],
542 TOTAL_ZEROS_VLC_BITS, 1);
543 }
544 }
545
546 #define STORE_BLOCK(type) \
547 scantable += zeros_left + total_coeff - 1; \
548 if(n >= LUMA_DC_BLOCK_INDEX){ \
549 ((type*)block)[*scantable] = level[0]; \
550 for(i=1;i<total_coeff && zeros_left > 0;i++) { \
551 if(zeros_left < 7) \
552 run_before = get_vlc2(gb, run_vlc[zeros_left], RUN_VLC_BITS, 1); \
553 else \
554 run_before = get_vlc2(gb, run7_vlc_table, RUN7_VLC_BITS, 2); \
555 zeros_left -= run_before; \
556 scantable -= 1 + run_before; \
557 ((type*)block)[*scantable]= level[i]; \
558 } \
559 for(;i<total_coeff;i++) { \
560 scantable--; \
561 ((type*)block)[*scantable]= level[i]; \
562 } \
563 }else{ \
564 ((type*)block)[*scantable] = ((int)(level[0] * qmul[*scantable] + 32))>>6; \
565 for(i=1;i<total_coeff && zeros_left > 0;i++) { \
566 if(zeros_left < 7) \
567 run_before = get_vlc2(gb, run_vlc[zeros_left], RUN_VLC_BITS, 1); \
568 else \
569 run_before = get_vlc2(gb, run7_vlc_table, RUN7_VLC_BITS, 2); \
570 zeros_left -= run_before; \
571 scantable -= 1 + run_before; \
572 ((type*)block)[*scantable]= ((int)(level[i] * qmul[*scantable] + 32))>>6; \
573 } \
574 for(;i<total_coeff;i++) { \
575 scantable--; \
576 ((type*)block)[*scantable]= ((int)(level[i] * qmul[*scantable] + 32))>>6; \
577 } \
578 }
579
580
2/2
✓ Branch 0 taken 10462176 times.
✓ Branch 1 taken 19715306 times.
30177482 if (h->pixel_shift) {
581
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)
582 } else {
583
18/18
✓ Branch 0 taken 1507582 times.
✓ Branch 1 taken 18207724 times.
✓ Branch 2 taken 659826 times.
✓ Branch 3 taken 20003 times.
✓ Branch 6 taken 1109906 times.
✓ Branch 7 taken 1077505 times.
✓ Branch 8 taken 679829 times.
✓ Branch 9 taken 430077 times.
✓ Branch 10 taken 1084536 times.
✓ Branch 11 taken 1507582 times.
✓ Branch 12 taken 27108357 times.
✓ Branch 13 taken 4108039 times.
✓ Branch 16 taken 35442038 times.
✓ Branch 17 taken 13982082 times.
✓ Branch 18 taken 31216396 times.
✓ Branch 19 taken 4225642 times.
✓ Branch 20 taken 11870050 times.
✓ Branch 21 taken 18207724 times.
64566117 STORE_BLOCK(int16_t)
584 }
585
586
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 30177482 times.
30177482 if(zeros_left<0){
587 av_log(h->avctx, AV_LOG_ERROR, "negative number of zero coeffs at %d %d\n", sl->mb_x, sl->mb_y);
588 return -1;
589 }
590
591 30177482 return 0;
592 }
593
594 static av_always_inline
595 2999279 int decode_luma_residual(const H264Context *h, H264SliceContext *sl,
596 GetBitContext *gb, const uint8_t *scan,
597 const uint8_t *scan8x8, int pixel_shift,
598 int mb_type, int cbp, int p)
599 {
600 int i4x4, i8x8;
601
1/2
✓ Branch 0 taken 2999279 times.
✗ Branch 1 not taken.
2999279 int qscale = p == 0 ? sl->qscale : sl->chroma_qp[p - 1];
602
2/2
✓ Branch 0 taken 298287 times.
✓ Branch 1 taken 2700992 times.
2999279 if(IS_INTRA16x16(mb_type)){
603 298287 AV_ZERO128(sl->mb_luma_dc[p]+0);
604 298287 AV_ZERO128(sl->mb_luma_dc[p]+8);
605 298287 AV_ZERO128(sl->mb_luma_dc[p]+16);
606 298287 AV_ZERO128(sl->mb_luma_dc[p]+24);
607
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 298287 times.
298287 if (decode_residual(h, sl, gb, sl->mb_luma_dc[p], LUMA_DC_BLOCK_INDEX + p, scan, NULL, 16) < 0) {
608 return -1; //FIXME continue if partitioned and other return -1 too
609 }
610
611 av_assert2((cbp&15) == 0 || (cbp&15) == 15);
612
613
2/2
✓ Branch 0 taken 103916 times.
✓ Branch 1 taken 194371 times.
298287 if(cbp&15){
614
2/2
✓ Branch 0 taken 415664 times.
✓ Branch 1 taken 103916 times.
519580 for(i8x8=0; i8x8<4; i8x8++){
615
2/2
✓ Branch 0 taken 1662656 times.
✓ Branch 1 taken 415664 times.
2078320 for(i4x4=0; i4x4<4; i4x4++){
616 1662656 const int index= i4x4 + 4*i8x8 + p*16;
617
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1662656 times.
1662656 if( decode_residual(h, sl, gb, sl->mb + (16*index << pixel_shift),
618 1662656 index, scan + 1, h->ps.pps->dequant4_coeff[p][qscale], 15) < 0 ){
619 return -1;
620 }
621 }
622 }
623 103916 return 0xf;
624 }else{
625 194371 fill_rectangle(&sl->non_zero_count_cache[scan8[p*16]], 4, 4, 8, 0, 1);
626 194371 return 0;
627 }
628 }else{
629
2/2
✓ Branch 0 taken 1151757 times.
✓ Branch 1 taken 1549235 times.
2700992 int cqm = (IS_INTRA( mb_type ) ? 0:3)+p;
630 /* For CAVLC 4:4:4, we need to keep track of the luma 8x8 CBP for deblocking nnz purposes. */
631 2700992 int new_cbp = 0;
632
2/2
✓ Branch 0 taken 10803968 times.
✓ Branch 1 taken 2700992 times.
13504960 for(i8x8=0; i8x8<4; i8x8++){
633
2/2
✓ Branch 0 taken 7831392 times.
✓ Branch 1 taken 2972576 times.
10803968 if(cbp & (1<<i8x8)){
634
2/2
✓ Branch 0 taken 2320623 times.
✓ Branch 1 taken 5510769 times.
7831392 if(IS_8x8DCT(mb_type)){
635 2320623 int16_t *buf = &sl->mb[64*i8x8+256*p << pixel_shift];
636 uint8_t *nnz;
637
2/2
✓ Branch 0 taken 9282492 times.
✓ Branch 1 taken 2320623 times.
11603115 for(i4x4=0; i4x4<4; i4x4++){
638 9282492 const int index= i4x4 + 4*i8x8 + p*16;
639
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9282492 times.
9282492 if( decode_residual(h, sl, gb, buf, index, scan8x8+16*i4x4,
640 9282492 h->ps.pps->dequant8_coeff[cqm][qscale], 16) < 0 )
641 return -1;
642 }
643 2320623 nnz = &sl->non_zero_count_cache[scan8[4 * i8x8 + p * 16]];
644 2320623 nnz[0] += nnz[1] + nnz[8] + nnz[9];
645 2320623 new_cbp |= !!nnz[0] << i8x8;
646 }else{
647
2/2
✓ Branch 0 taken 22043076 times.
✓ Branch 1 taken 5510769 times.
27553845 for(i4x4=0; i4x4<4; i4x4++){
648 22043076 const int index= i4x4 + 4*i8x8 + p*16;
649
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 22043076 times.
22043076 if( decode_residual(h, sl, gb, sl->mb + (16*index << pixel_shift), index,
650 22043076 scan, h->ps.pps->dequant4_coeff[cqm][qscale], 16) < 0 ){
651 return -1;
652 }
653 22043076 new_cbp |= sl->non_zero_count_cache[scan8[index]] << i8x8;
654 }
655 }
656 }else{
657 2972576 uint8_t * const nnz = &sl->non_zero_count_cache[scan8[4 * i8x8 + p * 16]];
658 2972576 nnz[0] = nnz[1] = nnz[8] = nnz[9] = 0;
659 }
660 }
661 2700992 return new_cbp;
662 }
663 }
664
665 4849870 int ff_h264_decode_mb_cavlc(const H264Context *h, H264SliceContext *sl)
666 {
667 int mb_xy;
668 int partition_count;
669 unsigned int mb_type, cbp;
670 4849870 int dct8x8_allowed = h->ps.pps->transform_8x8_mode;
671
4/4
✓ Branch 0 taken 389328 times.
✓ Branch 1 taken 4460542 times.
✓ Branch 2 taken 346560 times.
✓ Branch 3 taken 42768 times.
4849870 const int decode_chroma = h->ps.sps->chroma_format_idc == 1 || h->ps.sps->chroma_format_idc == 2;
672 4849870 const int pixel_shift = h->pixel_shift;
673
674 4849870 mb_xy = sl->mb_xy = sl->mb_x + sl->mb_y*h->mb_stride;
675
676 ff_tlog(h->avctx, "pic:%d mb:%d/%d\n", h->poc.frame_num, sl->mb_x, sl->mb_y);
677 4849870 cbp = 0; /* avoid warning. FIXME: find a solution without slowing
678 down the code */
679
2/2
✓ Branch 0 taken 3763413 times.
✓ Branch 1 taken 1086457 times.
4849870 if (sl->slice_type_nos != AV_PICTURE_TYPE_I) {
680
2/2
✓ Branch 0 taken 2638480 times.
✓ Branch 1 taken 1124933 times.
3763413 if (sl->mb_skip_run == -1) {
681 2638480 unsigned mb_skip_run = get_ue_golomb_long(&sl->gb);
682
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2638480 times.
2638480 if (mb_skip_run > h->mb_num) {
683 av_log(h->avctx, AV_LOG_ERROR, "mb_skip_run %d is invalid\n", mb_skip_run);
684 return AVERROR_INVALIDDATA;
685 }
686 2638480 sl->mb_skip_run = mb_skip_run;
687 }
688
689
2/2
✓ Branch 0 taken 1128538 times.
✓ Branch 1 taken 2634875 times.
3763413 if (sl->mb_skip_run--) {
690
4/4
✓ Branch 0 taken 11109 times.
✓ Branch 1 taken 1117429 times.
✓ Branch 2 taken 5515 times.
✓ Branch 3 taken 5594 times.
1128538 if (FRAME_MBAFF(h) && (sl->mb_y & 1) == 0) {
691
2/2
✓ Branch 0 taken 2894 times.
✓ Branch 1 taken 2621 times.
5515 if (sl->mb_skip_run == 0)
692 2894 sl->mb_mbaff = sl->mb_field_decoding_flag = get_bits1(&sl->gb);
693 }
694 1128538 decode_mb_skip(h, sl);
695 1128538 return 0;
696 }
697 }
698
2/2
✓ Branch 0 taken 497835 times.
✓ Branch 1 taken 3223497 times.
3721332 if (FRAME_MBAFF(h)) {
699
2/2
✓ Branch 0 taken 248957 times.
✓ Branch 1 taken 248878 times.
497835 if ((sl->mb_y & 1) == 0)
700 248957 sl->mb_mbaff = sl->mb_field_decoding_flag = get_bits1(&sl->gb);
701 }
702
703 3721332 sl->prev_mb_skipped = 0;
704
705 3721332 mb_type= get_ue_golomb(&sl->gb);
706
2/2
✓ Branch 0 taken 901135 times.
✓ Branch 1 taken 2820197 times.
3721332 if (sl->slice_type_nos == AV_PICTURE_TYPE_B) {
707
2/2
✓ Branch 0 taken 760098 times.
✓ Branch 1 taken 141037 times.
901135 if(mb_type < 23){
708 760098 partition_count = ff_h264_b_mb_type_info[mb_type].partition_count;
709 760098 mb_type = ff_h264_b_mb_type_info[mb_type].type;
710 }else{
711 141037 mb_type -= 23;
712 141037 goto decode_intra_mb;
713 }
714
2/2
✓ Branch 0 taken 1733740 times.
✓ Branch 1 taken 1086457 times.
2820197 } else if (sl->slice_type_nos == AV_PICTURE_TYPE_P) {
715
2/2
✓ Branch 0 taken 1467775 times.
✓ Branch 1 taken 265965 times.
1733740 if(mb_type < 5){
716 1467775 partition_count = ff_h264_p_mb_type_info[mb_type].partition_count;
717 1467775 mb_type = ff_h264_p_mb_type_info[mb_type].type;
718 }else{
719 265965 mb_type -= 5;
720 265965 goto decode_intra_mb;
721 }
722 }else{
723 av_assert2(sl->slice_type_nos == AV_PICTURE_TYPE_I);
724
1/4
✓ Branch 0 taken 1086457 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
1086457 if (sl->slice_type == AV_PICTURE_TYPE_SI && mb_type)
725 mb_type--;
726 1086457 decode_intra_mb:
727
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1493459 times.
1493459 if(mb_type > 25){
728 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);
729 return -1;
730 }
731 1493459 partition_count=0;
732 1493459 cbp = ff_h264_i_mb_type_info[mb_type].cbp;
733 1493459 sl->intra16x16_pred_mode = ff_h264_i_mb_type_info[mb_type].pred_mode;
734 1493459 mb_type = ff_h264_i_mb_type_info[mb_type].type;
735 }
736
737
2/2
✓ Branch 0 taken 981328 times.
✓ Branch 1 taken 2740004 times.
3721332 if (MB_FIELD(sl))
738 981328 mb_type |= MB_TYPE_INTERLACED;
739
740 3721332 h->slice_table[mb_xy] = sl->slice_num;
741
742
2/2
✓ Branch 0 taken 17446 times.
✓ Branch 1 taken 3703886 times.
3721332 if(IS_INTRA_PCM(mb_type)){
743 17446 const int mb_size = ff_h264_mb_sizes[h->ps.sps->chroma_format_idc] *
744 17446 h->ps.sps->bit_depth_luma;
745
746 // We assume these blocks are very rare so we do not optimize it.
747 17446 sl->intra_pcm_ptr = align_get_bits(&sl->gb);
748
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 17446 times.
17446 if (get_bits_left(&sl->gb) < mb_size) {
749 av_log(h->avctx, AV_LOG_ERROR, "Not enough data for an intra PCM block.\n");
750 return AVERROR_INVALIDDATA;
751 }
752 17446 skip_bits_long(&sl->gb, mb_size);
753
754 // In deblocking, the quantizer is 0
755 17446 h->cur_pic.qscale_table[mb_xy] = 0;
756 // All coeffs are present
757 17446 memset(h->non_zero_count[mb_xy], 16, 48);
758
759 17446 h->cur_pic.mb_type[mb_xy] = mb_type;
760 17446 return 0;
761 }
762
763 3703886 fill_decode_neighbors(h, sl, mb_type);
764 3703886 fill_decode_caches(h, sl, mb_type);
765
766 //mb_pred
767
2/2
✓ Branch 0 taken 1476013 times.
✓ Branch 1 taken 2227873 times.
3703886 if(IS_INTRA(mb_type)){
768 int pred_mode;
769 // init_top_left_availability(h);
770
2/2
✓ Branch 0 taken 1177726 times.
✓ Branch 1 taken 298287 times.
1476013 if(IS_INTRA4x4(mb_type)){
771 int i;
772 1177726 int di = 1;
773
4/4
✓ Branch 0 taken 854913 times.
✓ Branch 1 taken 322813 times.
✓ Branch 3 taken 541711 times.
✓ Branch 4 taken 313202 times.
1177726 if(dct8x8_allowed && get_bits1(&sl->gb)){
774 541711 mb_type |= MB_TYPE_8x8DCT;
775 541711 di = 4;
776 }
777
778 // fill_intra4x4_pred_table(h);
779
2/2
✓ Branch 0 taken 12343084 times.
✓ Branch 1 taken 1177726 times.
13520810 for(i=0; i<16; i+=di){
780 12343084 int mode = pred_intra_mode(h, sl, i);
781
782
2/2
✓ Branch 1 taken 6614479 times.
✓ Branch 2 taken 5728605 times.
12343084 if(!get_bits1(&sl->gb)){
783 6614479 const int rem_mode= get_bits(&sl->gb, 3);
784 6614479 mode = rem_mode + (rem_mode >= mode);
785 }
786
787
2/2
✓ Branch 0 taken 2166844 times.
✓ Branch 1 taken 10176240 times.
12343084 if(di==4)
788 2166844 fill_rectangle(&sl->intra4x4_pred_mode_cache[ scan8[i] ], 2, 2, 8, mode, 1);
789 else
790 10176240 sl->intra4x4_pred_mode_cache[scan8[i]] = mode;
791 }
792 1177726 write_back_intra_pred_mode(h, sl);
793
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1177726 times.
1177726 if (ff_h264_check_intra4x4_pred_mode(sl->intra4x4_pred_mode_cache, h->avctx,
794 1177726 sl->top_samples_available, sl->left_samples_available) < 0)
795 return -1;
796 }else{
797 596574 sl->intra16x16_pred_mode = ff_h264_check_intra_pred_mode(h->avctx, sl->top_samples_available,
798 298287 sl->left_samples_available, sl->intra16x16_pred_mode, 0);
799
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 298287 times.
298287 if (sl->intra16x16_pred_mode < 0)
800 return -1;
801 }
802
2/2
✓ Branch 0 taken 1448884 times.
✓ Branch 1 taken 27129 times.
1476013 if(decode_chroma){
803 1448884 pred_mode= ff_h264_check_intra_pred_mode(h->avctx, sl->top_samples_available,
804 1448884 sl->left_samples_available, get_ue_golomb_31(&sl->gb), 1);
805
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1448884 times.
1448884 if(pred_mode < 0)
806 return -1;
807 1448884 sl->chroma_pred_mode = pred_mode;
808 } else {
809 27129 sl->chroma_pred_mode = DC_128_PRED8x8;
810 }
811
2/2
✓ Branch 0 taken 517693 times.
✓ Branch 1 taken 1710180 times.
2227873 }else if(partition_count==4){
812 int i, j, sub_partition_count[4], list, ref[2][4];
813
814
2/2
✓ Branch 0 taken 178547 times.
✓ Branch 1 taken 339146 times.
517693 if (sl->slice_type_nos == AV_PICTURE_TYPE_B) {
815
2/2
✓ Branch 0 taken 714188 times.
✓ Branch 1 taken 178547 times.
892735 for(i=0; i<4; i++){
816 714188 sl->sub_mb_type[i]= get_ue_golomb_31(&sl->gb);
817
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 714188 times.
714188 if(sl->sub_mb_type[i] >=13){
818 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);
819 return -1;
820 }
821 714188 sub_partition_count[i] = ff_h264_b_sub_mb_type_info[sl->sub_mb_type[i]].partition_count;
822 714188 sl->sub_mb_type[i] = ff_h264_b_sub_mb_type_info[sl->sub_mb_type[i]].type;
823 }
824
2/2
✓ Branch 0 taken 56097 times.
✓ Branch 1 taken 122450 times.
178547 if( IS_DIRECT(sl->sub_mb_type[0]|sl->sub_mb_type[1]|sl->sub_mb_type[2]|sl->sub_mb_type[3])) {
825 56097 ff_h264_pred_direct_motion(h, sl, &mb_type);
826 56097 sl->ref_cache[0][scan8[4]] =
827 56097 sl->ref_cache[1][scan8[4]] =
828 56097 sl->ref_cache[0][scan8[12]] =
829 56097 sl->ref_cache[1][scan8[12]] = PART_NOT_AVAILABLE;
830 }
831 }else{
832 av_assert2(sl->slice_type_nos == AV_PICTURE_TYPE_P); //FIXME SP correct ?
833
2/2
✓ Branch 0 taken 1356584 times.
✓ Branch 1 taken 339146 times.
1695730 for(i=0; i<4; i++){
834 1356584 sl->sub_mb_type[i]= get_ue_golomb_31(&sl->gb);
835
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1356584 times.
1356584 if(sl->sub_mb_type[i] >=4){
836 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);
837 return -1;
838 }
839 1356584 sub_partition_count[i] = ff_h264_p_sub_mb_type_info[sl->sub_mb_type[i]].partition_count;
840 1356584 sl->sub_mb_type[i] = ff_h264_p_sub_mb_type_info[sl->sub_mb_type[i]].type;
841 }
842 }
843
844
2/2
✓ Branch 0 taken 696240 times.
✓ Branch 1 taken 517693 times.
1213933 for (list = 0; list < sl->list_count; list++) {
845
2/2
✓ Branch 0 taken 572388 times.
✓ Branch 1 taken 123852 times.
696240 int ref_count = IS_REF0(mb_type) ? 1 : sl->ref_count[list] << MB_MBAFF(sl);
846
2/2
✓ Branch 0 taken 2784960 times.
✓ Branch 1 taken 696240 times.
3481200 for(i=0; i<4; i++){
847
2/2
✓ Branch 0 taken 232378 times.
✓ Branch 1 taken 2552582 times.
2784960 if(IS_DIRECT(sl->sub_mb_type[i])) continue;
848
2/2
✓ Branch 0 taken 2224582 times.
✓ Branch 1 taken 328000 times.
2552582 if(IS_DIR(sl->sub_mb_type[i], 0, list)){
849 unsigned int tmp;
850
2/2
✓ Branch 0 taken 780389 times.
✓ Branch 1 taken 1444193 times.
2224582 if(ref_count == 1){
851 780389 tmp= 0;
852
2/2
✓ Branch 0 taken 454436 times.
✓ Branch 1 taken 989757 times.
1444193 }else if(ref_count == 2){
853 454436 tmp= get_bits1(&sl->gb)^1;
854 }else{
855 989757 tmp= get_ue_golomb_31(&sl->gb);
856
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 989757 times.
989757 if(tmp>=ref_count){
857 av_log(h->avctx, AV_LOG_ERROR, "ref %u overflow\n", tmp);
858 return -1;
859 }
860 }
861 2224582 ref[list][i]= tmp;
862 }else{
863 //FIXME
864 328000 ref[list][i] = -1;
865 }
866 }
867 }
868
869
2/2
✓ Branch 0 taken 51527 times.
✓ Branch 1 taken 466166 times.
517693 if(dct8x8_allowed)
870 51527 dct8x8_allowed = get_dct8x8_allowed(h, sl);
871
872
2/2
✓ Branch 0 taken 696240 times.
✓ Branch 1 taken 517693 times.
1213933 for (list = 0; list < sl->list_count; list++) {
873
2/2
✓ Branch 0 taken 2784960 times.
✓ Branch 1 taken 696240 times.
3481200 for(i=0; i<4; i++){
874
2/2
✓ Branch 0 taken 232378 times.
✓ Branch 1 taken 2552582 times.
2784960 if(IS_DIRECT(sl->sub_mb_type[i])) {
875 232378 sl->ref_cache[list][ scan8[4*i] ] = sl->ref_cache[list][ scan8[4*i]+1 ];
876 232378 continue;
877 }
878 2552582 sl->ref_cache[list][ scan8[4*i] ]=sl->ref_cache[list][ scan8[4*i]+1 ]=
879 2552582 sl->ref_cache[list][ scan8[4*i]+8 ]=sl->ref_cache[list][ scan8[4*i]+9 ]= ref[list][i];
880
881
2/2
✓ Branch 0 taken 2224582 times.
✓ Branch 1 taken 328000 times.
2552582 if(IS_DIR(sl->sub_mb_type[i], 0, list)){
882 2224582 const int sub_mb_type= sl->sub_mb_type[i];
883
2/2
✓ Branch 0 taken 1678039 times.
✓ Branch 1 taken 546543 times.
2224582 const int block_width= (sub_mb_type & (MB_TYPE_16x16|MB_TYPE_16x8)) ? 2 : 1;
884
2/2
✓ Branch 0 taken 3687770 times.
✓ Branch 1 taken 2224582 times.
5912352 for(j=0; j<sub_partition_count[i]; j++){
885 int mx, my;
886 3687770 const int index= 4*i + block_width*j;
887 3687770 int16_t (* mv_cache)[2]= &sl->mv_cache[list][ scan8[index] ];
888 3687770 pred_motion(h, sl, index, block_width, list, sl->ref_cache[list][ scan8[index] ], &mx, &my);
889 3687770 mx += (unsigned)get_se_golomb(&sl->gb);
890 3687770 my += (unsigned)get_se_golomb(&sl->gb);
891 ff_tlog(h->avctx, "final mv:%d %d\n", mx, my);
892
893
2/2
✓ Branch 0 taken 1165880 times.
✓ Branch 1 taken 2521890 times.
3687770 if(IS_SUB_8X8(sub_mb_type)){
894 1165880 mv_cache[ 1 ][0]=
895 1165880 mv_cache[ 8 ][0]= mv_cache[ 9 ][0]= mx;
896 1165880 mv_cache[ 1 ][1]=
897 1165880 mv_cache[ 8 ][1]= mv_cache[ 9 ][1]= my;
898
2/2
✓ Branch 0 taken 1024318 times.
✓ Branch 1 taken 1497572 times.
2521890 }else if(IS_SUB_8X4(sub_mb_type)){
899 1024318 mv_cache[ 1 ][0]= mx;
900 1024318 mv_cache[ 1 ][1]= my;
901
2/2
✓ Branch 0 taken 688600 times.
✓ Branch 1 taken 808972 times.
1497572 }else if(IS_SUB_4X8(sub_mb_type)){
902 688600 mv_cache[ 8 ][0]= mx;
903 688600 mv_cache[ 8 ][1]= my;
904 }
905 3687770 mv_cache[ 0 ][0]= mx;
906 3687770 mv_cache[ 0 ][1]= my;
907 }
908 }else{
909 328000 uint32_t *p= (uint32_t *)&sl->mv_cache[list][ scan8[4*i] ][0];
910 328000 p[0] = p[1]=
911 328000 p[8] = p[9]= 0;
912 }
913 }
914 }
915
2/2
✓ Branch 0 taken 139126 times.
✓ Branch 1 taken 1571054 times.
1710180 }else if(IS_DIRECT(mb_type)){
916 139126 ff_h264_pred_direct_motion(h, sl, &mb_type);
917 139126 dct8x8_allowed &= h->ps.sps->direct_8x8_inference_flag;
918 }else{
919 int list, mx, my, i;
920 //FIXME we should set ref_idx_l? to 0 if we use that later ...
921
2/2
✓ Branch 0 taken 1070835 times.
✓ Branch 1 taken 500219 times.
1571054 if(IS_16X16(mb_type)){
922
2/2
✓ Branch 0 taken 1334724 times.
✓ Branch 1 taken 1070835 times.
2405559 for (list = 0; list < sl->list_count; list++) {
923 unsigned int val;
924
2/2
✓ Branch 0 taken 1127389 times.
✓ Branch 1 taken 207335 times.
1334724 if(IS_DIR(mb_type, 0, list)){
925 1127389 unsigned rc = sl->ref_count[list] << MB_MBAFF(sl);
926
2/2
✓ Branch 0 taken 627938 times.
✓ Branch 1 taken 499451 times.
1127389 if (rc == 1) {
927 627938 val= 0;
928
2/2
✓ Branch 0 taken 135504 times.
✓ Branch 1 taken 363947 times.
499451 } else if (rc == 2) {
929 135504 val= get_bits1(&sl->gb)^1;
930 }else{
931 363947 val= get_ue_golomb_31(&sl->gb);
932
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 363947 times.
363947 if (val >= rc) {
933 av_log(h->avctx, AV_LOG_ERROR, "ref %u overflow\n", val);
934 return -1;
935 }
936 }
937 1127389 fill_rectangle(&sl->ref_cache[list][ scan8[0] ], 4, 4, 8, val, 1);
938 }
939 }
940
2/2
✓ Branch 0 taken 1334724 times.
✓ Branch 1 taken 1070835 times.
2405559 for (list = 0; list < sl->list_count; list++) {
941
2/2
✓ Branch 0 taken 1127389 times.
✓ Branch 1 taken 207335 times.
1334724 if(IS_DIR(mb_type, 0, list)){
942 1127389 pred_motion(h, sl, 0, 4, list, sl->ref_cache[list][ scan8[0] ], &mx, &my);
943 1127389 mx += (unsigned)get_se_golomb(&sl->gb);
944 1127389 my += (unsigned)get_se_golomb(&sl->gb);
945 ff_tlog(h->avctx, "final mv:%d %d\n", mx, my);
946
947 1127389 fill_rectangle(sl->mv_cache[list][ scan8[0] ], 4, 4, 8, pack16to32(mx,my), 4);
948 }
949 }
950 }
951
2/2
✓ Branch 0 taken 264997 times.
✓ Branch 1 taken 235222 times.
500219 else if(IS_16X8(mb_type)){
952
2/2
✓ Branch 0 taken 363542 times.
✓ Branch 1 taken 264997 times.
628539 for (list = 0; list < sl->list_count; list++) {
953
2/2
✓ Branch 0 taken 727084 times.
✓ Branch 1 taken 363542 times.
1090626 for(i=0; i<2; i++){
954 unsigned int val;
955
2/2
✓ Branch 0 taken 572878 times.
✓ Branch 1 taken 154206 times.
727084 if(IS_DIR(mb_type, i, list)){
956 572878 unsigned rc = sl->ref_count[list] << MB_MBAFF(sl);
957
2/2
✓ Branch 0 taken 230171 times.
✓ Branch 1 taken 342707 times.
572878 if (rc == 1) {
958 230171 val= 0;
959
2/2
✓ Branch 0 taken 80255 times.
✓ Branch 1 taken 262452 times.
342707 } else if (rc == 2) {
960 80255 val= get_bits1(&sl->gb)^1;
961 }else{
962 262452 val= get_ue_golomb_31(&sl->gb);
963
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 262452 times.
262452 if (val >= rc) {
964 av_log(h->avctx, AV_LOG_ERROR, "ref %u overflow\n", val);
965 return -1;
966 }
967 }
968 }else
969 154206 val= LIST_NOT_USED&0xFF;
970 727084 fill_rectangle(&sl->ref_cache[list][ scan8[0] + 16*i ], 4, 2, 8, val, 1);
971 }
972 }
973
2/2
✓ Branch 0 taken 363542 times.
✓ Branch 1 taken 264997 times.
628539 for (list = 0; list < sl->list_count; list++) {
974
2/2
✓ Branch 0 taken 727084 times.
✓ Branch 1 taken 363542 times.
1090626 for(i=0; i<2; i++){
975 unsigned int val;
976
2/2
✓ Branch 0 taken 572878 times.
✓ Branch 1 taken 154206 times.
727084 if(IS_DIR(mb_type, i, list)){
977 572878 pred_16x8_motion(h, sl, 8*i, list, sl->ref_cache[list][scan8[0] + 16*i], &mx, &my);
978 572878 mx += (unsigned)get_se_golomb(&sl->gb);
979 572878 my += (unsigned)get_se_golomb(&sl->gb);
980 ff_tlog(h->avctx, "final mv:%d %d\n", mx, my);
981
982 572878 val= pack16to32(mx,my);
983 }else
984 154206 val=0;
985 727084 fill_rectangle(sl->mv_cache[list][ scan8[0] + 16*i ], 4, 2, 8, val, 4);
986 }
987 }
988 }else{
989 av_assert2(IS_8X16(mb_type));
990
2/2
✓ Branch 0 taken 315213 times.
✓ Branch 1 taken 235222 times.
550435 for (list = 0; list < sl->list_count; list++) {
991
2/2
✓ Branch 0 taken 630426 times.
✓ Branch 1 taken 315213 times.
945639 for(i=0; i<2; i++){
992 unsigned int val;
993
2/2
✓ Branch 0 taken 503708 times.
✓ Branch 1 taken 126718 times.
630426 if(IS_DIR(mb_type, i, list)){ //FIXME optimize
994 503708 unsigned rc = sl->ref_count[list] << MB_MBAFF(sl);
995
2/2
✓ Branch 0 taken 202563 times.
✓ Branch 1 taken 301145 times.
503708 if (rc == 1) {
996 202563 val= 0;
997
2/2
✓ Branch 0 taken 82740 times.
✓ Branch 1 taken 218405 times.
301145 } else if (rc == 2) {
998 82740 val= get_bits1(&sl->gb)^1;
999 }else{
1000 218405 val= get_ue_golomb_31(&sl->gb);
1001
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 218405 times.
218405 if (val >= rc) {
1002 av_log(h->avctx, AV_LOG_ERROR, "ref %u overflow\n", val);
1003 return -1;
1004 }
1005 }
1006 }else
1007 126718 val= LIST_NOT_USED&0xFF;
1008 630426 fill_rectangle(&sl->ref_cache[list][ scan8[0] + 2*i ], 2, 4, 8, val, 1);
1009 }
1010 }
1011
2/2
✓ Branch 0 taken 315213 times.
✓ Branch 1 taken 235222 times.
550435 for (list = 0; list < sl->list_count; list++) {
1012
2/2
✓ Branch 0 taken 630426 times.
✓ Branch 1 taken 315213 times.
945639 for(i=0; i<2; i++){
1013 unsigned int val;
1014
2/2
✓ Branch 0 taken 503708 times.
✓ Branch 1 taken 126718 times.
630426 if(IS_DIR(mb_type, i, list)){
1015 503708 pred_8x16_motion(h, sl, i*4, list, sl->ref_cache[list][ scan8[0] + 2*i ], &mx, &my);
1016 503708 mx += (unsigned)get_se_golomb(&sl->gb);
1017 503708 my += (unsigned)get_se_golomb(&sl->gb);
1018 ff_tlog(h->avctx, "final mv:%d %d\n", mx, my);
1019
1020 503708 val= pack16to32(mx,my);
1021 }else
1022 126718 val=0;
1023 630426 fill_rectangle(sl->mv_cache[list][ scan8[0] + 2*i ], 2, 4, 8, val, 4);
1024 }
1025 }
1026 }
1027 }
1028
1029
2/2
✓ Branch 0 taken 2227873 times.
✓ Branch 1 taken 1476013 times.
3703886 if(IS_INTER(mb_type))
1030 2227873 write_back_motion(h, sl, mb_type);
1031
1032
2/2
✓ Branch 0 taken 3405599 times.
✓ Branch 1 taken 298287 times.
3703886 if(!IS_INTRA16x16(mb_type)){
1033 3405599 cbp= get_ue_golomb(&sl->gb);
1034
1035
2/2
✓ Branch 0 taken 3366249 times.
✓ Branch 1 taken 39350 times.
3405599 if(decode_chroma){
1036
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3366249 times.
3366249 if(cbp > 47){
1037 av_log(h->avctx, AV_LOG_ERROR, "cbp too large (%u) at %d %d\n", cbp, sl->mb_x, sl->mb_y);
1038 return -1;
1039 }
1040
2/2
✓ Branch 0 taken 1153577 times.
✓ Branch 1 taken 2212672 times.
3366249 if (IS_INTRA4x4(mb_type))
1041 1153577 cbp = ff_h264_golomb_to_intra4x4_cbp[cbp];
1042 else
1043 2212672 cbp = ff_h264_golomb_to_inter_cbp[cbp];
1044 }else{
1045
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 39350 times.
39350 if(cbp > 15){
1046 av_log(h->avctx, AV_LOG_ERROR, "cbp too large (%u) at %d %d\n", cbp, sl->mb_x, sl->mb_y);
1047 return -1;
1048 }
1049
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];
1050 15201 else cbp= golomb_to_inter_cbp_gray[cbp];
1051 }
1052 } else {
1053
3/4
✓ Branch 0 taken 2980 times.
✓ Branch 1 taken 295307 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2980 times.
298287 if (!decode_chroma && cbp>15) {
1054 av_log(h->avctx, AV_LOG_ERROR, "gray chroma\n");
1055 return AVERROR_INVALIDDATA;
1056 }
1057 }
1058
1059
6/6
✓ Branch 0 taken 1349162 times.
✓ Branch 1 taken 2354724 times.
✓ Branch 2 taken 1154939 times.
✓ Branch 3 taken 194223 times.
✓ Branch 4 taken 275548 times.
✓ Branch 5 taken 879391 times.
3703886 if(dct8x8_allowed && (cbp&15) && !IS_INTRA(mb_type)){
1060 275548 mb_type |= MB_TYPE_8x8DCT*get_bits1(&sl->gb);
1061 }
1062 3703886 sl->cbp=
1063 3703886 h->cbp_table[mb_xy]= cbp;
1064 3703886 h->cur_pic.mb_type[mb_xy] = mb_type;
1065
1066
4/4
✓ Branch 0 taken 875961 times.
✓ Branch 1 taken 2827925 times.
✓ Branch 2 taken 171354 times.
✓ Branch 3 taken 704607 times.
6703165 if(cbp || IS_INTRA16x16(mb_type)){
1067 int i4x4, i8x8, chroma_idx;
1068 int dquant;
1069 int ret;
1070 2999279 GetBitContext *gb = &sl->gb;
1071 const uint8_t *scan, *scan8x8;
1072 2999279 const int max_qp = 51 + 6 * (h->ps.sps->bit_depth_luma - 8);
1073
1074 2999279 dquant= get_se_golomb(&sl->gb);
1075
1076 2999279 sl->qscale += (unsigned)dquant;
1077
1078
2/2
✓ Branch 0 taken 8070 times.
✓ Branch 1 taken 2991209 times.
2999279 if (((unsigned)sl->qscale) > max_qp){
1079
2/2
✓ Branch 0 taken 3860 times.
✓ Branch 1 taken 4210 times.
8070 if (sl->qscale < 0) sl->qscale += max_qp + 1;
1080 4210 else sl->qscale -= max_qp+1;
1081
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8070 times.
8070 if (((unsigned)sl->qscale) > max_qp){
1082 av_log(h->avctx, AV_LOG_ERROR, "dquant out of range (%d) at %d %d\n", dquant, sl->mb_x, sl->mb_y);
1083 sl->qscale = max_qp;
1084 return -1;
1085 }
1086 }
1087
1088 2999279 sl->chroma_qp[0] = get_chroma_qp(h->ps.pps, 0, sl->qscale);
1089 2999279 sl->chroma_qp[1] = get_chroma_qp(h->ps.pps, 1, sl->qscale);
1090
1091
2/2
✓ Branch 0 taken 824163 times.
✓ Branch 1 taken 2175116 times.
2999279 if(IS_INTERLACED(mb_type)){
1092
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;
1093
2/2
✓ Branch 0 taken 824002 times.
✓ Branch 1 taken 161 times.
824163 scan = sl->qscale ? h->field_scan : h->field_scan_q0;
1094 }else{
1095
2/2
✓ Branch 0 taken 2174227 times.
✓ Branch 1 taken 889 times.
2175116 scan8x8 = sl->qscale ? h->zigzag_scan8x8_cavlc : h->zigzag_scan8x8_cavlc_q0;
1096
2/2
✓ Branch 0 taken 2174227 times.
✓ Branch 1 taken 889 times.
2175116 scan = sl->qscale ? h->zigzag_scan : h->zigzag_scan_q0;
1097 }
1098
1099
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2999279 times.
2999279 if ((ret = decode_luma_residual(h, sl, gb, scan, scan8x8, pixel_shift, mb_type, cbp, 0)) < 0 ) {
1100 return -1;
1101 }
1102 2999279 h->cbp_table[mb_xy] |= ret << 12;
1103
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2999279 times.
2999279 if (CHROMA444(h)) {
1104 if (decode_luma_residual(h, sl, gb, scan, scan8x8, pixel_shift, mb_type, cbp, 1) < 0 ) {
1105 return -1;
1106 }
1107 if (decode_luma_residual(h, sl, gb, scan, scan8x8, pixel_shift, mb_type, cbp, 2) < 0 ) {
1108 return -1;
1109 }
1110 } else {
1111 2999279 const int num_c8x8 = h->ps.sps->chroma_format_idc;
1112
1113
2/2
✓ Branch 0 taken 1646069 times.
✓ Branch 1 taken 1353210 times.
2999279 if(cbp&0x30){
1114
2/2
✓ Branch 0 taken 3292138 times.
✓ Branch 1 taken 1646069 times.
4938207 for(chroma_idx=0; chroma_idx<2; chroma_idx++)
1115
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 3292138 times.
3292138 if (decode_residual(h, sl, gb, sl->mb + ((256 + 16*16*chroma_idx) << pixel_shift),
1116 CHROMA_DC_BLOCK_INDEX + chroma_idx,
1117
2/2
✓ Branch 0 taken 579058 times.
✓ Branch 1 taken 2713080 times.
3292138 CHROMA422(h) ? ff_h264_chroma422_dc_scan : ff_h264_chroma_dc_scan,
1118 NULL, 4 * num_c8x8) < 0) {
1119 return -1;
1120 }
1121 }
1122
1123
2/2
✓ Branch 0 taken 1028292 times.
✓ Branch 1 taken 1970987 times.
2999279 if(cbp&0x20){
1124
2/2
✓ Branch 0 taken 2056584 times.
✓ Branch 1 taken 1028292 times.
3084876 for(chroma_idx=0; chroma_idx<2; chroma_idx++){
1125
2/2
✓ Branch 0 taken 1192326 times.
✓ Branch 1 taken 864258 times.
2056584 const uint32_t *qmul = h->ps.pps->dequant4_coeff[chroma_idx+1+(IS_INTRA( mb_type ) ? 0:3)][sl->chroma_qp[chroma_idx]];
1126 2056584 int16_t *mb = sl->mb + (16*(16 + 16*chroma_idx) << pixel_shift);
1127
2/2
✓ Branch 0 taken 2443728 times.
✓ Branch 1 taken 2056584 times.
4500312 for (i8x8 = 0; i8x8<num_c8x8; i8x8++) {
1128
2/2
✓ Branch 0 taken 9774912 times.
✓ Branch 1 taken 2443728 times.
12218640 for (i4x4 = 0; i4x4 < 4; i4x4++) {
1129 9774912 const int index = 16 + 16*chroma_idx + 8*i8x8 + i4x4;
1130
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 9774912 times.
9774912 if (decode_residual(h, sl, gb, mb, index, scan + 1, qmul, 15) < 0)
1131 return -1;
1132 9774912 mb += 16 << pixel_shift;
1133 }
1134 }
1135 }
1136 }else{
1137 1970987 fill_rectangle(&sl->non_zero_count_cache[scan8[16]], 4, 4, 8, 0, 1);
1138 1970987 fill_rectangle(&sl->non_zero_count_cache[scan8[32]], 4, 4, 8, 0, 1);
1139 }
1140 }
1141 }else{
1142 704607 fill_rectangle(&sl->non_zero_count_cache[scan8[ 0]], 4, 4, 8, 0, 1);
1143 704607 fill_rectangle(&sl->non_zero_count_cache[scan8[16]], 4, 4, 8, 0, 1);
1144 704607 fill_rectangle(&sl->non_zero_count_cache[scan8[32]], 4, 4, 8, 0, 1);
1145 }
1146 3703886 h->cur_pic.qscale_table[mb_xy] = sl->qscale;
1147 3703886 write_back_non_zero_count(h, sl);
1148
1149 3703886 return 0;
1150 }
1151